Commit 00526440 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Improve forms and specs

parent 2541e50d
No related merge requests found
...@@ -10,7 +10,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -10,7 +10,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end end
def show def show
@deployments = environment.deployments.order(id: :desc).page(params[:page]).per(30) @deployments = environment.deployments.order(id: :desc).page(params[:page])
end end
def new def new
...@@ -44,6 +44,6 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -44,6 +44,6 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end end
def environment def environment
@environment ||= project.environments.find_by!(id: params[:id]) @environment ||= project.environments.find(params[:id])
end end
end end
...@@ -251,7 +251,8 @@ class Ability ...@@ -251,7 +251,8 @@ class Ability
:create_container_image, :create_container_image,
:update_container_image, :update_container_image,
:create_environment, :create_environment,
:create_deployment :create_deployment,
:update_deployment
] ]
end end
...@@ -270,7 +271,6 @@ class Ability ...@@ -270,7 +271,6 @@ class Ability
:push_code_to_protected_branches, :push_code_to_protected_branches,
:update_project_snippet, :update_project_snippet,
:update_environment, :update_environment,
:update_deployment,
:admin_milestone, :admin_milestone,
:admin_project_snippet, :admin_project_snippet,
:admin_project_member, :admin_project_member,
......
= form_for @environment, url: namespace_project_environments_path(@project.namespace, @project), html: { class: 'col-lg-9' } do |f|
= form_errors(@environment)
.form-group
= f.label :name, 'Name', class: 'label-light'
= f.text_field :name, required: true, class: 'form-control'
= f.submit 'Create environment', class: 'btn btn-create'
= link_to 'Cancel', namespace_project_environments_path(@project.namespace, @project), class: 'btn btn-cancel'
- @no_container = true - page_title 'New Environment'
- page_title "New Environment"
= render "projects/pipelines/head"
.row.prepend-top-default.append-bottom-default .row.prepend-top-default.append-bottom-default
.col-lg-3 .col-lg-3
%h4.prepend-top-0 %h4.prepend-top-0
New Environment New Environment
%p Environments allow you to track deployments of your application
= form_for @environment, url: namespace_project_environments_path(@project.namespace, @project), html: { class: "col-lg-9" } do |f| = render 'form'
= form_errors(@environment)
.form-group
= f.label :name, 'Environment name', class: 'label-light'
= f.text_field :name, required: true, class: 'form-control'
= f.submit 'Create environment', class: 'btn btn-create'
= link_to "Cancel", namespace_project_environments_path(@project.namespace, @project), class: "btn btn-cancel"
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
.col-md-3 .col-md-3
.nav-controls .nav-controls
- if can?(current_user, :update_environment, @environment) - if can?(current_user, :update_environment, @environment)
= link_to 'Destroy', namespace_project_environment_path(@project.namespace, @project, @environment), data: { confirm: 'Are you sure?' }, class: 'btn btn-danger', method: :delete = link_to 'Destroy', namespace_project_environment_path(@project.namespace, @project, @environment), data: { confirm: 'Are you sure you want to delete this environment?' }, class: 'btn btn-danger', method: :delete
- if @deployments.blank? - if @deployments.blank?
%ul.content-list.environments %ul.content-list.environments
......
...@@ -107,7 +107,7 @@ describe 'Environments' do ...@@ -107,7 +107,7 @@ describe 'Environments' do
context 'for valid name' do context 'for valid name' do
before do before do
fill_in('Environment name', with: 'production') fill_in('Name', with: 'production')
click_on 'Create environment' click_on 'Create environment'
end end
...@@ -118,7 +118,7 @@ describe 'Environments' do ...@@ -118,7 +118,7 @@ describe 'Environments' do
context 'for invalid name' do context 'for invalid name' do
before do before do
fill_in('Environment name', with: 'name with spaces') fill_in('Name', with: 'name with spaces')
click_on 'Create environment' click_on 'Create environment'
end end
...@@ -140,7 +140,9 @@ describe 'Environments' do ...@@ -140,7 +140,9 @@ describe 'Environments' do
before { visit namespace_project_environment_path(project.namespace, project, environment) } before { visit namespace_project_environment_path(project.namespace, project, environment) }
context 'when logged as developer' do context 'when logged as master' do
let(:role) { :master }
before { click_link 'Destroy' } before { click_link 'Destroy' }
it 'does not have environment' do it 'does not have environment' do
...@@ -148,8 +150,8 @@ describe 'Environments' do ...@@ -148,8 +150,8 @@ describe 'Environments' do
end end
end end
context 'when logged as reporter' do context 'when logged as developer' do
let(:role) { :reporter } let(:role) { :developer }
it 'does not have a Destroy link' do it 'does not have a Destroy link' do
expect(page).not_to have_link('Destroy') expect(page).not_to have_link('Destroy')
......
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