Improve forms and specs

This commit is contained in:
Kamil Trzcinski 2016-06-15 12:07:06 +02:00
parent 2541e50d7c
commit 0052644009
6 changed files with 22 additions and 20 deletions

View file

@ -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

View file

@ -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,

View file

@ -0,0 +1,7 @@
= 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'

View file

@ -1,16 +1,9 @@
- @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'

View file

@ -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

View file

@ -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')