agile-proxy 0.1.19 → 0.1.20

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: 806cb5ed2d0d286c13adb4d4ab3dc7bcad28917d
4
- data.tar.gz: ab62ffd2e6b2b11908314548d0598599619cd998
3
+ metadata.gz: 7faec1aa540783f6fe42b674e1aeea119a470b15
4
+ data.tar.gz: 1b01c98d23e6c95eb894601b4b05c3420a4219df
5
5
  SHA512:
6
- metadata.gz: 99266a1f6aab8c91a2fa1ae70bc7a357a3feb5193ef955da264e953827103a5c39f5b21929a54ff52dc5fd1ce8b80738bf6bdbb20899197bf56d2f9090d855fc
7
- data.tar.gz: a778c6e2c5b72bf83c714a5a951aad3d0d34a6f104f0b9e3f90fb78fbe9b34769356d15f4d1e9f5af46be7f4c0aa8d9cae123241c22002530cd9f7d2af194656
6
+ metadata.gz: 43f930138c348608ef2972536c2192c08716b4603a2bb9234108926da5d2d8e532a9618082a7a54b7f1212e5711d35eb79e0fcd455a31aa33dac3895ced35789
7
+ data.tar.gz: bfbdf55b64323489c085822e565f1a32f2f3447684142f36c9bf48de9e2a7a9ffc7379bf7b400450e5dafbfe4ce1b799225c4c0bb4754d92950ee3ceb56a574e
data/README.md CHANGED
@@ -121,4 +121,5 @@ v0.1.15 - 0.1.17 - No functionality change, these were just to try and please tr
121
121
  v0.1.18 - Fixed issue with integration test which was showing up now that travis is working again
122
122
  v0.1.19 - Recordings now record the request spec id.
123
123
  Recordings can now be accessed via /request_specs/:request_spec_id/recordings to provide recordings specific to the request spec
124
+ v0.1.20 - An individual request spec can now be set to 'record_requests' rather than requiring the whole application to be in record mode which slows down every request
124
125
 
@@ -0,0 +1,7 @@
1
+ class AddRecordRequestsToRequestSpecs < ActiveRecord::Migration
2
+ def change
3
+ change_table(:request_specs) do |t|
4
+ t.boolean :record_requests, default: false
5
+ end
6
+ end
7
+ end
@@ -22,7 +22,7 @@ module AgileProxy
22
22
  @permitted_params ||= declared(
23
23
  params,
24
24
  { include_missing: false },
25
- [:spec, :note, :response, :http_method, :url, :url_type, :conditions]
25
+ [:spec, :note, :response, :http_method, :url, :url_type, :conditions, :record_requests]
26
26
  )
27
27
  end
28
28
 
@@ -35,7 +35,8 @@ module AgileProxy
35
35
  "Connection to #{request.url}#{body} not stubbed and new http connections are disabled"
36
36
  ]
37
37
  end
38
- if application.record_requests
38
+ request_spec = env['agile_proxy.request_spec']
39
+ if application.record_requests || (request_spec && request_spec.record_requests)
39
40
  application.recordings.create request_headers: request.headers,
40
41
  request_body: body,
41
42
  request_url: request.url,
@@ -43,7 +44,7 @@ module AgileProxy
43
44
  response_headers: rack_response[1],
44
45
  response_body: rack_response[2],
45
46
  response_status: rack_response[0],
46
- request_spec_id: env['agile_proxy.request_spec_id']
47
+ request_spec_id: request_spec ? request_spec.id : nil
47
48
  end
48
49
  rack_response
49
50
  end
@@ -62,7 +62,7 @@ module AgileProxy
62
62
  route_spec = {
63
63
  path => proc do |router_env|
64
64
  AgileProxy.log(:info, "agile-proxy: STUB #{method} for '#{request.url}'")
65
- router_env['agile_proxy.request_spec_id'] = spec.id
65
+ router_env['agile_proxy.request_spec'] = spec
66
66
  spec.call(HashWithIndifferentAccess.new(router_env['action_dispatch.request.path_parameters'].merge(router_env['action_dispatch.request.query_parameters']).merge(router_env['action_dispatch.request.request_parameters'])), headers, body)
67
67
  end
68
68
  }
