osem-fcy/spec/models/track_spec.rb
AEtherC0r3 68fc750e9f Implement track requests and add the track organizer role
About track requests:
Create migration that adds the fields submitter_id, state, and
cfp_active to Tracks
Add validations and the self_organized? method to the Track model
Create a new TracksController outide of the admin namespace
Create the relevant views for index, show, new and edit
Modify the admin views for tracks to include extra info for
self-organized tracks

About track organizers:
Create the role when a self-organized track is created
Define track organizer abilities
Modify the roles views and controller to handle the new role

The route for Roles#edit needs to have higher priority than the nested
routes for track roles, otherwise, the word edit in the url is matched
as a track with short_name edit
2017-07-14 12:38:53 +03:00

57 lines
1.8 KiB
Ruby

require 'spec_helper'
describe Track do
subject { create(:track) }
let(:track) { create(:track) }
let(:self_organized_track) { create(:track, :self_organized) }
describe 'association' do
it { is_expected.to belong_to(:program) }
it { is_expected.to belong_to(:submitter).class_name('User') }
it { is_expected.to have_many(:events) }
end
describe 'validation' do
it 'has a valid factory' do
expect(build(:track)).to be_valid
end
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to allow_value('#ABCDEF').for(:color) }
it { is_expected.to allow_value('#124689').for(:color) }
it { is_expected.to validate_presence_of(:short_name) }
it { is_expected.to allow_value('My_track_name').for(:short_name) }
it { is_expected.to_not allow_value('My track name').for(:short_name) }
it { is_expected.to validate_uniqueness_of(:short_name).scoped_to(:program_id) }
context 'when self-organized' do
before :each do
allow(subject).to receive(:self_organized?).and_return(true)
end
it { is_expected.to validate_presence_of(:state) }
it { is_expected.to validate_inclusion_of(:cfp_active).in_array([true, false]) }
end
context 'when regular' do
before :each do
allow(subject).to receive(:self_organized?).and_return(false)
end
it { is_expected.to_not validate_presence_of(:state) }
it { is_expected.to_not validate_inclusion_of(:cfp_active) }
end
end
describe '#self_organized?' do
it 'returns true when it has a submitter' do
expect(self_organized_track.submitter).to be_a User
expect(self_organized_track.self_organized?).to eq true
end
it 'returns false when it doesn\'t have a submitter' do
expect(track.submitter).to eq nil
expect(track.self_organized?).to eq false
end
end
end