1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/lib/factory_girl/strategy
Simon Coffey fd3bf889f8
Stub strategy disables all persistence instance methods
Previously, instances created with the Stub strategy disabled a number of
methods defined by ActiveRecord::Persistence, to ensure that stubbed instances
did not read or write to the database. However, this blacklist was incomplete,
allowing some methods (e.g. #save!) to be called on stub instances.

This expands the blacklist to disable all methods defined by
ActiveRecord::Persistence that are not explicitly defined on stub instances
(currently #new_record?, #persisted?), or do not talk to the database at all
(#becomes, #becomes!).

The blacklist is correct as of current Rails master (the pre-release for Rails
5.0). It also, as a result, includes a couple of methods that are not defined
by ActiveRecord::Persistence in earlier versions of Rails, and will not
automatically include methods added to this module in future versions of
Rails.

It would be possible to make this automatic using reflection, and instead
using a whitelist of allowed methods:

    ActiveRecord::Persistence.public_instance_methods

However, at present this test is not dependent on ActiveRecord, so I have left
this for future work if desired.
2016-07-19 05:20:26 -04:00
..
attributes_for.rb Don't refer to strategies by class anywhere 2012-04-25 15:03:10 -05:00
build.rb Refactor Strategies 2012-04-13 17:20:02 -04:00
create.rb Refactor Strategies 2012-04-13 17:20:02 -04:00
null.rb Refactor Strategies 2012-04-13 17:20:02 -04:00
stub.rb Stub strategy disables all persistence instance methods 2016-07-19 05:20:26 -04:00