Permalink
Browse files

removed AR from all AMo tests, including any unneeded files (schema, …

…fixtures and test helper)
  • Loading branch information...
1 parent 88ad3ed commit 605c6455ac722ed9679e17458a47cc649cdedab0 @joshk joshk committed with Carl Lerche May 8, 2010
@@ -5,6 +5,7 @@
require 'config'
require 'active_model'
+require 'active_support/core_ext/string/access'
# Show backtraces for deprecated behavior for quicker cleanup.
ActiveSupport::Deprecation.debug = true
@@ -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
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -1,5 +1,4 @@
require "cases/helper"
-require 'cases/tests_database'
require 'models/person'
@@ -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 @@ def test_errors_full_messages_uses_format
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
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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 @@ def test_validation_order
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
@@ -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
View
@@ -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

0 comments on commit 605c645

Please sign in to comment.