Fixes Model.new(nil) with attribute protection. GH issue #8

Signed-off-by: Marcos Tapajós <tapajos@gmail.com>
This commit is contained in:
Will Leinweber 2010-08-20 15:57:03 -05:00 committed by Marcos Tapajós
parent b20bfad11f
commit 62f4f72cab
2 changed files with 6 additions and 1 deletions

View file

@ -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

View file

@ -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')