agile-proxy 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b0ac0c54c3b6fbb655ba9996eeb3a2d994be8e1
4
- data.tar.gz: 029090ba04333c73aabec281024e6a172e53d54f
3
+ metadata.gz: 74ae4ece459f7aec91a77ac5daefe1b1978de480
4
+ data.tar.gz: 1b1e68ecff0556340c41281a1f24faa3a6b75202
5
5
  SHA512:
6
- metadata.gz: 6393cc970654e874f2756aeca50474a8ad1e1b5118c0fa07d6520629c0610addddc87d2cbc3225c798008a9d7c8065f358a2abf96ba166c1e980597ede380f65
7
- data.tar.gz: d8b6e4455fca2fb1983a27c6864e97629819cbb07ba260df1465443429e5401fae127e6e360c9a6b67424e5ac61a09a9e9049799ec37cdfdc632a74ef8cec795
6
+ metadata.gz: e604574ae397091d8909ad20981f4d4a03dac2fbc28c7885fb588a071234f6b6ab5be27aef4750158f0857d522742cac69add078f09dc4c783b7e647460152bc
7
+ data.tar.gz: af0e99b04466f2c5120f552f8fa78e4753eae7273552fc4ca2d0a41cd8e5fd49e6c1f1686db4370c4b9989acb974d20d052228eeda12177c2089883292cab911
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- agile-proxy (0.1.10)
4
+ agile-proxy (0.1.11)
5
5
  activerecord (~> 4.1.6)
6
6
  em-http-request (~> 1.1.2)
7
7
  em-synchrony (~> 1.0.3)
data/bin/agile_proxy CHANGED
@@ -31,7 +31,7 @@ module AgileProxy
31
31
  end
32
32
 
33
33
  def environment
34
- ENV['AGILE_PROXY_ENV'] || Dir.pwd == File.expand_path('..', File.dirname(__FILE__)) ? 'development' : 'production'
34
+ ENV['AGILE_PROXY_ENV'] || (Dir.pwd == File.expand_path('..', File.dirname(__FILE__)) ? 'development' : 'production')
35
35
  end
36
36
  end
37
37
  package_name 'Http Flexible Proxy'
data/config.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  development:
2
2
  adapter: sqlite3
3
- database: 'db/development.db'
3
+ database: ':memory:'
4
4
  test:
5
5
  adapter: sqlite3
6
6
  database: 'db/test.db'
@@ -58,7 +58,7 @@ module AgileProxy
58
58
  delete do
59
59
  authenticate!
60
60
  scope = current_application.request_specs
61
- scope.delete_all
61
+ scope.destroy_all
62
62
  { request_specs: [], total: 0 }
63
63
  end
64
64
  desc 'Create a new request specification'
@@ -47,6 +47,13 @@ module AgileProxy
47
47
  end
48
48
 
49
49
  def add_to_router(request, headers, body, route_set)
50
+ # This needs a bit of explaining as the router did not quite behave as expected.
51
+ # This proc calls route definition methods such as get, post etc.. with the path and handler
52
+ # the handler being an inline proc.
53
+ # But, we also pass a constraints handler
54
+ # After constraints are handled though, the 'action_dispatch.request.parameters' are deleted
55
+ # from the env, so our handler preserves them in agile_proxy.parameters.
56
+ # A bit weird, but it works reliably.
50
57
  proc do |spec|
51
58
  path = URI.parse(spec.url).path
52
59
  path = '/' if path == ''
@@ -55,10 +62,16 @@ module AgileProxy
55
62
  route_spec = {
56
63
  path => proc do |router_env|
57
64
  AgileProxy.log(:info, "agile-proxy: STUB #{method} for '#{request.url}'")
58
- spec.call(router_env['action_dispatch.request.parameters'], headers, body)
65
+ spec.call(router_env['agile_proxy.parameters'], headers, body)
59
66
  end
60
67
  }
61
- route_spec[:constraints] = ActiveSupport::JSON.decode(spec.conditions).symbolize_keys unless spec.conditions.empty?
68
+ route_spec[:constraints] = ->(request) {
69
+ ret_value = spec.conditions_json.all? do |k, v|
70
+ request.params.key?(k) && request.params[k] == v
71
+ end
72
+ request.env['agile_proxy.parameters'] = request.env['action_dispatch.request.parameters']
73
+ ret_value
74
+ }
62
75
  route_set.send method, route_spec
