# == Schema Information
#
# Table name: datalogger_day_prods
#
#  id            :integer          not null, primary key
#  datalogger_id :integer          not null, foreign key
#  date          :date             not null
#  energy        :integer          not null
#  created_at    :datetime         not null
#  updated_at    :datetime         not null
#

require 'rails_helper'

RSpec.describe DataloggerDayProd, type: :model do

  subject { FactoryGirl.create :datalogger_day_prod }

  it { is_expected.to validate_presence_of(:datalogger_id) }
  it { is_expected.to validate_presence_of(:date) }
  it { is_expected.to validate_numericality_of(:energy).only_integer.is_greater_than_or_equal_to(0) }

  it { expect(subject.created_at).to_not be_nil }
  it { expect(subject.updated_at).to_not be_nil }

  context "when have datalogger_day_prod with same date" do

    let(:mirror_datalogger_day_prod) { FactoryGirl.build :datalogger_day_prod, datalogger_id: subject.datalogger_id, date: subject.date }

    it { expect(mirror_datalogger_day_prod).to_not be_valid }

  end
end
