Module: RailsAuditLog::Graphql::Testing::RSpecMatchers

Defined in:
lib/rails_audit_log/graphql/testing/rspec_matchers.rb

Overview

RSpec matchers for asserting GraphQL audit log entries in a query response.

Include this module in your RSpec configuration to use the #have_graphql_audit_entry matcher:

RSpec.configure do |config|
  config.include RailsAuditLog::Graphql::Testing::RSpecMatchers
end

Or include it in a single example group:

RSpec.describe "audit logging" do
  include RailsAuditLog::Graphql::Testing::RSpecMatchers
end

The matcher inspects the auditLogEntries and auditLogEntriesConnection.nodes keys in the response data. To use the touching chain, include diff { attribute } in your GraphQL query.

Defined Under Namespace

Classes: HaveGraphqlAuditEntry

Instance Method Summary collapse

Instance Method Details

#have_graphql_audit_entry(event) ⇒ HaveGraphqlAuditEntry

Returns a matcher that asserts a GraphQL response contains an audit log entry with the given event type.

Examples:

Assert an update entry exists

result = MySchema.execute('{ auditLogEntries { event } }')
expect(result).to have_graphql_audit_entry(:update)

Assert an update entry that touched :title

result = MySchema.execute('{ auditLogEntries { event diff { attribute } } }')
expect(result).to have_graphql_audit_entry(:update).touching(:title)

Assert a create entry for a specific model

expect(result).to have_graphql_audit_entry(:create).for_type("Post")

Parameters:

  • event (Symbol, String)

    expected event type (:create, :update, :destroy)

Returns:



41
42
43
# File 'lib/rails_audit_log/graphql/testing/rspec_matchers.rb', line 41

def have_graphql_audit_entry(event)
  HaveGraphqlAuditEntry.new(event.to_s)
end