saucy 0.8.4 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/controllers/plans_controller.rb +19 -2
- data/spec/controllers/plans_controller_spec.rb +62 -4
- metadata +17 -17
@@ -13,12 +13,29 @@ class PlansController < ApplicationController
|
|
13
13
|
def update
|
14
14
|
@plans = Plan.ordered
|
15
15
|
@account = current_account
|
16
|
-
|
17
|
-
|
16
|
+
from_plan = @account.plan
|
17
|
+
|
18
18
|
if @account.save_customer_and_subscription!(params[:account])
|
19
|
+
to_plan = @account.plan
|
20
|
+
notify_observers_of_plan_change(from_plan, to_plan)
|
19
21
|
redirect_to edit_account_path(@account), :notice => t('.update.notice', :default => "Plan changed successfully")
|
20
22
|
else
|
21
23
|
render :edit
|
22
24
|
end
|
23
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def notify_observers_of_plan_change(from_plan, to_plan)
|
30
|
+
notify_observers("plan_upgraded", from_plan, to_plan) if from_plan.price < to_plan.price
|
31
|
+
notify_observers("plan_downgraded", from_plan, to_plan) if from_plan.price > to_plan.price
|
32
|
+
end
|
33
|
+
|
34
|
+
def notify_observers(event_name, from_plan, to_plan)
|
35
|
+
Saucy::Configuration.notify(event_name,
|
36
|
+
:account => @account,
|
37
|
+
:request => request,
|
38
|
+
:from_plan => from_plan,
|
39
|
+
:to_plan => to_plan)
|
40
|
+
end
|
24
41
|
end
|
@@ -1,13 +1,71 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe PlansController, "successful
|
3
|
+
describe PlansController, "successful upgrade", :as => :account_admin do
|
4
|
+
let!(:original_plan) { account.plan }
|
5
|
+
let!(:upgraded_plan) { Factory(:paid_plan) }
|
6
|
+
|
4
7
|
before do
|
5
8
|
Account.stubs(:find_by_keyword! => account)
|
6
|
-
|
7
|
-
|
9
|
+
new_account_attributes = Factory.attributes_for(:paid_account).merge({
|
10
|
+
:plan_id => upgraded_plan.id
|
11
|
+
})
|
12
|
+
put :update, :account_id => account.to_param, :account => new_account_attributes
|
8
13
|
end
|
9
14
|
|
10
15
|
it "notifies observers" do
|
11
|
-
should notify_observers("plan_upgraded", :account => account, :request => request)
|
16
|
+
should notify_observers("plan_upgraded", :account => account, :request => request, :from_plan => original_plan, :to_plan => upgraded_plan)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe PlansController, "successful downgrade", :as => :account_admin do
|
21
|
+
let!(:account) { Factory(:paid_account) }
|
22
|
+
let!(:original_plan) { account.plan }
|
23
|
+
let!(:downgraded_plan) { Factory(:plan) }
|
24
|
+
|
25
|
+
before do
|
26
|
+
Account.stubs(:find_by_keyword! => account)
|
27
|
+
new_account_attributes = Factory.attributes_for(:paid_account).merge({
|
28
|
+
:plan_id => downgraded_plan.id
|
29
|
+
})
|
30
|
+
put :update, :account_id => account.to_param, :account => new_account_attributes
|
31
|
+
end
|
32
|
+
|
33
|
+
it "notifies observers" do
|
34
|
+
should notify_observers("plan_downgraded", :account => account, :request => request, :from_plan => original_plan, :to_plan => downgraded_plan)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe PlansController, "unsuccessful update", :as => :account_admin do
|
39
|
+
let!(:original_plan) { account.plan }
|
40
|
+
let!(:upgraded_plan) { Factory(:paid_plan) }
|
41
|
+
|
42
|
+
before do
|
43
|
+
Account.stubs(:find_by_keyword! => account)
|
44
|
+
account.stubs(:save_customer_and_subscription! => false)
|
45
|
+
new_account_attributes = Factory.attributes_for(:paid_account).merge({
|
46
|
+
:plan_id => upgraded_plan.id
|
47
|
+
})
|
48
|
+
put :update, :account_id => account.to_param, :account => new_account_attributes
|
49
|
+
end
|
50
|
+
|
51
|
+
it "does not notify observers" do
|
52
|
+
should_not notify_observers("plan_upgraded", :account => account, :request => request, :from_plan => original_plan, :to_plan => upgraded_plan)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe PlansController, "successful update that does not change the plan", :as => :account_admin do
|
57
|
+
let!(:original_plan) { account.plan }
|
58
|
+
|
59
|
+
before do
|
60
|
+
Account.stubs(:find_by_keyword! => account)
|
61
|
+
new_account_attributes = Factory.attributes_for(:paid_account).merge({
|
62
|
+
:plan_id => original_plan.id
|
63
|
+
})
|
64
|
+
put :update, :account_id => account.to_param, :account => new_account_attributes
|
65
|
+
end
|
66
|
+
|
67
|
+
it "does not notify observers about upgrade or downgrade" do
|
68
|
+
should_not notify_observers("plan_upgraded", :account => account, :request => request, :from_plan => original_plan, :to_plan => original_plan)
|
69
|
+
should_not notify_observers("plan_downgraded", :account => account, :request => request, :from_plan => original_plan, :to_plan => original_plan)
|
12
70
|
end
|
13
71
|
end
|
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:
|
4
|
+
hash: 53
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 5
|
10
|
+
version: 0.8.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- thoughtbot, inc.
|
@@ -22,8 +22,8 @@ date: 2011-06-28 00:00:00 -04:00
|
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
|
-
name: clearance
|
26
25
|
prerelease: false
|
26
|
+
type: :runtime
|
27
27
|
requirement: &id001 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
@@ -35,11 +35,11 @@ dependencies:
|
|
35
35
|
- 11
|
36
36
|
- 0
|
37
37
|
version: 0.11.0
|
38
|
-
|
38
|
+
name: clearance
|
39
39
|
version_requirements: *id001
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
|
-
name: formtastic
|
42
41
|
prerelease: false
|
42
|
+
type: :runtime
|
43
43
|
requirement: &id002 !ruby/object:Gem::Requirement
|
44
44
|
none: false
|
45
45
|
requirements:
|
@@ -50,11 +50,11 @@ dependencies:
|
|
50
50
|
- 1
|
51
51
|
- 2
|
52
52
|
version: "1.2"
|
53
|
-
|
53
|
+
name: formtastic
|
54
54
|
version_requirements: *id002
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: railties
|
57
56
|
prerelease: false
|
57
|
+
type: :runtime
|
58
58
|
requirement: &id003 !ruby/object:Gem::Requirement
|
59
59
|
none: false
|
60
60
|
requirements:
|
@@ -66,11 +66,11 @@ dependencies:
|
|
66
66
|
- 0
|
67
67
|
- 3
|
68
68
|
version: 3.0.3
|
69
|
-
|
69
|
+
name: railties
|
70
70
|
version_requirements: *id003
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
|
-
name: braintree
|
73
72
|
prerelease: false
|
73
|
+
type: :runtime
|
74
74
|
requirement: &id004 !ruby/object:Gem::Requirement
|
75
75
|
none: false
|
76
76
|
requirements:
|
@@ -82,11 +82,11 @@ dependencies:
|
|
82
82
|
- 6
|
83
83
|
- 2
|
84
84
|
version: 2.6.2
|
85
|
-
|
85
|
+
name: braintree
|
86
86
|
version_requirements: *id004
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
|
-
name: sham_rack
|
89
88
|
prerelease: false
|
89
|
+
type: :runtime
|
90
90
|
requirement: &id005 !ruby/object:Gem::Requirement
|
91
91
|
none: false
|
92
92
|
requirements:
|
@@ -98,11 +98,11 @@ dependencies:
|
|
98
98
|
- 3
|
99
99
|
- 3
|
100
100
|
version: 1.3.3
|
101
|
-
|
101
|
+
name: sham_rack
|
102
102
|
version_requirements: *id005
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
|
-
name: sinatra
|
105
104
|
prerelease: false
|
105
|
+
type: :runtime
|
106
106
|
requirement: &id006 !ruby/object:Gem::Requirement
|
107
107
|
none: false
|
108
108
|
requirements:
|
@@ -114,11 +114,11 @@ dependencies:
|
|
114
114
|
- 1
|
115
115
|
- 2
|
116
116
|
version: 1.1.2
|
117
|
-
|
117
|
+
name: sinatra
|
118
118
|
version_requirements: *id006
|
119
119
|
- !ruby/object:Gem::Dependency
|
120
|
-
name: aruba
|
121
120
|
prerelease: false
|
121
|
+
type: :development
|
122
122
|
requirement: &id007 !ruby/object:Gem::Requirement
|
123
123
|
none: false
|
124
124
|
requirements:
|
@@ -130,7 +130,7 @@ dependencies:
|
|
130
130
|
- 2
|
131
131
|
- 6
|
132
132
|
version: 0.2.6
|
133
|
-
|
133
|
+
name: aruba
|
134
134
|
version_requirements: *id007
|
135
135
|
description: Clearance-based Rails engine for Software as a Service (Saas) that provides account and project management
|
136
136
|
email: support@thoughtbot.com
|