Skip to content

Commit

Permalink
Added flipper, so admin could enable or disable mhc calculator (#969)
Browse files Browse the repository at this point in the history
* Added flipper, so admin could enable or disable mhc calculator
  • Loading branch information
SleekMutt authored Nov 24, 2024
1 parent f73b6d8 commit a6b2208
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
7 changes: 7 additions & 0 deletions app/controllers/calculators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class CalculatorsController < ApplicationController
before_action :authenticate_user!, only: :receive_recomendations
before_action :check_mhc_flipper, only: :mhc_calculator

def index
if Flipper[:show_calculators_list].enabled?
Expand Down Expand Up @@ -52,4 +53,10 @@ def collection
def resource
collection.friendly.find(params[:slug])
end

def check_mhc_flipper
return if Flipper[:mhc_calculator_status].enabled?

raise ActionController::RoutingError, "Mhc calculator flipper is disabled"
end
end
5 changes: 5 additions & 0 deletions app/views/account/shared/_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<%= link_to t("layouts.navigation.calculate"), calculator_path, class: "tab-main-page" %>
<% end %>
</li>
<li>
<% if Flipper[:mhc_calculator_status].enabled? %>
<%= link_to t("layouts.navigation.mhc_calculator"), mhc_calculator_path, class: "tab-main-page" %>
<% end %>
</li>
<li>
<%= link_to t("layouts.navigation.about_us"), about_path, class: "tab-main-page" %>
</li>
Expand Down
3 changes: 3 additions & 0 deletions config/initializers/flipper/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@

Flipper[:sandbox_mode].en_description = "This feature flag is responsible for enabling sandbox mode"
Flipper[:sandbox_mode].uk_description = "Відкриває можливість використовувати режим пісочниці"

Flipper[:mhc_calculator_status].en_description = "This feature flag is responsible for enabling mhc calculator"
Flipper[:mhc_calculator_status].uk_description = "Відкриває можливість використовувати калькулятор продуктів жіночої гігієни"
end
3 changes: 3 additions & 0 deletions config/locales/en/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ en:
about_us: "About us"
admin: "Admin"
calculate: "Diaper calculator"
mhc_calculator: "Pad calculator"
log_out: "Log Out"
sign_up: "Sign Up"
log_in: "Log In"
Expand Down Expand Up @@ -480,6 +481,8 @@ en:
name: "Show calculators on the public side"
sandbox_mode:
name: "Enable sandbox mode"
mhc_calculator_status:
name: "Enable mhc calculator"
sessions:
new:
log_in_header: "Log In"
Expand Down
3 changes: 3 additions & 0 deletions config/locales/uk/uk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ uk:
admin: "Адміністратор"
calculate: "Калькулятор підгузків"
log_out: "Вийти"
mhc_calculator: "Калькулятор прокладок"
sign_up: "Зареєструватися"
log_in: "Увійти"
contact_us: "Зв'яжіться з нами"
Expand Down Expand Up @@ -440,6 +441,8 @@ uk:
name: "Показати калькулятори користувачам"
sandbox_mode:
name: "Увімкнути режим пісочниці"
mhc_calculator_status:
name: "Увімкнути калькулятор продуктів жіночої гігієни"
sessions:
new:
log_in_header: "Увійти"
Expand Down
21 changes: 16 additions & 5 deletions spec/requests/calculators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,23 @@
end

describe "GET /mhc_calculator" do
it "renders pad calculator" do
get mhc_calculator_path
context "mhc calculator is enabled" do
include_context :mhc_calculator_enabled

expect(response).to be_successful
expect(response).to render_template(:mhc_calculator)
expect(response.body).to include("results")
it "renders pad calculator" do
get mhc_calculator_path

expect(response).to be_successful
expect(response).to render_template(:mhc_calculator)
end
end

context "mhc calculator is disabled" do
include_context :mhc_calculator_disabled

it "renders pad calculator" do
expect { get mhc_calculator_path }.to raise_error(ActionController::RoutingError)
end
end
end

Expand Down
14 changes: 14 additions & 0 deletions spec/support/shared/context/feature_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,19 @@ def sandbox_mode_context(mode)
end
end

RSpec.shared_context :mhc_calculator_enabled do
before do
FeatureFlag.find_or_create_by!(name: "show_calculators_list")
Flipper.enable(:mhc_calculator_status)
end
end

RSpec.shared_context :mhc_calculator_disabled do
before do
FeatureFlag.find_or_create_by!(name: "show_calculators_list")
Flipper.disable(:mhc_calculator_status)
end
end

sandbox_mode_context(:enable)
sandbox_mode_context(:disable)

0 comments on commit a6b2208

Please sign in to comment.