Fixes Model.new(nil) with attribute protection. GH issue #8
Signed-off-by: Marcos Tapajós <tapajos@gmail.com>
This commit is contained in:
parent
b20bfad11f
commit
62f4f72cab
|
@ -54,7 +54,7 @@ module CouchRest
|
||||||
|
|
||||||
attributes.reject! do |property_name, property_value|
|
attributes.reject! do |property_name, property_value|
|
||||||
protected_names.include?(property_name.to_s)
|
protected_names.include?(property_name.to_s)
|
||||||
end
|
end if attributes
|
||||||
|
|
||||||
attributes || {}
|
attributes || {}
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,6 +43,8 @@ describe "Model Attributes" do
|
||||||
property :admin, :default => false
|
property :admin, :default => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it { expect { WithAccessible.new(nil) }.to_not raise_error }
|
||||||
|
|
||||||
it "should recognize accessible properties" do
|
it "should recognize accessible properties" do
|
||||||
props = WithAccessible.accessible_properties.map { |prop| prop.name}
|
props = WithAccessible.accessible_properties.map { |prop| prop.name}
|
||||||
props.should include("name")
|
props.should include("name")
|
||||||
|
@ -72,6 +74,8 @@ describe "Model Attributes" do
|
||||||
property :admin, :default => false, :protected => true
|
property :admin, :default => false, :protected => true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it { expect { WithProtected.new(nil) }.to_not raise_error }
|
||||||
|
|
||||||
it "should recognize protected properties" do
|
it "should recognize protected properties" do
|
||||||
props = WithProtected.protected_properties.map { |prop| prop.name}
|
props = WithProtected.protected_properties.map { |prop| prop.name}
|
||||||
props.should_not include("name")
|
props.should_not include("name")
|
||||||
|
@ -103,6 +107,7 @@ describe "Model Attributes" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect { WithBothAndUnspecified.new }.to_not raise_error }
|
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
|
it 'should assume that any unspecified property is protected by default' do
|
||||||
user = WithBothAndUnspecified.new(:name => 'will', :admin => true, :phone => '555-1234')
|
user = WithBothAndUnspecified.new(:name => 'will', :admin => true, :phone => '555-1234')
|
||||||
|
|
Loading…
Reference in a new issue