pact_broker 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/CHANGELOG.md +16 -2
  2. data/Gemfile.lock +12 -21
  3. data/config.ru +2 -1
  4. data/db/migrations/05_add_order_column_to_version.rb +7 -0
  5. data/db/pact_broker_database.sqlite3 +0 -0
  6. data/lib/pact_broker/api.rb +23 -11
  7. data/lib/pact_broker/api/representors.rb +4 -1
  8. data/lib/pact_broker/api/representors/pact_broker_urls.rb +8 -0
  9. data/lib/pact_broker/api/representors/pact_collection_representor.rb +34 -0
  10. data/lib/pact_broker/api/representors/pact_pacticipant_representor.rb +27 -0
  11. data/lib/pact_broker/api/representors/pact_representor.rb +27 -0
  12. data/lib/pact_broker/api/representors/pacticipant_collection_representor.rb +20 -0
  13. data/lib/pact_broker/api/representors/pacticipant_empty_collection_representor.rb +33 -0
  14. data/lib/pact_broker/api/representors/representable_pact.rb +19 -0
  15. data/lib/pact_broker/api/representors/version_representor.rb +1 -0
  16. data/lib/pact_broker/models/order_versions.rb +33 -0
  17. data/lib/pact_broker/models/pact.rb +7 -2
  18. data/lib/pact_broker/models/pacticipant.rb +3 -1
  19. data/lib/pact_broker/models/version.rb +7 -1
  20. data/lib/pact_broker/repositories/pact_repository.rb +26 -5
  21. data/lib/pact_broker/resources/json_resource.rb +37 -0
  22. data/lib/pact_broker/resources/latest_pact.rb +41 -0
  23. data/lib/pact_broker/resources/latest_pacts.rb +49 -0
  24. data/lib/pact_broker/resources/pact.rb +49 -0
  25. data/lib/pact_broker/resources/pacticipant.rb +80 -0
  26. data/lib/pact_broker/resources/pacticipants.rb +41 -0
  27. data/lib/pact_broker/services/pact_service.rb +11 -9
  28. data/lib/pact_broker/version.rb +1 -1
  29. data/pact_broker.gemspec +2 -3
  30. data/spec/lib/pact_broker/api/representors/pact_collection_representor_spec.rb +23 -0
  31. data/spec/lib/pact_broker/api/representors/representable_pact_spec.rb +29 -0
  32. data/spec/lib/pact_broker/models/order_versions_spec.rb +23 -0
  33. data/spec/lib/pact_broker/repositories/pact_repository_spec.rb +39 -0
  34. data/spec/service_consumers/pact_helper.rb +2 -19
  35. data/spec/service_consumers/provider_states_for_pact_broker_client.rb +1 -48
  36. data/spec/spec_helper.rb +19 -0
  37. data/spec/support/provider_state_builder.rb +91 -0
  38. metadata +32 -29
  39. data/lib/pact_broker/api/base_api.rb +0 -40
  40. data/lib/pact_broker/api/index_api.rb +0 -23
  41. data/lib/pact_broker/api/pact_api.rb +0 -33
  42. data/lib/pact_broker/api/pacticipant_api.rb +0 -54
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@ Do this to generate your change history
2
2
 
3
3
  $ git log --date=relative --pretty=format:' * %h - %s (%an, %ad)' 'package/pact-broker-0.0.PRODVERSION'..'package/pact-broker-0.0.NEWVERSION'
4
4
 
5
- #### 0.0.NEWVERSION (YYYY-MM-DD HH:00)
5
+ #### 0.0.5 (2013-11-13)
6
6
 
7
- * Your changes go here
7
+ * 2cf987c - Added data migration to script which adds order column (Beth, 56 minutes ago)
8
+ * 9c709a9 - Changing queries to use new order column. (Beth, 61 minutes ago)
9
+ * 173f231 - Renaming var (Beth, 65 minutes ago)
10
+ * f9be93d - Renamed SortVersions to OrderVersions (Beth, 66 minutes ago)
11
+ * ca6e479 - Added SortVersions as an after version save hook (Beth, 69 minutes ago)
12
+ * 23cd1a3 - Adding order column to version table (Beth, 11 hours ago)
13
+ * c504e5f - Fixing application/json+hal to application/hal+json (Beth, 2 days ago)
14
+ * 1d24b9b - Removing old sinatra API (Beth, 2 days ago)
15
+ * fd1832c - WIP. Converting to use Webmachine (Beth, 2 days ago)
16
+ * 0b096a4 - Redoing the the URLs yet again (Beth, 3 days ago)
17
+ * 0934d89 - Implementing list latest pacts (Beth, 3 days ago)
18
+ * ed2d354 - Changed one_to_one associations to many_to_one (Beth, 4 days ago)
19
+ * 28de0ea - WIP implementing pacts/latest. (Beth, 6 days ago)
20
+ * 1cd36e6 - Changing to new /pacts/latest URL format (Beth, 6 days ago)
21
+ * 54f8fc3 - Writing underlying code to find the latest pact for each consumer/provider pair. (Beth, 6 days ago)
data/Gemfile.lock CHANGED
@@ -1,21 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pact_broker (0.0.4)
4
+ pact_broker (0.0.5)
5
5
  httparty
