Sha256: 1de7c4a7b461a67d52a02a479bad9bb2e93540cd91e90f8de3fa3eca593eedfd

Contents?: true

Size: 1.17 KB

Versions: 42

Compression:

Stored size: 1.17 KB

Contents

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

Version data entries

42 entries across 38 versions & 1 rubygems

Version Path
representable-3.0.4 test/stringify_hash_test.rb
representable-3.0.3 test/stringify_hash_test.rb
representable-3.0.2 test/stringify_hash_test.rb
representable-3.0.1 test/stringify_hash_test.rb
representable-3.0.0 test/stringify_hash_test.rb
representable-2.4.1 test-with-deprecations/stringify_hash_test.rb
representable-2.4.1 test/stringify_hash_test.rb
representable-2.4.0 test/stringify_hash_test.rb
representable-2.4.0 test-with-deprecations/stringify_hash_test.rb
representable-2.4.0.rc5 test-with-deprecations/stringify_hash_test.rb
representable-2.4.0.rc5 test/stringify_hash_test.rb
representable-2.4.0.rc4 test/stringify_hash_test.rb
representable-2.4.0.rc4 test-with-deprecations/stringify_hash_test.rb
representable-2.4.0.rc3 test/stringify_hash_test.rb
representable-2.4.0.rc2 test/stringify_hash_test.rb
representable-2.4.0.rc1 test/stringify_hash_test.rb
representable-2.3.0 test/stringify_hash_test.rb
representable-2.2.3 test/stringify_hash_test.rb
representable-2.2.2 test/stringify_hash_test.rb
representable-2.2.1 test/stringify_hash_test.rb