actionpack 0.9.0 → 0.9.5

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.

Files changed (37) hide show
  1. data/CHANGELOG +88 -0
  2. data/README +2 -2
  3. data/RUNNING_UNIT_TESTS +12 -1
  4. data/install.rb +7 -3
  5. data/lib/action_controller.rb +2 -0
  6. data/lib/action_controller/assertions/action_pack_assertions.rb +39 -6
  7. data/lib/action_controller/base.rb +82 -49
  8. data/lib/action_controller/cgi_process.rb +3 -2
  9. data/lib/action_controller/helpers.rb +89 -0
  10. data/lib/action_controller/layout.rb +9 -3
  11. data/lib/action_controller/request.rb +7 -2
  12. data/lib/action_controller/response.rb +2 -2
  13. data/lib/action_controller/support/class_inheritable_attributes.rb +1 -1
  14. data/lib/action_controller/support/inflector.rb +8 -0
  15. data/lib/action_controller/test_process.rb +3 -2
  16. data/lib/action_controller/url_rewriter.rb +27 -11
  17. data/lib/action_view/base.rb +11 -0
  18. data/lib/action_view/helpers/active_record_helper.rb +5 -5
  19. data/lib/action_view/helpers/date_helper.rb +8 -1
  20. data/lib/action_view/helpers/form_helper.rb +12 -6
  21. data/lib/action_view/helpers/form_options_helper.rb +44 -1
  22. data/lib/action_view/helpers/text_helper.rb +13 -31
  23. data/lib/action_view/helpers/url_helper.rb +11 -5
  24. data/lib/action_view/partials.rb +5 -2
  25. data/rakefile +12 -3
  26. data/test/controller/action_pack_assertions_test.rb +30 -2
  27. data/test/controller/active_record_assertions_test.rb +2 -1
  28. data/test/controller/helper_test.rb +110 -0
  29. data/test/controller/send_file_test.rb +68 -0
  30. data/test/controller/url_test.rb +81 -35
  31. data/test/fixtures/helpers/abc_helper.rb +5 -0
  32. data/test/template/active_record_helper_test.rb +3 -3
  33. data/test/template/date_helper_test.rb +1 -0
  34. data/test/template/form_helper_test.rb +13 -6
  35. data/test/template/form_options_helper_test.rb +1 -1
  36. data/test/template/url_helper_test.rb +18 -4
  37. metadata +7 -2
@@ -1,35 +1,5 @@
1
1
  module ActionView
2
- # The template helpers serves to relieve the templates from including the same inline code again and again. It's a
3
- # set of standardized methods for working with forms (FormHelper), dates (DateHelper), texts (TextHelper), and
4
- # Active Records (ActiveRecordHelper) that's available to all templates by default.
5
- #
6
- # It's also really easy to make your own helpers and it's much encouraged to keep the template files free
7
- # from complicated logic. It's even encouraged to bundle common compositions of methods from other helpers
8
- # (often the common helpers) as they're used by the specific application.
9
- #
10
- # Defining a helper requires you to include a specialized +append_features+ method that makes them capable
11
- # of configuring their integration upon inclusion in a controller, like this:
12
- #
13
- # module MyHelper
14
- # def self.append_features(controller)
15
- # controller.ancestors.include?(ActionController::Base) ?
16
- # controller.add_template_helper(self) : super
17
- # end
18
- #
19
- # def hello_world() "hello world" end
20
- # end
21
- #
22
- # MyHelper can now be included in a controller, like this:
23
- #
24
- # require 'my_helper'
25
- # class MyController < ActionController::Base
26
- # include MyHelper
27
- # end
28
- #
29
- # ...and, same as above, used in any template rendered from MyController, like this:
30
- #
31
- # Let's hear what the helper has to say: <tt><%= hello_world %></tt>
32
- module Helpers
2
+ module Helpers #:nodoc:
33
3
  # Provides a set of methods for working with text strings that can help unburden the level of inline Ruby code in the
