master
1require "rails_helper"
2
3describe My::AvatarsController do
4 let(:user) { create(:user) }
5
6 context "when logged in " do
7 before { http_login(user) }
8
9 describe "#create" do
10 context "when uploading a new avatar" do
11 let(:image) { Rack::Test::UploadedFile.new('spec/fixtures/images/gorilla.jpg', 'image/jpeg') }
12
13 before { post :create, params: { photo: { image: image } } }
14
15 it "saves the new avatar" do
16 user.reload
17 expect(user.avatar).to_not be_nil
18 expect(user.avatar.image).to_not be_blank
19 end
20
21 it "redirects to the avatar page" do
22 expect(response).to redirect_to(new_my_avatar_path)
23 end
24
25 it "displays a flash notice" do
26 expect(flash[:notice]).to_not be_nil
27 end
28 end
29 end
30
31 describe "#new" do
32 before { get :new, params: { id: user.id } }
33
34 it "displays the current avatar" do
35 expect(assigns(:avatar)).to_not be_nil
36 end
37 end
38 end
39end