Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
neoteric-archiver / spec / archiver_spec.rb
Size: Mime:
require 'spec_no_rails_helper'
require './lib/neoteric-archiver'

class BlogImplementer < ActiveRecord::Base
  self.table_name = 'implementers'
  include Neoteric::Archiver

  archive_fields :single => :pubdate,
                 :scope  => :published

  scope :published, where('drafted IS NULL or drafted = ?', false)
end

class EventImplementer < ActiveRecord::Base
  self.table_name = 'implementers'
  include Neoteric::Archiver

  archive_fields :starts => :starts,
                 :ends   => :ends
end

module Neoteric
  describe Archiver do
    describe "event archivin" do
      let!(:august10) do
        EventImplementer.create!(:starts => Date.parse('Aug 1, 2010'),
                                 :ends => Date.parse('Aug 7, 2010'))
      end

      let!(:july10) do
        EventImplementer.create!(:starts => Date.parse('Jul 1, 2010'),
                                 :ends => Date.parse('Jul 7, 2010'))
      end

      let!(:august11) do
        EventImplementer.create!(:starts => Date.parse('Aug 1, 2011'),
                                 :ends => Date.parse('Aug 7, 2011'))
      end

      describe ".by_month" do
        let(:posts) { EventImplementer.by_month(2010, 8) }

        it "returns posts from a given month" do
          posts.should include(august10)
        end

        it "excludes posts from the same month but different year" do
          posts.should_not include(august11)
        end

        it "excludes posts from other months" do
          posts.should_not include(july10)
        end
      end

      describe ".archive" do
        let(:posts) { EventImplementer.archive }

        before :each do
          Timecop.freeze(Date.parse("Aug 8, 2011"))
        end

        after :all do
          Timecop.return
        end

        it "includes posts from before today" do
          posts.should include(august10)
          posts.should include(july10)
        end

        it "does not include posts from this month" do
          posts.should_not include(august11)
        end
      end

      describe ".archive_months" do
        before :each do
          Timecop.freeze(Date.parse('Mar 1, 2011'))

          EventImplementer.delete_all
          # create 2 in the same month to ensure uniqueness
          EventImplementer.create!(:starts => Date.parse('Jan 18, 2011'))
          EventImplementer.create!(:starts => Date.parse('Jan 17, 2011'))

          # this one is pubdate today
          EventImplementer.create!(:starts => Time.now)
        end

        after :all do
          Timecop.return
        end

        it "returns readable months in the archive" do
          item = EventImplementer.archive_months.first

          item.fullname.should == "January 2011"
          item.count.should == 2
        end

        it "returns them in the correct date order" do
          EventImplementer.create!(:starts => Date.parse('Feb 1, 2011'))

          first_item = EventImplementer.archive_months.first

          first_item.fullname.should == "February 2011"
        end

        it "returns years before current year instead of all months" do
          EventImplementer.create!(:starts => Date.parse('Feb 1, 2010'))

          last_item = EventImplementer.archive_months.last

          last_item.fullname.should == "2010"
        end
      end
    end
  end

  describe "blog archivin" do
    let!(:august10) do
      BlogImplementer.create!(:pubdate => Date.parse('Aug 1, 2010'))
    end

    let!(:july10) do
      BlogImplementer.create!(:pubdate => Date.parse('July 1, 2010'))
    end

    let!(:august11) do
      BlogImplementer.create!(:pubdate => Date.parse('Aug 1, 2011'))
    end

    describe ".by_month" do
      let(:posts) { BlogImplementer.by_month(2010, 8) }

      it "returns posts from a given month" do
        posts.should include(august10)
      end

      it "excludes posts from the same month but different year" do
        posts.should_not include(august11)
      end

      it "excludes posts from other months" do
        posts.should_not include(july10)
      end
    end

    describe ".archive" do
      let(:posts) { BlogImplementer.archive }

      before :each do
        Timecop.freeze(Date.parse("Aug 1, 2011"))
      end

      after :all do
        Timecop.return
      end

      it "includes posts from before the beginning of this month" do
        posts.should include(august10)
        posts.should include(july10)
      end

      it "does not include posts from this month" do
        posts.should_not include(august11)
      end
    end

    describe ".archive_months" do
      before :each do
        Timecop.freeze(Date.parse('Mar 1, 2011'))

        BlogImplementer.delete_all
        # create 2 in the same month to ensure uniqueness
        BlogImplementer.create!(:pubdate => Date.parse('Jan 18, 2011'))
        BlogImplementer.create!(:pubdate => Date.parse('Jan 17, 2011'))
        BlogImplementer.create!(:pubdate => Date.parse('Jan 17, 2011'),
                                :drafted => true)

        # this one is pubdate today
        BlogImplementer.create!(:pubdate => Date.today)
      end

      after :all do
        Timecop.return
      end

      it "returns readable months in the archive" do
        month = BlogImplementer.archive_months.first

        month.fullname.should == 'January 2011'
        month.month.should == 1
        month.year.should == 2011
        month.count.should == 2
      end

      it "returns them in the correct date order" do
        BlogImplementer.create!(:pubdate => Date.parse('Feb 1, 2011'))

        first_item = BlogImplementer.archive_months.first

        first_item.fullname.should == "February 2011"
      end

      it "returns years before current year instead of all months" do
        BlogImplementer.create!(:pubdate => Date.parse('Feb 1, 2010'))

        last_item = BlogImplementer.archive_months.last

        last_item.fullname.should == "2010"
      end
    end
  end
end