Add model test for sponsership_level

This commit is contained in:
Aditya Prakash 2016-03-22 18:38:42 +05:30
parent 6a6824cef1
commit 53f732ce9c

View file

@ -1,7 +1,7 @@
require 'spec_helper'
describe SponsorshipLevel do
describe 'validations' do
describe 'validation' do
it 'has a valid factory' do
expect(build(:sponsorship_level)).to be_valid
@ -11,4 +11,31 @@ describe SponsorshipLevel do
should validate_presence_of(:title)
end
end
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))
.to eq [2, 1, 3]
end
it 'maintains order after deleting one element' do
@first_sponsorship_level.destroy
expect(SponsorshipLevel.where(conference_id: conference.id).order(:position).map(&:id))
.to eq [2, 3]
end
end
end