From b9e10922ee15e1070f3c45e21513d20af401e71f Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Wed, 23 Mar 2016 17:18:51 +0200 Subject: [PATCH] drop dietary choices, social events, and html_export_path --- .../admin/conference_controller.rb | 5 +- app/models/conference.rb | 4 - app/models/dietary_choice.rb | 4 - app/models/registration.rb | 3 - app/models/revision_observer.rb | 2 +- app/models/social_event.rb | 4 - app/views/admin/registrations/edit.html.haml | 7 - config/routes.rb | 2 - ...160309182642_remove_social_events_table.rb | 134 ++++++++++++++ ...0309182655_remove_dietary_choices_table.rb | 173 ++++++++++++++++++ ...emove_html_export_path_from_conferences.rb | 5 + spec/factories/social_events.rb | 9 - spec/models/registration_spec.rb | 2 - 13 files changed, 315 insertions(+), 39 deletions(-) delete mode 100644 app/models/dietary_choice.rb delete mode 100644 app/models/social_event.rb create mode 100644 db/migrate/20160309182642_remove_social_events_table.rb create mode 100644 db/migrate/20160309182655_remove_dietary_choices_table.rb create mode 100644 db/migrate/20160309183052_remove_html_export_path_from_conferences.rb delete mode 100644 spec/factories/social_events.rb diff --git a/app/controllers/admin/conference_controller.rb b/app/controllers/admin/conference_controller.rb index 9cdf0846..dd520157 100644 --- a/app/controllers/admin/conference_controller.rb +++ b/app/controllers/admin/conference_controller.rb @@ -177,10 +177,9 @@ module Admin private def conference_params - params.require(:conference).permit(:title, :short_title, :description, :timezone, :html_export_path, + params.require(:conference).permit(:title, :short_title, :description, :timezone, :start_date, :end_date, :rooms_attributes, :tracks_attributes, - :dietary_choices_attributes, :use_dietary_choices, - :tickets_attributes, :social_events_attributes, :event_types_attributes, + :tickets_attributes, :event_types_attributes, :logo, :questions_attributes, :question_ids, :answers_attributes, :answer_ids, :difficulty_levels_attributes, :use_difficulty_levels, :use_vpositions, :use_vdays, :vdays_attributes, diff --git a/app/models/conference.rb b/app/models/conference.rb index 048da738..e43ef9ae 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -19,11 +19,9 @@ class Conference < ActiveRecord::Base has_one :email_settings, dependent: :destroy has_one :program, dependent: :destroy has_one :venue, dependent: :destroy - has_many :social_events, dependent: :destroy has_many :ticket_purchases, dependent: :destroy has_many :supporters, through: :ticket_purchases, source: :user has_many :tickets, dependent: :destroy - has_many :dietary_choices, dependent: :destroy has_many :lodgings, dependent: :destroy has_many :registrations, dependent: :destroy @@ -38,9 +36,7 @@ class Conference < ActiveRecord::Base has_many :commercials, as: :commercialable, dependent: :destroy has_many :subscriptions, dependent: :destroy - accepts_nested_attributes_for :social_events, allow_destroy: true accepts_nested_attributes_for :venue - accepts_nested_attributes_for :dietary_choices, allow_destroy: true accepts_nested_attributes_for :tickets, allow_destroy: true accepts_nested_attributes_for :sponsorship_levels, allow_destroy: true accepts_nested_attributes_for :sponsors, allow_destroy: true diff --git a/app/models/dietary_choice.rb b/app/models/dietary_choice.rb deleted file mode 100644 index 48ff7828..00000000 --- a/app/models/dietary_choice.rb +++ /dev/null @@ -1,4 +0,0 @@ -class DietaryChoice < ActiveRecord::Base - belongs_to :conference - has_many :registrations -end diff --git a/app/models/registration.rb b/app/models/registration.rb index d02fa8bb..0d314c3d 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -1,9 +1,7 @@ class Registration < ActiveRecord::Base belongs_to :user belongs_to :conference - belongs_to :dietary_choice - has_and_belongs_to_many :social_events has_and_belongs_to_many :events has_and_belongs_to_many :qanswers has_and_belongs_to_many :vchoices @@ -12,7 +10,6 @@ class Registration < ActiveRecord::Base has_many :workshops, through: :events_registrations, source: :event accepts_nested_attributes_for :user - accepts_nested_attributes_for :social_events accepts_nested_attributes_for :qanswers delegate :name, to: :user diff --git a/app/models/revision_observer.rb b/app/models/revision_observer.rb index 7247efc0..4d2784f4 100644 --- a/app/models/revision_observer.rb +++ b/app/models/revision_observer.rb @@ -12,7 +12,7 @@ # in table 'conferences' looks like a more simple and straightforward solution # class RevisionObserver < ActiveRecord::Observer - observe :conference, :event, :room, :social_event, :track + observe :conference, :event, :room, :track def after_save(model) begin diff --git a/app/models/social_event.rb b/app/models/social_event.rb deleted file mode 100644 index e75224ab..00000000 --- a/app/models/social_event.rb +++ /dev/null @@ -1,4 +0,0 @@ -class SocialEvent < ActiveRecord::Base - belongs_to :conference - has_and_belongs_to_many :registrations -end diff --git a/app/views/admin/registrations/edit.html.haml b/app/views/admin/registrations/edit.html.haml index 694da7a5..0cd19eea 100644 --- a/app/views/admin/registrations/edit.html.haml +++ b/app/views/admin/registrations/edit.html.haml @@ -13,11 +13,4 @@ = u.input :affiliation, placeholder: 'Company/User Group/nothing', as: :string = f.inputs 'Registration Information' do = render partial: 'conference_registrations/registration_info', locals: { f: f } - - -# Not necessary - - if @conference.social_events.count > 0 - = f.inputs 'Are you planning to attend any of the parties?' do - %br Yes, I'll be attending... - %br - = f.input :social_events, as: :check_boxes, label: false, collection: @conference.social_events = f.action :submit, button_html: { class: 'btn btn-primary' } diff --git a/config/routes.rb b/config/routes.rb index 9ec449f9..c416f3b0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,8 +27,6 @@ Osem::Application.routes.draw do resource :schedule, only: [:show, :update] get 'commercials/render_commercial' => 'commercials#render_commercial' resources :commercials, only: [:index, :create, :update, :destroy] - get '/dietary_choices' => 'dietchoices#show', as: 'dietary_list' - patch '/dietary_choices' => 'dietchoices#update', as: 'dietary_update' get '/volunteers_list' => 'volunteers#show' get '/volunteers' => 'volunteers#index', as: 'volunteers_info' patch '/volunteers' => 'volunteers#update', as: 'volunteers_update' diff --git a/db/migrate/20160309182642_remove_social_events_table.rb b/db/migrate/20160309182642_remove_social_events_table.rb new file mode 100644 index 00000000..e44a7c3f --- /dev/null +++ b/db/migrate/20160309182642_remove_social_events_table.rb @@ -0,0 +1,134 @@ +class RemoveSocialEventsTable < ActiveRecord::Migration + class TempConference < ActiveRecord::Base + self.table_name = 'conferences' + + has_many :temp_social_events + end + + class TempSocialEvent < ActiveRecord::Base + self.table_name = 'social_events' + + belongs_to :temp_conference + has_and_belongs_to_many :temp_registrations + end + + class TempRegistration < ActiveRecord::Base + self.table_name = 'registrations' + + belongs_to :temp_conference + has_and_belongs_to_many :temp_social_events + has_and_belongs_to_many :temp_qanswers + end + + class TempRegistrationsSocialEvent < ActiveRecord::Base + self.table_name = 'registrations_social_events' + + belongs_to :temp_registrations + belongs_to :temp_social_events + end + + class TempQuestionType < ActiveRecord::Base + self.table_name = 'question_types' + + has_many :temp_questions + end + + class TempQuestion < ActiveRecord::Base + self.table_name = 'questions' + + has_many :temp_qanswers + has_many :temp_answers, through: :temp_qanswers + belongs_to :temp_question_type + has_and_belongs_to_many :temp_conferences + end + + class TempAnswer < ActiveRecord::Base + self.table_name = 'answers' + + has_many :temp_qanswers + has_many :temp_questions, through: :temp_qanswers + end + + class TempQanswer < ActiveRecord::Base + self.table_name = 'qanswers' + + belongs_to :temp_question + belongs_to :temp_answer + has_and_belongs_to_many :temp_registrations + end + + class TempConferencesQuestions < ActiveRecord::Base + self.table_name = 'conferences_questions' + end + + class TempQanswerRegistration < ActiveRecord::Base + self.table_name = 'qanswers_registrations' + end + + def up + # Create Question of 'Multiple Choice' type + qtype = TempQuestionType.find_or_create_by!(title: 'Multiple Choice') + + TempConference.all.each do |conference| + if TempSocialEvent.where(conference_id: conference.id).any? + # Find existing question or initialize it + question = TempQuestion.find_or_initialize_by(title: 'Which of the following social events are you going to attend?', + conference_id: conference.id, + question_type_id: qtype.id) + question.save! + # Enable the question for the conference + TempConferencesQuestions.find_or_create_by!(conference_id: conference.id, + question_id: question.id) + end + + TempSocialEvent.where(conference_id: conference.id).each do |social_event| + answer = TempAnswer.find_or_create_by!(title: social_event.title) + # Associate answer with the question + qa = TempQanswer.find_or_initialize_by(question_id: question.id, + answer_id: answer.id) + qa.save! + + # Associate appropriate answer with registration + TempRegistrationsSocialEvent.where(social_event_id: social_event.id).each do |registration_social_event| + registration = TempRegistration.find(registration_social_event.registration_id) + TempQanswerRegistration.find_or_create_by!(registration_id: registration.id, + qanswer_id: qa.id) + end + end + end + + drop_table :social_events + drop_table :registrations_social_events + end + + def down + create_table :social_events do |t| + t.references :conference + t.string :title + t.text :description + t.date :date + end + + create_table :registrations_social_events, id: false do |t| + t.references :registration, :social_event + end + + qtype = TempQuestionType.find_by(title: 'Multiple Choice') + + TempConference.all.each do |conference| + if qtype && (question = TempQuestion.find_by(title: 'Which of the following social events are you going to attend?', + conference_id: conference.id, question_type_id: qtype.id)) + TempQanswer.where(question_id: question.id).each do |qa| + TempQanswerRegistration.where(qanswer_id: qa.id).each do |qa_registration| + answer = TempAnswer.find(qa.answer_id) + registration = TempRegistration.find(qa_registration.registration_id) + social_event = TempSocialEvent.find_or_create_by!(title: answer.title, + conference_id: conference.id) + TempRegistrationsSocialEvent.find_or_create_by!(registration_id: registration.id, + social_event_id: social_event.id) + end + end + end + end + end +end diff --git a/db/migrate/20160309182655_remove_dietary_choices_table.rb b/db/migrate/20160309182655_remove_dietary_choices_table.rb new file mode 100644 index 00000000..c61876bc --- /dev/null +++ b/db/migrate/20160309182655_remove_dietary_choices_table.rb @@ -0,0 +1,173 @@ +class RemoveDietaryChoicesTable < ActiveRecord::Migration + class TempDietaryChoice < ActiveRecord::Base + self.table_name = 'dietary_choices' + + belongs_to :temp_conference + end + + class TempConference < ActiveRecord::Base + self.table_name = 'conferences' + + has_many :temp_dietary_choices, dependent: :destroy + end + + class TempRegistration < ActiveRecord::Base + self.table_name = 'registrations' + + belongs_to :temp_conference + end + + class TempQuestionType < ActiveRecord::Base + self.table_name = 'question_types' + + has_many :temp_questions + end + + class TempQuestion < ActiveRecord::Base + self.table_name = 'questions' + + has_many :temp_qanswers + has_many :temp_answers, through: :temp_qanswers + belongs_to :temp_question_type + has_and_belongs_to_many :temp_conferences + end + + class TempAnswer < ActiveRecord::Base + self.table_name = 'answers' + + has_many :temp_qanswers + has_many :temp_questions, through: :temp_qanswers + end + + class TempQanswer < ActiveRecord::Base + self.table_name = 'qanswers' + + belongs_to :temp_question + belongs_to :temp_answer + has_and_belongs_to_many :temp_registrations + end + + class TempConferencesQuestions < ActiveRecord::Base + self.table_name = 'conferences_questions' + end + + class TempQanswerRegistration < ActiveRecord::Base + self.table_name = 'qanswers_registrations' + end + + def up + # Create Question of 'Multiple Choice' type + if TempDietaryChoice.all.any? + qtype = TempQuestionType.find_or_create_by!(title: 'Single Choice') + end + + # Migrate dietary_choice_id to a question + TempConference.all.each do |conference| + if TempDietaryChoice.where(conference_id: conference.id).any? + # Find existing question or initialize it + question = TempQuestion.find_or_initialize_by(title: 'Which is your dietary choice?', + conference_id: conference.id, + question_type_id: qtype.id) + question.save! + # Enable the question for the conference + TempConferencesQuestions.find_or_create_by!(conference_id: conference.id, + question_id: question.id) + + TempDietaryChoice.where(conference_id: conference.id).each do |dietary_choice| + answer = TempAnswer.find_or_create_by!(title: dietary_choice.title) + # Associate answer with the question + qa = TempQanswer.find_or_initialize_by(question_id: question.id, + answer_id: answer.id) + qa.save! + + # Associate appropriate answer with registration + TempRegistration.where(dietary_choice_id: dietary_choice.id).each do |registration| + TempQanswerRegistration.find_or_create_by!(registration_id: registration.id, + qanswer_id: qa.id) + end + end + end + end + + # Migrate other_dietary_choice to a question and put data in other_special_needs + TempRegistration.all.each do |registration| + if registration.other_dietary_choice.present? + conference = TempConference.find(registration.conference_id) + qtype = TempQuestionType.find_or_create_by!(title: 'Yes/No') + question = TempQuestion.find_or_initialize_by(title: 'Do you have another dietary choice?', + conference_id: conference.id, + question_type_id: qtype.id) + question.save! + # Enable the question for the conference + TempConferencesQuestions.find_or_create_by!(conference_id: conference.id, + question_id: question.id) + + # Create 'Yes' answer + answer_yes = TempAnswer.find_or_create_by!(title: 'Yes') + + # Associate answer with the question + qa = TempQanswer.find_or_initialize_by(question_id: question.id, + answer_id: answer_yes.id) + + qa.save! + + # Associate appropriate answer with registration + TempQanswerRegistration.find_or_create_by!(registration_id: registration.id, + qanswer_id: qa.id) + + # Move data from other_dietary_choice to other_special_needs + registration.other_special_needs << "Other dietary choice: #{registration.other_dietary_choice}." + registration.save! + end + end + + remove_column :conferences, :use_dietary_choices + remove_column :registrations, :dietary_choice_id + remove_column :registrations, :other_dietary_choice + drop_table :dietary_choices + end + + def down + create_table :dietary_choices do |t| + t.references :conference + t.string :title, null: false + t.timestamps + end + + add_column :conferences, :use_dietary_choices, :boolean + add_column :registrations, :dietary_choice_id, :integer + add_column :registrations, :other_dietary_choice, :text + + qtype = TempQuestionType.find_by(title: 'Single Choice') + TempConference.all.each do |conference| + if qtype && (question = TempQuestion.find_by(title: 'Which is your dietary choice?', + conference_id: conference.id, question_type_id: qtype.id)) + TempQanswer.where(question_id: question.id).each do |qa| + TempQanswerRegistration.where(qanswer_id: qa.id).each do |qa_registration| + answer = TempAnswer.find(qa.answer_id) + registration = TempRegistration.find(qa_registration.registration_id) + dietary_choice = TempDietaryChoice.find_or_create_by!(title: answer.title, + conference_id: conference.id) + registration.dietary_choice_id = dietary_choice.id + registration.save! + end + end + end + end + + qtype = TempQuestionType.find_by(title: 'Yes/No') + answer_yes = TempAnswer.find_by(title: 'Yes') + TempConference.all.each do |conference| + if qtype && (question = TempQuestion.find_by(title: 'Do you have another dietary choice?', + conference_id: conference.id, question_type_id: qtype.id)) + TempQanswer.where(question_id: question.id, answer_id: answer_yes.id).each do |qa| + TempQanswerRegistration.where(qanswer_id: qa.id).each do |qa_registration| + registration = TempRegistration.find(qa_registration.registration_id) + registration.other_dietary_choice = 'Yes' + registration.save! + end + end + end + end + end +end diff --git a/db/migrate/20160309183052_remove_html_export_path_from_conferences.rb b/db/migrate/20160309183052_remove_html_export_path_from_conferences.rb new file mode 100644 index 00000000..f1d3171e --- /dev/null +++ b/db/migrate/20160309183052_remove_html_export_path_from_conferences.rb @@ -0,0 +1,5 @@ +class RemoveHtmlExportPathFromConferences < ActiveRecord::Migration + def change + remove_column :conferences, :html_export_path, :string + end +end diff --git a/spec/factories/social_events.rb b/spec/factories/social_events.rb deleted file mode 100644 index 46088701..00000000 --- a/spec/factories/social_events.rb +++ /dev/null @@ -1,9 +0,0 @@ -FactoryGirl.define do - factory :social_event do - title 'Example Social Event' - description 'Lorem Ipsum Dolsum' - date { Date.today } - conference - end - -end diff --git a/spec/models/registration_spec.rb b/spec/models/registration_spec.rb index af94a6ad..eff512db 100644 --- a/spec/models/registration_spec.rb +++ b/spec/models/registration_spec.rb @@ -29,8 +29,6 @@ describe 'Registration' do describe 'association' do it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:conference) } - it { is_expected.to belong_to(:dietary_choice) } - it { is_expected.to have_and_belong_to_many(:social_events) } it { is_expected.to have_and_belong_to_many(:events) } it { is_expected.to have_and_belong_to_many(:qanswers) } it { is_expected.to have_and_belong_to_many(:vchoices) }