waw 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENCE.rdoc +25 -0
- data/README.rdoc +32 -0
- data/bin/waw +32 -0
- data/bin/waw-profile +26 -0
- data/bin/waw-start +26 -0
- data/bin/wspec +33 -0
- data/layouts/empty/Rakefile +14 -0
- data/layouts/empty/config.ru +5 -0
- data/layouts/empty/config/commons.cfg +31 -0
- data/layouts/empty/config/devel.cfg +21 -0
- data/layouts/empty/ignore +7 -0
- data/layouts/empty/logs/dontforgetme +0 -0
- data/layouts/empty/resources/messages.rs +1 -0
- data/layouts/empty/test/wspec/site_respond.wspec +3 -0
- data/layouts/empty/test/wspec/test_all.rb +13 -0
- data/layouts/empty/waw.deploy +1 -0
- data/layouts/empty/waw.routing +6 -0
- data/layouts/static/dependencies +1 -0
- data/layouts/static/public/.wawaccess +18 -0
- data/layouts/static/public/css/style.css +0 -0
- data/layouts/static/public/images/dontforgetme +0 -0
- data/layouts/static/public/js/project.js +0 -0
- data/layouts/static/public/pages/.wawaccess +30 -0
- data/layouts/static/public/pages/404.wtpl +1 -0
- data/layouts/static/public/pages/index.wtpl +5 -0
- data/layouts/static/public/templates/.wawaccess +9 -0
- data/layouts/static/public/templates/layout.wtpl +17 -0
- data/layouts/static/test/wspec/static_pages_are_served.wspec +21 -0
- data/layouts/static/waw.routing +8 -0
- data/lib/waw.rb +99 -0
- data/lib/waw/commands/command.rb +115 -0
- data/lib/waw/commands/profile_command.rb +66 -0
- data/lib/waw/commands/start_command.rb +59 -0
- data/lib/waw/config.rb +110 -0
- data/lib/waw/controller.rb +25 -0
- data/lib/waw/controllers/action/action.rb +91 -0
- data/lib/waw/controllers/action/action_utils.rb +30 -0
- data/lib/waw/controllers/action/js_generation.rb +116 -0
- data/lib/waw/controllers/action_controller.rb +133 -0
- data/lib/waw/controllers/error/backtrace.rb +54 -0
- data/lib/waw/controllers/error_handler.rb +62 -0
- data/lib/waw/controllers/json_controller.rb +31 -0
- data/lib/waw/controllers/no_cache.rb +22 -0
- data/lib/waw/controllers/static/match.rb +80 -0
- data/lib/waw/controllers/static/waw_access.rb +235 -0
- data/lib/waw/controllers/static/waw_access_dsl.rb +48 -0
- data/lib/waw/controllers/static_controller.rb +37 -0
- data/lib/waw/default_config.cfg +14 -0
- data/lib/waw/environment_utils.rb +57 -0
- data/lib/waw/errors.rb +4 -0
- data/lib/waw/ext.rb +3 -0
- data/lib/waw/ext/core.rb +4 -0
- data/lib/waw/ext/core/hash.rb +47 -0
- data/lib/waw/ext/core/logger.rb +10 -0
- data/lib/waw/ext/core/module.rb +20 -0
- data/lib/waw/ext/core/object.rb +29 -0
- data/lib/waw/ext/rack.rb +19 -0
- data/lib/waw/ext/rack/builder.rb +43 -0
- data/lib/waw/ext/rack/delegator.rb +51 -0
- data/lib/waw/ext/rack/urlmap.rb +55 -0
- data/lib/waw/ext/wlang.rb +1 -0
- data/lib/waw/ext/wlang/hosted_language.rb +21 -0
- data/lib/waw/fullstate.rb +8 -0
- data/lib/waw/fullstate/on_class.rb +37 -0
- data/lib/waw/fullstate/on_instance.rb +27 -0
- data/lib/waw/fullstate/variable.rb +36 -0
- data/lib/waw/kern.rb +6 -0
- data/lib/waw/kern/app.rb +48 -0
- data/lib/waw/kern/empty/waw.deploy +0 -0
- data/lib/waw/kern/empty/waw.routing +1 -0
- data/lib/waw/kern/freezed_state.rb +32 -0
- data/lib/waw/kern/hooks.rb +53 -0
- data/lib/waw/kern/lifecycle.rb +248 -0
- data/lib/waw/kern/living_state.rb +87 -0
- data/lib/waw/kern/utils.rb +27 -0
- data/lib/waw/resource_collection.rb +100 -0
- data/lib/waw/restart.rb +32 -0
- data/lib/waw/routing.rb +43 -0
- data/lib/waw/routing/action_routing.rb +78 -0
- data/lib/waw/routing/dsl.rb +45 -0
- data/lib/waw/routing/feedback.rb +23 -0
- data/lib/waw/routing/form_validation_feedback.rb +36 -0
- data/lib/waw/routing/javascript.rb +17 -0
- data/lib/waw/routing/redirect.rb +26 -0
- data/lib/waw/routing/refresh.rb +17 -0
- data/lib/waw/routing/routing_rule.rb +16 -0
- data/lib/waw/scope_utils.rb +69 -0
- data/lib/waw/session.rb +51 -0
- data/lib/waw/testing.rb +1 -0
- data/lib/waw/tools/mail.rb +4 -0
- data/lib/waw/tools/mail/mail.rb +119 -0
- data/lib/waw/tools/mail/mail_agent.rb +123 -0
- data/lib/waw/tools/mail/mailbox.rb +62 -0
- data/lib/waw/tools/mail/template.rb +38 -0
- data/lib/waw/utils/dsl_helper.rb +116 -0
- data/lib/waw/validation.rb +175 -0
- data/lib/waw/validation/and_validator.rb +27 -0
- data/lib/waw/validation/array_validations.rb +38 -0
- data/lib/waw/validation/boolean_validator.rb +32 -0
- data/lib/waw/validation/comparison_validations.rb +45 -0
- data/lib/waw/validation/date_validator.rb +31 -0
- data/lib/waw/validation/default_validator.rb +30 -0
- data/lib/waw/validation/dsl_ruby_extensions.rb +11 -0
- data/lib/waw/validation/errors.rb +17 -0
- data/lib/waw/validation/ext.rb +3 -0
- data/lib/waw/validation/file_validator.rb +30 -0
- data/lib/waw/validation/float_validator.rb +19 -0
- data/lib/waw/validation/helpers.rb +67 -0
- data/lib/waw/validation/integer_validator.rb +16 -0
- data/lib/waw/validation/isin_validator.rb +24 -0
- data/lib/waw/validation/mandatory_validator.rb +17 -0
- data/lib/waw/validation/missing_validator.rb +17 -0
- data/lib/waw/validation/not_validator.rb +20 -0
- data/lib/waw/validation/or_validator.rb +34 -0
- data/lib/waw/validation/regexp_validator.rb +29 -0
- data/lib/waw/validation/same_validator.rb +16 -0
- data/lib/waw/validation/signature.rb +157 -0
- data/lib/waw/validation/size_validations.rb +44 -0
- data/lib/waw/validation/string_validator.rb +15 -0
- data/lib/waw/validation/validator.rb +48 -0
- data/lib/waw/wawgen.rb +2 -0
- data/lib/waw/wawgen/create.rb +166 -0
- data/lib/waw/wawgen/project.rb +25 -0
- data/lib/waw/wspec.rb +5 -0
- data/lib/waw/wspec/browser.rb +240 -0
- data/lib/waw/wspec/dsl.rb +201 -0
- data/lib/waw/wspec/html_analysis.rb +136 -0
- data/lib/waw/wspec/html_analysis/tag.rb +56 -0
- data/lib/waw/wspec/runner.rb +70 -0
- data/lib/waw/wspec/scenario.rb +35 -0
- data/lib/waw/wspec/suite.rb +54 -0
- data/test/bricks/error_handler/config/test.cfg +2 -0
- data/test/bricks/error_handler/logs/webapp.log +1411 -0
- data/test/bricks/error_handler/test/error_handler.wspec +16 -0
- data/test/bricks/error_handler/waw.deploy +1 -0
- data/test/bricks/error_handler/waw.routing +27 -0
- data/test/integration/waw_create_integration_test.rb +24 -0
- data/test/spec/assumptions_spec.rb +30 -0
- data/test/spec/controllers/action_controller_spec.rb +14 -0
- data/test/spec/controllers/static/waw_access_spec.rb +112 -0
- data/test/spec/environment_utils_spec.rb +15 -0
- data/test/spec/ext/core/hash_spec.rb +58 -0
- data/test/spec/fixtures.rb +41 -0
- data/test/spec/fixtures/action/config/default.cfg +2 -0
- data/test/spec/fixtures/action/lib/action_controller_test.rb +12 -0
- data/test/spec/fixtures/action/waw.deploy +1 -0
- data/test/spec/fixtures/action/waw.routing +6 -0
- data/test/spec/fixtures/empty/waw.deploy +0 -0
- data/test/spec/fixtures/empty/waw.routing +0 -0
- data/test/spec/fullstate/on_class_spec.rb +59 -0
- data/test/spec/fullstate/on_instance_spec.rb +59 -0
- data/test/spec/fullstate/session_spec.rb +43 -0
- data/test/spec/fullstate/variable_spec.rb +55 -0
- data/test/spec/resource_collection_spec.rb +50 -0
- data/test/spec/test_all.rb +9 -0
- data/test/spec/tools/mail/mail_agent_spec.rb +116 -0
- data/test/spec/tools/mail/mail_spec.rb +56 -0
- data/test/spec/tools/mail/mailbox_spec.rb +57 -0
- data/test/spec/tools/mail/template_spec.rb +47 -0
- data/test/spec/validation/array_validation_spec.rb +63 -0
- data/test/spec/validation/array_validator_spec.rb +17 -0
- data/test/spec/validation/date_validation_spec.rb +35 -0
- data/test/spec/validation/default_validation_spec.rb +37 -0
- data/test/spec/validation/disjuctive_validation_spec.rb +33 -0
- data/test/spec/validation/errors_spec.rb +37 -0
- data/test/spec/validation/file_validator_spec.rb +34 -0
- data/test/spec/validation/mail_validation_spec.rb +51 -0
- data/test/spec/validation/missing_validation_spec.rb +43 -0
- data/test/spec/validation/same_validation_spec.rb +24 -0
- data/test/spec/validation/signature_intuition_spec.rb +37 -0
- data/test/spec/validation/signature_spec.rb +164 -0
- data/test/spec/validation/validation_spec.rb +28 -0
- data/test/spec/wspec/html_analysis/tag_spec.rb +38 -0
- data/test/spec/wspec/html_analysis_spec.rb +170 -0
- data/test/unit/test_all.rb +8 -0
- data/test/unit/waw/app_test.rb +126 -0
- data/test/unit/waw/app_test/config/commons.cfg +2 -0
- data/test/unit/waw/app_test/config/devel.cfg +1 -0
- data/test/unit/waw/config_test.rb +54 -0
- data/test/unit/waw/controllers/action_controller_test.rb +76 -0
- data/test/unit/waw/controllers/action_test.rb +35 -0
- data/test/unit/waw/controllers/example_action_controller_test.rb +24 -0
- data/test/unit/waw/controllers/multiple_action_controller_test.rb +78 -0
- data/test/unit/waw/controllers/static/example/css/example.css +1 -0
- data/test/unit/waw/controllers/static/example/index.html +1 -0
- data/test/unit/waw/controllers/static/example/js/example.js +1 -0
- data/test/unit/waw/controllers/static/example/pages/hello.wtpl +1 -0
- data/test/unit/waw/controllers/static/waw_access_test.rb +76 -0
- data/test/unit/waw/ext/rack_test.rb +74 -0
- data/test/unit/waw/resource_collection_test.rb +49 -0
- data/test/unit/waw/resources.txt +4 -0
- data/test/unit/waw/routing/routing_test.rb +26 -0
- data/test/unit/waw/utils/dsl_helper_test.rb +79 -0
- data/test/unit/waw/utils/dsl_helper_test_extensions1.rb +4 -0
- data/test/unit/waw/validation/signature_test.rb +193 -0
- data/test/unit/waw/validation_test.rb +319 -0
- data/test/unit/waw/wspec/html_analysis_test.html +81 -0
- data/test/unit/waw/wspec/html_analysis_test.rb +26 -0
- metadata +272 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'waw'
|
|
2
|
+
|
|
3
|
+
module Waw::Validation
|
|
4
|
+
validator :my_validator, validator{|s| s=="I'm my_validator"}
|
|
5
|
+
end
|
|
6
|
+
class SomeDSL
|
|
7
|
+
include Waw::Validation
|
|
8
|
+
end
|
|
9
|
+
describe ::Waw::Validation do
|
|
10
|
+
|
|
11
|
+
it "should respond to installed validators" do
|
|
12
|
+
Waw::Validation.should respond_to(:my_validator)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should allow other classes/modules (like DSLs) to include it and to get validators for free (issue #260)" do
|
|
16
|
+
SomeDSL.new.should respond_to(:my_validator)
|
|
17
|
+
SomeDSL.new.my_validator.convert_and_validate(nil).should == [false, [nil]]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should support being reopened later" do
|
|
21
|
+
module Waw::Validation
|
|
22
|
+
validator :second_validator_test, validator{|arg| Integer===arg}
|
|
23
|
+
end
|
|
24
|
+
SomeDSL.new.should respond_to(:second_validator_test)
|
|
25
|
+
SomeDSL.new.second_validator_test.convert_and_validate(12).should == [true, [12]]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'waw'
|
|
2
|
+
require 'waw/wspec'
|
|
3
|
+
|
|
4
|
+
describe Waw::WSpec::HTMLAnalysis::Tag do
|
|
5
|
+
|
|
6
|
+
def tag(name, attributes = {})
|
|
7
|
+
Waw::WSpec::HTMLAnalysis::Tag.new(nil, name, attributes)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should give access to its name" do
|
|
11
|
+
tag('a').name.should == 'a'
|
|
12
|
+
tag('div').name.should == 'div'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should give access to its attributes" do
|
|
16
|
+
tag = tag('a', :id => "link", :class => "current")
|
|
17
|
+
tag.attributes.should == {:id => "link", :class => "current"}
|
|
18
|
+
tag[:id].should == "link"
|
|
19
|
+
tag[:class].should == "current"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should provide a helper for matching an attribute specification" do
|
|
23
|
+
tag = tag('a', :id => "link", :class => "current")
|
|
24
|
+
tag.matches?(:id => 'link').should be_true
|
|
25
|
+
tag.matches?(:id => 'link', :class => "current").should be_true
|
|
26
|
+
tag.matches?(:id => 'link', :class => "current", :noone => "something").should be_false
|
|
27
|
+
tag.matches?(:id => 'nolink').should be_false
|
|
28
|
+
tag.matches?(:id => 'link', :class => "notthegoodone").should be_false
|
|
29
|
+
tag.matches?(:noone => 'something').should be_false
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should allow expression regular expressions in the matching helper' do
|
|
33
|
+
tag = tag('a', :id => "link", :class => "current")
|
|
34
|
+
tag.matches?(:id => /^([a-z]+)$/).should be_true
|
|
35
|
+
tag.matches?(:id => /^([0-9]+)$/).should be_false
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
require 'waw'
|
|
2
|
+
require 'waw/wspec'
|
|
3
|
+
|
|
4
|
+
class ServicesController < ::Waw::ActionController
|
|
5
|
+
|
|
6
|
+
def self.url
|
|
7
|
+
'/services'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
signature {}
|
|
11
|
+
def say_hello(params)
|
|
12
|
+
:ok
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe Waw::WSpec::HTMLAnalysis do
|
|
18
|
+
include Waw::WSpec::HTMLAnalysis
|
|
19
|
+
|
|
20
|
+
def browser_contents
|
|
21
|
+
<<-HTML
|
|
22
|
+
<html>
|
|
23
|
+
<head>
|
|
24
|
+
<title>This is a WSpec rspec test</title>
|
|
25
|
+
<link rel="stylesheet" type="text/css" href="/css/style.css" />
|
|
26
|
+
<link rel="stylesheet" type="text/css" href="/css/olympiades.css" />
|
|
27
|
+
<link rel="stylesheet" type="text/css" href="/css/scienceinfuse" />
|
|
28
|
+
<script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script>
|
|
29
|
+
<script type="text/javascript" src="/js/waw.js"></script>
|
|
30
|
+
<script type="text/javascript" src="/js/acmscw.js"></script>
|
|
31
|
+
<script type="text/javascript" src="/js/acmscw_generated.js"></script>
|
|
32
|
+
</head>
|
|
33
|
+
<body>
|
|
34
|
+
<div id="menu">
|
|
35
|
+
<a href="/hello" class="current">Hello</a>
|
|
36
|
+
<a href="/world">World</a>
|
|
37
|
+
</div>
|
|
38
|
+
<div id="main">
|
|
39
|
+
<link href="service?key=value"/>
|
|
40
|
+
<form id="services_say_hello" class="say-hello">
|
|
41
|
+
</form>
|
|
42
|
+
<form action="/say/hello" id="say_hello2">
|
|
43
|
+
</form>
|
|
44
|
+
</div>
|
|
45
|
+
<div id="footer">
|
|
46
|
+
<a href="http://github.com/blambeau/waw">waw</a>
|
|
47
|
+
</div>
|
|
48
|
+
</body>
|
|
49
|
+
</html>
|
|
50
|
+
HTML
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "should correctly decode attributes" do
|
|
54
|
+
decode_attributes_string("").should == {}
|
|
55
|
+
decode_attributes_string('href="http://www.google.com"').should == {:href => 'http://www.google.com'}
|
|
56
|
+
decode_attributes_string("href='http://www.google.com'").should == {:href => 'http://www.google.com'}
|
|
57
|
+
decode_attributes_string('href="http://www.google.com" src="/images/test.jpg"').should == {
|
|
58
|
+
:href => 'http://www.google.com',
|
|
59
|
+
:src => "/images/test.jpg"
|
|
60
|
+
}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should provide a useful tags helper, returning an array of tags" do
|
|
64
|
+
links = tags('a')
|
|
65
|
+
links.size.should == 3
|
|
66
|
+
links[0].name.should == 'a'
|
|
67
|
+
links[0][:href].should == '/hello'
|
|
68
|
+
links[0][:class].should == 'current'
|
|
69
|
+
links[1].name.should == 'a'
|
|
70
|
+
links[1][:href].should == '/world'
|
|
71
|
+
links[1][:class].should be_nil
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "should allow passing a block to the tags helper method" do
|
|
75
|
+
links = []
|
|
76
|
+
tags('a') {|tag| links << tag}
|
|
77
|
+
links.size.should == 3
|
|
78
|
+
links[0].name.should == 'a'
|
|
79
|
+
links[0][:href].should == '/hello'
|
|
80
|
+
links[0][:class].should == 'current'
|
|
81
|
+
links[1].name.should == 'a'
|
|
82
|
+
links[1][:href].should == '/world'
|
|
83
|
+
links[1][:class].should be_nil
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "should provide a each_tag friendly method" do
|
|
87
|
+
links = []
|
|
88
|
+
each_tag('a') {|tag| links << tag}
|
|
89
|
+
links.size.should == 3
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should support a tags helper method allowing to express constraints" do
|
|
93
|
+
tags('div').size.should == 3
|
|
94
|
+
tags('div', :id => 'menu').size.should == 1
|
|
95
|
+
tags('div', :id => 'main').size.should == 1
|
|
96
|
+
tags('div', :id => 'none').size.should == 0
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "should support a tags helper method supporting regexp constraints" do
|
|
100
|
+
tags('link', :rel => "stylesheet", :href => /\.css$/).size.should == 2
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should support a tags helper method allowing complex uris, as href attributes for example" do
|
|
104
|
+
tags = tags('link', :href => "service?key=value")
|
|
105
|
+
tags.size.should == 1
|
|
106
|
+
tags[0][:href].should == 'service?key=value'
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "should support a non plural form for the tags helper method" do
|
|
110
|
+
tag = tag('a')
|
|
111
|
+
(Waw::WSpec::HTMLAnalysis::Tag===tag).should be_true
|
|
112
|
+
tag[:href].should == '/hello'
|
|
113
|
+
tag('nothing').should be_nil
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "should correctly implement has_tag?" do
|
|
117
|
+
has_tag?("title").should be_true
|
|
118
|
+
has_tag?("a").should be_true
|
|
119
|
+
has_tag?("div").should be_true
|
|
120
|
+
has_tag?("div", :id => 'menu').should be_true
|
|
121
|
+
has_tag?("div", :id => 'notmenu').should be_false
|
|
122
|
+
has_tag?("p").should be_false
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "should provide shortcuts for links" do
|
|
126
|
+
all_links.size.should == 3
|
|
127
|
+
links.size.should == 3
|
|
128
|
+
links(:href => '/hello').size.should == 1
|
|
129
|
+
links(:href => '/none').size.should == 0
|
|
130
|
+
links(:class => 'current').size.should == 1
|
|
131
|
+
links(:class => /.*/).size.should == 1
|
|
132
|
+
links(:class => 'nothing').size.should == 0
|
|
133
|
+
|
|
134
|
+
link(:href => '/hello').should_not be_nil
|
|
135
|
+
first_link(:href => '/hello').should_not be_nil
|
|
136
|
+
|
|
137
|
+
link(:nohing => true).should be_nil
|
|
138
|
+
|
|
139
|
+
has_link?(:href => '/hello').should be_true
|
|
140
|
+
has_link?(:nohing => true).should be_false
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "should provide shortcuts for internal links" do
|
|
144
|
+
all_internal_links.size.should == 2
|
|
145
|
+
internal_links.size.should == 2
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it "should provide shortcuts for external links" do
|
|
149
|
+
all_external_links.size.should == 1
|
|
150
|
+
external_links.size.should == 1
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it "should provide shortcuts for forms" do
|
|
154
|
+
form(:id => 'services_say_hello').should_not be_nil
|
|
155
|
+
form(:id => 'say_hello2').should_not be_nil
|
|
156
|
+
form(:action => '/say/hello').should_not be_nil
|
|
157
|
+
form(:id => 'say_hello2', :action => '/say/hello').should_not be_nil
|
|
158
|
+
form(:id => 'nothing').should be_nil
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it "should support looking forms through Action instances" do
|
|
162
|
+
ServicesController.say_hello.id.should == "services_say_hello"
|
|
163
|
+
form = form(:action => ServicesController.say_hello)
|
|
164
|
+
form.should_not be_nil
|
|
165
|
+
form[:action].should == ServicesController.say_hello
|
|
166
|
+
form[:class].should == 'say-hello'
|
|
167
|
+
form[:id].should == ServicesController.say_hello.id
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'waw'
|
|
4
|
+
module Waw
|
|
5
|
+
class AppTest < Test::Unit::TestCase
|
|
6
|
+
include ::Waw::Kern::FreezedState
|
|
7
|
+
include ::Waw::Kern::Hooks
|
|
8
|
+
include ::Waw::Kern::Utils
|
|
9
|
+
include ::Waw::Kern::Lifecycle
|
|
10
|
+
attr_reader :folder
|
|
11
|
+
|
|
12
|
+
# Thrash class for the logger
|
|
13
|
+
class Trash
|
|
14
|
+
def self.write(*args) end
|
|
15
|
+
def self.close(*args) end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def setup
|
|
19
|
+
@folder = File.join(File.dirname(__FILE__), 'app_test')
|
|
20
|
+
wawrouting(nil, "nil")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def teardown
|
|
24
|
+
FileUtils.rm_rf File.join('logs')
|
|
25
|
+
FileUtils.rm_rf File.join(@folder, 'wawdeploy')
|
|
26
|
+
FileUtils.rm_rf File.join(@folder, 'waw.deploy')
|
|
27
|
+
FileUtils.rm_rf File.join(@folder, 'waw.routing')
|
|
28
|
+
FileUtils.rm_rf File.join(@folder, 'waw.commons.routing')
|
|
29
|
+
FileUtils.rm_rf File.join(@folder, 'waw.devel.routing')
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def wawdeploy(words, old=false)
|
|
33
|
+
File.open(File.join(@folder, old ? "wawdeploy" : "waw.deploy"), 'w') do |io|
|
|
34
|
+
io << "# It supports comments\n"
|
|
35
|
+
io << words.join(' ') << "\n"
|
|
36
|
+
io << "# And here too\n"
|
|
37
|
+
end
|
|
38
|
+
yield
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def wawrouting(name, value)
|
|
42
|
+
file = name ? "waw.#{name}.routing" : "waw.routing"
|
|
43
|
+
File.open(File.join(@folder, file), 'w') do |io|
|
|
44
|
+
io << "'#{value}'"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_it_supports_empty_config
|
|
49
|
+
assert_nothing_raised do
|
|
50
|
+
wawdeploy %w{} do
|
|
51
|
+
load_application(folder)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_it_load_config_in_good_order
|
|
57
|
+
wawdeploy %w{commons devel} do
|
|
58
|
+
load_application(folder)
|
|
59
|
+
assert_equal 2, config.test_value
|
|
60
|
+
assert_equal %w{commons devel}, deploy_words
|
|
61
|
+
end
|
|
62
|
+
wawdeploy %w{devel commons} do
|
|
63
|
+
load_application(folder)
|
|
64
|
+
assert_equal 1, config.test_value
|
|
65
|
+
assert_equal %w{devel commons}, deploy_words
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_it_supports_old_wawdeploy
|
|
70
|
+
wawdeploy %w{commons devel}, true do
|
|
71
|
+
load_application(folder)
|
|
72
|
+
assert_equal 2, config.test_value
|
|
73
|
+
assert_equal %w{commons devel}, deploy_words
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_it_loads_correct_routing
|
|
78
|
+
wawdeploy %w{commons devel} do
|
|
79
|
+
wawrouting nil, "This is the standard routing"
|
|
80
|
+
wawrouting "commons", "This is the commons routing"
|
|
81
|
+
wawrouting "devel", "This is the devel routing"
|
|
82
|
+
load_application(folder)
|
|
83
|
+
assert_equal "This is the devel routing", app
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_it_loads_correct_routing_2
|
|
88
|
+
wawdeploy %w{commons devel} do
|
|
89
|
+
wawrouting nil, "This is the standard routing"
|
|
90
|
+
wawrouting "commons", "This is the commons routing"
|
|
91
|
+
load_application(folder)
|
|
92
|
+
assert_equal "This is the commons routing", app
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_it_loads_correct_routing_3
|
|
97
|
+
wawdeploy %w{devel} do
|
|
98
|
+
wawrouting nil, "This is the standard routing"
|
|
99
|
+
wawrouting "commons", "This is the commons routing"
|
|
100
|
+
load_application(folder)
|
|
101
|
+
assert_equal "This is the standard routing", app
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_it_loads_correct_routing_4
|
|
106
|
+
wawdeploy %w{} do
|
|
107
|
+
wawrouting nil, "This is the standard routing"
|
|
108
|
+
wawrouting "commons", "This is the commons routing"
|
|
109
|
+
wawrouting "devel", "This is the commons routing"
|
|
110
|
+
load_application(folder)
|
|
111
|
+
assert_equal "This is the standard routing", app
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_it_loads_correct_routing_4
|
|
116
|
+
wawdeploy %w{devel commons} do
|
|
117
|
+
wawrouting nil, "This is the standard routing"
|
|
118
|
+
wawrouting "commons", "This is the commons routing"
|
|
119
|
+
wawrouting "devel", "This is the commons routing"
|
|
120
|
+
load_application(folder)
|
|
121
|
+
assert_equal "This is the commons routing", app
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
test_value 2
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'waw'
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
module Waw
|
|
4
|
+
class ConfigTest < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
def root_folder
|
|
7
|
+
File.dirname(__FILE__)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_default_config
|
|
11
|
+
c = Config.new(self, false).merge <<-EOF
|
|
12
|
+
log_dir 'logs'
|
|
13
|
+
log_frequency 'weekly'
|
|
14
|
+
log_level Logger::DEBUG
|
|
15
|
+
EOF
|
|
16
|
+
assert_equal 'logs', c.log_dir
|
|
17
|
+
assert_equal 'weekly', c.log_frequency
|
|
18
|
+
assert_equal Logger::DEBUG, c.log_level
|
|
19
|
+
assert_equal ['logs'], c.log_dir(true)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_config_allows_future_references
|
|
23
|
+
c = Config.new(self, false)
|
|
24
|
+
c.merge <<-EOF
|
|
25
|
+
first 12
|
|
26
|
+
second first
|
|
27
|
+
EOF
|
|
28
|
+
assert_equal 12, c.second
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_config_allows_block
|
|
32
|
+
c = Config.new(self, false)
|
|
33
|
+
c.merge <<-EOF
|
|
34
|
+
help 12
|
|
35
|
+
jsgeneration { true }
|
|
36
|
+
EOF
|
|
37
|
+
assert_equal 12, c.help
|
|
38
|
+
assert_equal true, c.jsgeneration
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_config_allows_block_referencing_others
|
|
42
|
+
c = Config.new(self, false)
|
|
43
|
+
c.merge <<-EOF
|
|
44
|
+
mode 'devel'
|
|
45
|
+
jsgeneration { mode=='devel' }
|
|
46
|
+
sendmails { mode=='production' }
|
|
47
|
+
EOF
|
|
48
|
+
assert_equal 'devel', c.mode
|
|
49
|
+
assert_equal true, c.jsgeneration
|
|
50
|
+
assert_equal false, c.sendmails
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'waw'
|
|
3
|
+
module Waw
|
|
4
|
+
class ActionControllerTest < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
class MyMailController < Waw::ActionController
|
|
7
|
+
|
|
8
|
+
def this_is_possible
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
signature {
|
|
12
|
+
validation :mail, mandatory, :missing_email
|
|
13
|
+
validation :mail, mail, :invalid_email
|
|
14
|
+
}
|
|
15
|
+
def subscribe(params)
|
|
16
|
+
this_is_possible
|
|
17
|
+
:ok
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
signature {
|
|
21
|
+
validation :age, integer & (is>18), :bad_age
|
|
22
|
+
}
|
|
23
|
+
def say_hello_to_adult(params)
|
|
24
|
+
params[:age]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def not_an_action
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def controller
|
|
33
|
+
MyMailController.instance
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_singleton_pattern
|
|
37
|
+
assert_equal false, MyMailController.respond_to?(:new)
|
|
38
|
+
assert_equal true, MyMailController.respond_to?(:instance)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_installed_method_on_instance
|
|
42
|
+
assert MyMailController.instance.respond_to?(:subscribe)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_installed_method_on_class
|
|
46
|
+
assert MyMailController.respond_to?(:subscribe)
|
|
47
|
+
assert ::Waw::ActionController::Action===MyMailController.subscribe
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_js_generation_has_seen_new_controller
|
|
51
|
+
assert ::Waw::ActionController.controllers.include?(MyMailController)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_controller_installation
|
|
55
|
+
assert controller.respond_to?(:subscribe)
|
|
56
|
+
assert controller.respond_to?(:not_an_action)
|
|
57
|
+
assert_equal false, controller.respond_to?(:action_not_an_action)
|
|
58
|
+
assert controller.has_action?(:subscribe)
|
|
59
|
+
assert controller.has_action?("/services/subscribe")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_controller_subscribe
|
|
63
|
+
assert_equal [:success, :ok], controller.subscribe(:mail => "blambeau@gmail.com")
|
|
64
|
+
assert_equal [:"validation-ko", [:invalid_email]], controller.subscribe(:mail => "blambeau_gmail.com")
|
|
65
|
+
assert_equal [:"validation-ko", [:missing_email, :invalid_email]], controller.subscribe(:mail => nil)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_controller_say_hello_to_adult
|
|
69
|
+
assert_equal [:success, 20], controller.say_hello_to_adult(:age => 20)
|
|
70
|
+
assert_equal [:success, 20], controller.say_hello_to_adult(:age => "20")
|
|
71
|
+
assert_equal [:success, 20], controller.say_hello_to_adult(:age => " 20 ")
|
|
72
|
+
assert_equal [:"validation-ko", [:bad_age]], controller.say_hello_to_adult(:age => "18")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
end
|