34
4
  # templates. In the example below we iterate over a collection of posts provided to the template and prints each title
35
5
  # after making sure it doesn't run longer than 20 characters:
@@ -114,6 +84,18 @@ module ActionView
114
84
  # We can't really help what's not there
115
85
  end
116
86
 
87
+ begin
88
+ require "bluecloth"
89
+
90
+ # Returns the text with all the Markdown codes turned into HTML-tags.
91
+ # <i>This method is only available if BlueCloth can be required</i>.
92
+ def markdown(text)
93
+ BlueCloth.new(text).to_html
94
+ end
95
+ rescue LoadError
96
+ # We can't really help what's not there
97
+ end
98
+
117
99
  # Turns all links into words, like "<a href="something">else</a>" to "else".
118
100
  def strip_links(text)
119
101
  text.gsub(/<a.*>(.*)<\/a>/m, '\1')
@@ -17,11 +17,11 @@ module ActionView
17
17
  # confirm alerts where if you pass :confirm => 'Are you sure?', the link will be guarded with a JS popup asking that question.
18
18
  # If the user accepts, the link is processed, otherwise not.
19
19
  def link_to(name, options = {}, html_options = {}, *parameters_for_method_reference)
20
+ convert_confirm_option_to_javascript!(html_options) unless html_options.nil?
20
21
  if options.is_a?(String)
21
- content_tag "a", name, "href" => options
22
+ content_tag "a", name, (html_options || {}).merge({ "href" => options })
22
23
  else
23
- convert_confirm_option_to_javascript!(html_options)
24
- content_tag("a", name, html_options.merge({ "href" => url_for(options, *parameters_for_method_reference) }))
24
+ content_tag("a", name, (html_options || {}).merge({ "href" => url_for(options, *parameters_for_method_reference) }))
25
25
  end
26
26
  end
27
27
 
@@ -41,6 +41,12 @@ module ActionView
41
41
  end
42
42
  end
43
43
 
44
+ # Creates a link tag for starting an email to the specified <tt>email_address</tt>, which is also used as the name of the
45
+ # link unless +name+ is specified. Additional HTML options, such as class or id, can be passed in the <tt>html_options</tt> hash.
46
+ def mail_to(email_address, name = nil, html_options = {})
47
+ content_tag "a", name || email_address, html_options.merge({ "href" => "mailto:#{email_address}" })
48
+ end
49
+
44
50
  private
45
51
  def destination_equal_to_current(options)
46
52
  params_without_location = @params.reject { |key, value| %w( controller action id ).include?(key) }
@@ -50,7 +56,7 @@ module ActionView
50
56
  options[:controller] == @params['controller'] &&
51
57
  (options.has_key?(:params) ? params_without_location == options[:params] : true)
52
58
  end
53
-
59
+
54
60
  def assume_current_url_options!(options)
55
61
  if options[:controller].nil?
56
62
  options[:controller] = @params['controller']
@@ -63,7 +69,7 @@ module ActionView
63
69
 
64
70
  def convert_confirm_option_to_javascript!(html_options)
65
71
  if html_options.include?(:confirm)
66
- html_options["onClick"] = "return confirm('#{html_options[:confirm]}');"
72
+ html_options["onclick"] = "return confirm('#{html_options[:confirm]}');"
67
73
  html_options.delete(:confirm)
68
74
  end
69
75
  end
@@ -44,9 +44,12 @@ module ActionView
44
44
  end
45
45
 
46
46
  return nil if collection_of_partials.empty?
47
- partial_spacer_template ?
48
- collection_of_partials.join(render("#{controller.send(:controller_name)}/_#{partial_spacer_template}")) :
47
+ if partial_spacer_template
48
+ spacer_path, spacer_name = partial_pieces(partial_spacer_template)
49
+ collection_of_partials.join(render("#{spacer_path}/_#{spacer_name}"))
50
+ else
49
51
  collection_of_partials
