Sha256: 7422574f51eae4a69477f09972fbfb1ad841736f8d7dade98ba154ea38800e2c

Contents?: true

Size: 939 Bytes

Versions: 4

Compression:

Stored size: 939 Bytes

Contents

RSpec.describe Spree::QuestionCategory, type: :model do

  context 'instance attributes' do
    it 'create a new instance given valid attributes' do
      described_class.create!(name: 'Question 1')
    end
  end

  it 'factory is valid' do
    expect(build(:question_category)).to be_valid
  end

  context 'relation' do
    it { is_expected.to have_many(:questions) }

    it 'have questions' do
      expect(subject.questions).not_to be_nil
    end
  end

  context 'validation' do
    it { is_expected.to validate_presence_of(:name) }
    it { is_expected.to validate_uniqueness_of(:name) }
    it { is_expected.to accept_nested_attributes_for(:questions) }
  end

  context 'acts as list' do

    subject { create(:question_category) }

    before do
      2.times { create(:question_category) }
    end

    it 'can have its position changed' do
      subject.move_to_bottom
      expect(subject.position).to eq(3)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spree-faq-2.4.0 spec/models/question_category_spec.rb
spree-faq-2.3.0 spec/models/question_category_spec.rb
spree-faq-2.2.1 spec/models/question_category_spec.rb
spree-faq-2.1.1 spec/models/question_category_spec.rb