2016-07-06 21:00:35 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Log, type: :model do
|
2016-09-28 17:08:43 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-07-06 21:00:35 -05:00
|
|
|
end
|