pact_broker 2.7.0.beta.1 → 2.7.0.beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +30 -4
  4. data/db/migrations/{01_create_pacticipant_table.rb → 000001_create_pacticipant_table.rb} +0 -0
  5. data/db/migrations/{02_create_versions_table.rb → 000002_create_versions_table.rb} +0 -0
  6. data/db/migrations/{03_create_pacts_table.rb → 000003_create_pacts_table.rb} +0 -0
  7. data/db/migrations/{04_create_tags_table.rb → 000004_create_tags_table.rb} +0 -0
  8. data/db/migrations/{05_add_order_column_to_version.rb → 000005_add_order_column_to_version.rb} +0 -0
  9. data/db/migrations/{06_make_version_foreign_key_mandatory.rb → 000006_make_version_foreign_key_mandatory.rb} +0 -0
  10. data/db/migrations/{07_increase_json_content_length.rb → 000007_increase_json_content_length.rb} +0 -0
  11. data/db/migrations/{08_create_latest_pact_view.rb → 000008_create_latest_pact_view.rb} +0 -0
  12. data/db/migrations/{09_add_timestamps.rb → 000009_add_timestamps.rb} +0 -0
  13. data/db/migrations/{10_populate_timestamps.rb → 000010_populate_timestamps.rb} +0 -0
  14. data/db/migrations/{11_made_timestamps_mandatory.rb → 000011_made_timestamps_mandatory.rb} +0 -0
  15. data/db/migrations/{12_create_webhooks_table.rb → 000012_create_webhooks_table.rb} +0 -0
  16. data/db/migrations/{13_add_columns_to_webhooks.rb → 000013_add_columns_to_webhooks.rb} +0 -0
  17. data/db/migrations/{14_add_timestamps_to_pact_views.rb → 000014_add_timestamps_to_pact_views.rb} +0 -0
  18. data/db/migrations/{15_create_pact_version_content.rb → 000015_create_pact_version_content.rb} +0 -0
  19. data/db/migrations/{16_add_pact_content_foreign_key_to_pacts.rb → 000016_add_pact_content_foreign_key_to_pacts.rb} +0 -0
  20. data/db/migrations/{17_migrate_json_content_to_pact_version_content_table.rb → 000017_migrate_json_content_to_pact_version_content_table.rb} +0 -0
  21. data/db/migrations/{18_drop_json_content_column_from_pacts.rb → 000018_drop_json_content_column_from_pacts.rb} +0 -0
  22. data/db/migrations/{19_make_pact_version_content_sha_not_nullable.rb → 000019_make_pact_version_content_sha_not_nullable.rb} +0 -0
  23. data/db/migrations/{20_add_pact_version_content_sha_to_all_pacts_view.rb → 000020_add_pact_version_content_sha_to_all_pacts_view.rb} +0 -0
  24. data/db/migrations/{21_recreate_latest_pacts_view.rb → 000021_recreate_latest_pacts_view.rb} +0 -0
  25. data/db/migrations/{22_create_latest_tagged_pacts_view.rb → 000022_create_latest_tagged_pacts_view.rb} +0 -0
  26. data/db/migrations/{23_create_pact_versions_table.rb → 000023_create_pact_versions_table.rb} +0 -0
  27. data/db/migrations/{24_populate_pact_versions.rb → 000024_populate_pact_versions.rb} +0 -0
  28. data/db/migrations/{25_make_pv_pacticipants_mandatory.rb → 000025_make_pv_pacticipants_mandatory.rb} +0 -0
  29. data/db/migrations/{26_create_pact_publications.rb → 000026_create_pact_publications.rb} +0 -0
  30. data/db/migrations/{27_populate_pact_publications.rb → 000027_populate_pact_publications.rb} +0 -0
  31. data/db/migrations/{28_create_all_pact_publications.rb → 000028_create_all_pact_publications.rb} +0 -0
  32. data/db/migrations/{29_create_latest_tagged_pact_publications.rb → 000029_create_latest_tagged_pact_publications.rb} +0 -0
  33. data/db/migrations/{30_drop_old_tables_and_views.rb → 000030_drop_old_tables_and_views.rb} +0 -0
  34. data/db/migrations/{31_create_verifications.rb → 000031_create_verifications.rb} +0 -0
  35. data/db/migrations/{32_create_latest_verifications.rb → 000032_create_latest_verifications.rb} +0 -0
  36. data/db/migrations/{33_create_config_table.rb → 000033_create_config_table.rb} +0 -0
  37. data/db/migrations/{34_create_index_on_consumer_version_order.rb → 000034_create_index_on_consumer_version_order.rb} +0 -0
  38. data/db/migrations/{35_create_index_on_names.rb → 000035_create_index_on_names.rb} +0 -0
  39. data/db/migrations/{36_create_webhook_execution.rb → 000036_create_webhook_execution.rb} +0 -0
  40. data/db/migrations/{37_create_labels_table.rb → 000037_create_labels_table.rb} +0 -0
  41. data/db/migrations/{38_create_triggered_webhooks_table.rb → 000038_create_triggered_webhooks_table.rb} +0 -0
  42. data/db/migrations/{39_add_triggered_webhooks_fk_to_execution.rb → 000039_add_triggered_webhooks_fk_to_execution.rb} +0 -0
  43. data/db/migrations/{40_create_latest_triggered_webhooks_view.rb → 000040_create_latest_triggered_webhooks_view.rb} +0 -0
  44. data/db/migrations/{41_migrate_execution_data.rb → 000041_migrate_execution_data.rb} +0 -0
  45. data/db/migrations/{42_delete_orphan_webhook_data.rb → 000042_delete_orphan_webhook_data.rb} +0 -0
  46. data/db/migrations/{43_add_provider_version_to_verification.rb → 000043_add_provider_version_to_verification.rb} +0 -0
  47. data/db/migrations/{44_populate_verifications_provider_version_id.rb → 000044_populate_verifications_provider_version_id.rb} +0 -0
  48. data/db/migrations/{45_set_verification_provider_number_nullable.rb → 000045_set_verification_provider_number_nullable.rb} +0 -0
  49. data/db/migrations/{46_recreate_latest_verifications.rb → 000046_recreate_latest_verifications.rb} +0 -0
  50. data/db/migrations/{47_create_all_verifications.rb → 000047_create_all_verifications.rb} +4 -0
  51. data/db/pact_broker_database.sqlite3 +0 -0
  52. data/db/test/backwards_compatibility/Appraisals +8 -0
  53. data/db/test/backwards_compatibility/Rakefile +23 -6
  54. data/db/test/backwards_compatibility/gemfiles/1.18.0.gemfile.lock +20 -19
  55. data/db/test/backwards_compatibility/gemfiles/2.0.0.gemfile.lock +20 -19
  56. data/db/test/backwards_compatibility/gemfiles/2.1.0.gemfile.lock +20 -19
  57. data/db/test/backwards_compatibility/gemfiles/2.2.0.gemfile.lock +29 -26
  58. data/db/test/backwards_compatibility/gemfiles/2.3.0.gemfile.lock +29 -26
  59. data/db/test/backwards_compatibility/gemfiles/2.4.2.gemfile.lock +29 -26
  60. data/db/test/backwards_compatibility/gemfiles/2.5.1.gemfile +13 -0
  61. data/db/test/backwards_compatibility/gemfiles/2.5.1.gemfile.lock +199 -0
  62. data/db/test/backwards_compatibility/gemfiles/2.6.0.gemfile +13 -0
  63. data/db/test/backwards_compatibility/gemfiles/2.6.0.gemfile.lock +199 -0
  64. data/db/test/backwards_compatibility/gemfiles/head.gemfile.lock +30 -27
  65. data/db/test/backwards_compatibility/spec/publish_pact_spec.rb +1 -1
  66. data/db/test/change_migration_strategy/Rakefile +21 -0
  67. data/db/test/change_migration_strategy/before/Gemfile +6 -0
  68. data/lib/pact_broker/api/decorators/matrix_decorator.rb +19 -1
  69. data/lib/pact_broker/api/decorators/matrix_text_decorator.rb +29 -0
  70. data/lib/pact_broker/api/renderers/html_pact_renderer.rb +1 -1
  71. data/lib/pact_broker/api/resources/matrix.rb +21 -11
  72. data/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb +2 -2
  73. data/lib/pact_broker/app.rb +27 -2
  74. data/lib/pact_broker/db/migrate.rb +1 -1
  75. data/lib/pact_broker/db/version.rb +4 -5
  76. data/lib/pact_broker/db.rb +1 -1
  77. data/lib/pact_broker/domain/relationship.rb +4 -24
  78. data/lib/pact_broker/matrix/parse_query.rb +22 -0
  79. data/lib/pact_broker/matrix/repository.rb +57 -26
  80. data/lib/pact_broker/matrix/service.rb +23 -16
  81. data/lib/pact_broker/pacticipants/service.rb +5 -21
  82. data/lib/pact_broker/pacts/pact_publication.rb +0 -4
  83. data/lib/pact_broker/pacts/repository.rb +1 -1
  84. data/lib/pact_broker/tags/service.rb +1 -0
  85. data/lib/pact_broker/ui/controllers/matrix.rb +3 -2
  86. data/lib/pact_broker/ui/controllers/relationships.rb +2 -2
  87. data/lib/pact_broker/ui/view_models/matrix_line.rb +38 -5
  88. data/lib/pact_broker/ui/view_models/relationship.rb +1 -19
  89. data/lib/pact_broker/ui/views/matrix/show.haml +18 -3
  90. data/lib/pact_broker/ui/views/relationships/show.haml +2 -2
  91. data/lib/pact_broker/verifications/repository.rb +0 -3
  92. data/lib/pact_broker/version.rb +1 -1
  93. data/lib/rack/hal_browser/redirect.rb +2 -2
  94. data/lib/rack/pact_broker/configurable_make_it_later.rb +24 -0
  95. data/lib/rack/pact_broker/no_auth.rb +13 -0
  96. data/pact_broker.gemspec +1 -0
  97. data/script/seed-matrix.rb +71 -0
  98. data/script/seed.rb +0 -5
  99. data/spec/features/get_matrix_spec.rb +4 -1
  100. data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +41 -7
  101. data/spec/lib/pact_broker/api/resources/matrix_spec.rb +6 -2
  102. data/spec/lib/pact_broker/app_spec.rb +69 -0
  103. data/spec/lib/pact_broker/domain/relationship_spec.rb +1 -1
  104. data/spec/lib/pact_broker/matrix/parse_query_spec.rb +79 -0
  105. data/spec/lib/pact_broker/matrix/repository_spec.rb +244 -12
  106. data/spec/lib/pact_broker/matrix/service_spec.rb +39 -9
  107. data/spec/lib/pact_broker/pacticipants/service_spec.rb +4 -78
  108. data/spec/lib/pact_broker/pacts/repository_spec.rb +14 -16
  109. data/spec/lib/pact_broker/ui/view_models/relationship_spec.rb +5 -4
  110. data/spec/migrations/change_migration_strategy_spec.rb +86 -0
  111. data/spec/service_consumers/provider_states_for_pact_broker_client.rb +34 -0
  112. data/spec/support/test_data_builder.rb +6 -0
  113. data/tasks/database.rb +1 -1
  114. metadata +78 -52
  115. data/lib/pact_broker/ui/views/relationships/show-prod-tags.haml +0 -83
  116. data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +0 -35
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ raise "Please supply database path" unless ARGV[0]
4
+
5
+ $LOAD_PATH.unshift './lib'
6
+ $LOAD_PATH.unshift './spec'
7
+ ENV['RACK_ENV'] = 'development'
8
+ require 'sequel'
9
+ require 'logger'
10
+ DATABASE_CREDENTIALS = {logger: Logger.new($stdout), adapter: "sqlite", database: ARGV[0], :encoding => 'utf8'}
11
+ connection = Sequel.connect(DATABASE_CREDENTIALS)
12
+ connection.timezone = :utc
13
+ require 'pact_broker/db'
14
+ PactBroker::DB.connection = connection
15
+ require 'pact_broker'
16
+ require 'support/test_data_builder'
17
+
18
+
19
+ tables_to_clean = [:labels, :webhook_executions, :triggered_webhooks, :verifications, :pact_publications, :pact_versions, :pacts, :pact_version_contents, :tags, :versions, :webhook_headers, :webhooks, :pacticipants]
20
+
21
+ tables_to_clean.each do | table_name |
22
+ connection[table_name].delete if connection.table_exists?(table_name)
23
+ end
24
+
25
+ =begin
26
+
27
+ A -> B -> C
28
+
29
+ 1 s 1 f 1
30
+
31
+ 2 s 2
32
+
33
+ =end
34
+
35
+ # TestDataBuilder.new.create_pact_with_hierarchy("A", "1.2.3", "B")
36
+ # .use_provider("B")
37
+ # .create_version("2.0.0")
38
+ # .create_provider("C")
39
+ # .create_version("3.0.0")
40
+ # .create_pact
41
+
42
+ TestDataBuilder.new
43
+ .create_pact_with_hierarchy("A", "1", "B")
44
+ .create_verification(provider_version: '1', success: false)
45
+ .create_verification(provider_version: '2', number: 2)
46
+ .create_verification(provider_version: '4', number: 3)
47
+ .create_provider_version("5")
48
+ .use_consumer("B")
49
+ .use_consumer_version("1")
50
+ .create_provider("C")
51
+ .create_pact
52
+ .create_verification(provider_version: '1', success: false)
53
+ .use_consumer_version("2")
54
+ .create_pact
55
+ .create_verification(provider_version: '2', success: true)
56
+ .create_consumer_version("3")
57
+ .create_pact
58
+ .create_pact_with_hierarchy("the-example-application", "391c43cae8c0e83c570c191f7324fccd67e53abc", "another-example-application")
59
+ .create_verification(provider_version: '391c43cae8c0e83c570c191f7324fccd67e53abc')
60
+ .create_verification(provider_version: '57fa24e44efc4d8aa42bb855a8217f145b5b1b5b', number: 2, success: false)
61
+ .create_verification(provider_version: '4', number: 3)
62
+ .use_consumer("another-example-application")
63
+ .use_consumer_version("391c43cae8c0e83c570c191f7324fccd67e53abc")
64
+ .create_provider("a-third-example-application")
65
+ .create_pact
66
+ .create_verification(provider_version: '391c43cae8c0e83c570c191f7324fccd67e53abc', success: false)
67
+ .use_consumer_version("57fa24e44efc4d8aa42bb855a8217f145b5b1b5b")
68
+ .create_pact
69
+ .create_verification(provider_version: '57fa24e44efc4d8aa42bb855a8217f145b5b1b5b', success: true)
70
+
71
+
data/script/seed.rb CHANGED
@@ -59,12 +59,9 @@ TestDataBuilder.new
59
59
  .create_verification(provider_version: "1.4.234", success: true, execution_date: DateTime.now - 15)
