Project

General

Profile

« Previous | Next » 

Revision 13257

Removes #respond_to?(:force_encoding) checks in functional tests.

View differences:

sandbox/rails-4.1/test/functional/attachments_controller_test.rb
139 139
    assert a.save
140 140
    assert_equal 'japanese-utf-8.txt', a.filename
141 141

  
142
    str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
143
    str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
142
    str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8')
144 143

  
145 144
    get :show, :id => a.id
146 145
    assert_response :success
sandbox/rails-4.1/test/functional/issues_controller_test.rb
473 473

  
474 474
  def test_index_csv_big_5
475 475
    with_settings :default_language => "zh-TW" do
476
      str_utf8  = "\xe4\xb8\x80\xe6\x9c\x88"
477
      str_big5  = "\xa4@\xa4\xeb"
478
      if str_utf8.respond_to?(:force_encoding)
479
        str_utf8.force_encoding('UTF-8')
480
        str_big5.force_encoding('Big5')
481
      end
476
      str_utf8  = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8')
477
      str_big5  = "\xa4@\xa4\xeb".force_encoding('Big5')
482 478
      issue = Issue.generate!(:subject => str_utf8)
483 479

  
484 480
      get :index, :project_id => 1, 
......
487 483
                  :format => 'csv'
488 484
      assert_equal 'text/csv; header=present', @response.content_type
489 485
      lines = @response.body.chomp.split("\n")
490
      s1 = "\xaa\xac\xbaA"
491
      if str_utf8.respond_to?(:force_encoding)
492
        s1.force_encoding('Big5')
493
      end
486
      s1 = "\xaa\xac\xbaA".force_encoding('Big5')
494 487
      assert_include s1, lines[0]
495 488
      assert_include str_big5, lines[1]
496 489
    end
......
498 491

  
499 492
  def test_index_csv_cannot_convert_should_be_replaced_big_5
500 493
    with_settings :default_language => "zh-TW" do
501
      str_utf8  = "\xe4\xbb\xa5\xe5\x86\x85"
502
      if str_utf8.respond_to?(:force_encoding)
503
        str_utf8.force_encoding('UTF-8')
504
      end
494
      str_utf8  = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
505 495
      issue = Issue.generate!(:subject => str_utf8)
506 496

  
507 497
      get :index, :project_id => 1, 
......
512 502
                  :set_filter => 1
513 503
      assert_equal 'text/csv; header=present', @response.content_type
514 504
      lines = @response.body.chomp.split("\n")
515
      s1 = "\xaa\xac\xbaA" # status
516
      if str_utf8.respond_to?(:force_encoding)
517
        s1.force_encoding('Big5')
518
      end
505
      s1 = "\xaa\xac\xbaA".force_encoding('Big5') # status
519 506
      assert lines[0].include?(s1)
520 507
      s2 = lines[1].split(",")[2]
521
      if s1.respond_to?(:force_encoding)
522
        s3 = "\xa5H?" # subject
523
        s3.force_encoding('Big5')
524
        assert_equal s3, s2
525
      elsif RUBY_PLATFORM == 'java'
508
      if RUBY_PLATFORM == 'java'
526 509
        assert_equal "??", s2
527 510
      else
528
        assert_equal "\xa5H???", s2
511
        s3 = "\xa5H?".force_encoding('Big5') # subject
512
        assert_equal s3, s2
529 513
      end
530 514
    end
531 515
  end
sandbox/rails-4.1/test/functional/repositories_bazaar_controller_test.rb
26 26
  REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
27 27
  REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
28 28
  PRJ_ID = 3
29
  CHAR_1_UTF8_HEX   = "\xc3\x9c"
29
  CHAR_1_UTF8_HEX   = "\xc3\x9c".dup.force_encoding('UTF-8')
30 30

  
31 31
  def setup
32 32
    User.current = nil
......
36 36
                    :url          => REPOSITORY_PATH_TRUNK,
37 37
                    :log_encoding => 'UTF-8')
38 38
    assert @repository
39
    @char_1_utf8 = CHAR_1_UTF8_HEX.dup
40
    if @char_1_utf8.respond_to?(:force_encoding)
