merb-core 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/LICENSE +1 -1
  2. data/README +3 -3
  3. data/Rakefile +144 -33
  4. data/bin/merb +0 -0
  5. data/bin/merb-specs +0 -0
  6. data/docs/bootloading.dox +1 -0
  7. data/docs/merb-core-call-stack-diagram.mmap +0 -0
  8. data/docs/merb-core-call-stack-diagram.pdf +0 -0
  9. data/docs/merb-core-call-stack-diagram.png +0 -0
  10. data/lib/merb-core.rb +159 -37
  11. data/lib/merb-core/autoload.rb +1 -0
  12. data/lib/merb-core/bootloader.rb +208 -92
  13. data/lib/merb-core/config.rb +20 -6
  14. data/lib/merb-core/controller/abstract_controller.rb +113 -61
  15. data/lib/merb-core/controller/exceptions.rb +28 -13
  16. data/lib/merb-core/controller/merb_controller.rb +73 -44
  17. data/lib/merb-core/controller/mime.rb +25 -7
  18. data/lib/merb-core/controller/mixins/authentication.rb +1 -1
  19. data/lib/merb-core/controller/mixins/controller.rb +44 -8
  20. data/lib/merb-core/controller/mixins/render.rb +191 -128
  21. data/lib/merb-core/controller/mixins/responder.rb +65 -63
  22. data/lib/merb-core/controller/template.rb +103 -54
  23. data/lib/merb-core/core_ext.rb +7 -12
  24. data/lib/merb-core/core_ext/kernel.rb +128 -136
  25. data/lib/merb-core/dispatch/cookies.rb +26 -4
  26. data/lib/merb-core/dispatch/default_exception/default_exception.rb +93 -0
  27. data/lib/merb-core/dispatch/default_exception/views/_css.html.erb +198 -0
  28. data/lib/merb-core/dispatch/default_exception/views/_javascript.html.erb +73 -0
  29. data/lib/merb-core/dispatch/default_exception/views/index.html.erb +92 -0
  30. data/lib/merb-core/dispatch/dispatcher.rb +156 -224
  31. data/lib/merb-core/dispatch/request.rb +126 -25
  32. data/lib/merb-core/dispatch/router.rb +61 -6
  33. data/lib/merb-core/dispatch/router/behavior.rb +122 -41
  34. data/lib/merb-core/dispatch/router/route.rb +147 -22
  35. data/lib/merb-core/dispatch/session.rb +52 -2
  36. data/lib/merb-core/dispatch/session/cookie.rb +4 -2
  37. data/lib/merb-core/dispatch/session/memcached.rb +38 -27
  38. data/lib/merb-core/dispatch/session/memory.rb +18 -11
  39. data/lib/merb-core/dispatch/worker.rb +28 -0
  40. data/lib/merb-core/gem_ext/erubis.rb +58 -0
  41. data/lib/merb-core/logger.rb +3 -31
  42. data/lib/merb-core/plugins.rb +25 -3
  43. data/lib/merb-core/rack.rb +18 -12
  44. data/lib/merb-core/rack/adapter.rb +10 -8
  45. data/lib/merb-core/rack/adapter/ebb.rb +2 -2
  46. data/lib/merb-core/rack/adapter/irb.rb +31 -21
  47. data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +26 -0
  48. data/lib/merb-core/rack/adapter/thin.rb +19 -9
  49. data/lib/merb-core/rack/adapter/thin_turbo.rb +24 -0
  50. data/lib/merb-core/rack/application.rb +9 -84
  51. data/lib/merb-core/rack/middleware.rb +26 -0
  52. data/lib/merb-core/rack/middleware/path_prefix.rb +31 -0
  53. data/lib/merb-core/rack/middleware/profiler.rb +19 -0
  54. data/lib/merb-core/rack/middleware/static.rb +45 -0
  55. data/lib/merb-core/server.rb +27 -9
  56. data/lib/merb-core/tasks/audit.rake +68 -0
  57. data/lib/merb-core/tasks/merb.rb +1 -0
  58. data/lib/merb-core/tasks/merb_rake_helper.rb +12 -0
  59. data/lib/merb-core/tasks/stats.rake +71 -0
  60. data/lib/merb-core/test.rb +2 -1
  61. data/lib/merb-core/test/helpers/multipart_request_helper.rb +3 -3
  62. data/lib/merb-core/test/helpers/request_helper.rb +66 -24
  63. data/lib/merb-core/test/matchers/controller_matchers.rb +36 -4
  64. data/lib/merb-core/test/matchers/route_matchers.rb +12 -3
  65. data/lib/merb-core/test/matchers/view_matchers.rb +3 -3
  66. data/lib/merb-core/test/run_specs.rb +1 -0
  67. data/lib/merb-core/test/tasks/spectasks.rb +13 -5
  68. data/lib/merb-core/test/test_ext/string.rb +14 -0
  69. data/lib/merb-core/vendor/facets/dictionary.rb +3 -3
  70. data/lib/merb-core/vendor/facets/inflect.rb +82 -37
  71. data/lib/merb-core/version.rb +2 -2
  72. data/spec/private/config/config_spec.rb +39 -4
  73. data/spec/private/core_ext/kernel_spec.rb +3 -14
  74. data/spec/private/dispatch/bootloader_spec.rb +1 -1
  75. data/spec/private/dispatch/cookies_spec.rb +181 -69
  76. data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +0 -2
  77. data/spec/private/dispatch/fixture/app/controllers/foo.rb +0 -2
  78. data/spec/private/dispatch/fixture/config/rack.rb +10 -0
  79. data/spec/private/dispatch/fixture/log/merb_test.log +7054 -1802
  80. data/spec/private/dispatch/route_params_spec.rb +2 -3
  81. data/spec/private/dispatch/session_mixin_spec.rb +47 -0
  82. data/spec/private/plugins/plugin_spec.rb +73 -59
  83. data/spec/private/router/behavior_spec.rb +60 -0
  84. data/spec/private/router/fixture/log/merb_test.log +1693 -0
  85. data/spec/private/router/route_spec.rb +414 -0
  86. data/spec/private/router/router_spec.rb +175 -0
  87. data/spec/private/vendor/facets/plural_spec.rb +564 -0
  88. data/spec/private/vendor/facets/singular_spec.rb +489 -0
  89. data/spec/public/abstract_controller/controllers/cousins.rb +41 -0
  90. data/spec/public/abstract_controller/controllers/helpers.rb +12 -2
  91. data/spec/public/abstract_controller/controllers/partial.rb +17 -2
  92. data/spec/public/abstract_controller/controllers/render.rb +16 -1
  93. data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +1 -0
  94. data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +1 -0
  95. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +1 -0
  96. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +1 -0
  97. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +1 -0
  98. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +1 -0
  99. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +1 -0
  100. data/spec/public/abstract_controller/filter_spec.rb +20 -1
  101. data/spec/public/abstract_controller/helper_spec.rb +10 -2
  102. data/spec/public/abstract_controller/partial_spec.rb +8 -0
  103. data/spec/public/abstract_controller/render_spec.rb +8 -0
  104. data/spec/public/abstract_controller/spec_helper.rb +7 -3
  105. data/spec/public/boot_loader/boot_loader_spec.rb +2 -2
  106. data/spec/public/controller/base_spec.rb +10 -2
  107. data/spec/public/controller/config/init.rb +6 -0
  108. data/spec/public/controller/controllers/authentication.rb +9 -11
  109. data/spec/public/controller/controllers/base.rb +2 -8
  110. data/spec/public/controller/controllers/cookies.rb +16 -0
  111. data/spec/public/controller/controllers/dispatcher.rb +35 -0
  112. data/spec/public/controller/controllers/display.rb +62 -14
  113. data/spec/public/controller/controllers/redirect.rb +36 -0
  114. data/spec/public/controller/controllers/responder.rb +37 -11
  115. data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +1 -0
  116. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +1 -0
  117. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +1 -0
  118. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +1 -0
  119. data/spec/public/controller/cookies_spec.rb +23 -0
  120. data/spec/public/controller/dispatcher_spec.rb +411 -0
  121. data/spec/public/controller/display_spec.rb +43 -10
  122. data/spec/public/controller/redirect_spec.rb +33 -0
  123. data/spec/public/controller/responder_spec.rb +79 -11
  124. data/spec/public/controller/spec_helper.rb +3 -1
  125. data/spec/public/controller/url_spec.rb +10 -0
  126. data/spec/public/core/merb_core_spec.rb +11 -0
  127. data/spec/public/core_ext/fixtures/core_ext_dependency.rb +2 -0
  128. data/spec/public/core_ext/kernel_spec.rb +9 -0
  129. data/spec/public/core_ext/spec_helper.rb +1 -0
  130. data/spec/public/directory_structure/directory/log/merb_test.log +3729 -272
  131. data/spec/public/directory_structure/directory_spec.rb +3 -4
  132. data/spec/public/logger/logger_spec.rb +4 -4
  133. data/spec/public/reloading/directory/log/merb_test.log +288066 -15
  134. data/spec/public/reloading/reload_spec.rb +49 -27
  135. data/spec/public/request/multipart_spec.rb +26 -0
  136. data/spec/public/request/request_spec.rb +21 -2
  137. data/spec/public/router/fixation_spec.rb +27 -0
  138. data/spec/public/router/fixture/log/merb_test.log +30050 -0
  139. data/spec/public/router/nested_matches_spec.rb +97 -0
  140. data/spec/public/router/resource_spec.rb +1 -9
  141. data/spec/public/router/resources_spec.rb +0 -20
  142. data/spec/public/router/spec_helper.rb +27 -9
  143. data/spec/public/router/special_spec.rb +21 -8
  144. data/spec/public/template/template_spec.rb +17 -5
  145. data/spec/public/test/controller_matchers_spec.rb +10 -0
  146. data/spec/public/test/request_helper_spec.rb +29 -0
  147. data/spec/public/test/route_helper_spec.rb +18 -1
  148. data/spec/public/test/route_matchers_spec.rb +28 -1
  149. data/spec/public/test/view_matchers_spec.rb +3 -3
  150. data/spec/spec_helper.rb +56 -12
  151. metadata +89 -47
  152. data/lib/merb-core/core_ext/class.rb +0 -299
  153. data/lib/merb-core/core_ext/hash.rb +0 -426
  154. data/lib/merb-core/core_ext/mash.rb +0 -154
  155. data/lib/merb-core/core_ext/object.rb +0 -147
  156. data/lib/merb-core/core_ext/object_space.rb +0 -14
  157. data/lib/merb-core/core_ext/rubygems.rb +0 -28
  158. data/lib/merb-core/core_ext/set.rb +0 -46
  159. data/lib/merb-core/core_ext/string.rb +0 -89
  160. data/lib/merb-core/core_ext/time.rb +0 -13
  161. data/lib/merb-core/dispatch/exceptions.html.erb +0 -297
  162. data/spec/private/core_ext/class_spec.rb +0 -22
  163. data/spec/private/core_ext/hash_spec.rb +0 -522
  164. data/spec/private/core_ext/object_spec.rb +0 -121
  165. data/spec/private/core_ext/set_spec.rb +0 -26
  166. data/spec/private/core_ext/string_spec.rb +0 -167
  167. data/spec/private/core_ext/time_spec.rb +0 -16
  168. data/spec/private/dispatch/dispatch_spec.rb +0 -26
  169. data/spec/private/dispatch/fixture/log/development.log +0 -1
  170. data/spec/private/dispatch/fixture/log/merb.4000.pid +0 -1
  171. data/spec/private/dispatch/fixture/log/production.log +0 -1
  172. data/spec/private/dispatch/fixture/merb.4000.pid +0 -1
  173. data/spec/private/rack/application_spec.rb +0 -43
  174. data/spec/public/controller/log/merb.4000.pid +0 -1
  175. data/spec/public/directory_structure/directory/log/merb.4000.pid +0 -1
  176. data/spec/public/directory_structure/directory/merb.4000.pid +0 -1
  177. data/spec/public/reloading/directory/log/merb.4000.pid +0 -1
  178. data/spec/public/reloading/directory/merb.4000.pid +0 -1
