From 014ff1acc365e1ac621d2a37227414827c205b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Thu, 4 Jul 2019 16:49:11 +0200 Subject: [PATCH] Use new changed? Rails method `attribute_changed?` inside of after callbacks has changed his behaviour. The new return value will reflect the behavior of calling the method after `save` returned. To maintain the current behavior, I have `saved_change_to_attribute?` instead. --- app/models/conference.rb | 6 +++--- app/models/program.rb | 4 ++-- app/models/venue.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/conference.rb b/app/models/conference.rb index ca37e6d0..be3c36ad 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -115,7 +115,7 @@ class Conference < ApplicationRecord # Delete all EventSchedules that are not in the hours range # After the conference has been successfully updated def delete_event_schedules - if start_hour_changed? || end_hour_changed? + if saved_change_to_start_hour? || saved_change_to_end_hour? event_schedules = program.event_schedules.select do |event_schedule| event_schedule.start_time.hour < start_hour || event_schedule.end_time.hour > end_hour || @@ -642,7 +642,7 @@ class Conference < ApplicationRecord def notify_on_dates_changed? return false unless email_settings.send_on_conference_dates_updated # do not notify unless one of the dates changed - return false unless start_date_changed? || end_date_changed? + return false unless saved_change_to_start_date? || saved_change_to_end_date? # do not notify unless the mail content is set up (email_settings.conference_dates_updated_subject.present? && email_settings.conference_dates_updated_body.present?) @@ -659,7 +659,7 @@ class Conference < ApplicationRecord # do not notify unless we allow a registration return false unless registration_period # do not notify unless one of the dates changed - return false unless registration_period.start_date_changed? || registration_period.end_date_changed? + return false unless registration_period.saved_change_to_start_date? || registration_period.saved_change_to_end_date? # do not notify unless the mail content is set up (email_settings.conference_registration_dates_updated_subject.present? && email_settings.conference_registration_dates_updated_body.present?) diff --git a/app/models/program.rb b/app/models/program.rb index 0dadee15..8db24c6c 100644 --- a/app/models/program.rb +++ b/app/models/program.rb @@ -72,8 +72,8 @@ class Program < ApplicationRecord after_create :create_event_types after_create :create_difficulty_levels - after_save :unschedule_unfit_events, if: :schedule_interval_changed? - after_save :normalize_event_types_length, if: :schedule_interval_changed? + after_save :unschedule_unfit_events, if: :saved_change_to_schedule_interval? + after_save :normalize_event_types_length, if: :saved_change_to_schedule_interval? validate :check_languages_format # Returns all event_schedules for the selected schedule ordered by start_time diff --git a/app/models/venue.rb b/app/models/venue.rb index 592279ad..5abdcf96 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -37,7 +37,7 @@ class Venue < ApplicationRecord def notify_on_venue_changed? return false unless conference.try(:email_settings).try(:send_on_venue_updated) # do not notify unless the address changed - return false unless name_changed? || street_changed? || city_changed? || country_changed? + return false unless saved_change_to_name? || saved_change_to_street? || saved_change_to_city? || saved_change_to_country? # do not notify unless the mail content is set up (!conference.email_settings.venue_updated_subject.blank? && !conference.email_settings.venue_updated_body.blank?)