Class: ElabsMatchers::Matchers::Persist::PersistMatcher

Inherits:
Struct
  • Object
show all
Defined in:
lib/elabs_matchers/matchers/persist.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) attribute

Returns the value of attribute attribute

Returns:

  • (Object)

    the current value of attribute



6
7
8
# File 'lib/elabs_matchers/matchers/persist.rb', line 6

def attribute
  @attribute
end

- (Object) record (readonly)

Returns the value of attribute record



7
8
9
# File 'lib/elabs_matchers/matchers/persist.rb', line 7

def record
  @record
end

- (Object) value

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



6
7
8
# File 'lib/elabs_matchers/matchers/persist.rb', line 6

def value
  @value
end

Instance Method Details

- (Object) failure_message_for_should



18
19
20
# File 'lib/elabs_matchers/matchers/persist.rb', line 18

def failure_message_for_should
  "Expected #{attribute} to be persisted and retain its value of #{value.inspect} but the value was #{@final_value.inspect}."
end

- (Object) failure_message_for_should_not



22
23
24
# File 'lib/elabs_matchers/matchers/persist.rb', line 22

def failure_message_for_should_not
  "Expected #{attribute} not to be persisted and retain its value of #{value.inspect} but it did."
end

- (Boolean) matches?(record)

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
# File 'lib/elabs_matchers/matchers/persist.rb', line 9

def matches?(record)
  record.send(:#{attribute}=", value)
  record.save!
  record = record.class.find(record.id)
  @final_value = record.send(attribute)

  @final_value == value
end