File: stringify_hash_test.rb

package info (click to toggle)
ruby-representable 3.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 896 kB
  • sloc: ruby: 6,432; makefile: 3
file content (41 lines) | stat: -rw-r--r-- 1,194 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'test_helper'

class StringifyHashTest < Minitest::Spec
describe "#from_hash" do
  representer!(:name => :song_representer) do

    include Representable::Hash
    include Representable::Hash::AllowSymbols

    property :title
  end

  representer!(:inject => :song_representer) do
    include Representable::Hash::AllowSymbols

    property :song, :extend => song_representer, :class => OpenStruct
   end

   it "parses symbols, too" do
     OpenStruct.new.extend(representer).from_hash({:song => {:title => "Der Optimist"}}).song.title.must_equal "Der Optimist"
   end

   it "still parses strings" do
     OpenStruct.new.extend(representer).from_hash({"song" => {"title" => "Der Optimist"}}).song.title.must_equal "Der Optimist"
   end

   describe "with :wrap" do
    representer!(:inject => :song_representer) do
      include Representable::Hash::AllowSymbols

      self.representation_wrap = :album
      property :song, :extend => song_representer, :class => OpenStruct
    end

     it "parses symbols, too" do
       OpenStruct.new.extend(representer).from_hash({:album => {:song => {:title => "Der Optimist"}}}).song.title.must_equal "Der Optimist"
     end
   end
 end

end