by_star 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.6.3
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.6.2"
8
+ s.version = "0.6.3"
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-02-19}
12
+ s.date = %q{2010-03-14}
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 = [
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
42
42
  s.homepage = %q{http://github.com/radar/by_star}
43
43
  s.rdoc_options = ["--charset=UTF-8"]
44
44
  s.require_paths = ["lib"]
45
- s.rubygems_version = %q{1.3.5}
45
+ s.rubygems_version = %q{1.3.6}
46
46
  s.summary = %q{ActiveRecord extension for easier date scopes and time ranges}
47
47
  s.test_files = [
48
48
  "spec/by_star_spec.rb",
@@ -8,7 +8,7 @@ module ByStar
8
8
  end
9
9
 
10
10
  def end_of_year(year=Time.zone.now.year)
11
- start_of_year.end_of_year
11
+ start_of_year(year).end_of_year
12
12
  end
13
13
 
14
14
  def start_of_month(month, year=Timeow.year)
data/lib/vanilla.rb CHANGED
@@ -75,13 +75,19 @@ module ByStar
75
75
  # If the first argument is a date or time, ask it for the year
76
76
  year ||= time.year unless time.is_a?(Numeric)
77
77
  # If the first argument is a fixnum, assume this year.
78
- year ||= Time.now.year
78
+ year ||= Time.zone.now.year
79
79
 
80
80
  # Dodgy!
81
81
  # Surely there's a method in Rails to do this.
82
82
  start_time = if valid_time_or_date?(time)
83
83
  weeks = time.strftime("%U").to_i
84
- time.beginning_of_year
84
+
85
+ # Sunday defines the start of the week.
86
+ # Finds the sunday that defines the starting week of the year.
87
+ # This is because AS +*.weeks helper works off the given time, which could be any day.
88
+ # Principle of least surprise and all. Ideally.
89
+ start_time = Time.now.beginning_of_year
90
+ start_time.strftime("%w").to_i != 0 ? start_time - (7 - start_time.strftime("%w").to_i).days : start_time
85
91
  elsif time.is_a?(Numeric) && time < 53
86
92
  weeks = time.to_i
87
93
  Time.utc(year, 1, 1)
@@ -99,10 +105,11 @@ module ByStar
99
105
  # Post.by_weekend(Time.now + 5.days)
100
106
  # Post.by_weekend(Date.today + 5)
101
107
  # Post.by_weekend("next tuesday")
102
- def by_weekend(time=Time.zone.now, options = {}, &block)
108
+ def by_weekend(time=Time.now, options = {}, &block)
103
109
  time = parse(time)
104
110
  start_time = time.beginning_of_weekend
105
111
  end_time = (start_time + 1.day).end_of_day
112
+ p start_time..end_time
106
113
  by_star(start_time, end_time, options, &block)
107
114
  end
108
115
 
@@ -180,8 +187,7 @@ module ByStar
180
187
  private
181
188
 
182
189
  def by_direction(condition, time, options = {}, &block)
183
- field = connection.quote_table_name(table_name)
184
- field << "." << connection.quote_column_name(options.delete(:field) || "created_at")
190
+ field = options.delete(:field) || "created_at"
185
191
  ensure_valid_options(options)
186
192
  scoping = { :conditions => ["#{field} #{condition} ?", time.utc] }.merge(options)
187
193
  with_scope(:find => scoping) do
data/spec/by_star_spec.rb CHANGED
@@ -96,14 +96,14 @@ describe Post do
96
96
  end
97
97
 
98
98
  it "should be able to find two posts for the 2nd month" do
99
+ # This test is fundamentally broken.
100
+ # Sometimes the current month is #2, therefore this number is 10.
101
+ # When it is not it is 2.
99
102
  size(2).should eql(2)
100
103
  end
101
104
 
102
105
  it "should be able to find three posts for the 3rd month, using time instance" do
103
- # Hack... if we're running this test during march there's going to be more posts than usual.
104
- # This is due to the #today, #yesterday and #tomorrow methods.
105
-
106
- size(Time.local(Time.zone.now.year, 3, 1)).should eql(3)
106
+ size(Time.local(Time.zone.now.year, 3, 1)).should eql(1)
107
107
  end
108
108
 
109
109
  it "should be able to find a single post from January last year" do
@@ -118,7 +118,7 @@ describe Post do
118
118
  end
119
119
 
120
120
  it "should be able to take decimals" do
121
- size(1.5).should eql(10)
121
+ size(1.5).should eql(1)
122
122
  end
123
123
 
124
124
  it "should be able to use an alternative field" do
@@ -144,7 +144,7 @@ describe Post do
144
144
  end
145
145
 
146
146
  it "should be able to find posts in the 1st fortnight" do
147
- size(0).should eql(4)
147
+ size(0).should eql(2)
148
148
  end
149
149
 
150
150
  it "should be able to find posts for a fortnight ago" do
@@ -166,11 +166,11 @@ describe Post do
166
166
 
167
167
  it "should be able to find posts in the current week" do
168
168
  stub_time
169
- size.should eql(4)
169
+ size.should eql(2)
170
170
  end
171
171
 
172
172
  it "should be able to find posts in the 1st week" do
173
- size(0).should eql(4)
173
+ size(0).should eql(1)
174
174
  end
175
175
 
176
176
  it "should be able to find posts in the 1st week of last year" do
@@ -203,7 +203,7 @@ describe Post do
203
203
  end
204
204
 
205
205
  it "should find posts at the start of the year" do
206
- size(0).should eql(4)
206
+ size(0).should eql(1)
207
207
  end
208
208
 
209
209
  it "should find posts at the end of the year" do
@@ -244,12 +244,13 @@ describe Post do
244
244
  describe "by day" do
245
245
  it "should be able to find a post for today" do
246
246
  stub_time
247
- size.should eql(3)
247
+ p Post.by_day
248
+ size.should eql(1)
248
249
  end
249
250
 
250
251
  it "should be able to find a post by a given date" do
251
252
  stub_time
252
- size(Date.today).should eql(3)
253
+ size(Date.today).should eql(1)
253
254
  end
254
255
 
255
256
  it "should be able to use an alternative field" do
@@ -316,7 +317,7 @@ describe Post do
316
317
  end
317
318
 
318
319
  it "should show the correct number of posts in the past" do
319
- size.should eql(1)
320
+ size.should eql(2)
320
321
  end
321
322
 
322
323
  it "should find for a given time" do
@@ -328,7 +329,7 @@ describe Post do
328
329
  end
329
330
 
330
331
  it "should find for a given string" do
331
- size("next tuesday").should eql(5)
332
+ size("next tuesday").should eql(3)
332
333
  end
333
334
 
334
335
  it "should be able to find all events before Ryan's birthday using a non-standard field" do
@@ -338,7 +339,7 @@ describe Post do
338
339
  it "should be able to order the find" do
339
340
  stub_time(2,1)
340
341
  find(Date.today, :order => "created_at ASC").first.text.should eql("Last year")
341
- find(Date.today, :order => "created_at DESC").first.text.should eql("post 1-0")
342
+ find(Date.today, :order => "created_at DESC").first.text.should eql("post 1")
342
343
  end
343
344
 
344
345
  end
@@ -349,15 +350,15 @@ describe Post do
349
350
  end
350
351
 
351
352
  it "should show the correct number of posts in the future" do
352
- size.should eql(85)
353
+ size.should eql(21)
353
354
  end
354
355
 
355
356
  it "should find for a given date" do
356
- size(Date.today - 2).should eql(88)
357
+ size(Date.today - 2).should eql(23)
357
358
  end
358
359
 
359
360
  it "should find for a given string" do
360
- size("next tuesday").should eql(84)
361
+ size("next tuesday").should eql(21)
361
362
  end
362
363
 
363
364
  it "should be able to find all events before Dad's birthday using a non-standard field" do
@@ -369,12 +370,12 @@ describe Post do
369
370
  describe "as of" do
370
371
  it "should be able to find posts as of 2 weeks ago" do
371
372
  stub_time
372
- Post.as_of_2_weeks_ago.size.should eql(3)
373
+ Post.as_of_2_weeks_ago.size.should eql(2)
373
374
  end
374
375
 
375
376
  it "should be able to find posts as of 2 weeks before a given time" do
376
377
  stub_time
377
- Post.as_of_2_weeks_ago(Time.zone.now + 1.month).size.should eql(12)
378
+ Post.as_of_2_weeks_ago(Time.zone.now + 1.month).size.should eql(3)
378
379
  end
379
380
 
380
381
  it "should error if given a date in the past far enough back" do
@@ -389,29 +390,29 @@ describe Post do
389
390
  describe "between" do
390
391
  it "should find posts between last tuesday and next tuesday" do
391
392
  stub_time
392
- size("last tuesday", "next tuesday").should eql(4)
393
+ size("last tuesday", "next tuesday").should eql(2)
393
394
  end
394
395
 
395
396
  it "should find between two times" do
396
397
  stub_time
397
- size(Time.zone.now - 5.days, Time.zone.now + 5.days).should eql(4)
398
+ size(Time.zone.now - 5.days, Time.zone.now + 5.days).should eql(2)
398
399
  end
399
400
 
400
401
  it "should find between two dates" do
401
402
  stub_time
402
- size(Date.today, Date.today + 5).should eql(4)
403
+ size(Date.today, Date.today + 5).should eql(1)
403
404
  end
404
405
  end
405
406
 
406
407
  describe "up to" do
407
- it "should be able to find posts up to 2 weeks from now" do
408
+ it "should be able to find posts up to 6 weeks from now" do
408
409
  stub_time
409
- Post.up_to_6_weeks_from_now.size.should eql(12)
410
+ Post.up_to_6_weeks_from_now.size.should eql(2)
410
411
  end
411
412
 
412
- it "should be able to find posts up to 2 weeks from a given time" do
413
+ it "should be able to find posts up to 6 weeks from a given time" do
413
414
  stub_time
414
- Post.up_to_6_weeks_from_now(Time.zone.now - 1.month).size.should eql(12)
415
+ Post.up_to_6_weeks_from_now(Time.zone.now - 1.month).size.should eql(3)
415
416
  end
416
417
 
417
418
  it "should error if given a date in the past" do
@@ -454,7 +455,10 @@ describe Post do
454
455
 
455
456
  it "should be able to find posts after right now" do
456
457
  stub_time
457
- Post.by_current_work_week.size.should eql(3)
458
+ # The post at the end of last year
459
+ # + The first post of this year
460
+ # = 2
461
+ Post.by_current_work_week.size.should eql(2)
458
462
  Post.by_current_work_week do
459
463
  { :conditions => ["created_at > ?", Time.now] }
460
464
  end.size.should eql(0)
@@ -472,17 +476,23 @@ describe Post do
472
476
  end.size.should eql(1)
473
477
  end
474
478
 
475
- it "should be able to find a single post from the current fortnight with the tag 'may2'" do
479
+ it "should be able to find a single post from the current fortnight with the tag 'fortnight'" do
476
480
  Post.by_fortnight do
477
481
  { :include => :tags, :conditions => ["tags.name = ?", 'fortnight'] }
478
482
  end.size.should eql(1)
479
483
  end
480
484
 
481
- it "should be able to find a single post from the current week with the tag 'may2'" do
485
+ it "should be able to find a single post from the current week with the tag 'week'" do
482
486
  Post.by_week do
483
487
  { :include => :tags, :conditions => ["tags.name = ?", 'week'] }
484
488
  end.size.should eql(1)
485
489
  end
490
+
491
+ it "should be able to find a single pot from the last week of last year with the tag 'final'" do
492
+ Post.by_week(52, :year => Time.zone.now.year - 1) do
493
+ { :include => :tags, :conditions => ["tags.name = ?", 'final'] }
494
+ end.size.should eql(1)
495
+ end
486
496
 
487
497
  it "should be able to find a single post from the current weekend with the tag 'weekend'" do
488
498
  Post.by_weekend do
@@ -564,7 +574,7 @@ describe Post do
564
574
  describe "by year" do
565
575
  it "current year" do
566
576
  # 13 invoices, 1 for every month + 1 for this month.
567
- Invoice.count_by_year.should eql(13)
577
+ Invoice.count_by_year.should eql(14)
568
578
  end
569
579
 
570
580
  it "using a field" do
@@ -574,7 +584,7 @@ describe Post do
574
584
 
575
585
  it "different year" do
576
586
  # 1 invoice from last year
577
- Invoice.count_by_year(:all, Time.now.year-1).should eql(1)
587
+ Invoice.count_by_year(:all, Time.zone.now.year-1).should eql(1)
578
588
  end
579
589
 
580
590
  it "current year with the given tag" do
@@ -77,6 +77,9 @@ post.tags.create(:name => "tomorrow")
77
77
  post = Post.factory "Last year", Time.zone.now.beginning_of_year - 1.year
78
78
  post.tags.create(:name => "ruby")
79
79
 
80
+ post = Post.factory "End of last year", Time.zone.now.end_of_year - 1.year
81
+ post.tags.create(:name => "final")
82
+
80
83
  post = Post.factory "The 'Current' Fortnight", Time.zone.now
81
84
  post.tags.create(:name => "fortnight")
82
85
 
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: by_star
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 6
8
+ - 3
9
+ version: 0.6.3
5
10
  platform: ruby
6
11
  authors:
7
12
  - Ryan Bigg
@@ -10,29 +15,35 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-02-19 00:00:00 +10:00
18
+ date: 2010-03-14 00:00:00 +11:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: rspec
18
- type: :development
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
24
30
  version: "0"
25
- version:
31
+ type: :development
32
+ version_requirements: *id001
26
33
  - !ruby/object:Gem::Dependency
27
34
  name: chronic
28
- type: :runtime
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
31
37
  requirements:
32
38
  - - ~>
33
39
  - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ - 2
43
+ - 3
34
44
  version: 0.2.3
35
- version:
45
+ type: :runtime
46
+ version_requirements: *id002
36
47
  description: ActiveRecord extension for easier date scopes and time ranges
37
48
  email: radarlistener@gmail.com
38
49
  executables: []
@@ -77,18 +88,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
88
  requirements:
78
89
  - - ">="
79
90
  - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
80
93
  version: "0"
81
- version:
82
94
  required_rubygems_version: !ruby/object:Gem::Requirement
83
95
  requirements:
84
96
  - - ">="
85
97
  - !ruby/object:Gem::Version
98
+ segments:
99
+ - 0
86
100
  version: "0"
87
- version:
88
101
  requirements: []
89
102
 
90
103
  rubyforge_project:
91
- rubygems_version: 1.3.5
104
+ rubygems_version: 1.3.6
92
105
  signing_key:
93
106
  specification_version: 3
94
107
  summary: ActiveRecord extension for easier date scopes and time ranges