From 9bcf1a80add9ecb8b9b10b49385334aee3d25920 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Wed, 6 Jul 2022 19:44:33 +0200 Subject: [PATCH] Merge `author_name` with `author_identifier` --- app/controllers/ajax/inbox_controller.rb | 2 +- app/models/inbox.rb | 2 +- app/workers/export_worker.rb | 2 +- .../20220706174120_drop_author_name_field_from_questions.rb | 6 ++++++ db/schema.rb | 3 +-- spec/controllers/ajax/inbox_controller_spec.rb | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20220706174120_drop_author_name_field_from_questions.rb diff --git a/app/controllers/ajax/inbox_controller.rb b/app/controllers/ajax/inbox_controller.rb index fa107671..4c6b33a3 100644 --- a/app/controllers/ajax/inbox_controller.rb +++ b/app/controllers/ajax/inbox_controller.rb @@ -8,7 +8,7 @@ class Ajax::InboxController < AjaxController question = Question.create!(content: QuestionGenerator.generate, author_is_anonymous: true, - author_name: 'justask', + author_identifier: 'justask', user: current_user) inbox = Inbox.create!(user: current_user, question_id: question.id, new: true) diff --git a/app/models/inbox.rb b/app/models/inbox.rb index 4d863686..5c84a055 100644 --- a/app/models/inbox.rb +++ b/app/models/inbox.rb @@ -7,7 +7,7 @@ class Inbox < ApplicationRecord before_create do raise "User does not want to receive anonymous questions" if !returning && question.author_is_anonymous && - (question.author_name != "justask") && + (question.author_identifier != "justask") && !user.privacy_allow_anonymous_questions? end diff --git a/app/workers/export_worker.rb b/app/workers/export_worker.rb index 74af60b0..368f5ea6 100644 --- a/app/workers/export_worker.rb +++ b/app/workers/export_worker.rb @@ -10,7 +10,7 @@ class ExportWorker exporter.export question = Question.create(content: "Your #{APP_CONFIG['site_name']} data export is ready! You can download it " + "from the settings page under the \"Export\" tab.", author_is_anonymous: true, - author_name: "retrospring_exporter") + author_identifier: "retrospring_exporter") Inbox.create(user_id: user_id, question_id: question.id, new: true) end end diff --git a/db/migrate/20220706174120_drop_author_name_field_from_questions.rb b/db/migrate/20220706174120_drop_author_name_field_from_questions.rb new file mode 100644 index 00000000..b7cdd9ec --- /dev/null +++ b/db/migrate/20220706174120_drop_author_name_field_from_questions.rb @@ -0,0 +1,6 @@ +class DropAuthorNameFieldFromQuestions < ActiveRecord::Migration[6.1] + def change + execute "update questions set author_identifier = author_name where author_name is not null and author_identifier is null;" + remove_column :questions, :author_name + end +end diff --git a/db/schema.rb b/db/schema.rb index 25c25432..3f6fedee 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_07_06_172257) do +ActiveRecord::Schema.define(version: 2022_07_06_174120) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -166,7 +166,6 @@ ActiveRecord::Schema.define(version: 2022_07_06_172257) do create_table "questions", id: :bigint, default: -> { "gen_timestamp_id('questions'::text)" }, force: :cascade do |t| t.string "content" t.boolean "author_is_anonymous" - t.string "author_name" t.string "author_identifier" t.bigint "user_id" t.datetime "created_at" diff --git a/spec/controllers/ajax/inbox_controller_spec.rb b/spec/controllers/ajax/inbox_controller_spec.rb index 3d99ffe7..35515b86 100644 --- a/spec/controllers/ajax/inbox_controller_spec.rb +++ b/spec/controllers/ajax/inbox_controller_spec.rb @@ -23,7 +23,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do allow(QuestionGenerator).to receive(:generate).and_return("Is Mayonnaise an instrument?") expect { subject }.to(change { user.inboxes.count }.by(1)) expect(user.inboxes.last.question.author_is_anonymous).to eq(true) - expect(user.inboxes.last.question.author_name).to eq("justask") + expect(user.inboxes.last.question.author_identifier).to eq("justask") expect(user.inboxes.last.question.user).to eq(user) expect(user.inboxes.last.question.content).to eq("Is Mayonnaise an instrument?") end