1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

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 = klass.new
@instance.id = next_id @instance.id = next_id
@instance.instance_eval do @instance.instance_eval do
def persisted?
!new_record?
end
def new_record? def new_record?
id.nil? id.nil?
end end

View file

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