2014-08-05 18:23:42 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
feature Commercial do
|
|
|
|
|
# It is necessary to use bang version of let to build roles before user
|
2014-08-12 11:51:59 +03:00
|
|
|
let!(:conference) { create(:conference) }
|
2014-08-12 15:48:29 +03:00
|
|
|
let!(:organizer_role) { create(:organizer_role, resource: conference) }
|
2014-08-12 11:51:59 +03:00
|
|
|
let!(:organizer) { create(:user, role_ids: [organizer_role.id]) }
|
2014-08-28 15:21:05 +02:00
|
|
|
let!(:participant) { create(:user) }
|
2014-08-05 18:23:42 +02:00
|
|
|
|
2014-08-28 15:21:05 +02:00
|
|
|
context 'in admin area' do
|
|
|
|
|
scenario 'adds, updates, deletes of a conference', feature: true, js: true do
|
2014-08-05 18:23:42 +02:00
|
|
|
expected_count = conference.commercials.count + 1
|
|
|
|
|
|
2014-08-12 11:51:59 +03:00
|
|
|
sign_in organizer
|
2014-08-05 18:23:42 +02:00
|
|
|
|
|
|
|
|
visit admin_conference_commercials_path(conference.short_title)
|
|
|
|
|
|
2015-04-22 21:30:32 +02:00
|
|
|
# Workaround to enable the 'Create Commercial' button
|
|
|
|
|
page.execute_script("$('#commercial_submit_action').prop('disabled', false)")
|
2014-08-05 18:23:42 +02:00
|
|
|
|
|
|
|
|
# Create valid commercial
|
2015-04-22 21:30:32 +02:00
|
|
|
fill_in 'commercial_url', with: 'https://www.youtube.com/watch?v=M9bq_alk-sw'
|
2014-08-05 18:23:42 +02:00
|
|
|
click_button 'Create Commercial'
|
|
|
|
|
expect(flash).to eq('Commercial was successfully created.')
|
|
|
|
|
expect(conference.commercials.count).to eq(expected_count)
|
|
|
|
|
|
2015-04-22 21:30:32 +02:00
|
|
|
commercial = conference.commercials.where(url: 'https://www.youtube.com/watch?v=M9bq_alk-sw').first
|
|
|
|
|
fill_in "commercial_url_#{commercial.id}", with: 'https://www.youtube.com/watch?v=VNkDJk5_9eU'
|
|
|
|
|
click_button 'Update'
|
2014-08-05 18:23:42 +02:00
|
|
|
|
|
|
|
|
expect(flash).to eq('Commercial was successfully updated.')
|
|
|
|
|
expect(conference.commercials.count).to eq(expected_count)
|
2015-04-22 21:30:32 +02:00
|
|
|
commercial.reload
|
|
|
|
|
expect(commercial.url).to eq 'https://www.youtube.com/watch?v=VNkDJk5_9eU'
|
2014-08-05 18:23:42 +02:00
|
|
|
|
|
|
|
|
# Delete commercial
|
|
|
|
|
click_link 'Delete'
|
|
|
|
|
|
|
|
|
|
expect(flash).to eq('Commercial was successfully destroyed.')
|
|
|
|
|
expect(conference.commercials.count).to eq(expected_count - 1)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-08-28 15:21:05 +02:00
|
|
|
context 'in public area' do
|
|
|
|
|
let!(:event) { create(:event, conference: conference, title: 'Example Proposal') }
|
|
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
|
event.event_users = [create(:event_user,
|
|
|
|
|
user_id: participant.id,
|
|
|
|
|
event_id: event.id,
|
|
|
|
|
event_role: 'submitter')]
|
|
|
|
|
|
|
|
|
|
@expected_count = Commercial.count + 1
|
|
|
|
|
sign_in participant
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:each) do
|
|
|
|
|
sign_out
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-22 21:30:32 +02:00
|
|
|
scenario 'adds a commercial of an event', feature: true, js: true do
|
2014-08-28 15:21:05 +02:00
|
|
|
visit edit_conference_proposal_path(conference.short_title, event.id)
|
|
|
|
|
click_link 'Commercials'
|
2015-04-22 21:30:32 +02:00
|
|
|
fill_in 'commercial_url', with: 'https://www.youtube.com/watch?v=M9bq_alk-sw'
|
2014-08-28 15:21:05 +02:00
|
|
|
|
2015-04-22 21:30:32 +02:00
|
|
|
# Workaround to enable the 'Create Commercial' button
|
|
|
|
|
page.execute_script("$('#commercial_submit_action').prop('disabled', false)")
|
2014-08-28 15:21:05 +02:00
|
|
|
|
|
|
|
|
click_button 'Create Commercial'
|
|
|
|
|
expect(flash).to eq('Commercial was successfully created.')
|
|
|
|
|
expect(event.commercials.count).to eq(@expected_count)
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-22 21:30:32 +02:00
|
|
|
scenario 'updates a commercial of an event', feature: true, js: true do
|
|
|
|
|
commercial = create(:commercial,
|
|
|
|
|
commercialable_id: event.id,
|
|
|
|
|
commercialable_type: 'Event')
|
2014-08-28 15:21:05 +02:00
|
|
|
visit edit_conference_proposal_path(conference.short_title, event.id)
|
|
|
|
|
click_link 'Commercials'
|
2015-04-22 21:30:32 +02:00
|
|
|
fill_in "commercial_url_#{commercial.id}", with: 'https://www.youtube.com/watch?v=M9bq_alk-sw'
|
|
|
|
|
click_button 'Update'
|
2014-08-28 15:21:05 +02:00
|
|
|
expect(flash).to eq('Commercial was successfully updated.')
|
|
|
|
|
expect(event.commercials.count).to eq(@expected_count)
|
2015-04-22 21:30:32 +02:00
|
|
|
commercial.reload
|
|
|
|
|
expect(commercial.url).to eq('https://www.youtube.com/watch?v=M9bq_alk-sw')
|
2014-08-28 15:21:05 +02:00
|
|
|
end
|
|
|
|
|
|
2015-04-22 21:30:32 +02:00
|
|
|
scenario 'deletes a commercial of an event', feature: true, js: true do
|
2014-08-28 15:21:05 +02:00
|
|
|
create(:commercial,
|
|
|
|
|
commercialable_id: event.id,
|
|
|
|
|
commercialable_type: 'Event')
|
|
|
|
|
visit edit_conference_proposal_path(conference.short_title, event.id)
|
|
|
|
|
click_link 'Commercials'
|
|
|
|
|
click_link 'Delete'
|
|
|
|
|
page.driver.network_traffic
|
|
|
|
|
expect(flash).to eq('Commercial was successfully destroyed.')
|
|
|
|
|
expect(event.commercials.count).to eq(@expected_count - 1)
|
|
|
|
|
end
|
2014-08-05 18:23:42 +02:00
|
|
|
end
|
|
|
|
|
end
|