52
+ end
50
53
  end
51
54
 
52
55
  private
data/rakefile CHANGED
@@ -6,7 +6,10 @@ require 'rake/packagetask'
6
6
  require 'rake/gempackagetask'
7
7
  require 'rake/contrib/rubyforgepublisher'
8
8
 
9
- PKG_VERSION = "0.9.0"
9
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
10
+ PKG_NAME = 'actionpack'
11
+ PKG_VERSION = '0.9.5' + PKG_BUILD
12
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
10
13
 
11
14
  desc "Default Task"
12
15
  task :default => [ :test ]
@@ -38,10 +41,10 @@ dist_dirs = [ "lib", "test", "examples" ]
38
41
 
39
42
  spec = Gem::Specification.new do |s|
40
43
  s.platform = Gem::Platform::RUBY
41
- s.name = 'actionpack'
44
+ s.name = PKG_NAME
45
+ s.version = PKG_VERSION
42
46
  s.summary = "Web-flow and rendering framework putting the VC in MVC."
43
47
  s.description = %q{Eases web-request routing, handling, and response as a half-way front, half-way page controller. Implemented with specific emphasis on enabling easy unit/integration testing that doesn't require a browser.}
44
- s.version = PKG_VERSION
45
48
 
46
49
  s.author = "David Heinemeier Hansson"
47
50
  s.email = "david@loudthinking.com"
@@ -68,6 +71,12 @@ Rake::GemPackageTask.new(spec) do |p|
68
71
  end
69
72
 
70
73
 
74
+ # Publish beta gem
75
+ desc "Publish the API documentation"
76
+ task :pgem => [:package] do
77
+ Rake::SshFilePublisher.new("davidhh@one.textdrive.com", "domains/rubyonrails.org/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
78
+ end
79
+
71
80
  # Publish documentation
72
81
  desc "Publish the API documentation"
73
82
  task :pdoc => [:rdoc] do
@@ -146,7 +146,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
146
146
  # test the assert_rendered_file
147
147
  def test_assert_rendered_file
148
148
  process :hello_world
149
- assert_rendered_file 'test_request_response/hello_world'
149
+ assert_rendered_file 'test/hello_world'
150
150
  assert_rendered_file 'hello_world'
151
151
  assert_rendered_file
152
152
  end
@@ -163,6 +163,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
163
163
  def test_session_objects
164
164
  process :session_stuffing
165
165
  assert @response.has_session_object?('xmas')
166
+ assert_session_equal 'turkey', 'xmas'
166
167
  assert !@response.has_session_object?('easter')
167
168
  end
168
169
 
@@ -178,6 +179,11 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
178
179
  process :nothing
179
180
  assert_nil @response.template_objects['howdy']
180
181
  end
182
+
183
+ def test_assigned_equal
184
+ process :assign_this
185
+ assert_assigned_equal "ho", :howdy
186
+ end
181
187
 
182
188
  # check the empty flashing
183
189
  def test_flash_me_naked
@@ -202,6 +208,12 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
202
208
  assert_nil @response.flash['hello']
203
209
  end
204
210
 
211
+ # examine that the flash objects are what we expect
212
+ def test_flash_equals
213
+ process :flash_me
214
+ assert_flash_equal 'my name is inigo montoya...', 'hello'
215
+ end
216
+
205
217
 
206
218
  # check if we were rendered by a file-based template?
207
219
  def test_rendered_action
@@ -292,4 +304,20 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
292
304
  process :hello_xml_world
293
305
  assert_template_xpath_match('//p', %w( abes monks wiseguys ))
294
306
  end
295
- end
307
+ end
308
+
309
+ class ActionPackHeaderTest < Test::Unit::TestCase
310
+ def setup
311
+ @controller = ActionPackAssertionsController.new
312
+ @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
313
+ end
314
+ def test_rendering_xml_sets_content_type
315
+ process :hello_xml_world
316
+ assert_equal('text/xml', @controller.headers['Content-Type'])
317
+ end
318
+ def test_rendering_xml_respects_content_type
319
+ @response.headers['Content-Type'] = 'application/pdf'
320
+ process :hello_xml_world
321
+ assert_equal('application/pdf', @controller.headers['Content-Type'])
322
+ end
323
+ end
@@ -4,7 +4,8 @@ if Object.const_defined?("ActiveRecord") || File.exist?(path_to_ar)
4
4
  # This test is very different than the others. It requires ActiveRecord to
5
5
  # run. There's a bunch of stuff we are assuming here:
6
6
  #
7
- # 1. active_record exists as a sibling directory to actionpack
7
+ # 1. activerecord exists as a sibling directory to actionpack
8
+ # (i.e., actionpack/../activerecord)
8
9
  # 2. you've created the appropriate database to run the active_record unit tests
9
10
  # 3. you set the appropriate database connection below
10
11
 
@@ -0,0 +1,110 @@
1
+ require File.dirname(__FILE__) + '/../abstract_unit'
2
+
3
+ class HelperTest < Test::Unit::TestCase
4
+ HELPER_PATHS = %w(/../fixtures/helpers)
5
+
6
+ class TestController < ActionController::Base
7
+ attr_accessor :delegate_attr
8
+ def delegate_method() end
9
+ def rescue_action(e) raise end
10
+ end
11
+
12
+ module LocalAbcHelper
13
+ def a() end
14
+ def b() end
15
+ def c() end
16
+ end
17
+
18
+
19
+ def setup
20
+ # Increment symbol counter.
21
+ @symbol = (@@counter ||= 'A0').succ!.dup
22
+
23
+ # Generate new controller class.
24
+ controller_class_name = "Helper#{@symbol}Controller"
25
+ eval("class #{controller_class_name} < TestController; end")
26
+ @controller_class = self.class.const_get(controller_class_name)
27
+
28
+ # Generate new template class and assign to controller.
29
+ template_class_name = "Test#{@symbol}View"
30
+ eval("class #{template_class_name} < ActionView::Base; end")
31
+ @template_class = self.class.const_get(template_class_name)
32
+ @controller_class.template_class = @template_class
33
+
34
+ # Add helper paths to LOAD_PATH.
35
+ HELPER_PATHS.each { |path|
36
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + path)
37
+ }
38
+
39
+ # Set default test helper.
40
+ self.test_helper = LocalAbcHelper
41
+ end
42
+
43
+ def teardown
44
+ # Reset template class.
45
+ #ActionController::Base.template_class = ActionView::Base
46
+
47
+ # Remove helper paths from LOAD_PATH.
48
+ HELPER_PATHS.each { |path|
49
+ $LOAD_PATH.delete(File.dirname(__FILE__) + path)
50
+ }
51
+ end
52
+
53
+
54
+ def test_deprecated_helper
55
+ assert_equal helper_methods, missing_methods
56
+ assert_nothing_raised { @controller_class.helper TestHelper }
57
+ assert_equal [], missing_methods
58
+ end
59
+
60
+ def test_declare_helper
61
+ require 'abc_helper'
62
+ self.test_helper = AbcHelper
63
+ assert_equal helper_methods, missing_methods
64
+ assert_nothing_raised { @controller_class.helper :abc }
65
+ assert_equal [], missing_methods
66
+ end
67
+
68
+ def test_declare_missing_helper
69
+ assert_equal helper_methods, missing_methods
70
+ assert_raise(ArgumentError) { @controller_class.helper :missing }
71
+ end
72
+
73
+ def test_helper_block
74
+ assert_nothing_raised {
75
+ @controller_class.helper { def block_helper_method; end }
76
+ }
77
+ assert template_methods.include?('block_helper_method')
78
+ end
79
+
80
+ def test_helper_block_include
81
+ assert_equal helper_methods, missing_methods
82
+ assert_nothing_raised {
83
+ @controller_class.helper { include TestHelper }
84
+ }
85
+ assert [], missing_methods
86
+ end
87
+
88
+ def test_helper_method
89
+ assert_nothing_raised { @controller_class.helper_method :delegate_method }
90
+ assert template_methods.include?('delegate_method')
91
+ end
92
+
93
+ def test_helper_attr
94
+ assert_nothing_raised { @controller_class.helper_attr :delegate_attr }
95
+ assert template_methods.include?('delegate_attr')
96
+ assert template_methods.include?('delegate_attr=')
97
+ end
98
+
99
+
100
+ private
101
+ def helper_methods; TestHelper.instance_methods end
102
+ def template_methods; @template_class.instance_methods end
103
+ def missing_methods; helper_methods - template_methods end
104
+
105
+ def test_helper=(helper_module)
106
+ old_verbose, $VERBOSE = $VERBOSE, nil
107
+ self.class.const_set('TestHelper', helper_module)
108
+ $VERBOSE = old_verbose
109
+ end
110
+ end
@@ -0,0 +1,68 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'abstract_unit')
2
+
3
+
4
+ module TestFileUtils
5
+ def file_name() File.basename(__FILE__) end
6
+ def file_path() File.expand_path(__FILE__) end
7
+ def file_data() File.open(file_path, 'rb') { |f| f.read } end
8
+ end
9
+
10
+
11
+ class SendFileController < ActionController::Base
12
+ include TestFileUtils
13
+
14
+ attr_writer :options
15
+ def options() @options ||= {} end
16
+
17
+ def file() send_file(file_path, options) end
18
+ def data() send_data(file_data, options) end
19
+
20
+ def rescue_action(e) raise end
21
+ end
22
+
23
+
24
+ class SendFileTest < Test::Unit::TestCase
25
+ include TestFileUtils
26
+
27
+ def setup
28
+ @controller = SendFileController.new
29
+ @request = ActionController::TestRequest.new
30
+ @response = ActionController::TestResponse.new
31
+ end
32
+
33
+ def test_file_nostream
34
+ @controller.options = { :stream => false }
35
+ response = nil
36
+ assert_nothing_raised { response = process('file') }
37
+ assert_not_nil response
38
+ assert_kind_of String, response.body
39
+ assert_equal file_data, response.body
40
+ end
41
+
42
+ def test_file_stream
43
+ response = nil
44
+ assert_nothing_raised { response = process('file') }
45
+ assert_not_nil response
46
+ assert_kind_of Proc, response.body
47
+
48
+ old_stdout = $stdout
49
+ begin
50
+ require 'stringio'
51
+ $stdout = StringIO.new
52
+ $stdout.binmode
53
+ assert_nothing_raised { response.body.call }
54
+ assert_equal file_data, $stdout.string
55
+ ensure
56
+ $stdout = old_stdout
57
+ end
58
+ end
59
+
60
+ def test_data
61
+ response = nil
62
+ assert_nothing_raised { response = process('data') }
63
+ assert_not_nil response
64
+
65
+ assert_kind_of String, response.body
66
+ assert_equal file_data, response.body
67
+ end
68
+ end
@@ -30,9 +30,14 @@ class UrlTest < Test::Unit::TestCase
30
30
  { "type" => "ISBN", "code" => "0743536703" }
