by_star 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.6.0
data/by_star.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{by_star}
8
- s.version = "0.5.2"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ryan Bigg", "Mislav Marohni\304\207"]
12
- s.date = %q{2010-01-13}
12
+ s.date = %q{2010-01-18}
13
13
  s.description = %q{ActiveRecord extension for easier date scopes and time ranges}
14
14
  s.email = %q{radarlistener@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  "Rakefile",
23
23
  "VERSION",
24
24
  "by_star.gemspec",
25
+ "init.rb",
25
26
  "lib/by_star.rb",
26
27
  "lib/calculations.rb",
27
28
  "lib/calculations/count.rb",
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'by_star'
2
+ ActiveRecord::Base.send :include, ByStar
data/spec/by_star_spec.rb CHANGED
@@ -3,7 +3,7 @@ require 'by_star'
3
3
 
4
4
  describe Post do
5
5
 
6
- def stub_time(day=15, month=5, year=Time.zone.now.year, hour=0, minute=0)
6
+ def stub_time(day=1, month=1, year=Time.zone.now.year, hour=0, minute=0)
7
7
  stub = "#{day}-#{month}-#{year} #{hour}:#{minute}".to_time
8
8
  Time.stub!(:now).and_return(stub)
9
9
  Time.zone.stub!(:now).and_return(stub)
@@ -77,11 +77,11 @@ describe Post do
77
77
 
78
78
  it "should be able to find posts for the current month" do
79
79
  stub_time
80
- size.should eql(8)
80
+ size.should eql(10)
81
81
  end
82
82
 
83
83
  it "should be able to find a single post for January" do
84
- size("January").should eql(1)
84
+ size("January").should eql(10)
85
85
  end
86
86
 
87
87
  it "should be able to find two posts for the 2nd month" do
@@ -107,7 +107,7 @@ describe Post do
107
107
  end
108
108
 
109
109
  it "should be able to take decimals" do
110
- size(1.5).should eql(1)
110
+ size(1.5).should eql(10)
111
111
  end
112
112
 
113
113
  it "should be able to use an alternative field" do
@@ -129,16 +129,16 @@ describe Post do
129
129
 
130
130
  it "should be able to find posts in the current fortnight" do
131
131
  stub_time
132
- size.should eql(3)
132
+ size.should eql(4)
133
133
  end
134
134
 
135
135
  it "should be able to find posts in the 1st fortnight" do
136
- size(0).should eql(1)
136
+ size(0).should eql(4)
137
137
  end
138
138
 
139
139
  it "should be able to find posts for a fortnight ago" do
140
140
  stub_time
141
- size(2.weeks.ago).should eql(5)
141
+ size(2.weeks.ago).should eql(0)
142
142
  end
143
143
 
144
144
  it "should raise an error when given an invalid argument" do
@@ -155,11 +155,11 @@ describe Post do
155
155
 
156
156
  it "should be able to find posts in the current week" do
157
157
  stub_time
158
- size.should eql(3)
158
+ size.should eql(4)
159
159
  end
160
160
 
161
161
  it "should be able to find posts in the 1st week" do
162
- size(0).should eql(1)
162
+ size(0).should eql(4)
163
163
  end
164
164
 
165
165
  it "should be able to find posts in the 1st week of last year" do
@@ -192,7 +192,7 @@ describe Post do
192
192
  end
193
193
 
194
194
  it "should find posts at the start of the year" do
195
- size(0).should eql(1)
195
+ size(0).should eql(4)
196
196
  end
197
197
 
198
198
  it "should find posts at the end of the year" do
@@ -202,15 +202,15 @@ describe Post do
202
202
  end
203
203
 
204
204
  describe "by weekend" do
205
- it "should be able to find the posts on the weekend of the 1st May" do
206
- stub_time(1, 8)
207
- size.should eql(8)
205
+ it "should be able to find the posts on the weekend of the 1st of January" do
206
+ stub_time
207
+ size.should eql(1)
208
208
  end
209
209
 
210
210
  it "should be able to use an alternative field" do
211
211
  year = Time.zone.now.year
212
212
  stub_time(1, 8)
213
- Event.by_weekend(nil, :field => "start_time").size.should eql(1)
213
+ Event.by_weekend(nil, :field => "start_time").size.should eql(0)
214
214
  end
215
215
  end
216
216
 
@@ -233,12 +233,12 @@ describe Post do
233
233
  describe "by day" do
234
234
  it "should be able to find a post for today" do
235
235
  stub_time
236
- size.should eql(2)
236
+ size.should eql(3)
237
237
  end
238
238
 
239
239
  it "should be able to find a post by a given date" do
240
240
  stub_time
241
- size(Date.today).should eql(2)
241
+ size(Date.today).should eql(3)
242
242
  end
243
243
 
244
244
  it "should be able to use an alternative field" do
@@ -305,26 +305,27 @@ describe Post do
305
305
  end
306
306
 
307
307
  it "should show the correct number of posts in the past" do
308
- size.should eql(16)
308
+ size.should eql(1)
309
309
  end
310
310
 
311
311
  it "should find for a given time" do
312
- size(Time.zone.now - 2.days).should eql(16)
312
+ size(Time.zone.now - 2.days).should eql(1)
313
313
  end
314
314
 
315
315
  it "should find for a given date" do
316
- size(Date.today - 2).should eql(16)
316
+ size(Date.today - 2).should eql(1)
317
317
  end
318
318
 
319
319
  it "should find for a given string" do
320
- size("next tuesday").should eql(19)
320
+ size("next tuesday").should eql(5)
321
321
  end
322
322
 
323
323
  it "should be able to find all events before Ryan's birthday using a non-standard field" do
324
- Event.past("01-01-#{Time.zone.now.year+2}".to_time, :field => "start_time").size.should eql(8)
324
+ Event.past("01-01-#{Time.zone.now.year+2}".to_time, :field => "start_time").size.should eql(9)
325
325
  end
326
326
 
327
327
  it "should be able to order the find" do
328
+ stub_time(2,1)
328
329
  find(Date.today, :order => "created_at ASC").first.text.should eql("Last year")
329
330
  find(Date.today, :order => "created_at DESC").first.text.should eql("post 0")
330
331
  end
@@ -337,31 +338,32 @@ describe Post do
337
338
  end
338
339
 
339
340
  it "should show the correct number of posts in the future" do
340
- size.should eql(71)
341
+ size.should eql(85)
341
342
  end
342
343
 
343
344
  it "should find for a given date" do
344
- size(Date.today - 2).should eql(73)
345
+ size(Date.today - 2).should eql(88)
345
346
  end
346
347
 
347
348
  it "should find for a given string" do
348
- size("next tuesday").should eql(70)
349
+ size("next tuesday").should eql(84)
349
350
  end
350
351
 
351
- it "should be able to find all events after Dad's birthday using a non-standard field" do
352
- Event.past("05-07-#{Time.zone.now.year}".to_time, :field => "start_time").size.should eql(1)
352
+ it "should be able to find all events before Dad's birthday using a non-standard field" do
353
+ # TODO: This will change in May. Figure out how to fix.
354
+ Event.past("05-07-#{Time.zone.now.year}".to_time, :field => "start_time").size.should eql(5)
353
355
  end
354
356
  end
355
357
 
356
358
  describe "as of" do
357
359
  it "should be able to find posts as of 2 weeks ago" do
358
360
  stub_time
359
- Post.as_of_2_weeks_ago.size.should eql(7)
361
+ Post.as_of_2_weeks_ago.size.should eql(3)
360
362
  end
361
363
 
362
364
  it "should be able to find posts as of 2 weeks before a given time" do
363
365
  stub_time
364
- Post.as_of_2_weeks_ago(Time.zone.now + 1.month).size.should eql(14)
366
+ Post.as_of_2_weeks_ago(Time.zone.now + 1.month).size.should eql(12)
365
367
  end
366
368
 
367
369
  it "should error if given a date in the past far enough back" do
@@ -376,29 +378,29 @@ describe Post do
376
378
  describe "between" do
377
379
  it "should find posts between last tuesday and next tuesday" do
378
380
  stub_time
379
- size("last tuesday", "next tuesday").should eql(3)
381
+ size("last tuesday", "next tuesday").should eql(4)
380
382
  end
381
383
 
382
384
  it "should find between two times" do
383
385
  stub_time
384
- size(Time.zone.now - 5.days, Time.zone.now + 5.days).should eql(3)
386
+ size(Time.zone.now - 5.days, Time.zone.now + 5.days).should eql(4)
385
387
  end
386
388
 
387
389
  it "should find between two dates" do
388
390
  stub_time
389
- size(Date.today, Date.today + 5).should eql(3)
391
+ size(Date.today, Date.today + 5).should eql(4)
390
392
  end
391
393
  end
392
394
 
393
395
  describe "up to" do
394
396
  it "should be able to find posts up to 2 weeks from now" do
395
397
  stub_time
396
- Post.up_to_6_weeks_from_now.size.should eql(9)
398
+ Post.up_to_6_weeks_from_now.size.should eql(12)
397
399
  end
398
400
 
399
401
  it "should be able to find posts up to 2 weeks from a given time" do
400
402
  stub_time
401
- Post.up_to_6_weeks_from_now(Time.zone.now - 1.month).size.should eql(14)
403
+ Post.up_to_6_weeks_from_now(Time.zone.now - 1.month).size.should eql(12)
402
404
  end
403
405
 
404
406
  it "should error if given a date in the past" do
@@ -441,7 +443,7 @@ describe Post do
441
443
 
442
444
  it "should be able to find posts after right now" do
443
445
  stub_time
444
- Post.by_current_work_week.size.should eql(2)
446
+ Post.by_current_work_week.size.should eql(3)
445
447
  Post.by_current_work_week do
446
448
  { :conditions => ["created_at > ?", Time.now] }
447
449
  end.size.should eql(0)
@@ -513,7 +515,7 @@ describe Post do
513
515
 
514
516
  it "should work when block is empty" do
515
517
  stub_time
516
- Post.future { }.size.should eql(71)
518
+ Post.future { }.size.should eql(85)
517
519
  end
518
520
 
519
521
  it "should be able to find a single post from the future with the tag 'tomorrow' (redux)" do
@@ -534,7 +536,7 @@ describe Post do
534
536
  describe "by month" do
535
537
  it "current month" do
536
538
  stub_time
537
- Invoice.sum_by_month(:value).should eql(15000)
539
+ Invoice.sum_by_month(:value).should eql(11000)
538
540
  end
539
541
  end
540
542
  end
@@ -582,7 +584,7 @@ describe Post do
582
584
 
583
585
  it "current month with blank block" do
584
586
  stub_time
585
- Post.count_by_month(:all, Time.zone.now) { }.should eql(8)
587
+ Post.count_by_month(:all, Time.zone.now) { }.should eql(10)
586
588
  end
587
589
  end
588
590
  end
@@ -55,7 +55,13 @@ Post.factory "Tomorrow's post", Time.zone.now + 1.day
55
55
  Post.factory "That's it!", Time.zone.now.end_of_year
56
56
 
57
57
  # For by_weekend scoped test
58
- post = Post.factory "Weekend of May", "16-05-#{Time.zone.now.year}".to_time
58
+ # We need to calculate the weekend.
59
+ time = Time.now.beginning_of_year
60
+ while time.wday != 6
61
+ time += 1.day
62
+ end
63
+
64
+ post = Post.factory "Weekend of January", time
59
65
  post.tags.create(:name => "weekend")
60
66
 
61
67
  # For by_day scoped test
@@ -70,17 +76,18 @@ post.tags.create(:name => "yesterday")
70
76
  post = Post.factory "Tomorrow's Another Day", Time.zone.now.tomorrow
71
77
  post.tags.create(:name => "tomorrow")
72
78
 
73
- post = Post.factory "Last year", Time.local(year - 1, 1, 1)
79
+ post = Post.factory "Last year", Time.zone.now.beginning_of_year - 1.year
74
80
  post.tags.create(:name => "ruby")
75
81
 
76
- post = Post.factory "The 'Current' Fortnight", Time.local(year, 5, 15)
82
+ post = Post.factory "The 'Current' Fortnight", Time.zone.now.beginning_of_year
77
83
  post.tags.create(:name => "may")
78
84
 
79
- post = Post.factory "The 'Current' Week", Time.local(year, 5, 15)
85
+ post = Post.factory "The 'Current' Week", Time.zone.now.beginning_of_year
80
86
  post.tags.create(:name => "may2")
81
87
 
82
88
 
83
89
  Event.create(:name => "Ryan's birthday!", :start_time => "04-12-#{Time.zone.now.year}".to_time)
90
+ Event.create(:name => "Ryan's birthday, last year!", :start_time => "04-12-#{Time.zone.now.year-1}".to_time)
84
91
  Event.create(:name => "Dad's birthday!", :start_time => "05-07-#{Time.zone.now.year}".to_time)
85
92
  Event.create(:name => "Mum's birthday!", :start_time => "17-11-#{Time.zone.now.year}".to_time)
86
93
  Event.create(:name => "Today", :start_time => Time.zone.now)
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  require 'rubygems'
2
- require 'activerecord'
2
+ require 'active_record'
3
3
  require 'fileutils'
4
+ require 'logger'
4
5
  FileUtils.mkdir_p("tmp")
5
6
 
6
7
  ActiveRecord::Base.logger = Logger.new("tmp/activerecord.log")
7
8
  $:.unshift(File.join(File.dirname(__FILE__), "../lib"))
8
9
 
9
- require 'activesupport'
10
+ require 'active_support'
10
11
  require 'by_star'
11
12
  require 'spec'
12
13
 
@@ -24,3 +25,13 @@ end
24
25
  # bootstraping the plugin through init.rb
25
26
  # tests how it would load in a real application
26
27
  load File.dirname(__FILE__) + "/../rails/init.rb"
28
+ # Print the location of puts/p calls so you can find them later
29
+ def puts str
30
+ super caller.first if caller.first.index("shoulda.rb") == -1
31
+ super str
32
+ end
33
+
34
+ def p obj
35
+ puts caller.first
36
+ super obj
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: by_star
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-13 00:00:00 +10:00
13
+ date: 2010-01-18 00:00:00 +10:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -48,6 +48,7 @@ files:
48
48
  - Rakefile
49
49
  - VERSION
50
50
  - by_star.gemspec
51
+ - init.rb
51
52
  - lib/by_star.rb
52
53
  - lib/calculations.rb
53
54
  - lib/calculations/count.rb