Sha256: 195344d70324c46bab573d5f5b19f83882581967ecf757e93eea8de95ff8403f

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

require "spec_helper"
require "ostruct"

describe ApplicationController, type: :controller do
  controller do
  end

  before(:each) do
    @mock_warden = OpenStruct.new
    @controller.request.env["warden"] = @mock_warden
  end

  it "should create an anonymous user for a guest" do
    allow(@mock_warden).to receive(:authenticate).with(anything).and_return(false)

    expect(@controller.current_or_guest_user.email).to match(/guest/)
  end

  it "should use the current user when available" do
    m = double
    allow(@mock_warden).to receive(:authenticate).with(anything).and_return(m)

    expect(@controller.current_or_guest_user).to eq(m)
  end

  it "should run the 'logging_in' callbacks" do
    # A user is logged in
    current_user = double
    allow(@controller).to receive(:current_user) { current_user }

    # There is a guest user instance
    guest_user = double
    allow(guest_user).to receive(:destroy)
    allow(@controller).to receive(:guest_user) { guest_user }
    allow(@controller).to receive(:session) { {guest_user_id: 123} }

    expect(@controller).to receive(:run_callbacks).with(:logging_in_user).and_call_original
    expect(@controller).to receive(:transfer_guest_to_user).and_call_original

    @controller.current_or_guest_user
  end

  it "should define a 'logging_in' callback" do
    expect(@controller).to respond_to(:_logging_in_user_callbacks)
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/devise-guests-0.8.3/spec/controllers/application_controller_spec.rb
devise-guests-0.8.3 spec/controllers/application_controller_spec.rb
devise-guests-0.8.2 spec/controllers/application_controller_spec.rb
devise-guests-0.8.1 spec/controllers/application_controller_spec.rb