Sha256: 6cab3370005f6911809e3ae26815d6b86ee9ca4f30758e56b868d7219e4fd2cc

Contents?: true

Size: 1.06 KB

Versions: 15

Compression:

Stored size: 1.06 KB

Contents

require 'rails_helper'

# This is a controller mixin, but testing as a model spec!
RSpec.describe Journaled::Actor do
  let(:user) { double("User") }
  let(:klass) do
    Class.new do
      cattr_accessor :before_actions
      self.before_actions = []

      def self.before_action(&hook)
        before_actions << hook
      end

      include Journaled::Actor

      self.journaled_actor = :current_user

      def current_user
        nil
      end

      def trigger_before_actions
        before_actions.each { |proc| instance_eval(&proc) }
      end
    end
  end

  subject { klass.new }

  it "Stores a thunk returning nil if current_user returns nil" do
    subject.trigger_before_actions

    allow(subject).to receive(:current_user).and_return(nil)

    expect(RequestStore.store[:journaled_actor_proc].call).to eq nil
  end

  it "Stores a thunk returning current_user if it is set when called" do
    subject.trigger_before_actions

    allow(subject).to receive(:current_user).and_return(user)

    expect(RequestStore.store[:journaled_actor_proc].call).to eq user
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
journaled-4.0.0 spec/models/concerns/journaled/actor_spec.rb
journaled-3.1.0 spec/models/concerns/journaled/actor_spec.rb
journaled-3.0.0 spec/models/concerns/journaled/actor_spec.rb
journaled-2.5.0 spec/models/concerns/journaled/actor_spec.rb
journaled-2.4.0 spec/models/concerns/journaled/actor_spec.rb
journaled-2.3.1 spec/models/concerns/journaled/actor_spec.rb
journaled-2.3.0 spec/models/concerns/journaled/actor_spec.rb
journaled-2.2.0 spec/models/concerns/journaled/actor_spec.rb
journaled-2.1.1 spec/models/concerns/journaled/actor_spec.rb
journaled-2.1.0 spec/models/concerns/journaled/actor_spec.rb
journaled-2.0.3 spec/models/concerns/journaled/actor_spec.rb
journaled-2.0.2 spec/models/concerns/journaled/actor_spec.rb
journaled-2.0.1 spec/models/concerns/journaled/actor_spec.rb
journaled-2.0.0 spec/models/concerns/journaled/actor_spec.rb
journaled-2.0.0.rc1 spec/models/concerns/journaled/actor_spec.rb