Skip to content

Commit

Permalink
users can select role upon login and see role later on
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtoddmathes committed Apr 10, 2024
1 parent 4c5ad0a commit 0c84d5a
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 14 deletions.
5 changes: 5 additions & 0 deletions rails_root/app/models/survey_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

# This is the model for the SurveyProfile
class SurveyProfile < ApplicationRecord
enum role: {
principal: 0,
teacher: 1,
superintendent: 2
}
has_many :responses,
foreign_key: :profile_id,
class_name: 'SurveyResponse',
Expand Down
6 changes: 6 additions & 0 deletions rails_root/app/views/survey_profiles/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
<%= form.text_field :district_name %>
</div>
<div>
<%= form.label :role, style: "display: block" %>
<%= form.select :role,['Principal', 'Teacher', 'Superintendent'],{prompt: 'Select a role'}, style: "display: block" %>
</div>
<div>
<%= form.label :submit, style: "display: block" %>
<%= form.submit %>
</div>
<% end %>
5 changes: 5 additions & 0 deletions rails_root/app/views/survey_profiles/_survey_profile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
<%= survey_profile.district_name %>
</p>

<p>
<strong>Role:</strong>
<%= survey_profile.role %>
</p>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddRoleToSurveyProfile < ActiveRecord::Migration[7.1]
def change
add_column :survey_profiles, :role, :integer, default: 0
end
end
10 changes: 2 additions & 8 deletions rails_root/db/schema.rb

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

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' },
district_name: 'District 1', role: 'principal' },
{ user_id: '6', first_name: 'Jane', last_name: 'Doe', campus_name: 'Campus 2',
district_name: 'District 2' },
district_name: 'District 2', role: 'teacher' },
{ user_id: '7', first_name: 'Jim', last_name: 'Doe', campus_name: 'Campus 3',
district_name: 'District 3' }
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 @@ -7,7 +7,7 @@ Feature: Survey Profile Creation upon successful OAuth login
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 first and last name and district name and campus name and click create
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 I am redirected to the home page

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +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'

if @attributes.values.any?(&:nil?)
expect do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@
expect(page).to have_current_path(new_survey_profile_path)
end

Then('I fill in my first and last name and district name and campus name and click create') do
Then('I fill in my first and last name and district name and campus name and organization role and click create') 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

Expand Down
3 changes: 2 additions & 1 deletion rails_root/features/step_definitions/model_rework_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
end

@model_attributes['SurveyProfile'] = {}
@model_attributes['SurveyProfile']['role'] = 'principal'
SurveyProfile.column_names.each do |name|
@model_attributes['SurveyProfile'][name] = 10 if name != 'created_at' && name != 'updated_at'
@model_attributes['SurveyProfile'][name] = 10 if name != 'created_at' && name != 'updated_at' && name != 'role'
end

@model_attributes['SurveyResponse'] = {}
Expand Down

0 comments on commit 0c84d5a

Please sign in to comment.