Move tests to cases
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8660 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
105a27f39e
commit
42b39ae3f2
@ -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"))
|
2
activerecord/test/active_schema_test_mysql.rb → activerecord/test/cases/active_schema_test_mysql.rb
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)
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
76
activerecord/test/associations/eager_test.rb → activerecord/test/cases/associations/eager_test.rb
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")
|
@ -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
|
@ -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"
|
@ -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)
|
@ -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")
|
@ -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
|
@ -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
|
@ -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
|
||||
|
||||
|
||||
def test_count_with_column_parameter
|
||||
assert_equal 5, Account.count(:firm_id)
|
||||
end
|
||||
|
||||
|
||||
def test_count_with_column_and_options_parameter
|
||||
assert_equal 2, Account.count(:firm_id, :conditions => "credit_limit = 50")
|
||||
end
|
||||
|
||||
|
||||
def test_count_with_no_parameters_isnt_deprecated
|
||||
assert_not_deprecated { Account.count }
|
||||
end
|
@ -56,7 +56,7 @@ class ParentDeveloper < ActiveRecord::Base
|
||||
end
|
||||
|
||||
class ChildDeveloper < ParentDeveloper
|
||||
|
||||
|
||||
end
|
||||
|
||||
class RecursiveCallbackDeveloper < ActiveRecord::Base
|
||||
@ -361,7 +361,7 @@ def test_before_destroy_returning_false
|
||||
david = ImmutableDeveloper.find(1)
|
||||
assert !david.destroy
|
||||
assert_not_nil ImmutableDeveloper.find_by_id(1)
|
||||
end
|
||||
end
|
||||
|
||||
def test_zzz_callback_returning_false # must be run last since we modify CallbackDeveloper
|
||||
david = CallbackDeveloper.find(1)
|
||||
@ -384,17 +384,17 @@ def test_zzz_callback_returning_false # must be run last since we modify Callbac
|
||||
[ :before_validation, :returning_false ]
|
||||
], david.history
|
||||
end
|
||||
|
||||
|
||||
def test_inheritence_of_callbacks
|
||||
parent = ParentDeveloper.new
|
||||
assert !parent.after_save_called
|
||||
parent.save
|
||||
assert parent.after_save_called
|
||||
|
||||
|
||||
child = ChildDeveloper.new
|
||||
assert !child.after_save_called
|
||||
child.save
|
||||
assert child.after_save_called
|
||||
end
|
||||
|
||||
|
||||
end
|
@ -24,7 +24,7 @@ def test_first_level
|
||||
assert_equal [ :one, :two ], B.read_inheritable_attribute("first")
|
||||
assert_equal [ :three ], C.read_inheritable_attribute("first")
|
||||
end
|
||||
|
||||
|
||||
def test_second_level
|
||||
assert_equal [ :one, :two, :four ], D.read_inheritable_attribute("first")
|
||||
assert_equal [ :one, :two ], B.read_inheritable_attribute("first")
|
0
activerecord/test/connection_test_firebird.rb → activerecord/test/cases/connection_test_firebird.rb
0
activerecord/test/connection_test_firebird.rb → activerecord/test/cases/connection_test_firebird.rb
@ -2,36 +2,36 @@
|
||||
|
||||
class CopyTableTest < ActiveSupport::TestCase
|
||||
fixtures :companies, :comments
|
||||
|
||||
|
||||
def setup
|
||||
@connection = ActiveRecord::Base.connection
|
||||
class << @connection
|
||||
public :copy_table, :table_structure, :indexes
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_copy_table(from = 'companies', to = 'companies2', options = {})
|
||||
assert_nothing_raised {copy_table(from, to, options)}
|
||||
assert_equal row_count(from), row_count(to)
|
||||
|
||||
|
||||
if block_given?
|
||||
yield from, to, options
|
||||
else
|
||||
assert_equal column_names(from), column_names(to)
|
||||
end
|
||||
|
||||
|
||||
@connection.drop_table(to) rescue nil
|
||||
end
|
||||
|
||||
|
||||
def test_copy_table_renaming_column
|
||||
test_copy_table('companies', 'companies2',
|
||||
test_copy_table('companies', 'companies2',
|
||||
:rename => {'client_of' => 'fan_of'}) do |from, to, options|
|
||||
expected = column_values(from, 'client_of')
|
||||
assert expected.any?, 'only nils in resultset; real values are needed'
|
||||
assert_equal expected, column_values(to, 'fan_of')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_copy_table_with_index
|
||||
test_copy_table('comments', 'comments_with_index') do
|
||||
@connection.add_index('comments_with_index', ['post_id', 'type'])
|
||||
@ -41,11 +41,11 @@ def test_copy_table_with_index
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_copy_table_without_primary_key
|
||||
test_copy_table('developers_projects', 'programmers_projects')
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
def copy_table(from, to, options = {})
|
||||
@connection.copy_table(from, to, {:temporary => true}.merge(options))
|
||||
@ -54,7 +54,7 @@ def copy_table(from, to, options = {})
|
||||
def column_names(table)
|
||||
@connection.table_structure(table).map {|column| column['name']}
|
||||
end
|
||||
|
||||
|
||||
def column_values(table, column)
|
||||
@connection.select_all("SELECT #{column} FROM #{table} ORDER BY id").map {|row| row[column]}
|
||||
end
|
||||
@ -62,7 +62,7 @@ def column_values(table, column)
|
||||
def table_indexes_without_name(table)
|
||||
@connection.indexes('comments_with_index').delete(:name)
|
||||
end
|
||||
|
||||
|
||||
def row_count(table)
|
||||
@connection.select_one("SELECT COUNT(*) AS count FROM #{table}")['count']
|
||||
end
|
4
activerecord/test/datatype_test_postgresql.rb → activerecord/test/cases/datatype_test_postgresql.rb
4
activerecord/test/datatype_test_postgresql.rb → activerecord/test/cases/datatype_test_postgresql.rb
@ -43,10 +43,10 @@ def setup
|
||||
|
||||
@connection.execute("INSERT INTO postgresql_network_addresses (cidr_address, inet_address, mac_address) VALUES('192.168.0/24', '172.16.1.254/32', '01:23:45:67:89:0a')")
|
||||
@first_network_address = PostgresqlNetworkAddress.find(1)
|
||||
|
||||
|
||||
@connection.execute("INSERT INTO postgresql_bit_strings (bit_string, bit_string_varying) VALUES (B'00010101', X'15')")
|
||||
@first_bit_string = PostgresqlBitString.find(1)
|
||||
|
||||
|
||||
@connection.execute("INSERT INTO postgresql_oids (obj_id) VALUES (1234)")
|
||||
@first_oid = PostgresqlOid.find(1)
|
||||
end
|
@ -10,7 +10,7 @@ def test_saves_both_date_and_time
|
||||
task = Task.new
|
||||
task.starting = now
|
||||
task.save!
|
||||
|
||||
|
||||
# check against Time.local_time, since some platforms will return a Time instead of a DateTime
|
||||
assert_equal Time.local_time(*time_values), Task.find(task.id).starting
|
||||
end
|
@ -145,13 +145,13 @@ def test_find_only_some_columns
|
||||
assert topic.attribute_present?("author_name")
|
||||
assert topic.respond_to?("author_name")
|
||||
end
|
||||
|
||||
|
||||
def test_find_on_blank_conditions
|
||||
[nil, " ", [], {}].each do |blank|
|
||||
assert_nothing_raised { Topic.find(:first, :conditions => blank) }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_find_on_blank_bind_conditions
|
||||
[ [""], ["",{}] ].each do |blank|
|
||||
assert_nothing_raised { Topic.find(:first, :conditions => blank) }
|
||||
@ -337,7 +337,7 @@ def test_find_by_one_attribute
|
||||
assert_equal topics(:first), Topic.find_by_title("The First Topic")
|
||||
assert_nil Topic.find_by_title("The First Topic!")
|
||||
end
|
||||
|
||||
|
||||
def test_find_by_one_attribute_caches_dynamic_finder
|
||||
# ensure this test can run independently of order
|
||||
class << Topic; self; end.send(:remove_method, :find_by_title) if Topic.respond_to?(:find_by_title)
|
||||
@ -482,13 +482,13 @@ def test_find_or_initialize_from_one_attribute
|
||||
assert_equal "38signals", sig38.name
|
||||
assert sig38.new_record?
|
||||
end
|
||||
|
||||
|
||||
def test_find_or_initialize_from_one_attribute_should_set_attribute_even_when_protected
|
||||
c = Company.find_or_initialize_by_name_and_rating("Fortune 1000", 1000)
|
||||
assert_equal "Fortune 1000", c.name
|
||||
assert_equal 1000, c.rating
|
||||
assert c.valid?
|
||||
assert c.new_record?
|
||||
assert c.new_record?
|
||||
end
|
||||
|
||||
def test_find_or_create_from_one_attribute_should_set_attribute_even_when_protected
|
||||
@ -496,11 +496,11 @@ def test_find_or_create_from_one_attribute_should_set_attribute_even_when_protec
|
||||
assert_equal "Fortune 1000", c.name
|
||||
assert_equal 1000, c.rating
|
||||
assert c.valid?
|
||||
assert !c.new_record?
|
||||
assert !c.new_record?
|
||||
end
|
||||
|
||||
def test_dynamic_find_or_initialize_from_one_attribute_caches_method
|
||||
class << Company; self; end.send(:remove_method, :find_or_initialize_by_name) if Company.respond_to?(:find_or_initialize_by_name)
|
||||
class << Company; self; end.send(:remove_method, :find_or_initialize_by_name) if Company.respond_to?(:find_or_initialize_by_name)
|
||||
assert !Company.respond_to?(:find_or_initialize_by_name)
|
||||
sig38 = Company.find_or_initialize_by_name("38signals")
|
||||
assert Company.respond_to?(:find_or_initialize_by_name)
|
@ -310,11 +310,11 @@ def test_fixture_table_names
|
||||
|
||||
class SetupTest < ActiveSupport::TestCase
|
||||
# fixtures :topics
|
||||
|
||||
|
||||
def setup
|
||||
@first = true
|
||||
end
|
||||
|
||||
|
||||
def test_nothing
|
||||
end
|
||||
end
|
||||
@ -324,7 +324,7 @@ def setup
|
||||
super
|
||||
@second = true
|
||||
end
|
||||
|
||||
|
||||
def test_subclassing_should_preserve_setups
|
||||
assert @first
|
||||
assert @second
|
@ -33,7 +33,7 @@ def test_inheritance_find
|
||||
assert Company.find(2).kind_of?(Client), "Summit should be a client"
|
||||
assert Client.find(2).kind_of?(Client), "Summit should be a client"
|
||||
end
|
||||
|
||||
|
||||
def test_alt_inheritance_find
|
||||
switch_to_alt_inheritance_column
|
||||
test_inheritance_find
|
||||
@ -45,7 +45,7 @@ def test_inheritance_find_all
|
||||
assert companies[0].kind_of?(Firm), "37signals should be a firm"
|
||||
assert companies[1].kind_of?(Client), "Summit should be a client"
|
||||
end
|
||||
|
||||
|
||||
def test_alt_inheritance_find_all
|
||||
switch_to_alt_inheritance_column
|
||||
test_inheritance_find_all
|
||||
@ -56,11 +56,11 @@ def test_inheritance_save
|
||||
firm = Firm.new
|
||||
firm.name = "Next Angle"
|
||||
firm.save
|
||||
|
||||
|
||||
next_angle = Company.find(firm.id)
|
||||
assert next_angle.kind_of?(Firm), "Next Angle should be a firm"
|
||||
end
|
||||
|
||||
|
||||
def test_alt_inheritance_save
|
||||
switch_to_alt_inheritance_column
|
||||
test_inheritance_save
|
||||
@ -72,7 +72,7 @@ def test_inheritance_condition
|
||||
assert_equal 2, Firm.count
|
||||
assert_equal 3, Client.count
|
||||
end
|
||||
|
||||
|
||||
def test_alt_inheritance_condition
|
||||
switch_to_alt_inheritance_column
|
||||
test_inheritance_condition
|
||||
@ -83,7 +83,7 @@ def test_finding_incorrect_type_data
|
||||
assert_raises(ActiveRecord::RecordNotFound) { Firm.find(2) }
|
||||
assert_nothing_raised { Firm.find(1) }
|
||||
end
|
||||
|
||||
|
||||
def test_alt_finding_incorrect_type_data
|
||||
switch_to_alt_inheritance_column
|
||||
test_finding_incorrect_type_data
|
||||
@ -95,7 +95,7 @@ def test_update_all_within_inheritance
|
||||
assert_equal "I am a client", Client.find(:all).first.name
|
||||
assert_equal "37signals", Firm.find(:all).first.name
|
||||
end
|
||||
|
||||
|
||||
def test_alt_update_all_within_inheritance
|
||||
switch_to_alt_inheritance_column
|
||||
test_update_all_within_inheritance
|
||||
@ -107,7 +107,7 @@ def test_destroy_all_within_inheritance
|
||||
assert_equal 0, Client.count
|
||||
assert_equal 2, Firm.count
|
||||
end
|
||||
|
||||
|
||||
def test_alt_destroy_all_within_inheritance
|
||||
switch_to_alt_inheritance_column
|
||||
test_destroy_all_within_inheritance
|
||||
@ -119,7 +119,7 @@ def test_find_first_within_inheritance
|
||||
assert_kind_of Firm, Firm.find(:first, :conditions => "name = '37signals'")
|
||||
assert_nil Client.find(:first, :conditions => "name = '37signals'")
|
||||
end
|
||||
|
||||
|
||||
def test_alt_find_first_within_inheritance
|
||||
switch_to_alt_inheritance_column
|
||||
test_find_first_within_inheritance
|
||||
@ -141,12 +141,12 @@ def test_alt_complex_inheritance
|
||||
test_complex_inheritance
|
||||
switch_to_default_inheritance_column
|
||||
end
|
||||
|
||||
|
||||
def test_eager_load_belongs_to_something_inherited
|
||||
account = Account.find(1, :include => :firm)
|
||||
assert_not_nil account.instance_variable_get("@firm"), "nil proves eager load failed"
|
||||
end
|
||||
|
||||
|
||||
def test_alt_eager_loading
|
||||
switch_to_alt_inheritance_column
|
||||
test_eager_load_belongs_to_something_inherited
|
@ -28,9 +28,9 @@ def has_been_notified?
|
||||
|
||||
class TopicaObserver < ActiveRecord::Observer
|
||||
observe :topic
|
||||
|
||||
|
||||
attr_reader :topic
|
||||
|
||||
|
||||
def after_find(topic)
|
||||
@topic = topic
|
||||
end
|
||||
@ -38,7 +38,7 @@ def after_find(topic)
|
||||
|
||||
class TopicObserver < ActiveRecord::Observer
|
||||
attr_reader :topic
|
||||
|
||||
|
||||
def after_find(topic)
|
||||
@topic = topic
|
||||
end
|
@ -34,7 +34,7 @@ def test_lock_existing
|
||||
|
||||
assert_raises(ActiveRecord::StaleObjectError) { p2.save! }
|
||||
end
|
||||
|
||||
|
||||
def test_lock_repeating
|
||||
p1 = Person.find(1)
|
||||
p2 = Person.find(1)
|
||||
@ -64,7 +64,7 @@ def test_lock_new
|
||||
|
||||
assert_raises(ActiveRecord::StaleObjectError) { p2.save! }
|
||||
end
|
||||
|
||||
|
||||
def test_lock_new_with_nil
|
||||
p1 = Person.new(:first_name => 'anika')
|
||||
p1.save!
|
||||
@ -72,7 +72,7 @@ def test_lock_new_with_nil
|
||||
p1.save!
|
||||
assert_equal 1, p1.lock_version
|
||||
end
|
||||
|
||||
|
||||
|
||||
def test_lock_column_name_existing
|
||||
t1 = LegacyThing.find(1)
|
@ -7,7 +7,7 @@
|
||||
|
||||
class MethodScopingTest < ActiveSupport::TestCase
|
||||
fixtures :developers, :projects, :comments, :posts
|
||||
|
||||
|
||||
def test_set_conditions
|
||||
Developer.with_scope(:find => { :conditions => 'just a test...' }) do
|
||||
assert_equal 'just a test...', Developer.send(:current_scoped_methods)[:find][:conditions]
|
||||
@ -19,46 +19,46 @@ def test_scoped_find
|
||||
assert_nothing_raised { Developer.find(1) }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_scoped_find_first
|
||||
Developer.with_scope(:find => { :conditions => "salary = 100000" }) do
|
||||
assert_equal Developer.find(10), Developer.find(:first, :order => 'name')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_scoped_find_combines_conditions
|
||||
Developer.with_scope(:find => { :conditions => "salary = 9000" }) do
|
||||
assert_equal developers(:poor_jamis), Developer.find(:first, :conditions => "name = 'Jamis'")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_scoped_find_sanitizes_conditions
|
||||
Developer.with_scope(:find => { :conditions => ['salary = ?', 9000] }) do
|
||||
assert_equal developers(:poor_jamis), Developer.find(:first)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_scoped_find_combines_and_sanitizes_conditions
|
||||
Developer.with_scope(:find => { :conditions => ['salary = ?', 9000] }) do
|
||||
assert_equal developers(:poor_jamis), Developer.find(:first, :conditions => ['name = ?', 'Jamis'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_scoped_find_all
|
||||
Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
|
||||
assert_equal [developers(:david)], Developer.find(:all)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_scoped_count
|
||||
Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
|
||||
assert_equal 1, Developer.count
|
||||
end
|
||||
end
|
||||
|
||||
Developer.with_scope(:find => { :conditions => 'salary = 100000' }) do
|
||||
assert_equal 8, Developer.count
|
||||
assert_equal 1, Developer.count(:conditions => "name LIKE 'fixture_1%'")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_scoped_find_include
|
||||
@ -70,7 +70,7 @@ def test_scoped_find_include
|
||||
assert !scoped_developers.include?(developers(:jamis))
|
||||
assert_equal 1, scoped_developers.size
|
||||
end
|
||||
|
||||
|
||||
def test_scoped_count_include
|
||||
# with the include, will retrieve only developers for the given project
|
||||
Developer.with_scope(:find => { :include => :projects }) do
|
||||
@ -184,7 +184,7 @@ def test_nested_scoped_find_include
|
||||
assert_nothing_raised { Developer.find(1) }
|
||||
assert_equal('David', Developer.find(:first).name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_nested_scoped_find_merged_include
|
||||
@ -194,31 +194,31 @@ def test_nested_scoped_find_merged_include
|
||||
assert_equal 1, Developer.instance_eval('current_scoped_methods')[:find][:include].length
|
||||
assert_equal('David', Developer.find(:first).name)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# the nested scope doesn't remove the first :include
|
||||
Developer.with_scope(:find => { :include => :projects, :conditions => "projects.id = 2" }) do
|
||||
Developer.with_scope(:find => { :include => [] }) do
|
||||
assert_equal 1, Developer.instance_eval('current_scoped_methods')[:find][:include].length
|
||||
assert_equal('David', Developer.find(:first).name)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# mixing array and symbol include's will merge correctly
|
||||
Developer.with_scope(:find => { :include => [:projects], :conditions => "projects.id = 2" }) do
|
||||
Developer.with_scope(:find => { :include => :projects }) do
|
||||
assert_equal 1, Developer.instance_eval('current_scoped_methods')[:find][:include].length
|
||||
assert_equal('David', Developer.find(:first).name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_nested_scoped_find_replace_include
|
||||
Developer.with_scope(:find => { :include => :projects }) do
|
||||
Developer.with_exclusive_scope(:find => { :include => [] }) do
|
||||
assert_equal 0, Developer.instance_eval('current_scoped_methods')[:find][:include].length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_three_level_nested_exclusive_scoped_find
|
||||
@ -315,11 +315,11 @@ def test_ensure_that_method_scoping_is_correctly_restored
|
||||
|
||||
class HasManyScopingTest< ActiveSupport::TestCase
|
||||
fixtures :comments, :posts
|
||||
|
||||
|
||||
def setup
|
||||
@welcome = Post.find(1)
|
||||
end
|
||||
|
||||
|
||||
def test_forwarding_of_static_methods
|
||||
assert_equal 'a comment...', Comment.what_are_you
|
||||
assert_equal 'a comment...', @welcome.comments.what_are_you
|
||||
@ -329,7 +329,7 @@ def test_forwarding_to_scoped
|
||||
assert_equal 4, Comment.search_by_type('Comment').size
|
||||
assert_equal 2, @welcome.comments.search_by_type('Comment').size
|
||||
end
|
||||
|
||||
|
||||
def test_forwarding_to_dynamic_finders
|
||||
assert_equal 4, Comment.find_all_by_type('Comment').size
|
||||
assert_equal 2, @welcome.comments.find_all_by_type('Comment').size
|
@ -24,7 +24,7 @@ def puts(text="")
|
||||
|
||||
class MigrationTest < ActiveSupport::TestCase
|
||||
self.use_transactional_fixtures = false
|
||||
|
||||
|
||||
fixtures :people
|
||||
|
||||
def setup
|
||||
@ -80,7 +80,7 @@ def test_add_index
|
||||
assert_nothing_raised { Person.connection.add_index("people", ["key"], :name => "key_idx", :unique => true) }
|
||||
assert_nothing_raised { Person.connection.remove_index("people", :name => "key_idx", :unique => true) }
|
||||
end
|
||||
|
||||
|
||||
# Sybase adapter does not support indexes on :boolean columns
|
||||
# OpenBase does not have named indexes. You must specify a single column
|
||||
unless current_adapter?(:SybaseAdapter, :OpenBaseAdapter)
|
||||
@ -201,8 +201,8 @@ def test_add_column_not_null_with_default
|
||||
Person.connection.create_table :testings do |t|
|
||||
t.column :foo, :string
|
||||
end
|
||||
|
||||
con = Person.connection
|
||||
|
||||
con = Person.connection
|
||||
Person.connection.enable_identity_insert("testings", true) if current_adapter?(:SybaseAdapter)
|
||||
Person.connection.execute "insert into testings (#{con.quote_column_name('id')}, #{con.quote_column_name('foo')}) values (1, 'hello')"
|
||||
Person.connection.enable_identity_insert("testings", false) if current_adapter?(:SybaseAdapter)
|
||||
@ -306,11 +306,11 @@ def test_native_types
|
||||
|
||||
# Test for 30 significent digits (beyond the 16 of float), 10 of them
|
||||
# after the decimal place.
|
||||
|
||||
|
||||
unless current_adapter?(:SQLite3Adapter)
|
||||
assert_equal BigDecimal.new("0012345678901234567890.0123456789"), bob.wealth
|
||||
end
|
||||
|
||||
|
||||
assert_equal true, bob.male?
|
||||
|
||||
assert_equal String, bob.first_name.class
|
||||
@ -346,7 +346,7 @@ def test_unabstracted_database_dependent_types
|
||||
ActiveRecord::Migration.add_column :people, :intelligence_quotient, :tinyint
|
||||
Person.reset_column_information
|
||||
Person.create :intelligence_quotient => 300
|
||||
jonnyg = Person.find(:first)
|
||||
jonnyg = Person.find(:first)
|
||||
assert_equal 127, jonnyg.intelligence_quotient
|
||||
jonnyg.destroy
|
||||
ensure
|
||||
@ -439,7 +439,7 @@ def test_rename_column_with_sql_reserved_word
|
||||
Person.connection.add_column("people", "first_name", :string) rescue nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_rename_column_with_an_index
|
||||
ActiveRecord::Base.connection.create_table(:hats) do |table|
|
||||
table.column :hat_name, :string, :limit => 100
|
||||
@ -482,7 +482,7 @@ def test_change_type_of_not_null_column
|
||||
assert_nothing_raised do
|
||||
Topic.connection.change_column "topics", "written_on", :datetime, :null => false
|
||||
Topic.reset_column_information
|
||||
|
||||
|
||||
Topic.connection.change_column "topics", "written_on", :datetime, :null => false
|
||||
Topic.reset_column_information
|
||||
end
|
||||
@ -496,7 +496,7 @@ def test_rename_table
|
||||
ActiveRecord::Base.connection.rename_table :octopuses, :octopi
|
||||
|
||||
# Using explicit id in insert for compatibility across all databases
|
||||
con = ActiveRecord::Base.connection
|
||||
con = ActiveRecord::Base.connection
|
||||
con.enable_identity_insert("octopi", true) if current_adapter?(:SybaseAdapter)
|
||||
assert_nothing_raised { con.execute "INSERT INTO octopi (#{con.quote_column_name('id')}, #{con.quote_column_name('url')}) VALUES (1, 'http://www.foreverflying.com/octopus-black7.jpg')" }
|
||||
con.enable_identity_insert("octopi", false) if current_adapter?(:SybaseAdapter)
|
||||
@ -508,9 +508,9 @@ def test_rename_table
|
||||
ActiveRecord::Base.connection.drop_table :octopi rescue nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_change_column_nullability
|
||||
Person.delete_all
|
||||
Person.delete_all
|
||||
Person.connection.add_column "people", "funny", :boolean
|
||||
Person.reset_column_information
|
||||
assert Person.columns_hash["funny"].null, "Column 'funny' must initially allow nulls"
|
||||
@ -528,11 +528,11 @@ def test_rename_table_with_an_index
|
||||
t.column :url, :string
|
||||
end
|
||||
ActiveRecord::Base.connection.add_index :octopuses, :url
|
||||
|
||||
|
||||
ActiveRecord::Base.connection.rename_table :octopuses, :octopi
|
||||
|
||||
# Using explicit id in insert for compatibility across all databases
|
||||
con = ActiveRecord::Base.connection
|
||||
con = ActiveRecord::Base.connection
|
||||
con.enable_identity_insert("octopi", true) if current_adapter?(:SybaseAdapter)
|
||||
assert_nothing_raised { con.execute "INSERT INTO octopi (#{con.quote_column_name('id')}, #{con.quote_column_name('url')}) VALUES (1, 'http://www.foreverflying.com/octopus-black7.jpg')" }
|
||||
con.enable_identity_insert("octopi", false) if current_adapter?(:SybaseAdapter)
|
||||
@ -564,12 +564,12 @@ def test_change_column
|
||||
assert new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == false }
|
||||
assert_nothing_raised { Topic.connection.change_column :topics, :approved, :boolean, :default => true }
|
||||
end
|
||||
|
||||
|
||||
def test_change_column_with_nil_default
|
||||
Person.connection.add_column "people", "contributor", :boolean, :default => true
|
||||
Person.reset_column_information
|
||||
assert Person.new.contributor?
|
||||
|
||||
|
||||
assert_nothing_raised { Person.connection.change_column "people", "contributor", :boolean, :default => nil }
|
||||
Person.reset_column_information
|
||||
assert !Person.new.contributor?
|
||||
@ -589,7 +589,7 @@ def test_change_column_with_new_default
|
||||
ensure
|
||||
Person.connection.remove_column("people", "administrator") rescue nil
|
||||
end
|
||||
|
||||
|
||||
def test_change_column_default
|
||||
Person.connection.change_column_default "people", "first_name", "Tester"
|
||||
Person.reset_column_information
|
||||
@ -618,8 +618,8 @@ def test_add_table
|
||||
assert !Reminder.table_exists?
|
||||
|
||||
WeNeedReminders.up
|
||||
|
||||
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
|
||||
|
||||
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
|
||||
assert_equal "hello world", Reminder.find(:first).content
|
||||
|
||||
WeNeedReminders.down
|
||||
@ -852,7 +852,7 @@ def test_create_table_with_binary_column
|
||||
columns = Person.connection.columns(:binary_testings)
|
||||
data_column = columns.detect { |c| c.name == "data" }
|
||||
|
||||
if current_adapter?(:MysqlAdapter)
|
||||
if current_adapter?(:MysqlAdapter)
|
||||
assert_equal '', data_column.default
|
||||
else
|
||||
assert_nil data_column.default
|
||||
@ -870,12 +870,12 @@ def test_migrator_with_duplicates
|
||||
def test_migrator_with_missing_version_numbers
|
||||
ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/fixtures/migrations_with_missing_versions/', 500)
|
||||
assert !Person.column_methods_hash.include?(:middle_name)
|
||||
assert_equal 4, ActiveRecord::Migrator.current_version
|
||||
|
||||
assert_equal 4, ActiveRecord::Migrator.current_version
|
||||
|
||||
ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/fixtures/migrations_with_missing_versions/', 2)
|
||||
Person.reset_column_information
|
||||
assert !Reminder.table_exists?
|
||||
assert Person.column_methods_hash.include?(:last_name)
|
||||
assert Person.column_methods_hash.include?(:last_name)
|
||||
assert_equal 2, ActiveRecord::Migrator.current_version
|
||||
end
|
||||
|
||||
@ -925,7 +925,7 @@ def test_references_column_type_adds_id
|
||||
t.references :customer
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_references_column_type_with_polymorphic_adds_type
|
||||
with_new_table do |t|
|
||||
t.expects(:column).with('taggable_type', :string, {})
|
||||
@ -933,7 +933,7 @@ def test_references_column_type_with_polymorphic_adds_type
|
||||
t.references :taggable, :polymorphic => true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag
|
||||
with_new_table do |t|
|
||||
t.expects(:column).with('taggable_type', :string, {:null => false})
|
||||
@ -941,14 +941,14 @@ def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_
|
||||
t.references :taggable, :polymorphic => true, :null => false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_belongs_to_works_like_references
|
||||
with_new_table do |t|
|
||||
t.expects(:column).with('customer_id', :integer, {})
|
||||
t.belongs_to :customer
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_timestamps_creates_updated_at_and_created_at
|
||||
with_new_table do |t|
|
||||
t.expects(:column).with(:created_at, :datetime)
|
||||
@ -956,7 +956,7 @@ def test_timestamps_creates_updated_at_and_created_at
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_integer_creates_integer_column
|
||||
with_new_table do |t|
|
||||
t.expects(:column).with(:foo, 'integer', {})
|
||||
@ -964,7 +964,7 @@ def test_integer_creates_integer_column
|
||||
t.integer :foo, :bar
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_string_creates_string_column
|
||||
with_new_table do |t|
|
||||
t.expects(:column).with(:foo, 'string', {})
|
||||
@ -972,7 +972,7 @@ def test_string_creates_string_column
|
||||
t.string :foo, :bar
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
def with_new_table
|
||||
Person.connection.create_table :delete_me do |t|
|
||||
@ -981,8 +981,7 @@ def with_new_table
|
||||
ensure
|
||||
Person.connection.drop_table :delete_me rescue nil
|
||||
end
|
||||
|
||||
|
||||
end # SexyMigrationsTest
|
||||
end # uses_mocha
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ class Mixin < ActiveRecord::Base
|
||||
class Time
|
||||
@@forced_now_time = nil
|
||||
cattr_accessor :forced_now_time
|
||||
|
||||
|
||||
class << self
|
||||
def now_with_forcing
|
||||
if @@forced_now_time
|
||||
@ -23,11 +23,11 @@ def now_with_forcing
|
||||
|
||||
class TouchTest < ActiveSupport::TestCase
|
||||
fixtures :mixins
|
||||
|
||||
|
||||
def setup
|
||||
Time.forced_now_time = Time.now
|
||||
end
|
||||
|
||||
|
||||
def teardown
|
||||
Time.forced_now_time = nil
|
||||
end
|
||||
@ -36,7 +36,7 @@ def test_time_mocking
|
||||
five_minutes_ago = 5.minutes.ago
|
||||
Time.forced_now_time = five_minutes_ago
|
||||
assert_equal five_minutes_ago, Time.now
|
||||
|
||||
|
||||
Time.forced_now_time = nil
|
||||
assert_not_equal five_minutes_ago, Time.now
|
||||
end
|
@ -15,7 +15,7 @@ def test_module_spanning_has_and_belongs_to_many_associations
|
||||
project.developers << MyApplication::Business::Developer.create("name" => "John")
|
||||
assert "John", project.developers.last.name
|
||||
end
|
||||
|
||||
|
||||
def test_associations_spanning_cross_modules
|
||||
account = MyApplication::Billing::Account.find(:first, :order => 'id')
|
||||
assert_kind_of MyApplication::Business::Firm, account.firm
|
||||
@ -24,11 +24,11 @@ def test_associations_spanning_cross_modules
|
||||
assert_kind_of MyApplication::Billing::Nested::Firm, account.nested_qualified_billing_firm
|
||||
assert_kind_of MyApplication::Billing::Nested::Firm, account.nested_unqualified_billing_firm
|
||||
end
|
||||
|
||||
|
||||
def test_find_account_and_include_company
|
||||
account = MyApplication::Billing::Account.find(1, :include => :firm)
|
||||
assert_kind_of MyApplication::Business::Firm, account.instance_variable_get('@firm')
|
||||
assert_kind_of MyApplication::Business::Firm, account.firm
|
||||
end
|
||||
|
||||
|
||||
end
|
@ -65,7 +65,7 @@ def test_string_key
|
||||
def test_find_with_more_than_one_string_key
|
||||
assert_equal 2, Subscriber.find(subscribers(:first).nick, subscribers(:second).nick).length
|
||||
end
|
||||
|
||||
|
||||
def test_primary_key_prefix
|
||||
ActiveRecord::Base.primary_key_prefix_type = :table_name
|
||||
Topic.reset_primary_key
|
||||
@ -79,7 +79,7 @@ def test_primary_key_prefix
|
||||
Topic.reset_primary_key
|
||||
assert_equal "id", Topic.primary_key
|
||||
end
|
||||
|
||||
|
||||
def test_delete_should_quote_pkey
|
||||
assert_nothing_raised { MixedCaseMonkey.delete(1) }
|
||||
end
|
@ -71,13 +71,13 @@ def test_has_many_with_through_is_not_implicitly_marked_readonly
|
||||
end
|
||||
|
||||
def test_readonly_scoping
|
||||
Post.with_scope(:find => { :conditions => '1=1' }) do
|
||||
Post.with_scope(:find => { :conditions => '1=1' }) do
|
||||
assert !Post.find(1).readonly?
|
||||
assert Post.find(1, :readonly => true).readonly?
|
||||
assert !Post.find(1, :readonly => false).readonly?
|
||||
end
|
||||
|
||||
Post.with_scope(:find => { :joins => ' ' }) do
|
||||
Post.with_scope(:find => { :joins => ' ' }) do
|
||||
assert !Post.find(1).readonly?
|
||||
assert Post.find(1, :readonly => true).readonly?
|
||||
assert !Post.find(1, :readonly => false).readonly?
|
||||
@ -86,7 +86,7 @@ def test_readonly_scoping
|
||||
# Oracle barfs on this because the join includes unqualified and
|
||||
# conflicting column names
|
||||
unless current_adapter?(:OracleAdapter)
|
||||
Post.with_scope(:find => { :joins => ', developers' }) do
|
||||
Post.with_scope(:find => { :joins => ', developers' }) do
|
||||
assert Post.find(1).readonly?
|
||||
assert Post.find(1, :readonly => true).readonly?
|
||||
assert !Post.find(1, :readonly => false).readonly?
|
@ -45,7 +45,7 @@ def test_column_string_type_and_limit
|
||||
assert_equal :string, @first.column_for_attribute("title").type
|
||||
assert_equal 255, @first.column_for_attribute("title").limit
|
||||
end
|
||||
|
||||
|
||||
def test_column_null_not_null
|
||||
subscriber = Subscriber.find(:first)
|
||||
assert subscriber.column_for_attribute("name").null
|
||||
@ -87,7 +87,7 @@ def test_aggregation_reflection
|
||||
assert_equal reflection_for_address, Customer.reflect_on_aggregation(:address)
|
||||
|
||||
assert_equal Address, Customer.reflect_on_aggregation(:address).klass
|
||||
|
||||
|
||||
assert_equal Money, Customer.reflect_on_aggregation(:balance).klass
|
||||
end
|
||||
|
||||
@ -157,7 +157,7 @@ def test_association_reflection_in_modules
|
||||
:class_name => 'Nested::Firm',
|
||||
:table_name => 'companies'
|
||||
end
|
||||
|
||||
|
||||
def test_reflection_of_all_associations
|
||||
assert_equal 17, Firm.reflect_on_all_associations.size
|
||||
assert_equal 15, Firm.reflect_on_all_associations(:has_many).size
|
2
activerecord/test/reserved_word_test_mysql.rb → activerecord/test/cases/reserved_word_test_mysql.rb
2
activerecord/test/reserved_word_test_mysql.rb → activerecord/test/cases/reserved_word_test_mysql.rb
@ -141,7 +141,7 @@ def test_activerecord_introspection
|
||||
assert_nothing_raised { Group.table_exists? }
|
||||
assert_nothing_raised { Group.columns }
|
||||
end
|
||||
|
||||
|
||||
# Calculations
|
||||
def test_calculations_work_with_reserved_words
|
||||
assert_nothing_raised { Group.count }
|
@ -28,7 +28,7 @@ def setup
|
||||
end
|
||||
|
||||
def teardown
|
||||
set_session_auth
|
||||
set_session_auth
|
||||
@connection.execute "RESET search_path"
|
||||
USERS.each do |u|
|
||||
@connection.execute "DROP SCHEMA #{u} CASCADE"
|
@ -11,14 +11,14 @@ def standard_dump
|
||||
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
||||
stream.string
|
||||
end
|
||||
|
||||
|
||||
def test_schema_dump
|
||||
output = standard_dump
|
||||
assert_match %r{create_table "accounts"}, output
|
||||
assert_match %r{create_table "authors"}, output
|
||||
assert_no_match %r{create_table "schema_info"}, output
|
||||
end
|
||||
|
||||
|
||||
def test_schema_dump_excludes_sqlite_sequence
|
||||
output = standard_dump
|
||||
assert_no_match %r{create_table "sqlite_sequence"}, output
|
||||
@ -41,7 +41,7 @@ def test_types_line_up
|
||||
column_definition_lines.each do |column_set|
|
||||
next if column_set.empty?
|
||||
|
||||
lengths = column_set.map do |column|
|
||||
lengths = column_set.map do |column|
|
||||
if match = column.match(/t\.(?:integer|decimal|float|datetime|timestamp|time|date|text|binary|string|boolean)\s+"/)
|
||||
match[0].length
|
||||
end
|
||||
@ -50,7 +50,7 @@ def test_types_line_up
|
||||
assert_equal 1, lengths.uniq.length
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_arguments_line_up
|
||||
column_definition_lines.each do |column_set|
|
||||
assert_line_up(column_set, /:default => /)
|
||||
@ -58,15 +58,15 @@ def test_arguments_line_up
|
||||
assert_line_up(column_set, /:null => /)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_no_dump_errors
|
||||
output = standard_dump
|
||||
assert_no_match %r{\# Could not dump table}, output
|
||||
end
|
||||
|
||||
|
||||
def test_schema_dump_includes_not_null_columns
|
||||
stream = StringIO.new
|
||||
|
||||
|
||||
ActiveRecord::SchemaDumper.ignore_tables = [/^[^r]/]
|
||||
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
||||
output = stream.string
|
||||
@ -75,8 +75,8 @@ def test_schema_dump_includes_not_null_columns
|
||||
|
||||
def test_schema_dump_with_string_ignored_table
|
||||
stream = StringIO.new
|
||||
|
||||
ActiveRecord::SchemaDumper.ignore_tables = ['accounts']
|
||||
|
||||
ActiveRecord::SchemaDumper.ignore_tables = ['accounts']
|
||||
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
||||
output = stream.string
|
||||
assert_no_match %r{create_table "accounts"}, output
|
||||
@ -87,8 +87,8 @@ def test_schema_dump_with_string_ignored_table
|
||||
|
||||
def test_schema_dump_with_regexp_ignored_table
|
||||
stream = StringIO.new
|
||||
|
||||
ActiveRecord::SchemaDumper.ignore_tables = [/^account/]
|
||||
|
||||
ActiveRecord::SchemaDumper.ignore_tables = [/^account/]
|
||||
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
||||
output = stream.string
|
||||
assert_no_match %r{create_table "accounts"}, output
|
||||
@ -98,8 +98,8 @@ def test_schema_dump_with_regexp_ignored_table
|
||||
|
||||
|
||||
def test_schema_dump_illegal_ignored_table_value
|
||||
stream = StringIO.new
|
||||
ActiveRecord::SchemaDumper.ignore_tables = [5]
|
||||
stream = StringIO.new
|
||||
ActiveRecord::SchemaDumper.ignore_tables = [5]
|
||||
assert_raise(StandardError) do
|
||||
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
||||
end
|
||||
@ -120,7 +120,7 @@ def test_mysql_schema_dump_should_honor_nonstandard_primary_keys
|
||||
end
|
||||
|
||||
def test_schema_dump_includes_decimal_options
|
||||
stream = StringIO.new
|
||||
stream = StringIO.new
|
||||
ActiveRecord::SchemaDumper.ignore_tables = [/^[^n]/]
|
||||
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
||||
output = stream.string
|
@ -3,7 +3,7 @@
|
||||
|
||||
class SerializationTest < ActiveSupport::TestCase
|
||||
FORMATS = [ :xml, :json ]
|
||||
|
||||
|
||||
def setup
|
||||
@contact_attributes = {
|
||||
:name => 'aaron stack',
|
||||
@ -16,12 +16,12 @@ def setup
|
||||
|
||||
@contact = Contact.new(@contact_attributes)
|
||||
end
|
||||
|
||||
|
||||
def test_serialize_should_be_reversible
|
||||
for format in FORMATS
|
||||
@serialized = Contact.new.send("to_#{format}")
|
||||
contact = Contact.new.send("from_#{format}", @serialized)
|
||||
|
||||
|
||||
assert_equal @contact_attributes.keys.collect(&:to_s).sort, contact.attributes.keys.collect(&:to_s).sort, "For #{format}"
|
||||
end
|
||||
end
|
@ -13,5 +13,5 @@ def test_oracle_synonym
|
||||
subject = Subject.new
|
||||
assert_equal(topic.attributes, subject.attributes)
|
||||
end
|
||||
|
||||
|
||||
end
|
@ -13,7 +13,7 @@ def setup
|
||||
@connections = []
|
||||
@allow_concurrency = ActiveRecord::Base.allow_concurrency
|
||||
end
|
||||
|
||||
|
||||
def teardown
|
||||
# clear the connection cache
|
||||
ActiveRecord::Base.send(:clear_all_cached_connections!)
|
||||
@ -22,11 +22,11 @@ def teardown
|
||||
# reestablish old connection
|
||||
ActiveRecord::Base.establish_connection(@connection)
|
||||
end
|
||||
|
||||
|
||||
def gather_connections(use_threaded_connections)
|
||||
ActiveRecord::Base.allow_concurrency = use_threaded_connections
|
||||
ActiveRecord::Base.establish_connection(@connection)
|
||||
|
||||
|
||||
5.times do
|
||||
Thread.new do
|
||||
Topic.find :first
|
@ -1,5 +1,5 @@
|
||||
print "Using native DB2\n"
|
||||
require_dependency 'fixtures/course'
|
||||
require_dependency 'models/course'
|
||||
require 'logger'
|
||||
|
||||
ActiveRecord::Base.logger = Logger.new("debug.log")
|
||||
|
@ -1,5 +1,5 @@
|
||||
print "Using native Firebird\n"
|
||||
require_dependency 'fixtures/course'
|
||||
require_dependency 'models/course'
|
||||
require 'logger'
|
||||
|
||||
ActiveRecord::Base.logger = Logger.new("debug.log")
|
||||
|
@ -1,5 +1,5 @@
|
||||
puts 'Using native Frontbase'
|
||||
require_dependency 'fixtures/course'
|
||||
require_dependency 'models/course'
|
||||
require 'logger'
|
||||
|
||||
ActiveRecord::Base.logger = Logger.new("debug.log")
|
||||
|
@ -1,5 +1,5 @@
|
||||
print "Using native MySQL\n"
|
||||
require_dependency 'fixtures/course'
|
||||
require_dependency 'models/course'
|
||||
require 'logger'
|
||||
|
||||
RAILS_DEFAULT_LOGGER = Logger.new('debug.log')
|
||||
|
@ -1,5 +1,5 @@
|
||||
print "Using native OpenBase\n"
|
||||
require_dependency 'fixtures/course'
|
||||
require_dependency 'models/course'
|
||||
require 'logger'
|
||||
|
||||
ActiveRecord::Base.logger = Logger.new("debug.log")
|
||||
|
@ -1,5 +1,5 @@
|
||||
print "Using Oracle\n"
|
||||
require_dependency 'fixtures/course'
|
||||
require_dependency 'models/course'
|
||||
require 'logger'
|
||||
|
||||
ActiveRecord::Base.logger = Logger.new STDOUT
|
||||
|
@ -1,5 +1,5 @@
|
||||
print "Using native PostgreSQL\n"
|
||||
require_dependency 'fixtures/course'
|
||||
require_dependency 'models/course'
|
||||
require 'logger'
|
||||
|
||||
ActiveRecord::Base.logger = Logger.new("debug.log")
|
||||
|
@ -1,5 +1,5 @@
|
||||
print "Using native SQlite\n"
|
||||
require_dependency 'fixtures/course'
|
||||
require_dependency 'models/course'
|
||||
require 'logger'
|
||||
ActiveRecord::Base.logger = Logger.new("debug.log")
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
print "Using native SQLite3\n"
|
||||
require_dependency 'fixtures/course'
|
||||
require_dependency 'models/course'
|
||||
require 'logger'
|
||||
ActiveRecord::Base.logger = Logger.new("debug.log")
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
print "Using native SQLite3\n"
|
||||
require_dependency 'fixtures/course'
|
||||
require_dependency 'models/course'
|
||||
require 'logger'
|
||||
ActiveRecord::Base.logger = Logger.new("debug.log")
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
print "Using native Sybase Open Client\n"
|
||||
require_dependency 'fixtures/course'
|
||||
require_dependency 'models/course'
|
||||
require 'logger'
|
||||
|
||||
ActiveRecord::Base.logger = Logger.new("debug.log")
|
||||
|
Loading…
Reference in New Issue
Block a user