Project

General

Profile

Defect #29259 » allow-preview-for-any-text-files-v2.diff

Go MAEDA, 2018-08-10 10:03

View differences:

app/models/attachment.rb (working copy)
235 235
  end
236 236

  
237 237
  def is_text?
238
    Redmine::MimeType.is_type?('text', filename)
238
    Redmine::MimeType.is_type?('text', filename) ||
239
      ! Redmine::Utils.binary?(File.read(diskfile, 4096)) rescue false
239 240
  end
240 241

  
241 242
  def is_image?
app/views/projects/settings/_versions.html.erb (working copy)
16 16
<table class="list versions">
17 17
  <thead><tr>
18 18
    <th><%= l(:label_version) %></th>
19
    <th><%= l(:field_default_version) %></th>
20 19
    <th><%= l(:field_effective_date) %></th>
21 20
    <th><%= l(:field_description) %></th>
22 21
    <th><%= l(:field_status) %></th>
......
28 27
<% @versions.sort.each do |version| %>
29 28
    <tr class="version <%=h version.status %> <%= 'shared' if version.project != @project %>">
30 29
    <td class="name <%= 'icon icon-shared' if version.project != @project %>"><%= link_to_version version %></td>
31
    <td class="tick"><%= checked_image(version.id == @project.default_version_id) %></td>
32 30
    <td class="date"><%= format_date(version.effective_date) %></td>
33 31
    <td class="description"><%= version.description %></td>
34 32
    <td class="status"><%= l("version_status_#{version.status}") %></td>
lib/redmine/scm/adapters/abstract_adapter.rb (working copy)
425 425

  
426 426
      module ScmData
427 427
        def self.binary?(data)
428
          unless data.empty?
429
            data.count( "^ -~", "^\r\n" ).fdiv(data.size) > 0.3 || data.index( "\x00" )
430
          end
428
          Redmine::Utils.binary?(data)
431 429
        end
432 430
      end
433 431
    end
lib/redmine/utils.rb (working copy)
61 61
          end
62 62
        end
63 63
      end
64

  
65
      def binary?(data)
66
        unless data.empty?
67
          data.count( "^ -~", "^\r\n" ).fdiv(data.size) > 0.3 || data.index( "\x00" )
68
        end
69
      end
64 70
    end
65 71

  
66 72
    module Shell
test/fixtures/files/hello.go (working copy)
1
package main
2

  
3
import "fmt"
4

  
5
func main() {
6
  fmt.Println("Hello, world!")
7
}
8
package main
9

  
10
import "fmt"
11

  
12
func main() {
13
  fmt.Println("Hello, world!")
14
}
test/functional/my_controller_test.rb (working copy)
208 208

  
209 209
    assert_select 'div#block-activity' do
210 210
      assert_select 'h3' do
211
        assert_select 'a[href=?]', activity_path(from: Date.current, user_id: user.id),  :text => 'Activity'
211
        assert_select 'a[href=?]', activity_path(from: Date.today, user_id: user.id),  :text => 'Activity'
212 212
      end
213 213
      assert_select 'div#activity' do
214 214
        assert_select 'dt', 10
test/functional/projects_controller_test.rb (working copy)
641 641
    assert_select 'a#tab-versions[href=?]', '/projects/ecookbook/settings/versions?version_name=.1&version_status='
642 642
  end
643 643

  
644
  def test_settings_should_show_default_version_in_versions_tab
645
    project = Project.find(1)
646
    project.default_version_id = 3
647
    project.save!
648

  
649
    @request.session[:user_id] = 2
650

  
651
    get :settings, :params => {
652
        :id => 'ecookbook',
653
        :tab => 'versions',
654
      }
655
    assert_response :success
656

  
657
    assert_select 'table.versions tbody' do
658
      # asserts that only one version is marked as default
659
      assert_select 'td.tick span.icon-checked', 1
660
      # asserts which version is marked as default
661
      assert_select 'tr:first-child td.tick span.icon-checked', 1
662
    end
663
  end
664

  
665 644
  def test_settings_should_show_locked_members
666 645
    user = User.generate!
667 646
    member = User.add_to_project(user, Project.find(1))
test/unit/attachment_test.rb (working copy)
444 444
    puts '(ImageMagick convert not available)'
445 445
  end
446 446

  
447
  def test_is_text
448
    files = [
449
      {:name => 'testfile.txt', :type => 'text/plain'},
450
      {:name => 'hello.go', :type => 'text/plain'},
451
      {:name => '2006/07/060719210727_archive.zip', :type => 'application/octet-stream'}
452
    ]
453

  
454
    a_text, a_go, a_bin = files.map do |f|
455
      a = Attachment.new(:container => Issue.find(1),
456
        :file => uploaded_test_file(f[:name], f[:type]),
457
        :author => User.find(1))
458
      a.save!
459
      a
460
    end
461

  
462
    assert a_text.is_text?
463
    assert a_go.is_text?
464
    assert_not a_bin.is_text?
465
  end
466

  
447 467
end
(2-2/3)