spec/models/question_spec.rb in spree-faq-2.0.1 vs spec/models/question_spec.rb in spree-faq-2.1.0

- old
+ new

@@ -1,58 +1,53 @@ -RSpec.describe Spree::Question, type: :model do +require 'spec_helper' +describe Spree::Question do + let!(:question_category) { create(:question_category) } let(:question) { create(:question, question_category_id: question_category.id) } subject { question } - it 'factory is valid' do - expect(build(:question)).to be_valid + context 'factory' do + it 'is valid' do + expect(build(:question)).to be_valid + end end context 'instance attributes' do - it 'creates a new instance given valid attributes' do + it 'create a new instance given valid attributes' do described_class.create!(question: 'Question 1', answer: 'Answer 1', question_category: create(:question_category)) end end context 'relation' do - it { is_expected.to belong_to(:question_category) } + it { should belong_to(:question_category) } - it 'belongs to a category' do + it 'belong to a category' do expect(subject.question_category).not_to be_nil end end context 'validation' do - it { is_expected.to validate_presence_of(:question_category_id) } - it { is_expected.to validate_presence_of(:question) } - it { is_expected.to validate_presence_of(:answer) } + it { should validate_presence_of(:question_category_id) } + it { should validate_presence_of(:question) } + it { should validate_presence_of(:answer) } - it 'requires a category' do + it 'require a category' do invalid_question = build(:question, question_category: nil) - expect(invalid_question.valid?).to be_falsey - expect(invalid_question.errors[:question_category_id].size).to be(1) + expect(invalid_question).to have(1).error_on(:question_category_id) end - it 'requires a question' do + it 'require a question' do invalid_question = build(:question, question: nil) - expect(invalid_question.valid?).to be_falsey - expect(invalid_question.errors[:question].size).to be(1) + expect(invalid_question).to have(1).error_on(:question) end - it 'requires a answer' do + it 'require a answer' do invalid_question = build(:question, answer: nil) - expect(invalid_question.valid?).to be_falsey - expect(invalid_question.errors[:answer].size).to be(1) - end - end - - context 'mass assignment' do - %w(question answer question_category_id question_category).each do |column| - it { should allow_mass_assignment_of(column.to_sym) } + expect(invalid_question).to have(1).error_on(:answer) end end context 'acts as list' do