Compare commits

..

18 Commits

Author SHA1 Message Date
Brenda Wallace
f08e740ac6 Removed owner_matches?
it's not used anymore
2017-04-19 08:22:03 +00:00
Brenda Wallace
5f23bcfad6 Photo#show for signed in and not signed in, and other members 2017-04-19 08:22:03 +00:00
Brenda Wallace
3cd7b86c99 Photos#show links to items 2017-04-19 08:22:03 +00:00
Brenda Wallace
bd53d4a271 updating view spec - link to delete photo has changed 2017-04-19 08:22:03 +00:00
Brenda Wallace
16d88730ec controller specs for PhotoAssociations 2017-04-19 08:22:03 +00:00
Brenda Wallace
5ad88eb6bd Responsive image on photos#show 2017-04-19 08:22:03 +00:00
Brenda Wallace
b617eb3140 Deleting photo's association with another item 2017-04-19 08:22:03 +00:00
Brenda Wallace
acc4d3ad84 Only delete own associations 2017-04-19 08:22:03 +00:00
Brenda Wallace
beb3f7e2b8 Don't overwrite edited photo titles 2017-04-19 08:22:03 +00:00
Brenda Wallace
ab46a8dd96 UI for removing photos from plantings 2017-04-19 08:22:03 +00:00
Brenda Wallace
b6b578d7e6 Layout change on photos 2017-04-19 08:22:03 +00:00
Brenda Wallace
4d07cf80fa Editing title of photos 2017-04-19 08:22:03 +00:00
Brenda Wallace
93f6b65d8d bugfix: Only show harvests if we have some 2017-04-19 08:22:03 +00:00
Brenda Wallace
b40a6723e1 gardens#show Include crop, owner, harvesss and garden in query 2017-04-19 08:22:03 +00:00
Brenda Wallace
2058d28b37 Include owner in query, because we need it later 2017-04-19 08:22:03 +00:00
Brenda Wallace
682c6d6f5e Reduced query count by .includes() on plantings 2017-04-19 08:22:03 +00:00
Brenda Wallace
2be55acc92 Route for flickr auth callback -- Fixes #1106 2017-04-19 08:22:03 +00:00
Brenda Wallace
a9a040182c Rubocop compliance for members controller 2017-04-19 08:22:03 +00:00
16 changed files with 202 additions and 60 deletions

View File

@@ -109,7 +109,6 @@ Style/BarePercentLiterals:
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'app/controllers/members_controller.rb'
- 'spec/controllers/order_items_controller_spec.rb'
- 'spec/features/notifications_spec.rb'
- 'spec/models/ability_spec.rb'
@@ -123,7 +122,6 @@ Style/BlockDelimiters:
# Cop supports --auto-correct.
Style/BlockEndNewline:
Exclude:
- 'app/controllers/members_controller.rb'
- 'spec/models/ability_spec.rb'
- 'spec/models/member_spec.rb'
- 'spec/models/planting_spec.rb'
@@ -223,7 +221,6 @@ Style/MultilineTernaryOperator:
# Cop supports --auto-correct.
Style/MutableConstant:
Exclude:
- 'app/controllers/members_controller.rb'
- 'app/models/planting.rb'
# Cop supports --auto-correct.

View File

@@ -14,13 +14,13 @@ class MembersController < ApplicationController
respond_to do |format|
format.html # index.html.haml
format.json {
format.json do
render json: @members.to_json(only: [
:id, :login_name,
:slug, :bio, :created_at,
:location, :latitude, :longitude
])
}
end
end
end
@@ -38,18 +38,19 @@ class MembersController < ApplicationController
respond_to do |format|
format.html # show.html.haml
format.json {
format.json do
render json: @member.to_json(only: [
:id, :login_name, :bio,
:created_at, :slug, :location,
:latitude, :longitude
])
}
format.rss {
end
format.rss do
render(
layout: false,
locals: { member: @member }
)}
)
end
end
end
@@ -66,7 +67,7 @@ class MembersController < ApplicationController
EMAIL_TYPE_STRING = {
send_notification_email: "direct message notifications",
send_planting_reminder: "planting reminders"
}
}.freeze
def unsubscribe
verifier = ActiveSupport::MessageVerifier.new(ENV['RAILS_SECRET_TOKEN'])

