Skip to content

Commit 7e2954e

Browse files
committed
adds hooks for inclusion of other plugin's data
- redmine_supply / issue 15
1 parent 2971afe commit 7e2954e

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

lib/redmine_gtt_print/issue_to_json.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def call
3636
json[:attributes][:map] = self.class.map_data(data[:center], [data[:geojson]])
3737
end
3838

39+
context = {
40+
issue: @issue, other_attributes: @other_attributes, json: json
41+
}
42+
Redmine::Hook.call_hook(:redmine_gtt_print_issue_to_json, context)
43+
3944
json.to_json
4045
end
4146

lib/redmine_gtt_print/issues_to_json.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ def call
4343
#)
4444
end
4545

46+
context = {
47+
issues: @issues, other_attributes: @other_attributes, json: hsh
48+
}
49+
Redmine::Hook.call_hook(:redmine_gtt_print_issues_to_json, context)
50+
4651
hsh.to_json
4752
end
4853

test/test_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
require File.expand_path(File.dirname(__FILE__) + '/../../redmine_gtt/test/test_helper')
22

3+
class TestHookListener < Redmine::Hook::Listener
4+
def redmine_gtt_print_issue_to_json(context)
5+
context[:json][:issue_to_json_hook] = context[:issue].id
6+
end
7+
def redmine_gtt_print_issues_to_json(context)
8+
context[:json][:issues_to_json_hook] = context[:issues].size
9+
end
10+
end
11+
312
class TestMapfish
413
attr_reader :issue, :layout
514
def print_configs

test/unit/issue_to_json_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ class IssueToJsonTest < ActiveSupport::TestCase
3838
assert_equal 15052703.2783315, geom['coordinates'].flatten.first
3939
end
4040

41+
test "should call hook" do
42+
assert j = RedmineGttPrint::IssueToJson.(@issue, 'das layout')
43+
assert h = JSON.parse(j)
44+
assert_equal @issue.id, h["issue_to_json_hook"]
45+
end
46+
4147
test 'should handle issue without geometry' do
4248
i = Issue.find(2)
4349
assert j = RedmineGttPrint::IssueToJson.(i, 'layout')

test/unit/issues_to_json_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class IssuesToJsonTest < ActiveSupport::TestCase
2929
assert_equal @issues[1].subject, table[1].last
3030
end
3131

32+
test "should call hook" do
33+
assert j = RedmineGttPrint::IssuesToJson.(@issues, 'das layout')
34+
assert h = JSON.parse(j)
35+
assert_equal @issues.size, h["issues_to_json_hook"]
36+
end
37+
3238
test 'should include map json in attributes' do
3339
skip 'removed for now'
3440
assert j = RedmineGttPrint::IssuesToJson.(@issues, 'das layout')

0 commit comments

Comments
 (0)