Repository URL to install this package:
|
Version:
0.0.11 ▾
|
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
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
it "returns an openstruct of months in the archive" do
results = [OpenStruct.new(:fullname => 'January 2011',
:month => 1,
:year => 2011,
:count => 2)]
EventImplementer.archive_months.should == results
end
it "returns them in the correct date order" do
EventImplementer.create!(:starts => Date.parse('Feb 1, 2011'))
first_item = OpenStruct.new(:fullname => 'February 2011',
:month => 2,
:year => 2011,
:count => 1)
EventImplementer.archive_months.first.should == first_item
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
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
it "returns an openstruct of months in the archive" do
results = [OpenStruct.new(:fullname => 'January 2011',
:month => 1,
:year => 2011,
:count => 2)]
BlogImplementer.archive_months.should == results
end
it "returns them in the correct date order" do
BlogImplementer.create!(:pubdate => Date.parse('Feb 1, 2011'))
first_item = OpenStruct.new(:fullname => 'February 2011',
:month => 2,
:year => 2011,
:count => 1)
BlogImplementer.archive_months.first.should == first_item
end
end
end
end