6
6
  json
7
7
  roar
8
8
  sequel
9
- sinatra
10
- sinatra-contrib
11
- sinatra-param
12
9
  sqlite3
10
+ versionomy
11
+ webmachine
13
12
 
14
13
  GEM
15
14
  remote: https://rubygems.org/
16
15
  specs:
16
+ as-notifications (1.0.1)
17
17
  awesome_print (1.1.0)
18
- backports (3.3.5)
18
+ blockenspiel (0.4.5)
19
19
  builder (3.2.2)
20
20
  ci_reporter (1.9.0)
21
21
  builder (>= 2.1.2)
@@ -35,6 +35,7 @@ GEM
35
35
  httparty (0.12.0)
36
36
  json (~> 1.8)
37
37
  multi_xml (>= 0.5.2)
38
+ i18n (0.6.5)
38
39
  json (1.8.1)
39
40
  method_source (0.8.2)
40
41
  mini_portile (0.5.2)
@@ -56,8 +57,6 @@ GEM
56
57
  method_source (~> 0.8)
57
58
  slop (~> 3.4)
58
59
  rack (1.5.2)
59
- rack-protection (1.5.1)
60
- rack
61
60
  rack-test (0.6.2)
62
61
  rack (>= 1.0)
63
62
  rake (10.0.4)
@@ -84,19 +83,6 @@ GEM
84
83
  multi_json (~> 1.0)
85
84
  simplecov-html (~> 0.7.1)
86
85
  simplecov-html (0.7.1)
87
- sinatra (1.4.4)
88
- rack (~> 1.4)
89
- rack-protection (~> 1.4)
90
- tilt (~> 1.3, >= 1.3.4)
91
- sinatra-contrib (1.4.1)
92
- backports (>= 2.0)
93
- multi_json
94
- rack-protection
95
- rack-test
96
- sinatra (~> 1.4.0)
97
- tilt (~> 1.3)
98
- sinatra-param (1.0.0)
99
- sinatra (~> 1.3)
100
86
  slop (3.4.6)
101
87
  sqlite3 (1.3.8)
102
88
  thin (1.6.1)
@@ -104,7 +90,12 @@ GEM
104
90
  eventmachine (>= 1.0.0)
105
91
  rack (>= 1.0.0)
106
92
  thor (0.18.1)
107
- tilt (1.4.1)
93
+ versionomy (0.4.4)
94
+ blockenspiel (>= 0.4.5)
95
+ webmachine (1.2.1)
96
+ as-notifications (~> 1.0)
97
+ i18n (>= 0.4.0)
98
+ multi_json
108
99
 
109
100
  PLATFORMS
110
101
  ruby
data/config.ru CHANGED
@@ -1,10 +1,11 @@
1
1
  require File.dirname(__FILE__) + '/config/boot'
2
2
  require 'pact_broker/db'
3
3
  require 'pact_broker/api'
4
+ require 'pact_broker/resources/pact'
4
5
 
5
6
 
6
7
  use Rack::Static, root: 'public', urls: ['/favicon.ico']
7
8
 
8
9
  run Rack::URLMap.new(
9
- '/' => PactBroker::API,
10
+ '/' => PactBroker::API
10
11
  )
@@ -0,0 +1,7 @@
1
+ Sequel.migration do
2
+ change do
3
+ add_column(:versions, :order, Integer)
4
+ self[:versions].update(:order => :id)
5
+ end
6
+ end
7
+
Binary file
@@ -1,18 +1,30 @@
1
- require 'sinatra'
1
+ require 'pact_broker/resources/pact'
2
+ require 'pact_broker/resources/latest_pact'
3
+ require 'pact_broker/resources/latest_pacts'
4
+ require 'pact_broker/resources/pacticipant'
5
+ require 'pact_broker/resources/pacticipants'
2
6
 
3
- require_relative 'api/index_api'
4
- require_relative 'api/pacticipant_api'
5
- require_relative 'api/pact_api'
7
+ require 'webmachine/adapters/rack'
6
8
 
7
9
  module PactBroker
8
- class API < Sinatra::Base
9
- # content_type :json, 'application/json'
10
- # content_type :xml, 'text/xml'
11
- # default_format :json
12
10
 
13
- use Api::IndexApi
14
- use Api::PacticipantApi
15
- use Api::PactApi
11
+ API ||= begin
12
+ pact_api = Webmachine::Application.new do |app|
13
+ app.routes do
14
+ add(['trace', '*'], Webmachine::Trace::TraceResource) unless ENV['RACK_ENV'] == 'production'
15
+ add ['pact', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number], Resources::Pact
16
+ add ['pact', 'provider', :provider_name, 'consumer', :consumer_name, 'latest'], Resources::LatestPact
17
+ add ['pacts', 'latest'], Resources::LatestPacts
18
+ add ['pacticipants'], Resources::Pacticipants
19
+ add ['pacticipants', :name], Resources::Pacticipant
20
+ end
21
+ end
16
22
 
23
+ pact_api.configure do |config|
24
+ config.adapter = :Rack
25
+ end
26
+
27
+ pact_api.adapter
17
28
  end
29
+
18
30
  end
@@ -1,3 +1,6 @@
1
1
  require 'pact_broker/api/representors/pacticipant_representor'
2
2
  require 'pact_broker/api/representors/pacticipant_collection_representor'
3
- require 'pact_broker/api/representors/version_representor'
3
+ require 'pact_broker/api/representors/version_representor'
4
+ require 'pact_broker/api/representors/pact_collection_representor'
5
+ require 'pact_broker/api/representors/pact_pacticipant_representor'
6
+ require 'pact_broker/api/representors/pact_representor'
@@ -26,6 +26,14 @@ module PactBroker
26
26
  "#{pacticipant_url(version.pacticipant)}/versions/#{version.number}"
27
27
  end
28
28
 
29
+ def pact_url pact
30
+ "#{version_url(pact.consumer_version)}/pacts/#{url_encode(pact.provider.name)}"
31
+ end
32
+
33
+ def latest_pacts_url
34
+ "#{base_url}/pacts/latest"
35
+ end
36
+
29
37
  def url_encode param
30
38
  ERB::Util.url_encode param
31
39
  end
@@ -0,0 +1,34 @@
1
+ require 'roar/representer/json/hal'
2
+ require_relative 'pact_broker_urls'
3
+ require_relative 'version_representor'
4
+ require_relative 'pact_representor'
5
+
6
+ module PactBroker
7
+
8
+ module Api
9
+
10
+ module Representors
11
+
12
+ module PactCollectionRepresenter
13
+ include Roar::Representer::JSON::HAL
14
+ include PactBroker::Api::PactBrokerUrls
15
+
16
+
17
+ collection :pacts, :class => PactBroker::Models::Pact, :extend => PactBroker::Api::Representors::PactRepresenter
18
+
19
+ def pacts
20
+ self
21
+ end
22
+
23
+ link :self do
24
+ latest_pacts_url
25
+ end
26
+
27
+ links :pacts do
28
+ collect{ | pact | {:href => pact_url(pact) } }
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,27 @@
1
+ require 'roar/representer/json/hal'
2
+ require_relative 'pact_broker_urls'
3
+ require_relative 'version_representor'
4
+
5
+ module PactBroker
6
+
7
+ module Api
8
+
9
+ module Representors
10
+
11
+ module PactPacticipantRepresenter
12
+ include Roar::Representer::JSON::HAL
13
+ include Roar::Representer::JSON::HAL::Links
14
+ include PactBroker::Api::PactBrokerUrls
15
+
16
+ property :name
17
+ property :repository_url
18
+ property :version, :class => "PactBroker::Models::Version", :extend => PactBroker::Api::Representors::VersionRepresenter, :embedded => true
19
+
20
+ link :self do
21
+ pacticipant_url(self)
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'roar/representer/json/hal'
2
+ require_relative 'pact_broker_urls'
3
+ require_relative 'pact_pacticipant_representor'
4
+
5
+ module PactBroker
6
+
7
+ module Api
8
+
9
+ module Representors
10
+
11
+ module PactRepresenter
12
+ include Roar::Representer::JSON::HAL
13
+ include Roar::Representer::JSON::HAL::Links
14
+ include PactBroker::Api::PactBrokerUrls
15
+
16
+
17
+ property :consumer, :extend => PactBroker::Api::Representors::PactPacticipantRepresenter, :embedded => true
18
+ property :provider, :extend => PactBroker::Api::Representors::PactPacticipantRepresenter, :embedded => true
19
+
20
+ link :self do
21
+ pact_url(self)
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -2,6 +2,26 @@ require 'roar/representer/json/hal'
2
2
  require_relative 'pact_broker_urls'
3
3
  require_relative 'version_representor'
4
4
 
