diff options
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/connection_pool_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/connection_specification/resolver_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relation/where_test.rb | 61 | ||||
-rw-r--r-- | activerecord/test/cases/store_test.rb | 14 | ||||
-rw-r--r-- | activerecord/test/cases/tasks/mysql_rake_test.rb | 21 |
5 files changed, 79 insertions, 21 deletions
diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb index 8287b35aaf..0718d0886f 100644 --- a/activerecord/test/cases/connection_pool_test.rb +++ b/activerecord/test/cases/connection_pool_test.rb @@ -89,7 +89,7 @@ module ActiveRecord end def test_full_pool_exception - assert_raises(PoolFullError) do + assert_raises(ConnectionTimeoutError) do (@pool.size + 1).times do @pool.checkout end diff --git a/activerecord/test/cases/connection_specification/resolver_test.rb b/activerecord/test/cases/connection_specification/resolver_test.rb index 673a2b2b88..434d2b7ba5 100644 --- a/activerecord/test/cases/connection_specification/resolver_test.rb +++ b/activerecord/test/cases/connection_specification/resolver_test.rb @@ -13,7 +13,6 @@ module ActiveRecord spec = resolve 'mysql://foo?encoding=utf8' assert_equal({ :adapter => "mysql", - :database => "", :host => "foo", :encoding => "utf8" }, spec) end @@ -33,7 +32,6 @@ module ActiveRecord spec = resolve 'mysql://foo:123?encoding=utf8' assert_equal({ :adapter => "mysql", - :database => "", :port => 123, :host => "foo", :encoding => "utf8" }, spec) diff --git a/activerecord/test/cases/relation/where_test.rb b/activerecord/test/cases/relation/where_test.rb index 90c690e266..3163cf79ad 100644 --- a/activerecord/test/cases/relation/where_test.rb +++ b/activerecord/test/cases/relation/where_test.rb @@ -1,10 +1,71 @@ require "cases/helper" +require 'models/author' +require 'models/price_estimate' +require 'models/treasure' require 'models/post' +require 'models/comment' module ActiveRecord class WhereTest < ActiveRecord::TestCase fixtures :posts + def test_belongs_to_shallow_where + author = Author.new + author.id = 1 + + assert_equal Post.where(author_id: 1).to_sql, Post.where(author: author).to_sql + end + + def test_belongs_to_nested_where + parent = Comment.new + parent.id = 1 + + expected = Post.where(comments: { parent_id: 1 }).joins(:comments) + actual = Post.where(comments: { parent: parent }).joins(:comments) + + assert_equal expected.to_sql, actual.to_sql + end + + def test_polymorphic_shallow_where + treasure = Treasure.new + treasure.id = 1 + + expected = PriceEstimate.where(estimate_of_type: 'Treasure', estimate_of_id: 1) + actual = PriceEstimate.where(estimate_of: treasure) + + assert_equal expected.to_sql, actual.to_sql + end + + def test_polymorphic_sti_shallow_where + treasure = HiddenTreasure.new + treasure.id = 1 + + expected = PriceEstimate.where(estimate_of_type: 'Treasure', estimate_of_id: 1) + actual = PriceEstimate.where(estimate_of: treasure) + + assert_equal expected.to_sql, actual.to_sql + end + + def test_polymorphic_nested_where + thing = Post.new + thing.id = 1 + + expected = Treasure.where(price_estimates: { thing_type: 'Post', thing_id: 1 }).joins(:price_estimates) + actual = Treasure.where(price_estimates: { thing: thing }).joins(:price_estimates) + + assert_equal expected.to_sql, actual.to_sql + end + + def test_polymorphic_sti_nested_where + treasure = HiddenTreasure.new + treasure.id = 1 + + expected = Treasure.where(price_estimates: { estimate_of_type: 'Treasure', estimate_of_id: 1 }).joins(:price_estimates) + actual = Treasure.where(price_estimates: { estimate_of: treasure }).joins(:price_estimates) + + assert_equal expected.to_sql, actual.to_sql + end + def test_where_error assert_raises(ActiveRecord::StatementInvalid) do Post.where(:id => { 'posts.author_id' => 10 }).first diff --git a/activerecord/test/cases/store_test.rb b/activerecord/test/cases/store_test.rb index 2741f223da..dc47d40f41 100644 --- a/activerecord/test/cases/store_test.rb +++ b/activerecord/test/cases/store_test.rb @@ -29,6 +29,12 @@ class StoreTest < ActiveRecord::TestCase assert_equal 'graeters', @john.reload.settings[:icecream] end + test "overriding a read accessor" do + @john.settings[:phone_number] = '1234567890' + + assert_equal '(123) 456-7890', @john.phone_number + end + test "updating the store will mark it as changed" do @john.color = 'red' assert @john.settings_changed? @@ -54,6 +60,12 @@ class StoreTest < ActiveRecord::TestCase assert_equal false, @john.remember_login end + test "overriding a write accessor" do + @john.phone_number = '(123) 456-7890' + + assert_equal '1234567890', @john.settings[:phone_number] + end + test "preserve store attributes data in HashWithIndifferentAccess format without any conversion" do @john.json_data = HashWithIndifferentAccess.new(:height => 'tall', 'weight' => 'heavy') @john.height = 'low' @@ -124,7 +136,7 @@ class StoreTest < ActiveRecord::TestCase end test "all stored attributes are returned" do - assert_equal [:color, :homepage, :favorite_food], Admin::User.stored_attributes[:settings] + assert_equal [:color, :homepage, :favorite_food, :phone_number], Admin::User.stored_attributes[:settings] end test "stores_attributes are class level settings" do diff --git a/activerecord/test/cases/tasks/mysql_rake_test.rb b/activerecord/test/cases/tasks/mysql_rake_test.rb index be591da8d6..46b97a1274 100644 --- a/activerecord/test/cases/tasks/mysql_rake_test.rb +++ b/activerecord/test/cases/tasks/mysql_rake_test.rb @@ -32,7 +32,7 @@ module ActiveRecord with('my-app-db', {:charset => 'latin', :collation => 'latin_ci'}) ActiveRecord::Tasks::DatabaseTasks.create @configuration.merge( - 'charset' => 'latin', 'collation' => 'latin_ci' + 'encoding' => 'latin', 'collation' => 'latin_ci' ) end @@ -176,7 +176,7 @@ module ActiveRecord with('test-db', {:charset => 'latin', :collation => 'latin_ci'}) ActiveRecord::Tasks::DatabaseTasks.purge @configuration.merge( - 'charset' => 'latin', 'collation' => 'latin_ci' + 'encoding' => 'latin', 'collation' => 'latin_ci' ) end end @@ -219,44 +219,31 @@ module ActiveRecord class MySQLStructureDumpTest < ActiveRecord::TestCase def setup - @connection = stub(:structure_dump => true) @configuration = { 'adapter' => 'mysql', 'database' => 'test-db' } - - ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) end def test_structure_dump filename = "awesome-file.sql" - ActiveRecord::Base.expects(:establish_connection).with(@configuration) - @connection.expects(:structure_dump) + Kernel.expects(:system).with("mysqldump", "--result-file", filename, "--no-data", "test-db") ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename) - assert File.exists?(filename) - ensure - FileUtils.rm(filename) end end class MySQLStructureLoadTest < ActiveRecord::TestCase def setup - @connection = stub @configuration = { 'adapter' => 'mysql', 'database' => 'test-db' } - - ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) - Kernel.stubs(:system) end def test_structure_load filename = "awesome-file.sql" - Kernel.expects(:system).with('mysql', '--database', 'test-db', '--execute', %{SET FOREIGN_KEY_CHECKS = 0; SOURCE #{filename}; SET FOREIGN_KEY_CHECKS = 1}) + Kernel.expects(:system).with('mysql', '--execute', %{SET FOREIGN_KEY_CHECKS = 0; SOURCE #{filename}; SET FOREIGN_KEY_CHECKS = 1}, "--database", "test-db") ActiveRecord::Tasks::DatabaseTasks.structure_load(@configuration, filename) end |