From cce3ff7aea589d18d4da96acda3341afbaf024a3 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Wed, 7 Jun 2017 11:11:29 +0530 Subject: [PATCH] creating default organization while creating a conference --- app/controllers/admin/conferences_controller.rb | 14 +++++++++++--- app/views/admin/conferences/new.html.haml | 2 ++ spec/models/conference_spec.rb | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index f9e1177d..c6d54f04 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -72,11 +72,19 @@ module Admin def new @conference = Conference.new + @organizations = {} + Organization.all.each do |organization| + @organizations.store(organization.name, organization.id) if can? :create, Conference.new(organization: organization) + end end def create - @conference = Conference.new(conference_params) - + conference_params_copy = conference_params + if ENV['ORGANIZATIONS_ENABLED'] != 'true' + org = Organization.exists?(name: 'default') ? Organization.find_by(name: 'default') : Organization.create(name: 'default') + conference_params_copy[:organization_id] = org.id + end + @conference = Conference.new(conference_params_copy) if @conference.save # user that creates the conference becomes organizer of that conference current_user.add_role :organizer, @conference @@ -211,7 +219,7 @@ module Admin :vpositions_attributes, :use_volunteers, :color, :sponsorship_levels_attributes, :sponsors_attributes, :targets, :targets_attributes, - :campaigns, :campaigns_attributes, :registration_limit) + :campaigns, :campaigns_attributes, :registration_limit, :organization_id) end end end diff --git a/app/views/admin/conferences/new.html.haml b/app/views/admin/conferences/new.html.haml index 014758de..7f414563 100644 --- a/app/views/admin/conferences/new.html.haml +++ b/app/views/admin/conferences/new.html.haml @@ -6,6 +6,8 @@ input_html: { required: 'required' } = f.input :short_title, hint: "A short and unique handle for your conference, using only letters, numbers, underscores, and dashes. This will be used to identify your conference in URLs etc. Example: 'froscon2011'", input_html: { required: 'required', pattern: '[a-zA-Z0-9_-]+', title: 'Only letters, numbers, underscores, and dashes.' }, prepend: conferences_url + '/' + - if ENV['ORGANIZATIONS_ENABLED'] == 'true' + = f.input :organization, as: :select, collection: @organizations = f.inputs 'Scheduling' do = f.input :timezone, as: :time_zone, default: Time.zone.name, hint: 'Please select in what time zone your conference will take place.' = f.input :start_date, as: :string, input_html: { id: 'conference-start-datepicker', required: 'required' } diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index b5a6d5f0..9bdbea83 100755 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -1630,7 +1630,7 @@ describe Conference do end describe 'after_create' do - let(:conference) { Conference.new(title: 'ABC', short_title: 'XYZ', start_date: Date.today, end_date: Date.today + 10, timezone: 'GMT') } + let(:conference) { create(:conference) } it 'calls back to create free ticket' do conference.save