saucy 0.3.2 → 0.3.3

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/README.md CHANGED
@@ -90,6 +90,11 @@ To extend the ProjectsController:
90
90
  end
91
91
  end
92
92
 
93
+ To define additional limit meters, or override existing limit meters, create the
94
+ partials:
95
+
96
+ app/views/limits/_#{limitname}_meter.html.erb
97
+
93
98
  ## Gotchas
94
99
 
95
100
  Make sure you don't do this in ApplicationController:
@@ -0,0 +1,13 @@
1
+ module LimitsHelper
2
+ def current_percentage(limit, account)
3
+ number_to_percentage((limit.current_count(account).to_f / limit.value) * 100)
4
+ end
5
+
6
+ def render_limit_meter(limit)
7
+ if FileTest.exist?(File.join(Rails.root, 'app', 'views', 'limits' , "_#{limit.name}_meter.html.erb"))
8
+ render "limits/#{limit.name}_meter", :limit => limit
9
+ else
10
+ render "limits/meter", :limit => limit
11
+ end
12
+ end
13
+ end
@@ -36,10 +36,14 @@ class Limit < ActiveRecord::Base
36
36
  end
37
37
 
38
38
  def within?(account)
39
- account.send(:"#{name}_count") <= value
39
+ current_count(account) <= value
40
40
  end
41
41
 
42
42
  def can_add_one?(account)
43
- (account.send(:"#{name}_count") + 1) <= value
43
+ (current_count(account) + 1) <= value
44
+ end
45
+
46
+ def current_count(account)
47
+ account.send(:"#{name}_count")
44
48
  end
45
49
  end
@@ -8,6 +8,10 @@
8
8
  <h3>Your Plan</h3>
9
9
  <%= render @account.plan %>
10
10
  <%= link_to "Upgrade", edit_account_plan_path(current_account), :id => "upgrade-account" %>
11
+
12
+ <% @account.plan.limits.numbered.each do |limit| -%>
13
+ <%= render_limit_meter(limit) %>
14
+ <% end -%>
11
15
  </div>
12
16
 
13
17
  <%= content_tag_for :div, @account do -%>
@@ -0,0 +1,13 @@
1
+ <%= content_tag_for :div, limit, :class => "#{limit.name} meter" do %>
2
+ <span class="numbers">
3
+ <em><%= limit.current_count(current_account) %></em><span>/<%= limit.value %></span>
4
+ </span>
5
+ <span class="label">
6
+ <%= limit.name %>
7
+ </span>
8
+ <div class="bar">
9
+ <span style="width: <%= current_percentage(limit, current_account) %>;">
10
+ <%= current_percentage(limit, current_account) %>
11
+ </span>
12
+ </div>
13
+ <% end %>
@@ -123,3 +123,21 @@ Feature: Manage Plan
123
123
  And I should see "5 projects" within ".basic"
124
124
  And I should see "ssl" within ".basic"
125
125
  And I should not see "ssl" within ".free"
126
+
127
+ Scenario: Viewing current usage
128
+ Given a paid plan exists with a name of "Basic"
129
+ And the following account exists:
130
+ | name | keyword | plan | cardholder_name | billing_email | card_number | verification_code | expiration_month | expiration_year |
131
+ | Test | test | name: Basic | Joe Smith | jsmith@example.com | 4111111111115555 | 122 | 01 | 2015 |
132
+ And the following limits exist:
133
+ | plan | name | value | value_type |
134
+ | name: Basic | users | 1 | number |
135
+ | name: Basic | projects | 5 | number |
136
+ | name: Basic | ssl | 1 | boolean |
137
+ And I have signed in with "joe@example.com/test"
138
+ And "joe@example.com" is an admin of the "Test" account
139
+ When I go to the settings page for the "Test" account
140
+ Then I should see "1/1" within ".users.meter"
141
+ And I should see "100.000%" within ".users.meter"
142
+ And I should see "0/5" within ".projects.meter"
143
+ And I should see "0.000%" within ".projects.meter"
@@ -81,7 +81,7 @@ class CreateSaucyTables < ActiveRecord::Migration
81
81
  create_table :limits do |t|
82
82
  t.belongs_to :plan
83
83
  t.string :name
84
- t.integer :value, :null => false, :default => 0
84
+ t.column :value, 'BIGINT UNSIGNED', :null => false, :default => 0
85
85
  t.string :value_type, :null => false, :default => "number"
86
86
 
87
87
  t.timestamps
@@ -19,6 +19,9 @@ module Saucy
19
19
  :expiration_year]
20
20
  end
21
21
 
22
+ initializer 'limits.helper' do |app|
23
+ ActionView::Base.send :include, LimitsHelper
24
+ end
22
25
 
23
26
  {:short_date => "%x"}.each do |k, v|
24
27
  Time::DATE_FORMATS[k] = v
@@ -45,6 +45,11 @@ describe Limit, "with account and limits" do
45
45
  subject.within?(@account)
46
46
  end
47
47
 
48
+ it "gives the current count for the account of the limit" do
49
+ @account.stubs(:users_count => 99)
50
+ subject.current_count(@account).should == 99
51
+ end
52
+
48
53
  it "can query whether the given account is below the specified limit" do
49
54
  Limit.within?("users", @account)
50
55
  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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 2
10
- version: 0.3.2
9
+ - 3
10
+ version: 0.3.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - thoughtbot, inc.
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2011-03-21 00:00:00 -04:00
21
+ date: 2011-03-22 00:00:00 -04:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -137,6 +137,7 @@ files:
137
137
  - app/controllers/memberships_controller.rb
138
138
  - app/controllers/plans_controller.rb
139
139
  - app/controllers/profiles_controller.rb
140
+ - app/helpers/limits_helper.rb
140
141
  - app/mailers/billing_mailer.rb
141
142
  - app/mailers/invitation_mailer.rb
142
143
  - app/models/invitation.rb
@@ -164,6 +165,7 @@ files:
164
165
  - app/views/invitations/new.html.erb
165
166
  - app/views/invitations/show.html.erb
166
167
  - app/views/layouts/saucy.html.erb
168
+ - app/views/limits/_meter.html.erb
167
169
  - app/views/memberships/edit.html.erb
168
170
  - app/views/memberships/index.html.erb
169
171
  - app/views/plans/_plan.html.erb