Skip to content

Instantly share code, notes, and snippets.

@pat
Forked from radar/by_star.rb
Created July 3, 2009 00:55
Show Gist options
  • Select an option

  • Save pat/139854 to your computer and use it in GitHub Desktop.

Select an option

Save pat/139854 to your computer and use it in GitHub Desktop.

Revisions

  1. pat revised this gist Jul 3, 2009. 2 changed files with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion by_star.rb
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    # Post.by_day("next tuesday")
    def by_day(time = Time.zone.now, options = {}, &block)
    time = parse(time)
    by_star(time.beginning_of_day, time.end_of_day, options, &block)
    by_star(time.utc.beginning_of_day, time.utc.end_of_day, options, &block)
    end
    alias_method :today, :by_day

    File renamed without changes.
  2. @radar radar revised this gist Jul 3, 2009. 2 changed files with 31 additions and 0 deletions.
    31 changes: 31 additions & 0 deletions by_star.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    # Examples:
    # Post.by_day
    # Post.by_day(Time.yesterday)
    # Post.by_day("next tuesday")
    def by_day(time = Time.zone.now, options = {}, &block)
    time = parse(time)
    by_star(time.beginning_of_day, time.end_of_day, options, &block)
    end
    alias_method :today, :by_day

    # Examples:
    # Post.yesterday
    # # 2 days ago:
    # Post.yesterday(Time.yesterday)
    # # day before next tuesday
    # Post.yesterday("next tuesday")
    def yesterday(time = Time.zone.now, options = {}, &block)
    time = parse(time)
    by_day(time.advance(:days => -1), options, &block)
    end

    # Examples:
    # Post.tomorrow
    # # 2 days from now:
    # Post.tomorrow(Time.tomorrow)
    # # day after next tuesday
    # Post.tomorrow("next tuesday")
    def tomorrow(time = Time.zone.now, options = {}, &block)
    time = parse(time)
    by_day(time.advance(:days => 1), options, &block)
    end
    File renamed without changes.
  3. @radar radar revised this gist Jul 3, 2009. 1 changed file with 22 additions and 0 deletions.
    22 changes: 22 additions & 0 deletions by_star_spec.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    def find(*args)
    method = description_args.first.sub(' ', '_')
    Post.send(method, *args)
    end

    describe "today" do
    it "should show the post for tomorrow" do
    find("tomorrow").map(&:text).should include("Tomorrow's post")
    end
    end

    describe "yesterday" do
    it "should be able find yesterday, given a Date" do
    find(Date.today).map(&:text).should include("Yesterday's post")
    end
    end

    describe "tomorrow" do
    it "should be able find tomorrow, given a Date" do
    find(Date.today).map(&:text).should include("Tomorrow's post")
    end
    end
  4. @radar radar revised this gist Jul 3, 2009. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    Failures for by_star only occur (seemingly) in a positive timezone where the local time is in a day in the future from UTC. So in +1000 (Brisbane) these three specs only fail BEFORE 10am. After 10am it's a sea of wonderful green.
    Failures for by_star only occur (seemingly) in a positive timezone where the local time is in a day in the future from UTC.
    So in +1000 (Brisbane) these three specs only fail BEFORE 10am. After 10am it's a sea of wonderful green.

    ..................................F..F..F...................................

  5. @radar radar revised this gist Jul 3, 2009. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    Failures for by_star only occur (seemingly) in a positive timezone where the local time is in a day in the future from UTC. So in +1000 (Brisbane) these three specs only fail BEFORE 10am. After 10am it's a sea of wonderful green.

    ..................................F..F..F...................................

    1)
  6. @radar radar created this gist Jul 3, 2009.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    ..................................F..F..F...................................

    1)
    'Post today should show the post for tomorrow' FAILED
    expected ["Today's post", "Today"] to include "Tomorrow's post"
    ./spec/by_star_spec.rb:197:

    2)
    'Post yesterday should be able find yesterday, given a Date' FAILED
    expected ["Today's post", "Today"] to include "Yesterday's post"
    ./spec/by_star_spec.rb:213:

    3)
    'Post tomorrow should be able find tomorrow, given a Date' FAILED
    expected [] to include "Tomorrow's post"
    ./spec/by_star_spec.rb:230:

    Finished in 0.263454 seconds

    76 examples, 3 failures