Compare commits

...

87 Commits

Author SHA1 Message Date
Cesy
812a6f5ec2 Merge pull request #1328 from Growstuff/dev
release 24
2017-04-28 07:31:21 +01:00
Shiny
f1b42ec699 Merge branch 'master' into dev 2017-04-25 13:14:40 +12:00
Brenda Wallace
26c17ea19c Plantings Thumbnails, fit to box 2017-04-25 10:58:17 +12:00
Brenda Wallace
acc75f80bf include harvests when retrieving data for plantings#index 2017-04-25 10:58:17 +12:00
Daniel O'Connor
a79a65363f Merge pull request #1326 from Br3nda/plantings-validators
Plantings validators
2017-04-24 17:47:41 +09:30
Shiny
dfeb4804e7 Merge branch 'dev' into plantings-validators 2017-04-23 19:35:37 +12:00
deppbot
9d20fafd06 Bundle Update on 2017-04-23 2017-04-23 19:35:23 +12:00
Shiny
e9a5ef0058 Merge branch 'dev' into plantings-validators 2017-04-22 20:50:29 +12:00
Brenda Wallace
d2378376e4 Plantings validators
Adding garden presence true.
Checks crop presence before crop approved
2017-04-22 20:48:48 +12:00
Daniel O'Connor
4b1b5d8a18 Merge pull request #1323 from Growstuff/bundle-update-2017-04-20-122131
Bundle Update on 2017-04-20
2017-04-20 15:27:04 +09:30
deppbot
a0770e80e7 Bundle Update on 2017-04-20 2017-04-20 12:21:32 +08:00
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
Shiny
f39fe94173 Merge branch 'master' into dev 2017-04-18 18:27:43 +00:00
Brenda Wallace
976bdbbd96 Removed owner_matches?
it's not used anymore
2017-04-18 07:09:47 +00:00
Brenda Wallace
cff1d8bfb9 Photo#show for signed in and not signed in, and other members 2017-04-18 07:09:47 +00:00
Brenda Wallace
bbdc54cb69 Photos#show links to items 2017-04-18 07:09:47 +00:00
Brenda Wallace
36f1f7b71a updating view spec - link to delete photo has changed 2017-04-18 07:09:47 +00:00
Brenda Wallace
e1731793dd controller specs for PhotoAssociations 2017-04-18 07:09:47 +00:00
Brenda Wallace
8ea3b27612 Responsive image on photos#show 2017-04-18 07:09:47 +00:00
Brenda Wallace
9469a69078 Deleting photo's association with another item 2017-04-18 07:09:47 +00:00
Brenda Wallace
cc46fe3336 Only delete own associations 2017-04-18 07:09:47 +00:00
Brenda Wallace
52b4064a2d Don't overwrite edited photo titles 2017-04-18 07:09:47 +00:00
Brenda Wallace
d367b9ef21 UI for removing photos from plantings 2017-04-18 07:09:47 +00:00
Brenda Wallace
4711e4669f Layout change on photos 2017-04-18 07:09:47 +00:00
Brenda Wallace
3e55024f98 Editing title of photos 2017-04-18 07:09:47 +00:00
Daniel O'Connor
ccf56bf944 Merge pull request #1321 from Br3nda/harvests-display
bugfix: Only show harvests if we have some
2017-04-18 12:24:01 +09:30
Shiny
42e51a9cf6 Merge branch 'dev' into harvests-display 2017-04-17 10:00:20 +00:00
Brenda Wallace
667e0cc0e3 bugfix: Only show harvests if we have some 2017-04-17 21:59:31 +12:00
Brenda Wallace
339830b3bb gardens#show Include crop, owner, harvesss and garden in query 2017-04-17 08:59:34 +00:00
Brenda Wallace
7770164672 Include owner in query, because we need it later 2017-04-17 08:59:34 +00:00
Brenda Wallace
f333607572 Reduced query count by .includes() on plantings 2017-04-17 08:59:34 +00:00
Brenda Wallace
87d3764eeb Route for flickr auth callback -- Fixes #1106 2017-04-17 08:28:52 +00:00
Cesy
faf487b719 Merge pull request #1314 from Br3nda/members-controller
Rubocop compliance for members controller
2017-04-17 09:13:26 +01:00
Shiny
53eb171dfc Merge pull request #1317 from Growstuff/dev
release 22
2017-04-17 05:00:59 +00:00
Shiny
3dbf0df19e Merge branch 'dev' into members-controller 2017-04-17 03:49:54 +00:00
deppbot
b0b6931678 Bundle Update on 2017-04-17 2017-04-17 03:45:39 +00:00
Shiny
cd272a6443 Merge branch 'dev' into members-controller 2017-04-16 09:44:32 +00:00
Daniel O'Connor
d515dba7f2 Merge pull request #1316 from Br3nda/garden-thumbnail
Garden thumbnail display cleanup
2017-04-16 15:50:52 +09:30
Shiny
4958330c9e Merge branch 'master' into dev 2017-04-16 02:42:38 +00:00
Brenda Wallace
17236a4a8a Garden thumbnail display cleanup 2017-04-16 13:48:22 +12:00
Brenda Wallace
936a8778ed Rubocop compliance for members controller 2017-04-16 12:03:48 +12:00
Daniel O'Connor
3ccab3f857 Merge pull request #1309 from Br3nda/fix_1305
Fix 1305
2017-04-15 17:11:02 +09:30
Daniel O'Connor
0201e873eb Merge branch 'dev' into fix_1305 2017-04-15 17:03:15 +09:30
Daniel O'Connor
20289e6566 Merge pull request #1310 from Br3nda/counter-caches
Adding counter caches
2017-04-15 17:01:20 +09:30
Shiny
85ded414ec Merge branch 'dev' into fix_1305 2017-04-15 06:50:16 +00:00
Shiny
299c95c5f5 Merge branch 'dev' into counter-caches 2017-04-14 07:40:19 +00:00
Taylor Griffin
8f51090098 make mentionbot settings file 2017-04-14 07:40:01 +00:00
deppbot
5551eeba24 Bundle Update on 2017-04-14 2017-04-14 07:10:10 +00:00
Shiny
7a5a68f511 Merge branch 'dev' into counter-caches 2017-04-14 01:44:44 +00:00
Shiny
6d4ec9ad34 Merge branch 'dev' into fix_1305 2017-04-14 01:44:35 +00:00
Brenda Wallace
fffef75813 Ignore ConsecutiveComments and IdNames in haml for now 2017-04-14 01:43:42 +00:00
Brenda Wallace
0e2d7b4393 Allow instance variables in partials for now 2017-04-14 01:43:42 +00:00
Brenda Wallace
f08068c289 Upgrade haml_lint 2017-04-14 01:43:42 +00:00
deppbot
ff653934ad Bundle Update on 2017-04-08 2017-04-14 01:43:42 +00:00
Brenda Wallace
c4bed2cf4d Merge branch 'haml-lint-fix' into counter-caches 2017-04-14 11:42:02 +12:00
Brenda Wallace
47c0f74f81 Ignore ConsecutiveComments and IdNames in haml for now 2017-04-14 11:40:52 +12:00
Brenda Wallace
171e34914b Allow instance variables in partials for now 2017-04-14 11:40:46 +12:00
Brenda Wallace
8010a8b56c Upgrade haml_lint 2017-04-14 11:40:40 +12:00
Brenda Wallace
ac165ce0cd Adding counter caches 2017-04-14 11:32:31 +12:00
Brenda Wallace
4925fde28f Ignore ConsecutiveComments and IdNames in haml for now 2017-04-14 09:43:16 +12:00
Brenda Wallace
6580cf38b0 Allow instance variables in partials for now 2017-04-13 23:02:16 +12:00
Brenda Wallace
fdf10202ba Upgrade haml_lint 2017-04-13 22:56:07 +12:00
Brenda Wallace
85a368999b we love rubocop 2017-04-13 14:30:51 +12:00
Daniel O'Connor
6ba4b4560e Fix #1305 by adding aggregation
Expand test coverage
member_id is owner_id on plantings
Argue with ActionView::Template::Error about what we can group on

