Skip to content

Commit

Permalink
fixed failing tests which were caused by bad couter defn in spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Wiger committed May 23, 2011
1 parent 6c8e9ae commit e42dd15
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/redis/objects.rb
Expand Up @@ -91,15 +91,15 @@ def redis_prefix(klass = self) #:nodoc:

def redis_field_key(name, id=nil) #:nodoc:
klass = first_ancestor_with(name)
# This can never ever ever ever change or upgrades will corrupt all data
# to comment above: I don't think people where using Proc as keys before (that would create a weird key). Should be ok
# READ THIS: This can never ever ever ever change or upgrades will corrupt all data
# I don't think people were using Proc as keys before (that would create a weird key). Should be ok
key = klass.redis_objects[name.to_sym][:key]
if key && key.respond_to?(:call)
key = key.call self
end
if id.nil? and !klass.redis_objects[name.to_sym][:global]
raise NilObjectId,
"Attempt to address redis-object :#{name} on class #{klass.name} with nil id (unsaved record?) [object_id=#{object_id}]"
"[#{klass.redis_objects[name.to_sym]}] Attempt to address redis-object :#{name} on class #{klass.name} with nil id (unsaved record?) [object_id=#{object_id}]"
end
key || "#{redis_prefix(klass)}:#{id}:#{name}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/redis/objects/counters.rb
Expand Up @@ -83,7 +83,7 @@ def reset_counter(name, id=nil, to=nil)
private

def verify_counter_defined!(name, id) #:nodoc:
raise Redis::Objects::UndefinedCounter, "Undefined counter :#{name} for class #{self.name}" unless counter_defined?(name)
raise NoMethodError, "Undefined counter :#{name} for class #{self.name}" unless counter_defined?(name)
if id.nil? and !@redis_objects[name][:global]
raise Redis::Objects::MissingID, "Missing ID for non-global counter #{self.name}##{name}"
end
Expand Down
5 changes: 3 additions & 2 deletions spec/redis_objects_active_record_spec.rb
Expand Up @@ -29,8 +29,8 @@ class Blog < ActiveRecord::Base
include Redis::Objects
has_many :posts
def before_create
#self.posts_count ||= 0
#self.posts_count += 1
self.posts_count ||= 0
self.posts_count += 1
end
end

Expand Down Expand Up @@ -98,6 +98,7 @@ class Post < ActiveRecord::Base
Post.create :blog => blog2
blog.reload.posts_count.should == 1
blog2.reload.posts_count.should == 2
blog.posts_count.should == 1
end
end

Expand Down
5 changes: 2 additions & 3 deletions spec/redis_objects_model_spec.rb
Expand Up @@ -18,13 +18,12 @@ class Roster

# global class counters
counter :total_players_online, :global => true
list :all_player_stats, :global => true
set :all_players_online, :global => true
value :last_player, :global => true

# custom keys
counter :player_totals, :key => 'players/#{username}/total'
list :all_player_stats, :key => 'players:all_stats'
list :all_player_stats, :key => 'players:all_stats', :global => true
set :total_wins, :key => 'players:#{id}:all_stats'
value :my_rank, :key => 'players:my_rank:#{username}'
value :weird_key, :key => 'players:weird_key:#{raise}', :global => true
Expand Down Expand Up @@ -340,7 +339,7 @@ class CustomMethodRoster < MethodRoster
Roster.increment_counter(:badness, 2)
rescue => error
end
error.should.be.kind_of(Redis::Objects::UndefinedCounter)
error.should.be.kind_of(NoMethodError)

error = nil
begin
Expand Down

0 comments on commit e42dd15

Please sign in to comment.