Class: FlexMock::Extensions::ActiveRecordModel
- Defined in:
- lib/flexmock/extensions/active_record_model.rb
Instance Method Summary collapse
-
#create(container, opts) ⇒ Object
Create the test double.
-
#handle(args, opts) ⇒ Object
Handle the argument list.
-
#post_create(opts, location) ⇒ Object
Do any post-creation setup on the mock object.
Instance Method Details
#create(container, opts) ⇒ Object
Create the test double.
Create the custome test double according to the data from the argument list. The object returned from this method is the object returned from the original flexmock() method call. This the returned object is NOT the actual mock object (which is the case for things like partial proxies), then the opts.mock field should be set to contain the actual mock object.
31 32 33 34 |
# File 'lib/flexmock/extensions/active_record_model.rb', line 31 def create(container, opts) id = next_id FlexMock.new("#{opts.data[:model_class]}_#{id}", container) end |
#handle(args, opts) ⇒ Object
Handle the argument list.
This method is called whenever an unrecognized symbol is detected in the flexmock argument list. If the extension class can handle it, it should return true.
Extension data can be stored in the opts.data hash for later use during the create and post_create phase.
15 16 17 18 19 20 21 |
# File 'lib/flexmock/extensions/active_record_model.rb', line 15 def handle(args, opts) return false unless args.first == :model args.shift opts.data[:model_class] = args.shift opts.extended = self true end |
#post_create(opts, location) ⇒ Object
Do any post-creation setup on the mock object.
37 38 39 |
# File 'lib/flexmock/extensions/active_record_model.rb', line 37 def post_create(opts, location) add_model_methods(opts.mock, opts.data[:model_class], location) end |