waw 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. data/LICENCE.rdoc +25 -0
  2. data/README.rdoc +32 -0
  3. data/bin/waw +32 -0
  4. data/bin/waw-profile +26 -0
  5. data/bin/waw-start +26 -0
  6. data/bin/wspec +33 -0
  7. data/layouts/empty/Rakefile +14 -0
  8. data/layouts/empty/config.ru +5 -0
  9. data/layouts/empty/config/commons.cfg +31 -0
  10. data/layouts/empty/config/devel.cfg +21 -0
  11. data/layouts/empty/ignore +7 -0
  12. data/layouts/empty/logs/dontforgetme +0 -0
  13. data/layouts/empty/resources/messages.rs +1 -0
  14. data/layouts/empty/test/wspec/site_respond.wspec +3 -0
  15. data/layouts/empty/test/wspec/test_all.rb +13 -0
  16. data/layouts/empty/waw.deploy +1 -0
  17. data/layouts/empty/waw.routing +6 -0
  18. data/layouts/static/dependencies +1 -0
  19. data/layouts/static/public/.wawaccess +18 -0
  20. data/layouts/static/public/css/style.css +0 -0
  21. data/layouts/static/public/images/dontforgetme +0 -0
  22. data/layouts/static/public/js/project.js +0 -0
  23. data/layouts/static/public/pages/.wawaccess +30 -0
  24. data/layouts/static/public/pages/404.wtpl +1 -0
  25. data/layouts/static/public/pages/index.wtpl +5 -0
  26. data/layouts/static/public/templates/.wawaccess +9 -0
  27. data/layouts/static/public/templates/layout.wtpl +17 -0
  28. data/layouts/static/test/wspec/static_pages_are_served.wspec +21 -0
  29. data/layouts/static/waw.routing +8 -0
  30. data/lib/waw.rb +99 -0
  31. data/lib/waw/commands/command.rb +115 -0
  32. data/lib/waw/commands/profile_command.rb +66 -0
  33. data/lib/waw/commands/start_command.rb +59 -0
  34. data/lib/waw/config.rb +110 -0
  35. data/lib/waw/controller.rb +25 -0
  36. data/lib/waw/controllers/action/action.rb +91 -0
  37. data/lib/waw/controllers/action/action_utils.rb +30 -0
  38. data/lib/waw/controllers/action/js_generation.rb +116 -0
  39. data/lib/waw/controllers/action_controller.rb +133 -0
  40. data/lib/waw/controllers/error/backtrace.rb +54 -0
  41. data/lib/waw/controllers/error_handler.rb +62 -0
  42. data/lib/waw/controllers/json_controller.rb +31 -0
  43. data/lib/waw/controllers/no_cache.rb +22 -0
  44. data/lib/waw/controllers/static/match.rb +80 -0
  45. data/lib/waw/controllers/static/waw_access.rb +235 -0
  46. data/lib/waw/controllers/static/waw_access_dsl.rb +48 -0
  47. data/lib/waw/controllers/static_controller.rb +37 -0
  48. data/lib/waw/default_config.cfg +14 -0
  49. data/lib/waw/environment_utils.rb +57 -0
  50. data/lib/waw/errors.rb +4 -0
  51. data/lib/waw/ext.rb +3 -0
  52. data/lib/waw/ext/core.rb +4 -0
  53. data/lib/waw/ext/core/hash.rb +47 -0
  54. data/lib/waw/ext/core/logger.rb +10 -0
  55. data/lib/waw/ext/core/module.rb +20 -0
  56. data/lib/waw/ext/core/object.rb +29 -0
  57. data/lib/waw/ext/rack.rb +19 -0
  58. data/lib/waw/ext/rack/builder.rb +43 -0
  59. data/lib/waw/ext/rack/delegator.rb +51 -0
  60. data/lib/waw/ext/rack/urlmap.rb +55 -0
  61. data/lib/waw/ext/wlang.rb +1 -0
  62. data/lib/waw/ext/wlang/hosted_language.rb +21 -0
  63. data/lib/waw/fullstate.rb +8 -0
  64. data/lib/waw/fullstate/on_class.rb +37 -0
  65. data/lib/waw/fullstate/on_instance.rb +27 -0
  66. data/lib/waw/fullstate/variable.rb +36 -0
  67. data/lib/waw/kern.rb +6 -0
  68. data/lib/waw/kern/app.rb +48 -0
  69. data/lib/waw/kern/empty/waw.deploy +0 -0
  70. data/lib/waw/kern/empty/waw.routing +1 -0
  71. data/lib/waw/kern/freezed_state.rb +32 -0
  72. data/lib/waw/kern/hooks.rb +53 -0
  73. data/lib/waw/kern/lifecycle.rb +248 -0
  74. data/lib/waw/kern/living_state.rb +87 -0
  75. data/lib/waw/kern/utils.rb +27 -0
  76. data/lib/waw/resource_collection.rb +100 -0
  77. data/lib/waw/restart.rb +32 -0
  78. data/lib/waw/routing.rb +43 -0
  79. data/lib/waw/routing/action_routing.rb +78 -0
  80. data/lib/waw/routing/dsl.rb +45 -0
  81. data/lib/waw/routing/feedback.rb +23 -0
  82. data/lib/waw/routing/form_validation_feedback.rb +36 -0
  83. data/lib/waw/routing/javascript.rb +17 -0
  84. data/lib/waw/routing/redirect.rb +26 -0
  85. data/lib/waw/routing/refresh.rb +17 -0
  86. data/lib/waw/routing/routing_rule.rb +16 -0
  87. data/lib/waw/scope_utils.rb +69 -0
  88. data/lib/waw/session.rb +51 -0
  89. data/lib/waw/testing.rb +1 -0
  90. data/lib/waw/tools/mail.rb +4 -0
  91. data/lib/waw/tools/mail/mail.rb +119 -0
  92. data/lib/waw/tools/mail/mail_agent.rb +123 -0
  93. data/lib/waw/tools/mail/mailbox.rb +62 -0
  94. data/lib/waw/tools/mail/template.rb +38 -0
  95. data/lib/waw/utils/dsl_helper.rb +116 -0
  96. data/lib/waw/validation.rb +175 -0
  97. data/lib/waw/validation/and_validator.rb +27 -0
  98. data/lib/waw/validation/array_validations.rb +38 -0
  99. data/lib/waw/validation/boolean_validator.rb +32 -0
  100. data/lib/waw/validation/comparison_validations.rb +45 -0
  101. data/lib/waw/validation/date_validator.rb +31 -0
  102. data/lib/waw/validation/default_validator.rb +30 -0
  103. data/lib/waw/validation/dsl_ruby_extensions.rb +11 -0
  104. data/lib/waw/validation/errors.rb +17 -0
  105. data/lib/waw/validation/ext.rb +3 -0
  106. data/lib/waw/validation/file_validator.rb +30 -0
  107. data/lib/waw/validation/float_validator.rb +19 -0
  108. data/lib/waw/validation/helpers.rb +67 -0
  109. data/lib/waw/validation/integer_validator.rb +16 -0
  110. data/lib/waw/validation/isin_validator.rb +24 -0
  111. data/lib/waw/validation/mandatory_validator.rb +17 -0
  112. data/lib/waw/validation/missing_validator.rb +17 -0
  113. data/lib/waw/validation/not_validator.rb +20 -0
  114. data/lib/waw/validation/or_validator.rb +34 -0
  115. data/lib/waw/validation/regexp_validator.rb +29 -0
  116. data/lib/waw/validation/same_validator.rb +16 -0
  117. data/lib/waw/validation/signature.rb +157 -0
  118. data/lib/waw/validation/size_validations.rb +44 -0
  119. data/lib/waw/validation/string_validator.rb +15 -0
  120. data/lib/waw/validation/validator.rb +48 -0
  121. data/lib/waw/wawgen.rb +2 -0
  122. data/lib/waw/wawgen/create.rb +166 -0
  123. data/lib/waw/wawgen/project.rb +25 -0
  124. data/lib/waw/wspec.rb +5 -0
  125. data/lib/waw/wspec/browser.rb +240 -0
  126. data/lib/waw/wspec/dsl.rb +201 -0
  127. data/lib/waw/wspec/html_analysis.rb +136 -0
  128. data/lib/waw/wspec/html_analysis/tag.rb +56 -0
  129. data/lib/waw/wspec/runner.rb +70 -0
  130. data/lib/waw/wspec/scenario.rb +35 -0
  131. data/lib/waw/wspec/suite.rb +54 -0
  132. data/test/bricks/error_handler/config/test.cfg +2 -0
  133. data/test/bricks/error_handler/logs/webapp.log +1411 -0
  134. data/test/bricks/error_handler/test/error_handler.wspec +16 -0
  135. data/test/bricks/error_handler/waw.deploy +1 -0
  136. data/test/bricks/error_handler/waw.routing +27 -0
  137. data/test/integration/waw_create_integration_test.rb +24 -0
  138. data/test/spec/assumptions_spec.rb +30 -0
  139. data/test/spec/controllers/action_controller_spec.rb +14 -0
  140. data/test/spec/controllers/static/waw_access_spec.rb +112 -0
  141. data/test/spec/environment_utils_spec.rb +15 -0
  142. data/test/spec/ext/core/hash_spec.rb +58 -0
  143. data/test/spec/fixtures.rb +41 -0
  144. data/test/spec/fixtures/action/config/default.cfg +2 -0
  145. data/test/spec/fixtures/action/lib/action_controller_test.rb +12 -0
  146. data/test/spec/fixtures/action/waw.deploy +1 -0
  147. data/test/spec/fixtures/action/waw.routing +6 -0
  148. data/test/spec/fixtures/empty/waw.deploy +0 -0
  149. data/test/spec/fixtures/empty/waw.routing +0 -0
  150. data/test/spec/fullstate/on_class_spec.rb +59 -0
  151. data/test/spec/fullstate/on_instance_spec.rb +59 -0
  152. data/test/spec/fullstate/session_spec.rb +43 -0
  153. data/test/spec/fullstate/variable_spec.rb +55 -0
  154. data/test/spec/resource_collection_spec.rb +50 -0
  155. data/test/spec/test_all.rb +9 -0
  156. data/test/spec/tools/mail/mail_agent_spec.rb +116 -0
  157. data/test/spec/tools/mail/mail_spec.rb +56 -0
  158. data/test/spec/tools/mail/mailbox_spec.rb +57 -0
  159. data/test/spec/tools/mail/template_spec.rb +47 -0
  160. data/test/spec/validation/array_validation_spec.rb +63 -0
  161. data/test/spec/validation/array_validator_spec.rb +17 -0
  162. data/test/spec/validation/date_validation_spec.rb +35 -0
  163. data/test/spec/validation/default_validation_spec.rb +37 -0
  164. data/test/spec/validation/disjuctive_validation_spec.rb +33 -0
  165. data/test/spec/validation/errors_spec.rb +37 -0
  166. data/test/spec/validation/file_validator_spec.rb +34 -0
  167. data/test/spec/validation/mail_validation_spec.rb +51 -0
  168. data/test/spec/validation/missing_validation_spec.rb +43 -0
  169. data/test/spec/validation/same_validation_spec.rb +24 -0
  170. data/test/spec/validation/signature_intuition_spec.rb +37 -0
  171. data/test/spec/validation/signature_spec.rb +164 -0
  172. data/test/spec/validation/validation_spec.rb +28 -0
  173. data/test/spec/wspec/html_analysis/tag_spec.rb +38 -0
  174. data/test/spec/wspec/html_analysis_spec.rb +170 -0
  175. data/test/unit/test_all.rb +8 -0
  176. data/test/unit/waw/app_test.rb +126 -0
  177. data/test/unit/waw/app_test/config/commons.cfg +2 -0
  178. data/test/unit/waw/app_test/config/devel.cfg +1 -0
  179. data/test/unit/waw/config_test.rb +54 -0
  180. data/test/unit/waw/controllers/action_controller_test.rb +76 -0
  181. data/test/unit/waw/controllers/action_test.rb +35 -0
  182. data/test/unit/waw/controllers/example_action_controller_test.rb +24 -0
  183. data/test/unit/waw/controllers/multiple_action_controller_test.rb +78 -0
  184. data/test/unit/waw/controllers/static/example/css/example.css +1 -0
  185. data/test/unit/waw/controllers/static/example/index.html +1 -0
  186. data/test/unit/waw/controllers/static/example/js/example.js +1 -0
  187. data/test/unit/waw/controllers/static/example/pages/hello.wtpl +1 -0
  188. data/test/unit/waw/controllers/static/waw_access_test.rb +76 -0
  189. data/test/unit/waw/ext/rack_test.rb +74 -0
  190. data/test/unit/waw/resource_collection_test.rb +49 -0
  191. data/test/unit/waw/resources.txt +4 -0
  192. data/test/unit/waw/routing/routing_test.rb +26 -0
  193. data/test/unit/waw/utils/dsl_helper_test.rb +79 -0
  194. data/test/unit/waw/utils/dsl_helper_test_extensions1.rb +4 -0
  195. data/test/unit/waw/validation/signature_test.rb +193 -0
  196. data/test/unit/waw/validation_test.rb +319 -0
  197. data/test/unit/waw/wspec/html_analysis_test.html +81 -0
  198. data/test/unit/waw/wspec/html_analysis_test.rb +26 -0
  199. metadata +272 -0
