test/hash_test.rb in representable-3.0.1 vs test/hash_test.rb in representable-3.0.2

- old
+ new

@@ -1,7 +1,29 @@ require 'test_helper' +class HashPublicMethodsTest < Minitest::Spec + #--- + # from_hash + class BandRepresenter < Representable::Decorator + include Representable::Hash + property :id + property :name + end + + let (:data) { {"id"=>1,"name"=>"Rancid"} } + + it { BandRepresenter.new(Band.new).from_hash(data)[:id, :name].must_equal [1, "Rancid"] } + it { BandRepresenter.new(Band.new).parse(data)[:id, :name].must_equal [1, "Rancid"] } + + #--- + # to_hash + let (:band) { Band.new(1, "Rancid") } + + it { BandRepresenter.new(band).to_hash.must_equal data } + it { BandRepresenter.new(band).render.must_equal data } +end + class HashWithScalarPropertyTest < MiniTest::Spec Album = Struct.new(:title) representer! do property :title @@ -155,6 +177,6 @@ describe "#from_hash" do it "parses a block style list" do album.extend(representer).from_hash("songs" => ["Off Key Melody", "Sinking"]).must_equal Album.new(["Off Key Melody", "Sinking"]) end end -end \ No newline at end of file +end