60
60
  .revise_pact
61
61
  .create_consumer_version("1.2.101")
62
- .create_consumer_version_tag('prod')
63
62
  .publish_pact
64
- .create_verification(provider_version: "9.9.10", success: false, execution_date: DateTime.now - 15)
65
63
  .create_consumer_version("1.2.102")
66
64
  .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
65
  .create_provider("Animals")
69
66
  .create_webhook(method: 'GET', url: 'http://localhost:9393/')
70
67
  .publish_pact(created_at: (Time.now - 140).to_datetime)
@@ -79,8 +76,6 @@ TestDataBuilder.new
79
76
  .create_provider("The back end")
80
77
  .create_webhook(method: 'GET', url: 'http://localhost:9393/')
81
78
  .create_consumer_version("1.2.106")
82
- .create_consumer_version_tag("production")
83
- .create_consumer_version_tag("feat-x")
84
79
  .publish_pact
85
80
  .create_consumer("Some other app")
86
81
  .create_provider("A service")
@@ -10,7 +10,10 @@ describe "Get matrix for consumer and provider" do
10
10
  let(:path) { "/matrix" }
11
11
  let(:params) do
12
12
  {
13
- selectors: ['Consumer/version/1.0.0','Provider/version/4.5.6']
13
+ q: [
14
+ { pacticipant: 'Consumer', version: '1.0.0' },
15
+ { pacticipant: 'Provider', version: '4.5.6' }
16
+ ]
14
17
  }
