From dd52a9b2ab0b78708a7b23fba061a0fc0f730b38 Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Fri, 30 Jun 2017 05:26:21 +0530 Subject: [PATCH] Make ticket layout configurable Added option for conference organizer to switch between ticket layouts (horizontal or vertical). Added test for the same. --- .../admin/conferences_controller.rb | 2 +- app/controllers/physical_ticket_controller.rb | 1 + app/models/conference.rb | 3 +++ app/views/admin/conferences/edit.html.haml | 1 + app/views/physical_ticket/show.pdf.prawn | 2 +- ...232817_add_ticket_layout_to_conferences.rb | 5 +++++ db/schema.rb | 1 + .../physical_ticket_controller_spec.rb | 20 +++++++++++++++++++ spec/factories/conferences.rb | 1 + spec/models/conference_spec.rb | 4 ++++ 10 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20170629232817_add_ticket_layout_to_conferences.rb create mode 100644 spec/controllers/physical_ticket_controller_spec.rb diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index f8c9ea19..6716a253 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -211,7 +211,7 @@ module Admin :vpositions_attributes, :use_volunteers, :color, :sponsorship_levels_attributes, :sponsors_attributes, :targets, :targets_attributes, - :campaigns, :campaigns_attributes, :registration_limit, :organization_id) + :campaigns, :campaigns_attributes, :registration_limit, :organization_id, :ticket_layout) end end end diff --git a/app/controllers/physical_ticket_controller.rb b/app/controllers/physical_ticket_controller.rb index 09b38ff2..8617e0d9 100644 --- a/app/controllers/physical_ticket_controller.rb +++ b/app/controllers/physical_ticket_controller.rb @@ -12,5 +12,6 @@ class PhysicalTicketController < ApplicationController def show @file_name = "ticket_for_#{@conference.short_title}" @user = @physical_ticket.user + @ticket_layout = @conference.ticket_layout.to_sym end end diff --git a/app/models/conference.rb b/app/models/conference.rb index 11fab753..cf94b334 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -57,6 +57,7 @@ class Conference < ActiveRecord::Base :end_date, :start_hour, :end_hour, + :ticket_layout, :organization, presence: true validates :short_title, uniqueness: true @@ -73,6 +74,8 @@ class Conference < ActiveRecord::Base after_create :create_free_ticket after_update :delete_event_schedules + enum ticket_layout: [:portrait, :landscape] + ## # Checks if the user is registered to the conference # diff --git a/app/views/admin/conferences/edit.html.haml b/app/views/admin/conferences/edit.html.haml index 5aa717ea..2d5df126 100644 --- a/app/views/admin/conferences/edit.html.haml +++ b/app/views/admin/conferences/edit.html.haml @@ -17,6 +17,7 @@ = image_tag @conference.picture.thumb.url = f.input :picture, label: false, hint: 'This will be displayed on the front page.' = f.hidden_field :picture_cache + = f.input :ticket_layout, as: :select, collection: Conference.ticket_layouts.keys, hint: "Layout type for tickets of the conference." = f.inputs name: 'Scheduling' do = f.input :timezone, as: :time_zone, hint: 'The conference time zone' = f.input :start_date, as: :string, input_html: { id: 'conference-start-datepicker', readonly: 'readonly' } diff --git a/app/views/physical_ticket/show.pdf.prawn b/app/views/physical_ticket/show.pdf.prawn index 90f11fd5..92206baf 100644 --- a/app/views/physical_ticket/show.pdf.prawn +++ b/app/views/physical_ticket/show.pdf.prawn @@ -1,4 +1,4 @@ -prawn_document(filename: @file_name, page_layout: :portrait, :page_size =>'A4' ) do |pdf| +prawn_document(filename: @file_name, page_layout: @ticket_layout, :page_size =>'A4' ) do |pdf| # Vertical Layout top = pdf.bounds.top bottom = pdf.bounds.bottom diff --git a/db/migrate/20170629232817_add_ticket_layout_to_conferences.rb b/db/migrate/20170629232817_add_ticket_layout_to_conferences.rb new file mode 100644 index 00000000..c07f85c3 --- /dev/null +++ b/db/migrate/20170629232817_add_ticket_layout_to_conferences.rb @@ -0,0 +1,5 @@ +class AddTicketLayoutToConferences < ActiveRecord::Migration + def change + add_column :conferences, :ticket_layout, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 2e2fb088..4a9cc724 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -105,6 +105,7 @@ ActiveRecord::Schema.define(version: 20170629162450) do t.integer "start_hour", default: 9 t.integer "end_hour", default: 20 t.integer "organization_id" + t.integer "ticket_layout", default: 0 end add_index "conferences", ["organization_id"], name: "index_conferences_on_organization_id" diff --git a/spec/controllers/physical_ticket_controller_spec.rb b/spec/controllers/physical_ticket_controller_spec.rb new file mode 100644 index 00000000..7a430479 --- /dev/null +++ b/spec/controllers/physical_ticket_controller_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe PhysicalTicketController do + 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) } + + describe 'GET #show' do + before :each do + sign_in user + get :show, id: physical_ticket.id, conference_id: conference.short_title + end + + it 'assigns ticket_layout' do + ticket_layout = conference.ticket_layout.to_sym + expect(assigns(:ticket_layout)).to eq ticket_layout + end + end +end diff --git a/spec/factories/conferences.rb b/spec/factories/conferences.rb index e1ef7d84..1e4d8551 100644 --- a/spec/factories/conferences.rb +++ b/spec/factories/conferences.rb @@ -10,6 +10,7 @@ FactoryGirl.define do start_hour 9 end_hour 20 registration_limit 0 + ticket_layout 'portrait' description { Faker::Hipster.paragraph } organization after(:create) do |conference| diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index d6e4f485..eaef9293 100755 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -1573,6 +1573,10 @@ describe Conference do should validate_presence_of(:end_hour) end + it 'is not valid without a ticket_layout' do + should validate_presence_of(:ticket_layout) + end + it 'is not valid with a duplicate short title' do should validate_uniqueness_of(:short_title) end