diff --git a/controllers/mpog_software_plugin_controller.rb b/controllers/mpog_software_plugin_controller.rb index 38baff3..f638760 100644 --- a/controllers/mpog_software_plugin_controller.rb +++ b/controllers/mpog_software_plugin_controller.rb @@ -173,6 +173,7 @@ class MpogSoftwarePluginController < ApplicationController if institution.cnpj.nil? or institution.cnpj.blank? institution.errors.add(:cnpj, _("can't be blank")) + return institution end InstitutionHelper.register_institution_modification institution diff --git a/test/functional/mpog_software_plugin_controller_test.rb b/test/functional/mpog_software_plugin_controller_test.rb index 6fc1574..7371f3a 100644 --- a/test/functional/mpog_software_plugin_controller_test.rb +++ b/test/functional/mpog_software_plugin_controller_test.rb @@ -72,6 +72,36 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase assert json_response["success"] end + should "create more than one institution without acronym" do + @controller.stubs(:verify_recaptcha).returns(true) + + xhr :get, :new_institution, + :authenticity_token=>"dsa45a6das52sd", + :name => "foo bar", + :community=>{:name=>"foo bar", :country => "BR", :state => "DF", :city => "Brasilia"}, + :governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id}, + :juridical => {:nature => @juridical_nature.id}, + :institution => {:cnpj=>"12.234.567/8900-10", :acronym=>"", :type=>"PublicInstitution"}, + :recaptcha_response_field=>'' + + json_response = ActiveSupport::JSON.decode(@response.body) + + assert json_response["success"] + + xhr :get, :new_institution, + :authenticity_token=>"dsa45a6das52sd", + :name => "foo bar 2", + :community=>{:name=>"foo bar 2", :country => "BR", :state => "DF", :city => "Brasilia"}, + :governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id}, + :juridical => {:nature => @juridical_nature.id}, + :institution => {:cnpj=>"12.224.567/8900-10", :acronym=>"", :type=>"PublicInstitution"}, + :recaptcha_response_field=>'' + + json_response = ActiveSupport::JSON.decode(@response.body) + + assert json_response["success"] + end + should "not create a institution that already exists" do @controller.stubs(:verify_recaptcha).returns(true) @@ -89,6 +119,23 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase assert !json_response["success"] end + should "not create a institution without cnpj" do + @controller.stubs(:verify_recaptcha).returns(true) + + xhr :get, :new_institution, + :authenticity_token=>"dsa45a6das52sd", + :name => "Ministerio Publico da Uniao", + :community=>{:name=>"Ministerio Publico da Uniao", :country => "BR", :state => "DF", :city => "Brasilia"}, + :governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id}, + :juridical => {:nature => @juridical_nature.id}, + :institution => {:cnpj=> "", :acronym=>"fb", :type=>"PublicInstitution"}, + :recaptcha_response_field=>'' + + json_response = ActiveSupport::JSON.decode(@response.body) + + assert !json_response["success"] + end + should "verify if institution name already exists" do xhr :get, :institution_already_exists, :name=>"Ministerio Publico da Uniao" assert_equal "true", @response.body -- libgit2 0.21.2