15
18
  end
16
19
  let(:last_response_body) { JSON.parse(subject.body, symbolize_names: true) }
@@ -3,10 +3,12 @@ require 'pact_broker/api/decorators/matrix_decorator'
3
3
  module PactBroker
4
4
  module Api
5
5
  module Decorators
6
- describe MatrixPactDecorator do
6
+ describe MatrixDecorator do
7
7
  describe "to_json" do
8
8
  let(:verification_date) { DateTime.new(2017, 12, 31) }
9
9
  let(:pact_created_at) { DateTime.new(2017, 1, 1) }
10
+ let(:line_1_success) { true }
11
+ let(:line_2_success) { true }
10
12
  let(:line_1) do
11
13
  {
12
14
  consumer_name: "Consumer",
@@ -15,7 +17,7 @@ module PactBroker
15
17
  pact_created_at: pact_created_at,
16
18
  provider_version_number: "4.5.6",
17
19
  provider_name: "Provider",
18
- success: true,
20
+ success: line_1_success,
19
21
  number: 1,
20
22
  build_url: nil,
21
23
  verification_executed_at: verification_date
@@ -30,10 +32,10 @@ module PactBroker
30
32
  pact_created_at: pact_created_at,
31
33
  provider_version_number: nil,
32
34
  provider_name: "Provider",
33
- success: nil,
35
+ success: line_2_success,
34
36
  number: nil,
35
37
  build_url: nil,
36
- verification_executed_at: nil
38
+ verification_executed_at: verification_date
37
39
  }
