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,43 @@
1
+ require 'waw'
2
+ describe ::Waw::Session do
3
+ include ::Waw::Fixtures
4
+ before(:each) { load_empty_app }
5
+ after(:each) { unload_empty_app }
6
+
7
+ def session
8
+ @empty_app.session
9
+ end
10
+
11
+ it "should allows being extended" do
12
+ class ::Waw::Session
13
+ session_var :my_variable, 15
14
+ end
15
+ (session.my_variable = 12).should == 12
16
+ session.my_variable.should == 12
17
+ end
18
+
19
+ it "should allow resetting variables" do
20
+ class ::Waw::Session
21
+ session_var :my_variable, 15
22
+ end
23
+ session.my_variable = 12
24
+ session.reset(:my_variable)
25
+ session.my_variable.should == 15
26
+ end
27
+
28
+ it "should allow query variables without parameters" do
29
+ class ::Waw::Session
30
+ session_var(:my_query){ "hello" }
31
+ end
32
+ session.my_query.should == "hello"
33
+ end
34
+
35
+ it "should allow query variables with parameters" do
36
+ class ::Waw::Session
37
+ session_var(:my_id, 12)
38
+ session_var(:my_query){|session| session.my_id }
39
+ end
40
+ session.my_query.should == 12
41
+ end
42
+
43
+ end
@@ -0,0 +1,55 @@
1
+ require "waw"
2
+ describe Waw::FullState::Variable do
3
+ include ::Waw::Fixtures
4
+ before(:each) { load_empty_app }
5
+ after(:each) { unload_empty_app }
6
+
7
+ # Creates a variable instance
8
+ def variable(name, default_value = nil, &block)
9
+ Waw::FullState::Variable.new(name, default_value, &block)
10
+ rescue => ex
11
+ raise ex
12
+ end
13
+
14
+ it "should accept respect assignation" do
15
+ var = variable(:name)
16
+ (var.value = 12).should == 12
17
+ var.value.should == 12
18
+ var.value += 1
19
+ var.value.should == 13
20
+ end
21
+
22
+ it "should respect default values" do
23
+ var = variable(:name, 12)
24
+ var.value.should == 12
25
+ var.value += 1
26
+ var.value.should == 13
27
+ end
28
+
29
+ it "should respect block default values" do
30
+ var = variable(:name){ "hello world" }
31
+ var.value.should == "hello world"
32
+ var.value = 1
33
+ var.value.should == 1
34
+ end
35
+
36
+ it "should allow reset with a default value" do
37
+ var = variable(:name, 12)
38
+ var.value = 2
39
+ var.reset
40
+ var.value.should == 12
41
+ end
42
+
43
+ it "should allow reset with a block as default" do
44
+ var = variable(:name){ "hello world" }
45
+ var.value = 2
46
+ var.reset
47
+ var.value.should == "hello world"
48
+ end
49
+
50
+ it "should detect bad usages" do
51
+ # don't know why it does not work
52
+ #variable(:name, 12){ 13 }.should raise_exception(ArgumentError)
53
+ end
54
+
55
+ end
@@ -0,0 +1,50 @@
1
+ require 'waw'
2
+ describe ::Waw::ResourceCollection do
3
+
4
+ it "should support creating resources simply" do
5
+ resources = ::Waw::ResourceCollection.parse_resources <<-EOF
6
+ name 'hello'
7
+ who 12
8
+ EOF
9
+ resources.name.should == 'hello'
10
+ resources.who.should == 12
11
+ end
12
+
13
+ it "should support default values" do
14
+ resources = ::Waw::ResourceCollection.parse_resources <<-EOF
15
+ EOF
16
+ resources.name('hello').should == 'hello'
17
+ end
18
+
19
+ it "should support passing blocks" do
20
+ resources = ::Waw::ResourceCollection.parse_resources <<-EOF
21
+ what {|r| 12 }
22
+ EOF
23
+ resources.what.should == 12
24
+ end
25
+
26
+ it "should support installing Proc as resources" do
27
+ resources = ::Waw::ResourceCollection.parse_resources <<-EOF
28
+ what Kernel.lambda { 12 }
29
+ EOF
30
+ Proc.should === resources.what
31
+ resources.what.call.should == 12
32
+ end
33
+
34
+ it "should support self referencing" do
35
+ resources = ::Waw::ResourceCollection.parse_resources <<-EOF
36
+ who 'hello'
37
+ who2 who
38
+ EOF
39
+ resources.who2.should == 'hello'
40
+ end
41
+
42
+ it "should support self referencing with blocks" do
43
+ resources = ::Waw::ResourceCollection.parse_resources <<-EOF
44
+ who {'hello'}
45
+ who2 who
46
+ EOF
47
+ resources.who2.should == 'hello'
48
+ end
49
+
50
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
2
+ require 'waw'
3
+ require 'spec/autorun'
4
+ require File.join(File.dirname(__FILE__), 'fixtures')
5
+ test_files = Dir[File.join(File.dirname(__FILE__), '**/*_spec.rb')]
6
+ test_files.each { |file|
7
+ require(file)
8
+ }
9
+
@@ -0,0 +1,116 @@
1
+ require 'waw'
2
+ require 'waw/tools/mail'
3
+ describe ::Waw::Tools::MailAgent do
4
+
5
+ def agent
6
+ @agent ||= ::Waw::Tools::MailAgent.new
7
+ end
8
+
9
+ it("should provide a mail helper, hiding the Mail class") {
10
+ mail = agent.mail("Subject", "Body", "sender", "receiver")
11
+ mail.is_a?(::Waw::Tools::MailAgent::Mail).should be_true
12
+ mail.subject.should == "Subject"
13
+ mail.body.should == "Body"
14
+ mail.from.should == "sender"
15
+ mail.to.should == ["receiver"]
16
+ }
17
+
18
+ it("should provide a template helper, hiding the Template class") {
19
+ template = agent.template("Subject", "Body", "sender", "receiver")
20
+ template.is_a?(::Waw::Tools::MailAgent::Template).should be_true
21
+ template.subject.should == "Subject"
22
+ template.body.should == "Body"
23
+ template.from.should == "sender"
24
+ template.to.should == ["receiver"]
25
+ }
26
+
27
+ it("should allow sending mails easily") {
28
+ agent << agent.mail("Subject", "Message", "sender", "receiver")
29
+ agent.mailbox("receiver").size.should == 1
30
+ mail = agent.mailbox("receiver").read(0)
31
+ mail.subject.should == "Subject"
32
+ mail.body.should == "Message"
33
+ }
34
+
35
+ it("should allow sending mails to many receivers") {
36
+ agent << agent.mail("Subject", "Message", "sender", "receiver1", "receiver2")
37
+ agent.mailbox("receiver1").size.should == 1
38
+ agent.mailbox("receiver2").size.should == 1
39
+ }
40
+
41
+ it("should allow sending carbon copies") {
42
+ mail = agent.mail("Subject", "Message", "sender", "receiver1")
43
+ mail.cc = ["cc@chefbe.net"]
44
+ mail.bcc = ["bcc@chefbe.net"]
45
+ agent << mail
46
+ agent.mailbox("receiver1").size.should == 1
47
+ agent.mailbox("cc@chefbe.net").size.should == 1
48
+ agent.mailbox("bcc@chefbe.net").size.should == 1
49
+ }
50
+
51
+ # it("should really send mails if we force it") {
52
+ # agent = ::Waw::Tools::MailAgent.new({:host => 'localhost', :port => 7654, :timeout => 1}, true)
53
+ # agent << mail("Subject", "Message", "sender", "receiver1", "receiver2")
54
+ # }
55
+
56
+ it("should support mail templates") {
57
+ agent.add_template(:waw_info, "Hi ${who}, and welcome in waw", "We've received your request ${id}", "info@waw.org")
58
+ mail = agent.to_mail(:waw_info, {:who => "guy", :id => 123})
59
+ mail.subject.should == "Hi guy, and welcome in waw"
60
+ mail.body.should == "We've received your request 123"
61
+ mail.from.should == "info@waw.org"
62
+ }
63
+
64
+ it("should provide a great job when working with templates") {
65
+ agent.add_template(:waw_info, "Hi ${who}, and welcome in waw", "We've received your request ${id}", "info@waw.org")
66
+ agent.send_mail(:waw_info, {:who => "guy", :id => 123}, "blambeau@gmail.com")
67
+ mailbox = agent.mailbox("blambeau@gmail.com")
68
+ mailbox.size.should == 1
69
+ mailbox[0].subject.should == "Hi guy, and welcome in waw"
70
+ mailbox[0].body.should == "We've received your request 123"
71
+ mailbox[0].from.should == "info@waw.org"
72
+ mailbox[0].to.should == ["blambeau@gmail.com"]
73
+ }
74
+
75
+ it("should provide a send_mail with signature 1") {
76
+ agent.send_mail agent.mail("Subject", "Message", "sender", "receiver1", "receiver2")
77
+ mail = agent.mailbox("receiver1")[0]
78
+ mail.subject.should == "Subject"
79
+ mail = agent.mailbox("receiver2")[0]
80
+ mail.subject.should == "Subject"
81
+ }
82
+
83
+ it("should provide a send_mail with signature 2") {
84
+ agent.add_template(:waw_info, "${subject}", "${body}", "info@waw.org", "receiver1", "receiver2")
85
+ agent.send_mail(:waw_info, {:subject => "hello", :body => "world"})
86
+ mail = agent.mailbox("receiver1")[0]
87
+ mail.subject.should == "hello"
88
+ mail.body.should == "world"
89
+ mail = agent.mailbox("receiver2")[0]
90
+ mail.subject.should == "hello"
91
+ mail.body.should == "world"
92
+ }
93
+
94
+ it("should provide a send_mail with signature 3") {
95
+ agent.add_template(:waw_info, "${subject}", "${body}", "info@waw.org")
96
+ agent.send_mail(:waw_info, {:subject => "hello", :body => "world"}, "receiver1", "receiver2")
97
+ mail = agent.mailbox("receiver1")[0]
98
+ mail.subject.should == "hello"
99
+ mail.body.should == "world"
100
+ mail = agent.mailbox("receiver2")[0]
101
+ mail.subject.should == "hello"
102
+ mail.body.should == "world"
103
+ }
104
+
105
+ it("should provide a send_mail with signature 4") {
106
+ agent.add_template(:waw_info, "${subject}", "${body}", "info@waw.org")
107
+ agent.send_mail(:waw_info, {:subject => "hello", :body => "world"}, ["receiver1", "receiver2"])
108
+ mail = agent.mailbox("receiver1")[0]
109
+ mail.subject.should == "hello"
110
+ mail.body.should == "world"
111
+ mail = agent.mailbox("receiver2")[0]
112
+ mail.subject.should == "hello"
113
+ mail.body.should == "world"
114
+ }
115
+
116
+ end
@@ -0,0 +1,56 @@
1
+ require 'waw'
2
+ require 'waw/tools/mail'
3
+ describe ::Waw::Tools::MailAgent::Mail do
4
+
5
+ it "should correctly support encode/decode for testing purposes at least" do
6
+ mail = ::Waw::Tools::MailAgent::Mail.new
7
+ mail.from = "blambeau@gmail.com"
8
+ mail.to = ["blambeau@chefbe.net", "llambeau@chefbe.net"]
9
+ mail.cc = ["cc@chefbe.net"]
10
+ mail.bcc = ["bcc@chefbe.net"]
11
+ mail.subject = "This is a test mail"
12
+ mail.body = "Hello people"
13
+
14
+ mail = ::Waw::Tools::MailAgent::Mail.decode(mail.encode)
15
+ mail.from.should == "blambeau@gmail.com"
16
+ mail.to.should == ["blambeau@chefbe.net", "llambeau@chefbe.net"]
17
+ mail.cc.should == ["cc@chefbe.net"]
18
+ mail.bcc.should == ["bcc@chefbe.net"]
19
+ mail.subject.should == "This is a test mail"
20
+ mail.content_type.should == "text/plain"
21
+ mail.charset.should == "UTF-8"
22
+ mail.body.should == "Hello people"
23
+ end
24
+
25
+ it "should support encode/decode on long bodies" do
26
+ mail = ::Waw::Tools::MailAgent::Mail.new
27
+ body = <<-EOF
28
+ <p>This is a complex framework</p>
29
+
30
+ <p>But definitely fine!</p>
31
+ EOF
32
+ mail.body = body
33
+ mail.content_type = 'text/html'
34
+
35
+ mail.content_type.should == "text/html"
36
+ mail.charset.should == "UTF-8"
37
+ mail.body.should == body
38
+ end
39
+
40
+ it "should provide a short form for initialize" do
41
+ mail = ::Waw::Tools::MailAgent::Mail.new("The subject", "The message", "me", "you")
42
+ mail.subject.should == "The subject"
43
+ mail.body.should == "The message"
44
+ mail.from.should == "me"
45
+ mail.to.should == ["you"]
46
+ end
47
+
48
+ it "should support multiple receivers in the short form for initialize" do
49
+ mail = ::Waw::Tools::MailAgent::Mail.new("The subject", "The message", "me", "you", "us")
50
+ mail.subject.should == "The subject"
51
+ mail.body.should == "The message"
52
+ mail.from.should == "me"
53
+ mail.to.should == ["you", "us"]
54
+ end
55
+
56
+ end
@@ -0,0 +1,57 @@
1
+ require 'waw'
2
+ require 'waw/tools/mail'
3
+ describe Waw::Tools::MailAgent::Mailbox do
4
+
5
+ # Returns a mail instance
6
+ def mail(subject)
7
+ mail = Waw::Tools::MailAgent::Mail.new
8
+ mail.subject = subject
9
+ mail
10
+ end
11
+
12
+ def mailbox(who)
13
+ Waw::Tools::MailAgent::Mailbox.new(who)
14
+ end
15
+
16
+ it "should allow pushing mails" do
17
+ mailbox = mailbox("blambeau@gmail.com")
18
+ mailbox << mail("This is the first mail")
19
+ mailbox << mail("This is the second mail")
20
+ mailbox.size.should == 2
21
+ end
22
+
23
+ it "should allow getting mails" do
24
+ mailbox = mailbox("blambeau@gmail.com")
25
+ mailbox << mail("This is the first mail")
26
+ mailbox << mail("This is the second mail")
27
+ mailbox[0].subject.should == "This is the first mail"
28
+ mailbox[1].subject.should == "This is the second mail"
29
+ end
30
+
31
+ it "should allow reading mails" do
32
+ mailbox = mailbox("blambeau@gmail.com")
33
+ mailbox << mail("This is the first mail")
34
+ mailbox.is_read?(0).should be_false
35
+ (mail = mailbox.read(0)).should_not be_nil
36
+ mail.subject.should == "This is the first mail"
37
+ mailbox.is_read?(0).should be_true
38
+ end
39
+
40
+ it "should allow clearing the mailbox" do
41
+ mailbox = mailbox("blambeau@gmail.com")
42
+ mailbox << mail("This is the first mail")
43
+ mailbox << mail("This is the second mail")
44
+ mailbox.size.should == 2
45
+ mailbox.clear
46
+ mailbox.size.should == 0
47
+ end
48
+
49
+ it "should be robust to unexistant mails" do
50
+ mailbox = mailbox("blambeau@gmail.com")
51
+ mailbox[0].should be_nil
52
+ mailbox[-1].should be_nil
53
+ mailbox.is_read?(0).should be_nil
54
+ mailbox.read(0).should be_nil
55
+ end
56
+
57
+ end
@@ -0,0 +1,47 @@
1
+ require 'waw'
2
+ require 'waw/tools/mail'
3
+
4
+ describe ::Waw::Tools::MailAgent::Template do
5
+
6
+ def template(*args)
7
+ ::Waw::Tools::MailAgent::Template.new(*args)
8
+ end
9
+
10
+ it("should act as a mail for the construction") {
11
+ template = template("${subject}", "${body}", "from")
12
+ template.subject.should == "${subject}"
13
+ template.body.should == "${body}"
14
+ template.from.should == "from"
15
+ }
16
+
17
+ it("should detect wlang dialect from content-type") {
18
+ template = template("${subject}", "${body}", "from")
19
+ template.dialect.should == "wlang/active-string"
20
+ template.content_type = "text/html"
21
+ template.dialect.should == "wlang/xhtml"
22
+ }
23
+
24
+ it("should support easy to_mail instantiation") {
25
+ template = template("Here is the: ${subject}", "Here is the: ${body}", "from", "receiver1", "receiver2")
26
+ mail = template.to_mail(:subject => "The subject", :body => "The body")
27
+
28
+ # the template has not changed
29
+ template.subject.should == "Here is the: ${subject}"
30
+ template.body.should == "Here is the: ${body}"
31
+ template.to.should == ["receiver1", "receiver2"]
32
+
33
+ # the mail should be instantiated
34
+ mail.from.should == "from"
35
+ mail.subject.should == "Here is the: The subject"
36
+ mail.body.should == "Here is the: The body"
37
+ mail.to.should == ["receiver1", "receiver2"]
38
+ }
39
+
40
+ it("should ensure than to_mail returns something really detached from the template") {
41
+ template = template("Here is the: ${subject}", "Here is the: ${body}", "from", "receiver1", "receiver2")
42
+ mail = template.to_mail(:subject => "The subject", :body => "The body")
43
+ mail.to.clear
44
+ template.to.should == ["receiver1", "receiver2"]
45
+ }
46
+
47
+ end
@@ -0,0 +1,63 @@
1
+ require 'waw'
2
+ describe ::Waw::Validation::ArrayValidations do
3
+
4
+ it "should be correctly installed" do
5
+ Waw::Validation.array.should == Waw::Validation::ArrayValidations
6
+ Waw::Validation.array[Integer].should_not be_nil
7
+ Waw::Validation.array[Integer].is_a?(Waw::Validation::Validator).should be_true
8
+ end
9
+
10
+ it "should be autorized in a signature" do
11
+ signature = Waw::Validation.signature {
12
+ validation :id, array[Integer], :bad_array
13
+ }
14
+ end
15
+
16
+ it "should be correctly block or allow data" do
17
+ signature = Waw::Validation.signature {
18
+ validation :id, array[Integer], :bad_array
19
+ }
20
+ signature.allows?(:id => nil).should be_false
21
+ signature.allows?(:id => 1).should be_false
22
+ signature.allows?(:id => []).should be_true
23
+ signature.allows?(:id => [1, 2]).should be_true
24
+ signature.allows?(:id => ["1", "2"]).should be_true
25
+ signature.allows?(:id => ["1", "hello"]).should be_false
26
+ signature.allows?(:id => ["1", nil]).should be_false
27
+ signature.allows?(:id => ["1", ""]).should be_false
28
+
29
+ signature = Waw::Validation.signature {
30
+ validation :id, array[String], :bad_array
31
+ }
32
+ signature.allows?(:id => []).should be_true
33
+ end
34
+
35
+ it "should get converted sub values" do
36
+ signature = Waw::Validation.signature {
37
+ validation :id, array[Integer], :bad_array
38
+ }
39
+ signature.first_converted(:id => [1]).should == [1]
40
+ signature.first_converted(:id => ["1"]).should == [1]
41
+ signature.first_converted(:id => ["1", "2"]).should == [1, 2]
42
+ end
43
+
44
+ it "should allow complex validators" do
45
+ signature = Waw::Validation.signature {
46
+ validation :id, array[Integer | missing], :bad_array
47
+ }
48
+ signature.allows?(:id => nil).should be_false
49
+ signature.allows?(:id => ["1", "2"]).should be_true
50
+ signature.allows?(:id => ["1", nil]).should be_true
51
+ signature.allows?(:id => ["1", ""]).should be_true
52
+ end
53
+
54
+ it "should remove missing values" do
55
+ signature = Waw::Validation.signature {
56
+ validation :id, array[Integer | missing], :bad_array
57
+ }
58
+ signature.first_converted(:id => ["1", nil]).should == [1]
59
+ signature.first_converted(:id => ["1", ""]).should == [1]
60
+ signature.first_converted(:id => ["1", "", nil, "12", " "]).should == [1, 12]
61
+ end
62
+
63
+ end