Sha256: 0248ec2d24d58c1703269bcb75c78a87b2819ade7c9b9049d9ee8349b6e91036

Contents?: true

Size: 1.32 KB

Versions: 14

Compression:

Stored size: 1.32 KB

Contents

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.enabled_for_controller = true
    ::PaperTrail.whodunnit = nil
    ::PaperTrail.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

14 entries across 14 versions & 2 rubygems

Version Path
paper_trail-8.1.2 lib/paper_trail/frameworks/rspec.rb
paper_trail-8.1.1 lib/paper_trail/frameworks/rspec.rb
paper_trail-8.1.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-8.0.1 lib/paper_trail/frameworks/rspec.rb
paper_trail-8.0.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-7.1.3 lib/paper_trail/frameworks/rspec.rb
paper_trail-7.1.2 lib/paper_trail/frameworks/rspec.rb
paper_trail-7.1.1 lib/paper_trail/frameworks/rspec.rb
paper_trail-7.1.0 lib/paper_trail/frameworks/rspec.rb
paper_trail-7.0.3 lib/paper_trail/frameworks/rspec.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/paper_trail-7.0.2/lib/paper_trail/frameworks/rspec.rb
paper_trail-7.0.2 lib/paper_trail/frameworks/rspec.rb
paper_trail-7.0.1 lib/paper_trail/frameworks/rspec.rb
paper_trail-7.0.0 lib/paper_trail/frameworks/rspec.rb