Commit 3a116bc3520e84015d805d1565ff9aca80117977

Authored by Luciano Prestes
1 parent fc1161f0

Implement functional tests for Institution date_modification

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
lib/institution_helper.rb
... ... @@ -49,6 +49,7 @@ module InstitutionHelper
49 49  
50 50 def self.register_institution_modification institution
51 51 institution.date_modification = current_date
  52 + institution.save!
52 53 end
53 54  
54 55 protected
... ...
lib/mpog_software_plugin.rb
... ... @@ -245,9 +245,9 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
245 245 end
246 246  
247 247 def institution_transaction
  248 + InstitutionHelper.register_institution_modification context.profile.institution
248 249 if context.params.has_key?(:governmental_power)
249 250 context.profile.institution.governmental_power_id = context.params[:governmental_power]
250   - InstitutionHelper.register_institution_modification context.profile.institution
251 251 context.profile.institution.save!
252 252 end
253 253  
... ...
test/functional/mpog_software_plugin_controller_test.rb
... ... @@ -3,7 +3,6 @@ require File.dirname(__FILE__) + &#39;/../../controllers/mpog_software_plugin_contro
3 3  
4 4 class MpogSoftwarePluginController; def rescue_action(e) raise e end; end
5 5  
6   -
7 6 class MpogSoftwarePluginControllerTest < ActionController::TestCase
8 7  
9 8 def setup
... ... @@ -110,7 +109,6 @@ class MpogSoftwarePluginControllerTest &lt; ActionController::TestCase
110 109 assert_equal "false", @response.body
111 110 end
112 111  
113   -
114 112 should "response as XML to export softwares" do
115 113 get :download, :format => 'xml'
116 114 assert_equal 'text/xml', @response.content_type
... ... @@ -132,6 +130,20 @@ class MpogSoftwarePluginControllerTest &lt; ActionController::TestCase
132 130 assert_equal "false", @response.body
133 131 end
134 132  
  133 + should "update institution date_modification in your creation" do
  134 + @controller.stubs(:verify_recaptcha).returns(true)
  135 +
  136 + xhr :get, :new_institution,
  137 + :authenticity_token=>"dsa45a6das52sd",
  138 + :community=>{:name=>"foo bar"},
  139 + :institution => {:cnpj=>"12.234.567/8900-10", :acronym=>"fb", :type=>"PublicInstitution"},
  140 + :governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id},
  141 + :recaptcha_response_field=>''
  142 +
  143 + date = Time.now.day.to_s + "/" + Time.now.month.to_s + "/" + Time.now.year.to_s
  144 + assert_equal date, Institution.last.date_modification
  145 + end
  146 +
135 147  
136 148 private
137 149  
... ...
test/functional/profile_editor_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,54 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../../../../app/controllers/my_profile/profile_editor_controller'
  3 +
  4 +class ProfileEditorController; def rescue_action(e) raise e end; end
  5 +
  6 +class ProfileEditorControllerTest < ActionController::TestCase
  7 +
  8 + def setup
  9 + @controller = ProfileEditorController.new
  10 + @request = ActionController::TestRequest.new
  11 + @response = ActionController::TestResponse.new
  12 + @profile = create_user('default_user').person
  13 + Environment.default.affiliate(@profile, [Environment::Roles.admin(Environment.default.id)] + Profile::Roles.all_roles(Environment.default.id))
  14 + @environment = Environment.default
  15 + @environment.enabled_plugins = ['MpogSoftwarePlugin']
  16 +
  17 + @govPower = GovernmentalPower.create(:name=>"Some Gov Power")
  18 + @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  19 +
  20 + admin = create_user("adminuser").person
  21 + admin.stubs(:has_permission?).returns("true")
  22 + login_as('adminuser')
  23 +
  24 + @environment.add_admin(admin)
  25 + @environment.save
  26 + end
  27 +
  28 + should "update institution date_modification in your creation" do
  29 + institution = create_public_institution("Ministerio Publico da Uniao", "MPU", @govPower, @govSphere)
  30 + institution.date_modification = "Invalid Date"
  31 +
  32 + post :edit, :profile => Institution.last.community.identifier, :profile_data => {:name => "Ministerio da Saude"}, :institution => institution
  33 +
  34 + date = Time.now.day.to_s + "/" + Time.now.month.to_s + "/" + Time.now.year.to_s
  35 + assert_equal date, Institution.last.date_modification
  36 + end
  37 +
  38 + private
  39 +
  40 + def create_public_institution name, acronym, gov_p, gov_s
  41 + institution_community = fast_create(Community)
  42 + institution_community.name = name
  43 +
  44 + institution = PublicInstitution.new
  45 + institution.community = institution_community
  46 + institution.name = name
  47 + institution.acronym = acronym
  48 + institution.governmental_power = gov_p
  49 + institution.governmental_sphere = gov_s
  50 + institution.save!
  51 + institution
  52 + end
  53 +
  54 +end
0 55 \ No newline at end of file
... ...