@@ -0,0 +1,97 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe "A route derived from the blocks of #match" do
4
+
5
+ it "should inherit the :controller option." do
6
+ Merb::Router.prepare do |r|
7
+ r.match('/alpha', :controller=>'Alphas') do |alpha|
8
+ alpha.match('').to(:action=>'normal')
9
+ end
10
+ end
11
+ route_to('/alpha').should have_route(:controller=>'Alphas',:action=>'normal')
12
+ end
13
+
14
+ it "should inherit the :action option." do
15
+ Merb::Router.prepare do |r|
16
+ r.match('/alpha', :action=>'wierd') do |alpha|
17
+ alpha.match('').to(:controller=>'Alphas')
18
+ end
19
+ end
20
+ route_to('/alpha').should have_route(:controller=>'Alphas',:action=>'wierd')
21
+ end
22
+
23
+ it "should inherit the default :action of 'index'" do
24
+ Merb::Router.prepare do |r|
25
+ r.match('/alpha', :controller=>'Alphas') do |alpha|
26
+ alpha.match('').to({})
27
+ end
28
+ end
29
+ route_to('/alpha').should have_route(:controller=>'Alphas',:action=>'index')
30
+ end
31
+
32
+ it "should make use of the :params option" do
33
+ Merb::Router.prepare do |r|
34
+ r.match('/alpha', :controller=>'Alphas', :params =>{:key=>'value'}) do |alpha|
35
+ alpha.match('').to(:action=>'normal',:key2=>'value2')
36
+ end
37
+ end
38
+ route_to('/alpha').should have_route(:controller=>'Alphas',:key=>'value',:action=>'normal',:key2=>'value2')
39
+ end
40
+
41
+ it "should inherit the parameters through many levels" do
42
+ Merb::Router.prepare do |r|
43
+ r.match('/alpha', :controller=>'Alphas') do |alpha|
44
+ alpha.match('/beta', :action=>'normal') do |beta|
45
+ beta.match('/:id').to(:id=>':id')
46
+ end
47
+ end
48
+ end
49
+ route_to('/alpha/beta/gamma').should have_route(:controller=>'Alphas',:action=>'normal', :id=>'gamma')
50
+ end
51
+
52
+ it "allows wrapping of nested routes all having shared argument" do
53
+ Merb::Router.prepare do |r|
54
+ r.match('/:language') do |i18n|
55
+ i18n.match!('/:controller/:action')
56
+ end
57
+ end
58
+ route_to('/fr/hotels/search').should have_route(:controller => 'hotels', :action => "search", :language => "fr")
59
+ end
60
+
61
+ it "allows wrapping of nested routes all having shared argument" do
62
+ Merb::Router.prepare do |r|
63
+ r.match(/\/?(.*)?/).to(:language => "[1]") do |l|
64
+ l.match("/guides/:action/:id").to(:controller => "tour_guides")
65
+ end
66
+ end
67
+
68
+ route_to('/en/guides/search/london').should have_route(:controller => 'tour_guides', :action => "search", :language => "en", :id => "london")
69
+ end
70
+
71
+ it "allows wrapping of nested routes all having shared OPTIONAL argument" do
72
+ Merb::Router.prepare do |r|
73
+ r.match(/\/?(.*)?/).to(:language => "[1]") do |l|
74
+ l.match("/guides/:action/:id").to(:controller => "tour_guides")
75
+ end
76
+ end
77
+
78
+ route_to('/guides/search/london').should have_route(:controller => 'tour_guides', :action => "search", :id => "london")
79
+ end
80
+
81
+ it "allows wrapping of nested routes all having shared argument with PREDEFINED VALUES" do
82
+ Merb::Router.prepare do |r|
83
+ r.match(/\/?(en|es|fr|be|nl)?/).to(:language => "[1]") do |l|
84
+ l.match("/guides/:action/:id").to(:controller => "tour_guides")
85
+ end
86
+ end
87
+
88
+ route_to('/nl/guides/search/denboss').should have_route(:controller => 'tour_guides', :action => "search", :id => "denboss", :language => "nl")
89
+ route_to('/es/guides/search/barcelona').should have_route(:controller => 'tour_guides', :action => "search", :id => "barcelona", :language => "es")
90
+ route_to('/fr/guides/search/lille').should have_route(:controller => 'tour_guides', :action => "search", :id => "lille", :language => "fr")
91
+ route_to('/en/guides/search/london').should have_route(:controller => 'tour_guides', :action => "search", :id => "london", :language => "en")
92
+ route_to('/be/guides/search/brussels').should have_route(:controller => 'tour_guides', :action => "search", :id => "brussels", :language => "be")
93
+
94
+ route_to('/guides/search/brussels').should have_route(:controller => 'tour_guides', :action => "search", :id => "brussels")
95
+ route_to('/se/guides/search/stokholm').should have_route(:controller => 'tour_guides', :action => "search", :id => "stokholm", :language => nil)
96
+ end
97
+ end
@@ -31,15 +31,7 @@ describe "resources routes" do
31
31
  route_to('/foo/edit', :method => :get).should have_route(:controller => 'foo', :action => 'edit', :id => nil)
