A platform for community discussion. Free, open, simple.
DEV: Clean up d-cakeday code after the move (#35213)
Jarek Radoszc02de976fc2e
diff --git a/plugins/discourse-cakeday/config/routes.rb b/plugins/discourse-cakeday/config/routes.rbnew file mode 100644index 00000000000..9523083ce81--- /dev/null+++ b/plugins/discourse-cakeday/config/routes.rb@@ -0,0 +1,8 @@+# frozen_string_literal: true++DiscourseCakeday::Engine.routes.draw do+ get "birthdays" => "birthdays#index"+ get "birthdays/:filter" => "birthdays#index"+ get "anniversaries" => "anniversaries#index"+ get "anniversaries/:filter" => "anniversaries#index"+enddiff --git a/plugins/discourse-cakeday/db/migrate/20250717093505_persist_cakeday_enabled.rb b/plugins/discourse-cakeday/db/migrate/20250717093505_persist_cakeday_enabled.rbindex f5bfb6194fd..8a3fb509fdf 100644--- a/plugins/discourse-cakeday/db/migrate/20250717093505_persist_cakeday_enabled.rb+++ b/plugins/discourse-cakeday/db/migrate/20250717093505_persist_cakeday_enabled.rb@@ -1,17 +1,17 @@# frozen_string_literal: true-# TODO: Comment this migration out when merging the plugin into core+# Commented out because this was only required to move this plugin into coreclass PersistCakedayEnabled < ActiveRecord::Migration[7.2]- def up- # 5 is bool data_type- DB.exec(<<~SQL, value: SiteSetting.cakeday_enabled ? "t" : "f")- INSERT INTO site_settings(name, data_type, value, created_at, updated_at)- VALUES('cakeday_enabled', 5, :value, NOW(), NOW())- ON CONFLICT (name) DO NOTHING- SQL- end+ # def up+ # # 5 is bool data_type+ # DB.exec(<<~SQL, value: SiteSetting.cakeday_enabled ? "t" : "f")+ # INSERT INTO site_settings(name, data_type, value, created_at, updated_at)+ # VALUES('cakeday_enabled', 5, :value, NOW(), NOW())+ # ON CONFLICT (name) DO NOTHING+ # SQL+ # end- def down- raise ActiveRecord::IrreversibleMigration- end+ # def down+ # raise ActiveRecord::IrreversibleMigration+ # endenddiff --git a/plugins/discourse-cakeday/db/migrate/20250811132217_persist_cakeday_birthday_enabled.rb b/plugins/discourse-cakeday/db/migrate/20250811132217_persist_cakeday_birthday_enabled.rbindex 7323bf3013b..29708b52c7a 100644--- a/plugins/discourse-cakeday/db/migrate/20250811132217_persist_cakeday_birthday_enabled.rb+++ b/plugins/discourse-cakeday/db/migrate/20250811132217_persist_cakeday_birthday_enabled.rb@@ -1,17 +1,17 @@# frozen_string_literal: true-# TODO: Comment this migration out when merging the plugin into core+# Commented out because this was only required to move this plugin into coreclass PersistCakedayBirthdayEnabled < ActiveRecord::Migration[8.0]- def up- # 5 is bool data_type- DB.exec(<<~SQL, value: SiteSetting.cakeday_birthday_enabled ? "t" : "f")- INSERT INTO site_settings(name, data_type, value, created_at, updated_at)- VALUES('cakeday_birthday_enabled', 5, :value, NOW(), NOW())- ON CONFLICT (name) DO NOTHING- SQL- end+ # def up+ # # 5 is bool data_type+ # DB.exec(<<~SQL, value: SiteSetting.cakeday_birthday_enabled ? "t" : "f")+ # INSERT INTO site_settings(name, data_type, value, created_at, updated_at)+ # VALUES('cakeday_birthday_enabled', 5, :value, NOW(), NOW())+ # ON CONFLICT (name) DO NOTHING+ # SQL+ # end- def down- raise ActiveRecord::IrreversibleMigration- end+ # def down+ # raise ActiveRecord::IrreversibleMigration+ # endenddiff --git a/plugins/discourse-cakeday/lib/discourse_cakeday/engine.rb b/plugins/discourse-cakeday/lib/discourse_cakeday/engine.rbnew file mode 100644index 00000000000..cfd7232de43--- /dev/null+++ b/plugins/discourse-cakeday/lib/discourse_cakeday/engine.rb@@ -0,0 +1,8 @@+# frozen_string_literal: true++module DiscourseCakeday+ class Engine < ::Rails::Engine+ engine_name PLUGIN_NAME+ isolate_namespace DiscourseCakeday+ end+enddiff --git a/plugins/discourse-cakeday/plugin.rb b/plugins/discourse-cakeday/plugin.rbindex b0b1a090306..1dffd7eeab8 100644--- a/plugins/discourse-cakeday/plugin.rb+++ b/plugins/discourse-cakeday/plugin.rb@@ -9,28 +9,18 @@register_asset "stylesheets/cakeday.scss"register_asset "stylesheets/emoji-images.scss"-register_svg_icon "cake-candles" if respond_to?(:register_svg_icon)+register_svg_icon "cake-candles"enabled_site_setting :cakeday_enabled-after_initialize do- module ::DiscourseCakeday- PLUGIN_NAME = "discourse-cakeday"-- class Engine < ::Rails::Engine- engine_name PLUGIN_NAME- isolate_namespace DiscourseCakeday- end- end+module ::DiscourseCakeday+ PLUGIN_NAME = "discourse-cakeday"+end- ::DiscourseCakeday::Engine.routes.draw do- get "birthdays" => "birthdays#index"- get "birthdays/:filter" => "birthdays#index"- get "anniversaries" => "anniversaries#index"- get "anniversaries/:filter" => "anniversaries#index"- end+require_relative "lib/discourse_cakeday/engine"- Discourse::Application.routes.append { mount ::DiscourseCakeday::Engine, at: "/cakeday" }+after_initialize do+ Discourse::Application.routes.append { mount DiscourseCakeday::Engine, at: "/cakeday" }require_relative "app/jobs/onceoff/fix_invalid_date_of_birth"require_relative "app/jobs/onceoff/migrate_date_of_birth_to_users_table"diff --git a/plugins/discourse-cakeday/spec/integration/cakeday_spec.rb b/plugins/discourse-cakeday/spec/integration/cakeday_spec.rbindex a9bef3c86e7..4e82b3044f3 100644--- a/plugins/discourse-cakeday/spec/integration/cakeday_spec.rb+++ b/plugins/discourse-cakeday/spec/integration/cakeday_spec.rb@@ -1,10 +1,13 @@# frozen_string_literal: true-require "rails_helper"+RSpec.describe "Anniversaries and Birthdays" do+ before do+ SiteSetting.cakeday_enabled = true+ SiteSetting.cakeday_birthday_enabled = true+ end-describe "Anniversaries and Birthdays" dodescribe "when not logged in" do- it "should return the right response" do+ it "returns the right response" doget "/cakeday/anniversaries.json"expect(response.status).to eq(403)end@@ -16,14 +19,14 @@ describe "Anniversaries and Birthdays" dobefore { sign_in(current_user) }- it "should return 404 when viewing anniversaries and cakeday_enabled is false" do+ it "returns 404 when viewing anniversaries and cakeday_enabled is false" doSiteSetting.cakeday_enabled = falseget "/cakeday/anniversaries.json"expect(response.status).to eq(404)end- it "should return 404 when viewing birthdays and cakeday_birthday_enabled is false" do+ it "returns 404 when viewing birthdays and cakeday_birthday_enabled is false" doSiteSetting.cakeday_birthday_enabled = falseget "/cakeday/birthdays.json"@@ -31,7 +34,7 @@ describe "Anniversaries and Birthdays" doenddescribe "when viewing anniversaries" do- it "should return the right payload" do+ it "returns the right payload" dofreeze_time(time) docreated_at = time - 1.year@@ -47,27 +50,27 @@ describe "Anniversaries and Birthdays" doget "/cakeday/anniversaries.json", params: { month: time.month }- body = JSON.parse(response.body)+ body = response.parsed_bodyexpect(body["anniversaries"].map { |u| u["id"] }).to eq [user2.id, user1.id, user3.id]get "/cakeday/anniversaries.json", params: { filter: "today" }- body = JSON.parse(response.body)+ body = response.parsed_bodyexpect(body["anniversaries"].map { |u| u["id"] }).to eq [user1.id, user3.id]get "/cakeday/anniversaries.json", params: { filter: "tomorrow" }- body = JSON.parse(response.body)+ body = response.parsed_bodyexpect(body["anniversaries"].map { |u| u["id"] }).to eq [user4.id]get "/cakeday/anniversaries.json", params: { filter: "upcoming" }- body = JSON.parse(response.body)+ body = response.parsed_bodyexpect(body["anniversaries"].map { |u| u["id"] }).to eq [user5.id]endend- it "should account for the current user's timezone" do+ it "accounts for the current user's timezone" do# Asia/Calcutta is +5.5 hours from UTCcurrent_user.user_option.update!(timezone: "Asia/Calcutta")@@ -84,12 +87,12 @@ describe "Anniversaries and Birthdays" doget "/cakeday/anniversaries.json", params: { filter: "today" }- body = JSON.parse(response.body)+ body = response.parsed_bodyexpect(body["anniversaries"].map { |u| u["id"] }).to contain_exactly(user1.id, user2.id)get "/cakeday/anniversaries.json", params: { filter: "tomorrow" }- body = JSON.parse(response.body)+ body = response.parsed_bodyexpect(body["anniversaries"].map { |u| u["id"] }).to contain_exactly(user3.id, user4.id)endend@@ -98,7 +101,7 @@ describe "Anniversaries and Birthdays" dodescribe "when viewing birthdays" dolet(:time) { Time.zone.local(2016, 9, 30) }- it "should return the right payload" do+ it "returns the right payload" dofreeze_time(time) douser1 = Fabricate(:user, date_of_birth: "1904-9-28")user2 = Fabricate(:user, date_of_birth: "1904-9-29")@@ -108,22 +111,22 @@ describe "Anniversaries and Birthdays" doget "/cakeday/birthdays.json", params: { month: time.month }- body = JSON.parse(response.body)+ body = response.parsed_bodyexpect(body["birthdays"].map { |u| u["id"] }).to eq [user1.id, user2.id, user3.id]get "/cakeday/birthdays.json", params: { filter: "today" }- body = JSON.parse(response.body)+ body = response.parsed_bodyexpect(body["birthdays"].map { |u| u["id"] }).to eq [user3.id]get "/cakeday/birthdays.json", params: { filter: "tomorrow" }- body = JSON.parse(response.body)+ body = response.parsed_bodyexpect(body["birthdays"].map { |u| u["id"] }).to eq [user4.id]get "/cakeday/birthdays.json", params: { filter: "upcoming" }- body = JSON.parse(response.body)+ body = response.parsed_bodyexpect(body["birthdays"].map { |u| u["id"] }).to eq [user5.id]endend@@ -139,14 +142,14 @@ describe "Anniversaries and Birthdays" doget "/cakeday/birthdays.json", params: { filter: "today" }- body = JSON.parse(response.body)+ body = response.parsed_bodyexpect(body["birthdays"].map { |u| u["id"] }).to eq [user1.id, user3.id, user2.id]SiteSetting.prioritize_username_in_ux = falseget "/cakeday/birthdays.json", params: { filter: "today" }- body = JSON.parse(response.body)+ body = response.parsed_bodyexpect(body["birthdays"].map { |u| u["id"] }).to eq [user2.id, user3.id, user1.id]endenddiff --git a/plugins/discourse-cakeday/spec/jobs/migrate_date_of_birth_to_users_table_spec.rb b/plugins/discourse-cakeday/spec/jobs/migrate_date_of_birth_to_users_table_spec.rbindex efd49c57036..9a84d6877f3 100644--- a/plugins/discourse-cakeday/spec/jobs/migrate_date_of_birth_to_users_table_spec.rb+++ b/plugins/discourse-cakeday/spec/jobs/migrate_date_of_birth_to_users_table_spec.rb@@ -1,12 +1,10 @@# frozen_string_literal: true-require "rails_helper"--describe Jobs::MigrateDateOfBirthToUsersTable do+RSpec.describe Jobs::MigrateDateOfBirthToUsersTable dolet(:user) { Fabricate(:user) }context "with YYYY-MM-DD" do- it "should migrate successfully" do+ it "migrates successfully" douser.custom_fields["date_of_birth"] = "1904-05-02"user.save!@@ -17,7 +15,7 @@ describe Jobs::MigrateDateOfBirthToUsersTable doendcontext "with DD-MM-YYYY" do- it "should migrate successfully" do+ it "migrates successfully" douser.custom_fields["date_of_birth"] = "02-05-1904"user.save!@@ -28,7 +26,7 @@ describe Jobs::MigrateDateOfBirthToUsersTable doendcontext "with DD/MM/YYYY" do- it "should migrate successfully" do+ it "migrates successfully" douser.custom_fields["date_of_birth"] = "02/05/1904"user.save!diff --git a/plugins/discourse-cakeday/spec/serializers/post_serializer_spec.rb b/plugins/discourse-cakeday/spec/serializers/post_serializer_spec.rbindex 954f1634b06..80ee11dae9e 100644--- a/plugins/discourse-cakeday/spec/serializers/post_serializer_spec.rb+++ b/plugins/discourse-cakeday/spec/serializers/post_serializer_spec.rb@@ -1,7 +1,5 @@# frozen_string_literal: true-require "rails_helper"-RSpec.describe PostSerializer dolet(:user) { Fabricate(:user, date_of_birth: "2017-04-05") }let(:post) { Fabricate(:post, user: user) }@@ -9,17 +7,17 @@ RSpec.describe PostSerializer docontext "when user is logged in" dolet(:serializer) { described_class.new(post, scope: Guardian.new(user), root: false) }- it "should include both the user's birthdate and cakedate" do+ it "includes both the user's birthdate and cakedate" doexpect(serializer.as_json[:user_birthdate]).to eq(user.date_of_birth)expect(serializer.as_json[:user_cakedate]).to eq(user.created_at.strftime("%Y-%m-%d"))end- it "should not include the user's cakedate when cakeday_enabled is false" do+ it "does not include the user's cakedate when cakeday_enabled is false" doSiteSetting.cakeday_enabled = falseexpect(serializer.as_json.has_key?(:user_cakedate)).to eq(false)end- it "should not include the user's birthdate when cakeday_birthday_enabled is false" do+ it "does not include the user's birthdate when cakeday_birthday_enabled is false" doSiteSetting.cakeday_birthday_enabled = falseexpect(serializer.as_json.has_key?(:user_birthdate)).to eq(false)end@@ -27,11 +25,11 @@ RSpec.describe PostSerializer docontext "when user has hidden their profile" dobefore { user.user_option.update!(hide_profile: true) }- it "should not include the user's cakedate" do+ it "does not include the user's cakedate" doexpect(serializer.as_json.has_key?(:user_cakedate)).to eq(false)end- it "should not include the user's birthdate" do+ it "does not include the user's birthdate" doexpect(serializer.as_json.has_key?(:user_birthdate)).to eq(false)endend@@ -40,7 +38,7 @@ RSpec.describe PostSerializer docontext "when user is not logged in" dolet(:serializer) { described_class.new(post, scope: Guardian.new, root: false) }- it "should not include the user's birthdate nor the cakedate" do+ it "does not include the user's birthdate nor the cakedate" doexpect(serializer.as_json.has_key?(:user_birthdate)).to eq(false)expect(serializer.as_json.has_key?(:user_cakedate)).to eq(false)enddiff --git a/plugins/discourse-cakeday/spec/serializers/user_serializer_spec.rb b/plugins/discourse-cakeday/spec/serializers/user_serializer_spec.rbindex 140b2d2bece..e7be8e19fcc 100644--- a/plugins/discourse-cakeday/spec/serializers/user_serializer_spec.rb+++ b/plugins/discourse-cakeday/spec/serializers/user_serializer_spec.rb@@ -1,24 +1,22 @@# frozen_string_literal: true-require "rails_helper"-RSpec.describe UserSerializer dolet(:user) { Fabricate(:user, date_of_birth: "2017-04-05") }context "when user is logged in" dolet(:serializer) { described_class.new(user, scope: Guardian.new(user), root: false) }- it "should include both the user's birthdate and cakedate" do+ it "includes both the user's birthdate and cakedate" doexpect(serializer.as_json[:birthdate]).to eq(user.date_of_birth)expect(serializer.as_json[:cakedate]).to eq(user.created_at.strftime("%Y-%m-%d"))end- it "should not include the user's cakedate when cakeday_enabled is false" do+ it "does not include the user's cakedate when cakeday_enabled is false" doSiteSetting.cakeday_enabled = falseexpect(serializer.as_json.has_key?(:cakedate)).to eq(false)end- it "should not include the user's birthdate when cakeday_birthday_enabled is false" do+ it "does not include the user's birthdate when cakeday_birthday_enabled is false" doSiteSetting.cakeday_birthday_enabled = falseexpect(serializer.as_json.has_key?(:birthdate)).to eq(false)end@@ -26,11 +24,11 @@ RSpec.describe UserSerializer docontext "when user has hidden their profile" dobefore { user.user_option.update!(hide_profile: true) }- it "should not include the user's cakedate" do+ it "does not include the user's cakedate" doexpect(serializer.as_json.has_key?(:user_cakedate)).to eq(false)end- it "should not include the user's birthdate" do+ it "does not include the user's birthdate" doexpect(serializer.as_json.has_key?(:user_birthdate)).to eq(false)endend@@ -39,7 +37,7 @@ RSpec.describe UserSerializer docontext "when user is not logged in" dolet(:serializer) { described_class.new(user, scope: Guardian.new, root: false) }- it "should not include the user's birthdate nor the cakedate" do+ it "does not include the user's birthdate nor the cakedate" doexpect(serializer.as_json.has_key?(:birthdate)).to eq(false)expect(serializer.as_json.has_key?(:cakedate)).to eq(false)enddiff --git a/plugins/discourse-cakeday/spec/system/cakeday_user_summary_spec.rb b/plugins/discourse-cakeday/spec/system/cakeday_user_summary_spec.rbindex 622c79836d9..992882085e2 100644--- a/plugins/discourse-cakeday/spec/system/cakeday_user_summary_spec.rb+++ b/plugins/discourse-cakeday/spec/system/cakeday_user_summary_spec.rb@@ -1,6 +1,6 @@# frozen_string_literal: true-describe "Cakeday/Birthday emojis", type: :system do+RSpec.describe "Cakeday/Birthday emojis" doCONTROL_DATE = Time.zone.local(2020, 6, 10)fab!(:current_user) { Fabricate(:admin, date_of_birth: CONTROL_DATE.prev_year(14)) }diff --git a/plugins/discourse-cakeday/spec/system/core_features_spec.rb b/plugins/discourse-cakeday/spec/system/core_features_spec.rbindex db86db283bd..ea0fa3f5e4d 100644--- a/plugins/discourse-cakeday/spec/system/core_features_spec.rb+++ b/plugins/discourse-cakeday/spec/system/core_features_spec.rb@@ -1,6 +1,6 @@# frozen_string_literal: true-RSpec.describe "Core features", type: :system do+RSpec.describe "Core features" dobefore { enable_current_plugin }it_behaves_like "having working core features"diff --git a/plugins/discourse-cakeday/test/javascripts/acceptance/cakeday-sidebar-test.js b/plugins/discourse-cakeday/test/javascripts/acceptance/cakeday-sidebar-test.jsindex 3eb50857a55..2c7da1ebfa0 100644--- a/plugins/discourse-cakeday/test/javascripts/acceptance/cakeday-sidebar-test.js+++ b/plugins/discourse-cakeday/test/javascripts/acceptance/cakeday-sidebar-test.js@@ -24,7 +24,7 @@ acceptance("Cakeday - Sidebar with cakeday disabled", function (needs) {assert.dom(".sidebar-section-link[data-link-name='anniversaries']")- .doesNotExist("it does not display the anniversaries link in sidebar");+ .doesNotExist("does not display the anniversaries link in sidebar");});test("birthdays sidebar link is hidden", async function (assert) {@@ -36,7 +36,7 @@ acceptance("Cakeday - Sidebar with cakeday disabled", function (needs) {assert.dom(".sidebar-section-link[data-link-name='birthdays']")- .doesNotExist("it does not display the birthdays link in sidebar");+ .doesNotExist("does not display the birthdays link in sidebar");});});@@ -91,7 +91,7 @@ acceptance("Cakeday - Sidebar with cakeday enabled", function (needs) {assert.strictEqual(currentURL(),"/cakeday/anniversaries/today",- "it navigates to the right page"+ "navigates to the right page");});@@ -125,7 +125,7 @@ acceptance("Cakeday - Sidebar with cakeday enabled", function (needs) {assert.strictEqual(currentURL(),"/cakeday/birthdays/today",- "it navigates to the right page"+ "navigates to the right page");});});