Track related refactoring

Add roles as nested routes to track (for the track organizer role)
Allow transition from to_accept to to_reject and backwards
Split Track#valid_dates validation to many independent ones
Show all the confirmed tracks in the conference's splashpage
Add comment in admin/Tracks#toggle_cfp_inclusion
Rewrite admin/TracksController#accept spec
Add feature spec for track requests
Change 'In' to 'Room' in Tracks#index
Rewrite Track#overlapping
Refactor code in ProposalsController
Fix typos
This commit is contained in:
AEtherC0r3 2017-08-17 13:36:46 +03:00 committed by Stella Rouzi
parent 9c4892bfc8
commit 27fa79a826
21 changed files with 279 additions and 144 deletions

View file

@ -3,9 +3,11 @@ require 'spec_helper'
describe Admin::TracksController do
let(:admin) { create(:admin) }
let(:conference) { create(:conference) }
let(:conference) { create(:conference, start_date: Date.current - 1.day) }
let(:venue) { create(:venue, conference: conference) }
let(:room) { create(:room, venue: venue) }
let!(:track) { create(:track, program: conference.program, color: '#800080') }
let!(:self_organized_track) { create(:track, :self_organized, program: conference.program, name: 'My awesome track') }
let!(:self_organized_track) { create(:track, :self_organized, program: conference.program, name: 'My awesome track', start_date: Date.current, end_date: Date.current, room: room) }
before :each do
sign_in(admin)
@ -81,7 +83,7 @@ describe Admin::TracksController do
expect(Track.find(assigns(:track).id)).to be_a Track
end
it 'the new tracks has the correct attributes' do
it 'the new track has the correct attributes' do
expect(assigns(:track).state).to eq 'confirmed'
expect(assigns(:track).cfp_active).to eq true
end
@ -358,20 +360,13 @@ describe Admin::TracksController do
end
describe 'PATCH #accept' do
shared_examples 'fails to accept' do |start_date, end_date, room|
shared_examples 'fails to accept' do
before :each do
self_organized_track.start_date = start_date ? Date.today : nil
self_organized_track.end_date = end_date ? Date.today : nil
if room
conference.venue = create(:venue)
self_organized_track.room = create(:room, venue: conference.venue)
else
self_organized_track.room = nil
end
self_organized_track.save!
patch :accept, conference_id: conference.short_title, id: self_organized_track.short_name
self_organized_track.reload
end
it 'assigns the correct track' do
expect(assigns(:track)).to eq self_organized_track
end
it 'redirects to Tracks#edit' do
@ -385,12 +380,6 @@ describe Admin::TracksController do
context 'has start_date, end_date and room' do
before :each do
self_organized_track.start_date = Date.today
self_organized_track.end_date = Date.today
conference.venue = create(:venue)
self_organized_track.room = create(:room, venue: conference.venue)
self_organized_track.save!
patch :accept, conference_id: conference.short_title, id: self_organized_track.short_name
self_organized_track.reload
end
@ -409,31 +398,71 @@ describe Admin::TracksController do
end
context 'has start_date and end_date' do
it_behaves_like 'fails to accept', true, true, false
before :each do
self_organized_track.room = nil
self_organized_track.save!
end
it_behaves_like 'fails to accept'
end
context 'has start_date and room' do
it_behaves_like 'fails to accept', true, false, true
before :each do
self_organized_track.end_date = nil
self_organized_track.save!
end
it_behaves_like 'fails to accept'
end
context 'has start_date' do
it_behaves_like 'fails to accept', true, false, false
before :each do
self_organized_track.end_date = nil
self_organized_track.room = nil
self_organized_track.save!
end
it_behaves_like 'fails to accept'
end
context 'has end_date and room' do
it_behaves_like 'fails to accept', false, true, true
before :each do
self_organized_track.start_date = nil
self_organized_track.save!
end
it_behaves_like 'fails to accept'
end
context 'has end_date' do
it_behaves_like 'fails to accept', false, true, false
before :each do
self_organized_track.start_date = nil
self_organized_track.room = nil
self_organized_track.save!
end
it_behaves_like 'fails to accept'
end
context 'has room' do
it_behaves_like 'fails to accept', false, false, true
before :each do
self_organized_track.start_date = nil
self_organized_track.end_date = nil
self_organized_track.save!
end
it_behaves_like 'fails to accept'
end
context 'has non of start_date, end_date, room' do
it_behaves_like 'fails to accept', false, false, false
context 'has none of start_date, end_date, room' do
before :each do
self_organized_track.start_date = nil
self_organized_track.end_date = nil
self_organized_track.room = nil
self_organized_track.save!
end
it_behaves_like 'fails to accept'
end
end

