pact_broker 2.87.0 → 2.88.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/docs/CONFIGURATION.md +1 -1
  4. data/docs/api/WEBHOOKS.md +789 -0
  5. data/lib/pact_broker/api/decorators/pact_decorator.rb +12 -0
  6. data/lib/pact_broker/api/resources/default_base_resource.rb +1 -1
  7. data/lib/pact_broker/api/resources/environment.rb +3 -3
  8. data/lib/pact_broker/api/resources/metadata_resource_methods.rb +33 -3
  9. data/lib/pact_broker/api/resources/pact_version.rb +4 -0
  10. data/lib/pact_broker/api/resources/previous_distinct_pact_version.rb +1 -1
  11. data/lib/pact_broker/api/resources/webhook_execution.rb +7 -3
  12. data/lib/pact_broker/api.rb +5 -0
  13. data/lib/pact_broker/deployments/environment_service.rb +3 -1
  14. data/lib/pact_broker/doc/views/provider-pacts-for-verification.markdown +7 -7
  15. data/lib/pact_broker/domain/webhook.rb +2 -2
  16. data/lib/pact_broker/test/http_test_data_builder.rb +1 -0
  17. data/lib/pact_broker/test/test_data_builder.rb +6 -0
  18. data/lib/pact_broker/version.rb +1 -1
  19. data/lib/pact_broker/versions/abbreviate_number.rb +8 -4
  20. data/lib/webmachine/describe_routes.rb +62 -0
  21. data/script/data/branches.rb +1 -1
  22. data/script/docs/generate-api-docs.rb +117 -0
  23. data/script/docs/regenerate-api-docs.sh +11 -0
  24. data/spec/fixtures/approvals/docs_webhooks_executing_a_saved_webhook_options.approved.json +20 -0
  25. data/spec/fixtures/approvals/docs_webhooks_executing_a_saved_webhook_post.approved.json +43 -0
  26. data/spec/fixtures/approvals/docs_webhooks_executing_an_unsaved_webhook_options.approved.json +20 -0
  27. data/spec/fixtures/approvals/docs_webhooks_executing_an_unsaved_webhook_post.approved.json +63 -0
  28. data/spec/fixtures/approvals/docs_webhooks_logs_of_triggered_webhook_get.approved.json +20 -0
  29. data/spec/fixtures/approvals/docs_webhooks_logs_of_triggered_webhook_options.approved.json +20 -0
  30. data/spec/fixtures/approvals/docs_webhooks_pact_webhooks_get.approved.json +45 -0
  31. data/spec/fixtures/approvals/docs_webhooks_pact_webhooks_options.approved.json +20 -0
  32. data/spec/fixtures/approvals/docs_webhooks_triggered_webhooks_for_pact_publication_get.approved.json +52 -0
  33. data/spec/fixtures/approvals/docs_webhooks_triggered_webhooks_for_pact_publication_options.approved.json +20 -0
  34. data/spec/fixtures/approvals/docs_webhooks_triggered_webhooks_for_verification_publication_get.approved.json +32 -0
  35. data/spec/fixtures/approvals/docs_webhooks_triggered_webhooks_for_verification_publication_options.approved.json +20 -0
  36. data/spec/fixtures/approvals/docs_webhooks_webhook_get.approved.json +74 -0
  37. data/spec/fixtures/approvals/docs_webhooks_webhook_options.approved.json +20 -0
  38. data/spec/fixtures/approvals/docs_webhooks_webhook_put.approved.json +77 -0
  39. data/spec/fixtures/approvals/docs_webhooks_webhooks_for_a_provider_get.approved.json +41 -0
  40. data/spec/fixtures/approvals/docs_webhooks_webhooks_for_a_provider_options.approved.json +20 -0
  41. data/spec/fixtures/approvals/docs_webhooks_webhooks_for_consumer_and_provider_get.approved.json +45 -0
  42. data/spec/fixtures/approvals/docs_webhooks_webhooks_for_consumer_and_provider_options.approved.json +20 -0
  43. data/spec/fixtures/approvals/docs_webhooks_webhooks_for_consumer_get.approved.json +41 -0
  44. data/spec/fixtures/approvals/docs_webhooks_webhooks_for_consumer_options.approved.json +20 -0
  45. data/spec/fixtures/approvals/docs_webhooks_webhooks_get.approved.json +45 -0
  46. data/spec/fixtures/approvals/docs_webhooks_webhooks_options.approved.json +20 -0
  47. data/spec/fixtures/approvals/docs_webhooks_webhooks_post.approved.json +78 -0
  48. data/spec/fixtures/approvals/docs_webhooks_webhooks_status_get.approved.json +79 -0
  49. data/spec/fixtures/approvals/docs_webhooks_webhooks_status_options.approved.json +20 -0
  50. data/spec/fixtures/approvals/get_provider_pacts_for_verification.approved.json +1 -2
  51. data/spec/fixtures/approvals/publish_contract_no_branch.approved.json +1 -2
  52. data/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json +1 -2
  53. data/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json +1 -2
  54. data/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json +1 -2
  55. data/spec/fixtures/approvals/publish_contract_with_validation_error.approved.json +1 -2
  56. data/spec/integration/pact_metdata_spec.rb +105 -0
  57. data/spec/integration/webhooks_documentation_spec.rb +348 -0
  58. data/spec/lib/pact_broker/deployments/environment_service_spec.rb +21 -0
  59. data/spec/lib/pact_broker/domain/webhook_spec.rb +35 -0
  60. data/spec/lib/pact_broker/versions/abbreviate_number_spec.rb +2 -1
  61. data/spec/support/documentation.rb +64 -0
  62. data/spec/support/rack_helpers.rb +1 -1
  63. data/tasks/development.rake +14 -13
  64. metadata +65 -3
