commit
3f324d4e6f
4 changed files with 85 additions and 0 deletions
16
app/controllers/admin/ticket_scannings_controller.rb
Normal file
16
app/controllers/admin/ticket_scannings_controller.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
module Admin
|
||||||
|
class TicketScanningsController < Admin::BaseController
|
||||||
|
before_action :authenticate_user!
|
||||||
|
load_resource :physical_ticket, find_by: :token
|
||||||
|
# We authorize manually in these actions
|
||||||
|
skip_authorize_resource only: [:create]
|
||||||
|
|
||||||
|
def create
|
||||||
|
@ticket_scanning = TicketScanning.new(physical_ticket: @physical_ticket)
|
||||||
|
authorize! :create, @ticket_scanning
|
||||||
|
@ticket_scanning.save
|
||||||
|
redirect_to conferences_path,
|
||||||
|
notice: "Ticket with token #{@physical_ticket.token} successfully scanned."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -144,6 +144,10 @@ class AdminAbility
|
||||||
can :manage, Sponsor, conference_id: conf_ids
|
can :manage, Sponsor, conference_id: conf_ids
|
||||||
can :manage, SponsorshipLevel, conference_id: conf_ids
|
can :manage, SponsorshipLevel, conference_id: conf_ids
|
||||||
can :manage, Ticket, conference_id: conf_ids
|
can :manage, Ticket, conference_id: conf_ids
|
||||||
|
can :create, TicketScanning do |ticket_scanning|
|
||||||
|
conf_id = ticket_scanning.physical_ticket.ticket_purchase.conference_id
|
||||||
|
conf_ids.include? conf_id
|
||||||
|
end
|
||||||
can :index, Comment, commentable_type: 'Event',
|
can :index, Comment, commentable_type: 'Event',
|
||||||
commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids).pluck(:id)).pluck(:id)
|
commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids).pluck(:id)).pluck(:id)
|
||||||
|
|
||||||
|
|
@ -219,6 +223,10 @@ class AdminAbility
|
||||||
can :manage, Question do |question|
|
can :manage, Question do |question|
|
||||||
!(question.conferences.pluck(:id) & conf_ids_for_info_desk).empty?
|
!(question.conferences.pluck(:id) & conf_ids_for_info_desk).empty?
|
||||||
end
|
end
|
||||||
|
can :create, TicketScanning do |ticket_scanning|
|
||||||
|
conf_id = ticket_scanning.physical_ticket.ticket_purchase.conference_id
|
||||||
|
conf_ids_for_info_desk.include? conf_id
|
||||||
|
end
|
||||||
|
|
||||||
# Abilities for Role (Conference resource)
|
# Abilities for Role (Conference resource)
|
||||||
can [:index, :show], Role do |role|
|
can [:index, :show], Role do |role|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ Osem::Application.routes.draw do
|
||||||
patch :toggle_confirmation
|
patch :toggle_confirmation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
resource :ticket_scanning, only: [:create]
|
||||||
resources :comments, only: [:index]
|
resources :comments, only: [:index]
|
||||||
resources :conferences do
|
resources :conferences do
|
||||||
resource :contact, except: [:index, :new, :create, :show, :destroy]
|
resource :contact, except: [:index, :new, :create, :show, :destroy]
|
||||||
|
|
|
||||||
60
spec/controllers/admin/ticket_scannings_controller_spec.rb
Normal file
60
spec/controllers/admin/ticket_scannings_controller_spec.rb
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Admin::TicketScanningsController do
|
||||||
|
let(:admin) { create(:admin) }
|
||||||
|
let(:conference) { create(:conference) }
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
let(:paid_ticket_purchase) { create(:ticket_purchase, conference: conference, user: user) }
|
||||||
|
let(:physical_ticket) { create(:physical_ticket, ticket_purchase: paid_ticket_purchase) }
|
||||||
|
|
||||||
|
context 'logged in as user with no role' do
|
||||||
|
before :each do
|
||||||
|
sign_in user
|
||||||
|
end
|
||||||
|
describe 'POST #create' do
|
||||||
|
it 'does not create new ticket scanning' do
|
||||||
|
expected = expect do
|
||||||
|
post :create, physical_ticket_id: physical_ticket.token
|
||||||
|
end
|
||||||
|
expected.to_not change(TicketScanning, :count)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects to root' do
|
||||||
|
post :create, physical_ticket_id: physical_ticket.token
|
||||||
|
expect(flash[:alert]).to eq('You are not authorized to access this page.')
|
||||||
|
expect(response).to redirect_to(root_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'logged in as admin' do
|
||||||
|
before :each do
|
||||||
|
sign_in admin
|
||||||
|
end
|
||||||
|
describe 'POST #create' do
|
||||||
|
context 'with valid physical_ticket' do
|
||||||
|
it 'creates new ticket scanning' do
|
||||||
|
expected = expect do
|
||||||
|
post :create, physical_ticket_id: physical_ticket.token
|
||||||
|
end
|
||||||
|
expected.to change { TicketScanning.count }.by(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects to index' do
|
||||||
|
post :create, physical_ticket_id: physical_ticket.token
|
||||||
|
expect(flash[:notice]).to eq("Ticket with token #{physical_ticket.token} successfully scanned.")
|
||||||
|
expect(response).to redirect_to(conferences_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with Invalid physical_ticket' do
|
||||||
|
it 'raises exception' do
|
||||||
|
expected = expect do
|
||||||
|
post :create, physical_ticket_id: 'XXXX'
|
||||||
|
end
|
||||||
|
expected.to raise_exception(ActiveRecord::RecordNotFound)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue