2011-12-18 18:35:25 -05:00
|
|
|
require 'cases/helper'
|
|
|
|
require 'models/teapot'
|
|
|
|
|
|
|
|
class BasicInclusionModelTest < ActiveRecord::TestCase
|
|
|
|
def test_basic_model
|
|
|
|
Teapot.create!(:name => "Ronnie Kemper")
|
|
|
|
assert_equal "Ronnie Kemper", Teapot.find(1).name
|
|
|
|
end
|
2011-12-23 07:52:57 -05:00
|
|
|
|
2011-12-24 06:06:38 -05:00
|
|
|
def test_initialization
|
|
|
|
t = Teapot.new(:name => "Bob")
|
|
|
|
assert_equal "Bob", t.name
|
|
|
|
end
|
|
|
|
|
2011-12-23 07:52:57 -05:00
|
|
|
def test_inherited_model
|
|
|
|
teapot = CoolTeapot.create!(:name => "Bob")
|
|
|
|
teapot.reload
|
|
|
|
|
|
|
|
assert_equal "Bob", teapot.name
|
|
|
|
assert_equal "mmm", teapot.aaahhh
|
|
|
|
end
|
2011-12-23 16:55:05 -05:00
|
|
|
|
|
|
|
def test_generated_feature_methods
|
|
|
|
assert Teapot < Teapot::GeneratedFeatureMethods
|
|
|
|
end
|
2011-12-23 18:54:35 -05:00
|
|
|
|
|
|
|
def test_exists
|
|
|
|
t = Teapot.create!(:name => "Ronnie Kemper")
|
|
|
|
assert Teapot.exists?(t)
|
|
|
|
end
|
2011-12-23 19:24:49 -05:00
|
|
|
|
|
|
|
def test_predicate_builder
|
|
|
|
t = Teapot.create!(:name => "Bob")
|
|
|
|
assert_equal "Bob", Teapot.where(:id => [t]).first.name
|
|
|
|
assert_equal "Bob", Teapot.where(:id => t).first.name
|
|
|
|
end
|
2011-12-24 05:23:19 -05:00
|
|
|
|
|
|
|
def test_nested_model
|
|
|
|
assert_equal "ceiling_teapots", Ceiling::Teapot.table_name
|
|
|
|
end
|
2011-12-18 18:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class InclusionUnitTest < ActiveRecord::TestCase
|
|
|
|
def setup
|
|
|
|
@klass = Class.new { include ActiveRecord::Model }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_non_abstract_class
|
|
|
|
assert !@klass.abstract_class?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_abstract_class
|
|
|
|
@klass.abstract_class = true
|
|
|
|
assert @klass.abstract_class?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_establish_connection
|
|
|
|
assert @klass.respond_to?(:establish_connection)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_adapter_connection
|
|
|
|
assert @klass.respond_to?("#{ActiveRecord::Base.connection_config[:adapter]}_connection")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_connection_handler
|
|
|
|
assert_equal ActiveRecord::Base.connection_handler, @klass.connection_handler
|
|
|
|
end
|
2011-12-23 16:37:52 -05:00
|
|
|
|
|
|
|
def test_mirrored_configuration
|
|
|
|
ActiveRecord::Base.time_zone_aware_attributes = true
|
|
|
|
assert @klass.time_zone_aware_attributes
|
|
|
|
ActiveRecord::Base.time_zone_aware_attributes = false
|
|
|
|
assert !@klass.time_zone_aware_attributes
|
|
|
|
ensure
|
|
|
|
ActiveRecord::Base.time_zone_aware_attributes = false
|
|
|
|
end
|
2011-12-23 19:33:05 -05:00
|
|
|
|
|
|
|
# Doesn't really test anything, but this is here to ensure warnings don't occur
|
|
|
|
def test_included_twice
|
|
|
|
@klass.send :include, ActiveRecord::Model
|
|
|
|
end
|
2011-12-24 06:02:02 -05:00
|
|
|
|
|
|
|
def test_deprecation_proxy
|
|
|
|
assert_equal ActiveRecord::Model.name, ActiveRecord::Model::DeprecationProxy.name
|
|
|
|
assert_equal ActiveRecord::Base.superclass, assert_deprecated { ActiveRecord::Model::DeprecationProxy.superclass }
|
|
|
|
|
|
|
|
sup = nil
|
|
|
|
ActiveSupport.on_load(:__test_active_record_model_deprecation) do
|
|
|
|
sup = superclass
|
|
|
|
end
|
|
|
|
assert_deprecated do
|
|
|
|
ActiveSupport.run_load_hooks(:__test_active_record_model_deprecation, ActiveRecord::Model::DeprecationProxy)
|
|
|
|
end
|
|
|
|
assert_equal ActiveRecord::Base.superclass, sup
|
|
|
|
end
|
2011-12-18 18:35:25 -05:00
|
|
|
end
|
2011-12-23 16:47:58 -05:00
|
|
|
|
|
|
|
class InclusionFixturesTest < ActiveRecord::TestCase
|
|
|
|
fixtures :teapots
|
|
|
|
|
|
|
|
def test_fixtured_record
|
|
|
|
assert_equal "Bob", teapots(:bob).name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_timestamped_fixture
|
|
|
|
assert_not_nil teapots(:bob).created_at
|
|
|
|
end
|
|
|
|
end
|