@@ -0,0 +1,348 @@
1
+ require "timecop"
2
+
3
+ WEBHOOK_TESTED_PATHS = []
4
+ WEBHOOKS_NO_DOCUMENTATION = %w[
5
+ ]
6
+ WEBHOOK_ROUTES_REQURING_A_TEST = PactBroker.routes
7
+ .select { | route | route[:path].include?("webhook") }
8
+ .reject { | route | WEBHOOKS_NO_DOCUMENTATION.include?(route[:path]) }
9
+
10
+ # Fails on Github Actions
11
+ RSpec.describe "webhook routes", skip: true do
12
+ before do
13
+ Timecop.freeze(Time.new(2021, 9, 1, 10, 7, 21))
14
+ td.create_consumer("Foo")
15
+ .create_provider("Bar")
16
+ .create_consumer_version("2")
17
+ .create_pact(json_content: { integrations: [] }.to_json )
18
+ .create_verification(provider_version: "3")
19
+ .create_webhook(
20
+ uuid: "d2181b32-8b03-4daf-8cc0-d9168b2f6fac",
21
+ url: "https://example.org/example",
22
+ description: "an example webhook",
23
+ body: webhook_body
24
+ )
25
+ .create_triggered_webhook(uuid: "6cd5cc48-db3c-4a4c-a36d-e9bedeb9d91e")
26
+ .create_webhook_execution
27
+ end
28
+
29
+ after do
30
+ Timecop.return
31
+ end
32
+
33
+ let(:webhook_body) do
34
+ { "pactUrl" =>"${pactbroker.pactUrl}" }
35
+ end
36
+
37
+ before do
38
+ if ENV["DEBUG"] == "true"
39
+ PactBroker.routes.find{ | route| route[:path] == path_template }
40
+ end
41
+ WEBHOOK_TESTED_PATHS << path_template
42
+ end
43
+
44
+ after(:all) do
45
+ missed_routes = WEBHOOK_ROUTES_REQURING_A_TEST.reject { | route | WEBHOOK_TESTED_PATHS.include?(route[:path]) }
46
+
47
+ if missed_routes.any? && ENV["DEBUG"] != "true"
48
+ puts "WEBHOOK ROUTES MISSING COVERAGE:"
49
+ puts missed_routes.to_yaml
50
+ end
51
+ end
52
+
53
+ let(:category) { "Webhooks" }
54
+ let(:pact_version_sha) { PactBroker::Pacts::PactVersion.last.sha }
55
+ let(:triggered_webhook_uuid) { PactBroker::Webhooks::TriggeredWebhook.last.trigger_uuid }
56
+ let(:webhook_uuid) { PactBroker::Webhooks::TriggeredWebhook.last.webhook.uuid }
57
+
58
+ let(:webhook_hash) do
59
+ {
60
+ "description" => "an example webhook",
61
+ "events" => [{
62
+ "name" => "contract_content_changed"
63
+ }],
64
+ "request" =>{
65
+ "method" =>"POST",
66
+ "url" =>"https://example.org/example",
67
+ "username" =>"username",
68
+ "password" =>"password",
69
+ "headers" =>{
70
+ "Accept" =>"application/json"
71
+ },
72
+ "body" => webhook_body
73
+ }
74
+ }
75
+ end
76
+
77
+ let(:parameter_values) do
78
+ {
79
+ pact_version_sha: pact_version_sha,
80
+ provider_name: "Bar",
81
+ consumer_name: "Foo",
82
+ consumer_version_number: "2",
83
+ provider_version_number: "3",
84
+ trigger_uuid: triggered_webhook_uuid,
85
+ verification_number: "1"
86
+ }
87
+ end
88
+
89
+ let(:custom_parameter_values) do
90
+ {
91
+
92
+ }
93
+ end
94
+
95
+ let(:rack_headers) do
96
+ {
97
+ "ACCEPT" => "application/hal+json"
98
+ }
99
+ end
100
+
101
+ let(:http_params) { {} }
102
+ let(:http_method) { "GET" }
103
+
104
+ let(:path) do
105
+ build_path(path_template, parameter_values, custom_parameter_values)
106
+ end
107
+
108
+ let(:approval_request_example_name) do
109
+ build_approval_name(category, pact_broker_example_name, http_method)
110
+ end
111
+
112
+ let(:pact_broker_example_name) do | example |
113
+ example.example_group.parent_groups[-2].description
114
+ end
115
+
116
+ subject { send(http_method.downcase, path, http_params, rack_headers) }
117
+
118
+ shared_examples "request" do
119
+ it "returns a body" do
120
+ subject
121
+ Approvals.verify(expected_interaction(subject, WEBHOOK_TESTED_PATHS.size), :name => approval_request_example_name, format: :json)
122
+ end
123
+ end
124
+
125
+ shared_examples "supports GET" do
126
+ its(:status) { is_expected.to eq 200 }
127
+ include_examples "request"
128
+ end
129
+
130
+
131
+ shared_examples "supports POST" do
132
+ let(:http_method) { "POST" }
133
+ let(:rack_headers) do
134
+ {
135
+ "CONTENT_TYPE" => "application/json",
136
+ "ACCEPT" => "application/hal+json"
137
+ }
138
+ end
139
+
140
+ its(:status) { is_expected.to be_between(200, 201) }
141
+ include_examples "request"
142
+
143
+ end
144
+
145
+ shared_examples "supports PUT" do
146
+ describe "PUT" do
147
+ let(:http_method) { "PUT" }
148
+ let(:rack_headers) do
149
+ {
150
+ "CONTENT_TYPE" => "application/json",
151
+ "ACCEPT" => "application/hal+json"
152
+ }
153
+ end
154
+
155
+ its(:status) { is_expected.to be_between(200, 201) }
156
+
157
+ include_examples "request"
158
+ end
159
+ end
160
+
161
+ shared_examples "supports OPTIONS" do
162
+ let(:http_method) { "OPTIONS" }
163
+
164
+ its(:status) { is_expected.to eq 200 }
165
+ include_examples "request"
166
+ end
167
+
168
+ describe "Webhook" do
169
+ let(:path_template) { "/webhooks/:uuid" }
170
+ let(:custom_parameter_values) { { uuid: webhook_uuid } }
171
+
172
+ describe "GET" do
173
+ include_examples "supports GET"
174
+ end
175
+
176
+ describe "PUT" do
177
+ let(:http_params) { webhook_hash.to_json }
178
+ include_examples "supports PUT"
179
+ end
180
+
181
+ describe "OPTIONS" do
182
+ include_examples "supports OPTIONS"
183
+ end
184
+ end
185
+
186
+ describe "Webhooks" do
187
+ let(:path_template) { "/webhooks" }
188
+
189
+ describe "GET" do
190
+ include_examples "supports GET"
191
+ end
192
+
193
+ describe "POST" do
194
+ before do
195
+ allow(PactBroker::Webhooks::Service).to receive(:next_uuid).and_return("dCGCl-Ba3PqEFJ_iE9mJkQ")
196
+ end
197
+
198
+ let(:http_params) { webhook_hash.to_json }
199
+ include_examples "supports POST"
200
+ end
201
+
202
+ describe "OPTIONS" do
203
+ include_examples "supports OPTIONS"
204
+ end
205
+ end
206
+
207
+ describe "Webhooks for consumer" do
208
+ let(:path_template) { "/webhooks/consumer/:consumer_name" }
209
+
210
+ describe "GET" do
211
+ include_examples "supports GET"
212
+ end
213
+
214
+ describe "OPTIONS" do
215
+ include_examples "supports OPTIONS"
216
+ end
217
+ end
218
+
219
+ describe "Webhooks for a provider" do
220
+ let(:path_template) { "/webhooks/provider/:provider_name" }
221
+
222
+ describe "GET" do
223
+ include_examples "supports GET"
224
+ end
225
+
226
+ describe "OPTIONS" do
227
+ include_examples "supports OPTIONS"
228
+ end
229
+ end
230
+
231
+ describe "Webhooks for consumer and provider" do
232
+ let(:path_template) { "/webhooks/provider/:provider_name/consumer/:consumer_name" }
233
+
234
+ describe "GET" do
235
+ include_examples "supports GET"
236
+ end
237
+
238
+ describe "OPTIONS" do
239
+ include_examples "supports OPTIONS"
240
+ end
241
+ end
242
+
243
+ describe "Pact webhooks" do
244
+ let(:path_template) do
245
+ "/pacts/provider/:provider_name/consumer/:consumer_name/webhooks"
246
+ end
247
+
248
+ describe "GET" do
249
+ include_examples "supports GET"
250
+ end
251
+
252
+ describe "OPTIONS" do
253
+ include_examples "supports OPTIONS"
254
+ end
255
+ end
256
+
257
+ describe "Webhooks status" do
258
+ let(:path_template) do
259
+ "/pacts/provider/:provider_name/consumer/:consumer_name/webhooks/status"
260
+ end
261
+
262
+ describe "GET" do
263
+ include_examples "supports GET"
264
+ end
265
+
266
+ describe "OPTIONS" do
267
+ include_examples "supports OPTIONS"
268
+ end
269
+ end
270
+
271
+ describe "Executing a saved webhook" do
272
+ let(:path_template) { "/webhooks/:uuid/execute" }
273
+ let(:custom_parameter_values) { { uuid: webhook_uuid } }
274
+
275
+ include_examples "supports OPTIONS"
276
+
277
+ describe "POST" do
278
+ before do
279
+ stub_request(:post, /http/).to_return(:status => 200)
280
+ allow(PactBroker.configuration).to receive(:webhook_host_whitelist).and_return([/.*/])
281
+ end
282
+
283
+ include_examples "supports POST"
284
+ end
285
+
286
+ end
287
+
288
+ describe "Executing an unsaved webhook" do
289
+ let(:path_template) { "/webhooks/execute" }
290
+
291
+ describe "OPTIONS" do
292
+ include_examples "supports OPTIONS"
293
+ end
294
+
295
+ describe "POST" do
296
+ before do
297
+ stub_request(:post, /http/).to_return(:status => 200)
298
+ allow(PactBroker.configuration).to receive(:webhook_host_whitelist).and_return([/.*/])
299
+ end
300
+
301
+ let(:http_params) do
302
+ webhook_hash.to_json
303
+ end
304
+ include_examples "supports POST"
305
+ end
306
+ end
307
+
308
+ describe "Triggered webhooks for pact publication" do
309
+ let(:path_template) do
310
+ "/pacts/provider/:provider_name/consumer/:consumer_name/version/:consumer_version_number/triggered-webhooks"
311
+ end
312
+
313
+ describe "GET" do
314
+ include_examples "supports GET"
315
+ end
316
+
317
+ describe "OPTIONS" do
318
+ include_examples "supports OPTIONS"
319
+ end
320
+ end
321
+
322
+ describe "Triggered webhooks for verification publication" do
323
+ let(:path_template) do
324
+ "/pacts/provider/:provider_name/consumer/:consumer_name/pact-version/:pact_version_sha/verification-results/:verification_number/triggered-webhooks"
325
+ end
326
+
327
+ describe "GET" do
328
+ include_examples "supports GET"
329
+ end
330
+
331
+ describe "OPTIONS" do
332
+ include_examples "supports OPTIONS"
333
+ end
334
+ end
335
+
336
+ describe "Logs of triggered webhook" do
337
+ let(:path_template) { "/triggered-webhooks/:uuid/logs" }
338
+ let(:custom_parameter_values) { { uuid: triggered_webhook_uuid } }
339
+
340
+ describe "GET" do
341
+ include_examples "supports GET"
342
+ end
343
+
344
+ describe "OPTIONS" do
345
+ include_examples "supports OPTIONS"
346
+ end
347
+ end
348
+ end
@@ -32,6 +32,27 @@ module PactBroker
32
32
  end