41
      @char_1_utf8.force_encoding('UTF-8')
42
    end
43 39
  end
44 40

  
45 41
  if File.directory?(REPOSITORY_PATH)
......
176 172
      end
177 173
    end
178 174

  
179
    if REPOSITORY_PATH.respond_to?(:force_encoding)
180
      def test_annotate_author_non_ascii
181
        log_encoding = nil
182
        if Encoding.locale_charmap == "UTF-8" ||
183
             Encoding.locale_charmap == "ISO-8859-1"
184
          log_encoding = Encoding.locale_charmap
185
        end
186
        unless log_encoding.nil?
187
          repository = Repository::Bazaar.create(
188
                        :project      => @project,
189
                        :url          => File.join(REPOSITORY_PATH, "author_non_ascii"),
190
                        :identifier => 'author_non_ascii',
191
                        :log_encoding => log_encoding)
192
          assert repository
193
          get :annotate, :id => PRJ_ID, :repository_id => 'author_non_ascii',
194
              :path => repository_path_hash(['author-non-ascii-test.txt'])[:param]
195
          assert_response :success
196
          assert_template 'annotate'
197
          assert_select "th.line-num", :text => '1' do
198
            assert_select "+ td.revision" do
199
              assert_select "a", :text => '2'
200
              assert_select "+ td.author", :text => "test #{@char_1_utf8}" do
201
                assert_select "+ td",
202
                              :text => "author non ASCII test"
203
              end
175
    def test_annotate_author_non_ascii
176
      log_encoding = nil
177
      if Encoding.locale_charmap == "UTF-8" ||
178
           Encoding.locale_charmap == "ISO-8859-1"
179
        log_encoding = Encoding.locale_charmap
180
      end
181
      unless log_encoding.nil?
182
        repository = Repository::Bazaar.create(
183
                      :project      => @project,
184
                      :url          => File.join(REPOSITORY_PATH, "author_non_ascii"),
185
                      :identifier => 'author_non_ascii',
186
                      :log_encoding => log_encoding)
187
        assert repository
188
        get :annotate, :id => PRJ_ID, :repository_id => 'author_non_ascii',
189
            :path => repository_path_hash(['author-non-ascii-test.txt'])[:param]
190
        assert_response :success
191
        assert_template 'annotate'
192
        assert_select "th.line-num", :text => '1' do
193
          assert_select "+ td.revision" do
194
            assert_select "a", :text => '2'
195
            assert_select "+ td.author", :text => "test #{CHAR_1_UTF8_HEX}" do
196
              assert_select "+ td",
197
                            :text => "author non ASCII test"
204 198
            end
205 199
          end
206 200
        end
sandbox/rails-4.1/test/functional/repositories_filesystem_controller_test.rb
98 98
               "and Encoding.default_external is not UTF-8. " +
99 99
               "Current value is '#{Encoding.default_external.to_s}'"
100 100
        else
101
          str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
102
          str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
101
          str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8')
103 102
          assert_tag :tag => 'th',
104 103
                     :content => '3',
105 104
                     :attributes => { :class => 'line-num' },
sandbox/rails-4.1/test/functional/repositories_git_controller_test.rb
26 26
  REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
27 27
  REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28 28
  PRJ_ID     = 3
29
  CHAR_1_HEX = "\xc3\x9c"
30
  FELIX_HEX  = "Felix Sch\xC3\xA4fer"
29
  CHAR_1_HEX = "\xc3\x9c".force_encoding('UTF-8')
30
  FELIX_HEX  = "Felix Sch\xC3\xA4fer".force_encoding('UTF-8')
31 31
  NUM_REV = 28
32 32

  
33 33
  ## Git, Mercurial and CVS path encodings are binary.
......
50 50
                      :path_encoding => 'ISO-8859-1'
51 51
                      )
52 52
    assert @repository
53
    @char_1        = CHAR_1_HEX.dup
54
    @felix_utf8  = FELIX_HEX.dup
55
    if @char_1.respond_to?(:force_encoding)
56
      @char_1.force_encoding('UTF-8')
57
      @felix_utf8.force_encoding('UTF-8')
58
    end
59 53
  end
