mail_manager 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +15 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +20 -0
  4. data/.rspec +1 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/Gemfile +27 -0
  8. data/Guardfile +24 -0
  9. data/LICENSE.txt +22 -0
  10. data/MIT-LICENSE +20 -0
  11. data/Manifest.txt +141 -0
  12. data/Procfile +4 -0
  13. data/README +243 -0
  14. data/README.md +29 -0
  15. data/README.rdoc +3 -0
  16. data/Rakefile +33 -0
  17. data/app/.DS_Store +0 -0
  18. data/app/assets/javascripts/mail_manager/application.js +15 -0
  19. data/app/assets/stylesheets/mail_manager/application.css +13 -0
  20. data/app/controllers/mail_manager/application_controller.rb +4 -0
  21. data/app/controllers/mail_manager/base_controller.rb +22 -0
  22. data/app/controllers/mail_manager/bounces_controller.rb +32 -0
  23. data/app/controllers/mail_manager/contacts_controller.rb +75 -0
  24. data/app/controllers/mail_manager/mailing_lists_controller.rb +49 -0
  25. data/app/controllers/mail_manager/mailings_controller.rb +102 -0
  26. data/app/controllers/mail_manager/messages_controller.rb +30 -0
  27. data/app/controllers/mail_manager/subscriptions_controller.rb +104 -0
  28. data/app/helpers/mail_manager/application_helper.rb +4 -0
  29. data/app/helpers/mail_manager/subscriptions_helper.rb +8 -0
  30. data/app/models/.DS_Store +0 -0
  31. data/app/models/mail_manager.rb +12 -0
  32. data/app/models/mail_manager/bounce.rb +133 -0
  33. data/app/models/mail_manager/contact.rb +91 -0
  34. data/app/models/mail_manager/contactable_registry.rb +190 -0
  35. data/app/models/mail_manager/mailable_registry.rb +127 -0
  36. data/app/models/mail_manager/mailer.rb +267 -0
  37. data/app/models/mail_manager/mailing.rb +266 -0
  38. data/app/models/mail_manager/mailing_list.rb +36 -0
  39. data/app/models/mail_manager/message.rb +127 -0
  40. data/app/models/mail_manager/subscription.rb +126 -0
  41. data/app/models/mail_manager/test_message.rb +175 -0
  42. data/app/models/status_history.rb +60 -0
  43. data/app/views/layouts/mail_manager/application.html.erb +14 -0
  44. data/app/views/mail_manager/bounces/_email_parts.html.erb +30 -0
  45. data/app/views/mail_manager/bounces/index.html.erb +32 -0
  46. data/app/views/mail_manager/bounces/show.html.erb +38 -0
  47. data/app/views/mail_manager/contacts/_form.html.erb +27 -0
  48. data/app/views/mail_manager/contacts/double_opt_in.html.erb +1 -0
  49. data/app/views/mail_manager/contacts/edit.html.erb +12 -0
  50. data/app/views/mail_manager/contacts/index.html.erb +86 -0
  51. data/app/views/mail_manager/contacts/new.html.erb +9 -0
  52. data/app/views/mail_manager/contacts/show.html.erb +22 -0
  53. data/app/views/mail_manager/contacts/subscribe.html.erb +2 -0
  54. data/app/views/mail_manager/contacts/thank_you.html.erb +12 -0
  55. data/app/views/mail_manager/help/_available_email_substitutions.html.erb +5 -0
  56. data/app/views/mail_manager/mailer/double_opt_in.erb +6 -0
  57. data/app/views/mail_manager/mailer/unsubscribed.erb +5 -0
  58. data/app/views/mail_manager/mailer/unsubscribed.html.erb +5 -0
  59. data/app/views/mail_manager/mailing_lists/_form.html.erb +20 -0
  60. data/app/views/mail_manager/mailing_lists/edit.html.erb +13 -0
  61. data/app/views/mail_manager/mailing_lists/index.html.erb +39 -0
  62. data/app/views/mail_manager/mailing_lists/new.html.erb +9 -0
  63. data/app/views/mail_manager/mailing_lists/show.html.erb +13 -0
  64. data/app/views/mail_manager/mailings/_form.html.erb +81 -0
  65. data/app/views/mail_manager/mailings/edit.html.erb +12 -0
  66. data/app/views/mail_manager/mailings/index.html.erb +52 -0
  67. data/app/views/mail_manager/mailings/new.html.erb +9 -0
  68. data/app/views/mail_manager/mailings/show.html.erb +28 -0
  69. data/app/views/mail_manager/mailings/test.html.erb +12 -0
  70. data/app/views/mail_manager/messages/index.html.erb +37 -0
  71. data/app/views/mail_manager/subscriptions/_form.html.erb +37 -0
  72. data/app/views/mail_manager/subscriptions/_subscriptions.html.erb +13 -0
  73. data/app/views/mail_manager/subscriptions/edit.html.erb +11 -0
  74. data/app/views/mail_manager/subscriptions/index.html.erb +32 -0
  75. data/app/views/mail_manager/subscriptions/new.html.erb +9 -0
  76. data/app/views/mail_manager/subscriptions/show.html.erb +8 -0
  77. data/app/views/mail_manager/subscriptions/unsubscribe.html.erb +2 -0
  78. data/app/views/mail_manager/subscriptions/unsubscribe_by_email_address.html.erb +13 -0
  79. data/config/daemons.yml +5 -0
  80. data/config/routes.rb +43 -0
  81. data/db/migrate/001_mail_mgr_initial.rb +84 -0
  82. data/db/migrate/002_mail_mgr_create_contact.rb +60 -0
  83. data/db/migrate/003_mail_mgr_test_message.rb +23 -0
  84. data/db/migrate/004_add_deleted_at_to_mailing_lists.rb +15 -0
  85. data/db/migrate/005_contacts_deleted_at.rb +15 -0
  86. data/db/migrate/006_mail_mgr_mailing_list_add_defaults_to_active.rb +15 -0
  87. data/db/migrate/007_mail_mgr_message_add_from_email_address.rb +15 -0
  88. data/db/mlm_migrate/001_mlm_initial.rb +67 -0
  89. data/db/mlm_migrate/002_mailable_as_polymorphic.rb +27 -0
  90. data/db/mlm_migrate/003_contact_as_polymorphic.rb +64 -0
  91. data/db/mlm_migrate/004_bounce_mlm_mailing_id.rb +26 -0
  92. data/db/mlm_migrate/005_mlm_to_mail_mgr_scoped.rb +29 -0
  93. data/engine_plan.rb +13 -0
  94. data/features/bounce_management.feature +0 -0
  95. data/features/contact_management.feature +24 -0
  96. data/features/mailable.feature +23 -0
  97. data/features/mailing_management.feature +78 -0
  98. data/features/message.feature +11 -0
  99. data/features/step_definitions/email_steps.rb +50 -0
  100. data/features/step_definitions/mlm_steps.rb +11 -0
  101. data/features/step_definitions/pickle_steps.rb +41 -0
  102. data/features/step_definitions/webrat_steps.rb +115 -0
  103. data/features/subscription_management.feature +17 -0
  104. data/features/support/env.rb +31 -0
  105. data/features/support/paths.rb +44 -0
  106. data/lib/daemons/mail_manager.rb +38 -0
  107. data/lib/daemons/mail_manager_ctl +15 -0
  108. data/lib/deleteable.rb +50 -0
  109. data/lib/lock.rb +36 -0
  110. data/lib/mail_manager.rb +5 -0
  111. data/lib/mail_manager/config.rb +50 -0
  112. data/lib/mail_manager/engine.rb +43 -0
  113. data/lib/mail_manager/version.rb +3 -0
  114. data/lib/tasks/mail_manager.rake +143 -0
  115. data/lib/tasks/mail_manager_tasks.rake +4 -0
  116. data/lib/tasks/rspec.rake +165 -0
  117. data/lib/workers/mail_manager/bounce_job.rb +52 -0
  118. data/lib/workers/mail_manager/mailing_job.rb +30 -0
  119. data/lib/workers/mail_manager/message_job.rb +38 -0
  120. data/lib/workers/mail_manager/test_message_job.rb +37 -0
  121. data/mail_manager.gemspec +29 -0
  122. data/script/rails +8 -0
  123. data/spec/rcov.opts +2 -0
  124. data/spec/spec.opts +4 -0
  125. data/spec/spec_helper.rb +47 -0
  126. data/spec/test_app/README.rdoc +261 -0
  127. data/spec/test_app/Rakefile +7 -0
  128. data/spec/test_app/app/assets/javascripts/application.js +15 -0
  129. data/spec/test_app/app/assets/javascripts/users.js +2 -0
  130. data/spec/test_app/app/assets/stylesheets/application.css +13 -0
  131. data/spec/test_app/app/assets/stylesheets/scaffold.css +56 -0
  132. data/spec/test_app/app/assets/stylesheets/users.css +4 -0
  133. data/spec/test_app/app/controllers/application_controller.rb +3 -0
  134. data/spec/test_app/app/controllers/users_controller.rb +83 -0
  135. data/spec/test_app/app/helpers/application_helper.rb +2 -0
  136. data/spec/test_app/app/helpers/users_helper.rb +2 -0
  137. data/spec/test_app/app/models/user.rb +13 -0
  138. data/spec/test_app/app/views/layouts/application.html.erb +14 -0
  139. data/spec/test_app/app/views/users/_form.html.erb +33 -0
  140. data/spec/test_app/app/views/users/edit.html.erb +6 -0
  141. data/spec/test_app/app/views/users/index.html.erb +29 -0
  142. data/spec/test_app/app/views/users/new.html.erb +5 -0
  143. data/spec/test_app/app/views/users/show.html.erb +25 -0
  144. data/spec/test_app/config.ru +4 -0
  145. data/spec/test_app/config/application.rb +65 -0
  146. data/spec/test_app/config/boot.rb +10 -0
  147. data/spec/test_app/config/database.yml +25 -0
  148. data/spec/test_app/config/environment.rb +14 -0
  149. data/spec/test_app/config/environments/development.rb +37 -0
  150. data/spec/test_app/config/environments/production.rb +67 -0
  151. data/spec/test_app/config/environments/test.rb +37 -0
  152. data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
  153. data/spec/test_app/config/initializers/inflections.rb +15 -0
  154. data/spec/test_app/config/initializers/mime_types.rb +5 -0
  155. data/spec/test_app/config/initializers/secret_token.rb +7 -0
  156. data/spec/test_app/config/initializers/session_store.rb +8 -0
  157. data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
  158. data/spec/test_app/config/locales/en.yml +5 -0
  159. data/spec/test_app/config/lockable.yml +3 -0
  160. data/spec/test_app/config/mail_manager.yml +21 -0
  161. data/spec/test_app/config/routes.rb +7 -0
  162. data/spec/test_app/db/migrate/20131217101010_create_users.rb +13 -0
  163. data/spec/test_app/db/migrate/20131221064151_mail_mgr_initial.rb +84 -0
  164. data/spec/test_app/db/migrate/20131221064152_mail_mgr_create_contact.rb +60 -0
  165. data/spec/test_app/db/migrate/20131221064153_mail_mgr_test_message.rb +23 -0
  166. data/spec/test_app/db/migrate/20131221064154_add_deleted_at_to_mailing_lists.rb +15 -0
  167. data/spec/test_app/db/migrate/20131221064155_contacts_deleted_at.rb +15 -0
  168. data/spec/test_app/db/migrate/20131221064156_mail_mgr_mailing_list_add_defaults_to_active.rb +15 -0
  169. data/spec/test_app/db/migrate/20131221064157_mail_mgr_message_add_from_email_address.rb +15 -0
  170. data/spec/test_app/db/migrate/20131221072600_create_delayed_jobs.rb +22 -0
  171. data/spec/test_app/db/schema.rb +131 -0
  172. data/spec/test_app/db/structure.sql +31 -0
  173. data/spec/test_app/public/404.html +26 -0
  174. data/spec/test_app/public/422.html +26 -0
  175. data/spec/test_app/public/500.html +25 -0
  176. data/spec/test_app/public/favicon.ico +0 -0
  177. data/spec/test_app/script/delayed_job +5 -0
  178. data/spec/test_app/script/lockable +36 -0
  179. data/spec/test_app/script/rails +6 -0
  180. data/spec/test_app/spec/controllers/users_controller_spec.rb +160 -0
  181. data/spec/test_app/spec/factories/mailing_lists.rb +7 -0
  182. data/spec/test_app/spec/factories/mailings.rb +6 -0
  183. data/spec/test_app/spec/factories/original_factories.rb.txt +107 -0
  184. data/spec/test_app/spec/factories/users.rb +10 -0
  185. data/spec/test_app/spec/models/mail_manager/bounce_spec.rb +17 -0
  186. data/spec/test_app/spec/models/mail_manager/mailing_list_spec.rb +15 -0
  187. data/spec/test_app/spec/models/user_spec.rb +37 -0
  188. data/spec/test_app/spec/requests/users_spec.rb +11 -0
  189. data/spec/test_app/spec/routing/users_routing_spec.rb +35 -0
  190. data/spec/test_app/spec/support/database_cleaner.rb +23 -0
  191. data/spec/test_app/spec/support/files/bad_utf8_chars.eml +32 -0
  192. data/spec/test_app/spec/views/users/edit.html.erb_spec.rb +24 -0
  193. data/spec/test_app/spec/views/users/index.html.erb_spec.rb +29 -0
  194. data/spec/test_app/spec/views/users/new.html.erb_spec.rb +24 -0
  195. data/spec/test_app/spec/views/users/show.html.erb_spec.rb +21 -0
  196. data/zeus.json +22 -0
  197. metadata +424 -0
