diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-04-08 23:24:27 +0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-04-08 23:24:27 +0300 |
commit | ee497599cc69b126cc2e4a929f1799d3d3eb989d (patch) | |
tree | 07616b6ffaa63b5b93a61049f321547fc30ce593 /app/models/notification_setting.rb | |
parent | 069724cef5873b83720004772d1e874030cc9fff (diff) |
Use default_value_for to set default NotificationSetting#level
Diffstat (limited to 'app/models/notification_setting.rb')
-rw-r--r-- | app/models/notification_setting.rb | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb index 13a8995b036..d89194b5a12 100644 --- a/app/models/notification_setting.rb +++ b/app/models/notification_setting.rb @@ -1,4 +1,10 @@ class NotificationSetting < ActiveRecord::Base + # Notification level + # Note: When adding an option, it MUST go on the end of the array. + enum level: [:disabled, :participating, :watch, :global, :mention] + + default_value_for :level, NotificationSetting.levels[:global] + belongs_to :user belongs_to :source, polymorphic: true @@ -8,9 +14,6 @@ class NotificationSetting < ActiveRecord::Base validates :user_id, uniqueness: { scope: [:source_type, :source_id], message: "already exists in source", allow_nil: true } - # Notification level - # Note: When adding an option, it MUST go on the end of the array. - enum level: [:disabled, :participating, :watch, :global, :mention] scope :for_groups, -> { where(source_type: 'Namespace') } scope :for_projects, -> { where(source_type: 'Project') } @@ -19,14 +22,9 @@ class NotificationSetting < ActiveRecord::Base setting = find_or_initialize_by(source: source) unless setting.persisted? - setting.set_defaults setting.save end setting end - - def set_defaults - self.level = :global - end end |