@@ -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.19'
5
+ VERSION = '0.1.20'
6
6
  end
@@ -57,6 +57,7 @@ module AgileProxy
57
57
  [@http_url, @https_url, @http_url_no_proxy, @https_url_no_proxy].each do |url|
58
58
  @stubs_with_recordings.push Spec.for url, 'index_old', create_request_spec(url: "#{url}/index.html", response: { content_type: 'text/html', content: '<html><body>This Is An Older Mock</body></html>' }) #This is intentional - the system should always use the latest
59
59
  @stubs_with_recordings.push Spec.for url, 'index', create_request_spec(url: "#{url}/index.html", response: { content_type: 'text/html', content: '<html><body>Mocked Content</body></html>' })
60
+ @stubs_with_recordings.push Spec.for url, 'index_recording', create_request_spec(url: "#{url}/indexRecording.html", response: { content_type: 'text/html', content: '<html><body>Mocked Content</body></html>' })
60
61
  @stubs_with_recordings.push Spec.for url, 'api_forums', create_request_spec(url: "#{url}/api/forums", response: { content_type: 'application/json', content: JSON.pretty_generate(forums: [], total: 0) })
61
62
  @stubs_with_recordings.push Spec.for url, 'api_forums_post', create_request_spec(url: "#{url}/api/forums", http_method: 'POST', response: { content_type: 'application/json', content: '{"created": true}' })
62
63
  @stubs_with_recordings.push Spec.for url, 'api_forum_post', create_request_spec(url: "#{url}/api/forums/:forum_id/:post_id", response: { content_type: 'text/html', content: '<html><body><h1>Sorted By: {{sort}}</h1><h2>{{forum_id}}</h2><h3>{{post_id}}</h3></body></html>', is_template: true })
@@ -65,6 +65,14 @@ shared_examples_for 'a request stub' do |options = {}|
65
65
  expect(http.get('/index.html').status).to eql 200
66
66
  end
67
67
 
68
+ #TODO When time allows, work out how to easily test this as the stubs are not recorded for anything but recorded tests
69
+ #the lookup table would need to contain all stubs and we would need a way of indexing them to allow the test to find
70
+ # the correct one.
71
+ xit 'Should record a stub if specified in the stub irrespective of whether app is recording or not' do
72
+ expect(http.get('/indexRecording.html').status).to eql 200
73
+ expect(recordings_for('index_recording')).to include(recordings_matcher_for('index_recording', '/indexRecording.html'))
74
+ end
75
+
68
76
  it 'Should stub a different get request with json response' do
69
77
  resp = http.get('/api/forums')
70
78
  expect(ActiveSupport::JSON.decode(resp.body).symbolize_keys).to eql forums: [], total: 0
@@ -119,7 +119,7 @@ describe AgileProxy::Api::RequestSpecs, api_test: true do
119
119
  end
120
120
  describe 'POST /users/1/applications/1/request_specs' do
121
121
  let(:request_spec_instance) { request_spec_assoc_class.new }
122
- let(:persisted_attributes) { { user_id: 1, application_id: 1, url: 'http://www.test.com', http_method: 'GET' } }
122
+ let(:persisted_attributes) { { user_id: 1, application_id: 1, url: 'http://www.test.com', http_method: 'GET', record_requests: true } }
123
123
  before :each do
124
124
  expect(request_spec_instance).to receive(:as_json).with(default_json_spec).and_return(persisted_attributes)
125
125
  expect(current_user).to receive(:id).and_return(1)
@@ -8,12 +8,13 @@ describe AgileProxy::RequestHandler do
8
8
  end
9
9
 
10
10
  context 'with stubbed handlers' do
11
- let(:env) { to_rack_env(url: 'http://dummy.host.com/index.html').merge('agile_proxy.request_spec_id' => 8) }
11
+ let(:env) { to_rack_env(url: 'http://dummy.host.com/index.html').merge('agile_proxy.request_spec' => mock_request_spec) }
12
12
  let(:stub_handler) { Class.new }
