From 00526440092bb82beb86b87376dd1ea6178bf05f Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Wed, 15 Jun 2016 12:07:06 +0200 Subject: [PATCH] Improve forms and specs --- app/controllers/projects/environments_controller.rb | 4 ++-- app/models/ability.rb | 4 ++-- app/views/projects/environments/_form.html.haml | 7 +++++++ app/views/projects/environments/new.html.haml | 13 +++---------- app/views/projects/environments/show.html.haml | 2 +- spec/features/environments_spec.rb | 12 +++++++----- 6 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 app/views/projects/environments/_form.html.haml diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index 1f9f676c63b..4b433796161 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -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 diff --git a/app/models/ability.rb b/app/models/ability.rb index 32e45674682..734b152605b 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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, diff --git a/app/views/projects/environments/_form.html.haml b/app/views/projects/environments/_form.html.haml new file mode 100644 index 00000000000..c07f4bd510c --- /dev/null +++ b/app/views/projects/environments/_form.html.haml @@ -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' diff --git a/app/views/projects/environments/new.html.haml b/app/views/projects/environments/new.html.haml index 533f624c4e2..54465828ba9 100644 --- a/app/views/projects/environments/new.html.haml +++ b/app/views/projects/environments/new.html.haml @@ -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' diff --git a/app/views/projects/environments/show.html.haml b/app/views/projects/environments/show.html.haml index b41b1651a81..069b77b5adf 100644 --- a/app/views/projects/environments/show.html.haml +++ b/app/views/projects/environments/show.html.haml @@ -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 diff --git a/spec/features/environments_spec.rb b/spec/features/environments_spec.rb index b73bb30e216..8002b793986 100644 --- a/spec/features/environments_spec.rb +++ b/spec/features/environments_spec.rb @@ -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')