Commit 488335e53677b3562741ba9692d5f976b7709402

Authored by Rodrigo Souto
1 parent 92e9abd2

Fixing tests after stoa merg

plugins/stoa/test/functional/stoa_plugin_controller_test.rb
@@ -22,13 +22,17 @@ class StoaPluginControllerTest < ActionController::TestCase @@ -22,13 +22,17 @@ class StoaPluginControllerTest < ActionController::TestCase
22 t.date "dtanas" 22 t.date "dtanas"
23 end 23 end
24 ActiveRecord::Base.establish_connection(:test) 24 ActiveRecord::Base.establish_connection(:test)
25 - @user = User.find_by_login('real_user') || create_user('real_user', :password => '123456', :password_confirmation => '123456') 25 + env = Environment.default
  26 + env.enable_plugin(StoaPlugin.name)
  27 + env.enable('skip_new_user_email_confirmation')
  28 + env.save!
  29 + @user = create_user_full('real_user', {:password => '123456', :password_confirmation => '123456'}, {:usp_id => 9999999})
26 StoaPlugin::UspUser.create!(:codpes => 12345678, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30') 30 StoaPlugin::UspUser.create!(:codpes => 12345678, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30')
27 - Environment.default.enable_plugin(StoaPlugin.name)  
28 end 31 end
29 32
30 def teardown 33 def teardown
31 @db.unlink 34 @db.unlink
  35 + @user.destroy
32 end 36 end
33 37
34 attr_accessor :user 38 attr_accessor :user
plugins/stoa/test/unit/person.rb
@@ -1,65 +0,0 @@ @@ -1,65 +0,0 @@
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper'  
2 -  
3 -class StoaPlugin::Person < ActiveSupport::TestCase  
4 -  
5 - def setup  
6 - @environment = Environment.default  
7 - @environment.enable_plugin(StoaPlugin)  
8 - end  
9 -  
10 - attr_reader :environment  
11 -  
12 - should 'validates uniqueness of usp_id' do  
13 - usp_id = 87654321  
14 - fast_create(Person, :usp_id => usp_id)  
15 - another_person = Person.new(:usp_id => usp_id)  
16 - another_person.valid?  
17 -  
18 - assert another_person.errors.invalid?(:usp_id)  
19 - end  
20 -  
21 - should 'allow nil usp_id only if person has an invitation_code' do  
22 - person = Person.new(:environment => environment)  
23 - person.valid?  
24 - assert person.errors.invalid?(:usp_id)  
25 -  
26 - Task.create!(:code => 12345678)  
27 - person.invitation_code = 12345678  
28 - person.valid?  
29 -  
30 - assert !person.errors.invalid?(:usp_id)  
31 - end  
32 -  
33 - should 'allow multiple nil usp_id' do  
34 - fast_create(Person)  
35 - Task.create!(:code => 87654321)  
36 - person = Person.new(:invitation_code => 87654321)  
37 - person.valid?  
38 -  
39 - assert !person.errors.invalid?(:usp_id)  
40 - end  
41 -  
42 - should 'not allow person to be saved with a finished invitation that is not his own' do  
43 - t = Task.create!(:code => 87654321, :target_id => 1)  
44 - t.finish  
45 - person = Person.new(:environment => environment, :invitation_code => 87654321)  
46 - person.valid?  
47 -  
48 - assert person.errors.invalid?(:usp_id)  
49 - end  
50 -  
51 - should 'allow person to be saved with a finished invitation if it is his own' do  
52 - t = Task.create!(:code => 87654321)  
53 - user = User.new(:login => 'some-person', :email => 'some-person@example.com', :password => 'test', :password_confirmation => 'test', :person_data => {:environment => environment, :invitation_code => 87654321})  
54 - user.save!  
55 - person = user.person  
56 - t.target_id = person.id  
57 - t.finish  
58 -  
59 - person.valid?  
60 - assert !person.errors.invalid?(:usp_id)  
61 - end  
62 -  
63 -  
64 -end  
65 -  
plugins/stoa/test/unit/person_test.rb 0 → 100644
@@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +
  3 +class StoaPlugin::Person < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @environment = Environment.default
  7 + @environment.enable_plugin(StoaPlugin)
  8 + end
  9 +
  10 + attr_reader :environment
  11 +
  12 + should 'validates uniqueness of usp_id' do
  13 + usp_id = 87654321
  14 + fast_create(Person, :usp_id => usp_id)
  15 + another_person = Person.new(:usp_id => usp_id)
  16 + another_person.valid?
  17 +
  18 + assert another_person.errors.invalid?(:usp_id)
  19 + end
  20 +
  21 + should 'allow nil usp_id only if person has an invitation_code' do
  22 + person = Person.new(:environment => environment)
  23 + person.valid?
  24 + assert person.errors.invalid?(:usp_id)
  25 +
  26 + Task.create!(:code => 12345678)
  27 + person.invitation_code = 12345678
  28 + person.valid?
  29 +
  30 + assert !person.errors.invalid?(:usp_id)
  31 + end
  32 +
  33 + should 'allow multiple nil usp_id' do
  34 + fast_create(Person)
  35 + Task.create!(:code => 87654321)
  36 + person = Person.new(:invitation_code => 87654321)
  37 + person.valid?
  38 +
  39 + assert !person.errors.invalid?(:usp_id)
  40 + end
  41 +
  42 + should 'not allow person to be saved with a finished invitation that is not his own' do
  43 + t = Task.create!(:code => 87654321, :target_id => 1)
  44 + t.finish
  45 + person = Person.new(:environment => environment, :invitation_code => 87654321)
  46 + person.valid?
  47 +
  48 + assert person.errors.invalid?(:usp_id)
  49 + end
  50 +
  51 + should 'allow person to be saved with a finished invitation if it is his own' do
  52 + t = Task.create!(:code => 87654321)
  53 + user = User.new(:login => 'some-person', :email => 'some-person@example.com', :password => 'test', :password_confirmation => 'test', :person_data => {:environment => environment, :invitation_code => 87654321})
  54 + user.save!
  55 + person = user.person
  56 + t.target_id = person.id
  57 + t.finish
  58 +
  59 + person.valid?
  60 + assert !person.errors.invalid?(:usp_id)
  61 + end
  62 +
  63 +
  64 +end
  65 +