32
32
  end
33
33
 
34
- it "should match a get to /foo;edit to the blogposts controller and edit action" do
35
- route_to('/foo;edit', :method => :get).should have_route(:controller => 'foo', :action => 'edit', :id => nil)
36
- end
37
-
38
34
  it "should match a get to /foo/delete to the blogposts controller and delete action" do
39
35
  route_to('/foo/delete', :method => :get).should have_route(:controller => 'foo', :action => 'delete', :id => nil)
40
36
  end
41
-
42
- it "should match a get to /foo;delete to the blogposts controller and delete action" do
43
- route_to('/foo;delete', :method => :get).should have_route(:controller => 'foo', :action => 'delete', :id => nil)
44
- end
45
- end
37
+ end
@@ -35,22 +35,12 @@ describe "resources routes" do
35
35
  route_to('/blogposts/1/edit', :method => :get).should have_route(:controller => 'blogposts', :action => 'edit', :id => "1")
36
36
  end
37
37
 
38
- it "should match a get to /blogposts/1;edit to the blogposts controller and the edit action with id 1" do
39
- route_to('/blogposts/1;edit', :method => :get).should have_route(:controller => 'blogposts', :action => 'edit', :id => "1")
40
- end
41
-
42
38
  it "should not match a put to /blogposts/1/edit" do
