rosa-build/spec/controllers/api/v1/advisories_controller_spec.rb

144 lines
4.7 KiB
Ruby
Raw Normal View History

require 'spec_helper'
shared_examples_for 'api advisories user with show rights' do
it 'should be able to perform show action' do
2014-01-21 04:51:49 +00:00
get :show, id: @advisory.advisory_id, format: :json
response.should be_success
end
it 'should be able to perform index action' do
2014-01-21 04:51:49 +00:00
get :index, format: :json
response.should be_success
end
end
2012-10-18 16:44:28 +01:00
shared_examples_for 'api advisories user with admin rights' do
context 'api advisories user with create rights' do
2014-01-21 04:51:49 +00:00
let(:params) { {build_list_id: @build_list.id, advisory: {description: 'test'}} }
2012-10-18 16:44:28 +01:00
it 'should be able to perform create action' do
2014-01-21 04:51:49 +00:00
post :create, params, format: :json
2012-10-18 16:44:28 +01:00
response.should be_success
end
it 'ensures that advisory has been created' do
2014-01-21 04:51:49 +00:00
lambda { post :create, params, format: :json }.should change{ Advisory.count }.by(1)
2012-10-18 16:44:28 +01:00
end
it 'ensures that build_list has been associated with advisory' do
2014-01-21 04:51:49 +00:00
post :create, params, format: :json
2012-10-18 16:44:28 +01:00
@build_list.reload
@build_list.advisory.should_not be_nil
end
end
context 'api advisories user with update rights' do
2014-01-21 04:51:49 +00:00
let(:params) { {id: @advisory.advisory_id, build_list_id: @build_list.id} }
2012-10-18 16:44:28 +01:00
it 'should be able to perform update action' do
2014-01-21 04:51:49 +00:00
put :update, params, format: :json
2012-10-18 16:44:28 +01:00
response.should be_success
end
it 'ensures that advisory has not been created' do
2014-01-21 04:51:49 +00:00
lambda { put :update, params, format: :json }.should_not change{ Advisory.count }
2012-10-18 16:44:28 +01:00
end
it 'ensures that build_list has been associated with advisory' do
2014-01-21 04:51:49 +00:00
put :update, params, format: :json
2012-10-18 16:44:28 +01:00
@build_list.reload
@build_list.advisory.should_not be_nil
end
end
end
shared_examples_for 'api advisories user without admin rights' do
context 'api advisories user without create rights' do
2014-01-21 04:51:49 +00:00
let(:params) { {build_list_id: @build_list.id, advisory: {description: 'test'}} }
2012-10-18 16:44:28 +01:00
it 'should not be able to perform create action' do
2014-01-21 04:51:49 +00:00
post :create, params, format: :json
2012-10-18 16:44:28 +01:00
response.should_not be_success
end
it 'ensures that advisory has not been created' do
2014-01-21 04:51:49 +00:00
lambda { post :create, params, format: :json }.should_not change{ Advisory.count }
2012-10-18 16:44:28 +01:00
end
it 'ensures that build_list has not been associated with advisory' do
2014-01-21 04:51:49 +00:00
post :create, params, format: :json
2012-10-18 16:44:28 +01:00
@build_list.reload
@build_list.advisory.should be_nil
end
end
context 'api advisories user without update rights' do
2014-01-21 04:51:49 +00:00
let(:params) { {id: @advisory.advisory_id, build_list_id: @build_list.id} }
2012-10-18 16:44:28 +01:00
it 'should not be able to perform update action' do
2014-01-21 04:51:49 +00:00
put :update, params, format: :json
2012-10-18 16:44:28 +01:00
response.should_not be_success
end
it 'ensures that advisory has not been created' do
2014-01-21 04:51:49 +00:00
lambda { put :update, params, format: :json }.should_not change{ Advisory.count }
2012-10-18 16:44:28 +01:00
end
it 'ensures that build_list has not been associated with advisory' do
2014-01-21 04:51:49 +00:00
put :update, params, format: :json
2012-10-18 16:44:28 +01:00
@build_list.reload
@build_list.advisory.should be_nil
end
end
end
describe Api::V1::AdvisoriesController do
before do
stub_symlink_methods
@advisory = FactoryGirl.create(:advisory)
2013-07-01 13:20:38 +01:00
@build_list = FactoryGirl.create(:build_list)
2012-10-18 17:25:24 +01:00
@build_list.save_to_platform.update_column(:released, true)
@build_list.save_to_repository.update_column(:publish_without_qa, false)
2012-10-18 16:44:28 +01:00
@build_list.update_column(:status, BuildList::BUILD_PUBLISHED)
end
context 'for guest' do
2014-01-21 04:51:49 +00:00
if APP_CONFIG['anonymous_access']
it_should_behave_like 'api advisories user with show rights'
end
it 'should not be able to perform show action', :anonymous_access => false do
2014-01-21 04:51:49 +00:00
get :show, id: @advisory.advisory_id, format: :json
response.should_not be_success
end
it 'should not be able to perform index action', :anonymous_access => false do
2014-01-21 04:51:49 +00:00
get :index, format: :json
response.should_not be_success
end
2012-10-18 16:44:28 +01:00
it_should_behave_like 'api advisories user without admin rights'
end
context 'for simple user' do
before do
@user = FactoryGirl.create(:user)
http_login(@user)
end
it_should_behave_like 'api advisories user with show rights'
2012-10-18 16:44:28 +01:00
it_should_behave_like 'api advisories user without admin rights'
end
context 'for admin' do
before do
@admin = FactoryGirl.create(:admin)
http_login(@admin)
end
it_should_behave_like 'api advisories user with show rights'
2012-10-18 16:44:28 +01:00
it_should_behave_like 'api advisories user with admin rights'
end
context 'for user who has access to update build_list' do
before do
@user = FactoryGirl.create(:user)
create_relation @build_list.save_to_platform, @user, 'admin'
http_login(@user)
end
it_should_behave_like 'api advisories user with show rights'
2012-10-18 16:44:28 +01:00
it_should_behave_like 'api advisories user with admin rights'
end
end