View file

@ -4,26 +4,29 @@ feature Track do
let!(:conference) { create(:conference) }
let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) }
let!(:organizer) { create(:user, role_ids: [organizer_role.id]) }
let(:user) { create(:user) }
shared_examples 'tracks' do
shared_examples 'admin tracks' do
scenario 'adds a track', feature: true, js: true do
sign_in organizer
visit admin_conference_program_tracks_path(conference_id: conference.short_title)
click_link 'New Track'
expected = expect do
visit admin_conference_program_tracks_path(conference_id: conference.short_title)
click_link 'New Track'
fill_in 'track_name', with: 'Distribution'
fill_in 'track_short_name', with: 'Distribution'
page.find('#track_color').set('#B94D4D')
fill_in 'track_description', with: 'Events about our Linux distribution'
click_button 'Create Track'
fill_in 'track_name', with: 'Distribution'
fill_in 'track_short_name', with: 'Distribution'
page.find('#track_color').set('#B94D4D')
fill_in 'track_description', with: 'Events about our Linux distribution'
click_button 'Create Track'
end
expected.to change { Track.count }.by 1
expect(flash).to eq('Track successfully created.')
within('table#tracks') do
expect(page.has_content?('Distribution')).to be true
expect(page.has_content?('Events about our Linux')).to be true
expect(page.assert_selector('tr', count: 2)).to be true
end
end
@ -31,15 +34,17 @@ feature Track do
track = create(:track, program_id: conference.program.id)
sign_in organizer
visit admin_conference_program_tracks_path(conference_id: conference.short_title)
expected = expect do
visit admin_conference_program_tracks_path(conference_id: conference.short_title)
click_link 'Delete'
click_link 'Delete'
end
expected.to change { Track.count }.by(-1)
expect(flash).to eq('Track successfully deleted.')
within('table#tracks') do
expect(page.has_content?(track.name)).to be false
expect(page.has_content?(track.description)).to be false
expect(page.has_content?('No data available in table')).to eq true
end
end
@ -47,25 +52,104 @@ feature Track do
create(:track, program_id: conference.program.id)
sign_in organizer
visit admin_conference_program_tracks_path(conference_id: conference.short_title)
click_link 'Edit'
expected = expect do
visit admin_conference_program_tracks_path(conference_id: conference.short_title)
click_link 'Edit'
fill_in 'track_name', with: 'Distribution'
fill_in 'track_short_name', with: 'Distribution'
page.find('#track_color').set('#B94D4D')
fill_in 'track_description', with: 'Events about our Linux distribution'
click_button 'Update Track'
fill_in 'track_name', with: 'Distribution'
fill_in 'track_short_name', with: 'Distribution'
page.find('#track_color').set('#B94D4D')
fill_in 'track_description', with: 'Events about our Linux distribution'
click_button 'Update Track'
end
expected.to_not(change { Track.count })
expect(flash).to eq('Track successfully updated.')
within('table#tracks') do
expect(page.has_content?('Distribution')).to be true
expect(page.has_content?('Events about our Linux')).to be true
expect(page.assert_selector('tr', count: 2)).to be true
end
end
end
shared_examples 'non admin tracks' do
scenario 'adds a track', feature: true, js: true do
sign_in user
expected = expect do
visit conference_program_tracks_path(conference_id: conference.short_title)
click_link 'New Track request'
fill_in 'track_name', with: 'Distribution'
fill_in 'track_short_name', with: 'Distribution'
page.find('#track_color').set('#B94D4D')
fill_in 'track_description', with: 'Events about our Linux distribution'
fill_in 'track_relevance', with: 'Maintainer of super awesome distribution'
click_button 'Create Track'
end
expected.to change { Track.count }.by 1
expect(flash).to eq('Track request successfully created.')
within('table#tracks') do
expect(page.has_content?('Distribution')).to eq true
expect(page.has_content?('Events about our Linux dist...')).to eq true
end
end
scenario 'withdraws a track', feature: true, js: true do
track = create(:track, :self_organized, program_id: conference.program.id, submitter: user)
sign_in user
expected = expect do
visit conference_program_tracks_path(conference_id: conference.short_title)
accept_confirm do
click_link 'Withdraw'
end
end
expected.to_not(change { Track.count })
expect(flash).to eq("Track #{track.name} withdrawn.")
within('table#tracks') do
expect(page.has_content?(track.name)).to eq true
expect(page.has_link?('Re-Submit')).to eq true
end
end
scenario 'updates a track', feature: true, js: true do
create(:track, :self_organized, program_id: conference.program.id, submitter: user)
sign_in user
expected = expect do
visit conference_program_tracks_path(conference_id: conference.short_title)
click_link 'Edit'
fill_in 'track_name', with: 'Distribution'
fill_in 'track_short_name', with: 'Distribution'
page.find('#track_color').set('#B94D4D')
fill_in 'track_description', with: 'Events about our Linux distribution'
click_button 'Update Track'
end
expected.to_not(change { Track.count })
expect(flash).to eq('Track request successfully updated.')
within('table#tracks') do
expect(page.has_content?('Distribution')).to eq true
expect(page.has_content?('Events about our Linux dist...')).to eq true
end
end
end
describe 'organizer' do
it_behaves_like 'tracks'
it_behaves_like 'admin tracks'
end
describe 'signed in user' do
before :each do
create(:cfp, cfp_type: 'tracks', program: conference.program)
end
it_behaves_like 'non admin tracks'
end
end

