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
|
+
some content
|
@@ -0,0 +1,20 @@
|
|
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/remote'
|
7
|
+
|
8
|
+
require 'crystal/spec/remote'
|
9
|
+
|
10
|
+
Spec::Example::ExampleGroup.class_eval do
|
11
|
+
def self.with_remote_spec
|
12
|
+
before :all do
|
13
|
+
crystal.after :environment do
|
14
|
+
crystal.conveyors.services do |ss|
|
15
|
+
ss.use Crystal::Processors::RemoteCaller, :content
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "Remote Basic" do
|
4
|
+
with_environment :test
|
5
|
+
with_remote_spec
|
6
|
+
|
7
|
+
it "basic" do
|
8
|
+
class BasicSpec
|
9
|
+
inherit Crystal::Remote
|
10
|
+
|
11
|
+
def call
|
12
|
+
{:result => 'some result'}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
workspace = rcall BasicSpec, :call, :format => 'json'
|
17
|
+
|
18
|
+
workspace.delete(:remote_object).should be_a(BasicSpec)
|
19
|
+
expected_result = {
|
20
|
+
:params => {"format" => "json"},
|
21
|
+
|
22
|
+
:class => BasicSpec,
|
23
|
+
:method_name => "call",
|
24
|
+
|
25
|
+
:remote_result => {:result => "some result"},
|
26
|
+
:content => %({"result":"some result"})
|
27
|
+
}
|
28
|
+
workspace.to_h(true).symbolize_keys.subset(expected_result.keys).should == expected_result
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "error handling should behave different in :production, :development and :test modes" do
|
32
|
+
it "error in :development mode" do
|
33
|
+
class JsonErrorSpec
|
34
|
+
inherit Crystal::Remote
|
35
|
+
|
36
|
+
def call_with_error
|
37
|
+
raise 'some error'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
config.environment = :development
|
42
|
+
silence_logger!
|
43
|
+
|
44
|
+
workspace = rcall JsonErrorSpec, 'call_with_error', :format => 'json'
|
45
|
+
|
46
|
+
workspace.delete(:remote_object).should be_a(JsonErrorSpec)
|
47
|
+
workspace.include?(:remote_result).should be_false
|
48
|
+
expected_result = {
|
49
|
+
:params => {"format" => "json"},
|
50
|
+
|
51
|
+
:class => JsonErrorSpec,
|
52
|
+
:method_name => "call_with_error",
|
53
|
+
|
54
|
+
:content => %({"error":"some error"})
|
55
|
+
}
|
56
|
+
workspace.to_h.symbolize_keys.subset(expected_result.keys).should == expected_result
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should be able to protect methods from GET request"
|
61
|
+
|
62
|
+
it "should not allow unregistered object types be used as return value" do
|
63
|
+
class UnregisteredReturnValueSpec
|
64
|
+
inherit Crystal::Remote
|
65
|
+
|
66
|
+
def call
|
67
|
+
Object.new
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
lambda{
|
72
|
+
rcall UnregisteredReturnValueSpec, 'call', :format => 'json'
|
73
|
+
}.should raise_error(/You can't use object of type 'Object' as Remote's return value!/)
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "Router Basic" do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
class ::SomeController
|
7
|
+
def call; end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
after :all do
|
12
|
+
remove_constants %w(
|
13
|
+
SomeController
|
14
|
+
BlogControllerSpec
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
before :each do
|
19
|
+
@router = Crystal::Router.new :class
|
20
|
+
# @router.routes.push :default_router, Crystal::DefaultRouter.new
|
21
|
+
|
22
|
+
@params = OpenObject.new
|
23
|
+
@router.stub(:workspace).and_return({:params => @params}.to_openobject)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "encode" do
|
27
|
+
@router.encode(SomeController, :call, :format => :json).should == ["/some_controller/call.json", {}]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "decode" do
|
31
|
+
@router.decode("/some_controller/call", {}).should == [SomeController, 'call', {}]
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "named routes" do
|
35
|
+
before :all do
|
36
|
+
class BlogControllerSpec
|
37
|
+
def call; end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
before :each do
|
42
|
+
@router.routes.unshift :named_router, Crystal::NamedRouter.new
|
43
|
+
@router.routes[:named_router].add 'some/path', SomeController
|
44
|
+
@router.routes[:named_router].add 'blog', BlogControllerSpec
|
45
|
+
|
46
|
+
@named_router = @router.routes[:named_router]
|
47
|
+
|
48
|
+
@helper = Object.new
|
49
|
+
@helper.extend Crystal::NamedRouter::Helper
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should encode and decode using named route" do
|
53
|
+
@router.encode(SomeController, :call, :format => :json).should == ["/some/path/call.json", {}]
|
54
|
+
@router.decode("/some/path/call", {}).should == [SomeController, 'call', {}]
|
55
|
+
|
56
|
+
@router.encode(BlogControllerSpec, :call, :format => :json).should == ["/blog/call.json", {}]
|
57
|
+
@router.decode("/blog/call", {}).should == [BlogControllerSpec, 'call', {}]
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should generate <method_name>_<route_name>_path methods (on the fly)" do
|
61
|
+
@named_router.encode_route_method('show_blog_path').should == ["/blog/show", {}]
|
62
|
+
lambda{@named_router.encode_route_method('show_unknown_path')}.should raise_error(/Unknown route/)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should provide helper" do
|
66
|
+
crystal.register :router
|
67
|
+
crystal[:router] = @router
|
68
|
+
@helper.show_blog_path.should == ["/blog/show", {}]
|
69
|
+
lambda{@helper.show_blog}.should raise_error(/undefined method/)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "url_for" do
|
74
|
+
it "should convert complex params to json" do
|
75
|
+
@router.url_for(SomeController, :call, :a => :b, :as_json => true).should == %(/some_controller/call?json=%7B%22a%22%3A%22b%22%7D)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should escape params" do
|
79
|
+
@router.url_for(SomeController, :call, :a => 'b/c').should == "/some_controller/call?a=b%2Fc"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "url_for_remote" do
|
83
|
+
@router.stub(:current_class).and_return(SomeController)
|
84
|
+
|
85
|
+
@router.url_for(SomeController, :call, :format => :json).should == "/some_controller/call.json"
|
86
|
+
@router.url_for(:call, :format => :json).should == "/some_controller/call.json"
|
87
|
+
|
88
|
+
@router.url_for(SomeController, :call).should == "/some_controller/call"
|
89
|
+
@router.url_for(:call).should == "/some_controller/call"
|
90
|
+
@router.url_for('call').should == "/some_controller/call"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "url_for_path should recognize first slash as to use url_for_path" do
|
94
|
+
@router.url_for('/some_path', :key => :value).should == "/some_path?key=value"
|
95
|
+
@router.url_for('/some_path').should == "/some_path"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should mark url string with format" do
|
99
|
+
@router.stub(:current_class).and_return(SomeController)
|
100
|
+
@router.url_for(:call, :format => :js).marks.format.to_s.should == 'js'
|
101
|
+
|
102
|
+
@router.url_for('/path').marks.format.should be_nil
|
103
|
+
@router.url_for('/path', :format => :js).marks.format.to_s.should == 'js'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "persistent params" do
|
108
|
+
before :each do
|
109
|
+
@router.global_persistent_params << :l
|
110
|
+
end
|
111
|
+
|
112
|
+
it "global persistent params" do
|
113
|
+
@params.l, @params.id = 'ru', 1
|
114
|
+
|
115
|
+
@router.url_for('/path').should == "/path?l=ru"
|
116
|
+
@router.url_for('/path', :l => 'en').should == "/path?l=en"
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should persist params with begining underscore" do
|
120
|
+
@params._space, @params.id = 'space_id', 1
|
121
|
+
|
122
|
+
@router.url_for('/path').should == '/path'
|
123
|
+
|
124
|
+
@router.persist_params do
|
125
|
+
@router.url_for('/path').should == '/path?_space=space_id'
|
126
|
+
@router.url_for('/path', :_space => 'another_id').should == '/path?_space=another_id'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "Configurator" do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
class ::BlogControllerSpec; end
|
7
|
+
end
|
8
|
+
|
9
|
+
after :all do
|
10
|
+
remove_constants %w(BlogControllerSpec)
|
11
|
+
end
|
12
|
+
|
13
|
+
before :each do
|
14
|
+
@named_router = Crystal::NamedRouter.new
|
15
|
+
|
16
|
+
@router = Crystal::Router.new :class
|
17
|
+
@router.routes.unshift :named_router, @named_router
|
18
|
+
|
19
|
+
Crystal::Routes::Configurator.stub(:router).and_return(@router)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "named routes" do
|
23
|
+
crystal.routes do |config|
|
24
|
+
config.named_route 'blog', BlogControllerSpec
|
25
|
+
end
|
26
|
+
|
27
|
+
@named_router.names.should include('blog')
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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/http'
|
7
|
+
require 'crystal/router'
|
8
|
+
|
9
|
+
require 'spec_ext'
|
10
|
+
require 'crystal/spec/environment'
|
11
|
+
|
12
|
+
Spec::Example::ExampleGroup.class_eval do
|
13
|
+
def self.with_router_spec
|
14
|
+
before :all do
|
15
|
+
crystal.after :environment do
|
16
|
+
crystal.register :router, :depends_on => :environment do
|
17
|
+
Crystal::Router.new(:class, [[:default_router, Crystal::DefaultRouter.new]])
|
18
|
+
end
|
19
|
+
|
20
|
+
crystal.conveyors.web.use Crystal::Processors::Router, :class_variable, :method_variable
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "Remote Basic" do
|
4
|
+
with_environment :test
|
5
|
+
with_router_spec
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
class ::AnRemote
|
9
|
+
def call; end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
after :all do
|
14
|
+
remove_constants %w(AnRemote)
|
15
|
+
end
|
16
|
+
|
17
|
+
def call_router path, params
|
18
|
+
crystal.conveyors.web.call :path => path, :params => Crystal::Params.new(params)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "basic" do
|
22
|
+
workspace = call_router '/an_remote/call', :format => 'json'
|
23
|
+
|
24
|
+
expected_result = {
|
25
|
+
:path => "/an_remote/call",
|
26
|
+
:params => {"format" => "json"}, #, 'method_name' => 'call', 'class_name' => 'AnRemote'},
|
27
|
+
|
28
|
+
:class_variable => AnRemote,
|
29
|
+
:method_variable => "call"
|
30
|
+
}
|
31
|
+
workspace.to_h(true).symbolize_keys.subset(expected_result.keys).should == expected_result
|
32
|
+
end
|
33
|
+
|
34
|
+
it "params must be casted to string" do
|
35
|
+
workspace = call_router '/an_remote/call', :a => 'b'
|
36
|
+
workspace.params.to_h.subset('a').should == {'a' => 'b'}
|
37
|
+
end
|
38
|
+
|
39
|
+
it "default router should raise error if route is invalid" do
|
40
|
+
lambda{call_router '/invalid/call', :format => 'json'}.should raise_error(/uninitialized constant Invalid/)
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
require "crystal/support/callbacks"
|
3
|
+
|
4
|
+
describe "Callbacks" do
|
5
|
+
before :all do
|
6
|
+
class BasicCallbacksSpec
|
7
|
+
inherit Crystal::Callbacks
|
8
|
+
|
9
|
+
set_callback :callback_name, :before, :before_callback
|
10
|
+
set_callback :callback_name, :after, :after_callback
|
11
|
+
set_callback :callback_name, :around, :around_callback
|
12
|
+
|
13
|
+
protected
|
14
|
+
def around_callback
|
15
|
+
around_callback_called
|
16
|
+
yield
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "basic" do
|
22
|
+
o = BasicCallbacksSpec.new
|
23
|
+
o.should_receive :before_callback
|
24
|
+
o.should_receive :around_callback_called
|
25
|
+
o.should_receive :after_callback
|
26
|
+
o.run_callbacks(:callback_name){"result"}.should == "result"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "blocks" do
|
30
|
+
class BlockCallbacksSpec
|
31
|
+
inherit Crystal::Callbacks
|
32
|
+
|
33
|
+
set_callback(:callback_name, :before){|controller| controller.result << :before}
|
34
|
+
set_callback :callback_name, :around do |controller, block|
|
35
|
+
begin
|
36
|
+
controller.result << :around_begin
|
37
|
+
block.call
|
38
|
+
ensure
|
39
|
+
controller.result << :around_end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
set_callback(:callback_name, :after){|controller| controller.result << :after}
|
43
|
+
|
44
|
+
def result
|
45
|
+
@result ||= []
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
o = BlockCallbacksSpec.new
|
50
|
+
o.run_callbacks(:callback_name){"result"}.should == "result"
|
51
|
+
o.result.should == [:before, :around_begin, :after, :around_end]
|
52
|
+
end
|
53
|
+
|
54
|
+
it "inheritance" do
|
55
|
+
class InheritedCallbacksSpec < BasicCallbacksSpec
|
56
|
+
set_callback :callback_name, :before, :before_callback2
|
57
|
+
end
|
58
|
+
|
59
|
+
o = InheritedCallbacksSpec.new
|
60
|
+
o.should_receive :before_callback
|
61
|
+
o.should_receive :before_callback2
|
62
|
+
o.should_receive :around_callback_called
|
63
|
+
o.should_receive :after_callback
|
64
|
+
o.run_callbacks(:callback_name){"result"}.should == "result"
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'terminator' do
|
68
|
+
class CallbackTerminatorSpec
|
69
|
+
inherit Crystal::Callbacks
|
70
|
+
|
71
|
+
set_callback :callback_name, :before, :before_callback, :terminator => false
|
72
|
+
set_callback :callback_name, :before, :before_callback2
|
73
|
+
|
74
|
+
def method
|
75
|
+
run_callbacks :callback_name do
|
76
|
+
"result"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
protected
|
81
|
+
def before_callback
|
82
|
+
false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
o = CallbackTerminatorSpec.new
|
87
|
+
o.should_not_receive :before_callback2
|
88
|
+
o.run_callbacks(:callback_name){"result"}.should_not == "result"
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'conditions' do
|
92
|
+
class CallbackConditionsSpec
|
93
|
+
inherit Crystal::Callbacks
|
94
|
+
|
95
|
+
set_callback :callback_name, :before, :before_callback, :only => :another_method
|
96
|
+
end
|
97
|
+
|
98
|
+
o = CallbackConditionsSpec.new
|
99
|
+
o.should_not_receive :before_callback
|
100
|
+
o.run_callbacks(:callback_name, :method => :method){"result"}.should == 'result'
|
101
|
+
|
102
|
+
o = CallbackConditionsSpec.new
|
103
|
+
o.should_receive :before_callback
|
104
|
+
o.run_callbacks(:callback_name, :method => :another_method){"result"}.should == 'result'
|
105
|
+
end
|
106
|
+
|
107
|
+
it "if, unless conditions" do
|
108
|
+
c = Crystal::Callbacks::AbstractCallback.new
|
109
|
+
c.conditions = {:if => lambda{|target, inf| true}}
|
110
|
+
c.run?(nil, {}).should be_true
|
111
|
+
|
112
|
+
c.conditions = {:if => lambda{|target, inf| false}}
|
113
|
+
c.run?(nil, {}).should be_false
|
114
|
+
|
115
|
+
c.conditions = {:unless => lambda{|target, inf| true}}
|
116
|
+
c.run?(nil, {}).should be_false
|
117
|
+
|
118
|
+
c.conditions = {:unless => lambda{|target, inf| false}}
|
119
|
+
c.run?(nil, {}).should be_true
|
120
|
+
end
|
121
|
+
|
122
|
+
it "only, except conditions" do
|
123
|
+
c = Crystal::Callbacks::AbstractCallback.new
|
124
|
+
c.conditions = {:only => :a}
|
125
|
+
c.run?(nil, {:method => :a}).should be_true
|
126
|
+
|
127
|
+
c.conditions = {:only => :b}
|
128
|
+
c.run?(nil, {:method => :a}).should be_false
|
129
|
+
|
130
|
+
c.conditions = {:except => :a}
|
131
|
+
c.run?(nil, {:method => :a}).should be_false
|
132
|
+
|
133
|
+
c.conditions = {:except => :b}
|
134
|
+
c.run?(nil, {:method => :a}).should be_true
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
it "around callback should be able to change result value" do
|
139
|
+
class ChangeResultValueSpec
|
140
|
+
inherit Crystal::Callbacks
|
141
|
+
|
142
|
+
set_callback :callback_name, :around, :around_callback
|
143
|
+
|
144
|
+
def around_callback
|
145
|
+
yield
|
146
|
+
'another result'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
o = ChangeResultValueSpec.new
|
151
|
+
o.run_callbacks(:callback_name){"result"}.should == 'another result'
|
152
|
+
end
|
153
|
+
end
|