38
40
  end
39
41
 
@@ -94,7 +96,7 @@ module PactBroker
94
96
  end
95
97
 
96
98
  let(:lines){ [line_1, line_2]}
97
- let(:json) { MatrixPactDecorator.new(lines).to_json(user_options: { base_url: 'http://example.org' }) }
99
+ let(:json) { MatrixDecorator.new(lines).to_json(user_options: { base_url: 'http://example.org' }) }
98
100
  let(:parsed_json) { JSON.parse(json, symbolize_names: true) }
99
101
 
100
102
  it "includes the consumer details" do
@@ -113,11 +115,19 @@ module PactBroker
113
115
  expect(parsed_json[:matrix][0][:pact]).to eq pact_hash
114
116
  end
115
117
 
118
+ it "includes a summary" do
119
+ expect(parsed_json[:summary][:deployable]).to eq true
120
+ expect(parsed_json[:summary][:reason]).to match /All verification results are published/
121
+ end
122
+
116
123
  context "when the pact has not been verified" do
117
- let(:verification_hash) do
118
- nil
124
+ before do
125
+ line_2[:success] = nil
126
+ line_2[:verification_executed_at] = nil
119
127
  end
120
128
 
129
+ let(:verification_hash) { nil }
130
+
121
131
  it "has empty provider details" do
