require 'rails_helper'

RSpec.describe Dunlop::ApplicationRecordAdditions::EpochWeeks do
  let(:model) { NonWorkflowProject }

  describe 'set_epoch_weeks!' do
    it "creates the proper iso weeks" do
      record1 = create :non_workflow_project, working_week: 53, working_year: 2015, working_date: '2017-11-28'
      record2 = create :non_workflow_project

      model.set_epoch_weeks! date_column: :working_date
      record1.reload.epoch_week.should eq 2500
      record2.reload.epoch_week.should be nil
    end
  end

  describe 'set_epoch_weeks_from_iso_week!' do
    it "creates the proper iso weeks" do
      record1 = create :non_workflow_project, working_week: 53, working_year: 2015, working_date: '2017-11-28'
      record2 = create :non_workflow_project

      model.set_epoch_weeks_from_iso_week! week_column: :working_week, year_column: :working_year
      record1.reload.epoch_week.should eq 2400
      record2.reload.epoch_week.should be nil
    end
  end
end

