mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-25 09:19:15 -04:00
Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f08e740ac6 | ||
|
|
5f23bcfad6 | ||
|
|
3cd7b86c99 | ||
|
|
bd53d4a271 | ||
|
|
16d88730ec | ||
|
|
5ad88eb6bd | ||
|
|
b617eb3140 | ||
|
|
acc4d3ad84 | ||
|
|
beb3f7e2b8 | ||
|
|
ab46a8dd96 | ||
|
|
b6b578d7e6 | ||
|
|
4d07cf80fa | ||
|
|
93f6b65d8d | ||
|
|
b40a6723e1 | ||
|
|
2058d28b37 | ||
|
|
682c6d6f5e | ||
|
|
2be55acc92 | ||
|
|
a9a040182c | ||
|
|
53eb171dfc | ||
|
|
b0b6931678 | ||
|
|
d515dba7f2 | ||
|
|
4958330c9e | ||
|
|
17236a4a8a | ||
|
|
3ccab3f857 | ||
|
|
0201e873eb | ||
|
|
20289e6566 | ||
|
|
85ded414ec | ||
|
|
299c95c5f5 | ||
|
|
8f51090098 | ||
|
|
5551eeba24 | ||
|
|
7a5a68f511 | ||
|
|
6d4ec9ad34 | ||
|
|
fffef75813 | ||
|
|
0e2d7b4393 | ||
|
|
f08068c289 | ||
|
|
ff653934ad | ||
|
|
c4bed2cf4d | ||
|
|
47c0f74f81 | ||
|
|
171e34914b | ||
|
|
8010a8b56c | ||
|
|
ac165ce0cd | ||
|
|
4925fde28f | ||
|
|
6580cf38b0 | ||
|
|
fdf10202ba | ||
|
|
85a368999b | ||
|
|
6ba4b4560e | ||
|
|
71aedb136a | ||
|
|
65c988790b | ||
|
|
0372d3b9b0 | ||
|
|
3272ea1ca5 | ||
|
|
5392d7d900 | ||
|
|
45f2abeab5 |
@@ -1,3 +1,9 @@
|
||||
linters:
|
||||
LineLength:
|
||||
max: 120
|
||||
InstanceVariables:
|
||||
enabled: false
|
||||
IdNames:
|
||||
enabled: false
|
||||
ConsecutiveComments:
|
||||
enabled: false
|
||||
|
||||
3
.mention-bot
Normal file
3
.mention-bot
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"userBlacklist": ["tygriffin","oshiho3"]
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
2
Gemfile
2
Gemfile
@@ -122,7 +122,7 @@ group :development, :test do
|
||||
gem 'factory_girl_rails' # for creating test data
|
||||
gem 'haml-i18n-extractor'
|
||||
gem 'haml-rails' # HTML templating language
|
||||
gem 'haml_lint', '~> 0.20.0' # Checks haml files for goodness
|
||||
gem 'haml_lint' # Checks haml files for goodness
|
||||
gem 'i18n-tasks' # adds tests for finding missing and unused translations
|
||||
gem 'jasmine' # javascript unit testing
|
||||
gem 'poltergeist' # for headless JS testing
|
||||
|
||||
37
Gemfile.lock
37
Gemfile.lock
@@ -25,7 +25,7 @@ GEM
|
||||
addressable
|
||||
active_merchant-paypal-bogus-gateway (0.1.0)
|
||||
activemerchant
|
||||
active_utils (3.3.1)
|
||||
active_utils (3.3.3)
|
||||
activesupport (>= 3.2, < 5.2.0)
|
||||
i18n
|
||||
activejob (4.2.8)
|
||||
@@ -52,7 +52,7 @@ GEM
|
||||
public_suffix (~> 2.0, >= 2.0.2)
|
||||
arel (6.0.4)
|
||||
ast (2.3.0)
|
||||
autoprefixer-rails (6.7.7.1)
|
||||
autoprefixer-rails (6.7.7.2)
|
||||
execjs
|
||||
bcrypt (3.1.11)
|
||||
better_errors (2.1.1)
|
||||
@@ -153,17 +153,17 @@ GEM
|
||||
json
|
||||
thread
|
||||
thread_safe
|
||||
elasticsearch (2.0.1)
|
||||
elasticsearch-api (= 2.0.1)
|
||||
elasticsearch-transport (= 2.0.1)
|
||||
elasticsearch-api (2.0.1)
|
||||
elasticsearch (2.0.2)
|
||||
elasticsearch-api (= 2.0.2)
|
||||
elasticsearch-transport (= 2.0.2)
|
||||
elasticsearch-api (2.0.2)
|
||||
multi_json
|
||||
elasticsearch-model (0.1.9)
|
||||
activesupport (> 3)
|
||||
elasticsearch (> 0.4)
|
||||
hashie
|
||||
elasticsearch-rails (0.1.9)
|
||||
elasticsearch-transport (2.0.1)
|
||||
elasticsearch-transport (2.0.2)
|
||||
faraday
|
||||
multi_json
|
||||
erubis (2.7.0)
|
||||
@@ -189,8 +189,8 @@ GEM
|
||||
gibbon (1.2.1)
|
||||
httparty
|
||||
multi_json (>= 1.9.0)
|
||||
globalid (0.3.7)
|
||||
activesupport (>= 4.1.0)
|
||||
globalid (0.4.0)
|
||||
activesupport (>= 4.2.0)
|
||||
gravatar-ultimate (2.0.0)
|
||||
activesupport (>= 2.3.14)
|
||||
rack
|
||||
@@ -222,8 +222,9 @@ GEM
|
||||
haml (>= 4.0.6, < 5.0)
|
||||
html2haml (>= 1.0.1)
|
||||
railties (>= 4.0.1)
|
||||
haml_lint (0.20.0)
|
||||
haml (~> 4.0)
|
||||
haml_lint (0.24.0)
|
||||
haml (>= 4.0, < 5.1)
|
||||
rainbow
|
||||
rake (>= 10, < 13)
|
||||
rubocop (>= 0.47.0)
|
||||
sysexits (~> 1.1)
|
||||
@@ -265,7 +266,7 @@ GEM
|
||||
js-routes (1.3.3)
|
||||
railties (>= 3.2)
|
||||
sprockets-rails
|
||||
json (2.0.3)
|
||||
json (2.0.4)
|
||||
jwt (1.5.6)
|
||||
kaminari (0.17.0)
|
||||
actionpack (>= 3.0.0)
|
||||
@@ -300,7 +301,7 @@ GEM
|
||||
multi_xml (0.6.0)
|
||||
multipart-post (2.0.0)
|
||||
nenv (0.3.0)
|
||||
newrelic_rpm (4.0.0.332)
|
||||
newrelic_rpm (4.1.0.333)
|
||||
nokogiri (1.7.1)
|
||||
mini_portile2 (~> 2.1.0)
|
||||
notiffany (0.1.1)
|
||||
@@ -435,7 +436,7 @@ GEM
|
||||
ruby-progressbar (1.8.1)
|
||||
ruby-units (2.1.0)
|
||||
ruby_dep (1.5.0)
|
||||
ruby_parser (3.8.4)
|
||||
ruby_parser (3.9.0)
|
||||
sexp_processor (~> 4.1)
|
||||
rubyzip (1.2.1)
|
||||
sass (3.4.23)
|
||||
@@ -449,7 +450,7 @@ GEM
|
||||
childprocess (~> 0.5)
|
||||
rubyzip (~> 1.0)
|
||||
websocket (~> 1.0)
|
||||
sexp_processor (4.8.0)
|
||||
sexp_processor (4.9.0)
|
||||
shellany (0.0.1)
|
||||
sidekiq (4.2.10)
|
||||
concurrent-ruby (~> 1.0)
|
||||
@@ -472,7 +473,7 @@ GEM
|
||||
activesupport (>= 4.0)
|
||||
sprockets (>= 3.0.0)
|
||||
sysexits (1.2.0)
|
||||
term-ansicolor (1.5.0)
|
||||
term-ansicolor (1.6.0)
|
||||
tins (~> 1.0)
|
||||
terminal-table (1.7.3)
|
||||
unicode-display_width (~> 1.1.1)
|
||||
@@ -488,7 +489,7 @@ GEM
|
||||
execjs (>= 0.3.0)
|
||||
json (>= 1.8.0)
|
||||
unicode-display_width (1.1.3)
|
||||
unicorn (5.2.0)
|
||||
unicorn (5.3.0)
|
||||
kgio (~> 2.6)
|
||||
raindrops (~> 0.7)
|
||||
uniform_notifier (1.10.0)
|
||||
@@ -552,7 +553,7 @@ DEPENDENCIES
|
||||
haml
|
||||
haml-i18n-extractor
|
||||
haml-rails
|
||||
haml_lint (~> 0.20.0)
|
||||
haml_lint
|
||||
hashie (>= 3.5.3)
|
||||
heroku-api
|
||||
i18n-tasks
|
||||
|
||||
@@ -333,3 +333,6 @@ $state-success-bg: lighten($green, 50%)
|
||||
overflow: hidden
|
||||
text-overflow: ellipsis
|
||||
white-space: nowrap
|
||||
|
||||
ul.plantings
|
||||
list-style-type: none
|
||||
|
||||
@@ -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'])
|
||||
|
||||
13
app/controllers/photo_associations_controller.rb
Normal file
13
app/controllers/photo_associations_controller.rb
Normal 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
|
||||
@@ -21,13 +21,14 @@ module GardensHelper
|
||||
if plantings.blank?
|
||||
"None"
|
||||
else
|
||||
output = ""
|
||||
plantings.first(2).each do |planting|
|
||||
output = '<ul class="plantings">'
|
||||
plantings.each do |planting|
|
||||
output += "<li>"
|
||||
output += planting.quantity.nil? ? "0 " : "#{planting.quantity} "
|
||||
output += link_to planting.crop.name, planting.crop
|
||||
output += ", planted on #{planting.planted_at}</li>"
|
||||
end
|
||||
output += '</ul>'
|
||||
output.html_safe
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ class Garden < ActiveRecord::Base
|
||||
include PhotoCapable
|
||||
friendly_id :garden_slug, use: [:slugged, :finders]
|
||||
|
||||
belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id'
|
||||
belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id', counter_cache: true
|
||||
has_many :plantings, -> { order(created_at: :desc) }, dependent: :destroy
|
||||
has_many :crops, through: :plantings
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -5,7 +5,7 @@ class Harvest < ActiveRecord::Base
|
||||
friendly_id :harvest_slug, use: [:slugged, :finders]
|
||||
|
||||
belongs_to :crop
|
||||
belongs_to :owner, class_name: 'Member'
|
||||
belongs_to :owner, class_name: 'Member', counter_cache: true
|
||||
belongs_to :plant_part
|
||||
belongs_to :planting
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class Member < ActiveRecord::Base
|
||||
.has_plantings
|
||||
}
|
||||
|
||||
scope :has_plantings, -> { joins(:plantings).where("plantings.id IS NOT NULL") }
|
||||
scope :has_plantings, -> { joins(:plantings).group("members.id") }
|
||||
|
||||
has_many :follows, class_name: "Follow", foreign_key: "follower_id"
|
||||
has_many :followed, through: :follows
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,7 +4,7 @@ class Seed < ActiveRecord::Base
|
||||
friendly_id :seed_slug, use: [:slugged, :finders]
|
||||
|
||||
belongs_to :crop
|
||||
belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id'
|
||||
belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id', counter_cache: true
|
||||
|
||||
default_scope { order("created_at desc") }
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
.panel.panel-success
|
||||
.panel-heading
|
||||
%h3.panel-title
|
||||
= link_to display_garden_name(garden), garden
|
||||
= link_to display_garden_name(garden), garden_path(garden)
|
||||
- if can? :edit, garden
|
||||
%a.pull-right{ href: edit_garden_path(garden), role: "button", id: "edit_garden_glyphicon" }
|
||||
%span.glyphicon.glyphicon-pencil{ title: "Edit" }
|
||||
@@ -14,7 +14,7 @@
|
||||
.col-md-8
|
||||
%dl.dl-horizontal
|
||||
%dt Name :
|
||||
%dd= link_to display_garden_name(garden), garden
|
||||
%dd= link_to display_garden_name(garden), garden_path(garden)
|
||||
%dt Location :
|
||||
%dd
|
||||
- if garden.location.blank?
|
||||
@@ -29,11 +29,9 @@
|
||||
%b
|
||||
= localize_plural(garden.plantings, Planting)
|
||||
= ":"
|
||||
= display_garden_plantings(garden.plantings.current)
|
||||
= display_garden_plantings(garden.plantings.current.includes(:crop).first(2))
|
||||
- if garden.plantings.size > 2
|
||||
%br
|
||||
= link_to "See more plantings >>", garden_path(garden)
|
||||
.panel-footer
|
||||
%dt Description
|
||||
%dd
|
||||
= display_garden_description(garden)
|
||||
%dd= display_garden_description(garden)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
4
app/views/photos/_photo_association_delete.haml
Normal file
4
app/views/photos/_photo_association_delete.haml
Normal 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" }
|
||||
21
app/views/photos/_photo_associations.html.haml
Normal file
21
app/views/photos/_photo_associations.html.haml
Normal 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 }
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
- if planting.harvests
|
||||
- unless planting.harvests.empty?
|
||||
Harvests:
|
||||
%ul
|
||||
- planting.harvests.each do |harvest|
|
||||
|
||||
@@ -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'
|
||||
|
||||
15
db/migrate/20170413221549_counter_caches.rb
Normal file
15
db/migrate/20170413221549_counter_caches.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class CounterCaches < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :members, :gardens_count, :integer
|
||||
add_column :members, :harvests_count, :integer
|
||||
add_column :members, :seeds_count, :integer
|
||||
|
||||
Member.find_each do |member|
|
||||
Member.reset_counters(member.id, :gardens)
|
||||
Member.reset_counters(member.id, :harvests)
|
||||
Member.reset_counters(member.id, :seeds)
|
||||
Member.reset_counters(member.id, :plantings)
|
||||
say "Member #{member.login_name} counter caches updated"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170104035248) do
|
||||
ActiveRecord::Schema.define(version: 20170413221549) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -323,6 +323,9 @@ ActiveRecord::Schema.define(version: 20170104035248) do
|
||||
t.boolean "newsletter"
|
||||
t.boolean "send_planting_reminder", default: true
|
||||
t.string "preferred_avatar_uri"
|
||||
t.integer "gardens_count"
|
||||
t.integer "harvests_count"
|
||||
t.integer "seeds_count"
|
||||
end
|
||||
|
||||
add_index "members", ["confirmation_token"], name: "index_members_on_confirmation_token", unique: true, using: :btree
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
set -euv
|
||||
|
||||
gem install overcommit rubocop haml-lint bundler-audit
|
||||
gem install --update overcommit rubocop haml-lint bundler-audit
|
||||
npm install
|
||||
pip install yamllint --user
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
# Git pre-commit hook
|
||||
# To install, run "rake hooks"
|
||||
|
||||
if git diff-index --quiet HEAD --; then
|
||||
# no changes between index and working copy; just run tests
|
||||
rspec spec
|
||||
else
|
||||
# Test the version that's about to be committed,
|
||||
# stashing all unindexed changes
|
||||
git stash -q --keep-index
|
||||
rspec spec
|
||||
git stash pop -q
|
||||
fi
|
||||
41
spec/controllers/photo_associations_controller_spec.rb
Normal file
41
spec/controllers/photo_associations_controller_spec.rb
Normal 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
|
||||
@@ -42,10 +42,10 @@ describe GardensHelper do
|
||||
plantings = [FactoryGirl.create(:planting, quantity: 10, crop: crop)]
|
||||
result = helper.display_garden_plantings(plantings)
|
||||
|
||||
output = "<li>"
|
||||
output = '<ul class="plantings"><li>'
|
||||
output += "10 " + link_to(crop.name, crop)
|
||||
output += ", planted on #{plantings.first.planted_at}"
|
||||
output += "</li>"
|
||||
output += "</li></ul>"
|
||||
expect(result).to eq output
|
||||
end
|
||||
|
||||
@@ -58,16 +58,16 @@ describe GardensHelper do
|
||||
crop2 = FactoryGirl.create(:crop)
|
||||
plantings << FactoryGirl.create(:planting, quantity: 10, crop: crop2)
|
||||
|
||||
result = helper.display_garden_plantings(plantings)
|
||||
result = helper.display_garden_plantings(plantings.first(2))
|
||||
|
||||
output = "<li>"
|
||||
output = '<ul class="plantings"><li>'
|
||||
output += "10 " + link_to(crop1.name, crop1)
|
||||
output += ", planted on #{plantings.first.planted_at}"
|
||||
output += "</li>"
|
||||
output += "<li>"
|
||||
output += "10 " + link_to(crop2.name, crop2)
|
||||
output += ", planted on #{plantings.first.planted_at}"
|
||||
output += "</li>"
|
||||
output += "</li></ul>"
|
||||
expect(result).to eq output
|
||||
end
|
||||
|
||||
@@ -83,16 +83,16 @@ describe GardensHelper do
|
||||
crop3 = FactoryGirl.create(:crop)
|
||||
plantings << FactoryGirl.create(:planting, quantity: 10, crop: crop3)
|
||||
|
||||
result = helper.display_garden_plantings(plantings)
|
||||
result = helper.display_garden_plantings(plantings.first(2))
|
||||
|
||||
output = "<li>"
|
||||
output = '<ul class="plantings"><li>'
|
||||
output += "10 " + link_to(crop1.name, crop1)
|
||||
output += ", planted on #{plantings.first.planted_at}"
|
||||
output += "</li>"
|
||||
output += "<li>"
|
||||
output += "10 " + link_to(crop2.name, crop2)
|
||||
output += ", planted on #{plantings.first.planted_at}"
|
||||
output += "</li>"
|
||||
output += "</li></ul>"
|
||||
expect(result).to eq output
|
||||
end
|
||||
end
|
||||
|
||||
@@ -264,30 +264,43 @@ describe 'member' do
|
||||
end
|
||||
end
|
||||
|
||||
context 'interesting scope' do
|
||||
describe 'interesting scope' do
|
||||
# interesting members are defined as:
|
||||
# 1) confirmed
|
||||
# 2) have a location
|
||||
# 3) have at least one planting
|
||||
# 4) ordered by the most recent sign in
|
||||
|
||||
it 'finds interesting members' do
|
||||
members = [
|
||||
:london_member, :london_member, :london_member,
|
||||
:unconfirmed_member, # !1
|
||||
:london_member, # 1, 2, !3
|
||||
:member # 1, !2, 3
|
||||
].collect { |m| FactoryGirl.create(m) }
|
||||
context 'with a few members and plantings' do
|
||||
before :each do
|
||||
@members = [
|
||||
:london_member, :london_member, :london_member,
|
||||
:unconfirmed_member, # !1
|
||||
:london_member, # 1, 2, !3
|
||||
:member # 1, !2, 3
|
||||
].collect { |m| FactoryGirl.create(m) }
|
||||
|
||||
[0, 1, 2, 3, 5].each do |i|
|
||||
FactoryGirl.create(:planting, owner: members[i])
|
||||
[0, 1, 2, 3, 5].each do |i|
|
||||
FactoryGirl.create(:planting, owner: @members[i])
|
||||
end
|
||||
|
||||
@members[0].updated_at = 3.days.ago
|
||||
@members[1].updated_at = 2.days.ago
|
||||
@members[2].updated_at = 1.day.ago
|
||||
|
||||
# TODO: Shouldn't this save?
|
||||
|
||||
@result = Member.interesting
|
||||
|
||||
# Some members have multiple plantings, but should only appear once
|
||||
3.times do
|
||||
FactoryGirl.create(:planting, owner: @members[2])
|
||||
end
|
||||
end
|
||||
|
||||
members[0].updated_at = 3.days.ago
|
||||
members[1].updated_at = 2.days.ago
|
||||
members[2].updated_at = 1.day.ago
|
||||
|
||||
Member.interesting.should eq [members[2], members[1], members[0]]
|
||||
it 'finds interesting members without duplicates in the correct order' do
|
||||
@result.should eq [@members[2], @members[1], @members[0]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user