diff options
Diffstat (limited to 'activemodel/test')
18 files changed, 12 insertions, 128 deletions
diff --git a/activemodel/test/cases/helper.rb b/activemodel/test/cases/helper.rb index 8578ab7dbd..a81584bbad 100644 --- a/activemodel/test/cases/helper.rb +++ b/activemodel/test/cases/helper.rb @@ -5,6 +5,7 @@ $:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) require 'config' require 'active_model' +require 'active_support/core_ext/string/access' # Show backtraces for deprecated behavior for quicker cleanup. ActiveSupport::Deprecation.debug = true diff --git a/activemodel/test/cases/tests_database.rb b/activemodel/test/cases/tests_database.rb deleted file mode 100644 index 8ca54d2678..0000000000 --- a/activemodel/test/cases/tests_database.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'logger' - -$:.unshift(File.dirname(__FILE__) + '/../../../activerecord/lib') -require 'active_record' - -module ActiveModel - module TestsDatabase - mattr_accessor :connected - - def self.included(base) - unless self.connected - setup_connection - setup_schema - end - - base.send :include, ActiveRecord::TestFixtures - end - - def self.setup_schema - original, $stdout = $stdout, StringIO.new - load(SCHEMA_FILE) - ensure - $stdout = original - self.connected = true - end - - def self.setup_connection - defaults = { :database => ':memory:' } - - adapter = defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' - options = defaults.merge :adapter => adapter, :timeout => 500 - ActiveRecord::Base.establish_connection(options) - end - end -end diff --git a/activemodel/test/cases/validations/acceptance_validation_test.rb b/activemodel/test/cases/validations/acceptance_validation_test.rb index 4d0c7cde8b..de04e11258 100644 --- a/activemodel/test/cases/validations/acceptance_validation_test.rb +++ b/activemodel/test/cases/validations/acceptance_validation_test.rb @@ -1,13 +1,11 @@ # encoding: utf-8 require 'cases/helper' -require 'cases/tests_database' require 'models/topic' require 'models/reply' require 'models/person' class AcceptanceValidationTest < ActiveModel::TestCase - include ActiveModel::TestsDatabase def teardown Topic.reset_callbacks(:validate) diff --git a/activemodel/test/cases/validations/conditional_validation_test.rb b/activemodel/test/cases/validations/conditional_validation_test.rb index 6bb5752702..3cb95b4a00 100644 --- a/activemodel/test/cases/validations/conditional_validation_test.rb +++ b/activemodel/test/cases/validations/conditional_validation_test.rb @@ -1,11 +1,9 @@ # encoding: utf-8 require 'cases/helper' -require 'cases/tests_database' require 'models/topic' class ConditionalValidationTest < ActiveModel::TestCase - include ActiveModel::TestsDatabase def teardown Topic.reset_callbacks(:validate) diff --git a/activemodel/test/cases/validations/confirmation_validation_test.rb b/activemodel/test/cases/validations/confirmation_validation_test.rb index ee6fc68840..d0418170fa 100644 --- a/activemodel/test/cases/validations/confirmation_validation_test.rb +++ b/activemodel/test/cases/validations/confirmation_validation_test.rb @@ -1,12 +1,10 @@ # encoding: utf-8 require 'cases/helper' -require 'cases/tests_database' require 'models/topic' require 'models/person' class ConfirmationValidationTest < ActiveModel::TestCase - include ActiveModel::TestsDatabase def teardown Topic.reset_callbacks(:validate) diff --git a/activemodel/test/cases/validations/exclusion_validation_test.rb b/activemodel/test/cases/validations/exclusion_validation_test.rb index e0abb9016b..be9d98d644 100644 --- a/activemodel/test/cases/validations/exclusion_validation_test.rb +++ b/activemodel/test/cases/validations/exclusion_validation_test.rb @@ -1,12 +1,10 @@ # encoding: utf-8 require 'cases/helper' -require 'cases/tests_database' require 'models/topic' require 'models/person' class ExclusionValidationTest < ActiveModel::TestCase - include ActiveModel::TestsDatabase def teardown Topic.reset_callbacks(:validate) diff --git a/activemodel/test/cases/validations/format_validation_test.rb b/activemodel/test/cases/validations/format_validation_test.rb index d1731f2bf9..6c4fb36d52 100644 --- a/activemodel/test/cases/validations/format_validation_test.rb +++ b/activemodel/test/cases/validations/format_validation_test.rb @@ -1,12 +1,10 @@ # encoding: utf-8 require 'cases/helper' -require 'cases/tests_database' require 'models/topic' require 'models/person' class PresenceValidationTest < ActiveModel::TestCase - include ActiveModel::TestsDatabase def teardown Topic.reset_callbacks(:validate) diff --git a/activemodel/test/cases/validations/i18n_generate_message_validation_test.rb b/activemodel/test/cases/validations/i18n_generate_message_validation_test.rb index 3a644c92c9..58a8d179ad 100644 --- a/activemodel/test/cases/validations/i18n_generate_message_validation_test.rb +++ b/activemodel/test/cases/validations/i18n_generate_message_validation_test.rb @@ -1,5 +1,4 @@ require "cases/helper" -require 'cases/tests_database' require 'models/person' diff --git a/activemodel/test/cases/validations/i18n_validation_test.rb b/activemodel/test/cases/validations/i18n_validation_test.rb index d65d94d599..547d80f46e 100644 --- a/activemodel/test/cases/validations/i18n_validation_test.rb +++ b/activemodel/test/cases/validations/i18n_validation_test.rb @@ -1,11 +1,9 @@ # -*- coding: utf-8 -*- require "cases/helper" -require 'cases/tests_database' require 'models/person' class I18nValidationTest < ActiveModel::TestCase - include ActiveModel::TestsDatabase def setup Person.reset_callbacks(:validate) @@ -63,7 +61,7 @@ class I18nValidationTest < ActiveModel::TestCase assert_equal ["Field Name empty"], @person.errors.full_messages end - # ActiveRecord::Validations + # ActiveModel::Validations # validates_confirmation_of w/ mocha def test_validates_confirmation_of_generates_message Person.validates_confirmation_of :title diff --git a/activemodel/test/cases/validations/inclusion_validation_test.rb b/activemodel/test/cases/validations/inclusion_validation_test.rb index f128b2c9e9..0716b4f087 100644 --- a/activemodel/test/cases/validations/inclusion_validation_test.rb +++ b/activemodel/test/cases/validations/inclusion_validation_test.rb @@ -1,12 +1,10 @@ # encoding: utf-8 require 'cases/helper' -require 'cases/tests_database' require 'models/topic' require 'models/person' class InclusionValidationTest < ActiveModel::TestCase - include ActiveModel::TestsDatabase def teardown Topic.reset_callbacks(:validate) diff --git a/activemodel/test/cases/validations/length_validation_test.rb b/activemodel/test/cases/validations/length_validation_test.rb index f188d04ba2..012c5a2f37 100644 --- a/activemodel/test/cases/validations/length_validation_test.rb +++ b/activemodel/test/cases/validations/length_validation_test.rb @@ -1,12 +1,10 @@ # encoding: utf-8 require 'cases/helper' -require 'cases/tests_database' require 'models/topic' require 'models/person' class LengthValidationTest < ActiveModel::TestCase - include ActiveModel::TestsDatabase def teardown Topic.reset_callbacks(:validate) diff --git a/activemodel/test/cases/validations/numericality_validation_test.rb b/activemodel/test/cases/validations/numericality_validation_test.rb index 2cf69ec264..be620c53fa 100644 --- a/activemodel/test/cases/validations/numericality_validation_test.rb +++ b/activemodel/test/cases/validations/numericality_validation_test.rb @@ -1,12 +1,10 @@ # encoding: utf-8 require 'cases/helper' -require 'cases/tests_database' require 'models/topic' require 'models/person' class NumericalityValidationTest < ActiveModel::TestCase - include ActiveModel::TestsDatabase def teardown Topic.reset_callbacks(:validate) diff --git a/activemodel/test/cases/validations/presence_validation_test.rb b/activemodel/test/cases/validations/presence_validation_test.rb index 370b519812..b1450586a8 100644 --- a/activemodel/test/cases/validations/presence_validation_test.rb +++ b/activemodel/test/cases/validations/presence_validation_test.rb @@ -1,13 +1,11 @@ # encoding: utf-8 require 'cases/helper' -require 'cases/tests_database' require 'models/topic' require 'models/person' require 'models/custom_reader' class PresenceValidationTest < ActiveModel::TestCase - include ActiveModel::TestsDatabase teardown do Topic.reset_callbacks(:validate) diff --git a/activemodel/test/cases/validations/validations_context_test.rb b/activemodel/test/cases/validations/validations_context_test.rb index 06bd8e7903..15a49e38dd 100644 --- a/activemodel/test/cases/validations/validations_context_test.rb +++ b/activemodel/test/cases/validations/validations_context_test.rb @@ -1,11 +1,9 @@ # encoding: utf-8 require 'cases/helper' -require 'cases/tests_database' require 'models/topic' -class ValidationsContextTest < ActiveRecord::TestCase - include ActiveModel::TestsDatabase +class ValidationsContextTest < ActiveModel::TestCase def teardown Topic.reset_callbacks(:validate) diff --git a/activemodel/test/cases/validations/with_validation_test.rb b/activemodel/test/cases/validations/with_validation_test.rb index b68b511852..6d825cd316 100644 --- a/activemodel/test/cases/validations/with_validation_test.rb +++ b/activemodel/test/cases/validations/with_validation_test.rb @@ -1,11 +1,9 @@ # encoding: utf-8 require 'cases/helper' -require 'cases/tests_database' require 'models/topic' class ValidatesWithTest < ActiveModel::TestCase - include ActiveModel::TestsDatabase def teardown Topic.reset_callbacks(:validate) diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index 0594580804..578ffc27dd 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -1,13 +1,11 @@ # encoding: utf-8 require 'cases/helper' -require 'cases/tests_database' require 'models/topic' require 'models/reply' require 'models/custom_reader' class ValidationsTest < ActiveModel::TestCase - include ActiveModel::TestsDatabase def setup Topic._validators.clear @@ -166,15 +164,15 @@ class ValidationsTest < ActiveModel::TestCase t = Topic.new :title => '' assert t.invalid? - assert_equal :title, key = t.errors.keys.first - assert_equal "can't be blank", t.errors[key].first - assert_equal 'is too short (minimum is 2 characters)', t.errors[key].second - assert_equal :author_name, key = t.errors.keys.second - assert_equal "can't be blank", t.errors[key].first - assert_equal :author_email_address, key = t.errors.keys.third - assert_equal 'will never be valid', t.errors[key].first - assert_equal :content, key = t.errors.keys.fourth - assert_equal 'is too short (minimum is 2 characters)', t.errors[key].first + assert_equal :title, key = t.errors.keys[0] + assert_equal "can't be blank", t.errors[key][0] + assert_equal 'is too short (minimum is 2 characters)', t.errors[key][1] + assert_equal :author_name, key = t.errors.keys[1] + assert_equal "can't be blank", t.errors[key][0] + assert_equal :author_email_address, key = t.errors.keys[2] + assert_equal 'will never be valid', t.errors[key][0] + assert_equal :content, key = t.errors.keys[3] + assert_equal 'is too short (minimum is 2 characters)', t.errors[key][0] end def test_invalid_should_be_the_opposite_of_valid diff --git a/activemodel/test/fixtures/topics.yml b/activemodel/test/fixtures/topics.yml deleted file mode 100644 index e4c61ce2d8..0000000000 --- a/activemodel/test/fixtures/topics.yml +++ /dev/null @@ -1,41 +0,0 @@ -first: - id: 1 - title: The First Topic - author_name: David - author_email_address: david@loudthinking.com - written_on: 2003-07-16t15:28:11.2233+01:00 - last_read: 2004-04-15 - bonus_time: 2005-01-30t15:28:00.00+01:00 - content: Have a nice day - approved: false - replies_count: 1 - -second: - id: 2 - title: The Second Topic of the day - author_name: Mary - written_on: 2004-07-15t15:28:00.0099+01:00 - content: Have a nice day - approved: true - replies_count: 0 - parent_id: 1 - type: Reply - -third: - id: 3 - title: The Third Topic of the day - author_name: Nick - written_on: 2005-07-15t15:28:00.0099+01:00 - content: I'm a troll - approved: true - replies_count: 1 - -fourth: - id: 4 - title: The Fourth Topic of the day - author_name: Carl - written_on: 2006-07-15t15:28:00.0099+01:00 - content: Why not? - approved: true - type: Reply - parent_id: 3 diff --git a/activemodel/test/schema.rb b/activemodel/test/schema.rb deleted file mode 100644 index 56b824d445..0000000000 --- a/activemodel/test/schema.rb +++ /dev/null @@ -1,14 +0,0 @@ -ActiveRecord::Schema.define do - create_table :topics, :force => true do |t| - t.string :title - t.string :author_name - t.text :content - t.boolean :approved, :default => true - t.string :type - end - - create_table :developers, :force => true do |t| - t.string :name - t.float :salary - end -end |