#465: Fixed: undefined method 'uname' for nil:NilClass

This commit is contained in:
Vokhmin Alexey V 2015-04-18 23:55:34 +03:00
parent bb8a4aa227
commit 08db1ad59a
3 changed files with 42 additions and 3 deletions

View File

@ -15,11 +15,14 @@ class ProjectPolicy < ApplicationPolicy
local_reader? local_reader?
end end
alias_method :read?, :show? alias_method :read?, :show?
alias_method :fork?, :show?
alias_method :archive?, :show? alias_method :archive?, :show?
alias_method :get_id?, :show? alias_method :get_id?, :show?
alias_method :refs_list?, :show? alias_method :refs_list?, :show?
def fork?
!user.guest? && show?
end
def create? def create?
return false if user.guest? return false if user.guest?
return true if is_admin? return true if is_admin?

View File

@ -3,6 +3,7 @@
'ng-init' => "init('#{@project.name_with_owner}', '#{@treeish}', '#{@path}')" } 'ng-init' => "init('#{@project.name_with_owner}', '#{@treeish}', '#{@path}')" }
.files .files
.pull-left= render 'whereami' .pull-left= render 'whereami'
- if policy(@project).fork?
.pull-right= render 'fork' .pull-right= render 'fork'
.clearfix .clearfix
%table.table.table-hover %table.table.table-hover

View File

@ -16,7 +16,7 @@ RSpec.describe ProjectPolicy, type: :policy do
end end
end end
%i(show? read? fork? archive? get_id? refs_list?).each do |perm| %i(show? read? archive? get_id? refs_list?).each do |perm|
permissions perm do permissions perm do
it "grants access to anonymous user" do it "grants access to anonymous user" do
expect(subject).to permit(User.new, project) expect(subject).to permit(User.new, project)
@ -53,6 +53,41 @@ RSpec.describe ProjectPolicy, type: :policy do
end end
end end
permissions :fork? do
it "denies access to anonymous user" do
expect(subject).to_not permit(User.new, project)
end
it "grants access to user" do
expect(subject).to permit(user, project)
end
context 'hidden project' do
before do
project.visibility = 'hidden'
end
it "grants access for owner of project" do
expect(subject).to permit(project.owner, project)
end
it "grants access for member of project owner group" do
project = FactoryGirl.build(:group_project)
allow_any_instance_of(ProjectPolicy).to receive(:user_group_ids).and_return([project.owner_id])
expect(subject).to permit(user, project)
end
it "grants access for reader of project" do
allow_any_instance_of(ProjectPolicy).to receive(:local_reader?).and_return(true)
expect(subject).to permit(user, project)
end
it "grants access for to global admin" do
expect(subject).to permit(FactoryGirl.create(:admin), project)
end
end
end
permissions :create? do permissions :create? do
it "denies access to anonymous user" do it "denies access to anonymous user" do
expect(subject).to_not permit(User.new, project) expect(subject).to_not permit(User.new, project)