spec/trackoid_spec.rb in trackoid-0.2.0 vs spec/trackoid_spec.rb in trackoid-0.3.0

- old
+ new

@@ -48,10 +48,14 @@ it "should create a method for accesing the stats" do @mock.respond_to?(:visits).should be_true end + it "should NOT create an index for the stats field" do + @mock.class.index_options.should_not include(:visits_data) + end + it "should respond 'false' to field_changed? method" do # Ok, this test is not very relevant since it will return false even # if Trackid does not override it. @mock.visits_changed?.should be_false end @@ -103,10 +107,11 @@ @object_id = Test.first.id end before do @mock = Test.find(@object_id) + @today = Time.now end it "should increment visits stats for today" do @mock.visits.inc @mock.visits.today.should == 1 @@ -116,16 +121,16 @@ @mock.visits.inc @mock.visits.today.should == 2 end it "should also work for yesterday" do - @mock.visits.inc(DateTime.now - 1) + @mock.visits.inc(@today - 1.day) @mock.visits.yesterday.should == 1 end it "should also work for yesterday if adding another visit (for a total of 2)" do - @mock.visits.inc(DateTime.now - 1) + @mock.visits.inc(@today - 1.day) @mock.visits.yesterday.should == 2 end it "then, the visits of today + yesterday must be the same" do @mock.visits.last_days(2).should == [2, 2] @@ -143,23 +148,28 @@ @mock.visits.inc("2010-07-11") @mock.visits.on("2010-07-11").should == 1 end it "should give the first date with first_date" do - @mock.visits.first_date.should == Date.parse("2010-07-11") + t = Time.parse("2010-07-11") + f = @mock.visits.first_date + [f.year, f.month, f.day, f.hour].should == [t.year, t.month, t.day, t.hour] end it "should give the last date with last_date" do - @mock.visits.last_date.should == Date.today + future = @today + 1.month + @mock.visits.set(22, future) + f = @mock.visits.last_date + [f.year, f.month, f.day, f.hour].should == [future.year, future.month, future.day, future.hour] end it "should give the first value" do @mock.visits.first_value.should == 1 end it "should give the last value" do - @mock.visits.last_value.should == 2 + @mock.visits.last_value.should == 22 end end context "testing reader operations without reloading models" do before(:all) do @@ -177,39 +187,39 @@ @mock.visits.today.should == 5 Test.find(@object_id).visits.today.should == 5 end it "'set' operator must work on arbitrary days" do - @mock.visits.set(5, Date.parse("2010-05-01")) - @mock.visits.on(Date.parse("2010-05-01")).should == 5 - Test.find(@object_id).visits.on(Date.parse("2010-05-01")).should == 5 + @mock.visits.set(5, Time.parse("2010-05-01")) + @mock.visits.on(Time.parse("2010-05-01")).should == 5 + Test.find(@object_id).visits.on(Time.parse("2010-05-01")).should == 5 end it "'add' operator must work" do @mock.visits.add(5) @mock.visits.today.should == 10 # Remember 5 set on previous test Test.find(@object_id).visits.today.should == 10 end it "'add' operator must work on arbitrary days" do - @mock.visits.add(5, Date.parse("2010-05-01")) - @mock.visits.on(Date.parse("2010-05-01")).should == 10 - Test.find(@object_id).visits.on(Date.parse("2010-05-01")).should == 10 + @mock.visits.add(5, Time.parse("2010-05-01")) + @mock.visits.on(Time.parse("2010-05-01")).should == 10 + Test.find(@object_id).visits.on(Time.parse("2010-05-01")).should == 10 end it "on() accessor must work on dates as String" do # We have data for today as previous tests populated the visits field @mock.visits.on("2010-05-01").should == 10 end - it "on() accessor must work on dates as Date ancestors" do + it "on() accessor must work on Date descendants" do # We have data for today as previous tests populated the visits field @mock.visits.on(Date.parse("2010-05-01")).should == 10 end it "on() accessor must work on dates as Ranges" do # We have data for today as previous tests populated the visits field - @mock.visits.on(Date.parse("2010-04-30")..Date.parse("2010-05-02")).should == [0, 10, 0] + @mock.visits.on(Time.parse("2010-04-30")..Time.parse("2010-05-02")).should == [0, 10, 0] end end context "regression test for github issues" do it "should not raise undefined method [] for nil:NilClass when adding a new track into an existing object" do