Sha256: 23a369e35481d83b5c935404918d52c5148aa2c29bb83b6509be8a4b47bee00b

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

require 'spec_helper'

shared_examples_for "by year" do
  describe "by year" do
    def posts_count(*args)
      find_posts(*args).count
    end

    def find_posts(*args)
      options = args.extract_options!
      Post.by_year(args.first, options)
    end

    let(:this_years_posts) { 18 }

    it "should be able to find all the posts in the current year" do
      posts_count.should eql(this_years_posts)
    end

    it "should be able to find if given a string" do
      posts_count(Time.zone.now.year.to_s).should eql(this_years_posts)
    end

    it "should be able to find a single post from last year" do
      posts_count(Time.zone.now.year-1).should eql(3)
    end

    it "knows what last year's posts were" do
      find_posts(Time.zone.now.year-1).map(&:text).should =~ ["A week ago", "This time, last year", "Yesterday's post"]
    end

    it "can find posts given a 2-digit year" do
      # Should be good for at least a couple of years.
      posts_count(Time.zone.now.year-2001).should eql(3)
    end

    it "should be able to use an alternative field (string)" do
      Event.by_year(:field => "start_time").count.should eql(6)
    end

    it "should be able to use an alternative field (symbol)" do
      Event.by_year(:field => :start_time).count.should eql(6)
    end

    it "should not have to specify the field when using by_star_field" do
      Event.by_year.count.should eql(6)
    end

    it "should not include yesterday's (Dec 31st <last year>) event in by_year" do
      Event.by_year.map(&:name).should_not include("Yesterday")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
by_star-2.1.0.beta2 spec/by_star/shared/by_year.rb