data/engine_plan.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'zeus/rails'
2
+
3
+ ROOT_PATH = File.expand_path(Dir.pwd)
4
+ ENV_PATH = File.expand_path('spec/test_app/config/environment', ROOT_PATH)
5
+ BOOT_PATH = File.expand_path('spec/test_app/config/boot', ROOT_PATH)
6
+ APP_PATH = File.expand_path('spec/test_app/config/application', ROOT_PATH)
7
+ ENGINE_ROOT = File.expand_path(Dir.pwd)
8
+ ENGINE_PATH = File.expand_path('lib/mail_manager/engine', ENGINE_ROOT)
9
+
10
+ class EnginePlan < Zeus::Rails
11
+ end
12
+
13
+ Zeus.plan = EnginePlan.new
File without changes
@@ -0,0 +1,24 @@
1
+ Feature: Manage Contacts
2
+ In order to value
3
+ As a role
4
+ I want feature
5
+
6
+
7
+ Scenario: Search Contacts that exist
8
+ Given a contact: "Bob" exists with email_address: "bob@example.com"
9
+ And I am logged in and authorized for everything
10
+ When I go to the mail mgr contacts page
11
+ And I fill in "term" with "bob"
12
+ And I press "Search"
13
+ Then I should be on the mail mgr contacts page
14
+ And I should see "bob@example.com"
15
+
16
+ Scenario: Search Contacts that don't exist
17
+ Given a contact: "Bob" exists with email_address: "bob@example.com"
18
+ And I am logged in and authorized for everything
19
+ When I go to the mail mgr contacts page
20
+ And I fill in "term" with "sam"
21
+ And I press "Search"
22
+ Then I should be on the mail mgr contacts page
23
+ And I should not see "sam"
24
+
@@ -0,0 +1,23 @@
1
+ Feature: Mailable Registration
2
+ In order to have different things to email
3
+ As an object
4
+ I want be able to register as a mailable object
5
+
6
+ Scenario: reusable mailables will be available when I create a new mailing
7
+ Given the following mlm mailable records
8
+ | name | email_html | email_text | reusable |
9
+ | June Newsletter | <head><title>June Newsletter</title><body>June Newsletter</body></html> | June Newsletter | true |
10
+ | July Newsletter | <head><title>July Newsletter</title><body>July Newsletter</body></html> | July Newsletter | false |
11
+ And an mlm mailing list exists with name: "Newsletter"
12
+ When I go to the new mlm mailing page
13
+ Then I should see "June Newsletter"
14
+ And I should not see "July Newsletter"
15
+
16
+ Scenario: a new raw mailable can be created when creating a new mailing
17
+ When I go to the new mlm mailing page
18
+ And I select "New Mailable" from "mailing[mailable]"
19
+ And I fill in "mailable[name]" with "July Newsletter"
20
+ And I fill in "mailable[email_html]" with "<head><title>June Newsletter</title><body>July Newsletter</body></html>"
21
+ And I fill in "mailable[email_text]" with "July Newsletter"
22
+ And I check "mailable[reusable]"
23
+ Then an mlm mailable should exist with name: "July Newsletter", email_html: "<head><title>June Newsletter</title><body>July Newsletter</body></html>", email_text: "July Newsletter", reusable: true
@@ -0,0 +1,78 @@
1
+ Feature: Mailing Management
2
+ In order send mailings to my mailing list
3
+ As a valid user
4
+ I want to create, modify, schedule and cancel mailings
5
+
6
+ Background:
7
+ Given the following mlm mailable records
8
+ | name | email_html | email_text | reusable |
9
+ | June Newsletter | <head><title>June Newsletter</title><body>June Newsletter</body></html> | June Newsletter | false |
10
+ | July Newsletter | <head><title>July Newsletter</title><body>July Newsletter</body></html> | July Newsletter | true |
11
+ And the following mlm mailing list records
12
+ | name |
13
+ | The Mailing List |
14
+
15
+ Scenario: mailings are created by a valid user
16
+ When I go to the mlm mailings page
17
+ And I follow "New Mailing"
18
+ And I fill in "mailing[subject]" with "Fun Fun Fun July 2009"
19
+ And I select "July Newsletter" from "mailing[mailable]"
20
+ And I press "Save"
21
+ Then I should be on the mlm mailings page
22
+ And I should see "Fun Fun Fun"
23
+ And I should see "pending"
24
+ #And I should see "Send Test"
25
+ And I should see "Schedule"
26
+ And I should see "Edit"
27
+ And an mlm mailing should exist with subject: "Fun Fun Fun July 2009"
28
+
29
+ Scenario: edit a mailing
30
+ Given the following mlm mailing records
31
+ | subject |
32
+ | Fun Fun Fun July 2009 |
33
+ When I go to the mlm mailings page
34
+ And I follow "Edit"
35
+ And I fill in "mailing[subject]" with "Fun! Fun! Fun! July 2009"
36
+ And I press "Save"
37
+ And I should see "Fun! Fun! Fun! July 2009"
38
+ And I should see "pending"
39
+ And I should see "Send Test"
40
+ And I should see "Schedule"
41
+ And I should see "Edit"
42
+
43
+ Scenario: schedule a mailing
44
+ Given the following mlm mailing records
45
+ | subject |
46
+ | Fun Fun Fun July 2009 |
47
+ When I go to the mlm mailings page
48
+ And I follow "Schedule"
49
+ Then I should see "Fun Fun Fun"
50
+ And I should see "scheduled"
51
+ #And I should see "Send Test"
52
+ And I should see "Edit"
53
+ And I should see "Cancel"
54
+
55
+ Scenario: Cancel a mailing
56
+ Given the following mlm mailing records
57
+ | subject | status |
58
+ | Fun Fun Fun July 2009 | scheduled |
59
+ When I go to the mlm mailings page
60
+ And I follow "Cancel"
61
+ Then I should see "Fun Fun Fun"
62
+ And I should see "pending"
63
+ And I should see "Send Test"
64
+ And I should see "Edit"
65
+
66
+ Scenario: send a test message for mailing
67
+ Given the following mlm mailing records
68
+ | subject | status | scheduled_at |
69
+ | Fun Fun Fun July 2009 | scheduled | Time.now |
70
+ When I go to the mlm mailings page
71
+ And I follow "Send Test"
72
+ And I fill in "test_email_addresses" with "test@example.com"
73
+ And I press "Send Test Email"
74
+ Then I should see "scheduled"
75
+ And I should see "Send Test"
76
+ And I should see "Edit"
77
+ And I should see "Cancel"
78
+ And an email is sent to "test@example.com" with subject: "Fun Fun Fun July 2009"
@@ -0,0 +1,11 @@
1
+ Feature: Messages are tied to mailings even without subscriptions
2
+ In order to have relations with non-subscribed contacts
3
+ As an administrator
4
+ I want to send messages for contacts that aren't subscribed
5
+
6
+ Given I am logged in and authorized for everything
7
+ And a mailing: "Mailing" exists
8
+ And a contact: "Contact" exists with email_address: "bob@example.com"
9
+ And a
10
+
11
+
@@ -0,0 +1,50 @@
1
+ # this file generated by script/generate pickle email
2
+
3
+ ActionMailer::Base.delivery_method = :test
4
+ ActionMailer::Base.perform_deliveries = true
5
+
6
+ Before do
7
+ ActionMailer::Base.deliveries.clear
8
+ end
9
+
10
+ Given(/^all emails? (?:have|has) been delivered$/) do
11
+ ActionMailer::Base.deliveries.clear
12
+ end
13
+
14
+ Given(/^(\d)+ emails? should be delivered$/) do |count|
15
+ emails.size.should == count.to_i
16
+ end
17
+
18
+ Then(/^(\d)+ emails? should be delivered to (.*)$/) do |count, to|
19
+ to =~ /^#{capture_model}$/ && to = model($1).email
20
+ emails("to: \"#{to}\"").size.should == count.to_i
21
+ end
22
+
23
+ Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fields|
24
+ emails(fields).size.should == count.to_i
25
+ end
26
+
27
+ Then(/^#{capture_email} should be delivered to (.+)$/) do |email_ref, to|
28
+ to =~ /^#{capture_model}$/ && to = model($1).email
29
+ email(email_ref, "to: \"#{to}\"").should_not be_nil
30
+ end
31
+
32
+ Then(/^#{capture_email} should have #{capture_fields}$/) do |email_ref, fields|
33
+ email(email_ref, fields).should_not be_nil
34
+ end
35
+
36
+ Then(/^#{capture_email} should contain "(.*)"$/) do |email_ref, text|
37
+ email(email_ref).body.should =~ /#{text}/
38
+ end
39
+
40
+ Then(/^#{capture_email} should not contain "(.*)"$/) do |email_ref, text|
41
+ email(email_ref).body.should_not =~ /#{text}/
42
+ end
43
+
44
+ Then(/^#{capture_email} should link to (.+)$/) do |email_ref, page|
45
+ email(email_ref).body.should =~ /#{path_to(page)}/
46
+ end
47
+
48
+ Then(/^show me the emails?$/) do
49
+ save_and_open_emails
50
+ end
@@ -0,0 +1,11 @@
1
+ Then /^contact: "([^"]*)" subscribes to mailing list: "([^"]*)"$/ do |contact_name, mailing_list_name|
2
+ contact = model(%Q|contact: "#{contact_name}"|)
3
+ mailing_list = model(%Q|mailing_list: "#{mailing_list_name}"|)
4
+ contact.subscribe(mailing_list)
5
+ end
6
+
7
+ Then /^contact: "([^"]*)" should not be subscribed to mailing list: "([^"]*)"$/ do |contact_name, mailing_list_name|
8
+ contact = model(%Q|contact: "#{contact_name}"|)
9
+ mailing_list = model(%Q|mailing_list: "#{mailing_list_name}"|)
10
+ contact.subscriptions.detect{|subscription| subscription.active? and subscription.mailing_list == mailing_list}.should be_nil
11
+ end
@@ -0,0 +1,41 @@
1
+ # this file generated by script/generate pickle
2
+
3
+ # create a model
4
+ Given(/^#{capture_model} exists?(?: with #{capture_fields})?$/) do |name, fields|
5
+ create_model(name, fields)
6
+ end
7
+
8
+ # create n models
9
+ Given(/^(\d+) #{capture_plural_factory} exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
10
+ count.to_i.times { create_model(plural_factory.singularize, fields) }
11
+ end
12
+
13
+ # find a model
14
+ Then(/^#{capture_model} should exist(?: with #{capture_fields})?$/) do |name, fields|
15
+ find_model(name, fields).should_not be_nil
16
+ end
17
+
18
+ # find exactly n models
19
+ Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
20
+ find_models(plural_factory.singularize, fields).size.should == count.to_i
21
+ end
22
+
23
+ # assert model is in another model's has_many assoc
24
+ Then(/^#{capture_model} should be (?:in|one of|amongst) #{capture_model}'s (\w+)$/) do |target, owner, association|
25
+ model(owner).send(association).should include(model(target))
26
+ end
27
+
28
+ # assert model is another model's has_one/belongs_to assoc
29
+ Then(/^#{capture_model} should be #{capture_model}'s (\w+)$/) do |target, owner, association|
30
+ model(owner).send(association).should == model(target)
31
+ end
32
+
33
+ # assert model.predicate?
34
+ Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
35
+ model(name).should send("be_#{predicate.gsub(' ', '_')}")
36
+ end
37
+
38
+ # assert not model.predicate?
39
+ Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
40
+ model(name).should_not send("be_#{predicate.gsub(' ', '_')}")
41
+ end
@@ -0,0 +1,115 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
2
+
3
+ # Commonly used webrat steps
4
+ # http://github.com/brynary/webrat
5
+
6
+ Given /^I am on (.+)$/ do |page_name|
7
+ visit path_to(page_name)
8
+ end
9
+
10
+ When /^I go to (.+)$/ do |page_name|
11
+ visit path_to(page_name)
12
+ end
13
+
14
+ When /^I press "([^\"]*)"$/ do |button|
15
+ click_button(button)
16
+ end
17
+
18
+ When /^I follow "([^\"]*)"$/ do |link|
19
+ click_link(link)
20
+ end
21
+
22
+ When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
23
+ fill_in(field, :with => value)
24
+ end
25
+
26
+ When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
27
+ select(value, :from => field)
28
+ end
29
+
30
+ # Use this step in conjunction with Rail's datetime_select helper. For example:
31
+ # When I select "December 25, 2008 10:00" as the date and time
32
+ When /^I select "([^\"]*)" as the date and time$/ do |time|
33
+ select_datetime(time)
34
+ end
35
+
36
+ # Use this step when using multiple datetime_select helpers on a page or
37
+ # you want to specify which datetime to select. Given the following view:
38
+ # <%= f.label :preferred %><br />
39
+ # <%= f.datetime_select :preferred %>
40
+ # <%= f.label :alternative %><br />
41
+ # <%= f.datetime_select :alternative %>
42
+ # The following steps would fill out the form:
43
+ # When I select "November 23, 2004 11:20" as the "Preferred" date and time
44
+ # And I select "November 25, 2004 10:30" as the "Alternative" date and time
45
+ When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
46
+ select_datetime(datetime, :from => datetime_label)
47
+ end
48
+
49
+ # Use this step in conjunction with Rail's time_select helper. For example:
50
+ # When I select "2:20PM" as the time
51
+ # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
52
+ # will convert the 2:20PM to 14:20 and then select it.
53
+ When /^I select "([^\"]*)" as the time$/ do |time|
54
+ select_time(time)
55
+ end
56
+
57
+ # Use this step when using multiple time_select helpers on a page or you want to
58
+ # specify the name of the time on the form. For example:
59
+ # When I select "7:30AM" as the "Gym" time
60
+ When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
61
+ select_time(time, :from => time_label)
62
+ end
63
+
64
+ # Use this step in conjunction with Rail's date_select helper. For example:
65
+ # When I select "February 20, 1981" as the date
66
+ When /^I select "([^\"]*)" as the date$/ do |date|
67
+ select_date(date)
68
+ end
69
+
70
+ # Use this step when using multiple date_select helpers on one page or
71
+ # you want to specify the name of the date on the form. For example:
72
+ # When I select "April 26, 1982" as the "Date of Birth" date
73
+ When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
74
+ select_date(date, :from => date_label)
75
+ end
76
+
77
+ When /^I check "([^\"]*)"$/ do |field|
78
+ check(field)
79
+ end
80
+
81
+ When /^I uncheck "([^\"]*)"$/ do |field|
82
+ uncheck(field)
83
+ end
84
+
85
+ When /^I choose "([^\"]*)"$/ do |field|
86
+ choose(field)
87
+ end
88
+
89
+ When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
90
+ attach_file(field, path)
91
+ end
92
+
93
+ Then /^I should see "([^\"]*)"$/ do |text|
94
+ response.should contain(text)
95
+ end
96
+
97
+ Then /^I should not see "([^\"]*)"$/ do |text|
98
+ response.should_not contain(text)
99
+ end
100
+
101
+ Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
102
+ field_labeled(field).value.should =~ /#{value}/
103
+ end
104
+
105
+ Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
106
+ field_labeled(field).value.should_not =~ /#{value}/
107
+ end
108
+
109
+ Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
110
+ field_labeled(label).should be_checked
111
+ end
112
+
113
+ Then /^I should be on (.+)$/ do |page_name|
114
+ URI.parse(current_url).path.should == path_to(page_name)
115
+ end
@@ -0,0 +1,17 @@
1
+ Feature: Manage Subscriptions
2
+ In order to have a list of email addresses to send messages to
3
+ As an administrator
4
+ I want to manage a contact's subscriptions
5
+
6
+ Scenario: Unsubscribe sends an email
7
+ Given a mailing: "Mailing" exists
8
+ And a mailing_list: "List1" exists with name: "List1"
9
+ And mailing_list: "List1" is one of mailing: "Mailing"'s mailing_lists
10
+ And a mailing_list: "List2" exists with name: "List2"
11
+ And mailing_list: "List2" is one of mailing: "Mailing"'s mailing_lists
12
+ And a mailing_list: "List3" exists with name: "List3"
13
+ And a mailing_list: "List4" exists with name: "List4"
14
+ And a contact: "Bob" exists with email_address: "bob@example.com"
15
+ And contact: "Bob" is subscribed to "List1, List3"
16
+ And mailing: "Mailing"'s "deliver" should "be_true"
17
+
@@ -0,0 +1,31 @@
1
+ # Sets up the Rails environment for Cucumber
2
+ ENV["RAILS_ENV"] ||= "test"
3
+ ENV["RAILS_ROOT"] ||= File.dirname(__FILE__) + "/../../spec/test_app"
4
+ require File.expand_path(ENV['RAILS_ROOT'] + "/config/environment.rb")
5
+ require 'cucumber/rails/world'
6
+ require 'cucumber/formatter/unicode' # Comment out this line if you don't want Cucumber Unicode support
7
+ Cucumber::Rails.use_transactional_fixtures
8
+ Cucumber::Rails.bypass_rescue # Comment out this line if you want Rails own error handling
9
+ # (e.g. rescue_action_in_public / rescue_responses / rescue_from)
10
+
11
+ require 'webrat'
12
+
13
+ Webrat.configure do |config|
14
+ config.mode = :rails
15
+ end
16
+
17
+ require 'cucumber/rails/rspec'
18
+ require 'webrat/core/matchers'
19
+
20
+ `rake db:test:clone_structure`
21
+
22
+ require "#{MailManager::PLUGIN_ROOT}/spec/factories"
23
+ require 'pickle/world'
24
+ # Example of configuring pickle:
25
+ #
26
+ #Pickle.configure do |config|
27
+ # config.adapters = [:factory_girl]
28
+ #config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
29
+ #end
30
+ require 'pickle/path/world'
31
+ require 'pickle/email/world'
@@ -0,0 +1,44 @@
1
+ module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in webrat_steps.rb
7
+ #
8
+ def path_to(page_name)
9
+ case page_name
10
+
11
+ when /the homepage/
12
+ '/'
13
+
14
+ # Add more mappings here.
15
+ # Here is a more fancy example:
16
+ #
17
+ # when /^(.*)'s profile page$/i
18
+ # user_profile_path(User.find_by_login($1))
19
+ # added by script/generate pickle path
20
+
21
+ when /^#{capture_model}(?:'s)? page$/ # eg. the forum's page
22
+ path_to_pickle $1
23
+
24
+ when /^#{capture_model}(?:'s)? #{capture_model}(?:'s)? page$/ # eg. the forum's post's page
25
+ path_to_pickle $1, $2
26
+
27
+ when /^#{capture_model}(?:'s)? #{capture_model}'s (.+?) page$/ # eg. the forum's post's comments page
28
+ path_to_pickle $1, $2, :extra => $3 # or the forum's post's edit page
29
+
30
+ when /^#{capture_model}(?:'s)? (.+?) page$/ # eg. the forum's posts page
31
+ path_to_pickle $1, :extra => $2 # or the forum's edit page
32
+
33
+ when /^the (.+?) page$/ # translate to named route
34
+ send "#{$1.downcase.gsub(' ','_')}_path"
35
+
36
+ # end added by pickle path
37
+ else
38
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
39
+ "Now, go and add a mapping in #{__FILE__}"
40
+ end
41
+ end
42
+ end
43
+
44
+ World(NavigationHelpers)