122
132
  expect(parsed_json[:matrix][1][:provider]).to eq provider_hash.merge(version: nil)
123
133
  end
@@ -126,6 +136,30 @@ module PactBroker
126
136
  expect(parsed_json[:matrix][1][:verificationResult]).to eq verification_hash
127
137
  end
128
138
  end
139
+
140
+ context "when one or more successes are nil" do
141
+ let(:line_1_success) { nil }
142
+
143
+ it "has a deployable flag of nil" do
144
+ expect(parsed_json[:summary][:deployable]).to be nil
145
+ end
146
+
147
+ it "has an explanation" do
148
+ expect(parsed_json[:summary][:reason]).to match /Missing/
149
+ end
150
+ end
151
+
152
+ context "when one or more successes are false" do
153
+ let(:line_1_success) { false }
154
+
155
+ it "has a deployable flag of false" do
156
+ expect(parsed_json[:summary][:deployable]).to be false
157
+ end
158
+
159
+ it "has an explanation" do
160
+ expect(parsed_json[:summary][:reason]).to match /have failed/
161
+ end
162
+ end
129
163
  end
130
164
  end
131
165
  end
@@ -7,18 +7,22 @@ module PactBroker
7
7
  describe Matrix do
8
8
  before do
9
9
  allow(PactBroker::Matrix::Service).to receive(:validate_selectors).and_return(error_messages)
