Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move tests to cases

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8660 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 42b39ae3f2991692672364d7e09b1e4002e66261 1 parent 105a27f
@jeremy jeremy authored
Showing with 513 additions and 515 deletions.
  1. +1 −1  activerecord/test/{ → cases}/aaa_create_tables_test.rb
  2. +1 −1  activerecord/test/{ → cases}/active_schema_test_mysql.rb
  3. 0  activerecord/test/{ → cases}/adapter_test.rb
  4. +95 −95 activerecord/test/{ → cases}/adapter_test_sqlserver.rb
  5. +15 −15 activerecord/test/{ → cases}/aggregations_test.rb
  6. +2 −2 activerecord/test/{ → cases}/ar_schema_test.rb
  7. +6 −7 activerecord/test/{ → cases}/associations/callbacks_test.rb
  8. +10 −10 activerecord/test/{ → cases}/associations/cascaded_eager_loading_test.rb
  9. +3 −3 activerecord/test/{ → cases}/associations/eager_singularization_test.rb
  10. +38 −38 activerecord/test/{ → cases}/associations/eager_test.rb
  11. +6 −6 activerecord/test/{ → cases}/associations/extension_test.rb
  12. +5 −5 activerecord/test/{ → cases}/associations/inner_join_association_test.rb
  13. +15 −15 activerecord/test/{ → cases}/associations/join_model_test.rb
  14. +15 −15 activerecord/test/{ → cases}/associations_test.rb
  15. +6 −6 activerecord/test/{ → cases}/attribute_methods_test.rb
  16. +124 −124 activerecord/test/{ → cases}/base_test.rb
  17. 0  activerecord/test/{ → cases}/binary_test.rb
  18. +20 −20 activerecord/test/{ → cases}/calculations_test.rb
  19. +5 −5 activerecord/test/{ → cases}/callbacks_test.rb
  20. +1 −1  activerecord/test/{ → cases}/class_inheritable_attributes_test.rb
  21. 0  activerecord/test/{ → cases}/column_alias_test.rb
  22. 0  activerecord/test/{ → cases}/connection_test_firebird.rb
  23. 0  activerecord/test/{ → cases}/connection_test_mysql.rb
  24. +11 −11 activerecord/test/{ → cases}/copy_table_test_sqlite.rb
  25. +2 −2 activerecord/test/{ → cases}/datatype_test_postgresql.rb
  26. +1 −1  activerecord/test/{ → cases}/date_time_test.rb
  27. 0  activerecord/test/{ → cases}/default_test_firebird.rb
  28. 0  activerecord/test/{ → cases}/defaults_test.rb
  29. 0  activerecord/test/{ → cases}/deprecated_finder_test.rb
  30. +7 −7 activerecord/test/{ → cases}/finder_test.rb
  31. +3 −3 activerecord/test/{ → cases}/fixtures_test.rb
  32. +11 −11 activerecord/test/{ → cases}/inheritance_test.rb
  33. 0  activerecord/test/{ → cases}/json_serialization_test.rb
  34. +3 −3 activerecord/test/{ → cases}/lifecycle_test.rb
  35. +3 −3 activerecord/test/{ → cases}/locking_test.rb
  36. +24 −24 activerecord/test/{ → cases}/method_scoping_test.rb
  37. +31 −32 activerecord/test/{ → cases}/migration_test.rb
  38. 0  activerecord/test/{ → cases}/migration_test_firebird.rb
  39. +4 −4 activerecord/test/{ → cases}/mixin_test.rb
  40. +3 −3 activerecord/test/{ → cases}/modules_test.rb
  41. 0  activerecord/test/{ → cases}/multiple_db_test.rb
  42. +2 −2 activerecord/test/{ → cases}/pk_test.rb
  43. 0  activerecord/test/{ → cases}/query_cache_test.rb
  44. +3 −3 activerecord/test/{ → cases}/readonly_test.rb
  45. +3 −3 activerecord/test/{ → cases}/reflection_test.rb
  46. +1 −1  activerecord/test/{ → cases}/reserved_word_test_mysql.rb
  47. +1 −1  activerecord/test/{ → cases}/schema_authorization_test_postgresql.rb
  48. +14 −14 activerecord/test/{ → cases}/schema_dumper_test.rb
  49. 0  activerecord/test/{ → cases}/schema_test_postgresql.rb
  50. +3 −3 activerecord/test/{ → cases}/serialization_test.rb
  51. +1 −1  activerecord/test/{ → cases}/synonym_test_oracle.rb
  52. 0  activerecord/test/{ → cases}/table_name_test_sqlserver.rb
  53. +3 −3 activerecord/test/{ → cases}/threaded_connections_test.rb
  54. 0  activerecord/test/{ → cases}/transactions_test.rb
  55. 0  activerecord/test/{ → cases}/unconnected_test.rb
  56. 0  activerecord/test/{ → cases}/validations_test.rb
  57. 0  activerecord/test/{ → cases}/xml_serialization_test.rb
  58. +1 −1  activerecord/test/connections/native_db2/connection.rb
  59. +1 −1  activerecord/test/connections/native_firebird/connection.rb
  60. +1 −1  activerecord/test/connections/native_frontbase/connection.rb
  61. +1 −1  activerecord/test/connections/native_mysql/connection.rb
  62. +1 −1  activerecord/test/connections/native_openbase/connection.rb
  63. +1 −1  activerecord/test/connections/native_oracle/connection.rb
  64. +1 −1  activerecord/test/connections/native_postgresql/connection.rb
  65. +1 −1  activerecord/test/connections/native_sqlite/connection.rb
  66. +1 −1  activerecord/test/connections/native_sqlite3/connection.rb
  67. +1 −1  activerecord/test/connections/native_sqlite3/in_memory_connection.rb
  68. +1 −1  activerecord/test/connections/native_sybase/connection.rb
