saucy 0.7.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ 0.8.0
2
+
3
+ Added a notification for trials that just ended. When upgrading, you'll need to
4
+ add to add a boolean notified_of_completed_trial column to the accounts table,
5
+ which should be NOT NULL and default to false. These notifications go out with
6
+ the daily Saucy jobs.
7
+
1
8
  0.7.3
2
9
 
3
10
  Added a uniqueness constraint for keyword on accounts/projects. When upgrading,
@@ -40,4 +40,14 @@ class BillingMailer < ActionMailer::Base
40
40
  :reply_to => Saucy::Configuration.support_email_address,
41
41
  :from => Saucy::Configuration.manager_email_address)
42
42
  end
43
+
44
+ def completed_trial(account)
45
+ @account = account
46
+ mail(:to => account.admin_emails,
47
+ :subject => I18n.t(:subject,
48
+ :scope => [:billing_mailer, :completed_trial],
49
+ :default => "Your trial has ended"),
50
+ :reply_to => Saucy::Configuration.support_email_address,
51
+ :from => Saucy::Configuration.manager_email_address)
52
+ end
43
53
  end
@@ -0,0 +1,15 @@
1
+ <%= t(".greeting") %>
2
+
3
+ <%= t(".completed_trial_notice",
4
+ :account_name => @account.name,
5
+ :app_name => t("app_name")) %>
6
+
7
+ <%= edit_account_plan_url(@account) %>
8
+
9
+ <%= t(".contact", :app_name => t("app_name")) %>
10
+
11
+ ============================================================
12
+
13
+ Thanks for your business,
14
+ The <%= t("app_name") %> Team
15
+ <%= t("app_url") %>
@@ -16,6 +16,10 @@ en:
16
16
  greeting: Thanks for giving us a try!
17
17
  expiration_notice: "Your 30 day trial for %{account_name} is expiring soon. I hope that you've enjoyed %{app_name} enough to sign up for a paid subscription. If you'd like to continue using your account, please take a moment to choose a paid plan:"
18
18
  contact: "If you need more time to evaluate %{app_name} or you have any questions, please don't hesitate to contact me."
19
+ completed_trial:
20
+ greeting: Thanks for giving us a try!
21
+ expiration_notice: "Your 30 day trial for %{account_name} is over, and your account has become inactive. If you'd like to continue using your account, please take a moment to choose a paid plan:"
22
+ contact: "If you need more time to evaluate %{app_name} or you have any questions, please don't hesitate to contact me."
19
23
  new_unactivated:
20
24
  body: |-
21
25
  Hi,
@@ -56,7 +56,7 @@ DESC
56
56
  edit_account_plan_path(account)
57
57
  when /^the new project page for the newest account by "([^"]*)"$/
58
58
  user = User.find_by_email!($1)
59
- account = user.accounts.order("created_at desc").first
59
+ account = user.accounts.order("id desc").first
60
60
  new_account_project_path(account)
61
61
  when /^the "([^"]*)" project page$/
62
62
  project = Project.find_by_name!($1)
@@ -70,3 +70,13 @@ Feature: Trial plans
70
70
  When I sign in as "admin@example.com/password"
71
71
  And I follow the link sent to "admin@example.com" with subject "A check in"
72
72
  Then I should be on the new project page for the newest account by "admin@example.com"
73
+
74
+ Scenario: Receive a reminder about an expired trial plan
75
+ Given a "Temp" account exists with a name of "Test" created 30 days ago
76
+ And a user exists with an email of "admin@example.com"
77
+ And "admin@example.com" is an admin of the "Test" account
78
+ When the daily Saucy jobs are processed
79
+ And I sign in as "admin@example.com"
80
+ And I follow the link sent to "admin@example.com" with subject "Your trial has ended"
81
+ Then I should be on the upgrade plan page for the "Test" account
82
+
@@ -20,7 +20,9 @@ class CreateSaucyTables < ActiveRecord::Migration
20
20
  table.string :subscription_token
21
21
  table.string :subscription_status
22
22
  table.datetime :next_billing_date
23
+ table.boolean :notified_of_disabling, :default => false, :null => false
23
24
  table.boolean :notified_of_expiration, :default => false, :null => false
25
+ table.boolean :notified_of_completed_trial, :default => false, :null => false
24
26
  table.boolean :asked_to_activate, :default => false, :null => false
25
27
  table.boolean :activated, :default => false, :null => false
