pact_broker 2.9.0 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -1
  3. data/config.ru +2 -2
  4. data/lib/pact_broker/api/decorators/relationships_csv_decorator.rb +6 -6
  5. data/lib/pact_broker/domain/group.rb +3 -3
  6. data/lib/pact_broker/domain/{relationship.rb → index_item.rb} +27 -7
  7. data/lib/pact_broker/groups/service.rb +2 -3
  8. data/lib/pact_broker/index/service.rb +56 -0
  9. data/lib/pact_broker/pacticipants/service.rb +0 -12
  10. data/lib/pact_broker/pacts/pact_publication.rb +4 -0
  11. data/lib/pact_broker/pacts/repository.rb +1 -1
  12. data/lib/pact_broker/relationships/groupify.rb +8 -8
  13. data/lib/pact_broker/services.rb +5 -0
  14. data/lib/pact_broker/tags/repository.rb +11 -1
  15. data/lib/pact_broker/tags/service.rb +3 -1
  16. data/lib/pact_broker/ui/app.rb +3 -3
  17. data/lib/pact_broker/ui/controllers/clusters.rb +1 -1
  18. data/lib/pact_broker/ui/controllers/groups.rb +1 -1
  19. data/lib/pact_broker/ui/controllers/index.rb +22 -0
  20. data/lib/pact_broker/ui/view_models/{relationship.rb → index_item.rb} +32 -5
  21. data/lib/pact_broker/ui/view_models/index_items.rb +30 -0
  22. data/lib/pact_broker/ui/views/index/show-with-tags.haml +83 -0
  23. data/lib/pact_broker/ui/views/{relationships → index}/show.haml +18 -18
  24. data/lib/pact_broker/ui/views/matrix/show.haml +1 -1
  25. data/lib/pact_broker/verifications/repository.rb +3 -0
  26. data/lib/pact_broker/version.rb +1 -1
  27. data/public/stylesheets/{relationships.css → index.css} +0 -0
  28. data/script/seed.rb +55 -39
  29. data/spec/integration/app_spec.rb +1 -1
  30. data/spec/integration/endpoints/{group.rb → group_spec.rb} +0 -3
  31. data/spec/integration/ui/index_spec.rb +36 -0
  32. data/spec/lib/pact_broker/domain/group_spec.rb +3 -3
  33. data/spec/lib/pact_broker/domain/{relationship_spec.rb → index_items_spec.rb} +3 -3
  34. data/spec/lib/pact_broker/groups/service_spec.rb +5 -4
  35. data/spec/lib/pact_broker/index/service_spec.rb +131 -0
  36. data/spec/lib/pact_broker/pacticipants/service_spec.rb +2 -35
  37. data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +35 -0
  38. data/spec/lib/pact_broker/pacts/repository_spec.rb +16 -14
  39. data/spec/lib/pact_broker/relationships/groupify_spec.rb +7 -7
  40. data/spec/lib/pact_broker/tags/repository_spec.rb +23 -1
  41. data/spec/lib/pact_broker/tags/service_spec.rb +0 -1
  42. data/spec/lib/pact_broker/ui/controllers/index_spec.rb +71 -0
  43. data/spec/lib/pact_broker/ui/view_models/{relationship_spec.rb → index_item_spec.rb} +38 -18
  44. data/spec/lib/pact_broker/ui/view_models/{relationships_spec.rb → index_items_spec.rb} +10 -10
  45. metadata +26 -18
  46. data/lib/pact_broker/ui/controllers/relationships.rb +0 -21
  47. data/lib/pact_broker/ui/view_models/relationships.rb +0 -30
  48. data/spec/lib/pact_broker/ui/controllers/relationships_spec.rb +0 -39
@@ -0,0 +1,22 @@
1
+ require 'pact_broker/ui/controllers/base_controller'
2
+ require 'pact_broker/ui/view_models/index_items'
3
+ require 'haml'
4
+
5
+ module PactBroker
6
+ module UI
7
+ module Controllers
8
+ class Index < Base
9
+
10
+ include PactBroker::Services
11
+
12
+ get "/" do
13
+ tags = params[:tags] == 'true' ? true : [*params[:tags]].compact
14
+ view_model = ViewDomain::IndexItems.new(index_service.find_index_items(tags: tags))
15
+ page = tags == true || tags.any? ? :'index/show-with-tags' : :'index/show'
16
+ haml page, {locals: {index_items: view_model, title: "Pacts"}, layout: :'layouts/main'}
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -5,7 +5,7 @@ require 'pact_broker/date_helper'
5
5
  module PactBroker
6
6
  module UI
7
7
  module ViewDomain
