Questions: fixes, redesign form, fix edit error

This commit is contained in:
Stella Rouzi 2015-09-10 12:39:52 +03:00
parent 38bc2e3c3a
commit e25425bd77
20 changed files with 300 additions and 117 deletions

View 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

View 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