|
| 1 | +RSpec.describe 'Flavors API' do |
| 2 | + let(:flavor) { FactoryGirl.create(:flavor_openstack) } |
| 3 | + |
| 4 | + describe 'GET/api/flavors' do |
| 5 | + it 'lists all the flavor bases with an appropriate role' do |
| 6 | + flavor = FactoryGirl.create(:flavor_openstack) |
| 7 | + |
| 8 | + api_basic_authorize collection_action_identifier(:flavors, :read, :get) |
| 9 | + |
| 10 | + run_get(api_flavors_url) |
| 11 | + |
| 12 | + expected = { |
| 13 | + 'count' => 1, |
| 14 | + 'subcount' => 1, |
| 15 | + 'name' => 'flavors', |
| 16 | + 'resources' => [hash_including('href' => a_string_matching(api_flavors_url(nil, flavor.compressed_id)))] |
| 17 | + } |
| 18 | + expect(response.parsed_body).to include(expected) |
| 19 | + expect(response).to have_http_status(:ok) |
| 20 | + end |
| 21 | + |
| 22 | + it 'forbids access to flavor bases without an appropriate role' do |
| 23 | + api_basic_authorize |
| 24 | + |
| 25 | + run_get(api_flavors_url) |
| 26 | + |
| 27 | + expect(response).to have_http_status(:forbidden) |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + describe 'GET /api/flavors/:id' do |
| 32 | + it 'will show a flavor base' do |
| 33 | + api_basic_authorize action_identifier(:flavors, :read, :resource_actions, :get) |
| 34 | + |
| 35 | + flavor = FactoryGirl.create(:flavor) |
| 36 | + |
| 37 | + run_get(api_flavor_url(nil, flavor)) |
| 38 | + |
| 39 | + expected = { |
| 40 | + 'href' => a_string_matching(api_flavors_url(nil, flavor.compressed_id)) |
| 41 | + } |
| 42 | + expect(response.parsed_body).to include(expected) |
| 43 | + expect(response).to have_http_status(:ok) |
| 44 | + end |
| 45 | + |
| 46 | + it 'forbids access to a flavor base' do |
| 47 | + api_basic_authorize |
| 48 | + |
| 49 | + run_get(api_flavors_url) |
| 50 | + |
| 51 | + expect(response).to have_http_status(:forbidden) |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + describe 'DELETE /api/flavors/:id' do |
| 56 | + it 'will delete a flavor' do |
| 57 | + flavor = FactoryGirl.create(:flavor) |
| 58 | + |
| 59 | + api_basic_authorize action_identifier(:flavors, :delete, :resource_actions, :delete) |
| 60 | + |
| 61 | + run_delete api_flavor_url(nil, flavor) |
| 62 | + |
| 63 | + expect(response).to have_http_status(:no_content) |
| 64 | + end |
| 65 | + |
| 66 | + it 'will not delete a flavor without an appropriate role' do |
| 67 | + flavor = FactoryGirl.create(:flavor) |
| 68 | + |
| 69 | + api_basic_authorize |
| 70 | + |
| 71 | + run_post(api_flavors_url, :action => 'delete') |
| 72 | + |
| 73 | + expect(response).to have_http_status(:forbidden) |
| 74 | + end |
| 75 | + end |
| 76 | +end |
0 commit comments