View file

@ -3,7 +3,7 @@ require 'spec_helper'
describe Cfp do
subject { create(:cfp) }
let!(:conference) { create(:conference, end_date: Date.today) }
let!(:cfp) { create(:cfp, start_date: Date.today - 2, end_date: Date.today - 1, program_id: conference.program.id) }
let!(:cfp) { create(:cfp, cfp_type: 'events', start_date: Date.today - 2, end_date: Date.today - 1, program_id: conference.program.id) }
describe 'validations' do
it { is_expected.to validate_presence_of(:cfp_type) }
@ -18,7 +18,7 @@ describe Cfp do
end
it 'returns nil when the cfp for events doesn\'t exist' do
conference.program.cfp.destroy
cfp.destroy!
expect(conference.program.cfps.for_events).to eq nil
end
end

View file

@ -68,14 +68,14 @@ describe Track do
it { is_expected.to_not validate_presence_of(:description) }
end
describe '#valid_dates' do
describe '#dates_within_conference_dates' do
before :each do
@conference = create(:conference, start_date: 1.day.ago, end_date: 2.days.from_now)
end
context 'is valid' do
it 'when the track\'s start date is before it\'s end date and between the conference start/end dates' do
track = build(:track, start_date: Date.today, end_date: Date.tomorrow, program: @conference.program)
it 'when the track\'s dates are between the conference\'s dates' do
track = build(:track, start_date: @conference.start_date, end_date: @conference.end_date, program: @conference.program)
expect(track.valid?).to eq true
end
end
@ -84,27 +84,42 @@ describe Track do
it 'when the track\'s start date is before the conference\'s start date' do
track = build(:track, start_date: 2.days.ago, end_date: Date.tomorrow, program: @conference.program)
expect(track.valid?).to eq false
expect(track.errors[:start_date]).to eq ["can't be before the conference start date (#{1.day.ago.to_date})"]
end
it 'when the track\'s end date is before the conference\'s start date' do
track = build(:track, start_date: 3.days.ago, end_date: 2.days.ago, program: @conference.program)
expect(track.valid?).to eq false
expect(track.errors[:end_date]).to eq ["can't be before the conference start date (#{1.day.ago.to_date})"]
expect(track.errors[:start_date]).to eq ["can't be outside of the conference's dates (#{1.day.ago.to_date}-#{2.days.from_now.to_date})"]
end
it 'when the track\'s start date is after the conference\'s end date' do
track = build(:track, start_date: 3.days.from_now, end_date: 4.days.from_now, program: @conference.program)
expect(track.valid?).to eq false
expect(track.errors[:start_date]).to eq ["can't be after the conference end date (#{2.days.from_now.to_date})"]
expect(track.errors[:start_date]).to eq ["can't be outside of the conference's dates (#{1.day.ago.to_date}-#{2.days.from_now.to_date})"]
end
it 'when the track\'s end date is before the conference\'s start date' do
track = build(:track, start_date: 3.days.ago, end_date: 2.days.ago, program: @conference.program)
expect(track.valid?).to eq false
expect(track.errors[:end_date]).to eq ["can't be outside of the conference's dates (#{1.day.ago.to_date}-#{2.days.from_now.to_date})"]
end
it 'when the track\'s end date is after the conference\'s end date' do
track = build(:track, start_date: Date.today, end_date: 3.days.from_now, program: @conference.program)
expect(track.valid?).to eq false
expect(track.errors[:end_date]).to eq ["can't be after the conference end date (#{2.days.from_now.to_date})"]
expect(track.errors[:end_date]).to eq ["can't be outside of the conference's dates (#{1.day.ago.to_date}-#{2.days.from_now.to_date})"]
end
end
end
describe '#start_date_before_end_date' do
before :each do
@conference = create(:conference, start_date: 1.day.ago, end_date: 2.days.from_now)
end
context 'is valid' do
it 'when the track\'s start date is before its end date' do
track = build(:track, start_date: Date.today, end_date: Date.tomorrow, program: @conference.program)
expect(track.valid?).to eq true
end
end
context 'is invalid' do
it 'when the track\'s start date is after it\'s end date' do
track = build(:track, start_date: 1.day.from_now, end_date: 1.day.ago)
expect(track.valid?).to eq false
@ -235,7 +250,7 @@ describe Track do
end
context 'includes' do
it 'when track is confirmed' do
it 'tracks with state \'confirmed\'' do
confirmed_track = create(:track, state: 'confirmed', program: @program)
expect(@program.tracks.confirmed.include?(confirmed_track)).to eq true
end
@ -243,7 +258,7 @@ describe Track do
context 'excludes' do
%w[new to_accept accepted to_reject rejected canceled withdrawn].each do |state|
it "when track is #{state.humanize}" do
it "tracks with state '#{state}'" do
unconfirmed_track = create(:track, state: state, program: @program)
expect(@program.tracks.confirmed.include?(unconfirmed_track)).to eq false
end
@ -310,10 +325,10 @@ describe Track do
transitions = [:restart, :to_accept, :accept, :confirm, :to_reject, :reject, :cancel, :withdraw]
states_transitions = { new: { restart: false, to_accept: true, accept: true, confirm: false, to_reject: true, reject: true, cancel: false, withdraw: true },
to_accept: { restart: false, to_accept: false, accept: true, confirm: false, to_reject: false, reject: false, cancel: true, withdraw: true },
to_accept: { restart: false, to_accept: false, accept: true, confirm: false, to_reject: true, reject: false, cancel: true, withdraw: true },
accepted: { restart: false, to_accept: false, accept: false, confirm: true, to_reject: false, reject: false, cancel: true, withdraw: true },
confirmed: { restart: false, to_accept: false, accept: false, confirm: false, to_reject: false, reject: false, cancel: true, withdraw: true },
to_reject: { restart: false, to_accept: false, accept: false, confirm: false, to_reject: false, reject: true, cancel: true, withdraw: true },
to_reject: { restart: false, to_accept: true, accept: false, confirm: false, to_reject: false, reject: true, cancel: true, withdraw: true },
rejected: { restart: true, to_accept: false, accept: false, confirm: false, to_reject: false, reject: false, cancel: false, withdraw: false },
canceled: { restart: true, to_accept: false, accept: false, confirm: false, to_reject: false, reject: false, cancel: false, withdraw: false },
withdrawn: { restart: true, to_accept: false, accept: false, confirm: false, to_reject: false, reject: false, cancel: false, withdraw: false } }