Don't recreate photos, but update metadata.

This commit is contained in:
Miles Gould
2013-05-31 11:48:24 +01:00
parent b1b24c4323
commit b2916e28f3
3 changed files with 14 additions and 4 deletions

View File

@@ -46,13 +46,14 @@ class PhotosController < ApplicationController
# POST /photos
# POST /photos.json
def create
@photo = Photo.new(params[:photo])
@photo = Photo.find_by_flickr_photo_id(params[:photo][:flickr_photo_id]) ||
Photo.new(params[:photo])
@photo.owner_id = current_member.id
@photo.set_flickr_metadata
respond_to do |format|
if @photo.save
format.html { redirect_to @photo, notice: 'Photo was successfully created.' }
format.html { redirect_to @photo, notice: 'Photo was successfully added.' }
format.json { render json: @photo, status: :created, location: @photo }
else
format.html { render action: "new" }

View File

@@ -1,5 +1,3 @@
%p#notice= notice
= image_tag(@photo.fullsize_url, :alt => 'A plant', :class => 'img-rounded')
%p

View File

@@ -91,6 +91,17 @@ describe PhotosController do
end
end
describe "for the second time" do
it "does not add a photo twice" do
expect {
post :create, {:photo => { :flickr_photo_id => 1 } }
}.to change(Photo, :count).by(1)
expect {
post :create, {:photo => { :flickr_photo_id => 1 } }
}.to change(Photo, :count).by(0)
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved photo as @photo" do
# Trigger the behavior that occurs when invalid params are submitted