60 54

  
61 55
  def test_create_and_update
......
231 225
        with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
232 226
          ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
233 227
            get :entry, :id => PRJ_ID,
234
                :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
228
                :path => repository_path_hash(['latin-1-dir', "test-#{CHAR_1_HEX}.txt"])[:param],
235 229
                :rev => r1
236 230
            assert_response :success
237 231
            assert_template 'entry'
......
239 233
                   :content => '1',
240 234
                   :attributes => { :class => 'line-num' },
241 235
                   :sibling => { :tag => 'td',
242
                                 :content => /test-#{@char_1}.txt/ }
236
                                 :content => /test-#{CHAR_1_HEX}.txt/ }
243 237
          end
244 238
        end
245 239
      end
......
419 413
                         :descendant => {
420 414
                           :tag => 'th',
421 415
                           :attributes => { :class => 'filename' } ,
422
                           :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
416
                           :content => /latin-1-dir\/test-#{CHAR_1_HEX}.txt/ ,
423 417
                          },
424 418
                         :sibling => {
425 419
                           :tag => 'tbody',
426 420
                           :descendant => {
427 421
                              :tag => 'td',
428 422
                              :attributes => { :class => /diff_in/ },
429
                              :content => /test-#{@char_1}.txt/
423
                              :content => /test-#{CHAR_1_HEX}.txt/
430 424
                           }
431 425
                         }
432 426
            end
......
535 529
        with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
536 530
          ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
537 531
            get :annotate, :id => PRJ_ID,
538
                :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
532
                :path => repository_path_hash(['latin-1-dir', "test-#{CHAR_1_HEX}.txt"])[:param],
539 533
                :rev => r1
540 534
            assert_select "th.line-num", :text => '1' do
541 535
              assert_select "+ td.revision" do
542 536
                assert_select "a", :text => '57ca437c'
543 537
                assert_select "+ td.author", :text => "jsmith" do
544 538
                  assert_select "+ td",
545
                                :text => "test-#{@char_1}.txt"
539
                                :text => "test-#{CHAR_1_HEX}.txt"
546 540
                end
547 541
              end
548 542
            end
......
559 553
        assert_select "th.line-num", :text => '1' do
560 554
          assert_select "+ td.revision" do
561 555
            assert_select "a", :text => '83ca5fd5'
562
            assert_select "+ td.author", :text => @felix_utf8 do
556
            assert_select "+ td.author", :text => FELIX_HEX do
563 557
              assert_select "+ td",
564 558
                            :text => "And this is a file with a leading and trailing space..."
565 559
            end
sandbox/rails-4.1/test/functional/repositories_mercurial_controller_test.rb
41 41
                      )
42 42
    assert @repository
43 43
    @diff_c_support = true
44
    @char_1        = CHAR_1_HEX.dup
45
    @tag_char_1    = "tag-#{CHAR_1_HEX}-00"
46
    @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
47
    @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
48
    if @char_1.respond_to?(:force_encoding)
49
      @char_1.force_encoding('UTF-8')
50
      @tag_char_1.force_encoding('UTF-8')
51
      @branch_char_0.force_encoding('UTF-8')
52
      @branch_char_1.force_encoding('UTF-8')
53
    end
44
    @char_1        = CHAR_1_HEX.dup.force_encoding('UTF-8')
45
    @tag_char_1    = "tag-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
46
    @branch_char_0 = "branch-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
47
    @branch_char_1 = "branch-#{CHAR_1_HEX}-01".force_encoding('UTF-8')
54 48
  end
55 49

  
56 50
  if ruby19_non_utf8_pass
sandbox/rails-4.1/test/functional/time_entry_reports_controller_test.rb
240 240

  
241 241
  def test_csv_big_5
242 242
    Setting.default_language = "zh-TW"
243
    str_utf8  = "\xe4\xb8\x80\xe6\x9c\x88"
244
    str_big5  = "\xa4@\xa4\xeb"
245
    if str_utf8.respond_to?(:force_encoding)
246
      str_utf8.force_encoding('UTF-8')
247
      str_big5.force_encoding('Big5')
248
    end
243
    str_utf8  = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8')
