osem-fcy/spec/models/sponsorship_level_spec.rb

55 lines
1.6 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2021-02-20 09:57:27 -08:00
# == Schema Information
#
# Table name: sponsorship_levels
#
# id :bigint not null, primary key
# position :integer
# title :string
# created_at :datetime
# updated_at :datetime
# conference_id :integer
#
2014-06-05 11:56:04 +05:30
require 'spec_helper'
describe SponsorshipLevel do
2016-03-22 18:38:42 +05:30
describe 'validation' do
2014-06-05 11:56:04 +05:30
it 'has a valid factory' do
expect(build(:sponsorship_level)).to be_valid
end
it 'is not valid without a title' do
should validate_presence_of(:title)
end
end
2016-03-22 18:38:42 +05:30
describe 'association' do
it { is_expected.to belong_to(:conference) }
it { is_expected.to have_many(:sponsors) }
end
describe 'acts_as_list' do
let(:conference) { create(:conference) }
before do
@first_sponsorship_level = create(:sponsorship_level, conference: conference)
@second_sponsorship_level = create(:sponsorship_level, conference: conference)
@second_sponsorship_level.move_higher
@third_sponsorship_level = create(:sponsorship_level, conference: conference)
end
it 'is positions sponsorship_levels in order' do
expect(SponsorshipLevel.where(conference_id: conference.id).order(:position).map(&:id))
2016-08-17 18:49:00 +02:00
.to eq [@second_sponsorship_level.id, @first_sponsorship_level.id, @third_sponsorship_level.id]
2016-03-22 18:38:42 +05:30
end
it 'maintains order after deleting one element' do
@first_sponsorship_level.destroy
expect(SponsorshipLevel.where(conference_id: conference.id).order(:position).map(&:id))
2016-08-17 18:49:00 +02:00
.to eq [@second_sponsorship_level.id, @third_sponsorship_level.id]
2016-03-22 18:38:42 +05:30
end
end
2014-06-05 11:56:04 +05:30
end