Reorder gender columns

mciea-main
rebuilt 2 years ago
parent 2a8148b8cd
commit 5ea01ac916

@ -9,11 +9,11 @@ module Analyze
end end
def to_s def to_s
'Students by Gender' "Students by Gender"
end end
def slug def slug
'students-by-gender' "students-by-gender"
end end
def columns def columns
@ -21,6 +21,7 @@ module Analyze
genders.each do |gender| genders.each do |gender|
array << column_for_gender_code(code: gender.qualtrics_code) array << column_for_gender_code(code: gender.qualtrics_code)
end end
array.sort_by!(&:to_s)
array << Analyze::Graph::Column::AllStudent array << Analyze::Graph::Column::AllStudent
end end
end end

@ -79,12 +79,12 @@ module Analyze
gender_params = params[:genders] gender_params = params[:genders]
return genders unless gender_params return genders unless gender_params
gender_params.split(",").map { |gender| Gender.find_by_designation(gender) }.compact gender_params.split(",").sort.map { |gender| Gender.find_by_designation(gender) }.compact
end end
end end
def genders def genders
@genders ||= Gender.all @genders ||= Gender.all.order(designation: :ASC)
end end
def groups def groups

@ -1,77 +1,77 @@
require 'rails_helper' require "rails_helper"
describe Analyze::Presenter do describe Analyze::Presenter do
let(:category) { create(:category, category_id: '1', name: 'first category') } let(:category) { create(:category, category_id: "1", name: "first category") }
let(:category_2) { create(:category, category_id: '2', name: 'second category') } let(:category_2) { create(:category, category_id: "2", name: "second category") }
let(:wrong_category) { create(:category, category_id: '999', name: 'wrong category') } let(:wrong_category) { create(:category, category_id: "999", name: "wrong category") }
let(:subcategory) { create(:subcategory, subcategory_id: '1A', name: 'first subcategory', category:) } let(:subcategory) { create(:subcategory, subcategory_id: "1A", name: "first subcategory", category:) }
let(:subcategory_2) { create(:subcategory, subcategory_id: '2A', name: 'second subcategory', category: category_2) } let(:subcategory_2) { create(:subcategory, subcategory_id: "2A", name: "second subcategory", category: category_2) }
let(:wrong_subcategory) do let(:wrong_subcategory) do
create(:subcategory, subcategory_id: '99A', name: 'wrong subcategory', category: wrong_category) create(:subcategory, subcategory_id: "99A", name: "wrong subcategory", category: wrong_category)
end end
let(:measure) { create(:measure, measure_id: '1A-i', name: 'first measure', subcategory:) } let(:measure) { create(:measure, measure_id: "1A-i", name: "first measure", subcategory:) }
let(:measure_2) { create(:measure, measure_id: '2A-i', name: 'second measure', subcategory: subcategory_2) } let(:measure_2) { create(:measure, measure_id: "2A-i", name: "second measure", subcategory: subcategory_2) }
let(:wrong_measure) do let(:wrong_measure) do
create(:wrong_measure, measure_id: '99A', name: 'wrong measure', subcategory: wrong_subcategory) create(:wrong_measure, measure_id: "99A", name: "wrong measure", subcategory: wrong_subcategory)
end end
let(:scale) { create(:student_scale, measure:) } let(:scale) { create(:student_scale, measure:) }
let(:survey_item) { create(:student_survey_item, scale:) } let(:survey_item) { create(:student_survey_item, scale:) }
let(:school) { create(:school) } let(:school) { create(:school) }
let(:academic_year) { create(:academic_year) } let(:academic_year) { create(:academic_year) }
let(:ay_2021_22) { create(:academic_year, range: '2021-22') } let(:ay_2021_22) { create(:academic_year, range: "2021-22") }
let(:ay_2022_23) { create(:academic_year, range: '2022-23') } let(:ay_2022_23) { create(:academic_year, range: "2022-23") }
let(:wrong_ay) { create(:academic_year, range: '9999-99') } let(:wrong_ay) { create(:academic_year, range: "9999-99") }
let(:black) { create(:race, designation: 'black', qualtrics_code: 1) } let(:black) { create(:race, designation: "black", qualtrics_code: 1) }
let(:white) { create(:race, designation: 'white', qualtrics_code: 2) } let(:white) { create(:race, designation: "white", qualtrics_code: 2) }
let(:wrong_race) { create(:race, designation: 'wrong race', qualtrics_code: 9999) } let(:wrong_race) { create(:race, designation: "wrong race", qualtrics_code: 9999) }
let(:female) { create(:gender, designation: 'female', qualtrics_code: 1) } let(:female) { create(:gender, designation: "female", qualtrics_code: 1) }
let(:male) { create(:gender, designation: 'male', qualtrics_code: 2) } let(:male) { create(:gender, designation: "male", qualtrics_code: 2) }
let(:wrong_gender) { create(:gender, designation: 'wrong_gender', qualtrics_code: 2) } let(:wrong_gender) { create(:gender, designation: "wrong_gender", qualtrics_code: 2) }
context '.category' do context ".category" do
before :each do before :each do
category category
category_2 category_2
wrong_category wrong_category
end end
context 'when a category is provided in the params hash' do context "when a category is provided in the params hash" do
it 'returns the category with the given id' do it "returns the category with the given id" do
params = { category: '1' } params = { category: "1" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.category).to eq category expect(presenter.category).to eq category
params = { category: '2' } params = { category: "2" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.category).to eq category_2 expect(presenter.category).to eq category_2
end end
end end
context 'when no category is provided in the params hash' do context "when no category is provided in the params hash" do
it 'returns the first category' do it "returns the first category" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.category).to eq category expect(presenter.category).to eq category
end end
end end
context 'when a category that doesnt exist in the database is passed' do context "when a category that doesnt exist in the database is passed" do
it 'returns the first category' do it "returns the first category" do
params = { category: '4' } params = { category: "4" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.category).to eq category expect(presenter.category).to eq category
end end
end end
end end
context '.categories' do context ".categories" do
it 'returns all categories' do it "returns all categories" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.categories).to eq Category.all.order(:category_id) expect(presenter.categories).to eq Category.all.order(:category_id)
end end
end end
context '.subcategory' do context ".subcategory" do
before :each do before :each do
category category
category_2 category_2
@ -80,203 +80,203 @@ describe Analyze::Presenter do
subcategory_2 subcategory_2
wrong_subcategory wrong_subcategory
end end
context 'when a subcategory is provided in the params hash' do context "when a subcategory is provided in the params hash" do
it 'returns the subcategory with the given id' do it "returns the subcategory with the given id" do
params = { subcategory: '1A' } params = { subcategory: "1A" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.subcategory).to eq subcategory expect(presenter.subcategory).to eq subcategory
params = { subcategory: '2A' } params = { subcategory: "2A" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.subcategory).to eq subcategory_2 expect(presenter.subcategory).to eq subcategory_2
end end
end end
context 'when no subcategory is provided in the params hash' do context "when no subcategory is provided in the params hash" do
it 'returns the first subcategory' do it "returns the first subcategory" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.subcategory).to eq subcategory expect(presenter.subcategory).to eq subcategory
end end
end end
context 'when a subcategory that doesnt exist in the database is passed' do context "when a subcategory that doesnt exist in the database is passed" do
it 'returns the first subcategory' do it "returns the first subcategory" do
params = { subcategory: '4A' } params = { subcategory: "4A" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.subcategory).to eq subcategory expect(presenter.subcategory).to eq subcategory
end end
end end
end end
context '.subcategories' do context ".subcategories" do
before :each do before :each do
category category
wrong_category wrong_category
subcategory subcategory
wrong_subcategory wrong_subcategory
end end
it 'returns all subcategories for a given category' do it "returns all subcategories for a given category" do
params = { category: '1' } params = { category: "1" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.subcategories).to eq category.subcategories.all.order(:subcategory_id) expect(presenter.subcategories).to eq category.subcategories.all.order(:subcategory_id)
end end
end end
context '.measures' do context ".measures" do
before :each do before :each do
category category
subcategory subcategory
measure measure
end end
it 'returns all measures for a given subcategory' do it "returns all measures for a given subcategory" do
params = { category: '1' } params = { category: "1" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.measures).to eq category.subcategories.flat_map(&:measures) expect(presenter.measures).to eq category.subcategories.flat_map(&:measures)
end end
end end
context '.academic_years' do context ".academic_years" do
before :each do before :each do
ay_2021_22 ay_2021_22
ay_2022_23 ay_2022_23
end end
it 'returns all academic years' do it "returns all academic years" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.academic_years).to eq AcademicYear.all.order(:range) expect(presenter.academic_years).to eq AcademicYear.all.order(:range)
end end
end end
context '.selected_academic_years' do context ".selected_academic_years" do
before :each do before :each do
ay_2021_22 ay_2021_22
ay_2022_23 ay_2022_23
wrong_ay wrong_ay
end end
context 'when no academic years are provided in the params hash' do context "when no academic years are provided in the params hash" do
it 'returns an empty array if no params are provided' do it "returns an empty array if no params are provided" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_academic_years).to eq [] expect(presenter.selected_academic_years).to eq []
end end
end end
context 'when a single academic year is provided in the params hash' do context "when a single academic year is provided in the params hash" do
it 'returns the academic year with the given id' do it "returns the academic year with the given id" do
params = { academic_years: '2021-22' } params = { academic_years: "2021-22" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_academic_years).to eq [AcademicYear.find_by_range('2021-22')] expect(presenter.selected_academic_years).to eq [AcademicYear.find_by_range("2021-22")]
params = { academic_years: '2022-23' } params = { academic_years: "2022-23" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_academic_years).to eq [AcademicYear.find_by_range('2022-23')] expect(presenter.selected_academic_years).to eq [AcademicYear.find_by_range("2022-23")]
end end
end end
context 'when multiple academic years are provided in the params hash' do context "when multiple academic years are provided in the params hash" do
it 'returns the academic year with the given ids' do it "returns the academic year with the given ids" do
params = { academic_years: '2021-22,2022-23' } params = { academic_years: "2021-22,2022-23" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_academic_years).to eq [AcademicYear.find_by_range('2021-22'), expect(presenter.selected_academic_years).to eq [AcademicYear.find_by_range("2021-22"),
AcademicYear.find_by_range('2022-23')] AcademicYear.find_by_range("2022-23")]
end end
end end
end end
context '.races' do context ".races" do
before :each do before :each do
black black
white white
wrong_race wrong_race
end end
it 'returns all races' do it "returns all races" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.races).to eq Race.all.order(designation: :ASC) expect(presenter.races).to eq Race.all.order(designation: :ASC)
end end
end end
context '.selected_races' do context ".selected_races" do
before :each do before :each do
black black
white white
wrong_race wrong_race
end end
context 'when no races are provided in the params hash' do context "when no races are provided in the params hash" do
it 'returns an array with all races if no params are provided' do it "returns an array with all races if no params are provided" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_races).to eq presenter.races expect(presenter.selected_races).to eq presenter.races
end end
end end
context 'when one race is provided in the params hash' do context "when one race is provided in the params hash" do
it 'returns a single race with the given slug' do it "returns a single race with the given slug" do
params = { races: 'white' } params = { races: "white" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_races).to eq [Race.find_by_slug('white')] expect(presenter.selected_races).to eq [Race.find_by_slug("white")]
params = { races: 'black' } params = { races: "black" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_races).to eq [Race.find_by_slug('black')] expect(presenter.selected_races).to eq [Race.find_by_slug("black")]
end end
end end
context 'when multiple races are provided in the params hash' do context "when multiple races are provided in the params hash" do
it 'returns multiple races with the given slugs' do it "returns multiple races with the given slugs" do
params = { races: 'white,black' } params = { races: "white,black" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_races).to eq [Race.find_by_slug('white'), Race.find_by_slug('black')] expect(presenter.selected_races).to eq [Race.find_by_slug("white"), Race.find_by_slug("black")]
end end
end end
end end
context '.graph' do context ".graph" do
context 'when no params are provided' do context "when no params are provided" do
it 'returns the default(first) graph object' do it "returns the default(first) graph object" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.graph.to_s).to eq Analyze::Graph::AllData.new.to_s expect(presenter.graph.to_s).to eq Analyze::Graph::AllData.new.to_s
end end
end end
context 'when a graph is provided in the params hash' do context "when a graph is provided in the params hash" do
it 'returns the graph object with the given slug' do it "returns the graph object with the given slug" do
params = { graph: 'all_data' } params = { graph: "all_data" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.graph.to_s).to eq Analyze::Graph::AllData.new.to_s expect(presenter.graph.to_s).to eq Analyze::Graph::AllData.new.to_s
params = { graph: 'students-and-teachers' } params = { graph: "students-and-teachers" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.graph.to_s).to eq Analyze::Graph::StudentsAndTeachers.new.to_s expect(presenter.graph.to_s).to eq Analyze::Graph::StudentsAndTeachers.new.to_s
params = { graph: 'students-by-race' } params = { graph: "students-by-race" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.graph.to_s).to eq Analyze::Graph::StudentsByRace.new(races: nil).to_s expect(presenter.graph.to_s).to eq Analyze::Graph::StudentsByRace.new(races: nil).to_s
params = { graph: 'students-by-grade' } params = { graph: "students-by-grade" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.graph.to_s).to eq Analyze::Graph::StudentsByGrade.new(grades: nil).to_s expect(presenter.graph.to_s).to eq Analyze::Graph::StudentsByGrade.new(grades: nil).to_s
params = { graph: 'students-by-gender' } params = { graph: "students-by-gender" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.graph.to_s).to eq Analyze::Graph::StudentsByGender.new(genders: nil).to_s expect(presenter.graph.to_s).to eq Analyze::Graph::StudentsByGender.new(genders: nil).to_s
end end
end end
context 'when a parameter that does not match a graph is provided' do context "when a parameter that does not match a graph is provided" do
it 'returns the default(first) graph object' do it "returns the default(first) graph object" do
params = { graph: 'invalid parameter' } params = { graph: "invalid parameter" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.graph.to_s).to eq Analyze::Graph::AllData.new.to_s expect(presenter.graph.to_s).to eq Analyze::Graph::AllData.new.to_s
end end
end end
end end
context '.grades' do context ".grades" do
before :each do before :each do
school school
academic_year academic_year
@ -286,8 +286,8 @@ describe Analyze::Presenter do
create_list(:survey_item_response, 20, school:, academic_year:, grade: 4, survey_item:) create_list(:survey_item_response, 20, school:, academic_year:, grade: 4, survey_item:)
end end
context 'when no grades are provided in the params hash' do context "when no grades are provided in the params hash" do
it 'returns the set of grades for which there are more than ten responses' do it "returns the set of grades for which there are more than ten responses" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.grades).to eq [1, 2, 3, 4] expect(presenter.grades).to eq [1, 2, 3, 4]
@ -295,7 +295,7 @@ describe Analyze::Presenter do
end end
end end
context '.selected_grades' do context ".selected_grades" do
before :each do before :each do
school school
academic_year academic_year
@ -305,86 +305,86 @@ describe Analyze::Presenter do
create_list(:survey_item_response, 20, school:, academic_year:, grade: 4, survey_item:) create_list(:survey_item_response, 20, school:, academic_year:, grade: 4, survey_item:)
end end
context 'when no grades are provided in the params hash' do context "when no grades are provided in the params hash" do
it 'returns only the set of grades selected even if other grades have sufficient responses' do it "returns only the set of grades selected even if other grades have sufficient responses" do
params = { grades: '1,2,3' } params = { grades: "1,2,3" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_grades).to eq [1, 2, 3] expect(presenter.selected_grades).to eq [1, 2, 3]
end end
end end
end end
context '.selected_genders' do context ".selected_genders" do
before :each do before :each do
male male
female female
wrong_gender wrong_gender
end end
context 'when no parameters are provided' do context "when no parameters are provided" do
it 'returns all genders' do it "returns all genders" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_genders).to eq Gender.all expect(presenter.selected_genders).to eq Gender.all.order(designation: :ASC)
end end
end end
context 'when a single gender is provided in the params hash' do context "when a single gender is provided in the params hash" do
it 'returns the gender with the given designation' do it "returns the gender with the given designation" do
params = { genders: 'female' } params = { genders: "female" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_genders).to eq [Gender.find_by_designation('female')] expect(presenter.selected_genders).to eq [Gender.find_by_designation("female")]
params = { genders: 'male' } params = { genders: "male" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_genders).to eq [Gender.find_by_designation('male')] expect(presenter.selected_genders).to eq [Gender.find_by_designation("male")]
end end
end end
context 'when multiple genders are provided in the params hash' do context "when multiple genders are provided in the params hash" do
it 'returns multilple genders with the given designations' do it "returns multilple genders with the given designations" do
params = { genders: 'female,male' } params = { genders: "female,male" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_genders).to eq [Gender.find_by_designation('female'), expect(presenter.selected_genders).to eq [Gender.find_by_designation("female"),
Gender.find_by_designation('male')] Gender.find_by_designation("male")]
end end
end end
end end
context '.genders' do context ".genders" do
before :each do before :each do
female female
male male
end end
it 'returns all genders' do it "returns all genders" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.genders).to eq Gender.all expect(presenter.genders).to eq Gender.all.order(designation: :ASC)
end end
end end
context '.group' do context ".group" do
context 'when no parameters are provided' do context "when no parameters are provided" do
it 'returns the first item in the list of groups' do it "returns the first item in the list of groups" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.group.slug).to eq presenter.groups.first.slug expect(presenter.group.slug).to eq presenter.groups.first.slug
end end
end end
context 'when a group is provided in the params hash' do context "when a group is provided in the params hash" do
it 'returns the group with the given slug' do it "returns the group with the given slug" do
params = { group: 'gender' } params = { group: "gender" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.group.slug).to eq 'gender' expect(presenter.group.slug).to eq "gender"
params = { group: 'grade' } params = { group: "grade" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.group.slug).to eq 'grade' expect(presenter.group.slug).to eq "grade"
params = { group: 'race' } params = { group: "race" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.group.slug).to eq 'race' expect(presenter.group.slug).to eq "race"
# Not yet implemented # Not yet implemented
# params = { group: 'income' } # params = { group: 'income' }
@ -393,75 +393,75 @@ describe Analyze::Presenter do
end end
end end
context 'when a parameter that does not match a group is provided' do context "when a parameter that does not match a group is provided" do
it 'returns the first item in the list of groups' do it "returns the first item in the list of groups" do
params = { group: 'invalid group' } params = { group: "invalid group" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.group.slug).to eq presenter.groups.first.slug expect(presenter.group.slug).to eq presenter.groups.first.slug
end end
end end
end end
context '.slice' do context ".slice" do
context 'when no parameters are provided' do context "when no parameters are provided" do
it 'returns the first item in the list of slices' do it "returns the first item in the list of slices" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq 'all-data' expect(presenter.slice.slug).to eq "all-data"
end end
end end
context 'when a slice is provided in the params hash' do context "when a slice is provided in the params hash" do
it 'returns the slice with the given slug' do it "returns the slice with the given slug" do
params = { source: 'survey-data-only', slice: 'students-and-teachers' } params = { source: "survey-data-only", slice: "students-and-teachers" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq 'students-and-teachers' expect(presenter.slice.slug).to eq "students-and-teachers"
end end
end end
context 'when a slice is provided but the source is left blank ' do context "when a slice is provided but the source is left blank " do
it 'returns the slice from the default source (all-data)' do it "returns the slice from the default source (all-data)" do
params = { slice: 'students-and-teachers' } params = { slice: "students-and-teachers" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq 'all-data' expect(presenter.slice.slug).to eq "all-data"
end end
end end
context 'when a parameter that does not match a slice is provided' do context "when a parameter that does not match a slice is provided" do
it 'it returns the first slice from the chosen source' do it "it returns the first slice from the chosen source" do
params = { source: 'survey-data-only', slice: 'invalid-slice' } params = { source: "survey-data-only", slice: "invalid-slice" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq 'students-and-teachers' expect(presenter.slice.slug).to eq "students-and-teachers"
end end
end end
end end
context '.source' do context ".source" do
context 'when no parameters are provided' do context "when no parameters are provided" do
it 'returns the first item in the list of sources' do it "returns the first item in the list of sources" do
params = {} params = {}
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq 'all-data' expect(presenter.slice.slug).to eq "all-data"
end end
end end
context 'when a source is provided in the params hash' do context "when a source is provided in the params hash" do
it 'returns the source with the given slug' do it "returns the source with the given slug" do
params = { source: 'all-data' } params = { source: "all-data" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.source.slug).to eq 'all-data' expect(presenter.source.slug).to eq "all-data"
params = { source: 'survey-data-only' } params = { source: "survey-data-only" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.source.slug).to eq 'survey-data-only' expect(presenter.source.slug).to eq "survey-data-only"
end end
end end
context 'when a parameter that does not match a source is provided' do context "when a parameter that does not match a source is provided" do
it 'returns the first item in the list of sources' do it "returns the first item in the list of sources" do
params = { source: 'invalid-source' } params = { source: "invalid-source" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq 'all-data' expect(presenter.slice.slug).to eq "all-data"
end end
end end
end end

Loading…
Cancel
Save