actionpack 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

@@ -77,7 +77,7 @@ class HelperTest < Test::Unit::TestCase
77
77
 
78
78
  def test_declare_missing_helper
79
79
  assert_equal helper_methods, missing_methods
80
- assert_raise(LoadError) { @controller_class.helper :missing }
80
+ assert_raise(MissingSourceFile) { @controller_class.helper :missing }
81
81
  end
82
82
 
83
83
  def test_declare_missing_file_from_helper
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/../abstract_unit'
2
+
3
+ class TestTest < Test::Unit::TestCase
4
+ class TestController < ActionController::Base
5
+ def set_flash
6
+ flash["test"] = ">#{flash["test"]}<"
7
+ end
8
+ end
9
+
10
+ def setup
11
+ @controller = TestController.new
12
+ @request = ActionController::TestRequest.new
13
+ @response = ActionController::TestResponse.new
14
+ end
15
+
16
+ def test_process_without_flash
17
+ process :set_flash
18
+ assert_flash_equal "><", "test"
19
+ end
20
+
21
+ def test_process_with_flash
22
+ process :set_flash, nil, nil, { "test" => "value" }
23
+ assert_flash_equal ">value<", "test"
24
+ end
25
+ end
@@ -0,0 +1,137 @@
1
+ require File.dirname(__FILE__) + '/../abstract_unit'
2
+
3
+ class VerificationTest < Test::Unit::TestCase
4
+ class TestController < ActionController::Base
5
+ verify :only => :guarded_one, :params => "one",
6
+ :redirect_to => { :action => "unguarded" }
7
+
8
+ verify :only => :guarded_two, :params => %w( one two ),
9
+ :redirect_to => { :action => "unguarded" }
10
+
11
+ verify :only => :guarded_with_flash, :params => "one",
12
+ :add_flash => { "notice" => "prereqs failed" },
13
+ :redirect_to => { :action => "unguarded" }
14
+
15
+ verify :only => :guarded_in_session, :session => "one",
16
+ :redirect_to => { :action => "unguarded" }
17
+
18
+ verify :only => [:multi_one, :multi_two], :session => %w( one two ),
19
+ :redirect_to => { :action => "unguarded" }
20
+
21
+ def guarded_one
22
+ render_text "#{@params["one"]}"
23
+ end
24
+
25
+ def guarded_with_flash
26
+ render_text "#{@params["one"]}"
27
+ end
28
+
29
+ def guarded_two
30
+ render_text "#{@params["one"]}:#{@params["two"]}"
31
+ end
32
+
33
+ def guarded_in_session
34
+ render_text "#{@session["one"]}"
35
+ end
36
+
37
+ def multi_one
38
+ render_text "#{@session["one"]}:#{@session["two"]}"
39
+ end
40
+
41
+ def multi_two
42
+ render_text "#{@session["two"]}:#{@session["one"]}"
43
+ end
44
+
45
+ def unguarded
46
+ render_text "#{@params["one"]}"
47
+ end
48
+ end
49
+
50
+ def setup
51
+ @controller = TestController.new
52
+ @request = ActionController::TestRequest.new
53
+ @response = ActionController::TestResponse.new
54
+ end
55
+
56
+ def test_guarded_one_with_prereqs
57
+ process "guarded_one", "one" => "here"
58
+ assert_equal "here", @response.body
59
+ end
60
+
61
+ def test_guarded_one_without_prereqs
62
+ process "guarded_one"
63
+ assert_redirected_to :action => "unguarded"
64
+ end
65
+
66
+ def test_guarded_with_flash_with_prereqs
67
+ process "guarded_with_flash", "one" => "here"
68
+ assert_equal "here", @response.body
69
+ assert_flash_empty
70
+ end
71
+
72
+ def test_guarded_with_flash_without_prereqs
73
+ process "guarded_with_flash"
74
+ assert_redirected_to :action => "unguarded"
75
+ assert_flash_equal "prereqs failed", "notice"
76
+ end
77
+
78
+ def test_guarded_two_with_prereqs
79
+ process "guarded_two", "one" => "here", "two" => "there"
80
+ assert_equal "here:there", @response.body
81
+ end
82
+
83
+ def test_guarded_two_without_prereqs_one
84
+ process "guarded_two", "two" => "there"
85
+ assert_redirected_to :action => "unguarded"
86
+ end
87
+
88
+ def test_guarded_two_without_prereqs_two
89
+ process "guarded_two", "one" => "here"
90
+ assert_redirected_to :action => "unguarded"
91
+ end
92
+
93
+ def test_guarded_two_without_prereqs_both
94
+ process "guarded_two"
95
+ assert_redirected_to :action => "unguarded"
96
+ end
97
+
98
+ def test_unguarded_with_params
99
+ process "unguarded", "one" => "here"
100
+ assert_equal "here", @response.body
101
+ end
102
+
103
+ def test_unguarded_without_params
104
+ process "unguarded"
105
+ assert_equal "", @response.body
106
+ end
107
+
108
+ def test_guarded_in_session_with_prereqs
109
+ process "guarded_in_session", {}, "one" => "here"
110
+ assert_equal "here", @response.body
111
+ end
112
+
113
+ def test_guarded_in_session_without_prereqs
114
+ process "guarded_in_session"
115
+ assert_redirected_to :action => "unguarded"
116
+ end
117
+
118
+ def test_multi_one_with_prereqs
119
+ process "multi_one", {}, "one" => "here", "two" => "there"
120
+ assert_equal "here:there", @response.body
121
+ end
122
+
123
+ def test_multi_one_without_prereqs
124
+ process "multi_one"
125
+ assert_redirected_to :action => "unguarded"
126
+ end
127
+
128
+ def test_multi_two_with_prereqs
129
+ process "multi_two", {}, "one" => "here", "two" => "there"
130
+ assert_equal "there:here", @response.body
131
+ end
132
+
133
+ def test_multi_two_without_prereqs
134
+ process "multi_two"
135
+ assert_redirected_to :action => "unguarded"
136
+ end
137
+ end
@@ -13,6 +13,22 @@ class DateHelperTest < Test::Unit::TestCase
13
13
  assert_equal "about 3 hours", distance_of_time_in_words(from, Time.mktime(2004, 3, 7, 0, 41))
14
14
  assert_equal "about 4 hours", distance_of_time_in_words(from, Time.mktime(2004, 3, 7, 1, 20))
15
15
  assert_equal "2 days", distance_of_time_in_words(from, Time.mktime(2004, 3, 9, 15, 40))
16
+
17
+ # include seconds
18
+ assert_equal "less than a minute", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 41, 19), false)
19
+ assert_equal "less than 5 seconds", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 41, 19), true)
20
+ assert_equal "less than 10 seconds", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 41, 28), true)
21
+ assert_equal "less than 20 seconds", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 41, 38), true)
22
+ assert_equal "half a minute", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 41, 48), true)
23
+ assert_equal "less than a minute", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 42, 17), true)
24
+
25
+ assert_equal "1 minute", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 42, 18), true)
26
+ assert_equal "1 minute", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 42, 28), true)
27
+ assert_equal "2 minutes", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 42, 48), true)
28
+
29
+ # test to < from
30
+ assert_equal "about 4 hours", distance_of_time_in_words(Time.mktime(2004, 3, 7, 1, 20), from)
31
+ assert_equal "less than 20 seconds", distance_of_time_in_words(Time.mktime(2004, 3, 6, 21, 41, 38), from, true)
16
32
  end
17
33
 
18
34
  def test_select_day
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/../abstract_unit'
2
+
3
+ class JavascriptHelperTest < Test::Unit::TestCase
4
+ include ActionView::Helpers::JavascriptHelper
5
+
6
+ def test_escape_javascript
7
+ assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
8
+ end
9
+ end
@@ -1,5 +1,6 @@
1
1
  require 'test/unit'
2
2
  require File.dirname(__FILE__) + '/../../lib/action_view/helpers/text_helper'
3
+ require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/numeric' # for human_size
3
4
 
4
5
  class TextHelperTest < Test::Unit::TestCase
5
6
  include ActionView::Helpers::TextHelper
@@ -52,6 +53,22 @@ class TextHelperTest < Test::Unit::TestCase
52
53
  highlight("This is a beautiful? morning", "beautiful? morning")
53
54
  )
54
55
  end
56
+
57
+ def test_human_size
58
+ assert_equal("0 Bytes", human_size(0))
59
+ assert_equal("3 Bytes", human_size(3.14159265))
60
+ assert_equal("123 Bytes", human_size(123.0))
61
+ assert_equal("123 Bytes", human_size(123))
62
+ assert_equal("1.2 KB", human_size(1234))
63
+ assert_equal("12.1 KB", human_size(12345))
64
+ assert_equal("1.2 MB", human_size(1234567))
65
+ assert_equal("1.1 GB", human_size(1234567890))
66
+ assert_equal("1.1 TB", human_size(1234567890123))
67
+ assert_equal("444.0 KB", human_size(444.kilobytes))
68
+ assert_equal("1023.0 MB", human_size(1023.megabytes))
69
+ assert_equal("3.0 TB", human_size(3.terabytes))
70
+ assert_nil human_size('x')
71
+ end
55
72
 
56
73
  def test_excerpt
57
74
  assert_equal("...is a beautiful morni...", excerpt("This is a beautiful morning", "beautiful", 5))
@@ -72,4 +89,5 @@ class TextHelperTest < Test::Unit::TestCase
72
89
  assert_equal %(Go to http://www.rubyonrails.com), auto_link("Go to http://www.rubyonrails.com", :email_addresses)
73
90
  assert_equal %(Go to <a href="http://www.rubyonrails.com">http://www.rubyonrails.com</a> and say hello to <a href="mailto:david@loudthinking.com">david@loudthinking.com</a>), auto_link("Go to http://www.rubyonrails.com and say hello to david@loudthinking.com")
74
91
  end
92
+
75
93
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.8
3
3
  specification_version: 1
4
4
  name: actionpack
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.6.0
7
- date: 2005-03-22
6
+ version: 1.7.0
7
+ date: 2005-03-27
8
8
  summary: Web-flow and rendering framework putting the VC in MVC.
9
9
  require_paths:
10
10
  - lib
@@ -64,6 +64,7 @@ files:
64
64
  - lib/action_controller/templates
65
65
  - lib/action_controller/test_process.rb
66
66
  - lib/action_controller/url_rewriter.rb
67
+ - lib/action_controller/verification.rb
67
68
  - lib/action_controller/assertions/action_pack_assertions.rb
68
69
  - lib/action_controller/assertions/active_record_assertions.rb
69
70
  - lib/action_controller/cgi_ext/cgi_ext.rb
@@ -136,7 +137,8 @@ files:
136
137
  - test/controller/request_test.rb
137
138
  - test/controller/routing_tests.rb
138
139
  - test/controller/send_file_test.rb
139
- - test/controller/url_obsolete.rb
140
+ - test/controller/test_test.rb
141
+ - test/controller/verification_test.rb
140
142
  - test/fixtures/fun
141
143
  - test/fixtures/helpers
142
144
  - test/fixtures/layouts
@@ -163,6 +165,7 @@ files:
163
165
  - test/template/form_helper_test.rb
164
166
  - test/template/form_options_helper_test.rb
165
167
  - test/template/form_tag_helper_test.rb
168
+ - test/template/javascript_helper.rb
166
169
  - test/template/tag_helper_test.rb
167
170
  - test/template/text_helper_test.rb
168
171
  - test/template/url_helper_test.rb
@@ -197,5 +200,5 @@ dependencies:
197
200
  -
198
201
  - "="
199
202
  - !ruby/object:Gem::Version
200
- version: 1.0.2
203
+ version: 1.0.3
201
204
  version:
@@ -1,487 +0,0 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
2
- require 'action_controller/url_rewriter'
3
-
4
- MockRequest = Struct.new("MockRequest", :protocol, :host, :port, :path, :parameters, :path_parameters)
5
- class MockRequest
6
- def host_with_port
7
- if (protocol == "http://" && port == 80) || (protocol == "https://" && port == 443)
8
- host
9
- else
10
- host + ":#{port}"
11
- end
12
- end
13
- end
14
-
15
- class UrlMockFactory
16
- def self.create(path, parameters)
17
- ActionController::UrlRewriter.new(
18
- MockRequest.new("http://", "example.com", 80, path, parameters),
19
- parameters
20
- )
21
- end
22
- end
23
-
24
- # old-style support for .new
25
- module ActionController
26
- class UrlRewriter
27
- def self.old_new(request, controller, action)
28
- request.parameters[:controller] = controller
29
- request.parameters[:action] = action
30
- return new(request, request.parameters)
31
- end
32
- end
33
- end
34
- class UrlTest < Test::Unit::TestCase
35
- def setup
36
- @library_url = ActionController::UrlRewriter.old_new(MockRequest.new(
37
- "http://",
38
- "www.singlefile.com",
39
- 80,
40
- "/library/books/ISBN/0743536703/show",
41
- { "type" => "ISBN", "code" => "0743536703" }
42
- ), "books", "show")
43
-
44
- @library_url_using_module = ActionController::UrlRewriter.old_new(MockRequest.new(
45
- "http://",
46
- "www.singlefile.com",
47
- 80,
48
- "/library/books/ISBN/0743536703/show",
49
- { "type" => "ISBN", "code" => "0743536703", "module" => "library" }
50
- ), "books", "show")
51
-
52
- @library_url_on_index = ActionController::UrlRewriter.old_new(MockRequest.new(
53
- "http://",
54
- "www.singlefile.com",
55
- 80,
56
- "/library/books/ISBN/0743536703/",
57
- { "type" => "ISBN", "code" => "0743536703" }
58
- ), "books", "index")
59
-
60
- @clean_urls = [
61
- ActionController::UrlRewriter.old_new(MockRequest.new(
62
- "http://", "www.singlefile.com", 80, "/identity/", {}
63
- ), "identity", "index"),
64
- ActionController::UrlRewriter.old_new(MockRequest.new(
65
- "http://", "www.singlefile.com", 80, "/identity", {}
66
- ), "identity", "index")
67
- ]
68
-
69
- @clean_url_with_id = ActionController::UrlRewriter.old_new(MockRequest.new(
70
- "http://", "www.singlefile.com", 80, "/identity/show/5", { "id" => "5" }
71
- ), "identity", "show")
72
-
73
- @clean_url_with_same_action_and_controller_name = ActionController::UrlRewriter.old_new(MockRequest.new(
74
- "http://", "www.singlefile.com", 80, "/login/login", { }
75
- ), "login", "login")
76
-
77
- @clean_url_with_same_action_and_controller_and_module_name = ActionController::UrlRewriter.old_new(MockRequest.new(
78
- "http://", "www.singlefile.com", 80, "/login/login/login", { "module" => "login" }
79
- ), "login", "login")
80
-
81
- @clean_url_with_id_as_char = ActionController::UrlRewriter.old_new(MockRequest.new(
82
- "http://", "www.singlefile.com", 80, "/teachers/show/t", { "id" => "t" }
83
- ), "teachers", "show")
84
- end
85
-
86
- def test_clean_action
87
- assert_equal "http://www.singlefile.com/library/books/ISBN/0743536703/edit", @library_url.rewrite(:action => "edit")
88
- end
89
-
90
- def test_clean_action_to_another_host
91
- assert_equal(
92
- "http://www.booksphere.com/library/books/ISBN/0743536703/edit",
93
- @library_url.rewrite(:action => "edit", :host => "www.booksphere.com")
94
- )
95
- end
96
-
97
- def test_clean_action_to_another_host_and_protocol
98
- assert_equal(
99
- "https://www.booksphere.com/library/books/ISBN/0743536703/edit",
100
- @library_url.rewrite(:action => "edit", :host => "www.booksphere.com", :protocol => "https://")
101
- )
102
- end
103
-
104
- def test_clean_action_with_only_path
105
- assert_equal "/library/books/ISBN/0743536703/edit", @library_url.rewrite(:action => "edit", :only_path => true)
106
- end
107
-
108
- def test_action_from_index
109
- assert_equal "http://www.singlefile.com/library/books/ISBN/0743536703/edit", @library_url_on_index.rewrite(:action => "edit")
110
- end
111
-
112
- def test_action_from_index_on_clean
113
- @clean_urls.each do |url|
114
- assert_equal "http://www.singlefile.com/identity/edit", url.rewrite(:action => "edit")
115
- end
116
- end
117
-
118
- def test_action_without_prefix
119
- assert_equal "http://www.singlefile.com/library/books/", @library_url.rewrite(:action => "index", :action_prefix => "")
120
- end
121
-
122
- def test_action_with_prefix
123
- assert_equal(
124
- "http://www.singlefile.com/library/books/XTC/123/show",
125
- @library_url.rewrite(:action => "show", :action_prefix => "XTC/123")
126
- )
127
- end
128
-
129
- def test_action_prefix_alone
130
- assert_equal(
131
- "http://www.singlefile.com/library/books/XTC/123/",
132
- @library_url.rewrite(:action_prefix => "XTC/123")
133
- )
134
- end
135
-
136
- def test_action_with_suffix
137
- assert_equal(
138
- "http://www.singlefile.com/library/books/show/XTC/123",
139
- @library_url.rewrite(:action => "show", :action_prefix => "", :action_suffix => "XTC/123")
140
- )
141
- end
142
-
143
- def test_clean_controller
144
- assert_equal "http://www.singlefile.com/library/settings/", @library_url.rewrite(:controller => "settings")
145
- end
146
-
147
- def test_clean_controller_prefix
148
- assert_equal "http://www.singlefile.com/shop/", @library_url.rewrite(:controller_prefix => "shop")
149
- end
150
-
151
- def test_clean_controller_with_module
152
- assert_equal "http://www.singlefile.com/shop/purchases/", @library_url.rewrite(:module => "shop", :controller => "purchases")
153
- end
154
-
155
- def test_getting_out_of_a_module
156
- assert_equal "http://www.singlefile.com/purchases/", @library_url_using_module.rewrite(:module => false, :controller => "purchases")
157
- end
158
-
159
- def test_controller_and_action
160
- assert_equal "http://www.singlefile.com/library/settings/show", @library_url.rewrite(:controller => "settings", :action => "show")
161
- end
162
-
163
- def test_controller_and_action_and_anchor
164
- assert_equal(
165
- "http://www.singlefile.com/library/settings/show#5",
166
- @library_url.rewrite(:controller => "settings", :action => "show", :anchor => "5")
167
- )
168
- end
169
-
170
- def test_controller_and_action_and_empty_overwrite_params_and_anchor
171
- assert_equal(
172
- "http://www.singlefile.com/library/settings/show?code=0743536703&type=ISBN#5",
173
- @library_url.rewrite(:controller => "settings", :action => "show", :overwrite_params => {}, :anchor => "5")
174
- )
175
- end
176
-
177
- def test_controller_and_action_and_overwrite_params_and_anchor
178
- assert_equal(
179
- "http://www.singlefile.com/library/settings/show?code=0000001&type=ISBN#5",
180
- @library_url.rewrite(:controller => "settings", :action => "show", :overwrite_params => {"code"=>"0000001"}, :anchor => "5")
181
- )
182
- end
183
-
184
- def test_controller_and_action_and_overwrite_params_with_nil_value_and_anchor
185
- assert_equal(
186
- "http://www.singlefile.com/library/settings/show?type=ISBN#5",
187
- @library_url.rewrite(:controller => "settings", :action => "show", :overwrite_params => {"code" => nil}, :anchor => "5")
188
- )
189
- end
190
-
191
- def test_controller_and_action_params_and_overwrite_params_and_anchor
192
- assert_equal(
193
- "http://www.singlefile.com/library/settings/show?code=0000001&version=5.0#5",
194
- @library_url.rewrite(:controller => "settings", :action => "show", :params=>{"version" => "5.0"}, :overwrite_params => {"code"=>"0000001"}, :anchor => "5")
195
- )
196
- end
197
-
198
- def test_controller_and_action_and_params_anchor
199
- assert_equal(
200
- "http://www.singlefile.com/library/settings/show?update=1#5",
201
- @library_url.rewrite(:controller => "settings", :action => "show", :params => { "update" => "1"}, :anchor => "5")
202
- )
203
- end
204
-
205
- def test_controller_and_index_action
206
- assert_equal "http://www.singlefile.com/library/settings/", @library_url.rewrite(:controller => "settings", :action => "index")
207
- end
208
-
209
- def test_same_controller_and_action_names
210
- assert_equal "http://www.singlefile.com/login/logout", @clean_url_with_same_action_and_controller_name.rewrite(:action => "logout")
211
- end
212
-
213
- def xtest_same_module_and_controller_and_action_names
214
- assert_equal "http://www.singlefile.com/login/login/logout", @clean_url_with_same_action_and_controller_and_module_name.rewrite(:action => "logout")
215
- end
216
-
217
- def test_controller_and_action_with_same_name_as_controller
218
- @clean_urls.each do |url|
219
- assert_equal "http://www.singlefile.com/anything/identity", url.rewrite(:controller => "anything", :action => "identity")
220
- end
221
- end
222
-
223
- def test_controller_and_index_action_without_controller_prefix
224
- assert_equal(
225
- "http://www.singlefile.com/settings/",
226
- @library_url.rewrite(:controller => "settings", :action => "index", :controller_prefix => "")
227
- )
228
- end
229
-
230
- def test_controller_and_index_action_with_controller_prefix
231
- assert_equal(
232
- "http://www.singlefile.com/fantastic/settings/show",
233
- @library_url.rewrite(:controller => "settings", :action => "show", :controller_prefix => "fantastic")
234
- )
235
- end
236
-
237
- def test_path_parameters
238
- assert_equal "http://www.singlefile.com/library/books/EXBC/0743536703/show", @library_url.rewrite(:path_params => {"type" => "EXBC"})
239
- end
240
-
241
- def test_parameters
242
- assert_equal(
243
- "http://www.singlefile.com/library/books/ISBN/0743536703/show?delete=1&name=David",
244
- @library_url.rewrite(:params => {"delete" => "1", "name" => "David"})
245
- )
246
- end
247
-
248
- def test_parameters_with_id
249
- @clean_urls.each do |url|
250
- assert_equal(
251
- "http://www.singlefile.com/identity/show?name=David&id=5",
252
- url.rewrite(
253
- :action => "show",
254
- :params => { "id" => "5", "name" => "David" }
255
- )
256
- )
257
- end
258
- end
259
-
260
- def test_parameters_with_array
261
- @clean_urls.each do |url|
262
- assert_equal(
263
- "http://www.singlefile.com/identity/show?id[]=3&id[]=5&id[]=10",
264
- url.rewrite(
265
- :action => "show",
266
- :params => { 'id' => [ 3, 5, 10 ] } )
267
- )
268
- end
269
- end
270
-
271
- def test_action_with_id
272
- assert_equal(
273
- "http://www.singlefile.com/identity/show/7",
274
- @clean_url_with_id.rewrite(
275
- :action => "show",
276
- :id => 7
277
- )
278
- )
279
- @clean_urls.each do |url|
280
- assert_equal(
281
- "http://www.singlefile.com/identity/index/7",
282
- url.rewrite(:id => 7)
283
- )
284
- end
285
- end
286
-
287
- def test_parameters_with_id_and_away
288
- assert_equal(
289
- "http://www.singlefile.com/identity/show/25?name=David",
290
- @clean_url_with_id.rewrite(
291
- :path_params => { "id" => "25" },
292
- :params => { "name" => "David" }
293
- )
294
- )
295
- end
296
-
297
- def test_parameters_with_index_and_id
298
- @clean_urls.each do |url|
299
- assert_equal(
300
- "http://www.singlefile.com/identity/index/25?name=David",
301
- url.rewrite(
302
- :path_params => { "id" => "25" },
303
- :params => { "name" => "David" }
304
- )
305
- )
306
- end
307
- end
308
-
309
- def test_action_going_away_from_id
310
- assert_equal(
311
- "http://www.singlefile.com/identity/list",
312
- @clean_url_with_id.rewrite(
313
- :action => "list"
314
- )
315
- )
316
- end
317
-
318
- def test_parameters_with_direct_id_and_away
319
- assert_equal(
320
- "http://www.singlefile.com/identity/show/25?name=David",
321
- @clean_url_with_id.rewrite(
322
- :id => "25",
323
- :params => { "name" => "David" }
324
- )
325
- )
326
- end
327
-
328
- def test_parameters_with_direct_id_and_away
329
- assert_equal(
330
- "http://www.singlefile.com/store/open/25?name=David",
331
- @clean_url_with_id.rewrite(
332
- :controller => "store",
333
- :action => "open",
334
- :id => "25",
335
- :params => { "name" => "David" }
336
- )
337
- )
338
- end
339
-
340
- def test_parameters_to_id
341
- @clean_urls.each do |url|
342
- %w(show index).each do |action|
343
- assert_equal(
344
- "http://www.singlefile.com/identity/#{action}/25?name=David",
345
- url.rewrite(
346
- :action => action,
347
- :path_params => { "id" => "25" },
348
- :params => { "name" => "David" }
349
- )
350
- )
351
- end
352
- end
353
- end
354
-
355
- def test_parameters_from_id
356
- assert_equal(
357
- "http://www.singlefile.com/identity/",
358
- @clean_url_with_id.rewrite(
359
- :action => "index"
360
- )
361
- )
362
- end
363
-
364
- def test_id_as_char_and_part_of_controller
365
- assert_equal(
366
- "http://www.singlefile.com/teachers/skill/5",
367
- @clean_url_with_id_as_char.rewrite(
368
- :action => "skill",
369
- :id => 5
370
- )
371
- )
372
- end
373
-
374
- def test_from_clean_to_library
375
- @clean_urls.each do |url|
376
- assert_equal(
377
- "http://www.singlefile.com/library/books/ISBN/0743536703/show?delete=1&name=David",
378
- url.rewrite(
379
- :controller_prefix => "library",
380
- :controller => "books",
381
- :action_prefix => "ISBN/0743536703",
382
- :action => "show",
383
- :params => { "delete" => "1", "name" => "David" }
384
- )
385
- )
386
- end
387
- end
388
-
389
- def test_from_library_to_clean
390
- assert_equal(
391
- "http://www.singlefile.com/identity/",
392
- @library_url.rewrite(
393
- :controller => "identity", :controller_prefix => ""
394
- )
395
- )
396
- end
397
-
398
- def test_from_another_port
399
- @library_url = ActionController::UrlRewriter.old_new(MockRequest.new(
400
- "http://",
401
- "www.singlefile.com",
402
- 8080,
403
- "/library/books/ISBN/0743536703/show",
404
- { "type" => "ISBN", "code" => "0743536703" }
405
- ), "books", "show")
406
-
407
- assert_equal(
408
- "http://www.singlefile.com:8080/identity/",
409
- @library_url.rewrite(
410
- :controller => "identity", :controller_prefix => ""
411
- )
412
- )
413
- end
414
-
415
- def test_basecamp
416
- basecamp_url = ActionController::UrlRewriter.old_new(MockRequest.new(
417
- "http://",
418
- "projects.basecamp",
419
- 80,
420
- "/clients/disarray/1/msg/transcripts/",
421
- {"category_name"=>"transcripts", "client_name"=>"disarray", "action"=>"index", "controller"=>"msg", "project_name"=>"1"}
422
- ), "msg", "index")
423
-
424
- assert_equal(
425
- "http://projects.basecamp/clients/disarray/1/msg/transcripts/1/comments",
426
- basecamp_url.rewrite(:action_prefix => "transcripts/1", :action => "comments")
427
- )
428
- end
429
-
430
- def test_on_explicit_index_page # My index page is very modest, thank you...
431
- url = ActionController::UrlRewriter.old_new(
432
- MockRequest.new(
433
- "http://", "example.com", 80, "/controller/index",
434
- {"controller"=>"controller", "action"=>"index"}
435
- ), "controller", "index"
436
- )
437
- assert_equal("http://example.com/controller/foo", url.rewrite(:action => 'foo'))
438
- end
439
-
440
- def test_rewriting_on_similar_fragments
441
- url = UrlMockFactory.create("/advertisements/advert/", {"controller"=>"advert", "action"=>"index"})
442
- assert_equal("http://example.com/advertisements/advert/news", url.rewrite(:action => 'news'))
443
- end
444
-
445
- def test_rewriting_on_similar_fragments_with_action_prefixes
446
- url = UrlMockFactory.create(
447
- "/clients/prall/1/msg/all/",
448
- { "category_name"=>"all", "client_name"=>"prall", "action"=>"index", "controller"=>"msg", "project_name"=>"1"}
449
- )
450
-
451
- assert_equal(
452
- "http://example.com/clients/prall/1/msg/all/new",
453
- url.rewrite({ :controller => "msg", :action_prefix => "all", :action => "new" })
454
- )
455
-
456
- url = UrlMockFactory.create(
457
- "/clients/prall/1/msg/all/",
458
- { "category_name"=>"all", "client_name"=>"prall", "action"=>"index", "controller"=>"msg", "project_name"=>"1"}
459
- )
460
-
461
- assert_equal(
462
- "http://example.com/clients/prall/1/msg/allous/new",
463
- url.rewrite({ :controller => "msg", :action_prefix => "allous", :action => "new" })
464
- )
465
- end
466
-
467
- def test_clean_application_prefix
468
- assert_equal "http://www.singlefile.com/namespace/library/books/ISBN/0743536703/show",
469
- @library_url.rewrite(:application_prefix => "/namespace")
470
- end
471
-
472
- def test_clean_application_prefix_with_controller_prefix
473
- assert_equal "http://www.singlefile.com/namespace/shop/",
474
- @library_url.rewrite(:application_prefix => "/namespace",
475
- :controller_prefix => "shop" )
476
- end
477
-
478
- def test_blank_application_prefix
479
- assert_equal "http://www.singlefile.com/library/books/ISBN/0743536703/show",
480
- @library_url.rewrite(:application_prefix => "")
481
- end
482
-
483
- def test_nil_application_prefix
484
- assert_equal "http://www.singlefile.com/library/books/ISBN/0743536703/show",
485
- @library_url.rewrite(:application_prefix => nil)
486
- end
487
- end