31
31
  ), "books", "index")
32
32
 
33
- @clean_url = ActionController::UrlRewriter.new(MockRequest.new(
34
- "http://", "www.singlefile.com", 80, "/identity/", {}
35
- ), "identity", "index")
33
+ @clean_urls = [
34
+ ActionController::UrlRewriter.new(MockRequest.new(
35
+ "http://", "www.singlefile.com", 80, "/identity/", {}
36
+ ), "identity", "index"),
37
+ ActionController::UrlRewriter.new(MockRequest.new(
38
+ "http://", "www.singlefile.com", 80, "/identity", {}
39
+ ), "identity", "index")
40
+ ]
36
41
 
37
42
  @clean_url_with_id = ActionController::UrlRewriter.new(MockRequest.new(
38
43
  "http://", "www.singlefile.com", 80, "/identity/show/5", { "id" => "5" }
@@ -54,9 +59,11 @@ class UrlTest < Test::Unit::TestCase
54
59
  def test_action_from_index
55
60
  assert_equal "http://www.singlefile.com/library/books/ISBN/0743536703/edit", @library_url_on_index.rewrite(:action => "edit")
56
61
  end
57
-
62
+
58
63
  def test_action_from_index_on_clean
59
- assert_equal "http://www.singlefile.com/identity/edit", @clean_url.rewrite(:action => "edit")
64
+ @clean_urls.each do |url|
65
+ assert_equal "http://www.singlefile.com/identity/edit", url.rewrite(:action => "edit")
66
+ end
60
67
  end
61
68
 
62
69
  def test_action_without_prefix
@@ -127,7 +134,7 @@ class UrlTest < Test::Unit::TestCase
127
134
  def test_controller_and_action_params_and_overwrite_params_and_anchor
128
135
  assert_equal(
129
136
  "http://www.singlefile.com/library/settings/show?code=0000001&version=5.0#5",
130
- @library_url.rewrite(:controller => "settings", :action => "show", :params=>{"version" => "5.0" }, :overwrite_params => {"code"=>"0000001"}, :anchor => "5")
137
+ @library_url.rewrite(:controller => "settings", :action => "show", :params=>{"version" => "5.0"}, :overwrite_params => {"code"=>"0000001"}, :anchor => "5")
131
138
  )
132
139
  end
133
140
 
@@ -143,7 +150,9 @@ class UrlTest < Test::Unit::TestCase
143
150
  end
144
151
 
145
152
  def test_controller_and_action_with_same_name_as_controller
146
- assert_equal "http://www.singlefile.com/anything/identity", @clean_url.rewrite(:controller => "anything", :action => "identity")
153
+ @clean_urls.each do |url|
154
+ assert_equal "http://www.singlefile.com/anything/identity", url.rewrite(:controller => "anything", :action => "identity")
155
+ end
147
156
  end
148
157
 
149
158
  def test_controller_and_index_action_without_controller_prefix
@@ -172,13 +181,15 @@ class UrlTest < Test::Unit::TestCase
172
181
  end
173
182
 
174
183
  def test_parameters_with_id
175
- assert_equal(
176
- "http://www.singlefile.com/identity/show?name=David&id=5",
177
- @clean_url.rewrite(
178
- :action => "show",
179
- :params => {"id" => "5", "name" => "David"}
184
+ @clean_urls.each do |url|
185
+ assert_equal(
186
+ "http://www.singlefile.com/identity/show?name=David&id=5",
187
+ url.rewrite(
188
+ :action => "show",
189
+ :params => { "id" => "5", "name" => "David" }
190
+ )
180
191
  )
181
- )
192
+ end
182
193
  end
183
194
 
184
195
  def test_action_with_id
@@ -189,18 +200,36 @@ class UrlTest < Test::Unit::TestCase
189
200
  :id => 7
190
201
  )
191
202
  )
203
+ @clean_urls.each do |url|
204
+ assert_equal(
205
+ "http://www.singlefile.com/identity/index/7",
206
+ url.rewrite(:id => 7)
207
+ )
208
+ end
192
209
  end
193
210
 
194
211
  def test_parameters_with_id_and_away
195
212
  assert_equal(
196
213
  "http://www.singlefile.com/identity/show/25?name=David",
197
214
  @clean_url_with_id.rewrite(
198
- :path_params => {"id" => "25" },
199
- :params => { "name" => "David"}
215
+ :path_params => { "id" => "25" },
216
+ :params => { "name" => "David" }
200
217
  )
201
218
  )
202
219
  end
203
220
 
221
+ def test_parameters_with_index_and_id
222
+ @clean_urls.each do |url|
223
+ assert_equal(
224
+ "http://www.singlefile.com/identity/index/25?name=David",
225
+ url.rewrite(
226
+ :path_params => { "id" => "25" },
227
+ :params => { "name" => "David" }
228
+ )
229
+ )
230
+ end
231
+ end
232
+
204
233
  def test_action_going_away_from_id
205
234
  assert_equal(
206
235
  "http://www.singlefile.com/identity/list",
@@ -215,7 +244,7 @@ class UrlTest < Test::Unit::TestCase
215
244
  "http://www.singlefile.com/identity/show/25?name=David",
216
245
  @clean_url_with_id.rewrite(
217
246
  :id => "25",
218
- :params => { "name" => "David"}
247
+ :params => { "name" => "David" }
219
248
  )
220
249
  )
221
250
  end
@@ -227,20 +256,24 @@ class UrlTest < Test::Unit::TestCase
227
256
  :controller => "store",
228
257
  :action => "open",
229
258
  :id => "25",
230
- :params => { "name" => "David"}
259
+ :params => { "name" => "David" }
231
260
  )
232
261
  )
233
262
  end
234
263
 
235
264
  def test_parameters_to_id
236
- assert_equal(
237
- "http://www.singlefile.com/identity/show/25?name=David",
238
- @clean_url.rewrite(
239
- :action => "show",
240
- :path_params => {"id" => "25" },
241
- :params => { "name" => "David"}
242
- )
243
- )
265
+ @clean_urls.each do |url|
266
+ %w(show index).each do |action|
267
+ assert_equal(
268
+ "http://www.singlefile.com/identity/#{action}/25?name=David",
269
+ url.rewrite(
270
+ :action => action,
271
+ :path_params => { "id" => "25" },
272
+ :params => { "name" => "David" }
273
+ )
274
+ )
275
+ end
276
+ end
244
277
  end
245
278
 
246
279
  def test_parameters_from_id
@@ -262,17 +295,19 @@ class UrlTest < Test::Unit::TestCase
262
295
  )
263
296
  end
264
297
 
265
- def test_from_clean_to_libray
266
- assert_equal(
267
- "http://www.singlefile.com/library/books/ISBN/0743536703/show?delete=1&name=David",
268
- @clean_url.rewrite(
269
- :controller_prefix => "library",
270
- :controller => "books",
271
- :action_prefix => "ISBN/0743536703",
272
- :action => "show",
273
- :params => {"delete" => "1", "name" => "David"}
298
+ def test_from_clean_to_library
299
+ @clean_urls.each do |url|
300
+ assert_equal(
301
+ "http://www.singlefile.com/library/books/ISBN/0743536703/show?delete=1&name=David",
302
+ url.rewrite(
303
+ :controller_prefix => "library",
304
+ :controller => "books",
305
+ :action_prefix => "ISBN/0743536703",
306
+ :action => "show",
307
+ :params => { "delete" => "1", "name" => "David" }
308
+ )
274
309
  )
275
- )
310
+ end
276
311
  end
277
312
 
278
313
  def test_from_library_to_clean
@@ -315,4 +350,15 @@ class UrlTest < Test::Unit::TestCase
315
350
  basecamp_url.rewrite(:action_prefix => "transcripts/1", :action => "comments")
316
351
  )
317
352
  end
353
+
354
+ def test_on_explicit_index_page # My index page is very modest, thank you...
355
+ url = ActionController::UrlRewriter.new(
356
+ MockRequest.new(
357
+ "http://", "example.com", 80, "/controller/index",
358
+ {"controller"=>"controller", "action"=>"index"}
359
+ ), "controller", "index"
360
+ )
361
+ assert_equal("http://example.com/controller/foo", url.rewrite(:action => 'foo'))
362
+ end
363
+
318
364
  end