pact_broker 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/README.md +8 -11
  4. data/lib/pact_broker/api.rb +2 -0
  5. data/lib/pact_broker/api/decorators/decorator_context.rb +8 -1
  6. data/lib/pact_broker/api/decorators/pact_decorator.rb +18 -3
  7. data/lib/pact_broker/api/decorators/pact_version_decorator.rb +39 -0
  8. data/lib/pact_broker/api/decorators/pact_versions_decorator.rb +48 -0
  9. data/lib/pact_broker/api/decorators/pacticipant_decorator.rb +3 -3
  10. data/lib/pact_broker/api/decorators/webhook_decorator.rb +1 -1
  11. data/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +1 -1
  12. data/lib/pact_broker/api/decorators/webhooks_decorator.rb +1 -1
  13. data/lib/pact_broker/api/pact_broker_urls.rb +16 -6
  14. data/lib/pact_broker/api/renderers/html_pact_renderer.rb +35 -6
  15. data/lib/pact_broker/api/resources/base_resource.rb +80 -33
  16. data/lib/pact_broker/api/resources/group.rb +26 -24
  17. data/lib/pact_broker/api/resources/index.rb +52 -51
  18. data/lib/pact_broker/api/resources/latest_pact.rb +22 -22
  19. data/lib/pact_broker/api/resources/latest_pacts.rb +18 -17
  20. data/lib/pact_broker/api/resources/pact.rb +34 -39
  21. data/lib/pact_broker/api/resources/pact_versions.rb +35 -0
  22. data/lib/pact_broker/api/resources/pact_webhooks.rb +54 -61
  23. data/lib/pact_broker/api/resources/pacticipant.rb +40 -39
  24. data/lib/pact_broker/api/resources/pacticipant_resource_methods.rb +19 -0
  25. data/lib/pact_broker/api/resources/pacticipants.rb +52 -17
  26. data/lib/pact_broker/api/resources/relationships.rb +18 -17
  27. data/lib/pact_broker/api/resources/tag.rb +30 -29
  28. data/lib/pact_broker/api/resources/webhook.rb +29 -28
  29. data/lib/pact_broker/api/resources/webhook_execution.rb +0 -1
  30. data/lib/pact_broker/api/resources/webhook_resource_methods.rb +24 -0
  31. data/lib/pact_broker/api/resources/webhooks.rb +18 -17
  32. data/lib/pact_broker/app.rb +1 -0
  33. data/lib/pact_broker/configuration.rb +2 -2
  34. data/lib/pact_broker/doc/views/webhooks.markdown +1 -1
  35. data/lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb +43 -0
  36. data/lib/pact_broker/locale/en.yml +7 -0
  37. data/lib/pact_broker/messages.rb +20 -1
  38. data/lib/pact_broker/models/pact.rb +8 -0
  39. data/lib/pact_broker/models/pacticipant.rb +9 -0
  40. data/lib/pact_broker/models/version.rb +1 -0
  41. data/lib/pact_broker/repositories/pact_repository.rb +6 -0
  42. data/lib/pact_broker/repositories/pacticipant_repository.rb +4 -0
  43. data/lib/pact_broker/repositories/webhook_repository.rb +2 -3
  44. data/lib/pact_broker/services/pact_service.rb +20 -0
  45. data/lib/pact_broker/services/pacticipant_service.rb +28 -0
  46. data/lib/pact_broker/services/webhook_service.rb +7 -2
  47. data/lib/pact_broker/version.rb +1 -1
  48. data/pact_broker.gemspec +1 -1
  49. data/public/stylesheets/github.css +1 -1
  50. data/public/stylesheets/pact.css +12 -0
  51. data/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +10 -0
  52. data/spec/lib/pact_broker/api/decorators/pact_version_decorator_spec.rb +49 -0
  53. data/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +9 -1
  54. data/spec/lib/pact_broker/api/resources/group_spec.rb +1 -1
  55. data/spec/lib/pact_broker/api/resources/latest_pact_spec.rb +1 -1
  56. data/spec/lib/pact_broker/api/resources/pact_spec.rb +35 -6
  57. data/spec/lib/pact_broker/api/resources/pact_webhooks_spec.rb +6 -4
  58. data/spec/lib/pact_broker/api/resources/pacticipants_spec.rb +91 -0
  59. data/spec/lib/pact_broker/configuration_spec.rb +3 -3
  60. data/spec/lib/pact_broker/functions/find_potential_duplicate_pacticipant_names_spec.rb +82 -0
  61. data/spec/lib/pact_broker/messages_spec.rb +31 -0
  62. data/spec/lib/pact_broker/models/pacticipant_spec.rb +32 -0
  63. data/spec/lib/pact_broker/repositories/pact_repository_spec.rb +29 -0
  64. data/spec/lib/pact_broker/repositories/pacticipant_repository_spec.rb +29 -0
  65. data/spec/lib/pact_broker/repositories/webhook_repository_spec.rb +7 -18
  66. data/spec/lib/pact_broker/services/pact_service_spec.rb +20 -0
  67. data/spec/lib/pact_broker/services/pacticipant_service_spec.rb +87 -2
  68. data/spec/support/provider_state_builder.rb +7 -7
  69. data/tasks/rspec.rake +1 -1
  70. metadata +27 -2
