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

@ -98,11 +98,14 @@ module CouchRest
def persisted?
!new?
end
def to_key
new? ? nil : [id]
end
alias :to_param :id
alias :new_record? :new?
alias :new_document? :new?
alias :to_key :id
alias :to_param :id
end
end
end

View file

@ -40,7 +40,7 @@ describe "Model Base" do
end
end
describe "ActiveModel compatability" do
describe "ActiveModel compatability Basic" do
before(:each) do
@obj = Basic.new(nil)
@ -54,9 +54,9 @@ describe "Model Base" do
end
context "when the document is not new" do
it "returns id" do
it "returns id in an array" do
@obj.save
@obj.to_key.should eql(@obj['_id'])
@obj.to_key.should eql([@obj['_id']])
end
end
end
@ -91,6 +91,13 @@ describe "Model Base" do
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