Skip to content

Commit

Permalink
Merge pull request #468 from commercekitchen/rename_school_types
Browse files Browse the repository at this point in the history
Rename school types
  • Loading branch information
tmichaelreis authored Jul 20, 2020
2 parents ba4f18a + 143ce2e commit aefa5b9
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/models/school.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class School < ApplicationRecord

validates :school_name, presence: true

enum school_type: { elementary: 0, middle_school: 1, high_school: 2, charter_school: 3, specialty_school: 4 }
enum school_type: { elementary: 0, middle: 1, high: 2, charter: 3, specialty: 4 }

scope :enabled, -> { where(enabled: true) }
end
6 changes: 3 additions & 3 deletions spec/controllers/admin/schools_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@

it 'updates school' do
expect do
patch :update, params: { id: school.id, school: { school_type: 'middle_school' }, format: 'js' }
end.to change { school.reload.school_type }.from('elementary').to('middle_school')
patch :update, params: { id: school.id, school: { school_type: 'middle' }, format: 'js' }
end.to change { school.reload.school_type }.from('elementary').to('middle')
end

it 'does not update school for another subsite' do
sign_out admin
sign_in other_subsite_admin

expect do
patch :update, params: { id: school.id, school: { school_type: 'middle_school' }, format: 'js' }
patch :update, params: { id: school.id, school: { school_type: 'middle' }, format: 'js' }
end.to_not(change { school.reload.school_type })
end
end
Expand Down
26 changes: 20 additions & 6 deletions spec/controllers/ajax/schools_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
before do
@elementary_school1 = create(:school, school_type: :elementary, organization: organization)
@elementary_school2 = create(:school, school_type: :elementary, organization: organization)
@middle_school = create(:school, school_type: :middle_school, organization: organization)
@high_school = create(:school, school_type: :high_school, organization: organization)
@middle_school = create(:school, school_type: :middle, organization: organization)
@high_school = create(:school, school_type: :high, organization: organization)
@charter_school = create(:school, school_type: :charter, organization: organization)
@specialty_school = create(:school, school_type: :specialty, organization: organization)

create(:school, school_type: :elementary, organization: organization, enabled: false)
create(:school, school_type: :elementary, organization: organization, enabled: false)
create(:school, school_type: :middle_school, organization: organization, enabled: false)
create(:school, school_type: :high_school, organization: organization, enabled: false)
create(:school, school_type: :middle, organization: organization, enabled: false)
create(:school, school_type: :high, organization: organization, enabled: false)
create(:school, school_type: :charter, organization: organization, enabled: false)
create(:school, school_type: :specialty, organization: organization, enabled: false)

@request.host = "#{organization.subdomain}.test.host"
end
Expand All @@ -26,13 +30,23 @@
end

it 'returns active middle schools' do
get :index, params: { school_type: 'middle_school' }, format: :js
get :index, params: { school_type: 'middle' }, format: :js
expect(response.body).to eq([@middle_school].to_json)
end

it 'returns active high schools' do
get :index, params: { school_type: 'high_school' }, format: :js
get :index, params: { school_type: 'high' }, format: :js
expect(response.body).to eq([@high_school].to_json)
end

it 'returns active charter schools' do
get :index, params: { school_type: 'charter' }, format: :js
expect(response.body).to eq([@charter_school].to_json)
end

it 'returns active specialty schools' do
get :index, params: { school_type: 'specialty' }, format: :js
expect(response.body).to eq([@specialty_school].to_json)
end
end
end
2 changes: 1 addition & 1 deletion spec/controllers/registrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
describe 'school registration' do
let(:organization) { create(:organization, accepts_programs: true) }
let(:program) { create(:program, parent_type: :students_and_parents, organization: organization) }
let(:school) { create(:school, school_type: :middle_school, organization: organization) }
let(:school) { create(:school, school_type: :middle, organization: organization) }

before do
@request.host = "#{organization.subdomain}.test.host"
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/schools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FactoryBot.define do
factory :school do
school_name { Faker::Hipster.sentence(word_count: 3) }
school_type { :middle_school }
school_type { :middle }
organization

trait :disabled do
Expand Down
26 changes: 13 additions & 13 deletions spec/features/admin/school_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