@@ -8,57 +8,58 @@ module Webmachine
8
8
  end
9
9
  end
10
10
 
11
- module PactBroker::Api
11
+ module PactBroker
12
+ module Api
13
+ module Resources
12
14
 
13
- module Resources
15
+ class Pacticipant < BaseResource
14
16
 
15
- class Pacticipant < BaseResource
17
+ def content_types_provided
18
+ [["application/hal+json", :to_json]]
19
+ end
16
20
 
17
- def content_types_provided
18
- [["application/hal+json", :to_json]]
19
- end
21
+ def content_types_accepted
22
+ [["application/json", :from_json]]
23
+ end
20
24
 
21
- def content_types_accepted
22
- [["application/json", :from_json]]
23
- end
25
+ def allowed_methods
26
+ ["GET", "PATCH", "DELETE"]
27
+ end
24
28
 
25
- def allowed_methods
26
- ["GET", "PATCH", "DELETE"]
27
- end
29
+ def known_methods
30
+ super + ['PATCH']
31
+ end
28
32
 
29
- def known_methods
30
- super + ['PATCH']
31
- end
33
+ def from_json
34
+ if @pacticipant
35
+ @pacticipant = pacticipant_service.update params.merge(name: pacticipant_name)
36
+ else
37
+ @pacticipant = pacticipant_service.create params.merge(name: pacticipant_name)
38
+ response.headers["Location"] = pacticipant_url(base_url, @pacticipant)
39
+ end
40
+ response.body = to_json
41
+ end
32
42
 
33
- def from_json
34
- if @pacticipant
35
- @pacticipant = pacticipant_service.update params.merge(name: pacticipant_name)
36
- else
37
- @pacticipant = pacticipant_service.create params.merge(name: pacticipant_name)
38
- response.headers["Location"] = pacticipant_url(base_url, @pacticipant)
43
+ def resource_exists?
44
+ @pacticipant = pacticipant_service.find_pacticipant_by_name(pacticipant_name)
45
+ @pacticipant != nil
39
46
  end
40
- response.body = to_json
41
- end
42
47
 
43
- def resource_exists?
44
- @pacticipant = pacticipant_service.find_pacticipant_by_name(pacticipant_name)
45
- @pacticipant != nil
46
- end
48
+ def delete_resource
49
+ pacticipant_service.delete pacticipant_name
50
+ true
51
+ end
47
52
 
48
- def delete_resource
49
- pacticipant_service.delete pacticipant_name
50
- true
51
- end
53
+ def to_json
54
+ PactBroker::Api::Decorators::PacticipantRepresenter.new(@pacticipant).to_json(base_url: base_url)
55
+ end
52
56
 
53
- def to_json
54
- PactBroker::Api::Decorators::PacticipantRepresenter.new(@pacticipant).to_json(base_url: base_url)
55
- end
57
+ def pacticipant_name
58
+ identifier_from_path[:name]
59
+ end
56
60
 
57
- def pacticipant_name
58
- identifier_from_path[:name]
59
61
  end
60
-
61
62
  end
62
- end
63
63
 
64
- end
64
+ end
65
+ end
@@ -0,0 +1,19 @@
1
+ module PactBroker
2
+ module Api
3
+ module Resources
4
+
5
+ module PacticipantResourceMethods
6
+
7
+ def potential_duplicate_pacticipants? pacticipant_names
8
+ messages = pacticipant_service.messages_for_potential_duplicate_pacticipants pacticipant_names, base_url
9
+ if messages.any?
10
+ response.body = messages.join("\n")
11
+ response.headers['Content-Type'] = 'text/plain'
12
+ end
13
+ messages.any?
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,28 +1,63 @@
1
1
  require 'pact_broker/api/resources/base_resource'
2
+ require 'pact_broker/api/decorators/pacticipant_decorator'
3
+ require 'pact_broker/models/pacticipant'
2
4
 
3
- module PactBroker::Api
5
+ module PactBroker
6
+ module Api
7
+ module Resources
4
8
 
5
- module Resources
9
+ class Pacticipants < BaseResource
6
10
 
7
- class Pacticipants < BaseResource
11
+ def content_types_provided
12
+ [["application/hal+json", :to_json]]
13
+ end
8
14
 
