Sha256: 6180561c9b37eab3d06ab115b5fb4d8275c8e99ec17eb71d53cbcfe543a15e59
Contents?: true
Size: 1.55 KB
Versions: 2
Compression:
Stored size: 1.55 KB
Contents
require 'test_helper' class RepresenterTest < MiniTest::Spec describe "Representer::Base" do before do @c = Class.new do include Roar::Representer::Base end end it "aliases #representable_property to #property" do @c.property :title assert_equal "title", @c.representable_attrs.first.name end it "aliases #representable_collection to #collection" do @c.collection :songs assert_equal "songs", @c.representable_attrs.first.name end describe "#from_attributes" do it "accepts a block yielding the created representer instance" do @c.class_eval { attr_accessor :name } assert_equal("Conan", @c.from_attributes({}) { |rep| rep.name = "Conan" }.name) end it "copies known properties, only, but doesn't complain" do @c.class_eval { property :id } assert_equal 1, @c.from_attributes("id" => 1, "unknown" => "don't use me").id end it "accepts symbols and strings as property name" do @c.class_eval { property :id } assert_equal @c.from_attributes(:id => 1).id, @c.from_attributes("id" => 1).id end end end describe "Inheritance" do it "properly inherits properties" do base = Class.new do include Roar::Representer::JSON self.representation_name= "collection" property :name end assert_equal "{\"collection\":{\"name\":\"Paulo\"}}", Class.new(base).from_attributes(:name => "Paulo").to_json end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
roar-0.8.2 | test/representer_test.rb |
roar-0.8.1 | test/representer_test.rb |