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:
parent
e552dc322e
commit
f33a64e0d1
2 changed files with 8 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue