blob: ea052320ef935bd39888af7f294a45e3e24f833c (
plain) (
tree)
|
|
require "isolation/abstract_unit"
module ApplicationTests
class FrameworlsTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
def setup
build_app
boot_rails
FileUtils.rm_rf "#{app_path}/config/environments"
end
# AC & AM
test "set load paths set only if action controller or action mailer are in use" do
assert_nothing_raised NameError do
add_to_config <<-RUBY
config.root = "#{app_path}"
RUBY
use_frameworks []
require "#{app_path}/config/environment"
end
end
test "sets action_controller and action_mailer load paths" do
add_to_config <<-RUBY
config.root = "#{app_path}"
RUBY
require "#{app_path}/config/environment"
ActionController::Base.view_paths.include?(File.expand_path("app/views", app_path))
ActionMailer::Base.view_paths.include?(File.expand_path("app/views", app_path))
end
# AS
test "if there's no config.active_support.bare, all of ActiveSupport is required" do
use_frameworks []
require "#{app_path}/config/environment"
assert_nothing_raised { [1,2,3].rand }
end
test "config.active_support.bare does not require all of ActiveSupport" do
add_to_config "config.active_support.bare = true"
use_frameworks []
Dir.chdir("#{app_path}/app") do
require "#{app_path}/config/environment"
assert_raises(NoMethodError) { [1,2,3].rand }
end
end
# AR
test "database middleware doesn't initialize when session store is not active_record" do
add_to_config <<-RUBY
config.root = "#{app_path}"
config.action_controller.session_store = :cookie_store
RUBY
require "#{app_path}/config/environment"
assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore)
end
test "database middleware initializes when session store is active record" do
add_to_config "config.action_controller.session_store = :active_record_store"
require "#{app_path}/config/environment"
expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore]
middleware = Rails.application.config.middleware.map { |m| m.klass }
assert_equal expects, middleware & expects
end
test "database middleware doesn't initialize when activerecord is not in frameworks" do
use_frameworks []
require "#{app_path}/config/environment"
assert_nil defined?(ActiveRecord)
end
end
end
|