Questions: fixes, redesign form, fix edit error
This commit is contained in:
parent
38bc2e3c3a
commit
e25425bd77
20 changed files with 300 additions and 117 deletions
26
spec/controllers/admin/questions_controller_spec.rb
Normal file
26
spec/controllers/admin/questions_controller_spec.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Admin::QuestionsController do
|
||||
let!(:conference) { create(:conference) }
|
||||
let!(:question_with_answers) { create(:question_with_answers) }
|
||||
let!(:question_without_answers) { create(:question) }
|
||||
let(:organizer) { create(:organizer) }
|
||||
|
||||
describe 'PATCH #update_conference' do
|
||||
before(:each) do
|
||||
sign_in(organizer)
|
||||
end
|
||||
|
||||
it 'enables a question for a conference if the question has answers' do
|
||||
patch :toggle_question, conference_id: conference.short_title, id: question_with_answers, enable: 'true'
|
||||
|
||||
conference.reload
|
||||
|
||||
expect(conference.question_ids).to eq([question_with_answers.id])
|
||||
expect(conference.question_ids).to_not include([question_without_answers.id])
|
||||
|
||||
expect(flash[:notice]).to eq("Questions for #{conference.short_title} successfully updated. Note: Only questions with answers can be enabled for a conference.")
|
||||
expect(response).to redirect_to admin_conference_questions_path(conference.short_title)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -2,6 +2,22 @@
|
|||
|
||||
FactoryGirl.define do
|
||||
factory :answer do
|
||||
title 'Do you?'
|
||||
title 'I do'
|
||||
|
||||
factory :answer1 do
|
||||
title 'First Answer'
|
||||
end
|
||||
|
||||
factory :answer2 do
|
||||
title 'Second Answer'
|
||||
end
|
||||
|
||||
factory :answer_yes do
|
||||
title 'Yes'
|
||||
end
|
||||
|
||||
factory :answer_no do
|
||||
title 'No'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,11 +2,27 @@
|
|||
|
||||
FactoryGirl.define do
|
||||
factory :question do
|
||||
title 'blah'
|
||||
title 'Do you?'
|
||||
question_type
|
||||
after(:build) do |question|
|
||||
question.answers << build(:answer)
|
||||
question.conferences << build(:conference)
|
||||
|
||||
factory :question_with_answers do
|
||||
title 'Which do you choose?'
|
||||
|
||||
after(:build) do |question|
|
||||
question.answers << build(:answer1)
|
||||
question.answers << build(:answer2)
|
||||
end
|
||||
end
|
||||
|
||||
factory :attending_with_partner do
|
||||
title 'Will you attend with a partner?'
|
||||
association :question_type, factory: :yes_no
|
||||
global true
|
||||
|
||||
after(:build) do |question|
|
||||
question.answers << build(:answer_yes)
|
||||
question.answers << build(:answer_no)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,6 +2,18 @@
|
|||
|
||||
FactoryGirl.define do
|
||||
factory :question_type do
|
||||
title 'Multiple Choice'
|
||||
title 'A type for question'
|
||||
|
||||
factory :yes_no do
|
||||
title 'Yes/No'
|
||||
end
|
||||
|
||||
factory :single_choice do
|
||||
title 'Single Choice'
|
||||
end
|
||||
|
||||
factory :multiple_choice do
|
||||
title 'Multiple Choice'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
30
spec/views/admin/questions/index.html.haml_spec.rb
Normal file
30
spec/views/admin/questions/index.html.haml_spec.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'admin/questions/index' do
|
||||
let!(:conference) { create(:conference) }
|
||||
let!(:question_type) { create(:question_type) }
|
||||
|
||||
before(:each) do
|
||||
assign(:conference, conference)
|
||||
assign(:question, build(:question))
|
||||
assign(:questions, [ create(:attending_with_partner), create(:question_with_answers, conference_id: conference.id, title: 'Test question for this conf', question_type_id: question_type.id)])
|
||||
|
||||
render
|
||||
end
|
||||
|
||||
it 'renders all available questions' do
|
||||
expect(rendered).to have_selector('table th:nth-of-type(1)', text: 'Enabled')
|
||||
expect(rendered).to have_selector('table th:nth-of-type(2)', text: 'Title')
|
||||
expect(rendered).to have_selector('table th:nth-of-type(3)', text: 'Type')
|
||||
expect(rendered).to have_selector('table th:nth-of-type(4)', text: 'Answers')
|
||||
expect(rendered).to have_selector('table th:nth-of-type(5)', text: 'Actions')
|
||||
|
||||
expect(rendered).to have_selector('table tr:nth-of-type(1) td:nth-of-type(2)', text: 'Will you attend with a partner?')
|
||||
expect(rendered).to have_selector('table tr:nth-of-type(1) td:nth-of-type(3)', text: 'Yes/No')
|
||||
expect(rendered).to have_selector('table tr:nth-of-type(1) td:nth-of-type(4)', text: 'Yes (0), No (0)')
|
||||
|
||||
expect(rendered).to have_selector('table tr:nth-of-type(2) td:nth-of-type(2)', text: 'Test question for this conf')
|
||||
expect(rendered).to have_selector('table tr:nth-of-type(2) td:nth-of-type(3)', text: 'A type for question')
|
||||
expect(rendered).to have_selector('table tr:nth-of-type(2) td:nth-of-type(4)', text: 'First Answer (0), Second Answer (0)')
|
||||
end
|
||||
end
|
||||
35
spec/views/admin/questions/show.html.haml_spec.rb
Normal file
35
spec/views/admin/questions/show.html.haml_spec.rb
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'admin/questions/show' do
|
||||
let!(:conference) { create(:conference) }
|
||||
let!(:question_type) { create(:question_type) }
|
||||
let!(:question) { create(:question) }
|
||||
let!(:attending_with_partner) { create(:attending_with_partner) }
|
||||
let!(:user1) { create(:user, name: 'User 1') }
|
||||
let!(:user2) { create(:user, name: 'User 2') }
|
||||
let!(:user3) { create(:user, name: 'User 3') }
|
||||
|
||||
let!(:registration1) { create(:registration, conference: conference, user: user1) }
|
||||
let!(:qanswer1) { create(:qanswer, question: attending_with_partner, answer: attending_with_partner.answers.first) }
|
||||
let!(:registration2) { create(:registration, conference: conference, user: user2) }
|
||||
let!(:qanswer2) { create(:qanswer, question: attending_with_partner, answer: attending_with_partner.answers.second) }
|
||||
let!(:registration3) { create(:registration, conference: conference, user: user3) }
|
||||
|
||||
before(:each) do
|
||||
assign :conference, conference
|
||||
assign :question, attending_with_partner
|
||||
assign :registrations, [registration1, registration2]
|
||||
registration1.qanswers = [qanswer1]
|
||||
registration2.qanswers = [qanswer2]
|
||||
render
|
||||
end
|
||||
|
||||
it 'renders all users that answered the question' do
|
||||
expect(rendered).to include('User 1')
|
||||
expect(rendered).to include('User 2')
|
||||
end
|
||||
|
||||
it 'does not render users that have not answered the question' do
|
||||
expect(rendered).to_not include('User 3')
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue