mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
88 lines
2.9 KiB
Ruby
88 lines
2.9 KiB
Ruby
require 'spec_helper'
|
|
|
|
feature Ticket do
|
|
let!(:conference) { create(:conference, title: 'ExampleCon') }
|
|
let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) }
|
|
let!(:organizer) { create(:user, email: 'admin@example.com', role_ids: [organizer_role.id]) }
|
|
|
|
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'
|
|
expect(flash).to eq('Ticket successfully created.')
|
|
expect(Ticket.count).to eq(1)
|
|
end
|
|
|
|
scenario 'add a invalid ticket', feature: true, js: true do
|
|
visit admin_conference_tickets_path(conference.short_title)
|
|
click_link 'Add Ticket'
|
|
|
|
fill_in 'ticket_title', with: ''
|
|
fill_in 'ticket_price', with: '-1'
|
|
|
|
click_button 'Create Ticket'
|
|
expect(flash).to eq("Creating Ticket failed: Title can't be blank. Price cents must be greater than 0.")
|
|
expect(Ticket.count).to eq(0)
|
|
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)
|
|
click_link 'Edit'
|
|
|
|
fill_in 'ticket_title', with: 'Free Ticket'
|
|
fill_in 'ticket_price', with: '50'
|
|
|
|
click_button 'Update Ticket'
|
|
|
|
ticket.reload
|
|
# It's necessary to multiply by 100 because the price is in cents
|
|
expect(ticket.price).to eq(Money.new(50 * 100, 'USD'))
|
|
expect(ticket.title).to eq('Free Ticket')
|
|
expect(flash).to eq('Ticket successfully updated.')
|
|
expect(Ticket.count).to eq(1)
|
|
end
|
|
|
|
scenario 'edit invalid ticket', feature: true, js: true do
|
|
visit admin_conference_tickets_path(conference.short_title)
|
|
click_link 'Edit'
|
|
|
|
fill_in 'ticket_title', with: ''
|
|
fill_in 'ticket_price', with: '-5'
|
|
|
|
click_button 'Update Ticket'
|
|
|
|
ticket.reload
|
|
# It's necessary to multiply by 100 because the price is in cents
|
|
expect(ticket.price).to eq(Money.new(100 * 100, 'USD'))
|
|
expect(ticket.title).to eq('Business Ticket')
|
|
expect(flash).to eq("Ticket update failed: Title can't be blank. Price cents must be greater than 0.")
|
|
expect(Ticket.count).to eq(1)
|
|
end
|
|
|
|
scenario 'delete ticket', feature: true, js: true do
|
|
visit admin_conference_tickets_path(conference.short_title)
|
|
click_link 'Delete'
|
|
|
|
expect(flash).to eq('Ticket successfully destroyed.')
|
|
expect(Ticket.count).to eq(0)
|
|
end
|
|
end
|
|
end
|
|
end
|