Rename variable
2017-04-13 14:30:41 +12:00
Cesy
71aedb136a Merge pull request #1300 from Growstuff/bundle-update-2017-04-02-131809
Bundle Update on 2017-04-02
2017-04-08 15:06:16 +01:00
Shiny
65c988790b Merge branch 'dev' into bundle-update-2017-04-02-131809 2017-04-06 08:04:46 +12:00
Brenda Wallace
0372d3b9b0 Removing pre-commit.sh script 2017-04-06 08:04:09 +12:00
Shiny
3272ea1ca5 Merge branch 'dev' into bundle-update-2017-04-02-131809 2017-04-06 07:51:19 +12:00
Cesy
5392d7d900 Merge branch 'dev' into bundle-update-2017-04-02-131809 2017-04-03 08:47:32 +01:00
deppbot
45f2abeab5 Bundle Update on 2017-04-02 2017-04-02 13:18:11 +08:00
35 changed files with 345 additions and 170 deletions

View File

@@ -1,3 +1,9 @@
linters:
LineLength:
max: 120
InstanceVariables:
enabled: false
IdNames:
enabled: false
ConsecutiveComments:
enabled: false

3
.mention-bot Normal file
View File

@@ -0,0 +1,3 @@
{
"userBlacklist": ["tygriffin","oshiho3"]
}

View File

@@ -44,8 +44,6 @@ PreCommit:
command: ['npm', 'run', 'csslint']
HamlLint:
enabled: true
requires_files: true
on_warn: fail
command: ['bundle', 'exec', 'haml-lint', 'app/views']
JsonSyntax:
enabled: true

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

@@ -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

View File

