Project

General

Profile

Actions

Defect #32071

closed

FrozenError in assert_save in test/test_helper.rb

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

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Code cleanup/refactoring
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

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
   end

   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 = Attachment.new(:container => 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:

E

Error:
AttachmentTest#test_extension_should_be_validated_against_allowed_extensions:
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 = object.save
     message = "#{object.class} could not be saved" 
     errors = object.errors.full_messages.map {|m| "- #{m}"}
-    message << ":\n#{errors.join("\n")}" if errors.any?
+    message += ":\n#{errors.join("\n")}" if errors.any?
     assert_equal true, saved, message
   end


Related issues

Related to Redmine - Feature #26561: Enable frozen string literalsClosedGo MAEDA

Actions
Actions #1

Updated by Go MAEDA about 5 years ago

Actions #2

Updated by Go MAEDA about 5 years ago

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

Committed the patch.

Actions

Also available in: Atom PDF