Module: RSpec::Rails::Mocks::ActiveModelInstanceMethods

Defined in:
lib/rspec/rails/mocks.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) as_new_record

Stubs persisted? to return false and id to return nil

Returns:

  • self

16
17
18
19
20
# File 'lib/rspec/rails/mocks.rb', line 16
def as_new_record
  RSpec::Mocks.allow_message(self, :persisted?).and_return(false)
  RSpec::Mocks.allow_message(self, :id).and_return(nil)
  self
end

- (Boolean) persisted?

Returns true by default. Override with a stub.

Returns:

  • (Boolean)
23
24
25
# File 'lib/rspec/rails/mocks.rb', line 23
def persisted?
  true
end

- (Boolean) respond_to?(message, include_private = false)

Returns false for names matching /_before_type_cast$/, otherwise delegates to super.

Returns:

  • (Boolean)
29
30
31
# File 'lib/rspec/rails/mocks.rb', line 29
def respond_to?(message, include_private=false)
  message.to_s =~ /_before_type_cast$/ ? false : super
end