diff options
-rw-r--r-- | actionpack/test/abstract_unit.rb | 1 | ||||
-rw-r--r-- | actionpack/test/controller/active_record_assertions_test.rb | 210 | ||||
-rwxr-xr-x | activerecord/test/abstract_unit.rb | 1 | ||||
-rw-r--r-- | activerecord/test/connections/native_sqlite/connection.rb | 5 | ||||
-rw-r--r-- | activerecord/test/connections/native_sqlite3/connection.rb | 6 |
5 files changed, 119 insertions, 104 deletions
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 0fcb5e852d..3d61559ee3 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -1,4 +1,5 @@ $:.unshift(File.dirname(__FILE__) + '/../lib') +$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib') require 'test/unit' require 'action_controller' diff --git a/actionpack/test/controller/active_record_assertions_test.rb b/actionpack/test/controller/active_record_assertions_test.rb index 2a005b8586..49db40c5a2 100644 --- a/actionpack/test/controller/active_record_assertions_test.rb +++ b/actionpack/test/controller/active_record_assertions_test.rb @@ -1,120 +1,128 @@ path_to_ar = File.dirname(__FILE__) + '/../../../activerecord' if Object.const_defined?("ActiveRecord") || File.exist?(path_to_ar) -# This test is very different than the others. It requires ActiveRecord to -# run. There's a bunch of stuff we are assuming here: -# -# 1. activerecord exists as a sibling directory to actionpack -# (i.e., actionpack/../activerecord) -# 2. you've created the appropriate database to run the active_record unit tests -# 3. you set the appropriate database connection below - -driver_to_use = 'native_sqlite' - -$: << path_to_ar + '/lib/' -$: << path_to_ar + '/test/' -require 'active_record' unless Object.const_defined?("ActiveRecord") -require "connections/#{driver_to_use}/connection" -require 'fixtures/company' - -# ----------------------------------------------------------------------------- - -# add some validation rules to trip up the assertions -class Company - protected - def validate - errors.add_on_empty('name') - errors.add('rating', 'rating should not be 2') if rating == 2 - errors.add_to_base('oh oh') if rating == 3 - end -end + + # This test is very different than the others. It requires ActiveRecord to + # run. There's a bunch of stuff we are assuming here: + # + # 1. activerecord exists as a sibling directory to actionpack + # (i.e., actionpack/../activerecord) + # 2. you've created the appropriate database to run the active_record unit tests + # 3. you set the appropriate database connection below -# ----------------------------------------------------------------------------- + begin -require File.dirname(__FILE__) + '/../abstract_unit' + driver_to_use = 'native_sqlite' -# a controller class to handle the AR assertions -class ActiveRecordAssertionsController < ActionController::Base - # fail with 1 bad column - def nasty_columns_1 - @company = Company.new - @company.name = "B" - @company.rating = 2 - render_text "snicker...." - end + $: << path_to_ar + '/lib/' + $: << path_to_ar + '/test/' + require 'active_record' unless Object.const_defined?("ActiveRecord") + require "connections/#{driver_to_use}/connection" + require 'fixtures/company' + + # ----------------------------------------------------------------------------- + + # add some validation rules to trip up the assertions + class Company + protected + def validate + errors.add_on_empty('name') + errors.add('rating', 'rating should not be 2') if rating == 2 + errors.add_to_base('oh oh') if rating == 3 + end + end + + # ----------------------------------------------------------------------------- + + require File.dirname(__FILE__) + '/../abstract_unit' + + # a controller class to handle the AR assertions + class ActiveRecordAssertionsController < ActionController::Base + # fail with 1 bad column + def nasty_columns_1 + @company = Company.new + @company.name = "B" + @company.rating = 2 + render_text "snicker...." + end - # fail with 2 bad column - def nasty_columns_2 - @company = Company.new - @company.name = "" - @company.rating = 2 - render_text "double snicker...." - end + # fail with 2 bad column + def nasty_columns_2 + @company = Company.new + @company.name = "" + @company.rating = 2 + render_text "double snicker...." + end - # this will pass validation - def good_company - @company = Company.new - @company.name = "A" - @company.rating = 69 - render_text "Goodness Gracious!" - end + # this will pass validation + def good_company + @company = Company.new + @company.name = "A" + @company.rating = 69 + render_text "Goodness Gracious!" + end - # this will fail validation - def bad_company - @company = Company.new - render_text "Who's Bad?" - end + # this will fail validation + def bad_company + @company = Company.new + render_text "Who's Bad?" + end - # the safety dance...... - def rescue_action(e) raise; end -end + # the safety dance...... + def rescue_action(e) raise; end + end -# ----------------------------------------------------------------------------- + # ----------------------------------------------------------------------------- -ActiveRecordAssertionsController.template_root = File.dirname(__FILE__) + "/../fixtures/" + ActiveRecordAssertionsController.template_root = File.dirname(__FILE__) + "/../fixtures/" -# The test case to try the AR assertions -class ActiveRecordAssertionsControllerTest < Test::Unit::TestCase - # set it up - def setup - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - @controller = ActiveRecordAssertionsController.new - end + # The test case to try the AR assertions + class ActiveRecordAssertionsControllerTest < Test::Unit::TestCase + # set it up + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @controller = ActiveRecordAssertionsController.new + end - # test for 1 bad apple column - def test_some_invalid_columns - process :nasty_columns_1 - assert_success - assert_invalid_record 'company' - assert_invalid_column_on_record 'company', 'rating' - assert_valid_column_on_record 'company', 'name' - assert_valid_column_on_record 'company', ['name','id'] - end + # test for 1 bad apple column + def test_some_invalid_columns + process :nasty_columns_1 + assert_success + assert_invalid_record 'company' + assert_invalid_column_on_record 'company', 'rating' + assert_valid_column_on_record 'company', 'name' + assert_valid_column_on_record 'company', ['name','id'] + end - # test for 2 bad apples columns - def test_all_invalid_columns - process :nasty_columns_2 - assert_success - assert_invalid_record 'company' - assert_invalid_column_on_record 'company', 'rating' - assert_invalid_column_on_record 'company', 'name' - assert_invalid_column_on_record 'company', ['name','rating'] - end + # test for 2 bad apples columns + def test_all_invalid_columns + process :nasty_columns_2 + assert_success + assert_invalid_record 'company' + assert_invalid_column_on_record 'company', 'rating' + assert_invalid_column_on_record 'company', 'name' + assert_invalid_column_on_record 'company', ['name','rating'] + end - # ensure we have no problems with an ActiveRecord - def test_valid_record - process :good_company - assert_success - assert_valid_record 'company' - end + # ensure we have no problems with an ActiveRecord + def test_valid_record + process :good_company + assert_success + assert_valid_record 'company' + end - # ensure we have problems with an ActiveRecord - def test_invalid_record - process :bad_company - assert_success - assert_invalid_record 'company' + # ensure we have problems with an ActiveRecord + def test_invalid_record + process :bad_company + assert_success + assert_invalid_record 'company' + end + end + + rescue SqliteError => e + puts "Skipping active record based tests" + puts e.message end -end -end
\ No newline at end of file +end diff --git a/activerecord/test/abstract_unit.rb b/activerecord/test/abstract_unit.rb index dbab4b0e80..c798383e6d 100755 --- a/activerecord/test/abstract_unit.rb +++ b/activerecord/test/abstract_unit.rb @@ -1,4 +1,5 @@ $:.unshift(File.dirname(__FILE__) + '/../lib') +$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib') require 'test/unit' require 'active_record' diff --git a/activerecord/test/connections/native_sqlite/connection.rb b/activerecord/test/connections/native_sqlite/connection.rb index db688bdb70..e702006bc2 100644 --- a/activerecord/test/connections/native_sqlite/connection.rb +++ b/activerecord/test/connections/native_sqlite/connection.rb @@ -3,6 +3,9 @@ require 'fixtures/course' require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") +class SqliteError < StandardError +end + BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures') sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite" sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite" @@ -12,7 +15,7 @@ def make_connection(clazz, db_file, db_definitions_file) puts "SQLite database not found at #{db_file}. Rebuilding it." sqlite_command = "sqlite #{db_file} 'create table a (a integer); drop table a;'" puts "Executing '#{sqlite_command}'" - `#{sqlite_command}` + raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command) clazz.establish_connection( :adapter => "sqlite", :dbfile => db_file) diff --git a/activerecord/test/connections/native_sqlite3/connection.rb b/activerecord/test/connections/native_sqlite3/connection.rb index 573d942716..640a2b97f5 100644 --- a/activerecord/test/connections/native_sqlite3/connection.rb +++ b/activerecord/test/connections/native_sqlite3/connection.rb @@ -2,7 +2,9 @@ print "Using native SQLite3\n" require 'fixtures/course' require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") -ActiveRecord::Base.logger.level = Logger::DEBUG + +class SqliteError < StandardError +end BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures') sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3" @@ -13,7 +15,7 @@ def make_connection(clazz, db_file, db_definitions_file) puts "SQLite3 database not found at #{db_file}. Rebuilding it." sqlite_command = "sqlite3 #{db_file} 'create table a (a integer); drop table a;'" puts "Executing '#{sqlite_command}'" - `#{sqlite_command}` + raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command) clazz.establish_connection( :adapter => "sqlite3", :dbfile => db_file) |