rad_core 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +10 -0
- data/lib/rad/controller/abstract_controller/micelaneous.rb +31 -0
- data/lib/rad/controller/abstract_controller/render.rb +160 -0
- data/lib/rad/controller/abstract_controller/responder.rb +17 -0
- data/lib/rad/controller/abstract_controller.rb +64 -0
- data/lib/rad/controller/controller_context.rb +15 -0
- data/lib/rad/controller/http_controller.rb +48 -0
- data/lib/rad/controller/processors/controller_caller.rb +28 -0
- data/lib/rad/controller/processors/controller_error_handling.rb +51 -0
- data/lib/rad/controller/processors/controller_logger.rb +12 -0
- data/lib/rad/controller.rb +28 -0
- data/lib/rad/conveyor/conveyor.rb +74 -0
- data/lib/rad/conveyor/conveyors.rb +20 -0
- data/lib/rad/conveyor/params.rb +14 -0
- data/lib/rad/conveyor/processor.rb +68 -0
- data/lib/rad/conveyor/processors/conveyor_logger.rb +25 -0
- data/lib/rad/conveyor/workspace.rb +36 -0
- data/lib/rad/conveyor.rb +29 -0
- data/lib/rad/environment/config.rb +111 -0
- data/lib/rad/environment/dependency_resolver.rb +107 -0
- data/lib/rad/environment/environment.rb +29 -0
- data/lib/rad/environment/files_helper.rb +55 -0
- data/lib/rad/environment/logger.rb +21 -0
- data/lib/rad/environment.rb +55 -0
- data/lib/rad/html/flash.rb +42 -0
- data/lib/rad/html/helpers/basic_html_helper.rb +83 -0
- data/lib/rad/html/helpers/flash_helper.rb +5 -0
- data/lib/rad/html/helpers/form_helper.rb +115 -0
- data/lib/rad/html/helpers/html_helper.rb +5 -0
- data/lib/rad/html/helpers/javascript_helper.rb +18 -0
- data/lib/rad/html/helpers/model_helper.rb +135 -0
- data/lib/rad/html/include_into_controller.rb +0 -0
- data/lib/rad/html/processors/prepare_flash.rb +26 -0
- data/lib/rad/html/processors/scoped_params.rb +26 -0
- data/lib/rad/html.rb +26 -0
- data/lib/rad/http/http.rb +21 -0
- data/lib/rad/http/http_adapter.rb +36 -0
- data/lib/rad/http/middleware/static_files.rb +21 -0
- data/lib/rad/http/processors/evaluate_format.rb +22 -0
- data/lib/rad/http/processors/http_logger.rb +15 -0
- data/lib/rad/http/processors/http_writer.rb +30 -0
- data/lib/rad/http/processors/prepare_params.rb +22 -0
- data/lib/rad/http/support/rack/fixes.rb +36 -0
- data/lib/rad/http/support/rack/rack_adapter.rb +67 -0
- data/lib/rad/http/support/rack/request.rb +42 -0
- data/lib/rad/http/support/rack/response.rb +86 -0
- data/lib/rad/http.rb +48 -0
- data/lib/rad/integration/controller_micelaneous_helper.rb +19 -0
- data/lib/rad/integration/router/abstract_routing_helper.rb +22 -0
- data/lib/rad/integration/router/controller_routing_helper.rb +58 -0
- data/lib/rad/integration/router/view_routing_helper.rb +104 -0
- data/lib/rad/integration.rb +30 -0
- data/lib/rad/mail/letter.rb +30 -0
- data/lib/rad/mail/mail_controller.rb +31 -0
- data/lib/rad/mail/mailer.rb +23 -0
- data/lib/rad/mail/processors/letter_builder.rb +36 -0
- data/lib/rad/mail.rb +15 -0
- data/lib/rad/profiles/mail.rb +16 -0
- data/lib/rad/profiles/web.rb +68 -0
- data/lib/rad/profiles/web_require.rb +5 -0
- data/lib/rad/remote/processors/remote_caller.rb +54 -0
- data/lib/rad/remote/processors/remote_logger.rb +13 -0
- data/lib/rad/remote/remote.rb +15 -0
- data/lib/rad/remote.rb +9 -0
- data/lib/rad/router/core/configurator.rb +25 -0
- data/lib/rad/router/core/core_routing_helper.rb +41 -0
- data/lib/rad/router/core/default_format_processor.rb +12 -0
- data/lib/rad/router/core/processors/router.rb +29 -0
- data/lib/rad/router/core/router.rb +271 -0
- data/lib/rad/router/core/simple_router.rb +23 -0
- data/lib/rad/router/routers/abstract_router.rb +62 -0
- data/lib/rad/router/routers/alias_router.rb +113 -0
- data/lib/rad/router/routers/restful_router.rb +113 -0
- data/lib/rad/router.rb +29 -0
- data/lib/rad/spec/controller.rb +41 -0
- data/lib/rad/spec/environment.rb +51 -0
- data/lib/rad/spec/http.rb +93 -0
- data/lib/rad/spec/mail.rb +31 -0
- data/lib/rad/spec/remote.rb +9 -0
- data/lib/rad/spec/router.rb +18 -0
- data/lib/rad/spec/template.rb +12 -0
- data/lib/rad/spec/view.rb +10 -0
- data/lib/rad/spec/xhtml.rb +33 -0
- data/lib/rad/spec.rb +11 -0
- data/lib/rad/support/active_support/locales/en/actionpack.yml +154 -0
- data/lib/rad/support/active_support/locales/en/activesupport.yml +36 -0
- data/lib/rad/support/active_support/micelaneous.rb +2 -0
- data/lib/rad/support/active_support/time.rb +105 -0
- data/lib/rad/support/active_support.rb +49 -0
- data/lib/rad/support/addressable.rb +45 -0
- data/lib/rad/support/buffered_logger.rb +44 -0
- data/lib/rad/support/callbacks.rb +168 -0
- data/lib/rad/support/exception.rb +31 -0
- data/lib/rad/support/filters.rb +34 -0
- data/lib/rad/support/format.rb +17 -0
- data/lib/rad/support/hacks_and_fixes.rb +23 -0
- data/lib/rad/support/micon.rb +13 -0
- data/lib/rad/support/mime.rb +13 -0
- data/lib/rad/support/module.rb +48 -0
- data/lib/rad/support/rson.rb +53 -0
- data/lib/rad/support/ruby_ext_with_active_support.rb +4 -0
- data/lib/rad/support/string.rb +26 -0
- data/lib/rad/support.rb +63 -0
- data/lib/rad/template/support/tilt.rb +68 -0
- data/lib/rad/template/support/tilt_fixes.rb +17 -0
- data/lib/rad/template/template.rb +250 -0
- data/lib/rad/template/template_context.rb +62 -0
- data/lib/rad/template.rb +25 -0
- data/lib/rad_core/gems.rb +31 -0
- data/readme.md +33 -0
- data/spec/controller/abstract_controller_spec/views/OperationsOrderSpec/action.erb +1 -0
- data/spec/controller/abstract_controller_spec/views/ViewVariablesSpec/action.erb +11 -0
- data/spec/controller/abstract_controller_spec.rb +132 -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_context_spec.rb +123 -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_helper_spec.rb +53 -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/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/MultipleActions/actions.haml +7 -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/rem ExplicitRenderSpec/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/another_action.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/controller_render_spec.rb +217 -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/error_handling_spec.rb +117 -0
- data/spec/controller/http_controller_spec.rb +130 -0
- data/spec/controller/spec_helper.rb +19 -0
- data/spec/conveyor/conveyor_spec.rb +124 -0
- data/spec/conveyor/spec_helper.rb +3 -0
- data/spec/environment/config_spec/config.default.yml +3 -0
- data/spec/environment/config_spec/config.development.yml +3 -0
- data/spec/environment/config_spec/config.yml +5 -0
- data/spec/environment/config_spec.rb +30 -0
- data/spec/environment/environment_spec/path1/file1 +0 -0
- data/spec/environment/environment_spec/path1/some_folder/some_file +0 -0
- data/spec/environment/environment_spec/path2/file2 +0 -0
- data/spec/environment/environment_spec/path2/some_folder/some_file +0 -0
- data/spec/environment/environment_spec.rb +65 -0
- data/spec/environment/logger_spec.rb +19 -0
- data/spec/environment/minimal_app_spec/app.rb +1 -0
- data/spec/environment/minimal_app_spec.rb +25 -0
- data/spec/environment/spec_helper.rb +1 -0
- data/spec/environment/standard_app_spec/app/lib/app/init.rb +3 -0
- data/spec/environment/standard_app_spec/plugin_a/lib/plugin_a/init.rb +1 -0
- data/spec/environment/standard_app_spec/plugin_b/lib/emptygit +0 -0
- data/spec/environment/standard_app_spec.rb +48 -0
- data/spec/html/basic_html_helper_spec.rb +29 -0
- data/spec/html/form_helper_spec.rb +63 -0
- data/spec/html/javascript_helper_spec.rb +15 -0
- data/spec/html/model_helper_spec.rb +81 -0
- data/spec/html/scoped_params_spec.rb +15 -0
- data/spec/html/spec_helper.rb +28 -0
- data/spec/http/http_spec/app/lib/app/init.rb +10 -0
- data/spec/http/http_spec/app/runtime/public/emptygit +0 -0
- data/spec/http/http_spec/plugin_a/lib/plugin_a/init.rb +0 -0
- data/spec/http/http_spec/plugin_b/lib/plugin_b/init.rb +5 -0
- data/spec/http/http_spec/plugin_b/static/emptygit +0 -0
- data/spec/http/http_spec.rb +51 -0
- data/spec/http/micelaneous_spec.rb +13 -0
- data/spec/http/spec_helper.rb +5 -0
- data/spec/integration/basic_spec/views/smoke_test_spec/action.erb +1 -0
- data/spec/integration/basic_spec.rb +79 -0
- data/spec/integration/controller_routing_helper_spec.rb +84 -0
- data/spec/integration/flash_spec.rb +206 -0
- data/spec/integration/spec_helper.rb +5 -0
- data/spec/integration/spec_helper_spec.rb +63 -0
- data/spec/integration/view_routing_helper_spec.rb +134 -0
- data/spec/mail/mail_controller_spec/views/body_template_spec/signup.erb +1 -0
- data/spec/mail/mail_controller_spec.rb +61 -0
- data/spec/mail/spec_helper.rb +7 -0
- data/spec/remote/remote_spec.rb +75 -0
- data/spec/remote/spec_helper.rb +17 -0
- data/spec/router/alias_router_spec.rb +98 -0
- data/spec/router/basic_spec.rb +111 -0
- data/spec/router/configurator_spec.rb +18 -0
- data/spec/router/integration_spec.rb +42 -0
- data/spec/router/persistent_params_spec.rb +65 -0
- data/spec/router/restful_router_spec.rb +120 -0
- data/spec/router/routing_helper_spec.rb +55 -0
- data/spec/router/spec_helper.rb +20 -0
- data/spec/support/callbacks_spec.rb +157 -0
- data/spec/support/filters_spec.rb +60 -0
- data/spec/support/spec_helper.rb +4 -0
- data/spec/template/spec_helper.rb +6 -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/format_for_partials/_form.html.erb +1 -0
- data/spec/template/template_spec/views/format_for_partials/dialog.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/_edit.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/template_spec.rb +204 -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/encoding/erb.erb +1 -0
- data/spec/template/tilt_spec/views/encoding/haml.haml +1 -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
- data/spec/template/tilt_spec.rb +98 -0
- metadata +531 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'http/spec_helper'
|
2
|
+
|
3
|
+
describe "HTTP basics" do
|
4
|
+
it "response should accept string status messages" do
|
5
|
+
response = Rad::Response.new
|
6
|
+
|
7
|
+
response.status = :error
|
8
|
+
response.status.should == 500
|
9
|
+
|
10
|
+
response.status = :ok
|
11
|
+
response.status.should == 200
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
some content
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'integration/spec_helper'
|
2
|
+
|
3
|
+
describe "Integration" do
|
4
|
+
with_environment
|
5
|
+
with_http
|
6
|
+
with_load_path spec_dir
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
HttpController = Rad::HttpController
|
10
|
+
load 'rad/profiles/web.rb'
|
11
|
+
end
|
12
|
+
|
13
|
+
after :all do
|
14
|
+
remove_constants %w(
|
15
|
+
HttpController
|
16
|
+
SmokeTestSpec
|
17
|
+
JsonFormatSpec
|
18
|
+
RequestAndSessionSpec
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "smoke test" do
|
23
|
+
class ::SmokeTestSpec
|
24
|
+
inherit HttpController
|
25
|
+
|
26
|
+
def action
|
27
|
+
respond_to do |format|
|
28
|
+
format.json{render json: {a: 'b'}}
|
29
|
+
format.html{render inline: "some content"}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
wcall("/smoke_test_spec/action")
|
35
|
+
response.body.should == %(some content)
|
36
|
+
|
37
|
+
wcall("/smoke_test_spec/action", format: 'json')
|
38
|
+
response.body.should == %({"a":"b"})
|
39
|
+
end
|
40
|
+
|
41
|
+
it "json" do
|
42
|
+
class ::JsonFormatSpec
|
43
|
+
inherit HttpController
|
44
|
+
|
45
|
+
def action
|
46
|
+
render json: {a: 'b'}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
wcall("/json_format_spec/action.json")
|
51
|
+
response.body.should == %({"a":"b"})
|
52
|
+
# response.rson.should == {'result' => 'value'}
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should have workspace, request, env, and session" do
|
56
|
+
class ::RequestAndSessionSpec
|
57
|
+
inherit HttpController
|
58
|
+
|
59
|
+
inject workspace: :workspace
|
60
|
+
def action
|
61
|
+
workspace.should_not == nil
|
62
|
+
workspace.env.should_not == nil
|
63
|
+
workspace.request.should_not == nil
|
64
|
+
workspace.request.session.should_not == nil
|
65
|
+
|
66
|
+
self.class.request_and_session_passed = true
|
67
|
+
|
68
|
+
render json: {a: 'b'}
|
69
|
+
end
|
70
|
+
|
71
|
+
class << self
|
72
|
+
attr_accessor :request_and_session_passed
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
wcall('/request_and_session_spec/action.json')
|
77
|
+
RequestAndSessionSpec.request_and_session_passed.should be_true
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'html/spec_helper'
|
2
|
+
require 'integration/spec_helper'
|
3
|
+
|
4
|
+
describe "UrlHelper" do
|
5
|
+
before :all do
|
6
|
+
class ControllerStub
|
7
|
+
inherit Rad::ControllerRoutingHelper, Rad::ControllerMicelaneousHelper
|
8
|
+
|
9
|
+
def url_for *args
|
10
|
+
args.first
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after :all do
|
16
|
+
remove_constants :ControllerStub
|
17
|
+
end
|
18
|
+
|
19
|
+
before :each do
|
20
|
+
@c = ControllerStub.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def stub_workspace
|
24
|
+
@response = Rad::Response.new
|
25
|
+
@params = Rad::Params.new
|
26
|
+
|
27
|
+
@workspace = Object.new
|
28
|
+
@workspace.stub(:params).and_return(@params)
|
29
|
+
@workspace.stub(:response).and_return(@response)
|
30
|
+
|
31
|
+
@c.stub(:workspace).and_return(@workspace)
|
32
|
+
end
|
33
|
+
|
34
|
+
def within_request &block
|
35
|
+
@response.body = catch(:halt_render){block.call}
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "redirect_to" do
|
39
|
+
before :each do
|
40
|
+
stub_workspace
|
41
|
+
end
|
42
|
+
|
43
|
+
it "html format" do
|
44
|
+
@params.format = 'html'
|
45
|
+
|
46
|
+
within_request{@c.redirect_to('/some_book')}
|
47
|
+
@response.status.should == 301
|
48
|
+
@response.headers['Location'].should == "/some_book"
|
49
|
+
@response.body.should =~ /You are being/
|
50
|
+
end
|
51
|
+
|
52
|
+
it "full url, special case (from error)" do
|
53
|
+
@params.format = 'html'
|
54
|
+
|
55
|
+
within_request{@c.redirect_to('http://localhost/some_book')}
|
56
|
+
@response.status.should == 301
|
57
|
+
@response.headers['Location'].should == "http://localhost/some_book"
|
58
|
+
@response.body.should =~ /You are being/
|
59
|
+
end
|
60
|
+
|
61
|
+
it "js format" do
|
62
|
+
@params.format = 'js'
|
63
|
+
|
64
|
+
within_request{@c.redirect_to('/some_book')}
|
65
|
+
@response.status.should == 200
|
66
|
+
@response.headers['Location'].should be_blank
|
67
|
+
@response.body_as_string.should == "window.location = '/some_book';"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "reload_page" do
|
72
|
+
before :each do
|
73
|
+
stub_workspace
|
74
|
+
end
|
75
|
+
|
76
|
+
it "basic" do
|
77
|
+
@params.format = 'js'
|
78
|
+
|
79
|
+
within_request{@c.reload_page}
|
80
|
+
@response.status.should == 200
|
81
|
+
@response.body_as_string.should =~ /reload/
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
require 'html/spec_helper'
|
2
|
+
require 'integration/spec_helper'
|
3
|
+
|
4
|
+
describe "Flash" do
|
5
|
+
with_environment environment: :development
|
6
|
+
|
7
|
+
class MockFlashContext < Rad::MockTemplateContext
|
8
|
+
include Rad::FlashHelper , Rad::ControllerRoutingHelper
|
9
|
+
|
10
|
+
def url_for *args;
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class FlashTestRenderCaller < Rad::Processor
|
15
|
+
def call
|
16
|
+
context = MockFlashContext.new
|
17
|
+
block = workspace.check_flash.request
|
18
|
+
catch :halt_render do
|
19
|
+
block.call context if block
|
20
|
+
end
|
21
|
+
workspace.request_done = true
|
22
|
+
|
23
|
+
next_processor.call
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class FlashTestHelper < Rad::Processor
|
28
|
+
def call
|
29
|
+
block = workspace.check_flash.before_request
|
30
|
+
block.call workspace if block
|
31
|
+
workspace.before_request_done = true
|
32
|
+
|
33
|
+
next_processor.call
|
34
|
+
|
35
|
+
block = workspace.check_flash.after_request
|
36
|
+
block.call workspace if block
|
37
|
+
workspace.after_request_done = true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
before :all do
|
42
|
+
rad.after :environment do
|
43
|
+
rad.conveyors.web do |web|
|
44
|
+
web.use Rad::Processors::PrepareParams
|
45
|
+
web.use FlashTestHelper
|
46
|
+
web.use Rad::Processors::PrepareFlash
|
47
|
+
web.use FlashTestRenderCaller
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def check_flash opt
|
53
|
+
workspace = nil
|
54
|
+
result = Rad::HTTPAdapter.call(Rad::HTTPAdapter.mock_environment, check_flash: opt.to_openobject) do |c|
|
55
|
+
c.call
|
56
|
+
workspace = rad[:workspace]
|
57
|
+
end
|
58
|
+
|
59
|
+
workspace.before_request_done.should be_true
|
60
|
+
workspace.request_done.should be_true
|
61
|
+
workspace.after_request_done.should be_true
|
62
|
+
workspace
|
63
|
+
end
|
64
|
+
|
65
|
+
it "flash should be extracted from session if there's any" do
|
66
|
+
check_flash(
|
67
|
+
before_request: lambda{|workspace|
|
68
|
+
workspace.params.format = 'html'
|
69
|
+
workspace.request.session['flash'] = {info: 'Ok'}.to_json
|
70
|
+
},
|
71
|
+
request: lambda{|context|
|
72
|
+
context.flash.info.should == "Ok"
|
73
|
+
},
|
74
|
+
after_request: lambda{|workspace|
|
75
|
+
workspace.request.session['flash'].should be_nil
|
76
|
+
}
|
77
|
+
)
|
78
|
+
|
79
|
+
check_flash(
|
80
|
+
before_request: lambda{|workspace|
|
81
|
+
workspace.params.format = 'html'
|
82
|
+
},
|
83
|
+
request: lambda{|context|
|
84
|
+
context.flash.info.should be_nil
|
85
|
+
}
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "flash should be seen in the same request" do
|
90
|
+
check_flash(
|
91
|
+
before_request: lambda{|workspace|
|
92
|
+
workspace.params.format = 'html'
|
93
|
+
},
|
94
|
+
request: lambda{|context|
|
95
|
+
context.flash.info = "Ok"
|
96
|
+
context.flash.info.should == "Ok"
|
97
|
+
},
|
98
|
+
after_request: lambda{|workspace|
|
99
|
+
workspace.request.session['flash'].should be_nil
|
100
|
+
}
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "flash with :redirect should be saved for next request in session" do
|
105
|
+
check_flash(
|
106
|
+
before_request: lambda{|workspace|
|
107
|
+
workspace.params.format = 'html'
|
108
|
+
},
|
109
|
+
request: lambda{|context|
|
110
|
+
context.flash.info = "Ok"
|
111
|
+
context.flash.info.should == "Ok"
|
112
|
+
context.redirect_to '/'
|
113
|
+
context.flash.info.should be_nil
|
114
|
+
},
|
115
|
+
after_request: lambda{|workspace|
|
116
|
+
workspace.request.session['flash'].should == {info: 'Ok'}.to_json
|
117
|
+
}
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "AJAX ('js' format) flash should be displayed in the same request" do
|
122
|
+
check_flash(
|
123
|
+
before_request: lambda{|workspace|
|
124
|
+
workspace.params.format = 'js'
|
125
|
+
},
|
126
|
+
request: lambda{|context|
|
127
|
+
context.flash.info = "Ok"
|
128
|
+
context.flash.info.should == "Ok"
|
129
|
+
},
|
130
|
+
after_request: lambda{|workspace|
|
131
|
+
workspace.request.session['flash'].should be_nil
|
132
|
+
}
|
133
|
+
)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "flash with AJAX redirect ('js' format) should be saved for next request in session" do
|
137
|
+
check_flash(
|
138
|
+
before_request: lambda{|workspace|
|
139
|
+
workspace.params.format = 'js'
|
140
|
+
},
|
141
|
+
request: lambda{|context|
|
142
|
+
context.flash.info = "Ok"
|
143
|
+
context.flash.info.should == "Ok"
|
144
|
+
context.redirect_to '/'
|
145
|
+
context.flash.info.should be_nil
|
146
|
+
},
|
147
|
+
after_request: lambda{|workspace|
|
148
|
+
workspace.request.session['flash'].should == {info: 'Ok'}.to_json
|
149
|
+
}
|
150
|
+
)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "multiple messages with non-AJAX request" do
|
154
|
+
check_flash(
|
155
|
+
before_request: lambda{|workspace|
|
156
|
+
workspace.request.session['flash'] = {info: 'Ok'}.to_json
|
157
|
+
},
|
158
|
+
request: lambda{|context|
|
159
|
+
context.flash.error = "Error"
|
160
|
+
context.flash.error.should == "Error"
|
161
|
+
|
162
|
+
context.flash.info.should == 'Ok'
|
163
|
+
},
|
164
|
+
after_request: lambda{|workspace|
|
165
|
+
workspace.request.session['flash'].should be_nil
|
166
|
+
}
|
167
|
+
)
|
168
|
+
|
169
|
+
check_flash(
|
170
|
+
before_request: lambda{|workspace|
|
171
|
+
workspace.params.format = 'js'
|
172
|
+
workspace.request.session['flash'] = {info: 'Ok'}.to_json
|
173
|
+
},
|
174
|
+
request: lambda{|context|
|
175
|
+
context.flash.error = "Error"
|
176
|
+
context.flash.error.should == "Error"
|
177
|
+
context.redirect_to '/'
|
178
|
+
context.flash.error.should be_nil
|
179
|
+
|
180
|
+
context.flash.info.should == 'Ok'
|
181
|
+
},
|
182
|
+
after_request: lambda{|workspace|
|
183
|
+
workspace.request.session['flash'].should == {error: 'Error'}.to_json
|
184
|
+
}
|
185
|
+
)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "multiple messages with AJAX request" do
|
189
|
+
check_flash(
|
190
|
+
before_request: lambda{|workspace|
|
191
|
+
workspace.params.format = 'js'
|
192
|
+
workspace.request.session['flash'] = {info: 'Ok'}.to_json
|
193
|
+
},
|
194
|
+
request: lambda{|context|
|
195
|
+
context.flash.error = "Error"
|
196
|
+
context.flash.error.should == "Error"
|
197
|
+
|
198
|
+
context.flash.info.should == 'Ok'
|
199
|
+
},
|
200
|
+
after_request: lambda{|workspace|
|
201
|
+
workspace.request.session['flash'].should be_nil
|
202
|
+
}
|
203
|
+
)
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "controller/spec_helper"
|
2
|
+
|
3
|
+
describe "spec helper" do
|
4
|
+
with_environment
|
5
|
+
with_http
|
6
|
+
with_router
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
load 'rad/profiles/web.rb'
|
10
|
+
|
11
|
+
class ::Planes
|
12
|
+
inherit Rad::HttpController
|
13
|
+
|
14
|
+
def fly
|
15
|
+
render inline: 'all right'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
after :all do
|
21
|
+
remove_constants :Planes
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'wcall' do
|
25
|
+
it "basic usage" do
|
26
|
+
wcall(Planes, :fly).should =~ /all right/
|
27
|
+
wcall('/planes/fly').should =~ /all right/
|
28
|
+
end
|
29
|
+
|
30
|
+
it "with :cycle scope" do
|
31
|
+
wcall(Planes, :fly){|c|
|
32
|
+
c.call
|
33
|
+
}.should =~ /all right/
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "set_wcall" do
|
37
|
+
before :all do
|
38
|
+
set_wcall controller: Planes
|
39
|
+
end
|
40
|
+
|
41
|
+
it "usage with handy shortcut" do
|
42
|
+
wcall(:fly).should =~ /all right/
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "routes" do
|
48
|
+
before :each do
|
49
|
+
router = rad[:router]
|
50
|
+
router.routes.unshift :restful_router, Rad::RestfulRouter.new
|
51
|
+
router.routes[:restful_router].add :planes, class: Planes
|
52
|
+
end
|
53
|
+
|
54
|
+
it "url_for, url_for_path" do
|
55
|
+
url_for(Planes, :fly).should == "/planes/fly"
|
56
|
+
url_for_path("/path", key: 'value').should == "/path?key=value"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "named routes" do
|
60
|
+
fly_planes_path.should == "/planes/fly"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'html/spec_helper'
|
2
|
+
require 'integration/spec_helper'
|
3
|
+
|
4
|
+
describe "UrlHelper" do
|
5
|
+
before :all do
|
6
|
+
class MockRouter < Rad::Router
|
7
|
+
def url_for_path path, params
|
8
|
+
path = if params.blank?
|
9
|
+
path
|
10
|
+
else
|
11
|
+
path + '?' + params.to_a.collect{|a, b| "#{a}=#{b}"}.join("&")
|
12
|
+
end
|
13
|
+
|
14
|
+
"url_for: #{path}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def url_for_class klass, method, params
|
18
|
+
path = "#{klass}.#{method}"
|
19
|
+
url_for_path path, params
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
MOCK_ROUTER = MockRouter.new :class
|
24
|
+
|
25
|
+
class MockUrlHelperContext < Rad::MockTemplateContext
|
26
|
+
inherit Rad::ViewRoutingHelper
|
27
|
+
|
28
|
+
def url_for *args
|
29
|
+
|
30
|
+
opt = args.extract_options!
|
31
|
+
format = opt[:format]
|
32
|
+
args << opt
|
33
|
+
|
34
|
+
# url = args.inspect.gsub('"', "'")
|
35
|
+
url = MOCK_ROUTER.url_for *args
|
36
|
+
|
37
|
+
# url = "url_for: #{args.to_s}"
|
38
|
+
url.marks.format = format
|
39
|
+
url
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
after :all do
|
45
|
+
remove_constants :MOCK_ROUTER, :MockRouter, :MockUrlHelperContext
|
46
|
+
end
|
47
|
+
|
48
|
+
before :each do
|
49
|
+
@t = MockUrlHelperContext.new
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "link_to" do
|
53
|
+
before :all do
|
54
|
+
rad[:config] = Rad::Config.new
|
55
|
+
end
|
56
|
+
|
57
|
+
after :all do
|
58
|
+
rad.clear
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should works with url_for attributes" do
|
62
|
+
@t.link_to('Book', Object, :method, {format: 'json'}, class: 'highlight').to_xhtml('a').
|
63
|
+
should_be_fuzzy_equal_to(class: "highlight", href: "url_for: Object.method?format=json", content: "Book")
|
64
|
+
|
65
|
+
@t.link_to(Object, :method, {format: 'json'}, class: 'highlight'){'Book'}.to_xhtml('a').
|
66
|
+
should_be_fuzzy_equal_to(class: "highlight", href: "url_for: Object.method?format=json", content: "Book")
|
67
|
+
|
68
|
+
@t.link_to('Book', :method).to_xhtml('a').
|
69
|
+
should_be_fuzzy_equal_to(href: "url_for: .method", content: "Book")
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should works with url_for_path attributes" do
|
73
|
+
@t.link_to('Book', '/some_book', class: 'highlight').to_xhtml('a').
|
74
|
+
should_be_fuzzy_equal_to(class: "highlight", href: "/some_book", content: "Book")
|
75
|
+
|
76
|
+
@t.link_to('/some_book', class: 'highlight'){'Book'}.to_xhtml('a').
|
77
|
+
should_be_fuzzy_equal_to(class: "highlight", href: "/some_book", content: "Book")
|
78
|
+
|
79
|
+
@t.link_to('/some_book'){'Book'}.to_xhtml('a').
|
80
|
+
should_be_fuzzy_equal_to(href: "/some_book", content: "Book")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "links for 'js', 'json' formats should be automatically became remote" do
|
84
|
+
@t.link_to('Book', @t.url_for('/some_book', format: 'json')).to_xhtml('a').should_be_fuzzy_equal_to(
|
85
|
+
href: "url_for: /some_book?format=json", content: "Book",
|
86
|
+
onclick: "$(this).link_to({method: 'get', ajax: true}); return false;"
|
87
|
+
)
|
88
|
+
|
89
|
+
@t.link_to('Book', :method, {format: 'js'}, class: 'highlight').to_xhtml('a').should_be_fuzzy_equal_to(
|
90
|
+
href: "url_for: .method?format=js", content: "Book", class: 'highlight',
|
91
|
+
onclick: "$(this).link_to({method: 'get', ajax: true}); return false;"
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "confirm" do
|
96
|
+
@t.link_to('Book', '/some_book', confirm: 'Are you shure?').to_xhtml('a').should_be_fuzzy_equal_to(
|
97
|
+
href: "/some_book", content: "Book",
|
98
|
+
onclick: "return confirm('Are you shure?');"
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "POST method" do
|
103
|
+
@t.link_to('Book', '/some_book', method: :post).to_xhtml('a').should_be_fuzzy_equal_to(
|
104
|
+
href: "/some_book", content: "Book",
|
105
|
+
onclick: "$(this).link_to({method: 'post'}); return false;"
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "remote" do
|
110
|
+
@t.link_to('Book', '/some_book', remote: true).to_xhtml('a').should_be_fuzzy_equal_to(
|
111
|
+
href: "/some_book", content: "Book",
|
112
|
+
onclick: "$(this).link_to({method: 'get', ajax: true}); return false;"
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
it ":back" do
|
117
|
+
env = Object.new
|
118
|
+
env.stub(:[]).and_return('/go_back')
|
119
|
+
request = Object.new
|
120
|
+
request.stub(:env).and_return(env)
|
121
|
+
workspace = Object.new
|
122
|
+
workspace.stub(:request).and_return(request)
|
123
|
+
@t.stub(:workspace).and_return(workspace)
|
124
|
+
|
125
|
+
@t.link_to('Book', :back).to_xhtml('a').should_be_fuzzy_equal_to(href: "/go_back", content: "Book")
|
126
|
+
@t.link_to('Book', :back, class: '_some_js_mark').to_xhtml('a').
|
127
|
+
should_be_fuzzy_equal_to(href: "/go_back", class: '_some_js_mark', content: "Book")
|
128
|
+
end
|
129
|
+
|
130
|
+
it "#" do
|
131
|
+
@t.link_to('Book', '#').to_xhtml('a').should_be_fuzzy_equal_to(href: "#", content: "Book")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello <%= @name %>, signup notification.
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "mail/spec_helper"
|
2
|
+
|
3
|
+
describe "MailController" do
|
4
|
+
with_environment
|
5
|
+
with_mail
|
6
|
+
with_view_path "#{spec_dir}/views"
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
MailController = Rad::MailController
|
10
|
+
end
|
11
|
+
|
12
|
+
after :all do
|
13
|
+
remove_constants %w(
|
14
|
+
MailController
|
15
|
+
ExplicitBodySpec
|
16
|
+
BodyTemplateSpec
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def common_letter
|
21
|
+
{from: "john@mail.com", to: "ben@mail.com", subject: "hi there"}.to_openobject
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "building letter" do
|
25
|
+
it "shouldn't render view if body explicitly specified" do
|
26
|
+
class ::ExplicitBodySpec
|
27
|
+
inherit MailController
|
28
|
+
|
29
|
+
def signup model
|
30
|
+
@from, @to, @subject = model.from, model.to, model.subject
|
31
|
+
@body = "Hello Ben, signup notification."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
letter = ExplicitBodySpec.signup(common_letter.merge(body: 'Hello Ben, signup notification.'))
|
36
|
+
letter.to_h.to_openobject.should == common_letter.merge(body: 'Hello Ben, signup notification.')
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should use template for body" do
|
40
|
+
class ::BodyTemplateSpec
|
41
|
+
inherit MailController
|
42
|
+
|
43
|
+
def signup model, name
|
44
|
+
@name = name
|
45
|
+
@from, @to, @subject = model.from, model.to, model.subject
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
letter = BodyTemplateSpec.signup(common_letter, "Ben")
|
50
|
+
letter.to_h.to_openobject.should == common_letter.merge(body: 'Hello Ben, signup notification.')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "delivering" do
|
55
|
+
letter = Rad::Letter.new common_letter.merge(body: "some text")
|
56
|
+
letter.deliver
|
57
|
+
letter.deliver
|
58
|
+
|
59
|
+
sent_letters.should == [letter, letter]
|
60
|
+
end
|
61
|
+
end
|