43
39
  # not sure which of these is the best way to specify what I mean - so they're both in...
44
40
  route_to('/blogposts/1/edit', :method => :put).should have_nil_route
45
41
  route_to('/blogposts/1/edit', :method => :put).should_not have_route(:controller => 'blogposts', :action => 'edit', :id => "1")
46
42
  end
47
43
 
48
- it "should not match a put to /blogposts/1;edit" do
49
- # not sure which of these is the best way to specify what I mean - so they're both in...
50
- route_to('/blogposts/1;edit', :method => :put).should have_nil_route
51
- route_to('/blogposts/1;edit', :method => :put).should_not have_route(:controller => 'blogposts', :action => 'edit', :id => "1")
52
- end
53
-
54
44
  it "should match a get to /blogposts/1/delete to the blogposts controller and the delete action with id 1" do
55
45
  route_to('/blogposts/1/delete', :method => :get).should have_route(:controller => 'blogposts', :action => 'delete', :id => "1")
56
46
  end
@@ -79,10 +69,6 @@ describe "resources routes with named keys" do
79
69
  it "should match a get to /emails/bidule/merbivore_com/edit to the emails controller and the destroy action with username => 'bidule', domain => 'merbivore_com'" do
80
70
  route_to('/emails/bidule/merbivore_com/edit', :method => :get).should have_route(:controller => 'emails', :action => 'edit', :username => "bidule", :domain => "merbivore_com")
