2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2014-08-28 15:21:05 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
feature Ticket do
|
|
|
|
|
let!(:conference) { create(:conference, title: 'ExampleCon') }
|
2019-03-13 10:31:42 +01:00
|
|
|
let!(:organizer) { create(:organizer, resource: conference) }
|
2014-08-28 15:21:05 +02:00
|
|
|
|
|
|
|
|
context 'as a organizer' do
|
|
|
|
|
before(:each) do
|
|
|
|
|
sign_in organizer
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:each) do
|
|
|
|
|
sign_out
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'add a valid ticket', feature: true, js: true do
|
|
|
|
|
visit admin_conference_tickets_path(conference.short_title)
|
|
|
|
|
click_link 'Add Ticket'
|
|
|
|
|
|
|
|
|
|
fill_in 'ticket_title', with: 'Business Ticket'
|
|
|
|
|
fill_in 'ticket_description', with: 'The business ticket'
|
|
|
|
|
fill_in 'ticket_price', with: '100'
|
|
|
|
|
|
|
|
|
|
click_button 'Create Ticket'
|
2018-10-25 16:16:56 -07:00
|
|
|
page.find('#flash')
|
2014-08-28 15:21:05 +02:00
|
|
|
expect(flash).to eq('Ticket successfully created.')
|
2016-09-03 17:26:42 +05:30
|
|
|
expect(Ticket.count).to eq(2)
|
2014-08-28 15:21:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'Ticket already created' do
|
|
|
|
|
let!(:ticket) { create(:ticket, title: 'Business Ticket', price: 100, conference_id: conference.id) }
|
|
|
|
|
|
|
|
|
|
scenario 'edit valid ticket', feature: true, js: true do
|
|
|
|
|
visit admin_conference_tickets_path(conference.short_title)
|
2016-09-03 17:26:42 +05:30
|
|
|
click_link('Edit', href: edit_admin_conference_ticket_path(conference.short_title, ticket.id))
|
2014-08-28 15:21:05 +02:00
|
|
|
|
2016-09-03 17:26:42 +05:30
|
|
|
fill_in 'ticket_title', with: 'Event Ticket'
|
2014-08-28 15:21:05 +02:00
|
|
|
fill_in 'ticket_price', with: '50'
|
|
|
|
|
|
|
|
|
|
click_button 'Update Ticket'
|
|
|
|
|
|
|
|
|
|
ticket.reload
|
2016-01-25 19:00:56 +01:00
|
|
|
# It's necessary to multiply by 100 because the price is in cents
|
2018-10-25 16:16:56 -07:00
|
|
|
page.find('#flash')
|
|
|
|
|
expect(flash).to eq('Ticket successfully updated.')
|
2016-01-25 19:00:56 +01:00
|
|
|
expect(ticket.price).to eq(Money.new(50 * 100, 'USD'))
|
2016-09-03 17:26:42 +05:30
|
|
|
expect(ticket.title).to eq('Event Ticket')
|
|
|
|
|
expect(Ticket.count).to eq(2)
|
2014-08-28 15:21:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'delete ticket', feature: true, js: true do
|
|
|
|
|
visit admin_conference_tickets_path(conference.short_title)
|
2016-09-03 17:26:42 +05:30
|
|
|
click_link('Delete', href: admin_conference_ticket_path(conference.short_title, ticket.id))
|
2018-10-25 16:16:56 -07:00
|
|
|
page.accept_alert
|
|
|
|
|
page.find('#flash')
|
2014-08-28 15:21:05 +02:00
|
|
|
expect(flash).to eq('Ticket successfully destroyed.')
|
2016-09-03 17:26:42 +05:30
|
|
|
expect(Ticket.count).to eq(1)
|
2014-08-28 15:21:05 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|