33
33
  end
34
34
  end
35
+
36
+ describe ".replace" do
37
+ before do
38
+ td.create_environment("foo", uuid: "1", display_name: "bar", production: false)
39
+ end
40
+
41
+ subject { EnvironmentService.replace("1", Environment.new(name: "bar", display_name: "bar-2", production: true) ) }
42
+
43
+ it "replaces the attributes" do
44
+ subject
45
+ expect(Environment.first).to have_attributes(name: "bar", display_name: "bar-2", production: true)
46
+ end
47
+
48
+ context "with missing attributes" do
49
+ subject { EnvironmentService.replace("1", Environment.new ) }
50
+
51
+ it "raises an error" do
52
+ expect { subject }.to raise_error Sequel::DatabaseError
53
+ end
54
+ end
55
+ end
35
56
  end
36
57
  end
37
58
  end
@@ -32,18 +32,53 @@ module PactBroker
32
32
 
33
33
  context "with a consumer and provider" do
34
34
  it { is_expected.to eq "A webhook for the pact between Consumer and Provider" }
35
+
36
+ context "when provider is specified by a label" do
37
+ let(:provider) { WebhookPacticipant.new(label: "provider-label")}
38
+
39
+ it { is_expected.to eq "A webhook for the pact between Consumer and providers labeled 'provider-label'" }
40
+ end
41
+
42
+ context "when consumer is specified by a label" do
43
+ let(:consumer) { WebhookPacticipant.new(label: "consumer-label")}
44
+
45
+ it { is_expected.to eq "A webhook for the pact between consumers labeled 'consumer-label' and Provider" }
46
+ end
47
+
48
+ context "when both are specified by labels" do
49
+ let(:consumer) { WebhookPacticipant.new(label: "consumer-label")}
50
+ let(:provider) { WebhookPacticipant.new(label: "provider-label")}
51
+
52
+ it do
53
+ is_expected.to eq(
54
+ "A webhook for the pact between consumers labeled 'consumer-label' and providers labeled 'provider-label'"
55
+ )
56
+ end
57
+ end
35
58
  end
