Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding tests and groundwork to make survey response page render role-… #73

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rails_root/app/controllers/survey_profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ def set_survey_profile

# Only allow a list of trusted parameters through.
def survey_profile_params
params.require(:survey_profile).permit(:user_id, :first_name, :last_name, :campus_name, :district_name)
params.require(:survey_profile).permit(:user_id, :first_name, :last_name, :campus_name, :district_name, :role)
end
end
4 changes: 4 additions & 0 deletions rails_root/app/controllers/survey_responses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SurveyResponsesController < ApplicationController
# GET /survey_responses or /survey_responses.json
def index
if params[:query].present?

@survey_responses = SurveyResponse.where(share_code: params[:query])
flash[:warning] = "No survey responses found for share code #{params[:query]}" if @survey_responses.empty?
else
Expand All @@ -34,11 +35,14 @@ def current_user_id
def new
# login check is done in secure.rb
logger.info '========== new triggered =========='

@pagination, @questions, @section = paginate(collection: SurveyQuestion.all, params: { per_page: 10, page: 1 })
@survey_response = SurveyResponse.new
return return_to_root 'You are not logged in.' if current_user_id.nil?
return return_to_root 'Your profile could not be found. Please complete your profile.' unless SurveyProfile.exists?(user_id: current_user_id)

@survey_profile = SurveyProfile.find_by(user_id: current_user_id)

session[:survey_id] = nil
session[:page_number] = 1
end
Expand Down
6 changes: 3 additions & 3 deletions rails_root/app/models/survey_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# This is the model for the SurveyProfile
class SurveyProfile < ApplicationRecord
enum role: {
principal: 0,
teacher: 1,
superintendent: 2
Principal: 0,
Teacher: 1,
Superintendent: 2
}
has_many :responses,
foreign_key: :profile_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

json.extract! survey_profile, :id, :user_id, :first_name, :last_name, :campus_name, :district_name, :created_at,
:updated_at
:updated_at, :role
json.url survey_profile_url(survey_profile, format: :json)
1 change: 1 addition & 0 deletions rails_root/app/views/survey_profiles/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<td><%= survey_profile.last_name %></td>
<td><%= survey_profile.campus_name %></td>
<td><%= survey_profile.district_name %></td>
<td><%= survey_profile.role %></td>
<td><%= link_to "Show", survey_profile %></td>
</tr>
<% end %>
Expand Down
6 changes: 5 additions & 1 deletion rails_root/app/views/survey_responses/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<h1 class="text-center">ORGANIZATIONAL AND LEADERSHIP EFFECTIVENESS INVENTORY</h1>
<h1 class="text-center">ORGANIZATIONAL AND LEADERSHIP EFFECTIVENESS INVENTORY
<% if session[:userinfo].present? && @survey_profile.present?%>
- <%= @survey_profile.role %>
<% end %>
</h1>
<%# <%= render "form", survey_response: @survey_response, survey_sections: @survey_sections%>
<%= render partial: 'paginated_form', locals: {
pagination: @pagination,
Expand Down
6 changes: 3 additions & 3 deletions rails_root/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

SurveyProfile.create!([
{ user_id: '5', first_name: 'John', last_name: 'Doe', campus_name: 'Campus 1',
district_name: 'District 1', role: 'principal' },
district_name: 'District 1', role: 'Principal' },
{ user_id: '6', first_name: 'Jane', last_name: 'Doe', campus_name: 'Campus 2',
district_name: 'District 2', role: 'teacher' },
district_name: 'District 2', role: 'Teacher' },
{ user_id: '7', first_name: 'Jim', last_name: 'Doe', campus_name: 'Campus 3',
district_name: 'District 3', role: 'superintendent' }
district_name: 'District 3', role: 'Superintendent' }
])

# seed data for the survey_responses table
Expand Down
2 changes: 1 addition & 1 deletion rails_root/features/login_profile_generation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Survey Profile Creation upon successful OAuth login
And I have never created a survey profile
Then I am redirected to the create survey profile page
And I fill in my first and last name and district name and campus name and organization role and click create
Then a survey profile is created
Then a survey profile is created with the proper information
Then I am redirected to the home page


Expand Down
38 changes: 38 additions & 0 deletions rails_root/features/role_based_survey.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Feature: Specific Survey Questions Rendered based on User Role.
Verify Survey Profile and Survey Response

Scenario: User logs in for the first time and takes survey as a principal
Given that I am on the homepage
And I try to login
And I have never created a survey profile
Then I am redirected to the create survey profile page
And I fill in my information as a principal
Then a survey profile is created for me as a principal
Then I am redirected to the home page
Then I am logged in as a principal
When I navigate to the survey page
Then I should see the survey questions specific to the principal