63
76
  end
64
77
  end
@@ -29,7 +29,7 @@ module AgileProxy
29
29
  # This method returns a JSON decoded version of this as a HASH
30
30
  # @return [Hash] decoded conditions
31
31
  def conditions_json
32
- ActiveSupport::JSON.decode(conditions)
32
+ ActiveSupport::JSON.decode(conditions).with_indifferent_access
33
33
  end
34
34
  # This method's output is a 'rack' response, but its input is not.
35
35
  # When the router has determined that this request spec is the one that is going to be sent to the client,
@@ -2,5 +2,5 @@
2
2
  #
3
3
  # The Agile Proxy module is a common namespace for all classes / sub modules.
4
4
  module AgileProxy
5
- VERSION = '0.1.10'
5
+ VERSION = '0.1.11'
6
6
  end
@@ -43,6 +43,7 @@ module AgileProxy
43
43
  create_request_spec url: "#{url}/api/forums/:forum_id/:post_id", http_method: 'DELETE', response: { content_type: 'application/json', content: '{"deleted": true}' }
44
44
  create_request_spec url: "#{url}/api/forums/:forum_id/:post_id", conditions: '{"post_id": "special"}', response: { content_type: 'text/html', content: '<html><body><h1>Sorted By: {{sort}}</h1><h2>{{forum_id}}</h2><h3>{{post_id}}</h3><p>This is a special response</p></body></html>', is_template: true }
45
45
  create_request_spec url: "#{url}/api/forums/:forum_id/:post_id", conditions: '{"post_id": "special", "sort": "eversospecial"}', response: { content_type: 'text/html', content: '<html><body><h1>Sorted By: {{sort}}</h1><h2>{{forum_id}}</h2><h3>{{post_id}}</h3><p>This is an ever so special response</p></body></html>', is_template: true }
46
+ create_request_spec url: "#{url}/api/forums/:forum_id", http_method: 'POST',response: { content_type: 'text/html', content: '<html><body><h1></h1><h2>WRONG RESULT</h2><h3>{{forum_id}}</h3><p>This is an incorrect result probably because the conditions are being ignored ?</p></body></html>'}
46
47
  create_request_spec url: "#{url}/api/forums/:forum_id", http_method: 'POST', conditions: '{"posted_var":"special_value"}', response: { content_type: 'text/html', content: '<html><body><h1></h1><h2>{{posted_var}}</h2><h3>{{forum_id}}</h3><p>This should get data from the POSTed data</p></body></html>', is_template: true }