5
+ module Roar
6
+ module Representer
7
+ module Feature
8
+
9
+ module Hypermedia
10
+
11
+ #Monkey patch alert! Get "no method rel for Nil" when there is an empty array
12
+ #in links. Cannot reproduce this in the roar tests :(
13
+ alias_method :original_compile_links_for, :compile_links_for
14
+
15
+ def compile_links_for configs, *args
16
+ original_compile_links_for(configs, *args).select(&:any?)
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+
5
25
  module PactBroker
6
26
 
7
27
  module Api
@@ -0,0 +1,33 @@
1
+ require 'roar/representer/json/hal'
2
+ require_relative 'pact_broker_urls'
3
+ require_relative 'version_representor'
4
+
5
+ module PactBroker
6
+
7
+ module Api
8
+
9
+ module Representors
10
+
11
+ module PacticipantCollectionRepresenter
12
+ include Roar::Representer::JSON::HAL
13
+ include PactBroker::Api::PactBrokerUrls
14
+
15
+
16
+ collection :pacticipants, :class => PactBroker::Models::Pacticipant, :extend => PactBroker::Api::Representors::PacticipantRepresenter
17
+
18
+ def pacticipants
19
+ self
20
+ end
21
+
22
+ link :self do
23
+ pacticipants_url
24
+ end
25
+
26
+ links :pacticipants do
27
+ collect{ | pacticipant | {:href => pacticipant_url(pacticipant), :name => pacticipant.name } }
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ require 'ostruct'
2
+
3
+ module PactBroker
4
+ module Api
5
+ module Representors
6
+ class RepresentablePact
7
+
8
+ attr_reader :consumer, :provider, :consumer_version
9
+
10
+ def initialize pact
11
+ @consumer_version = pact.consumer_version
12
+ @consumer = OpenStruct.new(:version => @consumer_version, :name => pact.consumer.name)
13
+ @provider = OpenStruct.new(:version => nil, :name => pact.provider.name)
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -8,6 +8,7 @@ module PactBroker
8
8
  include Roar::Representer::JSON::HAL
9
9
  include Roar::Representer::JSON::HAL::Links
10
10
  include PactBroker::Api::PactBrokerUrls
11
+
11
12
  property :number
12
13
 
13
14
  link :self do
@@ -0,0 +1,33 @@
1
+ require 'versionomy'
2
+
3
+ module PactBroker
4
+ module Models
5
+ class OrderVersions
6
+
7
+ def self.call pacticipant_id
8
+ orderable_versions = PactBroker::Models::Version.where(:pacticipant_id => pacticipant_id).all.collect{| version | OrderableVersion.new(version) }
9
+ orderable_versions.sort.each_with_index{ | version, i | version.update_model(i) }
10
+ end
11
+
12
+ class OrderableVersion
13
+
14
+ attr_accessor :version_model, :sortable_number
15
+
16
+ def initialize version_model
17
+ @version_model = version_model
18
+ @sortable_number = Versionomy.parse(version_model.number)
19
+ end
20
+
21
+ def <=> other
22
+ self.sortable_number <=> other.sortable_number
23
+ end
24
+
25
+ def update_model new_order
26
+ # Sequel will only run the update if the column value has changed, so in 99% of
27
+ # cases, only one update will occur.
28
+ version_model.update(:order => new_order)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -5,14 +5,19 @@ module PactBroker
5
5
  module Models
6
6
  class Pact < Sequel::Model
7
7
 
8
- associate(:one_to_one, :provider, :class => "PactBroker::Models::Pacticipant", :key => :id, :primary_key => :provider_id)
9
- associate(:one_to_one, :consumer_version, :class => "PactBroker::Models::Version", :key => :id, :primary_key => :version_id)
8
+ set_primary_key :id
9
+ associate(:many_to_one, :provider, :class => "PactBroker::Models::Pacticipant", :key => :provider_id, :primary_key => :id)
10
+ associate(:many_to_one, :consumer_version, :class => "PactBroker::Models::Version", :key => :version_id, :primary_key => :id)
10
11
 
11
12
  #Need to work out how to do this properly!
12
13
  def consumer_version_number
13
14
  values[:consumer_version_number]
14
15
  end
15
16
 
17
+ def consumer
18
+ consumer_version.pacticipant
19
+ end
20
+
16
21
  def to_s
17
22
  "Pact: provider_id=#{provider_id}"
18
23
  end
@@ -6,7 +6,9 @@ module PactBroker
6
6
 
7
7
  class Pacticipant < Sequel::Model
8
8
 
9
- one_to_many :versions, :order => :id, :reciprocal => :pacticipant
9
+ set_primary_key :id
10
+
11
+ one_to_many :versions, :order => :order, :reciprocal => :pacticipant
10
12
  one_to_many :pacts
11
13
 
12
14
  def last_version