Permalink
Browse files

rvmrc and test tweak

  • Loading branch information...
1 parent 70292af commit 4245de8d8cb844607b7867f7cc9998ae693a505b @mrb committed Oct 28, 2010
Showing with 15 additions and 12 deletions.
  1. +1 −0 .rvmrc
  2. +9 −10 lib/achievements.rb
  3. +5 −2 test/achievements_test.rb
View
1 .rvmrc
@@ -0,0 +1 @@
+rvm 1.8.7
View
19 lib/achievements.rb
@@ -98,7 +98,8 @@ class Engine
def initialize(contexts)
connect if @redis.nil?
@contexts = contexts
- @achievements = @contexts.collect{|c| {c=>[]}}
+ @achievements = {}
+ @contexts.collect{|c| @achievements[c] = []}
end
def connect
@@ -126,7 +127,7 @@ def trigger(context, agent_id, name)
counter = Counter.new(context,agent_id,name)
result = incr counter
# Check Threshold
- if result > @redis.get("#{context}:#{name}")
+ if result > (@redis.get("#{context}:#{name}") || 0)
achieved << [context,name]
return achieved
else
@@ -149,14 +150,7 @@ def deactiveate(counter)
end
## Class Methods
- def self.find_achievement(name)
- results = @achievements.delete_if{|achievement| achievement.name != name}
- if result = results.uniq[0]
- result
- else
- nil
- end
- end
+
end
@@ -171,6 +165,11 @@ def initialize(context, name, threshold)
@threshold = threshold
@context = context
end
+
+ def to_hash
+ {:name => @name, :threshold => @threshold, :context => @context}
+ end
+
end
# Counter class is really a Redis key factory. Responsibility of
View
7 test/achievements_test.rb
@@ -39,8 +39,11 @@ class Item
end
test "achievement instantiation" do
- assert_equal User.engine.achievements, [{:context1 => [:one_time]},
- {:context2 => [:three_times]}]
+
+ end
+
+ test "binding achievement should create key value pair with name, context, threshold" do
+ assert_equal User.redis.get("")
end
test "first time trigger should create two counters and increment both" do

0 comments on commit 4245de8

Please sign in to comment.