Skip to content

Commit

Permalink
Merge pull request #4485 from mdeniz/improve_tests_user_group_adminis…
Browse files Browse the repository at this point in the history
…tration

Extend tests for user and group administration for projects and packages
  • Loading branch information
Ana06 committed Feb 12, 2018
2 parents 894bc86 + 72d6d24 commit 3a9ab7f
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/api/app/mixins/webui/manage_relationships.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def remove_role
main_object.remove_role(load_obj, Role.find_by_title(params[:role]))
main_object.store
rescue NotFoundError => e
flash[:error] = e.summary
flash[:error] = e.to_s
end
respond_to do |format|
format.js { render json: 'ok' }
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def self.add_user(obj, user, role, ignore_lock = nil, check = nil)
role = Role.find_by_title!(role) unless role.is_a? Role
if role.global
# only nonglobal roles may be set in an object
raise SaveError, "tried to set global role '#{role.title}' for user '#{user}' in #{obj.class} '#{name}'"
raise SaveError, "tried to set global role '#{role.title}' for user '#{user}' in #{obj.class} '#{obj.name}'"
end

user = User.find_by_login!(user) unless user.is_a? User
Expand All @@ -89,7 +89,7 @@ def self.add_group(obj, group, role, ignore_lock = nil, check = nil)

if role.global
# only nonglobal roles may be set in an object
raise SaveError, "tried to set global role '#{role_title}' for group '#{group}' in #{obj.class} '#{name}'"
raise SaveError, "tried to set global role '#{role.title}' for group '#{group}' in #{obj.class} '#{obj.name}'"
end

group = Group.find_by_title(group.to_s) unless group.is_a? Group
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions src/api/spec/controllers/webui/project_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1725,17 +1725,6 @@
it { expect(assigns[:maintained_projects]).to eq([maintained_project.project.name]) }
end

describe 'GET #save_person' do
let(:new_user) { create(:user) }

before do
login user
post :save_person, params: { project: user.home_project, role: 'maintainer', userid: new_user.login }
end

it { expect(response).to redirect_to(users_path) }
end

describe '#filter_matches?' do
let(:input) { 'ThisIsAPackage' }

Expand Down
83 changes: 77 additions & 6 deletions src/api/spec/models/relationship_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'rails_helper'

RSpec.describe Relationship do
let(:admin_user) { create(:admin_user, login: 'admin') }
let(:global_role) { create(:role, title: 'global_role', global: true) }
let(:normal_role) { create(:role, title: 'normal_role', global: false) }

before(:all) do
@caching_state = ActionController::Base.perform_caching
ActionController::Base.perform_caching = true
Expand All @@ -10,21 +14,88 @@
ActionController::Base.perform_caching = @caching_state
end

it '.add_user' do
skip
describe '.add_user' do
let(:role) { normal_role }
let(:user) { create(:confirmed_user, login: 'other_user') }
let(:project) { user.home_project }

before do
login(admin_user)
end

subject { Relationship.add_user(project, user, role, true, true) }

context 'with a global role' do
let(:role) { global_role }

it { expect { subject }.to raise_error(Relationship::SaveError, /tried to set global role/) }
end

context 'with an already existing relationship' do
before do
project.relationships.create(user: user, role: role)
end

it { expect { subject }.to raise_error(Relationship::SaveError, 'Relationship already exists') }
end

context 'with invalid relationship data' do
skip('This is imposible to happen with the actual validations and how the object is created')
end

context 'with valid data' do
before do
subject
end

it { expect { project.store }.to change { Relationship.count }.by(1) }
end
end

it '.add_group' do
skip
describe '.add_group' do
let(:role) { normal_role }
let(:user) { admin_user }
let(:project) { user.home_project }
let(:group) { create(:group) }

before do
login(admin_user)
end

subject { Relationship.add_group(project, group, role, true, true) }

context 'with a global role' do
let(:role) { global_role }

it { expect { subject }.to raise_error(Relationship::SaveError, /tried to set global role/) }
end

context 'with an already existing relationship' do
before do
project.relationships.create(group: group, role: role)
end

it { expect { subject }.to raise_error(Relationship::SaveError, 'Relationship already exists') }
end

context 'with invalid relationship data' do
skip('This is imposible to happen with the actual validations and how the object is created')
end

context 'with valid data' do
before do
subject
end

it { expect { project.store }.to change { Relationship.count }.by(1) }
end
end

describe '.forbidden_project_ids' do
let(:confirmed_user) { create(:confirmed_user) }
let(:project) { create(:forbidden_project) }

context 'for admins' do
let(:admin_user) { create(:admin_user) }

before do
login(admin_user)
end
Expand Down

0 comments on commit 3a9ab7f

Please sign in to comment.