spec/model_spec.rb in cistern-0.3.0 vs spec/model_spec.rb in cistern-0.3.1
- old
+ new
@@ -29,10 +29,17 @@
attribute :number, type: :integer
attribute :floater, type: :float
attribute :butternut, type: :integer, aliases: "squash", squash: "id"
attribute :custom, parser: lambda{|v, opts| "X!#{v}"}
+ attribute :same_alias_1, aliases: "nested"
+ attribute :same_alias_2, aliases: "nested"
+
+ attribute :same_alias_squashed_1, aliases: "nested", squash: "attr_1"
+ attribute :same_alias_squashed_2, aliases: "nested", squash: "attr_2"
+ attribute :same_alias_squashed_3, aliases: "nested", squash: "attr_2"
+
def save
requires :flag
end
end
@@ -72,9 +79,24 @@
TypeSpec.new(custom: "15").custom.should == "X!15"
end
it "should squash and cast" do
TypeSpec.new({"squash" => {"id" => "12"}}).butternut.should == 12
+ end
+
+ context "allowing the same alias for multiple attributes" do
+ it "should do so when not squashing" do
+ type_spec = TypeSpec.new({"nested" => "bamboo"})
+ type_spec.same_alias_1.should == "bamboo"
+ type_spec.same_alias_2.should == "bamboo"
+ end
+
+ it "should do so when squashing" do
+ type_spec = TypeSpec.new({"nested" => {"attr_1" => "bamboo", "attr_2" => "panda"}})
+ type_spec.same_alias_squashed_1.should == "bamboo"
+ type_spec.same_alias_squashed_2.should == "panda"
+ type_spec.same_alias_squashed_3.should == "panda"
+ end
end
it "should slice out unaccounted for attributes" do
TypeSpec.new({"something" => {"id" => "12"}}).attributes.keys.should_not include("something")
end