plugins/stoa/test/unit/usp_user.rb
@@ -1,47 +0,0 @@ @@ -1,47 +0,0 @@
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper'  
2 -  
3 -class StoaPlugin::UspUserTest < ActiveSupport::TestCase  
4 -  
5 - SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt']  
6 -  
7 - def setup  
8 - @db = Tempfile.new('stoa-test')  
9 - configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path}  
10 - ActiveRecord::Base.establish_connection(:stoa)  
11 - ActiveRecord::Schema.verbose = false  
12 - ActiveRecord::Schema.create_table "pessoa" do |t|  
13 - t.integer "codpes"  
14 - t.text "numcpf"  
15 - t.date "dtanas"  
16 - end  
17 - ActiveRecord::Base.establish_connection(:test)  
18 - StoaPlugin::UspUser.create!(:codpes => 123456, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30')  
19 - end  
20 -  
21 - def teardown  
22 - @db.unlink  
23 - end  
24 -  
25 - should 'check existence of usp_id' do  
26 - assert StoaPlugin::UspUser.exists?(123456)  
27 - assert !StoaPlugin::UspUser.exists?(654321)  
28 - end  
29 -  
30 - should 'check if usp_id matches with a cpf' do  
31 - assert StoaPlugin::UspUser.matches?(123456, :cpf, 12345678)  
32 - assert !StoaPlugin::UspUser.matches?(123456, :cpf, 87654321)  
33 - assert !StoaPlugin::UspUser.matches?(654321, :cpf, 12345678)  
34 - end  
35 -  
36 - should 'check if usp_id matches with a birth_date' do  
37 - assert StoaPlugin::UspUser.matches?(123456, :birth_date, '1970-01-30')  
38 - assert !StoaPlugin::UspUser.matches?(123456, :birth_date, '1999-01-30')  
39 - assert !StoaPlugin::UspUser.matches?(654321, :birth_date, '1970-01-30')  
40 - end  
41 -  
42 - should 'filter leading zeroes of id codes on exists and matches' do  
43 - assert StoaPlugin::UspUser.exists?('0000123456')  
44 - assert StoaPlugin::UspUser.matches?(123456, :cpf, '00012345678')  
45 - end  
46 -end  
47 -  
plugins/stoa/test/unit/usp_user_test.rb 0 → 100644
@@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +
  3 +class StoaPlugin::UspUserTest < ActiveSupport::TestCase
  4 +
  5 + SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt']
  6 +
  7 + def setup
  8 + @db = Tempfile.new('stoa-test')
  9 + configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path}
  10 + ActiveRecord::Base.establish_connection(:stoa)
  11 + ActiveRecord::Schema.verbose = false
  12 + ActiveRecord::Schema.create_table "pessoa" do |t|
  13 + t.integer "codpes"
  14 + t.text "numcpf"
  15 + t.date "dtanas"
  16 + end
  17 + ActiveRecord::Base.establish_connection(:test)
  18 + StoaPlugin::UspUser.create!(:codpes => 123456, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30')
  19 + end
  20 +
  21 + def teardown
  22 + @db.unlink
  23 + end
  24 +
  25 + should 'check existence of usp_id' do
  26 + assert StoaPlugin::UspUser.exists?(123456)
  27 + assert !StoaPlugin::UspUser.exists?(654321)
  28 + end
  29 +
  30 + should 'check if usp_id matches with a cpf' do
  31 + assert StoaPlugin::UspUser.matches?(123456, :cpf, 12345678)
  32 + assert !StoaPlugin::UspUser.matches?(123456, :cpf, 87654321)
  33 + assert !StoaPlugin::UspUser.matches?(654321, :cpf, 12345678)
  34 + end
  35 +
  36 + should 'check if usp_id matches with a birth_date' do
  37 + assert StoaPlugin::UspUser.matches?(123456, :birth_date, '1970-01-30')
  38 + assert !StoaPlugin::UspUser.matches?(123456, :birth_date, '1999-01-30')
  39 + assert !StoaPlugin::UspUser.matches?(654321, :birth_date, '1970-01-30')
  40 + end
  41 +
  42 + should 'filter leading zeroes of id codes on exists and matches' do
  43 + assert StoaPlugin::UspUser.exists?('0000123456')
  44 + assert StoaPlugin::UspUser.matches?(123456, :cpf, '00012345678')
  45 + end
  46 +end
  47 +
test/factories.rb
@@ -80,8 +80,8 @@ module Noosfero::Factory @@ -80,8 +80,8 @@ module Noosfero::Factory
80 :password_confirmation => name.underscore 80 :password_confirmation => name.underscore
81 }.merge(options) 81 }.merge(options)
82 user = User.new(data) 82 user = User.new(data)
  83 + user.person = Person.new(person_options)
