rad_core 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/bin/rad +20 -25
- data/lib/components/config.rb +1 -1
- data/lib/components/configurators.rb +2 -2
- data/lib/components/controller.rb +2 -2
- data/lib/components/conveyors.rb +2 -2
- data/lib/components/environment.rb +1 -1
- data/lib/components/environment.yml +28 -28
- data/lib/components/flash.rb +1 -1
- data/lib/components/html.rb +1 -1
- data/lib/components/http.rb +1 -1
- data/lib/components/http.yml +1 -1
- data/lib/components/logger.rb +2 -2
- data/lib/components/mailer.rb +2 -2
- data/lib/components/remote.rb +1 -1
- data/lib/components/router.rb +3 -3
- data/lib/components/template.rb +2 -2
- data/lib/components/web.rb +3 -3
- data/lib/rad.rb +1 -1
- data/lib/rad/_support/active_support.rb +7 -7
- data/lib/rad/_support/active_support/locales/ru/actionview.yml +8 -8
- data/lib/rad/_support/active_support/locales/ru/activesupport.yml +4 -4
- data/lib/rad/_support/active_support/locales/ru/datetime.yml +5 -5
- data/lib/rad/_support/active_support/time.rb +2 -2
- data/lib/rad/_support/addressable.rb +6 -6
- data/lib/rad/_support/class_loader.rb +1 -1
- data/lib/rad/_support/extensions.rb +5 -5
- data/lib/rad/_support/filters.rb +13 -13
- data/lib/rad/_support/hacks_and_fixes.rb +5 -5
- data/lib/rad/_support/mime.rb +4 -4
- data/lib/rad/_support/module.rb +11 -11
- data/lib/rad/_support/require.rb +5 -5
- data/lib/rad/_support/rson.rb +4 -4
- data/lib/rad/_support/string.rb +9 -9
- data/lib/rad/cli/helper.rb +5 -5
- data/lib/rad/configurators/_require.rb +2 -2
- data/lib/rad/configurators/abstract.rb +5 -5
- data/lib/rad/configurators/web.rb +8 -8
- data/lib/rad/controller/_abstract.rb +15 -14
- data/lib/rad/controller/_abstract/miscellaneous.rb +5 -5
- data/lib/rad/controller/_abstract/render.rb +40 -40
- data/lib/rad/controller/_abstract/responder.rb +1 -1
- data/lib/rad/controller/_context.rb +1 -1
- data/lib/rad/controller/_http.rb +11 -11
- data/lib/rad/controller/_require.rb +6 -6
- data/lib/rad/controller/processors/controller_caller.rb +3 -3
- data/lib/rad/controller/processors/controller_error_handling.rb +14 -14
- data/lib/rad/controller/processors/controller_logger.rb +1 -1
- data/lib/rad/conveyors/_conveyor.rb +9 -9
- data/lib/rad/conveyors/_conveyors.rb +4 -4
- data/lib/rad/conveyors/_params.rb +5 -5
- data/lib/rad/conveyors/_processor.rb +2 -2
- data/lib/rad/conveyors/_workspace.rb +5 -5
- data/lib/rad/conveyors/processors/conveyor_logger.rb +3 -3
- data/lib/rad/environment/_config.rb +4 -4
- data/lib/rad/environment/_environment.rb +10 -10
- data/lib/rad/environment/_files_helper.rb +5 -5
- data/lib/rad/environment/_logger.rb +9 -9
- data/lib/rad/environment/_require.rb +4 -4
- data/lib/rad/gems.rb +14 -14
- data/lib/rad/html/_flash.rb +5 -5
- data/lib/rad/html/_helpers/basic_html_helper.rb +12 -12
- data/lib/rad/html/_helpers/form_helper.rb +19 -19
- data/lib/rad/html/_helpers/javascript_helper.rb +6 -6
- data/lib/rad/html/_helpers/model_helper.rb +17 -17
- data/lib/rad/html/_require.rb +1 -1
- data/lib/rad/html/processors/prepare_flash.rb +3 -3
- data/lib/rad/html/processors/scoped_params.rb +4 -4
- data/lib/rad/http/_http.rb +4 -4
- data/lib/rad/http/_http_adapter.rb +5 -5
- data/lib/rad/http/_request.rb +11 -11
- data/lib/rad/http/_require.rb +8 -8
- data/lib/rad/http/_response.rb +5 -5
- data/lib/rad/http/_support/rack/fixes.rb +3 -3
- data/lib/rad/http/_support/rack/rack_adapter.rb +5 -5
- data/lib/rad/http/processors/evaluate_format.rb +4 -4
- data/lib/rad/http/processors/http_logger.rb +3 -3
- data/lib/rad/http/processors/http_writer.rb +7 -7
- data/lib/rad/http/processors/prepare_params.rb +5 -5
- data/lib/rad/mailer/_letter.rb +1 -1
- data/lib/rad/mailer/_mailer.rb +1 -1
- data/lib/rad/mailer/_mailer_controller.rb +6 -6
- data/lib/rad/mailer/_require.rb +1 -1
- data/lib/rad/mailer/processors/letter_builder.rb +6 -6
- data/lib/rad/profiles/mailer.rb +2 -2
- data/lib/rad/profiles/web.rb +13 -13
- data/lib/rad/remote/processors/remote_caller.rb +10 -10
- data/lib/rad/remote/processors/remote_logger.rb +1 -1
- data/lib/rad/router/_abstract_router.rb +9 -9
- data/lib/rad/router/_alias_router.rb +34 -34
- data/lib/rad/router/_basic_router.rb +12 -12
- data/lib/rad/router/_configurator.rb +6 -6
- data/lib/rad/router/_core_routing_helper.rb +4 -4
- data/lib/rad/router/_object_router.rb +45 -45
- data/lib/rad/router/_require.rb +8 -8
- data/lib/rad/router/_restful_router.rb +25 -25
- data/lib/rad/router/_router.rb +78 -78
- data/lib/rad/router/_simple_router.rb +5 -5
- data/lib/rad/router/processors/router.rb +6 -6
- data/lib/rad/spec/controller.rb +9 -9
- data/lib/rad/spec/environment.rb +7 -7
- data/lib/rad/spec/http.rb +2 -2
- data/lib/rad/spec/http_controller.rb +22 -22
- data/lib/rad/spec/mailer.rb +4 -4
- data/lib/rad/spec/remote.rb +1 -1
- data/lib/rad/spec/router.rb +4 -4
- data/lib/rad/spec/template.rb +2 -2
- data/lib/rad/tasks.rb +2 -2
- data/lib/rad/template/_context.rb +15 -15
- data/lib/rad/template/_relative_path_resolver.rb +1 -1
- data/lib/rad/template/_support/tilt.rb +17 -17
- data/lib/rad/template/_support/tilt_fixes.rb +3 -3
- data/lib/rad/template/_template.rb +47 -47
- data/lib/rad/web/_ajax_helper.rb +4 -4
- data/lib/rad/web/_controller_miscellaneous_helper.rb +5 -5
- data/lib/rad/web/_ensure_no_www.rb +5 -5
- data/lib/rad/web/_protect_from_forgery.rb +18 -18
- data/lib/rad/web/_require.rb +7 -7
- data/lib/rad/web/_router/abstract_routing_helper.rb +4 -4
- data/lib/rad/web/_router/controller_routing_helper.rb +15 -15
- data/lib/rad/web/_router/view_routing_helper.rb +12 -12
- data/readme.md +5 -5
- data/spec/controller/abstract_spec.rb +29 -29
- data/spec/controller/context_spec.rb +32 -32
- data/spec/controller/error_handling_spec.rb +31 -31
- data/spec/controller/helper_spec.rb +13 -13
- data/spec/controller/http_spec.rb +32 -32
- data/spec/controller/render_spec.rb +59 -59
- data/spec/conveyors/conveyors_spec.rb +32 -32
- data/spec/environment/config_spec.rb +6 -6
- data/spec/environment/environment_spec.rb +7 -7
- data/spec/environment/minimal_app_spec.rb +4 -4
- data/spec/environment/standard_app_spec.rb +10 -10
- data/spec/html/basic_html_helper_spec.rb +6 -6
- data/spec/html/form_helper_spec.rb +5 -5
- data/spec/html/javascript_helper_spec.rb +4 -4
- data/spec/html/model_helper_spec.rb +12 -12
- data/spec/html/scoped_params_spec.rb +2 -2
- data/spec/html/spec_helper.rb +3 -3
- data/spec/http/http_spec.rb +9 -9
- data/spec/http/miscellaneous_spec.rb +2 -2
- data/spec/mailer/mail_controller_spec.rb +23 -23
- data/spec/remote/remote_spec.rb +26 -26
- data/spec/router/alias_router_spec.rb +22 -22
- data/spec/router/basic_router_spec.rb +8 -8
- data/spec/router/configurator_spec.rb +4 -4
- data/spec/router/integration_spec.rb +17 -17
- data/spec/router/object_router_spec.rb +47 -47
- data/spec/router/persistent_params_spec.rb +18 -18
- data/spec/router/restful_router_spec.rb +39 -39
- data/spec/router/router_spec.rb +37 -37
- data/spec/router/routing_helper_spec.rb +18 -18
- data/spec/support/filters_spec.rb +11 -13
- data/spec/template/template_spec.rb +43 -45
- data/spec/template/template_spec/views/layout/content_for/content.erb +3 -1
- data/spec/template/template_spec/views/layout/content_for/layout.erb +1 -1
- data/spec/template/tilt_spec.rb +24 -24
- data/spec/web/basic_spec.rb +25 -25
- data/spec/web/controller_routing_helper_spec.rb +26 -26
- data/spec/web/flash_spec.rb +31 -31
- data/spec/web/protect_from_forgery_spec.rb +44 -44
- data/spec/web/spec_helper_spec.rb +16 -16
- data/spec/web/view_routing_helper_spec.rb +31 -31
- metadata +46 -49
- data/lib/rad/_support/callbacks.rb +0 -166
- data/lib/rad/_support/ruby_ext_with_active_support.rb +0 -4
- data/spec/support/callbacks_spec.rb +0 -157
data/spec/remote/remote_spec.rb
CHANGED
@@ -2,13 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Remote Basic" do
|
4
4
|
isolate :conveyors
|
5
|
-
|
5
|
+
|
6
6
|
before do
|
7
7
|
rad.conveyors.services do |ss|
|
8
8
|
ss.use Rad::Remote::Processors::RemoteCaller, :content
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
old_mode = rad.mode
|
13
13
|
after :all do
|
14
14
|
remove_constants %w(
|
@@ -16,73 +16,73 @@ describe "Remote Basic" do
|
|
16
16
|
JsonErrorSpec
|
17
17
|
UnregisteredReturnValueSpec
|
18
18
|
)
|
19
|
-
|
19
|
+
|
20
20
|
rad.mode = old_mode, true
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
it "basic" do
|
24
24
|
class BasicSpec
|
25
25
|
inherit Rad::Remote::RemoteController
|
26
|
-
|
26
|
+
|
27
27
|
def call
|
28
28
|
{result: 'some result'}
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
workspace = rcall BasicSpec, :call, format: 'json'
|
33
|
-
|
33
|
+
|
34
34
|
workspace.delete(:remote_object).should be_a(BasicSpec)
|
35
|
-
expected_result = {
|
35
|
+
expected_result = {
|
36
36
|
params: {format: 'json'},
|
37
|
-
|
38
|
-
class: BasicSpec,
|
39
|
-
method_name: :call,
|
40
|
-
|
37
|
+
|
38
|
+
class: BasicSpec,
|
39
|
+
method_name: :call,
|
40
|
+
|
41
41
|
remote_result: {result: "some result"},
|
42
42
|
content: %({"result":"some result"})
|
43
43
|
}
|
44
44
|
workspace.to_h(true).subset(expected_result.keys).should == expected_result
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
describe "error handling should behave different in :production, :development and :test modes" do
|
48
|
-
it "error in :development mode" do
|
48
|
+
it "error in :development mode" do
|
49
49
|
class JsonErrorSpec
|
50
50
|
inherit Rad::Remote::RemoteController
|
51
|
-
|
51
|
+
|
52
52
|
def call_with_error
|
53
53
|
raise 'some error'
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
rad.mode = :development, true
|
58
|
-
|
58
|
+
|
59
59
|
workspace = rcall JsonErrorSpec, 'call_with_error', format: 'json'
|
60
|
-
|
60
|
+
|
61
61
|
workspace.delete(:remote_object).should be_a(JsonErrorSpec)
|
62
62
|
workspace.include?(:remote_result).should be_false
|
63
63
|
expected_result = {
|
64
64
|
params: {format: 'json'},
|
65
|
-
|
66
|
-
class: JsonErrorSpec,
|
67
|
-
method_name: "call_with_error",
|
68
|
-
|
65
|
+
|
66
|
+
class: JsonErrorSpec,
|
67
|
+
method_name: "call_with_error",
|
68
|
+
|
69
69
|
content: %({"error":"some error"})
|
70
70
|
}
|
71
71
|
workspace.to_h.subset(expected_result.keys).should == expected_result
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
it "should be able to protect methods from GET request"
|
76
|
-
|
76
|
+
|
77
77
|
it "should not allow unregistered object types be used as return value" do
|
78
78
|
class UnregisteredReturnValueSpec
|
79
79
|
inherit Rad::Remote::RemoteController
|
80
|
-
|
80
|
+
|
81
81
|
def call
|
82
82
|
Object.new
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
lambda{
|
87
87
|
rcall UnregisteredReturnValueSpec, 'call', format: 'json'
|
88
88
|
}.should raise_error(/You can't use object of type 'Object' as Remote's return value!/)
|
@@ -5,91 +5,91 @@ describe "AliasRouter" do
|
|
5
5
|
class SomeController
|
6
6
|
end
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
after :all do
|
10
10
|
remove_constants %w(SomeController)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
before do
|
14
14
|
@router = Rad::Router::AliasRouter.new
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "encode / decode" do
|
18
18
|
@router.add '/login', class_name: 'SomeController', method: :login
|
19
19
|
|
20
20
|
@router.encode(SomeController, :login, {}).should == ["/login", {}]
|
21
|
-
@router.encode_method('login_path', false).should == [SomeController, :login]
|
21
|
+
@router.encode_method('login_path', false).should == [SomeController, :login]
|
22
22
|
@router.decode("/login", {}).should == [SomeController, :login, {}]
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it "should differentiate aliases with similar path elements" do
|
26
26
|
@router.add '/login', class_name: 'SomeController', method: :login
|
27
27
|
@router.add '/login/twitter', class_name: 'SomeController', method: :twitter
|
28
|
-
|
28
|
+
|
29
29
|
@router.encode(SomeController, :login, {}).should == ["/login", {}]
|
30
30
|
@router.decode("/login", {}).should == [SomeController, :login, {}]
|
31
|
-
|
31
|
+
|
32
32
|
@router.encode(SomeController, :twitter, {}).should == ["/login/twitter", {}]
|
33
33
|
@router.decode("/login/twitter", {}).should == [SomeController, :twitter, {}]
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "input validation" do
|
37
37
|
lambda{@router.add :login, class_name: 'SomeController', method: :login}.should raise_error(/\//)
|
38
38
|
lambda{@router.add '/login', class_name: 'SomeController'}.should raise_error(/method/)
|
39
|
-
lambda{@router.add '/login', method: :login}.should raise_error(/class/)
|
39
|
+
lambda{@router.add '/login', method: :login}.should raise_error(/class/)
|
40
40
|
lambda{@router.add '/login', class_name: 'SomeController', method: :login, invalid: 'value'}.should raise_error(/unknown/)
|
41
41
|
lambda{@router.add '/login', class_name: 'SomeController', method: :login, url_root: 'users'}.should raise_error(/\//)
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it "should use :url_root" do
|
45
45
|
@router.add '/login', class_name: 'SomeController', method: :login, url_root: '/space'
|
46
|
-
|
46
|
+
|
47
47
|
@router.encode(SomeController, :login, {}).should == ["/login", {url_root: '/space'}]
|
48
48
|
@router.decode("/space/login", {}).should == [SomeController, :login, {}]
|
49
|
-
end
|
50
|
-
|
49
|
+
end
|
50
|
+
|
51
51
|
it "should return nil if route unknown" do
|
52
52
|
@router.encode(SomeController, :unknown, {}).should be_nil
|
53
53
|
@router.encode_method(:unknown_path, false).should be_nil
|
54
54
|
@router.decode("/login", {}).should be_nil
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
it 'root alias' do
|
58
58
|
@router.add '/', class_name: 'SomeController', method: :home
|
59
59
|
|
60
60
|
@router.encode(SomeController, :home, {}).should == ["/", {}]
|
61
61
|
@router.decode("/", {}).should == [SomeController, :home, {}]
|
62
|
-
|
62
|
+
|
63
63
|
# should not support url_root
|
64
64
|
-> {@router.add '/', class_name: 'SomeController', method: :home, url_root: '/space'}.should raise_error(/url_root/)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
describe "prefixes" do
|
68
68
|
it "basics" do
|
69
69
|
@router.add '/statistics', class_name: 'SomeController', method: :statistics, prefix: [:l, :space]
|
70
|
-
|
70
|
+
|
71
71
|
@router.encode(SomeController, :statistics, l: 'en', space: 'personal').should == ["/en/personal/statistics", {}]
|
72
72
|
@router.encode_method("statistics_path", false).should == [SomeController, :statistics]
|
73
73
|
@router.decode("/en/personal/statistics", {}).should == [SomeController, :statistics, {l: 'en', space: 'personal'}]
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
it "should also works with path with slashes" do
|
77
77
|
@router.add '/blogs/show', class_name: 'SomeController', method: :show, prefix: [:l, :space]
|
78
|
-
|
78
|
+
|
79
79
|
@router.encode(SomeController, :show, l: 'en', space: 'personal').should == ["/en/personal/blogs/show", {}]
|
80
80
|
@router.decode("/en/personal/blogs/show", {}).should == [SomeController, :show, {l: 'en', space: 'personal'}]
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
it "should raise error if prefixes not provided" do
|
84
84
|
@router.add '/login', class_name: 'SomeController', method: :login, prefix: :l
|
85
85
|
|
86
86
|
lambda{@router.encode(SomeController, :login, {})}.should raise_error(/prefix/)
|
87
87
|
lambda{@router.decode('/login', {})}.should raise_error(/prefix/)
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
it "should works with :url_root" do
|
91
91
|
@router.add '/blogs/show', class_name: 'SomeController', method: :show, prefix: :l, url_root: '/users'
|
92
|
-
|
92
|
+
|
93
93
|
@router.encode(SomeController, :show, l: 'en').should == ["/en/blogs/show", {url_root: '/users'}]
|
94
94
|
@router.decode("/users/en/blogs/show", {}).should == [SomeController, :show, {l: 'en'}]
|
95
95
|
end
|
@@ -4,36 +4,36 @@ describe "RedirectRouter" do
|
|
4
4
|
before do
|
5
5
|
@router = Rad::Router::BasicRouter.new
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
it "skip" do
|
9
9
|
@router.skip(/\/fs/)
|
10
|
-
|
10
|
+
|
11
11
|
halt = catch :halt do
|
12
12
|
@router.decode("/users/all", {})
|
13
13
|
nil
|
14
14
|
end
|
15
15
|
halt.should be_nil
|
16
|
-
|
16
|
+
|
17
17
|
halt = catch :halt do
|
18
18
|
@router.decode("/fs/user/avatar", {})
|
19
19
|
nil
|
20
20
|
end
|
21
21
|
halt.should_not be_nil
|
22
22
|
end
|
23
|
-
|
24
|
-
it "redirect" do
|
23
|
+
|
24
|
+
it "redirect" do
|
25
25
|
workspace = Rad::Conveyors::Workspace.new
|
26
26
|
workspace.response = Rad::Http::Response.new
|
27
27
|
@router.stub!(:workspace).and_return(workspace)
|
28
|
-
|
28
|
+
|
29
29
|
@router.redirect(/^\/([^\/]+)$/, "/\\1/Items")
|
30
|
-
|
30
|
+
|
31
31
|
halt = catch :halt do
|
32
32
|
@router.decode("/default/Items", {})
|
33
33
|
nil
|
34
34
|
end
|
35
35
|
halt.should be_nil
|
36
|
-
|
36
|
+
|
37
37
|
halt = catch :halt do
|
38
38
|
@router.decode("/default", {})
|
39
39
|
nil
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Configurator" do
|
3
|
+
describe "Configurator" do
|
4
4
|
before do
|
5
5
|
@basic_router = Rad::Router::BasicRouter.new
|
6
6
|
@router = Rad::Router.new(:class, [
|
@@ -8,14 +8,14 @@ describe "Configurator" do
|
|
8
8
|
])
|
9
9
|
Rad::Router::Configurator.stub(:router).and_return(@router)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it "named routes" do
|
13
13
|
rad.router.configure do |config|
|
14
14
|
config.stub(:router).and_return(@router)
|
15
|
-
|
15
|
+
|
16
16
|
config.skip(/^\/favicon/)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
@basic_router.skip_routes.size.should > 0
|
20
20
|
end
|
21
21
|
end
|
@@ -1,47 +1,47 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Remote Basic" do
|
4
|
-
before :all do
|
3
|
+
describe "Remote Basic" do
|
4
|
+
before :all do
|
5
5
|
class ::AnRemote
|
6
6
|
def call; end
|
7
7
|
end
|
8
|
-
end
|
9
|
-
|
8
|
+
end
|
9
|
+
|
10
10
|
isolate :conveyors, :router
|
11
|
-
|
11
|
+
|
12
12
|
after :all do
|
13
13
|
remove_constants %w(AnRemote)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
before do
|
17
17
|
rad.conveyors.web.use Rad::Router::Processors::Router, :class_variable, :method_variable
|
18
18
|
rad.router.routers = [
|
19
19
|
[:simple_router, Rad::Router::SimpleRouter.new]
|
20
20
|
]
|
21
21
|
end
|
22
|
-
|
23
|
-
def call_router path, params
|
22
|
+
|
23
|
+
def call_router path, params
|
24
24
|
rad.conveyors.web.call path: path, params: Rad::Conveyors::Params.new(params)
|
25
25
|
end
|
26
|
-
|
27
|
-
it "basic" do
|
26
|
+
|
27
|
+
it "basic" do
|
28
28
|
workspace = call_router '/an_remote/call', format: 'json'
|
29
|
-
|
30
|
-
expected_result = {
|
31
|
-
path: "/an_remote/call",
|
29
|
+
|
30
|
+
expected_result = {
|
31
|
+
path: "/an_remote/call",
|
32
32
|
params: {format: 'json'},
|
33
|
-
|
34
|
-
class_variable: AnRemote,
|
33
|
+
|
34
|
+
class_variable: AnRemote,
|
35
35
|
method_variable: :call
|
36
36
|
}
|
37
37
|
workspace.to_h(true).subset(expected_result.keys).should == expected_result
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
it "params must be casted to string" do
|
41
41
|
workspace = call_router '/an_remote/call', a: 'b'
|
42
42
|
workspace.params.to_h.subset(:a).should == {a: 'b'}
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it "default router should raise error if route is invalid" do
|
46
46
|
lambda{call_router '/invalid/call', format: 'json'}.should raise_error(/uninitialized constant Invalid/)
|
47
47
|
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "ObjectRouter" do
|
3
|
+
describe "ObjectRouter" do
|
4
4
|
before :all do
|
5
5
|
class ::Blogs
|
6
6
|
# Object methods
|
7
7
|
def show; end
|
8
8
|
def update; end
|
9
|
-
|
9
|
+
|
10
10
|
# Singleton methods
|
11
11
|
def all; end
|
12
12
|
def some; end
|
13
|
-
end
|
13
|
+
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
after :all do
|
17
17
|
remove_constants %w(Blogs)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
before do
|
21
21
|
@router = Rad::Router::ObjectRouter.new
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
describe 'Singleton Resource' do
|
25
25
|
before do
|
26
26
|
@router.configure(
|
@@ -30,23 +30,23 @@ describe "ObjectRouter" do
|
|
30
30
|
id_to_class: -> id, params {nil}
|
31
31
|
)
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it "basic" do
|
35
35
|
@router.encode(Blogs, :some, {}).should == ["/Blogs/some", {}]
|
36
36
|
@router.encode_method('some_blog_path', false).should == [Blogs, :some]
|
37
37
|
@router.encode_method('some_blogs_path', false).should == [Blogs, :some]
|
38
38
|
@router.decode("/Blogs/some", {}).should == [Blogs, :some, {}]
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "by default should use :all method if the method not explicitly specified" do
|
42
42
|
@router.encode(Blogs, :all, {}).should == ["/Blogs", {}]
|
43
43
|
@router.encode(Blogs, nil, {}).should == ["/Blogs", {}]
|
44
44
|
@router.encode_method('blog_path', false).should == [Blogs, :all]
|
45
45
|
@router.encode_method('blogs_path', false).should == [Blogs, :all]
|
46
46
|
@router.decode("/Blogs", {}).should == [Blogs, :all, {}]
|
47
|
-
end
|
47
|
+
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
describe "Object Resource" do
|
51
51
|
before do
|
52
52
|
@router.configure(
|
@@ -55,30 +55,30 @@ describe "ObjectRouter" do
|
|
55
55
|
resource_to_class: -> resource {resource.constantize}
|
56
56
|
)
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
# TODO3 remove also class from :encode, use:
|
60
|
-
#
|
60
|
+
#
|
61
61
|
# @router.encode('about', :update, view: 'full').should == ["/about/update", {view: 'full'}]
|
62
62
|
# @router.encode_method('update_path').should == [:update]
|
63
|
-
#
|
64
|
-
it "basic" do
|
63
|
+
#
|
64
|
+
it "basic" do
|
65
65
|
@router.encode(Blogs, :update, id: 'about', view: 'full').should == ["/about/update", {view: 'full'}]
|
66
66
|
@router.encode_method('update_path', true).should == [Blogs, :update]
|
67
67
|
@router.decode("/about/update", {view: 'full'}).should == [Blogs, :update, {id: 'about', view: 'full'}]
|
68
|
-
end
|
69
|
-
|
68
|
+
end
|
69
|
+
|
70
70
|
it "by default should use :show method if the method not explicitly specified" do
|
71
71
|
@router.encode(Blogs, :show, id: 'about', view: 'full').should == ["/about", {view: 'full'}]
|
72
72
|
@router.encode(Blogs, nil, id: 'about', view: 'full').should == ["/about", {view: 'full'}]
|
73
73
|
@router.encode_method('path', true).should == [Blogs, :show]
|
74
74
|
@router.decode("/about", {view: 'full'}).should == [Blogs, :show, {id: 'about', view: 'full'}]
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
it "should raise error if :class for :id is not resolved" do
|
78
78
|
lambda{@router.decode("/non-existing-id", {view: 'full'})}.should raise_error(/no class for .* id/)
|
79
79
|
end
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
describe "prefixes" do
|
83
83
|
before do
|
84
84
|
@common_options = {
|
@@ -88,95 +88,95 @@ describe "ObjectRouter" do
|
|
88
88
|
id_to_class: -> id, params {id == 'about' ? Blogs : nil}
|
89
89
|
}
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
it "class resource" do
|
93
93
|
@router.configure @common_options.merge(prefix: [:l, :space])
|
94
|
-
|
94
|
+
|
95
95
|
@router.encode(Blogs, :some, l: 'en', space: 'personal').should == ["/en/personal/Blogs/some", {}]
|
96
96
|
@router.encode(Blogs, :all, l: 'en', space: 'personal').should == ["/en/personal/Blogs", {}]
|
97
97
|
@router.decode("/en/personal/Blogs/some", {}).should == [Blogs, :some, {l: 'en', space: 'personal'}]
|
98
98
|
@router.decode("/en/personal/Blogs", {}).should == [Blogs, :all, {l: 'en', space: 'personal'}]
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
it "object resource" do
|
102
102
|
@router.configure @common_options.merge(prefix: [:l, :space])
|
103
|
-
|
103
|
+
|
104
104
|
@router.encode(Blogs, :update, id: 'about', l: 'en', space: 'personal').should == ["/en/personal/about/update", {}]
|
105
105
|
@router.encode(Blogs, nil, id: 'about', l: 'en', space: 'personal').should == ["/en/personal/about", {}]
|
106
106
|
@router.decode("/en/personal/about/update", {}).should == [Blogs, :update, {id: 'about', l: 'en', space: 'personal'}]
|
107
107
|
@router.decode("/en/personal/about", {}).should == [Blogs, :show, {id: 'about', l: 'en', space: 'personal'}]
|
108
108
|
end
|
109
|
-
|
110
|
-
it "should raise error if prefixes not provided" do
|
109
|
+
|
110
|
+
it "should raise error if prefixes not provided" do
|
111
111
|
@router.configure @common_options.merge(prefix: :l)
|
112
|
-
|
113
|
-
lambda{@router.encode(Blogs, :some, {})}.should raise_error(/prefix/)
|
114
|
-
lambda{@router.encode(Blogs, :all, {})}.should raise_error(/prefix/)
|
112
|
+
|
113
|
+
lambda{@router.encode(Blogs, :some, {})}.should raise_error(/prefix/)
|
114
|
+
lambda{@router.encode(Blogs, :all, {})}.should raise_error(/prefix/)
|
115
115
|
lambda{@router.decode('/Blogs/some', {})}.should raise_error(/no class for .* id/)
|
116
116
|
lambda{@router.decode('/Blogs', {})}.should raise_error(/invalid 'size' of path/)
|
117
|
-
|
118
|
-
|
119
|
-
lambda{@router.encode(Blogs, :update, id: 'about')}.should raise_error(/prefix/)
|
120
|
-
lambda{@router.encode(Blogs, :show, id: 'about')}.should raise_error(/prefix/)
|
117
|
+
|
118
|
+
|
119
|
+
lambda{@router.encode(Blogs, :update, id: 'about')}.should raise_error(/prefix/)
|
120
|
+
lambda{@router.encode(Blogs, :show, id: 'about')}.should raise_error(/prefix/)
|
121
121
|
lambda{@router.decode('/about/update', {})}.should raise_error(/no class for .* id/)
|
122
122
|
lambda{@router.decode('/about', {})}.should raise_error(/invalid 'size' of path/)
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
it "should works with :url_root" do
|
126
126
|
@router.configure @common_options.merge(prefix: [:l], url_root: '/users')
|
127
|
-
|
127
|
+
|
128
128
|
@router.encode(Blogs, :some, l: 'en').should == ["/en/Blogs/some", {url_root: '/users'}]
|
129
129
|
@router.decode("/users/en/Blogs/some", {}).should == [Blogs, :some, {l: 'en'}]
|
130
|
-
|
130
|
+
|
131
131
|
@router.encode(Blogs, :update, id: 'about', l: 'en').should == ["/en/about/update", {url_root: '/users'}]
|
132
132
|
@router.decode("/users/en/about/update", {}).should == [Blogs, :update, {id: 'about', l: 'en'}]
|
133
133
|
end
|
134
134
|
end
|
135
|
-
|
136
|
-
describe "miscellaneous check" do
|
135
|
+
|
136
|
+
describe "miscellaneous check" do
|
137
137
|
before{@common_options = {default_class_name: 'Blogs'}}
|
138
|
-
|
138
|
+
|
139
139
|
# it "should raise if :id and not default class " do
|
140
140
|
# @router.configure @common_options
|
141
141
|
# lambda{@router.encode(Blogs, :some, id: 'about')}.should raise_error(/:id can't be used with :class/)
|
142
142
|
# end
|
143
|
-
|
143
|
+
|
144
144
|
it "should return nil if resource name is not in plural form" do
|
145
145
|
@router.configure @common_options
|
146
146
|
lambda{@router.decode('/Blog/some', {})}.should raise_error(/resource must be in plural form/)
|
147
147
|
end
|
148
|
-
|
148
|
+
|
149
149
|
it "object id should not start with capital letter" do
|
150
|
-
@router.configure @common_options
|
150
|
+
@router.configure @common_options
|
151
151
|
lambda{@router.encode(Blogs, :some, {id: 'About'})}.should raise_error(/capital/)
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
it "resource name should be uppercased" do
|
155
155
|
@router.configure @common_options.merge(class_to_resource: -> klass {'blogs'})
|
156
156
|
lambda{@router.encode(Blogs, :some, {})}.should raise_error(/capital/)
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
it "should not be allowed to called twice" do
|
160
160
|
@router.configure @common_options
|
161
161
|
lambda{@router.configure @common_options}.should raise_error(/twice/)
|
162
162
|
end
|
163
|
-
|
164
|
-
it "should allow only plural form in resource names" do
|
163
|
+
|
164
|
+
it "should allow only plural form in resource names" do
|
165
165
|
@router.configure @common_options.merge(class_to_resource: -> klass {'Blog'})
|
166
166
|
lambda{@router.encode(Blogs, :some, {})}.should raise_error(/plural/)
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
169
|
it "shouldn't allow slashes in resource name" do
|
170
170
|
@router.configure @common_options.merge(class_to_resource: -> klass {'Site/Blog'})
|
171
171
|
lambda{@router.encode(Blogs, :some, {})}.should raise_error(/\//)
|
172
172
|
end
|
173
|
-
|
173
|
+
|
174
174
|
# it "should correctly works with unknown routes" do
|
175
175
|
# @router.encode(Blogs, :show, {}).should be_nil
|
176
176
|
# @router.encode_method('show_blog_path').should be_nil
|
177
177
|
# @router.encode_method('show_blogs_path').should be_nil
|
178
178
|
# @router.decode("/Blogs/show", {}).should be_nil
|
179
|
-
#
|
179
|
+
#
|
180
180
|
# @router.encode(Blogs, :show, id: 'about', view: 'full').should be_nil
|
181
181
|
# @router.encode_method('show_blog_path').should be_nil
|
182
182
|
# @router.encode_method('show_blogs_path').should be_nil
|