Compare commits

..

37 Commits

Author SHA1 Message Date
Daniel O'Connor
f5a03b8991 Merge pull request #4161 from Growstuff/dependabot/bundler/rubocop-1.80.1
Bump rubocop from 1.80.0 to 1.80.1
2025-08-29 19:57:29 +09:30
Daniel O'Connor
d1d718df9e Add One click ask AI prompts for companion planting and growing guides (#4159)
* One click ask AI prompts

* One click ask AI prompts

* Update app/views/crops/show.html.haml
2025-08-29 19:54:38 +09:30
dependabot[bot]
da4bb17df8 Bump rubocop from 1.80.0 to 1.80.1
Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.80.0 to 1.80.1.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.80.0...v1.80.1)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-version: 1.80.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-28 08:59:30 +00:00
dependabot[bot]
0320cbe5ad Bump chartkick from 5.1.5 to 5.2.0 (#4072)
Bumps [chartkick](https://github.com/ankane/chartkick) from 5.1.5 to 5.2.0.
- [Changelog](https://github.com/ankane/chartkick/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ankane/chartkick/compare/v5.1.5...v5.2.0)

---
updated-dependencies:
- dependency-name: chartkick
  dependency-version: 5.2.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>
2025-08-28 00:16:34 +09:30
google-labs-jules[bot]
4d3c4ca10d Merge pull request #4154 from Growstuff/finish-expired-seeds-task
Add maintenance task to finish expired seeds
2025-08-28 00:16:16 +09:30
Daniel O'Connor
749134a7de Remove Openfarm data fetching (#4157) 2025-08-28 00:15:03 +09:30
Daniel O'Connor
1657a527e9 Remove Openfarm data fetching 2025-08-27 14:20:22 +00:00
google-labs-jules[bot]
ba6ec689c5 Merge pull request #4150 from Growstuff/feature/failed-plantings
Add failed status to plantings
2025-08-27 23:42:53 +09:30
Daniel O'Connor
df2853edd3 Merge pull request #4153 from Growstuff/age_in_days
Fix age in days, percentage grown calculations for future dates
2025-08-27 23:31:48 +09:30
Daniel O'Connor
948bb78656 Fix percentage grown 2025-08-27 13:44:44 +00:00
Daniel O'Connor
9c8ae50188 Fix https://github.com/Growstuff/growstuff/issues/3844 by avoiding future finished dates being considered past dates 2025-08-27 13:36:12 +00:00
dependabot[bot]
0ee6260272 Merge pull request #4152 from Growstuff/dependabot/bundler/scout_apm-5.7.1 2025-08-26 23:30:40 +00:00
dependabot[bot]
bf528220ab Bump scout_apm from 5.7.0 to 5.7.1
Bumps [scout_apm](https://github.com/scoutapp/scout_apm_ruby) from 5.7.0 to 5.7.1.
- [Changelog](https://github.com/scoutapp/scout_apm_ruby/blob/master/CHANGELOG.markdown)
- [Commits](https://github.com/scoutapp/scout_apm_ruby/compare/v5.7.0...v5.7.1)

---
updated-dependencies:
- dependency-name: scout_apm
  dependency-version: 5.7.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-26 23:22:37 +00:00
dependabot[bot]
fd89cc6bce Merge pull request #4151 from Growstuff/dependabot/bundler/rubocop-1.80.0 2025-08-26 23:21:29 +00:00
dependabot[bot]
08a3890ba2 Bump rubocop from 1.79.2 to 1.80.0
Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.79.2 to 1.80.0.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.79.2...v1.80.0)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-version: 1.80.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-25 14:33:48 +00:00
Daniel O'Connor
956c73cd1e This rake task iterates through all photos and removes any that have a 404 status on their fullsize_url. This will help to keep the database clean of broken photo references. (#4149)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2025-08-25 10:26:57 +09:30
google-labs-jules[bot]
8e74d1796a This rake task iterates through all photos and removes any that have a 404 status on their fullsize_url. This will help to keep the database clean of broken photo references. 2025-08-24 23:17:26 +00:00
google-labs-jules[bot]
a98990ccd2 Add transplant feature for plantings (#4133)
* Add ability to transplant a planting

* Fix view tests

* Transplantable gardens

* Add spec

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>
2025-08-24 22:31:14 +09:30
google-labs-jules[bot]
ac1463e2cf Add international alternate names for crops (#4132)
* I will add the international alternate names for the crops.

* Mark required

* Update factory

* Add placeholder

* Fix seeds

* Add language, though hardcoded to EN in most places

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>
2025-08-24 21:44:41 +09:30
google-labs-jules[bot]
8564ec7a7c Add comments to photos (#4130)
* Add comments to photos

Extend the photo show page to support comments by logged in users.

- Make the Comment model polymorphic.
- Update the Photo and Post models to have comments.
- Update the comments controller to handle the polymorphic association.
- Update the photo show page to display comments and a comment form.
- Create a reusable comments partial.

* Add migration

* Fix tests

* Fix tests

* Slightly fix tests

* Fix variables

* Add field

* Refactor slightly

* Refactor slightly

* Refactor slightly

* Refactor

* Photos respond to this as well

* Refactor to polymorphic_url

* Rename

* Wrong relationship

* Refactor and fix tests

* Fix relationships

* Fix rendering

* Fix tests

* Fix model tests

* Fix test

* Fix test

* Fix test

* Fix test

* Fix controller spec

* Fix view tests

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>
2025-08-24 21:10:16 +09:30
Daniel O'Connor
79a54351e3 Delete spec/tasks/openfarm_rake_spec.rb 2025-08-24 21:02:13 +09:30
dependabot[bot]
48aa2aafd3 Merge pull request #4066 from Growstuff/dependabot/bundler/oj-3.16.11 2025-08-24 08:15:56 +00:00
Daniel O'Connor
3b648925dd Merge branch 'dev' into dependabot/bundler/oj-3.16.11 2025-08-24 17:36:31 +09:30
Daniel O'Connor
d04ffbeddd Merge pull request #4146 from Growstuff/remove-twitter-auth
Remove twitter authentication
2025-08-24 17:35:56 +09:30
Daniel O'Connor
e1367613e6 Merge branch 'dev' into remove-twitter-auth 2025-08-24 17:08:19 +09:30
Daniel O'Connor
70f78f1175 Merge pull request #4148 from Growstuff/CloCkWeRX-patch-2
Delete lib/tasks/openfarm.rake
2025-08-24 17:07:19 +09:30
Daniel O'Connor
6131fdf141 Delete lib/tasks/openfarm.rake 2025-08-24 17:07:02 +09:30
Daniel O'Connor
44101e07fb Merge branch 'mainline' into dev 2025-08-24 16:40:08 +09:30
Daniel O'Connor
b4c1104af0 Merge branch 'dev' into remove-twitter-auth 2025-08-24 16:36:42 +09:30
Daniel O'Connor
3d4ba954e7 Remove defunct detail 2025-08-24 07:05:28 +00:00
google-labs-jules[bot]
0b639d5940 Remove twitter authentication
This change removes the twitter authentication feature from the application.

It removes the `omniauth-twitter` gem and all related code from controllers, views, and tests. It also removes the twitter icon and environment variable settings.
2025-08-24 07:03:20 +00:00
dependabot[bot]
26de3e7c5e Bump oj from 3.16.10 to 3.16.11
Bumps [oj](https://github.com/ohler55/oj) from 3.16.10 to 3.16.11.
- [Release notes](https://github.com/ohler55/oj/releases)
- [Changelog](https://github.com/ohler55/oj/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/ohler55/oj/compare/v3.16.10...v3.16.11)

---
updated-dependencies:
- dependency-name: oj
  dependency-version: 3.16.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-10 05:37:12 +00:00
Daniel O'Connor
5da8f815d3 Fix stupid mistake 2025-08-10 02:27:36 +00:00
Daniel O'Connor
d71370c0bc Merge pull request #4122 from Growstuff/dev
Release 65.2
2025-08-10 11:54:12 +09:30
Daniel O'Connor
c58ca74b53 Merge pull request #4120 from Growstuff/dev
Release 65.1
2025-08-10 11:39:11 +09:30
Daniel O'Connor
0d22706d42 Merge pull request #4118 from Growstuff/dev
August 2025 Release
2025-08-10 11:17:05 +09:30
Daniel O'Connor
1462279b60 Merge pull request #4011 from Growstuff/dev
March 2025-ish release
2025-03-29 16:43:24 +10:30
101 changed files with 586 additions and 332 deletions

View File

@@ -91,10 +91,9 @@ gem 'bootstrap-datepicker-rails'
# DRY-er easier bootstrap 4 forms
gem "bootstrap_form", ">= 4.5.0"
# For connecting to other services (eg Twitter)
# For connecting to other services (eg Flickr)
gem 'omniauth', '~> 1.3'
gem 'omniauth-flickr', '>= 0.0.15'
gem 'omniauth-twitter'
# Pretty charts
gem "chartkick"
@@ -202,3 +201,5 @@ group :travis do
end
gem "i18n_data", "~> 1.1"

View File

@@ -183,7 +183,7 @@ GEM
image_processing (~> 1.1)
marcel (~> 1.0.0)
ssrf_filter (~> 1.0)
chartkick (5.1.5)
chartkick (5.2.0)
childprocess (5.0.0)
coderay (1.1.3)
coercible (1.0.0)
@@ -341,6 +341,8 @@ GEM
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.8, >= 1.8.1)
terminal-table (>= 1.5.1)
i18n_data (1.1.0)
simple_po_parser (~> 1.1)
icalendar (2.11.2)
base64
ice_cube (~> 0.16)
@@ -440,7 +442,7 @@ GEM
nokogiri (1.18.9-x86_64-linux-gnu)
racc (~> 1.4)
oauth (0.5.6)
oj (3.16.10)
oj (3.16.11)
bigdecimal (>= 3.0)
ostruct (>= 0.2)
omniauth (1.9.2)
@@ -452,12 +454,9 @@ GEM
omniauth-oauth (1.1.0)
oauth
omniauth (~> 1.0)
omniauth-twitter (1.4.0)
omniauth-oauth (~> 1.1)
rack
open-uri (0.1.0)
orm_adapter (0.5.0)
ostruct (0.6.2)
ostruct (0.6.3)
parallel (1.27.0)
parser (3.3.9.0)
ast (~> 2.4.1)
@@ -608,7 +607,7 @@ GEM
rswag-ui (2.16.0)
actionpack (>= 5.2, < 8.1)
railties (>= 5.2, < 8.1)
rubocop (1.79.2)
rubocop (1.80.1)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
@@ -662,7 +661,7 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
scout_apm (5.7.0)
scout_apm (5.7.1)
parser
searchkick (5.3.1)
activemodel (>= 6.1)
@@ -680,6 +679,7 @@ GEM
logger
rack (>= 2.2.4)
redis-client (>= 0.22.2)
simple_po_parser (1.1.6)
sprockets (3.7.5)
base64
concurrent-ruby (~> 1.0)
@@ -704,7 +704,7 @@ GEM
trollop (1.16.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (3.1.4)
unicode-display_width (3.1.5)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
unicorn (6.1.0)
@@ -793,6 +793,7 @@ DEPENDENCIES
haml_lint (>= 0.25.1)
hashie (>= 3.5.3)
i18n-tasks
i18n_data (~> 1.1)
icalendar
jquery-rails
jquery-ui-rails!
@@ -810,7 +811,6 @@ DEPENDENCIES
oj
omniauth (~> 1.3)
omniauth-flickr (>= 0.0.15)
omniauth-twitter
percy-capybara (~> 5.0.0)
pg
platform-api

View File

@@ -62,5 +62,3 @@ For more information about this project, contact [info@growstuff.org](mailto:inf
Security Issues: If you find an authorization bypass or data breach, please contact our maintainers directly at [maintainers@growstuff.org](mailto:maintainers@growstuff.org).
You can also contact us on [Twitter](http://twitter.com/growstufforg/) or
[Facebook](https://www.facebook.com/pages/Growstuff/1531133417099494) or [Github](https://github.com/Growstuff/growstuff/issues)..

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -57,6 +57,6 @@ class AlternateNamesController < ApplicationController
private
def alternate_name_params
params.require(:alternate_name).permit(:crop_id, :name, :creator_id)
params.require(:alternate_name).permit(:crop_id, :name, :creator_id, :language)
end
end

View File

@@ -13,43 +13,55 @@ class CommentsController < ApplicationController
end
def new
@commentable = find_commentable
@comment = Comment.new
@post = Post.find_by(id: params[:post_id])
if @post
@comments = @post.comments
if @commentable
@comments = @commentable.comments
respond_with(@comments)
else
redirect_to(request.referer || root_url,
alert: "Can't post a comment on a non-existent post")
alert: "Can't post a comment on a non-existent commentable")
end
end
def edit
@comments = @comment.post.comments
# TODO: Why does this need a collection of comments?
@comments = @comment.commentable.comments
@commentable = @comment.commentable
end
def create
@comment = Comment.new(comment_params)
@commentable = @comment.commentable
@comment.author = current_member
@comment.save
respond_with @comment, location: @comment.post
respond_with @comment, location: @commentable
end
def update
@comment.update(body: comment_params['body'])
respond_with @comment, location: @comment.post
respond_with @comment, location: @comment.commentable
end
def destroy
@post = @comment.post
@commentable = @comment.commentable
@comment.destroy
respond_with(@post)
respond_with(@commentable)
end
private
def find_commentable
return unless params[:comment]
if params[:comment][:commentable_type] == 'Photo'
Photo.find(params[:comment][:commentable_id])
elsif params[:comment][:commentable_type] == 'Post'
Post.find(params[:comment][:commentable_id])
end
end
def comment_params
params.require(:comment).permit(:body, :post_id)
params.require(:comment).permit(:body, :commentable_id, :commentable_type)
end
end

View File

@@ -39,12 +39,6 @@ class CropsController < ApplicationController
respond_with @crops
end
def openfarm
@crop = Crop.find(params[:crop_slug])
@crop.update_openfarm_data!
respond_with @crop, location: @crop
end
def gbif
@crop = Crop.find(params[:crop_slug])
@crop.update_gbif_data!
@@ -137,7 +131,6 @@ class CropsController < ApplicationController
if @crop.approval_status_changed?(from: "pending", to: "approved")
notifier.deliver_now!
@crop.update_openfarm_data!
@crop.update_gbif_data!
end
else
@@ -166,7 +159,7 @@ class CropsController < ApplicationController
end
def save_crop_names
AlternateName.create!(names_params(:alt_name).map { |n| { name: n, creator_id: current_member.id, crop_id: @crop.id } })
AlternateName.create!(names_params(:alt_name).map { |n| { name: n, creator_id: current_member.id, crop_id: @crop.id, language: "EN" } })
ScientificName.create!(names_params(:sci_name).map { |n| { name: n, creator_id: current_member.id, crop_id: @crop.id } })
end
@@ -181,18 +174,16 @@ class CropsController < ApplicationController
def recreate_names(param_name, name_type)
return if params[param_name].blank?
destroy_names(name_type)
params[param_name].each_value do |value|
create_name!(name_type, value) unless value.empty?
end
end
def destroy_names(name_type)
@crop.send("#{name_type}_names").each(&:destroy)
end
params[param_name].each_value do |value|
next if value.empty?
def create_name!(name_type, value)
@crop.send("#{name_type}_names").create!(name: value, creator_id: current_member.id)
if name_type == 'alternate'
@crop.send("#{name_type}_names").create!(name: value, creator_id: current_member.id, language: "EN")
else
@crop.send("#{name_type}_names").create!(name: value, creator_id: current_member.id)
end
end
end
def crop_params
@@ -216,12 +207,12 @@ class CropsController < ApplicationController
def crop_json_fields
{
include: {
plantings: {
plantings: {
include: {
owner: { only: %i(id login_name location latitude longitude) }
}
},
scientific_names: { only: [:name] }, alternate_names: { only: [:name] }
scientific_names: { only: [:name] }, alternate_names: { only: %i(name language) }
}
}
end

View File

@@ -16,7 +16,6 @@ class MembersController < ApplicationController
def show
@member = Member.confirmed.kept.find_by!(slug: params[:slug])
@twitter_auth = @member.auth('twitter')
@flickr_auth = @member.auth('flickr')
@posts = @member.posts

View File

@@ -28,7 +28,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
@authentication = action.establish_authentication(auth, member)
if action.member_created?
raise "Invalid provider" unless %w(twitter flickr).index(auth['provider'].to_s)
raise "Invalid provider" unless %w(flickr).index(auth['provider'].to_s)
session["devise.#{auth['provider']}_data"] = request.env["omniauth.auth"]
sign_in member

View File

@@ -21,6 +21,7 @@ class PhotosController < ApplicationController
def show
@crops = Crop.distinct.joins(:photo_associations).where(photo_associations: { photo: @photo })
@comment = Comment.new(commentable: @photo)
respond_with(@photo)
end

View File

@@ -91,6 +91,32 @@ class PlantingsController < DataController
respond_with @planting, location: @planting.garden
end
def transplant
# The `load_and_authorize_resource` in DataController will handle finding the
# planting and authorizing the action.
# We still need to authorize the new garden
new_garden = Garden.find(params[:garden_id])
authorize! :update, new_garden
# Mark original planting as finished
@planting.update(finished: true, finished_at: Time.zone.now)
# Create a new planting
new_planting = @planting.dup
new_planting.garden = new_garden
new_planting.slug = nil # let friendly_id generate a new slug
new_planting.finished = false
new_planting.finished_at = nil
if new_planting.save
redirect_to edit_planting_path(new_planting), notice: 'Planting was successfully transplanted.'
else
# if the save fails, we should probably roll back the finishing of the original planting
@planting.update(finished: false, finished_at: nil)
redirect_to @planting, alert: "There was an error transplanting the planting: #{new_planting.errors.full_messages.to_sentence}"
end
end
private
def update_crop_medians
@@ -107,7 +133,7 @@ class PlantingsController < DataController
:crop_id, :description, :garden_id, :planted_at,
:parent_seed_id,
:quantity, :sunniness, :planted_from, :finished,
:finished_at
:finished_at, :failed
)
end

View File

@@ -6,7 +6,6 @@ class RegistrationsController < Devise::RegistrationsController
prepend_before_action :check_captcha, only: [:create] # Change this to be any actions you want to protect with recaptcha.
def edit
@twitter_auth = current_member.auth('twitter')
@flickr_auth = current_member.auth('flickr')
render "edit"
end

View File

@@ -50,7 +50,6 @@ module ApplicationHelper
uri.query = "&width=#{size}&height=#{size}" if uri.host == 'graph.facebook.com'
# TODO: Assess twitter - https://dev.twitter.com/overview/general/user-profile-images-and-banners
# TODO: Assess flickr - https://www.flickr.com/services/api/misc.buddyicons.html
return uri.to_s

View File

@@ -2,6 +2,7 @@
module ButtonsHelper
include IconsHelper
def garden_plant_something_button(garden, classes: "btn btn-default")
return unless can? :edit, garden
@@ -97,7 +98,7 @@ module ButtonsHelper
end
def planting_finish_button(planting, classes: 'btn btn-default btn-secondary')
return unless can?(:edit, planting) || planting.finished
return unless can?(:edit, planting) || planting.finished || planting.failed
link_to planting_path(slug: planting.slug, planting: { finished: 1 }),
method: :put, class: "#{classes} append-date" do
@@ -105,6 +106,15 @@ module ButtonsHelper
end
end
def planting_failed_button(planting, classes: 'btn btn-default btn-secondary')
return unless can?(:edit, planting) || planting.finished || planting.failed
link_to planting_path(slug: planting.slug, planting: { failed: 1 }),
method: :put, class: "#{classes}" do
finished_icon + ' ' + t('buttons.mark_as_failed')
end
end
def seed_finish_button(seed, classes: 'btn btn-default')
return unless can?(:create, Planting) && seed.active
@@ -122,7 +132,7 @@ module ButtonsHelper
end
def planting_save_seeds_button(planting, classes: 'btn btn-default')
return unless can?(:edit, planting)
return unless can?(:edit, planting) && !planting.failed?
link_to new_planting_seed_path(planting_slug: planting.slug), class: classes do
seed_icon + ' ' + t('buttons.save_seeds')

View File

@@ -43,6 +43,14 @@ module PlantingsHelper
(planting.first_harvest_predicted_at - Time.zone.today).to_i
end
# Returns a list of gardens the planting can be transplanted to
# based on the planting's owner.
def transplantable_gardens_by_owner(planting)
garden_ids = planting.owner.gardens.select(:id).to_a + GardenCollaborator.where(member_id: planting.owner.id).select(:garden_id).to_a
Garden.active.where.not(id: planting.garden_id).where(id: garden_ids)
end
def days_from_now_to_last_harvest(planting)
return unless planting.planted_at.present? && planting.last_harvest_predicted_at.present?

View File

@@ -111,6 +111,10 @@ class Ability
can :update, Planting do |planting|
planting.garden.garden_collaborators.where(member_id: member.id).any?
end
can :transplant, Planting, garden: { owner_id: member.id }
can :transplant, Planting do |planting|
planting.garden.garden_collaborators.where(member_id: member.id).any?
end
can :destroy, Planting do |planting|
planting.garden.garden_collaborators.where(member_id: member.id).any?
end

View File

@@ -5,6 +5,7 @@ class AlternateName < ApplicationRecord
belongs_to :creator, class_name: 'Member', inverse_of: :created_alternate_names
validates :name, presence: true
validates :crop, presence: true
validates :language, presence: true
after_commit :reindex

View File

@@ -2,26 +2,27 @@
class Comment < ApplicationRecord
belongs_to :author, class_name: 'Member', inverse_of: :comments
belongs_to :post, counter_cache: true
belongs_to :commentable, polymorphic: true, counter_cache: true
# validates :body, presence: true
scope :post_order, -> { order(created_at: :asc) } # for display on post page
after_create do
recipient = post.author.id
recipient = commentable.author.id
sender = author.id
# don't send notifications to yourself
if recipient != sender
Notification.create(
recipient_id: recipient,
sender_id: sender,
subject: "#{author} commented on #{post.subject}",
subject: "#{author} commented on #{commentable.subject}",
body:,
post_id: post.id
notifiable: commentable
)
end
end
def to_s
"#{author.login_name} commented on #{post.subject}"
"#{author.login_name} commented on #{commentable.subject}"
end
end

View File

@@ -8,7 +8,12 @@ module Finishable
scope :current, -> { where.not(finished: true) }
def active
!finished
# Plantings can fail. At the moment, activities and seeds cannot.
if respond_to?(:failed)
!finished && !failed
else
!finished
end
end
end
end

View File

@@ -4,10 +4,6 @@ module OpenFarmData
extend ActiveSupport::Concern
included do
def update_openfarm_data!
OpenfarmService.new.update_crop(self)
end
def of_photo
fetch_attr('main_image_path')
end

View File

@@ -38,7 +38,7 @@ module PredictHarvest
# status
def harvest_time?
return false if crop.perennial || finished
return false if crop.perennial || finished || failed
# We have harvests but haven't finished
harvests.size.positive? ||

View File

@@ -8,12 +8,12 @@ module PredictPlanting
before_save :calculate_lifespan
def calculate_lifespan
self.lifespan = (planted_at.present? && finished_at.present? ? finished_at - planted_at : nil)
self.lifespan = (planted_at.present? && finished_at.present? && !failed? ? finished_at - planted_at : nil)
end
# dates
def finish_predicted_at
if planted_at.blank?
if planted_at.blank? || failed?
nil
elsif crop.median_lifespan.present?
planted_at + crop.median_lifespan.days
@@ -34,15 +34,18 @@ module PredictPlanting
end
def actual_lifespan
return unless planted_at.present? && finished_at.present?
return unless planted_at.present? && finished_at.present? && !failed?
(finished_at - planted_at).to_i
end
def age_in_days
return if planted_at.blank?
return if failed?
known_last_day ||= finished_at || Time.zone.today
known_last_day = Time.zone.today if known_last_day > Time.zone.today
(known_last_day - planted_at).to_i
end
@@ -50,9 +53,9 @@ module PredictPlanting
Rails.cache.fetch("#{cache_key_with_version}/percentage_grown", expires_in: 8.hours) do
if finished?
100
elsif !planted?
elsif !planted? || failed?
0
elsif crop.perennial || finish_predicted_at.nil?
elsif crop.perennial || (finish_predicted_at.nil? && finished_at.nil?) # This covers future dated finished_at that hasn't occurrred yet.
nil
else
calculate_percentage_grown
@@ -71,7 +74,7 @@ module PredictPlanting
end
def late?
crop.annual? && !finished &&
crop.annual? && !finished && !failed &&
planted_at.present? &&
finish_predicted_at.present? &&
finish_predicted_at <= Time.zone.today

View File

@@ -59,7 +59,7 @@ class CsvImporter
alternate_names.split(/,\s*/).each do |name|
altname = AlternateName.find_by(name:, crop: @crop)
altname ||= AlternateName.create! name:, crop: @crop, creator: cropbot
altname ||= AlternateName.create! name:, crop: @crop, language: "EN", creator: cropbot
@crop.alternate_names << altname
end
end

View File

@@ -10,7 +10,8 @@ class Follow < ApplicationRecord
recipient_id: followed_id,
sender_id: follower_id,
subject: "#{follower.login_name} is now following you",
body: "#{follower.login_name} just followed you on #{ENV.fetch('GROWSTUFF_SITE_NAME', nil)}. "
body: "#{follower.login_name} just followed you on #{ENV.fetch('GROWSTUFF_SITE_NAME', nil)}. ",
notifiable: self
)
end
end

View File

@@ -5,6 +5,7 @@ class Garden < ApplicationRecord
include Geocodable
include PhotoCapable
include Ownable
friendly_id :garden_slug, use: %i(slugged finders)
has_many :plantings, dependent: :destroy
@@ -44,6 +45,7 @@ class Garden < ApplicationRecord
.where.not(gardens: { latitude: nil })
.where.not(gardens: { longitude: nil })
}
AREA_UNITS_VALUES = {
"square metres" => "square metre",
"square feet" => "square foot",

View File

@@ -3,7 +3,7 @@
class Notification < ApplicationRecord
belongs_to :sender, class_name: 'Member', inverse_of: :sent_notifications
belongs_to :recipient, class_name: 'Member', inverse_of: :notifications
belongs_to :post, optional: true
belongs_to :notifiable, polymorphic: true
validates :subject, length: { maximum: 255 }

View File

@@ -8,6 +8,7 @@ class Photo < ApplicationRecord
PHOTO_CAPABLE = %w(Garden Planting Harvest Seed Post Crop).freeze
has_many :photo_associations, dependent: :delete_all, inverse_of: :photo
has_many :comments, as: :commentable, dependent: :destroy
# This doesn't work, ActiveRecord tries to use the polymoriphic photographable
# relationship instead.
@@ -83,6 +84,14 @@ class Photo < ApplicationRecord
"#{title} by #{owner.login_name}"
end
def subject
title
end
def author
owner
end
def flickr_photo_id
source_id if source == 'flickr'
end

View File

@@ -43,7 +43,8 @@ class Planting < ApplicationRecord
.where.not(gardens: { latitude: nil })
.where.not(gardens: { longitude: nil })
}
scope :active, -> { where('finished <> true').where('finished_at IS NULL OR finished_at < ?', Time.zone.now) }
scope :active, -> { where(finished: false, failed: false).where('finished_at IS NULL OR finished_at < ?', Time.zone.now) }
scope :failed, -> { where(failed: true) }
scope :annual, -> { joins(:crop).where(crops: { perennial: false }) }
scope :perennial, -> { joins(:crop).where(crops: { perennial: true }) }
scope :interesting, -> { has_photos.one_per_owner.order(planted_at: :desc) }
@@ -72,6 +73,7 @@ class Planting < ApplicationRecord
validates :crop, presence: true, approved: { message: "must be present and exist in our database" }
validate :finished_must_be_after_planted
validate :owner_must_match_garden_owner
validate :cannot_be_finished_and_failed
validates :quantity, allow_nil: true, numericality: {
only_integer: true, greater_than_or_equal_to: 0
}
@@ -96,7 +98,11 @@ class Planting < ApplicationRecord
end
def finished?
finished || (finished_at.present? && finished_at <= Time.zone.today)
(finished || (finished_at.present? && finished_at <= Time.zone.today)) && !failed?
end
def failed?
failed
end
def planted?
@@ -120,6 +126,10 @@ class Planting < ApplicationRecord
private
def cannot_be_finished_and_failed
errors.add(:failed, "can't be true if planting is also finished") if finished && failed
end
# check that any finished_at date occurs after planted_at
def finished_must_be_after_planted
return unless planted_at && finished_at # only check if we have both

View File

@@ -3,6 +3,7 @@
class Post < ApplicationRecord
extend FriendlyId
include Likeable
friendly_id :author_date_subject, use: %i(slugged finders)
include PhotoCapable
@@ -10,9 +11,10 @@ class Post < ApplicationRecord
# Relationships
belongs_to :author, class_name: 'Member', inverse_of: :posts
belongs_to :forum, optional: true
has_many :comments, dependent: :destroy
has_many :comments, as: :commentable, dependent: :destroy
has_many :crop_posts, dependent: :delete_all
has_many :crops, through: :crop_posts
has_many :notifications, as: :notifiable, dependent: :destroy
after_create :send_notification
#
@@ -95,6 +97,7 @@ class Post < ApplicationRecord
Notification.create(
recipient_id:,
sender_id: sender,
notifiable: self,
subject: "#{author} mentioned you in their post #{subject}",
body:
)

View File

@@ -59,6 +59,7 @@ class Seed < ApplicationRecord
scope :has_location, -> { joins(:owner).where.not('members.location': nil) }
scope :recent, -> { order(created_at: :desc) }
scope :active, -> { where('finished <> true').where('finished_at IS NULL OR finished_at < ?', Time.zone.now) }
scope :expired, -> { active.where('plant_before < ?', Time.zone.today) }
def tradable
tradable_to != 'nowhere'

View File

@@ -13,6 +13,7 @@ module Api
attribute :slug
attribute :planted_at
attribute :failed
attribute :finished
attribute :finished_at
attribute :quantity
@@ -37,9 +38,7 @@ module Api
filter :finished
attribute :percentage_grown
def percentage_grown
@model.percentage_grown
end
delegate :percentage_grown, to: :@model
attribute :crop_name
attribute :crop_slug

View File

@@ -47,7 +47,7 @@
.row
.col-md-6
= f.check_box :finished, label: 'Mark as finished'
= f.check_box :finished, label: t('buttons.mark_as_finished')
%span.help-block= t('.finish_helper')
.card-footer

View File

@@ -31,7 +31,8 @@
= f.label :name, class: 'control-label col-md-2'
.col-md-8
= f.text_field :name, class: 'form-control'
.col-md-8
= f.select :language, I18nData.languages.map {|code, name| [name.split(";").first, code] }, class: 'form-control'
.form-group
.form-actions.col-md-offset-2.col-md-8
= f.submit 'Save', class: 'btn btn-primary'

View File

@@ -1,12 +1,11 @@
%a{ name: "comments" }
- if post.comments
- if commentable.comments
%hr/
%h2
= comment_icon
= localize_plural(post.comments, Comment)
- post.comments.post_order.each do |comment|
= localize_plural(commentable.comments, Comment)
- commentable.comments.post_order.each do |comment|
= render "comments/single", comment: comment
- else
%h2 There are no comments yet

View File

@@ -1 +1 @@
#{link_to 'commented', event_model} on #{link_to event_model.post, event_model.post}
#{link_to 'commented', event_model} on #{link_to event_model.commentable, event_model.commentable}

View File

@@ -1,3 +1,4 @@
- @comment ||= Comment.new(commentable: @commentable)
.card.col-md-8.col-lg-7.mx-auto.float-none.white.z-depth-1.py-2.px-2
.card-body
- if content_for? :title
@@ -14,13 +15,13 @@
%li= msg
.md-form
= f.text_area :body, rows: 6, class: 'form-control md-textarea', autofocus: 'autofocus'
= f.text_area :body, rows: 6, class: 'form-control md-textarea', autofocus: 'autofocus', required: true, pattern: '\w+'
= f.label :body, "Your comment:"
%span.help-block
= render partial: "shared/markdown_help"
.actions.text-right
= f.submit 'Post comment', class: 'btn btn-primary'
- if defined?(@post)
.field
= f.hidden_field :post_id, value: @post.id
.field
= f.hidden_field :commentable_id, value: @commentable.id
= f.hidden_field :commentable_type, value: @commentable.class.name

View File

@@ -2,6 +2,6 @@
%p
Editing comment on
= link_to @comment.post.subject, @comment.post
= link_to @comment.commentable.subject, @comment.commentable
= render 'form'
= render 'form', locals: { comment: @comment, commentable: @comment.commentable }

View File

@@ -5,17 +5,18 @@
%link= comments_url
- @comments.each do |comment|
%item
%title Comment by #{comment.author.login_name} on #{comment.post.subject}
%title Comment by #{comment.author.login_name} on #{comment.commentable.subject}
%description
:escaped_markdown
<p>
Comment on
#{ link_to comment.post.subject, post_url(comment.post) }
#{ link_to comment.commentable.subject, polymorphic_url(comment.commentable) }
</p>
:escaped_markdown
#{ strip_tags markdownify(comment.body) }
%pubdate= comment.created_at.to_fs(:rfc822)
%link= post_url(comment.post)
%link= polymorphic_url(comment.commentable)
%guid= comment_url(comment)

View File

@@ -1,11 +1,17 @@
= content_for :title, "New comment"
- if @commentable.is_a?(Post)
%section.blog-post
.card.post{ id: "post-#{@commentable.id}" }
.card-header
%h2.display-3= @commentable.subject
.card-body= render "posts/single", post: @commentable || @comment.commentable, subject: true
- elsif @commentable.is_a?(Photo)
%section.blog-post
.card.photo{ id: "photo-#{@commentable.id}" }
.card-header
%h2.display-3= @commentable.subject
.card-body= render "photos/card", photo: @commentable || @comment.commentable, subject: true
%section.blog-post
.card.post{ id: "post-#{@post.id}" }
.card-header
%h2.display-3= @post.subject
.card-body= render "posts/single", post: @post || @comment.post, subject: true
= render partial: "comments/comments", locals: { commentable: @commentable || @comment.commentable }
= render partial: "posts/comments", locals: { post: @post || @comment.post }
= render 'form'
= render 'form', locals: { comment: @comment, commentable: @commentable || @comment.commentable }

View File

@@ -5,7 +5,7 @@
- if can? :edit, an
.dropdown.planting-actions
%a#crop-actions-altnames.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-bs-toggle" => "dropdown", :type => "button", :href => '#'}
= an.name
= "#{an.name} (#{an.language})"
.dropdown-menu.dropdown-menu-xs{"aria-labelledby" => "crop-actions-altnames"}
- if can? :edit, an
= link_to edit_alternate_name_path(an), class: 'dropdown-item' do
@@ -16,7 +16,7 @@
= delete_icon
= t('.delete')
- else
.badge= an.name
.badge= "#{an.name} (#{an.language})"
%p.text-right

View File

@@ -10,10 +10,6 @@
= edit_icon
= t('.edit')
= link_to crop_openfarm_path(crop), method: :post, class: 'dropdown-item' do
= icon 'far', 'update'
Fetch data from OpenFarm
= link_to crop_gbif_path(crop), method: :post, class: 'dropdown-item' do
= icon 'far', 'update'
Fetch data from GBIF

View File

@@ -147,6 +147,14 @@
= icon 'fas', 'external-link-alt'
Google
%li.list-group-item
= link_to 'https://chat.openai.com/?model=gpt-4o&prompt=' + CGI.escape(['How do I grow', @crop.name, "and what grows well with it? What should I plant the next season if practicing crop rotation? Explain why and add links to your sources"].join(' ')),
target: "_blank",
class: 'card-link',
rel: "noopener noreferrer" do
= icon 'fas', 'external-link-alt'
ChatGPT
%li.list-group-item
= link_to "https://wikihow.com/wikiHowTo?search=#{CGI.escape "grow #{@crop.name}" }",
target: "_blank",

View File

@@ -3,19 +3,6 @@
html: { method: :put, class: 'form-horizontal' }) do |_f|
%br/
= render 'devise/shared/error_messages', resource: resource
.row
.col-md-12
%p
= image_tag "twitter_32.png", size: "32x32", alt: 'Twitter logo'
- if @twitter_auth
You are connected to Twitter as
= link_to @twitter_auth.name, "https://twitter.com/#{@twitter_auth.name}"
= link_to "Disconnect", @twitter_auth,
confirm: "Are you sure you want to remove this connection?",
method: :delete, class: "remove btn btn-danger"
- else
= link_to 'Connect to Twitter', '/members/auth/twitter', class: 'btn'
.row
.col-md-12
%p

View File

@@ -1,4 +1,4 @@
- if member.website_url.present? || member.instagram_handle.present? || member.facebook_handle.present? || member.bluesky_handle.present? || member.other_url.present? || twitter_auth || flickr_auth || member.show_email
- if member.website_url.present? || member.instagram_handle.present? || member.facebook_handle.present? || member.bluesky_handle.present? || member.other_url.present? || flickr_auth || member.show_email
%h4 Contact
- if member.website_url.present?
@@ -26,11 +26,6 @@
= icon 'fas', 'link', class: 'fa-fw'
= link_to "More...", member.other_url, target: '_blank', rel: 'noopener noreferrer'
- if twitter_auth
%p
= image_tag "twitter_32.png", size: "32x32", alt: 'Twitter logo'
= link_to twitter_auth.name, "https://twitter.com/#{twitter_auth.name}", target: '_blank', rel: 'noopener noreferrer'
- if flickr_auth
%p
= image_tag "flickr_32.png", size: "32x32", alt: 'Flickr logo'

View File

@@ -77,8 +77,7 @@
= render "stats", member: @member
.card-footer
= render "contact", member: @member, twitter_auth: @twitter_auth,
flickr_auth: @flickr_auth
= render "contact", member: @member, flickr_auth: @flickr_auth
.col-md-10#content
.row

View File

@@ -46,4 +46,12 @@
- else
= @photo.license_name
= render "associations", photo: @photo
= render "associations", photo: @photo
.row
- if can? :create, Comment
= link_to new_comment_path(comment: { commentable_type: 'Photo', commentable_id: @photo.id }), class: 'btn' do
= icon 'fas', 'comment'
Comment
.row
.col-md-9
= render 'comments/comments', commentable: @photo

View File

@@ -7,7 +7,16 @@
- if planting.active
= planting_plan_something_button(planting, classes: 'dropdown-item')
= planting_finish_button(planting, classes: 'dropdown-item')
= planting_failed_button(planting, classes: 'dropdown-item')
= planting_harvest_button(planting, classes: 'dropdown-item')
= planting_save_seeds_button(planting, classes: 'dropdown-item')
- if can?(:transplant, planting) && planting.active && transplantable_gardens_by_owner(planting).any?
.dropdown-divider
.px-2
= form_tag transplant_planting_path(planting), method: :post do
.form-group
= label_tag :garden_id, 'Transplant to:'
= select_tag :garden_id, options_from_collection_for_select(transplantable_gardens_by_owner(planting), :id, :name), class: 'form-control form-control-sm'
= submit_tag 'Transplant', class: 'btn btn-sm btn-primary mt-2'
.dropdown-divider
= delete_button(planting, classes: 'dropdown-item text-danger')

View File

@@ -19,6 +19,7 @@
- if planting.active
= planting_finish_button(planting, classes: 'dropdown-item')
= planting_failed_button(planting, classes: 'dropdown-item')
= planting_harvest_button(planting, classes: 'dropdown-item')
= planting_save_seeds_button(planting, classes: 'dropdown-item')

View File

@@ -1,13 +1,14 @@
%h2 Seeds saved
%a.btn.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-bs-toggle" => "dropdown", role: "button"}
= seed_icon
= t('buttons.save_seeds')
.dropdown-menu.dropdown-secondary
- Seed::TRADABLE_TO_VALUES.each do |trade|
= link_to seeds_path(return: 'planting', seed: {crop_id: planting.crop.id, parent_planting_id: planting.id, tradable_to: trade}), method: :post, class: 'dropdown-item' do
Will trade:
= trade
- if can?(:edit, planting) && !planting.failed?
%a.btn.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-bs-toggle" => "dropdown", role: "button"}
= seed_icon
= t('buttons.save_seeds')
.dropdown-menu.dropdown-secondary
- Seed::TRADABLE_TO_VALUES.each do |trade|
= link_to seeds_path(return: 'planting', seed: {crop_id: planting.crop.id, parent_planting_id: planting.id, tradable_to: trade}), method: :post, class: 'dropdown-item' do
Will trade:
= trade
- if planting.child_seeds.size.positive?
.index-cards

View File

@@ -40,7 +40,7 @@
- if planting.quantity.to_i.positive? && planting.planted_from.present?
= planting.planted_from.pluralize(planting.quantity.to_i)
- unless planting.finished?
- unless planting.finished? || planting.failed?
.card.fact-card.grid-sizer
%h3 Growing
%strong= seedling_icon

View File

@@ -34,9 +34,7 @@
.col-md-4
= f.text_field :planted_at,
value: @planting.planted_at ? @planting.planted_at.to_fs(:ymd) : '',
class: 'add-datepicker', label: 'When?'
%span.help-inline
Tip: Plan our your future plantings by forward dating, and subscribe to your iCalendar feed for reminders to plant
class: 'add-datepicker', label: 'When?', title: "Plan out your future plantings by forward dating, and subscribe to your iCalendar feed for reminders to plant"
.row
.col-md-4
@@ -49,14 +47,17 @@
.row
.col-md-6
= f.check_box :finished, label: 'Mark as finished'
%span.help-block= t('.finish_helper')
= f.check_box :finished, label: t('buttons.mark_as_finished'), title: t('.finish_helper')
.col-md-6
= f.text_field :finished_at,
value: @planting.finished_at ? @planting.finished_at.to_fs(:ymd) : '',
class: 'add-datepicker',
label: 'Finished date',
placeholder: 'optional'
.row
.col-md-6
= f.check_box :failed, label: t('buttons.mark_as_failed'), title: t('.failed_helper')
.card-footer
.text-right= f.submit 'Save'

View File

@@ -1,10 +1,9 @@
%h2 Harvests
- if can? :edit, planting
- if can?(:edit, planting) && !planting.failed
= render 'harvests/modal', harvest: Harvest.new(crop: planting.crop, planting: planting)
- if planting.harvests.empty?
%p No harvests recorded
- if !planting.finished? && can?(:edit, planting) && can?(:create, Harvest)
- if planting.finished? && can?(:edit, planting) && can?(:create, Harvest)
%p Record your harvests here to improve crop predictions, and you'll be able to compare with your garden next season.
- else
.index-cards

View File

@@ -8,6 +8,8 @@
%p.small #{harvest_icon} First harvest expected #{I18n.l planting.first_harvest_predicted_at}
- if planting.finished_at.present?
%p.small #{finished_icon} Finished #{I18n.l planting.finished_at}
- elsif planting.failed?
%p.small #{finished_icon} Failed
- elsif planting.finish_predicted_at.present?
%p.small #{finished_icon} Finish expected #{I18n.l planting.finish_predicted_at}
- if planting.planted_at.present? && planting.expected_lifespan.present?

View File

@@ -32,8 +32,10 @@
%strong= @planting.crop.name.titleize
%small.text-muted= @planting.crop.default_scientific_name
%tt
- if @planting.finished?
Finished
- if @planting.failed?
%span.badge.badge-danger Failed
- elsif @planting.finished?
%span.badge.badge-success Finished
- elsif @planting.percentage_grown.present?
#{@planting.percentage_grown.to_i}%
- if @planting.finish_is_predicatable?

View File

@@ -1,3 +1,4 @@
- @post ||= post if defined?(post)
%p
Posted by
- if @post.author
@@ -13,7 +14,7 @@
and edited at
= @post.updated_at.to_fs(:default)
= link_to "Permalink", post
= link_to "Permalink", @post
:markdown
#{ strip_tags markdownify(@post.body) }

View File

@@ -24,7 +24,7 @@
- content_for :buttonbar do
- if @post.comments.count > 10 && can?(:create, Comment)
= link_to 'Comment', new_comment_path(post_id: @post.id), class: 'btn'
= link_to 'Comment', new_comment_path(comment: { commentable_type: 'Post', commentable_id: @post.id }), class: 'btn'
- content_for :breadcrumbs do
%li.breadcrumb-item= link_to @post.author, @post.author
@@ -48,12 +48,12 @@
= render 'likes/likes', object: @post
.float-right
- if can? :create, Comment
= link_to new_comment_path(post_id: @post.id), class: 'btn' do
= link_to new_comment_path(comment: { commentable_type: 'Post', commentable_id: @post.id }), class: 'btn' do
= icon 'fas', 'comment'
Comment
%section.comments
= render "comments", post: @post
= render "comments/comments", commentable: @post
.col-md-4.col-12
= render @post.author

View File

@@ -38,7 +38,7 @@
.row
.col-12.col-md-4
= f.check_box :finished, label: 'Mark as finished'
= f.check_box :finished, label: t('buttons.mark_as_finished')
.col-12.col-md-4
= f.text_field :finished_at, class: 'add-datepicker', value: @seed.finished_at ? @seed.finished_at.to_fs(:ymd) : ''
.col-12.col-md-4

View File

@@ -1,6 +1,5 @@
# frozen_string_literal: true
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, ENV.fetch('GROWSTUFF_TWITTER_KEY', nil), ENV.fetch('GROWSTUFF_TWITTER_SECRET', nil)
provider :flickr, ENV.fetch('GROWSTUFF_FLICKR_KEY', nil), ENV.fetch('GROWSTUFF_FLICKR_SECRET', nil), scope: 'read'
end

View File

@@ -78,6 +78,7 @@ en:
harvest_crop: Harvest %{crop_name}
mark_as_active: Mark as active
mark_as_finished: Mark as finished
mark_as_failed: Mark as failed
mark_as_inactive: Mark as inactive
my_gardens: My Gardens
new_seeds: New saved seed
@@ -307,6 +308,8 @@ en:
finish_helper: >
A planting is finished when you've harvested all of the crop, or it dies, or it's otherwise
no longer growing in your garden.
failed_helper: >
Mark this planting as failed if it died or was removed without any harvest.
index:
title:
crop_plantings: Everyone's %{crop} plantings

View File

@@ -40,6 +40,9 @@ Rails.application.routes.draw do
collection do
get 'crop/:crop' => 'plantings#index', as: 'plantings_by_crop'
end
member do
post :transplant
end
end
resources :seeds, concerns: :has_photos, param: :slug do
@@ -78,7 +81,6 @@ Rails.application.routes.draw do
get 'sunniness' => 'charts/crops#sunniness', constraints: { format: 'json' }
get 'planted_from' => 'charts/crops#planted_from', constraints: { format: 'json' }
get 'harvested_for' => 'charts/crops#harvested_for', constraints: { format: 'json' }
post :openfarm
post :gbif
collection do

View File

@@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddLanguageToAlternateNames < ActiveRecord::Migration[7.2]
def change
add_column :alternate_names, :language, :string, null: false
end
end

View File

@@ -0,0 +1,11 @@
# frozen_string_literal: true
class SetDefaultLanguageForExistingAlternateNames < ActiveRecord::Migration[7.2]
def up
AlternateName.update_all(language: 'en')
end
def down
AlternateName.update_all(language: nil)
end
end

View File

@@ -0,0 +1,14 @@
class MakeNotificationsPolymorphic < ActiveRecord::Migration[6.1]
def change
add_column :notifications, :notifiable_type, :string
rename_column :notifications, :post_id, :notifiable_id
reversible do |dir|
dir.up do
ActiveRecord::Base.connection.execute("UPDATE notifications SET notifiable_type = 'Post' WHERE notifiable_type IS NULL")
end
end
add_index :notifications, %i(notifiable_type notifiable_id)
end
end

View File

@@ -0,0 +1,14 @@
class ChangeCommentsPolymorphic < ActiveRecord::Migration[7.2]
def change
add_column :comments, :commentable_type, :string
rename_column :comments, :post_id, :commentable_id
add_index :comments, %i(commentable_type commentable_id)
reversible do |dir|
dir.up do
ActiveRecord::Base.connection.execute("UPDATE comments SET commentable_type = 'Post' WHERE commentable_type IS NULL")
end
end
end
end

View File

@@ -0,0 +1,24 @@
# frozen_string_literal: true
class AddPhotosCommentCount < ActiveRecord::Migration[7.2]
def change
change_table :photos do |t|
t.integer :comments_count, default: 0
end
reversible do |dir|
dir.up { set_counter_value }
end
end
def set_counter_value
execute <<-SQL.squish
UPDATE photos
SET comments_count = (
SELECT count(1)
FROM comments
WHERE comments.commentable_id = comments.id
AND comments.commentable_type = 'Photo'
)
SQL
end
end

View File

@@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddFailedToPlantings < ActiveRecord::Migration[6.0]
def change
add_column :plantings, :failed, :boolean, default: false, null: false
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.2].define(version: 2024_09_29_041435) do
ActiveRecord::Schema[7.2].define(version: 2025_08_24_162600) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -67,6 +67,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_09_29_041435) do
t.integer "creator_id", null: false
t.datetime "created_at", precision: nil
t.datetime "updated_at", precision: nil
t.string "language"
end
create_table "authentications", id: :serial, force: :cascade do |t|
@@ -202,11 +203,12 @@ ActiveRecord::Schema[7.2].define(version: 2024_09_29_041435) do
end
create_table "comments", id: :serial, force: :cascade do |t|
t.integer "post_id", null: false
t.integer "commentable_id", null: false
t.integer "author_id", null: false
t.text "body", null: false
t.datetime "created_at", precision: nil
t.datetime "updated_at", precision: nil
t.string "commentable_type"
end
create_table "crop_companions", force: :cascade do |t|
@@ -470,9 +472,11 @@ ActiveRecord::Schema[7.2].define(version: 2024_09_29_041435) do
t.string "subject"
t.text "body"
t.boolean "read", default: false
t.integer "post_id"
t.integer "notifiable_id"
t.datetime "created_at", precision: nil
t.datetime "updated_at", precision: nil
t.string "notifiable_type"
t.index ["notifiable_type", "notifiable_id"], name: "index_notifications_on_notifiable_type_and_notifiable_id"
end
create_table "orders_products", id: false, force: :cascade do |t|
@@ -505,6 +509,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_09_29_041435) do
t.datetime "date_taken", precision: nil
t.integer "likes_count", default: 0
t.string "source"
t.integer "comments_count", default: 0
t.index ["fullsize_url"], name: "index_photos_on_fullsize_url", unique: true
t.index ["thumbnail_url"], name: "index_photos_on_thumbnail_url", unique: true
end
@@ -548,6 +553,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_09_29_041435) do
t.integer "parent_seed_id"
t.integer "harvests_count", default: 0
t.integer "likes_count", default: 0
t.boolean "failed", default: false, null: false
t.index ["slug"], name: "index_plantings_on_slug", unique: true
end

View File

@@ -40,11 +40,6 @@ GROWSTUFF_SITE_NAME="Growstuff (dev)"
GROWSTUFF_MAILCHIMP_APIKEY=""
GROWSTUFF_MAILCHIMP_NEWSLETTER_ID=""
# Used for connecting member accounts to Twitter
# Get Twitter key from https://dev.twitter.com/apps
GROWSTUFF_TWITTER_KEY=""
GROWSTUFF_TWITTER_SECRET=""
# Used for connecting member accounts to Flickr
# Get Flickr key from http://www.flickr.com/services/apps/create/apply/
GROWSTUFF_FLICKR_KEY=""

View File

@@ -61,8 +61,6 @@ class Growstuff::OauthSignupAction
def determine_name(auth)
case auth['provider']
when 'twitter'
auth['info']['nickname']
when 'flickr'
auth['info']['name']
else

View File

@@ -53,4 +53,12 @@ namespace :growstuff do
end
end
end
desc "Mark seeds as finished when plant-before date expires"
# usage: rake growstuff:finish_expired_seeds
task finish_expired_seeds: :environment do
Seed.expired.find_each do |seed|
seed.update(finished: true, finished_at: Time.zone.now)
end
end
end

View File

@@ -1,27 +0,0 @@
# frozen_string_literal: true
namespace :openfarm do
desc "Retrieve crop info from open farm"
# usage: rake growstuff:admin_user name=skud
task import: :environment do
Rails.logger = Logger.new(STDOUT)
OpenfarmService.new.import!
end
desc "Delete all pictures with source OpenFarm or from legacy S3 URL"
task delete_pictures: :environment do
puts "Deleting pictures with source OpenFarm or from legacy S3 URL..."
s3_legacy_url = 'https://s3.amazonaws.com/openfarm-project/%'
photos_to_delete = Photo.where(source: 'openfarm')
.or(Photo.where('fullsize_url LIKE ?', s3_legacy_url))
count = photos_to_delete.count
photos_to_delete.each do |photo|
photo.associations.each do |photo_association|
photo_association.delete
end
photo.delete
end
puts "Deleted #{count} pictures."
end
end

21
lib/tasks/photos.rake Normal file
View File

@@ -0,0 +1,21 @@
# frozen_string_literal: true
namespace :photos do
desc 'Removes references to photos that dont exist anymore (404)'
task prune_404s: :environment do
puts 'Checking for broken photo links...'
Photo.find_each do |photo|
puts "Checking #{photo.fullsize_url}..."
uri = URI.parse(photo.fullsize_url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = (uri.scheme == 'https')
request = Net::HTTP::Head.new(uri.request_uri)
response = http.request(request)
if response.code == '404'
puts "Photo #{photo.id} is broken, deleting."
photo.destroy
end
end
puts 'Done.'
end
end

58
lib/tasks/wikidata.rake Normal file
View File

@@ -0,0 +1,58 @@
# frozen_string_literal: true
require 'net/http'
require 'json'
namespace :wikidata do
desc "Imports alternate names from Wikidata"
task import_alternate_names: :environment do
creator = Member.find_by(admin: true)
unless creator
puts "Could not find an admin member to assign as creator."
return
end
Crop.all.each do |crop|
next unless crop.en_wikipedia_url.present?
begin
title = crop.en_wikipedia_url.split('/').last
puts "Processing crop: #{crop.name} (Wikipedia title: #{title})"
# Get Wikidata ID from Wikipedia API
wiki_uri = URI("https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&titles=#{title}&format=json")
wiki_response = Net::HTTP.get(wiki_uri)
wiki_data = JSON.parse(wiki_response)
page_id = wiki_data['query']['pages'].keys.first
wikidata_id = wiki_data['query']['pages'][page_id]['pageprops']['wikibase_item']
if wikidata_id
puts " Found Wikidata ID: #{wikidata_id}"
# Get aliases from Wikidata API
wikidata_uri = URI("https://www.wikidata.org/w/api.php?action=wbgetentities&ids=#{wikidata_id}&props=aliases&format=json")
wikidata_response = Net::HTTP.get(wikidata_uri)
wikidata_data = JSON.parse(wikidata_response)
aliases = wikidata_data['entities'][wikidata_id]['aliases']
aliases.each do |lang, values|
values.each do |value|
unless AlternateName.exists?(name: value['value'], language: lang, crop: crop)
AlternateName.create!(
name: value['value'],
language: lang,
crop: crop,
creator: creator
)
puts " Added alternate name: #{value['value']} (#{lang})"
end
end
end
else
puts " Could not find Wikidata ID for #{crop.name}"
end
rescue => e
puts " Error processing crop #{crop.name}: #{e.message}"
end
end
end
end

View File

@@ -20,6 +20,7 @@ RSpec.describe Api::V1::PlantingsController, type: :controller do
'description' => my_planting.description,
'expected-lifespan' => nil,
'finish-predicted-at' => nil,
'failed' => my_planting.failed,
'finished' => my_planting.finished,
'finished-at' => my_planting.finished_at,
'first-harvest-date' => nil,
@@ -54,6 +55,7 @@ RSpec.describe Api::V1::PlantingsController, type: :controller do
'description' => my_planting.description,
'expected-lifespan' => nil,
'finish-predicted-at' => nil,
'failed' => my_planting.failed,
'finished' => my_planting.finished,
'finished-at' => my_planting.finished_at,
'first-harvest-date' => nil,

View File

@@ -35,12 +35,16 @@ describe CommentsController do
let(:post) { FactoryBot.create(:post) }
describe "with valid params" do
before { get :new, params: { post_id: post.id } }
before do
get :new, params: {
comment: { commentable_id: post.id, commentable_type: "Post" }
}
end
let(:old_comment) { FactoryBot.create(:comment, post:) }
let(:old_comment) { FactoryBot.create(:comment, commentable: post) }
it "picks up post from params" do
expect(assigns(:post)).to eq(post)
expect(assigns(:commentable)).to eq(post)
end
it "assigns the old comments as @comments" do
@@ -60,8 +64,8 @@ describe CommentsController do
before { get :edit, params: { id: comment.to_param } }
describe "my comment" do
let!(:comment) { FactoryBot.create(:comment, author: member, post:) }
let!(:old_comment) { FactoryBot.create(:comment, post:, created_at: Time.zone.yesterday) }
let!(:comment) { FactoryBot.create(:comment, author: member, commentable: post) }
let!(:old_comment) { FactoryBot.create(:comment, commentable: post, created_at: Time.zone.yesterday) }
it "assigns previous comments as @comments" do
expect(assigns(:comments)).to eq([comment, old_comment])
@@ -69,7 +73,7 @@ describe CommentsController do
end
describe "not my comment" do
let(:comment) { FactoryBot.create(:comment, post:) }
let(:comment) { FactoryBot.create(:comment, commentable: post) }
it { expect(response).not_to be_successful }
end
@@ -82,7 +86,7 @@ describe CommentsController do
let(:comment) { FactoryBot.create(:comment, author: member) }
it "redirects to the comment's post" do
expect(response).to redirect_to(comment.post)
expect(response).to redirect_to(comment.commentable)
end
end
@@ -95,12 +99,12 @@ describe CommentsController do
describe "attempting to change post_id" do
let(:post) { FactoryBot.create(:post, subject: 'our post') }
let(:other_post) { FactoryBot.create(:post, subject: 'the other post') }
let(:valid_attributes) { { post_id: other_post.id, body: "kōrero" } }
let(:comment) { FactoryBot.create(:comment, author: member, post:) }
let(:valid_attributes) { { commentable_type: "Post", commentable_id: other_post.id, body: "kōrero" } }
let(:comment) { FactoryBot.create(:comment, author: member, commentable: post) }
it "does not change post_id" do
comment.reload
expect(comment.post_id).to eq(post.id)
expect(comment.commentable_id).to eq(post.id)
end
end
end
@@ -112,7 +116,7 @@ describe CommentsController do
let(:comment) { FactoryBot.create(:comment, author: member) }
it "redirects to the post the comment was on" do
expect(response).to redirect_to(comment.post)
expect(response).to redirect_to(comment.commentable)
end
end

View File

@@ -5,7 +5,6 @@ require 'rails_helper'
describe MembersController do
before do
@member = FactoryBot.create(:member)
@twitter_auth = FactoryBot.create(:authentication, member: @member)
@flickr_auth = FactoryBot.create(:flickr_authentication, member: @member)
end
@@ -29,11 +28,6 @@ describe MembersController do
expect(response).to be_successful
end
it "assigns @twitter_auth" do
get :show, params: { slug: @member.to_param }
expect(assigns(:twitter_auth)).to eq(@twitter_auth)
end
it "assigns @flickr_auth" do
get :show, params: { slug: @member.to_param }
expect(assigns(:flickr_auth)).to eq(@flickr_auth)

View File

@@ -16,12 +16,6 @@ describe RegistrationsController do
assigns(:member).should eq(@member)
end
it "picks up the twitter auth" do
@auth = FactoryBot.create(:authentication, member: @member)
get :edit
assigns(:twitter_auth).should eq @auth
end
it "picks up the flickr auth" do
@auth = FactoryBot.create(:flickr_authentication, member: @member)
get :edit

View File

@@ -5,6 +5,7 @@
FactoryBot.define do
factory :alternate_name do
name { "alternate name" }
language { "EN" }
crop
creator

View File

@@ -5,7 +5,7 @@
FactoryBot.define do
factory :authentication do
member
provider { 'twitter' }
provider { 'flickr' }
uid { 'foo' }
secret { 'bar' }
name { 'baz' }

View File

@@ -2,7 +2,7 @@
FactoryBot.define do
factory :comment do
post
association :commentable, factory: :post
author
sequence(:body) { |n| "OMG LOL #{n}" }
# because our commenters are more polite than YouTube's

View File

@@ -10,7 +10,7 @@ FactoryBot.define do
body { "MyText" }
read { false }
post
association :notifiable, factory: :post
factory :no_email_notification do
recipient { FactoryBot.create(:no_email_notifications_member) }

View File

@@ -7,9 +7,9 @@ describe 'Commenting on a post' do
let(:member) { create(:member) }
let(:post) { create(:post, author: member) }
before { visit new_comment_path post_id: post.id }
before { visit new_comment_path(comment: { commentable_type: "Post", commentable_id: post.id }) }
include_examples 'is accessible'
it_behaves_like 'is accessible'
it "creating a comment" do
fill_in "comment_body", with: "This is a sample test for comment"
@@ -20,13 +20,13 @@ describe 'Commenting on a post' do
end
context "editing a comment" do
let(:existing_comment) { create(:comment, post:, author: member) }
let(:existing_comment) { create(:comment, commentable: post, author: member) }
before do
visit edit_comment_path existing_comment
end
include_examples 'is accessible'
it_behaves_like 'is accessible'
it "saving edit" do
fill_in "comment_body", with: "Testing edit for comment"

View File

@@ -76,12 +76,6 @@ describe "member profile", :js do
end
end
it "twitter link" do
twitter_auth = create(:authentication, member:)
visit member_path(member)
expect(page).to have_link twitter_auth.name, href: "https://twitter.com/#{twitter_auth.name}"
end
it "flickr link" do
flickr_auth = create(:flickr_authentication, member:)
visit member_path(member)
@@ -161,7 +155,7 @@ describe "member profile", :js do
context 'member has comments' do
let(:post) { FactoryBot.create(:post) }
let!(:comment) { FactoryBot.create(:comment, post:, author: member) }
let!(:comment) { FactoryBot.create(:comment, commentable: post, author: member) }
before { visit member_path(member) }
@@ -227,8 +221,8 @@ describe "member profile", :js do
end
context "not signed in" do
include_examples 'member details'
include_examples 'member activity'
it_behaves_like 'member details'
it_behaves_like 'member activity'
it "no bio" do
member.update! bio: nil
@@ -239,8 +233,8 @@ describe "member profile", :js do
context "signed in member" do
include_context 'signed in member'
include_examples 'member details'
include_examples 'member activity'
it_behaves_like 'member details'
it_behaves_like 'member activity'
context "your own profile page" do
before { visit member_path(member) }

View File

@@ -188,8 +188,8 @@ rest of the garden.
describe 'posts' do
it 'loads posts#show' do
FactoryBot.create(:comment, post:)
FactoryBot.create(:comment, post:)
FactoryBot.create(:comment, commentable: post)
FactoryBot.create(:comment, commentable: post)
visit post_path(post)
page.percy_snapshot(page, name: "#{prefix}/posts#show")
end
@@ -199,7 +199,7 @@ rest of the garden.
FactoryBot.create_list(:post, 12, author: member)
end
Post.all.order(id: :desc).limit(4) do |post|
FactoryBot.create_list(:comment, rand(1..5), post:)
FactoryBot.create_list(:comment, rand(1..5), commentable: post)
end
visit posts_path
page.percy_snapshot(page, name: "#{prefix}/posts#index")
@@ -218,7 +218,7 @@ rest of the garden.
context "when signed out" do
let(:prefix) { 'signed-out' }
include_examples 'visit pages'
it_behaves_like 'visit pages'
it 'loads sign in page' do
visit crops_path # some random page
@@ -247,7 +247,7 @@ rest of the garden.
let(:prefix) { 'signed-in' }
include_context 'signed in member'
include_examples 'visit pages'
it_behaves_like 'visit pages'
it 'load my plantings#show' do
planting = FactoryBot.create(:planting, crop: tomato, owner: member, garden: member.gardens.first)
@@ -329,7 +329,7 @@ rest of the garden.
end
it 'comments#new' do
visit new_comment_path(post_id: post.id)
visit new_comment_path(comment: { commentable_type: Post, commentable_id: post.id })
page.percy_snapshot(page, name: "comments#new")
end
end

View File

@@ -233,6 +233,29 @@ describe "Planting a crop", :js, :search do
expect(page).to have_content "maize"
end
describe "Transplanting a planting" do
it "allows transplanting to another garden" do
other_garden = FactoryBot.create(:garden, owner: member, name: 'Backyard')
visit planting_path(planting)
click_link 'Actions'
select other_garden.name, from: 'Transplant to:'
click_on "Transplant"
expect(page).to have_content "Planting was successfully transplanted"
new_planting = Planting.last
planting.reload
# The old planting is finished.
expect(planting.finished).to be true
expect(planting.finished_at).not_to be_nil
# The new planting is a continuation of the old one.
expect(new_planting.garden).to eq(other_garden)
expect(new_planting.crop).to eq(planting.crop)
expect(new_planting.owner).to eq(planting.owner)
end
end
describe "Marking a planting as finished without a date" do
before do
fill_autocomplete "crop", with: "mai"

View File

@@ -41,7 +41,7 @@ describe ApplicationHelper do
context 'with a populated collection' do
context 'with one element' do
before { create(:comment, post:) }
before { create(:comment, commentable: post) }
it 'returns a string with the quantity and the plural of the model' do
expect(localize_plural(post.comments, Comment)).to eq '1 comment'
@@ -49,7 +49,7 @@ describe ApplicationHelper do
end
context 'with more than one element' do
before { create_list(:comment, 2, post:) }
before { create_list(:comment, 2, commentable: post) }
it 'returns a string with the quantity and the plural of the model' do
expect(localize_plural(post.comments, Comment)).to eq '2 comments'

View File

@@ -7,7 +7,7 @@ describe Comment do
let(:comment) { FactoryBot.create(:comment) }
it "belongs to a post" do
comment.post.should be_an_instance_of Post
comment.commentable.should be_an_instance_of Post
end
it "belongs to an author" do
@@ -26,17 +26,17 @@ describe Comment do
@c = FactoryBot.create(:comment)
@n = Notification.first
@n.sender.should eq @c.author
@n.recipient.should eq @c.post.author
@n.recipient.should eq @c.commentable.author
@n.subject.should include 'commented on'
@n.body.should eq @c.body
@n.post.should eq @c.post
@n.notifiable.should eq @c.commentable # polymorphic association, this is a Post.
end
it "doesn't send notifications to yourself" do
@m = FactoryBot.create(:member)
@p = FactoryBot.create(:post, author: @m)
expect do
FactoryBot.create(:comment, post: @p, author: @m)
FactoryBot.create(:comment, commentable: @p, author: @m)
end.not_to change(Notification, :count)
end
end
@@ -45,8 +45,8 @@ describe Comment do
before do
@m = FactoryBot.create(:member)
@p = FactoryBot.create(:post, author: @m)
@c1 = FactoryBot.create(:comment, post: @p, author: @m)
@c2 = FactoryBot.create(:comment, post: @p, author: @m)
@c1 = FactoryBot.create(:comment, commentable: @p, author: @m)
@c2 = FactoryBot.create(:comment, commentable: @p, author: @m)
end
it 'has a scope for ASC order for displaying on post page' do

View File

@@ -6,7 +6,7 @@ describe Notification do
let(:notification) { FactoryBot.create(:notification) }
it "belongs to a post" do
expect(notification.post).to be_an_instance_of Post
expect(notification.notifiable).to be_an_instance_of Post
end
it "belongs to a recipient" do

View File

@@ -45,6 +45,14 @@ describe Planting do
it { expect(planting.age_in_days).to eq(20) }
it { expect(planting.percentage_grown).to eq(100) }
end
describe 'planting finishing in the future' do
let(:planting) { FactoryBot.create(:planting, planted_at: 30.days.ago, finished_at: 10.days.from_now, finished: false) }
it { expect(planting.expected_lifespan).to eq(40) }
it { expect(planting.age_in_days).to eq(30) }
it { expect(planting.percentage_grown).to eq(75) }
end
end
context 'lots of data' do
@@ -513,6 +521,37 @@ describe Planting do
end
end
context "failed" do
let(:failed_planting) { FactoryBot.create(:planting, failed: true) }
it 'has a failed field' do
expect(failed_planting.failed).to be true
end
it 'has a failed scope' do
@p = FactoryBot.create(:planting)
@f = FactoryBot.create(:planting, failed: true)
described_class.failed.should include @f
described_class.failed.should_not include @p
end
it 'is not included in the active scope' do
@p = FactoryBot.create(:planting)
@f = FactoryBot.create(:planting, failed: true)
described_class.active.should include @p
described_class.active.should_not include @f
end
it 'cannot be finished and failed' do
@f = FactoryBot.build(:planting, finished: true, failed: true)
@f.should_not be_valid
end
it 'is not finished' do
@f = FactoryBot.build(:planting, finished: true, failed: true)
expect(@f.finished?).to be false
end
end
it 'excludes deleted members' do
expect(described_class.joins(:owner).all).to include(planting)
planting.owner.destroy
@@ -547,9 +586,13 @@ describe Planting do
let!(:finished_planting) do
FactoryBot.create(:finished_planting, owner: member, garden: member.gardens.first)
end
let!(:failed_planting) do
FactoryBot.create(:planting, failed: true, owner: member, garden: member.gardens.first)
end
it { expect(member.plantings.active).to include(planting) }
it { expect(member.plantings.active).not_to include(finished_planting) }
it { expect(member.plantings.active).not_to include(failed_planting) }
end
describe 'homepage', :search do

View File

@@ -19,22 +19,22 @@ describe Post do
it "has many comments" do
post = FactoryBot.create(:post, author: member)
FactoryBot.create(:comment, post:)
FactoryBot.create(:comment, post:)
FactoryBot.create(:comment, commentable: post)
FactoryBot.create(:comment, commentable: post)
post.comments.size.should == 2
end
it "supports counting comments" do
post = FactoryBot.create(:post, author: member)
FactoryBot.create(:comment, post:)
FactoryBot.create(:comment, post:)
FactoryBot.create(:comment, commentable: post)
FactoryBot.create(:comment, commentable: post)
post.comment_count.should == 2
end
it "destroys comments when deleted" do
post = FactoryBot.create(:post, author: member)
FactoryBot.create(:comment, post:)
FactoryBot.create(:comment, post:)
FactoryBot.create(:comment, commentable: post)
FactoryBot.create(:comment, commentable: post)
post.comments.size.should eq(2)
all = Comment.count
post.destroy
@@ -73,8 +73,8 @@ describe Post do
end
it "sets recent activity to comment time" do
comment = FactoryBot.create(:comment, post:,
created_at: 1.hour.ago)
comment = FactoryBot.create(:comment, commentable: post,
created_at: 1.hour.ago)
post.recent_activity.to_i.should eq comment.created_at.to_i
end
@@ -88,7 +88,7 @@ describe Post do
it "new comment on old post is recently active" do
# now comment on an older post
post2 = FactoryBot.create(:post, created_at: 1.minute.ago)
FactoryBot.create(:comment, post:, created_at: 1.second.ago)
FactoryBot.create(:comment, commentable: post, created_at: 1.second.ago)
described_class.recently_active.first.should eq post
described_class.recently_active.second.should eq post2
end

View File

@@ -132,6 +132,20 @@ describe Seed do
end
end
context 'expired' do
it 'returns seeds with a plant_before date in the past' do
expired_seed = FactoryBot.create(:seed, plant_before: 1.day.ago)
not_expired_seed = FactoryBot.create(:seed, plant_before: 1.day.from_now)
described_class.expired.should include expired_seed
described_class.expired.should_not include not_expired_seed
end
it 'does not return finished seeds' do
expired_seed = FactoryBot.create(:seed, plant_before: 1.day.ago, finished: true)
described_class.expired.should_not include expired_seed
end
end
context 'interesting' do
it 'lists interesting seeds' do
# to be interesting a seed must:

View File

@@ -57,6 +57,7 @@ RSpec.describe 'Plantings', type: :request do
{
"slug" => planting.slug,
"planted-at" => "2014-07-30",
"failed" => false,
"finished-at" => nil,
"finished" => false,
"quantity" => 33,

View File

@@ -1,33 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
require 'rake'
describe 'openfarm:delete_pictures' do
before(:all) do
Rails.application.load_tasks
end
# We need to do this because Rake tasks normally output to STDOUT, but we
# don't want to clutter up the test output.
before(:each) do
$stdout = StringIO.new
end
after(:each) do
$stdout = STDOUT
end
it 'deletes pictures with source OpenFarm' do
create(:photo, source: 'OpenFarm')
create(:photo, source: 'flickr')
expect(Photo.where(source: 'OpenFarm').count).to eq(1)
expect(Photo.where(source: 'flickr').count).to eq(1)
Rake::Task['openfarm:delete_pictures'].invoke
expect(Photo.where(source: 'OpenFarm').count).to eq(0)
expect(Photo.where(source: 'flickr').count).to eq(1)
end
end

View File

@@ -3,9 +3,12 @@
require 'rails_helper'
describe "comments/edit" do
let(:comment) { FactoryBot.create(:comment) }
before do
controller.stub(:current_user) { nil }
assign(:comment, FactoryBot.create(:comment))
assign(:comment, comment)
assign(:commentable, comment.commentable)
end
it "renders the edit comment form" do

View File

@@ -8,8 +8,8 @@ describe 'comments/index.rss.haml' do
@author = FactoryBot.create(:member)
@post = FactoryBot.create(:post)
assign(:comments, [
FactoryBot.create(:comment, author: @author, post: @post),
FactoryBot.create(:comment, author: @author, post: @post)
FactoryBot.create(:comment, author: @author, commentable: @post),
FactoryBot.create(:comment, author: @author, commentable: @post)
])
render
end

View File

@@ -6,9 +6,10 @@ describe "comments/new" do
before do
controller.stub(:current_user) { nil }
@post = FactoryBot.create(:post, body: 'tena koutou ki te ao')
@comment = FactoryBot.create(:comment, post: @post)
@comment = FactoryBot.create(:comment, commentable: @post)
assign(:comment, @comment)
assign(:comments, [@comment])
assign(:commentable, @post)
render
end

View File

@@ -60,29 +60,6 @@ describe 'devise/registrations/edit.html.haml', type: "view" do
end
context 'other sites section' do
context 'not connected to twitter' do
it 'has a link to connect' do
render
assert_select "a", "Connect to Twitter"
end
end
context 'connected to twitter' do
before do
@twitter_auth = FactoryBot.create(:authentication, member: @member)
render
end
it 'has a link to twitter profile' do
assert_select "a", href: "http://twitter.com/#{@twitter_auth.name}"
end
it 'has a link to disconnect' do
render
assert_select "a", href: @twitter_auth, text: "Disconnect"
end
end
context 'not connected to flickr' do
it 'has a link to connect' do
render

View File

@@ -24,7 +24,7 @@ describe "forums/index" do
context "posts" do
let!(:post) { FactoryBot.create(:forum_post, forum: forum1) }
let!(:comment) { FactoryBot.create(:comment, post:) }
let!(:comment) { FactoryBot.create(:comment, commentable: post) }
before { render }

View File

@@ -22,7 +22,7 @@ describe "posts/_single" do
end
it "doesn't contain a link to new comment" do
assert_select("a", { href: new_comment_path(post_id: @post.id) }, false)
assert_select("a", { href: new_comment_path(comment: { commmentable_type: "Post", commentable_id: @post.id }) }, false)
end
end
@@ -35,7 +35,7 @@ describe "posts/_single" do
end
it "contains link to new comment" do
assert_select("a", { href: new_comment_path(post_id: @post.id) }, "Reply")
assert_select("a", { href: new_comment_path(comment: { commmentable_type: "Post", commentable_id: @post.id }) }, "Reply")
end
it "does not contain an edit link" do
@@ -78,7 +78,7 @@ describe "posts/_single" do
sign_in @member
controller.stub(:current_user) { @member }
@post = FactoryBot.create(:post, author: @member)
@comment = FactoryBot.create(:comment, post: @post)
@comment = FactoryBot.create(:comment, commentable: @post)
@comment.update(body: "I've been updated")
render partial: "comments/single", locals: { comment: @comment }
end
@@ -113,7 +113,7 @@ describe "posts/_single" do
sign_in @member
controller.stub(:current_user) { @member }
@post = FactoryBot.create(:post, author: @member)
@comment = FactoryBot.create(:comment, post: @post)
@comment = FactoryBot.create(:comment, commentable: @post)
@comment.update(updated_at: @comment.created_at)
render partial: "comments/single", locals: { comment: @comment }
end

View File

@@ -61,7 +61,7 @@ describe "posts/show" do
context "when there is one comment" do
let(:post) { FactoryBot.create(:html_post, author:) }
let!(:comment) { FactoryBot.create(:comment, post:) }
let!(:comment) { FactoryBot.create(:comment, commentable: post) }
before do
@comments = post.comments
@@ -85,12 +85,12 @@ describe "posts/show" do
let(:post) { FactoryBot.create(:html_post, author:) }
before do
@comment1 = FactoryBot.create(:comment, post:, body: "F1rst!!!",
@comment1 = FactoryBot.create(:comment, commentable: post, body: "F1rst!!!",
created_at: Date.new(2010, 5, 17))
@comment3 = FactoryBot.create(:comment, post:, body: "Th1rd!!!",
@comment3 = FactoryBot.create(:comment, commentable: post, body: "Th1rd!!!",
created_at: Date.new(2012, 5, 17))
@comment4 = FactoryBot.create(:comment, post:, body: "F0urth!!!")
@comment2 = FactoryBot.create(:comment, post:, body: "S3c0nd!!1!",
@comment4 = FactoryBot.create(:comment, commentable: post, body: "F0urth!!!")
@comment2 = FactoryBot.create(:comment, commentable: post, body: "S3c0nd!!1!",
created_at: Date.new(2011, 5, 17))
@comments = post.comments
render
@@ -121,7 +121,7 @@ describe "posts/show" do
end
it 'shows a comment button' do
expect(subject).to have_link "Comment", href: new_comment_path(post_id: post.id)
expect(subject).to have_link "Comment", href: new_comment_path(comment: { commentable_type: "Post", commentable_id: post.id })
end
end
end

Some files were not shown because too many files have changed in this diff Show More