9
- def content_types_provided
10
- [["application/hal+json", :to_json]]
11
- end
15
+ def content_types_accepted
16
+ [["application/json", :from_json]]
17
+ end
12
18
 
13
- def allowed_methods
14
- ["GET"]
15
- end
19
+ def allowed_methods
20
+ ["GET", "POST"]
21
+ end
16
22
 
17
- def to_json
18
- generate_json(pacticipant_service.find_all_pacticipants)
19
- end
23
+ def malformed_request?
24
+ if request.post?
25
+ return invalid_json? || validation_errors?(new_model)
26
+ end
27
+ false
28
+ end
20
29
 
21
- def generate_json pacticipants
22
- PactBroker::Api::Decorators::PacticipantCollectionRepresenter.new(pacticipants).to_json(base_url: base_url)
23
- end
30
+ def post_is_create?
31
+ true
32
+ end
33
+
34
+ def from_json
35
+ created_model = pacticipant_service.create params
36
+ response.body = decorator_for(created_model).to_json(decorator_context)
37
+ end
38
+
39
+ def create_path
40
+ "/pacticpants/#{url_encode(params[:name])}"
41
+ end
42
+
43
+ def to_json
44
+ generate_json(pacticipant_service.find_all_pacticipants)
45
+ end
24
46
 
47
+ def generate_json pacticipants
48
+ PactBroker::Api::Decorators::PacticipantCollectionRepresenter.new(pacticipants).to_json(base_url: base_url)
49
+ end
50
+
51
+ def decorator_for model
52
+ PactBroker::Api::Decorators::PacticipantRepresenter.new(model)
53
+ end
54
+
55
+ def new_model
56
+ @new_model ||= decorator_for(PactBroker::Models::Pacticipant.new).from_json(request.body.to_s)
57
+ end
58
+
59
+ end
25
60
  end
26
- end
27
61
 
28
- end
62
+ end
63
+ end
@@ -1,29 +1,30 @@
1
1
  require 'pact_broker/api/resources/base_resource'
2
2
  require 'pact_broker/api/decorators/relationships_csv_decorator'
3
3
 
4
- module PactBroker::Api
4
+ module PactBroker
5
+ module Api
6
+ module Resources
5
7
 
6
- module Resources
8
+ class Relationships < BaseResource
7
9
 
8
- class Relationships < BaseResource
10
+ def content_types_provided
11
+ [["text/csv", :to_csv]]
12
+ end
9
13
 
10
- def content_types_provided
11
- [["text/csv", :to_csv]]
12
- end
14
+ def allowed_methods
15
+ ["GET"]
16
+ end
13
17
 
14
- def allowed_methods
15
- ["GET"]
16
- end
18
+ def to_csv
19
+ generate_csv(pact_service.find_latest_pacts)
20
+ end
17
21
 
18
- def to_csv
19
- generate_csv(pact_service.find_latest_pacts)
20
- end
22
+ def generate_csv pacts
23
+ PactBroker::Api::Decorators::RelationshipsCsvDecorator.new(pacts).to_csv
24
+ end
21
25
 
22
- def generate_csv pacts
23
- PactBroker::Api::Decorators::RelationshipsCsvDecorator.new(pacts).to_csv
24
26
  end
25
-
26
27
  end
27
- end
28
28
 
29
- end
29
+ end
30
+ end
@@ -1,44 +1,45 @@
1
1
  require 'pact_broker/api/resources/base_resource'
2
2
 
3
- module PactBroker::Api
3
+ module PactBroker
4
+ module Api
5
+ module Resources
4
6
 
5
- module Resources
7
+ class Tag < BaseResource
6
8
 
7
- class Tag < BaseResource
9
+ def content_types_provided
10
+ [["application/hal+json", :to_json]]
11
+ end
8
12
 
9
- def content_types_provided
10
- [["application/hal+json", :to_json]]
11
- end
13
+ def content_types_accepted
14
+ [["application/json", :from_json]]
15
+ end
12
16
 
13
- def content_types_accepted
14
- [["application/json", :from_json]]
15
- end
17
+ def allowed_methods
18
+ ["GET","PUT"]
19
+ end
16
20
 
17
- def allowed_methods
18
- ["GET","PUT"]
19
- end
21
+ def from_json
22
+ unless @tag
23
+ @tag = tag_service.create identifier_from_path
24
+ response.headers["Location"] = tag_url(base_url, @tag)
25
+ end
26
+ response.body = generate_json @tag
27
+ end
20
28
 
21
- def from_json
22
- unless @tag
23
- @tag = tag_service.create identifier_from_path
24
- response.headers["Location"] = tag_url(base_url, @tag)
29
+ def resource_exists?
30
+ @tag = tag_service.find identifier_from_path
25
31
  end
26
- response.body = generate_json @tag
27
- end
28
32
 
