From ecf82d8703b09f2d940cdd916d42e7309b1f8232 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Thu, 29 May 2025 12:37:16 +0200 Subject: [PATCH] Make tests pass with action text --- Gemfile | 2 +- Gemfile.lock | 3 +-- .../cards/comments_controller_test.rb | 4 +-- test/controllers/uploads_controller_test.rb | 25 ------------------- test/fixtures/action_text/markdowns.yml | 14 ----------- test/fixtures/action_text/rich_texts.yml | 20 ++++++++++++--- test/test_helper.rb | 2 +- test/test_helpers/action_text_test_helper.rb | 21 ++++++++++++++++ 8 files changed, 42 insertions(+), 49 deletions(-) delete mode 100644 test/controllers/uploads_controller_test.rb delete mode 100644 test/fixtures/action_text/markdowns.yml create mode 100644 test/test_helpers/action_text_test_helper.rb diff --git a/Gemfile b/Gemfile index c0455d262..d5b333b2c 100644 --- a/Gemfile +++ b/Gemfile @@ -27,7 +27,7 @@ gem "rqrcode" gem "redcarpet" gem "rouge" gem "jbuilder" -gem "actiontext-lexical", github: "basecamp/actiontext-lexical", branch: "initial" +gem "actiontext-lexical", github: "basecamp/actiontext-lexical" gem "image_processing", "~> 1.14" # Telemetry and logging diff --git a/Gemfile.lock b/Gemfile.lock index d9b3c3297..b3cefa8c6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,6 @@ GIT remote: https://github.com/basecamp/actiontext-lexical.git - revision: 8804035239fc0ba320dcb3cce47d56297af37634 - branch: initial + revision: 19038b86b8617062adbb930990edaacc1f643e3d specs: actiontext-lexical (0.1.0) rails (>= 8.0.2) diff --git a/test/controllers/cards/comments_controller_test.rb b/test/controllers/cards/comments_controller_test.rb index 690cf0656..012503e41 100644 --- a/test/controllers/cards/comments_controller_test.rb +++ b/test/controllers/cards/comments_controller_test.rb @@ -17,11 +17,11 @@ class Cards::CommentsControllerTest < ActionDispatch::IntegrationTest put card_comment_path(cards(:logo), comments(:logo_agreement_kevin)), params: { comment: { body: "I've changed my mind" } } assert_response :success - assert_equal "I've changed my mind", comments(:logo_agreement_kevin).reload.body.content + assert_action_text "I've changed my mind", comments(:logo_agreement_kevin).reload.body end test "update another user's comment" do - assert_no_changes "comments(:logo_agreement_jz).body.content" do + assert_no_changes ->{ comments(:logo_agreement_jz).reload.body.to_s } do put card_comment_path(cards(:logo), comments(:logo_agreement_jz)), params: { comment: { body: "I've changed my mind" } } end diff --git a/test/controllers/uploads_controller_test.rb b/test/controllers/uploads_controller_test.rb deleted file mode 100644 index 3f5f54af5..000000000 --- a/test/controllers/uploads_controller_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -require "test_helper" - -class UploadsControllerTest < ActionDispatch::IntegrationTest - setup do - sign_in_as :kevin - end - - test "create" do - assert_changes -> { ActiveStorage::Attachment.count }, 1 do - post uploads_path(format: "json"), params: { file: fixture_file_upload("moon.jpg", "image/jpeg") }, as: :xhr - end - - assert_response :success - assert_equal ActiveStorage::Attachment.last.slug_url(host: "#{ApplicationRecord.current_tenant}.example.com", port: nil), response.parsed_body["fileUrl"] - assert_equal "image/jpeg", response.parsed_body["mimetype"] - assert_equal "moon.jpg", response.parsed_body["fileName"] - end - - test "show" do - accounts("37s").uploads.attach fixture_file_upload("moon.jpg", "image/jpeg") - get upload_path(slug: accounts("37s").uploads.last.slug) - assert_response :redirect - assert_match /\/rails\/active_storage\/.*\/moon\.jpg/, @response.redirect_url - end -end diff --git a/test/fixtures/action_text/markdowns.yml b/test/fixtures/action_text/markdowns.yml deleted file mode 100644 index 519cd408b..000000000 --- a/test/fixtures/action_text/markdowns.yml +++ /dev/null @@ -1,14 +0,0 @@ -logo_agreement_jz: - record: logo_agreement_jz (Comment) - name: body - content: I agree. - -logo_agreement_kevin: - record: logo_agreement_kevin (Comment) - name: body - content: Same, let’s do it. - -layout_overflowing_david: - record: layout_overflowing_david (Comment) - name: body - content: The text is overflowing the container. diff --git a/test/fixtures/action_text/rich_texts.yml b/test/fixtures/action_text/rich_texts.yml index 8b371ea60..9a86c3b30 100644 --- a/test/fixtures/action_text/rich_texts.yml +++ b/test/fixtures/action_text/rich_texts.yml @@ -1,4 +1,16 @@ -# one: -# record: name_of_fixture (ClassOfFixture) -# name: content -# body:

In a million stars!

+logo_agreement_jz: + record: logo_agreement_jz (Comment) + name: body + body: I agree. + +logo_agreement_kevin: + record: logo_agreement_kevin (Comment) + name: body + body: Same, let’s do it. + +layout_overflowing_david: + record: layout_overflowing_david (Comment) + name: body + body: The text is overflowing the container. + + diff --git a/test/test_helper.rb b/test/test_helper.rb index 6e27d82fa..4e0a9fcee 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -22,7 +22,7 @@ module ActiveSupport fixtures :all include ActiveJob::TestHelper - include CardTestHelper, ChangeTestHelper, SessionTestHelper + include ActionTextTestHelper, CardTestHelper, ChangeTestHelper, SessionTestHelper end end diff --git a/test/test_helpers/action_text_test_helper.rb b/test/test_helpers/action_text_test_helper.rb new file mode 100644 index 000000000..037f2561f --- /dev/null +++ b/test/test_helpers/action_text_test_helper.rb @@ -0,0 +1,21 @@ +module ActionTextTestHelper + def assert_action_text(expected_html, content) + assert_equal_html <<~HTML, content.to_s +
#{expected_html} + HTML + end + + def assert_equal_html(expected, actual) + assert_equal normalize_html(expected), normalize_html(actual) + end + + def normalize_html(html) + Nokogiri::HTML.fragment(html).tap do |fragment| + fragment.traverse do |node| + if node.text? + node.content = node.text.strip.gsub(/\s+/, ' ') + end + end + end.to_html.strip + end +end