aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/associations/inner_join_association_test.rb14
-rwxr-xr-xactiverecord/test/base_test.rb8
-rw-r--r--activerecord/test/fixtures/db_definitions/schema.rb4
-rw-r--r--activerecord/test/fixtures/warehouse-things.yml3
-rw-r--r--activerecord/test/fixtures/warehouse_thing.rb5
-rwxr-xr-xactiverecord/test/validations_test.rb10
6 files changed, 35 insertions, 9 deletions
diff --git a/activerecord/test/associations/inner_join_association_test.rb b/activerecord/test/associations/inner_join_association_test.rb
index b108ee560c..56735afae5 100644
--- a/activerecord/test/associations/inner_join_association_test.rb
+++ b/activerecord/test/associations/inner_join_association_test.rb
@@ -10,30 +10,30 @@ class InnerJoinAssociationTest < ActiveSupport::TestCase
def test_construct_finder_sql_creates_inner_joins
sql = Author.send(:construct_finder_sql, :joins => :posts)
- assert_match /INNER JOIN `?posts`? ON `?posts`?.author_id = authors.id/, sql
+ assert_match /INNER JOIN .?posts.? ON .?posts.?.author_id = authors.id/, sql
end
def test_construct_finder_sql_cascades_inner_joins
sql = Author.send(:construct_finder_sql, :joins => {:posts => :comments})
- assert_match /INNER JOIN `?posts`? ON `?posts`?.author_id = authors.id/, sql
- assert_match /INNER JOIN `?comments`? ON `?comments`?.post_id = posts.id/, sql
+ assert_match /INNER JOIN .?posts.? ON .?posts.?.author_id = authors.id/, sql
+ assert_match /INNER JOIN .?comments.? ON .?comments.?.post_id = posts.id/, sql
end
def test_construct_finder_sql_inner_joins_through_associations
sql = Author.send(:construct_finder_sql, :joins => :categorized_posts)
- assert_match /INNER JOIN `?categorizations`?.*INNER JOIN `?posts`?/, sql
+ assert_match /INNER JOIN .?categorizations.?.*INNER JOIN .?posts.?/, sql
end
def test_construct_finder_sql_applies_association_conditions
sql = Author.send(:construct_finder_sql, :joins => :categories_like_general, :conditions => "TERMINATING_MARKER")
- assert_match /INNER JOIN `?categories`? ON.*AND.*`?General`?.*TERMINATING_MARKER/, sql
+ assert_match /INNER JOIN .?categories.? ON.*AND.*.?General.?.*TERMINATING_MARKER/, sql
end
def test_construct_finder_sql_unpacks_nested_joins
sql = Author.send(:construct_finder_sql, :joins => {:posts => [[:comments]]})
assert_no_match /inner join.*inner join.*inner join/i, sql, "only two join clauses should be present"
- assert_match /INNER JOIN `?posts`? ON `?posts`?.author_id = authors.id/, sql
- assert_match /INNER JOIN `?comments`? ON `?comments`?.post_id = `?posts`?.id/, sql
+ assert_match /INNER JOIN .?posts.? ON .?posts.?.author_id = authors.id/, sql
+ assert_match /INNER JOIN .?comments.? ON .?comments.?.post_id = .?posts.?.id/, sql
end
def test_construct_finder_sql_ignores_empty_joins_hash
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 276b7e100e..a62a4d16c2 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -12,6 +12,7 @@ require 'fixtures/subscriber'
require 'fixtures/keyboard'
require 'fixtures/post'
require 'fixtures/minimalistic'
+require 'fixtures/warehouse_thing'
require 'rexml/document'
class Category < ActiveRecord::Base; end
@@ -71,7 +72,7 @@ class TopicWithProtectedContentAndAccessibleAuthorName < ActiveRecord::Base
end
class BasicsTest < ActiveSupport::TestCase
- fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics
+ fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse-things'
def test_table_exists
assert !NonExistentTable.table_exists?
@@ -590,6 +591,11 @@ class BasicsTest < ActiveSupport::TestCase
assert_nil Topic.find(2).last_read
end
+ def test_update_all_with_non_standard_table_name
+ assert_equal 1, WarehouseThing.update_all(['value = ?', 0], ['id = ?', 1])
+ assert_equal 0, WarehouseThing.find(1).value
+ end
+
if current_adapter?(:MysqlAdapter)
def test_update_all_with_order_and_limit
assert_equal 1, Topic.update_all("content = 'bulk updated!'", nil, :limit => 1, :order => 'id DESC')
diff --git a/activerecord/test/fixtures/db_definitions/schema.rb b/activerecord/test/fixtures/db_definitions/schema.rb
index a943b84f42..d5affc2ab1 100644
--- a/activerecord/test/fixtures/db_definitions/schema.rb
+++ b/activerecord/test/fixtures/db_definitions/schema.rb
@@ -351,4 +351,8 @@ ActiveRecord::Schema.define do
t.datetime :updated_at
t.datetime :updated_on
end
+
+ create_table 'warehouse-things', :force => true do |t|
+ t.integer :value
+ end
end
diff --git a/activerecord/test/fixtures/warehouse-things.yml b/activerecord/test/fixtures/warehouse-things.yml
new file mode 100644
index 0000000000..9e07ba7db5
--- /dev/null
+++ b/activerecord/test/fixtures/warehouse-things.yml
@@ -0,0 +1,3 @@
+one:
+ id: 1
+ value: 1000 \ No newline at end of file
diff --git a/activerecord/test/fixtures/warehouse_thing.rb b/activerecord/test/fixtures/warehouse_thing.rb
new file mode 100644
index 0000000000..6ace1183cc
--- /dev/null
+++ b/activerecord/test/fixtures/warehouse_thing.rb
@@ -0,0 +1,5 @@
+class WarehouseThing < ActiveRecord::Base
+ set_table_name "warehouse-things"
+
+ validates_uniqueness_of :value
+end \ No newline at end of file
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb
index c4f6f2d6b1..daec199be1 100755
--- a/activerecord/test/validations_test.rb
+++ b/activerecord/test/validations_test.rb
@@ -3,6 +3,7 @@ require 'fixtures/topic'
require 'fixtures/reply'
require 'fixtures/person'
require 'fixtures/developer'
+require 'fixtures/warehouse_thing'
# The following methods in Topic are used in test_conditional_validation_*
class Topic
@@ -54,7 +55,7 @@ class Thaumaturgist < IneptWizard
end
class ValidationsTest < ActiveSupport::TestCase
- fixtures :topics, :developers
+ fixtures :topics, :developers, 'warehouse-things'
def setup
Topic.write_inheritable_attribute(:validate, nil)
@@ -435,6 +436,13 @@ class ValidationsTest < ActiveSupport::TestCase
assert t2.save, "should save with nil"
end
+ def test_validate_uniqueness_with_non_standard_table_names
+ i1 = WarehouseThing.create(:value => 1000)
+ assert !i1.valid?, "i1 should not be valid"
+ assert i1.errors.on(:value), "Should not be empty"
+ end
+
+
def test_validate_straight_inheritance_uniqueness
w1 = IneptWizard.create(:name => "Rincewind", :city => "Ankh-Morpork")
assert w1.valid?, "Saving w1"