Defect #32071

FrozenError in assert_save in test/test_helper.rb

Added by Go MAEDA about 3 years ago. Updated about 3 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:


Category:Code cleanup/refactoring
Target version:-
Resolution:Fixed Affected version:


You can reproduce the error by modifying test/unit/attachment_test.rb as follows and run the test.

diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb
index 2605f03f0..16ee090aa 100644
--- a/test/unit/attachment_test.rb
+++ b/test/unit/attachment_test.rb
@@ -125,7 +125,7 @@ class AttachmentTest < ActiveSupport::TestCase

   def test_extension_should_be_validated_against_allowed_extensions
-    with_settings :attachment_extensions_allowed => "txt, png" do
+    with_settings :attachment_extensions_allowed => "txt, jpg" do
       a = => Issue.find(1),
                          :file => mock_file_with_options(:original_filename => "test.png"),
                          :author => User.find(1))
$ bin/rails test test/unit/attachment_test.rb:127
Run options: --seed 15041

# Running:


FrozenError: can't modify frozen String
    test/test_helper.rb:207:in `assert_save'
    test/unit/attachment_test.rb:132:in `block in test_extension_should_be_validated_against_allowed_extensions'
    test/test_helper.rb:99:in `with_settings'
    test/unit/attachment_test.rb:128:in `test_extension_should_be_validated_against_allowed_extensions'

bin/rails test test/unit/attachment_test.rb:127

It can be fixed with the following patch.

diff --git a/test/test_helper.rb b/test/test_helper.rb
index 6a6fd7fa5..390d09518 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -204,7 +204,7 @@ class ActiveSupport::TestCase
     saved =
     message = "#{object.class} could not be saved" 
     errors = {|m| "- #{m}"}
-    message << ":\n#{errors.join("\n")}" if errors.any?
+    message += ":\n#{errors.join("\n")}" if errors.any?
     assert_equal true, saved, message

Related issues

Related to Redmine - Feature #26561: Enable frozen string literals Closed

Associated revisions

Revision 18474
Added by Go MAEDA about 3 years ago

Fix FrozenError during tests (#32071, #26561).

Patch by Go MAEDA.


#1 Updated by Go MAEDA about 3 years ago

#2 Updated by Go MAEDA about 3 years ago

  • Category set to Code cleanup/refactoring
  • Status changed from New to Closed
  • Resolution set to Fixed

Committed the patch.

Also available in: Atom PDF