diff --git a/rails_root/app/controllers/survey_profiles_controller.rb b/rails_root/app/controllers/survey_profiles_controller.rb index 75c470c..a0a18e6 100644 --- a/rails_root/app/controllers/survey_profiles_controller.rb +++ b/rails_root/app/controllers/survey_profiles_controller.rb @@ -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 diff --git a/rails_root/app/controllers/survey_responses_controller.rb b/rails_root/app/controllers/survey_responses_controller.rb index 68116f7..8ed2979 100644 --- a/rails_root/app/controllers/survey_responses_controller.rb +++ b/rails_root/app/controllers/survey_responses_controller.rb @@ -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 @@ -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 diff --git a/rails_root/app/models/survey_profile.rb b/rails_root/app/models/survey_profile.rb index 37da81c..d240014 100644 --- a/rails_root/app/models/survey_profile.rb +++ b/rails_root/app/models/survey_profile.rb @@ -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, diff --git a/rails_root/app/views/survey_profiles/_survey_profile.json.jbuilder b/rails_root/app/views/survey_profiles/_survey_profile.json.jbuilder index 3e74a32..3c18d96 100644 --- a/rails_root/app/views/survey_profiles/_survey_profile.json.jbuilder +++ b/rails_root/app/views/survey_profiles/_survey_profile.json.jbuilder @@ -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) diff --git a/rails_root/app/views/survey_profiles/index.html.erb b/rails_root/app/views/survey_profiles/index.html.erb index 76ded21..c3a5b86 100644 --- a/rails_root/app/views/survey_profiles/index.html.erb +++ b/rails_root/app/views/survey_profiles/index.html.erb @@ -20,6 +20,7 @@ <%= survey_profile.last_name %> <%= survey_profile.campus_name %> <%= survey_profile.district_name %> + <%= survey_profile.role %> <%= link_to "Show", survey_profile %> <% end %> diff --git a/rails_root/app/views/survey_responses/new.html.erb b/rails_root/app/views/survey_responses/new.html.erb index bc4fd75..066d6d2 100644 --- a/rails_root/app/views/survey_responses/new.html.erb +++ b/rails_root/app/views/survey_responses/new.html.erb @@ -1,4 +1,8 @@ -

ORGANIZATIONAL AND LEADERSHIP EFFECTIVENESS INVENTORY

+

ORGANIZATIONAL AND LEADERSHIP EFFECTIVENESS INVENTORY + <% if session[:userinfo].present? && @survey_profile.present?%> + - <%= @survey_profile.role %> + <% end %> +

<%# <%= render "form", survey_response: @survey_response, survey_sections: @survey_sections%> <%= render partial: 'paginated_form', locals: { pagination: @pagination, diff --git a/rails_root/db/seeds.rb b/rails_root/db/seeds.rb index 86b879e..1d14e8b 100644 --- a/rails_root/db/seeds.rb +++ b/rails_root/db/seeds.rb @@ -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 diff --git a/rails_root/features/login_profile_generation.feature b/rails_root/features/login_profile_generation.feature index 4b0ca09..dc1634a 100644 --- a/rails_root/features/login_profile_generation.feature +++ b/rails_root/features/login_profile_generation.feature @@ -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 diff --git a/rails_root/features/role_based_survey.feature b/rails_root/features/role_based_survey.feature new file mode 100644 index 0000000..fc415c5 --- /dev/null +++ b/rails_root/features/role_based_survey.feature @@ -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 diff --git a/rails_root/features/step_definitions/data_model_design_steps.rb b/rails_root/features/step_definitions/data_model_design_steps.rb index 8268417..b87f65a 100644 --- a/rails_root/features/step_definitions/data_model_design_steps.rb +++ b/rails_root/features/step_definitions/data_model_design_steps.rb @@ -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 diff --git a/rails_root/features/step_definitions/login_profile_generation_steps.rb b/rails_root/features/step_definitions/login_profile_generation_steps.rb index cc88c4e..6e57df7 100644 --- a/rails_root/features/step_definitions/login_profile_generation_steps.rb +++ b/rails_root/features/step_definitions/login_profile_generation_steps.rb @@ -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 \ No newline at end of file +#rubocop enable all diff --git a/rails_root/features/step_definitions/model_rework_steps.rb b/rails_root/features/step_definitions/model_rework_steps.rb index a0a4a02..e4cd4df 100644 --- a/rails_root/features/step_definitions/model_rework_steps.rb +++ b/rails_root/features/step_definitions/model_rework_steps.rb @@ -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 diff --git a/rails_root/features/step_definitions/role_based_survey_steps.rb b/rails_root/features/step_definitions/role_based_survey_steps.rb new file mode 100644 index 0000000..97242e5 --- /dev/null +++ b/rails_root/features/step_definitions/role_based_survey_steps.rb @@ -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