summaryrefslogtreecommitdiff
path: root/spec/controllers/api/v1/photos_controller_spec.rb
blob: 193d011c689bf4422dc462cdfba29e0a40fbdb8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require "rails_helper"

module Api
  module V1
    describe PhotosController do
      render_views

      let(:user) { create(:user) }
      let!(:cake) { create(:creation, user: user) }

      before :each do
        api_login(user)
      end

      describe "#index" do
        it "loads the cakes photos" do
          get :index, params: { cake_id: cake.id }, xhr: true
          expect(assigns(:photos)).to match_array(cake.photos)
        end
      end

      describe "#show" do
        let(:photo) { create(:photo, imageable: cake) }

        it "loads the photo" do
          get :show, params: { cake_id: cake.id, id: photo.id }, xhr: true
          expect(assigns(:photo)).to eql(photo)
        end
      end

      describe "#create" do
        let(:file) { fixture_file_upload("images/example.png", "image/png") }

        it "attaches a new photo to a cake" do
          allow(ProcessPhotoJob).to receive(:perform_later)

          post :create, params: { cake_id: cake.id, watermark: "watery", image: file }, xhr: true

          cake.reload
          expect(cake.photos.count).to eql(1)
          expect(cake.photos.first.watermark).to eql("watery")
          expect(cake.photos.first.image_processing).to be_truthy
          expect(ProcessPhotoJob).to have_received(:perform_later)
        end
      end
    end
  end
end