29
- def resource_exists?
30
- @tag = tag_service.find identifier_from_path
31
- end
33
+ def to_json
34
+ generate_json(@tag)
35
+ end
32
36
 
33
- def to_json
34
- generate_json(@tag)
35
- end
37
+ def generate_json tag
38
+ PactBroker::Api::Decorators::TagDecorator.new(tag).to_json(base_url: base_url)
39
+ end
36
40
 
37
- def generate_json tag
38
- PactBroker::Api::Decorators::TagDecorator.new(tag).to_json(base_url: base_url)
39
41
  end
40
-
41
42
  end
42
- end
43
43
 
44
- end
44
+ end
45
+ end
@@ -1,44 +1,45 @@
1
1
  require 'pact_broker/services'
2
2
  require 'pact_broker/api/decorators/webhook_decorator'
3
3
 
4
- module PactBroker::Api
4
+ module PactBroker
5
+ module Api
6
+ module Resources
5
7
 
6
- module Resources
8
+ class Webhook < BaseResource
7
9
 
8
- class Webhook < BaseResource
10
+ def content_types_provided
11
+ [["application/hal+json", :to_json]]
12
+ end
9
13
 
10
- def content_types_provided
11
- [["application/hal+json", :to_json]]
12
- end
14
+ def allowed_methods
15
+ ["GET", "DELETE"]
16
+ end
13
17
 
14
- def allowed_methods
15
- ["GET", "DELETE"]
16
- end
18
+ def resource_exists?
19
+ !webhook.nil?
20
+ end
17
21
 
18
- def resource_exists?
19
- !webhook.nil?
20
- end
22
+ def to_json
23
+ Decorators::WebhookDecorator.new(webhook).to_json(base_url: base_url)
24
+ end
21
25
 
22
- def to_json
23
- Decorators::WebhookDecorator.new(webhook).to_json(base_url: base_url)
24
- end
26
+ def delete_resource
27
+ webhook_service.delete_by_uuid uuid
28
+ true
29
+ end
25
30
 
26
- def delete_resource
27
- webhook_service.delete_by_uuid uuid
28
- true
29
- end
31
+ private
30
32
 
31
- private
33
+ def webhook
34
+ @webhook ||= webhook_service.find_by_uuid uuid
35
+ end
32
36
 
33
- def webhook
34
- @webhook ||= webhook_service.find_by_uuid uuid
35
- end
37
+ def uuid
38
+ identifier_from_path[:uuid]
39
+ end
36
40
 
37
- def uuid
38
- identifier_from_path[:uuid]
39
41
  end
40
-
41
42
  end
42
- end
43
43
 
44
- end
44
+ end
45
+ end
@@ -3,7 +3,6 @@ require 'pact_broker/api/decorators/webhook_execution_result_decorator'
3
3
 
4
4
  module PactBroker
5
5
  module Api
6
-
7
6
  module Resources
8
7
 
9
8
  class WebhookExecution < BaseResource
@@ -0,0 +1,24 @@
1
+ module PactBroker
2
+ module Api
3
+
4
+ module Resources
5
+
6
+ module WebhookResourceMethods
7
+
8
+ def malformed_webhook_request? webhook
9
+ begin
10
+ if (errors = webhook.validate).any?
11
+ set_json_validation_error_messages errors
12
+ return true
13
+ end
14
+ rescue
15
+ set_json_error_message 'Invalid JSON'
16
+ return true
17
+ end
18
+ false
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -1,29 +1,30 @@
1
1
  require 'pact_broker/services'
2
2
  require 'pact_broker/api/decorators/webhooks_decorator'
3
3
 
4
- module PactBroker::Api
4
+ module PactBroker
5
+ module Api
6
+ module Resources
5
7
 
6
- module Resources
8
+ class Webhooks < BaseResource
7
9
 
8
- class Webhooks < BaseResource
10
+ def content_types_provided
11
+ [["application/hal+json", :to_json]]
12
+ end
9
13
 
10
- def content_types_provided
11
- [["application/hal+json", :to_json]]
12
- end
14
+ def allowed_methods
15
+ ["GET"]
16
+ end
13
17
 
14
- def allowed_methods
15
- ["GET"]
16
- end
18
+ def to_json
19
+ Decorators::WebhooksDecorator.new(webhooks).to_json(decorator_context(resource_title: "Webhooks"))
20
+ end
17
21
 
18
- def to_json
19
- Decorators::WebhooksDecorator.new(webhooks).to_json(decorator_context(resource_title: "Webhooks"))
20
- end
22
+ def webhooks
23
+ webhook_service.find_all
24
+ end
21
25
 
22
- def webhooks
23
- webhook_service.find_all
24
26
  end
25
-
26
27
  end
27
- end
28
28
 
29
- end
29
+ end
30
+ end