36
59
 
37
60
  context "with a consumer only" do
38
61
  let(:provider) { nil }
39
62
 
40
63
  it { is_expected.to eq "A webhook for all pacts with consumer Consumer" }
64
+
65
+ context "when specified by a label" do
66
+ let(:consumer) { WebhookPacticipant.new(label: "consumer-label")}
67
+
68
+ it { is_expected.to eq "A webhook for all pacts with consumer labeled 'consumer-label'" }
69
+ end
41
70
  end
42
71
 
43
72
  context "with a provider only" do
44
73
  let(:consumer) { nil }
45
74
 
46
75
  it { is_expected.to eq "A webhook for all pacts with provider Provider" }
76
+
77
+ context "when specified by a label" do
78
+ let(:provider) { WebhookPacticipant.new(label: "provider-label")}
79
+
80
+ it { is_expected.to eq "A webhook for all pacts with provider labeled 'provider-label'" }
81
+ end
47
82
  end
48
83
 
49
84
  context "with neither a consumer nor a provider" do
@@ -8,7 +8,8 @@ module PactBroker
8
8
  ["202326572516dea6998a7f311fcaa161c0768fc2", "2023265"],
9
9
  ["1.2.3+areallyreallyreallylongexplanation", "1.2.3+areallyreallyreallylongexplanation"],
