master
1require "rails_helper"
2
3module Api
4 module V1
5 describe PhotosController do
6 render_views
7
8 let(:user) { create(:user) }
9 let!(:cake) { create(:creation, user: user) }
10
11 before :each do
12 api_login(user)
13 end
14
15 describe "#index" do
16 it "loads the cakes photos" do
17 get :index, params: { cake_id: cake.id }, xhr: true
18 expect(assigns(:photos)).to match_array(cake.photos)
19 end
20 end
21
22 describe "#show" do
23 let(:photo) { create(:photo, imageable: cake) }
24
25 it "loads the photo" do
26 get :show, params: { cake_id: cake.id, id: photo.id }, xhr: true
27 expect(assigns(:photo)).to eql(photo)
28 end
29 end
30
31 describe "#create" do
32 let(:file) { fixture_file_upload("images/example.png", "image/png") }
33
34 it "attaches a new photo to a cake" do
35 allow(ProcessPhotoJob).to receive(:perform_later)
36
37 post :create, params: { cake_id: cake.id, watermark: "watery", image: file }, xhr: true
38
39 cake.reload
40 expect(cake.photos.count).to eql(1)
41 expect(cake.photos.first.watermark).to eql("watery")
42 expect(cake.photos.first.image_processing).to be_truthy
43 expect(ProcessPhotoJob).to have_received(:perform_later)
44 end
45 end
46 end
47 end
48end