Module: DoSnapshot::RSpec::ApiV2Helpers
- Extended by:
- RSpec::Core::SharedContext
- Defined in:
- lib/do_snapshot/rspec/api_v2_helpers.rb
Overview
rubocop:disable Style/Documentation,Metrics/ModuleLength
Instance Method Summary collapse
-
#stub_droplet(id) ⇒ Object
Droplet data.
- #stub_droplet_fail(id) ⇒ Object
- #stub_droplet_inactive(id) ⇒ Object
-
#stub_droplet_snapshot(id, name) ⇒ Object
Snapshot.
- #stub_droplet_snapshot_fail(id, name) ⇒ Object
- #stub_droplet_start(id) ⇒ Object
- #stub_droplet_start_done(id) ⇒ Object
- #stub_droplet_start_fail(id) ⇒ Object
-
#stub_droplet_stop(id) ⇒ Object
Droplet actions.
- #stub_droplet_stop_fail(id) ⇒ Object
-
#stub_droplets ⇒ Object
List of droplets.
- #stub_droplets_empty ⇒ Object
- #stub_droplets_fail ⇒ Object
-
#stub_event_done(id) ⇒ Object
Event status.
- #stub_event_fail(id) ⇒ Object
- #stub_event_running(id) ⇒ Object
-
#stub_image_destroy(id) ⇒ Object
Image actions.
- #stub_image_destroy_fail(id) ⇒ Object
-
#stub_request_body(type, request, body) ⇒ Object
Body Helpers.
-
#stub_with_id(request, id, fixture, type = :get, body = nil, status = 200) ⇒ Object
Stub helpers.
-
#stub_with_id_name(request, id, name, fixture, type = :get, body = nil, status = 200) ⇒ Object
rubocop:disable Metrics/ParameterLists.
- #stub_without_id(request, fixture, type = :get, body = nil, status = 200) ⇒ Object
Instance Method Details
#stub_droplet(id) ⇒ Object
Droplet data
38 39 40 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 38 def stub_droplet(id) stub_with_id(droplet_find_uri, id, 'v2/show_droplet') end |
#stub_droplet_fail(id) ⇒ Object
42 43 44 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 42 def stub_droplet_fail(id) stub_with_id(droplet_find_uri, id, 'v2/error_message') end |
#stub_droplet_inactive(id) ⇒ Object
46 47 48 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 46 def stub_droplet_inactive(id) stub_with_id(droplet_find_uri, id, 'v2/show_droplet_inactive') end |
#stub_droplet_snapshot(id, name) ⇒ Object
Snapshot
87 88 89 90 91 92 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 87 def stub_droplet_snapshot(id, name) stub_with_id_name(snapshot_uri, id, name, 'v2/response_event', :post, type: 'snapshot', name: name ) end |
#stub_droplet_snapshot_fail(id, name) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 94 def stub_droplet_snapshot_fail(id, name) stub_with_id_name(snapshot_uri, id, name, 'v2/error_message', :post, { type: 'snapshot', name: name }, 404 ) end |
#stub_droplet_start(id) ⇒ Object
67 68 69 70 71 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 67 def stub_droplet_start(id) stub_with_id(droplet_start_uri, id, 'v2/show_event_power_on_start', :post, type: 'power_on' ) end |
#stub_droplet_start_done(id) ⇒ Object
73 74 75 76 77 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 73 def stub_droplet_start_done(id) stub_with_id(droplet_start_uri, id, 'v2/show_event_power_on_done', :post, type: 'power_on' ) end |
#stub_droplet_start_fail(id) ⇒ Object
79 80 81 82 83 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 79 def stub_droplet_start_fail(id) stub_with_id(droplet_start_uri, id, 'v2/error_message', :post, type: 'power_on' ) end |
#stub_droplet_stop(id) ⇒ Object
Droplet actions
52 53 54 55 56 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 52 def stub_droplet_stop(id) stub_with_id(droplet_stop_uri, id, 'v2/show_event_power_off_start', :post, type: 'power_off' ) end |
#stub_droplet_stop_fail(id) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 58 def stub_droplet_stop_fail(id) stub_with_id(droplet_stop_uri, id, 'v2/error_message', :post, { type: 'power_off' }, 404 ) end |
#stub_droplets ⇒ Object
List of droplets
24 25 26 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 24 def stub_droplets stub_without_id(droplets_uri, 'v2/show_droplets') end |
#stub_droplets_empty ⇒ Object
28 29 30 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 28 def stub_droplets_empty stub_without_id(droplets_uri, 'v2/show_droplets_empty') end |
#stub_droplets_fail ⇒ Object
32 33 34 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 32 def stub_droplets_fail stub_without_id(droplets_uri, 'v2/error_message') end |
#stub_event_done(id) ⇒ Object
Event status
106 107 108 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 106 def stub_event_done(id) stub_with_id(action_find_uri, id, 'v2/show_event_done') end |
#stub_event_fail(id) ⇒ Object
110 111 112 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 110 def stub_event_fail(id) stub_with_id(action_find_uri, id, 'v2/error_message') end |
#stub_event_running(id) ⇒ Object
114 115 116 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 114 def stub_event_running(id) stub_with_id(action_find_uri, id, 'v2/show_event_start') end |
#stub_image_destroy(id) ⇒ Object
Image actions
120 121 122 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 120 def stub_image_destroy(id) stub_with_id(image_destroy_uri, id, 'v2/empty', :delete, nil, 204) end |
#stub_image_destroy_fail(id) ⇒ Object
124 125 126 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 124 def stub_image_destroy_fail(id) stub_with_id(image_destroy_uri, id, 'v2/error_message', :delete, nil, 404) end |
#stub_request_body(type, request, body) ⇒ Object
Body Helpers
150 151 152 153 154 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 150 def stub_request_body(type, request, body) stub_response = stub_request(type, request).with(headers: { 'Authorization' => api_access_token }) return stub_response.with(body: body) if body stub_response end |
#stub_with_id(request, id, fixture, type = :get, body = nil, status = 200) ⇒ Object
Stub helpers
130 131 132 133 134 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 130 def stub_with_id(request, id, fixture, type = :get, body = nil, status = 200) # rubocop:disable Metrics/ParameterLists return unless request && fixture && id stub_request_body(type, url_with_id(request, id), body) .to_return(status: status, body: fixture(fixture)) end |
#stub_with_id_name(request, id, name, fixture, type = :get, body = nil, status = 200) ⇒ Object
rubocop:disable Metrics/ParameterLists
142 143 144 145 146 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 142 def stub_with_id_name(request, id, name, fixture, type = :get, body = nil, status = 200) # rubocop:disable Metrics/ParameterLists return unless request && fixture && id && name stub_request_body(type, url_with_id_name(request, id, name), body) .to_return(status: status, body: fixture(fixture)) end |
#stub_without_id(request, fixture, type = :get, body = nil, status = 200) ⇒ Object
136 137 138 139 140 |
# File 'lib/do_snapshot/rspec/api_v2_helpers.rb', line 136 def stub_without_id(request, fixture, type = :get, body = nil, status = 200) return unless request && fixture stub_request_body(type, request, body) .to_return(status: status, body: fixture(fixture)) end |