10
10
  ["2516dea6998a7f", "2516dea6998a7f"],
11
- ["1.2.3+202326572516dea6998a7f311fcaa161c0768fc2", "1.2.3+2023265"]
11
+ ["1.2.3+202326572516dea6998a7f311fcaa161c0768fc2", "1.2.3+2023265"],
12
+ ["this-is-very-long-text-this-is-very-long-text-this-is-very-long-text-this-is-very-long-text", "this-is-very-long-text-this-is-very-lon…-long-text"]
12
13
  ]
13
14
 
14
15
  TEST_CASES.each do |(input, output)|
@@ -0,0 +1,64 @@
1
+ module PactBroker
2
+ module Documentation
3
+
4
+ def remove_deprecated_links(thing)
5
+ case thing
6
+ when Hash then remove_deprecated_links_from_hash(thing)
7
+ when Array then thing.collect { |value| remove_deprecated_links(value) }
8
+ else thing
9
+ end
10
+ end
11
+
12
+ def remove_deprecated_links_from_hash(body)
13
+ body.each_with_object({}) do | (key, value), new_body |
14
+ if key == "_links"
15
+ links = value.select do | link_key, _value |
16
+ link_key.start_with?("pb:", "self", "next", "previous", "curies")
17
+ end
18
+ new_body["_links"] = links
19
+ else
20
+ new_body[key] = remove_deprecated_links(value)
21
+ end
22
+ end
23
+ end
24
+
25
+ def build_approval_name(category, example_name, http_method)
26
+ "docs_#{category}_" + example_name.tr(" ", "_") + "_" + http_method
27
+ end
28
+
29
+ def build_path(path_template, parameter_values, custom_parameter_values)
30
+ parameter_values.merge(custom_parameter_values).inject(path_template) do | new_path, (name, value) |
31
+ new_path.gsub(/:#{name}(\/|$)/, value + '\1')
32
+ end
33
+ end
34
+
35
+ def expected_interaction(response, order)
36
+ expectated_body = response.headers["Content-Type"]&.include?("json") && response.body && response.body != "" ? remove_deprecated_links(JSON.parse(response.body)) : response.body
37
+ expected_response = {
38
+ status: response.status,
39
+ headers: determinate_headers(response.headers),
40
+ body: expectated_body
41
+ }
42
+ request = {
43
+ method: http_method,
44
+ path_template: path_template,
45
+ path: path,
46
+ headers: rack_env_to_http_headers(rack_headers),
47
+ body: http_params.is_a?(String) ? JSON.parse(http_params) : nil
48
+ }.compact
49
+
50
+ {
51
+ category: category,
52
+ name: pact_broker_example_name,
53
+ order: order,
54
+ request: request,
55
+ response: expected_response
56
+ }
57
+ end
58
+
59
+ end
60
+ end
61
+
62
+ RSpec.configure do | config |
63
+ config.include(PactBroker::Documentation)
64
+ end
@@ -7,7 +7,7 @@ module PactBroker
7
7
  using PactBroker::StringRefinements
8
8
 
9
9
  def determinate_headers(headers)
10
- headers.without("Date", "Server")
10
+ headers.without("Date", "Server", "Content-Length")
11
11
  end
12
12
 
13
13
  def rack_env_to_http_headers(rack_env)
@@ -18,12 +18,17 @@ task "pact_broker:dev:setup" do
18
18
  end
19
19
 
20
20
  desc "List the Pact Broker API routes"
21
- task "pact_broker:routes", [:search_term] do | _, args |
22
- puts "Listing routes containing the term '#{args[:search_term]}'" if args[:search_term]
21
+ task :'pact_broker:routes', [:search_term] do | _t, args |
22
+ project_root = File.absolute_path(File.join(__dir__, "..", "..", ".."))
23
+ $LOAD_PATH << File.join(project_root,"app_shared","lib")
24
+
25
+ search_term = args[:search_term]
26
+ puts "Listing Pact Broker routes containing the term '#{search_term}'" if search_term
23
27
  require "tempfile"
24
28
  require "sequel"
25
29
  require "pact_broker"
26
30
  require "pact_broker/project_root"
31
+ require "pathname"
27
32
 
28
33
  Tempfile.create("pact_broker_routes") do |f|
29
34
  CONNECTION = Sequel.connect({ adapter: "sqlite", database: f.path, encoding: "utf8", sql_log_level: :debug })
@@ -32,20 +37,16 @@ task "pact_broker:routes", [:search_term] do | _, args |
32
37
  PactBroker::DB.run_migrations(CONNECTION)
33
38
 
34
39
  require "pact_broker/api"
40
+ require "webmachine/describe_routes"
35
41
 
36
- routes_debugging = PactBroker::API.application.routes.collect do | route |
37
- ["/" + route.path_spec.collect{ |part| part.is_a?(Symbol) ? ":#{part}" : part }.join("/"), route.resource]
38
- end
39
-
40
- if args[:search_term]
41
- routes_debugging = routes_debugging.select{ |(route, _)| route.include?(args[:search_term]) }
42
- end
42
+ routes = Webmachine::DescribeRoutes.call([PactBroker::API.application], search_term: search_term)
43
43
 
44
- routes_debugging.sort_by(&:first).each do | (path, resource_class) |
44
+ routes.each do | route |
45
45
  puts ""
46
- puts "#{path}"
47
- puts " class: #{resource_class}"
48
- puts " location: #{resource_class.instance_method(:allowed_methods).source_location.first.gsub(PactBroker.project_root.to_s + "/", "")}"
46
+ puts "#{route[:path]}"
47
+ puts " allowed_methods: #{route[:allowed_methods].join(", ")}"
48
+ puts " class: #{route[:resource_class]}"
49
+ puts " location: #{route[:resource_class_location]}"
49
50
  end
50
51
  end
51
52
  end