10
+ allow(PactBroker::Matrix::Service).to receive(:find).and_return([])
11
+ allow(PactBroker::Matrix::ParseQuery).to receive(:call).and_return([selectors, options])
10
12
  end
11
13
 
12
14
  let(:td) { TestDataBuilder.new }
13
15
  let(:path) { "/matrix" }
14
16
  let(:json_response_body) { JSON.parse(subject.body, symbolize_names: true) }
15
- let(:params) { { selectors: ['Foo/version/1', 'Bar/version/2'] } }
17
+ let(:params) { {q: [{pacticipant: 'Foo', version: '1'}, {pacticipant: 'Bar', version: '2'}]} }
16
18
  let(:error_messages) { [] }
19
+ let(:selectors) { double('selectors') }
20
+ let(:options) { double('options') }
17
21
 
18
22
  subject { get path, params, {'Content-Type' => 'application/hal+json'}; last_response }
19
23
 
20
24
  it "validates the selectors" do
21
- expect(PactBroker::Matrix::Service).to receive(:validate_selectors).with(['Foo/version/1', 'Bar/version/2'])
25
+ expect(PactBroker::Matrix::Service).to receive(:validate_selectors).with(selectors)
22
26
  subject
23
27
  end
24
28
 
@@ -65,6 +65,75 @@ module PactBroker
65
65
  end
66
66
  end
67
67
 
68
+ describe "use_xxx_auth" do
69
+ class TestAuth
70
+ def initialize app, *args, &block
71
+ @app = Rack::Auth::Basic.new(app, "Protected") do | username, password |
72
+ username == 'foo' && password == 'bar'
73
+ end
74
+ end
75
+
76
+ def call(env)
77
+ @app.call(env)
78
+ end
79
+ end
80
+
81
+ describe "use_api_auth" do
82
+ it "allows the API to be protected" do
83
+ app.use_api_auth TestAuth
84
+
85
+ basic_authorize 'foo', 'bar'
86
+ get "/"
87
+ expect(last_response.status).to eq 200
88
+
89
+ basic_authorize 'foo', 'wrong'
90
+ get "/"
91
+ expect(last_response.status).to eq 401
92
+ expect(last_response.headers["WWW-Authenticate"]).to eq "Basic realm=\"Protected\""
93
+ end
94
+ end
95
+
96
+ describe "use_ui_auth" do
97
+ it "allows the UI to be protected" do
98
+ app.use_ui_auth TestAuth
99
+
100
+ basic_authorize 'foo', 'bar'
101
+ get "/", nil, {'HTTP_ACCEPT' => 'text/html'}
102
+ expect(last_response.status).to eq 200
103
+
104
+ basic_authorize 'foo', 'wrong'
105
+ get "/", nil, {'HTTP_ACCEPT' => 'text/html'}
106
+ expect(last_response.status).to eq 401
107
+ expect(last_response.headers["WWW-Authenticate"]).to eq "Basic realm=\"Protected\""
108
+ end
109
+ end
110
+
111
+ context "ordering of calls" do
112
+ class TestAuth1
113
+ def initialize app; end
114
+ def call env; end
115
+ end
116
+
117
+ class TestAuth2 < TestAuth1; end
118
+
119
+ before do
120
+ allow(TestAuth1).to receive(:new).and_return(test_auth_1)
121
+ allow(TestAuth2).to receive(:new).and_return(test_auth_2)
122
+ end
123
+
124
+ let(:test_auth_1) { instance_double('TestAuth1', call: [404, {}, []]) }
125
+ let(:test_auth_2) { instance_double('TestAuth2', call: [404, {}, []]) }
126
+
127
+ it "calls the UI auth before the API auth" do
128
+ expect(test_auth_1).to receive(:call).ordered
129
+ expect(test_auth_2).to receive(:call).ordered
130
+ app.use_ui_auth TestAuth1
131
+ app.use_api_auth TestAuth2
132
+ get "/", nil, {'HTTP_ACCEPT' => 'text/html'}
133
+ end
134
+ end
135
+ end
136
+
68
137
  describe "authenticate" do
