Commit 0e1635a68a2a3f9c74ca52f2b5c19d63428faf2c
1 parent
e92b563a
Exists in
master
and in
4 other branches
Fixing requests after namespaces. Fixed admin bug with access to project
Showing
14 changed files
with
35 additions
and
62 deletions
Show diff stats
app/controllers/admin/projects_controller.rb
| @@ -42,4 +42,14 @@ class Admin::ProjectsController < AdminController | @@ -42,4 +42,14 @@ class Admin::ProjectsController < AdminController | ||
| 42 | 42 | ||
| 43 | redirect_to projects_url, notice: 'Project was successfully deleted.' | 43 | redirect_to projects_url, notice: 'Project was successfully deleted.' |
| 44 | end | 44 | end |
| 45 | + | ||
| 46 | + protected | ||
| 47 | + | ||
| 48 | + def project | ||
| 49 | + id = params[:project_id] || params[:id] | ||
| 50 | + id = id.split("/") if id.include?("/") | ||
| 51 | + | ||
| 52 | + @project ||= Project.find_by_path(id) | ||
| 53 | + @project || render_404 | ||
| 54 | + end | ||
| 45 | end | 55 | end |
app/helpers/application_helper.rb
| @@ -88,7 +88,7 @@ module ApplicationHelper | @@ -88,7 +88,7 @@ module ApplicationHelper | ||
| 88 | [ "Users", users.map {|u| [u.human_name, u.id]} ] | 88 | [ "Users", users.map {|u| [u.human_name, u.id]} ] |
| 89 | ] | 89 | ] |
| 90 | 90 | ||
| 91 | - if selected == :current_user | 91 | + if selected == :current_user && current_user.namespace |
| 92 | selected = current_user.namespace.id | 92 | selected = current_user.namespace.id |
| 93 | end | 93 | end |
| 94 | 94 |
app/observers/user_observer.rb
| 1 | class UserObserver < ActiveRecord::Observer | 1 | class UserObserver < ActiveRecord::Observer |
| 2 | def after_create(user) | 2 | def after_create(user) |
| 3 | - user.create_namespace(code: user.username, name: user.name) | 3 | + user.create_namespace(path: user.username, name: user.name) |
| 4 | 4 | ||
| 5 | log_info("User \"#{user.name}\" (#{user.email}) was created") | 5 | log_info("User \"#{user.name}\" (#{user.email}) was created") |
| 6 | 6 | ||
| @@ -13,7 +13,7 @@ class UserObserver < ActiveRecord::Observer | @@ -13,7 +13,7 @@ class UserObserver < ActiveRecord::Observer | ||
| 13 | 13 | ||
| 14 | def after_save user | 14 | def after_save user |
| 15 | if user.username_changed? and user.namespace | 15 | if user.username_changed? and user.namespace |
| 16 | - user.namespace.update_attributes(code: user.username) | 16 | + user.namespace.update_attributes(path: user.username) |
| 17 | end | 17 | end |
| 18 | end | 18 | end |
| 19 | 19 |
lib/api/projects.rb
| @@ -38,10 +38,7 @@ module Gitlab | @@ -38,10 +38,7 @@ module Gitlab | ||
| 38 | # Example Request | 38 | # Example Request |
| 39 | # POST /projects | 39 | # POST /projects |
| 40 | post do | 40 | post do |
| 41 | - params[:code] ||= params[:name] | ||
| 42 | - params[:path] ||= params[:name] | ||
| 43 | - attrs = attributes_for_keys [:path, | ||
| 44 | - :name, | 41 | + attrs = attributes_for_keys [:name, |
| 45 | :description, | 42 | :description, |
| 46 | :default_branch, | 43 | :default_branch, |
| 47 | :issues_enabled, | 44 | :issues_enabled, |
spec/controllers/commits_controller_spec.rb
| @@ -13,7 +13,7 @@ describe CommitsController do | @@ -13,7 +13,7 @@ describe CommitsController do | ||
| 13 | describe "GET show" do | 13 | describe "GET show" do |
| 14 | context "as atom feed" do | 14 | context "as atom feed" do |
| 15 | it "should render as atom" do | 15 | it "should render as atom" do |
| 16 | - get :show, project_id: project.code, id: "master.atom" | 16 | + get :show, project_id: project.path, id: "master.atom" |
| 17 | response.should be_success | 17 | response.should be_success |
| 18 | response.content_type.should == 'application/atom+xml' | 18 | response.content_type.should == 'application/atom+xml' |
| 19 | end | 19 | end |
spec/factories.rb
| @@ -12,7 +12,7 @@ FactoryGirl.define do | @@ -12,7 +12,7 @@ FactoryGirl.define do | ||
| 12 | factory :user, aliases: [:author, :assignee, :owner] do | 12 | factory :user, aliases: [:author, :assignee, :owner] do |
| 13 | email { Faker::Internet.email } | 13 | email { Faker::Internet.email } |
| 14 | name | 14 | name |
| 15 | - username 'john' | 15 | + username { Faker::Internet.user_name } |
| 16 | password "123456" | 16 | password "123456" |
| 17 | password_confirmation { password } | 17 | password_confirmation { password } |
| 18 | 18 |
spec/mailers/notify_spec.rb
| @@ -169,9 +169,7 @@ describe Notify do | @@ -169,9 +169,7 @@ describe Notify do | ||
| 169 | end | 169 | end |
| 170 | 170 | ||
| 171 | describe 'project access changed' do | 171 | describe 'project access changed' do |
| 172 | - let(:project) { create(:project, | ||
| 173 | - path: "Fuu", | ||
| 174 | - code: "Fuu") } | 172 | + let(:project) { create(:project) } |
| 175 | let(:user) { create(:user) } | 173 | let(:user) { create(:user) } |
| 176 | let(:users_project) { create(:users_project, | 174 | let(:users_project) { create(:users_project, |
| 177 | project: project, | 175 | project: project, |
spec/observers/user_observer_spec.rb
| @@ -13,7 +13,12 @@ describe UserObserver do | @@ -13,7 +13,12 @@ describe UserObserver do | ||
| 13 | end | 13 | end |
| 14 | 14 | ||
| 15 | context 'when a new user is created' do | 15 | context 'when a new user is created' do |
| 16 | - let(:user) { double(:user, id: 42, password: 'P@ssword!', name: 'John', email: 'u@mail.local', username: 'root') } | 16 | + let(:user) { double(:user, id: 42, |
| 17 | + password: 'P@ssword!', | ||
| 18 | + name: 'John', | ||
| 19 | + email: 'u@mail.local', | ||
| 20 | + username: 'root', | ||
| 21 | + create_namespace: true) } | ||
| 17 | let(:notification) { double :notification } | 22 | let(:notification) { double :notification } |
| 18 | 23 | ||
| 19 | it 'sends an email' do | 24 | it 'sends an email' do |
spec/observers/users_project_observer_spec.rb
| @@ -2,9 +2,7 @@ require 'spec_helper' | @@ -2,9 +2,7 @@ require 'spec_helper' | ||
| 2 | 2 | ||
| 3 | describe UsersProjectObserver do | 3 | describe UsersProjectObserver do |
| 4 | let(:user) { create(:user) } | 4 | let(:user) { create(:user) } |
| 5 | - let(:project) { create(:project, | ||
| 6 | - code: "Fuu", | ||
| 7 | - path: "Fuu" ) } | 5 | + let(:project) { create(:project) } |
| 8 | let(:users_project) { create(:users_project, | 6 | let(:users_project) { create(:users_project, |
| 9 | project: project, | 7 | project: project, |
| 10 | user: user )} | 8 | user: user )} |
spec/requests/admin/admin_hooks_spec.rb
| @@ -2,9 +2,7 @@ require 'spec_helper' | @@ -2,9 +2,7 @@ require 'spec_helper' | ||
| 2 | 2 | ||
| 3 | describe "Admin::Hooks" do | 3 | describe "Admin::Hooks" do |
| 4 | before do | 4 | before do |
| 5 | - @project = create(:project, | ||
| 6 | - name: "LeGiT", | ||
| 7 | - code: "LGT") | 5 | + @project = create(:project) |
| 8 | login_as :admin | 6 | login_as :admin |
| 9 | 7 | ||
| 10 | @system_hook = create(:system_hook) | 8 | @system_hook = create(:system_hook) |
spec/requests/admin/admin_projects_spec.rb
| @@ -39,8 +39,8 @@ describe "Admin::Projects" do | @@ -39,8 +39,8 @@ describe "Admin::Projects" do | ||
| 39 | end | 39 | end |
| 40 | 40 | ||
| 41 | it "should have project edit page" do | 41 | it "should have project edit page" do |
| 42 | - page.should have_content("Project name") | ||
| 43 | - page.should have_content("URL") | 42 | + page.should have_content("Edit project") |
| 43 | + page.should have_button("Save Project") | ||
| 44 | end | 44 | end |
| 45 | 45 | ||
| 46 | describe "Update project" do | 46 | describe "Update project" do |
| @@ -60,39 +60,6 @@ describe "Admin::Projects" do | @@ -60,39 +60,6 @@ describe "Admin::Projects" do | ||
| 60 | end | 60 | end |
| 61 | end | 61 | end |
| 62 | 62 | ||
| 63 | - describe "GET /admin/projects/new" do | ||
| 64 | - before do | ||
| 65 | - visit admin_projects_path | ||
| 66 | - click_link "New Project" | ||
| 67 | - end | ||
| 68 | - | ||
| 69 | - it "should be correct path" do | ||
| 70 | - current_path.should == new_admin_project_path | ||
| 71 | - end | ||
| 72 | - | ||
| 73 | - it "should have labels for new project" do | ||
| 74 | - page.should have_content("Project name is") | ||
| 75 | - end | ||
| 76 | - end | ||
| 77 | - | ||
| 78 | - describe "POST /admin/projects" do | ||
| 79 | - before do | ||
| 80 | - visit new_admin_project_path | ||
| 81 | - fill_in 'project_name', with: 'NewProject' | ||
| 82 | - expect { click_button "Create project" }.to change { Project.count }.by(1) | ||
| 83 | - @project = Project.last | ||
| 84 | - end | ||
| 85 | - | ||
| 86 | - it "should be correct path" do | ||
| 87 | - current_path.should == admin_project_path(@project) | ||
| 88 | - end | ||
| 89 | - | ||
| 90 | - it "should show project" do | ||
| 91 | - page.should have_content(@project.name) | ||
| 92 | - page.should have_content(@project.path) | ||
| 93 | - end | ||
| 94 | - end | ||
| 95 | - | ||
| 96 | describe "Add new team member" do | 63 | describe "Add new team member" do |
| 97 | before do | 64 | before do |
| 98 | @new_user = create(:user) | 65 | @new_user = create(:user) |
spec/requests/admin/admin_users_spec.rb
| @@ -23,6 +23,7 @@ describe "Admin::Users" do | @@ -23,6 +23,7 @@ describe "Admin::Users" do | ||
| 23 | @password = "123ABC" | 23 | @password = "123ABC" |
| 24 | visit new_admin_user_path | 24 | visit new_admin_user_path |
| 25 | fill_in "user_name", with: "Big Bang" | 25 | fill_in "user_name", with: "Big Bang" |
| 26 | + fill_in "user_username", with: "bang" | ||
| 26 | fill_in "user_email", with: "bigbang@mail.com" | 27 | fill_in "user_email", with: "bigbang@mail.com" |
| 27 | fill_in "user_password", with: @password | 28 | fill_in "user_password", with: @password |
| 28 | fill_in "user_password_confirmation", with: @password | 29 | fill_in "user_password_confirmation", with: @password |
spec/requests/api/milestones_spec.rb
| @@ -11,7 +11,7 @@ describe Gitlab::API do | @@ -11,7 +11,7 @@ describe Gitlab::API do | ||
| 11 | 11 | ||
| 12 | describe "GET /projects/:id/milestones" do | 12 | describe "GET /projects/:id/milestones" do |
| 13 | it "should return project milestones" do | 13 | it "should return project milestones" do |
| 14 | - get api("/projects/#{project.code}/milestones", user) | 14 | + get api("/projects/#{project.path}/milestones", user) |
| 15 | response.status.should == 200 | 15 | response.status.should == 200 |
| 16 | json_response.should be_an Array | 16 | json_response.should be_an Array |
| 17 | json_response.first['title'].should == milestone.title | 17 | json_response.first['title'].should == milestone.title |
| @@ -20,7 +20,7 @@ describe Gitlab::API do | @@ -20,7 +20,7 @@ describe Gitlab::API do | ||
| 20 | 20 | ||
| 21 | describe "GET /projects/:id/milestones/:milestone_id" do | 21 | describe "GET /projects/:id/milestones/:milestone_id" do |
| 22 | it "should return a project milestone by id" do | 22 | it "should return a project milestone by id" do |
| 23 | - get api("/projects/#{project.code}/milestones/#{milestone.id}", user) | 23 | + get api("/projects/#{project.path}/milestones/#{milestone.id}", user) |
| 24 | response.status.should == 200 | 24 | response.status.should == 200 |
| 25 | json_response['title'].should == milestone.title | 25 | json_response['title'].should == milestone.title |
| 26 | end | 26 | end |
| @@ -28,7 +28,7 @@ describe Gitlab::API do | @@ -28,7 +28,7 @@ describe Gitlab::API do | ||
| 28 | 28 | ||
| 29 | describe "POST /projects/:id/milestones" do | 29 | describe "POST /projects/:id/milestones" do |
| 30 | it "should create a new project milestone" do | 30 | it "should create a new project milestone" do |
| 31 | - post api("/projects/#{project.code}/milestones", user), | 31 | + post api("/projects/#{project.path}/milestones", user), |
| 32 | title: 'new milestone' | 32 | title: 'new milestone' |
| 33 | response.status.should == 201 | 33 | response.status.should == 201 |
| 34 | json_response['title'].should == 'new milestone' | 34 | json_response['title'].should == 'new milestone' |
| @@ -38,7 +38,7 @@ describe Gitlab::API do | @@ -38,7 +38,7 @@ describe Gitlab::API do | ||
| 38 | 38 | ||
| 39 | describe "PUT /projects/:id/milestones/:milestone_id" do | 39 | describe "PUT /projects/:id/milestones/:milestone_id" do |
| 40 | it "should update a project milestone" do | 40 | it "should update a project milestone" do |
| 41 | - put api("/projects/#{project.code}/milestones/#{milestone.id}", user), | 41 | + put api("/projects/#{project.path}/milestones/#{milestone.id}", user), |
| 42 | title: 'updated title' | 42 | title: 'updated title' |
| 43 | response.status.should == 200 | 43 | response.status.should == 200 |
| 44 | json_response['title'].should == 'updated title' | 44 | json_response['title'].should == 'updated title' |
spec/requests/api/projects_spec.rb
| @@ -53,7 +53,6 @@ describe Gitlab::API do | @@ -53,7 +53,6 @@ describe Gitlab::API do | ||
| 53 | 53 | ||
| 54 | it "should assign attributes to project" do | 54 | it "should assign attributes to project" do |
| 55 | project = attributes_for(:project, { | 55 | project = attributes_for(:project, { |
| 56 | - path: project.name.parameterize, | ||
| 57 | description: Faker::Lorem.sentence, | 56 | description: Faker::Lorem.sentence, |
| 58 | default_branch: 'stable', | 57 | default_branch: 'stable', |
| 59 | issues_enabled: false, | 58 | issues_enabled: false, |
| @@ -257,7 +256,7 @@ describe Gitlab::API do | @@ -257,7 +256,7 @@ describe Gitlab::API do | ||
| 257 | describe "POST /projects/:id/snippets" do | 256 | describe "POST /projects/:id/snippets" do |
| 258 | it "should create a new project snippet" do | 257 | it "should create a new project snippet" do |
| 259 | post api("/projects/#{project.path}/snippets", user), | 258 | post api("/projects/#{project.path}/snippets", user), |
| 260 | - title: 'api test', file_name: 'sample.rb', path: 'test' | 259 | + title: 'api test', file_name: 'sample.rb', code: 'test' |
| 261 | response.status.should == 201 | 260 | response.status.should == 201 |
| 262 | json_response['title'].should == 'api test' | 261 | json_response['title'].should == 'api test' |
| 263 | end | 262 | end |
| @@ -266,10 +265,10 @@ describe Gitlab::API do | @@ -266,10 +265,10 @@ describe Gitlab::API do | ||
| 266 | describe "PUT /projects/:id/snippets/:shippet_id" do | 265 | describe "PUT /projects/:id/snippets/:shippet_id" do |
| 267 | it "should update an existing project snippet" do | 266 | it "should update an existing project snippet" do |
| 268 | put api("/projects/#{project.path}/snippets/#{snippet.id}", user), | 267 | put api("/projects/#{project.path}/snippets/#{snippet.id}", user), |
| 269 | - path: 'updated path' | 268 | + code: 'updated code' |
| 270 | response.status.should == 200 | 269 | response.status.should == 200 |
| 271 | json_response['title'].should == 'example' | 270 | json_response['title'].should == 'example' |
| 272 | - snippet.reload.content.should == 'updated path' | 271 | + snippet.reload.content.should == 'updated code' |
| 273 | end | 272 | end |
| 274 | end | 273 | end |
| 275 | 274 |