Skip to content

Commit

Permalink
Merge pull request #1634 from siddhantbajaj/admin-registration
Browse files Browse the repository at this point in the history
Registration tickets to be set before registration period
  • Loading branch information
Ana06 committed Aug 22, 2017
2 parents 84522a9 + 157c270 commit 4c1b56b
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/models/admin_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ def signed_in_with_organizer_role(user, conf_ids_for_organization_admin = [])
can :manage, Commercial, commercialable_type: 'Conference',
commercialable_id: conf_ids
can :manage, Registration, conference_id: conf_ids
can :manage, RegistrationPeriod, conference_id: conf_ids
can :manage, RegistrationPeriod do |registration_period|
conference = registration_period.conference
conf_ids.include?(conference.id) && conference.tickets.for_registration.any?
end
can :manage, Booth, conference_id: conf_ids
can :manage, Question, conference_id: conf_ids
can :manage, Question do |question|
Expand Down
6 changes: 5 additions & 1 deletion app/models/conference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ class Conference < ActiveRecord::Base
has_many :ticket_purchases, dependent: :destroy
has_many :payments, dependent: :destroy
has_many :supporters, through: :ticket_purchases, source: :user
has_many :tickets, dependent: :destroy
has_many :tickets, dependent: :destroy do
def for_registration
where(registration_ticket: true)
end
end
has_many :resources, dependent: :destroy
has_many :booths, dependent: :destroy

Expand Down
11 changes: 9 additions & 2 deletions app/views/admin/registration_periods/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,12 @@
= link_to 'Delete', admin_conference_registration_period_path,
method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger'
- else
- if can? :create, @conference.build_registration_period
= link_to 'New Registration Period', new_admin_conference_registration_period_path, class: 'btn btn-primary'
- unless @conference.tickets.for_registration.empty?
- if can? :create, @conference.build_registration_period
= link_to 'New Registration Period', new_admin_conference_registration_period_path, class: 'btn btn-primary'
- else
.h3.text-left
No Registration Tickets!
%small
= link_to 'Create registration tickets', new_admin_conference_ticket_path
before creating the registration period.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# It is necessary to use bang version of let to build roles before user
let(:conference) { create(:conference) }
let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) }

let!(:registration_ticket) { create(:registration_ticket, conference: conference) }
let(:organizer) { create(:user, role_ids: organizer_role.id) }
let(:organizer2) { create(:user, email: 'organizer2@email.osem', role_ids: organizer_role.id) }
let(:participant) { create(:user) }
Expand Down
3 changes: 3 additions & 0 deletions spec/factories/tickets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
title { "#{Faker::Hipster.word} Ticket" }
price_cents 1000
price_currency 'USD'
factory :registration_ticket do
registration_ticket true
end
end
end
1 change: 1 addition & 0 deletions spec/features/organization_admin_ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
let(:conference) { create(:full_conference, organization: organization) }
let(:role_organization_admin) { Role.find_by(name: 'organization_admin', resource: organization) }
let(:user_organization_admin) { create(:user, role_ids: [role_organization_admin.id]) }
let!(:registration_ticket) { create(:registration_ticket, conference: conference) }

context 'when user is organization_admin' do
before do
Expand Down
1 change: 1 addition & 0 deletions spec/features/organizer_ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
let(:role_organizer_conf) { Role.find_by(name: 'organizer', resource: conference) }
let(:role_organizer_other_conf) { Role.find_by(name: 'organizer', resource: other_conference) }
let(:user_organizer) { create(:user, role_ids: [role_organizer_conf.id, role_organizer_other_conf.id]) }
let!(:registration_ticket) { create(:registration_ticket, conference: conference) }

context 'when user is organizer' do
before do
Expand Down
1 change: 1 addition & 0 deletions spec/features/registration_periods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
let!(:conference) { create(:conference) }
let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) }
let!(:organizer) { create(:user, email: 'admin@example.com', role_ids: [organizer_role.id]) }
let!(:registration_ticket) { create(:registration_ticket, conference: conference) }

shared_examples 'successfully' do
scenario 'create and update registration period', js: true do
Expand Down
1 change: 1 addition & 0 deletions spec/models/admin_ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

let!(:organization) { create(:organization) }
let!(:my_conference) { create(:full_conference, organization: organization) }
let!(:registration_ticket) { create(:registration_ticket, conference: my_conference) }
let(:my_venue) { my_conference.venue || create(:venue, conference: my_conference) }
let(:my_registration) { create(:registration, conference: my_conference, user: admin) }

Expand Down
1 change: 1 addition & 0 deletions spec/models/registration_period_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

describe RegistrationPeriod do
let!(:conference) { create(:conference, start_date: Date.today, end_date: Date.today + 6) }
let!(:registration_ticket) { create(:registration_ticket, conference: conference) }
let!(:registration_period) { create(:registration_period, start_date: Date.today - 2, end_date: Date.today - 1, conference: conference) }

describe 'validations' do
Expand Down

0 comments on commit 4c1b56b

Please sign in to comment.