crystal_ext 0.0.7 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +70 -7
- data/lib/crystal/controller.rb +28 -0
- data/lib/crystal/controller/abstract_controller.rb +60 -0
- data/lib/crystal/controller/abstract_controller/micelaneous.rb +31 -0
- data/lib/crystal/controller/abstract_controller/render.rb +133 -0
- data/lib/crystal/controller/abstract_controller/responder.rb +17 -0
- data/lib/crystal/controller/controller_context.rb +7 -0
- data/lib/crystal/controller/http_controller.rb +43 -0
- data/lib/crystal/controller/processors/controller_caller.rb +40 -0
- data/lib/crystal/controller/processors/controller_error_handling.rb +53 -0
- data/lib/crystal/controller/processors/controller_logger.rb +13 -0
- data/lib/crystal/conveyor.rb +29 -0
- data/lib/crystal/conveyor/conveyor.rb +74 -0
- data/lib/crystal/conveyor/conveyors.rb +20 -0
- data/lib/crystal/conveyor/params.rb +22 -0
- data/lib/crystal/conveyor/processor.rb +68 -0
- data/lib/crystal/conveyor/processors/conveyor_logger.rb +24 -0
- data/lib/crystal/conveyor/workspace.rb +36 -0
- data/lib/crystal/environment.rb +52 -0
- data/lib/crystal/environment/config.rb +118 -0
- data/lib/crystal/environment/dependency_resolver.rb +107 -0
- data/lib/crystal/environment/environment.rb +5 -0
- data/lib/crystal/environment/files_helper.rb +42 -0
- data/lib/crystal/environment/logger.rb +21 -0
- data/lib/crystal/html.rb +28 -0
- data/lib/crystal/html/controller_helpers/controller_url_helper.rb +52 -0
- data/lib/crystal/html/controller_helpers/flash_helper.rb +5 -0
- data/lib/crystal/html/flash.rb +40 -0
- data/lib/crystal/html/include_into_controller.rb +24 -0
- data/lib/crystal/html/processors/prepare_flash.rb +26 -0
- data/lib/crystal/html/processors/scoped_params.rb +30 -0
- data/lib/crystal/html/view_helpers/basic_html_helper.rb +83 -0
- data/lib/crystal/html/view_helpers/form_helper.rb +104 -0
- data/lib/crystal/html/view_helpers/javascript_helper.rb +18 -0
- data/lib/crystal/html/view_helpers/model_helper.rb +119 -0
- data/lib/crystal/html/view_helpers/view_url_helper.rb +66 -0
- data/lib/crystal/http.rb +47 -0
- data/lib/crystal/http/http.rb +18 -0
- data/lib/crystal/http/http_adapter.rb +30 -0
- data/lib/crystal/http/middleware/static_files.rb +20 -0
- data/lib/crystal/http/processors/evaluate_format.rb +22 -0
- data/lib/crystal/http/processors/http_logger.rb +15 -0
- data/lib/crystal/http/processors/http_writer.rb +48 -0
- data/lib/crystal/http/processors/prepare_params.rb +24 -0
- data/lib/crystal/http/rack_config.rb +15 -0
- data/lib/crystal/http/support/rack/rack_adapter.rb +65 -0
- data/lib/crystal/http/support/rack/request.rb +12 -0
- data/lib/crystal/http/support/rack/response.rb +39 -0
- data/lib/crystal/mailer.rb +13 -0
- data/lib/crystal/mailer/mail.rb +7 -0
- data/lib/{crystal_ext/profiles/web_ext.rb → crystal/profiles/web.rb} +9 -15
- data/lib/crystal/profiles/web_require.rb +5 -0
- data/lib/crystal/remote.rb +9 -0
- data/lib/crystal/remote/processors/remote_caller.rb +54 -0
- data/lib/crystal/remote/processors/remote_logger.rb +13 -0
- data/lib/crystal/remote/remote.rb +15 -0
- data/lib/crystal/router.rb +19 -0
- data/lib/crystal/router/configurator.rb +23 -0
- data/lib/crystal/router/default_format_processor.rb +12 -0
- data/lib/crystal/router/default_router.rb +23 -0
- data/lib/crystal/router/named_router.rb +63 -0
- data/lib/crystal/router/processors/router.rb +22 -0
- data/lib/crystal/router/router.rb +218 -0
- data/lib/crystal/router/routing_helper.rb +17 -0
- data/lib/crystal/spec.rb +8 -0
- data/lib/crystal/spec/controller.rb +15 -0
- data/lib/crystal/spec/environment.rb +41 -0
- data/lib/crystal/spec/http.rb +67 -0
- data/lib/crystal/spec/mail.rb +20 -0
- data/lib/crystal/spec/remote.rb +9 -0
- data/lib/crystal/spec/view.rb +10 -0
- data/lib/crystal/spec/xhtml.rb +33 -0
- data/lib/crystal/support.rb +46 -0
- data/lib/crystal/support/active_support.rb +39 -0
- data/lib/crystal/support/active_support/micelaneous.rb +2 -0
- data/lib/crystal/support/addressable.rb +45 -0
- data/lib/crystal/support/buffered_logger.rb +38 -0
- data/lib/crystal/support/callbacks.rb +155 -0
- data/lib/crystal/support/exception.rb +20 -0
- data/lib/crystal/support/filters.rb +34 -0
- data/lib/crystal/support/format.rb +9 -0
- data/lib/crystal/support/gems.rb +8 -0
- data/lib/crystal/support/micon.rb +13 -0
- data/lib/crystal/support/mime.rb +11 -0
- data/lib/crystal/support/module.rb +44 -0
- data/lib/crystal/support/rson.rb +53 -0
- data/lib/crystal/support/ruby_ext_with_active_support.rb +4 -0
- data/lib/crystal/support/safe_hash.rb +135 -0
- data/lib/crystal/support/string.rb +26 -0
- data/lib/crystal/template.rb +21 -0
- data/lib/crystal/template/support/tilt.rb +68 -0
- data/lib/crystal/template/template.rb +244 -0
- data/lib/crystal/template/template_context.rb +57 -0
- data/lib/views/crystal_default_templates/development/error.html.erb +11 -0
- data/lib/views/crystal_default_templates/development/error.js.erb +1 -0
- data/readme.md +8 -11
- data/spec/_mailer/basic_spec.rb +110 -0
- data/spec/_mailer/helper.rb +7 -0
- data/spec/controller/abstract_controller_spec.rb +137 -0
- data/spec/controller/abstract_controller_spec/views/OperationsOrderSpec/action.erb +1 -0
- data/spec/controller/abstract_controller_spec/views/ViewVariablesSpec/action.erb +10 -0
- data/spec/controller/controller_context_spec.rb +122 -0
- data/spec/controller/controller_context_spec/views/ItemSpec/actions.erb +4 -0
- data/spec/controller/controller_context_spec/views/ItemSpec/show.erb +0 -0
- data/spec/controller/controller_context_spec/views/ItemSpec/update.erb +0 -0
- data/spec/controller/controller_context_spec/views/NamespaceSpec/ClassSpec/show.erb +0 -0
- data/spec/controller/controller_context_spec/views/PageSpec/actions.erb +3 -0
- data/spec/controller/controller_context_spec/views/PageSpec/show.erb +0 -0
- data/spec/controller/controller_context_spec/views/namespace_spec/class_spec/update.erb +0 -0
- data/spec/controller/controller_helper_spec.rb +57 -0
- data/spec/controller/controller_helper_spec/views/HelperMethodSpec/action.erb +1 -0
- data/spec/controller/controller_helper_spec/views/HelperSpec/action.erb +1 -0
- data/spec/controller/controller_render_spec.rb +191 -0
- data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/custom_template.erb +1 -0
- data/spec/controller/controller_render_spec/views/AnotherActionSpec/another_action.erb +1 -0
- data/spec/controller/controller_render_spec/views/AnotherLayout/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/ExplicitRenderSpec/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/ExplicitRenderSpec/another_action.erb +1 -0
- data/spec/controller/controller_render_spec/views/ForbidPartialAsActionSpec/_action.erb +1 -0
- data/spec/controller/controller_render_spec/views/FormatSpec/action.html.erb +1 -0
- data/spec/controller/controller_render_spec/views/FormatSpec/action.js.erb +1 -0
- data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_with_layout.erb +1 -0
- data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_without_layout.erb +1 -0
- data/spec/controller/controller_render_spec/views/LayoutSpec/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/layouts/admin.erb +1 -0
- data/spec/controller/controller_render_spec/views/layouts/app.html.erb +1 -0
- data/spec/controller/controller_render_spec/views/layouts/app.js.erb +1 -0
- data/spec/controller/controller_render_spec/views/some_template.erb +1 -0
- data/spec/controller/controller_render_spec/views/standalone.html.erb +1 -0
- data/spec/controller/error_handling_spec.rb +96 -0
- data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/a.erb +1 -0
- data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/b.erb +1 -0
- data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/c.erb +1 -0
- data/spec/controller/helper.rb +21 -0
- data/spec/controller/http_controller_spec.rb +89 -0
- data/spec/conveyor/conveyor_spec.rb +124 -0
- data/spec/conveyor/helper.rb +8 -0
- data/spec/environment/_dependency_resolver_spec.rb +50 -0
- data/spec/environment/environment_spec.rb +85 -0
- data/spec/environment/environment_spec/app/app_plugin/config/ec_layout +1 -0
- data/spec/environment/environment_spec/app/app_plugin/ec_some_file +1 -0
- data/spec/environment/environment_spec/app/config/config.test.yml +1 -0
- data/spec/environment/environment_spec/app/config/config.yml +2 -0
- data/spec/environment/environment_spec/gem_plugin/config/ec_layout +1 -0
- data/spec/environment/helper.rb +6 -0
- data/spec/environment/logger_spec.rb +18 -0
- data/spec/environment/minimal_app_spec.rb +27 -0
- data/spec/environment/minimal_app_spec/app.rb +3 -0
- data/spec/environment/standard_app_spec.rb +63 -0
- data/spec/environment/standard_app_spec_data/config/init.rb +18 -0
- data/spec/environment/standard_app_spec_data/plugin_a/plugin_a.rb +7 -0
- data/spec/html/basic_html_helper_spec.rb +28 -0
- data/spec/html/flash_spec.rb +184 -0
- data/spec/html/form_helper_spec.rb +56 -0
- data/spec/html/helper.rb +31 -0
- data/spec/html/javascript_helper_spec.rb +15 -0
- data/spec/html/model_helper_spec.rb +65 -0
- data/spec/html/scoped_params_spec.rb +17 -0
- data/spec/html/url_helper_spec.rb +151 -0
- data/spec/http/helper.rb +9 -0
- data/spec/http/http_spec.rb +56 -0
- data/spec/http/http_spec_data/config/init.rb +7 -0
- data/spec/http/http_spec_data/plugin_b/plugin_b.rb +6 -0
- data/spec/integration/basic_spec.rb +82 -0
- data/spec/integration/basic_spec/views/smoke_test_spec/action.erb +1 -0
- data/spec/integration/helper.rb +10 -0
- data/spec/remote/helper.rb +20 -0
- data/spec/remote/remote_spec.rb +75 -0
- data/spec/router/basic_spec.rb +130 -0
- data/spec/router/configurator_spec.rb +29 -0
- data/spec/router/helper.rb +24 -0
- data/spec/router/integration_spec.rb +42 -0
- data/spec/spec.opts +4 -0
- data/spec/support/callbacks_spec.rb +153 -0
- data/spec/support/filters_spec.rb +59 -0
- data/spec/support/helper.rb +7 -0
- data/spec/support/safe_hash_spec.rb +82 -0
- data/spec/template/helper.rb +8 -0
- data/spec/template/template_spec.rb +189 -0
- data/spec/template/template_spec/file.erb +1 -0
- data/spec/template/template_spec/views/basic/custom_context.erb +1 -0
- data/spec/template/template_spec/views/basic/extension.erb +1 -0
- data/spec/template/template_spec/views/basic/general.html.erb +5 -0
- data/spec/template/template_spec/views/basic/non_existing_format.html.erb +0 -0
- data/spec/template/template_spec/views/format/format.erb +1 -0
- data/spec/template/template_spec/views/format/format.html.erb +1 -0
- data/spec/template/template_spec/views/format/format.js.erb +1 -0
- data/spec/template/template_spec/views/layout/basic/content.erb +1 -0
- data/spec/template/template_spec/views/layout/basic/layout.erb +1 -0
- data/spec/template/template_spec/views/layout/content_for/content.erb +3 -0
- data/spec/template/template_spec/views/layout/content_for/layout.erb +3 -0
- data/spec/template/template_spec/views/layout/format/content.html.erb +1 -0
- data/spec/template/template_spec/views/layout/format/content.js.erb +1 -0
- data/spec/template/template_spec/views/layout/format/layout.html.erb +1 -0
- data/spec/template/template_spec/views/layout/format/layout.js.erb +1 -0
- data/spec/template/template_spec/views/layout/nested_yield/a.erb +1 -0
- data/spec/template/template_spec/views/layout/nested_yield/layout.erb +1 -0
- data/spec/template/template_spec/views/layout/nested_yield/layout_b.erb +1 -0
- data/spec/template/template_spec/views/layout/same_context/a.erb +1 -0
- data/spec/template/template_spec/views/layout/same_context/b.erb +1 -0
- data/spec/template/template_spec/views/layout/same_context/layout.erb +1 -0
- data/spec/template/template_spec/views/nested/format/a.erb +1 -0
- data/spec/template/template_spec/views/nested/format/b.erb +1 -0
- data/spec/template/template_spec/views/nested/relative/a.erb +1 -0
- data/spec/template/template_spec/views/nested/relative/b.erb +1 -0
- data/spec/template/template_spec/views/nested/relative/c.erb +1 -0
- data/spec/template/template_spec/views/nested/shared/c.erb +1 -0
- data/spec/template/template_spec/views/nesting_format/_dialog.html.erb +1 -0
- data/spec/template/template_spec/views/nesting_format/_form.html.erb +1 -0
- data/spec/template/template_spec/views/nesting_format/dialog.js.erb +1 -0
- data/spec/template/template_spec/views/other/template.erb +1 -0
- data/spec/template/template_spec/views/prefixes/_underscored.erb +1 -0
- data/spec/template/template_spec/views/prefixes/without_prefix.erb +1 -0
- data/spec/template/tilt_spec.rb +96 -0
- data/spec/template/tilt_spec/views/concat_and_capture.erb +1 -0
- data/spec/template/tilt_spec/views/concat_and_capture.haml +3 -0
- data/spec/template/tilt_spec/views/errors.erb +3 -0
- data/spec/template/tilt_spec/views/errors.haml +3 -0
- data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_erb.erb +4 -0
- data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_haml.haml +1 -0
- data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_erb.erb +1 -0
- data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_haml.haml +2 -0
- data/spec/template/tilt_spec/views/nested_capture_and_concat.haml +3 -0
- data/spec/template/tilt_spec/views/ugly.haml +3 -0
- data/spec/template/tilt_spec/views/yield.erb +1 -0
- metadata +303 -33
- data/lib/crystal_ext/defer_js.rb +0 -75
- data/lib/crystal_ext/ensure_no_www.rb +0 -39
- data/lib/crystal_ext/gems.rb +0 -2
- data/lib/crystal_ext/i18n.rb +0 -25
- data/lib/crystal_ext/i18n/locales/ru/pluralization.rb +0 -62
- data/lib/crystal_ext/plugin.rb +0 -23
- data/lib/crystal_ext/plugin/app.rb +0 -19
- data/lib/crystal_ext/plugin/web.rb +0 -44
- data/lib/crystal_ext/prepare_model.rb +0 -20
- data/lib/crystal_ext/profiles/web_ext_require.rb +0 -13
- data/lib/crystal_ext/protect_from_forgery.rb +0 -66
- data/lib/crystal_ext/user_error.rb +0 -14
- data/spec/controller_spec_helper.rb +0 -19
- data/spec/defer_js_spec.rb +0 -33
- data/spec/i18n_spec.rb +0 -31
- data/spec/i18n_spec/locales/en/general.yml +0 -5
- data/spec/i18n_spec/locales/ru/general.yml +0 -7
- data/spec/prepare_model_spec.rb +0 -43
- data/spec/protect_from_forgery_spec.rb +0 -169
- data/spec/spec_helper.rb +0 -4
- data/spec/user_error_spec.rb +0 -41
@@ -0,0 +1,56 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "FormHelper" do
|
4
|
+
class MockFormHelperContext < Crystal::MockTemplateContext
|
5
|
+
include Crystal::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(:action => '/'){"content"}
|
26
|
+
@t.buffer.should == %(<form action="/">content</form>)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "hidden_field_tag" do
|
30
|
+
@t.hidden_field_tag('item', 'hidden value').should == %(<input class=" hidden_input" name="item" type="hidden" value="hidden value"></input>)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "password_field_tag" do
|
34
|
+
@t.password_field_tag('item').should == %(<input class=" password_input" name="item" type="password"></input>)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "radio_button_tag" do
|
38
|
+
@t.radio_button_tag('item').should == %(<input class=" radio_input" name="item" type="radio" value="1"></input>)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "select_tag" do
|
42
|
+
@t.select_tag('item'){'content'}.should == %(<select class=" select_input" name="item">content</select>)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "submit_tag" do
|
46
|
+
@t.submit_tag('ok').should == %(<input class=" submit_input" type="submit" value="ok"></input>)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "text_field_tag" do
|
50
|
+
@t.text_field_tag('item', 'value').should == %(<input class=" text_input" name="item" type="text" value="value"></input>)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "text_area_tag" do
|
54
|
+
@t.text_area_tag('item', 'value').should == %(<textarea class=" textarea_input" name="item">value</textarea>)
|
55
|
+
end
|
56
|
+
end
|
data/spec/html/helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
dir = File.dirname __FILE__
|
2
|
+
crystal_dir = File.expand_path "#{dir}/../.."
|
3
|
+
lib_dir = "#{crystal_dir}/lib"
|
4
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include? lib_dir
|
5
|
+
|
6
|
+
require 'crystal/html'
|
7
|
+
|
8
|
+
module Crystal
|
9
|
+
class MockTemplateContext
|
10
|
+
inject :config => :config, :workspace => :workspace
|
11
|
+
|
12
|
+
attr_accessor :output, :capture, :buffer
|
13
|
+
|
14
|
+
def capture &block
|
15
|
+
block.call
|
16
|
+
end
|
17
|
+
|
18
|
+
def concat value = nil
|
19
|
+
@buffer ||= ""
|
20
|
+
@buffer << value
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
inherit Crystal::BasicHtmlHelper
|
25
|
+
# include BasicHtmlHelper, FlashHelper, FormHelper, JavascriptHelper, UrlHelper
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
require 'crystal/spec/environment'
|
31
|
+
require 'crystal/spec/xhtml'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "BasicHtmlHelper" do
|
4
|
+
class MockJavascriptHelperContext < Crystal::MockTemplateContext
|
5
|
+
inherit Crystal::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,65 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "ModelHelper" do
|
4
|
+
class MockModelHelperContext < Crystal::MockTemplateContext
|
5
|
+
inherit Crystal::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)
|
14
|
+
@t.buffer.should == "<form></form>"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "error_messages" do
|
18
|
+
@t.form_for(:aname, nil){|f| f.error_messages}
|
19
|
+
@t.buffer.should == "<form></form>"
|
20
|
+
|
21
|
+
model = {:errors => {:base => 'some error'}}
|
22
|
+
@t.buffer = ""
|
23
|
+
@t.form_for(:book, model){|f| f.error_messages}
|
24
|
+
@t.buffer.should == %{<form><div class="error_messages">some error</div></form>}
|
25
|
+
end
|
26
|
+
|
27
|
+
it "field error" do
|
28
|
+
model = {
|
29
|
+
:title => "Super Hero",
|
30
|
+
:errors => {:title => 'some error in title'}
|
31
|
+
}
|
32
|
+
@t.form_for(:book, model){|f| f.text_field(:title)}
|
33
|
+
doc = @t.buffer.to_xhtml
|
34
|
+
doc.css("form div.field_error_messages").first.content.should == "some error in title"
|
35
|
+
doc.css("form span.field_with_errors input").first.should_be_equal_to :name => "book[title]", :value => "Super Hero"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "field_helpers" do
|
39
|
+
model = {
|
40
|
+
:available => false,
|
41
|
+
:title => "Super Hero"
|
42
|
+
}
|
43
|
+
|
44
|
+
@t.form_for(:book, model){|f| %{
|
45
|
+
#{f.check_box :available}
|
46
|
+
#{f.file_field :title}
|
47
|
+
#{f.hidden_field :title}
|
48
|
+
#{f.password_field :title}
|
49
|
+
#{f.radio_button :available}
|
50
|
+
#{f.submit 'Ok'}
|
51
|
+
#{f.text_field :title}
|
52
|
+
#{f.text_area :title}
|
53
|
+
} }
|
54
|
+
doc = @t.buffer.to_xhtml
|
55
|
+
|
56
|
+
doc.css("*[type='checkbox']").first.should_be_equal_to :name => "book[available]", :value => '1'
|
57
|
+
doc.css("*[type='file']").first.should_be_equal_to :name => "book[title]"
|
58
|
+
doc.css("*[type='hidden']").first.should_be_equal_to :name => "book[title]", :value => 'Super Hero'
|
59
|
+
doc.css("*[type='password']").first.should_be_equal_to :name => "book[title]"
|
60
|
+
doc.css("*[type='radio']").first.should_be_equal_to :name => "book[available]", :value => '1'
|
61
|
+
doc.css("*[type='submit']").first.should_be_equal_to :value => 'Ok'
|
62
|
+
doc.css("*[type='text']").first.should_be_equal_to :name => "book[title]", :value => 'Super Hero'
|
63
|
+
doc.css("textarea").first.should_be_equal_to :name => "book[title]", :content => 'Super Hero'
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "ScopedParams" do
|
4
|
+
it "basic" do
|
5
|
+
workspace = {
|
6
|
+
:params => {"book[title]" => "Super Hero"}
|
7
|
+
}.to_openobject
|
8
|
+
|
9
|
+
@processor = Crystal::Processors::ScopedParams.new(lambda{})
|
10
|
+
@processor.stub(:workspace).and_return(workspace)
|
11
|
+
@processor.call
|
12
|
+
|
13
|
+
workspace.params.should == {
|
14
|
+
"book" => {"title" => "Super Hero"}
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "UrlHelper" do
|
4
|
+
class MockUrlHelperContext < Crystal::MockTemplateContext
|
5
|
+
inherit Crystal::ControllerUrlHelper, Crystal::ViewUrlHelper
|
6
|
+
|
7
|
+
def url_for *args
|
8
|
+
opt = args.extract_options!
|
9
|
+
format = opt.stringify_keys['format']
|
10
|
+
args << opt
|
11
|
+
|
12
|
+
url = args.inspect.gsub('"', "'")
|
13
|
+
url.marks.format = format
|
14
|
+
url
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
before :each do
|
19
|
+
@t = MockUrlHelperContext.new
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "link_to" do
|
23
|
+
before :all do
|
24
|
+
crystal[:config] = Crystal::Config.new
|
25
|
+
end
|
26
|
+
|
27
|
+
after :all do
|
28
|
+
crystal.clear
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should works with url_for_remote attributes" do
|
32
|
+
@t.link_to('Book', Object, :method, {:format => :json}, :class => 'highlight').to_xhtml('a').
|
33
|
+
should_be_equal_to(:class => "highlight", :href => "[Object, :method, {:format=>:json}]", :content => "Book")
|
34
|
+
|
35
|
+
@t.link_to(Object, :method, {:format => :json}, :class => 'highlight'){'Book'}.to_xhtml('a').
|
36
|
+
should_be_equal_to(:class => "highlight", :href => "[Object, :method, {:format=>:json}]", :content => "Book")
|
37
|
+
|
38
|
+
@t.link_to('Book', :method).to_xhtml('a').
|
39
|
+
should_be_equal_to(:href => "[:method, {}]", :content => "Book")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should works with url_for_path attributes" do
|
43
|
+
@t.link_to('Book', '/some_book', {}, :class => 'highlight').to_xhtml('a').
|
44
|
+
should_be_equal_to(:class => "highlight", :href => "['/some_book', {}]", :content => "Book")
|
45
|
+
|
46
|
+
@t.link_to('/some_book', {}, :class => 'highlight'){'Book'}.to_xhtml('a').
|
47
|
+
should_be_equal_to(:class => "highlight", :href => "['/some_book', {}]", :content => "Book")
|
48
|
+
|
49
|
+
@t.link_to('/some_book'){'Book'}.to_xhtml('a').
|
50
|
+
should_be_equal_to(:href => "['/some_book', {}]", :content => "Book")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "links for :js, :json formats should be automatically became remote" do
|
54
|
+
@t.link_to('Book', '/some_book', :format => :json).to_xhtml('a').should_be_equal_to(
|
55
|
+
:href => "['/some_book', {:format=>:json}]", :content => "Book",
|
56
|
+
:onclick => "$(this).link_to({method: 'get', ajax: true}); return false;"
|
57
|
+
)
|
58
|
+
|
59
|
+
@t.link_to('Book', :method, {:format => :js}, :class => 'highlight').to_xhtml('a').should_be_equal_to(
|
60
|
+
:href => "[:method, {:format=>:js}]", :content => "Book", :class => 'highlight',
|
61
|
+
:onclick => "$(this).link_to({method: 'get', ajax: true}); return false;"
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "confirm" do
|
66
|
+
@t.link_to('Book', '/some_book', {}, :confirm => 'Are you shure?').to_xhtml('a').should_be_equal_to(
|
67
|
+
:href => "['/some_book', {}]", :content => "Book",
|
68
|
+
:onclick => "return confirm(Are you shure?);"
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "POST method" do
|
73
|
+
@t.link_to('Book', '/some_book', {}, :method => :post).to_xhtml('a').should_be_equal_to(
|
74
|
+
:href => "['/some_book', {}]", :content => "Book",
|
75
|
+
:onclick => "$(this).link_to({method: 'post'}); return false;"
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "remote" do
|
80
|
+
@t.link_to('Book', '/some_book', {}, :remote => true).to_xhtml('a').should_be_equal_to(
|
81
|
+
:href => "['/some_book', {}]", :content => "Book",
|
82
|
+
:onclick => "$(this).link_to({method: 'get', ajax: true}); return false;"
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
it ":back" do
|
87
|
+
env = Object.new
|
88
|
+
env.stub(:[]).and_return('/go_back')
|
89
|
+
request = Object.new
|
90
|
+
request.stub(:env).and_return(env)
|
91
|
+
workspace = Object.new
|
92
|
+
workspace.stub(:request).and_return(request)
|
93
|
+
@t.stub(:workspace).and_return(workspace)
|
94
|
+
|
95
|
+
@t.link_to('Book', :back).to_xhtml('a').should_be_equal_to(:href => "/go_back", :content => "Book")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "#" do
|
99
|
+
@t.link_to('Book', '#').to_xhtml('a').should_be_equal_to(:href => "#", :content => "Book")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def stub_workspace
|
104
|
+
@response = Crystal::Response.new
|
105
|
+
@params = Crystal::Params.new
|
106
|
+
|
107
|
+
@workspace = Object.new
|
108
|
+
@workspace.stub(:params).and_return(@params)
|
109
|
+
@workspace.stub(:response).and_return(@response)
|
110
|
+
|
111
|
+
@t.stub(:workspace).and_return(@workspace)
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "redirect_to" do
|
115
|
+
before :each do
|
116
|
+
stub_workspace
|
117
|
+
end
|
118
|
+
|
119
|
+
it "html format" do
|
120
|
+
@workspace.stub(:params).and_return({:format => 'html'}.to_openobject)
|
121
|
+
|
122
|
+
@t.redirect_to('/some_book').should == nil
|
123
|
+
@response.status.should == 301
|
124
|
+
@response.headers['Location'].should == "['/some_book', {}]"
|
125
|
+
@response.body.should =~ /You are being/
|
126
|
+
end
|
127
|
+
|
128
|
+
it "js format" do
|
129
|
+
@workspace.stub(:params).and_return({:format => 'js'}.to_openobject)
|
130
|
+
|
131
|
+
@t.redirect_to('/some_book').should be_nil
|
132
|
+
@response.status.should == 200
|
133
|
+
@response.headers['Location'].should be_blank
|
134
|
+
@response.body.should == "window.location = '['/some_book', {}]';"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "reload_page" do
|
139
|
+
before :each do
|
140
|
+
stub_workspace
|
141
|
+
end
|
142
|
+
|
143
|
+
it "basic" do
|
144
|
+
@params.format = 'js'
|
145
|
+
|
146
|
+
@t.reload_page
|
147
|
+
@response.status.should == 200
|
148
|
+
@response.body.should =~ /reload/
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
data/spec/http/helper.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "HTTP basics" do
|
4
|
+
inject :environment => :environment,
|
5
|
+
:conveyors => :conveyors
|
6
|
+
|
7
|
+
with_environment :development
|
8
|
+
|
9
|
+
before :all do
|
10
|
+
@dir = File.expand_path(File.dirname(__FILE__))
|
11
|
+
@app_original_dir = "#{@dir}/http_spec_data"
|
12
|
+
$APP_DIR = "#{@dir}/http_spec"
|
13
|
+
|
14
|
+
FileUtils.rm_r $APP_DIR if File.exist? $APP_DIR
|
15
|
+
FileUtils.cp_r @app_original_dir, $APP_DIR
|
16
|
+
|
17
|
+
crystal.after :environment do
|
18
|
+
crystal.conveyors.web do |web|
|
19
|
+
web.use Crystal::Processors::HttpWriter
|
20
|
+
web.use Crystal::Processors::PrepareParams
|
21
|
+
web.use Crystal::Processors::EvaluateFormat
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
load "#{$APP_DIR}/config/init.rb"
|
26
|
+
end
|
27
|
+
|
28
|
+
after :all do
|
29
|
+
remove_constants %w(PrepareParamsStub)
|
30
|
+
|
31
|
+
$LOAD_PATH.delete "#{$APP_DIR}/plugin_a"
|
32
|
+
$LOAD_PATH.delete "#{$APP_DIR}/plugin_b"
|
33
|
+
|
34
|
+
FileUtils.rm_r $APP_DIR if File.exist? $APP_DIR
|
35
|
+
end
|
36
|
+
|
37
|
+
it "public symlink" do
|
38
|
+
crystal[:environment]
|
39
|
+
crystal.config.environment.should == 'development'
|
40
|
+
File.should exist("#{$APP_DIR}/public/plugin_b")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "http call" do
|
44
|
+
workspace = nil
|
45
|
+
Crystal::HTTPAdapter.mock_call do |&block|
|
46
|
+
block.call
|
47
|
+
workspace = crystal[:workspace]
|
48
|
+
end
|
49
|
+
# .should == [200, {"Content-Type" => "text/html"}, ""]
|
50
|
+
|
51
|
+
expected_result = {:path => "/", :response => [200, {"Content-Type" => "text/html"}, ""], :params => {"format" => "html"}}
|
52
|
+
workspace.to_h.symbolize_keys.subset(expected_result.keys).should == expected_result
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "Integration" do
|
4
|
+
with_environment
|
5
|
+
with_http
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
HttpController = Crystal::HttpController
|
9
|
+
|
10
|
+
@dir = "#{File.expand_path(File.dirname(__FILE__))}/basic_spec"
|
11
|
+
$LOAD_PATH << @dir
|
12
|
+
|
13
|
+
load 'crystal/profiles/web.rb'
|
14
|
+
end
|
15
|
+
|
16
|
+
after :all do
|
17
|
+
$LOAD_PATH.delete @dir
|
18
|
+
remove_constants %w(
|
19
|
+
HttpController
|
20
|
+
SmokeTestSpec
|
21
|
+
JsonFormatSpec
|
22
|
+
RequestAndSessionSpec
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "smoke test" do
|
27
|
+
class ::SmokeTestSpec
|
28
|
+
inherit HttpController
|
29
|
+
|
30
|
+
def action
|
31
|
+
respond_to do |format|
|
32
|
+
format.json{render :json => {:a => 'b'}}
|
33
|
+
format.html{render :inline => "some content"}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
wcall("/smoke_test_spec/action")
|
39
|
+
response.body.should == %(some content)
|
40
|
+
|
41
|
+
wcall("/smoke_test_spec/action", :format => 'json')
|
42
|
+
response.body.should == %({"a":"b"})
|
43
|
+
end
|
44
|
+
|
45
|
+
it "json" do
|
46
|
+
class ::JsonFormatSpec
|
47
|
+
inherit HttpController
|
48
|
+
|
49
|
+
def action
|
50
|
+
render :json => {:a => 'b'}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
wcall("/json_format_spec/action.json")
|
55
|
+
response.body.should == %({"a":"b"})
|
56
|
+
# response.rson.should == {'result' => 'value'}
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should have workspace, request and session" do
|
60
|
+
class ::RequestAndSessionSpec
|
61
|
+
inherit HttpController
|
62
|
+
|
63
|
+
inject :workspace => :workspace
|
64
|
+
def action
|
65
|
+
workspace.should_not == nil
|
66
|
+
workspace.request.should_not == nil
|
67
|
+
workspace.request.session.should_not == nil
|
68
|
+
|
69
|
+
self.class.request_and_session_passed = true
|
70
|
+
|
71
|
+
render :json => {:a => 'b'}
|
72
|
+
end
|
73
|
+
|
74
|
+
class << self
|
75
|
+
attr_accessor :request_and_session_passed
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
wcall('/request_and_session_spec/action.json')
|
80
|
+
RequestAndSessionSpec.request_and_session_passed.should be_true
|
81
|
+
end
|
82
|
+
end
|