Commit 6ff2ac68a0c97ed01b2899ad4a11335d6a417d10
1 parent
8147529e
Exists in
colab
and in
4 other branches
Removing whitespaces on the beginning and end of some of the fields before saving
Signed off by: Daniel Alves <danpaulalves@gmail.com>
Showing
12 changed files
with
76 additions
and
6 deletions
Show diff stats
app/controllers/kalibro_configurations_controller.rb
| @@ -71,6 +71,7 @@ class KalibroConfigurationsController < ApplicationController | @@ -71,6 +71,7 @@ class KalibroConfigurationsController < ApplicationController | ||
| 71 | 71 | ||
| 72 | # Never trust parameters from the scary internet, only allow the white list through. | 72 | # Never trust parameters from the scary internet, only allow the white list through. |
| 73 | def kalibro_configuration_params | 73 | def kalibro_configuration_params |
| 74 | + params[:kalibro_configuration][:name].strip! | ||
| 74 | params[:kalibro_configuration] | 75 | params[:kalibro_configuration] |
| 75 | end | 76 | end |
| 76 | 77 |
app/controllers/projects_controller.rb
| @@ -73,6 +73,7 @@ class ProjectsController < ApplicationController | @@ -73,6 +73,7 @@ class ProjectsController < ApplicationController | ||
| 73 | 73 | ||
| 74 | # Never trust parameters from the scary internet, only allow the white list through. | 74 | # Never trust parameters from the scary internet, only allow the white list through. |
| 75 | def project_params | 75 | def project_params |
| 76 | + params[:project][:name].strip! | ||
| 76 | params[:project] | 77 | params[:project] |
| 77 | end | 78 | end |
| 78 | 79 |
app/controllers/reading_groups_controller.rb
| @@ -62,6 +62,7 @@ class ReadingGroupsController < ApplicationController | @@ -62,6 +62,7 @@ class ReadingGroupsController < ApplicationController | ||
| 62 | 62 | ||
| 63 | # Never trust parameters from the scary internet, only allow the white list through. | 63 | # Never trust parameters from the scary internet, only allow the white list through. |
| 64 | def reading_group_params | 64 | def reading_group_params |
| 65 | + params[:reading_group][:name].strip! | ||
| 65 | params[:reading_group] | 66 | params[:reading_group] |
| 66 | end | 67 | end |
| 67 | 68 |
app/controllers/readings_controller.rb
| @@ -50,6 +50,7 @@ class ReadingsController < ApplicationController | @@ -50,6 +50,7 @@ class ReadingsController < ApplicationController | ||
| 50 | 50 | ||
| 51 | # Never trust parameters from the scary internet, only allow the white list through. | 51 | # Never trust parameters from the scary internet, only allow the white list through. |
| 52 | def reading_params | 52 | def reading_params |
| 53 | + params[:reading][:label].strip! | ||
| 53 | params[:reading] | 54 | params[:reading] |
| 54 | end | 55 | end |
| 55 | 56 |
app/controllers/repositories_controller.rb
| @@ -115,6 +115,7 @@ private | @@ -115,6 +115,7 @@ private | ||
| 115 | 115 | ||
| 116 | # Never trust parameters from the scary internet, only allow the white list through. | 116 | # Never trust parameters from the scary internet, only allow the white list through. |
| 117 | def repository_params | 117 | def repository_params |
| 118 | + params[:repository][:name].strip! | ||
| 118 | params[:repository][:address].strip! | 119 | params[:repository][:address].strip! |
| 119 | params[:repository] | 120 | params[:repository] |
| 120 | end | 121 | end |
config/initializers/devise.rb
| @@ -45,7 +45,7 @@ Devise.setup do |config| | @@ -45,7 +45,7 @@ Devise.setup do |config| | ||
| 45 | # Configure which authentication keys should have whitespace stripped. | 45 | # Configure which authentication keys should have whitespace stripped. |
| 46 | # These keys will have whitespace before and after removed upon creating or | 46 | # These keys will have whitespace before and after removed upon creating or |
| 47 | # modifying a user and when used to authenticate or find a user. Default is :email. | 47 | # modifying a user and when used to authenticate or find a user. Default is :email. |
| 48 | - config.strip_whitespace_keys = [ :email ] | 48 | + config.strip_whitespace_keys = [ :email, :name ] |
| 49 | 49 | ||
| 50 | # Tell if authentication through request.params is enabled. True by default. | 50 | # Tell if authentication through request.params is enabled. True by default. |
| 51 | # It can be set to an array that will enable params authentication only for the | 51 | # It can be set to an array that will enable params authentication only for the |
features/kalibro_configuration/create.feature
| @@ -39,3 +39,13 @@ Feature: Configuration Creation | @@ -39,3 +39,13 @@ Feature: Configuration Creation | ||
| 39 | And I fill the Description field with "Web Service to collect metrics" | 39 | And I fill the Description field with "Web Service to collect metrics" |
| 40 | When I press the Save button | 40 | When I press the Save button |
| 41 | Then I should see "Name can't be blank" | 41 | Then I should see "Name can't be blank" |
| 42 | + | ||
| 43 | + @kalibro_configuration_restart | ||
| 44 | + Scenario: configuration name with whitespaces | ||
| 45 | + Given I am a regular user | ||
| 46 | + And I am signed in | ||
| 47 | + And I have a configuration named "Kalibro Metrics" | ||
| 48 | + And I am at the New Configuration page | ||
| 49 | + And I fill the Name field with " Kalibro Metrics " | ||
| 50 | + When I press the Save button | ||
| 51 | + Then I should see "Name has already been taken" |
features/project/create.feature
| @@ -45,3 +45,15 @@ Feature: Project Creation | @@ -45,3 +45,15 @@ Feature: Project Creation | ||
| 45 | And I click the Your projects link | 45 | And I click the Your projects link |
| 46 | When I click the New Project link | 46 | When I click the New Project link |
| 47 | Then I should see "New Project" | 47 | Then I should see "New Project" |
| 48 | + | ||
| 49 | + @kalibro_processor_restart | ||
| 50 | + Scenario: Choosing a name with whitespaces on the beginning and end | ||
| 51 | + Given I am a regular user | ||
| 52 | + And I am signed in | ||
| 53 | + And I have a project named "Kalibro Metrics" | ||
| 54 | + And I am at the New Project page | ||
| 55 | + And I fill the Name field with " Kalibro Metrics " | ||
| 56 | + And I fill the Description field with "Web Service to collect metrics" | ||
| 57 | + When I press the Save button | ||
| 58 | + Then I should see "Name has already been taken" | ||
| 59 | + |
features/reading/new.feature
| @@ -89,3 +89,18 @@ Feature: New reading | @@ -89,3 +89,18 @@ Feature: New reading | ||
| 89 | When I press the Save button | 89 | When I press the Save button |
| 90 | Then I should see "Color must be hexadecimal" | 90 | Then I should see "Color must be hexadecimal" |
| 91 | And I should be at the New Reading page | 91 | And I should be at the New Reading page |
| 92 | + | ||
| 93 | + @kalibro_configuration_restart | ||
| 94 | + Scenario: Label with whitespaces | ||
| 95 | + Given I am a regular user | ||
| 96 | + And I am signed in | ||
| 97 | + And I own a sample reading group | ||
| 98 | + And I have a sample reading within the sample reading group labeled "My Reading" | ||
| 99 | + And I am at the New Reading page | ||
| 100 | + And I fill the Label field with " My Reading " | ||
| 101 | + And I fill the Grade field with "10" | ||
| 102 | + And I fill the Color field with "ffff00" | ||
| 103 | + When I press the Save button | ||
| 104 | + Then I should see "Label Should be unique within a Reading Group" | ||
| 105 | + And I should be at the New Reading page | ||
| 106 | + |
features/reading_group/create.feature
| @@ -22,7 +22,7 @@ Scenario: Reading Group creation | @@ -22,7 +22,7 @@ Scenario: Reading Group creation | ||
| 22 | And I should see "Destroy Reading Group" | 22 | And I should see "Destroy Reading Group" |
| 23 | 23 | ||
| 24 | @kalibro_configuration_restart | 24 | @kalibro_configuration_restart |
| 25 | -Scenario: reading group creation with already taken name | 25 | +Scenario: Reading Group creation with already taken name |
| 26 | Given I am a regular user | 26 | Given I am a regular user |
| 27 | And I am signed in | 27 | And I am signed in |
| 28 | And I have a reading group named "Group" | 28 | And I have a reading group named "Group" |
| @@ -33,7 +33,7 @@ Scenario: reading group creation with already taken name | @@ -33,7 +33,7 @@ Scenario: reading group creation with already taken name | ||
| 33 | Then I should see "Name has already been taken" | 33 | Then I should see "Name has already been taken" |
| 34 | 34 | ||
| 35 | @kalibro_configuration_restart | 35 | @kalibro_configuration_restart |
| 36 | -Scenario: reading group creation with blank name | 36 | +Scenario: Reading Group creation with blank name |
| 37 | Given I am a regular user | 37 | Given I am a regular user |
| 38 | And I am signed in | 38 | And I am signed in |
| 39 | And I am at the New Reading Group page | 39 | And I am at the New Reading Group page |
| @@ -41,3 +41,14 @@ Scenario: reading group creation with blank name | @@ -41,3 +41,14 @@ Scenario: reading group creation with blank name | ||
| 41 | And I fill the Description field with "Anything" | 41 | And I fill the Description field with "Anything" |
| 42 | When I press the Save button | 42 | When I press the Save button |
| 43 | Then I should see "Name can't be blank" | 43 | Then I should see "Name can't be blank" |
| 44 | + | ||
| 45 | +@kalibro_configuration_restart | ||
| 46 | +Scenario: Reading Group name with whitespaces | ||
| 47 | + Given I am a regular user | ||
| 48 | + And I am signed in | ||
| 49 | + And I have a reading group named "Reading Group" | ||
| 50 | + And I am at the New Reading Group page | ||
| 51 | + And I fill the Name field with " Reading Group " | ||
| 52 | + When I press the Save button | ||
| 53 | + Then I should see "Name has already been taken" | ||
| 54 | + |
features/repository/create.feature
| @@ -54,3 +54,20 @@ Scenario: repository creation with name already taken | @@ -54,3 +54,20 @@ Scenario: repository creation with name already taken | ||
| 54 | And I set the select field "repository_kalibro_configuration_id" as "Java" | 54 | And I set the select field "repository_kalibro_configuration_id" as "Java" |
| 55 | When I press the Save button | 55 | When I press the Save button |
| 56 | Then I should see "Name should be unique within project" | 56 | Then I should see "Name should be unique within project" |
| 57 | + | ||
| 58 | +@kalibro_configuration_restart @kalibro_processor_restart @javascript | ||
| 59 | +Scenario: Repository name with whitespaces | ||
| 60 | + Given I am a regular user | ||
| 61 | + And I am signed in | ||
| 62 | + And I own a sample project | ||
| 63 | + And I have a sample configuration with native metrics | ||
| 64 | + And I have a sample repository within the sample project named "Kalibro Entities" | ||
| 65 | + And I am at the New Repository page | ||
| 66 | + And I fill the Name field with " Kalibro Entities " | ||
| 67 | + And I set the select field "License" as "ISC License (ISC)" | ||
| 68 | + And I set the select field "Type" as "GIT" | ||
| 69 | + And I fill the Address field with "https://github.com/mezuro/kalibro_gem.git" | ||
| 70 | + And I set the select field "Process Period" as "1 day" | ||
| 71 | + And I set the select field "repository_kalibro_configuration_id" as "Java" | ||
| 72 | + When I press the Save button | ||
| 73 | + Then I should see "Name should be unique within project" |
spec/controllers/repositories_controller_spec.rb
| @@ -21,7 +21,7 @@ describe RepositoriesController, :type => :controller do | @@ -21,7 +21,7 @@ describe RepositoriesController, :type => :controller do | ||
| 21 | it { is_expected.to render_template(:new) } | 21 | it { is_expected.to render_template(:new) } |
| 22 | end | 22 | end |
| 23 | 23 | ||
| 24 | - context "when the current user doesn't owns the project" do | 24 | + context "when the current user doesn't own the project" do |
| 25 | before :each do | 25 | before :each do |
| 26 | get :new, project_id: project.id.to_s | 26 | get :new, project_id: project.id.to_s |
| 27 | end | 27 | end |
| @@ -42,7 +42,7 @@ describe RepositoriesController, :type => :controller do | @@ -42,7 +42,7 @@ describe RepositoriesController, :type => :controller do | ||
| 42 | 42 | ||
| 43 | describe 'create' do | 43 | describe 'create' do |
| 44 | let (:repository) { FactoryGirl.build(:repository, project_id: project.id) } | 44 | let (:repository) { FactoryGirl.build(:repository, project_id: project.id) } |
| 45 | - 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 | 45 | + let(:repository_params) { FactoryGirl.build(:repository).to_hash } |
| 46 | 46 | ||
| 47 | before do | 47 | before do |
| 48 | sign_in FactoryGirl.create(:user) | 48 | sign_in FactoryGirl.create(:user) |
| @@ -76,7 +76,7 @@ describe RepositoriesController, :type => :controller do | @@ -76,7 +76,7 @@ describe RepositoriesController, :type => :controller do | ||
| 76 | end | 76 | end |
| 77 | end | 77 | end |
| 78 | 78 | ||
| 79 | - context "when the current user doesn't owns the project " do | 79 | + context "when the current user doesn't own the project " do |
| 80 | before :each do | 80 | before :each do |
| 81 | post :create, project_id: project.id, repository: repository_params | 81 | post :create, project_id: project.id, repository: repository_params |
| 82 | end | 82 | end |