26
28
  table.datetime :trial_expires_at
data/lib/saucy/account.rb CHANGED
@@ -98,9 +98,16 @@ module Saucy
98
98
  end
99
99
  end
100
100
 
101
+ def deliver_completed_trial_notifications
102
+ trial_completed.each do |account|
103
+ BillingMailer.completed_trial(account).deliver
104
+ account.notified_of_completed_trial = true
105
+ account.save!
106
+ end
107
+ end
108
+
101
109
  def trial_expiring
102
- includes(:plan).
103
- where(:plans => { :trial => true }).
110
+ trial.
104
111
  where(:notified_of_expiration => false).
105
112
  where(["accounts.trial_expires_at <= ?", 7.days.from_now])
106
113
  end
@@ -109,6 +116,17 @@ module Saucy
109
116
  where(["accounts.created_at <= ?", 7.days.ago]).
110
117
  where(:asked_to_activate => false, :activated => false)
111
118
  end
119
+
120
+ def trial_completed
121
+ trial.
122
+ where(:notified_of_completed_trial => false).
123
+ where(["accounts.trial_expires_at <= ?", Time.now])
124
+ end
125
+
126
+ def trial
127
+ includes(:plan).
128
+ where(:plans => { :trial => true })
129
+ end
112
130
  end
113
131
  end
114
132
  end
@@ -14,9 +14,15 @@ namespace :saucy do
14
14
  Account.deliver_expiring_trial_notifications
15
15
  end
16
16
 
17
+ desc "Deliver notifications to users with completed trial accounts"
18
+ task :deliver_completed_trial_notifications => :environment do
19
+ Account.deliver_completed_trial_notifications
20
+ end
21
+
17
22
  desc "Run all daily tasks"
18
23
  task :daily => [:update_subscriptions,
19
24
  :ask_users_to_activate,
20
- :deliver_expiring_trial_notifications]
25
+ :deliver_expiring_trial_notifications,
26
+ :deliver_completed_trial_notifications]
21
27
  end
22
28
 
@@ -162,6 +162,37 @@ describe Account do
162
162
  expiring.each { |account| account.reload.should be_notified_of_expiration }
163
163
  end
164
164
 
165
+ it "sends notifications for completed trials" do
166
+ trial = Factory(:plan, :trial => true)
167
+ forever = Factory(:plan, :trial => false)
168
+
169
+ unexpired_trial = Factory(:account, :plan => trial, :created_at => 29.days.ago)
170
+ unnotified_expired_trial = Factory(:account, :plan => trial, :created_at => 31.days.ago)
171
+ expiring_now = Factory(:account, :plan => trial, :created_at => 1.day.ago)
172
+ notified_expired_trial = Factory(:account, :plan => trial,
173
+ :created_at => 31.days.ago,
174
+ :notified_of_completed_trial => true)
175
+ forever = Factory(:account, :plan => forever, :created_at => 31.days.ago)
176
+
177
+ expiring_now.trial_expires_at = 1.day.ago
178
+ expiring_now.save!
179
+
180
+ requires_notification = [unnotified_expired_trial, expiring_now]
181
+
182
+ mail = stub('mail', :deliver => true)
183
+ BillingMailer.stubs(:completed_trial => mail)
184
+
185
+ Account.deliver_completed_trial_notifications
186
+
187
+ requires_notification.each do |account|
188
+ BillingMailer.should have_received(:completed_trial).with(account)
189
+ end
190
+
191
+ mail.should have_received(:deliver).twice
192
+
193
+ requires_notification.each { |account| account.reload.should be_notified_of_completed_trial }
194
+ end
195
+
165
196
  it "sends notifications for unactivated accounts after 7 days" do
166
197
  unactivated = [Factory(:account, :created_at => 7.days.ago),
167
198
  Factory(:account, :created_at => 8.days.ago)]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saucy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 7
9
- - 3
10
- version: 0.7.3
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - thoughtbot, inc.
@@ -169,6 +169,7 @@ files:
169
169
  - app/views/accounts/edit.html.erb
170
170
  - app/views/accounts/index.html.erb
171
171
  - app/views/accounts/new.html.erb
172
+ - app/views/billing_mailer/completed_trial.text.erb
172
173
  - app/views/billing_mailer/expiring_trial.text.erb
173
174
  - app/views/billing_mailer/new_unactivated.text.erb
174
175
  - app/views/billing_mailer/problem.html.erb