mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 16:19:52 +01:00
30 lines
916 B
Ruby
30 lines
916 B
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Question, :type => :model do
|
|
before :each do
|
|
@question = Question.new(
|
|
content: 'Is this a question?',
|
|
user: FactoryBot.create(:user)
|
|
)
|
|
end
|
|
|
|
subject { @question }
|
|
|
|
it { should respond_to(:content) }
|
|
|
|
it '#content returns a string' do
|
|
expect(@question.content).to match 'Is this a question?'
|
|
end
|
|
|
|
it 'has many answers' do
|
|
5.times { |i| Answer.create(content: "This is an answer. #{i}", user: FactoryBot.create(:user), question: @question) }
|
|
expect(@question.answer_count).to match 5
|
|
end
|
|
|
|
it 'also deletes the answers when deleted' do
|
|
5.times { |i| Answer.create(content: "This is an answer. #{i}", user: FactoryBot.create(:user), question: @question) }
|
|
first_answer_id = @question.answers.first.id
|
|
@question.destroy
|
|
expect{Answer.find(first_answer_id)}.to raise_error(ActiveRecord::RecordNotFound)
|
|
end
|
|
end
|