diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index 63f84c9ce..fb1e8f3fc 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -73,6 +73,9 @@ class VersionsController < ApplicationController to_a end format.api + format.text do + send_data(@version.version_details_to_text, type: 'text/plain', filename: "#{@version.name}.txt") + end end end diff --git a/app/models/version.rb b/app/models/version.rb index 6f2548563..5d4747af1 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -110,6 +110,7 @@ end class Version < ActiveRecord::Base include Redmine::SafeAttributes + include Redmine::I18n after_update :update_issues_from_sharing_change after_save :update_default_project_version @@ -402,6 +403,17 @@ class Version < ActiveRecord::Base @default_project_version = (arg == '1' || arg == true) end + def version_details_to_text + [ + "# #{self.name}", + format_date(self.effective_date), + self.description, + self.fixed_issues.visible.map do |issue| + "* #{issue.tracker.name} ##{issue.id} #{issue.subject}\n" + end.join + ].compact.join("\n\n") + end + private # Update the issue's fixed versions. Used if a version's sharing changes. diff --git a/app/views/versions/show.html.erb b/app/views/versions/show.html.erb index 0527eae9c..ab0773e71 100644 --- a/app/views/versions/show.html.erb +++ b/app/views/versions/show.html.erb @@ -56,6 +56,10 @@ <% end %> +<% other_formats_links do |f| %> + <%= f.link_to_with_query_parameters 'Text' %> +<% end %> + <%= call_hook :view_versions_show_bottom, :version => @version %> <% html_title @version.name %> diff --git a/test/functional/versions_controller_test.rb b/test/functional/versions_controller_test.rb index fdd767560..111e5d08f 100644 --- a/test/functional/versions_controller_test.rb +++ b/test/functional/versions_controller_test.rb @@ -20,6 +20,7 @@ require File.expand_path('../../test_helper', __FILE__) class VersionsControllerTest < Redmine::ControllerTest + include Redmine::I18n fixtures :projects, :enabled_modules, :trackers, :projects_trackers, :versions, :issue_statuses, :issue_categories, :enumerations, @@ -220,6 +221,18 @@ class VersionsControllerTest < Redmine::ControllerTest assert_select 'a.icon.icon-add', :text => 'New issue' end + def test_show_with_text_format + version = Version.find(2) + get :show, params: {id: version.id, format: :text} + assert_response :success + assert_equal 'text/plain', response.media_type + + result = response.body.split("\n\n") + assert_equal "# #{version.name}", result[0] + assert_equal format_date(version.effective_date), result[1] + assert_equal version.description, result[2] + end + def test_new @request.session[:user_id] = 2 get :new, :params => {:project_id => '1'} diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb index 413190fdf..35705db40 100644 --- a/test/unit/version_test.rb +++ b/test/unit/version_test.rb @@ -351,6 +351,19 @@ class VersionTest < ActiveSupport::TestCase assert_nil version.custom_field_value(cf2) end + def test_version_details_to_text + expected = <<~EXPECTED + # 0.1 + + 07/01/2006 + + Beta + + * Bug #11 Closed issue on a closed version + EXPECTED + assert_equal expected, Version.find(1).version_details_to_text + end + private def add_issue(version, attributes={})