Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

rvmrc and test tweak

  • Loading branch information...
commit 4245de8d8cb844607b7867f7cc9998ae693a505b 1 parent 70292af
Michael Bernstein authored

Showing 3 changed files with 15 additions and 12 deletions. Show diff stats Hide diff stats

  1. +1 0  .rvmrc
  2. +9 10 lib/achievements.rb
  3. +5 2 test/achievements_test.rb
1  .rvmrc
... ... @@ -0,0 +1 @@
  1 +rvm 1.8.7
19 lib/achievements.rb
@@ -98,7 +98,8 @@ class Engine
98 98 def initialize(contexts)
99 99 connect if @redis.nil?
100 100 @contexts = contexts
101   - @achievements = @contexts.collect{|c| {c=>[]}}
  101 + @achievements = {}
  102 + @contexts.collect{|c| @achievements[c] = []}
102 103 end
103 104
104 105 def connect
@@ -126,7 +127,7 @@ def trigger(context, agent_id, name)
126 127 counter = Counter.new(context,agent_id,name)
127 128 result = incr counter
128 129 # Check Threshold
129   - if result > @redis.get("#{context}:#{name}")
  130 + if result > (@redis.get("#{context}:#{name}") || 0)
130 131 achieved << [context,name]
131 132 return achieved
132 133 else
@@ -149,14 +150,7 @@ def deactiveate(counter)
149 150 end
150 151
151 152 ## Class Methods
152   - def self.find_achievement(name)
153   - results = @achievements.delete_if{|achievement| achievement.name != name}
154   - if result = results.uniq[0]
155   - result
156   - else
157   - nil
158   - end
159   - end
  153 +
160 154
161 155 end
162 156
@@ -171,6 +165,11 @@ def initialize(context, name, threshold)
171 165 @threshold = threshold
172 166 @context = context
173 167 end
  168 +
  169 + def to_hash
  170 + {:name => @name, :threshold => @threshold, :context => @context}
  171 + end
  172 +
174 173 end
175 174
176 175 # Counter class is really a Redis key factory. Responsibility of
7 test/achievements_test.rb
@@ -39,8 +39,11 @@ class Item
39 39 end
40 40
41 41 test "achievement instantiation" do
42   - assert_equal User.engine.achievements, [{:context1 => [:one_time]},
43   - {:context2 => [:three_times]}]
  42 +
  43 + end
  44 +
  45 + test "binding achievement should create key value pair with name, context, threshold" do
  46 + assert_equal User.redis.get("")
44 47 end
45 48
46 49 test "first time trigger should create two counters and increment both" do

0 comments on commit 4245de8

Please sign in to comment.
Something went wrong with that request. Please try again.