Merge 003d272e74 into bead2ecff7
This commit is contained in:
commit
29151f8a8d
19 changed files with 384 additions and 15 deletions
|
|
@ -660,6 +660,7 @@ RSpec/AnyInstance:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'spec/controllers/admin/rooms_controller_spec.rb'
|
- 'spec/controllers/admin/rooms_controller_spec.rb'
|
||||||
- 'spec/controllers/admin/sponsorship_levels_controller_spec.rb'
|
- 'spec/controllers/admin/sponsorship_levels_controller_spec.rb'
|
||||||
|
- 'spec/controllers/admin/tickets_controller_spec.rb'
|
||||||
- 'spec/controllers/admin/tracks_controller_spec.rb'
|
- 'spec/controllers/admin/tracks_controller_spec.rb'
|
||||||
- 'spec/controllers/admin/users_controller_spec.rb'
|
- 'spec/controllers/admin/users_controller_spec.rb'
|
||||||
- 'spec/controllers/conference_registration_controller_spec.rb'
|
- 'spec/controllers/conference_registration_controller_spec.rb'
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,30 @@ module Admin
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def give
|
||||||
|
ticket_purchase = @ticket.ticket_purchases.new(gift_ticket_params)
|
||||||
|
recipient = ticket_purchase.user
|
||||||
|
if ticket_purchase.save
|
||||||
|
redirect_to(
|
||||||
|
admin_conference_ticket_path(@conference.short_title, @ticket),
|
||||||
|
notice: "#{recipient.name} was given a #{@ticket.title} ticket."
|
||||||
|
)
|
||||||
|
else
|
||||||
|
redirect_back(
|
||||||
|
fallback_location: admin_conference_ticket_path(@conference.short_title, @ticket),
|
||||||
|
error: "Unable to give #{recipient.name} a #{@ticket.title} ticket: " +
|
||||||
|
ticket_purchase.errors.full_messages.to_sentence
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
if @ticket.destroy
|
if @ticket.destroy
|
||||||
redirect_to admin_conference_tickets_path(conference_id: @conference.short_title),
|
redirect_to admin_conference_tickets_path(conference_id: @conference.short_title),
|
||||||
notice: 'Ticket successfully destroyed.'
|
notice: 'Ticket successfully deleted.'
|
||||||
else
|
else
|
||||||
redirect_to admin_conference_tickets_path(conference_id: @conference.short_title),
|
redirect_to admin_conference_tickets_path(conference_id: @conference.short_title),
|
||||||
error: 'Ticket was successfully destroyed.' \
|
error: 'Deleting ticket failed! ' \
|
||||||
"#{@ticket.errors.full_messages.join('. ')}."
|
"#{@ticket.errors.full_messages.join('. ')}."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -52,7 +69,19 @@ module Admin
|
||||||
private
|
private
|
||||||
|
|
||||||
def ticket_params
|
def ticket_params
|
||||||
params.require(:ticket).permit(:conference, :title, :url, :description, :conference_id, :price_cents, :price_currency, :price, :registration_ticket)
|
params.require(:ticket).permit(
|
||||||
|
:conference, :conference_id,
|
||||||
|
:title, :url, :description,
|
||||||
|
:price_cents, :price_currency, :price,
|
||||||
|
:registration_ticket, :visible
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def gift_ticket_params
|
||||||
|
response = params.require(:ticket_purchase).permit(
|
||||||
|
:user_id
|
||||||
|
)
|
||||||
|
response.merge(paid: true, amount_paid: 0, conference: @conference)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ class ConferenceRegistrationsController < ApplicationController
|
||||||
sign_in(@registration.user)
|
sign_in(@registration.user)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @conference.tickets.any? && !current_user.supports?(@conference)
|
if @conference.tickets.visible.any? && !current_user.supports?(@conference)
|
||||||
redirect_to conference_tickets_path(@conference.short_title),
|
redirect_to conference_tickets_path(@conference.short_title),
|
||||||
notice: 'You are now registered and will be receiving E-Mail notifications.'
|
notice: 'You are now registered and will be receiving E-Mail notifications.'
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ class ConferencesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if splashpage.include_registrations || splashpage.include_tickets
|
if splashpage.include_registrations || splashpage.include_tickets
|
||||||
@tickets = @conference.tickets.order(:price_cents)
|
@tickets = @conference.tickets.visible.order('price_cents')
|
||||||
end
|
end
|
||||||
if splashpage.include_lodgings
|
if splashpage.include_lodgings
|
||||||
@lodgings = @conference.lodgings.order(:name)
|
@lodgings = @conference.lodgings.order(:name)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@
|
||||||
class TicketsController < ApplicationController
|
class TicketsController < ApplicationController
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
load_resource :conference, find_by: :short_title
|
load_resource :conference, find_by: :short_title
|
||||||
load_resource :ticket, through: :conference
|
before_action :load_tickets
|
||||||
|
authorize_resource :ticket, through: :conference
|
||||||
authorize_resource :conference_registrations, class: Registration
|
authorize_resource :conference_registrations, class: Registration
|
||||||
before_action :check_load_resource, only: :index
|
before_action :check_load_resource, only: :index
|
||||||
|
|
||||||
|
|
@ -14,4 +15,8 @@ class TicketsController < ApplicationController
|
||||||
redirect_to root_path, notice: "There are no tickets available for #{@conference.title}!"
|
redirect_to root_path, notice: "There are no tickets available for #{@conference.title}!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_tickets
|
||||||
|
@tickets = @conference.tickets.visible
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,10 @@ class Ability
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
can :index, Ticket
|
can :index, Organization
|
||||||
|
can :index, Ticket do |ticket|
|
||||||
|
ticket.visible
|
||||||
|
end
|
||||||
can :manage, TicketPurchase, user_id: user.id
|
can :manage, TicketPurchase, user_id: user.id
|
||||||
can [:new, :create], Payment, user_id: user.id
|
can [:new, :create], Payment, user_id: user.id
|
||||||
can [:index, :show], PhysicalTicket, user: user
|
can [:index, :show], PhysicalTicket, user: user
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ class Ticket < ApplicationRecord
|
||||||
|
|
||||||
validates :price_cents, numericality: { greater_than_or_equal_to: 0 }
|
validates :price_cents, numericality: { greater_than_or_equal_to: 0 }
|
||||||
|
|
||||||
|
scope :visible, -> { where(visible: true) }
|
||||||
|
|
||||||
def bought?(user)
|
def bought?(user)
|
||||||
buyers.include?(user)
|
buyers.include?(user)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class TicketPurchase < ApplicationRecord
|
||||||
errors.push('You cannot buy more than one registration tickets.')
|
errors.push('You cannot buy more than one registration tickets.')
|
||||||
else
|
else
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
conference.tickets.each do |ticket|
|
conference.tickets.visible.each do |ticket|
|
||||||
quantity = purchases[ticket.id.to_s].to_i
|
quantity = purchases[ticket.id.to_s].to_i
|
||||||
# if the user bought the ticket and is still unpaid, just update the quantity
|
# if the user bought the ticket and is still unpaid, just update the quantity
|
||||||
purchase = if ticket.bought?(user) && ticket.unpaid?(user)
|
purchase = if ticket.bought?(user) && ticket.unpaid?(user)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
<<<<<<< HEAD
|
||||||
= form_for(@ticket, url: (@ticket.new_record? ? admin_conference_tickets_path : admin_conference_ticket_path(@conference.short_title, @ticket))) do |f|
|
= form_for(@ticket, url: (@ticket.new_record? ? admin_conference_tickets_path : admin_conference_ticket_path(@conference.short_title, @ticket))) do |f|
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :title
|
= f.label :title
|
||||||
|
|
@ -21,5 +22,8 @@
|
||||||
%label
|
%label
|
||||||
= f.check_box :registration_ticket
|
= f.check_box :registration_ticket
|
||||||
A registration ticket is with which user register for the conference.
|
A registration ticket is with which user register for the conference.
|
||||||
|
%label
|
||||||
|
= f.check_box :visible
|
||||||
|
Only visible tickets are available to registrants. Non-visible tickets can only be managed by Admins.
|
||||||
%p.text-right
|
%p.text-right
|
||||||
= f.submit nil, class: 'btn btn-primary'
|
= f.submit nil, class: 'btn btn-primary'
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
%th Sold
|
%th Sold
|
||||||
%th Turnover
|
%th Turnover
|
||||||
%th Registration Ticket
|
%th Registration Ticket
|
||||||
|
%th Visible?
|
||||||
%th Actions
|
%th Actions
|
||||||
%tbody
|
%tbody
|
||||||
- @conference.tickets.each do |ticket|
|
- @conference.tickets.each do |ticket|
|
||||||
|
|
@ -31,6 +32,8 @@
|
||||||
= humanized_money_with_symbol ticket.tickets_turnover_total(ticket.id)
|
= humanized_money_with_symbol ticket.tickets_turnover_total(ticket.id)
|
||||||
%td
|
%td
|
||||||
= ticket.registration_ticket? ? 'Yes' : 'No'
|
= ticket.registration_ticket? ? 'Yes' : 'No'
|
||||||
|
%td
|
||||||
|
= ticket.visible? ? 'Yes' : 'No'
|
||||||
%td
|
%td
|
||||||
.btn-group
|
.btn-group
|
||||||
= link_to 'Edit', edit_admin_conference_ticket_path(@conference.short_title, ticket.id),
|
= link_to 'Edit', edit_admin_conference_ticket_path(@conference.short_title, ticket.id),
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,12 @@
|
||||||
%small
|
%small
|
||||||
= humanized_money_with_symbol @ticket.price
|
= humanized_money_with_symbol @ticket.price
|
||||||
= link_to 'Edit Ticket', edit_admin_conference_ticket_path, class: 'btn btn-primary pull-right'
|
= link_to 'Edit Ticket', edit_admin_conference_ticket_path, class: 'btn btn-primary pull-right'
|
||||||
|
- if can? :give, Ticket
|
||||||
|
.pull-right
|
||||||
|
= link_to 'Give a Ticket', '#',
|
||||||
|
data: { toggle: 'modal', target: "#modal-give-ticket-#{@ticket.id}" },
|
||||||
|
class: 'button btn btn-default btn-info'
|
||||||
|
|
||||||
%p.text-muted
|
%p.text-muted
|
||||||
People who bought this ticket
|
People who bought this ticket
|
||||||
.row
|
.row
|
||||||
|
|
@ -36,3 +42,26 @@
|
||||||
= buyer.affiliation
|
= buyer.affiliation
|
||||||
%td
|
%td
|
||||||
= @ticket.tickets_paid(buyer)
|
= @ticket.tickets_paid(buyer)
|
||||||
|
|
||||||
|
- content_for :modals do
|
||||||
|
.modal.fade{ id: "modal-give-ticket-#{@ticket.id}" }
|
||||||
|
.modal-dialog
|
||||||
|
.modal-content
|
||||||
|
= semantic_form_for(@ticket.ticket_purchases.new,
|
||||||
|
url: give_admin_conference_ticket_path(@conference, @ticket)) do |f|
|
||||||
|
.modal-header
|
||||||
|
%button.close{ data: { dismiss: 'modal' } }
|
||||||
|
%i.fa.fa-close
|
||||||
|
%h3.modal-title
|
||||||
|
Give a
|
||||||
|
= @ticket.title
|
||||||
|
Ticket
|
||||||
|
.modal-body
|
||||||
|
= user_selector_input(:user, f, '', false)
|
||||||
|
.modal-footer
|
||||||
|
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }
|
||||||
|
|
||||||
|
:javascript
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('#ticket_purchase_user_id').selectize({})
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@
|
||||||
= link_to event.title, conference_program_proposal_path(@conference.short_title, event.id)
|
= link_to event.title, conference_program_proposal_path(@conference.short_title, event.id)
|
||||||
= '(' + registered_text(event) + ')'
|
= '(' + registered_text(event) + ')'
|
||||||
|
|
||||||
- if @conference.tickets.any?
|
- if @conference.tickets.visible.any?
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
%h4
|
%h4
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@
|
||||||
%th Price
|
%th Price
|
||||||
%th Total
|
%th Total
|
||||||
%tbody
|
%tbody
|
||||||
- @conference.tickets.each do |ticket|
|
- @conference.tickets.visible.each do |ticket|
|
||||||
= render 'ticket', f: f, ticket: ticket
|
= render partial: 'ticket', f: f, locals: {ticket: ticket}
|
||||||
%tr
|
%tr
|
||||||
%td
|
%td
|
||||||
- if @conference.tickets.for_registration.any?
|
- if @conference.tickets.for_registration.any?
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,11 @@ Osem::Application.routes.draw do
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :resources
|
resources :resources
|
||||||
resources :tickets
|
resources :tickets do
|
||||||
|
member do
|
||||||
|
post :give
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :sponsors, except: [:show]
|
resources :sponsors, except: [:show]
|
||||||
resources :lodgings, except: [:show]
|
resources :lodgings, except: [:show]
|
||||||
resources :emails, only: [:show, :update, :index]
|
resources :emails, only: [:show, :update, :index]
|
||||||
|
|
|
||||||
11
db/migrate/20180409170433_add_visible_to_tickets.rb
Normal file
11
db/migrate/20180409170433_add_visible_to_tickets.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
class AddVisibleToTickets < ActiveRecord::Migration[5.0]
|
||||||
|
def up
|
||||||
|
add_column :tickets, :visible, :boolean, default: true
|
||||||
|
Ticket.reset_column_information
|
||||||
|
Ticket.update_all(visible: true) # rubocop:disable Rails/SkipsModelValidations
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
remove_column :tickets, :visible
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -522,6 +522,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_11_21_114727) do
|
||||||
t.boolean "registration_ticket", default: false
|
t.boolean "registration_ticket", default: false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.boolean "visible", default: true
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "tracks", force: :cascade do |t|
|
create_table "tracks", force: :cascade do |t|
|
||||||
|
|
|
||||||
247
spec/controllers/admin/tickets_controller_spec.rb
Normal file
247
spec/controllers/admin/tickets_controller_spec.rb
Normal file
|
|
@ -0,0 +1,247 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Admin::TicketsController do
|
||||||
|
let(:admin) { create(:admin) }
|
||||||
|
let(:conference) { create(:conference) }
|
||||||
|
let!(:ticket) { create(:ticket, conference: conference) }
|
||||||
|
let(:new_title) { Faker::Hipster.sentence }
|
||||||
|
|
||||||
|
context 'admin is signed in' do
|
||||||
|
before { sign_in admin }
|
||||||
|
|
||||||
|
describe 'GET #index' do
|
||||||
|
before { get :index, conference_id: conference }
|
||||||
|
|
||||||
|
it 'assigns conference and tickets variables via cancancan' do
|
||||||
|
expect(assigns(:conference)).to eq conference
|
||||||
|
expect(assigns(:tickets)).to eq conference.tickets
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders index template' do
|
||||||
|
expect(response).to render_template('index')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'GET #edit' do
|
||||||
|
before { get :edit, conference_id: conference, id: ticket }
|
||||||
|
|
||||||
|
it 'assigns ticket variable via cancancan' do
|
||||||
|
expect(assigns(:ticket)).to eq ticket
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders edit template' do
|
||||||
|
expect(response).to render_template('edit')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'GET #new' do
|
||||||
|
before { get :new, conference_id: conference }
|
||||||
|
|
||||||
|
it 'assigns ticket variable' do
|
||||||
|
expect(assigns(:ticket)).to be_instance_of(Ticket)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders new template' do
|
||||||
|
expect(response).to render_template('new')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'POST #create' do
|
||||||
|
context 'saves successfuly' do
|
||||||
|
before(:each, run: true) do
|
||||||
|
post :create, conference_id: conference, ticket: attributes_for(:ticket)
|
||||||
|
end
|
||||||
|
|
||||||
|
let!(:ticket_count) { conference.tickets.count }
|
||||||
|
|
||||||
|
it 'redirects to index path', run: true do
|
||||||
|
expect(response).to redirect_to(
|
||||||
|
admin_conference_tickets_path(conference_id: conference)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows success message in flash notice', run: true do
|
||||||
|
expect(flash[:notice]).to match('Ticket successfully created.')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates new ticket' do
|
||||||
|
expect do
|
||||||
|
post :create, ticket: attributes_for(:ticket),
|
||||||
|
conference_id: conference
|
||||||
|
end.to change{ conference.tickets.count }.from(ticket_count).to(ticket_count + 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'save fails' do
|
||||||
|
before do
|
||||||
|
allow_any_instance_of(Ticket).to receive(:save).and_return(false)
|
||||||
|
post :create, conference_id: conference, ticket: attributes_for(:ticket)
|
||||||
|
end
|
||||||
|
|
||||||
|
let!(:ticket_count) { conference.tickets.count }
|
||||||
|
|
||||||
|
it 'renders new template' do
|
||||||
|
expect(response).to render_template('new')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows error in flash message' do
|
||||||
|
expect(flash[:error]).to match("Creating Ticket failed: #{ticket.errors.full_messages.join('. ')}.")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not create new ticket' do
|
||||||
|
expect(conference.tickets.count).to eq ticket_count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'PATCH #update' do
|
||||||
|
context 'updates successfully' do
|
||||||
|
before do
|
||||||
|
patch :update, conference_id: conference, id: ticket,
|
||||||
|
ticket: attributes_for(:ticket, title: new_title)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects to index path' do
|
||||||
|
expect(response).to redirect_to(
|
||||||
|
admin_conference_tickets_path(conference_id: conference)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows success message in flash notice' do
|
||||||
|
expect(flash[:notice]).to match('Ticket successfully updated.')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'updates the ticket' do
|
||||||
|
ticket.reload
|
||||||
|
expect(ticket.title).to eq(new_title)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'update fails' do
|
||||||
|
before do
|
||||||
|
allow_any_instance_of(Ticket).to receive(:save).and_return(false)
|
||||||
|
patch :update, conference_id: conference, id: ticket,
|
||||||
|
ticket: attributes_for(:ticket, title: new_title)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders edit template' do
|
||||||
|
expect(response).to render_template('edit')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows error in flash message' do
|
||||||
|
expect(flash[:error]).to match("Ticket update failed: #{ticket.errors.full_messages.join('. ')}.")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not update ticket' do
|
||||||
|
ticket.reload
|
||||||
|
expect(ticket.title).not_to eq(new_title)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'DELETE #destroy' do
|
||||||
|
context 'deletes successfully' do
|
||||||
|
before(:each, run: true) do
|
||||||
|
delete :destroy, conference_id: conference, id: ticket
|
||||||
|
end
|
||||||
|
|
||||||
|
let!(:ticket_count) { conference.tickets.count }
|
||||||
|
|
||||||
|
it 'redirects to index path', run: true do
|
||||||
|
expect(response).to redirect_to(
|
||||||
|
admin_conference_tickets_path(conference_id: conference)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows success message in flash notice', run: true do
|
||||||
|
expect(flash[:notice]).to match('Ticket successfully deleted.')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'deletes the ticket' do
|
||||||
|
expect do
|
||||||
|
delete :destroy, conference_id: conference, id: ticket
|
||||||
|
end.to change{ conference.tickets.count }.from(ticket_count).to(ticket_count - 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'delete fails' do
|
||||||
|
let!(:ticket_count) { conference.tickets.count }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow_any_instance_of(Ticket).to receive(:destroy).and_return(false)
|
||||||
|
delete :destroy, conference_id: conference, id: ticket
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects to index path' do
|
||||||
|
expect(response).to redirect_to(
|
||||||
|
admin_conference_tickets_path(conference_id: conference)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows error in flash message' do
|
||||||
|
expect(flash[:error]).to match("Deleting ticket failed! #{ticket.errors.full_messages.join('. ')}.")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not delete ticket' do
|
||||||
|
expect(conference.tickets.count).to eq(ticket_count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'POST #give' do
|
||||||
|
context 'grants a ticket purchase to a user' do
|
||||||
|
let!(:purchase_count) { admin.ticket_purchases.count }
|
||||||
|
|
||||||
|
before do
|
||||||
|
post :give, conference_id: conference, id: ticket,
|
||||||
|
ticket_purchase: { user_id: admin.id }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects to ticket' do
|
||||||
|
expect(response).to redirect_to(
|
||||||
|
admin_conference_ticket_path(conference_id: conference, id: ticket)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows success message in flash notice' do
|
||||||
|
expect(flash[:notice]).to match(
|
||||||
|
"#{admin.name} was given a #{ticket.title} ticket."
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a ticket purchase' do
|
||||||
|
expect(admin.ticket_purchases.count).to eq(purchase_count + 1)
|
||||||
|
expect(admin.ticket_purchases.last.ticket).to eq(ticket)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'giving fails' do
|
||||||
|
before do
|
||||||
|
allow_any_instance_of(TicketPurchase).to receive(:save).and_return(false)
|
||||||
|
post :give, conference_id: conference, id: ticket,
|
||||||
|
ticket_purchase: { user_id: admin.id }
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:purchase_count) { admin.ticket_purchases.count }
|
||||||
|
|
||||||
|
it 'redirects to ticket' do
|
||||||
|
expect(response).to redirect_to(
|
||||||
|
admin_conference_ticket_path(conference_id: conference, id: ticket)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows error in flash message' do
|
||||||
|
expect(flash[:error]).to match(
|
||||||
|
"Unable to give #{admin.name} a #{ticket.title} ticket: "
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not create a ticket purchase' do
|
||||||
|
expect(admin.ticket_purchases.count).to eq(purchase_count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -5,6 +5,7 @@ FactoryBot.define do
|
||||||
title { "#{Faker::Hipster.word} Ticket" }
|
title { "#{Faker::Hipster.word} Ticket" }
|
||||||
price_cents { 1000 }
|
price_cents { 1000 }
|
||||||
price_currency { 'USD' }
|
price_currency { 'USD' }
|
||||||
|
visible { true }
|
||||||
factory :registration_ticket do
|
factory :registration_ticket do
|
||||||
registration_ticket { true }
|
registration_ticket { true }
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ feature Ticket do
|
||||||
sign_out
|
sign_out
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'add a valid ticket', feature: true, js: true do
|
scenario 'add a valid ticket', feature: true do
|
||||||
visit admin_conference_tickets_path(conference.short_title)
|
visit admin_conference_tickets_path(conference.short_title)
|
||||||
click_link 'Add Ticket'
|
click_link 'Add Ticket'
|
||||||
|
|
||||||
|
|
@ -29,10 +29,39 @@ feature Ticket do
|
||||||
expect(Ticket.count).to eq(2)
|
expect(Ticket.count).to eq(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'add a invalid ticket', feature: 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'
|
||||||
|
page.find('#flash')
|
||||||
|
expect(flash).to eq("Creating Ticket failed: Title can't be blank. Price cents must be greater than or equal to 0.")
|
||||||
|
expect(Ticket.count).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'add a hidden ticket', feature: true do
|
||||||
|
visit admin_conference_tickets_path(conference.short_title)
|
||||||
|
click_link 'Add Ticket'
|
||||||
|
|
||||||
|
fill_in 'ticket_title', with: 'Hidden Ticket'
|
||||||
|
fill_in 'ticket_description', with: 'The hidden ticket'
|
||||||
|
fill_in 'ticket_price', with: '100'
|
||||||
|
uncheck 'ticket_visible'
|
||||||
|
|
||||||
|
click_button 'Create Ticket'
|
||||||
|
page.find('#flash')
|
||||||
|
expect(flash).to eq('Ticket successfully created.')
|
||||||
|
expect(Ticket.count).to eq(2)
|
||||||
|
expect(Ticket.visible.count).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
context 'Ticket already created' do
|
context 'Ticket already created' do
|
||||||
let!(:ticket) { create(:ticket, title: 'Business Ticket', price: 100, conference_id: conference.id) }
|
let!(:ticket) { create(:ticket, title: 'Business Ticket', price: 100, conference_id: conference.id) }
|
||||||
|
|
||||||
scenario 'edit valid ticket', feature: true, js: true do
|
scenario 'edit valid ticket', feature: true do
|
||||||
visit admin_conference_tickets_path(conference.short_title)
|
visit admin_conference_tickets_path(conference.short_title)
|
||||||
click_link('Edit', href: edit_admin_conference_ticket_path(conference.short_title, ticket.id))
|
click_link('Edit', href: edit_admin_conference_ticket_path(conference.short_title, ticket.id))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue