Adds a #persisted? method to the Stub object to conform to the

ActiveModel API

Closes #145
This commit is contained in:
Joshua Clayton 2011-06-27 16:44:37 -04:00
parent e552dc322e
commit f33a64e0d1
2 changed files with 8 additions and 0 deletions

View File

@ -7,6 +7,10 @@ module FactoryGirl
@instance = klass.new
@instance.id = next_id
@instance.instance_eval do
def persisted?
!new_record?
end
def new_record?
id.nil?
end

View File

@ -16,6 +16,10 @@ describe FactoryGirl::Proxy::Stub do
@stub.result(nil).should_not be_new_record
end
it "should be persisted" do
@stub.result(nil).should be_persisted
end
it "should not be able to connect to the database" do
lambda { @stub.result(nil).reload }.should raise_error(RuntimeError)
end