Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emoji's in Comments #2477

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions db/migrate/20241008214055_change_comments_charset_and_collation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ChangeCommentsCharsetAndCollation < ActiveRecord::Migration[7.1]
def up
execute <<-SQL
ALTER TABLE comments CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
SQL
end

def down
execute <<-SQL
ALTER TABLE comments CONVERT TO CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci;
SQL
end
end
13 changes: 13 additions & 0 deletions db/migrate/20241008225112_rss_logs_charset_and_collation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class RssLogsCharsetAndCollation < ActiveRecord::Migration[7.1]
def up
execute <<-SQL
ALTER TABLE rss_logs CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
SQL
end

def down
execute <<-SQL
ALTER TABLE rss_logs CONVERT TO CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci;
SQL
end
end
10 changes: 5 additions & 5 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_10_01_233907) do
ActiveRecord::Schema[7.1].define(version: 2024_10_08_225112) do
create_table "api_keys", id: :integer, charset: "utf8mb3", force: :cascade do |t|
t.datetime "created_at", precision: nil
t.datetime "last_used", precision: nil
Expand Down Expand Up @@ -38,11 +38,11 @@
t.string "number"
end

create_table "comments", id: :integer, charset: "utf8mb3", force: :cascade do |t|
create_table "comments", id: :integer, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.datetime "created_at", precision: nil
t.integer "user_id"
t.string "summary", limit: 100
t.text "comment"
t.text "comment", size: :medium
t.string "target_type", limit: 30
t.integer "target_id"
t.datetime "updated_at", precision: nil
Expand Down Expand Up @@ -629,11 +629,11 @@
t.integer "to_user_id"
end

create_table "rss_logs", id: :integer, charset: "utf8mb3", force: :cascade do |t|
create_table "rss_logs", id: :integer, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.integer "observation_id"
t.integer "species_list_id"
t.datetime "updated_at", precision: nil
t.text "notes"
t.text "notes", size: :medium
t.integer "name_id"
t.integer "location_id"
t.integer "project_id"
Expand Down
22 changes: 22 additions & 0 deletions test/controllers/comments_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,28 @@ def test_save_comment
assert_equal("Some text.", comment.comment)
end

def test_save_comment_with_emojis
assert_equal(10, rolf.contribution)
obs = observations(:minimal_unknown_obs)
comment_count = obs.comments.size
params = { target: obs.id,
type: "Observation",
comment: { summary: "🍄 emoji in summary",
comment: "🍄‍🟫 and in body" } }

assert_nothing_raised do
post_requires_login(:create, params)
end

assert_redirected_to(permanent_observation_path(obs.id))
assert_equal(11, rolf.reload.contribution)
obs.reload
assert_equal(comment_count + 1, obs.comments.size)
comment = Comment.last
assert_equal("🍄 emoji in summary", comment.summary)
assert_equal("🍄‍🟫 and in body", comment.comment)
end

def test_update_comment
comment = comments(:minimal_unknown_obs_comment_1)
obs = comment.target
Expand Down