Scenario: User logs in for the first time and takes survey as a teacher
Given that I am on the homepage
And I try to login
And I have never created a survey profile
Then I am redirected to the create survey profile page
And I fill in my information as a teacher
Then a survey profile is created for me as a teacher
Then I am redirected to the home page
Then I am logged in as a teacher
When I navigate to the survey page
Then I should see the survey questions specific to the teacher

Scenario: User logs in for the first time and takes survey as a superintendent
Given that I am on the homepage
And I try to login
And I have never created a survey profile
Then I am redirected to the create survey profile page
And I fill in my information as a superintendent
Then a survey profile is created for me as a superintendent
Then I am redirected to the home page
Then I am logged in as a superintendent
When I navigate to the survey page
Then I should see the survey questions specific to the superintendent
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
When('I try to create model instances') do |table|
table.hashes.each do |model|
@attributes = @model_attributes[model['model_name']]
@attributes['role'] = 'principal' if model['model_name'] == 'SurveyProfile'
@attributes['role'] = 'Principal' if model['model_name'] == 'SurveyProfile'

if @attributes.values.any?(&:nil?)
expect do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@
expect(page).to have_content('John Doe - Welcome to Our Rails App')
end

Then('a survey profile is created') do
Then('a survey profile is created with the proper information') do
profile = SurveyProfile.find_by_user_id('google-oauth2|100507718411999601151')
expect(profile.role).to eq('Principal')
expect(profile).not_to be_nil
end
#rubocop enable all
#rubocop enable all
2 changes: 1 addition & 1 deletion rails_root/features/step_definitions/model_rework_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
end

@model_attributes['SurveyProfile'] = {}
@model_attributes['SurveyProfile']['role'] = 'principal'
@model_attributes['SurveyProfile']['role'] = 'Principal'
SurveyProfile.column_names.each do |name|
@model_attributes['SurveyProfile'][name] = 10 if name != 'created_at' && name != 'updated_at' && name != 'role'
end
Expand Down
79 changes: 79 additions & 0 deletions rails_root/features/step_definitions/role_based_survey_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# frozen_string_literal: true

Then('I fill in my information as a principal') do
fill_in 'First name', with: 'John'
fill_in 'Last name', with: 'Doe'
fill_in 'Campus name', with: 'Joe Campus'
fill_in 'District name', with: 'Joe District'
select 'Principal', from: 'Role'
click_button 'Create Survey profile'
end

Then('a survey profile is created for me as a principal') do
profile = SurveyProfile.find_by_user_id('google-oauth2|100507718411999601151')
expect(profile.role).to eq('Principal')
expect(profile).not_to be_nil
end

Then('I am logged in as a principal') do
expect(page).to have_content('John Doe - Welcome to Our Rails App')
expect(page).to have_content('Role: Principal')
end

When('I navigate to the survey page') do
visit new_survey_response_path
end

Then('I should see the survey questions specific to the principal') do
expect(page).to have_content('ORGANIZATIONAL AND LEADERSHIP EFFECTIVENESS INVENTORY - Principal')
end



Then('I fill in my information as a teacher') do
fill_in 'First name', with: 'John'
fill_in 'Last name', with: 'Doe'
fill_in 'Campus name', with: 'Joe Campus'
fill_in 'District name', with: 'Joe District'
select 'Teacher', from: 'Role'
click_button 'Create Survey profile'
end

Then('a survey profile is created for me as a teacher') do
profile = SurveyProfile.find_by_user_id('google-oauth2|100507718411999601151')
expect(profile.role).to eq('Teacher')
expect(profile).not_to be_nil
end

Then('I am logged in as a teacher') do
expect(page).to have_content('John Doe - Welcome to Our Rails App')
expect(page).to have_content('Role: Teacher')
end

Then('I should see the survey questions specific to the teacher') do
expect(page).to have_content('ORGANIZATIONAL AND LEADERSHIP EFFECTIVENESS INVENTORY - Teacher')
end

Then('I fill in my information as a superintendent') do
fill_in 'First name', with: 'John'
fill_in 'Last name', with: 'Doe'
fill_in 'Campus name', with: 'Joe Campus'
fill_in 'District name', with: 'Joe District'
select 'Superintendent', from: 'Role'
click_button 'Create Survey profile'
end

Then('a survey profile is created for me as a superintendent') do
profile = SurveyProfile.find_by_user_id('google-oauth2|100507718411999601151')
expect(profile.role).to eq('Superintendent')
expect(profile).not_to be_nil
end

Then('I am logged in as a superintendent') do
expect(page).to have_content('John Doe - Welcome to Our Rails App')
expect(page).to have_content('Role: Superintendent')
end

Then('I should see the survey questions specific to the superintendent') do
expect(page).to have_content('ORGANIZATIONAL AND LEADERSHIP EFFECTIVENESS INVENTORY - Superintendent')
end
Loading