parent
2a5c88d9cf
commit
ba027a31a7
@ -0,0 +1,38 @@
|
||||
- aggregated_responses = question.aggregated_responses_for_school(@school)
|
||||
- return if aggregated_responses.nil?
|
||||
|
||||
.col-6.py-3
|
||||
.question.p-2{id: "question-#{question.id}"}
|
||||
%p.question-text.pt-3.px-2
|
||||
%b Question:
|
||||
= question.text
|
||||
|
||||
.pb-3.px-2
|
||||
.indicator-container.float-left
|
||||
= render 'school_categories/indicator', info: aggregated_responses, small: true
|
||||
|
||||
.pl-3.pt-1.float-left
|
||||
%p
|
||||
%b Total Responses:
|
||||
= aggregated_responses.count
|
||||
%p
|
||||
%b Most Popular:
|
||||
= truncate(aggregated_responses.most_popular_answer, length: 27)
|
||||
%p
|
||||
%b Source:
|
||||
=# question.source(@school)
|
||||
|
||||
.clearfix
|
||||
|
||||
-#
|
||||
.show-hide
|
||||
%p
|
||||
%span{class: 'toggle', data: {toggle: 'histogram-answers'}}= "<span class='toggle'>Show</span> Histogram".html_safe
|
||||
|
|
||||
%span{class: 'toggle', data: {toggle: 'raw'}}= "<span class='toggle'>Show</span> Raw Data".html_safe
|
||||
|
||||
- if question.is_a?(Question) || question.is_a?(GroupedQuestion)
|
||||
.histogram-answers.hidden
|
||||
= render question
|
||||
|
||||
%p.raw.hidden= likerts.join(', ')
|
||||
@ -0,0 +1,54 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Question, type: :model do
|
||||
|
||||
let!(:school1) { School.create!(name: 'School 1') }
|
||||
let!(:school2) { School.create!(name: 'School 2') }
|
||||
|
||||
let!(:school1recipients) { create_recipients(school1, 5) }
|
||||
let!(:school2recipients) { create_recipients(school2, 4) }
|
||||
|
||||
let!(:category1) { Category.create!(name: 'Resources') }
|
||||
let!(:category2) { Category.create!(name: 'Category 2') }
|
||||
|
||||
let!(:category1questions) { create_questions(3, category1) }
|
||||
let!(:category2questions) { create_questions(3, category2) }
|
||||
let(:question) { category1questions.first }
|
||||
|
||||
let!(:attempt1) { Attempt.create!(question: category1questions[0], recipient: school1recipients[0], answer_index: 3)}
|
||||
let!(:attempt2) { Attempt.create!(question: category1questions[0], recipient: school1recipients[1], answer_index: 2)}
|
||||
let!(:attempt3) { Attempt.create!(question: category1questions[0], recipient: school1recipients[2])}
|
||||
let!(:attempt4) { Attempt.create!(question: category1questions[0], recipient: school1recipients[3], answer_index: 3)}
|
||||
let!(:attempt5) { Attempt.create!(question: category1questions[0], recipient: school2recipients[0], answer_index: 4)}
|
||||
let!(:attempt6) { Attempt.create!(question: category1questions[1], recipient: school1recipients[0], answer_index: 5)}
|
||||
let!(:attempt7) { Attempt.create!(question: category1questions[2], recipient: school1recipients[0], answer_index: 5)}
|
||||
let!(:attempt8) { Attempt.create!(question: category2questions[0], recipient: school1recipients[0], answer_index: 3)}
|
||||
let!(:attempt9) { Attempt.create!(question: category2questions[1], recipient: school1recipients[1], answer_index: 1)}
|
||||
|
||||
describe 'aggregated_responses_for_school' do
|
||||
|
||||
let(:aggregated_responses) { question.aggregated_responses_for_school(school1) }
|
||||
|
||||
it 'aggregates all attempts with responses for the question for a given school' do
|
||||
expect(aggregated_responses.count).to eq(3)
|
||||
expect(aggregated_responses.responses.to_a).to eq([attempt1, attempt2, attempt4])
|
||||
expect(aggregated_responses.answer_index_total).to eq(8)
|
||||
end
|
||||
|
||||
it 'should calculate answer_index_average' do
|
||||
expect(aggregated_responses.answer_index_average).to eq(8.0 / 3)
|
||||
end
|
||||
|
||||
it 'should calculate the most popular answer' do
|
||||
expect(aggregated_responses.most_popular_answer).to eq(question.option3)
|
||||
end
|
||||
|
||||
it 'should provide access to the question and category' do
|
||||
expect(aggregated_responses.question).to eq(question)
|
||||
expect(aggregated_responses.category).to eq(question.category)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
Loading…
Reference in new issue