Skip to content

Commit

Permalink
Renamed contexts and added additional test
Browse files Browse the repository at this point in the history
  • Loading branch information
SleekMutt committed Nov 28, 2024
1 parent cfafd9b commit d166852
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion spec/features/account/calculators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let!(:napkin_calculator) { create(:calculator, en_name: "Napkin Calculator") }

include_context :authorize_admin
include_context :show_constructor
include_context :enable_calculators_constructor

it "visits admin page" do
visit account_calculators_path
Expand Down
2 changes: 1 addition & 1 deletion spec/features/show_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
describe "GET #show" do
let(:calculator) { create(:calculator) }

include_context :show_constructor
include_context :enable_calculators_constructor

before do
allow(controller).to receive(:resource).and_return(calculator)
Expand Down
2 changes: 1 addition & 1 deletion spec/features/visit_login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:user) { create(:user) }
let(:calculator) { create(:calculator) }

include_context :show_constructor
include_context :enable_calculators_constructor

it "when sign in with correct login and password" do
allow_any_instance_of(ApplicationController)
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/account/calculators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe "Account::CalculatorsController", type: :request do
include_context :authorize_admin
include_context :show_constructor
include_context :enable_calculators_constructor

let!(:calculator) { create(:calculator) }

Expand All @@ -25,7 +25,7 @@

describe "GET #index" do
context "when flipper is turned off" do
include_context :hide_constructor
include_context :disable_calculators_constructor

it "raises routing error" do
expect { get account_calculators_path }.to raise_error(ActionController::RoutingError)
Expand Down
13 changes: 12 additions & 1 deletion spec/requests/calculators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
RSpec.describe CalculatorsController, type: :request do
let(:calculator) { create(:calculator) }

include_context :show_constructor
include_context :enable_calculators_constructor

describe "GET #index" do
context "when show_calculators_list feature is enabled" do
include_context :show_calculators_list
before(:example, :disabled_constructor) do
include_context :disable_calculators_constructor
end

it "renders the calculators index when show_calculators_list is enabled" do
get calculators_path
Expand All @@ -18,6 +21,14 @@
expect(response).to render_template(:index)
expect(assigns(:calculators)).not_to be_nil
end

context 'and constructor flipper is disabled' do
include_context :disable_calculators_constructor

it 'raises routing error' do
expect { get calculators_path }.to raise_error(ActionController::RoutingError)
end
end
end

context "when show_calculators_list feature is disabled" do
Expand Down
4 changes: 2 additions & 2 deletions spec/support/shared/context/feature_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
end
end

RSpec.shared_context :show_constructor do
RSpec.shared_context :enable_calculators_constructor do
before do
FeatureFlag.find_or_create_by!(name: "constructor_status")
Flipper.enable(:constructor_status)
end
end

RSpec.shared_context :hide_constructor do
RSpec.shared_context :disable_calculators_constructor do
before do
FeatureFlag.find_or_create_by!(name: "constructor_status")
Flipper.disable(:constructor_status)
Expand Down

0 comments on commit d166852

Please sign in to comment.