81
71
  end
82
-
83
- it "should match a get to /emails/bidule/merbivore_com;edit to the emails controller and the destroy action with username => 'bidule', domain => 'merbivore_com'" do
84
- route_to('/emails/bidule/merbivore_com;edit', :method => :get).should have_route(:controller => 'emails', :action => 'edit', :username => "bidule", :domain => "merbivore_com")
85
- end
86
72
 
87
73
  it "should not match a put to /emails/bidule/merbivore_com/edit" do
88
74
  # not sure which of these is the best way to specify what I mean - so they're both in...
@@ -90,12 +76,6 @@ describe "resources routes with named keys" do
90
76
  route_to('/emails/bidule/merbivore_com/edit', :method => :put).should_not have_route(:controller => 'emails', :action => 'edit', :username => "bidule", :domain => "merbivore_com")
91
77
  end
92
78
 
93
- it "should not match a put to /emails/bidule/merbivore_com;edit" do
94
- # not sure which of these is the best way to specify what I mean - so they're both in...
95
- route_to('/emails/bidule/merbivore_com;edit', :method => :put).should have_nil_route
96
- route_to('/emails/bidule/merbivore_com;edit', :method => :put).should_not have_route(:controller => 'emails', :action => 'edit', :username => "bidule", :domain => "merbivore_com")
97
- end
98
-
99
79
  it "should match a get to /emails/bidule/merbivore_com/delete to the emails controller and the delete action with username => 'bidule', domain => 'merbivore_com'" do
100
80
  route_to('/emails/bidule/merbivore_com/delete', :method => :get).should have_route(:controller => 'emails', :action => 'delete', :username => "bidule", :domain => "merbivore_com")
101
81
  end
