mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-13 18:55:45 -04:00
Don't recreate photos, but update metadata.
This commit is contained in:
@@ -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" }
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
%p#notice= notice
|
||||
|
||||
= image_tag(@photo.fullsize_url, :alt => 'A plant', :class => 'img-rounded')
|
||||
|
||||
%p
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user