|
6 | 6 | end
|
7 | 7 | end
|
8 | 8 |
|
| 9 | + describe 'processing' do |
| 10 | + let(:user) { Fabricate(:user, tracking_code: 'fake_tracking_code') } |
| 11 | + let(:protip) { Fabricate(:protip) } |
| 12 | + |
| 13 | + it 'associates the zombie like to the correct user' do |
| 14 | + zombie_like = Fabricate(:like, likable: protip, |
| 15 | + tracking_code: user.tracking_code) |
| 16 | + |
| 17 | + ProcessLikeJob.new.perform('associate_to_user', zombie_like.id) |
| 18 | + |
| 19 | + zombie_like.reload |
| 20 | + |
| 21 | + expect(zombie_like.user_id).to eql user.id |
| 22 | + end |
| 23 | + |
| 24 | + it 'destroys like that are invalid' do |
| 25 | + invalid_like = Like.new(value: 1, tracking_code: user.tracking_code) |
| 26 | + invalid_like.save(validate: false) |
| 27 | + |
| 28 | + ProcessLikeJob.new.perform('associate_to_user', invalid_like.id) |
| 29 | + |
| 30 | + expect(Like.where(id: invalid_like.id)).not_to exist |
| 31 | + end |
| 32 | + |
| 33 | + it 'destroys likes that are non-unique' do |
| 34 | + original_like = Fabricate(:like, user: user, likable: protip) |
| 35 | + |
| 36 | + duplicate_like = Fabricate(:like, likable: protip, |
| 37 | + tracking_code: user.tracking_code) |
| 38 | + |
| 39 | + ProcessLikeJob.new.perform('associate_to_user', duplicate_like.id) |
| 40 | + |
| 41 | + expect(Like.where(id: duplicate_like.id)).not_to exist |
| 42 | + end |
| 43 | + |
| 44 | + it 'destroys likes if no user with the tracking code exists' do |
| 45 | + unassociatable_like = Fabricate(:like, likable: protip, |
| 46 | + tracking_code: 'unassociatable_tracking_code') |
| 47 | + |
| 48 | + ProcessLikeJob.new.perform('associate_to_user', unassociatable_like.id) |
| 49 | + |
| 50 | + expect(Like.where(id: unassociatable_like.id)).not_to exist |
| 51 | + end |
| 52 | + end |
| 53 | + |
9 | 54 | end
|
0 commit comments