@@ -25,7 +25,7 @@ GEM
addressable
active_merchant-paypal-bogus-gateway (0.1.0)
activemerchant
active_utils (3.3.1)
active_utils (3.3.4)
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)
@@ -73,7 +73,7 @@ GEM
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
bootstrap_form (2.6.0)
bootstrap_form (2.7.0)
builder (3.2.3)
bullet (5.5.1)
activesupport (>= 3.0.0)
@@ -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.1.0)
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)
@@ -445,11 +446,11 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
selenium-webdriver (3.3.0)
selenium-webdriver (3.4.0)
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

View File

@@ -108,8 +108,6 @@ p.stats
.planting
dl.planting-attributes
font-size: 85%
dt
text-align: left
dd
@@ -118,14 +116,13 @@ p.stats
@media (min-width: $screen-md-min)
.planting-thumbnail
dl.planting-attributes
font-size: 85%
width: 100%
dt
text-align: left
width: 80px
width: 120px
dd
padding-left: 80px
padding-left: 120px
margin-left: auto
.navbar .navbar-form
@@ -333,3 +330,10 @@ $state-success-bg: lighten($green, 50%)
overflow: hidden
text-overflow: ellipsis
white-space: nowrap
ul.plantings
list-style-type: none
ul.thumbnail-buttons
list-style-type: none
text-align: right

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

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

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

@@ -27,9 +27,9 @@ class Planting < ActiveRecord::Base
to: :crop,
prefix: true
validates :crop, approved: true
validates :crop, presence: { message: "must be present and exist in our database" }
validates :garden, presence: true
validates :crop, presence: true
validates :crop, approved: { message: "must be present and exist in our database" }
validates :quantity,
numericality: {

View File

@@ -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") }

View File

@@ -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)

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

@@ -7,7 +7,7 @@
= link_to image_tag((planting.default_photo ? planting.default_photo.thumbnail_url : 'placeholder_150.png'),
alt: planting.crop_id, class: 'img'),
planting
.col-xs-7.col-md-5
.col-xs-7.col-md-6
%dl.dl-horizontal.planting-attributes
%dt Owner:
%dd= link_to planting.owner.login_name, planting.owner
@@ -15,10 +15,12 @@
%dd= link_to planting.garden.name, planting.garden
%dt Planted on:
%dd= planting.planted_at
%dt Quantity:
%dd= display_planting_quantity(planting)
%dt Finished on:
%dd= display_finished(planting)
- if planting.quantity
%dt Quantity:
%dd= display_planting_quantity(planting)
- if planting.finished?
%dt Finished on:
%dd= display_finished(planting)
%dt Sun/shade?:
%dd
- sunniness = planting.sunniness.blank? ? "not specified" : planting.sunniness
@@ -26,32 +28,34 @@
= " (#{sunniness})"
%dt Planted from:
%dd= display_planted_from(planting)
.col-xs-1.col-md-3
%ul{ style: "list-style-type:none; text-align:right" }
%li= link_to 'Details', planting, class: 'btn btn-default btn-xs'
- if can? :edit, planting
%li= link_to 'Edit', edit_planting_path(planting), class: 'btn btn-default btn-xs'
- if can? :create, Harvest
%li= link_to 'Harvest', new_planting_harvest_path(planting), class: 'btn btn-default btn-xs'
- unless planting.finished
%li
= link_to "Mark as finished",
planting_path(planting, planting: { finished: 1 }),
method: :put,
class: 'btn btn-default btn-xs append-date'
- if can? :destroy, planting
%li
= link_to 'Delete',
planting, method: :delete,
data: { confirm: 'Are you sure?' },
class: 'btn btn-default btn-xs'
.row
.col-xs-12.col-md-4
%dl
%dt Days until maturity:
%dd= display_days_before_maturity(planting)
%dt Mature in:
%dd
= display_days_before_maturity(planting)
days
.col-xs-12.col-md-8
= render partial: 'plantings/planting_progress', locals: { planting: planting }
.col-xs-12.col-md-8
= render partial: 'plantings/planting_harvest', locals: { planting: planting }
= link_to 'Details', planting, class: 'btn btn-default btn-xs'
- if can? :edit, planting
= link_to edit_planting_path(planting), class: 'btn btn-default btn-xs' do
%span.glyphicon.glyphicon-pencil{ title: "Edit" }
- if can?(:edit, planting) && can?(:create, Harvest)
= link_to 'Harvest', new_planting_harvest_path(planting), class: 'btn btn-default btn-xs'
- if can?(:edit, planting) && !planting.finished
= link_to "Mark as finished",
planting_path(planting, planting: { finished: 1 }),
method: :put,
class: 'btn btn-default btn-xs append-date'
- if can? :destroy, planting
= link_to planting, method: :delete,
data: { confirm: 'Are you sure?' },
class: 'btn btn-default btn-xs' do
%span.glyphicon.glyphicon-trash{ title: "Delete" }
.row
.col-xs-12.col-md-12
%p= render partial: 'plantings/planting_progress', locals: { planting: planting }

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,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

View File

@@ -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

View File

@@ -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

View File

@@ -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

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

@@ -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

View File

@@ -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

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