Module: RSpec::Rails::Mocks::ActiveRecordInstanceMethods
- Defined in:
- lib/rspec/rails/mocks.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
Transforms the key to a method and calls it.
-
#association(association_name) ⇒ Object
Returns an object representing an association from the mocked model's perspective.
-
#destroy ⇒ Object
Stubs
persisted?
to returnfalse
andid
to returnnil
. -
#new_record? ⇒ Boolean
Returns the opposite of
persisted?
.
Instance Method Details
#[](key) ⇒ Object
Transforms the key to a method and calls it.
55 56 57 |
# File 'lib/rspec/rails/mocks.rb', line 55 def [](key) send(key) end |
#association(association_name) ⇒ Object
Returns an object representing an association from the mocked model's perspective. For use by Rails internally only.
66 67 68 69 |
# File 'lib/rspec/rails/mocks.rb', line 66 def association(association_name) @associations ||= Hash.new { |h, k| h[k] = Association.new(k) } @associations[association_name] end |
#destroy ⇒ Object
Stubs persisted?
to return false
and id
to return nil
.
49 50 51 52 |
# File 'lib/rspec/rails/mocks.rb', line 49 def destroy RSpec::Mocks.(self, :persisted?).and_return(false) RSpec::Mocks.(self, :id).and_return(nil) end |
#new_record? ⇒ Boolean
Returns the opposite of persisted?
60 61 62 |
# File 'lib/rspec/rails/mocks.rb', line 60 def new_record? !persisted? end |