Adds model and controller tests for Question.

This commit is contained in:
Stella Rouzi 2015-09-16 12:20:52 +03:00
parent e25425bd77
commit a04df00bdc
6 changed files with 311 additions and 24 deletions

View file

@ -0,0 +1,39 @@
require 'spec_helper'
describe Answer do
let(:conference) { create(:conference) }
let(:question) { create(:question) }
let(:second_answer) { create(:second_answer) }
let(:registration) { create(:registration, conference: conference) }
describe 'validations' do
it 'has a valid factory' do
expect(build(:answer)).to be_valid
end
it 'is not valid without a title' do
should validate_presence_of(:title)
expect(build(:answer, title: nil)).not_to be_valid
end
it 'cannot be modified if the question is being used' do
question.answers << second_answer
second_answer.title = 'new title'
expect(second_answer.valid?).to be false
end
end
describe '#sum_replies' do
before :each do
conference.questions << question
registration.qanswers << create(:qanswer, question: question, answer: second_answer)
end
it 'returns no of replies for the answer, given a question and a conference' do
expect(second_answer.sum_replies(question, conference)).to eq 1
end
end
end

View file

@ -0,0 +1,22 @@
require 'spec_helper'
describe Question do
describe 'validations' do
it 'has a valid factory' do
expect(build(:question)).to be_valid
end
it 'is not valid without a title' do
should validate_presence_of(:title)
expect(build(:question, title: nil)).not_to be_valid
end
it 'is not valid without a question type' do
should validate_presence_of(:question_type_id)
expect(build(:question, question_type_id: nil)).not_to be_valid
end
end
end