1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
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"
expanded_path = File.expand_path("app/views", app_path)
assert_equal ActionController::Base.view_paths[0].to_s, expanded_path
assert_equal ActionMailer::Base.view_paths[0].to_s, expanded_path
end
test "allows me to configure default url options for ActionMailer" do
app_file "config/environments/development.rb", <<-RUBY
AppTemplate::Application.configure do
config.action_mailer.default_url_options = { :host => "test.rails" }
end
RUBY
require "#{app_path}/config/environment"
assert_equal "test.rails", ActionMailer::Base.default_url_options[:host]
end
test "does not include url helpers as action methods" do
app_file "config/routes.rb", <<-RUBY
AppTemplate::Application.routes.draw do
get "/foo", :to => lambda { |env| [200, {}, []] }, :as => :foo
end
RUBY
app_file "app/mailers/foo.rb", <<-RUBY
class Foo < ActionMailer::Base
def notify
end
end
RUBY
require "#{app_path}/config/environment"
assert Foo.method_defined?(:foo_path)
assert_equal ["notify"], Foo.action_methods
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].sample }
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].forty_two }
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.session_store :cookie_store, { :key => "blahblahblah" }
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.session_store :active_record_store"
require "#{app_path}/config/environment"
expects = [ActiveRecord::QueryCache, ActiveRecord::SessionStore]
middleware = Rails.application.config.middleware.map { |m| m.klass }
assert_equal expects, middleware & expects
end
test "database middleware initializes when allow concurrency is true" do
add_to_config "config.threadsafe!"
require "#{app_path}/config/environment"
expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache]
middleware = Rails.application.config.middleware.map { |m| m.klass }
assert_equal expects, middleware & expects
end
test "active_record extensions are applied to ActiveRecord" do
add_to_config "config.active_record.table_name_prefix = 'tbl_'"
require "#{app_path}/config/environment"
assert_equal 'tbl_', ActiveRecord::Base.table_name_prefix
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::Base)
end
end
end
|