ghazel-erubis_rails_helper 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/README.rdoc +66 -0
  2. data/lib/erubis_rails_helper/erubis/generator.rb +100 -0
  3. data/lib/erubis_rails_helper/template_handlers/erubis.rb +260 -0
  4. data/lib/erubis_rails_helper.rb +20 -0
  5. data/test/abstract_unit.rb +51 -0
  6. data/test/controller/action_pack_assertions_test.rb +516 -0
  7. data/test/controller/addresses_render_test.rb +37 -0
  8. data/test/controller/assert_select_test.rb +734 -0
  9. data/test/controller/base_test.rb +217 -0
  10. data/test/controller/benchmark_test.rb +32 -0
  11. data/test/controller/caching_test.rb +690 -0
  12. data/test/controller/capture_test.rb +66 -0
  13. data/test/controller/content_type_test.rb +168 -0
  14. data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
  15. data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
  16. data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
  17. data/test/controller/cookie_test.rb +111 -0
  18. data/test/controller/deprecation/deprecated_base_methods_test.rb +32 -0
  19. data/test/controller/dispatcher_test.rb +103 -0
  20. data/test/controller/fake_controllers.rb +33 -0
  21. data/test/controller/fake_models.rb +19 -0
  22. data/test/controller/filter_params_test.rb +49 -0
  23. data/test/controller/filters_test.rb +885 -0
  24. data/test/controller/flash_test.rb +142 -0
  25. data/test/controller/header_test.rb +14 -0
  26. data/test/controller/helper_test.rb +224 -0
  27. data/test/controller/html-scanner/cdata_node_test.rb +15 -0
  28. data/test/controller/html-scanner/document_test.rb +148 -0
  29. data/test/controller/html-scanner/node_test.rb +89 -0
  30. data/test/controller/html-scanner/sanitizer_test.rb +273 -0
  31. data/test/controller/html-scanner/tag_node_test.rb +238 -0
  32. data/test/controller/html-scanner/text_node_test.rb +50 -0
  33. data/test/controller/html-scanner/tokenizer_test.rb +131 -0
  34. data/test/controller/http_basic_authentication_test.rb +88 -0
  35. data/test/controller/http_digest_authentication_test.rb +178 -0
  36. data/test/controller/integration_test.rb +417 -0
  37. data/test/controller/layout_test.rb +204 -0
  38. data/test/controller/logging_test.rb +46 -0
  39. data/test/controller/middleware_stack_test.rb +90 -0
  40. data/test/controller/mime_responds_test.rb +536 -0
  41. data/test/controller/mime_type_test.rb +93 -0
  42. data/test/controller/polymorphic_routes_test.rb +293 -0
  43. data/test/controller/rack_test.rb +294 -0
  44. data/test/controller/record_identifier_test.rb +139 -0
  45. data/test/controller/redirect_test.rb +282 -0
  46. data/test/controller/render_test.rb +1752 -0
  47. data/test/controller/request/json_params_parsing_test.rb +45 -0
  48. data/test/controller/request/multipart_params_parsing_test.rb +223 -0
  49. data/test/controller/request/query_string_parsing_test.rb +120 -0
  50. data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
  51. data/test/controller/request/xml_params_parsing_test.rb +88 -0
  52. data/test/controller/request_forgery_protection_test.rb +246 -0
  53. data/test/controller/request_test.rb +407 -0
  54. data/test/controller/rescue_test.rb +536 -0
  55. data/test/controller/resources_test.rb +1341 -0
  56. data/test/controller/routing_test.rb +2557 -0
  57. data/test/controller/selector_test.rb +628 -0
  58. data/test/controller/send_file_test.rb +161 -0
  59. data/test/controller/session/cookie_store_test.rb +239 -0
  60. data/test/controller/session/mem_cache_store_test.rb +127 -0
  61. data/test/controller/session/test_session_test.rb +58 -0
  62. data/test/controller/test_test.rb +692 -0
  63. data/test/controller/translation_test.rb +26 -0
  64. data/test/controller/url_rewriter_test.rb +359 -0
  65. data/test/controller/verification_test.rb +270 -0
  66. data/test/controller/view_paths_test.rb +141 -0
  67. data/test/controller/webservice_test.rb +260 -0
  68. data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
  69. data/test/fixtures/company.rb +10 -0
  70. data/test/fixtures/developer.rb +9 -0
  71. data/test/fixtures/helpers/abc_helper.rb +5 -0
  72. data/test/fixtures/helpers/fun/games_helper.rb +3 -0
  73. data/test/fixtures/helpers/fun/pdf_helper.rb +3 -0
  74. data/test/fixtures/mascot.rb +3 -0
  75. data/test/fixtures/project.rb +3 -0
  76. data/test/fixtures/reply.rb +7 -0
  77. data/test/fixtures/topic.rb +3 -0
  78. data/test/template/asset_tag_helper_test.rb +713 -0
  79. data/test/template/atom_feed_helper_test.rb +286 -0
  80. data/test/template/benchmark_helper_test.rb +86 -0
  81. data/test/template/compiled_templates_test.rb +203 -0
  82. data/test/template/date_helper_i18n_test.rb +120 -0
  83. data/test/template/date_helper_test.rb +2469 -0
  84. data/test/template/erb_util_test.rb +24 -0
  85. data/test/template/form_helper_test.rb +1176 -0
  86. data/test/template/form_options_helper_test.rb +751 -0
  87. data/test/template/form_tag_helper_test.rb +327 -0
  88. data/test/template/javascript_helper_test.rb +106 -0
  89. data/test/template/number_helper_i18n_test.rb +69 -0
  90. data/test/template/number_helper_test.rb +128 -0
  91. data/test/template/prototype_helper_test.rb +639 -0
  92. data/test/template/record_tag_helper_test.rb +58 -0
  93. data/test/template/render_test.rb +291 -0
  94. data/test/template/sanitize_helper_test.rb +48 -0
  95. data/test/template/scriptaculous_helper_test.rb +90 -0
  96. data/test/template/tag_helper_test.rb +97 -0
  97. data/test/template/test_test.rb +54 -0
  98. data/test/template/text_helper_test.rb +520 -0
  99. data/test/template/translation_helper_test.rb +32 -0
  100. data/test/template/url_helper_test.rb +614 -0
  101. data/test/test_erubis_rails_helper.rb +4 -0
  102. data/test/testing_sandbox.rb +15 -0
  103. data/test/view/test_case_test.rb +8 -0
  104. metadata +174 -0
@@ -0,0 +1,161 @@
1
+ require 'abstract_unit'
2
+
3
+ module TestFileUtils
4
+ def file_name() File.basename(__FILE__) end
5
+ def file_path() File.expand_path(__FILE__) end
6
+ def file_data() File.open(file_path, 'rb') { |f| f.read } end
7
+ end
8
+
9
+ class SendFileController < ActionController::Base
10
+ include TestFileUtils
11
+ layout "layouts/standard" # to make sure layouts don't interfere
12
+
13
+ attr_writer :options
14
+ def options() @options ||= {} end
15
+
16
+ def file() send_file(file_path, options) end
17
+ def data() send_data(file_data, options) end
18
+
19
+ def rescue_action(e) raise end
20
+ end
21
+
22
+ class SendFileTest < ActionController::TestCase
23
+ tests SendFileController
24
+ include TestFileUtils
25
+
26
+ Mime::Type.register "image/png", :png unless defined? Mime::PNG
27
+
28
+ def setup
29
+ @controller = SendFileController.new
30
+ @request = ActionController::TestRequest.new
31
+ @response = ActionController::TestResponse.new
32
+ end
33
+
34
+ def test_file_nostream
35
+ @controller.options = { :stream => false }
36
+ response = nil
37
+ assert_nothing_raised { response = process('file') }
38
+ assert_not_nil response
39
+ assert_kind_of String, response.body
40
+ assert_equal file_data, response.body
41
+ end
42
+
43
+ def test_file_stream
44
+ response = nil
45
+ assert_nothing_raised { response = process('file') }
46
+ assert_not_nil response
47
+ assert_kind_of Proc, response.body
48
+
49
+ require 'stringio'
50
+ output = StringIO.new
51
+ output.binmode
52
+ assert_nothing_raised { response.body.call(response, output) }
53
+ assert_equal file_data, output.string
54
+ end
55
+
56
+ def test_file_url_based_filename
57
+ @controller.options = { :url_based_filename => true }
58
+ response = nil
59
+ assert_nothing_raised { response = process('file') }
60
+ assert_not_nil response
61
+ assert_equal "attachment", response.headers["Content-Disposition"]
62
+ end
63
+
64
+ def test_x_sendfile_header
65
+ @controller.options = { :x_sendfile => true }
66
+
67
+ response = nil
68
+ assert_nothing_raised { response = process('file') }
69
+ assert_not_nil response
70
+
71
+ assert_equal @controller.file_path, response.headers['X-Sendfile']
72
+ assert response.body.blank?
73
+ assert !response.etag?
74
+ end
75
+
76
+ def test_data
77
+ response = nil
78
+ assert_nothing_raised { response = process('data') }
79
+ assert_not_nil response
80
+
81
+ assert_kind_of String, response.body
82
+ assert_equal file_data, response.body
83
+ end
84
+
85
+ def test_headers_after_send_shouldnt_include_charset
86
+ response = process('data')
87
+ assert_equal "application/octet-stream", response.content_type
88
+
89
+ response = process('file')
90
+ assert_equal "application/octet-stream", response.content_type
91
+ end
92
+
93
+ # Test that send_file_headers! is setting the correct HTTP headers.
94
+ def test_send_file_headers!
95
+ options = {
96
+ :length => 1,
97
+ :type => Mime::PNG,
98
+ :disposition => 'disposition',
99
+ :filename => 'filename'
100
+ }
101
+
102
+ # Do it a few times: the resulting headers should be identical
103
+ # no matter how many times you send with the same options.
104
+ # Test resolving Ticket #458.
105
+ @controller.headers = {}
106
+ @controller.send(:send_file_headers!, options)
107
+ @controller.send(:send_file_headers!, options)
108
+ @controller.send(:send_file_headers!, options)
109
+
110
+ h = @controller.headers
111
+ assert_equal 1, h['Content-Length']
112
+ assert_equal 'image/png', h['Content-Type']
113
+ assert_equal 'disposition; filename="filename"', h['Content-Disposition']
114
+ assert_equal 'binary', h['Content-Transfer-Encoding']
115
+
116
+ # test overriding Cache-Control: no-cache header to fix IE open/save dialog
117
+ @controller.headers = { 'Cache-Control' => 'no-cache' }
118
+ @controller.send(:send_file_headers!, options)
119
+ h = @controller.headers
120
+ assert_equal 'private', h['Cache-Control']
121
+ end
122
+
123
+ def test_send_file_headers_with_mime_lookup_with_symbol
124
+ options = {
125
+ :length => 1,
126
+ :type => :png
127
+ }
128
+
129
+ @controller.headers = {}
130
+ @controller.send(:send_file_headers!, options)
131
+
132
+ headers = @controller.headers
133
+
134
+ assert_equal 'image/png', headers['Content-Type']
135
+ end
136
+
137
+
138
+ def test_send_file_headers_with_bad_symbol
139
+ options = {
140
+ :length => 1,
141
+ :type => :this_type_is_not_registered
142
+ }
143
+
144
+ @controller.headers = {}
145
+ assert_raise(ArgumentError){ @controller.send(:send_file_headers!, options) }
146
+ end
147
+
148
+ %w(file data).each do |method|
149
+ define_method "test_send_#{method}_status" do
150
+ @controller.options = { :stream => false, :status => 500 }
151
+ assert_nothing_raised { assert_not_nil process(method) }
152
+ assert_equal '500 Internal Server Error', @response.status
153
+ end
154
+
155
+ define_method "test_default_send_#{method}_status" do
156
+ @controller.options = { :stream => false }
157
+ assert_nothing_raised { assert_not_nil process(method) }
158
+ assert_equal ActionController::Base::DEFAULT_RENDER_STATUS_CODE, @response.status
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,239 @@
1
+ require 'abstract_unit'
2
+ require 'stringio'
3
+
4
+ class CookieStoreTest < ActionController::IntegrationTest
5
+ SessionKey = '_myapp_session'
6
+ SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33'
7
+
8
+ DispatcherApp = ActionController::Dispatcher.new
9
+ CookieStoreApp = ActionController::Session::CookieStore.new(DispatcherApp, :key => SessionKey, :secret => SessionSecret)
10
+
11
+ Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1')
12
+
13
+ SignedBar = "BAh7BjoIZm9vIghiYXI%3D--fef868465920f415f2c0652d6910d3af288a0367"
14
+
15
+ class TestController < ActionController::Base
16
+ def no_session_access
17
+ head :ok
18
+ end
19
+
20
+ def persistent_session_id
21
+ render :text => session[:session_id]
22
+ end
23
+
24
+ def set_session_value
25
+ session[:foo] = "bar"
26
+ render :text => Rack::Utils.escape(Verifier.generate(session.to_hash))
27
+ end
28
+
29
+ def get_session_value
30
+ render :text => "foo: #{session[:foo].inspect}"
31
+ end
32
+
33
+ def get_session_id
34
+ render :text => "foo: #{session[:foo].inspect}; id: #{request.session_options[:id]}"
35
+ end
36
+
37
+ def call_reset_session
38
+ reset_session
39
+ head :ok
40
+ end
41
+
42
+ def raise_data_overflow
43
+ session[:foo] = 'bye!' * 1024
44
+ head :ok
45
+ end
46
+
47
+ def rescue_action(e) raise end
48
+ end
49
+
50
+ def setup
51
+ @integration_session = open_session(CookieStoreApp)
52
+ end
53
+
54
+ def test_raises_argument_error_if_missing_session_key
55
+ assert_raise(ArgumentError, nil.inspect) {
56
+ ActionController::Session::CookieStore.new(nil,
57
+ :key => nil, :secret => SessionSecret)
58
+ }
59
+
60
+ assert_raise(ArgumentError, ''.inspect) {
61
+ ActionController::Session::CookieStore.new(nil,
62
+ :key => '', :secret => SessionSecret)
63
+ }
64
+ end
65
+
66
+ def test_raises_argument_error_if_missing_secret
67
+ assert_raise(ArgumentError, nil.inspect) {
68
+ ActionController::Session::CookieStore.new(nil,
69
+ :key => SessionKey, :secret => nil)
70
+ }
71
+
72
+ assert_raise(ArgumentError, ''.inspect) {
73
+ ActionController::Session::CookieStore.new(nil,
74
+ :key => SessionKey, :secret => '')
75
+ }
76
+ end
77
+
78
+ def test_raises_argument_error_if_secret_is_probably_insecure
79
+ assert_raise(ArgumentError, "password".inspect) {
80
+ ActionController::Session::CookieStore.new(nil,
81
+ :key => SessionKey, :secret => "password")
82
+ }
83
+
84
+ assert_raise(ArgumentError, "secret".inspect) {
85
+ ActionController::Session::CookieStore.new(nil,
86
+ :key => SessionKey, :secret => "secret")
87
+ }
88
+
89
+ assert_raise(ArgumentError, "12345678901234567890123456789".inspect) {
90
+ ActionController::Session::CookieStore.new(nil,
91
+ :key => SessionKey, :secret => "12345678901234567890123456789")
92
+ }
93
+ end
94
+
95
+ def test_setting_session_value
96
+ with_test_route_set do
97
+ get '/set_session_value'
98
+ assert_response :success
99
+ assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly",
100
+ headers['Set-Cookie']
101
+ end
102
+ end
103
+
104
+ def test_getting_session_value
105
+ with_test_route_set do
106
+ cookies[SessionKey] = SignedBar
107
+ get '/get_session_value'
108
+ assert_response :success
109
+ assert_equal 'foo: "bar"', response.body
110
+ end
111
+ end
112
+
113
+ def test_getting_session_id
114
+ with_test_route_set do
115
+ cookies[SessionKey] = SignedBar
116
+ get '/persistent_session_id'
117
+ assert_response :success
118
+ assert_equal response.body.size, 32
119
+ session_id = response.body
120
+
121
+ get '/get_session_id'
122
+ assert_response :success
123
+ assert_equal "foo: \"bar\"; id: #{session_id}", response.body
124
+ end
125
+ end
126
+
127
+ def test_disregards_tampered_sessions
128
+ with_test_route_set do
129
+ cookies[SessionKey] = "BAh7BjoIZm9vIghiYXI%3D--123456780"
130
+ get '/get_session_value'
131
+ assert_response :success
132
+ assert_equal 'foo: nil', response.body
133
+ end
134
+ end
135
+
136
+ def test_close_raises_when_data_overflows
137
+ with_test_route_set do
138
+ assert_raise(ActionController::Session::CookieStore::CookieOverflow) {
139
+ get '/raise_data_overflow'
140
+ }
141
+ end
142
+ end
143
+
144
+ def test_doesnt_write_session_cookie_if_session_is_not_accessed
145
+ with_test_route_set do
146
+ get '/no_session_access'
147
+ assert_response :success
148
+ assert_equal "", headers['Set-Cookie']
149
+ end
150
+ end
151
+
152
+ def test_doesnt_write_session_cookie_if_session_is_unchanged
153
+ with_test_route_set do
154
+ cookies[SessionKey] = "BAh7BjoIZm9vIghiYXI%3D--" +
155
+ "fef868465920f415f2c0652d6910d3af288a0367"
156
+ get '/no_session_access'
157
+ assert_response :success
158
+ assert_equal "", headers['Set-Cookie']
159
+ end
160
+ end
161
+
162
+ def test_setting_session_value_after_session_reset
163
+ with_test_route_set do
164
+ get '/set_session_value'
165
+ assert_response :success
166
+ session_payload = response.body
167
+ assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly",
168
+ headers['Set-Cookie']
169
+
170
+ get '/call_reset_session'
171
+ assert_response :success
172
+ assert_not_equal [], headers['Set-Cookie']
173
+ assert_not_equal session_payload, cookies[SessionKey]
174
+
175
+ get '/get_session_value'
176
+ assert_response :success
177
+ assert_equal 'foo: nil', response.body
178
+ end
179
+ end
180
+
181
+ def test_persistent_session_id
182
+ with_test_route_set do
183
+ cookies[SessionKey] = SignedBar
184
+ get '/persistent_session_id'
185
+ assert_response :success
186
+ assert_equal response.body.size, 32
187
+ session_id = response.body
188
+ get '/persistent_session_id'
189
+ assert_equal session_id, response.body
190
+ reset!
191
+ get '/persistent_session_id'
192
+ assert_not_equal session_id, response.body
193
+ end
194
+ end
195
+
196
+ def test_session_store_with_expire_after
197
+ app = ActionController::Session::CookieStore.new(DispatcherApp, :key => SessionKey, :secret => SessionSecret, :expire_after => 5.hours)
198
+ @integration_session = open_session(app)
199
+
200
+ with_test_route_set do
201
+ # First request accesses the session
202
+ time = Time.local(2008, 4, 24)
203
+ Time.stubs(:now).returns(time)
204
+ expected_expiry = (time + 5.hours).gmtime.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
205
+
206
+ cookies[SessionKey] = SignedBar
207
+
208
+ get '/set_session_value'
209
+ assert_response :success
210
+
211
+ cookie_body = response.body
212
+ assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly",
213
+ headers['Set-Cookie']
214
+
215
+ # Second request does not access the session
216
+ time = Time.local(2008, 4, 25)
217
+ Time.stubs(:now).returns(time)
218
+ expected_expiry = (time + 5.hours).gmtime.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
219
+
220
+ get '/no_session_access'
221
+ assert_response :success
222
+
223
+ assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly",
224
+ headers['Set-Cookie']
225
+ end
226
+ end
227
+
228
+ private
229
+ def with_test_route_set
230
+ with_routing do |set|
231
+ set.draw do |map|
232
+ map.with_options :controller => "cookie_store_test/test" do |c|
233
+ c.connect "/:action"
234
+ end
235
+ end
236
+ yield
237
+ end
238
+ end
239
+ end
@@ -0,0 +1,127 @@
1
+ require 'abstract_unit'
2
+
3
+ # You need to start a memcached server inorder to run these tests
4
+ class MemCacheStoreTest < ActionController::IntegrationTest
5
+ class TestController < ActionController::Base
6
+ def no_session_access
7
+ head :ok
8
+ end
9
+
10
+ def set_session_value
11
+ session[:foo] = "bar"
12
+ head :ok
13
+ end
14
+
15
+ def get_session_value
16
+ render :text => "foo: #{session[:foo].inspect}"
17
+ end
18
+
19
+ def get_session_id
20
+ session[:foo]
21
+ render :text => "#{request.session_options[:id]}"
22
+ end
23
+
24
+ def call_reset_session
25
+ session[:bar]
26
+ reset_session
27
+ session[:bar] = "baz"
28
+ head :ok
29
+ end
30
+
31
+ def rescue_action(e) raise end
32
+ end
33
+
34
+ begin
35
+ DispatcherApp = ActionController::Dispatcher.new
36
+ MemCacheStoreApp = ActionController::Session::MemCacheStore.new(
37
+ DispatcherApp, :key => '_session_id')
38
+
39
+
40
+ def setup
41
+ @integration_session = open_session(MemCacheStoreApp)
42
+ end
43
+
44
+ def test_setting_and_getting_session_value
45
+ with_test_route_set do
46
+ get '/set_session_value'
47
+ assert_response :success
48
+ assert cookies['_session_id']
49
+
50
+ get '/get_session_value'
51
+ assert_response :success
52
+ assert_equal 'foo: "bar"', response.body
53
+ end
54
+ end
55
+
56
+ def test_getting_nil_session_value
57
+ with_test_route_set do
58
+ get '/get_session_value'
59
+ assert_response :success
60
+ assert_equal 'foo: nil', response.body
61
+ end
62
+ end
63
+
64
+ def test_setting_session_value_after_session_reset
65
+ with_test_route_set do
66
+ get '/set_session_value'
67
+ assert_response :success
68
+ assert cookies['_session_id']
69
+ session_id = cookies['_session_id']
70
+
71
+ get '/call_reset_session'
72
+ assert_response :success
73
+ assert_not_equal [], headers['Set-Cookie']
74
+
75
+ get '/get_session_value'
76
+ assert_response :success
77
+ assert_equal 'foo: nil', response.body
78
+
79
+ get '/get_session_id'
80
+ assert_response :success
81
+ assert_not_equal session_id, response.body
82
+ end
83
+ end
84
+
85
+ def test_getting_session_id
86
+ with_test_route_set do
87
+ get '/set_session_value'
88
+ assert_response :success
89
+ assert cookies['_session_id']
90
+ session_id = cookies['_session_id']
91
+
92
+ get '/get_session_id'
93
+ assert_response :success
94
+ assert_equal session_id, response.body
95
+ end
96
+ end
97
+
98
+ def test_prevents_session_fixation
99
+ with_test_route_set do
100
+ get '/get_session_value'
101
+ assert_response :success
102
+ assert_equal 'foo: nil', response.body
103
+ session_id = cookies['_session_id']
104
+
105
+ reset!
106
+
107
+ get '/set_session_value', :_session_id => session_id
108
+ assert_response :success
109
+ assert_equal nil, cookies['_session_id']
110
+ end
111
+ end
112
+ rescue LoadError, RuntimeError
113
+ $stderr.puts "Skipping MemCacheStoreTest tests. Start memcached and try again."
114
+ end
115
+
116
+ private
117
+ def with_test_route_set
118
+ with_routing do |set|
119
+ set.draw do |map|
120
+ map.with_options :controller => "mem_cache_store_test/test" do |c|
121
+ c.connect "/:action"
122
+ end
123
+ end
124
+ yield
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,58 @@
1
+ require 'abstract_unit'
2
+ require 'stringio'
3
+
4
+ class ActionController::TestSessionTest < ActiveSupport::TestCase
5
+
6
+ def test_calling_delete_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session
7
+ assert_deprecated(/use clear instead/){ ActionController::TestSession.new.delete }
8
+ end
9
+
10
+ def test_calling_update_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session
11
+ assert_deprecated(/use replace instead/){ ActionController::TestSession.new.update }
12
+ end
13
+
14
+ def test_calling_close_raises_deprecation_warning
15
+ assert_deprecated(/sessions should no longer be closed/){ ActionController::TestSession.new.close }
16
+ end
17
+
18
+ def test_defaults
19
+ session = ActionController::TestSession.new
20
+ assert_equal({}, session.data)
21
+ assert_equal('', session.session_id)
22
+ end
23
+
24
+ def test_ctor_allows_setting
25
+ session = ActionController::TestSession.new({:one => 'one', :two => 'two'})
26
+ assert_equal('one', session[:one])
27
+ assert_equal('two', session[:two])
28
+ end
29
+
30
+ def test_setting_session_item_sets_item
31
+ session = ActionController::TestSession.new
32
+ session[:key] = 'value'
33
+ assert_equal('value', session[:key])
34
+ end
35
+
36
+ def test_calling_delete_removes_item
37
+ session = ActionController::TestSession.new
38
+ session[:key] = 'value'
39
+ assert_equal('value', session[:key])
40
+ session.delete(:key)
41
+ assert_nil(session[:key])
42
+ end
43
+
44
+ def test_calling_update_with_params_passes_to_attributes
45
+ session = ActionController::TestSession.new()
46
+ session.update('key' => 'value')
47
+ assert_equal('value', session[:key])
48
+ end
49
+
50
+ def test_clear_emptys_session
51
+ params = {:one => 'one', :two => 'two'}
52
+ session = ActionController::TestSession.new({:one => 'one', :two => 'two'})
53
+ session.clear
54
+ assert_nil(session[:one])
55
+ assert_nil(session[:two])
56
+ end
57
+
58
+ end