Skip to content

Commit

Permalink
Make prjconf a nested resource inside projects
Browse files Browse the repository at this point in the history
To simplify the routes, move the project/prjconf/:project routes to the
`resources :projects`
  • Loading branch information
vpereira committed Oct 2, 2019
1 parent d67c5a7 commit 724a0f1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/api/app/views/webui/project/prjconf.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
%h3= @pagetitle
- if User.possibly_nobody.can_modify?(@project)
= render partial: 'webui/shared/editor', locals: { text: @content, mode: 'prjconf',
save: { url: save_project_config_path, method: :post,
data: { project: @project.name, submit: 'config' } } }
save: { url: project_config_path, method: :put,
data: { project_name: @project.name, submit: 'config' } } }
- else
= render partial: 'webui/shared/editor', locals: { text: @content, mode: 'prjconf', style: { read_only: true } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
%h3= @pagetitle
- if User.possibly_nobody.can_modify?(@project)
= render partial: 'webui/shared/editor', locals: { text: @content, mode: 'prjconf',
save: { url: save_project_config_path, method: :post,
data: { project: @project.name, submit: 'config' } } }
save: { url: project_config_path, method: :put,
data: { project_name: @project.name, submit: 'config' } } }
- else
= render partial: 'webui/shared/editor', locals: { text: @content, mode: 'prjconf', style: { read_only: true } }
6 changes: 1 addition & 5 deletions src/api/config/routes/webui_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,6 @@
end
end

controller 'webui/projects/project_configuration' do
get 'project/prjconf/:project' => :show, constraints: cons, as: :project_config
post 'project/save_prjconf/:project' => :update, constraints: cons, as: :save_project_config
end

controller 'webui/project' do
get 'project/' => :index, as: 'projects'
get 'project/list_public' => :index, as: 'project_list_public'
Expand Down Expand Up @@ -258,6 +253,7 @@
resource :ssl_certificate, controller: 'webui/projects/ssl_certificate', only: [:show], constraints: cons
resource :pulse, controller: 'webui/projects/pulse', only: [:show], constraints: cons
resource :meta, controller: 'webui/projects/meta', only: [:show, :update], constraints: cons
resource :prjconf, controller: 'webui/projects/project_configuration', only: [:show, :update], as: :config, constraints: cons
resource :rebuild_time, controller: 'webui/projects/rebuild_times', only: [:show], constraints: cons do
get 'rebuild_time_png'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
end

it { expect { get :show, params: { project: apache_project } }.not_to raise_error }
it { expect { get :show, params: { project_name: apache_project.name } }.not_to raise_error }
end

context 'Can not load project config' do
Expand All @@ -27,7 +27,7 @@
}
end

it { expect { get :show, params: { project: apache_project } }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect { get :show, params: { project_name: apache_project.name } }.to raise_error(ActiveRecord::RecordNotFound) }
end
end

Expand All @@ -41,7 +41,7 @@
allow(::ProjectConfigurationService::ProjectConfigurationUpdater).to receive(:new) {
-> { OpenStruct.new(saved?: true) }
}
post :update, params: { project: user.home_project.name, config: 'save config' }
post :update, params: { project_name: user.home_project.name, config: 'save config' }
end

it { expect(flash[:success]).to eq('Config successfully saved!') }
Expand All @@ -53,7 +53,7 @@
allow(::ProjectConfigurationService::ProjectConfigurationUpdater).to receive(:new) {
-> { OpenStruct.new(saved?: false, errors: 'yay') }
}
post :update, params: { project: user.home_project.name, config: '' }
post :update, params: { project_name: user.home_project.name, config: '' }
end

it { expect(flash[:error]).not_to be_nil }
Expand All @@ -62,7 +62,7 @@

context 'cannot save with an unauthorized user' do
before do
post :update, params: { project: another_project.name, config: 'save config' }
post :update, params: { project_name: another_project.name, config: 'save config' }
end

it { expect(flash[:error]).to eq('Sorry, you are not authorized to update this Project.') }
Expand All @@ -71,7 +71,7 @@
end

context 'with a non existing project' do
let(:post_update) { post :update, params: { project: 'non:existing:project', config: 'save config' } }
let(:post_update) { post :update, params: { project_name: 'non:existing:project', config: 'save config' } }

it 'raise a RecordNotFound Exception' do
expect { post_update }.to raise_error ActiveRecord::RecordNotFound
Expand Down

0 comments on commit 724a0f1

Please sign in to comment.