Commit 29966d34ce6d1448ca9ccc42983ebf122af08551
Committed by
Gust
1 parent
c3069314
Exists in
master
and in
5 other branches
Fix unit tests mpog_software_plugin_test and mpog_validation_test
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Rodrigo Medeiros <rodrigo.mss01@gmail.com>
Showing
4 changed files
with
24 additions
and
34 deletions
Show diff stats
lib/mpog_software_plugin.rb
| ... | ... | @@ -254,8 +254,6 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
| 254 | 254 | end |
| 255 | 255 | end |
| 256 | 256 | |
| 257 | - protected | |
| 258 | - | |
| 259 | 257 | def calc_percentage_registration person |
| 260 | 258 | required_list = profile_required_list |
| 261 | 259 | empty_fields = profile_required_empty_list person |
| ... | ... | @@ -266,6 +264,9 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
| 266 | 264 | percentege |
| 267 | 265 | end |
| 268 | 266 | |
| 267 | + protected | |
| 268 | + | |
| 269 | + | |
| 269 | 270 | def create_url_to_edit_profile person |
| 270 | 271 | new_url = person.public_profile_url |
| 271 | 272 | new_url[:controller] = 'profile_editor' | ... | ... |
test/unit/mpog_software_plugin_test.rb
| 1 | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
| 2 | +require File.dirname(__FILE__) + '/plugin_test_helper' | |
| 2 | 3 | |
| 3 | 4 | class MpogSoftwarePluginTest < ActiveSupport::TestCase |
| 5 | + include PluginTestHelper | |
| 4 | 6 | |
| 5 | 7 | def setup |
| 6 | 8 | @plugin = MpogSoftwarePlugin.new |
| 7 | - @user = create_user | |
| 9 | + @user = create_user 'login', 'test@email.com', '1234', '1234', 'test2@email.com' | |
| 8 | 10 | @person = @user.person |
| 9 | 11 | end |
| 10 | 12 | |
| ... | ... | @@ -25,36 +27,10 @@ class MpogSoftwarePluginTest < ActiveSupport::TestCase |
| 25 | 27 | required_list = ["cell_phone","contact_phone","institution","comercial_phone","country","city","state","organization_website","area_interest","image"] |
| 26 | 28 | |
| 27 | 29 | empty_fields = required_list.count - 1 |
| 28 | - test_percentege = (empty_fields * 100) / required_list.count | |
| 30 | + test_percentege = 100 - ((empty_fields * 100) / required_list.count) | |
| 29 | 31 | |
| 30 | 32 | plugin_percentege = @plugin.calc_percentage_registration(@person) |
| 31 | 33 | |
| 32 | 34 | assert_equal(test_percentege, plugin_percentege) |
| 33 | 35 | end |
| 34 | - | |
| 35 | - should 'return message with percentege of incomplete registration' do | |
| 36 | - @user.person.name = "Person Name" | |
| 37 | - @user.person.cell_phone = "76888919" | |
| 38 | - | |
| 39 | - plugin_percentege = @plugin.calc_percentage_registration(@user.person) | |
| 40 | - | |
| 41 | - expected_result = "Registration " + plugin_percentege.to_s + "% incomplete "; | |
| 42 | - plugin_result = @plugin.incomplete_registration({:user => @user}) | |
| 43 | - | |
| 44 | - assert_equal(expected_result, plugin_result) | |
| 45 | - end | |
| 46 | - | |
| 47 | - private | |
| 48 | - | |
| 49 | - def create_user | |
| 50 | - user = User.new | |
| 51 | - user.login = "login" | |
| 52 | - user.email = "user@email.com" | |
| 53 | - user.password = "123456" | |
| 54 | - user.password_confirmation = "123456" | |
| 55 | - user.secondary_email = "user@secondary_email.com" | |
| 56 | - user.save | |
| 57 | - user.person.save | |
| 58 | - user | |
| 59 | - end | |
| 60 | 36 | end | ... | ... |
test/unit/mpog_validation_test.rb
| 1 | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
| 2 | +require File.dirname(__FILE__) + '/plugin_test_helper' | |
| 2 | 3 | |
| 3 | 4 | class MpogSoftwarePluginValidationTest < ActiveSupport::TestCase |
| 5 | + include PluginTestHelper | |
| 6 | + | |
| 4 | 7 | def setup |
| 5 | 8 | @plugin = MpogSoftwarePlugin.new |
| 6 | - institution = Institution::new(:name => "Test institution") | |
| 7 | - institution.save | |
| 8 | - @user = fast_create(User) | |
| 9 | - @user.institution = institution | |
| 9 | + @user = create_user 'login', 'test@email.com', '1234', '1234', 'test2@email.com' | |
| 10 | + | |
| 10 | 11 | end |
| 11 | 12 | |
| 12 | 13 | def teardown | ... | ... |
test/unit/plugin_test_helper.rb
| ... | ... | @@ -35,4 +35,16 @@ module PluginTestHelper |
| 35 | 35 | community |
| 36 | 36 | end |
| 37 | 37 | |
| 38 | + def create_user login, email, password, password_confirmation, secondary_email | |
| 39 | + user = User.new | |
| 40 | + user.login = login | |
| 41 | + user.email = email | |
| 42 | + user.password = password | |
| 43 | + user.password_confirmation = password_confirmation | |
| 44 | + user.secondary_email = secondary_email | |
| 45 | + user.save | |
| 46 | + user.person.save | |
| 47 | + user | |
| 48 | + end | |
| 49 | + | |
| 38 | 50 | end | ... | ... |