Renaming Attribute Protection and solving problem modifying the provided hash to the #attributes= method

This commit is contained in:
Sam Lown 2010-10-22 15:39:12 +02:00
parent 1d1d815435
commit d0ed97ed8b
12 changed files with 65 additions and 112 deletions

View file

@ -62,20 +62,13 @@ describe CouchRest::Model::Base do
@default_model_key = 'model'
end
it "should set default configuration options on Model::Base" do
CouchRest::Model::Base.model_type_key.should eql(@default_model_key)
end
it "should provide options from instance" do
cat = Cat.new
cat.model_type_key.should eql(@default_model_key)
end
it "should be possible to override on class using configure method" do
default_model_key = Cat.model_type_key
Cat.instance_eval do
model_type_key 'cat-type'
end
CouchRest::Model::Base.model_type_key.should eql(@default_model_key)
CouchRest::Model::Base.model_type_key.should eql(default_model_key)
Cat.model_type_key.should eql('cat-type')
cat = Cat.new
cat.model_type_key.should eql('cat-type')

View file

@ -34,6 +34,12 @@ describe "Model Attributes" do
user.name.should == "will"
user.phone.should == "555-5555"
end
it "should provide a list of all properties as accessible" do
user = NoProtection.new(:name => "will", :phone => "555-5555")
user.accessible_properties.length.should eql(2)
user.protected_properties.should be_empty
end
end
describe "Model Base", "accessible flag" do
@ -65,6 +71,12 @@ describe "Model Attributes" do
user.name.should == "will"
user.admin.should == false
end
it "should provide correct accessible and protected property lists" do
user = WithAccessible.new(:name => 'will', :admin => true)
user.accessible_properties.map{|p| p.to_s}.should eql(['name'])
user.protected_properties.map{|p| p.to_s}.should eql(['admin'])
end
end
describe "Model Base", "protected flag" do
@ -96,6 +108,21 @@ describe "Model Attributes" do
user.name.should == "will"
user.admin.should == false
end
it "should not modify the provided attribute hash" do
user = WithProtected.new
attrs = {:name => "will", :admin => true}
user.attributes = attrs
attrs[:admin].should be_true
attrs[:name].should eql('will')
end
it "should provide correct accessible and protected property lists" do
user = WithProtected.new(:name => 'will', :admin => true)
user.accessible_properties.map{|p| p.to_s}.should eql(['name'])
user.protected_properties.map{|p| p.to_s}.should eql(['admin'])
end
end
describe "Model Base", "mixing protected and accessible flags" do
@ -115,6 +142,7 @@ describe "Model Attributes" do
user.admin.should == false
user.phone.should == 'unset phone number'
end
end
describe "from database" do

View file

@ -93,7 +93,7 @@ describe "Subclassing a Model" do
end
it "should have an all view with a guard clause for model == subclass name in the map function" do
OnlineCourse.design_doc['views']['all']['map'].should =~ /if \(doc\['model'\] == 'OnlineCourse'\)/
OnlineCourse.design_doc['views']['all']['map'].should =~ /if \(doc\['#{OnlineCourse.model_type_key}'\] == 'OnlineCourse'\)/
end
end