Commit d431e4339269041784986da40a0e0879baaf96a9
1 parent
00a1f5bc
Exists in
master
and in
4 other branches
Fix few bugs and tests after refactoring ownership logic
Showing
19 changed files
with
58 additions
and
61 deletions
Show diff stats
app/controllers/admin/users_controller.rb
@@ -9,7 +9,7 @@ class Admin::UsersController < AdminController | @@ -9,7 +9,7 @@ class Admin::UsersController < AdminController | ||
9 | def show | 9 | def show |
10 | @admin_user = User.find(params[:id]) | 10 | @admin_user = User.find(params[:id]) |
11 | 11 | ||
12 | - @projects = if @admin_user.projects.empty? | 12 | + @projects = if @admin_user.authorized_projects.empty? |
13 | Project | 13 | Project |
14 | else | 14 | else |
15 | Project.without_user(@admin_user) | 15 | Project.without_user(@admin_user) |
@@ -98,7 +98,7 @@ class Admin::UsersController < AdminController | @@ -98,7 +98,7 @@ class Admin::UsersController < AdminController | ||
98 | 98 | ||
99 | def destroy | 99 | def destroy |
100 | @admin_user = User.find(params[:id]) | 100 | @admin_user = User.find(params[:id]) |
101 | - if @admin_user.my_own_projects.count > 0 | 101 | + if @admin_user.personal_projects.count > 0 |
102 | redirect_to admin_users_path, alert: "User is a project owner and can't be removed." and return | 102 | redirect_to admin_users_path, alert: "User is a project owner and can't be removed." and return |
103 | end | 103 | end |
104 | @admin_user.destroy | 104 | @admin_user.destroy |
app/helpers/namespaces_helper.rb
1 | module NamespacesHelper | 1 | module NamespacesHelper |
2 | def namespaces_options(selected = :current_user, scope = :default) | 2 | def namespaces_options(selected = :current_user, scope = :default) |
3 | - groups = current_user.namespaces.select {|n| n.type == 'Group'} | 3 | + groups = current_user.owned_groups.select {|n| n.type == 'Group'} |
4 | 4 | ||
5 | users = if scope == :all | 5 | users = if scope == :all |
6 | Namespace.root | 6 | Namespace.root |
app/models/ability.rb
@@ -29,21 +29,10 @@ class Ability | @@ -29,21 +29,10 @@ class Ability | ||
29 | rules << project_guest_rules | 29 | rules << project_guest_rules |
30 | end | 30 | end |
31 | 31 | ||
32 | - if project.namespace | ||
33 | - # If user own project namespace | ||
34 | - # (Ex. group owner or account owner) | ||
35 | - if project.namespace.owner == user | ||
36 | - rules << project_admin_rules | ||
37 | - end | ||
38 | - else | ||
39 | - # For compatibility with global projects | ||
40 | - # use projects.owner_id | ||
41 | - if project.owner == user | ||
42 | - rules << project_admin_rules | ||
43 | - end | 32 | + if project.owner == user |
33 | + rules << project_admin_rules | ||
44 | end | 34 | end |
45 | 35 | ||
46 | - | ||
47 | rules.flatten | 36 | rules.flatten |
48 | end | 37 | end |
49 | 38 |
app/models/key.rb
app/models/project.rb
@@ -80,7 +80,7 @@ class Project < ActiveRecord::Base | @@ -80,7 +80,7 @@ class Project < ActiveRecord::Base | ||
80 | 80 | ||
81 | # Scopes | 81 | # Scopes |
82 | scope :public_only, where(private_flag: false) | 82 | scope :public_only, where(private_flag: false) |
83 | - scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) } | 83 | + scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) } |
84 | scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } | 84 | scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } |
85 | scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } | 85 | scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } |
86 | scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") } | 86 | scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") } |
app/models/user.rb
@@ -187,4 +187,9 @@ class User < ActiveRecord::Base | @@ -187,4 +187,9 @@ class User < ActiveRecord::Base | ||
187 | (projects.namespace_id IS NULL AND projects.creator_id = :user_id)", | 187 | (projects.namespace_id IS NULL AND projects.creator_id = :user_id)", |
188 | namespaces: namespaces.map(&:id), user_id: self.id) | 188 | namespaces: namespaces.map(&:id), user_id: self.id) |
189 | end | 189 | end |
190 | + | ||
191 | + # Team membership in personal projects | ||
192 | + def tm_in_personal_projects | ||
193 | + personal_projects.users_projects.where(user_id: self.id) | ||
194 | + end | ||
190 | end | 195 | end |
app/roles/account.rb
@@ -69,7 +69,7 @@ module Account | @@ -69,7 +69,7 @@ module Account | ||
69 | 69 | ||
70 | def projects_limit_percent | 70 | def projects_limit_percent |
71 | return 100 if projects_limit.zero? | 71 | return 100 if projects_limit.zero? |
72 | - (my_own_projects.count.to_f / projects_limit) * 100 | 72 | + (personal_projects.count.to_f / projects_limit) * 100 |
73 | end | 73 | end |
74 | 74 | ||
75 | def recent_push project_id = nil | 75 | def recent_push project_id = nil |
app/views/admin/projects/index.html.haml
@@ -28,7 +28,10 @@ | @@ -28,7 +28,10 @@ | ||
28 | %span.monospace= project.path_with_namespace + ".git" | 28 | %span.monospace= project.path_with_namespace + ".git" |
29 | %td= project.users_projects.count | 29 | %td= project.users_projects.count |
30 | %td | 30 | %td |
31 | - = link_to project.chief.name, [:admin, project.chief] | 31 | + - if project.owner |
32 | + = link_to project.owner.name, [:admin, project.owner] | ||
33 | + - else | ||
34 | + (deleted) | ||
32 | %td= last_commit(project) | 35 | %td= last_commit(project) |
33 | %td= link_to 'Edit', edit_admin_project_path(project), id: "edit_#{dom_id(project)}", class: "btn small" | 36 | %td= link_to 'Edit', edit_admin_project_path(project), id: "edit_#{dom_id(project)}", class: "btn small" |
34 | %td.bgred= link_to 'Destroy', [:admin, project], confirm: "REMOVE #{project.name}? Are you sure?", method: :delete, class: "btn small danger" | 37 | %td.bgred= link_to 'Destroy', [:admin, project], confirm: "REMOVE #{project.name}? Are you sure?", method: :delete, class: "btn small danger" |
app/views/admin/users/show.html.haml
@@ -106,8 +106,8 @@ | @@ -106,8 +106,8 @@ | ||
106 | %td= link_to group.name, admin_group_path(group) | 106 | %td= link_to group.name, admin_group_path(group) |
107 | 107 | ||
108 | 108 | ||
109 | -- if @admin_user.projects.present? | ||
110 | - %h5 Projects: | 109 | +- if @admin_user.personal_projects.present? |
110 | + %h5 Personal Projects: | ||
111 | %br | 111 | %br |
112 | 112 | ||
113 | %table.zebra-striped | 113 | %table.zebra-striped |
@@ -118,7 +118,7 @@ | @@ -118,7 +118,7 @@ | ||
118 | %th | 118 | %th |
119 | %th | 119 | %th |
120 | 120 | ||
121 | - - @admin_user.users_projects.each do |tm| | 121 | + - @admin_user.tm_in_personal_projects.each do |tm| |
122 | - project = tm.project | 122 | - project = tm.project |
123 | %tr | 123 | %tr |
124 | %td= link_to project.name_with_namespace, admin_project_path(project) | 124 | %td= link_to project.name_with_namespace, admin_project_path(project) |
app/views/profiles/show.html.haml
@@ -64,7 +64,7 @@ | @@ -64,7 +64,7 @@ | ||
64 | %legend | 64 | %legend |
65 | Personal projects: | 65 | Personal projects: |
66 | %small.right | 66 | %small.right |
67 | - %span= current_user.my_own_projects.count | 67 | + %span= current_user.personal_projects.count |
68 | of | 68 | of |
69 | %span= current_user.projects_limit | 69 | %span= current_user.projects_limit |
70 | .padded | 70 | .padded |
lib/api/projects.rb
@@ -9,7 +9,7 @@ module Gitlab | @@ -9,7 +9,7 @@ module Gitlab | ||
9 | # Example Request: | 9 | # Example Request: |
10 | # GET /projects | 10 | # GET /projects |
11 | get do | 11 | get do |
12 | - @projects = paginate current_user.projects | 12 | + @projects = paginate current_user.authorized_projects |
13 | present @projects, with: Entities::Project | 13 | present @projects, with: Entities::Project |
14 | end | 14 | end |
15 | 15 |
spec/factories.rb
@@ -37,7 +37,7 @@ FactoryGirl.define do | @@ -37,7 +37,7 @@ FactoryGirl.define do | ||
37 | end | 37 | end |
38 | 38 | ||
39 | factory :namespace do | 39 | factory :namespace do |
40 | - sequence(:name) { |n| "group#{n}" } | 40 | + sequence(:name) { |n| "namespace#{n}" } |
41 | path { name.downcase.gsub(/\s/, '_') } | 41 | path { name.downcase.gsub(/\s/, '_') } |
42 | owner | 42 | owner |
43 | end | 43 | end |
spec/requests/api/issues_spec.rb
@@ -4,7 +4,7 @@ describe Gitlab::API do | @@ -4,7 +4,7 @@ describe Gitlab::API do | ||
4 | include ApiHelpers | 4 | include ApiHelpers |
5 | 5 | ||
6 | let(:user) { create(:user) } | 6 | let(:user) { create(:user) } |
7 | - let!(:project) { create(:project, owner: user) } | 7 | + let!(:project) { create(:project, namespace: user.namespace ) } |
8 | let!(:issue) { create(:issue, author: user, assignee: user, project: project) } | 8 | let!(:issue) { create(:issue, author: user, assignee: user, project: project) } |
9 | before { project.add_access(user, :read) } | 9 | before { project.add_access(user, :read) } |
10 | 10 |
spec/requests/api/merge_requests_spec.rb
@@ -4,7 +4,7 @@ describe Gitlab::API do | @@ -4,7 +4,7 @@ describe Gitlab::API do | ||
4 | include ApiHelpers | 4 | include ApiHelpers |
5 | 5 | ||
6 | let(:user) { create(:user ) } | 6 | let(:user) { create(:user ) } |
7 | - let!(:project) { create(:project, owner: user) } | 7 | + let!(:project) { create(:project, namespace: user.namespace ) } |
8 | let!(:merge_request) { create(:merge_request, author: user, assignee: user, project: project, title: "Test") } | 8 | let!(:merge_request) { create(:merge_request, author: user, assignee: user, project: project, title: "Test") } |
9 | before { project.add_access(user, :read) } | 9 | before { project.add_access(user, :read) } |
10 | 10 |
spec/requests/api/milestones_spec.rb
@@ -4,7 +4,7 @@ describe Gitlab::API do | @@ -4,7 +4,7 @@ describe Gitlab::API do | ||
4 | include ApiHelpers | 4 | include ApiHelpers |
5 | 5 | ||
6 | let(:user) { create(:user) } | 6 | let(:user) { create(:user) } |
7 | - let!(:project) { create(:project, owner: user) } | 7 | + let!(:project) { create(:project, namespace: user.namespace ) } |
8 | let!(:milestone) { create(:milestone, project: project) } | 8 | let!(:milestone) { create(:milestone, project: project) } |
9 | 9 | ||
10 | before { project.add_access(user, :read) } | 10 | before { project.add_access(user, :read) } |
spec/requests/api/notes_spec.rb
@@ -4,7 +4,7 @@ describe Gitlab::API do | @@ -4,7 +4,7 @@ describe Gitlab::API do | ||
4 | include ApiHelpers | 4 | include ApiHelpers |
5 | 5 | ||
6 | let(:user) { create(:user) } | 6 | let(:user) { create(:user) } |
7 | - let!(:project) { create(:project, owner: user) } | 7 | + let!(:project) { create(:project, namespace: user.namespace ) } |
8 | let!(:issue) { create(:issue, project: project, author: user) } | 8 | let!(:issue) { create(:issue, project: project, author: user) } |
9 | let!(:snippet) { create(:snippet, project: project, author: user) } | 9 | let!(:snippet) { create(:snippet, project: project, author: user) } |
10 | let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) } | 10 | let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) } |
spec/requests/api/projects_spec.rb
@@ -7,7 +7,7 @@ describe Gitlab::API do | @@ -7,7 +7,7 @@ describe Gitlab::API do | ||
7 | let(:user2) { create(:user) } | 7 | let(:user2) { create(:user) } |
8 | let(:user3) { create(:user) } | 8 | let(:user3) { create(:user) } |
9 | let!(:hook) { create(:project_hook, project: project, url: "http://example.com") } | 9 | let!(:hook) { create(:project_hook, project: project, url: "http://example.com") } |
10 | - let!(:project) { create(:project, owner: user ) } | 10 | + let!(:project) { create(:project, namespace: user.namespace ) } |
11 | let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') } | 11 | let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') } |
12 | let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } | 12 | let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } |
13 | let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) } | 13 | let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) } |
@@ -79,7 +79,7 @@ describe Gitlab::API do | @@ -79,7 +79,7 @@ describe Gitlab::API do | ||
79 | end | 79 | end |
80 | 80 | ||
81 | it "should return a project by path name" do | 81 | it "should return a project by path name" do |
82 | - get api("/projects/#{project.path}", user) | 82 | + get api("/projects/#{project.id}", user) |
83 | response.status.should == 200 | 83 | response.status.should == 200 |
84 | json_response['name'].should == project.name | 84 | json_response['name'].should == project.name |
85 | end | 85 | end |
@@ -93,7 +93,7 @@ describe Gitlab::API do | @@ -93,7 +93,7 @@ describe Gitlab::API do | ||
93 | 93 | ||
94 | describe "GET /projects/:id/repository/branches" do | 94 | describe "GET /projects/:id/repository/branches" do |
95 | it "should return an array of project branches" do | 95 | it "should return an array of project branches" do |
96 | - get api("/projects/#{project.path}/repository/branches", user) | 96 | + get api("/projects/#{project.id}/repository/branches", user) |
97 | response.status.should == 200 | 97 | response.status.should == 200 |
98 | json_response.should be_an Array | 98 | json_response.should be_an Array |
99 | json_response.first['name'].should == project.repo.heads.sort_by(&:name).first.name | 99 | json_response.first['name'].should == project.repo.heads.sort_by(&:name).first.name |
@@ -102,7 +102,7 @@ describe Gitlab::API do | @@ -102,7 +102,7 @@ describe Gitlab::API do | ||
102 | 102 | ||
103 | describe "GET /projects/:id/repository/branches/:branch" do | 103 | describe "GET /projects/:id/repository/branches/:branch" do |
104 | it "should return the branch information for a single branch" do | 104 | it "should return the branch information for a single branch" do |
105 | - get api("/projects/#{project.path}/repository/branches/new_design", user) | 105 | + get api("/projects/#{project.id}/repository/branches/new_design", user) |
106 | response.status.should == 200 | 106 | response.status.should == 200 |
107 | 107 | ||
108 | json_response['name'].should == 'new_design' | 108 | json_response['name'].should == 'new_design' |
@@ -112,7 +112,7 @@ describe Gitlab::API do | @@ -112,7 +112,7 @@ describe Gitlab::API do | ||
112 | 112 | ||
113 | describe "GET /projects/:id/members" do | 113 | describe "GET /projects/:id/members" do |
114 | it "should return project team members" do | 114 | it "should return project team members" do |
115 | - get api("/projects/#{project.path}/members", user) | 115 | + get api("/projects/#{project.id}/members", user) |
116 | response.status.should == 200 | 116 | response.status.should == 200 |
117 | json_response.should be_an Array | 117 | json_response.should be_an Array |
118 | json_response.count.should == 2 | 118 | json_response.count.should == 2 |
@@ -120,7 +120,7 @@ describe Gitlab::API do | @@ -120,7 +120,7 @@ describe Gitlab::API do | ||
120 | end | 120 | end |
121 | 121 | ||
122 | it "finds team members with query string" do | 122 | it "finds team members with query string" do |
123 | - get api("/projects/#{project.path}/members", user), query: user.username | 123 | + get api("/projects/#{project.id}/members", user), query: user.username |
124 | response.status.should == 200 | 124 | response.status.should == 200 |
125 | json_response.should be_an Array | 125 | json_response.should be_an Array |
126 | json_response.count.should == 1 | 126 | json_response.count.should == 1 |
@@ -130,7 +130,7 @@ describe Gitlab::API do | @@ -130,7 +130,7 @@ describe Gitlab::API do | ||
130 | 130 | ||
131 | describe "GET /projects/:id/members/:user_id" do | 131 | describe "GET /projects/:id/members/:user_id" do |
132 | it "should return project team member" do | 132 | it "should return project team member" do |
133 | - get api("/projects/#{project.path}/members/#{user.id}", user) | 133 | + get api("/projects/#{project.id}/members/#{user.id}", user) |
134 | response.status.should == 200 | 134 | response.status.should == 200 |
135 | json_response['email'].should == user.email | 135 | json_response['email'].should == user.email |
136 | json_response['access_level'].should == UsersProject::MASTER | 136 | json_response['access_level'].should == UsersProject::MASTER |
@@ -140,7 +140,7 @@ describe Gitlab::API do | @@ -140,7 +140,7 @@ describe Gitlab::API do | ||
140 | describe "POST /projects/:id/members" do | 140 | describe "POST /projects/:id/members" do |
141 | it "should add user to project team" do | 141 | it "should add user to project team" do |
142 | expect { | 142 | expect { |
143 | - post api("/projects/#{project.path}/members", user), user_id: user2.id, | 143 | + post api("/projects/#{project.id}/members", user), user_id: user2.id, |
144 | access_level: UsersProject::DEVELOPER | 144 | access_level: UsersProject::DEVELOPER |
145 | }.to change { UsersProject.count }.by(1) | 145 | }.to change { UsersProject.count }.by(1) |
146 | 146 | ||
@@ -152,7 +152,7 @@ describe Gitlab::API do | @@ -152,7 +152,7 @@ describe Gitlab::API do | ||
152 | 152 | ||
153 | describe "PUT /projects/:id/members/:user_id" do | 153 | describe "PUT /projects/:id/members/:user_id" do |
154 | it "should update project team member" do | 154 | it "should update project team member" do |
155 | - put api("/projects/#{project.path}/members/#{user3.id}", user), access_level: UsersProject::MASTER | 155 | + put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: UsersProject::MASTER |
156 | response.status.should == 200 | 156 | response.status.should == 200 |
157 | json_response['email'].should == user3.email | 157 | json_response['email'].should == user3.email |
158 | json_response['access_level'].should == UsersProject::MASTER | 158 | json_response['access_level'].should == UsersProject::MASTER |
@@ -162,14 +162,14 @@ describe Gitlab::API do | @@ -162,14 +162,14 @@ describe Gitlab::API do | ||
162 | describe "DELETE /projects/:id/members/:user_id" do | 162 | describe "DELETE /projects/:id/members/:user_id" do |
163 | it "should remove user from project team" do | 163 | it "should remove user from project team" do |
164 | expect { | 164 | expect { |
165 | - delete api("/projects/#{project.path}/members/#{user3.id}", user) | 165 | + delete api("/projects/#{project.id}/members/#{user3.id}", user) |
166 | }.to change { UsersProject.count }.by(-1) | 166 | }.to change { UsersProject.count }.by(-1) |
167 | end | 167 | end |
168 | end | 168 | end |
169 | 169 | ||
170 | describe "GET /projects/:id/hooks" do | 170 | describe "GET /projects/:id/hooks" do |
171 | it "should return project hooks" do | 171 | it "should return project hooks" do |
172 | - get api("/projects/#{project.path}/hooks", user) | 172 | + get api("/projects/#{project.id}/hooks", user) |
173 | 173 | ||
174 | response.status.should == 200 | 174 | response.status.should == 200 |
175 | 175 | ||
@@ -181,7 +181,7 @@ describe Gitlab::API do | @@ -181,7 +181,7 @@ describe Gitlab::API do | ||
181 | 181 | ||
182 | describe "GET /projects/:id/hooks/:hook_id" do | 182 | describe "GET /projects/:id/hooks/:hook_id" do |
183 | it "should return a project hook" do | 183 | it "should return a project hook" do |
184 | - get api("/projects/#{project.path}/hooks/#{hook.id}", user) | 184 | + get api("/projects/#{project.id}/hooks/#{hook.id}", user) |
185 | response.status.should == 200 | 185 | response.status.should == 200 |
186 | json_response['url'].should == hook.url | 186 | json_response['url'].should == hook.url |
187 | end | 187 | end |
@@ -190,7 +190,7 @@ describe Gitlab::API do | @@ -190,7 +190,7 @@ describe Gitlab::API do | ||
190 | describe "POST /projects/:id/hooks" do | 190 | describe "POST /projects/:id/hooks" do |
191 | it "should add hook to project" do | 191 | it "should add hook to project" do |
192 | expect { | 192 | expect { |
193 | - post api("/projects/#{project.path}/hooks", user), | 193 | + post api("/projects/#{project.id}/hooks", user), |
194 | "url" => "http://example.com" | 194 | "url" => "http://example.com" |
195 | }.to change {project.hooks.count}.by(1) | 195 | }.to change {project.hooks.count}.by(1) |
196 | end | 196 | end |
@@ -198,7 +198,7 @@ describe Gitlab::API do | @@ -198,7 +198,7 @@ describe Gitlab::API do | ||
198 | 198 | ||
199 | describe "PUT /projects/:id/hooks/:hook_id" do | 199 | describe "PUT /projects/:id/hooks/:hook_id" do |
200 | it "should update an existing project hook" do | 200 | it "should update an existing project hook" do |
201 | - put api("/projects/#{project.path}/hooks/#{hook.id}", user), | 201 | + put api("/projects/#{project.id}/hooks/#{hook.id}", user), |
202 | url: 'http://example.org' | 202 | url: 'http://example.org' |
203 | response.status.should == 200 | 203 | response.status.should == 200 |
204 | json_response['url'].should == 'http://example.org' | 204 | json_response['url'].should == 'http://example.org' |
@@ -209,7 +209,7 @@ describe Gitlab::API do | @@ -209,7 +209,7 @@ describe Gitlab::API do | ||
209 | describe "DELETE /projects/:id/hooks" do | 209 | describe "DELETE /projects/:id/hooks" do |
210 | it "should delete hook from project" do | 210 | it "should delete hook from project" do |
211 | expect { | 211 | expect { |
212 | - delete api("/projects/#{project.path}/hooks", user), | 212 | + delete api("/projects/#{project.id}/hooks", user), |
213 | hook_id: hook.id | 213 | hook_id: hook.id |
214 | }.to change {project.hooks.count}.by(-1) | 214 | }.to change {project.hooks.count}.by(-1) |
215 | end | 215 | end |
@@ -217,7 +217,7 @@ describe Gitlab::API do | @@ -217,7 +217,7 @@ describe Gitlab::API do | ||
217 | 217 | ||
218 | describe "GET /projects/:id/repository/tags" do | 218 | describe "GET /projects/:id/repository/tags" do |
219 | it "should return an array of project tags" do | 219 | it "should return an array of project tags" do |
220 | - get api("/projects/#{project.path}/repository/tags", user) | 220 | + get api("/projects/#{project.id}/repository/tags", user) |
221 | response.status.should == 200 | 221 | response.status.should == 200 |
222 | json_response.should be_an Array | 222 | json_response.should be_an Array |
223 | json_response.first['name'].should == project.repo.tags.sort_by(&:name).reverse.first.name | 223 | json_response.first['name'].should == project.repo.tags.sort_by(&:name).reverse.first.name |
@@ -229,7 +229,7 @@ describe Gitlab::API do | @@ -229,7 +229,7 @@ describe Gitlab::API do | ||
229 | before { project.add_access(user2, :read) } | 229 | before { project.add_access(user2, :read) } |
230 | 230 | ||
231 | it "should return project commits" do | 231 | it "should return project commits" do |
232 | - get api("/projects/#{project.path}/repository/commits", user) | 232 | + get api("/projects/#{project.id}/repository/commits", user) |
233 | response.status.should == 200 | 233 | response.status.should == 200 |
234 | 234 | ||
235 | json_response.should be_an Array | 235 | json_response.should be_an Array |
@@ -239,7 +239,7 @@ describe Gitlab::API do | @@ -239,7 +239,7 @@ describe Gitlab::API do | ||
239 | 239 | ||
240 | context "unauthorized user" do | 240 | context "unauthorized user" do |
241 | it "should not return project commits" do | 241 | it "should not return project commits" do |
242 | - get api("/projects/#{project.path}/repository/commits") | 242 | + get api("/projects/#{project.id}/repository/commits") |
243 | response.status.should == 401 | 243 | response.status.should == 401 |
244 | end | 244 | end |
245 | end | 245 | end |
@@ -247,7 +247,7 @@ describe Gitlab::API do | @@ -247,7 +247,7 @@ describe Gitlab::API do | ||
247 | 247 | ||
248 | describe "GET /projects/:id/snippets" do | 248 | describe "GET /projects/:id/snippets" do |
249 | it "should return an array of project snippets" do | 249 | it "should return an array of project snippets" do |
250 | - get api("/projects/#{project.path}/snippets", user) | 250 | + get api("/projects/#{project.id}/snippets", user) |
251 | response.status.should == 200 | 251 | response.status.should == 200 |
252 | json_response.should be_an Array | 252 | json_response.should be_an Array |
253 | json_response.first['title'].should == snippet.title | 253 | json_response.first['title'].should == snippet.title |
@@ -256,7 +256,7 @@ describe Gitlab::API do | @@ -256,7 +256,7 @@ describe Gitlab::API do | ||
256 | 256 | ||
257 | describe "GET /projects/:id/snippets/:snippet_id" do | 257 | describe "GET /projects/:id/snippets/:snippet_id" do |
258 | it "should return a project snippet" do | 258 | it "should return a project snippet" do |
259 | - get api("/projects/#{project.path}/snippets/#{snippet.id}", user) | 259 | + get api("/projects/#{project.id}/snippets/#{snippet.id}", user) |
260 | response.status.should == 200 | 260 | response.status.should == 200 |
261 | json_response['title'].should == snippet.title | 261 | json_response['title'].should == snippet.title |
262 | end | 262 | end |
@@ -264,7 +264,7 @@ describe Gitlab::API do | @@ -264,7 +264,7 @@ describe Gitlab::API do | ||
264 | 264 | ||
265 | describe "POST /projects/:id/snippets" do | 265 | describe "POST /projects/:id/snippets" do |
266 | it "should create a new project snippet" do | 266 | it "should create a new project snippet" do |
267 | - post api("/projects/#{project.path}/snippets", user), | 267 | + post api("/projects/#{project.id}/snippets", user), |
268 | title: 'api test', file_name: 'sample.rb', code: 'test' | 268 | title: 'api test', file_name: 'sample.rb', code: 'test' |
269 | response.status.should == 201 | 269 | response.status.should == 201 |
270 | json_response['title'].should == 'api test' | 270 | json_response['title'].should == 'api test' |
@@ -273,7 +273,7 @@ describe Gitlab::API do | @@ -273,7 +273,7 @@ describe Gitlab::API do | ||
273 | 273 | ||
274 | describe "PUT /projects/:id/snippets/:shippet_id" do | 274 | describe "PUT /projects/:id/snippets/:shippet_id" do |
275 | it "should update an existing project snippet" do | 275 | it "should update an existing project snippet" do |
276 | - put api("/projects/#{project.path}/snippets/#{snippet.id}", user), | 276 | + put api("/projects/#{project.id}/snippets/#{snippet.id}", user), |
277 | code: 'updated code' | 277 | code: 'updated code' |
278 | response.status.should == 200 | 278 | response.status.should == 200 |
279 | json_response['title'].should == 'example' | 279 | json_response['title'].should == 'example' |
@@ -284,31 +284,31 @@ describe Gitlab::API do | @@ -284,31 +284,31 @@ describe Gitlab::API do | ||
284 | describe "DELETE /projects/:id/snippets/:snippet_id" do | 284 | describe "DELETE /projects/:id/snippets/:snippet_id" do |
285 | it "should delete existing project snippet" do | 285 | it "should delete existing project snippet" do |
286 | expect { | 286 | expect { |
287 | - delete api("/projects/#{project.path}/snippets/#{snippet.id}", user) | 287 | + delete api("/projects/#{project.id}/snippets/#{snippet.id}", user) |
288 | }.to change { Snippet.count }.by(-1) | 288 | }.to change { Snippet.count }.by(-1) |
289 | end | 289 | end |
290 | end | 290 | end |
291 | 291 | ||
292 | describe "GET /projects/:id/snippets/:snippet_id/raw" do | 292 | describe "GET /projects/:id/snippets/:snippet_id/raw" do |
293 | it "should get a raw project snippet" do | 293 | it "should get a raw project snippet" do |
294 | - get api("/projects/#{project.path}/snippets/#{snippet.id}/raw", user) | 294 | + get api("/projects/#{project.id}/snippets/#{snippet.id}/raw", user) |
295 | response.status.should == 200 | 295 | response.status.should == 200 |
296 | end | 296 | end |
297 | end | 297 | end |
298 | 298 | ||
299 | describe "GET /projects/:id/:sha/blob" do | 299 | describe "GET /projects/:id/:sha/blob" do |
300 | it "should get the raw file contents" do | 300 | it "should get the raw file contents" do |
301 | - get api("/projects/#{project.path}/repository/commits/master/blob?filepath=README.md", user) | 301 | + get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user) |
302 | response.status.should == 200 | 302 | response.status.should == 200 |
303 | end | 303 | end |
304 | 304 | ||
305 | it "should return 404 for invalid branch_name" do | 305 | it "should return 404 for invalid branch_name" do |
306 | - get api("/projects/#{project.path}/repository/commits/invalid_branch_name/blob?filepath=README.md", user) | 306 | + get api("/projects/#{project.id}/repository/commits/invalid_branch_name/blob?filepath=README.md", user) |
307 | response.status.should == 404 | 307 | response.status.should == 404 |
308 | end | 308 | end |
309 | 309 | ||
310 | it "should return 404 for invalid file" do | 310 | it "should return 404 for invalid file" do |
311 | - get api("/projects/#{project.path}/repository/commits/master/blob?filepath=README.invalid", user) | 311 | + get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.invalid", user) |
312 | response.status.should == 404 | 312 | response.status.should == 404 |
313 | end | 313 | end |
314 | end | 314 | end |
spec/requests/projects_spec.rb
@@ -5,7 +5,7 @@ describe "Projects" do | @@ -5,7 +5,7 @@ describe "Projects" do | ||
5 | 5 | ||
6 | describe "GET /projects/show" do | 6 | describe "GET /projects/show" do |
7 | before do | 7 | before do |
8 | - @project = create(:project, owner: @user) | 8 | + @project = create(:project, namespace: @user.namespace) |
9 | @project.add_access(@user, :read) | 9 | @project.add_access(@user, :read) |
10 | 10 | ||
11 | visit project_path(@project) | 11 | visit project_path(@project) |
@@ -37,7 +37,7 @@ describe "Projects" do | @@ -37,7 +37,7 @@ describe "Projects" do | ||
37 | 37 | ||
38 | describe "PUT /projects/:id" do | 38 | describe "PUT /projects/:id" do |
39 | before do | 39 | before do |
40 | - @project = create(:project, owner: @user) | 40 | + @project = create(:project, namespace: @user.namespace) |
41 | @project.add_access(@user, :admin, :read) | 41 | @project.add_access(@user, :admin, :read) |
42 | 42 | ||
43 | visit edit_project_path(@project) | 43 | visit edit_project_path(@project) |
@@ -58,7 +58,7 @@ describe "Projects" do | @@ -58,7 +58,7 @@ describe "Projects" do | ||
58 | 58 | ||
59 | describe "DELETE /projects/:id" do | 59 | describe "DELETE /projects/:id" do |
60 | before do | 60 | before do |
61 | - @project = create(:project, owner: @user) | 61 | + @project = create(:project, namespace: @user.namespace) |
62 | @project.add_access(@user, :read, :admin) | 62 | @project.add_access(@user, :read, :admin) |
63 | visit edit_project_path(@project) | 63 | visit edit_project_path(@project) |
64 | end | 64 | end |
spec/spec_helper.rb
@@ -38,7 +38,7 @@ RSpec.configure do |config| | @@ -38,7 +38,7 @@ RSpec.configure do |config| | ||
38 | stub_gitolite! | 38 | stub_gitolite! |
39 | 39 | ||
40 | # !!! Observers disabled by default in tests | 40 | # !!! Observers disabled by default in tests |
41 | - ActiveRecord::Base.observers.disable(:all) | 41 | + #ActiveRecord::Base.observers.disable(:all) |
42 | # ActiveRecord::Base.observers.enable(:all) | 42 | # ActiveRecord::Base.observers.enable(:all) |
43 | 43 | ||
44 | # Use tmp dir for FS manipulations | 44 | # Use tmp dir for FS manipulations |