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,124 @@
|
|
1
|
+
require "conveyor/spec_helper"
|
2
|
+
|
3
|
+
describe "Conveyor" do
|
4
|
+
inject conveyors: :conveyors
|
5
|
+
|
6
|
+
with_environment environment: :development
|
7
|
+
|
8
|
+
def call_conveyor
|
9
|
+
r = conveyors.web.call(result: [])
|
10
|
+
r.result
|
11
|
+
end
|
12
|
+
|
13
|
+
it "smoke test" do
|
14
|
+
class SmokeTestASpec < Rad::Processor
|
15
|
+
def call
|
16
|
+
workspace.result << :a_before
|
17
|
+
next_processor.call
|
18
|
+
workspace.result << :a_after
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class SmokeTestBSpec < Rad::Processor
|
23
|
+
def call
|
24
|
+
rad[:workspace].result << :b_before
|
25
|
+
next_processor.call
|
26
|
+
rad[:workspace].result << :b_after
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
conveyors.web.use SmokeTestASpec
|
31
|
+
conveyors.web.use SmokeTestBSpec
|
32
|
+
call_conveyor.should == [:a_before, :b_before, :b_after, :a_after]
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "error handling" do
|
36
|
+
it "common case" do
|
37
|
+
class CommonCaseASpec < Rad::Processor
|
38
|
+
def call
|
39
|
+
workspace.result << :a_before
|
40
|
+
|
41
|
+
begin
|
42
|
+
next_processor.call
|
43
|
+
rescue StandardError => e
|
44
|
+
workspace.result << e.message
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class CommonCaseBSpec < Rad::Processor
|
50
|
+
def call
|
51
|
+
workspace.result << :b_before
|
52
|
+
raise 'error before'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
conveyors.web.use CommonCaseASpec
|
57
|
+
conveyors.web.use CommonCaseBSpec
|
58
|
+
call_conveyor.should == [:a_before, :b_before, "error before"]
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should raise error if not catched" do
|
62
|
+
class NotCatchedErrorSpec < Rad::Processor
|
63
|
+
def call
|
64
|
+
workspace.result << :before
|
65
|
+
raise 'error before'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
conveyors.web.use NotCatchedErrorSpec
|
70
|
+
lambda{call_conveyor}.should raise_error(/error before/)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "in after block" do
|
74
|
+
class ErrorInAfterBlockASpec < Rad::Processor
|
75
|
+
def call
|
76
|
+
workspace.result << :a_before
|
77
|
+
|
78
|
+
begin
|
79
|
+
next_processor.call
|
80
|
+
rescue StandardError => e
|
81
|
+
workspace.result << e.message
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
class ErrorInAfterBlockBSpec < Rad::Processor
|
88
|
+
def call
|
89
|
+
workspace.result << :b_before
|
90
|
+
next_processor.call
|
91
|
+
raise 'error after'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
conveyors.web.use ErrorInAfterBlockASpec
|
97
|
+
conveyors.web.use ErrorInAfterBlockBSpec
|
98
|
+
call_conveyor.should == [:a_before, :b_before, "error after"]
|
99
|
+
end
|
100
|
+
|
101
|
+
it "bubbling (from error)" do
|
102
|
+
class ErrorBubblingASpec < Rad::Processor
|
103
|
+
def call
|
104
|
+
begin
|
105
|
+
next_processor.call
|
106
|
+
rescue RuntimeError => e
|
107
|
+
workspace.result << e.message
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class ErrorBubblingBSpec < Rad::Processor
|
113
|
+
def call
|
114
|
+
raise 'error'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
conveyors.web.use ErrorBubblingASpec
|
119
|
+
conveyors.web.use ErrorBubblingBSpec
|
120
|
+
|
121
|
+
call_conveyor.should == ['error']
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'environment/spec_helper'
|
2
|
+
|
3
|
+
require 'rad/environment'
|
4
|
+
require 'rad/spec/environment'
|
5
|
+
|
6
|
+
describe 'config' do
|
7
|
+
before :each do
|
8
|
+
@c = Rad::Config.new
|
9
|
+
@c.environment = 'development'
|
10
|
+
@c.key = 'value'
|
11
|
+
@c.key2 = 'value2'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should merge with existing config" do
|
15
|
+
@c.key2!.should == 'value2'
|
16
|
+
|
17
|
+
@c.merge_config! "#{spec_dir}/config.yml"
|
18
|
+
@c.key!.should == 'value'
|
19
|
+
@c.key2!.should == 'another_value'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should merge hashes (with the following order: config.default <= config <= config.environment)" do
|
23
|
+
@c.merge_config! "#{spec_dir}/config.yml"
|
24
|
+
|
25
|
+
@c.user_service.default_key("invalid").should == 'default_value'
|
26
|
+
@c.user_service.key("invalid").should == 'value'
|
27
|
+
@c.user_service.test_key("invalid").should == 'test_value'
|
28
|
+
@c.user_service.name.should == 'test_name'
|
29
|
+
end
|
30
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'environment/spec_helper'
|
2
|
+
|
3
|
+
require 'rad/environment'
|
4
|
+
require 'rad/spec/environment'
|
5
|
+
|
6
|
+
describe "Environment basic spec" do
|
7
|
+
with_load_path "#{spec_dir}/path1", "#{spec_dir}/path2"
|
8
|
+
|
9
|
+
inject env: :environment
|
10
|
+
|
11
|
+
before :all do
|
12
|
+
@path1, @path2 = "#{spec_dir}/path1", "#{spec_dir}/path2"
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'files' do
|
16
|
+
with_environment
|
17
|
+
|
18
|
+
it "find_files?" do
|
19
|
+
env.file_exist?('/some_folder/some_file').should be_true
|
20
|
+
env.file_exist?('/file1').should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "find_file" do
|
24
|
+
lambda{env.find_file('/some_folder/some_file')}.should raise_error(/Found multiple files/)
|
25
|
+
env.find_file('/file1').should == "#{@path1}/file1"
|
26
|
+
lambda{env.find_file('file1')}.should raise_error(AssertionError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "find_files" do
|
30
|
+
env.find_files('/some_folder/some_file').sort.should == ["#{@path1}/some_folder/some_file", "#{@path2}/some_folder/some_file"]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "find_files_by_pattern" do
|
34
|
+
env.find_files_by_pattern('/*/some_file').sort.should == ["#{@path1}/some_folder/some_file", "#{@path2}/some_folder/some_file"]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'config' do
|
39
|
+
with_environment
|
40
|
+
|
41
|
+
it "smoke test" do
|
42
|
+
config
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "spec should be isolated (via swap_metadata)" do
|
47
|
+
describe "first spec" do
|
48
|
+
with_environment
|
49
|
+
|
50
|
+
before :all do
|
51
|
+
rad.register(:spec_component)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "check" do
|
55
|
+
Micon.metadata.should include(:spec_component)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "second spec" do
|
60
|
+
it "check" do
|
61
|
+
Micon.metadata.should_not include(:spec_component)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'environment/spec_helper'
|
2
|
+
|
3
|
+
require 'rad/environment'
|
4
|
+
|
5
|
+
describe "Environment basic spec" do
|
6
|
+
before :all do
|
7
|
+
rad.clear
|
8
|
+
::SILENCE_LOGGER = true
|
9
|
+
end
|
10
|
+
|
11
|
+
after :all do
|
12
|
+
rad.clear
|
13
|
+
remove_constants :SILENCE_LOGGER
|
14
|
+
end
|
15
|
+
|
16
|
+
it "logger should work before Rad initialized" do
|
17
|
+
rad[:logger].should_not be_nil
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
rad[:config].environment = :test
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'environment/spec_helper'
|
2
|
+
|
3
|
+
require 'rad/environment'
|
4
|
+
|
5
|
+
describe "Environment basic spec" do
|
6
|
+
inject env: :environment
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
load "#{spec_dir}/app.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
after :all do
|
13
|
+
rad.clear
|
14
|
+
end
|
15
|
+
|
16
|
+
it "core components" do
|
17
|
+
rad[:logger].should_not be_nil
|
18
|
+
rad[:environment].should_not be_nil
|
19
|
+
rad[:config].should_not be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "application runtime_dir" do
|
23
|
+
env.config.runtime_dir?.should be_false
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rspec_ext'
|
@@ -0,0 +1 @@
|
|
1
|
+
SpecResult << "plugin_a"
|
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'environment/spec_helper'
|
2
|
+
|
3
|
+
require 'rad/environment'
|
4
|
+
require 'rad/spec/environment'
|
5
|
+
|
6
|
+
describe "Environment basic spec" do
|
7
|
+
before :each do
|
8
|
+
SpecResult.clear
|
9
|
+
end
|
10
|
+
|
11
|
+
inject environment: :environment
|
12
|
+
|
13
|
+
the_spec_dir = with_tmp_spec_dir
|
14
|
+
|
15
|
+
with_load_path(
|
16
|
+
"#{the_spec_dir}/plugin_a/lib",
|
17
|
+
"#{the_spec_dir}/plugin_b/lib",
|
18
|
+
"#{the_spec_dir}/app/lib"
|
19
|
+
)
|
20
|
+
|
21
|
+
with_environment runtime_dir: the_spec_dir
|
22
|
+
|
23
|
+
before :all do
|
24
|
+
Env = Rad::Environment
|
25
|
+
::SpecResult = []
|
26
|
+
end
|
27
|
+
|
28
|
+
before :each do
|
29
|
+
load "app/init.rb"
|
30
|
+
end
|
31
|
+
|
32
|
+
after :all do
|
33
|
+
remove_constants %w(SpecResult)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "core components" do
|
37
|
+
rad[:logger].should_not be_nil
|
38
|
+
rad[:environment].should_not be_nil
|
39
|
+
rad[:config].should_not be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "loading order" do
|
43
|
+
rad[:environment]
|
44
|
+
rad.register :custom_component
|
45
|
+
rad[:custom_component]
|
46
|
+
SpecResult.should == %w(init plugin_a)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'html/spec_helper'
|
2
|
+
|
3
|
+
require 'rad/spec/xhtml'
|
4
|
+
|
5
|
+
describe "BasicHtmlHelper" do
|
6
|
+
before :each do
|
7
|
+
@t = Rad::MockTemplateContext.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "tag" do
|
11
|
+
@t.tag(:div, 'content', class: 'hidden').should == %(<div class="hidden">content</div>)
|
12
|
+
@t.tag(:div, class: 'hidden'){'content'}
|
13
|
+
@t.buffer.should == %(<div class="hidden">content</div>)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "stylesheet_link_tag" do
|
17
|
+
@t.stylesheet_link_tag('/public/js/app.css').should == %(<link href="/public/js/app.css" media="screen" rel="stylesheet" type="text/css"></link>)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "image_tag" do
|
21
|
+
@t.image_tag('face.png', width: 100).should == %(<img src="face.png" width="100"></img>)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "basic html tags" do
|
25
|
+
it "label" do
|
26
|
+
@t.label_tag('book', 'Book').should == %(<label for="book">Book</label>)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'html/spec_helper'
|
2
|
+
|
3
|
+
describe "FormHelper" do
|
4
|
+
class MockFormHelperContext < Rad::MockTemplateContext
|
5
|
+
include Rad::FormHelper
|
6
|
+
end
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@t = MockFormHelperContext.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "check_box_tag" do
|
13
|
+
@t.check_box_tag('item').should == %(<input class=" checkbox_input" name="item" type="checkbox" value="1"></input>)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "field_set_tag" do
|
17
|
+
@t.field_set_tag{'content'}.should == %(<fieldset class=" fieldset_input">content</fieldset>)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "file_field_tag" do
|
21
|
+
@t.file_field_tag('item').should == %(<input class=" file_input" name="item" type="file"></input>)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "form_tag" do
|
25
|
+
@t.form_tag(id: 'the_form', action: '/'){"content"}
|
26
|
+
@t.buffer.to_xhtml('#the_form').should_be_fuzzy_equal_to(
|
27
|
+
id: 'the_form', action: '/', content: 'content', method: 'post'
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "hidden_field_tag" do
|
32
|
+
@t.hidden_field_tag('item', 'hidden value').should == %(<input class=" hidden_input" name="item" type="hidden" value="hidden value"></input>)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "password_field_tag" do
|
36
|
+
@t.password_field_tag('item').should == %(<input class=" password_input" name="item" type="password"></input>)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "radio_button_tag" do
|
40
|
+
@t.radio_button_tag('item').should == %(<input class=" radio_input" name="item" type="radio" value="1"></input>)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "select_tag" do
|
44
|
+
@t.select_tag('item', nil, [["Dollar", "$"], ["Kroner", "DKK"]]).should ==
|
45
|
+
%(<select class=" select_input" name="item">\n<option value="$">Dollar</option>\n<option value="DKK">Kroner</option>\n</select>)
|
46
|
+
|
47
|
+
@t.select_tag('item', '$', [["Dollar", "$"], ["Kroner", "DKK"]], class: 'highlight').should ==
|
48
|
+
%(<select class="highlight select_input" name="item">\n<option selected="selected" value="$">Dollar</option>\n\
|
49
|
+
<option value="DKK">Kroner</option>\n</select>)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "submit_tag" do
|
53
|
+
@t.submit_tag('ok').should == %(<input class=" submit_input" type="submit" value="ok"></input>)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "text_field_tag" do
|
57
|
+
@t.text_field_tag('item', 'value').should == %(<input class=" text_input" name="item" type="text" value="value"></input>)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "text_area_tag" do
|
61
|
+
@t.text_area_tag('item', 'value').should == %(<textarea class=" textarea_input" name="item">value</textarea>)
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'html/spec_helper'
|
2
|
+
|
3
|
+
describe "BasicHtmlHelper" do
|
4
|
+
class MockJavascriptHelperContext < Rad::MockTemplateContext
|
5
|
+
inherit Rad::JavascriptHelper
|
6
|
+
end
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@t = MockJavascriptHelperContext.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "javascript_include_tag" do
|
13
|
+
@t.javascript_include_tag('/public/js/app.js').should == %(<script src="/public/js/app.js" type="text/javascript"></script>)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'html/spec_helper'
|
2
|
+
|
3
|
+
describe "ModelHelper" do
|
4
|
+
class MockModelHelperContext < Rad::MockTemplateContext
|
5
|
+
inherit Rad::FormHelper
|
6
|
+
end
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@t = MockModelHelperContext.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "form_for" do
|
13
|
+
@t.form_for(:aname, nil, id: 'the_form', action: '/'){"content"}
|
14
|
+
@t.buffer.to_xhtml('#the_form').should_be_fuzzy_equal_to(
|
15
|
+
id: 'the_form', action: '/', content: 'content', method: 'post'
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "error_messages" do
|
20
|
+
@t.form_for(:aname, nil){|f| f.error_messages}
|
21
|
+
lambda{@t.buffer.to_xhtml('form div')}.should raise_error(/not found/)
|
22
|
+
|
23
|
+
model = {errors: {base: ['some error']}}
|
24
|
+
@t.buffer = ""
|
25
|
+
@t.form_for(:book, model){|f| f.error_messages}
|
26
|
+
@t.buffer.to_xhtml('form div').should_be_fuzzy_equal_to class: 'error_messages', content: 'some error'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "field error" do
|
30
|
+
model = {
|
31
|
+
title: "Super Hero",
|
32
|
+
errors: {title: ['some error in title']}
|
33
|
+
}
|
34
|
+
@t.form_for(:book, model){|f| f.text_field(:title)}
|
35
|
+
doc = @t.buffer.to_xhtml
|
36
|
+
doc.css("form div.field_error_messages").first.content.should == "some error in title"
|
37
|
+
doc.css("form span.field_with_errors input").first.should_be_fuzzy_equal_to name: "book[title]", value: "Super Hero"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should insert human readable label if not specified" do
|
41
|
+
model = {}
|
42
|
+
model.stub(:t).and_return{|k| "translated #{k}"}
|
43
|
+
|
44
|
+
@t.form_for(:book, model){|f| f.text_field(:title)}
|
45
|
+
@t.buffer.should =~ /translated title/
|
46
|
+
|
47
|
+
@t.form_for(:book, model){|f| f.text_field(:title, label: 'some label')}
|
48
|
+
@t.buffer.should =~ /some label/
|
49
|
+
end
|
50
|
+
|
51
|
+
it "field_helpers" do
|
52
|
+
model = {
|
53
|
+
available: false,
|
54
|
+
title: "Super Hero",
|
55
|
+
theme: 'simple'
|
56
|
+
}
|
57
|
+
|
58
|
+
@t.form_for(:book, model){|f| %{
|
59
|
+
#{f.check_box :available}
|
60
|
+
#{f.file_field :title}
|
61
|
+
#{f.hidden_field :title}
|
62
|
+
#{f.password_field :title}
|
63
|
+
#{f.radio_button :available}
|
64
|
+
#{f.submit 'Ok'}
|
65
|
+
#{f.text_field :title}
|
66
|
+
#{f.text_area :title}
|
67
|
+
#{f.select :theme, %w(a b)}
|
68
|
+
} }
|
69
|
+
doc = @t.buffer.to_xhtml
|
70
|
+
|
71
|
+
doc.css("*[type='checkbox']").first.should_be_fuzzy_equal_to name: "book[available]", value: '1'
|
72
|
+
doc.css("*[type='file']").first.should_be_fuzzy_equal_to name: "book[title]"
|
73
|
+
doc.css("*[type='hidden']").first.should_be_fuzzy_equal_to name: "book[title]", value: 'Super Hero'
|
74
|
+
doc.css("*[type='password']").first.should_be_fuzzy_equal_to name: "book[title]"
|
75
|
+
doc.css("*[type='radio']").first.should_be_fuzzy_equal_to name: "book[available]", value: '1'
|
76
|
+
doc.css("*[type='submit']").first.should_be_fuzzy_equal_to value: 'Ok'
|
77
|
+
doc.css("*[type='text']").first.should_be_fuzzy_equal_to name: "book[title]", value: 'Super Hero'
|
78
|
+
doc.css("textarea").first.should_be_fuzzy_equal_to name: "book[title]", content: 'Super Hero'
|
79
|
+
doc.css("select").first.should_be_fuzzy_equal_to name: "book[theme]"
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'html/spec_helper'
|
2
|
+
|
3
|
+
describe "ScopedParams" do
|
4
|
+
it "basic" do
|
5
|
+
workspace = Rad::Workspace.new.update(params: {"book[title]" => "Super Hero"})
|
6
|
+
|
7
|
+
@processor = Rad::Processors::ScopedParams.new(lambda{})
|
8
|
+
@processor.stub(:workspace).and_return(workspace)
|
9
|
+
@processor.call
|
10
|
+
|
11
|
+
workspace.params.should == {
|
12
|
+
book: {"title" => "Super Hero"}
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rspec_ext'
|
2
|
+
|
3
|
+
require 'rad/html'
|
4
|
+
|
5
|
+
module Rad
|
6
|
+
class MockTemplateContext
|
7
|
+
inject config: :config, workspace: :workspace
|
8
|
+
|
9
|
+
attr_accessor :output, :capture, :buffer
|
10
|
+
|
11
|
+
def capture &block
|
12
|
+
block.call
|
13
|
+
end
|
14
|
+
|
15
|
+
def concat value = nil
|
16
|
+
@buffer ||= ""
|
17
|
+
@buffer << value
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
inherit Rad::BasicHtmlHelper
|
22
|
+
# include BasicHtmlHelper, FlashHelper, FormHelper, JavascriptHelper, UrlHelper
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
require 'rad/spec/environment'
|
28
|
+
require 'rad/spec/xhtml'
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'http/spec_helper'
|
2
|
+
|
3
|
+
describe "HTTP basics" do
|
4
|
+
inject environment: :environment, conveyors: :conveyors
|
5
|
+
|
6
|
+
the_spec_dir = with_tmp_spec_dir
|
7
|
+
with_environment environment: :development, runtime_dir: "#{the_spec_dir}/app/runtime"
|
8
|
+
|
9
|
+
with_load_path(
|
10
|
+
"#{the_spec_dir}/app/lib",
|
11
|
+
"#{the_spec_dir}/plugin_a/lib",
|
12
|
+
"#{the_spec_dir}/plugin_b/lib",
|
13
|
+
)
|
14
|
+
|
15
|
+
before :all do
|
16
|
+
rad.after :environment do
|
17
|
+
rad.conveyors.web do |web|
|
18
|
+
web.use Rad::Processors::HttpWriter
|
19
|
+
web.use Rad::Processors::PrepareParams
|
20
|
+
web.use Rad::Processors::EvaluateFormat
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
after :all do
|
26
|
+
remove_constants %w(PrepareParamsStub)
|
27
|
+
end
|
28
|
+
|
29
|
+
before :each do
|
30
|
+
load "app/init.rb"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "public symlink" do
|
34
|
+
rad[:environment]
|
35
|
+
rad.config.environment.should == 'development'
|
36
|
+
File.should exist("#{spec_dir}/app/runtime/public/plugin_b")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "http call" do
|
40
|
+
workspace = nil
|
41
|
+
Rad::HTTPAdapter.call Rad::HTTPAdapter.mock_environment do |c|
|
42
|
+
c.call
|
43
|
+
workspace = rad[:workspace]
|
44
|
+
end
|
45
|
+
# .should == [200, {"Content-Type" => "text/html"}, ""]
|
46
|
+
|
47
|
+
workspace.delete(:env).should be_a(Hash)
|
48
|
+
expected_result = {path: "/", response: [200, {"Content-Type" => "text/html"}, ""], params: {format: 'html'}}
|
49
|
+
workspace.to_h.subset(expected_result.keys).should == expected_result
|
50
|
+
end
|
51
|
+
end
|