gamifier 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,15 +2,29 @@ require 'gamifier/model'
2
2
 
3
3
  module Gamifier
4
4
  class ActivityDefinition < Model
5
- def limit_per_day(times_per_day)
5
+
6
+ def limit(n_times, over_time)
6
7
  self.enable_rate_limiting = true
7
- self.bucket_max_capacity = times_per_day
8
- self.bucket_drain_rate = times_per_day/24.0
8
+ self.bucket_max_capacity = n_times
9
+ self.bucket_drain_rate = n_times.to_f / over_time.to_f
10
+ self
11
+ end
12
+
13
+ def limit_per_day(times_per_day)
14
+ limit(times_per_day, 24.0)
15
+ end
16
+
17
+ def limit_per_week(times_per_week)
18
+ limit(times_per_week, 24.0 * 7.0)
9
19
  end
10
20
 
11
21
  def limit_once_per_day
12
22
  limit_per_day 1
13
23
  end
14
24
 
25
+ def limit_once_per_week
26
+ limit_per_week 1
27
+ end
28
+
15
29
  end
16
- end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Gamifier
2
- VERSION = "1.0.6" unless defined?(Gamifier::VERSION)
2
+ VERSION = "1.0.7" unless defined?(Gamifier::VERSION)
3
3
  end
@@ -17,4 +17,4 @@ describe "managing collections" do
17
17
  ENGINE.activity_definitions.all(:site => "ibadgedyou.dev").length.should == 0
18
18
  end
19
19
 
20
- end
20
+ end
@@ -1,24 +1,59 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Gamifier::Player do
4
+
4
5
  before do
5
6
  @engine = mock(Gamifier::Engine)
6
7
  end
7
- describe "limit_per_day" do
8
- it "should set rate limits" do
9
- a = Gamifier::ActivityDefinition.new
10
8
 
11
- a.limit_per_day(1)
12
- a.attributes.should include({:enable_rate_limiting => true, :bucket_max_capacity => 1})
9
+ describe ".limit" do
10
+
11
+ subject { Gamifier::ActivityDefinition.new.limit(1, 24.0) }
12
+
13
+ it { subject.enable_rate_limiting.should be_true }
14
+ it { subject.bucket_max_capacity.should == 1 }
15
+ it { subject.bucket_drain_rate.should == 1 / 24.0 }
16
+
17
+ end
18
+
19
+ describe ".limit_per_day" do
20
+
21
+ subject { Gamifier::ActivityDefinition.new.limit_per_day(1) }
22
+
23
+ it { subject.enable_rate_limiting.should be_true }
24
+ it { subject.bucket_max_capacity.should == 1 }
25
+ it { subject.bucket_drain_rate.should == 1 / 24.0 }
26
+
27
+ end
28
+
29
+ describe ".limit_per_week" do
30
+
31
+ subject { Gamifier::ActivityDefinition.new.limit_per_week(1) }
32
+
33
+ it { subject.enable_rate_limiting.should be_true }
34
+ it { subject.bucket_max_capacity.should == 1 }
35
+ it { subject.bucket_drain_rate.should == 1 / (24.0 * 7.0) }
13
36
 
14
- end
15
37
  end
16
38
 
17
- describe "limit_once_per_day" do
18
- it "should set rate limits" do
19
- a = Gamifier::ActivityDefinition.new
20
- a.should_receive(:limit_per_day).with(1)
21
- a.limit_once_per_day
22
- end
39
+ describe ".limit_once_per_day" do
40
+
41
+ subject { Gamifier::ActivityDefinition.new.limit_once_per_day }
42
+
43
+ it { subject.enable_rate_limiting.should be_true }
44
+ it { subject.bucket_max_capacity.should == 1 }
45
+ it { subject.bucket_drain_rate.should == 1 / 24.0 }
46
+
23
47
  end
48
+
49
+ describe ".limit_once_per_week" do
50
+
51
+ subject { Gamifier::ActivityDefinition.new.limit_once_per_week }
52
+
53
+ it { subject.enable_rate_limiting.should be_true }
54
+ it { subject.bucket_max_capacity.should == 1 }
55
+ it { subject.bucket_drain_rate.should == 1 / (24.0 * 7.0) }
56
+
57
+ end
58
+
24
59
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamifier
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 6
10
- version: 1.0.6
9
+ - 7
10
+ version: 1.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Cyril Rohr
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-09-24 00:00:00 Z
18
+ date: 2012-09-26 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: faraday