Skip to content

Commit

Permalink
fixed the :with bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Adkisson committed Apr 29, 2010
1 parent 9722dec commit c62cc4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 10 additions & 7 deletions lib/modesty/metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,22 @@ def track!(count=1, options={})
end

with = options[:with] || {}
with = Hash[with.map do |k,v|
plural_with = Hash[with.map do |k,v|
[k.to_s.pluralize.to_sym, v]
end]

with[:users] ||= Modesty.identity if Modesty.identity
plural_with[:users] ||= Modesty.identity if Modesty.identity
self.experiments.each do |exp|
# only track the for the experiment group if
# the user has previously hit the experiment
identity_slug = exp.identity_for(self)
identity = if identity_slug
i = with[identity_slug]
i = plural_with[identity_slug]
raise IdentityError, """
#TODO
#{exp.inspect} requires #{self.inspect} to be tracked
with #{identity_slug.to_s.singularize.to_sym.inspect}.
It was tracked :with => #{with.inspect}
""".squish unless i
i
else
Expand All @@ -136,13 +139,13 @@ def track!(count=1, options={})
if identity
alt = exp.data.get_cached_alternative(identity)
if alt
(self/(exp.slug/alt)).data.track!(count, with)
(self/(exp.slug/alt)).data.track!(count, plural_with)
end
end
end

self.data.track!(count, with)
@parent.track!(count, with) if @parent
self.data.track!(count, plural_with)
@parent.track!(count, :with => with) if @parent
end

def /(sym)
Expand Down
6 changes: 4 additions & 2 deletions spec/identity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
Modesty.metrics.clear
Modesty.data.flushdb

Modesty.new_metric :donation_amount
Modesty.new_metric :donation_amount do |m|
m.submetric :birthday_wish
end
Modesty.new_metric :donation
Modesty.new_metric :creation

Expand Down Expand Up @@ -96,7 +98,7 @@

# user 500, who is in the experiment group, donates $30 to user 700's wish
Modesty.with_identity 500 do
Modesty.track! :donation_amount, 30, :with => {:creator => 700}
Modesty.track! :donation_amount/:birthday_wish, 30, :with => {:creator => 700}
end

# a guest donates $15 to user 700's wish
Expand Down

0 comments on commit c62cc4b

Please sign in to comment.