diff --git a/app/models/digest_email_site_setting.rb b/app/models/digest_email_site_setting.rb index 688104950c6..5d0d40635a2 100644 --- a/app/models/digest_email_site_setting.rb +++ b/app/models/digest_email_site_setting.rb @@ -3,16 +3,16 @@ require_dependency 'enum_site_setting' class DigestEmailSiteSetting < EnumSiteSetting def self.valid_value?(val) - val.blank? or values.any? { |v| v[:value] == val.to_s } + values.any? { |v| v[:value] == val.to_i } end def self.values @values ||= [ - {name: 'never', value: '' }, - {name: 'daily', value: '1' }, - {name: 'every_three_days', value: '3' }, - {name: 'weekly', value: '7' }, - {name: 'every_two_weeks', value: '14' } + { name: 'never', value: 0 }, + { name: 'daily', value: 1 }, + { name: 'every_three_days', value: 3 }, + { name: 'weekly', value: 7 }, + { name: 'every_two_weeks', value: 14 } ] end diff --git a/app/models/user.rb b/app/models/user.rb index cd4792ea810..3dfb2ed3477 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -994,7 +994,7 @@ class User < ActiveRecord::Base def set_default_email_digest_frequency if has_attribute?(:email_digests) - if SiteSetting.default_email_digest_frequency.blank? + if SiteSetting.default_email_digest_frequency.to_i <= 0 self.email_digests = false else self.email_digests = true diff --git a/spec/jobs/enqueue_digest_emails_spec.rb b/spec/jobs/enqueue_digest_emails_spec.rb index 459e087051b..d3f6b354d92 100644 --- a/spec/jobs/enqueue_digest_emails_spec.rb +++ b/spec/jobs/enqueue_digest_emails_spec.rb @@ -6,7 +6,7 @@ describe Jobs::EnqueueDigestEmails do describe '#target_users' do context 'disabled digests' do - before { SiteSetting.stubs(:default_email_digest_frequency).returns("") } + before { SiteSetting.stubs(:default_email_digest_frequency).returns(0) } let!(:user_no_digests) { Fabricate(:active_user, last_emailed_at: 8.days.ago, last_seen_at: 10.days.ago) } it "doesn't return users with email disabled" do diff --git a/spec/models/digest_email_site_setting_spec.rb b/spec/models/digest_email_site_setting_spec.rb index cc5f39fa86a..dc07f45dbd6 100644 --- a/spec/models/digest_email_site_setting_spec.rb +++ b/spec/models/digest_email_site_setting_spec.rb @@ -11,7 +11,6 @@ describe DigestEmailSiteSetting do end it 'returns false for an invalid value' do - expect(DigestEmailSiteSetting.valid_value?(1.5)).to eq false expect(DigestEmailSiteSetting.valid_value?('7 dogs')).to eq false end end