ghazel-erubis_rails_helper 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +66 -0
- data/lib/erubis_rails_helper/erubis/generator.rb +100 -0
- data/lib/erubis_rails_helper/template_handlers/erubis.rb +260 -0
- data/lib/erubis_rails_helper.rb +20 -0
- data/test/abstract_unit.rb +51 -0
- data/test/controller/action_pack_assertions_test.rb +516 -0
- data/test/controller/addresses_render_test.rb +37 -0
- data/test/controller/assert_select_test.rb +734 -0
- data/test/controller/base_test.rb +217 -0
- data/test/controller/benchmark_test.rb +32 -0
- data/test/controller/caching_test.rb +690 -0
- data/test/controller/capture_test.rb +66 -0
- data/test/controller/content_type_test.rb +168 -0
- data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
- data/test/controller/cookie_test.rb +111 -0
- data/test/controller/deprecation/deprecated_base_methods_test.rb +32 -0
- data/test/controller/dispatcher_test.rb +103 -0
- data/test/controller/fake_controllers.rb +33 -0
- data/test/controller/fake_models.rb +19 -0
- data/test/controller/filter_params_test.rb +49 -0
- data/test/controller/filters_test.rb +885 -0
- data/test/controller/flash_test.rb +142 -0
- data/test/controller/header_test.rb +14 -0
- data/test/controller/helper_test.rb +224 -0
- data/test/controller/html-scanner/cdata_node_test.rb +15 -0
- data/test/controller/html-scanner/document_test.rb +148 -0
- data/test/controller/html-scanner/node_test.rb +89 -0
- data/test/controller/html-scanner/sanitizer_test.rb +273 -0
- data/test/controller/html-scanner/tag_node_test.rb +238 -0
- data/test/controller/html-scanner/text_node_test.rb +50 -0
- data/test/controller/html-scanner/tokenizer_test.rb +131 -0
- data/test/controller/http_basic_authentication_test.rb +88 -0
- data/test/controller/http_digest_authentication_test.rb +178 -0
- data/test/controller/integration_test.rb +417 -0
- data/test/controller/layout_test.rb +204 -0
- data/test/controller/logging_test.rb +46 -0
- data/test/controller/middleware_stack_test.rb +90 -0
- data/test/controller/mime_responds_test.rb +536 -0
- data/test/controller/mime_type_test.rb +93 -0
- data/test/controller/polymorphic_routes_test.rb +293 -0
- data/test/controller/rack_test.rb +294 -0
- data/test/controller/record_identifier_test.rb +139 -0
- data/test/controller/redirect_test.rb +282 -0
- data/test/controller/render_test.rb +1752 -0
- data/test/controller/request/json_params_parsing_test.rb +45 -0
- data/test/controller/request/multipart_params_parsing_test.rb +223 -0
- data/test/controller/request/query_string_parsing_test.rb +120 -0
- data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
- data/test/controller/request/xml_params_parsing_test.rb +88 -0
- data/test/controller/request_forgery_protection_test.rb +246 -0
- data/test/controller/request_test.rb +407 -0
- data/test/controller/rescue_test.rb +536 -0
- data/test/controller/resources_test.rb +1341 -0
- data/test/controller/routing_test.rb +2557 -0
- data/test/controller/selector_test.rb +628 -0
- data/test/controller/send_file_test.rb +161 -0
- data/test/controller/session/cookie_store_test.rb +239 -0
- data/test/controller/session/mem_cache_store_test.rb +127 -0
- data/test/controller/session/test_session_test.rb +58 -0
- data/test/controller/test_test.rb +692 -0
- data/test/controller/translation_test.rb +26 -0
- data/test/controller/url_rewriter_test.rb +359 -0
- data/test/controller/verification_test.rb +270 -0
- data/test/controller/view_paths_test.rb +141 -0
- data/test/controller/webservice_test.rb +260 -0
- data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
- data/test/fixtures/company.rb +10 -0
- data/test/fixtures/developer.rb +9 -0
- data/test/fixtures/helpers/abc_helper.rb +5 -0
- data/test/fixtures/helpers/fun/games_helper.rb +3 -0
- data/test/fixtures/helpers/fun/pdf_helper.rb +3 -0
- data/test/fixtures/mascot.rb +3 -0
- data/test/fixtures/project.rb +3 -0
- data/test/fixtures/reply.rb +7 -0
- data/test/fixtures/topic.rb +3 -0
- data/test/template/asset_tag_helper_test.rb +713 -0
- data/test/template/atom_feed_helper_test.rb +286 -0
- data/test/template/benchmark_helper_test.rb +86 -0
- data/test/template/compiled_templates_test.rb +203 -0
- data/test/template/date_helper_i18n_test.rb +120 -0
- data/test/template/date_helper_test.rb +2469 -0
- data/test/template/erb_util_test.rb +24 -0
- data/test/template/form_helper_test.rb +1176 -0
- data/test/template/form_options_helper_test.rb +751 -0
- data/test/template/form_tag_helper_test.rb +327 -0
- data/test/template/javascript_helper_test.rb +106 -0
- data/test/template/number_helper_i18n_test.rb +69 -0
- data/test/template/number_helper_test.rb +128 -0
- data/test/template/prototype_helper_test.rb +639 -0
- data/test/template/record_tag_helper_test.rb +58 -0
- data/test/template/render_test.rb +291 -0
- data/test/template/sanitize_helper_test.rb +48 -0
- data/test/template/scriptaculous_helper_test.rb +90 -0
- data/test/template/tag_helper_test.rb +97 -0
- data/test/template/test_test.rb +54 -0
- data/test/template/text_helper_test.rb +520 -0
- data/test/template/translation_helper_test.rb +32 -0
- data/test/template/url_helper_test.rb +614 -0
- data/test/test_erubis_rails_helper.rb +4 -0
- data/test/testing_sandbox.rb +15 -0
- data/test/view/test_case_test.rb +8 -0
- metadata +174 -0
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class ViewLoadPathsTest < ActionController::TestCase
|
4
|
+
class TestController < ActionController::Base
|
5
|
+
def self.controller_path() "test" end
|
6
|
+
def rescue_action(e) raise end
|
7
|
+
|
8
|
+
before_filter :add_view_path, :only => :hello_world_at_request_time
|
9
|
+
|
10
|
+
def hello_world() end
|
11
|
+
def hello_world_at_request_time() render(:action => 'hello_world') end
|
12
|
+
|
13
|
+
private
|
14
|
+
def add_view_path
|
15
|
+
prepend_view_path "#{FIXTURE_LOAD_PATH}/override"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Test::SubController < ActionController::Base
|
20
|
+
layout 'test/sub'
|
21
|
+
def hello_world; render(:template => 'test/hello_world'); end
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup
|
25
|
+
TestController.view_paths = nil
|
26
|
+
|
27
|
+
@request = ActionController::TestRequest.new
|
28
|
+
@response = ActionController::TestResponse.new
|
29
|
+
|
30
|
+
@controller = TestController.new
|
31
|
+
# Following is needed in order to setup @controller.template object properly
|
32
|
+
@controller.send :initialize_template_class, @response
|
33
|
+
@controller.send :assign_shortcuts, @request, @response
|
34
|
+
|
35
|
+
# Track the last warning.
|
36
|
+
@old_behavior = ActiveSupport::Deprecation.behavior
|
37
|
+
@last_message = nil
|
38
|
+
ActiveSupport::Deprecation.behavior = Proc.new { |message, callback| @last_message = message }
|
39
|
+
end
|
40
|
+
|
41
|
+
def teardown
|
42
|
+
ActiveSupport::Deprecation.behavior = @old_behavior
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_template_load_path_was_set_correctly
|
46
|
+
assert_equal [FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_controller_appends_view_path_correctly
|
50
|
+
@controller.append_view_path 'foo'
|
51
|
+
assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths.map(&:to_s)
|
52
|
+
|
53
|
+
@controller.append_view_path(%w(bar baz))
|
54
|
+
assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths.map(&:to_s)
|
55
|
+
|
56
|
+
@controller.append_view_path(FIXTURE_LOAD_PATH)
|
57
|
+
assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_controller_prepends_view_path_correctly
|
61
|
+
@controller.prepend_view_path 'baz'
|
62
|
+
assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
|
63
|
+
|
64
|
+
@controller.prepend_view_path(%w(foo bar))
|
65
|
+
assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
|
66
|
+
|
67
|
+
@controller.prepend_view_path(FIXTURE_LOAD_PATH)
|
68
|
+
assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_template_appends_view_path_correctly
|
72
|
+
@controller.instance_variable_set :@template, ActionView::Base.new(TestController.view_paths, {}, @controller)
|
73
|
+
class_view_paths = TestController.view_paths
|
74
|
+
|
75
|
+
@controller.append_view_path 'foo'
|
76
|
+
assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths.map(&:to_s)
|
77
|
+
|
78
|
+
@controller.append_view_path(%w(bar baz))
|
79
|
+
assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths.map(&:to_s)
|
80
|
+
assert_equal class_view_paths, TestController.view_paths
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_template_prepends_view_path_correctly
|
84
|
+
@controller.instance_variable_set :@template, ActionView::Base.new(TestController.view_paths, {}, @controller)
|
85
|
+
class_view_paths = TestController.view_paths
|
86
|
+
|
87
|
+
@controller.prepend_view_path 'baz'
|
88
|
+
assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
|
89
|
+
|
90
|
+
@controller.prepend_view_path(%w(foo bar))
|
91
|
+
assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
|
92
|
+
assert_equal class_view_paths, TestController.view_paths
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_view_paths
|
96
|
+
get :hello_world
|
97
|
+
assert_response :success
|
98
|
+
assert_equal "Hello world!", @response.body
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_view_paths_override
|
102
|
+
TestController.prepend_view_path "#{FIXTURE_LOAD_PATH}/override"
|
103
|
+
get :hello_world
|
104
|
+
assert_response :success
|
105
|
+
assert_equal "Hello overridden world!", @response.body
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_view_paths_override_for_layouts_in_controllers_with_a_module
|
109
|
+
@controller = Test::SubController.new
|
110
|
+
Test::SubController.view_paths = [ "#{FIXTURE_LOAD_PATH}/override", FIXTURE_LOAD_PATH, "#{FIXTURE_LOAD_PATH}/override2" ]
|
111
|
+
get :hello_world
|
112
|
+
assert_response :success
|
113
|
+
assert_equal "layout: Hello overridden world!", @response.body
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_view_paths_override_at_request_time
|
117
|
+
get :hello_world_at_request_time
|
118
|
+
assert_response :success
|
119
|
+
assert_equal "Hello overridden world!", @response.body
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_inheritance
|
123
|
+
original_load_paths = ActionController::Base.view_paths
|
124
|
+
|
125
|
+
self.class.class_eval %{
|
126
|
+
class A < ActionController::Base; end
|
127
|
+
class B < A; end
|
128
|
+
class C < ActionController::Base; end
|
129
|
+
}
|
130
|
+
|
131
|
+
A.view_paths = ['a/path']
|
132
|
+
|
133
|
+
assert_equal ['a/path'], A.view_paths.map(&:to_s)
|
134
|
+
assert_equal A.view_paths, B.view_paths
|
135
|
+
assert_equal original_load_paths, C.view_paths
|
136
|
+
|
137
|
+
C.view_paths = []
|
138
|
+
assert_nothing_raised { C.view_paths << 'c/path' }
|
139
|
+
assert_equal ['c/path'], C.view_paths.map(&:to_s)
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,260 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class WebServiceTest < ActionController::IntegrationTest
|
4
|
+
class TestController < ActionController::Base
|
5
|
+
def assign_parameters
|
6
|
+
if params[:full]
|
7
|
+
render :text => dump_params_keys
|
8
|
+
else
|
9
|
+
render :text => (params.keys - ['controller', 'action']).sort.join(", ")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def dump_params_keys(hash = params)
|
14
|
+
hash.keys.sort.inject("") do |s, k|
|
15
|
+
value = hash[k]
|
16
|
+
value = Hash === value ? "(#{dump_params_keys(value)})" : ""
|
17
|
+
s << ", " unless s.empty?
|
18
|
+
s << "#{k}#{value}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def rescue_action(e) raise end
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup
|
26
|
+
@controller = TestController.new
|
27
|
+
@default_param_parsers = ActionController::Base.param_parsers.dup
|
28
|
+
end
|
29
|
+
|
30
|
+
def teardown
|
31
|
+
ActionController::Base.param_parsers = @default_param_parsers
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_check_parameters
|
35
|
+
with_test_route_set do
|
36
|
+
get "/"
|
37
|
+
assert_equal '', @controller.response.body
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_post_xml
|
42
|
+
with_test_route_set do
|
43
|
+
post "/", '<entry attributed="true"><summary>content...</summary></entry>',
|
44
|
+
{'CONTENT_TYPE' => 'application/xml'}
|
45
|
+
|
46
|
+
assert_equal 'entry', @controller.response.body
|
47
|
+
assert @controller.params.has_key?(:entry)
|
48
|
+
assert_equal 'content...', @controller.params["entry"]['summary']
|
49
|
+
assert_equal 'true', @controller.params["entry"]['attributed']
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_put_xml
|
54
|
+
with_test_route_set do
|
55
|
+
put "/", '<entry attributed="true"><summary>content...</summary></entry>',
|
56
|
+
{'CONTENT_TYPE' => 'application/xml'}
|
57
|
+
|
58
|
+
assert_equal 'entry', @controller.response.body
|
59
|
+
assert @controller.params.has_key?(:entry)
|
60
|
+
assert_equal 'content...', @controller.params["entry"]['summary']
|
61
|
+
assert_equal 'true', @controller.params["entry"]['attributed']
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_put_xml_using_a_type_node
|
66
|
+
with_test_route_set do
|
67
|
+
put "/", '<type attributed="true"><summary>content...</summary></type>',
|
68
|
+
{'CONTENT_TYPE' => 'application/xml'}
|
69
|
+
|
70
|
+
assert_equal 'type', @controller.response.body
|
71
|
+
assert @controller.params.has_key?(:type)
|
72
|
+
assert_equal 'content...', @controller.params["type"]['summary']
|
73
|
+
assert_equal 'true', @controller.params["type"]['attributed']
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_put_xml_using_a_type_node_and_attribute
|
78
|
+
with_test_route_set do
|
79
|
+
put "/", '<type attributed="true"><summary type="boolean">false</summary></type>',
|
80
|
+
{'CONTENT_TYPE' => 'application/xml'}
|
81
|
+
|
82
|
+
assert_equal 'type', @controller.response.body
|
83
|
+
assert @controller.params.has_key?(:type)
|
84
|
+
assert_equal false, @controller.params["type"]['summary']
|
85
|
+
assert_equal 'true', @controller.params["type"]['attributed']
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_post_xml_using_a_type_node
|
90
|
+
with_test_route_set do
|
91
|
+
post "/", '<font attributed="true"><type>arial</type></font>',
|
92
|
+
{'CONTENT_TYPE' => 'application/xml'}
|
93
|
+
|
94
|
+
assert_equal 'font', @controller.response.body
|
95
|
+
assert @controller.params.has_key?(:font)
|
96
|
+
assert_equal 'arial', @controller.params['font']['type']
|
97
|
+
assert_equal 'true', @controller.params["font"]['attributed']
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_post_xml_using_a_root_node_named_type
|
102
|
+
with_test_route_set do
|
103
|
+
post "/", '<type type="integer">33</type>',
|
104
|
+
{'CONTENT_TYPE' => 'application/xml'}
|
105
|
+
|
106
|
+
assert @controller.params.has_key?(:type)
|
107
|
+
assert_equal 33, @controller.params['type']
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_post_xml_using_an_attributted_node_named_type
|
112
|
+
with_test_route_set do
|
113
|
+
ActionController::Base.param_parsers[Mime::XML] = Proc.new { |data| Hash.from_xml(data)['request'].with_indifferent_access }
|
114
|
+
post "/", '<request><type type="string">Arial,12</type><z>3</z></request>',
|
115
|
+
{'CONTENT_TYPE' => 'application/xml'}
|
116
|
+
|
117
|
+
assert_equal 'type, z', @controller.response.body
|
118
|
+
assert @controller.params.has_key?(:type)
|
119
|
+
assert_equal 'Arial,12', @controller.params['type'], @controller.params.inspect
|
120
|
+
assert_equal '3', @controller.params['z'], @controller.params.inspect
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_register_and_use_yaml
|
125
|
+
with_test_route_set do
|
126
|
+
ActionController::Base.param_parsers[Mime::YAML] = Proc.new { |d| YAML.load(d) }
|
127
|
+
post "/", {"entry" => "loaded from yaml"}.to_yaml,
|
128
|
+
{'CONTENT_TYPE' => 'application/x-yaml'}
|
129
|
+
|
130
|
+
assert_equal 'entry', @controller.response.body
|
131
|
+
assert @controller.params.has_key?(:entry)
|
132
|
+
assert_equal 'loaded from yaml', @controller.params["entry"]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_register_and_use_yaml_as_symbol
|
137
|
+
with_test_route_set do
|
138
|
+
ActionController::Base.param_parsers[Mime::YAML] = :yaml
|
139
|
+
post "/", {"entry" => "loaded from yaml"}.to_yaml,
|
140
|
+
{'CONTENT_TYPE' => 'application/x-yaml'}
|
141
|
+
|
142
|
+
assert_equal 'entry', @controller.response.body
|
143
|
+
assert @controller.params.has_key?(:entry)
|
144
|
+
assert_equal 'loaded from yaml', @controller.params["entry"]
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_register_and_use_xml_simple
|
149
|
+
with_test_route_set do
|
150
|
+
ActionController::Base.param_parsers[Mime::XML] = Proc.new { |data| Hash.from_xml(data)['request'].with_indifferent_access }
|
151
|
+
post "/", '<request><summary>content...</summary><title>SimpleXml</title></request>',
|
152
|
+
{'CONTENT_TYPE' => 'application/xml'}
|
153
|
+
|
154
|
+
assert_equal 'summary, title', @controller.response.body
|
155
|
+
assert @controller.params.has_key?(:summary)
|
156
|
+
assert @controller.params.has_key?(:title)
|
157
|
+
assert_equal 'content...', @controller.params["summary"]
|
158
|
+
assert_equal 'SimpleXml', @controller.params["title"]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_use_xml_ximple_with_empty_request
|
163
|
+
with_test_route_set do
|
164
|
+
ActionController::Base.param_parsers[Mime::XML] = :xml_simple
|
165
|
+
assert_nothing_raised { post "/", "", {'CONTENT_TYPE' => 'application/xml'} }
|
166
|
+
assert_equal "", @controller.response.body
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_dasherized_keys_as_xml
|
171
|
+
with_test_route_set do
|
172
|
+
ActionController::Base.param_parsers[Mime::XML] = :xml_simple
|
173
|
+
post "/?full=1", "<first-key>\n<sub-key>...</sub-key>\n</first-key>",
|
174
|
+
{'CONTENT_TYPE' => 'application/xml'}
|
175
|
+
assert_equal 'action, controller, first_key(sub_key), full', @controller.response.body
|
176
|
+
assert_equal "...", @controller.params[:first_key][:sub_key]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_typecast_as_xml
|
181
|
+
with_test_route_set do
|
182
|
+
ActionController::Base.param_parsers[Mime::XML] = :xml_simple
|
183
|
+
xml = <<-XML
|
184
|
+
<data>
|
185
|
+
<a type="integer">15</a>
|
186
|
+
<b type="boolean">false</b>
|
187
|
+
<c type="boolean">true</c>
|
188
|
+
<d type="date">2005-03-17</d>
|
189
|
+
<e type="datetime">2005-03-17T21:41:07Z</e>
|
190
|
+
<f>unparsed</f>
|
191
|
+
<g type="integer">1</g>
|
192
|
+
<g>hello</g>
|
193
|
+
<g type="date">1974-07-25</g>
|
194
|
+
</data>
|
195
|
+
XML
|
196
|
+
post "/", xml, {'CONTENT_TYPE' => 'application/xml'}
|
197
|
+
|
198
|
+
params = @controller.params
|
199
|
+
assert_equal 15, params[:data][:a]
|
200
|
+
assert_equal false, params[:data][:b]
|
201
|
+
assert_equal true, params[:data][:c]
|
202
|
+
assert_equal Date.new(2005,3,17), params[:data][:d]
|
203
|
+
assert_equal Time.utc(2005,3,17,21,41,7), params[:data][:e]
|
204
|
+
assert_equal "unparsed", params[:data][:f]
|
205
|
+
assert_equal [1, "hello", Date.new(1974,7,25)], params[:data][:g]
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_entities_unescaped_as_xml_simple
|
210
|
+
with_test_route_set do
|
211
|
+
ActionController::Base.param_parsers[Mime::XML] = :xml_simple
|
212
|
+
xml = <<-XML
|
213
|
+
<data><foo "bar's" & friends></data>
|
214
|
+
XML
|
215
|
+
post "/", xml, {'CONTENT_TYPE' => 'application/xml'}
|
216
|
+
assert_equal %(<foo "bar's" & friends>), @controller.params[:data]
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_typecast_as_yaml
|
221
|
+
with_test_route_set do
|
222
|
+
ActionController::Base.param_parsers[Mime::YAML] = :yaml
|
223
|
+
yaml = <<-YAML
|
224
|
+
---
|
225
|
+
data:
|
226
|
+
a: 15
|
227
|
+
b: false
|
228
|
+
c: true
|
229
|
+
d: 2005-03-17
|
230
|
+
e: 2005-03-17T21:41:07Z
|
231
|
+
f: unparsed
|
232
|
+
g:
|
233
|
+
- 1
|
234
|
+
- hello
|
235
|
+
- 1974-07-25
|
236
|
+
YAML
|
237
|
+
post "/", yaml, {'CONTENT_TYPE' => 'application/x-yaml'}
|
238
|
+
params = @controller.params
|
239
|
+
assert_equal 15, params[:data][:a]
|
240
|
+
assert_equal false, params[:data][:b]
|
241
|
+
assert_equal true, params[:data][:c]
|
242
|
+
assert_equal Date.new(2005,3,17), params[:data][:d]
|
243
|
+
assert_equal Time.utc(2005,3,17,21,41,7), params[:data][:e]
|
244
|
+
assert_equal "unparsed", params[:data][:f]
|
245
|
+
assert_equal [1, "hello", Date.new(1974,7,25)], params[:data][:g]
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
private
|
250
|
+
def with_test_route_set
|
251
|
+
with_routing do |set|
|
252
|
+
set.draw do |map|
|
253
|
+
map.with_options :controller => "web_service_test/test" do |c|
|
254
|
+
c.connect "/", :action => "assign_parameters"
|
255
|
+
end
|
256
|
+
end
|
257
|
+
yield
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|