8
- class Relationship
8
+ class IndexItem
9
9
 
10
10
  include PactBroker::Api::PactBrokerUrls
11
11
 
@@ -21,6 +21,19 @@ module PactBroker
21
21
  @relationship.provider_name
22
22
  end
23
23
 
24
+ def consumer_version_number
25
+ short_version_number(@relationship.consumer_version_number)
26
+ end
27
+
28
+ def provider_version_number
29
+ short_version_number(@relationship.provider_version_number)
30
+ end
31
+
32
+ def tag_names
33
+ latest_overall = @relationship.latest? ? "latest & " : ""
34
+ @relationship.tag_names.any? ? " (#{latest_overall}latest #{@relationship.tag_names.join(', ')}) ": " (latest) "
35
+ end
36
+
24
37
  def consumer_group_url
25
38
  Helpers::URLHelper.group_url consumer_name
26
39
  end
@@ -29,7 +42,7 @@ module PactBroker
29
42
  Helpers::URLHelper.group_url provider_name
30
43
  end
31
44
 
32
- def latest_pact_url
45
+ def pact_url
33
46
  "#{pactigration_base_url('', @relationship)}/latest"
34
47
  end
35
48
 
@@ -38,6 +51,7 @@ module PactBroker
38
51
  end
39
52
 
40
53
  def webhook_label
54
+ return "" unless show_webhook_status?
41
55
  case @relationship.webhook_status
42
56
  when :none then "Create"
43
57
  when :success, :failure then webhook_last_execution_date
@@ -47,6 +61,7 @@ module PactBroker
47
61
  end
48
62
 
49
63
  def webhook_status
64
+ return "" unless show_webhook_status?
50
65
  case @relationship.webhook_status
51
66
  when :success then "success"
52
67
  when :failure then "danger"
@@ -55,6 +70,10 @@ module PactBroker
55
70
  end
56
71
  end
57
72
 
73
+ def show_webhook_status?
74
+ @relationship.latest?
75
+ end
76
+
58
77
  def webhook_last_execution_date
59
78
  PactBroker::DateHelper.distance_of_time_in_words(@relationship.last_webhook_execution_date, DateTime.now) + " ago"
60
79
  end
@@ -99,11 +118,11 @@ module PactBroker
99
118
  def verification_tooltip
100
119
  case @relationship.verification_status
101
120
  when :success
102
- "Successfully verified by #{provider_name} (v#{@relationship.latest_verification_provider_version_number})"
121
+ "Successfully verified by #{provider_name} (v#{short_version_number(@relationship.latest_verification_provider_version_number)})"
103
122
  when :stale
104
- "Pact has changed since last successful verification by #{provider_name} (v#{@relationship.latest_verification_provider_version_number})"
123
+ "Pact has changed since last successful verification by #{provider_name} (v#{short_version_number(@relationship.latest_verification_provider_version_number)})"
105
124
  when :failed
106
- "Verification by #{provider_name} (v#{@relationship.latest_verification_provider_version_number}) failed"
125
+ "Verification by #{provider_name} (v#{short_version_number(@relationship.latest_verification_provider_version_number)}) failed"
107
126
  else
108
127
  nil
109
128
  end
@@ -115,6 +134,14 @@ module PactBroker
115
134
  provider_name.downcase <=> other.provider_name.downcase
116
135
  end
117
136
 
137
+ def short_version_number version_number
138
+ return "" if version_number.nil?
139
+ if version_number.size > 12
140
+ version_number[0..12] + "..."
141
+ else
142
+ version_number
143
+ end
144
+ end
118
145
  end
119
146
  end
120
147
  end
