Skip to content

Commit

Permalink
Feature/mvp interview survey (#4549)
Browse files Browse the repository at this point in the history
## Because
<!-- Summarize the purpose or reasons for this PR, e.g. what problem it
solves or what benefit it provides. -->
- We need a feature flag to hide the interview survey feature behind. 

## This PR
<!-- A bullet point list of one or more items describing the specific
changes. -->
- Creates route, controller, view, and updates flipper gates
- Adds feature flag check to controller
- System test coverage for feature flag behavior to ensure no one can
access the feature if it is disabled

## Issue
<!--
If this PR closes an open issue in this repo, replace the XXXXX below
with the issue number, e.g. Closes #2013.

If this PR closes an open issue in another TOP repo, replace the #XXXXX
with the URL of the issue, e.g. Closes
https://github.com/TheOdinProject/curriculum/issues/XXXXX

If this PR does not close, but is related to another issue or PR, you
can link it as above without the 'Closes' keyword, e.g. 'Related to
#2013'.
-->
Related to #4524  

~~Missing tests that were called for in that issue.~~ There are now two
system tests.

## Additional Information
<!-- Any other information about this PR, such as a link to a Discord
discussion. -->

~~The feature flag does work correctly in the view, but I'm not getting
a redirect to work in the controller if the feature is disabled. It
still renders the page as if the feature was enabled.~~ This is
resolved.
  • Loading branch information
JustWaveThings committed Jun 4, 2024
1 parent fa2994f commit 6950307
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 6950307

Please sign in to comment.