rad_core 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -2,119 +2,119 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe "Controller Context" do
|
|
4
4
|
with_view_path "#{spec_dir}/views"
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
before :all do
|
|
7
7
|
class ItemSpec
|
|
8
8
|
inherit Rad::Controller::Abstract
|
|
9
|
-
|
|
10
|
-
def show; end
|
|
9
|
+
|
|
10
|
+
def show; end
|
|
11
11
|
def update; end
|
|
12
12
|
def delete; end
|
|
13
13
|
def increase; end
|
|
14
|
-
def decrease; end
|
|
14
|
+
def decrease; end
|
|
15
15
|
end
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
class PageSpec < ItemSpec
|
|
18
18
|
def show; end
|
|
19
19
|
def increase; end
|
|
20
|
-
end
|
|
21
|
-
|
|
20
|
+
end
|
|
21
|
+
|
|
22
22
|
module NamespaceSpec
|
|
23
23
|
class ClassSpec
|
|
24
24
|
inherit Rad::Controller::Abstract
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
def show; end
|
|
27
27
|
def update; end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
after :all do
|
|
33
33
|
remove_constants %w(
|
|
34
34
|
ItemSpec
|
|
35
35
|
PageSpec
|
|
36
|
-
NamespaceSpec
|
|
36
|
+
NamespaceSpec
|
|
37
37
|
ItemSpecHelper
|
|
38
|
-
PageSpecHelper
|
|
39
|
-
)
|
|
38
|
+
PageSpecHelper
|
|
39
|
+
)
|
|
40
40
|
end
|
|
41
|
-
|
|
42
|
-
describe "basic" do
|
|
41
|
+
|
|
42
|
+
describe "basic" do
|
|
43
43
|
before{@args = [[''], nil, nil, nil]}
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
it "should return nil for non-existing template" do
|
|
46
46
|
ItemSpec.find_relative_template(:delete, *@args).should be_nil
|
|
47
47
|
PageSpec.find_relative_template(:delete, *@args).should be_nil
|
|
48
48
|
end
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
it "should provide template name for existing template" do
|
|
51
51
|
ItemSpec.find_relative_template(:update, *@args).should == "#{spec_dir}/views/item_spec/update.erb"
|
|
52
52
|
end
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
it "should inherit template name for template existing in parent" do
|
|
55
55
|
PageSpec.find_relative_template(:update, *@args).should == "#{spec_dir}/views/item_spec/update.erb"
|
|
56
56
|
end
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
it "should override template name for template existing in both self and parent" do
|
|
59
59
|
ItemSpec.find_relative_template(:show, *@args).should == "#{spec_dir}/views/item_spec/show.erb"
|
|
60
60
|
PageSpec.find_relative_template(:show, *@args).should == "#{spec_dir}/views/page_spec/show.erb"
|
|
61
61
|
end
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
it "should transfer namespaces into folders" do
|
|
64
64
|
NamespaceSpec::ClassSpec.find_relative_template(:show, *@args).should == "#{spec_dir}/views/NamespaceSpec/ClassSpec/show.erb"
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
describe "actions" do
|
|
69
69
|
before{@args = [[''], nil, nil, nil]}
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
it "should be able to check for action inside of actions.xxx files" do
|
|
72
72
|
ItemSpec.find_relative_template(:increase, *@args).should == "#{spec_dir}/views/item_spec/actions.erb"
|
|
73
73
|
end
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
it "should be able to check for action inside of actions.xxx files" do
|
|
76
76
|
ItemSpec.find_relative_template(:increase, *@args).should == "#{spec_dir}/views/item_spec/actions.erb"
|
|
77
77
|
ItemSpec.find_relative_template(:decrease, *@args).should == "#{spec_dir}/views/item_spec/actions.erb"
|
|
78
78
|
ItemSpec.find_relative_template(:action_not_defined_inside_of_actions_file, *@args).should == nil
|
|
79
79
|
end
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
it "should inherit actions.xxx" do
|
|
82
82
|
PageSpec.find_relative_template(:increase, *@args).should == "#{spec_dir}/views/item_spec/actions.erb"
|
|
83
83
|
PageSpec.find_relative_template(:decrease, *@args).should == "#{spec_dir}/views/page_spec/actions.erb"
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
describe "context_class, helper" do
|
|
88
|
-
before do
|
|
88
|
+
before do
|
|
89
89
|
ItemSpec.instance_variable_set "@context_class", nil
|
|
90
90
|
ItemSpec.instance_variable_set "@context_class", nil
|
|
91
91
|
end
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
it "context_class" do
|
|
94
94
|
ItemSpec.context_class.should == ItemSpec::ItemSpecContext
|
|
95
95
|
PageSpec.context_class.should == PageSpec::PageSpecContext
|
|
96
96
|
PageSpec::PageSpecContext.is?(PageSpec::ItemSpecContext).should be_true
|
|
97
97
|
end
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
it "helper" do
|
|
100
100
|
module ::ItemSpecHelper
|
|
101
101
|
def controller_item; end
|
|
102
102
|
end
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
module ::PageSpecHelper
|
|
105
105
|
def controller_page; end
|
|
106
106
|
end
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
ItemSpec.helper ItemSpecHelper
|
|
109
109
|
PageSpec.helper PageSpecHelper
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
ItemSpec::ItemSpecContext.instance_methods.should include(:controller_item)
|
|
112
|
-
|
|
112
|
+
|
|
113
113
|
PageSpec::PageSpecContext.instance_methods.should include(:controller_item)
|
|
114
114
|
PageSpec::PageSpecContext.instance_methods.should include(:controller_page)
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
|
-
|
|
117
|
+
|
|
118
118
|
describe "other" do
|
|
119
119
|
it "should understand underscored paths" do
|
|
120
120
|
NamespaceSpec::ClassSpec.find_relative_template(:update, [''], nil, nil, nil).should == "#{spec_dir}/views/namespace_spec/class_spec/update.erb"
|
|
@@ -2,12 +2,12 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe "Error handling" do
|
|
4
4
|
with_view_path "#{spec_dir}/views"
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
isolate :conveyors
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
before do
|
|
9
9
|
rad.controller.stub!(:test_error_template).and_return(rad.controller.development_error_template)
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
rad.conveyors.web do |web|
|
|
12
12
|
web.use Rad::Controller::Processors::ControllerErrorHandling
|
|
13
13
|
web.use Rad::Controller::Processors::ControllerCaller
|
|
@@ -16,94 +16,94 @@ describe "Error handling" do
|
|
|
16
16
|
|
|
17
17
|
before :all do
|
|
18
18
|
rad.controller
|
|
19
|
-
end
|
|
19
|
+
end
|
|
20
20
|
after :all do
|
|
21
21
|
remove_constants %w(
|
|
22
22
|
DisplayErrorWithFormat
|
|
23
|
-
DiferrentErrorHandlingSpec
|
|
23
|
+
DiferrentErrorHandlingSpec
|
|
24
24
|
ErrorInRedirectSpec
|
|
25
25
|
)
|
|
26
26
|
end
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
it "should correctly display error messages in :development (with correct format)" do
|
|
29
29
|
class ::DisplayErrorWithFormat
|
|
30
30
|
inherit Rad::Controller::Abstract
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
def method
|
|
33
|
-
raise params.error
|
|
33
|
+
raise params.error
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
rad.mode = :development, true
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
error = StandardError.new('some error')
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
ccall(
|
|
42
|
-
DisplayErrorWithFormat, :method,
|
|
42
|
+
DisplayErrorWithFormat, :method,
|
|
43
43
|
{error: error, format: 'html'}
|
|
44
44
|
).should =~ /html.+some error/m
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
ccall(
|
|
47
47
|
DisplayErrorWithFormat, :method,
|
|
48
48
|
{error: error, format: 'js'}
|
|
49
49
|
).should =~ /some error/
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
ccall(
|
|
52
52
|
DisplayErrorWithFormat, :method,
|
|
53
53
|
{error: error, format: :non_existing_mime}
|
|
54
54
|
).should =~ /some error/
|
|
55
55
|
end
|
|
56
|
-
|
|
56
|
+
|
|
57
57
|
it "should catch errors with redirect (from error)" do
|
|
58
|
-
# error: if response.headers['Location'] has been set before redirect, it'll do redirect
|
|
58
|
+
# error: if response.headers['Location'] has been set before redirect, it'll do redirect
|
|
59
59
|
# after error will be catched and no error message will be displayed
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
class ::ErrorInRedirectSpec
|
|
62
62
|
inherit Rad::Controller::Abstract
|
|
63
63
|
|
|
64
64
|
def a
|
|
65
65
|
response.headers['Location'] = '/'
|
|
66
66
|
raise 'some error'
|
|
67
|
-
end
|
|
67
|
+
end
|
|
68
68
|
end
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
rad.mode = :development, true
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
ccall(ErrorInRedirectSpec, :a, format: 'html')
|
|
73
73
|
response.headers['Location'].should be_nil
|
|
74
74
|
end
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
describe "should be different in :test, :development and :production" do
|
|
77
77
|
before :all do
|
|
78
78
|
class ::DiferrentErrorHandlingSpec
|
|
79
79
|
inherit Rad::Controller::Abstract
|
|
80
|
-
|
|
81
|
-
def a; end
|
|
80
|
+
|
|
81
|
+
def a; end
|
|
82
82
|
def b
|
|
83
83
|
raise 'some error'
|
|
84
|
-
end
|
|
84
|
+
end
|
|
85
85
|
def c; end
|
|
86
86
|
end
|
|
87
87
|
end
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
it "in :production errors shouldn't be shown to user"
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
it "in development errors should be catched" do
|
|
92
92
|
rad.mode = :development, true
|
|
93
|
-
|
|
93
|
+
|
|
94
94
|
# with view
|
|
95
95
|
ccall(DiferrentErrorHandlingSpec, :a).should == 'a'
|
|
96
|
-
%w(html js).each do |format|
|
|
97
|
-
ccall(DiferrentErrorHandlingSpec, :b, format: format).should =~ /some error/
|
|
96
|
+
%w(html js).each do |format|
|
|
97
|
+
ccall(DiferrentErrorHandlingSpec, :b, format: format).should =~ /some error/
|
|
98
98
|
ccall(DiferrentErrorHandlingSpec, :c, format: format).should =~ /error in template/
|
|
99
99
|
end
|
|
100
100
|
end
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
it "should not catch errors in :test environment" do
|
|
103
103
|
rad.mode = :test, true
|
|
104
104
|
|
|
105
105
|
# with render
|
|
106
|
-
ccall(DiferrentErrorHandlingSpec, :a).should == 'a'
|
|
106
|
+
ccall(DiferrentErrorHandlingSpec, :a).should == 'a'
|
|
107
107
|
lambda{ccall(DiferrentErrorHandlingSpec, :b)}.should raise_error(/some error/)
|
|
108
108
|
lambda{ccall(DiferrentErrorHandlingSpec, :c)}.should raise_error(/error in template/)
|
|
109
109
|
end
|
|
@@ -2,46 +2,46 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe "Abstract" do
|
|
4
4
|
with_view_path "#{spec_dir}/views"
|
|
5
|
-
with_abstract_controller
|
|
6
|
-
|
|
5
|
+
with_abstract_controller
|
|
6
|
+
|
|
7
7
|
after :all do
|
|
8
8
|
remove_constants %w(
|
|
9
9
|
SomeHelperSpec
|
|
10
10
|
HelperSpec
|
|
11
|
-
HelperMethodSpec
|
|
11
|
+
HelperMethodSpec
|
|
12
12
|
)
|
|
13
13
|
end
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
it "helper_method" do
|
|
16
16
|
class ::HelperMethodSpec
|
|
17
17
|
inherit Rad::Controller::Abstract
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
def some_controller_method
|
|
20
20
|
"some controller value (rendered in cotext of #{self.class})"
|
|
21
21
|
end
|
|
22
22
|
helper_method :some_controller_method
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
def action; end
|
|
25
25
|
end
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
ccall(HelperMethodSpec, :action).should == "some controller value (rendered in cotext of HelperMethodSpec)"
|
|
28
28
|
end
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
it "helper" do
|
|
31
31
|
module ::SomeHelperSpec
|
|
32
32
|
def wiget
|
|
33
33
|
"some wighet (rendered in context of #{self.class.name})"
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
class ::HelperSpec
|
|
38
38
|
inherit Rad::Controller::Abstract
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
helper SomeHelperSpec
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
def action; end
|
|
43
43
|
end
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
ccall(HelperSpec, :action).should == "some wighet (rendered in context of HelperSpec::HelperSpecContext)"
|
|
46
|
-
end
|
|
46
|
+
end
|
|
47
47
|
end
|
|
@@ -2,9 +2,9 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe "Http" do
|
|
4
4
|
with_view_path "#{spec_dir}/views"
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
isolate :conveyors
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
before do
|
|
9
9
|
rad.conveyors.web do |web|
|
|
10
10
|
web.use Rad::Http::Processors::HttpWriter
|
|
@@ -13,7 +13,7 @@ describe "Http" do
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
after :all do
|
|
16
|
-
remove_constants %w(
|
|
16
|
+
remove_constants %w(
|
|
17
17
|
ContentTypeSpec
|
|
18
18
|
StatusSpec
|
|
19
19
|
StatusShortcutsSpec
|
|
@@ -23,50 +23,50 @@ describe "Http" do
|
|
|
23
23
|
ViewVariablesSpec
|
|
24
24
|
)
|
|
25
25
|
end
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
describe 'render' do
|
|
28
28
|
it "should take :content_type option" do
|
|
29
29
|
class ::ContentTypeSpec
|
|
30
30
|
inherit Rad::Controller::Http
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
def action
|
|
33
33
|
render inline: "some content", content_type: Mime.js
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
wcall(ContentTypeSpec, :action)
|
|
38
38
|
response.content_type.should == "application/javascript"
|
|
39
39
|
end
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
it "should take :status option" do
|
|
42
42
|
class ::StatusSpec
|
|
43
43
|
inherit Rad::Controller::Http
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
def action
|
|
46
46
|
render inline: "some content", status: 220
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
wcall(StatusSpec, :action)
|
|
51
51
|
response.status.should == 220
|
|
52
52
|
end
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
it "should take shortcuts to status codes" do
|
|
55
55
|
class ::StatusShortcutsSpec
|
|
56
56
|
inherit Rad::Controller::Http
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
def ok
|
|
59
59
|
render :ok
|
|
60
60
|
end
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
def failed
|
|
63
63
|
render :failed
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
wcall(StatusShortcutsSpec, :ok)
|
|
68
68
|
response.status.should == 200
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
wcall(StatusShortcutsSpec, :failed)
|
|
71
71
|
response.status.should == 500
|
|
72
72
|
end
|
|
@@ -74,66 +74,66 @@ describe "Http" do
|
|
|
74
74
|
it "should take :location option" do
|
|
75
75
|
class ::LocationSpec
|
|
76
76
|
inherit Rad::Controller::Http
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
def action
|
|
79
79
|
render location: "/"
|
|
80
|
-
end
|
|
80
|
+
end
|
|
81
81
|
end
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
# mock
|
|
84
84
|
class ::LocationSpec
|
|
85
85
|
def redirect_to location
|
|
86
86
|
self.class.location = location
|
|
87
87
|
end
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
class << self
|
|
90
90
|
attr_accessor :location
|
|
91
|
-
end
|
|
91
|
+
end
|
|
92
92
|
end
|
|
93
|
-
|
|
93
|
+
|
|
94
94
|
wcall(LocationSpec, :action, format: 'html')
|
|
95
95
|
LocationSpec.location.should == '/'
|
|
96
96
|
end
|
|
97
|
-
end
|
|
98
|
-
|
|
97
|
+
end
|
|
98
|
+
|
|
99
99
|
it "should specify request method" do
|
|
100
100
|
class ::RequestMethod
|
|
101
101
|
inherit Rad::Controller::Http
|
|
102
|
-
def action
|
|
102
|
+
def action
|
|
103
103
|
request.post?.should == true
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
|
-
|
|
107
|
-
workspace, params = {env: {'REQUEST_METHOD' => 'POST'}}, {}
|
|
106
|
+
|
|
107
|
+
workspace, params = {env: {'REQUEST_METHOD' => 'POST'}}, {}
|
|
108
108
|
wcall(RequestMethod, :action, workspace, params)
|
|
109
109
|
end
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
it "should protect methods from GET request" do
|
|
112
112
|
class ::ForbidGetSpec
|
|
113
113
|
inherit Rad::Controller::Http
|
|
114
114
|
allow_get_for :get_action
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
def get_action; end
|
|
117
117
|
def post_action; end
|
|
118
118
|
end
|
|
119
|
-
|
|
119
|
+
|
|
120
120
|
workspace = {env: {'REQUEST_METHOD' => 'GET'}}
|
|
121
|
-
|
|
121
|
+
|
|
122
122
|
wcall(ForbidGetSpec, :get_action, workspace, {})
|
|
123
123
|
lambda{
|
|
124
124
|
wcall(ForbidGetSpec, :post_action, workspace, {})
|
|
125
125
|
}.should raise_error(/not allowed/)
|
|
126
126
|
end
|
|
127
|
-
|
|
127
|
+
|
|
128
128
|
it "request and response must be availiable in view" do
|
|
129
129
|
class ::ViewVariablesSpec
|
|
130
130
|
inherit Rad::Controller::Http
|
|
131
|
-
|
|
131
|
+
|
|
132
132
|
def action
|
|
133
133
|
@instance_variable = "iv value"
|
|
134
134
|
end
|
|
135
135
|
end
|
|
136
|
-
|
|
136
|
+
|
|
137
137
|
wcall(ViewVariablesSpec, :action).should == %(\
|
|
138
138
|
request: true
|
|
139
139
|
response: true)
|