View File

@@ -0,0 +1,13 @@
class PhotoAssociationsController < ApplicationController
before_action :authenticate_member!
respond_to :json, :html
def destroy
@photo = Photo.find_by!(id: params[:photo_id], owner: current_member)
collection = Growstuff::Constants::PhotoModels.get_relation(@photo, params[:type])
item_class = Growstuff::Constants::PhotoModels.get_item(params[:type])
@item = item_class.find_by!(id: params[:id], owner_id: current_member.id)
collection.delete(@item)
respond_with(@photo)
end
end

View File

@@ -62,7 +62,7 @@ class Garden < ActiveRecord::Base
unique_plantings = []
seen_crops = []
plantings.each do |p|
plantings.includes(:garden, :crop, :owner, :harvests).each do |p|
unless seen_crops.include?(p.crop)
unique_plantings.push(p)
seen_crops.push(p.crop)

View File

@@ -10,6 +10,10 @@ class Photo < ActiveRecord::Base
default_scope { order("created_at desc") }
def associations?
plantings.any? || harvests.any? || gardens.any? || seeds.any?
end
def all_associations
associations = []
Growstuff::Constants::PhotoModels.relations.each do |association_name|
@@ -30,7 +34,7 @@ class Photo < ActiveRecord::Base
licenses = flickr.photos.licenses.getInfo
license = licenses.find { |l| l.id == info.license }
{
title: info.title || "Untitled",
title: calculate_title(info),
license_name: license.name,
license_url: license.url,
thumbnail_url: FlickRaw.url_q(info),
@@ -39,6 +43,16 @@ class Photo < ActiveRecord::Base
}
end
def calculate_title(info)
if id && title # already has a title saved
title
elsif info.title # use title from flickr
info.title
else
'untitled'
end
end
def set_flickr_metadata
update_attributes(flickr_metadata)
end

View File

@@ -55,7 +55,7 @@
%p= localize_plural(@garden.photos, Photo)
.row-fluid
%ul.thumbnails
- @garden.photos.each do |p|
- @garden.photos.includes(:owner).each do |p|
.col-md-2.six-across
= render partial: 'photos/thumbnail', locals: { photo: p }
.row-fluid
@@ -68,7 +68,7 @@
- if @garden.plantings.current.empty?
%p Nothing is currently planted here.
- else
- @garden.plantings.current.each.with_index do |planting_current, _|
- @garden.plantings.current.includes(:crop, :owner, :harvests, :garden).each.with_index do |planting_current, _|
= render partial: "plantings/thumbnail", locals: { planting: planting_current }
.row-fluid

View File

@@ -36,7 +36,7 @@
%p= localize_plural(g.photos, Photo)
.row
%ul.thumbnails
- g.photos.each do |p|
- g.photos.includes(:owner).each do |p|
.col-md-2.six-across
= render partial: 'photos/thumbnail', locals: { photo: p }
.row

View File

@@ -0,0 +1,4 @@
- if can? :edit, photo
= link_to photo_associations_path(photo_id: photo.id, type: type, id: thing.id),
method: 'delete', class: 'btn btn-default btn-xs' do
%span.glyphicon.glyphicon-remove{ title: "Remove link" }

View File

@@ -0,0 +1,21 @@
%h4 This photo depicts:
%ul
- @photo.plantings.each do |planting|
%li
= link_to t('photos.show.planting', planting: planting.to_s, owner: planting.owner.to_s), planting_path(planting)
= render partial: "photo_association_delete", locals: { photo: @photo, type: 'planting', thing: planting }
- @photo.harvests.each do |harvest|
%li
= link_to t('photos.show.harvest', crop: harvest.crop.name, owner: harvest.owner.to_s), harvest_path(harvest)
= render partial: "photo_association_delete", locals: { photo: @photo, type: 'harvest', thing: harvest }
- @photo.gardens.each do |garden|
%li
= link_to t('photos.show.garden', garden: garden.to_s, owner: garden.owner.to_s), garden_path(garden)
= render partial: "photo_association_delete", locals: { photo: @photo, type: 'garden', thing: garden }
- @photo.seeds.each do |seed|
%li
= link_to t('photos.show.seed', seed: seed.to_s, owner: seed.owner.to_s), seed_path(seed)
= render partial: "photo_association_delete", locals: { photo: @photo, type: 'seed', thing: seed }

View File

@@ -1,2 +1,5 @@
- content_for :title, "Edit Photo"
= form_for(@photo) do |f|
= f.label :title
= f.text_field :title, placeholder: "title"
= f.submit

View File

@@ -36,5 +36,5 @@
- else
.alert
You must
= link_to "connect your account to Flickr", '/auth/flickr'
= link_to "connect your account to Flickr", '/members/auth/flickr'
to add photos.

View File

@@ -8,7 +8,19 @@
= tag("meta", property: "og:site_name", content: ENV['GROWSTUFF_SITE_NAME'])
.row
.col-md-6
.col-md-8
%p= image_tag(@photo.fullsize_url, alt: @photo.title, class: 'img img-responsive')
.col-md-4
%p
- if can? :destroy, @photo
= link_to @photo, method: :delete,
data: { confirm: 'Are you sure?' }, class: 'btn btn-default btn-xs' do
%span.glyphicon.glyphicon-trash{ title: "Delete" }
- if can? :edit, @photo
= link_to edit_photo_path(@photo), class: 'btn btn-default btn-xs' do
%span.glyphicon.glyphicon-pencil{ title: "Edit" }
%p
%strong Posted by:
= link_to @photo.owner, @photo.owner
@@ -19,30 +31,7 @@
- else
= succeed "." do
= @photo.license_name
%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-default btn-xs'
.col-md-6
- unless @photo.plantings.empty? && @photo.harvests.empty? && @photo.gardens.empty? && @photo.seeds.empty?
%p This photo depicts:
%ul
- @photo.plantings.each do |p|
%li= link_to t('.planting', planting: p.to_s, owner: p.owner.to_s), planting_path(p)
- @photo.harvests.each do |h|
%li= link_to t('.harvest', crop: h.crop.name, owner: h.owner.to_s), harvest_path(h)
- @photo.gardens.each do |g|
%li= link_to t('.garden', garden: g.to_s, owner: g.owner.to_s), garden_path(g)
- @photo.seeds.each do |s|
%li= link_to t('.seed', seed: s.to_s, owner: s.owner.to_s), seed_path(s)
.row
.col-md-12
%p= image_tag(@photo.fullsize_url, alt: @photo.title, class: 'img')
%p= link_to "View on Flickr", @photo.link_url
- if @photo.associations?
= render "photo_associations", locals: { photo: @photo }

View File

@@ -1,4 +1,4 @@
- if planting.harvests
- unless planting.harvests.empty?
Harvests:
%ul
- planting.harvests.each do |harvest|

View File

@@ -17,6 +17,7 @@ Growstuff::Application.routes.draw do
resources :members
resources :photos
delete 'photo_associations' => 'photo_associations#destroy'
resources :authentications, only: [:create, :destroy]
@@ -81,6 +82,7 @@ Growstuff::Application.routes.draw do
root to: 'home#index'
get 'auth/:provider/callback' => 'authentications#create'
get 'members/auth/:provider/callback' => 'authentications#create'
get '/shop' => 'shop#index'
get '/shop/:action' => 'shop#:action'

View File

@@ -0,0 +1,41 @@
require 'rails_helper'
describe PhotoAssociationsController do
login_member
describe "destroy" do
let(:valid_params) do
{
id: harvest.id,
type: 'harvest',
photo_id: photo.id
}
end
before { photo.harvests << harvest }
describe "my harvest my photo" do
let(:harvest) { FactoryGirl.create :harvest, owner: member }
let(:photo) { FactoryGirl.create :photo, owner: member }
it "removes link" do
expect { delete :destroy, valid_params }.to change { photo.harvests.count }.by(-1)
end
end
describe "another member's harvest from another member's photo" do
let(:harvest) { FactoryGirl.create :harvest }
let(:photo) { FactoryGirl.create :photo }
it do
expect do
begin
delete :destroy, valid_params
rescue
nil
end
end.not_to change { photo.harvests.count }
end
it { expect { delete :destroy, valid_params }.to raise_error(ActiveRecord::RecordNotFound) }
end
end
end

View File

@@ -13,17 +13,17 @@
require 'rails_helper'
describe "photos/show" do
before(:each) do
@member = FactoryGirl.create(:member)
controller.stub(:current_user) { @member }
end
let(:photo) { FactoryGirl.create :photo, owner: member }
before { @photo = photo }
context "CC-licensed photo" do
before(:each) do
@photo = assign(:photo, FactoryGirl.create(:photo, owner: @member))
render
end
let(:member) { FactoryGirl.create :member }
let(:harvest) { FactoryGirl.create :harvest, owner: member }
let(:planting) { FactoryGirl.create :planting, owner: member }
let(:seed) { FactoryGirl.create :seed, owner: member }
let(:garden) { FactoryGirl.create :garden, owner: member }
shared_examples "photo data renders" do
it "shows the image" do
assert_select "img[src='#{@photo.fullsize_url}']"
end
@@ -32,22 +32,79 @@ describe "photos/show" do
assert_select "a", href: @photo.owner
end
it "links to the CC license" do
assert_select "a", href: @photo.license_url,
text: @photo.license_name
end
it "shows a link to the original image" do
assert_select "a", href: @photo.link_url, text: "View on Flickr"
end
it "links to harvest" do
assert_select "a", href: harvest_path(harvest)
end
it "links to planting" do
assert_select "a", href: planting_path(planting)
end
it "links to garden" do
assert_select "a", href: garden_path(garden)
end
it "links to seeds" do
assert_select "a", href: seed_path(seed)
end
end
shared_examples "No links to change data" do
it "does not have a delete button" do
assert_select "a[href='#{photo_path(@photo)}']", false
end
end
context "signed in as owner" do
before(:each) do
controller.stub(:current_user) { member }
render
end
include_examples "photo data renders"
it "has a delete button" do
assert_select "a[href='#{photo_path(@photo)}']", 'Delete Photo'
assert_select "a[href='#{photo_path(@photo)}']"
end
end
context "signed in as another member" do
before(:each) do
controller.stub(:current_user) { FactoryGirl.create :member }
render
end
include_examples "photo data renders"
include_examples "No links to change data"
end
context "not signed in" do
before(:each) do
controller.stub(:current_user) { nil }
render
end
include_examples "photo data renders"
include_examples "No links to change data"
end
context "CC-licensed photo" do
before(:each) do
controller.stub(:current_user) { nil }
# @photo = assign(:photo, FactoryGirl.create(:photo, owner: @member))
@photo.harvests << harvest
@photo.plantings << planting
@photo.seeds << seed
@photo.gardens << garden
render
end
it "links to the CC license" do
assert_select "a", href: @photo.license_url,
text: @photo.license_name
end
end
context "unlicensed photo" do
before(:each) do
controller.stub(:current_user) { nil }
@photo = assign(:photo, FactoryGirl.create(:unlicensed_photo))
render
end