69
138
  before do
70
139
  PactBroker.configuration.authenticate do | resource, authorization_header, options |
@@ -13,7 +13,7 @@ module PactBroker
13
13
  allow(webhook_executions).to receive(:sort).and_return(webhook_executions)
14
14
  end
15
15
 
16
- subject { Relationship.create(nil, nil, nil, true, nil, [], webhook_executions) }
16
+ subject { Relationship.create(nil, nil, nil, nil, [], webhook_executions) }
17
17
 
18
18
  it "returns the created_at date of the last execution" do
19
19
  expect(subject.last_webhook_execution_date).to eq DateTime.new(2015)
@@ -0,0 +1,79 @@
1
+ require 'pact_broker/matrix/parse_query'
2
+
3
+ module PactBroker
4
+ module Matrix
5
+ describe ParseQuery do
6
+ describe ".call" do
7
+ let(:query) { "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=9.9.9" }
8
+
9
+ subject { ParseQuery.call(query) }
10
+
11
+ it "extracts the pacticipant names and respective versions" do
12
+ expect(subject.first).to eq([{ pacticipant_name: "Foo", pacticipant_version_number: "1.2.3" }, { pacticipant_name: "Bar", pacticipant_version_number: "9.9.9" }])
13
+ end
14
+
15
+ context "with spaces" do
16
+ let(:query) { "q[][pacticipant]=Name%20With%20Spaces&q[][version]=1%202" }
17
+
18
+ it "works" do
19
+ expect(subject.first).to eq [{pacticipant_name: "Name With Spaces", pacticipant_version_number: "1 2"}]
20
+ end
21
+ end
22
+
23
+ context "with no q" do
24
+ let(:query) { "foo" }
25
+
26
+ it "returns an empty hash" do
27
+ expect(subject.first).to eq([])
28
+ end
29
+ end
30
+
31
+ context "with an incorrect param names" do
32
+ let(:query) { "q[][wrong]=Foo&q[][blah]=1.2.3" }
33
+
34
+ it "returns nil keys or values" do
35
+ expect(subject.first).to eq [{ pacticipant_name: nil, pacticipant_version_number: nil }]
36
+ end
37
+ end
38
+
39
+ context "with no options specified" do
40
+ let(:query) { "" }
41
+
42
+ it "does not set any options" do
43
+ expect(subject.last).to eq({})
44
+ end
45
+ end
46
+
47
+ context "with just one status specified" do
48
+ let(:query) { "success=true" }
49
+ it "extracts the one status" do
50
+ expect(subject.last).to eq success: [true]
51
+ end
52
+ end
53
+
54
+ context "with an array of statuses" do
55
+ let(:query) { "success[]=true&success[]=false&success[]=" }
56
+ it "extracts the statuses" do
57
+ expect(subject.last).to eq success: [true, false, nil]
58
+ end
59
+ end
60
+
61
+ context "with success[]=" do
62
+ let(:query) { "success[]=&foo=bar" }
63
+
64
+ it "sets an array with a nil success" do
65
+ expect(subject.last).to eq(success: [nil])
66
+ end
67
+ end
68
+
69
+ context "with success=" do
70
+ let(:query) { "success=&foo=bar" }
71
+
72
+ it "sets an array with a nil success" do
73
+ expect(subject.last).to eq(success: [nil])
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end