[#4327] Save the deliverable changes to the issue using the hooks.
This commit is contained in:
1
init.rb
1
init.rb
@@ -68,3 +68,4 @@ end
|
||||
require 'redmine_contracts/hooks/view_layouts_base_html_head_hook'
|
||||
require 'redmine_contracts/hooks/view_issues_show_details_bottom_hook'
|
||||
require 'redmine_contracts/hooks/view_issues_form_details_bottom_hook'
|
||||
require 'redmine_contracts/hooks/controller_issues_edit_before_save_hook'
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
module RedmineContracts
|
||||
module Hooks
|
||||
class ControllerIssuesEditBeforeSaveHook < Redmine::Hook::ViewListener
|
||||
def controller_issues_edit_before_save(context={})
|
||||
if context[:params] && context[:params][:issue] && context[:params][:issue][:deliverable_id].present?
|
||||
deliverable = Deliverable.find_by_id(context[:params][:issue][:deliverable_id])
|
||||
|
||||
if deliverable.contract.project == context[:issue].project
|
||||
context[:issue].deliverable = deliverable
|
||||
end
|
||||
end
|
||||
|
||||
return ''
|
||||
end
|
||||
|
||||
alias_method :controller_issues_new_before_save, :controller_issues_edit_before_save
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,59 @@
|
||||
require File.dirname(__FILE__) + '/../../../test_helper'
|
||||
|
||||
class RedmineContracts::Hooks::ControllerIssuesEditBeforeSaveTest < ActionController::IntegrationTest
|
||||
include Redmine::Hook::Helper
|
||||
|
||||
context "#controller_issues_edit_before_save" do
|
||||
setup do
|
||||
@project = Project.generate!
|
||||
IssueStatus.generate!(:is_default => true)
|
||||
@issue = Issue.generate_for_project!(@project)
|
||||
@contract1 = Contract.generate!(:project => @project)
|
||||
@contract2 = Contract.generate!(:project => @project)
|
||||
|
||||
@manager = User.generate!(:login => 'manager', :password => 'existing', :password_confirmation => 'existing', :admin => true)
|
||||
@role = Role.generate!(:permissions => [:view_issues, :add_issues, :edit_issues])
|
||||
User.add_to_project(@manager, @project, @role)
|
||||
@deliverable1 = FixedDeliverable.generate!(:contract => @contract1, :manager => @manager, :title => 'The Title for 1')
|
||||
@deliverable2 = FixedDeliverable.generate!(:contract => @contract2, :manager => @manager, :title => 'The Title for 2')
|
||||
|
||||
login_as('manager', 'existing')
|
||||
@project.reload
|
||||
end
|
||||
|
||||
context "for a new issue" do
|
||||
setup do
|
||||
visit_project(@project)
|
||||
click_link "New issue"
|
||||
end
|
||||
|
||||
should "set the issue's deliverable" do
|
||||
fill_in "Subject", :with => 'Hook test'
|
||||
select @deliverable2.title, :from => "Deliverable"
|
||||
click_button "Create"
|
||||
|
||||
assert_response :success
|
||||
|
||||
assert_equal @deliverable2, Issue.last.deliverable
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
context "for an existing issue" do
|
||||
setup do
|
||||
visit_issue_page(@issue)
|
||||
end
|
||||
|
||||
should "update the issue's deliverable" do
|
||||
select @deliverable2.title, :from => "Deliverable"
|
||||
click_button "Submit"
|
||||
|
||||
assert_response :success
|
||||
|
||||
@issue.reload
|
||||
assert_equal @deliverable2, @issue.deliverable
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user