Defect #29259 » allow-preview-for-any-text-files-v2.diff
| app/models/attachment.rb (working copy) | ||
|---|---|---|
|
end
|
||
|
def is_text?
|
||
|
Redmine::MimeType.is_type?('text', filename)
|
||
|
Redmine::MimeType.is_type?('text', filename) ||
|
||
|
! Redmine::Utils.binary?(File.read(diskfile, 4096)) rescue false
|
||
|
end
|
||
|
def is_image?
|
||
| app/views/projects/settings/_versions.html.erb (working copy) | ||
|---|---|---|
|
<table class="list versions">
|
||
|
<thead><tr>
|
||
|
<th><%= l(:label_version) %></th>
|
||
|
<th><%= l(:field_default_version) %></th>
|
||
|
<th><%= l(:field_effective_date) %></th>
|
||
|
<th><%= l(:field_description) %></th>
|
||
|
<th><%= l(:field_status) %></th>
|
||
| ... | ... | |
|
<% @versions.sort.each do |version| %>
|
||
|
<tr class="version <%=h version.status %> <%= 'shared' if version.project != @project %>">
|
||
|
<td class="name <%= 'icon icon-shared' if version.project != @project %>"><%= link_to_version version %></td>
|
||
|
<td class="tick"><%= checked_image(version.id == @project.default_version_id) %></td>
|
||
|
<td class="date"><%= format_date(version.effective_date) %></td>
|
||
|
<td class="description"><%= version.description %></td>
|
||
|
<td class="status"><%= l("version_status_#{version.status}") %></td>
|
||
| lib/redmine/scm/adapters/abstract_adapter.rb (working copy) | ||
|---|---|---|
|
module ScmData
|
||
|
def self.binary?(data)
|
||
|
unless data.empty?
|
||
|
data.count( "^ -~", "^\r\n" ).fdiv(data.size) > 0.3 || data.index( "\x00" )
|
||
|
end
|
||
|
Redmine::Utils.binary?(data)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| lib/redmine/utils.rb (working copy) | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
end
|
||
|
def binary?(data)
|
||
|
unless data.empty?
|
||
|
data.count( "^ -~", "^\r\n" ).fdiv(data.size) > 0.3 || data.index( "\x00" )
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
module Shell
|
||
| test/fixtures/files/hello.go (working copy) | ||
|---|---|---|
|
package main
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
func main() {
|
||
|
fmt.Println("Hello, world!")
|
||
|
}
|
||
|
package main
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
func main() {
|
||
|
fmt.Println("Hello, world!")
|
||
|
}
|
||
| test/functional/my_controller_test.rb (working copy) | ||
|---|---|---|
|
assert_select 'div#block-activity' do
|
||
|
assert_select 'h3' do
|
||
|
assert_select 'a[href=?]', activity_path(from: Date.current, user_id: user.id), :text => 'Activity'
|
||
|
assert_select 'a[href=?]', activity_path(from: Date.today, user_id: user.id), :text => 'Activity'
|
||
|
end
|
||
|
assert_select 'div#activity' do
|
||
|
assert_select 'dt', 10
|
||
| test/functional/projects_controller_test.rb (working copy) | ||
|---|---|---|
|
assert_select 'a#tab-versions[href=?]', '/projects/ecookbook/settings/versions?version_name=.1&version_status='
|
||
|
end
|
||
|
def test_settings_should_show_default_version_in_versions_tab
|
||
|
project = Project.find(1)
|
||
|
project.default_version_id = 3
|
||
|
project.save!
|
||
|
@request.session[:user_id] = 2
|
||
|
get :settings, :params => {
|
||
|
:id => 'ecookbook',
|
||
|
:tab => 'versions',
|
||
|
}
|
||
|
assert_response :success
|
||
|
assert_select 'table.versions tbody' do
|
||
|
# asserts that only one version is marked as default
|
||
|
assert_select 'td.tick span.icon-checked', 1
|
||
|
# asserts which version is marked as default
|
||
|
assert_select 'tr:first-child td.tick span.icon-checked', 1
|
||
|
end
|
||
|
end
|
||
|
def test_settings_should_show_locked_members
|
||
|
user = User.generate!
|
||
|
member = User.add_to_project(user, Project.find(1))
|
||
| test/unit/attachment_test.rb (working copy) | ||
|---|---|---|
|
puts '(ImageMagick convert not available)'
|
||
|
end
|
||
|
def test_is_text
|
||
|
files = [
|
||
|
{:name => 'testfile.txt', :type => 'text/plain'},
|
||
|
{:name => 'hello.go', :type => 'text/plain'},
|
||
|
{:name => '2006/07/060719210727_archive.zip', :type => 'application/octet-stream'}
|
||
|
]
|
||
|
a_text, a_go, a_bin = files.map do |f|
|
||
|
a = Attachment.new(:container => Issue.find(1),
|
||
|
:file => uploaded_test_file(f[:name], f[:type]),
|
||
|
:author => User.find(1))
|
||
|
a.save!
|
||
|
a
|
||
|
end
|
||
|
assert a_text.is_text?
|
||
|
assert a_go.is_text?
|
||
|
assert_not a_bin.is_text?
|
||
|
end
|
||
|
end
|
||