Module: RSpec::ActiveModel::Mocks::Mocks::ActiveRecordInstanceMethods
- Defined in:
- lib/rspec/active_model/mocks/mocks.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
(also: #_read_attribute)
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 Also known as: _read_attribute
Transforms the key to a method and calls it.
56 57 58 |
# File 'lib/rspec/active_model/mocks/mocks.rb', line 56 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.
71 72 73 74 |
# File 'lib/rspec/active_model/mocks/mocks.rb', line 71 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
.
50 51 52 53 |
# File 'lib/rspec/active_model/mocks/mocks.rb', line 50 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?
65 66 67 |
# File 'lib/rspec/active_model/mocks/mocks.rb', line 65 def new_record? !persisted? end |