diff --git a/lib/institution_helper.rb b/lib/institution_helper.rb index 7be5e68..c344d62 100644 --- a/lib/institution_helper.rb +++ b/lib/institution_helper.rb @@ -49,6 +49,7 @@ module InstitutionHelper def self.register_institution_modification institution institution.date_modification = current_date + institution.save! end protected diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index 2e298e3..18cb26a 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -245,9 +245,9 @@ class MpogSoftwarePlugin < Noosfero::Plugin end def institution_transaction + InstitutionHelper.register_institution_modification context.profile.institution if context.params.has_key?(:governmental_power) context.profile.institution.governmental_power_id = context.params[:governmental_power] - InstitutionHelper.register_institution_modification context.profile.institution context.profile.institution.save! end diff --git a/test/functional/mpog_software_plugin_controller_test.rb b/test/functional/mpog_software_plugin_controller_test.rb index 8348b12..52cbd5b 100644 --- a/test/functional/mpog_software_plugin_controller_test.rb +++ b/test/functional/mpog_software_plugin_controller_test.rb @@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_contro class MpogSoftwarePluginController; def rescue_action(e) raise e end; end - class MpogSoftwarePluginControllerTest < ActionController::TestCase def setup @@ -110,7 +109,6 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase assert_equal "false", @response.body end - should "response as XML to export softwares" do get :download, :format => 'xml' assert_equal 'text/xml', @response.content_type @@ -132,6 +130,20 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase assert_equal "false", @response.body end + should "update institution date_modification in your creation" do + @controller.stubs(:verify_recaptcha).returns(true) + + xhr :get, :new_institution, + :authenticity_token=>"dsa45a6das52sd", + :community=>{:name=>"foo bar"}, + :institution => {:cnpj=>"12.234.567/8900-10", :acronym=>"fb", :type=>"PublicInstitution"}, + :governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id}, + :recaptcha_response_field=>'' + + date = Time.now.day.to_s + "/" + Time.now.month.to_s + "/" + Time.now.year.to_s + assert_equal date, Institution.last.date_modification + end + private diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb new file mode 100644 index 0000000..f5d68bd --- /dev/null +++ b/test/functional/profile_editor_controller_test.rb @@ -0,0 +1,54 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../../../../app/controllers/my_profile/profile_editor_controller' + +class ProfileEditorController; def rescue_action(e) raise e end; end + +class ProfileEditorControllerTest < ActionController::TestCase + + def setup + @controller = ProfileEditorController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @profile = create_user('default_user').person + Environment.default.affiliate(@profile, [Environment::Roles.admin(Environment.default.id)] + Profile::Roles.all_roles(Environment.default.id)) + @environment = Environment.default + @environment.enabled_plugins = ['MpogSoftwarePlugin'] + + @govPower = GovernmentalPower.create(:name=>"Some Gov Power") + @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") + + admin = create_user("adminuser").person + admin.stubs(:has_permission?).returns("true") + login_as('adminuser') + + @environment.add_admin(admin) + @environment.save + end + + should "update institution date_modification in your creation" do + institution = create_public_institution("Ministerio Publico da Uniao", "MPU", @govPower, @govSphere) + institution.date_modification = "Invalid Date" + + post :edit, :profile => Institution.last.community.identifier, :profile_data => {:name => "Ministerio da Saude"}, :institution => institution + + date = Time.now.day.to_s + "/" + Time.now.month.to_s + "/" + Time.now.year.to_s + assert_equal date, Institution.last.date_modification + end + + private + + def create_public_institution name, acronym, gov_p, gov_s + institution_community = fast_create(Community) + institution_community.name = name + + institution = PublicInstitution.new + institution.community = institution_community + institution.name = name + institution.acronym = acronym + institution.governmental_power = gov_p + institution.governmental_sphere = gov_s + institution.save! + institution + end + +end \ No newline at end of file -- libgit2 0.21.2