Class: ModelTimeline::RSpec::Matchers::HaveTimelineChange Private

Inherits:
Object
  • Object
show all
Defined in:
lib/model_timeline/rspec/matchers.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

RSpec matcher to check if a model has timeline entries with changes to a specific attribute

Instance Method Summary collapse

Constructor Details

#initialize(attribute, association_name) ⇒ HaveTimelineChange

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize the matcher

Parameters:

  • attribute (String, Symbol)

    The attribute to check for changes



184
185
186
187
# File 'lib/model_timeline/rspec/matchers.rb', line 184

def initialize(attribute, association_name)
  @attribute = attribute.to_s
  @association_name = association_name
end

Instance Method Details

#failure_messageString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Message displayed when the expectation fails

Returns:

  • (String)

    A descriptive failure message



201
202
203
# File 'lib/model_timeline/rspec/matchers.rb', line 201

def failure_message
  "expected #{@subject} to have tracked changes to '#{@attribute}', but none was found"
end

#failure_message_when_negatedString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Message displayed when the negated expectation fails

Returns:

  • (String)

    A descriptive failure message for negated expectations



208
209
210
# File 'lib/model_timeline/rspec/matchers.rb', line 208

def failure_message_when_negated
  "expected #{@subject} not to have tracked changes to '#{@attribute}', but changes were found"
end

#matches?(subject) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if the subject matches the expectations

Parameters:

  • subject (Object)

    The model to check for timeline entries

Returns:

  • (Boolean)

    True if the model has timeline entries with changes to the specified attribute



193
194
195
196
# File 'lib/model_timeline/rspec/matchers.rb', line 193

def matches?(subject)
  @subject = subject
  @subject.public_send(@association_name).with_changed_attribute(@attribute).exists?
end