83 user.save! 84 user.save!
84 - user.person.update_attributes!(person_data.merge(person_options))  
85 user 85 user
86 end 86 end
87 87
@@ -114,7 +114,6 @@ module Noosfero::Factory @@ -114,7 +114,6 @@ module Noosfero::Factory
114 fast_update(person, {:home_page_id => homepage.id}) 114 fast_update(person, {:home_page_id => homepage.id})
115 box = fast_insert(Box, { :owner_type => "Profile", :owner_id => person.id, :position => 1}) 115 box = fast_insert(Box, { :owner_type => "Profile", :owner_id => person.id, :position => 1})
116 block = fast_insert(Block, { :box_id => box.id, :type => 'MainBlock', :position => 0}) 116 block = fast_insert(Block, { :box_id => box.id, :type => 'MainBlock', :position => 0})
117 - user.activate  
118 user 117 user
119 end 118 end
120 119
test/functional/account_controller_test.rb
@@ -622,14 +622,14 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -622,14 +622,14 @@ class AccountControllerTest &lt; ActionController::TestCase
622 @controller.expects(:environment).returns(env).at_least_once 622 @controller.expects(:environment).returns(env).at_least_once
623 profile = create_user('mylogin').person 623 profile = create_user('mylogin').person
624 get :check_url, :identifier => 'mylogin' 624 get :check_url, :identifier => 'mylogin'
625 - assert_equal 'available', assigns(:status_class) 625 + assert_equal 'validated', assigns(:status_class)
626 end 626 end
627 627
628 should 'check if url is not available on environment' do 628 should 'check if url is not available on environment' do
629 @controller.expects(:environment).returns(Environment.default).at_least_once 629 @controller.expects(:environment).returns(Environment.default).at_least_once
630 profile = create_user('mylogin').person 630 profile = create_user('mylogin').person
631 get :check_url, :identifier => 'mylogin' 631 get :check_url, :identifier => 'mylogin'
632 - assert_equal 'unavailable', assigns(:status_class) 632 + assert_equal 'invalid', assigns(:status_class)
633 end 633 end
634 634
635 should 'check if e-mail is available on environment' do 635 should 'check if e-mail is available on environment' do
@@ -637,7 +637,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -637,7 +637,7 @@ class AccountControllerTest &lt; ActionController::TestCase
637 @controller.expects(:environment).returns(env).at_least_once 637 @controller.expects(:environment).returns(env).at_least_once
638 profile = create_user('mylogin', :email => 'mylogin@noosfero.org', :environment_id => fast_create(Environment).id) 638 profile = create_user('mylogin', :email => 'mylogin@noosfero.org', :environment_id => fast_create(Environment).id)
639 get :check_email, :address => 'mylogin@noosfero.org' 639 get :check_email, :address => 'mylogin@noosfero.org'
640 - assert_equal 'available', assigns(:status_class) 640 + assert_equal 'validated', assigns(:status_class)
641 end 641 end
642 642
643 should 'check if e-mail is not available on environment' do 643 should 'check if e-mail is not available on environment' do
@@ -645,7 +645,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -645,7 +645,7 @@ class AccountControllerTest &lt; ActionController::TestCase
645 @controller.expects(:environment).returns(env).at_least_once 645 @controller.expects(:environment).returns(env).at_least_once
646 profile = create_user('mylogin', :email => 'mylogin@noosfero.org', :environment_id => env) 646 profile = create_user('mylogin', :email => 'mylogin@noosfero.org', :environment_id => env)
647 get :check_email, :address => 'mylogin@noosfero.org' 647 get :check_email, :address => 'mylogin@noosfero.org'
648 - assert_equal 'unavailable', assigns(:status_class) 648 + assert_equal 'invalid', assigns(:status_class)
649 end 649 end
650 650
651 should 'merge user data with extra stuff from plugins' do 651 should 'merge user data with extra stuff from plugins' do
@@ -766,7 +766,6 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -766,7 +766,6 @@ class AccountControllerTest &lt; ActionController::TestCase
766 766
767 assert_tag :tag => 'strong', :content => 'Plugin1 text' 767 assert_tag :tag => 'strong', :content => 'Plugin1 text'
768 assert_tag :tag => 'strong', :content => 'Plugin2 text' 768 assert_tag :tag => 'strong', :content => 'Plugin2 text'
769 ->>>>>>> stoa-full-invitation-and-signup  
770 end 769 end
771 770
772 protected 771 protected