From 8c94bb3a87ee687eec940753d6e7e93b0606ebd6 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Mon, 19 Oct 2015 00:25:11 +0300 Subject: [PATCH] Move the confirmation date to Proposition --- app/models/concerns/proposable.rb | 1 + app/models/conference.rb | 2 +- app/models/event.rb | 2 -- ...18211611_add_confirmed_at_to_propositions.rb | 5 +++++ ...e_confirmed_at_of_propositions_for_events.rb | 17 +++++++++++++++++ ...018212026_remove_confirmed_at_from_events.rb | 5 +++++ 6 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20151018211611_add_confirmed_at_to_propositions.rb create mode 100644 db/migrate/20151018211712_populate_confirmed_at_of_propositions_for_events.rb create mode 100644 db/migrate/20151018212026_remove_confirmed_at_from_events.rb diff --git a/app/models/concerns/proposable.rb b/app/models/concerns/proposable.rb index 190a1d8..77226a9 100644 --- a/app/models/concerns/proposable.rb +++ b/app/models/concerns/proposable.rb @@ -5,6 +5,7 @@ module Proposable has_one :proposition, as: :proposable, dependent: :destroy has_one :proposer, through: :proposition delegate :email, to: :proposer, prefix: true + scope :confirmed, -> { joins(:proposition).where.not(propositions: {confirmed_at: nil}) } Proposition.defined_enums["status"].keys.each do |status| scope status.to_sym, -> { joins(:proposition).where(propositions: {status: Proposition.defined_enums["status"][status]}) } diff --git a/app/models/conference.rb b/app/models/conference.rb index 0da4ecf..0aaecc6 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -32,7 +32,7 @@ class Conference < ActiveRecord::Base end def submissions_grouped_by_confirmation_day - submissions = events.approved.confirmed.group('date(events.confirmed_at)').select('date(events.confirmed_at) as confirmed_at, count(events.id) as number') + submissions = events.approved.confirmed.group('date(propositions.confirmed_at)').select('date(propositions.confirmed_at) as confirmed_at, count(events.id) as number') submissions.group_by { |s| s.confirmed_at.to_date } end diff --git a/app/models/event.rb b/app/models/event.rb index c33520c..35e2f61 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -24,8 +24,6 @@ class Event < ActiveRecord::Base validates :length, presence: true, numericality: {only_integer: true} validate :length_is_within_the_permitted_interval - scope :confirmed, -> { where.not confirmed_at: nil } - delegate :status, to: :proposition def proposer_profile diff --git a/db/migrate/20151018211611_add_confirmed_at_to_propositions.rb b/db/migrate/20151018211611_add_confirmed_at_to_propositions.rb new file mode 100644 index 0000000..0b8ae5e --- /dev/null +++ b/db/migrate/20151018211611_add_confirmed_at_to_propositions.rb @@ -0,0 +1,5 @@ +class AddConfirmedAtToPropositions < ActiveRecord::Migration + def change + add_column :propositions, :confirmed_at, :timestamp + end +end diff --git a/db/migrate/20151018211712_populate_confirmed_at_of_propositions_for_events.rb b/db/migrate/20151018211712_populate_confirmed_at_of_propositions_for_events.rb new file mode 100644 index 0000000..fd54dd5 --- /dev/null +++ b/db/migrate/20151018211712_populate_confirmed_at_of_propositions_for_events.rb @@ -0,0 +1,17 @@ +class Event < ActiveRecord::Base + include Proposable +end + +class PopulateConfirmedAtOfPropositionsForEvents < ActiveRecord::Migration + def up + Event.all do |event| + event.proposition.update(confirmed_at: event.confirmed_at) + end + end + + def down + Event.all do |event| + event.update(confirmed_at: event.proposition.confirmed_at) + end + end +end diff --git a/db/migrate/20151018212026_remove_confirmed_at_from_events.rb b/db/migrate/20151018212026_remove_confirmed_at_from_events.rb new file mode 100644 index 0000000..1173060 --- /dev/null +++ b/db/migrate/20151018212026_remove_confirmed_at_from_events.rb @@ -0,0 +1,5 @@ +class RemoveConfirmedAtFromEvents < ActiveRecord::Migration + def change + remove_column :events, :confirmed_at, :timestamp + end +end