Sha256: 3a1106cb3afe31d2a7fd442cd0d117fa2a217846af96f9a08ffb31433052cfe4

Contents?: true

Size: 1.36 KB

Versions: 26

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require "rspec/core"
require "rspec/matchers"
require "paper_trail/frameworks/rspec/helpers"

RSpec.configure do |config|
  config.include ::PaperTrail::RSpec::Helpers::InstanceMethods
  config.extend ::PaperTrail::RSpec::Helpers::ClassMethods

  config.before(:each) do
    ::PaperTrail.enabled = false
    ::PaperTrail.request.enabled = true
    ::PaperTrail.request.whodunnit = nil
    ::PaperTrail.request.controller_info = {} if defined?(::Rails) && defined?(::RSpec::Rails)
  end

  config.before(:each, versioning: true) do
    ::PaperTrail.enabled = true
  end
end

RSpec::Matchers.define :be_versioned do
  # check to see if the model has `has_paper_trail` declared on it
  match { |actual| actual.is_a?(::PaperTrail::Model::InstanceMethods) }
end

RSpec::Matchers.define :have_a_version_with do |attributes|
  # check if the model has a version with the specified attributes
  match do |actual|
    versions_association = actual.class.versions_association_name
    actual.send(versions_association).where_object(attributes).any?
  end
end

RSpec::Matchers.define :have_a_version_with_changes do |attributes|
  # check if the model has a version changes with the specified attributes
  match do |actual|
    versions_association = actual.class.versions_association_name
    actual.send(versions_association).where_object_changes(attributes).any?
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
paper_trail-16.0.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-15.2.0 lib/paper_trail/frameworks/rspec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/paper_trail-12.3.0/lib/paper_trail/frameworks/rspec.rb
paper_trail-15.1.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-15.0.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-14.0.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-13.0.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-12.3.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-12.2.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-12.1.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-12.0.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-11.1.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-11.0.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-10.3.1 lib/paper_trail/frameworks/rspec.rb
paper_trail-10.3.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-10.2.1 lib/paper_trail/frameworks/rspec.rb
paper_trail-10.2.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-10.1.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-10.0.1 lib/paper_trail/frameworks/rspec.rb
paper_trail-10.0.0 lib/paper_trail/frameworks/rspec.rb