aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/adapters/postgresql/hstore_test.rb89
-rw-r--r--activerecord/test/cases/associations/eager_load_nested_include_test.rb1
-rw-r--r--activerecord/test/cases/associations/eager_test.rb7
-rw-r--r--activerecord/test/cases/associations/extension_test.rb10
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb8
-rw-r--r--activerecord/test/cases/base_test.rb196
-rw-r--r--activerecord/test/cases/locking_test.rb52
-rw-r--r--activerecord/test/cases/named_scope_test.rb1
-rw-r--r--activerecord/test/cases/pooled_connections_test.rb8
-rw-r--r--activerecord/test/cases/validations/association_validation_test.rb14
-rw-r--r--activerecord/test/cases/validations/uniqueness_validation_test.rb30
11 files changed, 117 insertions, 299 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/hstore_test.rb b/activerecord/test/cases/adapters/postgresql/hstore_test.rb
new file mode 100644
index 0000000000..33bf4478cc
--- /dev/null
+++ b/activerecord/test/cases/adapters/postgresql/hstore_test.rb
@@ -0,0 +1,89 @@
+require "cases/helper"
+
+class PostgresqlHstoreTest < ActiveRecord::TestCase
+ class Hstore < ActiveRecord::Base
+ self.table_name = 'hstores'
+ end
+
+ def setup
+ @connection = ActiveRecord::Base.connection
+ begin
+ @connection.transaction do
+ @connection.create_table('hstores') do |t|
+ t.hstore 'tags'
+ end
+ end
+ rescue ActiveRecord::StatementInvalid
+ return skip "do not test on PG without hstore"
+ end
+ end
+
+ def teardown
+ @connection.execute 'drop table if exists hstores'
+ end
+
+ def test_column
+ column = Hstore.columns.find { |c| c.name == 'tags' }
+ assert column
+ assert_equal :hstore, column.type
+ end
+
+ def test_type_cast_hstore
+ column = Hstore.columns.find { |c| c.name == 'tags' }
+ assert column
+
+ data = "\"1\"=>\"2\""
+ hash = column.class.cast_hstore data
+ assert_equal({'1' => '2'}, hash)
+ assert_equal({'1' => '2'}, column.type_cast(data))
+ end
+
+ def test_select
+ @connection.execute "insert into hstores (tags) VALUES ('1=>2')"
+ x = Hstore.find :first
+ assert_equal({'1' => '2'}, x.tags)
+ end
+
+ def test_select_multikey
+ @connection.execute "insert into hstores (tags) VALUES ('1=>2,2=>3')"
+ x = Hstore.find :first
+ assert_equal({'1' => '2', '2' => '3'}, x.tags)
+ end
+
+ def test_create
+ assert_cycle('a' => 'b', '1' => '2')
+ end
+
+ def test_quotes
+ assert_cycle('a' => 'b"ar', '1"foo' => '2')
+ end
+
+ def test_whitespace
+ assert_cycle('a b' => 'b ar', '1"foo' => '2')
+ end
+
+ def test_backslash
+ assert_cycle('a\\b' => 'b\\ar', '1"foo' => '2')
+ end
+
+ def test_comma
+ assert_cycle('a, b' => 'bar', '1"foo' => '2')
+ end
+
+ def test_arrow
+ assert_cycle('a=>b' => 'bar', '1"foo' => '2')
+ end
+
+ private
+ def assert_cycle hash
+ x = Hstore.create!(:tags => hash)
+ x.reload
+ assert_equal(hash, x.tags)
+
+ # make sure updates work
+ x.tags = hash
+ x.save!
+ x.reload
+ assert_equal(hash, x.tags)
+ end
+end
diff --git a/activerecord/test/cases/associations/eager_load_nested_include_test.rb b/activerecord/test/cases/associations/eager_load_nested_include_test.rb
index 2cf9f89c3c..1e1958410c 100644
--- a/activerecord/test/cases/associations/eager_load_nested_include_test.rb
+++ b/activerecord/test/cases/associations/eager_load_nested_include_test.rb
@@ -6,7 +6,6 @@ require 'models/comment'
require 'models/category'
require 'models/categorization'
require 'models/tagging'
-require 'active_support/core_ext/array/random_access'
module Remembered
extend ActiveSupport::Concern
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 1dc71ac4cc..3d759e64f8 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -1095,4 +1095,11 @@ class EagerAssociationTest < ActiveRecord::TestCase
Post.includes(:comments).order(nil).where(:comments => {:body => "Thank you for the welcome"}).first
end
end
+
+ def test_deep_including_through_habtm
+ posts = Post.find(:all, :include => {:categories => :categorizations}, :order => "posts.id")
+ assert_no_queries { assert_equal 2, posts[0].categories[0].categorizations.length }
+ assert_no_queries { assert_equal 1, posts[0].categories[1].categorizations.length }
+ assert_no_queries { assert_equal 2, posts[1].categories[0].categorizations.length }
+ end
end
diff --git a/activerecord/test/cases/associations/extension_test.rb b/activerecord/test/cases/associations/extension_test.rb
index 395b59258d..d7c489c2b5 100644
--- a/activerecord/test/cases/associations/extension_test.rb
+++ b/activerecord/test/cases/associations/extension_test.rb
@@ -36,11 +36,6 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase
end
def test_marshalling_extensions
- if ENV['TRAVIS'] && RUBY_VERSION == "1.8.7"
- return skip("Marshalling tests disabled for Ruby 1.8.7 on Travis CI due to what appears " \
- "to be a Ruby bug.")
- end
-
david = developers(:david)
assert_equal projects(:action_controller), david.projects.find_most_recent
@@ -51,11 +46,6 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase
end
def test_marshalling_named_extensions
- if ENV['TRAVIS'] && RUBY_VERSION == "1.8.7"
- return skip("Marshalling tests disabled for Ruby 1.8.7 on Travis CI due to what appears " \
- "to be a Ruby bug.")
- end
-
david = developers(:david)
assert_equal projects(:action_controller), david.projects_extended_by_name.find_most_recent
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index 5e9f8028e9..8e509a9792 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -102,7 +102,6 @@ class AttributeMethodsTest < ActiveRecord::TestCase
def test_respond_to?
topic = Topic.find(1)
assert_respond_to topic, "title"
- assert_respond_to topic, "_title"
assert_respond_to topic, "title?"
assert_respond_to topic, "title="
assert_respond_to topic, :title
@@ -114,19 +113,12 @@ class AttributeMethodsTest < ActiveRecord::TestCase
assert !topic.respond_to?(:nothingness)
end
- def test_deprecated_underscore_method
- topic = Topic.find(1)
- assert_equal topic.title, assert_deprecated { topic._title }
- end
-
def test_respond_to_with_custom_primary_key
keyboard = Keyboard.create
assert_not_nil keyboard.key_number
assert_equal keyboard.key_number, keyboard.id
assert keyboard.respond_to?('key_number')
- assert keyboard.respond_to?('_key_number')
assert keyboard.respond_to?('id')
- assert keyboard.respond_to?('_id')
end
# Syck calls respond_to? before actually calling initialize
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 1012bfbd94..f102634ef1 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -1357,22 +1357,6 @@ class BasicsTest < ActiveRecord::TestCase
assert_equal author_name, Topic.find(topic.id).author_name
end
- if RUBY_VERSION < '1.9'
- def test_quote_chars
- with_kcode('UTF8') do
- str = 'The Narrator'
- topic = Topic.create(:author_name => str)
- assert_equal str, topic.author_name
-
- assert_kind_of ActiveSupport::Multibyte.proxy_class, str.mb_chars
- topic = Topic.find_by_author_name(str.mb_chars)
-
- assert_kind_of Topic, topic
- assert_equal str, topic.author_name, "The right topic should have been found by name even with name passed as Chars"
- end
- end
- end
-
def test_toggle_attribute
assert !topics(:first).approved?
topics(:first).toggle!(:approved)
@@ -1399,17 +1383,6 @@ class BasicsTest < ActiveRecord::TestCase
assert_equal dev, dev.reload
end
- def test_set_table_name_with_value
- k = Class.new( ActiveRecord::Base )
- k.table_name = "foo"
- assert_equal "foo", k.table_name
-
- assert_deprecated do
- k.set_table_name "bar"
- end
- assert_equal "bar", k.table_name
- end
-
def test_switching_between_table_name
assert_difference("GoodJoke.count") do
Joke.table_name = "cold_jokes"
@@ -1432,17 +1405,6 @@ class BasicsTest < ActiveRecord::TestCase
assert_equal klass.connection.quote_table_name("bar"), klass.quoted_table_name
end
- def test_set_table_name_with_block
- k = Class.new( ActiveRecord::Base )
- assert_deprecated do
- k.set_table_name "foo"
- k.set_table_name do
- ActiveSupport::Deprecation.silence { original_table_name } + "ks"
- end
- end
- assert_equal "fooks", k.table_name
- end
-
def test_set_table_name_with_inheritance
k = Class.new( ActiveRecord::Base )
def k.name; "Foo"; end
@@ -1450,145 +1412,6 @@ class BasicsTest < ActiveRecord::TestCase
assert_equal "foosks", k.table_name
end
- def test_original_table_name
- k = Class.new(ActiveRecord::Base)
- def k.name; "Foo"; end
- k.table_name = "bar"
-
- assert_deprecated do
- assert_equal "foos", k.original_table_name
- end
-
- k = Class.new(ActiveRecord::Base)
- k.table_name = "omg"
- k.table_name = "wtf"
-
- assert_deprecated do
- assert_equal "omg", k.original_table_name
- end
- end
-
- def test_set_primary_key_with_value
- k = Class.new( ActiveRecord::Base )
- k.primary_key = "foo"
- assert_equal "foo", k.primary_key
-
- assert_deprecated do
- k.set_primary_key "bar"
- end
- assert_equal "bar", k.primary_key
- end
-
- def test_set_primary_key_with_block
- k = Class.new( ActiveRecord::Base )
- k.primary_key = 'id'
-
- assert_deprecated do
- k.set_primary_key do
- "sys_" + ActiveSupport::Deprecation.silence { original_primary_key }
- end
- end
- assert_equal "sys_id", k.primary_key
- end
-
- def test_original_primary_key
- k = Class.new(ActiveRecord::Base)
- def k.name; "Foo"; end
- k.table_name = "posts"
- k.primary_key = "bar"
-
- assert_deprecated do
- assert_equal "id", k.original_primary_key
- end
-
- k = Class.new(ActiveRecord::Base)
- k.primary_key = "omg"
- k.primary_key = "wtf"
-
- assert_deprecated do
- assert_equal "omg", k.original_primary_key
- end
- end
-
- def test_set_inheritance_column_with_value
- k = Class.new( ActiveRecord::Base )
- k.inheritance_column = "foo"
- assert_equal "foo", k.inheritance_column
-
- assert_deprecated do
- k.set_inheritance_column "bar"
- end
- assert_equal "bar", k.inheritance_column
- end
-
- def test_set_inheritance_column_with_block
- k = Class.new( ActiveRecord::Base )
- assert_deprecated do
- k.set_inheritance_column do
- ActiveSupport::Deprecation.silence { original_inheritance_column } + "_id"
- end
- end
- assert_equal "type_id", k.inheritance_column
- end
-
- def test_original_inheritance_column
- k = Class.new(ActiveRecord::Base)
- def k.name; "Foo"; end
- k.inheritance_column = "omg"
-
- assert_deprecated do
- assert_equal "type", k.original_inheritance_column
- end
- end
-
- def test_set_sequence_name_with_value
- k = Class.new( ActiveRecord::Base )
- k.sequence_name = "foo"
- assert_equal "foo", k.sequence_name
-
- assert_deprecated do
- k.set_sequence_name "bar"
- end
- assert_equal "bar", k.sequence_name
- end
-
- def test_set_sequence_name_with_block
- k = Class.new( ActiveRecord::Base )
- k.table_name = "projects"
- orig_name = k.sequence_name
- return skip "sequences not supported by db" unless orig_name
-
- assert_deprecated do
- k.set_sequence_name do
- ActiveSupport::Deprecation.silence { original_sequence_name } + "_lol"
- end
- end
- assert_equal orig_name + "_lol", k.sequence_name
- end
-
- def test_original_sequence_name
- k = Class.new(ActiveRecord::Base)
- k.table_name = "projects"
- orig_name = k.sequence_name
- return skip "sequences not supported by db" unless orig_name
-
- k = Class.new(ActiveRecord::Base)
- k.table_name = "projects"
- k.sequence_name = "omg"
-
- assert_deprecated do
- assert_equal orig_name, k.original_sequence_name
- end
-
- k = Class.new(ActiveRecord::Base)
- k.table_name = "projects"
- k.sequence_name = "omg"
- k.sequence_name = "wtf"
- assert_deprecated do
- assert_equal "omg", k.original_sequence_name
- end
- end
-
def test_sequence_name_with_abstract_class
ak = Class.new(ActiveRecord::Base)
ak.abstract_class = true
@@ -1914,7 +1737,7 @@ class BasicsTest < ActiveRecord::TestCase
def test_benchmark_with_log_level
original_logger = ActiveRecord::Base.logger
log = StringIO.new
- ActiveRecord::Base.logger = Logger.new(log)
+ ActiveRecord::Base.logger = ActiveSupport::Logger.new(log)
ActiveRecord::Base.logger.level = Logger::WARN
ActiveRecord::Base.benchmark("Debug Topic Count", :level => :debug) { Topic.count }
ActiveRecord::Base.benchmark("Warn Topic Count", :level => :warn) { Topic.count }
@@ -1929,7 +1752,7 @@ class BasicsTest < ActiveRecord::TestCase
def test_benchmark_with_use_silence
original_logger = ActiveRecord::Base.logger
log = StringIO.new
- ActiveRecord::Base.logger = Logger.new(log)
+ ActiveRecord::Base.logger = ActiveSupport::Logger.new(log)
ActiveRecord::Base.benchmark("Logging", :level => :debug, :silence => false) { ActiveRecord::Base.logger.debug "Quiet" }
assert_match(/Quiet/, log.string)
ensure
@@ -1981,11 +1804,6 @@ class BasicsTest < ActiveRecord::TestCase
end
def test_marshal_round_trip
- if ENV['TRAVIS'] && RUBY_VERSION == "1.8.7"
- return skip("Marshalling tests disabled for Ruby 1.8.7 on Travis CI due to what appears " \
- "to be a Ruby bug.")
- end
-
expected = posts(:welcome)
marshalled = Marshal.dump(expected)
actual = Marshal.load(marshalled)
@@ -1994,11 +1812,6 @@ class BasicsTest < ActiveRecord::TestCase
end
def test_marshal_new_record_round_trip
- if ENV['TRAVIS'] && RUBY_VERSION == "1.8.7"
- return skip("Marshalling tests disabled for Ruby 1.8.7 on Travis CI due to what appears " \
- "to be a Ruby bug.")
- end
-
marshalled = Marshal.dump(Post.new)
post = Marshal.load(marshalled)
@@ -2006,11 +1819,6 @@ class BasicsTest < ActiveRecord::TestCase
end
def test_marshalling_with_associations
- if ENV['TRAVIS'] && RUBY_VERSION == "1.8.7"
- return skip("Marshalling tests disabled for Ruby 1.8.7 on Travis CI due to what appears " \
- "to be a Ruby bug.")
- end
-
post = Post.new
post.comments.build
diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb
index be7edb858f..f7ee83998d 100644
--- a/activerecord/test/cases/locking_test.rb
+++ b/activerecord/test/cases/locking_test.rb
@@ -226,48 +226,6 @@ class OptimisticLockingTest < ActiveRecord::TestCase
end
end
-class SetLockingColumnTest < ActiveRecord::TestCase
- def test_set_set_locking_column_with_value
- k = Class.new( ActiveRecord::Base )
- k.locking_column = "foo"
- assert_equal "foo", k.locking_column
-
- assert_deprecated do
- k.set_locking_column "bar"
- end
- assert_equal "bar", k.locking_column
- end
-
- def test_set_locking_column_with_block
- k = Class.new( ActiveRecord::Base )
- k.locking_column = 'foo'
-
- assert_deprecated do
- k.set_locking_column do
- "lock_" + ActiveSupport::Deprecation.silence { original_locking_column }
- end
- end
- assert_equal "lock_foo", k.locking_column
- end
-
- def test_original_locking_column
- k = Class.new(ActiveRecord::Base)
- k.locking_column = "bar"
-
- assert_deprecated do
- assert_equal ActiveRecord::Locking::Optimistic::ClassMethods::DEFAULT_LOCKING_COLUMN, k.original_locking_column
- end
-
- k = Class.new(ActiveRecord::Base)
- k.locking_column = "omg"
- k.locking_column = "wtf"
-
- assert_deprecated do
- assert_equal "omg", k.original_locking_column
- end
- end
-end
-
class OptimisticLockingWithSchemaChangeTest < ActiveRecord::TestCase
fixtures :people, :legacy_things, :references
@@ -421,16 +379,6 @@ unless current_adapter?(:SybaseAdapter, :OpenBaseAdapter) || in_memory_db?
assert first.end > second.end
end
- # Hit by ruby deadlock detection since connection checkout is mutexed.
- if RUBY_VERSION < '1.9.0'
- def test_second_lock_waits
- assert [0.2, 1, 5].any? { |zzz|
- first, second = duel(zzz) { Person.find 1, :lock => true }
- second.end > first.end
- }
- end
- end
-
protected
def duel(zzz = 5)
t0, t1, t2, t3 = nil, nil, nil, nil
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index 0eb3d900bd..e17ba76437 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -1,5 +1,4 @@
require "cases/helper"
-require 'active_support/core_ext/array/random_access'
require 'models/post'
require 'models/topic'
require 'models/comment'
diff --git a/activerecord/test/cases/pooled_connections_test.rb b/activerecord/test/cases/pooled_connections_test.rb
index bc3dfb1078..296621c0d1 100644
--- a/activerecord/test/cases/pooled_connections_test.rb
+++ b/activerecord/test/cases/pooled_connections_test.rb
@@ -33,14 +33,6 @@ class PooledConnectionsTest < ActiveRecord::TestCase
end
# Will deadlock due to lack of Monitor timeouts in 1.9
- if RUBY_VERSION < '1.9'
- def test_pooled_connection_checkout
- checkout_connections
- assert_equal 2, @connections.length
- assert_equal 2, @timed_out
- end
- end
-
def checkout_checkin_connections(pool_size, threads)
ActiveRecord::Base.establish_connection(@connection.merge({:pool => pool_size, :wait_timeout => 0.5}))
@connection_count = 0
diff --git a/activerecord/test/cases/validations/association_validation_test.rb b/activerecord/test/cases/validations/association_validation_test.rb
index 768fbc5b0a..f155b9bc40 100644
--- a/activerecord/test/cases/validations/association_validation_test.rb
+++ b/activerecord/test/cases/validations/association_validation_test.rb
@@ -91,14 +91,12 @@ class AssociationValidationTest < ActiveRecord::TestCase
end
def test_validates_size_of_association_utf8
- with_kcode('UTF8') do
- assert_nothing_raised { Owner.validates_size_of :pets, :minimum => 1 }
- o = Owner.new('name' => 'あいうえおかきくけこ')
- assert !o.save
- assert o.errors[:pets].any?
- o.pets.build('name' => 'あいうえおかきくけこ')
- assert o.valid?
- end
+ assert_nothing_raised { Owner.validates_size_of :pets, :minimum => 1 }
+ o = Owner.new('name' => 'あいうえおかきくけこ')
+ assert !o.save
+ assert o.errors[:pets].any?
+ o.pets.build('name' => 'あいうえおかきくけこ')
+ assert o.valid?
end
def test_validates_presence_of_belongs_to_association__parent_is_new_record
diff --git a/activerecord/test/cases/validations/uniqueness_validation_test.rb b/activerecord/test/cases/validations/uniqueness_validation_test.rb
index 0f1b3667cc..382ad0a06a 100644
--- a/activerecord/test/cases/validations/uniqueness_validation_test.rb
+++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb
@@ -149,16 +149,14 @@ class UniquenessValidationTest < ActiveRecord::TestCase
assert t2.valid?, "should validate with nil"
assert t2.save, "should save with nil"
- with_kcode('UTF8') do
- t_utf8 = Topic.new("title" => "Я тоже уникальный!")
- assert t_utf8.save, "Should save t_utf8 as unique"
-
- # If database hasn't UTF-8 character set, this test fails
- if Topic.find(t_utf8, :select => 'LOWER(title) AS title').title == "я тоже уникальный!"
- t2_utf8 = Topic.new("title" => "я тоже УНИКАЛЬНЫЙ!")
- assert !t2_utf8.valid?, "Shouldn't be valid"
- assert !t2_utf8.save, "Shouldn't save t2_utf8 as unique"
- end
+ t_utf8 = Topic.new("title" => "Я тоже уникальный!")
+ assert t_utf8.save, "Should save t_utf8 as unique"
+
+ # If database hasn't UTF-8 character set, this test fails
+ if Topic.find(t_utf8, :select => 'LOWER(title) AS title').title == "я тоже уникальный!"
+ t2_utf8 = Topic.new("title" => "я тоже УНИКАЛЬНЫЙ!")
+ assert !t2_utf8.valid?, "Shouldn't be valid"
+ assert !t2_utf8.save, "Shouldn't save t2_utf8 as unique"
end
end
@@ -256,13 +254,11 @@ class UniquenessValidationTest < ActiveRecord::TestCase
end
def test_validate_uniqueness_with_limit_and_utf8
- with_kcode('UTF8') do
- # Event.title is limited to 5 characters
- e1 = Event.create(:title => "一二三四五")
- assert e1.valid?, "Could not create an event with a unique, 5 character title"
- e2 = Event.create(:title => "一二三四五六七八")
- assert !e2.valid?, "Created an event whose title, with limit taken into account, is not unique"
- end
+ # Event.title is limited to 5 characters
+ e1 = Event.create(:title => "一二三四五")
+ assert e1.valid?, "Could not create an event with a unique, 5 character title"
+ e2 = Event.create(:title => "一二三四五六七八")
+ assert !e2.valid?, "Created an event whose title, with limit taken into account, is not unique"
end
def test_validate_straight_inheritance_uniqueness