From 62f4f72cab496184301bb0b635eb64d9ab664fee Mon Sep 17 00:00:00 2001 From: Will Leinweber Date: Fri, 20 Aug 2010 15:57:03 -0500 Subject: [PATCH] Fixes Model.new(nil) with attribute protection. GH issue #8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcos Tapajós --- lib/couchrest/model/attribute_protection.rb | 2 +- spec/couchrest/attribute_protection_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/couchrest/model/attribute_protection.rb b/lib/couchrest/model/attribute_protection.rb index 16d29b3..1ddbd80 100644 --- a/lib/couchrest/model/attribute_protection.rb +++ b/lib/couchrest/model/attribute_protection.rb @@ -54,7 +54,7 @@ module CouchRest attributes.reject! do |property_name, property_value| protected_names.include?(property_name.to_s) - end + end if attributes attributes || {} end diff --git a/spec/couchrest/attribute_protection_spec.rb b/spec/couchrest/attribute_protection_spec.rb index e4816a2..261b88b 100644 --- a/spec/couchrest/attribute_protection_spec.rb +++ b/spec/couchrest/attribute_protection_spec.rb @@ -43,6 +43,8 @@ describe "Model Attributes" do property :admin, :default => false end + it { expect { WithAccessible.new(nil) }.to_not raise_error } + it "should recognize accessible properties" do props = WithAccessible.accessible_properties.map { |prop| prop.name} props.should include("name") @@ -72,6 +74,8 @@ describe "Model Attributes" do property :admin, :default => false, :protected => true end + it { expect { WithProtected.new(nil) }.to_not raise_error } + it "should recognize protected properties" do props = WithProtected.protected_properties.map { |prop| prop.name} props.should_not include("name") @@ -103,6 +107,7 @@ describe "Model Attributes" do end it { expect { WithBothAndUnspecified.new }.to_not raise_error } + it { expect { WithBothAndUnspecified.new(nil) }.to_not raise_error } it 'should assume that any unspecified property is protected by default' do user = WithBothAndUnspecified.new(:name => 'will', :admin => true, :phone => '555-1234')