Skip to content

Commit

Permalink
a minor change to inform the user what model and method violated the …
Browse files Browse the repository at this point in the history
…stub
  • Loading branch information
fearoffish authored and joshuaclayton committed Apr 19, 2014
1 parent 1af660f commit b97b36a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/factory_girl/strategy/stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@ def new_record?
end

def save(*args)
raise 'stubbed models are not allowed to access the database'
raise "stubbed models are not allowed to access the database - #{self.class.to_s}#save(#{args.join(",")})"
end

def destroy(*args)
raise 'stubbed models are not allowed to access the database'
raise "stubbed models are not allowed to access the database - #{self.class.to_s}#destroy(#{args.join(",")})"
end

def connection
raise 'stubbed models are not allowed to access the database'
raise "stubbed models are not allowed to access the database - #{self.class.to_s}#connection()"
end

def reload
raise 'stubbed models are not allowed to access the database'
raise "stubbed models are not allowed to access the database - #{self.class.to_s}#reload()"
end

def update_attribute(*args)
raise 'stubbed models are not allowed to access the database'
raise "stubbed models are not allowed to access the database - #{self.class.to_s}#update_attribute(#{args.join(",")})"
end

def update_column(*args)
raise 'stubbed models are not allowed to access the database'
raise "stubbed models are not allowed to access the database - #{self.class.to_s}#update_column(#{args.join(",")})"
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/factory_girl/strategy/stub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
expect(subject.result(evaluation).created_at).to eq created_at
end

[:save, :destroy, :connection, :reload, :update_attribute].each do |database_method|
[:save, :destroy, :connection, :reload, :update_attribute, :update_column].each do |database_method|
it "raises when attempting to connect to the database by calling #{database_method}" do
expect do
subject.result(evaluation).send(database_method)
end.to raise_error(RuntimeError, "stubbed models are not allowed to access the database")
end.to raise_error(RuntimeError, "stubbed models are not allowed to access the database - #{subject.result(evaluation).class}##{database_method}()")
end
end
end
Expand Down

0 comments on commit b97b36a

Please sign in to comment.