2012-11-26 11:32:23 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2013-06-17 20:14:20 +01:00
|
|
|
shared_examples_for 'api maintainers user with reader rights' do
|
|
|
|
it 'should be able to perform index action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :index, platform_id: package.platform_id, format: :json
|
2015-03-26 00:26:24 +00:00
|
|
|
expect(response).to render_template(:index)
|
2013-06-17 20:14:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'loads all of the maintainers into @maintainers' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :index, platform_id: package.platform_id, format: :json
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(assigns(:maintainers).count).to eq 2
|
2015-03-26 00:26:24 +00:00
|
|
|
expect(assigns :maintainers).to include(package, package2)
|
2013-06-17 20:14:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'loads all of the maintainers into @maintainers when search by name' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :index, platform_id: package.platform_id, package_name: 'package1', format: :json
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(assigns(:maintainers).count).to eq 1
|
2015-03-26 00:26:24 +00:00
|
|
|
expect(assigns :maintainers).to include(package)
|
2013-06-17 20:14:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-02-19 01:12:08 +00:00
|
|
|
describe Api::V1::MaintainersController, type: :controller do
|
2012-11-30 17:16:05 +00:00
|
|
|
before do
|
|
|
|
stub_symlink_methods
|
2014-01-21 04:51:49 +00:00
|
|
|
FactoryGirl.create(:build_list_package, platform: package.platform)
|
2012-11-30 17:16:05 +00:00
|
|
|
end
|
2014-01-21 04:51:49 +00:00
|
|
|
let(:package) { FactoryGirl.create(:build_list_package, name: 'package1', actual: true) }
|
|
|
|
let!(:package2) { FactoryGirl.create(:build_list_package, platform: package.platform, actual: true) }
|
2012-11-30 17:16:05 +00:00
|
|
|
|
2012-11-26 11:32:23 +00:00
|
|
|
|
|
|
|
context 'for guest' do
|
2013-06-17 20:14:20 +01:00
|
|
|
if APP_CONFIG['anonymous_access']
|
|
|
|
it_should_behave_like 'api maintainers user with reader rights'
|
|
|
|
else
|
|
|
|
it 'should not be able to perform index action', :anonymous_access => false do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :index, platform_id: package.platform_id, format: :json
|
2015-03-26 00:26:24 +00:00
|
|
|
expect(response.status).to eq 401
|
2013-06-17 20:14:20 +01:00
|
|
|
end
|
2012-11-26 11:32:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for simple user' do
|
|
|
|
before do
|
|
|
|
http_login(FactoryGirl.create(:user))
|
|
|
|
end
|
|
|
|
|
2013-06-17 20:14:20 +01:00
|
|
|
it_should_behave_like 'api maintainers user with reader rights'
|
2012-11-26 11:32:23 +00:00
|
|
|
end
|
|
|
|
end
|