Sha256: 3ee6dcf49e5c374486cbe486073e8907dd8506e855bd52285f3d973df95ca318

Contents?: true

Size: 968 Bytes

Versions: 6

Compression:

Stored size: 968 Bytes

Contents

# frozen_string_literal: true

feature "securing dashboard access", js: true, type: :feature do
  before do
    dashboard_auth_lambda = -> { redirect_to("/") unless current_user.admin? }
    Sail::SettingsController.before_action(*dashboard_auth_lambda)

    Sail::Setting.create!(name: "setting", cast_type: :string,
                          value: :something,
                          description: "Setting that does something",
                          group: "feature_flags")
  end

  context "when user is admin" do
    it "can navigate to Sail" do
      visit "/sail"
      expect(page).to have_text("Setting")
    end
  end

  context "when user is not admin" do
    it "is redirect to root path" do
      user = User.new

      def user.admin?
        false
      end

      allow_any_instance_of(Sail::SettingsController).to receive(:current_user).and_return(user)

      visit "/sail"
      expect(page).to have_text("Inside dummy app")
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sail-3.2.0 spec/features/securing_dashboard_access_feature_spec.rb
sail-3.1.0 spec/features/securing_dashboard_access_feature_spec.rb
sail-3.0.1 spec/features/securing_dashboard_access_feature_spec.rb
sail-3.0.0 spec/features/securing_dashboard_access_feature_spec.rb
sail-2.1.1 spec/features/securing_dashboard_access_feature_spec.rb
sail-2.1.0 spec/features/securing_dashboard_access_feature_spec.rb