Feature #36679 » feature-36679-v2.patch
app/controllers/versions_controller.rb | ||
---|---|---|
73 | 73 |
to_a |
74 | 74 |
end |
75 | 75 |
format.api |
76 |
format.text do |
|
77 |
send_data(@version.version_details_to_text, type: 'text/plain', filename: "version-#{@version.id}.txt") |
|
78 |
end |
|
76 | 79 |
end |
77 | 80 |
end |
78 | 81 |
app/models/version.rb | ||
---|---|---|
110 | 110 | |
111 | 111 |
class Version < ActiveRecord::Base |
112 | 112 |
include Redmine::SafeAttributes |
113 |
include Redmine::I18n |
|
113 | 114 | |
114 | 115 |
after_update :update_issues_from_sharing_change |
115 | 116 |
after_save :update_default_project_version |
... | ... | |
402 | 403 |
@default_project_version = (arg == '1' || arg == true) |
403 | 404 |
end |
404 | 405 | |
406 |
def version_details_to_text |
|
407 |
[ |
|
408 |
"# #{self.name}", |
|
409 |
format_date(self.effective_date), |
|
410 |
self.description, |
|
411 |
self.fixed_issues.visible.map do |issue| |
|
412 |
"* #{issue.tracker.name} ##{issue.id} #{issue.subject}\n" |
|
413 |
end.join |
|
414 |
].compact.join("\n\n") |
|
415 |
end |
|
416 | ||
405 | 417 |
private |
406 | 418 | |
407 | 419 |
# Update the issue's fixed versions. Used if a version's sharing changes. |
app/views/versions/show.html.erb | ||
---|---|---|
56 | 56 |
<% end %> |
57 | 57 |
</div> |
58 | 58 | |
59 |
<% other_formats_links do |f| %> |
|
60 |
<%= f.link_to_with_query_parameters 'Text' %> |
|
61 |
<% end %> |
|
62 | ||
59 | 63 |
<%= call_hook :view_versions_show_bottom, :version => @version %> |
60 | 64 | |
61 | 65 |
<% html_title @version.name %> |
test/functional/versions_controller_test.rb | ||
---|---|---|
20 | 20 |
require File.expand_path('../../test_helper', __FILE__) |
21 | 21 | |
22 | 22 |
class VersionsControllerTest < Redmine::ControllerTest |
23 |
include Redmine::I18n |
|
23 | 24 |
fixtures :projects, :enabled_modules, |
24 | 25 |
:trackers, :projects_trackers, |
25 | 26 |
:versions, :issue_statuses, :issue_categories, :enumerations, |
... | ... | |
220 | 221 |
assert_select 'a.icon.icon-add', :text => 'New issue' |
221 | 222 |
end |
222 | 223 | |
224 |
def test_show_with_text_format |
|
225 |
version = Version.find(2) |
|
226 |
get :show, params: {id: version.id, format: :text} |
|
227 |
assert_response :success |
|
228 |
assert_equal 'text/plain', response.media_type |
|
229 | ||
230 |
result = response.body.split("\n\n") |
|
231 |
assert_equal "# #{version.name}", result[0] |
|
232 |
assert_equal format_date(version.effective_date), result[1] |
|
233 |
assert_equal version.description, result[2] |
|
234 |
end |
|
235 | ||
223 | 236 |
def test_new |
224 | 237 |
@request.session[:user_id] = 2 |
225 | 238 |
get :new, :params => {:project_id => '1'} |
test/unit/version_test.rb | ||
---|---|---|
351 | 351 |
assert_nil version.custom_field_value(cf2) |
352 | 352 |
end |
353 | 353 | |
354 |
def test_version_details_to_text |
|
355 |
expected = <<~EXPECTED |
|
356 |
# 0.1 |
|
357 | ||
358 |
07/01/2006 |
|
359 | ||
360 |
Beta |
|
361 | ||
362 |
* Bug #11 Closed issue on a closed version |
|
363 |
EXPECTED |
|
364 |
assert_equal expected, Version.find(1).version_details_to_text |
|
365 |
end |
|
366 | ||
354 | 367 |
private |
355 | 368 | |
356 | 369 |
def add_issue(version, attributes={}) |