Sha256: 1d1b2aef9e516ca142ff9653971c29e2795cdc28437cdeb84986e95151580f6c

Contents?: true

Size: 991 Bytes

Versions: 12

Compression:

Stored size: 991 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module WardenTestHelpers
    include Warden::Test::Helpers

    #
    # Utility method to login in the middle of a test as a different user from
    # the current one.
    #
    def relogin_as(user, scope: :user)
      logout scope

      login_as user, scope: scope
    end
  end
end

RSpec.configure do |config|
  config.include Decidim::WardenTestHelpers, type: :system
  config.include Decidim::WardenTestHelpers, type: :request
  config.include Devise::Test::ControllerHelpers, type: :controller

  config.before :each, type: :cell do
    if controller
      allow(controller).to receive(:current_organization).and_return(try(:organization) || try(:current_organization) || nil)
      allow(controller).to receive(:current_user).and_return(try(:user) || try(:current_user) || nil)
    end
  end

  config.after :each, type: :system do
    Warden.test_reset!
  end

  config.after :each, type: :request do
    Warden.test_reset!
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-dev-0.27.9 lib/decidim/dev/test/rspec_support/warden.rb
decidim-dev-0.27.8 lib/decidim/dev/test/rspec_support/warden.rb
decidim-dev-0.27.7 lib/decidim/dev/test/rspec_support/warden.rb
decidim-dev-0.27.6 lib/decidim/dev/test/rspec_support/warden.rb
decidim-dev-0.27.5 lib/decidim/dev/test/rspec_support/warden.rb
decidim-dev-0.27.4 lib/decidim/dev/test/rspec_support/warden.rb
decidim-dev-0.27.3 lib/decidim/dev/test/rspec_support/warden.rb
decidim-dev-0.27.2 lib/decidim/dev/test/rspec_support/warden.rb
decidim-dev-0.27.1 lib/decidim/dev/test/rspec_support/warden.rb
decidim-dev-0.27.0 lib/decidim/dev/test/rspec_support/warden.rb
decidim-dev-0.27.0.rc2 lib/decidim/dev/test/rspec_support/warden.rb
decidim-dev-0.27.0.rc1 lib/decidim/dev/test/rspec_support/warden.rb