244
    str_big5  = "\xa4@\xa4\xeb".force_encoding('Big5')
249 245
    user = User.find_by_id(3)
250 246
    user.firstname = str_utf8
251 247
    user.lastname  = "test-lastname"
......
270 266
    assert_equal 'text/csv; header=present', @response.content_type
271 267
    lines = @response.body.chomp.split("\n")    
272 268
    # Headers
273
    s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp"
274
    s2 = "\xa4u\xae\xc9\xc1`\xadp"
275
    if s1.respond_to?(:force_encoding)
276
      s1.force_encoding('Big5')
277
      s2.force_encoding('Big5')
278
    end
269
    s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5')
270
    s2 = "\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5')
279 271
    assert_equal s1, lines.first
280 272
    # Total row
281 273
    assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1]
282 274
    assert_equal "#{s2},7.30,7.30", lines[2]
283 275

  
284
    str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
285
    if str_tw.respond_to?(:force_encoding)
286
      str_tw.force_encoding('UTF-8')
287
    end
276
    str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)".force_encoding('UTF-8')
288 277
    assert_equal str_tw, l(:general_lang_name)
289 278
    assert_equal 'Big5', l(:general_csv_encoding)
290 279
    assert_equal ',', l(:general_csv_separator)
......
293 282

  
294 283
  def test_csv_cannot_convert_should_be_replaced_big_5
295 284
    Setting.default_language = "zh-TW"
296
    str_utf8  = "\xe4\xbb\xa5\xe5\x86\x85"
297
    if str_utf8.respond_to?(:force_encoding)
298
      str_utf8.force_encoding('UTF-8')
299
    end
285
    str_utf8  = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
300 286
    user = User.find_by_id(3)
301 287
    user.firstname = str_utf8
302 288
    user.lastname  = "test-lastname"
......
321 307
    assert_equal 'text/csv; header=present', @response.content_type
322 308
    lines = @response.body.chomp.split("\n")    
323 309
    # Headers
324
    s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp"
325
    if s1.respond_to?(:force_encoding)
326
      s1.force_encoding('Big5')
327
    end
310
    s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5')
328 311
    assert_equal s1, lines.first
329 312
    # Total row
330 313
    s2 = ""
331
    if s2.respond_to?(:force_encoding)
332
      s2 = "\xa5H?"
333
      s2.force_encoding('Big5')
334
    elsif RUBY_PLATFORM == 'java'
314
    if RUBY_PLATFORM == 'java'
335 315
      s2 = "??"
336 316
    else
337
      s2 = "\xa5H???"
317
      s2 = "\xa5H?".force_encoding('Big5')
338 318
    end
339 319
    assert_equal "#{s2} #{user.lastname},7.30,7.30", lines[1]
340 320
  end
......
362 342
      assert_equal 'text/csv; header=present', @response.content_type
363 343
      lines = @response.body.chomp.split("\n")    
364 344
      # Headers
365
      s1 = "Utilisateur;2011-11-11;Temps total"
366
      s2 = "Temps total"
367
      if s1.respond_to?(:force_encoding)
368
        s1.force_encoding('ISO-8859-1')
369
        s2.force_encoding('ISO-8859-1')
370
      end
345
      s1 = "Utilisateur;2011-11-11;Temps total".force_encoding('ISO-8859-1')
346
      s2 = "Temps total".force_encoding('ISO-8859-1')
371 347
      assert_equal s1, lines.first
372 348
      # Total row
373 349
      assert_equal "#{user.firstname} #{user.lastname};7,30;7,30", lines[1]
374 350
      assert_equal "#{s2};7,30;7,30", lines[2]
375 351

  
376
      str_fr = "Fran\xc3\xa7ais"
377
      if str_fr.respond_to?(:force_encoding)
378
        str_fr.force_encoding('UTF-8')
379
      end
352
      str_fr = "Fran\xc3\xa7ais".force_encoding('UTF-8')
380 353
      assert_equal str_fr, l(:general_lang_name)
381 354
      assert_equal 'ISO-8859-1', l(:general_csv_encoding)
382 355
      assert_equal ';', l(:general_csv_separator)

Also available in: Unified diff