spec/toy/attributes_spec.rb in toystore-0.6.3 vs spec/toy/attributes_spec.rb in toystore-0.6.4
- old
+ new
@@ -128,10 +128,17 @@
end
it "does not fail with nil" do
User.new(nil).should be_instance_of(User)
end
+
+ it "does guard attributes=" do
+ attrs = {'age' => 21}
+ user = User.allocate
+ user.should_receive(:attributes=).with(attrs, true)
+ user.send(:initialize, attrs)
+ end
end
describe "#initialize_from_database" do
before do
User.attribute(:age, Integer, :default => 20)
@@ -157,10 +164,16 @@
end
it "returns self" do
@user.initialize_from_database.should == @user
end
+
+ it "does not guard attributes=" do
+ attrs = {'age' => 21}
+ @user.should_receive(:attributes=).with(attrs, false)
+ @user.initialize_from_database(attrs)
+ end
end
describe "#attributes" do
it "defaults to hash with id" do
attrs = Model().new.attributes
@@ -387,9 +400,18 @@
it "reloads defaults" do
User.attribute(:skills, Array)
@user.reload
@user.skills.should == []
+ end
+
+ it "reloads attributes protected from mass assignment" do
+ User.attribute(:admin, Boolean)
+ User.attr_accessible(:name)
+ user = User.new(:name => 'John')
+ user.admin = true
+ user.save
+ user.reload.admin.should be_true
end
end
describe "Initialization of array attributes" do
before do
\ No newline at end of file