Sha256: b4a48eaca27eb58ba2f1e9eaa5a737adab87d28e453804eaf69856394deb6511

Contents?: true

Size: 1.43 KB

Versions: 5

Compression:

Stored size: 1.43 KB

Contents

require "spec_helper"

module AuditingSupportSpec
  class ExampleService < Shamu::Services::Service
    include Shamu::Auditing::Support

    public :audit_request
    public :with_request
  end

  class Change < Shamu::Services::Request
    attribute :name, presence: true
  end
end

describe Shamu::Auditing::Support do
  hunt( :service, Shamu::Auditing::AuditingService )

  let( :example_service ) { scorpion.new AuditingSupportSpec::ExampleService }
  let( :request )         { AuditingSupportSpec::Change.new name: "Penguin" }

  it "audits the request on success" do
    expect( service ).to receive( :commit )

    example_service.audit_request( request ) do |transaction|
    end
  end

  it "skips the request on failure" do
    expect( service ).not_to receive( :commit )
    request.name = nil

    example_service.audit_request( request ) do |transaction|
    end
  end

  it "intuits the audit type from the request class" do
    expect( service ).to receive( :commit ) do |transaction|
      expect( transaction.action ).to eq "change"
    end

    example_service.audit_request( request ) do |request|
    end
  end

  it "wraps with_request" do
    expect( service ).to receive( :commit )

    example_service.with_request( { name: "Example" }, AuditingSupportSpec::Change ) do |request, transaction|
      expect( request ).to be_a AuditingSupportSpec::Change
      expect( transaction ).to be_a Shamu::Auditing::Transaction
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
shamu-0.0.24 spec/lib/shamu/auditing/support_spec.rb
shamu-0.0.21 spec/lib/shamu/auditing/support_spec.rb
shamu-0.0.20 spec/lib/shamu/auditing/support_spec.rb
shamu-0.0.19 spec/lib/shamu/auditing/support_spec.rb
shamu-0.0.18 spec/lib/shamu/auditing/support_spec.rb