spec/toy/attributes_spec.rb in toystore-0.7.0 vs spec/toy/attributes_spec.rb in toystore-0.8.0
- old
+ new
@@ -421,6 +421,27 @@
it "initializes to empty array" do
User.new.skills.should == []
end
end
+
+ # https://github.com/newtoy/toystore/issues/13
+ describe "Overriding initialize and setting an attribute before calling super" do
+ before do
+ User.attribute(:name, String)
+ User.class_eval do
+ def initialize(*)
+ self.name = 'John'
+ super
+ end
+ end
+ end
+
+ it "does not throw error" do
+ lambda { User.new }.should_not raise_error
+ end
+
+ it "sets value" do
+ User.new.name.should == 'John'
+ end
+ end
end
\ No newline at end of file