Testing model name

This commit is contained in:
Sam Lown 2010-06-21 14:13:19 +02:00
parent 188fd0d4de
commit d138ebc05f
2 changed files with 15 additions and 5 deletions

View file

@ -99,10 +99,13 @@ module CouchRest
!new? !new?
end end
def to_key
new? ? nil : [id]
end
alias :to_param :id
alias :new_record? :new? alias :new_record? :new?
alias :new_document? :new? alias :new_document? :new?
alias :to_key :id
alias :to_param :id
end end
end end
end end

View file

@ -40,7 +40,7 @@ describe "Model Base" do
end end
end end
describe "ActiveModel compatability" do describe "ActiveModel compatability Basic" do
before(:each) do before(:each) do
@obj = Basic.new(nil) @obj = Basic.new(nil)
@ -54,9 +54,9 @@ describe "Model Base" do
end end
context "when the document is not new" do context "when the document is not new" do
it "returns id" do it "returns id in an array" do
@obj.save @obj.save
@obj.to_key.should eql(@obj['_id']) @obj.to_key.should eql([@obj['_id']])
end end
end end
end end
@ -91,6 +91,13 @@ describe "Model Base" do
end end
end end
describe "#model_name" do
it "returns the name of the model" do
@obj.class.model_name.should eql('Basic')
WithDefaultValues.model_name.human.should eql("With default values")
end
end
end end