require 'rails_helper'

RSpec.describe Log, type: :model do

  describe 'Rating Update' do
    it 'updates recipe rating on create' do
      r = create(:recipe)
      expect(r.rating).to be_nil

      l = build(:log, source_recipe: r, user: r.user)
      l.save

      r.reload
      expect(r.rating).to eq 1
    end

    it 'updates recipe rating on update' do
      r = create(:recipe)
      l = create(:log, source_recipe: r, user: r.user)
      r.update_rating!

      l.rating = 5
      l.save

      r.reload
      expect(r.rating).to eq 5
    end
  end

end