@@ -0,0 +1,30 @@
1
+ require 'pact_broker/ui/view_models/index_item'
2
+
3
+ module PactBroker
4
+ module UI
5
+ module ViewDomain
6
+ class IndexItems
7
+
8
+ def initialize index_items
9
+ @index_items = index_items.collect{ |index_item| IndexItem.new(index_item) }.sort
10
+ end
11
+
12
+ def each(&block)
13
+ index_items.each(&block)
14
+ end
15
+
16
+ def size_label
17
+ case index_items.size
18
+ when 1 then "1 pact"
19
+ else
20
+ "#{index_items.size} pacts"
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :index_items
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,83 @@
1
+ %body
2
+ %link{rel: 'stylesheet', href: '/css/bootstrap.min.css'}
3
+ %link{rel: 'stylesheet', href: '/stylesheets/index.css'}
4
+ %script{type: 'text/javascript', src:'/javascripts/jquery-2.1.1.min.js'}
5
+ %script{type: 'text/javascript', src:'/javascripts/jquery.tablesorter.min.js'}
6
+ %script{type: 'text/javascript', src:'/js/bootstrap.min.js'}
7
+ %nav.navbase-default.navbar-right{role: "navigation"}
8
+ .container
9
+ %ul
10
+ %li.navbar-right
11
+ %a{ href: '/hal-browser/browser.html' }
12
+ API Browser
13
+ .container
14
+ %h1.page-header
15
+ Pacts
16
+ %table.table.table-bordered.table-striped{ id: 'relationships' }
17
+ %thead
18
+ %th.consumer
19
+ Consumer
20
+ %span.glyphicon.glyphicon-sort.relationships-sort
21
+ %th.tag
22
+ Version
23
+ %span.glyphicon.glyphicon-sort.relationships-sort
24
+ %th.pact{ style: 'width: 40px' }
25
+ %th.provider
26
+ Provider
27
+ %span.glyphicon.glyphicon-sort.relationships-sort
28
+ %th.tag
29
+ Version
30
+ %span.glyphicon.glyphicon-sort.relationships-sort
31
+ %th
32
+ Published
33
+ %th
34
+ Webhook<br>status
35
+ %th
36
+ Last<br>verified
37
+ %tbody
38
+
39
+ - index_items.each do | index_item |
40
+ %tr
41
+ %td.consumer
42
+ %a{:href => index_item.consumer_group_url }
43
+ = index_item.consumer_name
44
+ %td
45
+ = index_item.consumer_version_number
46
+ %span{style: 'color:gray'}
47
+ = index_item.tag_names
48
+ %td.pact
49
+ %a{ href: index_item.pact_url, title: "View pact" }
50
+ %span.pact
51
+ %td.provider
52
+ %a{ href: index_item.provider_group_url }
53
+ = index_item.provider_name
54
+ %td
55
+ = index_item.provider_version_number
56
+ %td
57
+ = index_item.publication_date_of_latest_pact.gsub("about ", "")
58
+ %td{ class: index_item.webhook_status }
59
+ - if index_item.show_webhook_status?
60
+ %a{ href: index_item.webhook_url }
61
+ = index_item.webhook_label
62
+
63
+ %td{ class: index_item.verification_status, title: index_item.verification_tooltip, "data-toggle": "tooltip", "data-placement": "left" }
64
+ %div
65
+ = index_item.last_verified_date.gsub("about ", "")
66
+ - if index_item.warning?
67
+ %span.glyphicon.glyphicon-warning-sign{ 'aria-hidden': true }
68
+ %div.relationships-size
69
+ = index_items.size_label
70
+
71
+ :javascript
72
+ $(function(){
73
+ $("#relationships").tablesorter();
74
+ });
75
+
76
+ $(document).ready(function(){
77
+ $("span.pact").load("/images/doc-text.svg");
78
+ $('td[data-toggle="tooltip"]').each(function(index, td){
79
+ //appended tooltip div screws up table if it's appended after a
80
+ //td, so need to append it to a div
81
+ $(td).tooltip({container: $(td).first()});
82
+ });
83
+ });
@@ -1,6 +1,6 @@
1
1
  %body
2
2
  %link{rel: 'stylesheet', href: '/css/bootstrap.min.css'}
3
- %link{rel: 'stylesheet', href: '/stylesheets/relationships.css'}
3
+ %link{rel: 'stylesheet', href: '/stylesheets/index.css'}
4
4
  %script{type: 'text/javascript', src:'/javascripts/jquery-2.1.1.min.js'}
5
5
  %script{type: 'text/javascript', src:'/javascripts/jquery.tablesorter.min.js'}
6
6
  %script{type: 'text/javascript', src:'/js/bootstrap.min.js'}
@@ -8,12 +8,12 @@
8
8
  .container
9
9
  %ul
10
10
  %li.navbar-right
11
- %a{href: '/hal-browser/browser.html'}
11
+ %a{ href: '/hal-browser/browser.html' }
12
12
  API Browser
13
13
  .container
14
14
  %h1.page-header
15
15
  Pacts
16
- %table.table.table-bordered.table-striped{id: 'relationships'}
16
+ %table.table.table-bordered.table-striped{ id: 'relationships' }
17
17
  %thead
18
18
  %th
19
19
  %th.consumer
@@ -33,32 +33,32 @@
33
33
  Last<br>verified
34
34
  %tbody
35
35
 
36
- - relationships.each do | relationship |
36
+ - index_items.each do | index_item |
37
37
  %tr
38
38
  %td
39
39
  %td.consumer
