mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-25 16:28:24 -04:00
Delete photo from photos/show page
This commit is contained in:
1 parent
e9a78140d3
commit
a3d0f15fd5
6 files changed
+33
-3
No files matched your search
@@ -2,7 +2,9 @@ class Photo < ActiveRecord::Base
|
||||
attr_accessible :flickr_photo_id, :owner_id, :title, :license_name,
|
||||
:license_url, :thumbnail_url, :fullsize_url, :link_url
|
||||
belongs_to :owner, :class_name => 'Member'
|
||||
|
||||
has_and_belongs_to_many :plantings
|
||||
before_destroy {|photo| photo.plantings.clear}
|
||||
|
||||
default_scope order("created_at desc")
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ class Planting < ActiveRecord::Base
|
||||
|
||||
belongs_to :garden
|
||||
belongs_to :crop
|
||||
|
||||
has_and_belongs_to_many :photos
|
||||
before_destroy {|planting| planting.photos.clear}
|
||||
|
||||
default_scope order("created_at desc")
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
- content_for :title, "Photos"
|
||||
- content_for :title, "Photo Gallery"
|
||||
|
||||
%p This page shows all your photos.
|
||||
|
||||
%div.pagination
|
||||
= page_entries_info @photos, :model => "photos"
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
%p
|
||||
= link_to "View on Flickr", @photo.link_url
|
||||
|
||||
- if can? :destroy, @photo
|
||||
%p= link_to 'Delete Photo', @photo, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-mini'
|
||||
|
||||
.span6
|
||||
- if @photo.plantings.count > 0
|
||||
%p This photo depicts:
|
||||
|
||||
@@ -86,13 +86,24 @@ describe Planting do
|
||||
@planting.errors[:sunniness].should include("not valid is not a valid sunniness value")
|
||||
end
|
||||
|
||||
# we decided that all the tests for the planting/photo association would
|
||||
# be done on this side, not on the photos side
|
||||
context 'photos' do
|
||||
it 'has a photo' do
|
||||
before(:each) do
|
||||
@planting = FactoryGirl.create(:planting)
|
||||
@photo = FactoryGirl.create(:photo)
|
||||
@planting.photos << @photo
|
||||
end
|
||||
|
||||
it 'has a photo' do
|
||||
@planting.photos.first.should eq @photo
|
||||
end
|
||||
|
||||
it 'deletes association with photos when photo is deleted' do
|
||||
@photo.destroy
|
||||
@planting.reload
|
||||
@planting.photos.should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,9 +1,14 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "photos/show" do
|
||||
before(:each) do
|
||||
@member = FactoryGirl.create(:member)
|
||||
controller.stub(:current_user) { @member }
|
||||
end
|
||||
|
||||
context "CC-licensed photo" do
|
||||
before(:each) do
|
||||
@photo = assign(:photo, FactoryGirl.create(:photo))
|
||||
@photo = assign(:photo, FactoryGirl.create(:photo, :owner => @member))
|
||||
render
|
||||
end
|
||||
|
||||
@@ -23,6 +28,10 @@ describe "photos/show" do
|
||||
it "shows a link to the original image" do
|
||||
assert_select "a", :href => @photo.link_url, :text => "View on Flickr"
|
||||
end
|
||||
|
||||
it "has a delete button" do
|
||||
assert_select "a[href=#{photo_path(@photo)}]", 'Delete Photo'
|
||||
end
|
||||
end
|
||||
|
||||
context "unlicensed photo" do
|
||||
@@ -34,6 +43,7 @@ describe "photos/show" do
|
||||
it "contains the phrase 'All rights reserved'" do
|
||||
rendered.should contain "All rights reserved"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "linked to a planting" do
|
||||
|
||||
Reference in new issue
Block a user