From 6ff2ac68a0c97ed01b2899ad4a11335d6a417d10 Mon Sep 17 00:00:00 2001 From: Heitor Reis Date: Mon, 23 Feb 2015 13:00:54 -0300 Subject: [PATCH] Removing whitespaces on the beginning and end of some of the fields before saving --- app/controllers/kalibro_configurations_controller.rb | 1 + app/controllers/projects_controller.rb | 1 + app/controllers/reading_groups_controller.rb | 1 + app/controllers/readings_controller.rb | 1 + app/controllers/repositories_controller.rb | 1 + config/initializers/devise.rb | 2 +- features/kalibro_configuration/create.feature | 10 ++++++++++ features/project/create.feature | 12 ++++++++++++ features/reading/new.feature | 15 +++++++++++++++ features/reading_group/create.feature | 15 +++++++++++++-- features/repository/create.feature | 17 +++++++++++++++++ spec/controllers/repositories_controller_spec.rb | 6 +++--- 12 files changed, 76 insertions(+), 6 deletions(-) diff --git a/app/controllers/kalibro_configurations_controller.rb b/app/controllers/kalibro_configurations_controller.rb index 833be57..78a15f6 100644 --- a/app/controllers/kalibro_configurations_controller.rb +++ b/app/controllers/kalibro_configurations_controller.rb @@ -71,6 +71,7 @@ class KalibroConfigurationsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def kalibro_configuration_params + params[:kalibro_configuration][:name].strip! params[:kalibro_configuration] end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 29000af..7453aff 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -73,6 +73,7 @@ class ProjectsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def project_params + params[:project][:name].strip! params[:project] end diff --git a/app/controllers/reading_groups_controller.rb b/app/controllers/reading_groups_controller.rb index 57784e3..bccbc3e 100644 --- a/app/controllers/reading_groups_controller.rb +++ b/app/controllers/reading_groups_controller.rb @@ -62,6 +62,7 @@ class ReadingGroupsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def reading_group_params + params[:reading_group][:name].strip! params[:reading_group] end diff --git a/app/controllers/readings_controller.rb b/app/controllers/readings_controller.rb index 0dbc8e9..26b9ce9 100644 --- a/app/controllers/readings_controller.rb +++ b/app/controllers/readings_controller.rb @@ -50,6 +50,7 @@ class ReadingsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def reading_params + params[:reading][:label].strip! params[:reading] end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index a52d95a..fe9866d 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -115,6 +115,7 @@ private # Never trust parameters from the scary internet, only allow the white list through. def repository_params + params[:repository][:name].strip! params[:repository][:address].strip! params[:repository] end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 6f6a1fc..cfa6393 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -45,7 +45,7 @@ Devise.setup do |config| # Configure which authentication keys should have whitespace stripped. # These keys will have whitespace before and after removed upon creating or # modifying a user and when used to authenticate or find a user. Default is :email. - config.strip_whitespace_keys = [ :email ] + config.strip_whitespace_keys = [ :email, :name ] # Tell if authentication through request.params is enabled. True by default. # It can be set to an array that will enable params authentication only for the diff --git a/features/kalibro_configuration/create.feature b/features/kalibro_configuration/create.feature index bb5fb34..872e1c1 100644 --- a/features/kalibro_configuration/create.feature +++ b/features/kalibro_configuration/create.feature @@ -39,3 +39,13 @@ Feature: Configuration Creation And I fill the Description field with "Web Service to collect metrics" When I press the Save button Then I should see "Name can't be blank" + + @kalibro_configuration_restart + Scenario: configuration name with whitespaces + Given I am a regular user + And I am signed in + And I have a configuration named "Kalibro Metrics" + And I am at the New Configuration page + And I fill the Name field with " Kalibro Metrics " + When I press the Save button + Then I should see "Name has already been taken" diff --git a/features/project/create.feature b/features/project/create.feature index 756eec2..1f8802d 100644 --- a/features/project/create.feature +++ b/features/project/create.feature @@ -45,3 +45,15 @@ Feature: Project Creation And I click the Your projects link When I click the New Project link Then I should see "New Project" + + @kalibro_processor_restart + Scenario: Choosing a name with whitespaces on the beginning and end + Given I am a regular user + And I am signed in + And I have a project named "Kalibro Metrics" + And I am at the New Project page + And I fill the Name field with " Kalibro Metrics " + And I fill the Description field with "Web Service to collect metrics" + When I press the Save button + Then I should see "Name has already been taken" + diff --git a/features/reading/new.feature b/features/reading/new.feature index bb46204..b80d6c2 100644 --- a/features/reading/new.feature +++ b/features/reading/new.feature @@ -89,3 +89,18 @@ Feature: New reading When I press the Save button Then I should see "Color must be hexadecimal" And I should be at the New Reading page + + @kalibro_configuration_restart + Scenario: Label with whitespaces + Given I am a regular user + And I am signed in + And I own a sample reading group + And I have a sample reading within the sample reading group labeled "My Reading" + And I am at the New Reading page + And I fill the Label field with " My Reading " + And I fill the Grade field with "10" + And I fill the Color field with "ffff00" + When I press the Save button + Then I should see "Label Should be unique within a Reading Group" + And I should be at the New Reading page + diff --git a/features/reading_group/create.feature b/features/reading_group/create.feature index bf67146..110067d 100644 --- a/features/reading_group/create.feature +++ b/features/reading_group/create.feature @@ -22,7 +22,7 @@ Scenario: Reading Group creation And I should see "Destroy Reading Group" @kalibro_configuration_restart -Scenario: reading group creation with already taken name +Scenario: Reading Group creation with already taken name Given I am a regular user And I am signed in And I have a reading group named "Group" @@ -33,7 +33,7 @@ Scenario: reading group creation with already taken name Then I should see "Name has already been taken" @kalibro_configuration_restart -Scenario: reading group creation with blank name +Scenario: Reading Group creation with blank name Given I am a regular user And I am signed in And I am at the New Reading Group page @@ -41,3 +41,14 @@ Scenario: reading group creation with blank name And I fill the Description field with "Anything" When I press the Save button Then I should see "Name can't be blank" + +@kalibro_configuration_restart +Scenario: Reading Group name with whitespaces + Given I am a regular user + And I am signed in + And I have a reading group named "Reading Group" + And I am at the New Reading Group page + And I fill the Name field with " Reading Group " + When I press the Save button + Then I should see "Name has already been taken" + diff --git a/features/repository/create.feature b/features/repository/create.feature index 3fbe19d..057ca11 100644 --- a/features/repository/create.feature +++ b/features/repository/create.feature @@ -54,3 +54,20 @@ Scenario: repository creation with name already taken And I set the select field "repository_kalibro_configuration_id" as "Java" When I press the Save button Then I should see "Name should be unique within project" + +@kalibro_configuration_restart @kalibro_processor_restart @javascript +Scenario: Repository name with whitespaces + Given I am a regular user + And I am signed in + And I own a sample project + And I have a sample configuration with native metrics + And I have a sample repository within the sample project named "Kalibro Entities" + And I am at the New Repository page + And I fill the Name field with " Kalibro Entities " + And I set the select field "License" as "ISC License (ISC)" + And I set the select field "Type" as "GIT" + And I fill the Address field with "https://github.com/mezuro/kalibro_gem.git" + And I set the select field "Process Period" as "1 day" + And I set the select field "repository_kalibro_configuration_id" as "Java" + When I press the Save button + Then I should see "Name should be unique within project" diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb index 8a765f2..54d2012 100644 --- a/spec/controllers/repositories_controller_spec.rb +++ b/spec/controllers/repositories_controller_spec.rb @@ -21,7 +21,7 @@ describe RepositoriesController, :type => :controller do it { is_expected.to render_template(:new) } end - context "when the current user doesn't owns the project" do + context "when the current user doesn't own the project" do before :each do get :new, project_id: project.id.to_s end @@ -42,7 +42,7 @@ describe RepositoriesController, :type => :controller do describe 'create' do let (:repository) { FactoryGirl.build(:repository, project_id: project.id) } - let(:repository_params) { Hash[FactoryGirl.attributes_for(:repository).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers + let(:repository_params) { FactoryGirl.build(:repository).to_hash } before do sign_in FactoryGirl.create(:user) @@ -76,7 +76,7 @@ describe RepositoriesController, :type => :controller do end end - context "when the current user doesn't owns the project " do + context "when the current user doesn't own the project " do before :each do post :create, project_id: project.id, repository: repository_params end -- libgit2 0.21.2