From f695b5d3e7ffbdacc56e3b9dac72122b7a72bbde Mon Sep 17 00:00:00 2001 From: zachrab <zachrab@gmail.com> Date: Sun, 8 Feb 2015 21:49:31 -0800 Subject: [PATCH] Set disable_mail to true Add #clear_account! disable mail spec Add migration for disabling mail for all closed accounts Change migration to use #update_all for disable_mail attribute Add #clear_account! false fields spec --- app/models/user.rb | 2 +- ...20150209230946_disable_mail_for_closed_account.rb | 9 +++++++++ db/schema.rb | 2 +- spec/models/user_spec.rb | 12 ++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20150209230946_disable_mail_for_closed_account.rb diff --git a/app/models/user.rb b/app/models/user.rb index 7fb19c411e..8c2810e759 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -489,10 +489,10 @@ class User < ActiveRecord::Base self[field] = nil end [:getting_started, - :disable_mail, :show_community_spotlight_in_stream].each do |field| self[field] = false end + self[:disable_mail] = true self[:strip_exif] = true self[:email] = "deletedaccount_#{self[:id]}@example.org" diff --git a/db/migrate/20150209230946_disable_mail_for_closed_account.rb b/db/migrate/20150209230946_disable_mail_for_closed_account.rb new file mode 100644 index 0000000000..575b16cfcd --- /dev/null +++ b/db/migrate/20150209230946_disable_mail_for_closed_account.rb @@ -0,0 +1,9 @@ +class DisableMailForClosedAccount < ActiveRecord::Migration + def up + User.joins(:person).where(people: {closed_account: true}).update_all(disable_mail: true) + end + + def down + User.joins(:person).where(people: {closed_account: true}).update_all(disable_mail: false) + end +end diff --git a/db/schema.rb b/db/schema.rb index 67a8029741..c8edada902 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150106050733) do +ActiveRecord::Schema.define(version: 20150209230946) do create_table "account_deletions", force: true do |t| t.string "diaspora_handle" diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 33be531b01..37ad3a8e02 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -962,6 +962,18 @@ describe User, :type => :model do expect(@user.send(attr.to_sym)).to be_blank end end + + it 'disables mail' do + @user.disable_mail = false + @user.clear_account! + expect(@user.reload.disable_mail).to be true + end + + it 'sets getting_started and show_community_spotlight_in_stream fields to false' do + @user.clear_account! + expect(@user.reload.getting_started).to be false + expect(@user.reload.show_community_spotlight_in_stream).to be false + end end describe "#clearable_attributes" do -- GitLab