Skip to content

Commit

Permalink
Updated to fix specs and bump to mongoid 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshReedSchramm authored and j15e committed May 1, 2013
1 parent 90a83c4 commit 3a5ba1e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
23 changes: 23 additions & 0 deletions lib/mongoid/tracking/reader_extender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def to_f
@total.to_f
end

def to_i
@total.to_i
end

def ==(other)
@total == other
end
Expand All @@ -44,11 +48,30 @@ def <=>(other)
@total <=> other
end

def <(other)
@total < other
end
def <=(other)
@total <= other
end

def >(other)
@total > other
end

def >(other)
@total >= other
end

def +(other)
return @total + other unless other.is_a?(ReaderExtender)
self.class.new(other + @total, @hours.zip(other.hourly).map!(&:sum))
end

def coerce(other)
[self.to_i, other]
end

def as_json(options = nil)
@total
end
Expand Down
11 changes: 2 additions & 9 deletions spec/aggregates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class MockTest3
test_model.visits.referers.today.should =~ [["firefox", 1], ["chrome", 1]]

# Just for testing array manipulations
test_model.visits.browsers.today.inject(0) {|total, c| total + c.last }.should == 2
test_model.visits.browsers.today.inject(0) {|total, c| c.last + total }.should == 2
end

it "should return only values when specifying the aggregation key" do
Expand All @@ -287,13 +287,6 @@ class MockTest3
test_model.visits.today.should == 5
end

it "let's check what happens when sorting the best browser..." do
test_model.visits("Mozilla Firefox").inc
test_model.visits("Google Chrome").set(6)
test_model.visits.browsers.today.should =~ [["mozilla", 1], ["google", 6]]
test_model.visits.browsers.today.max {|a,b| a.second <=> b.second }.should == ["google", 6]
end

it "should work without aggregation information" do
test_model.visits("Mozilla Firefox").set(1)
test_model.visits("Google Chrome").set(6)
Expand All @@ -305,7 +298,7 @@ class MockTest3

# A more throughout test would check totals...
visits_today = test_model.visits.today
visits_today_with_browser = test_model.visits.browsers.today.inject(0) {|total, c| total + c.last }
visits_today_with_browser = test_model.visits.browsers.today.inject(0) {|total, c| c.last + total }
visits_today.should == visits_today_with_browser
end
end
Expand Down
2 changes: 1 addition & 1 deletion trackoid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }

s.add_dependency 'mongoid', '~> 3.0.5'
s.add_dependency 'mongoid', '~> 3.1'
s.add_dependency 'rake'
s.add_development_dependency 'rspec'
s.add_development_dependency 'mocha'
Expand Down

0 comments on commit 3a5ba1e

Please sign in to comment.