View
2  activerecord/test/aaa_create_tables_test.rb → activerecord/test/cases/aaa_create_tables_test.rb
@@ -21,7 +21,7 @@ def test_load_schema
end
assert true
end
-
+
def test_drop_and_create_courses_table
if Course.connection.supports_migrations?
eval(File.read("#{File.dirname(__FILE__)}/fixtures/db_definitions/schema2.rb"))
View
2  activerecord/test/active_schema_test_mysql.rb → activerecord/test/cases/active_schema_test_mysql.rb
@@ -38,7 +38,7 @@ def test_add_column_with_limit
def test_drop_table_with_specific_database
assert_equal "DROP TABLE `otherdb`.`people`", drop_table('otherdb.people')
end
-
+
private
def method_missing(method_symbol, *arguments)
ActiveRecord::Base.connection.send(method_symbol, *arguments)
View
0  activerecord/test/adapter_test.rb → activerecord/test/cases/adapter_test.rb
File renamed without changes
View
190 activerecord/test/adapter_test_sqlserver.rb → activerecord/test/cases/adapter_test_sqlserver.rb
@@ -1,95 +1,95 @@
-require 'abstract_unit'
-require 'fixtures/default'
-require 'fixtures/post'
-require 'fixtures/task'
-
-class SqlServerAdapterTest < ActiveSupport::TestCase
- class TableWithRealColumn < ActiveRecord::Base; end
-
- fixtures :posts, :tasks
-
- def setup
- @connection = ActiveRecord::Base.connection
- end
-
- def teardown
- @connection.execute("SET LANGUAGE us_english") rescue nil
- end
-
- def test_real_column_has_float_type
- assert_equal :float, TableWithRealColumn.columns_hash["real_number"].type
- end
-
- # SQL Server 2000 has a bug where some unambiguous date formats are not
- # correctly identified if the session language is set to german
- def test_date_insertion_when_language_is_german
- @connection.execute("SET LANGUAGE deutsch")
-
- assert_nothing_raised do
- Task.create(:starting => Time.utc(2000, 1, 31, 5, 42, 0), :ending => Date.new(2006, 12, 31))
- end
- end
-
- def test_indexes_with_descending_order
- # Make sure we have an index with descending order
- @connection.execute "CREATE INDEX idx_credit_limit ON accounts (credit_limit DESC)" rescue nil
- assert_equal ["credit_limit"], @connection.indexes('accounts').first.columns
- ensure
- @connection.execute "DROP INDEX accounts.idx_credit_limit"
- end
-
- def test_execute_without_block_closes_statement
- assert_all_statements_used_are_closed do
- @connection.execute("SELECT 1")
- end
- end
-
- def test_execute_with_block_closes_statement
- assert_all_statements_used_are_closed do
- @connection.execute("SELECT 1") do |sth|
- assert !sth.finished?, "Statement should still be alive within block"
- end
- end
- end
-
- def test_insert_with_identity_closes_statement
- assert_all_statements_used_are_closed do
- @connection.insert("INSERT INTO accounts ([id], [firm_id],[credit_limit]) values (999, 1, 50)")
- end
- end
-
- def test_insert_without_identity_closes_statement
- assert_all_statements_used_are_closed do
- @connection.insert("INSERT INTO accounts ([firm_id],[credit_limit]) values (1, 50)")
- end
- end
-
- def test_active_closes_statement
- assert_all_statements_used_are_closed do
- @connection.active?
- end
- end
-
- def assert_all_statements_used_are_closed(&block)
- existing_handles = []
- ObjectSpace.each_object(DBI::StatementHandle) {|handle| existing_handles << handle}
- GC.disable
-
- yield
-
- used_handles = []
- ObjectSpace.each_object(DBI::StatementHandle) {|handle| used_handles << handle unless existing_handles.include? handle}
-
- assert_block "No statements were used within given block" do
- used_handles.size > 0
- end
-
- ObjectSpace.each_object(DBI::StatementHandle) do |handle|
- assert_block "Statement should have been closed within given block" do
- handle.finished?
- end
- end
- ensure
- GC.enable
- end
-end
+require 'abstract_unit'
+require 'fixtures/default'
+require 'fixtures/post'
+require 'fixtures/task'
+
+class SqlServerAdapterTest < ActiveSupport::TestCase
+ class TableWithRealColumn < ActiveRecord::Base; end
+
+ fixtures :posts, :tasks
+
+ def setup
+ @connection = ActiveRecord::Base.connection
+ end
+
+ def teardown
+ @connection.execute("SET LANGUAGE us_english") rescue nil
+ end
+
+ def test_real_column_has_float_type
+ assert_equal :float, TableWithRealColumn.columns_hash["real_number"].type
+ end
+
+ # SQL Server 2000 has a bug where some unambiguous date formats are not
+ # correctly identified if the session language is set to german
+ def test_date_insertion_when_language_is_german
+ @connection.execute("SET LANGUAGE deutsch")
+
+ assert_nothing_raised do
+ Task.create(:starting => Time.utc(2000, 1, 31, 5, 42, 0), :ending => Date.new(2006, 12, 31))
+ end
+ end
+
+ def test_indexes_with_descending_order
+ # Make sure we have an index with descending order
+ @connection.execute "CREATE INDEX idx_credit_limit ON accounts (credit_limit DESC)" rescue nil
+ assert_equal ["credit_limit"], @connection.indexes('accounts').first.columns
+ ensure
+ @connection.execute "DROP INDEX accounts.idx_credit_limit"
+ end
+
+ def test_execute_without_block_closes_statement
+ assert_all_statements_used_are_closed do
+ @connection.execute("SELECT 1")
+ end
+ end
+
+ def test_execute_with_block_closes_statement
+ assert_all_statements_used_are_closed do
+ @connection.execute("SELECT 1") do |sth|
+ assert !sth.finished?, "Statement should still be alive within block"
+ end
+ end
+ end
+
+ def test_insert_with_identity_closes_statement
+ assert_all_statements_used_are_closed do
+ @connection.insert("INSERT INTO accounts ([id], [firm_id],[credit_limit]) values (999, 1, 50)")
+ end
+ end
+
+ def test_insert_without_identity_closes_statement
+ assert_all_statements_used_are_closed do
+ @connection.insert("INSERT INTO accounts ([firm_id],[credit_limit]) values (1, 50)")
+ end
+ end
+
+ def test_active_closes_statement
+ assert_all_statements_used_are_closed do
+ @connection.active?
+ end
+ end
+
+ def assert_all_statements_used_are_closed(&block)
+ existing_handles = []
+ ObjectSpace.each_object(DBI::StatementHandle) {|handle| existing_handles << handle}
+ GC.disable
+
+ yield
+
+ used_handles = []
+ ObjectSpace.each_object(DBI::StatementHandle) {|handle| used_handles << handle unless existing_handles.include? handle}
+
+ assert_block "No statements were used within given block" do
+ used_handles.size > 0
+ end
+
+ ObjectSpace.each_object(DBI::StatementHandle) do |handle|
+ assert_block "Statement should have been closed within given block" do
+ handle.finished?
+ end
+ end
+ ensure
+ GC.enable
+ end
+end
View
30 activerecord/test/aggregations_test.rb → activerecord/test/cases/aggregations_test.rb
@@ -1,5 +1,5 @@
require 'abstract_unit'
-require 'fixtures/customer'
+require 'models/customer'
class AggregationsTest < ActiveSupport::TestCase
fixtures :customers
@@ -9,36 +9,36 @@ def test_find_single_value_object
assert_kind_of Money, customers(:david).balance
assert_equal 300, customers(:david).balance.exchange_to("DKK").amount
end
-
+
def test_find_multiple_value_object
assert_equal customers(:david).address_street, customers(:david).address.street
assert(
customers(:david).address.close_to?(Address.new("Different Street", customers(:david).address_city, customers(:david).address_country))
)
end
-
+
def test_change_single_value_object
customers(:david).balance = Money.new(100)
customers(:david).save
assert_equal 100, customers(:david).reload.balance.amount
end
-
+
def test_immutable_value_objects
customers(:david).balance = Money.new(100)
assert_raise(ActiveSupport::FrozenObjectError) { customers(:david).balance.instance_eval { @amount = 20 } }
- end
-
+ end
+
def test_inferred_mapping
assert_equal "35.544623640962634", customers(:david).gps_location.latitude
assert_equal "-105.9309951055148", customers(:david).gps_location.longitude
-
+
customers(:david).gps_location = GpsLocation.new("39x-110")
assert_equal "39", customers(:david).gps_location.latitude
assert_equal "-110", customers(:david).gps_location.longitude
-
+
customers(:david).save
-
+
customers(:david).reload
assert_equal "39", customers(:david).gps_location.latitude
@@ -53,7 +53,7 @@ def test_reloaded_instance_refreshes_aggregations
customers(:david).reload
assert_equal '24x113', customers(:david)['gps_location']
- assert_equal GpsLocation.new('24x113'), customers(:david).gps_location
+ assert_equal GpsLocation.new('24x113'), customers(:david).gps_location
end
def test_gps_equality
@@ -63,32 +63,32 @@ def test_gps_equality
def test_gps_inequality
assert GpsLocation.new('39x110') != GpsLocation.new('39x111')
end
-
+
def test_allow_nil_gps_is_nil
assert_equal nil, customers(:zaphod).gps_location
end
-
+
def test_allow_nil_gps_set_to_nil
customers(:david).gps_location = nil
customers(:david).save
customers(:david).reload
assert_equal nil, customers(:david).gps_location
end
-
+
def test_allow_nil_set_address_attributes_to_nil
customers(:zaphod).address = nil
assert_equal nil, customers(:zaphod).attributes[:address_street]
assert_equal nil, customers(:zaphod).attributes[:address_city]
assert_equal nil, customers(:zaphod).attributes[:address_country]
end
-
+
def test_allow_nil_address_set_to_nil
customers(:zaphod).address = nil
customers(:zaphod).save
customers(:zaphod).reload
assert_equal nil, customers(:zaphod).address
end
-
+
def test_nil_raises_error_when_allow_nil_is_false
assert_raise(NoMethodError) { customers(:david).balance = nil }
end
View
4 activerecord/test/ar_schema_test.rb → activerecord/test/cases/ar_schema_test.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
-require "#{File.dirname(__FILE__)}/../lib/active_record/schema"
+require 'active_record/schema'
-if ActiveRecord::Base.connection.supports_migrations?
+if ActiveRecord::Base.connection.supports_migrations?
class ActiveRecordSchemaTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
View
13 activerecord/test/associations/callbacks_test.rb → ...erecord/test/cases/associations/callbacks_test.rb
@@ -1,10 +1,10 @@
require 'abstract_unit'
-require 'fixtures/post'
-require 'fixtures/comment'
-require 'fixtures/author'
-require 'fixtures/category'
-require 'fixtures/project'
-require 'fixtures/developer'
+require 'models/post'
+require 'models/comment'
+require 'models/author'
+require 'models/category'
+require 'models/project'
+require 'models/developer'
class AssociationCallbacksTest < ActiveSupport::TestCase
fixtures :posts, :authors, :projects, :developers
@@ -144,4 +144,3 @@ def test_dont_add_if_before_callback_raises_exception
assert !@david.unchangable_posts.include?(@authorless)
end
end
-
View
20 .../test/associations/cascaded_eager_loading_test.rb → ...cases/associations/cascaded_eager_loading_test.rb
@@ -1,12 +1,12 @@
require 'abstract_unit'
-require 'fixtures/post'
-require 'fixtures/comment'
-require 'fixtures/author'
-require 'fixtures/category'
-require 'fixtures/categorization'
-require 'fixtures/company'
-require 'fixtures/topic'
-require 'fixtures/reply'
+require 'models/post'
+require 'models/comment'
+require 'models/author'
+require 'models/category'
+require 'models/categorization'
+require 'models/company'
+require 'models/topic'
+require 'models/reply'
class CascadedEagerLoadingTest < ActiveSupport::TestCase
fixtures :authors, :mixins, :companies, :posts, :topics
@@ -93,8 +93,8 @@ def test_eager_association_loading_of_stis_with_multiple_references
end
end
-require 'fixtures/vertex'
-require 'fixtures/edge'
+require 'models/vertex'
+require 'models/edge'
class CascadedEagerLoadingTest < ActiveSupport::TestCase
fixtures :edges, :vertices
View
6 ...d/test/associations/eager_singularization_test.rb → .../cases/associations/eager_singularization_test.rb
@@ -85,7 +85,7 @@ def setup
@have_tables = false
end
end
-
+
def teardown
ActiveRecord::Base.connection.drop_table :viri
ActiveRecord::Base.connection.drop_table :octopi
@@ -99,7 +99,7 @@ def teardown
ActiveRecord::Base.connection.drop_table :dresses
ActiveRecord::Base.connection.drop_table :compresses
end
-
+
def test_eager_no_extra_singularization_belongs_to
return unless @have_tables
assert_nothing_raised do
@@ -135,7 +135,7 @@ def test_eager_no_extra_singularization_has_many_through_belongs_to
Crisis.find(:all, :include => :successes)
end
end
-
+
def test_eager_no_extra_singularization_has_many_through_has_many
return unless @have_tables
assert_nothing_raised do
View
76 activerecord/test/associations/eager_test.rb → activerecord/test/cases/associations/eager_test.rb
@@ -1,11 +1,11 @@
require 'abstract_unit'
-require 'fixtures/post'
-require 'fixtures/comment'
-require 'fixtures/author'
-require 'fixtures/category'
-require 'fixtures/company'
-require 'fixtures/person'
-require 'fixtures/reader'
+require 'models/post'
+require 'models/comment'
+require 'models/author'
+require 'models/category'
+require 'models/company'
+require 'models/person'
+require 'models/reader'
class EagerAssociationTest < ActiveSupport::TestCase
fixtures :posts, :comments, :authors, :categories, :categories_posts,
@@ -72,7 +72,7 @@ def test_eager_association_loading_with_belongs_to
assert titles.include?(posts(:welcome).title)
assert titles.include?(posts(:sti_post_and_comments).title)
end
-
+
def test_eager_association_loading_with_belongs_to_and_limit
comments = Comment.find(:all, :include => :post, :limit => 5, :order => 'comments.id')
assert_equal 5, comments.length
@@ -96,7 +96,7 @@ def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_cond
assert_equal 3, comments.length
assert_equal [6,7,8], comments.collect { |c| c.id }
end
-
+
def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_conditions_array
comments = Comment.find(:all, :include => :post, :conditions => ['post_id = ?',4], :limit => 3, :offset => 1, :order => 'comments.id')
assert_equal 3, comments.length
@@ -108,13 +108,13 @@ def test_eager_association_loading_with_belongs_to_and_limit_and_multiple_associ
assert_equal 1, posts.length
assert_equal [1], posts.collect { |p| p.id }
end
-
+
def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_multiple_associations
posts = Post.find(:all, :include => [:author, :very_special_comment], :limit => 1, :offset => 1, :order => 'posts.id')
assert_equal 1, posts.length
assert_equal [2], posts.collect { |p| p.id }
end
-
+
def test_eager_association_loading_with_belongs_to_inferred_foreign_key_from_association_name
author_favorite = AuthorFavorite.find(:first, :include => :favorite_author)
assert_equal authors(:mary), assert_no_queries { author_favorite.favorite_author }
@@ -124,7 +124,7 @@ def test_eager_association_loading_with_explicit_join
posts = Post.find(:all, :include => :comments, :joins => "INNER JOIN authors ON posts.author_id = authors.id AND authors.name = 'Mary'", :limit => 1, :order => 'author_id')
assert_equal 1, posts.length
end
-
+
def test_eager_with_has_many_through
posts_with_comments = people(:michael).posts.find(:all, :include => :comments)
posts_with_author = people(:michael).posts.find(:all, :include => :author )
@@ -138,7 +138,7 @@ def test_eager_with_has_many_through_an_sti_join_model
author = Author.find(:first, :include => :special_post_comments, :order => 'authors.id')
assert_equal [comments(:does_it_hurt)], assert_no_queries { author.special_post_comments }
end
-
+
def test_eager_with_has_many_through_an_sti_join_model_with_conditions_on_both
author = Author.find(:first, :include => :special_nonexistant_post_comments, :order => 'authors.id')
assert_equal [], author.special_nonexistant_post_comments
@@ -173,13 +173,13 @@ def test_eager_with_has_many_and_limit_and_conditions_array
posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "posts.body = ?", 'hello' ], :order => "posts.id")
end
assert_equal 2, posts.size
- assert_equal [4,5], posts.collect { |p| p.id }
+ assert_equal [4,5], posts.collect { |p| p.id }
end
def test_eager_with_has_many_and_limit_and_conditions_array_on_the_eagers
posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "authors.name = ?", 'David' ])
assert_equal 2, posts.size
-
+
count = Post.count(:include => [ :author, :comments ], :limit => 2, :conditions => [ "authors.name = ?", 'David' ])
assert_equal count, posts.size
end
@@ -198,7 +198,7 @@ def test_eager_with_has_many_and_limit_with_no_results
posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => "posts.title = 'magic forest'")
assert_equal 0, posts.size
end
-
+
def test_eager_count_performed_on_a_has_many_association_with_multi_table_conditional
author = authors(:david)
author_posts_without_comments = author.posts.select { |post| post.comments.blank? }
@@ -216,15 +216,15 @@ def test_eager_with_has_and_belongs_to_many_and_limit
end
def test_eager_with_has_many_and_limit_and_conditions_on_the_eagers
- posts = authors(:david).posts.find(:all,
- :include => :comments,
+ posts = authors(:david).posts.find(:all,
+ :include => :comments,
:conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'",
:limit => 2
)
assert_equal 2, posts.size
-
+
count = Post.count(
- :include => [ :comments, :author ],
+ :include => [ :comments, :author ],
:conditions => "authors.name = 'David' AND (comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment')",
:limit => 2
)
@@ -234,15 +234,15 @@ def test_eager_with_has_many_and_limit_and_conditions_on_the_eagers
def test_eager_with_has_many_and_limit_and_scoped_conditions_on_the_eagers
posts = nil
Post.with_scope(:find => {
- :include => :comments,
+ :include => :comments,
:conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'"
}) do
posts = authors(:david).posts.find(:all, :limit => 2)
assert_equal 2, posts.size
end
-
+
Post.with_scope(:find => {
- :include => [ :comments, :author ],
+ :include => [ :comments, :author ],
:conditions => "authors.name = 'David' AND (comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment')"
}) do
count = Post.count(:limit => 2)
@@ -252,15 +252,15 @@ def test_eager_with_has_many_and_limit_and_scoped_conditions_on_the_eagers
def test_eager_with_has_many_and_limit_and_scoped_and_explicit_conditions_on_the_eagers
Post.with_scope(:find => { :conditions => "1=1" }) do
- posts = authors(:david).posts.find(:all,
- :include => :comments,
+ posts = authors(:david).posts.find(:all,
+ :include => :comments,
:conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'",
:limit => 2
)
assert_equal 2, posts.size
-
+
count = Post.count(
- :include => [ :comments, :author ],
+ :include => [ :comments, :author ],
:conditions => "authors.name = 'David' AND (comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment')",
:limit => 2
)
@@ -316,7 +316,7 @@ def test_eager_with_has_one_dependent_does_not_destroy_dependent
assert_not_nil f.account
assert_equal companies(:first_firm, :reload).account, f.account
end
-
+
def test_eager_with_multi_table_conditional_properly_counts_the_records_when_using_size
author = authors(:david)
posts_with_no_comments = author.posts.select { |post| post.comments.blank? }
@@ -338,16 +338,16 @@ def test_eager_with_invalid_association_reference
post = Post.find(6, :include=>[ :monkeys, :elephants ])
}
end
-
+
def find_all_ordered(className, include=nil)
className.find(:all, :order=>"#{className.table_name}.#{className.primary_key}", :include=>include)
end
-
+
def test_limited_eager_with_order
assert_equal posts(:thinking, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title)', :limit => 2, :offset => 1)
assert_equal posts(:sti_post_and_comments, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title) DESC', :limit => 2, :offset => 1)
end
-
+
def test_limited_eager_with_multiple_order_columns
assert_equal posts(:thinking, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title), posts.id', :limit => 2, :offset => 1)
assert_equal posts(:sti_post_and_comments, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title) DESC, posts.id', :limit => 2, :offset => 1)
@@ -366,8 +366,8 @@ def assert_equal_after_sort(item1, item2, item3 = nil)
[Author, Category].each do |className|
d1 = find_all_ordered(className)
# test including all post types at once
- d2 = find_all_ordered(className, post_types)
- d1.each_index do |i|
+ d2 = find_all_ordered(className, post_types)
+ d1.each_index do |i|
assert_equal(d1[i], d2[i])
assert_equal_after_sort(d1[i].posts, d2[i].posts)
post_types[1..-1].each do |post_type|
@@ -380,21 +380,21 @@ def assert_equal_after_sort(item1, item2, item3 = nil)
end
end
end
-
+
def test_eager_with_multiple_associations_with_same_table_has_one
d1 = find_all_ordered(Firm)
d2 = find_all_ordered(Firm, :account)
- d1.each_index do |i|
+ d1.each_index do |i|
assert_equal(d1[i], d2[i])
assert_equal(d1[i].account, d2[i].account)
end
end
-
+
def test_eager_with_multiple_associations_with_same_table_belongs_to
firm_types = [:firm, :firm_with_basic_id, :firm_with_other_name, :firm_with_condition]
d1 = find_all_ordered(Client)
d2 = find_all_ordered(Client, firm_types)
- d1.each_index do |i|
+ d1.each_index do |i|
assert_equal(d1[i], d2[i])
firm_types.each { |type| assert_equal(d1[i].send(type), d2[i].send(type)) }
end
@@ -434,7 +434,7 @@ def test_preconfigured_includes_with_has_many_and_habtm
assert_equal 2, one.comments.size
assert_equal 2, one.categories.size
end
-
+
def test_count_with_include
if current_adapter?(:SQLServerAdapter, :SybaseAdapter)
assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "len(comments.body) > 15")
View
12 activerecord/test/associations/extension_test.rb → ...erecord/test/cases/associations/extension_test.rb
@@ -1,8 +1,8 @@
require 'abstract_unit'
-require 'fixtures/post'
-require 'fixtures/comment'
-require 'fixtures/project'
-require 'fixtures/developer'
+require 'models/post'
+require 'models/comment'
+require 'models/project'
+require 'models/developer'
class AssociationsExtensionsTest < ActiveSupport::TestCase
fixtures :projects, :developers, :developers_projects, :comments, :posts
@@ -10,7 +10,7 @@ class AssociationsExtensionsTest < ActiveSupport::TestCase
def test_extension_on_has_many
assert_equal comments(:more_greetings), posts(:welcome).comments.find_most_recent
end
-
+
def test_extension_on_habtm
assert_equal projects(:action_controller), developers(:david).projects.find_most_recent
end
@@ -44,4 +44,4 @@ def test_marshalling_named_extensions
david = Marshal.load(Marshal.dump(david))
assert_equal projects(:action_controller), david.projects_extended_by_name.find_most_recent
end
-end
+end
View
10 .../test/associations/inner_join_association_test.rb → ...cases/associations/inner_join_association_test.rb
@@ -12,18 +12,18 @@ 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
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
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
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
@@ -51,7 +51,7 @@ def test_find_with_implicit_inner_joins_honors_readonly_without_select
assert !authors.empty?, "expected authors to be non-empty"
assert authors.all? {|a| a.readonly? }, "expected all authors to be readonly"
end
-
+
def test_find_with_implicit_inner_joins_honors_readonly_with_select
authors = Author.find(:all, :select => 'authors.*', :joins => :posts)
assert !authors.empty?, "expected authors to be non-empty"
@@ -69,7 +69,7 @@ def test_find_with_implicit_inner_joins_does_not_set_associations
assert !authors.empty?, "expected authors to be non-empty"
assert authors.all? {|a| !a.send(:instance_variable_names).include?("@posts")}, "expected no authors to have the @posts association loaded"
end
-
+
def test_count_honors_implicit_inner_joins
real_count = Author.find(:all).sum{|a| a.posts.count }
assert_equal real_count, Author.count(:joins => :posts), "plain inner join count should match the number of referenced posts records"
View
30 activerecord/test/associations/join_model_test.rb → ...record/test/cases/associations/join_model_test.rb
@@ -32,7 +32,7 @@ def test_has_many_uniq_through_join_model
assert_equal 2, authors(:mary).categorized_posts.size
assert_equal 1, authors(:mary).unique_categorized_posts.size
end
-
+
def test_has_many_uniq_through_count
author = authors(:mary)
assert !authors(:mary).unique_categorized_posts.loaded?
@@ -41,7 +41,7 @@ def test_has_many_uniq_through_count
assert_queries(1) { assert_equal 0, author.unique_categorized_posts.count(:title, :conditions => "title is NULL") }
assert !authors(:mary).unique_categorized_posts.loaded?
end
-
+
def test_polymorphic_has_many
assert posts(:welcome).taggings.include?(taggings(:welcome_general))
end
@@ -107,7 +107,7 @@ def test_polymorphic_has_many_going_through_join_model_with_custom_foreign_key
def test_polymorphic_has_many_create_model_with_inheritance_and_custom_base_class
post = SubStiPost.create :title => 'SubStiPost', :body => 'SubStiPost body'
assert_instance_of SubStiPost, post
-
+
tagging = tags(:misc).taggings.create(:taggable => post)
assert_equal "SubStiPost", tagging.taggable_type
end
@@ -123,7 +123,7 @@ def test_polymorphic_has_many_going_through_join_model_with_inheritance_with_cus
def test_polymorphic_has_many_create_model_with_inheritance
post = posts(:thinking)
assert_instance_of SpecialPost, post
-
+
tagging = tags(:misc).taggings.create(:taggable => post)
assert_equal "Post", tagging.taggable_type
end
@@ -151,7 +151,7 @@ def test_create_polymorphic_has_many_with_scope
assert_equal "Post", tagging.taggable_type
assert_equal old_count+1, posts(:welcome).taggings.count
end
-
+
def test_create_bang_polymorphic_with_has_many_scope
old_count = posts(:welcome).taggings.count
tagging = posts(:welcome).taggings.create!(:tag => tags(:misc))
@@ -241,7 +241,7 @@ def test_include_polymorphic_has_one
assert_equal tagging, post.tagging
end
end
-
+
def test_include_polymorphic_has_one_defined_in_abstract_parent
item = Item.find_by_id(items(:dvd).id, :include => :tagging)
tagging = taggings(:godfather)
@@ -249,7 +249,7 @@ def test_include_polymorphic_has_one_defined_in_abstract_parent
assert_equal tagging, item.tagging
end
end
-
+
def test_include_polymorphic_has_many_through
posts = Post.find(:all, :order => 'posts.id')
posts_with_tags = Post.find(:all, :include => :tags, :order => 'posts.id')
@@ -271,7 +271,7 @@ def test_include_polymorphic_has_many
def test_has_many_find_all
assert_equal [categories(:general)], authors(:david).categories.find(:all)
end
-
+
def test_has_many_find_first
assert_equal categories(:general), authors(:david).categories.find(:first)
end
@@ -279,7 +279,7 @@ def test_has_many_find_first
def test_has_many_with_hash_conditions
assert_equal categories(:general), authors(:david).categories_like_general.find(:first)
end
-
+
def test_has_many_find_conditions
assert_equal categories(:general), authors(:david).categories.find(:first, :conditions => "categories.name = 'General'")
assert_equal nil, authors(:david).categories.find(:first, :conditions => "categories.name = 'Technology'")
@@ -320,7 +320,7 @@ def test_has_many_polymorphic
assert_equal posts(:welcome, :thinking), tags(:general).taggings.find(:all, :include => :taggable)
end
end
-
+
def test_has_many_polymorphic_with_source_type
assert_equal posts(:welcome, :thinking), tags(:general).tagged_posts
end
@@ -385,7 +385,7 @@ def test_eager_load_has_many_through_has_many
assert_equal [1,2,3,5,6,7,8,9,10], author.comments.collect(&:id)
end
end
-
+
def test_eager_load_has_many_through_has_many_with_conditions
post = Post.find(:first, :include => :invalid_tags)
assert_no_queries do
@@ -410,7 +410,7 @@ def test_add_to_self_referential_has_many_through
authors(:david).author_favorites.create :favorite_author => new_author
assert_equal new_author, authors(:david).reload.favorite_authors.first
end
-
+
def test_has_many_through_uses_conditions_specified_on_the_has_many_association
author = Author.find(:first)
assert !author.comments.blank?
@@ -506,7 +506,7 @@ def test_delete_associate_when_deleting_from_has_many_through
post_thinking.tags << tag
assert_equal(count + 1, post_thinking.tags(true).size)
- assert_nothing_raised { post_thinking.tags.delete(tag) }
+ assert_nothing_raised { post_thinking.tags.delete(tag) }
assert_equal(count, post_thinking.tags.size)
assert_equal(count, post_thinking.tags(true).size)
assert_equal(tags_before.sort, post_thinking.tags.sort)
@@ -522,7 +522,7 @@ def test_delete_associate_when_deleting_from_has_many_through_with_multiple_tags
post_thinking.tags << doomed << doomed2
assert_equal(count + 2, post_thinking.tags(true).size)
- assert_nothing_raised { post_thinking.tags.delete(doomed, doomed2, quaked) }
+ assert_nothing_raised { post_thinking.tags.delete(doomed, doomed2, quaked) }
assert_equal(count, post_thinking.tags.size)
assert_equal(count, post_thinking.tags(true).size)
assert_equal(tags_before.sort, post_thinking.tags.sort)
@@ -539,7 +539,7 @@ def test_has_many_through_sum_uses_calculations
def test_has_many_through_has_many_with_sti
assert_equal [comments(:does_it_hurt)], authors(:david).special_post_comments
end
-
+
def test_uniq_has_many_through_should_retain_order
comment_ids = authors(:david).comments.map(&:id)
assert_equal comment_ids.sort, authors(:david).ordered_uniq_comments.map(&:id)
View
30 activerecord/test/associations_test.rb → activerecord/test/cases/associations_test.rb
@@ -26,7 +26,7 @@ def test_bad_collection_keys
Class.new(ActiveRecord::Base).has_many(:wheels, :name => 'wheels')
end
end
-
+
def test_should_construct_new_finder_sql_after_create
person = Person.new
assert_equal [], person.readers.find(:all)
@@ -72,23 +72,23 @@ def test_storing_in_pstore
end
end
end
-
+
class AssociationProxyTest < ActiveSupport::TestCase
fixtures :authors, :posts, :categorizations, :categories, :developers, :projects, :developers_projects
-
+
def test_proxy_accessors
welcome = posts(:welcome)
assert_equal welcome, welcome.author.proxy_owner
assert_equal welcome.class.reflect_on_association(:author), welcome.author.proxy_reflection
welcome.author.class # force load target
assert_equal welcome.author, welcome.author.proxy_target
-
+
david = authors(:david)
assert_equal david, david.posts.proxy_owner
assert_equal david.class.reflect_on_association(:posts), david.posts.proxy_reflection
david.posts.first # force load target
assert_equal david.posts, david.posts.proxy_target
-
+
assert_equal david, david.posts_with_extension.testing_proxy_owner
assert_equal david.class.reflect_on_association(:posts_with_extension), david.posts_with_extension.testing_proxy_reflection
david.posts_with_extension.first # force load target
@@ -110,7 +110,7 @@ def test_push_has_many_through_does_not_load_target
assert !david.categories.loaded?
assert david.categories.include?(categories(:technology))
end
-
+
def test_push_followed_by_save_does_not_load_target
david = authors(:david)
@@ -685,21 +685,21 @@ def test_adding_using_create
assert_equal 3, first_firm.plain_clients.length
assert_equal 3, first_firm.plain_clients.size
end
-
+
def test_create_with_bang_on_has_many_when_parent_is_new_raises
- assert_raises(ActiveRecord::RecordNotSaved) do
+ assert_raises(ActiveRecord::RecordNotSaved) do
firm = Firm.new
firm.plain_clients.create! :name=>"Whoever"
end
end
def test_regular_create_on_has_many_when_parent_is_new_raises
- assert_raises(ActiveRecord::RecordNotSaved) do
+ assert_raises(ActiveRecord::RecordNotSaved) do
firm = Firm.new
firm.plain_clients.create :name=>"Whoever"
end
end
-
+
def test_create_with_bang_on_has_many_raises_when_record_not_saved
assert_raises(ActiveRecord::RecordInvalid) do
firm = Firm.find(:first)
@@ -708,8 +708,8 @@ def test_create_with_bang_on_has_many_raises_when_record_not_saved
end
def test_create_with_bang_on_habtm_when_parent_is_new_raises
- assert_raises(ActiveRecord::RecordNotSaved) do
- Developer.new("name" => "Aredridel").projects.create!
+ assert_raises(ActiveRecord::RecordNotSaved) do
+ Developer.new("name" => "Aredridel").projects.create!
end
end
@@ -790,13 +790,13 @@ def test_build_many
assert companies(:first_firm).save
assert_equal 3, companies(:first_firm).clients_of_firm(true).size
end
-
+
def test_build_followed_by_save_does_not_load_target
new_client = companies(:first_firm).clients_of_firm.build("name" => "Another Client")
assert companies(:first_firm).save
assert !companies(:first_firm).clients_of_firm.loaded?
end
-
+
def test_build_without_loading_association
first_topic = topics(:first)
Reply.column_names
@@ -1335,7 +1335,7 @@ def test_belongs_to_counter_after_update_attributes
topic.update_attributes(:title => "37signals")
assert_equal 1, Topic.find(topic.id)[:replies_count]
end
-
+
def test_belongs_to_counter_after_save
topic = Topic.create("title" => "monday night")
topic.replies.create("title" => "re: monday night", "content" => "football")
View
12 activerecord/test/attribute_methods_test.rb → activerecord/test/cases/attribute_methods_test.rb
@@ -48,24 +48,24 @@ def test_declared_attribute_method_affects_respond_to_and_method_missing
assert_equal ['title', 1, 2, 3], topic.send(meth, 1, 2, 3)
end
end
-
+
def test_should_unserialize_attributes_for_frozen_records
myobj = {:value1 => :value2}
topic = Topic.create("content" => myobj)
topic.freeze
assert_equal myobj, topic.content
end
-
+
def test_kernel_methods_not_implemented_in_activerecord
%w(test name display y).each do |method|
assert_equal false, ActiveRecord::Base.instance_method_already_implemented?(method), "##{method} is defined"
end
end
-
+
def test_primary_key_implemented
assert_equal true, Class.new(ActiveRecord::Base).instance_method_already_implemented?('id')
end
-
+
def test_defined_kernel_methods_implemented_in_model
%w(test name display y).each do |method|
klass = Class.new ActiveRecord::Base
@@ -73,7 +73,7 @@ def test_defined_kernel_methods_implemented_in_model
assert_equal true, klass.instance_method_already_implemented?(method), "##{method} is not defined"
end
end
-
+
def test_defined_kernel_methods_implemented_in_model_abstract_subclass
%w(test name display y).each do |method|
abstract = Class.new ActiveRecord::Base
@@ -83,7 +83,7 @@ def test_defined_kernel_methods_implemented_in_model_abstract_subclass
assert_equal true, klass.instance_method_already_implemented?(method), "##{method} is not defined"
end
end
-
+
def test_raises_dangerous_attribute_error_when_defining_activerecord_method_in_model
%w(save create_or_update).each do |method|
klass = Class.new ActiveRecord::Base
View
248 activerecord/test/base_test.rb → activerecord/test/cases/base_test.rb
@@ -65,8 +65,8 @@ class Task < ActiveRecord::Base
attr_protected :starting
end
-class TopicWithProtectedContentAndAccessibleAuthorName < ActiveRecord::Base
- self.table_name = 'topics'
+class TopicWithProtectedContentAndAccessibleAuthorName < ActiveRecord::Base
+ self.table_name = 'topics'
attr_accessible :author_name
attr_protected :content
end
@@ -78,7 +78,7 @@ def test_table_exists
assert !NonExistentTable.table_exists?
assert Topic.table_exists?
end
-
+
def test_set_attributes
topic = Topic.find(1)
topic.attributes = { "title" => "Budget", "author_name" => "Jason" }
@@ -92,7 +92,7 @@ def test_integers_as_nil
test = AutoId.create('value' => '')
assert_nil AutoId.find(test.id).value
end
-
+
def test_set_attributes_with_block
topic = Topic.new do |t|
t.title = "Budget"
@@ -102,7 +102,7 @@ def test_set_attributes_with_block
assert_equal("Budget", topic.title)
assert_equal("Jason", topic.author_name)
end
-
+
def test_respond_to?
topic = Topic.find(1)
assert topic.respond_to?("title")
@@ -116,7 +116,7 @@ def test_respond_to?
assert !topic.respond_to?("nothingness")
assert !topic.respond_to?(:nothingness)
end
-
+
def test_array_content
topic = Topic.new
topic.content = %w( one two three )
@@ -131,13 +131,13 @@ def test_hash_content
topic.save
assert_equal 2, Topic.find(topic.id).content["two"]
-
+
topic.content["three"] = 3
topic.save
assert_equal 3, Topic.find(topic.id).content["three"]
end
-
+
def test_update_array_content
topic = Topic.new
topic.content = %w( one two three )
@@ -146,12 +146,12 @@ def test_update_array_content
assert_equal(%w( one two three four ), topic.content)
topic.save
-
+
topic = Topic.find(topic.id)
topic.content << "five"
assert_equal(%w( one two three four five ), topic.content)
end
-
+
def test_case_sensitive_attributes_hash
# DB2 is not case-sensitive
return true if current_adapter?(:DB2Adapter)
@@ -166,11 +166,11 @@ def test_create
topic_reloaded = Topic.find(topic.id)
assert_equal("New Topic", topic_reloaded.title)
end
-
+
def test_save!
topic = Topic.new(:title => "New Topic")
assert topic.save!
-
+
reply = Reply.new
assert_raise(ActiveRecord::RecordInvalid) { reply.save! }
end
@@ -211,7 +211,7 @@ def test_hashes_not_mangled
topic.attributes= new_topic_values
assert_equal new_topic_values[:title], topic.title
end
-
+
def test_create_many
topics = Topic.create([ { "title" => "first" }, { "title" => "second" }])
assert_equal 2, topics.size
@@ -241,9 +241,9 @@ def test_update
topicReloaded.title = "Updated topic"
topicReloaded.save
-
+
topicReloadedAgain = Topic.find(topic.id)
-
+
assert_equal("Updated topic", topicReloadedAgain.title)
end
@@ -251,7 +251,7 @@ def test_update_columns_not_equal_attributes
topic = Topic.new
topic.title = "Still another topic"
topic.save
-
+
topicReloaded = Topic.find(topic.id)
topicReloaded.title = "A New Topic"
topicReloaded.send :write_attribute, 'does_not_exist', 'test'
@@ -262,7 +262,7 @@ def test_update_for_record_with_only_primary_key
minimalistic = minimalistics(:first)
assert_nothing_raised { minimalistic.save }
end
-
+
def test_write_attribute
topic = Topic.new
topic.send(:write_attribute, :title, "Still another topic")
@@ -321,29 +321,29 @@ def test_read_write_boolean_attribute
assert topic.approved?, "approved should be true"
# puts ""
end
-
+
def test_query_attribute_string
[nil, "", " "].each do |value|
assert_equal false, Topic.new(:author_name => value).author_name?
end
-
+
assert_equal true, Topic.new(:author_name => "Name").author_name?
end
-
+
def test_query_attribute_number
[nil, 0, "0"].each do |value|
assert_equal false, Developer.new(:salary => value).salary?
end
-
+
assert_equal true, Developer.new(:salary => 1).salary?
assert_equal true, Developer.new(:salary => "1").salary?
end
-
+
def test_query_attribute_boolean
[nil, "", false, "false", "f", 0].each do |value|
assert_equal false, Topic.new(:approved => value).approved?
end
-
+
[true, "true", "1", 1].each do |value|
assert_equal true, Topic.new(:approved => value).approved?
end
@@ -391,12 +391,12 @@ def test_preserving_date_objects
# Sybase ctlib does not (yet?) support the date type; use datetime instead.
# Oracle treats all dates/times as Time.
assert_kind_of(
- Time, Topic.find(1).last_read,
+ Time, Topic.find(1).last_read,
"The last_read attribute should be of the Time class"
)
else
assert_kind_of(
- Date, Topic.find(1).last_read,
+ Date, Topic.find(1).last_read,
"The last_read attribute should be of the Date class"
)
end
@@ -420,7 +420,7 @@ def test_preserving_time_objects
assert_equal 9900, Topic.find(2).written_on.usec
end
end
-
+
def test_custom_mutator
topic = Topic.find(1)
# This mutator is protected in the class definition
@@ -438,34 +438,34 @@ def test_destroy
def test_record_not_found_exception
assert_raises(ActiveRecord::RecordNotFound) { topicReloaded = Topic.find(99999) }
end
-
+
def test_initialize_with_attributes
- topic = Topic.new({
+ topic = Topic.new({
"title" => "initialized from attributes", "written_on" => "2003-12-12 23:23"
})
-
+
assert_equal("initialized from attributes", topic.title)
end
-
+
def test_initialize_with_invalid_attribute
begin
- topic = Topic.new({ "title" => "test",
+ topic = Topic.new({ "title" => "test",
"last_read(1i)" => "2005", "last_read(2i)" => "2", "last_read(3i)" => "31"})
rescue ActiveRecord::MultiparameterAssignmentErrors => ex
assert_equal(1, ex.errors.size)
assert_equal("last_read", ex.errors[0].attribute)
end
end
-
+
def test_load
- topics = Topic.find(:all, :order => 'id')
+ topics = Topic.find(:all, :order => 'id')
assert_equal(2, topics.size)
assert_equal(topics(:first).title, topics.first.title)
end
-
+
def test_load_with_condition
topics = Topic.find(:all, :conditions => "author_name = 'Mary'")
-
+
assert_equal(1, topics.size)
assert_equal(topics(:second).title, topics.first.title)
end
@@ -529,7 +529,7 @@ def test_table_name_guesses
ActiveRecord::Base.pluralize_table_names = true
classes.each(&:reset_table_name)
end
-
+
def test_destroy_all
assert_equal 2, Topic.count
@@ -552,7 +552,7 @@ def test_boolean_attributes
assert ! Topic.find(1).approved?
assert Topic.find(2).approved?
end
-
+
def test_increment_counter
Topic.increment_counter("replies_count", 1)
assert_equal 2, Topic.find(1).replies_count
@@ -560,7 +560,7 @@ def test_increment_counter
Topic.increment_counter("replies_count", 1)
assert_equal 3, Topic.find(1).replies_count
end
-
+
def test_decrement_counter
Topic.decrement_counter("replies_count", 2)
assert_equal -1, Topic.find(2).replies_count
@@ -627,7 +627,7 @@ def test_update_by_condition
assert_equal "Have a nice day", Topic.find(1).content
assert_equal "bulk updated!", Topic.find(2).content
end
-
+
def test_attribute_present
t = Topic.new
t.title = "hello there!"
@@ -636,13 +636,13 @@ def test_attribute_present
assert t.attribute_present?("written_on")
assert !t.attribute_present?("content")
end
-
+
def test_attribute_keys_on_new_instance
t = Topic.new
assert_equal nil, t.title, "The topics table has a title column, so it should be nil"
assert_raise(NoMethodError) { t.title2 }
end
-
+
def test_class_name
assert_equal "Firm", ActiveRecord::Base.class_name("firms")
assert_equal "Category", ActiveRecord::Base.class_name("categories")
@@ -661,26 +661,26 @@ def test_class_name
ActiveRecord::Base.table_name_suffix = ""
assert_equal "Firm", ActiveRecord::Base.class_name( "firms" )
end
-
+
def test_null_fields
assert_nil Topic.find(1).parent_id
assert_nil Topic.create("title" => "Hey you").parent_id
end
-
+
def test_default_values
topic = Topic.new
assert topic.approved?
assert_nil topic.written_on
assert_nil topic.bonus_time
assert_nil topic.last_read
-
+
topic.save
topic = Topic.find(topic.id)
assert topic.approved?
assert_nil topic.last_read
- # Oracle has some funky default handling, so it requires a bit of
+ # Oracle has some funky default handling, so it requires a bit of
# extra testing. See ticket #2788.
if current_adapter?(:OracleAdapter)
test = TestOracleDefault.new
@@ -736,21 +736,21 @@ def test_default_values_on_empty_strings
def test_equality
assert_equal Topic.find(1), Topic.find(2).topic
end
-
+
def test_equality_of_new_records
assert_not_equal Topic.new, Topic.new
end
-
+
def test_hashing
assert_equal [ Topic.find(1) ], [ Topic.find(2).topic ] & [ Topic.find(1) ]
end
-
+
def test_destroy_new_record
client = Client.new
client.destroy
assert client.frozen?
end
-
+
def test_destroy_record_with_associations
client = Client.find(3)
client.destroy
@@ -758,7 +758,7 @@ def test_destroy_record_with_associations
assert_kind_of Firm, client.firm
assert_raises(ActiveSupport::FrozenObjectError) { client.name = "something else" }
end
-
+
def test_update_attribute
assert !Topic.find(1).approved?
Topic.find(1).update_attribute("approved", true)
@@ -767,12 +767,12 @@ def test_update_attribute
Topic.find(1).update_attribute(:approved, false)
assert !Topic.find(1).approved?
end
-
+
def test_update_attributes
topic = Topic.find(1)
assert !topic.approved?
assert_equal "The First Topic", topic.title
-
+
topic.update_attributes("approved" => true, "title" => "The First Topic Updated")
topic.reload
assert topic.approved?
@@ -783,37 +783,37 @@ def test_update_attributes
assert !topic.approved?
assert_equal "The First Topic", topic.title
end
-
+
def test_update_attributes!
reply = Reply.find(2)
assert_equal "The Second Topic's of the day", reply.title
assert_equal "Have a nice day", reply.content
-
+
reply.update_attributes!("title" => "The Second Topic's of the day updated", "content" => "Have a nice evening")
reply.reload
assert_equal "The Second Topic's of the day updated", reply.title
assert_equal "Have a nice evening", reply.content
-
+
reply.update_attributes!(:title => "The Second Topic's of the day", :content => "Have a nice day")
reply.reload
assert_equal "The Second Topic's of the day", reply.title
assert_equal "Have a nice day", reply.content
-
+
assert_raise(ActiveRecord::RecordInvalid) { reply.update_attributes!(:title => nil, :content => "Have a nice evening") }
end
-
+
def test_mass_assignment_should_raise_exception_if_accessible_and_protected_attribute_writers_are_both_used
topic = TopicWithProtectedContentAndAccessibleAuthorName.new
assert_raises(RuntimeError) { topic.attributes = { "author_name" => "me" } }
assert_raises(RuntimeError) { topic.attributes = { "content" => "stuff" } }
end
-
+
def test_mass_assignment_protection
firm = Firm.new
firm.attributes = { "name" => "Next Angle", "rating" => 5 }
assert_equal 1, firm.rating
end
-
+
def test_mass_assignment_protection_against_class_attribute_writers
[:logger, :configurations, :primary_key_prefix_type, :table_name_prefix, :table_name_suffix, :pluralize_table_names, :colorize_logging,
:default_timezone, :allow_concurrency, :schema_format, :verification_timeout, :lock_optimistically, :record_timestamps].each do |method|
@@ -839,26 +839,26 @@ def test_customized_primary_key_remains_protected_when_referred_to_as_id
keyboard = Keyboard.new(:id => 9, :name => 'nice try')
assert_nil keyboard.id
end
-
+
def test_mass_assignment_protection_on_defaults
firm = Firm.new
firm.attributes = { "id" => 5, "type" => "Client" }
assert_nil firm.id
assert_equal "Firm", firm[:type]
end
-
+
def test_mass_assignment_accessible
reply = Reply.new("title" => "hello", "content" => "world", "approved" => true)
reply.save
assert reply.approved?
-
+
reply.approved = false
reply.save
assert !reply.approved?
end
-
+
def test_mass_assignment_protection_inheritance
assert_nil LoosePerson.accessible_attributes
assert_equal Set.new([ 'credit_rating', 'administrator' ]), LoosePerson.protected_attributes
@@ -875,14 +875,14 @@ def test_mass_assignment_protection_inheritance
assert_nil TightDescendant.protected_attributes
assert_equal Set.new([ 'name', 'address', 'phone_number' ]), TightDescendant.accessible_attributes
end
-
+
def test_readonly_attributes
assert_equal Set.new([ 'title' ]), ReadonlyTitlePost.readonly_attributes
-
+
post = ReadonlyTitlePost.create(:title => "cannot change this", :body => "changeable")
post.reload
assert_equal "cannot change this", post.title
-
+
post.update_attributes(:title => "try to change", :body => "changed")
post.reload
assert_equal "cannot change this", post.title
@@ -893,7 +893,7 @@ def test_multiparameter_attributes_on_date
attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "24" }
topic = Topic.find(1)
topic.attributes = attributes
- # note that extra #to_date call allows test to pass for Oracle, which
+ # note that extra #to_date call allows test to pass for Oracle, which
# treats dates/times the same
assert_date_from_db Date.new(2004, 6, 24), topic.last_read.to_date
end
@@ -902,7 +902,7 @@ def test_multiparameter_attributes_on_date_with_empty_date
attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "" }
topic = Topic.find(1)
topic.attributes = attributes
- # note that extra #to_date call allows test to pass for Oracle, which
+ # note that extra #to_date call allows test to pass for Oracle, which
# treats dates/times the same
assert_date_from_db Date.new(2004, 6, 1), topic.last_read.to_date
end
@@ -915,8 +915,8 @@ def test_multiparameter_attributes_on_date_with_all_empty
end
def test_multiparameter_attributes_on_time
- attributes = {
- "written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
+ attributes = {
+ "written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
"written_on(4i)" => "16", "written_on(5i)" => "24", "written_on(6i)" => "00"
}
topic = Topic.find(1)
@@ -925,8 +925,8 @@ def test_multiparameter_attributes_on_time
end
def test_multiparameter_attributes_on_time_with_empty_seconds
- attributes = {
- "written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
+ attributes = {
+ "written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
"written_on(4i)" => "16", "written_on(5i)" => "24", "written_on(6i)" => ""
}
topic = Topic.find(1)
@@ -937,12 +937,12 @@ def test_multiparameter_attributes_on_time_with_empty_seconds
def test_multiparameter_mass_assignment_protector
task = Task.new
time = Time.mktime(2000, 1, 1, 1)
- task.starting = time
+ task.starting = time
attributes = { "starting(1i)" => "2004", "starting(2i)" => "6", "starting(3i)" => "24" }
task.attributes = attributes
assert_equal time, task.starting
end
-
+
def test_multiparameter_assignment_of_aggregation
customer = Customer.new
address = Address.new("The Street", "The City", "The Country")
@@ -984,9 +984,9 @@ def test_boolean_cast_from_string
b_false = Booleantest.find(false_id)
assert !b_false.value?
b_true = Booleantest.find(true_id)
- assert b_true.value?
+ assert b_true.value?
end
-
+
def test_clone
topic = Topic.find(1)
cloned_topic = nil
@@ -995,15 +995,15 @@ def test_clone
assert cloned_topic.new_record?
# test if the attributes have been cloned
- topic.title = "a"
- cloned_topic.title = "b"
+ topic.title = "a"
+ cloned_topic.title = "b"
assert_equal "a", topic.title
assert_equal "b", cloned_topic.title
# test if the attribute values have been cloned
topic.title = {"a" => "b"}
cloned_topic = topic.clone
- cloned_topic.title["a"] = "c"
+ cloned_topic.title["a"] = "c"
assert_equal "b", topic.title["a"]
#test if attributes set as part of after_initialize are cloned correctly
@@ -1053,11 +1053,11 @@ def test_bignum
if current_adapter?(:PostgreSQLAdapter)
def test_default
default = Default.new
-
+
# fixed dates / times
assert_equal Date.new(2004, 1, 1), default.fixed_date
assert_equal Time.local(2004, 1,1,0,0,0,0), default.fixed_time
-
+
# char types
assert_equal 'Y', default.char1
assert_equal 'a varchar field', default.char2
@@ -1080,7 +1080,7 @@ def test_geometric_content
:a_polygon => '((2.0, 3), (5.5, 7.0), (8.5, 11.0))',
:a_circle => '<(5.3, 10.4), 2>'
)
-
+
assert g.save
# Reload and check that we have all the geometric attributes.
@@ -1098,7 +1098,7 @@ def test_geometric_content
assert_equal objs[0].isopen, 't'
# test alternate formats when defining the geometric types
-
+
g = Geometric.new(
:a_point => '5.0, 6.1',
#:a_line => '((2.0, 3), (5.5, 7.0))' # line type is currently unsupported in postgresql
@@ -1113,7 +1113,7 @@ def test_geometric_content
# Reload and check that we have all the geometric attributes.
h = Geometric.find(g.id)
-
+
assert_equal '(5,6.1)', h.a_point
assert_equal '[(2,3),(5.5,7)]', h.a_line_segment
assert_equal '(5.5,7),(2,3)', h.a_box # reordered to store upper right corner then bottom left corner
@@ -1203,10 +1203,10 @@ def test_quoting_arrays
end
MyObject = Struct.new :attribute1, :attribute2
-
+
def test_serialized_attribute
myobj = MyObject.new('value1', 'value2')
- topic = Topic.create("content" => myobj)
+ topic = Topic.create("content" => myobj)
Topic.serialize("content", MyObject)
assert_equal(myobj, topic.content)
end
@@ -1278,46 +1278,46 @@ def test_class_level_delete
def test_increment_attribute
assert_equal 50, accounts(:signals37).credit_limit
accounts(:signals37).increment! :credit_limit
- assert_equal 51, accounts(:signals37, :reload).credit_limit
+ assert_equal 51, accounts(:signals37, :reload).credit_limit
accounts(:signals37).increment(:credit_limit).increment!(:credit_limit)
assert_equal 53, accounts(:signals37, :reload).credit_limit
end
-
+
def test_increment_nil_attribute
assert_nil topics(:first).parent_id
topics(:first).increment! :parent_id
assert_equal 1, topics(:first).parent_id
end
-
+
def test_increment_attribute_by
assert_equal 50, accounts(:signals37).credit_limit
accounts(:signals37).increment! :credit_limit, 5
- assert_equal 55, accounts(:signals37, :reload).credit_limit
+ assert_equal 55, accounts(:signals37, :reload).credit_limit
accounts(:signals37).increment(:credit_limit, 1).increment!(:credit_limit, 3)
assert_equal 59, accounts(:signals37, :reload).credit_limit
end
-
+
def test_decrement_attribute
assert_equal 50, accounts(:signals37).credit_limit
accounts(:signals37).decrement!(:credit_limit)
assert_equal 49, accounts(:signals37, :reload).credit_limit
-
+
accounts(:signals37).decrement(:credit_limit).decrement!(:credit_limit)
assert_equal 47, accounts(:signals37, :reload).credit_limit
end
-
+
def test_decrement_attribute_by
assert_equal 50, accounts(:signals37).credit_limit
accounts(:signals37).decrement! :credit_limit, 5
- assert_equal 45, accounts(:signals37, :reload).credit_limit
+ assert_equal 45, accounts(:signals37, :reload).credit_limit
accounts(:signals37).decrement(:credit_limit, 1).decrement!(:credit_limit, 3)
assert_equal 41, accounts(:signals37, :reload).credit_limit
end
-
+
def test_toggle_attribute
assert !topics(:first).approved?
topics(:first).toggle!(:approved)
@@ -1394,17 +1394,17 @@ def test_set_inheritance_column_with_block
def test_count_with_join
res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.#{QUOTED_TYPE} = 'Post'"
-
+
res2 = Post.count(:conditions => "posts.#{QUOTED_TYPE} = 'Post'", :joins => "LEFT JOIN comments ON posts.id=comments.post_id")
assert_equal res, res2
-
+
res3 = nil
assert_nothing_raised do
res3 = Post.count(:conditions => "posts.#{QUOTED_TYPE} = 'Post'",
:joins => "LEFT JOIN comments ON posts.id=comments.post_id")
end
assert_equal res, res3
-
+
res4 = Post.count_by_sql "SELECT COUNT(p.id) FROM posts p, comments co WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id"
res5 = nil
assert_nothing_raised do
@@ -1413,7 +1413,7 @@ def test_count_with_join
:select => "p.id")
end
- assert_equal res4, res5
+ assert_equal res4, res5
unless current_adapter?(:SQLite2Adapter, :DeprecatedSQLiteAdapter)
res6 = Post.count_by_sql "SELECT COUNT(DISTINCT p.id) FROM posts p, comments co WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id"
@@ -1427,15 +1427,15 @@ def test_count_with_join
assert_equal res6, res7
end
end
-
- def test_clear_association_cache_stored
+
+ def test_clear_association_cache_stored
firm = Firm.find(1)
assert_kind_of Firm, firm
firm.clear_association_cache
assert_equal Firm.find(1).clients.collect{ |x| x.name }.sort, firm.clients.collect{ |x| x.name }.sort
end
-
+
def test_clear_association_cache_new_record
firm = Firm.new
client_stored = Client.find(3)
@@ -1463,31 +1463,31 @@ def test_scoped_find_conditions
assert !scoped_developers.include?(developers(:david)) # David's salary is less than 90,000
assert_equal 3, scoped_developers.size
end
-
+
def test_scoped_find_limit_offset
scoped_developers = Developer.with_scope(:find => { :limit => 3, :offset => 2 }) do
Developer.find(:all, :order => 'id')
- end
+ end
assert !scoped_developers.include?(developers(:david))
assert !scoped_developers.include?(developers(:jamis))
assert_equal 3, scoped_developers.size
-
+
# Test without scoped find conditions to ensure we get the whole thing
developers = Developer.find(:all, :order => 'id')
assert_equal Developer.count, developers.size
end
- def test_scoped_find_order
- # Test order in scope
+ def test_scoped_find_order
+ # Test order in scope
scoped_developers = Developer.with_scope(:find => { :limit => 1, :order => 'salary DESC' }) do
Developer.find(:all)
- end
+ end
assert_equal 'Jamis', scoped_developers.first.name
assert scoped_developers.include?(developers(:jamis))
# Test scope without order and order in find
scoped_developers = Developer.with_scope(:find => { :limit => 1 }) do
Developer.find(:all, :order => 'salary DESC')
- end
+ end
# Test scope order + find order, find has priority
scoped_developers = Developer.with_scope(:find => { :limit => 3, :order => 'id DESC' }) do
Developer.find(:all, :order => 'salary ASC')
@@ -1634,11 +1634,11 @@ def test_to_xml_skipping_attributes
xml = topics(:first).to_xml(:indent => 0, :skip_instruct => true, :except => [:title, :replies_count])
assert_equal "<topic>", xml.first(7)
assert !xml.include?(%(<title>The First Topic</title>))
- assert xml.include?(%(<author-name>David</author-name>))
+ assert xml.include?(%(<author-name>David</author-name>))
xml = topics(:first).to_xml(:indent => 0, :skip_instruct => true, :except => [:title, :author_name, :replies_count])
assert !xml.include?(%(<title>The First Topic</title>))
- assert !xml.include?(%(<author-name>David</author-name>))
+ assert !xml.include?(%(<author-name>David</author-name>))
end
def test_to_xml_including_has_many_association
@@ -1658,7 +1658,7 @@ def test_array_to_xml_including_methods
assert xml.include?(%(<topic-id type="integer">#{topics(:first).topic_id}</topic-id>)), xml
assert xml.include?(%(<topic-id type="integer">#{topics(:second).topic_id}</topic-id>)), xml
end
-
+
def test_array_to_xml_including_has_one_association
xml = [ companies(:first_firm), companies(:rails_core) ].to_xml(:indent => 0, :skip_instruct => true, :include => :account)
assert xml.include?(companies(:first_firm).account.to_xml(:indent => 0, :skip_instruct => true))
@@ -1679,7 +1679,7 @@ def test_to_xml_including_belongs_to_association
xml = companies(:second_client).to_xml(:indent => 0, :skip_instruct => true, :include => :firm)
assert xml.include?("<firm>")
end
-
+
def test_to_xml_including_multiple_associations
xml = companies(:first_firm).to_xml(:indent => 0, :skip_instruct => true, :include => [ :clients, :account ])
assert_equal "<firm>", xml.first(6)
@@ -1689,21 +1689,21 @@ def test_to_xml_including_multiple_associations
def test_to_xml_including_multiple_associations_with_options
xml = companies(:first_firm).to_xml(
- :indent => 0, :skip_instruct => true,
+ :indent => 0, :skip_instruct => true,
:include => { :clients => { :only => :name } }
)
-
+
assert_equal "<firm>", xml.first(6)
assert xml.include?(%(<client><name>Summit</name></client>))
assert xml.include?(%(<clients type="array"><client>))
end
-
+
def test_to_xml_including_methods
xml = Company.new.to_xml(:methods => :arbitrary_method, :skip_instruct => true)
assert_equal "<company>", xml.first(9)
assert xml.include?(%(<arbitrary-method>I am Jack's profound disappointment</arbitrary-method>))
end
-
+
def test_to_xml_with_block
value = "Rockin' the block"
xml = Company.new.to_xml(:skip_instruct => true) do |xml|
@@ -1712,7 +1712,7 @@ def test_to_xml_with_block
assert_equal "<company>", xml.first(9)
assert xml.include?(%(<arbitrary-element>#{value}</arbitrary-element>))
end
-
+
def test_except_attributes
assert_equal(
%w( author_name type id approved replies_count bonus_time written_on content author_email_address parent_id last_read).sort,
@@ -1724,21 +1724,21 @@ def test_except_attributes
topics(:first).attributes(:except => [ :title, :id, :type, :approved, :author_name ]).keys.sort
)
end
-
+
def test_include_attributes
assert_equal(%w( title ), topics(:first).attributes(:only => :title).keys)
assert_equal(%w( title author_name type id approved ).sort, topics(:first).attributes(:only => [ :title, :id, :type, :approved, :author_name ]).keys.sort)
end
-
+
def test_type_name_with_module_should_handle_beginning
assert_equal 'ActiveRecord::Person', ActiveRecord::Base.send(:type_name_with_module, 'Person')
assert_equal '::Person', ActiveRecord::Base.send(:type_name_with_module, '::Person')
end
-
+
def test_to_param_should_return_string
assert_kind_of String, Client.find(:first).to_param
end
-
+
def test_inspect_class
assert_equal 'ActiveRecord::Base', ActiveRecord::Base.inspect
assert_equal 'LoosePerson(abstract)', LoosePerson.inspect
@@ -1758,7 +1758,7 @@ def test_inspect_limited_select_instance
assert_equal %(#<Topic id: 1>), Topic.find(:first, :select => 'id', :conditions => 'id = 1').inspect
assert_equal %(#<Topic id: 1, title: "The First Topic">), Topic.find(:first, :select => 'id, title', :conditions => 'id = 1').inspect
end
-
+
def test_inspect_class_without_table
assert_equal "NonExistentTable(Table doesn't exist)", NonExistentTable.inspect
end
@@ -1770,7 +1770,7 @@ def test_attribute_for_inspect
assert_equal %("#{t.written_on.to_s(:db)}"), t.attribute_for_inspect(:written_on)
assert_equal '"The First Topic Now Has A Title With\nNewlines And M..."', t.attribute_for_inspect(:title)
end
-
+
def test_becomes
assert_kind_of Reply, topics(:first).becomes(Reply)
assert_equal "The First Topic", topics(:first).becomes(Reply).title
View
0  activerecord/test/binary_test.rb → activerecord/test/cases/binary_test.rb
File renamed without changes
View
40 activerecord/test/calculations_test.rb → activerecord/test/cases/calculations_test.rb
@@ -79,7 +79,7 @@ def test_should_limit_calculation_with_offset
end
def test_should_group_by_summed_field_having_condition
- c = Account.sum(:credit_limit, :group => :firm_id,
+ c = Account.sum(:credit_limit, :group => :firm_id,
:having => 'sum(credit_limit) > 50')
assert_nil c[1]
assert_equal 105, c[6]
@@ -92,22 +92,22 @@ def test_should_group_by_summed_association
assert_equal 105, c[companies(:rails_core)]
assert_equal 60, c[companies(:first_client)]
end
-
+
def test_should_sum_field_with_conditions
assert_equal 105, Account.sum(:credit_limit, :conditions => 'firm_id = 6')
end
def test_should_group_by_summed_field_with_conditions
- c = Account.sum(:credit_limit, :conditions => 'firm_id > 1',
+ c = Account.sum(:credit_limit, :conditions => 'firm_id > 1',
:group => :firm_id)
assert_nil c[1]
assert_equal 105, c[6]
assert_equal 60, c[2]
end
-
+
def test_should_group_by_summed_field_with_conditions_and_having
- c = Account.sum(:credit_limit, :conditions => 'firm_id > 1',
- :group => :firm_id,
+ c = Account.sum(:credit_limit, :conditions => 'firm_id > 1',
+ :group => :firm_id,
:having => 'sum(credit_limit) > 60')
assert_nil c[1]
assert_equal 105, c[6]
@@ -120,19 +120,19 @@ def test_should_group_by_fields_with_table_alias
assert_equal 105, c[6]
assert_equal 60, c[2]
end
-
+
def test_should_calculate_with_invalid_field
assert_equal 6, Account.calculate(:count, '*')
assert_equal 6, Account.calculate(:count, :all)
end
-
+
def test_should_calculate_grouped_with_invalid_field
c = Account.count(:all, :group => 'accounts.firm_id')
assert_equal 1, c[1]
assert_equal 2, c[6]
assert_equal 1, c[2]
end
-
+
def test_should_calculate_grouped_association_with_invalid_field
c = Account.count(:all, :group => :firm)
assert_equal 1, c[companies(:first_firm)]
@@ -159,11 +159,11 @@ def test_should_group_by_association_with_non_numeric_foreign_key
assert_equal 1, c.first.last
end
end
-
+
def test_should_not_modify_options_when_using_includes
options = {:conditions => 'companies.id > 1', :include => :firm}
options_copy = options.dup
-
+
Account.count(:all, options)
assert_equal options_copy, options
end
@@ -175,7 +175,7 @@ def test_should_calculate_grouped_by_function
assert_equal 3, c['CLIENT']
assert_equal 2, c['FIRM']
end
-
+
def test_should_calculate_grouped_by_function_with_table_alias
c = Company.count(:all, :group => "UPPER(companies.#{QUOTED_TYPE})")
assert_equal 2, c[nil]
@@ -183,7 +183,7 @@ def test_should_calculate_grouped_by_function_with_table_alias
assert_equal 3, c['CLIENT']
assert_equal 2, c['FIRM']
end
-
+
def test_should_not_overshadow_enumerable_sum
assert_equal 6, [1, 2, 3].sum(&:abs)
end
@@ -215,32 +215,32 @@ def test_should_reject_invalid_options
# empty options are valid
Company.send(:validate_calculation_options, func)
# these options are valid for all calculations
- [:select, :conditions, :joins, :order, :group, :having, :distinct].each do |opt|
+ [:select, :conditions, :joins, :order, :group, :having, :distinct].each do |opt|
Company.send(:validate_calculation_options, func, opt => true)
end
end
-
+
# :include is only valid on :count
Company.send(:validate_calculation_options, :count, :include => true)
end
-
+
assert_raises(ArgumentError) { Company.send(:validate_calculation_options, :sum, :foo => :bar) }
assert_raises(ArgumentError) { Company.send(:validate_calculation_options, :count, :foo => :bar) }
end
-
+
def test_should_count_selected_field_with_include
assert_equal 6, Account.count(:distinct => true, :include => :firm)
assert_equal 4, Account.count(:distinct => true, :include => :firm, :select => :credit_limit)
end
-
+