40
- %a{:href => relationship.consumer_group_url}
41
- = relationship.consumer_name
40
+ %a{ href: index_item.consumer_group_url }
41
+ = index_item.consumer_name
42
42
  %td.pact
43
- %a{:href => relationship.latest_pact_url, :title => "View pact"}
43
+ %a{ href: index_item.pact_url, :title => "View pact" }
44
44
  %span.pact
45
45
  %td.provider
46
- %a{:href => relationship.provider_group_url}
47
- = relationship.provider_name
46
+ %a{ href: index_item.provider_group_url }
47
+ = index_item.provider_name
48
48
  %td
49
49
  %td
50
- = relationship.publication_date_of_latest_pact
51
- %td{class: relationship.webhook_status}
52
- %a{:href => relationship.webhook_url}
53
- = relationship.webhook_label
50
+ = index_item.publication_date_of_latest_pact
51
+ %td{class: index_item.webhook_status}
52
+ %a{ href: index_item.webhook_url }
53
+ = index_item.webhook_label
54
54
 
55
- %td{class: relationship.verification_status, title: relationship.verification_tooltip, "data-toggle": "tooltip", "data-placement": "left"}
55
+ %td{ class: index_item.verification_status, title: index_item.verification_tooltip, "data-toggle": "tooltip", "data-placement": "left" }
56
56
  %div
57
- = relationship.last_verified_date
58
- - if relationship.warning?
59
- %span.glyphicon.glyphicon-warning-sign{'aria-hidden':true}
57
+ = index_item.last_verified_date
58
+ - if index_item.warning?
59
+ %span.glyphicon.glyphicon-warning-sign{ 'aria-hidden': true }
60
60
  %div.relationships-size
61
- = relationships.size_label
61
+ = index_items.size_label
62
62
 
63
63
  :javascript