13
13
  let(:proxy_handler) { Class.new }
14
14
  let(:application_class) { Class.new }
15
15
  let(:recordings_class) { Class.new }
16
16
  let(:application) { double('Application', record_requests: false, recordings: recordings_class) }
17
+ let(:mock_request_spec) {double('RequestSpec', id: 8, record_requests: false)}
17
18
 
18
19
  before do
19
20
  stub_const 'AgileProxy::StubHandler', stub_handler
@@ -41,13 +42,20 @@ describe AgileProxy::RequestHandler do
41
42
  expect(subject.call(env)).to eql [200, {}, 'Some data']
42
43
  end
43
44
 
44
- it 'Calls application.recordings.create with a reference to the stub if record_requests is true' do
45
+ it 'Calls application.recordings.create with a reference to the stub if record_requests is true on the application' do
45
46
  allow(application).to receive(:record_requests).and_return true
46
47
  expect(application.recordings).to receive(:create).with(a_hash_including request_spec_id: 8)
47
48
  expect_any_instance_of(stub_handler).to receive(:call).with(env).and_return [200, {}, 'Some data']
48
49
  expect_any_instance_of(proxy_handler).to_not receive(:call)
49
50
  expect(subject.call(env)).to eql [200, {}, 'Some data']
50
51
  end
52
+ it 'Calls application.recordings.create with a reference to the stub if record_requests is true on the request spec' do
53
+ allow(mock_request_spec).to receive(:record_requests).and_return true
54
+ expect(application.recordings).to receive(:create).with(a_hash_including request_spec_id: 8)
55
+ expect_any_instance_of(stub_handler).to receive(:call).with(env).and_return [200, {}, 'Some data']
56
+ expect_any_instance_of(proxy_handler).to_not receive(:call)
57
+ expect(subject.call(env)).to eql [200, {}, 'Some data']
58
+ end
51
59
 
52
60
  end
53
61
 
@@ -48,7 +48,6 @@ describe AgileProxy::StubHandler do
48
48
  request.body.rewind
49
49
  expect(stub).to receive(:call).with({ some: 'param' }, { 'Accept-Encoding' => 'gzip', 'Cache-Control' => 'no-cache' }, body).and_return([200, { 'Content-Type' => 'application/json' }, 'Some Content'])
50
50
  expect(handler.call(request.env)).to eql([200, { 'Content-Type' => 'application/json' }, 'Some Content'])
51
- expect(request.env).to include('agile_proxy.request_spec_id' => stub.id)
52
51
 
53
52
  end
54
53
  it 'should store the id of the request spec in the rack environment when call is called' do
@@ -58,6 +57,7 @@ describe AgileProxy::StubHandler do
58
57
  request.body.rewind
59
58
  expect(stub).to receive(:call).with({ some: 'param' }, { 'Accept-Encoding' => 'gzip', 'Cache-Control' => 'no-cache' }, body).and_return([200, { 'Content-Type' => 'application/json' }, 'Some Content'])
60
59
  expect(handler.call(request.env)).to eql([200, { 'Content-Type' => 'application/json' }, 'Some Content'])
60
+ expect(request.env).to include('agile_proxy.request_spec' => stub)
61
61
 
62
62
  end
63
63
  describe 'Routing patterns' do
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.19
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Taylor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-20 00:00:00.000000000 Z
11
+ date: 2015-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -2301,6 +2301,7 @@ files:
2301
2301
  - db/migrations/20141106083100_add_username_and_password_to_applications.rb
2302
2302
  - db/migrations/20141119143800_add_record_to_applications.rb
2303
2303
  - db/migrations/20141119174300_create_recordings.rb
2304
+ - db/migrations/20150221152500_add_record_requests_to_request_specs.rb
2304
2305
  - db/schema.rb
2305
2306
  - db/seed.rb
2306
2307
  - examples/README.md