Skip to content

Commit

Permalink
Feature flag for interview survey feature
Browse files Browse the repository at this point in the history
Because:
* We want to be able to turn on and off the feature.

This commit:
* Adds a feature flag for the interview survey feature.
* Adds a view, controller, and route for the feature.
* Adds 2 tests for the feature flag.
  • Loading branch information
JustWaveThings committed Jun 4, 2024
1 parent 70f4654 commit a9dd576
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 2 deletions.
12 changes: 12 additions & 0 deletions app/controllers/interview_surveys_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class InterviewSurveysController < ApplicationController
def new
unless Feature.enabled?(:survey_feature, current_user)
redirect_to dashboard_path, notice: 'Feature not enabled'
end
end

def create
# puts params[:survey]
redirect_to dashboard_path, notice: 'Survey Submitted'
end
end
11 changes: 11 additions & 0 deletions app/views/interview_surveys/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= title('Interview Survey') %>

<div>
<div class="page-container">
<h1 class="page-heading-title">Interview Survey</h1>

<div class='max-w-xl mx-auto'>
<%# where form will be rendered %>
</div>
</div>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@

resources :notifications, only: %i[index update]
resource :themes, only: :update
resources :interview_surveys, only: %i[new create]
end
18 changes: 18 additions & 0 deletions db/migrate/20240530151357_change_flipper_gates_value_to_text.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

class ChangeFlipperGatesValueToText < ActiveRecord::Migration[7.0]
def up
# Ensure this incremental update migration is idempotent
return unless connection.column_exists? :flipper_gates, :value, :string

if index_exists? :flipper_gates, %i[feature_key key value]
remove_index :flipper_gates, %i[feature_key key value]
end
change_column :flipper_gates, :value, :text
add_index :flipper_gates, %i[feature_key key value], unique: true, length: { value: 255 }
end

def down
change_column :flipper_gates, :value, :string
end
end
4 changes: 2 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions spec/system/interview_survey_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'rails_helper'

RSpec.describe 'Interview survey' do
let(:user) { create(:user) }

before do
sign_in(user)
end

context 'when the feature is enabled' do
before do
Flipper.enable(:survey_feature)
end

it 'shows the survey' do
visit new_interview_survey_path
expect(page).to have_content('Interview Survey')
end
end

context 'when the feature is disabled' do
it 'redirects to the dashboard' do
visit new_interview_survey_path
expect(page).to have_content('Feature not enabled')
expect(page).to have_current_path(dashboard_path)
end
end
end

0 comments on commit a9dd576

Please sign in to comment.