Commit a4bd4d81e81f30235334cbbd7a7399e7dfb0863c

Authored by Larissa Reis
1 parent 82305ca6

stoa-plugin-tests: fixes transaction errors with temp stoa database

  To avoid Rails throwing rollback transaction errors before each test,
  the connection with the temporary stoa database is established before
  all tests instead of between tests. This way transactions aren't
  interrupted by database disconnections.
plugins/stoa/test/functional/account_controller_test.rb
... ... @@ -8,30 +8,27 @@ class AccountControllerTest < ActionController::TestCase
8 8  
9 9 SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt']
10 10  
  11 + @db = Tempfile.new('stoa-test')
  12 + configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path}
  13 + ActiveRecord::Base.establish_connection(:stoa)
  14 + ActiveRecord::Schema.verbose = false
  15 + ActiveRecord::Schema.create_table "pessoa" do |t|
  16 + t.integer "codpes"
  17 + t.text "numcpf"
  18 + t.date "dtanas"
  19 + end
  20 + ActiveRecord::Base.establish_connection(:test)
  21 +
11 22 def setup
12 23 @controller = AccountController.new
13 24 @request = ActionController::TestRequest.new
14 25 @response = ActionController::TestResponse.new
15   - @db = Tempfile.new('stoa-test')
16   - configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path}
17   - ActiveRecord::Base.establish_connection(:stoa)
18   - ActiveRecord::Schema.verbose = false
19   - ActiveRecord::Schema.create_table "pessoa" do |t|
20   - t.integer "codpes"
21   - t.text "numcpf"
22   - t.date "dtanas"
23   - end
24   - ActiveRecord::Base.establish_connection(:test)
25   - StoaPlugin::UspUser.create!(:codpes => 12345678, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30')
  26 + StoaPlugin::UspUser.create!({:codpes => 12345678, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30'}, :without_protection => true)
26 27 Environment.default.enable_plugin(StoaPlugin.name)
27 28 @user = create_user('joao-stoa', {:password => 'pass', :password_confirmation => 'pass'},:usp_id=>'87654321')
28 29 @user.activate
29 30 end
30 31  
31   - def teardown
32   - @db.unlink
33   - end
34   -
35 32 should 'fail if confirmation value doesn\'t match' do
36 33 #StoaPlugin::UspUser.stubs(:matches?).returns(false)
37 34 post :signup, :profile_data => {:usp_id => '12345678'}, :confirmation_field => 'cpf', :cpf => '00000000'
... ...
plugins/stoa/test/unit/usp_user_test.rb
... ... @@ -4,22 +4,19 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase
4 4  
5 5 SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt']
6 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')
  7 + @db = Tempfile.new('stoa-test')
  8 + configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path}
  9 + ActiveRecord::Base.establish_connection(:stoa)
  10 + ActiveRecord::Schema.verbose = false
  11 + ActiveRecord::Schema.create_table "pessoa" do |t|
  12 + t.integer "codpes"
  13 + t.text "numcpf"
  14 + t.date "dtanas"
19 15 end
  16 + ActiveRecord::Base.establish_connection(:test)
20 17  
21   - def teardown
22   - @db.unlink
  18 + def setup
  19 + StoaPlugin::UspUser.create({:codpes => 123456, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30'}, :without_protection => true)
23 20 end
24 21  
25 22 should 'check existence of usp_id' do
... ... @@ -48,4 +45,3 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase
48 45 assert !StoaPlugin::UspUser.matches?(123456, nil, '00012345678')
49 46 end
50 47 end
51   -
... ...