@@ -1,36 +1,54 @@
1
1
  require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
2
  require 'ostruct'
3
+
4
+ require 'rack/mock'
5
+ require 'stringio'
6
+ Merb.start :environment => 'test',
7
+ :merb_root => File.dirname(__FILE__) / 'fixture'
8
+
9
+
3
10
  class SimpleRequest < OpenStruct
4
-
11
+
5
12
  def method
6
13
  @table[:method]
7
14
  end
8
-
15
+
9
16
  def params
10
17
  @table
11
18
  end
12
19
  end
13
20
 
14
21
  def prepare_route(from, to)
15
- Merb::Router.prepare {|r| r.match(from).to(to)}
22
+ Merb::Router.prepare {|r| r.match(from).to(to)}
16
23
  end
17
24
 
18
25
  def route_to(path, args = {}, protocol = "http://")
19
26
  Merb::Router.match(SimpleRequest.new({:protocol => protocol, :path => path}.merge(args)))[1]
20
27
  end
21
28
 
29
+ def match_for(path, args = {}, protocol = "http://")
30
+ Merb::Router.match(SimpleRequest.new({:protocol => protocol, :path => path}.merge(args)))
31
+ end
32
+
33
+ def matched_route_for(*args)
34
+ # get route index
35
+ idx = match_for(*args)[0]
36
+
37
+ Merb::Router.routes[idx]
38
+ end
39
+
22
40
  def generate(*args)
23
41
  Merb::Router.generate *args
24
42
  end
25
43
 
26
44
  module Merb
27
-
45
+
28
46
  module Test
29
-
47
+
30
48
  module RspecMatchers
31
49
 
32
50
  class HaveRoute
33
-
51
+
34
52
  def self.build(expected)
35
53
  this = new
36
54
  this.instance_variable_set("@expected", expected)
@@ -62,11 +80,11 @@ module Merb
62
80
  def have_route(expected)
63
81
  HaveRoute.build(expected)
64
82
  end
65
-
83
+
66
84
  def have_nil_route
67
85
  have_route({})
68
86
  end
69
-
87
+
70
88
  end
71
89
  end
72
- end
90
+ end
@@ -1,9 +1,9 @@
1
1
  require File.join(File.dirname(__FILE__), "spec_helper")
2
2
 
3
3
  describe "Regex-based routes" do
4
-
4
+
5
5
  it "should process a simple regex" do
6
- prepare_route(%r[^/foos?/(bar|baz)/:id], :controller => "foo", :action => "[1]", :id => ":id")
6
+ prepare_route(%r[^/foos?/(bar|baz)/:id], :controller => "foo", :action => "[1]", :id => ":id")
7
7
  route_to("/foo/bar/baz").should have_route(:controller => "foo", :action => "bar", :id => "baz")
8
8
  route_to("/foos/baz/bam").should have_route(:controller => "foo", :action => "baz", :id => "bam")
9
9
  end
@@ -11,7 +11,7 @@ describe "Regex-based routes" do
11
11
  it "should support inbound user agents" do
12
12
  Merb::Router.prepare do |r|
13
13
  r.match(%r[^/foo/(.+)], :user_agent => /(MSIE|Gecko)/).
14
- to(:controller => "foo", :title => "[1]", :action => "show", :agent => ":user_agent[1]")
14
+ to(:controller => "foo", :title => "[1]", :action => "show", :agent => ":user_agent[1]")
15
15
  end
16
16
  route_to("/foo/bar", :user_agent => /MSIE/).should have_route(
17
17
  :controller => "foo", :action => "show", :title => "bar", :agent => "MSIE"
@@ -21,7 +21,7 @@ describe "Regex-based routes" do
21
21
  end
22
22
 
23
23
  describe "Routes that are restricted based on incoming params" do
24
-
24
+
25
25
  it "should allow you to restrict routes to POST requests" do
26
26
  Merb::Router.prepare do |r|
27
27
  r.match("/:controller/create/:id", :method => :post).
@@ -30,12 +30,12 @@ describe "Routes that are restricted based on incoming params" do
30
30
  route_to("/foo/create/12", :method => "post").should have_route(
31
31
  :controller => "foo", :action => "create", :id => "12"
32
32
  )
33
-
33
+
34
34
  route_to("/foo/create/12", :method => "get").should_not have_route(
35
35
  :controller => "foo", :action => "create", :id => "12"
36
36
  )
37
37
  end
38
-
38
+
39
39
  it "should allow you to restrict routes based on protocol" do
40
40
  Merb::Router.prepare do |r|
41
41
  r.match(:protocol => "http://").to(:controller => "foo", :action => "bar")
@@ -44,5 +44,18 @@ describe "Routes that are restricted based on incoming params" do
44
44
  route_to("/foo/bar").should have_route(:controller => "foo", :action => "bar")
45
45
  route_to("/boo/hoo", :protocol => "https://").should have_route(:controller => "boo", :action => "hoo")
46
46
  end
47
-
48
- end
47
+
48
+ it "does not require explicit specifying of params" do
49
+ Merb::Router.prepare do |r|
50
+ r.match!("/fb/:callback_path/:controller/:action")
51
+ end
52
+
53
+ route_to("/fb/callybacky/products/search").should have_route(
54
+ :controller => "products", :action => "search", :callback_path => "callybacky"
55
+ )
56
+ route_to("/fb/ping/products/search").should have_route(
57
+ :controller => "products", :action => "search", :callback_path => "ping"
58
+ )
59
+ end
60
+
61
+ end
@@ -23,11 +23,11 @@ module Merb::Test::Fixtures
23
23
 
24
24
  class MyTemplateEngine
25
25
 
26
- def self.compile_template(path, name, mod)
27
- text = File.read(path)
26
+ def self.compile_template(io, name, mod)
27
+ text = io.read
28
28
  table = { "\r"=>"\\r", "\n"=>"\\n", "\t"=>"\\t", '"'=>'\\"', "\\"=>"\\\\" }
29
29
  text = (text.split("\n").map {|x| '"' + (x.gsub(/[\r\n\t"\\]/) { |m| table[m] }) + '"'}).join(" +\n")
30
- mod.class_eval <<-EOS, path
30
+ mod.class_eval <<-EOS, File.expand_path(io.path)
31
31
  def #{name}
32
32
  #{text}
33
33
  end
@@ -52,12 +52,13 @@ describe Merb::Template do
52
52
  it "should accept template-type registrations via #register_extensions" do
53
53
  Merb::Template.register_extensions(Merb::Test::Fixtures::MyTemplateEngine, %w[myt])
54
54
  Merb::Template.engine_for("foo.myt").should == Merb::Test::Fixtures::MyTemplateEngine
55
+ Merb::Template.template_extensions.should include("myt")
55
56
  end
56
57
 
57
58
  # @semipublic
58
59
 
59
60
  def rendering_template(template_path)
60
- Merb::Template.inline_template(template_path, Merb::Test::Fixtures::MyHelpers)
61
+ Merb::Template.inline_template(File.open(template_path), Merb::Test::Fixtures::MyHelpers)
61
62
  Merb::Test::Fixtures::Environment.new.
62
63
  send(Merb::Template.template_name(template_path))
63
64
  end
@@ -73,6 +74,17 @@ describe Merb::Template do
73
74
  rendering_template(template_path).should == "Hello world!"
74
75
  end
75
76
 
77
+ it "should compile and inline templates that comes through via VirtualFile" do
78
+ Merb::Template.inline_template(VirtualFile.new("Hello",
79
+ File.dirname(__FILE__) / "templates" / "template.html.erb"),
80
+ Merb::Test::Fixtures::MyHelpers)
81
+
82
+ res = Merb::Test::Fixtures::Environment.new.
83
+ send(Merb::Template.template_name(File.dirname(__FILE__) / "templates" / "template.html.erb"))
84
+
85
+ res.should == "Hello"
86
+ end
87
+
76
88
  it "should know how to correctly report errors" do
77
89
  template_path = File.dirname(__FILE__) / "templates" / "error.html.erb"
78
90
  running { render_template(template_path) }.should raise_error(NameError, /`foo'/)
@@ -85,7 +97,7 @@ describe Merb::Template do
85
97
 
86
98
  it "should find the full template name for a path via #template_for" do
87
99
  template_path = File.dirname(__FILE__) / "templates" / "template.html.erb"
88
- name = Merb::Template.inline_template(template_path, Merb::Test::Fixtures::MyHelpers)
100
+ name = Merb::Template.inline_template(File.open(template_path), Merb::Test::Fixtures::MyHelpers)
89
101
  Merb::Test::Fixtures::Environment.new.should respond_to(name)
90
102
  end
91
103
 
@@ -7,6 +7,10 @@ class TestController < Merb::Controller
7
7
  def redirect_action; redirect(@redirect_to || "/"); end
8
8
  def success_action; end
9
9
  def missing_action; render("i can has errorz", :status => 404); end
10
+
11
+ def redirect_with_message_action
12
+ redirect(@redirect_to, :message => "okey dookey")
13
+ end
10
14
  end
11
15
 
12
16
  describe Merb::Test::Rspec::ControllerMatchers do
@@ -42,6 +46,12 @@ describe Merb::Test::Rspec::ControllerMatchers do
42
46
  it "should work with the result of a get helper call" do
43
47
  get("/redirect"){|controller| controller.redirect_to = "http://example.com/" }.should redirect_to("http://example.com/")
44
48
  end
49
+
50
+ it 'takes :message option' do
51
+ dispatch_to(TestController, :redirect_with_message_action) { |controller|
52
+ controller.redirect_to = "http://example.com/"
53
+ }.should redirect_to("http://example.com/", :message => "okey dookey")
54
+ end
45
55
  end
46
56
 
47
57
  describe "#respond_successfully" do
@@ -26,10 +26,31 @@ describe Merb::Test::RequestHelper do
26
26
  controller.params[:name].should == "Fred"
27
27
  end
28
28
 
29
+ it "should dispatch to the given controller and action with the query string merged into the params" do
30
+ Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
31
+ controller = dispatch_to(@controller_klass, :show, {:name => "Fred"}, {'QUERY_STRING' => "last_name=Jones&age=42"} )
32
+
33
+ controller.params[:name].should == "Fred"
34
+ controller.params[:last_name].should == "Jones"
35
+ controller.params[:age].should == "42"
36
+ end
37
+
29
38
  it "should not hit the router to match its route" do
30
39
  Merb::Router.should_not_receive(:match)
31
40
  dispatch_to(@controller_klass, :index)
32
41
  end
42
+
43
+ it "merges :controller into params" do
44
+ controller = dispatch_to(@controller_klass, :show, :name => "Fred")
45
+
46
+ controller.params[:controller].should == @controller_klass.name.to_const_path
47
+ end
48
+
49
+ it "merges :action into params" do
50
+ controller = dispatch_to(@controller_klass, :show, :name => "Fred")
51
+
52
+ controller.params[:action].should == "show"
53
+ end
33
54
  end
34
55
 
35
56
  describe "#dispatch_with_basic_authentication_to" do
@@ -85,6 +106,14 @@ describe Merb::Test::RequestHelper do
85
106
  controller = get("/spec_helper_controller", :name => "Harry")
86
107
  controller.params[:name].should == "Harry"
87
108
  end
109
+
110
+ it "should perform the index action and have params available from the query string" do
111
+ Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
112
+ controller = get("/spec_helper_controller?last_name=Oswald&age=25", :name => "Harry")
113
+ controller.params[:name].should == "Harry"
114
+ controller.params[:last_name].should == "Oswald"
115
+ controller.params[:age].should == "25"
116
+ end
88
117
 
89
118
  it "should evaluate in the context of the controller in the block" do
90
119
  get("/spec_helper_controller") do |controller|
@@ -28,6 +28,23 @@ describe Merb::Test::RouteHelper do
28
28
  it "should work with a parameters hash" do
29
29
  url(:with_id, :id => 123).should == "/123"
30
30
  end
31
+
32
+ it "should turn extra hash items into query params" do
33
+ generated_url = url(:getter, :id => 123, :color => 'red', :size => 'large')
34
+ lambda {
35
+ generated_url.match(/\bid=123\b/) &&
36
+ generated_url.match(/\bsize=large\b/) &&
37
+ generated_url.match(/\bcolor=red\b/)
38
+ }.call.should_not be_nil
39
+ end
40
+
41
+ it "should remove items with nil values from query params" do
42
+ url(:getter, :color => nil, :size => 'large').should == "/?size=large"
43
+ end
44
+
45
+ it "should remove items with nil values from query params when named route isn't specified" do
46
+ url(:controller => 'cont', :action => 'act', :color => nil, :size => 'large').should == "/cont/act?size=large"
47
+ end
31
48
  end
32
49
 
33
50
  describe "#request_to" do
@@ -51,4 +68,4 @@ describe Merb::Test::RouteHelper do
51
68
  request_to("/123")[:id].should == "123"
52
69
  end
53
70
  end
54
- end
71
+ end