crystal_ext 0.0.7 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +70 -7
- data/lib/crystal/controller.rb +28 -0
- data/lib/crystal/controller/abstract_controller.rb +60 -0
- data/lib/crystal/controller/abstract_controller/micelaneous.rb +31 -0
- data/lib/crystal/controller/abstract_controller/render.rb +133 -0
- data/lib/crystal/controller/abstract_controller/responder.rb +17 -0
- data/lib/crystal/controller/controller_context.rb +7 -0
- data/lib/crystal/controller/http_controller.rb +43 -0
- data/lib/crystal/controller/processors/controller_caller.rb +40 -0
- data/lib/crystal/controller/processors/controller_error_handling.rb +53 -0
- data/lib/crystal/controller/processors/controller_logger.rb +13 -0
- data/lib/crystal/conveyor.rb +29 -0
- data/lib/crystal/conveyor/conveyor.rb +74 -0
- data/lib/crystal/conveyor/conveyors.rb +20 -0
- data/lib/crystal/conveyor/params.rb +22 -0
- data/lib/crystal/conveyor/processor.rb +68 -0
- data/lib/crystal/conveyor/processors/conveyor_logger.rb +24 -0
- data/lib/crystal/conveyor/workspace.rb +36 -0
- data/lib/crystal/environment.rb +52 -0
- data/lib/crystal/environment/config.rb +118 -0
- data/lib/crystal/environment/dependency_resolver.rb +107 -0
- data/lib/crystal/environment/environment.rb +5 -0
- data/lib/crystal/environment/files_helper.rb +42 -0
- data/lib/crystal/environment/logger.rb +21 -0
- data/lib/crystal/html.rb +28 -0
- data/lib/crystal/html/controller_helpers/controller_url_helper.rb +52 -0
- data/lib/crystal/html/controller_helpers/flash_helper.rb +5 -0
- data/lib/crystal/html/flash.rb +40 -0
- data/lib/crystal/html/include_into_controller.rb +24 -0
- data/lib/crystal/html/processors/prepare_flash.rb +26 -0
- data/lib/crystal/html/processors/scoped_params.rb +30 -0
- data/lib/crystal/html/view_helpers/basic_html_helper.rb +83 -0
- data/lib/crystal/html/view_helpers/form_helper.rb +104 -0
- data/lib/crystal/html/view_helpers/javascript_helper.rb +18 -0
- data/lib/crystal/html/view_helpers/model_helper.rb +119 -0
- data/lib/crystal/html/view_helpers/view_url_helper.rb +66 -0
- data/lib/crystal/http.rb +47 -0
- data/lib/crystal/http/http.rb +18 -0
- data/lib/crystal/http/http_adapter.rb +30 -0
- data/lib/crystal/http/middleware/static_files.rb +20 -0
- data/lib/crystal/http/processors/evaluate_format.rb +22 -0
- data/lib/crystal/http/processors/http_logger.rb +15 -0
- data/lib/crystal/http/processors/http_writer.rb +48 -0
- data/lib/crystal/http/processors/prepare_params.rb +24 -0
- data/lib/crystal/http/rack_config.rb +15 -0
- data/lib/crystal/http/support/rack/rack_adapter.rb +65 -0
- data/lib/crystal/http/support/rack/request.rb +12 -0
- data/lib/crystal/http/support/rack/response.rb +39 -0
- data/lib/crystal/mailer.rb +13 -0
- data/lib/crystal/mailer/mail.rb +7 -0
- data/lib/{crystal_ext/profiles/web_ext.rb → crystal/profiles/web.rb} +9 -15
- data/lib/crystal/profiles/web_require.rb +5 -0
- data/lib/crystal/remote.rb +9 -0
- data/lib/crystal/remote/processors/remote_caller.rb +54 -0
- data/lib/crystal/remote/processors/remote_logger.rb +13 -0
- data/lib/crystal/remote/remote.rb +15 -0
- data/lib/crystal/router.rb +19 -0
- data/lib/crystal/router/configurator.rb +23 -0
- data/lib/crystal/router/default_format_processor.rb +12 -0
- data/lib/crystal/router/default_router.rb +23 -0
- data/lib/crystal/router/named_router.rb +63 -0
- data/lib/crystal/router/processors/router.rb +22 -0
- data/lib/crystal/router/router.rb +218 -0
- data/lib/crystal/router/routing_helper.rb +17 -0
- data/lib/crystal/spec.rb +8 -0
- data/lib/crystal/spec/controller.rb +15 -0
- data/lib/crystal/spec/environment.rb +41 -0
- data/lib/crystal/spec/http.rb +67 -0
- data/lib/crystal/spec/mail.rb +20 -0
- data/lib/crystal/spec/remote.rb +9 -0
- data/lib/crystal/spec/view.rb +10 -0
- data/lib/crystal/spec/xhtml.rb +33 -0
- data/lib/crystal/support.rb +46 -0
- data/lib/crystal/support/active_support.rb +39 -0
- data/lib/crystal/support/active_support/micelaneous.rb +2 -0
- data/lib/crystal/support/addressable.rb +45 -0
- data/lib/crystal/support/buffered_logger.rb +38 -0
- data/lib/crystal/support/callbacks.rb +155 -0
- data/lib/crystal/support/exception.rb +20 -0
- data/lib/crystal/support/filters.rb +34 -0
- data/lib/crystal/support/format.rb +9 -0
- data/lib/crystal/support/gems.rb +8 -0
- data/lib/crystal/support/micon.rb +13 -0
- data/lib/crystal/support/mime.rb +11 -0
- data/lib/crystal/support/module.rb +44 -0
- data/lib/crystal/support/rson.rb +53 -0
- data/lib/crystal/support/ruby_ext_with_active_support.rb +4 -0
- data/lib/crystal/support/safe_hash.rb +135 -0
- data/lib/crystal/support/string.rb +26 -0
- data/lib/crystal/template.rb +21 -0
- data/lib/crystal/template/support/tilt.rb +68 -0
- data/lib/crystal/template/template.rb +244 -0
- data/lib/crystal/template/template_context.rb +57 -0
- data/lib/views/crystal_default_templates/development/error.html.erb +11 -0
- data/lib/views/crystal_default_templates/development/error.js.erb +1 -0
- data/readme.md +8 -11
- data/spec/_mailer/basic_spec.rb +110 -0
- data/spec/_mailer/helper.rb +7 -0
- data/spec/controller/abstract_controller_spec.rb +137 -0
- data/spec/controller/abstract_controller_spec/views/OperationsOrderSpec/action.erb +1 -0
- data/spec/controller/abstract_controller_spec/views/ViewVariablesSpec/action.erb +10 -0
- data/spec/controller/controller_context_spec.rb +122 -0
- data/spec/controller/controller_context_spec/views/ItemSpec/actions.erb +4 -0
- data/spec/controller/controller_context_spec/views/ItemSpec/show.erb +0 -0
- data/spec/controller/controller_context_spec/views/ItemSpec/update.erb +0 -0
- data/spec/controller/controller_context_spec/views/NamespaceSpec/ClassSpec/show.erb +0 -0
- data/spec/controller/controller_context_spec/views/PageSpec/actions.erb +3 -0
- data/spec/controller/controller_context_spec/views/PageSpec/show.erb +0 -0
- data/spec/controller/controller_context_spec/views/namespace_spec/class_spec/update.erb +0 -0
- data/spec/controller/controller_helper_spec.rb +57 -0
- data/spec/controller/controller_helper_spec/views/HelperMethodSpec/action.erb +1 -0
- data/spec/controller/controller_helper_spec/views/HelperSpec/action.erb +1 -0
- data/spec/controller/controller_render_spec.rb +191 -0
- data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/custom_template.erb +1 -0
- data/spec/controller/controller_render_spec/views/AnotherActionSpec/another_action.erb +1 -0
- data/spec/controller/controller_render_spec/views/AnotherLayout/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/ExplicitRenderSpec/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/ExplicitRenderSpec/another_action.erb +1 -0
- data/spec/controller/controller_render_spec/views/ForbidPartialAsActionSpec/_action.erb +1 -0
- data/spec/controller/controller_render_spec/views/FormatSpec/action.html.erb +1 -0
- data/spec/controller/controller_render_spec/views/FormatSpec/action.js.erb +1 -0
- data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_with_layout.erb +1 -0
- data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_without_layout.erb +1 -0
- data/spec/controller/controller_render_spec/views/LayoutSpec/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/layouts/admin.erb +1 -0
- data/spec/controller/controller_render_spec/views/layouts/app.html.erb +1 -0
- data/spec/controller/controller_render_spec/views/layouts/app.js.erb +1 -0
- data/spec/controller/controller_render_spec/views/some_template.erb +1 -0
- data/spec/controller/controller_render_spec/views/standalone.html.erb +1 -0
- data/spec/controller/error_handling_spec.rb +96 -0
- data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/a.erb +1 -0
- data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/b.erb +1 -0
- data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/c.erb +1 -0
- data/spec/controller/helper.rb +21 -0
- data/spec/controller/http_controller_spec.rb +89 -0
- data/spec/conveyor/conveyor_spec.rb +124 -0
- data/spec/conveyor/helper.rb +8 -0
- data/spec/environment/_dependency_resolver_spec.rb +50 -0
- data/spec/environment/environment_spec.rb +85 -0
- data/spec/environment/environment_spec/app/app_plugin/config/ec_layout +1 -0
- data/spec/environment/environment_spec/app/app_plugin/ec_some_file +1 -0
- data/spec/environment/environment_spec/app/config/config.test.yml +1 -0
- data/spec/environment/environment_spec/app/config/config.yml +2 -0
- data/spec/environment/environment_spec/gem_plugin/config/ec_layout +1 -0
- data/spec/environment/helper.rb +6 -0
- data/spec/environment/logger_spec.rb +18 -0
- data/spec/environment/minimal_app_spec.rb +27 -0
- data/spec/environment/minimal_app_spec/app.rb +3 -0
- data/spec/environment/standard_app_spec.rb +63 -0
- data/spec/environment/standard_app_spec_data/config/init.rb +18 -0
- data/spec/environment/standard_app_spec_data/plugin_a/plugin_a.rb +7 -0
- data/spec/html/basic_html_helper_spec.rb +28 -0
- data/spec/html/flash_spec.rb +184 -0
- data/spec/html/form_helper_spec.rb +56 -0
- data/spec/html/helper.rb +31 -0
- data/spec/html/javascript_helper_spec.rb +15 -0
- data/spec/html/model_helper_spec.rb +65 -0
- data/spec/html/scoped_params_spec.rb +17 -0
- data/spec/html/url_helper_spec.rb +151 -0
- data/spec/http/helper.rb +9 -0
- data/spec/http/http_spec.rb +56 -0
- data/spec/http/http_spec_data/config/init.rb +7 -0
- data/spec/http/http_spec_data/plugin_b/plugin_b.rb +6 -0
- data/spec/integration/basic_spec.rb +82 -0
- data/spec/integration/basic_spec/views/smoke_test_spec/action.erb +1 -0
- data/spec/integration/helper.rb +10 -0
- data/spec/remote/helper.rb +20 -0
- data/spec/remote/remote_spec.rb +75 -0
- data/spec/router/basic_spec.rb +130 -0
- data/spec/router/configurator_spec.rb +29 -0
- data/spec/router/helper.rb +24 -0
- data/spec/router/integration_spec.rb +42 -0
- data/spec/spec.opts +4 -0
- data/spec/support/callbacks_spec.rb +153 -0
- data/spec/support/filters_spec.rb +59 -0
- data/spec/support/helper.rb +7 -0
- data/spec/support/safe_hash_spec.rb +82 -0
- data/spec/template/helper.rb +8 -0
- data/spec/template/template_spec.rb +189 -0
- data/spec/template/template_spec/file.erb +1 -0
- data/spec/template/template_spec/views/basic/custom_context.erb +1 -0
- data/spec/template/template_spec/views/basic/extension.erb +1 -0
- data/spec/template/template_spec/views/basic/general.html.erb +5 -0
- data/spec/template/template_spec/views/basic/non_existing_format.html.erb +0 -0
- data/spec/template/template_spec/views/format/format.erb +1 -0
- data/spec/template/template_spec/views/format/format.html.erb +1 -0
- data/spec/template/template_spec/views/format/format.js.erb +1 -0
- data/spec/template/template_spec/views/layout/basic/content.erb +1 -0
- data/spec/template/template_spec/views/layout/basic/layout.erb +1 -0
- data/spec/template/template_spec/views/layout/content_for/content.erb +3 -0
- data/spec/template/template_spec/views/layout/content_for/layout.erb +3 -0
- data/spec/template/template_spec/views/layout/format/content.html.erb +1 -0
- data/spec/template/template_spec/views/layout/format/content.js.erb +1 -0
- data/spec/template/template_spec/views/layout/format/layout.html.erb +1 -0
- data/spec/template/template_spec/views/layout/format/layout.js.erb +1 -0
- data/spec/template/template_spec/views/layout/nested_yield/a.erb +1 -0
- data/spec/template/template_spec/views/layout/nested_yield/layout.erb +1 -0
- data/spec/template/template_spec/views/layout/nested_yield/layout_b.erb +1 -0
- data/spec/template/template_spec/views/layout/same_context/a.erb +1 -0
- data/spec/template/template_spec/views/layout/same_context/b.erb +1 -0
- data/spec/template/template_spec/views/layout/same_context/layout.erb +1 -0
- data/spec/template/template_spec/views/nested/format/a.erb +1 -0
- data/spec/template/template_spec/views/nested/format/b.erb +1 -0
- data/spec/template/template_spec/views/nested/relative/a.erb +1 -0
- data/spec/template/template_spec/views/nested/relative/b.erb +1 -0
- data/spec/template/template_spec/views/nested/relative/c.erb +1 -0
- data/spec/template/template_spec/views/nested/shared/c.erb +1 -0
- data/spec/template/template_spec/views/nesting_format/_dialog.html.erb +1 -0
- data/spec/template/template_spec/views/nesting_format/_form.html.erb +1 -0
- data/spec/template/template_spec/views/nesting_format/dialog.js.erb +1 -0
- data/spec/template/template_spec/views/other/template.erb +1 -0
- data/spec/template/template_spec/views/prefixes/_underscored.erb +1 -0
- data/spec/template/template_spec/views/prefixes/without_prefix.erb +1 -0
- data/spec/template/tilt_spec.rb +96 -0
- data/spec/template/tilt_spec/views/concat_and_capture.erb +1 -0
- data/spec/template/tilt_spec/views/concat_and_capture.haml +3 -0
- data/spec/template/tilt_spec/views/errors.erb +3 -0
- data/spec/template/tilt_spec/views/errors.haml +3 -0
- data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_erb.erb +4 -0
- data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_haml.haml +1 -0
- data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_erb.erb +1 -0
- data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_haml.haml +2 -0
- data/spec/template/tilt_spec/views/nested_capture_and_concat.haml +3 -0
- data/spec/template/tilt_spec/views/ugly.haml +3 -0
- data/spec/template/tilt_spec/views/yield.erb +1 -0
- metadata +303 -33
- data/lib/crystal_ext/defer_js.rb +0 -75
- data/lib/crystal_ext/ensure_no_www.rb +0 -39
- data/lib/crystal_ext/gems.rb +0 -2
- data/lib/crystal_ext/i18n.rb +0 -25
- data/lib/crystal_ext/i18n/locales/ru/pluralization.rb +0 -62
- data/lib/crystal_ext/plugin.rb +0 -23
- data/lib/crystal_ext/plugin/app.rb +0 -19
- data/lib/crystal_ext/plugin/web.rb +0 -44
- data/lib/crystal_ext/prepare_model.rb +0 -20
- data/lib/crystal_ext/profiles/web_ext_require.rb +0 -13
- data/lib/crystal_ext/protect_from_forgery.rb +0 -66
- data/lib/crystal_ext/user_error.rb +0 -14
- data/spec/controller_spec_helper.rb +0 -19
- data/spec/defer_js_spec.rb +0 -33
- data/spec/i18n_spec.rb +0 -31
- data/spec/i18n_spec/locales/en/general.yml +0 -5
- data/spec/i18n_spec/locales/ru/general.yml +0 -7
- data/spec/prepare_model_spec.rb +0 -43
- data/spec/protect_from_forgery_spec.rb +0 -169
- data/spec/spec_helper.rb +0 -4
- data/spec/user_error_spec.rb +0 -41
@@ -0,0 +1 @@
|
|
1
|
+
content
|
@@ -0,0 +1 @@
|
|
1
|
+
custom content
|
@@ -0,0 +1 @@
|
|
1
|
+
another action
|
@@ -0,0 +1 @@
|
|
1
|
+
action
|
@@ -0,0 +1 @@
|
|
1
|
+
action
|
@@ -0,0 +1 @@
|
|
1
|
+
another action
|
@@ -0,0 +1 @@
|
|
1
|
+
partial content
|
@@ -0,0 +1 @@
|
|
1
|
+
html format
|
@@ -0,0 +1 @@
|
|
1
|
+
js format
|
@@ -0,0 +1 @@
|
|
1
|
+
content
|
@@ -0,0 +1 @@
|
|
1
|
+
content
|
@@ -0,0 +1 @@
|
|
1
|
+
content
|
@@ -0,0 +1 @@
|
|
1
|
+
Admin layout, <%= yield %>
|
@@ -0,0 +1 @@
|
|
1
|
+
Layout html, <%= yield %>
|
@@ -0,0 +1 @@
|
|
1
|
+
Layout js, <%= yield %>
|
@@ -0,0 +1 @@
|
|
1
|
+
some template
|
@@ -0,0 +1 @@
|
|
1
|
+
standalone usage, <%= a %>
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "Error handling" do
|
4
|
+
with_environment :test
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
@dir = "#{File.expand_path(File.dirname(__FILE__))}/error_handling_spec"
|
8
|
+
$LOAD_PATH << @dir
|
9
|
+
AbstractController = Crystal::AbstractController
|
10
|
+
|
11
|
+
crystal.before :environment do
|
12
|
+
crystal.config.test_error_template = crystal.config.development_error_template!
|
13
|
+
end
|
14
|
+
|
15
|
+
crystal.after :environment do
|
16
|
+
crystal.conveyors.web do |web|
|
17
|
+
web.use Crystal::Processors::ControllerErrorHandling, :content
|
18
|
+
web.use Crystal::Processors::ControllerCaller, :content
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
after :all do
|
24
|
+
$LOAD_PATH.delete @dir
|
25
|
+
remove_constants %w(
|
26
|
+
DisplayErrorWithFormat
|
27
|
+
DiferrentErrorHandlingSpec
|
28
|
+
AbstractController
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should correctly display error messages in :development (with correct format)" do
|
33
|
+
class ::DisplayErrorWithFormat
|
34
|
+
inherit AbstractController
|
35
|
+
|
36
|
+
def method
|
37
|
+
raise params.error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
config.environment = :development
|
42
|
+
silence_logger!
|
43
|
+
|
44
|
+
error = StandardError.new('some error')
|
45
|
+
|
46
|
+
ccall(
|
47
|
+
DisplayErrorWithFormat, :method,
|
48
|
+
{:error => error, :format => :html}
|
49
|
+
).content.should =~ /html.+some error/m
|
50
|
+
|
51
|
+
ccall(
|
52
|
+
DisplayErrorWithFormat, :method,
|
53
|
+
{:error => error, :format => :js}
|
54
|
+
).content.should =~ /some error/
|
55
|
+
|
56
|
+
ccall(
|
57
|
+
DisplayErrorWithFormat, :method,
|
58
|
+
{:error => error, :format => :non_existing_mime}
|
59
|
+
).content.should =~ /some error/
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "should be different in :test, :development and :production" do
|
63
|
+
before :all do
|
64
|
+
class ::DiferrentErrorHandlingSpec
|
65
|
+
inherit AbstractController
|
66
|
+
|
67
|
+
def a; end
|
68
|
+
def b
|
69
|
+
raise 'error in remote'
|
70
|
+
end
|
71
|
+
def c; end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it "in :production errors shouldn't be shown to user"
|
76
|
+
|
77
|
+
it "in development errors should be catched" do
|
78
|
+
config.environment = :development
|
79
|
+
silence_logger!
|
80
|
+
|
81
|
+
# with view
|
82
|
+
ccall(DiferrentErrorHandlingSpec, :a).content.should == 'a'
|
83
|
+
ccall(DiferrentErrorHandlingSpec, :b).content.should =~ /error in remote/
|
84
|
+
ccall(DiferrentErrorHandlingSpec, :c).content.should =~ /error in template/
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not catch errors in :test environment" do
|
88
|
+
config.environment = :test
|
89
|
+
|
90
|
+
# with render
|
91
|
+
ccall(DiferrentErrorHandlingSpec, :a).content.should == 'a'
|
92
|
+
lambda{ccall(DiferrentErrorHandlingSpec, :b)}.should raise_error(/error in remote/)
|
93
|
+
lambda{ccall(DiferrentErrorHandlingSpec, :c)}.should raise_error(/error in template/)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
a
|
@@ -0,0 +1 @@
|
|
1
|
+
b
|
@@ -0,0 +1 @@
|
|
1
|
+
<% raise 'error in template' %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
dir = File.dirname __FILE__
|
2
|
+
crystal_dir = File.expand_path "#{dir}/../.."
|
3
|
+
lib_dir = "#{crystal_dir}/lib"
|
4
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include? lib_dir
|
5
|
+
|
6
|
+
require 'crystal/controller'
|
7
|
+
require 'crystal/http'
|
8
|
+
|
9
|
+
require 'crystal/spec'
|
10
|
+
|
11
|
+
Spec::Example::ExampleGroup.class_eval do
|
12
|
+
def self.with_abstract_controller_spec
|
13
|
+
before :all do
|
14
|
+
crystal.after :environment do
|
15
|
+
crystal.conveyors.web do |web|
|
16
|
+
web.use Crystal::Processors::ControllerCaller, :content
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "HttpController" do
|
4
|
+
with_environment :test
|
5
|
+
with_http
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
@dir = "#{File.expand_path(File.dirname(__FILE__))}/http_controller_spec"
|
9
|
+
$LOAD_PATH << @dir
|
10
|
+
HttpController = Crystal::HttpController
|
11
|
+
|
12
|
+
crystal.after :environment do
|
13
|
+
crystal.conveyors.web do |web|
|
14
|
+
web.use Crystal::Processors::HttpWriter, :content
|
15
|
+
web.use Crystal::Processors::ControllerCaller, :content
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
after :all do
|
21
|
+
$LOAD_PATH.delete @dir
|
22
|
+
remove_constants %w(
|
23
|
+
HttpController
|
24
|
+
ContentTypeSpec
|
25
|
+
StatusSpec
|
26
|
+
LocationSpec
|
27
|
+
ForbidGetSpec
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'render' do
|
32
|
+
it "should take :content_type option" do
|
33
|
+
class ::ContentTypeSpec
|
34
|
+
inherit HttpController
|
35
|
+
|
36
|
+
def action
|
37
|
+
render :inline => "some content", :content_type => Mime['js']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
wcall(ContentTypeSpec, :action)
|
42
|
+
response.content_type.should == "application/javascript"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should take :status option" do
|
46
|
+
class ::StatusSpec
|
47
|
+
inherit HttpController
|
48
|
+
|
49
|
+
def action
|
50
|
+
render :inline => "some content", :status => 220
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
wcall(StatusSpec, :action)
|
55
|
+
response.status.should == 220
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should take :location option" do
|
59
|
+
class ::LocationSpec
|
60
|
+
inherit HttpController
|
61
|
+
|
62
|
+
def action
|
63
|
+
render :location => "/", :status => 220
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
wcall(LocationSpec, :action)
|
68
|
+
response.location.should == "/"
|
69
|
+
response.status.should == 220
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should be able to protect methods from GET request" do
|
74
|
+
class ::ForbidGetSpec
|
75
|
+
inherit HttpController
|
76
|
+
allow_get_for :get_action
|
77
|
+
|
78
|
+
def get_action; end
|
79
|
+
def post_action; end
|
80
|
+
end
|
81
|
+
|
82
|
+
workspace = {:env => {'REQUEST_METHOD' => 'GET'}}
|
83
|
+
|
84
|
+
wcall(ForbidGetSpec, :get_action, workspace, {})
|
85
|
+
lambda{
|
86
|
+
wcall(ForbidGetSpec, :post_action, workspace, {})
|
87
|
+
}.should raise_error(/not allowed/)
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "Conveyor" do
|
4
|
+
inject :conveyors => :conveyors
|
5
|
+
|
6
|
+
with_environment :development
|
7
|
+
|
8
|
+
def call_conveyor
|
9
|
+
r = conveyors.web.call(:result => [])
|
10
|
+
r.result
|
11
|
+
end
|
12
|
+
|
13
|
+
it "smoke test" do
|
14
|
+
class SmokeTestASpec < Crystal::Processor
|
15
|
+
def call
|
16
|
+
workspace.result << :a_before
|
17
|
+
next_processor.call
|
18
|
+
workspace.result << :a_after
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class SmokeTestBSpec < Crystal::Processor
|
23
|
+
def call
|
24
|
+
crystal[:workspace].result << :b_before
|
25
|
+
next_processor.call
|
26
|
+
crystal[:workspace].result << :b_after
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
conveyors.web.use SmokeTestASpec
|
31
|
+
conveyors.web.use SmokeTestBSpec
|
32
|
+
call_conveyor.should == [:a_before, :b_before, :b_after, :a_after]
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "error handling" do
|
36
|
+
it "common case" do
|
37
|
+
class CommonCaseASpec < Crystal::Processor
|
38
|
+
def call
|
39
|
+
workspace.result << :a_before
|
40
|
+
|
41
|
+
begin
|
42
|
+
next_processor.call
|
43
|
+
rescue StandardError => e
|
44
|
+
workspace.result << e.message
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class CommonCaseBSpec < Crystal::Processor
|
50
|
+
def call
|
51
|
+
workspace.result << :b_before
|
52
|
+
raise 'error before'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
conveyors.web.use CommonCaseASpec
|
57
|
+
conveyors.web.use CommonCaseBSpec
|
58
|
+
call_conveyor.should == [:a_before, :b_before, "error before"]
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should raise error if not catched" do
|
62
|
+
class NotCatchedErrorSpec < Crystal::Processor
|
63
|
+
def call
|
64
|
+
workspace.result << :before
|
65
|
+
raise 'error before'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
conveyors.web.use NotCatchedErrorSpec
|
70
|
+
lambda{call_conveyor}.should raise_error(/error before/)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "in after block" do
|
74
|
+
class ErrorInAfterBlockASpec < Crystal::Processor
|
75
|
+
def call
|
76
|
+
workspace.result << :a_before
|
77
|
+
|
78
|
+
begin
|
79
|
+
next_processor.call
|
80
|
+
rescue StandardError => e
|
81
|
+
workspace.result << e.message
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
class ErrorInAfterBlockBSpec < Crystal::Processor
|
88
|
+
def call
|
89
|
+
workspace.result << :b_before
|
90
|
+
next_processor.call
|
91
|
+
raise 'error after'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
conveyors.web.use ErrorInAfterBlockASpec
|
97
|
+
conveyors.web.use ErrorInAfterBlockBSpec
|
98
|
+
call_conveyor.should == [:a_before, :b_before, "error after"]
|
99
|
+
end
|
100
|
+
|
101
|
+
it "bubbling (from error)" do
|
102
|
+
class ErrorBubblingASpec < Crystal::Processor
|
103
|
+
def call
|
104
|
+
begin
|
105
|
+
next_processor.call
|
106
|
+
rescue RuntimeError => e
|
107
|
+
workspace.result << e.message
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class ErrorBubblingBSpec < Crystal::Processor
|
113
|
+
def call
|
114
|
+
raise 'error'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
conveyors.web.use ErrorBubblingASpec
|
119
|
+
conveyors.web.use ErrorBubblingBSpec
|
120
|
+
|
121
|
+
call_conveyor.should == ['error']
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
# require 'crystal/support'
|
3
|
+
# require 'crystal/environment/dependency_resolver'
|
4
|
+
#
|
5
|
+
# describe "Dependency resolver" do
|
6
|
+
# before :each do
|
7
|
+
# @dr = Crystal::DependencyResolver.new
|
8
|
+
# @result = []
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# attr_reader :result
|
12
|
+
#
|
13
|
+
# def add s
|
14
|
+
# @result << s
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# def run *args, &block
|
18
|
+
# @dr.run *args, &block
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# def load token
|
22
|
+
# @dr.call(token)
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# it "should be ordered" do
|
26
|
+
# run(:init){add :init}
|
27
|
+
# run(:a, :after => :init){add :a}
|
28
|
+
# run(:b, :after => :a){add :b}
|
29
|
+
# run(:c, :after => :b){add :c}
|
30
|
+
#
|
31
|
+
# load :init
|
32
|
+
#
|
33
|
+
# result.should == [:init, :a, :b, :c]
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# it "should be ordered 2 (from error)" do
|
37
|
+
# run(:init){add :init}
|
38
|
+
# run(:_b, :before => :init){add :_b}
|
39
|
+
# run(:b_, :after => :init){add :b_}
|
40
|
+
#
|
41
|
+
# run(:_c, :before => :_b){add :_c}
|
42
|
+
# run(:c_, :after => :b_){add :c_}
|
43
|
+
#
|
44
|
+
# run(:_a, :before => :init){add :_a}
|
45
|
+
# run(:a_, :after => :init){add :a_}
|
46
|
+
#
|
47
|
+
# load :init
|
48
|
+
# result.should == [:_c, :_b, :_a, :init, :b_, :a_, :c_]
|
49
|
+
# end
|
50
|
+
# end
|