2012-08-21 18:15:28 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
shared_examples_for "api projects user with reader rights" do
|
2012-08-22 14:44:01 +01:00
|
|
|
include_examples "api projects user with show rights"
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "api projects user with reader rights for hidden project" do
|
2015-06-09 00:25:56 +01:00
|
|
|
before do
|
|
|
|
project.update_column(:visibility, 'hidden')
|
2012-08-22 14:44:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'api projects user with show rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "api projects user without reader rights for hidden project" do
|
2015-06-09 00:25:56 +01:00
|
|
|
before do
|
|
|
|
project.update_column(:visibility, 'hidden')
|
2012-08-22 14:44:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'api projects user without show rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "api projects user without show rights" do
|
2015-03-31 02:08:50 +01:00
|
|
|
it "to show access violation instead of project data" do
|
2015-06-09 00:25:56 +01:00
|
|
|
get :show, id: project.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(response).to_not be_success
|
2012-10-11 18:51:40 +01:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it "to show access violation instead of project refs_list" do
|
2015-06-09 00:25:56 +01:00
|
|
|
get :refs_list, id: project.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(response).to_not be_success
|
2012-08-22 14:44:01 +01:00
|
|
|
end
|
2012-08-28 17:57:12 +01:00
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it "to access violation instead of project data by get_id" do
|
2015-06-09 00:25:56 +01:00
|
|
|
get :get_id, name: project.name, owner: project.owner_uname, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(response).to_not be_success
|
2012-08-28 17:57:12 +01:00
|
|
|
end
|
2012-10-17 15:30:54 +01:00
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it "to show access violation instead of project members data" do
|
2015-06-09 00:25:56 +01:00
|
|
|
get :members, id: project.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(response).to_not be_success
|
2012-10-17 15:30:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'api projects user without fork rights' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { project } # init
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to not be able to perform fork action' do
|
|
|
|
expect do
|
2015-06-09 00:25:56 +01:00
|
|
|
post :fork, id: project.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
end.to_not change(Project, :count)
|
2015-06-09 00:25:56 +01:00
|
|
|
expect(response).to_not be_success
|
2012-10-17 15:30:54 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'api projects user with fork rights' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { project } # init
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to be able to perform fork action' do
|
|
|
|
expect do
|
2015-06-09 00:25:56 +01:00
|
|
|
post :fork, id: project.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
end.to change(Project, :count).by(1)
|
|
|
|
expect(response).to be_success
|
2013-11-19 11:02:05 +00:00
|
|
|
end
|
|
|
|
|
2015-06-09 00:25:56 +01:00
|
|
|
it 'to be able to perform fork action with different name' do
|
|
|
|
new_name = project.name + '_forked'
|
2015-03-31 02:08:50 +01:00
|
|
|
expect do
|
2015-06-09 00:25:56 +01:00
|
|
|
post :fork, id: project.id, fork_name: new_name, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
end.to change{ Project.where(name: new_name).count }.by(1)
|
2015-06-09 00:25:56 +01:00
|
|
|
expect(response).to be_success
|
2013-11-19 11:02:05 +00:00
|
|
|
end
|
2012-10-17 15:30:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'api projects user with fork rights for hidden project' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { project.update_column(:visibility, 'hidden') }
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user with fork rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'api projects user without fork rights for hidden project' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { project.update_column(:visibility, 'hidden') }
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user without fork rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
end
|
2012-08-21 18:15:28 +01:00
|
|
|
|
2012-08-22 14:44:01 +01:00
|
|
|
shared_examples_for "api projects user with show rights" do
|
2015-03-31 02:08:50 +01:00
|
|
|
it "to show project data" do
|
2015-06-09 00:25:56 +01:00
|
|
|
get :show, id: project.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(response).to render_template(:show)
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
2012-08-28 17:57:12 +01:00
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it "to show refs_list of project" do
|
2015-06-09 00:25:56 +01:00
|
|
|
get :refs_list, id: project.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(response).to render_template(:refs_list)
|
2012-10-11 18:51:40 +01:00
|
|
|
end
|
|
|
|
|
2012-08-28 17:57:12 +01:00
|
|
|
context 'project find by get_id' do
|
2015-03-31 02:08:50 +01:00
|
|
|
it "to find project by name and owner name" do
|
2015-06-09 00:25:56 +01:00
|
|
|
project.reload
|
|
|
|
get :get_id, name: project.name, owner: project.owner_uname, format: :json
|
|
|
|
expect(assigns[:project].id).to eq project.id
|
2012-08-28 17:57:12 +01:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it "to not find project by non existing name and owner name" do
|
2015-06-09 00:25:56 +01:00
|
|
|
get :get_id, name: 'NONE_EXISTING_NAME', owner: project.owner_uname, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(assigns :project).to be_blank
|
2012-08-28 17:57:12 +01:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it "to render 404 for non existing name and owner name" do
|
2015-06-09 00:25:56 +01:00
|
|
|
get :get_id, name: 'NONE_EXISTING_NAME', owner: project.owner_uname, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(response.body).to eq({status: 404, message: I18n.t("flash.404_message")}.to_json)
|
2012-08-28 17:57:12 +01:00
|
|
|
end
|
|
|
|
end
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
2012-10-17 18:08:21 +01:00
|
|
|
shared_examples_for 'api projects user with admin rights' do
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it "to be able to perform members action" do
|
2015-06-09 00:25:56 +01:00
|
|
|
get :members, id: project.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(response).to be_success
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to not set a wrong maintainer_id' do
|
2015-06-09 00:25:56 +01:00
|
|
|
put :update, project: { maintainer_id: -1 }, id: project.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(response).to_not be_success
|
2014-11-26 09:59:21 +00:00
|
|
|
end
|
2012-10-17 18:08:21 +01:00
|
|
|
|
|
|
|
context 'api project user with update rights' do
|
|
|
|
before do
|
2015-06-09 00:25:56 +01:00
|
|
|
put :update, project: { description: 'new description' }, id: project.id, format: :json
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to be able to perform update action' do
|
|
|
|
expect(response).to be_success
|
2015-06-09 00:25:56 +01:00
|
|
|
expect(project.reload.description).to eq 'new description'
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'api project user with add_member rights' do
|
|
|
|
let(:member) { FactoryGirl.create(:user) }
|
|
|
|
before do
|
2015-06-09 00:25:56 +01:00
|
|
|
put :add_member, member_id: member.id, type: 'User', role: 'admin', id: project.id, format: :json
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to be able to perform add_member action' do
|
|
|
|
expect(response).to be_success
|
2015-06-09 00:25:56 +01:00
|
|
|
expect(project.members).to include(member)
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'api project user with remove_member rights' do
|
|
|
|
let(:member) { FactoryGirl.create(:user) }
|
|
|
|
before do
|
2015-06-09 00:25:56 +01:00
|
|
|
project.add_member(member)
|
|
|
|
delete :remove_member, member_id: member.id, type: 'User', id: project.id, format: :json
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to be able to perform remove_member action' do
|
|
|
|
expect(response).to be_success
|
2015-06-09 00:25:56 +01:00
|
|
|
expect(project.members).to_not include(member)
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'api group user with update_member rights' do
|
|
|
|
let(:member) { FactoryGirl.create(:user) }
|
|
|
|
before do
|
2015-06-09 00:25:56 +01:00
|
|
|
project.add_member(member)
|
|
|
|
put :update_member, member_id: member.id, type: 'User', role: 'reader', id: project.id, format: :json
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to be able to perform update_member action' do
|
|
|
|
expect(response).to be_success
|
2015-06-09 00:25:56 +01:00
|
|
|
role = project.relations.by_actor(member).first.role
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(role).to eq 'reader'
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'api projects user without admin rights' do
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it "to not be able to perform members action" do
|
2015-06-09 00:25:56 +01:00
|
|
|
get :members, id: project.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(response).to_not be_success
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'api project user without update_member rights' do
|
|
|
|
let(:member) { FactoryGirl.create(:user) }
|
|
|
|
before do
|
2015-06-09 00:25:56 +01:00
|
|
|
project.add_member(member)
|
|
|
|
put :update_member, member_id: member.id, type: 'User', role: 'reader', id: project.id, format: :json
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to not be able to perform update_member action' do
|
|
|
|
expect(response).to_not be_success
|
2015-06-09 00:25:56 +01:00
|
|
|
role = project.relations.by_actor(member).first.role
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(role).to_not eq 'reader'
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'api project user without update rights' do
|
|
|
|
before do
|
2015-06-09 00:25:56 +01:00
|
|
|
put :update, project: {description: 'new description'}, id: project.id, format: :json
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to not be able to perform update action' do
|
|
|
|
expect(response).to_not be_success
|
2015-06-09 00:25:56 +01:00
|
|
|
expect(project.reload.description).to_not eq 'new description'
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'api project user without add_member rights' do
|
|
|
|
let(:member) { FactoryGirl.create(:user) }
|
|
|
|
before do
|
2015-06-09 00:25:56 +01:00
|
|
|
put :add_member, member_id: member.id, type: 'User', role: 'admin', id: project.id, format: :json
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to not be able to perform add_member action' do
|
|
|
|
expect(response).to_not be_success
|
2015-06-09 00:25:56 +01:00
|
|
|
expect(project.members).to_not include(member)
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'api project user without remove_member rights' do
|
|
|
|
let(:member) { FactoryGirl.create(:user) }
|
|
|
|
before do
|
2015-06-09 00:25:56 +01:00
|
|
|
project.add_member(member)
|
|
|
|
delete :remove_member, member_id: member.id, type: 'User', id: project.id, format: :json
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to be able to perform update action' do
|
|
|
|
expect(response).to_not be_success
|
2015-06-09 00:25:56 +01:00
|
|
|
expect(project.members).to include(member)
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'api projects user with owner rights' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { project } # init
|
|
|
|
|
2012-10-17 18:08:21 +01:00
|
|
|
context 'api project user with destroy rights' do
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to be able to perform destroy action' do
|
|
|
|
expect do
|
2015-06-09 00:25:56 +01:00
|
|
|
delete :destroy, id: project.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
end.to change(Project, :count).by(-1)
|
2015-06-09 00:25:56 +01:00
|
|
|
expect(response).to be_success
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'api projects user without owner rights' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { project } # init
|
|
|
|
|
2012-10-17 18:08:21 +01:00
|
|
|
context 'api project user with destroy rights' do
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to not be able to perform destroy action' do
|
|
|
|
expect do
|
2015-06-09 00:25:56 +01:00
|
|
|
delete :destroy, id: project.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
end.to_not change(Project, :count)
|
2015-06-09 00:25:56 +01:00
|
|
|
expect(response).to_not be_success
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-19 01:12:08 +00:00
|
|
|
describe Api::V1::ProjectsController, type: :controller do
|
2012-08-21 18:15:28 +01:00
|
|
|
|
2015-06-09 00:25:56 +01:00
|
|
|
let(:project) { FactoryGirl.create(:project) }
|
|
|
|
let(:hidden_project) { FactoryGirl.create(:project) }
|
|
|
|
let(:another_user) { FactoryGirl.create(:user) }
|
|
|
|
|
|
|
|
before do
|
2012-08-21 18:15:28 +01:00
|
|
|
stub_symlink_methods
|
|
|
|
|
2015-06-09 00:25:56 +01:00
|
|
|
# project = FactoryGirl.create(:project)
|
|
|
|
# hidden_project = FactoryGirl.create(:project)
|
|
|
|
# another_user = FactoryGirl.create(:user)
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for guest' do
|
2012-10-17 18:08:21 +01:00
|
|
|
|
|
|
|
[:index, :members].each do |action|
|
2015-03-31 02:08:50 +01:00
|
|
|
it "to not be able to perform #{action} action" do
|
2015-06-09 00:25:56 +01:00
|
|
|
get action, id: project.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(response).to_not be_success
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-11 18:51:40 +01:00
|
|
|
if APP_CONFIG['anonymous_access']
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user with show rights'
|
2012-10-11 18:51:40 +01:00
|
|
|
it_should_behave_like 'api projects user without reader rights for hidden project'
|
|
|
|
else
|
|
|
|
it_should_behave_like 'api projects user without show rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
end
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user without fork rights'
|
|
|
|
it_should_behave_like 'api projects user without fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user without admin rights'
|
|
|
|
it_should_behave_like 'api projects user without owner rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for simple user' do
|
2015-06-09 00:25:56 +01:00
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
http_login(user)
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
2012-08-22 14:44:01 +01:00
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to be able to perform index action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :index, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(response).to be_success
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'api project user with create rights' do
|
2015-06-09 00:25:56 +01:00
|
|
|
let(:params) { {project: {name: 'test_name', owner_id: user.id, owner_type: 'User', visibility: 'open'}, format: :json} }
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to be able to perform create action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :create, params, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
expect(response).to be_success
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
it 'ensures that project has been created' do
|
2015-03-31 02:08:50 +01:00
|
|
|
expect do
|
|
|
|
post :create, params
|
|
|
|
end.to change(Project, :count).by(1)
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
2013-05-07 19:25:31 +01:00
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'writer group to be able to create project for their group' do
|
2013-05-07 19:25:31 +01:00
|
|
|
group = FactoryGirl.create(:group)
|
2015-06-09 00:25:56 +01:00
|
|
|
create_actor_relation(group, user, 'writer')
|
2015-03-31 02:08:50 +01:00
|
|
|
expect do
|
|
|
|
post :create, params.deep_merge({project: {owner_type: 'Group', owner_id: group.id}})
|
|
|
|
end.to change(Project, :count).by(1)
|
2013-05-07 19:25:31 +01:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'reader group to not be able to create project for their group' do
|
2013-05-07 19:25:31 +01:00
|
|
|
group = FactoryGirl.create(:group)
|
2015-06-09 00:25:56 +01:00
|
|
|
create_actor_relation(group, user, 'reader')
|
2015-03-31 02:08:50 +01:00
|
|
|
expect do
|
|
|
|
post :create, params.deep_merge({project: {owner_type: 'Group', owner_id: group.id}})
|
|
|
|
end.to_not change(Project, :count)
|
2013-05-07 19:25:31 +01:00
|
|
|
end
|
2012-10-17 18:08:21 +01:00
|
|
|
end
|
|
|
|
|
2012-08-22 14:44:01 +01:00
|
|
|
it_should_behave_like 'api projects user with reader rights'
|
|
|
|
it_should_behave_like 'api projects user without reader rights for hidden project'
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user with fork rights'
|
|
|
|
it_should_behave_like 'api projects user without fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user without admin rights'
|
|
|
|
it_should_behave_like 'api projects user without owner rights'
|
2013-05-07 19:07:03 +01:00
|
|
|
|
2013-11-19 11:02:05 +00:00
|
|
|
context 'group writer' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { project } # init
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to be able to fork project to their group' do
|
2013-11-19 11:02:05 +00:00
|
|
|
group = FactoryGirl.create(:group)
|
2015-06-09 00:25:56 +01:00
|
|
|
create_actor_relation(group, user, 'writer')
|
2015-03-31 02:08:50 +01:00
|
|
|
expect do
|
2015-06-09 00:25:56 +01:00
|
|
|
post :fork, id: project.id, group_id: group.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
end.to change(Project, :count).by(1)
|
2013-11-19 11:02:05 +00:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to be able to fork project with different name to their group' do
|
2013-11-19 11:02:05 +00:00
|
|
|
group = FactoryGirl.create(:group)
|
2015-06-09 00:25:56 +01:00
|
|
|
create_actor_relation(group, user, 'writer')
|
|
|
|
new_name = project.name + '_forked'
|
2015-03-31 02:08:50 +01:00
|
|
|
expect do
|
2015-06-09 00:25:56 +01:00
|
|
|
post :fork, id: project.id, group_id: group.id, fork_name: new_name, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
end.to change { Project.where(name: new_name).count }.by(1)
|
2013-11-19 11:02:05 +00:00
|
|
|
end
|
2013-05-07 19:07:03 +01:00
|
|
|
end
|
|
|
|
|
2013-11-19 11:02:05 +00:00
|
|
|
context 'group reader' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { project } # init
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to not be able to fork project to their group' do
|
2013-11-19 11:02:05 +00:00
|
|
|
group = FactoryGirl.create(:group)
|
2015-06-09 00:25:56 +01:00
|
|
|
create_actor_relation(group, user, 'reader')
|
2015-03-31 02:08:50 +01:00
|
|
|
expect do
|
2015-06-09 00:25:56 +01:00
|
|
|
post :fork, id: project.id, group_id: group.id, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
end.to_not change(Project, :count)
|
2013-11-19 11:02:05 +00:00
|
|
|
end
|
|
|
|
|
2015-03-31 02:08:50 +01:00
|
|
|
it 'to not be able to fork project with different name to their group' do
|
2013-11-19 11:02:05 +00:00
|
|
|
group = FactoryGirl.create(:group)
|
2015-06-09 00:25:56 +01:00
|
|
|
new_name = project.name + '_forked'
|
|
|
|
create_actor_relation(group, user, 'reader')
|
2015-03-31 02:08:50 +01:00
|
|
|
expect do
|
2015-06-09 00:25:56 +01:00
|
|
|
post :fork, id: project.id, group_id: group.id, fork_name: new_name, format: :json
|
2015-03-31 02:08:50 +01:00
|
|
|
end.to_not change{ Project.where(name: new_name).count }
|
2013-11-19 11:02:05 +00:00
|
|
|
end
|
2013-05-07 19:07:03 +01:00
|
|
|
end
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for admin' do
|
2015-06-09 00:25:56 +01:00
|
|
|
let(:admin) { FactoryGirl.create(:admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
http_login(admin)
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'api projects user with reader rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
it_should_behave_like 'api projects user with reader rights for hidden project'
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user with fork rights'
|
|
|
|
it_should_behave_like 'api projects user with fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user with admin rights'
|
|
|
|
it_should_behave_like 'api projects user with owner rights'
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for owner user' do
|
2015-06-09 00:25:56 +01:00
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
|
|
let(:project) { FactoryGirl.create(:project, owner: user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
http_login(user)
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'api projects user with reader rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
it_should_behave_like 'api projects user with reader rights for hidden project'
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user without fork rights'
|
|
|
|
it_should_behave_like 'api projects user without fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user with admin rights'
|
|
|
|
it_should_behave_like 'api projects user with owner rights'
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for reader user' do
|
2015-06-09 00:25:56 +01:00
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
http_login(user)
|
|
|
|
create_relation(project, user, 'reader')
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'api projects user with reader rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
it_should_behave_like 'api projects user with reader rights for hidden project'
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user with fork rights'
|
|
|
|
it_should_behave_like 'api projects user with fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user without admin rights'
|
|
|
|
it_should_behave_like 'api projects user without owner rights'
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for writer user' do
|
2015-06-09 00:25:56 +01:00
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
http_login(user)
|
|
|
|
create_relation(project, user, 'writer')
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'api projects user with reader rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
it_should_behave_like 'api projects user with reader rights for hidden project'
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user with fork rights'
|
|
|
|
it_should_behave_like 'api projects user with fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user without admin rights'
|
|
|
|
it_should_behave_like 'api projects user without owner rights'
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for group' do
|
2015-06-09 00:25:56 +01:00
|
|
|
let(:group) { FactoryGirl.create(:group) }
|
|
|
|
let(:group_user) { FactoryGirl.create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
# project.relations.destroy_all
|
|
|
|
http_login(group_user)
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
2012-08-22 14:44:01 +01:00
|
|
|
context 'with no relations to project' do
|
|
|
|
it_should_behave_like 'api projects user with reader rights'
|
|
|
|
it_should_behave_like 'api projects user without reader rights for hidden project'
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user with fork rights'
|
|
|
|
it_should_behave_like 'api projects user without fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user without admin rights'
|
|
|
|
it_should_behave_like 'api projects user without owner rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
end
|
|
|
|
|
2012-08-21 18:15:28 +01:00
|
|
|
context 'owner of the project' do
|
2015-06-09 00:25:56 +01:00
|
|
|
let(:project) { FactoryGirl.create(:project, owner: group) }
|
2012-08-21 18:15:28 +01:00
|
|
|
|
|
|
|
context 'reader user' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { create_actor_relation(group, group_user, 'reader') }
|
2012-08-21 18:15:28 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'api projects user with reader rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
it_should_behave_like 'api projects user with reader rights for hidden project'
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user with fork rights'
|
|
|
|
it_should_behave_like 'api projects user with fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user without admin rights'
|
|
|
|
it_should_behave_like 'api projects user without owner rights'
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'admin user' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { create_actor_relation(group, group_user, 'admin') }
|
2012-08-21 18:15:28 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'api projects user with reader rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
it_should_behave_like 'api projects user with reader rights for hidden project'
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user with fork rights'
|
|
|
|
it_should_behave_like 'api projects user with fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user with admin rights'
|
|
|
|
it_should_behave_like 'api projects user with owner rights'
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'member of the project' do
|
|
|
|
context 'with admin rights' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before do
|
|
|
|
create_relation(project, group, 'admin')
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'reader user' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { create_actor_relation(group, group_user, 'reader') }
|
2012-08-21 18:15:28 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'api projects user with reader rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
it_should_behave_like 'api projects user with reader rights for hidden project'
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user with fork rights'
|
|
|
|
it_should_behave_like 'api projects user with fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user with admin rights'
|
|
|
|
it_should_behave_like 'api projects user without owner rights'
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'admin user' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { create_actor_relation(group, group_user, 'admin') }
|
2012-08-21 18:15:28 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'api projects user with reader rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
it_should_behave_like 'api projects user with reader rights for hidden project'
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user with fork rights'
|
|
|
|
it_should_behave_like 'api projects user with fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user with admin rights'
|
|
|
|
it_should_behave_like 'api projects user without owner rights'
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with reader rights' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { create_relation(project, group, 'reader') }
|
2012-08-21 18:15:28 +01:00
|
|
|
|
|
|
|
context 'reader user' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { create_actor_relation(group, group_user, 'reader') }
|
2012-08-21 18:15:28 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'api projects user with reader rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
it_should_behave_like 'api projects user with reader rights for hidden project'
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user with fork rights'
|
|
|
|
it_should_behave_like 'api projects user with fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user without admin rights'
|
|
|
|
it_should_behave_like 'api projects user without owner rights'
|
2012-08-21 18:15:28 +01:00
|
|
|
|
|
|
|
context 'user should has best role' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { create_relation(project, group_user, 'admin') }
|
2014-03-18 09:31:01 +00:00
|
|
|
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user with reader rights'
|
|
|
|
it_should_behave_like 'api projects user with fork rights'
|
|
|
|
it_should_behave_like 'api projects user with fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user with admin rights'
|
|
|
|
it_should_behave_like 'api projects user without owner rights'
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-09 00:25:56 +01:00
|
|
|
|
2012-08-21 18:15:28 +01:00
|
|
|
context 'admin user' do
|
2015-06-09 00:25:56 +01:00
|
|
|
before { create_actor_relation(group, group_user, 'admin') }
|
2012-08-21 18:15:28 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'api projects user with reader rights'
|
2012-08-22 14:44:01 +01:00
|
|
|
it_should_behave_like 'api projects user with reader rights for hidden project'
|
2012-10-17 15:30:54 +01:00
|
|
|
it_should_behave_like 'api projects user with fork rights'
|
|
|
|
it_should_behave_like 'api projects user with fork rights for hidden project'
|
2012-10-17 18:08:21 +01:00
|
|
|
it_should_behave_like 'api projects user without admin rights'
|
|
|
|
it_should_behave_like 'api projects user without owner rights'
|
2012-08-21 18:15:28 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|