Merge branch 'next-minor' into develop

This commit is contained in:
Benjamin Neff 2019-07-04 02:30:38 +02:00
commit e63fa7a398
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
3 changed files with 15 additions and 9 deletions

View file

@ -153,12 +153,7 @@ class PhotosController < ApplicationController
current_user.dispatch_post(@photo, to: photo_params[:aspect_ids]) current_user.dispatch_post(@photo, to: photo_params[:aspect_ids])
end end
if photo_params[:set_profile_photo] current_user.update_profile(photo: @photo) if photo_params[:set_profile_photo]
profile_params = {image_url: @photo.url(:thumb_large),
image_url_medium: @photo.url(:thumb_medium),
image_url_small: @photo.url(:thumb_small)}
current_user.update_profile(profile_params)
end
respond_to do |format| respond_to do |format|
format.json { render(layout: false, json: {"success" => true, "data" => @photo}.to_json) } format.json { render(layout: false, json: {"success" => true, "data" => @photo}.to_json) }

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class FixPendingProfilePhotos < ActiveRecord::Migration[5.1]
def up
Photo.where(pending: true).each do |photo|
photo.update(pending: false) if Profile.where(image_url: photo.url(:thumb_large)).exists?
end
end
end

View file

@ -44,7 +44,7 @@ describe PhotosController, :type => :controller do
describe '#create' do describe '#create' do
before do before do
allow(@controller).to receive(:file_handler).and_return(uploaded_photo) allow(@controller).to receive(:file_handler).and_return(uploaded_photo)
@params = {:photo => {:user_file => uploaded_photo, :aspect_ids => "all"} } @params = {photo: {user_file: uploaded_photo, aspect_ids: "all", pending: true}}
end end
it "creates a photo" do it "creates a photo" do
@ -67,11 +67,13 @@ describe PhotosController, :type => :controller do
expect(Photo.last.author).to eq(alice.person) expect(Photo.last.author).to eq(alice.person)
end end
it 'can set the photo as the profile photo' do it "can set the photo as the profile photo and unpends the photo" do
old_url = alice.person.profile.image_url old_url = alice.person.profile.image_url
@params[:photo][:set_profile_photo] = true @params[:photo][:set_profile_photo] = true
post :create, params: @params post :create, params: @params
expect(alice.reload.person.profile.image_url).not_to eq(old_url) new_url = alice.reload.person.profile.image_url
expect(new_url).not_to eq(old_url)
expect(Photo.find_by(remote_photo_name: new_url.rpartition("_").last).pending).to be_falsey
end end
end end