Permalink
Browse files

Move @attributes hash defaulting to dirty module

This is where the error was happening technically.
  • Loading branch information...
1 parent 8405dda commit 3f3afdb2a5e705273a70867ee14f0ac68408451f @jnunemaker committed May 19, 2012
Showing with 24 additions and 24 deletions.
  1. +0 −1 lib/toy/attributes.rb
  2. +2 −1 lib/toy/dirty.rb
  3. +0 −21 spec/toy/attributes_spec.rb
  4. +22 −1 spec/toy/dirty_spec.rb
@@ -71,7 +71,6 @@ def []=(key, value)
private
def read_attribute(key)
- @attributes ||= {}
@attributes[key.to_s]
end
View
@@ -19,10 +19,11 @@ def initialize_copy(*)
end
def write_attribute(name, value)
+ @attributes ||= {}
name = name.to_s
current = read_attribute(name)
attribute_will_change!(name) if current != value
super
end
end
-end
+end
@@ -307,25 +307,4 @@ def pirate=(value)
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
@@ -64,4 +64,25 @@
User.new.clone.should_not be_changed
end
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

0 comments on commit 3f3afdb

Please sign in to comment.