Commit acd8930c authored by Sean McGivern's avatar Sean McGivern

Tidy up user project specs

parent 97424ea5
...@@ -383,7 +383,7 @@ class User < ActiveRecord::Base ...@@ -383,7 +383,7 @@ class User < ActiveRecord::Base
def viewable_starred_projects def viewable_starred_projects
starred_projects.where("projects.visibility_level IN (?) OR projects.id IN (#{projects_union.to_sql})", starred_projects.where("projects.visibility_level IN (?) OR projects.id IN (#{projects_union.to_sql})",
[Gitlab::VisibilityLevel::PUBLIC, Gitlab::VisibilityLevel::INTERNAL]) [Project::PUBLIC, Project::INTERNAL])
end end
def owned_projects def owned_projects
......
...@@ -233,8 +233,6 @@ describe User, models: true do ...@@ -233,8 +233,6 @@ describe User, models: true do
@project = create :project, namespace: @user.namespace @project = create :project, namespace: @user.namespace
@project_2 = create :project, group: create(:group) # Grant MASTER access to the user @project_2 = create :project, group: create(:group) # Grant MASTER access to the user
@project_3 = create :project, group: create(:group) # Grant DEVELOPER access to the user @project_3 = create :project, group: create(:group) # Grant DEVELOPER access to the user
@project_4 = create :project, group: create(:group)
@project_5 = create :project, group: create(:group)
@project_2.team << [@user, :master] @project_2.team << [@user, :master]
@project_3.team << [@user, :developer] @project_3.team << [@user, :developer]
...@@ -787,23 +785,20 @@ describe User, models: true do ...@@ -787,23 +785,20 @@ describe User, models: true do
describe '#viewable_starred_projects' do describe '#viewable_starred_projects' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:public_project) { create(:project, :public) } let(:public_project) { create(:empty_project, :public) }
let(:private_project) { create(:project, :private) } let(:private_project) { create(:empty_project, :private) }
let(:private_viewable_project) { create(:project, :private) } let(:private_viewable_project) { create(:empty_project, :private) }
let(:viewable?) { -> (project) { user.can?(:read_project, project) } }
let(:projects) { [public_project, private_project, private_viewable_project] }
before do before do
private_viewable_project.team << [user, Gitlab::Access::MASTER] private_viewable_project.team << [user, Gitlab::Access::MASTER]
projects.each { |project| user.toggle_star(project) }
end
it 'returns only starred projects the user can view' do [public_project, private_project, private_viewable_project].each do |project|
expect(user.viewable_starred_projects).to all(satisfy(&viewable?)) user.toggle_star(project)
end
end end
it 'rejects only starred projects the user can not view' do it 'returns only starred projects the user can view' do
expect(projects - user.viewable_starred_projects).not_to include(satisfy(&viewable?)) expect(user.viewable_starred_projects).not_to include(private_project)
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment