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,217 @@
1
+ require 'abstract_unit'
2
+ require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
3
+
4
+ # Provide some controller to run the tests on.
5
+ module Submodule
6
+ class ContainedEmptyController < ActionController::Base
7
+ end
8
+ class ContainedNonEmptyController < ActionController::Base
9
+ def public_action
10
+ render :nothing => true
11
+ end
12
+
13
+ hide_action :hidden_action
14
+ def hidden_action
15
+ raise "Noooo!"
16
+ end
17
+
18
+ def another_hidden_action
19
+ end
20
+ hide_action :another_hidden_action
21
+ end
22
+ class SubclassedController < ContainedNonEmptyController
23
+ hide_action :public_action # Hiding it here should not affect the superclass.
24
+ end
25
+ end
26
+ class EmptyController < ActionController::Base
27
+ end
28
+ class NonEmptyController < ActionController::Base
29
+ def public_action
30
+ end
31
+
32
+ hide_action :hidden_action
33
+ def hidden_action
34
+ end
35
+ end
36
+
37
+ class MethodMissingController < ActionController::Base
38
+
39
+ hide_action :shouldnt_be_called
40
+ def shouldnt_be_called
41
+ raise "NO WAY!"
42
+ end
43
+
44
+ protected
45
+
46
+ def method_missing(selector)
47
+ render :text => selector.to_s
48
+ end
49
+
50
+ end
51
+
52
+ class DefaultUrlOptionsController < ActionController::Base
53
+ def default_url_options_action
54
+ end
55
+
56
+ def default_url_options(options = nil)
57
+ { :host => 'www.override.com', :action => 'new', :bacon => 'chunky' }
58
+ end
59
+ end
60
+
61
+ class ControllerClassTests < Test::Unit::TestCase
62
+ def test_controller_path
63
+ assert_equal 'empty', EmptyController.controller_path
64
+ assert_equal EmptyController.controller_path, EmptyController.new.controller_path
65
+ assert_equal 'submodule/contained_empty', Submodule::ContainedEmptyController.controller_path
66
+ assert_equal Submodule::ContainedEmptyController.controller_path, Submodule::ContainedEmptyController.new.controller_path
67
+ end
68
+ def test_controller_name
69
+ assert_equal 'empty', EmptyController.controller_name
70
+ assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name
71
+ end
72
+ end
73
+
74
+ class ControllerInstanceTests < Test::Unit::TestCase
75
+ def setup
76
+ @empty = EmptyController.new
77
+ @contained = Submodule::ContainedEmptyController.new
78
+ @empty_controllers = [@empty, @contained, Submodule::SubclassedController.new]
79
+
80
+ @non_empty_controllers = [NonEmptyController.new,
81
+ Submodule::ContainedNonEmptyController.new]
82
+ end
83
+
84
+ def test_action_methods
85
+ @empty_controllers.each do |c|
86
+ hide_mocha_methods_from_controller(c)
87
+ assert_equal Set.new, c.__send__(:action_methods), "#{c.controller_path} should be empty!"
88
+ end
89
+ @non_empty_controllers.each do |c|
90
+ hide_mocha_methods_from_controller(c)
91
+ assert_equal Set.new(%w(public_action)), c.__send__(:action_methods), "#{c.controller_path} should not be empty!"
92
+ end
93
+ end
94
+
95
+ protected
96
+ # Mocha adds some public instance methods to Object that would be
97
+ # considered actions, so explicitly hide_action them.
98
+ def hide_mocha_methods_from_controller(controller)
99
+ mocha_methods = [
100
+ :expects, :mocha, :mocha_inspect, :reset_mocha, :stubba_object,
101
+ :stubba_method, :stubs, :verify, :__metaclass__, :__is_a__, :to_matcher,
102
+ ]
103
+ controller.class.__send__(:hide_action, *mocha_methods)
104
+ end
105
+ end
106
+
107
+
108
+ class PerformActionTest < ActionController::TestCase
109
+ class MockLogger
110
+ attr_reader :logged
111
+
112
+ def initialize
113
+ @logged = []
114
+ end
115
+
116
+ def method_missing(method, *args)
117
+ @logged << args.first
118
+ end
119
+ end
120
+
121
+ def use_controller(controller_class)
122
+ @controller = controller_class.new
123
+
124
+ # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
125
+ # a more accurate simulation of what happens in "real life".
126
+ @controller.logger = Logger.new(nil)
127
+
128
+ @request = ActionController::TestRequest.new
129
+ @response = ActionController::TestResponse.new
130
+
131
+ @request.host = "www.nextangle.com"
132
+
133
+ rescue_action_in_public!
134
+ end
135
+
136
+ def test_get_on_priv_should_show_selector
137
+ use_controller MethodMissingController
138
+ get :shouldnt_be_called
139
+ assert_response :success
140
+ assert_equal 'shouldnt_be_called', @response.body
141
+ end
142
+
143
+ def test_method_missing_is_not_an_action_name
144
+ use_controller MethodMissingController
145
+ assert ! @controller.__send__(:action_methods).include?('method_missing')
146
+
147
+ get :method_missing
148
+ assert_response :success
149
+ assert_equal 'method_missing', @response.body
150
+ end
151
+
152
+ def test_get_on_hidden_should_fail
153
+ use_controller NonEmptyController
154
+ get :hidden_action
155
+ assert_response 404
156
+
157
+ get :another_hidden_action
158
+ assert_response 404
159
+ end
160
+
161
+ def test_namespaced_action_should_log_module_name
162
+ use_controller Submodule::ContainedNonEmptyController
163
+ @controller.logger = MockLogger.new
164
+ get :public_action
165
+ assert_match /Processing\sSubmodule::ContainedNonEmptyController#public_action/, @controller.logger.logged[1]
166
+ end
167
+ end
168
+
169
+ class DefaultUrlOptionsTest < ActionController::TestCase
170
+ tests DefaultUrlOptionsController
171
+
172
+ def setup
173
+ @request.host = 'www.example.com'
174
+ rescue_action_in_public!
175
+ end
176
+
177
+ def test_default_url_options_are_used_if_set
178
+ ActionController::Routing::Routes.draw do |map|
179
+ map.default_url_options 'default_url_options', :controller => 'default_url_options'
180
+ map.connect ':controller/:action/:id'
181
+ end
182
+
183
+ get :default_url_options_action # Make a dummy request so that the controller is initialized properly.
184
+
185
+ assert_equal 'http://www.override.com/default_url_options/new?bacon=chunky', @controller.url_for(:controller => 'default_url_options')
186
+ assert_equal 'http://www.override.com/default_url_options?bacon=chunky', @controller.send(:default_url_options_url)
187
+ ensure
188
+ ActionController::Routing::Routes.load!
189
+ end
190
+ end
191
+
192
+ class EmptyUrlOptionsTest < ActionController::TestCase
193
+ tests NonEmptyController
194
+
195
+ def setup
196
+ @request.host = 'www.example.com'
197
+ rescue_action_in_public!
198
+ end
199
+
200
+ def test_ensure_url_for_works_as_expected_when_called_with_no_options_if_default_url_options_is_not_set
201
+ get :public_action
202
+ assert_equal "http://www.example.com/non_empty/public_action", @controller.url_for
203
+ end
204
+ end
205
+
206
+ class EnsureNamedRoutesWorksTicket22BugTest < Test::Unit::TestCase
207
+ def test_named_routes_still_work
208
+ ActionController::Routing::Routes.draw do |map|
209
+ map.resources :things
210
+ end
211
+ EmptyController.send :include, ActionController::UrlWriter
212
+
213
+ assert_equal '/things', EmptyController.new.send(:things_path)
214
+ ensure
215
+ ActionController::Routing::Routes.load!
216
+ end
217
+ end
@@ -0,0 +1,32 @@
1
+ require 'abstract_unit'
2
+
3
+ # Provide some static controllers.
4
+ class BenchmarkedController < ActionController::Base
5
+ def public_action
6
+ render :nothing => true
7
+ end
8
+
9
+ def rescue_action(e)
10
+ raise e
11
+ end
12
+ end
13
+
14
+ class BenchmarkTest < ActionController::TestCase
15
+ tests BenchmarkedController
16
+
17
+ class MockLogger
18
+ def method_missing(*args)
19
+ end
20
+ end
21
+
22
+ def setup
23
+ # benchmark doesn't do anything unless a logger is set
24
+ @controller.logger = MockLogger.new
25
+ @request.host = "test.actioncontroller.i"
26
+ end
27
+
28
+ def test_with_http_1_0_request
29
+ @request.host = nil
30
+ assert_nothing_raised { get :public_action }
31
+ end
32
+ end