require 'rails_helper'

describe Week do
  describe "2016" do
    let(:time) { '2016-03-09T18:22:40Z'.to_time }
    before { Timecop.freeze time }
    after { Timecop.return }
    it "returns a date range from a week number" do
      described_class.new(38).should eq '2016-09-19'.to_date..'2016-09-25'.to_date
      described_class.new(38).year.should eq 2016
      described_class.new(38).number.should eq 38
    end

    it "can be given a custom year as option" do
      described_class.new(38, year: 2015).should eq '2015-09-14'.to_date..'2015-09-20'.to_date
      described_class.new(38, year: 2015).year.should eq 2015
      described_class.new(38, year: 2015).number.should eq 38
    end
  end

  describe "2015" do
    let(:time) { '2015-03-09T18:22:40Z'.to_time }
    before { Timecop.freeze time }
    after { Timecop.return }
    it "returns a date range from a week number" do
      described_class.new(38).should eq '2015-09-14'.to_date..'2015-09-20'.to_date
      described_class.new(38).year.should eq 2015
      described_class.new(38).number.should eq 38
    end
  end
end
