Commit 00526440 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Improve forms and specs

parent 2541e50d
......@@ -10,7 +10,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end
def show
@deployments = environment.deployments.order(id: :desc).page(params[:page]).per(30)
@deployments = environment.deployments.order(id: :desc).page(params[:page])
end
def new
......@@ -44,6 +44,6 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end
def environment
@environment ||= project.environments.find_by!(id: params[:id])
@environment ||= project.environments.find(params[:id])
end
end
......@@ -251,7 +251,8 @@ class Ability
:create_container_image,
:update_container_image,
:create_environment,
:create_deployment
:create_deployment,
:update_deployment
]
end
......@@ -270,7 +271,6 @@ class Ability
:push_code_to_protected_branches,
:update_project_snippet,
:update_environment,
:update_deployment,
:admin_milestone,
:admin_project_snippet,
: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"
= render "projects/pipelines/head"
- page_title 'New Environment'
.row.prepend-top-default.append-bottom-default
.col-lg-3
%h4.prepend-top-0
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|
= 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"
= render 'form'
......@@ -10,7 +10,7 @@
.col-md-3
.nav-controls
- 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?
%ul.content-list.environments
......
......@@ -107,7 +107,7 @@ describe 'Environments' do
context 'for valid name' do
before do
fill_in('Environment name', with: 'production')
fill_in('Name', with: 'production')
click_on 'Create environment'
end
......@@ -118,7 +118,7 @@ describe 'Environments' do
context 'for invalid name' do
before do
fill_in('Environment name', with: 'name with spaces')
fill_in('Name', with: 'name with spaces')
click_on 'Create environment'
end
......@@ -140,7 +140,9 @@ describe 'Environments' do
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' }
it 'does not have environment' do
......@@ -148,8 +150,8 @@ describe 'Environments' do
end
end
context 'when logged as reporter' do
let(:role) { :reporter }
context 'when logged as developer' do
let(:role) { :developer }
it 'does not have a Destroy link' do
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