64
64
  $(function(){
@@ -1,6 +1,6 @@
1
1
  %body
2
2
  %link{rel: 'stylesheet', href: '/css/bootstrap.min.css'}
3
- %link{rel: 'stylesheet', href: '/stylesheets/relationships.css'}
3
+ %link{rel: 'stylesheet', href: '/stylesheets/index.css'}
4
4
  %script{type: 'text/javascript', src:'/javascripts/jquery-2.1.1.min.js'}
5
5
  %script{type: 'text/javascript', src:'/javascripts/jquery.tablesorter.min.js'}
6
6
  %script{type: 'text/javascript', src:'/js/bootstrap.min.js'}
@@ -43,6 +43,9 @@ module PactBroker
43
43
  .all
44
44
  end
45
45
 
46
+ # The most recent verification for the latest revision of the pact
47
+ # belonging to the version with the largest consumer_version_order.
48
+
46
49
  def find_latest_verification_for consumer_name, provider_name, tag = nil
47
50
  query = LatestVerificationsByConsumerVersion
48
51
  .select_all_qualified
@@ -1,3 +1,3 @@
1
1
  module PactBroker
2
- VERSION = '2.9.0'
2
+ VERSION = '2.10.0'
3
3
  end
File without changes
data/script/seed.rb CHANGED
@@ -48,43 +48,59 @@ end
48
48
  # .create_pact
49
49
 
50
50
 
51
+ # TestDataBuilder.new
52
+ # .create_consumer("Foo")
53
+ # .create_label("microservice")
54
+ # .create_provider("Bar")
55
+ # .create_label("microservice")
56
+ # .create_webhook(method: 'GET', url: 'http://localhost:9393?url=${pactbroker.pactUrl}', body: '${pactbroker.pactUrl}')
57
+ # .create_consumer_version("1.2.100")
58
+ # .publish_pact
59
+ # .create_verification(provider_version: "1.4.234", success: true, execution_date: DateTime.now - 15)
60
+ # .revise_pact
61
+ # .create_consumer_version("1.2.101")
62
+ # .create_consumer_version_tag('prod')
63
+ # .publish_pact
64
+ # .create_verification(provider_version: "9.9.10", success: false, execution_date: DateTime.now - 15)
65
+ # .create_consumer_version("1.2.102")
66
+ # .publish_pact(created_at: (Date.today - 7).to_datetime)
67
+ # .create_verification(provider_version: "9.9.9", success: true, execution_date: DateTime.now - 14)
68
+ # .create_provider("Animals")
69
+ # .create_webhook(method: 'GET', url: 'http://localhost:9393/')
70
+ # .publish_pact(created_at: (Time.now - 140).to_datetime)
71
+ # .create_verification(provider_version: "2.0.366", execution_date: Date.today - 2) #changed
72
+ # .create_provider("Wiffles")
73
+ # .publish_pact
74
+ # .create_verification(provider_version: "3.6.100", success: false, execution_date: Date.today - 7)
75
+ # .create_provider("Hello World App")
76
+ # .create_consumer_version("1.2.107")
77
+ # .publish_pact(created_at: (Date.today - 1).to_datetime)
78
+ # .create_consumer("The Android App")
79
+ # .create_provider("The back end")
80
+ # .create_webhook(method: 'GET', url: 'http://localhost:9393/')
81
+ # .create_consumer_version("1.2.106")
82
+ # .create_consumer_version_tag("production")
83
+ # .create_consumer_version_tag("feat-x")
84
+ # .publish_pact
85
+ # .create_consumer("Some other app")
86
+ # .create_provider("A service")
87
+ # .create_webhook(method: 'GET', url: 'http://localhost:9393/')
88
+ # .create_triggered_webhook(status: 'success')
89
+ # .create_webhook_execution
90
+ # .create_webhook(method: 'POST', url: 'http://foo:9393/')
91
+ # .create_triggered_webhook(status: 'failure')
92
+ # .create_webhook_execution
93
+ # .create_consumer_version("1.2.106")
94
+ # .publish_pact(created_at: (Date.today - 26).to_datetime)
95
+ # .create_verification(provider_version: "4.8.152", execution_date: DateTime.now)
96
+
51
97
  TestDataBuilder.new
52
- .create_consumer("Foo")
53
- .create_label("microservice")
54
- .create_provider("Bar")
55
- .create_label("microservice")
56
- .create_webhook(method: 'GET', url: 'http://localhost:9393?url=${pactbroker.pactUrl}', body: '${pactbroker.pactUrl}')
57
- .create_consumer_version("1.2.100")
58
- .publish_pact
59
- .create_verification(provider_version: "1.4.234", success: true, execution_date: DateTime.now - 15)
60
- .revise_pact
61
- .create_consumer_version("1.2.101")
62
- .publish_pact
63
- .create_consumer_version("1.2.102")
64
- .publish_pact(created_at: (Date.today - 7).to_datetime)
65
- .create_provider("Animals")
66
- .create_webhook(method: 'GET', url: 'http://localhost:9393/')
67
- .publish_pact(created_at: (Time.now - 140).to_datetime)
68
- .create_verification(provider_version: "2.0.366", execution_date: Date.today - 2) #changed
69
- .create_provider("Wiffles")
70
- .publish_pact
71
- .create_verification(provider_version: "3.6.100", success: false, execution_date: Date.today - 7)
72
- .create_provider("Hello World App")
73
- .create_consumer_version("1.2.107")
74
- .publish_pact(created_at: (Date.today - 1).to_datetime)
75
- .create_consumer("The Android App")
76
- .create_provider("The back end")
77
- .create_webhook(method: 'GET', url: 'http://localhost:9393/')
78
- .create_consumer_version("1.2.106")
79
- .publish_pact
80
- .create_consumer("Some other app")
81
- .create_provider("A service")
82
- .create_webhook(method: 'GET', url: 'http://localhost:9393/')
83
- .create_triggered_webhook(status: 'success')
84
- .create_webhook_execution
85
- .create_webhook(method: 'POST', url: 'http://foo:9393/')
86
- .create_triggered_webhook(status: 'failure')
87
- .create_webhook_execution
88
- .create_consumer_version("1.2.106")
89
- .publish_pact(created_at: (Date.today - 26).to_datetime)
90
- .create_verification(provider_version: "4.8.152", execution_date: DateTime.now)
98
+ .create_pact_with_hierarchy("A", "1", "B")
99
+ .create_consumer_version_tag("master")
100
+ .create_consumer_version_tag("prod")
101
+ .create_verification(provider_version: "1")
102
+ .create_consumer_version("2")
103
+ .create_consumer_version_tag("master")
104
+ .create_pact
105
+ .create_verification(provider_version: "2")
106
+
@@ -31,7 +31,7 @@ module PactBroker
31
31
  context "when Accept includes text/html" do
32
32
  let(:env) { {'HTTP_ACCEPT' => 'text/html'} }
33
33
 
34
- subject { get path, '', env; last_response }
34
+ subject { get path, '', env; last_response.tap { |it| File.open("bethtest.html", "w") { |file| file << it.body } } }
35
35
 
36
36
  describe "a request for root" do
37
37
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "/groups/{pacticipant-name}" do
4
2
 
5
3
  let(:app) { PactBroker::API }
@@ -18,5 +16,4 @@ describe "/groups/{pacticipant-name}" do
18
16
  expect(last_response.body).to_not be_nil
19
17
  end
20
18
  end
21
-
22
19
  end