@@ -0,0 +1,17 @@
1
+ require "waw"
2
+ describe ::Waw::Validation::ArrayValidations::ArrayValidator do
3
+
4
+ def arrayval(subvalidator)
5
+ ::Waw::Validation::ArrayValidations::ArrayValidator.new(subvalidator)
6
+ end
7
+
8
+ it "should correctly validate non empty arrays" do
9
+ arrayval(String).validate(["hop", "hello"]).should be_true
10
+ arrayval(String).validate(["world"]).should be_true
11
+ end
12
+
13
+ it "should correctly validate empty arrays" do
14
+ arrayval(String).validate([]).should be_true
15
+ end
16
+
17
+ end
@@ -0,0 +1,35 @@
1
+ require 'waw'
2
+ describe "date proposed validation" do
3
+
4
+ # Creates a signature
5
+ def date
6
+ @date_validator ||= ::Waw::Validation.signature {
7
+ validation :date, date, :bad_date
8
+ }
9
+ end
10
+
11
+ it "should block missing values" do
12
+ date.blocks?(:date => nil).should be_true
13
+ date.blocks?(:date => "").should be_true
14
+ date.blocks?(:date => " ").should be_true
15
+ end
16
+
17
+ it "should be robust to strange values" do
18
+ date.blocks?(:date => nil).should be_true
19
+ date.blocks?(:date => 12).should be_true
20
+ date.blocks?(:date => self).should be_true
21
+ date.blocks?(:date => Class).should be_true
22
+ date.blocks?(:date => self).should be_true
23
+ end
24
+
25
+ it "should allow valid dates" do
26
+ date.allows?(:date => "2010/04/25").should be_true
27
+ date.allows?(:date => "25/04/2010").should be_true
28
+ end
29
+
30
+ it "should block invalid dates" do
31
+ date.allows?(:date => "2010/33/75").should be_false
32
+ date.allows?(:date => "2010/02/31").should be_false
33
+ end
34
+
35
+ end
@@ -0,0 +1,37 @@
1
+ require 'waw'
2
+ describe ::Waw::Validation::DefaultValidator do
3
+
4
+ def default(*args, &block)
5
+ ::Waw::Validation::DefaultValidator.new(*args, &block)
6
+ end
7
+
8
+ it "should be correct about missing values when calling validate" do
9
+ default(8).validate(1).should == false
10
+ default(8).validate(1, nil).should == false
11
+ default(8).validate(nil).should == true
12
+ default(8).validate("").should == true
13
+ default(8).validate(" ").should == true
14
+ default(8).validate("", nil).should == true
15
+ end
16
+
17
+ it "should be correct about missing values when calling convert_and_validate" do
18
+ default(8).convert_and_validate(1).should == [false, [1]]
19
+ default(8).convert_and_validate(nil).should == [true, [8]]
20
+ default(8).convert_and_validate(nil, nil).should == [true, [8, 8]]
21
+ end
22
+
23
+ it "should support passing a block (feature #305)" do
24
+ default{8}.convert_and_validate(1).should == [false, [1]]
25
+ default{8}.convert_and_validate(nil).should == [true, [8]]
26
+ default{8}.convert_and_validate(nil, nil).should == [true, [8, 8]]
27
+ end
28
+
29
+ it "should also work when used in signature (feature #{306})" do
30
+ signature = ::Waw::Validation.signature {
31
+ validation :time, String | default{Time.now}, :time
32
+ }
33
+ signature.allows?(:time => nil).should == true
34
+ Time.should === signature.first_converted(:time => nil)
35
+ end
36
+
37
+ end
@@ -0,0 +1,33 @@
1
+ require 'waw'
2
+ describe 'Disjunctive validators' do
3
+
4
+ it "should be ok to put Integer|missing" do
5
+ signature = Waw::Validation.signature {
6
+ validation :id, Integer | missing, :bad_id
7
+ }
8
+ end
9
+
10
+ it "Integer|missing should correctly accept missings" do
11
+ signature = Waw::Validation.signature {
12
+ validation :id, Integer | missing, :bad_id
13
+ }
14
+ signature.allows?(:id => nil).should be_true
15
+ signature.allows?(:id => "").should be_true
16
+ end
17
+
18
+ it "Integer|missing should correctly accept integers as well" do
19
+ signature = Waw::Validation.signature {
20
+ validation :id, Integer | missing, :bad_id
21
+ }
22
+ signature.allows?(:id => 12).should be_true
23
+ signature.allows?(:id => "12").should be_true
24
+ end
25
+
26
+ it "Integer|missing should correctly handle bulk conversions" do
27
+ validator = (Waw::Validation.integer | Waw::Validation.missing)
28
+ ok, values = validator.convert_and_validate(1, nil, 12, "1", "2", "")
29
+ ok.should be_true
30
+ values.should == [1, nil, 12, 1, 2, nil]
31
+ end
32
+
33
+ end
@@ -0,0 +1,37 @@
1
+ require "waw"
2
+ describe Waw::Validation::Error do
3
+
4
+ it "should be raisable easily" do
5
+ begin
6
+ raise Waw::Validation::Error, [:bad_user, :bad_age]
7
+ false.should be_true
8
+ rescue Waw::Validation::Error => ex
9
+ ex.failed.should == [:bad_user, :bad_age]
10
+ ex.message.should_not be_nil
11
+ ex.message.is_a?(String).should be_true
12
+ end
13
+ end
14
+
15
+ it "should allow catching subclasses with Error" do
16
+ begin
17
+ raise Waw::Validation::KO, [:bad_user, :bad_age]
18
+ false.should be_true
19
+ rescue Waw::Validation::Error => ex
20
+ ex.failed.should == [:bad_user, :bad_age]
21
+ ex.message.should_not be_nil
22
+ ex.message.is_a?(String).should be_true
23
+ end
24
+ end
25
+
26
+ it "should allow catching exact subclasses" do
27
+ begin
28
+ raise Waw::Validation::KO, [:bad_user, :bad_age]
29
+ false.should be_true
30
+ rescue Waw::Validation::KO => ex
31
+ ex.failed.should == [:bad_user, :bad_age]
32
+ ex.message.should_not be_nil
33
+ ex.message.is_a?(String).should be_true
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,34 @@
1
+ require 'waw'
2
+ require 'fileutils'
3
+ describe ::Waw::Validation::FileValidator do
4
+
5
+ def file
6
+ ::Waw::Validation::FileValidator.new
7
+ end
8
+
9
+ def sandbox_file_with_spaces
10
+ File.join(File.dirname(__FILE__), 'issue 360.txt')
11
+ end
12
+
13
+ before(:all) do
14
+ File.open(sandbox_file_with_spaces, 'w'){|io| io << "hello world!"}
15
+ File.read(sandbox_file_with_spaces).should == "hello world!"
16
+ end
17
+
18
+ after(:all) do
19
+ FileUtils.rm sandbox_file_with_spaces
20
+ end
21
+
22
+ it "should recognize real files" do
23
+ (file === __FILE__).should be_true
24
+ end
25
+
26
+ it "should support file names containing spaces (see #360)" do
27
+ (file === sandbox_file_with_spaces).should be_true
28
+ end
29
+
30
+ it "should not decode html paths itself (see #360)" do
31
+ (file === sandbox_file_with_spaces.gsub(/\s/,"%20")).should be_false
32
+ end
33
+
34
+ end
@@ -0,0 +1,51 @@
1
+ require 'waw'
2
+ describe "mail proposed validation" do
3
+
4
+ # Creates a signature
5
+ def mail
6
+ @mail_validator ||= ::Waw::Validation.signature {
7
+ validation :mail, mail, :bad_mail
8
+ }
9
+ end
10
+
11
+ it "should block missing values" do
12
+ mail.blocks?(:mail => nil).should be_true
13
+ mail.blocks?(:mail => "").should be_true
14
+ mail.blocks?(:mail => " ").should be_true
15
+ end
16
+
17
+ it "should be robust to strange values" do
18
+ mail.blocks?(:mail => nil).should be_true
19
+ mail.blocks?(:mail => 12).should be_true
20
+ mail.blocks?(:mail => self).should be_true
21
+ mail.blocks?(:mail => Class).should be_true
22
+ mail.blocks?(:mail => self).should be_true
23
+ end
24
+
25
+ it "should allow valid mails" do
26
+ mail.allows?(:mail => "blambeau@gmail.com").should be_true
27
+ mail.allows?(:mail => "blambeau@acm-sc.be").should be_true
28
+ end
29
+
30
+ it "should support mails with dots" do
31
+ mail.allows?(:mail => "bernard.lambeau@gmail.com").should be_true
32
+ end
33
+
34
+ it "should support mails with numbers" do
35
+ mail.allows?(:mail => "bernard007@gmail.com").should be_true
36
+ end
37
+
38
+ it "should support trailing spaces" do
39
+ mail.allows?(:mail => "blambeau@gmail.com ").should be_true
40
+ mail.allows?(:mail => " blambeau@acm-sc.be").should be_true
41
+ mail.allows?(:mail => " blambeau@acm-sc.be ").should be_true
42
+ end
43
+
44
+ it "should not support spaces inside the mail" do
45
+ mail.blocks?(:mail => "blamb gmail.com").should be_true
46
+ mail.blocks?(:mail => "blambeau@gmail.com and something here").should be_true
47
+ mail.blocks?(:mail => "something here blambeau@gmail.com").should be_true
48
+ mail.blocks?(:mail => "something here blambeau@gmail.com and also here").should be_true
49
+ end
50
+
51
+ end
@@ -0,0 +1,43 @@
1
+ require 'waw'
2
+ describe "missing validation" do
3
+
4
+ # Creates a signature
5
+ def missing(&block)
6
+ if block
7
+ ::Waw::Validation.signature(&block)
8
+ else
9
+ @missing_validator ||= ::Waw::Validation.signature {
10
+ validation :mail, missing, :bad_mail
11
+ }
12
+ end
13
+ end
14
+
15
+ it "should allow missing values" do
16
+ missing.allows?(:mail => nil).should be_true
17
+ missing.allows?(:mail => "").should be_true
18
+ missing.allows?(:mail => " ").should be_true
19
+ end
20
+
21
+ it "should block non missing values" do
22
+ missing.blocks?(:mail => "blambeau@gmail.com").should be_true
23
+ end
24
+
25
+ it "should be robust to strange values" do
26
+ missing.blocks?(:mail => 1234567).should be_true
27
+ missing.blocks?(:mail => self).should be_true
28
+ missing.blocks?(:mail => Object.new).should be_true
29
+ missing.blocks?(:mail => Class).should be_true
30
+ end
31
+
32
+ it "should correctly convert missings to nil" do
33
+ missing.first_converted(:mail => "").should be_nil
34
+ missing.first_converted(:mail => nil).should be_nil
35
+ missing.first_converted(:mail => " ").should be_nil
36
+ end
37
+
38
+ it "should never change non missings" do
39
+ missing.first_converted(:mail => "bla").should == "bla"
40
+ missing.first_converted(:mail => 12).should == 12
41
+ end
42
+
43
+ end
@@ -0,0 +1,24 @@
1
+ require 'waw'
2
+ describe "same proposed validation" do
3
+
4
+ # Creates a signature
5
+ def mail
6
+ @same_validator ||= ::Waw::Validation.signature {
7
+ validation [:pass, :confirm], mandatory & same, :bad_mail
8
+ }
9
+ end
10
+
11
+ it "should block invalid combinations" do
12
+ mail.blocks?(:pass => nil).should be_true
13
+ mail.blocks?(:confirm => "").should be_true
14
+ mail.blocks?(:pass => "", :confirm => "").should be_true
15
+ mail.blocks?(:pass => nil, :confirm => "blambeau").should be_true
16
+ mail.blocks?(:pass => "blambeau", :confirm => "").should be_true
17
+ end
18
+
19
+ it "should not block valid combinations" do
20
+ mail.blocks?(:pass => "blambeau", :confirm => "blambeau").should be_false
21
+ end
22
+
23
+
24
+ end
@@ -0,0 +1,37 @@
1
+ require 'waw'
2
+ describe ::Waw::Validation::Signature do
3
+
4
+ # Creates a signature
5
+ def signature(&block)
6
+ ::Waw::Validation.signature(&block)
7
+ end
8
+
9
+ it "should not be disjunction sensitive on missing" do
10
+ signature = signature {
11
+ validation :mail, mail | missing, :bad_mail
12
+ }
13
+ signature.first_converted(:mail => "blambeau@hotmail.com").should == "blambeau@hotmail.com"
14
+ signature.first_converted().should be_nil
15
+
16
+ signature = signature {
17
+ validation :mail, missing | mail, :bad_mail
18
+ }
19
+ signature.first_converted(:mail => "blambeau@hotmail.com").should == "blambeau@hotmail.com"
20
+ signature.first_converted().should be_nil
21
+ end
22
+
23
+ it "should not be disjunction sensitive on default" do
24
+ signature = signature {
25
+ validation :mail, mail | default("info@hotmail.com"), :bad_mail
26
+ }
27
+ signature.first_converted(:mail => "blambeau@hotmail.com").should == "blambeau@hotmail.com"
28
+ signature.first_converted().should == "info@hotmail.com"
29
+
30
+ signature = signature {
31
+ validation :mail, default("info@hotmail.com") | mail, :bad_mail
32
+ }
33
+ signature.first_converted(:mail => "blambeau@hotmail.com").should == "blambeau@hotmail.com"
34
+ signature.first_converted().should == "info@hotmail.com"
35
+ end
36
+
37
+ end
@@ -0,0 +1,164 @@
1
+ require 'waw'
2
+
3
+ describe ::Waw::Validation::Signature do
4
+
5
+ # Creates a signature
6
+ def signature(&block)
7
+ ::Waw::Validation.signature(&block)
8
+ end
9
+
10
+ it "should allow user-friendly DSL" do
11
+ signature {
12
+ validation :mail, mandatory & mail, :bad_email
13
+ validation [:password, :confirm], mandatory & equal, :password_dont_match
14
+ }.should_not be_nil
15
+ end
16
+
17
+ it "should have allows? and blocks? with opposite answers" do
18
+ signature = signature {
19
+ validation :age, is >= 18, :bad_age
20
+ }
21
+ signature.allows?().should be_false
22
+ signature.blocks?().should be_true
23
+ end
24
+
25
+ it "should allow valid data" do
26
+ signature = signature {
27
+ validation :age, is >= 18, :bad_age
28
+ }
29
+ signature.allows?(:age => 18).should be_true
30
+ signature.allows?(:age => 20).should be_true
31
+ end
32
+
33
+ it "should block invalid data" do
34
+ signature = signature {
35
+ validation :age, is >= 18, :bad_age
36
+ }
37
+ signature.blocks?().should be_true
38
+ signature.blocks?(:age => "").should be_true
39
+ signature.blocks?(:age => " ").should be_true
40
+ signature.blocks?(:age => nil).should be_true
41
+ signature.blocks?(:age => -10).should be_true
42
+ signature.blocks?(:age => 17).should be_true
43
+ signature.blocks?(:age => 17.99999).should be_true
44
+ end
45
+
46
+ it "should support missing in disjunction" do
47
+ signature = signature {
48
+ validation :mail, mail | missing, :bad_mail
49
+ }
50
+ signature.allows?(:mail => "blambeau@hotmail.com").should be_true
51
+ signature.blocks?(:mail => "blambeau@hotmail.com").should be_false
52
+ signature.allows?(:mail => "").should be_true
53
+ signature.allows?(:mail => " ").should be_true
54
+ signature.allows?(:mail => nil).should be_true
55
+ end
56
+
57
+ it "should allow Boolean to be like a ruby class" do
58
+ signature = signature {
59
+ validation :newsletter, Boolean, :bad_newsletter
60
+ }
61
+ signature.allows?(:newsletter => true).should be_true
62
+ signature.allows?(:newsletter => false).should be_true
63
+ signature.allows?(:newsletter => "true").should be_true
64
+ signature.allows?(:newsletter => "false").should be_true
65
+ end
66
+
67
+ it "should allow String ruby class as validator" do
68
+ signature = signature {
69
+ validation :name, String, :bad_name
70
+ }
71
+ signature.allows?(:name => "blambeau").should be_true
72
+ signature.allows?(:name => "").should be_true
73
+ signature.blocks?(:name => nil).should be_true
74
+ signature.blocks?().should be_true
75
+ end
76
+
77
+ it "should allow Integer ruby class as validator" do
78
+ signature = signature {
79
+ validation :age, Integer, :bad_age
80
+ }
81
+ signature.allows?(:age => 12).should be_true
82
+ signature.allows?(:age => "12").should be_true
83
+ signature.blocks?(:age => "hello").should be_true
84
+ signature.blocks?().should be_true
85
+ end
86
+
87
+ it "should allow Float ruby class as validator" do
88
+ signature = signature {
89
+ validation :temperature, Float, :bad_temperature
90
+ }
91
+ signature.allows?(:temperature => 12).should be_true
92
+ signature.allows?(:temperature => 12.0).should be_true
93
+ signature.allows?(:temperature => "12").should be_true
94
+ signature.allows?(:temperature => "12.0").should be_true
95
+ signature.blocks?(:temperature => "hello").should be_true
96
+ signature.blocks?().should be_true
97
+ end
98
+
99
+ it "should allow ruby classes as left part of a disjunction" do
100
+ signature = signature {
101
+ validation :age, missing | Integer, :bad_age
102
+ }
103
+ signature.allows?(:age => 12).should be_true
104
+ signature.allows?(:age => "").should be_true
105
+ signature.allows?(:age => nil).should be_true
106
+ signature.blocks?(:age => "hello").should be_true
107
+ end
108
+
109
+ it "should allow ruby classes as right part of a disjunction" do
110
+ signature = signature {
111
+ validation :age, Integer | missing, :bad_age
112
+ }
113
+ signature.allows?(:age => 12).should be_true
114
+ signature.allows?(:age => "").should be_true
115
+ signature.allows?(:age => nil).should be_true
116
+ signature.blocks?(:age => "hello").should be_true
117
+ end
118
+
119
+ it "should allow ruby classes as left part of a conjunction" do
120
+ signature = signature {
121
+ validation :age, (is > 10) & Integer, :bad_age
122
+ }
123
+ signature.allows?(:age => 12).should be_true
124
+ signature.allows?(:age => "").should be_false
125
+ signature.allows?(:age => nil).should be_false
126
+ signature.blocks?(:age => 7).should be_true
127
+ signature.blocks?(:age => "hello").should be_true
128
+ end
129
+
130
+ it "should allow ruby classes as right part of a conjunction" do
131
+ signature = signature {
132
+ validation :age, Integer & (is > 10), :bad_age
133
+ }
134
+ signature.allows?(:age => 12).should be_true
135
+ signature.allows?(:age => "").should be_false
136
+ signature.allows?(:age => nil).should be_false
137
+ signature.blocks?(:age => 7).should be_true
138
+ signature.blocks?(:age => "hello").should be_true
139
+ end
140
+
141
+ it "should provide a utility to get default data" do
142
+ signature = signature {
143
+ validation :name, String | default("hello"), :bad_name
144
+ validation :age, Integer | default(12), :bad_age
145
+ }
146
+ signature.default.should == {:name => "hello", :age => 12}
147
+ end
148
+
149
+ it "should support multiple args when computing defaults" do
150
+ signature = signature {
151
+ validation :name, String | default("hello"), :bad_name
152
+ validation [:age, :support], Integer | default(12), :bad_age
153
+ }
154
+ signature.default.should == {:name => "hello", :age => 12, :support => 12}
155
+ end
156
+
157
+ it "should support non defaults when computing defaults" do
158
+ signature = signature {
159
+ validation [:name1, :name2], String, :bad_name
160
+ }
161
+ signature.default.should == {:name1 => nil, :name2 => nil}
162
+ end
163
+
164
+ end