require 'rails_helper'

RSpec.describe Study, type: :model do
  describe 'associations' do
    it { should belong_to(:user) }
  end

  describe 'validations' do
    it { should validate_presence_of(:name) }
    it { should validate_presence_of(:hours) }
    it { should validate_presence_of(:hours_goal) }
    it { should validate_presence_of(:projects) }
    it { should validate_presence_of(:projects_goal) }
  end

  describe 'Progress calculation' do
    let(:study) { create_list(:study, 20) }
    subject { described_class.progress_calculation(study) }

    it {
      is_expected.to eq({ 'total_hours' => 100,
                          'total_hours_goal' => 100,
                          'total_projects' => 100,
                          'total_projects_goal' => 100 })
    }
  end
end
