saucy 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/limit.rb +16 -0
- data/app/views/plans/_plan.html.erb +15 -1
- data/app/views/plans/edit.html.erb +1 -1
- data/app/views/plans/index.html.erb +7 -3
- data/lib/generators/saucy/features/templates/features/manage_billing.feature +3 -90
- data/lib/generators/saucy/features/templates/features/manage_plan.feature +99 -0
- data/lib/saucy/account_authorization.rb +9 -1
- data/lib/saucy/plan.rb +3 -3
- data/spec/models/limit_spec.rb +26 -0
- metadata +5 -4
data/app/models/limit.rb
CHANGED
@@ -2,4 +2,20 @@ class Limit < ActiveRecord::Base
|
|
2
2
|
belongs_to :plan
|
3
3
|
|
4
4
|
validates_presence_of :name, :value
|
5
|
+
|
6
|
+
def self.numbered
|
7
|
+
where(:value_type => :number)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.boolean
|
11
|
+
where(:value_type => :boolean)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.named(name)
|
15
|
+
where(:name => name).first
|
16
|
+
end
|
17
|
+
|
18
|
+
def allowed?
|
19
|
+
value != 0
|
20
|
+
end
|
5
21
|
end
|
@@ -1,2 +1,16 @@
|
|
1
|
-
<p class="name"><%= plan.name %></p>
|
1
|
+
<p class="name"><%= link_to_unless current_account?, plan.name, new_plan_account_path(plan) %></p>
|
2
2
|
<p class="price"><% if plan.billed? %>$<%= plan.price %>/month<% else %>Free<% end %></p>
|
3
|
+
<ul class="features">
|
4
|
+
<% plan.limits.numbered.each do |limit| %>
|
5
|
+
<%= content_tag_for :li, limit, :class => limit.name do %>
|
6
|
+
<%= pluralize(limit.value, limit.name.singularize) %>
|
7
|
+
<% end %>
|
8
|
+
<% end %>
|
9
|
+
<% plan.limits.boolean.each do |limit| %>
|
10
|
+
<% if limit.allowed? -%>
|
11
|
+
<%= content_tag_for :li, limit, :class => limit.name do %>
|
12
|
+
<%= limit.name %>
|
13
|
+
<% end %>
|
14
|
+
<% end -%>
|
15
|
+
<% end %>
|
16
|
+
</ul>
|
@@ -5,7 +5,7 @@
|
|
5
5
|
<%= semantic_form_for @account, :url => account_plan_path(@account) do |form| %>
|
6
6
|
<%= form.inputs :class => "radio optional" do %>
|
7
7
|
<% @plans.each do |plan| -%>
|
8
|
-
<%=
|
8
|
+
<%= content_tag_for :li, plan, :class => "#{plan.name.parameterize} #{'disabled' if !@account.can_change_plan_to?(plan)}" do %>
|
9
9
|
<%= form.label :plan_id, render(plan), :value => plan.id %>
|
10
10
|
<%= form.radio_button :plan_id, plan.id, :disabled => !@account.can_change_plan_to?(plan) %>
|
11
11
|
<% end %>
|
@@ -1,7 +1,7 @@
|
|
1
|
-
Feature: Manage
|
1
|
+
Feature: Manage Billing
|
2
2
|
As a admin user
|
3
|
-
I want to be able to manage
|
4
|
-
|
3
|
+
I want to be able to manage my billing information
|
4
|
+
So that my account can stay up to date and in good standing
|
5
5
|
|
6
6
|
Scenario: Update the billing information on an account with a paid plan
|
7
7
|
Given a paid plan exists with a name of "Paid"
|
@@ -30,90 +30,3 @@ Feature: Manage Projects
|
|
30
30
|
And I press "Update"
|
31
31
|
Then I should see "updated successfully"
|
32
32
|
Then I should see "card ending in 1111"
|
33
|
-
|
34
|
-
Scenario: Change the plan to another paid plan on an account with a paid plan
|
35
|
-
Given a paid plan exists with a name of "Basic"
|
36
|
-
And a paid plan exists with a name of "Premium"
|
37
|
-
And the following account exists:
|
38
|
-
| name | keyword | plan | cardholder_name | billing_email | card_number | verification_code | expiration_month | expiration_year |
|
39
|
-
| Test | test | name: Basic | Joe Smith | jsmith@example.com | 4111111111115555 | 122 | 01 | 2015 |
|
40
|
-
And I have signed in with "joe@example.com/test"
|
41
|
-
And "joe@example.com" is an admin of the "Test" account
|
42
|
-
When I go to the settings page for the "Test" account
|
43
|
-
Then I should see "Your Plan"
|
44
|
-
And I should not see "Billing Information"
|
45
|
-
And I should see "Basic"
|
46
|
-
And I follow "Upgrade"
|
47
|
-
Then I should see "Upgrade Your Plan"
|
48
|
-
When I choose the "Premium" plan
|
49
|
-
And I press "Upgrade"
|
50
|
-
Then I should see "Plan changed successfully"
|
51
|
-
Then I should see "Premium"
|
52
|
-
|
53
|
-
Scenario: Change the plan from free to paid
|
54
|
-
Given a plan exists with a name of "Free"
|
55
|
-
And a paid plan exists with a name of "Basic"
|
56
|
-
And the following account exists:
|
57
|
-
| name | keyword | plan |
|
58
|
-
| Test | test | name: Free |
|
59
|
-
And I have signed in with "joe@example.com/test"
|
60
|
-
And "joe@example.com" is an admin of the "Test" account
|
61
|
-
When I go to the settings page for the "Test" account
|
62
|
-
Then I should not see "Billing" within ".tabs"
|
63
|
-
Then I should see "Your Plan"
|
64
|
-
And I follow "Upgrade"
|
65
|
-
Then I should see "Upgrade Your Plan"
|
66
|
-
When I choose the "Basic" plan
|
67
|
-
Then I should see "Billing Information"
|
68
|
-
And I fill in "Cardholder name" with "Ralph Robot"
|
69
|
-
And I fill in "Billing email" with "accounting@example.com"
|
70
|
-
And I fill in "Card number" with "4111111111111111"
|
71
|
-
And I fill in "Verification code" with "123"
|
72
|
-
And I select "March" from "Expiration month"
|
73
|
-
And I select "2020" from "Expiration year"
|
74
|
-
When I press "Upgrade"
|
75
|
-
Then I should see "Plan changed successfully"
|
76
|
-
And I should see "Basic"
|
77
|
-
And I follow "Billing"
|
78
|
-
Then I should see "card ending in 1111"
|
79
|
-
|
80
|
-
Scenario: Change the plan to a free on an account with a paid plan
|
81
|
-
Given a paid plan exists with a name of "Basic"
|
82
|
-
And a plan exists with a name of "Free"
|
83
|
-
And the following account exists:
|
84
|
-
| name | keyword | plan | cardholder_name | billing_email | card_number | verification_code | expiration_month | expiration_year |
|
85
|
-
| Test | test | name: Basic | Joe Smith | jsmith@example.com | 4111111111115555 | 122 | 01 | 2015 |
|
86
|
-
And I have signed in with "joe@example.com/test"
|
87
|
-
And "joe@example.com" is an admin of the "Test" account
|
88
|
-
When I go to the settings page for the "Test" account
|
89
|
-
Then I should see "Your Plan"
|
90
|
-
And I should not see "Billing Information"
|
91
|
-
And I should see "Basic"
|
92
|
-
And I follow "Upgrade"
|
93
|
-
Then I should see "Upgrade Your Plan"
|
94
|
-
When I choose the "Free" plan
|
95
|
-
And I press "Upgrade"
|
96
|
-
Then I should see "Plan changed successfully"
|
97
|
-
Then I should see "Free"
|
98
|
-
|
99
|
-
Scenario: Attempting to downgrade when beyond the limits
|
100
|
-
Given a paid plan exists with a name of "Basic"
|
101
|
-
And a plan exists with a name of "Free"
|
102
|
-
And the following account exists:
|
103
|
-
| name | keyword | plan | cardholder_name | billing_email | card_number | verification_code | expiration_month | expiration_year |
|
104
|
-
| Test | test | name: Basic | Joe Smith | jsmith@example.com | 4111111111115555 | 122 | 01 | 2015 |
|
105
|
-
And the following limits exist:
|
106
|
-
| plan | name | value |
|
107
|
-
| name: Basic | users | 1 |
|
108
|
-
| name: Free | users | 0 |
|
109
|
-
| name: Basic | projects | 5 |
|
110
|
-
| name: Free | projects | 1 |
|
111
|
-
And I have signed in with "joe@example.com/test"
|
112
|
-
And "joe@example.com" is an admin of the "Test" account
|
113
|
-
When I go to the settings page for the "Test" account
|
114
|
-
Then I should see "Your Plan"
|
115
|
-
And I should not see "Billing Information"
|
116
|
-
And I should see "Basic"
|
117
|
-
And I follow "Upgrade"
|
118
|
-
Then I should see "Upgrade Your Plan"
|
119
|
-
And the "Free" plan should be disabled
|
@@ -0,0 +1,99 @@
|
|
1
|
+
Feature: Manage Plan
|
2
|
+
As a admin user
|
3
|
+
I want to be able to upgrade and downgrade my account
|
4
|
+
So that I can pay what I want and get the features I want
|
5
|
+
|
6
|
+
Scenario: Change the plan to another paid plan on an account with a paid plan
|
7
|
+
Given a paid plan exists with a name of "Basic"
|
8
|
+
And a paid plan exists with a name of "Premium"
|
9
|
+
And the following account exists:
|
10
|
+
| name | keyword | plan | cardholder_name | billing_email | card_number | verification_code | expiration_month | expiration_year |
|
11
|
+
| Test | test | name: Basic | Joe Smith | jsmith@example.com | 4111111111115555 | 122 | 01 | 2015 |
|
12
|
+
And I have signed in with "joe@example.com/test"
|
13
|
+
And "joe@example.com" is an admin of the "Test" account
|
14
|
+
When I go to the settings page for the "Test" account
|
15
|
+
Then I should see "Your Plan"
|
16
|
+
And I should not see "Billing Information"
|
17
|
+
And I should see "Basic"
|
18
|
+
And I follow "Upgrade"
|
19
|
+
Then I should see "Upgrade Your Plan"
|
20
|
+
When I choose the "Premium" plan
|
21
|
+
And I press "Upgrade"
|
22
|
+
Then I should see "Plan changed successfully"
|
23
|
+
Then I should see "Premium"
|
24
|
+
|
25
|
+
Scenario: Change the plan from free to paid
|
26
|
+
Given a plan exists with a name of "Free"
|
27
|
+
And a paid plan exists with a name of "Basic"
|
28
|
+
And the following account exists:
|
29
|
+
| name | keyword | plan |
|
30
|
+
| Test | test | name: Free |
|
31
|
+
And I have signed in with "joe@example.com/test"
|
32
|
+
And "joe@example.com" is an admin of the "Test" account
|
33
|
+
When I go to the settings page for the "Test" account
|
34
|
+
Then I should not see "Billing" within ".tabs"
|
35
|
+
Then I should see "Your Plan"
|
36
|
+
And I follow "Upgrade"
|
37
|
+
Then I should see "Upgrade Your Plan"
|
38
|
+
When I choose the "Basic" plan
|
39
|
+
Then I should see "Billing Information"
|
40
|
+
And I fill in "Cardholder name" with "Ralph Robot"
|
41
|
+
And I fill in "Billing email" with "accounting@example.com"
|
42
|
+
And I fill in "Card number" with "4111111111111111"
|
43
|
+
And I fill in "Verification code" with "123"
|
44
|
+
And I select "March" from "Expiration month"
|
45
|
+
And I select "2020" from "Expiration year"
|
46
|
+
When I press "Upgrade"
|
47
|
+
Then I should see "Plan changed successfully"
|
48
|
+
And I should see "Basic"
|
49
|
+
And I follow "Billing"
|
50
|
+
Then I should see "card ending in 1111"
|
51
|
+
|
52
|
+
Scenario: Change the plan to a free on an account with a paid plan
|
53
|
+
Given a paid plan exists with a name of "Basic"
|
54
|
+
And a plan exists with a name of "Free"
|
55
|
+
And the following account exists:
|
56
|
+
| name | keyword | plan | cardholder_name | billing_email | card_number | verification_code | expiration_month | expiration_year |
|
57
|
+
| Test | test | name: Basic | Joe Smith | jsmith@example.com | 4111111111115555 | 122 | 01 | 2015 |
|
58
|
+
And I have signed in with "joe@example.com/test"
|
59
|
+
And "joe@example.com" is an admin of the "Test" account
|
60
|
+
When I go to the settings page for the "Test" account
|
61
|
+
Then I should see "Your Plan"
|
62
|
+
And I should not see "Billing Information"
|
63
|
+
And I should see "Basic"
|
64
|
+
And I follow "Upgrade"
|
65
|
+
Then I should see "Upgrade Your Plan"
|
66
|
+
When I choose the "Free" plan
|
67
|
+
And I press "Upgrade"
|
68
|
+
Then I should see "Plan changed successfully"
|
69
|
+
Then I should see "Free"
|
70
|
+
|
71
|
+
Scenario: Attempting to downgrade when beyond the limits
|
72
|
+
Given a paid plan exists with a name of "Basic"
|
73
|
+
And a plan exists with a name of "Free"
|
74
|
+
And the following account exists:
|
75
|
+
| name | keyword | plan | cardholder_name | billing_email | card_number | verification_code | expiration_month | expiration_year |
|
76
|
+
| Test | test | name: Basic | Joe Smith | jsmith@example.com | 4111111111115555 | 122 | 01 | 2015 |
|
77
|
+
And the following limits exist:
|
78
|
+
| plan | name | value | value_type |
|
79
|
+
| name: Basic | users | 1 | number |
|
80
|
+
| name: Free | users | 0 | number |
|
81
|
+
| name: Basic | projects | 5 | number |
|
82
|
+
| name: Free | projects | 1 | number |
|
83
|
+
| name: Basic | ssl | 1 | boolean |
|
84
|
+
| name: Free | ssl | 0 | boolean |
|
85
|
+
And I have signed in with "joe@example.com/test"
|
86
|
+
And "joe@example.com" is an admin of the "Test" account
|
87
|
+
When I go to the settings page for the "Test" account
|
88
|
+
Then I should see "Your Plan"
|
89
|
+
And I should not see "Billing Information"
|
90
|
+
And I should see "Basic"
|
91
|
+
And I follow "Upgrade"
|
92
|
+
Then I should see "Upgrade Your Plan"
|
93
|
+
And the "Free" plan should be disabled
|
94
|
+
And I should see "1 user" within ".basic"
|
95
|
+
And I should see "0 users" within ".free"
|
96
|
+
And I should see "1 project" within ".free"
|
97
|
+
And I should see "5 projects" within ".basic"
|
98
|
+
And I should see "ssl" within ".basic"
|
99
|
+
And I should not see "ssl" within ".free"
|
@@ -3,7 +3,7 @@ module Saucy
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
helper_method :current_account, :current_project
|
6
|
+
helper_method :current_account, :current_project, :current_account?, :current_project?
|
7
7
|
include InstanceMethods
|
8
8
|
end
|
9
9
|
|
@@ -18,6 +18,14 @@ module Saucy
|
|
18
18
|
::Project.find_by_keyword!(params[:project_id])
|
19
19
|
end
|
20
20
|
|
21
|
+
def current_project?
|
22
|
+
params[:project_id].present?
|
23
|
+
end
|
24
|
+
|
25
|
+
def current_account?
|
26
|
+
params[:account_id].present?
|
27
|
+
end
|
28
|
+
|
21
29
|
def authorize_admin
|
22
30
|
unless current_user.admin_of?(current_account)
|
23
31
|
deny_access("You must be an admin to access that page.")
|
data/lib/saucy/plan.rb
CHANGED
@@ -19,15 +19,15 @@ module Saucy
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def can_add_more?(limit, amount)
|
22
|
-
limits.
|
22
|
+
limits.numbered.named(limit).value > amount
|
23
23
|
end
|
24
24
|
|
25
25
|
def allows?(limit)
|
26
|
-
limits.
|
26
|
+
limits.boolean.named(limit).allowed?
|
27
27
|
end
|
28
28
|
|
29
29
|
def limit(limit_name)
|
30
|
-
limits.
|
30
|
+
limits.named(limit_name)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
data/spec/models/limit_spec.rb
CHANGED
@@ -7,3 +7,29 @@ describe Limit do
|
|
7
7
|
it { should validate_presence_of(:name) }
|
8
8
|
it { should validate_presence_of(:value) }
|
9
9
|
end
|
10
|
+
|
11
|
+
describe Limit, "various kinds" do
|
12
|
+
let!(:users) { Factory(:limit, :name => "users", :value => 1) }
|
13
|
+
let!(:ssl) { Factory(:limit, :name => "ssl", :value => 0, :value_type => :boolean) }
|
14
|
+
let!(:lighthouse) { Factory(:limit, :name => "lighthouse", :value => 1, :value_type => :boolean) }
|
15
|
+
|
16
|
+
it "gives the numbered limits" do
|
17
|
+
Limit.numbered.should == [users]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "gives the boolean limits" do
|
21
|
+
Limit.boolean.should == [ssl, lighthouse]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "gives the limits by name" do
|
25
|
+
Limit.named(:users).should == users
|
26
|
+
end
|
27
|
+
|
28
|
+
it "reports true for booleans with 1" do
|
29
|
+
lighthouse.allowed?.should be
|
30
|
+
end
|
31
|
+
|
32
|
+
it "reports false for booleans with 0" do
|
33
|
+
ssl.allowed?.should_not be
|
34
|
+
end
|
35
|
+
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: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- thoughtbot, inc.
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-01-
|
20
|
+
date: 2011-01-09 00:00:00 -05:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -211,6 +211,7 @@ files:
|
|
211
211
|
- lib/generators/saucy/features/templates/features/edit_user_permissions.feature
|
212
212
|
- lib/generators/saucy/features/templates/features/manage_account.feature
|
213
213
|
- lib/generators/saucy/features/templates/features/manage_billing.feature
|
214
|
+
- lib/generators/saucy/features/templates/features/manage_plan.feature
|
214
215
|
- lib/generators/saucy/features/templates/features/manage_projects.feature
|
215
216
|
- lib/generators/saucy/features/templates/features/manage_users.feature
|
216
217
|
- lib/generators/saucy/features/templates/features/new_account.feature
|