mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
working on aggregated results
This commit is contained in:
parent
f5b473ed28
commit
48eb55ad94
11 changed files with 120 additions and 8 deletions
|
|
@ -5,9 +5,11 @@ RSpec.describe AttemptsController, type: :controller do
|
|||
let(:valid_session) { {} }
|
||||
|
||||
let(:schedule) { Schedule.new }
|
||||
let(:recipient) { Recipient.create(name: 'Recipient', phone: '+11231231234') }
|
||||
let(:school) { School.create!(name: 'School') }
|
||||
let(:recipient) { Recipient.create!(name: 'Recipient', phone: '+11231231234') }
|
||||
let(:recipient_schedule) { RecipientSchedule.new }
|
||||
let(:question) { Question.new }
|
||||
let(:category) { Category.create!(name: 'Category') }
|
||||
let(:question) { create_questions(1, category).first }
|
||||
let!(:first_attempt) {
|
||||
Attempt.create(
|
||||
schedule: schedule,
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ describe "survey:attempt_questions" do
|
|||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:questions) { create_questions(3) }
|
||||
let!(:category) { Category.create(name: 'Category') }
|
||||
let!(:questions) { create_questions(3, category) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
|
@ -86,7 +87,7 @@ describe "survey:attempt_questions" do
|
|||
|
||||
describe 'A Week Later' do
|
||||
before :each do
|
||||
Timecop.freeze(Date.today + 8) { subject.invoke }
|
||||
Timecop.freeze(Date.today + 10) { subject.invoke }
|
||||
end
|
||||
|
||||
it 'should create the second attempt for each recipient with a different question' do
|
||||
|
|
|
|||
34
spec/models/school_category_spec.rb
Normal file
34
spec/models/school_category_spec.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SchoolCategory, type: :model do
|
||||
|
||||
let!(:school1) { School.create!(name: 'School 1') }
|
||||
let!(:school2) { School.create!(name: 'School 2') }
|
||||
|
||||
let!(:school1recipients) { create_recipients(school1, 4) }
|
||||
let!(:school2recipients) { create_recipients(school2, 4) }
|
||||
|
||||
let!(:category1) { Category.create!(name: 'Category 1') }
|
||||
let!(:category2) { Category.create!(name: 'Category 2') }
|
||||
|
||||
let!(:questions) { create_questions(3, category1) }
|
||||
|
||||
let!(:attempt1) { Attempt.create(question: questions[0], recipient: school1recipients[0], answer_index: 2)}
|
||||
let!(:attempt2) { Attempt.create(question: questions[0], recipient: school1recipients[1])}
|
||||
let!(:attempt3) { Attempt.create(question: questions[0], recipient: school1recipients[2], answer_index: 3)}
|
||||
let!(:attempt4) { Attempt.create(question: questions[0], recipient: school2recipients[0], answer_index: 4)}
|
||||
|
||||
let!(:school_category) { SchoolCategory.for(school1, category1).first }
|
||||
|
||||
describe 'aggregated_responses' do
|
||||
it 'should provide the count and sum of all attempts' do
|
||||
expect(school_category.aggregated_responses).to eq(
|
||||
attempt_count: 3,
|
||||
response_count: 2,
|
||||
answer_index_total: 5
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
@ -146,7 +146,7 @@ def create_recipients(school, count)
|
|||
return recipients
|
||||
end
|
||||
|
||||
def create_questions(count)
|
||||
def create_questions(count, category=nil)
|
||||
questions = []
|
||||
count.times do |i|
|
||||
questions << Question.create(
|
||||
|
|
@ -155,7 +155,8 @@ def create_questions(count)
|
|||
option2: "Option #{i}:#{count} B",
|
||||
option3: "Option #{i}:#{count} C",
|
||||
option4: "Option #{i}:#{count} D",
|
||||
option5: "Option #{i}:#{count} E"
|
||||
option5: "Option #{i}:#{count} E",
|
||||
category: category
|
||||
)
|
||||
end
|
||||
return questions
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue