Class: RailsAuditLog::Graphql::Testing::RSpecMatchers::HaveGraphqlAuditEntry Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_audit_log/graphql/testing/rspec_matchers.rb

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.

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ HaveGraphqlAuditEntry

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.

Returns a new instance of HaveGraphqlAuditEntry.

Parameters:

  • event (String)

    the required event value



48
49
50
51
52
# File 'lib/rails_audit_log/graphql/testing/rspec_matchers.rb', line 48

def initialize(event)
  @event = event
  @touching = nil
  @item_type = nil
end

Instance Method Details

#failure_messageObject

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.



85
86
87
88
89
# File 'lib/rails_audit_log/graphql/testing/rspec_matchers.rb', line 85

def failure_message
  "expected GraphQL response to include an audit entry with event #{@event.inspect}" \
    "#{touching_clause}#{type_clause}, but it did not.\n" \
    "Entries found: #{extract_entries(@response).map { |e| e["event"] }.inspect}"
end

#failure_message_when_negatedObject

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.



92
93
94
95
# File 'lib/rails_audit_log/graphql/testing/rspec_matchers.rb', line 92

def failure_message_when_negated
  "expected GraphQL response not to include an audit entry with event #{@event.inspect}" \
    "#{touching_clause}#{type_clause}, but one was found."
end

#for_type(item_type) ⇒ self

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.

Requires all matching entries to have itemType equal to item_type.

Parameters:

  • item_type (String)

    the ActiveRecord model class name

Returns:

  • (self)


68
69
70
71
# File 'lib/rails_audit_log/graphql/testing/rspec_matchers.rb', line 68

def for_type(item_type)
  @item_type = item_type.to_s
  self
end

#matches?(response) ⇒ 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.

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
# File 'lib/rails_audit_log/graphql/testing/rspec_matchers.rb', line 74

def matches?(response)
  @response = response
  matched = extract_entries(response).select { |e| e["event"] == @event }
  matched = matched.select { |e| e["itemType"] == @item_type } if @item_type
  if @touching
    matched = matched.select { |e| e["diff"]&.any? { |d| d["attribute"] == @touching } }
  end
  matched.any?
end

#touching(attribute) ⇒ self

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.

Requires at least one matching entry’s diff to contain attribute. The query must include diff { attribute } for this chain to work.

Parameters:

  • attribute (Symbol, String)

    the changed attribute name

Returns:

  • (self)


59
60
61
62
# File 'lib/rails_audit_log/graphql/testing/rspec_matchers.rb', line 59

def touching(attribute)
  @touching = attribute.to_s
  self
end