Rename `Appendable::Reaction` to `Reaction`
This commit is contained in:
parent
6dbc57ddc3
commit
1e29d3f86f
|
@ -4,7 +4,7 @@ class Answer < ApplicationRecord
|
||||||
belongs_to :user, counter_cache: :answered_count
|
belongs_to :user, counter_cache: :answered_count
|
||||||
belongs_to :question, counter_cache: :answer_count
|
belongs_to :question, counter_cache: :answer_count
|
||||||
has_many :comments, dependent: :destroy
|
has_many :comments, dependent: :destroy
|
||||||
has_many :smiles, class_name: "Appendable::Reaction", foreign_key: :parent_id, dependent: :destroy
|
has_many :smiles, class_name: "Reaction", foreign_key: :parent_id, dependent: :destroy
|
||||||
has_many :subscriptions, dependent: :destroy
|
has_many :subscriptions, dependent: :destroy
|
||||||
has_many :comment_smiles, through: :comments, source: :smiles
|
has_many :comment_smiles, through: :comments, source: :smiles
|
||||||
|
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
class Appendable < ApplicationRecord
|
|
||||||
belongs_to :parent, polymorphic: true
|
|
||||||
belongs_to :user
|
|
||||||
end
|
|
|
@ -3,7 +3,7 @@ class Comment < ApplicationRecord
|
||||||
belongs_to :answer, counter_cache: :comment_count
|
belongs_to :answer, counter_cache: :comment_count
|
||||||
validates :user_id, presence: true
|
validates :user_id, presence: true
|
||||||
validates :answer_id, presence: true
|
validates :answer_id, presence: true
|
||||||
has_many :smiles, class_name: "Appendable::Reaction", foreign_key: :parent_id, dependent: :destroy
|
has_many :smiles, class_name: "Reaction", foreign_key: :parent_id, dependent: :destroy
|
||||||
|
|
||||||
validates :content, length: { maximum: 512 }
|
validates :content, length: { maximum: 512 }
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Appendable::Reaction < Appendable
|
class Reaction < ApplicationRecord
|
||||||
|
belongs_to :parent, polymorphic: true
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
# rubocop:disable Rails/SkipsModelValidations
|
# rubocop:disable Rails/SkipsModelValidations
|
||||||
after_create do
|
after_create do
|
||||||
Notification.notify parent.user, self unless parent.user == user
|
Notification.notify parent.user, self unless parent.user == user
|
|
@ -34,7 +34,7 @@ class User < ApplicationRecord
|
||||||
has_many :answers, dependent: :destroy_async
|
has_many :answers, dependent: :destroy_async
|
||||||
has_many :comments, dependent: :destroy_async
|
has_many :comments, dependent: :destroy_async
|
||||||
has_many :inboxes, dependent: :destroy_async
|
has_many :inboxes, dependent: :destroy_async
|
||||||
has_many :smiles, class_name: "Appendable::Reaction", dependent: :destroy_async
|
has_many :smiles, class_name: "Reaction", dependent: :destroy_async
|
||||||
has_many :notifications, foreign_key: :recipient_id, dependent: :destroy_async
|
has_many :notifications, foreign_key: :recipient_id, dependent: :destroy_async
|
||||||
has_many :reports, dependent: :destroy_async
|
has_many :reports, dependent: :destroy_async
|
||||||
has_many :lists, dependent: :destroy_async
|
has_many :lists, dependent: :destroy_async
|
||||||
|
|
|
@ -7,13 +7,13 @@ module User::ReactionMethods
|
||||||
raise Errors::ReactingSelfBlockedOther if self.blocking?(item.user)
|
raise Errors::ReactingSelfBlockedOther if self.blocking?(item.user)
|
||||||
raise Errors::ReactingOtherBlockedSelf if item.user.blocking?(self)
|
raise Errors::ReactingOtherBlockedSelf if item.user.blocking?(self)
|
||||||
|
|
||||||
::Appendable::Reaction.create!(user: self, parent: item, content: "🙂")
|
Reaction.create!(user: self, parent: item, content: "🙂")
|
||||||
end
|
end
|
||||||
|
|
||||||
# unsmile an answer or comment
|
# unsmile an answer or comment
|
||||||
# @param item [ApplicationRecord] the answer/comment to unsmile
|
# @param item [ApplicationRecord] the answer/comment to unsmile
|
||||||
def unsmile(item)
|
def unsmile(item)
|
||||||
::Appendable::Reaction.find_by(user: self, parent: item).destroy
|
Reaction.find_by(user: self, parent: item).destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
def smiled?(item)
|
def smiled?(item)
|
||||||
|
|
|
@ -29,8 +29,7 @@ RailsAdmin.config do |config|
|
||||||
end
|
end
|
||||||
|
|
||||||
config.included_models = %w[
|
config.included_models = %w[
|
||||||
Appendable
|
Reaction
|
||||||
Appendable::Reaction
|
|
||||||
Answer
|
Answer
|
||||||
AnonymousBlock
|
AnonymousBlock
|
||||||
Comment
|
Comment
|
||||||
|
@ -58,8 +57,7 @@ RailsAdmin.config do |config|
|
||||||
{
|
{
|
||||||
"AnonymousBlock" => "user-secret",
|
"AnonymousBlock" => "user-secret",
|
||||||
"Answer" => "exclamation",
|
"Answer" => "exclamation",
|
||||||
"Appendable" => "paperclip",
|
"Reaction" => "smile",
|
||||||
"Appendable::Reaction" => "smile",
|
|
||||||
"Comment" => "comment",
|
"Comment" => "comment",
|
||||||
"Inbox" => "inbox",
|
"Inbox" => "inbox",
|
||||||
"List" => "list",
|
"List" => "list",
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class RenameAppendableToReaction < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
rename_table :appendables, :reactions
|
||||||
|
remove_column :reactions, :type
|
||||||
|
end
|
||||||
|
end
|
152
db/schema.rb
152
db/schema.rb
|
@ -10,8 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
ActiveRecord::Schema[7.0].define(version: 2023_10_26_032527) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
|
@ -19,11 +18,11 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.text "content", null: false
|
t.text "content", null: false
|
||||||
t.string "link_text"
|
t.string "link_text"
|
||||||
t.string "link_href"
|
t.string "link_href"
|
||||||
t.datetime "starts_at", null: false
|
t.datetime "starts_at", precision: nil, null: false
|
||||||
t.datetime "ends_at", null: false
|
t.datetime "ends_at", precision: nil, null: false
|
||||||
t.bigint "user_id", null: false
|
t.bigint "user_id", null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", precision: nil, null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", precision: nil, null: false
|
||||||
t.index ["user_id"], name: "index_announcements_on_user_id"
|
t.index ["user_id"], name: "index_announcements_on_user_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -31,8 +30,8 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.bigint "user_id"
|
t.bigint "user_id"
|
||||||
t.string "identifier"
|
t.string "identifier"
|
||||||
t.bigint "question_id"
|
t.bigint "question_id"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", null: false
|
||||||
t.bigint "target_user_id"
|
t.bigint "target_user_id"
|
||||||
t.index ["identifier"], name: "index_anonymous_blocks_on_identifier"
|
t.index ["identifier"], name: "index_anonymous_blocks_on_identifier"
|
||||||
t.index ["question_id"], name: "index_anonymous_blocks_on_question_id"
|
t.index ["question_id"], name: "index_anonymous_blocks_on_question_id"
|
||||||
|
@ -45,34 +44,22 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.bigint "question_id"
|
t.bigint "question_id"
|
||||||
t.integer "comment_count", default: 0, null: false
|
t.integer "comment_count", default: 0, null: false
|
||||||
t.bigint "user_id"
|
t.bigint "user_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at", precision: nil
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at", precision: nil
|
||||||
t.integer "smile_count", default: 0, null: false
|
t.integer "smile_count", default: 0, null: false
|
||||||
t.datetime "pinned_at"
|
t.datetime "pinned_at", precision: nil
|
||||||
t.index ["created_at"], name: "index_answers_on_created_at", order: :desc
|
t.index ["created_at"], name: "index_answers_on_created_at", order: :desc
|
||||||
t.index ["question_id"], name: "index_answers_on_question_id"
|
t.index ["question_id"], name: "index_answers_on_question_id"
|
||||||
t.index ["user_id", "created_at"], name: "index_answers_on_user_id_and_created_at"
|
t.index ["user_id", "created_at"], name: "index_answers_on_user_id_and_created_at"
|
||||||
t.index ["user_id", "pinned_at"], name: "index_answers_on_user_id_and_pinned_at"
|
t.index ["user_id", "pinned_at"], name: "index_answers_on_user_id_and_pinned_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "appendables", force: :cascade do |t|
|
|
||||||
t.string "type", null: false
|
|
||||||
t.bigint "user_id", null: false
|
|
||||||
t.bigint "parent_id", null: false
|
|
||||||
t.string "parent_type", null: false
|
|
||||||
t.text "content"
|
|
||||||
t.datetime "created_at", precision: 6, null: false
|
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
|
||||||
t.index ["parent_id", "parent_type"], name: "index_appendables_on_parent_id_and_parent_type"
|
|
||||||
t.index ["user_id", "created_at"], name: "index_appendables_on_user_id_and_created_at"
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table "comments", id: :bigint, default: -> { "gen_timestamp_id('comments'::text)" }, force: :cascade do |t|
|
create_table "comments", id: :bigint, default: -> { "gen_timestamp_id('comments'::text)" }, force: :cascade do |t|
|
||||||
t.string "content"
|
t.string "content"
|
||||||
t.bigint "answer_id"
|
t.bigint "answer_id"
|
||||||
t.bigint "user_id"
|
t.bigint "user_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at", precision: nil
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at", precision: nil
|
||||||
t.integer "smile_count", default: 0, null: false
|
t.integer "smile_count", default: 0, null: false
|
||||||
t.index ["answer_id"], name: "index_comments_on_answer_id"
|
t.index ["answer_id"], name: "index_comments_on_answer_id"
|
||||||
t.index ["user_id", "created_at"], name: "index_comments_on_user_id_and_created_at"
|
t.index ["user_id", "created_at"], name: "index_comments_on_user_id_and_created_at"
|
||||||
|
@ -82,8 +69,8 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.bigint "user_id"
|
t.bigint "user_id"
|
||||||
t.bigint "question_id"
|
t.bigint "question_id"
|
||||||
t.boolean "new"
|
t.boolean "new"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at", precision: nil
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at", precision: nil
|
||||||
t.index ["question_id"], name: "index_inboxes_on_question_id"
|
t.index ["question_id"], name: "index_inboxes_on_question_id"
|
||||||
t.index ["user_id"], name: "index_inboxes_on_user_id"
|
t.index ["user_id"], name: "index_inboxes_on_user_id"
|
||||||
end
|
end
|
||||||
|
@ -91,8 +78,8 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
create_table "list_members", id: :serial, force: :cascade do |t|
|
create_table "list_members", id: :serial, force: :cascade do |t|
|
||||||
t.integer "list_id", null: false
|
t.integer "list_id", null: false
|
||||||
t.bigint "user_id", null: false
|
t.bigint "user_id", null: false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at", precision: nil
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at", precision: nil
|
||||||
t.index ["list_id", "user_id"], name: "index_list_members_on_list_id_and_user_id", unique: true
|
t.index ["list_id", "user_id"], name: "index_list_members_on_list_id_and_user_id", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -101,16 +88,16 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "display_name"
|
t.string "display_name"
|
||||||
t.boolean "private", default: true
|
t.boolean "private", default: true
|
||||||
t.datetime "created_at"
|
t.datetime "created_at", precision: nil
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at", precision: nil
|
||||||
t.index ["user_id", "name"], name: "index_lists_on_user_id_and_name", unique: true
|
t.index ["user_id", "name"], name: "index_lists_on_user_id_and_name", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "mute_rules", id: :bigint, default: -> { "gen_timestamp_id('mute_rules'::text)" }, force: :cascade do |t|
|
create_table "mute_rules", id: :bigint, default: -> { "gen_timestamp_id('mute_rules'::text)" }, force: :cascade do |t|
|
||||||
t.bigint "user_id"
|
t.bigint "user_id"
|
||||||
t.string "muted_phrase"
|
t.string "muted_phrase"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", precision: nil, null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", precision: nil, null: false
|
||||||
t.index ["user_id"], name: "index_mute_rules_on_user_id"
|
t.index ["user_id"], name: "index_mute_rules_on_user_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -119,8 +106,8 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.bigint "target_id"
|
t.bigint "target_id"
|
||||||
t.bigint "recipient_id"
|
t.bigint "recipient_id"
|
||||||
t.boolean "new"
|
t.boolean "new"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at", precision: nil
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at", precision: nil
|
||||||
t.string "type", null: false
|
t.string "type", null: false
|
||||||
t.index ["new"], name: "index_notifications_on_new"
|
t.index ["new"], name: "index_notifications_on_new"
|
||||||
t.index ["recipient_id"], name: "index_notifications_on_recipient_id"
|
t.index ["recipient_id"], name: "index_notifications_on_recipient_id"
|
||||||
|
@ -134,8 +121,8 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.string "location", default: "", null: false
|
t.string "location", default: "", null: false
|
||||||
t.string "website", default: "", null: false
|
t.string "website", default: "", null: false
|
||||||
t.string "motivation_header", default: "", null: false
|
t.string "motivation_header", default: "", null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", precision: nil, null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", precision: nil, null: false
|
||||||
t.string "anon_display_name"
|
t.string "anon_display_name"
|
||||||
t.boolean "allow_long_questions", default: false
|
t.boolean "allow_long_questions", default: false
|
||||||
t.index ["user_id"], name: "index_profiles_on_user_id"
|
t.index ["user_id"], name: "index_profiles_on_user_id"
|
||||||
|
@ -146,18 +133,29 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.boolean "author_is_anonymous"
|
t.boolean "author_is_anonymous"
|
||||||
t.string "author_identifier"
|
t.string "author_identifier"
|
||||||
t.bigint "user_id"
|
t.bigint "user_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at", precision: nil
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at", precision: nil
|
||||||
t.integer "answer_count", default: 0, null: false
|
t.integer "answer_count", default: 0, null: false
|
||||||
t.boolean "direct", default: false, null: false
|
t.boolean "direct", default: false, null: false
|
||||||
t.index ["user_id", "created_at"], name: "index_questions_on_user_id_and_created_at"
|
t.index ["user_id", "created_at"], name: "index_questions_on_user_id_and_created_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "reactions", force: :cascade do |t|
|
||||||
|
t.bigint "user_id", null: false
|
||||||
|
t.bigint "parent_id", null: false
|
||||||
|
t.string "parent_type", null: false
|
||||||
|
t.text "content"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["parent_id", "parent_type"], name: "index_reactions_on_parent_id_and_parent_type"
|
||||||
|
t.index ["user_id", "created_at"], name: "index_reactions_on_user_id_and_created_at"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "relationships", id: :serial, force: :cascade do |t|
|
create_table "relationships", id: :serial, force: :cascade do |t|
|
||||||
t.bigint "source_id"
|
t.bigint "source_id"
|
||||||
t.bigint "target_id"
|
t.bigint "target_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at", precision: nil
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at", precision: nil
|
||||||
t.string "type", null: false
|
t.string "type", null: false
|
||||||
t.index ["source_id", "target_id", "type"], name: "index_relationships_on_source_id_and_target_id_and_type", unique: true
|
t.index ["source_id", "target_id", "type"], name: "index_relationships_on_source_id_and_target_id_and_type", unique: true
|
||||||
t.index ["source_id"], name: "index_relationships_on_source_id"
|
t.index ["source_id"], name: "index_relationships_on_source_id"
|
||||||
|
@ -169,8 +167,8 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.string "type", null: false
|
t.string "type", null: false
|
||||||
t.bigint "target_id", null: false
|
t.bigint "target_id", null: false
|
||||||
t.bigint "user_id", null: false
|
t.bigint "user_id", null: false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at", precision: nil
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at", precision: nil
|
||||||
t.boolean "deleted", default: false
|
t.boolean "deleted", default: false
|
||||||
t.string "reason"
|
t.string "reason"
|
||||||
t.index ["type", "target_id"], name: "index_reports_on_type_and_target_id"
|
t.index ["type", "target_id"], name: "index_reports_on_type_and_target_id"
|
||||||
|
@ -181,8 +179,8 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "resource_type"
|
t.string "resource_type"
|
||||||
t.bigint "resource_id"
|
t.bigint "resource_id"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", precision: nil, null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", precision: nil, null: false
|
||||||
t.index ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id"
|
t.index ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id"
|
||||||
t.index ["resource_type", "resource_id"], name: "index_roles_on_resource_type_and_resource_id"
|
t.index ["resource_type", "resource_id"], name: "index_roles_on_resource_type_and_resource_id"
|
||||||
end
|
end
|
||||||
|
@ -193,14 +191,14 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.text "certificate"
|
t.text "certificate"
|
||||||
t.string "password"
|
t.string "password"
|
||||||
t.integer "connections", default: 1, null: false
|
t.integer "connections", default: 1, null: false
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "type", null: false
|
t.string "type", null: false
|
||||||
t.string "auth_key"
|
t.string "auth_key"
|
||||||
t.string "client_id"
|
t.string "client_id"
|
||||||
t.string "client_secret"
|
t.string "client_secret"
|
||||||
t.string "access_token"
|
t.string "access_token"
|
||||||
t.datetime "access_token_expiration"
|
t.datetime "access_token_expiration", precision: nil
|
||||||
t.text "apn_key"
|
t.text "apn_key"
|
||||||
t.string "apn_key_id"
|
t.string "apn_key_id"
|
||||||
t.string "team_id"
|
t.string "team_id"
|
||||||
|
@ -210,9 +208,9 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
|
|
||||||
create_table "rpush_feedback", force: :cascade do |t|
|
create_table "rpush_feedback", force: :cascade do |t|
|
||||||
t.string "device_token"
|
t.string "device_token"
|
||||||
t.datetime "failed_at", null: false
|
t.datetime "failed_at", precision: nil, null: false
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", null: false
|
||||||
t.integer "app_id"
|
t.integer "app_id"
|
||||||
t.index ["device_token"], name: "index_rpush_feedback_on_device_token"
|
t.index ["device_token"], name: "index_rpush_feedback_on_device_token"
|
||||||
end
|
end
|
||||||
|
@ -225,14 +223,14 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.text "data"
|
t.text "data"
|
||||||
t.integer "expiry", default: 86400
|
t.integer "expiry", default: 86400
|
||||||
t.boolean "delivered", default: false, null: false
|
t.boolean "delivered", default: false, null: false
|
||||||
t.datetime "delivered_at"
|
t.datetime "delivered_at", precision: nil
|
||||||
t.boolean "failed", default: false, null: false
|
t.boolean "failed", default: false, null: false
|
||||||
t.datetime "failed_at"
|
t.datetime "failed_at", precision: nil
|
||||||
t.integer "error_code"
|
t.integer "error_code"
|
||||||
t.text "error_description"
|
t.text "error_description"
|
||||||
t.datetime "deliver_after"
|
t.datetime "deliver_after", precision: nil
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", null: false
|
||||||
t.boolean "alert_is_json", default: false, null: false
|
t.boolean "alert_is_json", default: false, null: false
|
||||||
t.string "type", null: false
|
t.string "type", null: false
|
||||||
t.string "collapse_key"
|
t.string "collapse_key"
|
||||||
|
@ -241,7 +239,7 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.integer "app_id", null: false
|
t.integer "app_id", null: false
|
||||||
t.integer "retries", default: 0
|
t.integer "retries", default: 0
|
||||||
t.string "uri"
|
t.string "uri"
|
||||||
t.datetime "fail_after"
|
t.datetime "fail_after", precision: nil
|
||||||
t.boolean "processing", default: false, null: false
|
t.boolean "processing", default: false, null: false
|
||||||
t.integer "priority"
|
t.integer "priority"
|
||||||
t.text "url_args"
|
t.text "url_args"
|
||||||
|
@ -259,8 +257,8 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
create_table "subscriptions", id: :serial, force: :cascade do |t|
|
create_table "subscriptions", id: :serial, force: :cascade do |t|
|
||||||
t.bigint "user_id", null: false
|
t.bigint "user_id", null: false
|
||||||
t.bigint "answer_id", null: false
|
t.bigint "answer_id", null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", precision: nil, null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", precision: nil, null: false
|
||||||
t.index ["user_id", "answer_id"], name: "index_subscriptions_on_user_id_and_answer_id"
|
t.index ["user_id", "answer_id"], name: "index_subscriptions_on_user_id_and_answer_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -282,8 +280,8 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.integer "background_color", default: 15789556
|
t.integer "background_color", default: 15789556
|
||||||
t.integer "body_text", default: 0
|
t.integer "body_text", default: 0
|
||||||
t.integer "muted_text", default: 7107965
|
t.integer "muted_text", default: 7107965
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", precision: nil, null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", precision: nil, null: false
|
||||||
t.integer "input_color", default: 15789556, null: false
|
t.integer "input_color", default: 15789556, null: false
|
||||||
t.integer "input_text", default: 0, null: false
|
t.integer "input_text", default: 0, null: false
|
||||||
t.integer "raised_accent", default: 16250871
|
t.integer "raised_accent", default: 16250871
|
||||||
|
@ -304,25 +302,25 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
create_table "user_bans", force: :cascade do |t|
|
create_table "user_bans", force: :cascade do |t|
|
||||||
t.bigint "user_id"
|
t.bigint "user_id"
|
||||||
t.string "reason"
|
t.string "reason"
|
||||||
t.datetime "expires_at"
|
t.datetime "expires_at", precision: nil
|
||||||
t.bigint "banned_by_id"
|
t.bigint "banned_by_id"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", precision: nil, null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", precision: nil, null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", id: :bigint, default: -> { "gen_timestamp_id('users'::text)" }, force: :cascade do |t|
|
create_table "users", id: :bigint, default: -> { "gen_timestamp_id('users'::text)" }, force: :cascade do |t|
|
||||||
t.string "email", default: "", null: false
|
t.string "email", default: "", null: false
|
||||||
t.string "encrypted_password", default: "", null: false
|
t.string "encrypted_password", default: "", null: false
|
||||||
t.string "reset_password_token"
|
t.string "reset_password_token"
|
||||||
t.datetime "reset_password_sent_at"
|
t.datetime "reset_password_sent_at", precision: nil
|
||||||
t.datetime "remember_created_at"
|
t.datetime "remember_created_at", precision: nil
|
||||||
t.integer "sign_in_count", default: 0, null: false
|
t.integer "sign_in_count", default: 0, null: false
|
||||||
t.datetime "current_sign_in_at"
|
t.datetime "current_sign_in_at", precision: nil
|
||||||
t.datetime "last_sign_in_at"
|
t.datetime "last_sign_in_at", precision: nil
|
||||||
t.string "current_sign_in_ip"
|
t.string "current_sign_in_ip"
|
||||||
t.string "last_sign_in_ip"
|
t.string "last_sign_in_ip"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at", precision: nil
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at", precision: nil
|
||||||
t.string "screen_name"
|
t.string "screen_name"
|
||||||
t.integer "asked_count", default: 0, null: false
|
t.integer "asked_count", default: 0, null: false
|
||||||
t.integer "answered_count", default: 0, null: false
|
t.integer "answered_count", default: 0, null: false
|
||||||
|
@ -347,13 +345,13 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.integer "profile_header_h"
|
t.integer "profile_header_h"
|
||||||
t.string "locale", default: "en"
|
t.string "locale", default: "en"
|
||||||
t.string "confirmation_token"
|
t.string "confirmation_token"
|
||||||
t.datetime "confirmed_at"
|
t.datetime "confirmed_at", precision: nil
|
||||||
t.datetime "confirmation_sent_at"
|
t.datetime "confirmation_sent_at", precision: nil
|
||||||
t.string "unconfirmed_email"
|
t.string "unconfirmed_email"
|
||||||
t.boolean "show_foreign_themes", default: true, null: false
|
t.boolean "show_foreign_themes", default: true, null: false
|
||||||
t.string "export_url"
|
t.string "export_url"
|
||||||
t.boolean "export_processing", default: false, null: false
|
t.boolean "export_processing", default: false, null: false
|
||||||
t.datetime "export_created_at"
|
t.datetime "export_created_at", precision: nil
|
||||||
t.string "otp_secret_key"
|
t.string "otp_secret_key"
|
||||||
t.integer "otp_module", default: 0, null: false
|
t.integer "otp_module", default: 0, null: false
|
||||||
t.boolean "privacy_lock_inbox", default: false
|
t.boolean "privacy_lock_inbox", default: false
|
||||||
|
@ -363,8 +361,8 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
t.boolean "sharing_enabled", default: false
|
t.boolean "sharing_enabled", default: false
|
||||||
t.boolean "sharing_autoclose", default: false
|
t.boolean "sharing_autoclose", default: false
|
||||||
t.string "sharing_custom_url"
|
t.string "sharing_custom_url"
|
||||||
t.datetime "notifications_updated_at"
|
t.datetime "notifications_updated_at", precision: nil
|
||||||
t.datetime "inbox_updated_at"
|
t.datetime "inbox_updated_at", precision: nil
|
||||||
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
||||||
t.index ["email"], name: "index_users_on_email", unique: true
|
t.index ["email"], name: "index_users_on_email", unique: true
|
||||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||||
|
@ -382,8 +380,8 @@ ActiveRecord::Schema.define(version: 2023_10_18_172518) do
|
||||||
create_table "web_push_subscriptions", force: :cascade do |t|
|
create_table "web_push_subscriptions", force: :cascade do |t|
|
||||||
t.bigint "user_id", null: false
|
t.bigint "user_id", null: false
|
||||||
t.json "subscription"
|
t.json "subscription"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", null: false
|
||||||
t.integer "failures", default: 0
|
t.integer "failures", default: 0
|
||||||
t.index ["user_id"], name: "index_web_push_subscriptions_on_user_id"
|
t.index ["user_id"], name: "index_web_push_subscriptions_on_user_id"
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ require "zip/filesystem"
|
||||||
# require all data export use cases via Zeitwerk
|
# require all data export use cases via Zeitwerk
|
||||||
# rubocop:disable Lint/Void
|
# rubocop:disable Lint/Void
|
||||||
UseCase::DataExport::Answers
|
UseCase::DataExport::Answers
|
||||||
UseCase::DataExport::Appendables
|
UseCase::DataExport::Reactions
|
||||||
UseCase::DataExport::Comments
|
UseCase::DataExport::Comments
|
||||||
UseCase::DataExport::MuteRules
|
UseCase::DataExport::MuteRules
|
||||||
UseCase::DataExport::Questions
|
UseCase::DataExport::Questions
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module UseCase
|
|
||||||
module DataExport
|
|
||||||
class Appendables < UseCase::DataExport::Base
|
|
||||||
def files = {
|
|
||||||
"appendables.json" => json_file!(
|
|
||||||
appendables: [
|
|
||||||
*user.smiles.map(&method(:collect_appendable))
|
|
||||||
]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
def collect_appendable(appendable)
|
|
||||||
{}.tap do |h|
|
|
||||||
column_names(::Appendable).each do |field|
|
|
||||||
h[field] = appendable[field]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module UseCase
|
||||||
|
module DataExport
|
||||||
|
class Reactions < UseCase::DataExport::Base
|
||||||
|
def files = {
|
||||||
|
"reactions.json" => json_file!(
|
||||||
|
reactions: [
|
||||||
|
*user.smiles.map(&method(:collect_reaction))
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
def collect_reaction(reaction)
|
||||||
|
{}.tap do |h|
|
||||||
|
column_names(::Reaction).each do |field|
|
||||||
|
h[field] = reaction[field]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -28,8 +28,8 @@ describe Ajax::SmileController, :ajax_controller, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a smile to the answer" do
|
it "creates a smile to the answer" do
|
||||||
expect { subject }.to(change { Appendable::Reaction.count }.by(1))
|
expect { subject }.to(change { Reaction.count }.by(1))
|
||||||
expect(answer.reload.smiles.ids).to include(Appendable::Reaction.last.id)
|
expect(answer.reload.smiles.ids).to include(Reaction.last.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
include_examples "returns the expected response"
|
||||||
|
@ -47,7 +47,7 @@ describe Ajax::SmileController, :ajax_controller, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not create a smile" do
|
it "does not create a smile" do
|
||||||
expect { subject }.not_to(change { Appendable::Reaction.count })
|
expect { subject }.not_to(change { Reaction.count })
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
include_examples "returns the expected response"
|
||||||
|
@ -100,7 +100,7 @@ describe Ajax::SmileController, :ajax_controller, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not create a smile" do
|
it "does not create a smile" do
|
||||||
expect { subject }.not_to(change { Appendable::Reaction.count })
|
expect { subject }.not_to(change { Reaction.count })
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
include_examples "returns the expected response"
|
||||||
|
@ -124,7 +124,7 @@ describe Ajax::SmileController, :ajax_controller, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not create a smile" do
|
it "does not create a smile" do
|
||||||
expect { subject }.not_to(change { Appendable::Reaction.count })
|
expect { subject }.not_to(change { Reaction.count })
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
include_examples "returns the expected response"
|
||||||
|
@ -160,7 +160,7 @@ describe Ajax::SmileController, :ajax_controller, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "deletes the smile" do
|
it "deletes the smile" do
|
||||||
expect { subject }.to(change { Appendable::Reaction.count }.by(-1))
|
expect { subject }.to(change { Reaction.count }.by(-1))
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
include_examples "returns the expected response"
|
||||||
|
@ -219,8 +219,8 @@ describe Ajax::SmileController, :ajax_controller, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a smile to the comment" do
|
it "creates a smile to the comment" do
|
||||||
expect { subject }.to(change { Appendable::Reaction.count }.by(1))
|
expect { subject }.to(change { Reaction.count }.by(1))
|
||||||
expect(comment.reload.smiles.ids).to include(Appendable::Reaction.last.id)
|
expect(comment.reload.smiles.ids).to include(Reaction.last.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
include_examples "returns the expected response"
|
||||||
|
@ -238,7 +238,7 @@ describe Ajax::SmileController, :ajax_controller, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not create a smile" do
|
it "does not create a smile" do
|
||||||
expect { subject }.not_to(change { Appendable::Reaction.count })
|
expect { subject }.not_to(change { Reaction.count })
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
include_examples "returns the expected response"
|
||||||
|
@ -304,7 +304,7 @@ describe Ajax::SmileController, :ajax_controller, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "deletes the smile" do
|
it "deletes the smile" do
|
||||||
expect { subject }.to(change { Appendable::Reaction.count }.by(-1))
|
expect { subject }.to(change { Reaction.count }.by(-1))
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
include_examples "returns the expected response"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :comment_smile, class: Appendable::Reaction do
|
factory :comment_smile, class: Reaction do
|
||||||
user { FactoryBot.build(:user) }
|
user { FactoryBot.build(:user) }
|
||||||
parent { FactoryBot.build(:comment) }
|
parent { FactoryBot.build(:comment) }
|
||||||
content { "🙂" }
|
content { "🙂" }
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :smile, class: Appendable::Reaction do
|
factory :smile, class: Reaction do
|
||||||
user { FactoryBot.create(:user) }
|
user { FactoryBot.create(:user) }
|
||||||
parent { FactoryBot.create(:answer, user: FactoryBot.create(:user)) }
|
parent { FactoryBot.create(:answer, user: FactoryBot.create(:user)) }
|
||||||
content { "🙂" }
|
content { "🙂" }
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
|
|
||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe UseCase::DataExport::Appendables, :data_export do
|
describe UseCase::DataExport::Reactions, :data_export do
|
||||||
include ActiveSupport::Testing::TimeHelpers
|
include ActiveSupport::Testing::TimeHelpers
|
||||||
|
|
||||||
context "when user doesn't have any appendable" do
|
context "when user doesn't have any reactions" do
|
||||||
it "returns an empty set of appendables" do
|
it "returns an empty set of reactions" do
|
||||||
expect(json_file("appendables.json")).to eq(
|
expect(json_file("reactions.json")).to eq(
|
||||||
{
|
{
|
||||||
appendables: []
|
reactions: []
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -19,32 +19,32 @@ describe UseCase::DataExport::Appendables, :data_export do
|
||||||
let(:answer) { FactoryBot.create(:answer, user:) }
|
let(:answer) { FactoryBot.create(:answer, user:) }
|
||||||
let(:comment) { FactoryBot.create(:comment, user:, answer:) }
|
let(:comment) { FactoryBot.create(:comment, user:, answer:) }
|
||||||
|
|
||||||
let!(:appendables) do
|
let!(:reactions) do
|
||||||
[
|
[
|
||||||
travel_to(Time.utc(2022, 12, 10, 13, 37, 42)) { FactoryBot.create(:comment_smile, user:, parent: comment) },
|
travel_to(Time.utc(2022, 12, 10, 13, 37, 42)) { FactoryBot.create(:comment_smile, user:, parent: comment) },
|
||||||
travel_to(Time.utc(2022, 12, 10, 13, 39, 21)) { FactoryBot.create(:smile, user:, parent: answer) }
|
travel_to(Time.utc(2022, 12, 10, 13, 39, 21)) { FactoryBot.create(:smile, user:, parent: answer) }
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the appendables as json" do
|
it "returns the reactions as json" do
|
||||||
expect(json_file("appendables.json")).to eq(
|
expect(json_file("reactions.json")).to eq(
|
||||||
{
|
{
|
||||||
appendables: [
|
reactions: [
|
||||||
{
|
{
|
||||||
id: appendables[0].id,
|
id: reactions[0].id,
|
||||||
type: "Appendable::Reaction",
|
type: "Reaction",
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
parent_id: appendables[0].parent_id,
|
parent_id: reactions[0].parent_id,
|
||||||
parent_type: "Comment",
|
parent_type: "Comment",
|
||||||
content: "🙂",
|
content: "🙂",
|
||||||
created_at: "2022-12-10T13:37:42.000Z",
|
created_at: "2022-12-10T13:37:42.000Z",
|
||||||
updated_at: "2022-12-10T13:37:42.000Z"
|
updated_at: "2022-12-10T13:37:42.000Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: appendables[1].id,
|
id: reactions[1].id,
|
||||||
type: "Appendable::Reaction",
|
type: "Reaction",
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
parent_id: appendables[1].parent_id,
|
parent_id: reactions[1].parent_id,
|
||||||
parent_type: "Answer",
|
parent_type: "Answer",
|
||||||
content: "🙂",
|
content: "🙂",
|
||||||
created_at: "2022-12-10T13:39:21.000Z",
|
created_at: "2022-12-10T13:39:21.000Z",
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Appendable::Reaction do
|
describe Reaction do
|
||||||
let(:user) { FactoryBot.create(:user) }
|
let(:user) { FactoryBot.create(:user) }
|
||||||
let(:owner) { FactoryBot.create(:user) }
|
let(:owner) { FactoryBot.create(:user) }
|
||||||
let(:parent) { FactoryBot.create(:answer, user: owner) }
|
let(:parent) { FactoryBot.create(:answer, user: owner) }
|
Loading…
Reference in New Issue