scenario 'Admin view a list of schools' do
@elementary_school = FactoryBot.create(:school, organization: organization, school_type: 'elementary')
@middle_school = FactoryBot.create(:school, organization: organization, school_type: 'middle_school')
@high_school = FactoryBot.create(:school, organization: organization, school_type: 'high_school')
@charter_school = FactoryBot.create(:school, organization: organization, school_type: 'charter_school')
@specialty_school = FactoryBot.create(:school, organization: organization, school_type: 'specialty_school')
@middle_school = FactoryBot.create(:school, organization: organization, school_type: 'middle')
@high_school = FactoryBot.create(:school, organization: organization, school_type: 'high')
@charter_school = FactoryBot.create(:school, organization: organization, school_type: 'charter')
@specialty_school = FactoryBot.create(:school, organization: organization, school_type: 'specialty')

visit admin_dashboard_index_path
click_link 'Manage Schools'
Expand All @@ -30,10 +30,10 @@
expect(page).to have_content(@high_school.school_name)

expect(page).to have_select('school_school_type', selected: 'Elementary')
expect(page).to have_select('school_school_type', selected: 'Middle School')
expect(page).to have_select('school_school_type', selected: 'High School')
expect(page).to have_select('school_school_type', selected: 'Charter School')
expect(page).to have_select('school_school_type', selected: 'Specialty School')
expect(page).to have_select('school_school_type', selected: 'Middle')
expect(page).to have_select('school_school_type', selected: 'High')
expect(page).to have_select('school_school_type', selected: 'Charter')
expect(page).to have_select('school_school_type', selected: 'Specialty')
end

scenario 'Admin changes a school type', js: true do
Expand All @@ -42,28 +42,28 @@
visit admin_schools_path

within('.resource-row') do
select('Middle School', from: 'school_school_type')
select('Middle', from: 'school_school_type')
end

expect(page).to have_select('school_school_type', selected: 'Middle School')
expect(page).to have_select('school_school_type', selected: 'Middle')

visit admin_schools_path

expect(page).to have_select('school_school_type', selected: 'Middle School')
expect(page).to have_select('school_school_type', selected: 'Middle')
end

scenario 'Admin creates a new school', js: true do
visit admin_schools_path

fill_in 'School Name', with: 'New School'

select('Middle School', from: 'school_school_type')
select('Middle', from: 'school_school_type')
click_button 'Add School'

expect(page).to have_selector('.resource-row')
within('.resource-row') do
expect(page).to have_content('New School')
expect(page).to have_select('school_school_type', selected: 'Middle School')
expect(page).to have_select('school_school_type', selected: 'Middle')
end
end
end
16 changes: 8 additions & 8 deletions spec/features/user/school_registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
before do
create(:program, program_name: 'MNPS', parent_type: :students_and_parents, organization: organization)
create(:school, school_type: :elementary, school_name: 'Lincoln Elementary', organization: organization)
create(:school, school_type: :middle_school, school_name: 'Middle School East', organization: organization)
create(:school, school_type: :high_school, school_name: 'GLHS', organization: organization)
create(:school, school_type: :charter_school, school_name: 'Magna Carta Charter School', organization: organization)
create(:school, school_type: :specialty_school, school_name: 'Denver School of Performing Arts', organization: organization)
create(:school, school_type: :middle, school_name: 'Middle School East', organization: organization)
create(:school, school_type: :high, school_name: 'GLHS', organization: organization)
create(:school, school_type: :charter, school_name: 'Magna Carta Charter School', organization: organization)
create(:school, school_type: :specialty, school_name: 'Denver School of Performing Arts', organization: organization)
end

scenario 'registers as student', js: true do
Expand Down Expand Up @@ -47,16 +47,16 @@
expect(page).to have_select('School', exact: true)
expect(page).to have_select('School', options: ['Select School...', 'Lincoln Elementary'])

select('Middle School', from: 'School Type')
select('Middle', from: 'School Type')
expect(page).to have_select('School', options: ['Select School...', 'Middle School East'])

select('Charter School', from: 'School Type')
select('Charter', from: 'School Type')
expect(page).to have_select('School', options: ['Select School...', 'Magna Carta Charter School'])

select('Specialty School', from: 'School Type')
select('Specialty', from: 'School Type')
expect(page).to have_select('School', options: ['Select School...', 'Denver School of Performing Arts'])

select('High School', from: 'School Type')
select('High', from: 'School Type')
expect(page).to have_select('School', options: ['Select School...', 'GLHS'])

select('GLHS', from: 'School')
Expand Down

0 comments on commit aefa5b9

Please sign in to comment.