Quantcast
Channel: Active questions tagged redis+ruby-on-rails - Stack Overflow
Viewing all articles
Browse latest Browse all 873

Better way to rspec test SideKiq GUI

$
0
0

My sidekiq gui needs to authenticate a user for admin rights before allowing access.

Is there a way to password protect and test the sidekiq gui controller directly? Instead of a feature test and instead of needing redis or mock redis?

Routes

  if Rails.env.development?    mount Sidekiq::Web, at: :sidekiq  else    # https://stackoverflow.com/questions/12265421/how-can-i-password-protect-my-sidekiq-route-i-e-require-authentication-for-th    authenticate :user, ->(u) { u.admin? } do      mount Sidekiq::Web => "/sidekiq"    end  end

RSPEC

# frozen_string_literal: truerequire "rails_helper"RSpec.describe "Sidekiq::Web", type: :feature do  context "with admin user" do    let(:user) { create(:user, :admin) }    before { sign_in(user) }    specify "can able to access sidekiq GUI" do      visit sidekiq_web_path      within "div#navbar-menu" do        expect(page).to have_link("Dashboard")      end    end  end  context "with normal user" do    let(:user) { create(:user) }    before { sign_in(user) }    it "can not able to access sidekiq GUI" do      expect {        visit(sidekiq_web_path)        expect(page).to have_link("Dashboard")      }.to raise_error(ActionController::RoutingError)    end  endend

Test Results:

Failures:  1) Sidekiq::Web with admin user can able to access sidekiq GUI     Failure/Error: raise CannotConnectError, "Error connecting to Redis on #{location} (#{error.class})"     Redis::CannotConnectError:       Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)     # /app/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:362:in `rescue in establish_connection'     # /app/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:343:in `establish_connection'     # /app/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:107:in `block in connect'

Viewing all articles
Browse latest Browse all 873

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>