47
48
  create_request_spec url: "#{url}/api/forums/:forum_id/posts", response: { content_type: 'application/json', content: JSON.pretty_generate(posts: [
48
49
  { forum_id: '{{forum_id}}', subject: 'My first post' },
@@ -144,7 +144,7 @@ describe AgileProxy::Api::RequestSpecs, api_test: true do
144
144
  end
145
145
  describe 'DELETE /users/1/applications/1/request_specs' do
146
146
  before :each do
147
- expect(request_spec_assoc_class).to receive(:delete_all)
147
+ expect(request_spec_assoc_class).to receive(:destroy_all)
148
148
  end
149
149
  it 'Should delete all request specs for the users application' do
150
150
  delete '/v1/users/1/applications/1/request_specs'
@@ -31,18 +31,18 @@ describe AgileProxy::StubHandler do
31
31
 
32
32
  describe '#handle_request' do
33
33
  it 'returns 404 if the request is not stubbed' do
34
- stub = double('stub', http_method: 'GET', url: 'http://example.test:8080/index', conditions: {}, call: [404, {}, 'Not found'])
34
+ stub = double('stub', http_method: 'GET', url: 'http://example.test:8080/index', conditions_json: {}, call: [404, {}, 'Not found'])
35
35
  expect(request_spec_class).to receive(:where).and_return double('association', all: [stub])
36
36
  expect(handler.call(to_rack_env(url: 'http://example.test:8080/index'))).to eql [404, {}, 'Not found']
37
37
  end
38
38
 
39
39
  it 'returns a response hash if the request is stubbed' do
40
- stub = double('stub', http_method: 'GET', url: 'http://example.test:8080/index', conditions: {}, call: [200, { 'Content-Type' => 'application/json' }, 'Some content'])
40
+ stub = double('stub', http_method: 'GET', url: 'http://example.test:8080/index', conditions_json: {}, call: [200, { 'Content-Type' => 'application/json' }, 'Some content'])
41
41
  expect(request_spec_class).to receive(:where).and_return double('association', all: [stub])
42
42
  expect(handler.call(request.env)).to eql([200, { 'Content-Type' => 'application/json' }, 'Some content'])
43
43
  end
44
44
  it 'Passes on the correct parameters to the stub call method' do
45
- stub = double('stub', http_method: 'GET', url: 'http://example.test:8080/index', conditions: {})
45
+ stub = double('stub', http_method: 'GET', url: 'http://example.test:8080/index', conditions_json: {})
46
46
  expect(request_spec_class).to receive(:where).and_return double('association', all: [stub])
47
47
  body = request.body.read
48
48
  request.body.rewind
@@ -52,7 +52,7 @@ describe AgileProxy::StubHandler do
52
52
  end
53
53
  describe 'Routing patterns' do
54
54
  describe 'With a simple GET match on the root of a domain' do
55
- let(:request_stub) { double 'stub', url: 'http://example.com', http_method: 'GET', conditions: {} }
55
+ let(:request_stub) { double 'stub', url: 'http://example.com', http_method: 'GET', conditions_json: {} }
56
56
  before :each do
57
57
  allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://example.com%').and_return double('association', all: [request_stub])
58
58
  allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://subdomain.example.com%').and_return double('association', all: [])
@@ -67,7 +67,7 @@ describe AgileProxy::StubHandler do
67
67
 
68
68
  end
69
69
  describe 'With a simple GET match inside a domain' do
70
- let(:request_stub) { double 'stub for simple get inside a domain', url: 'http://example.com/index', http_method: 'GET', conditions: {} }
70
+ let(:request_stub) { double 'stub for simple get inside a domain', url: 'http://example.com/index', http_method: 'GET', conditions_json: {} }
71
71
  before :each do
72
72
  allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://example.com%').and_return double('association', all: [request_stub])
73
73
  allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://subdomain.example.com%').and_return double('association', all: [])
@@ -83,7 +83,7 @@ describe AgileProxy::StubHandler do
83
83
 
84
84
  end
85
85
  describe 'With a simple POST match on the root of a domain' do
86
- let(:request_stub) { double 'stub', url: 'http://example.com', http_method: 'POST', conditions: {} }
86
+ let(:request_stub) { double 'stub', url: 'http://example.com', http_method: 'POST', conditions_json: {} }
87
87
  before :each do
88
88
  allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://example.com%').and_return double('association', all: [request_stub])
89
89
  allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://subdomain.example.com%').and_return double('association', all: [])
@@ -98,7 +98,7 @@ describe AgileProxy::StubHandler do
98
98
 
99
99
  end
100
100
  describe 'With a more complex route with conditions inside a domain' do
101
- let(:request_stub) { double 'stub for complex route inside a domain', url: 'http://example.com/users/:user_id/index', http_method: 'GET', conditions: { user_id: '1' }.to_json }
101
+ let(:request_stub) { double 'stub for complex route inside a domain', url: 'http://example.com/users/:user_id/index', http_method: 'GET', conditions_json: { user_id: '1' } }
102
102
  before :each do
103
103
  allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://example.com%').and_return double('association', all: [request_stub])
104
104
  expect(request_stub).to receive(:call).and_return([200, {}, ''])
@@ -112,7 +112,7 @@ describe AgileProxy::StubHandler do
112
112
  end
113
113
  end
114
114
  describe 'With a more complex route with conditions including query params inside a domain' do
115
- let(:request_stub) { double 'stub for complex route inside a domain', url: 'http://example.com/users/:user_id/index', http_method: 'GET', conditions: { user_id: '1', extra_1: 'extra_1', extra_2: 'extra_2' }.to_json }
115
+ let(:request_stub) { double 'stub for complex route inside a domain', url: 'http://example.com/users/:user_id/index', http_method: 'GET', conditions_json: { user_id: '1', extra_1: 'extra_1', extra_2: 'extra_2' } }
116
116
  before :each do
117
117
  allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://example.com%').and_return double('association', all: [request_stub])
118
118
  allow(request_stub).to receive(:call).and_return([200, {}, ''])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agile-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Taylor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-09 00:00:00.000000000 Z
11
+ date: 2014-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake