Compare commits

...

125 Commits

Author SHA1 Message Date
Shiny
b4fcf004cd Merge pull request #1484 from Growstuff/dev
Release 36
2017-12-14 19:37:02 +13:00
pozorvlak
b783448ec3 Merge pull request #1485 from Br3nda/planting-harvests
Show photos of a planting's harvests
2017-12-13 12:08:23 +00:00
pozorvlak
e8b5850bfe Merge branch 'dev' into planting-harvests 2017-12-13 10:57:40 +00:00
pozorvlak
bca72680c4 Merge pull request #1490 from Br3nda/dependabot/npm_and_yarn/coffeelint-2.0.7
Bump coffeelint from 1.16.0 to 2.0.7
2017-12-13 10:57:18 +00:00
pozorvlak
358eb96684 Merge branch 'dev' into dependabot/npm_and_yarn/coffeelint-2.0.7 2017-12-13 10:29:18 +00:00
pozorvlak
05807d41f4 Merge pull request #1491 from Br3nda/flickr-auth-fix
Fix Growstuff::OauthSignupAction not found error when connecting flickr
2017-12-13 10:27:16 +00:00
Shiny
96f1995768 Merge branch 'dev' into dependabot/npm_and_yarn/coffeelint-2.0.7 2017-12-13 23:26:07 +13:00
Shiny
deefbbce71 Merge branch 'dev' into planting-harvests 2017-12-13 23:25:56 +13:00
Brenda Wallace
1f66df0743 Fixed link to associated flickr, twitter, facebook accountss
fixes #1479
2017-12-13 22:23:22 +13:00
Brenda Wallace
72f52230a1 Fix Growstuff::OauthSignupAction not found error when connecting flickr account 2017-12-13 22:19:41 +13:00
Daniel O'Connor
acecbe93c1 Merge pull request #1487 from Growstuff/bundle-update-2017-12-11-160933
Bundle Update on 2017-12-11
2017-12-13 16:20:36 +10:00
dependabot[bot]
bafe2b7fd1 Bump coffeelint from 1.16.0 to 2.0.7
Bumps [coffeelint](https://github.com/clutchski/coffeelint) from 1.16.0 to 2.0.7.
- [Commits](https://github.com/clutchski/coffeelint/commits)
2017-12-12 11:00:57 +00:00
Shiny
3be1454a69 Merge branch 'dev' into bundle-update-2017-12-11-160933 2017-12-12 12:36:54 +13:00
Shiny
232e5d50ac Merge branch 'dev' into planting-harvests 2017-12-12 12:36:33 +13:00
pozorvlak
7207a39039 Merge pull request #1486 from Br3nda/cleanup/routes
Convert hashes in routes
2017-12-11 10:47:18 +00:00
deppbot
291f865f7f Bundle Update on 2017-12-11 2017-12-11 16:09:34 +08:00
Brenda Wallace
47e82eb0a7 Convert hashes in routes 2017-12-10 19:50:08 +13:00
Brenda Wallace
08dc2a0513 Show photos of a planting's harvests 2017-12-09 22:24:51 +13:00
Shiny
5d44196947 Merge branch 'master' into dev 2017-12-09 13:28:10 +13:00
Shiny
1c41cb7b66 Merge pull request #1483 from Growstuff/bundle-update-2017-12-08-121126
Bundle Update on 2017-12-08
2017-12-09 08:25:36 +13:00
Shiny
c3c55eaa09 Merge branch 'dev' into bundle-update-2017-12-08-121126 2017-12-09 08:15:28 +13:00
pozorvlak
98aa9521fe Merge pull request #1482 from Br3nda/ordering
Fixes to ordering
2017-12-08 12:04:48 +00:00
Shiny
96bb345ca9 Merge branch 'dev' into ordering 2017-12-08 20:20:27 +13:00
Shiny
9de991a075 Merge branch 'dev' into bundle-update-2017-12-08-121126 2017-12-08 20:19:39 +13:00
Shiny
f76619864c Merge pull request #1477 from Br3nda/upgrade-rubocop
Rubocop upgrade (and some style fixes)
2017-12-08 20:19:08 +13:00
deppbot
ec149997b0 Bundle Update on 2017-12-08 2017-12-08 12:11:27 +08:00
Brenda Wallace
ac07f18b2d Show most recent seeds first 2017-12-07 15:00:16 +13:00
Brenda Wallace
4ce3e8968f crops#show order posts by most recent first 2017-12-07 14:58:57 +13:00
Brenda Wallace
cd35538b83 Order forums by name 2017-12-07 13:42:48 +13:00
Brenda Wallace
35d8461811 Order recent plantings by when they were planted 2017-12-07 13:39:32 +13:00
Brenda Wallace
8d03a3ffa8 Most recent photos is a crop's default photo 2017-12-06 21:47:01 +13:00
Brenda Wallace
2b0f199329 change string replacement for performance reasons 2017-12-06 15:19:34 +13:00
Brenda Wallace
24f18f78da use bare percent literals 2017-12-06 14:33:51 +13:00
Brenda Wallace
3cc637017d Avoid {} for multiline 2017-12-06 14:29:21 +13:00
Brenda Wallace
37f9dcd7dd for simple loops, use Integer.times 2017-12-06 14:26:58 +13:00
Brenda Wallace
f516ef2e57 Don't use :: for method calls 2017-12-06 14:24:17 +13:00
Brenda Wallace
182c626226 Prefer if/unless modifier 2017-12-06 14:23:12 +13:00
Brenda Wallace
ea2fcd09dc Fixed last old style word array 2017-12-06 14:18:51 +13:00
Brenda Wallace
878fc7ebcd Use symbol procs 2017-12-06 14:17:34 +13:00
Brenda Wallace
3fdc23098e Use perl names for cli script variables 2017-12-06 14:16:47 +13:00
Brenda Wallace
515325c44e Fixed up % delimiters 2017-12-06 14:14:31 +13:00
Brenda Wallace
25b1836146 Removed nil comparison 2017-12-06 14:13:01 +13:00
Brenda Wallace
c925c95398 Use next, instead of a if wrapper 2017-12-06 14:11:27 +13:00
Brenda Wallace
2d00206abf Converted sprintf to format 2017-12-06 14:10:26 +13:00
Brenda Wallace
f499f245de Added new line after block end, for rubocpo 2017-12-06 14:08:05 +13:00
Brenda Wallace
35414391c3 modified spec to please rubocop 2017-12-06 14:07:18 +13:00
Brenda Wallace
1f7f4f52d1 Updated ability_spec.rb to use block end new lines 2017-12-06 14:02:48 +13:00
Brenda Wallace
b4efeee904 Merge remote-tracking branch 'origin/upgrade-rubocop' into upgrade-rubocop 2017-12-06 11:23:03 +13:00
Brenda Wallace
5b588bf9e9 Rubocop change namespace of some cops 2017-12-06 11:21:25 +13:00
Daniel O'Connor
07611e9a5d Merge branch 'dev' into upgrade-rubocop 2017-12-05 11:38:52 +10:30
Daniel O'Connor
baa89a790f Merge pull request #1480 from Growstuff/bundle-update-2017-12-05-081300
Bundle Update on 2017-12-05
2017-12-05 11:38:18 +10:30
deppbot
00395ae68b Bundle Update on 2017-12-05 2017-12-05 08:13:00 +08:00
Shiny
d7eb5e0014 Merge pull request #1472 from Growstuff/dev
Release 35
2017-12-02 21:16:29 +13:00
deppbot
f08d02f4c5 Bundle Update on 2017-12-02 2017-12-02 20:32:08 +13:00
Brenda Wallace
a6a7f789a3 Rubocop upgrade (and some style fixes) 2017-12-01 21:07:39 +13:00
Brenda Wallace
6ed7376c58 Name garden in spec to ensure it's ordered first 2017-11-29 20:59:37 +13:00
Brenda Wallace
c8a200bf19 Changed selector in view spec
it was having trouble finding the link
2017-11-29 20:59:37 +13:00
Brenda Wallace
a62b668781 Fix up duplicate order item in controller spec, and DRY 2017-11-29 20:59:37 +13:00
Brenda Wallace
09f82d5995 Tidy up home/crops partial view 2017-11-29 20:59:37 +13:00
Brenda Wallace
8d0bec34a6 Crops controller spec, use let, other cleanup 2017-11-29 20:59:37 +13:00
Brenda Wallace
d7ec4eacee Fix sort on plant parts 2017-11-29 20:59:37 +13:00
Brenda Wallace
3a3f4eefbf Added sort to members controller 2017-11-29 20:59:37 +13:00
Brenda Wallace
9e00023332 Fixed post ordering 2017-11-29 20:59:37 +13:00
Brenda Wallace
3058160a59 Removed an orderng spec for gardens 2017-11-29 20:59:37 +13:00
Brenda Wallace
e3886ce5b5 Fixed up unescaped model attribute 2017-11-29 20:59:37 +13:00
Brenda Wallace
48f8085e2d Fix seeds order 2017-11-29 20:59:37 +13:00
Brenda Wallace
594e466fd4 Fixed photos ordering 2017-11-29 20:59:37 +13:00
Brenda Wallace
b813669d71 Updated shop controller specs 2017-11-29 20:59:37 +13:00
Brenda Wallace
d0b8ae3411 Delete follows records when a member is deleted 2017-11-29 20:59:37 +13:00
Brenda Wallace
9c993e9f47 Plantings controller ordering and specs 2017-11-29 20:59:37 +13:00
Brenda Wallace
d5fece87d0 Tests for comments#index (and bugfix) 2017-11-29 20:59:37 +13:00
Brenda Wallace
33816d4312 Use faker gem, in account types - and add controller specs 2017-11-29 20:59:37 +13:00
Brenda Wallace
00e6aeed5c seed.tradable was back to front logic. fixed 2017-11-29 20:59:37 +13:00
Brenda Wallace
0205b345d0 A planting's photo is their most recent photo 2017-11-29 20:59:37 +13:00
Brenda Wallace
9f8a32e9f8 Feature plantings need to be ordered 2017-11-29 20:59:37 +13:00
Brenda Wallace
7357524271 Garden's default photo should be the most recent photo 2017-11-29 20:59:37 +13:00
Brenda Wallace
6aa689b0d8 Removed some model ordering specs 2017-11-29 20:59:37 +13:00
Brenda Wallace
962b3b574d Fixed up planting spec to not care about ordering 2017-11-29 20:59:37 +13:00
Brenda Wallace
d77d1d9a77 spec for notifications needs to be agnostic about the order 2017-11-29 20:59:37 +13:00
Brenda Wallace
4bed6da422 Crop validation methods can be private 2017-11-29 20:59:37 +13:00
Brenda Wallace
023c870d49 Fix up crop.recent 2017-11-29 20:59:37 +13:00
Brenda Wallace
9aff65e956 Added ordering to finding first photo 2017-11-29 20:59:37 +13:00
Brenda Wallace
0446c0a405 Add ordering back into controller #index 2017-11-29 20:59:37 +13:00
Brenda Wallace
7719d1f896 Remote default ordering scopes, and clean up models 2017-11-29 20:59:37 +13:00
Brenda Wallace
c9558e4d51 Merge branch 'master' into dev
Conflicts:
	Gemfile.lock
2017-11-29 10:46:08 +13:00
deppbot
8a679670e4 Bundle Update on 2017-11-29 2017-11-29 07:00:25 +13:00
pozorvlak
a7586e9d2b Merge pull request #1448 from Br3nda/fix/1211
upgrade leaflet-rails
2017-11-27 20:42:22 +00:00
Shiny
811011419e Exit if we can't cd 2017-11-26 09:39:43 +13:00
Shiny
dae3ea2789 removed some debug 2017-11-25 19:41:41 +13:00
Shiny
49aa6bb846 Update .travis.yml 2017-11-25 19:41:03 +13:00
Brenda Wallace
c154a9b845 Upgraded leaflet maskercluster 2017-11-25 19:34:05 +13:00
Shiny
ad14ecb41b Merge branch 'dev' into fix/1211 2017-11-25 17:03:23 +13:00
deppbot
08a73ce503 Bundle Update on 2017-11-24 2017-11-25 09:53:29 +13:00
Brenda Wallace
229396d9e7 Add id and type back to photos#new 2017-11-22 22:06:41 +13:00
Daniel O'Connor
0fa02272b0 Merge pull request #1465 from Growstuff/bundle-update-2017-11-21-121132
Bundle Update on 2017-11-21
2017-11-22 16:36:46 +10:30
deppbot
a91b8605c4 Bundle Update on 2017-11-21 2017-11-21 12:11:33 +08:00
pozorvlak
f1107b518c Merge pull request #1460 from Br3nda/fix/gardens-index
Fix gardens actions, and add specs
2017-11-20 11:21:07 +00:00
Shiny
52d93a7ccd Merge branch 'dev' into fix/1211 2017-11-19 18:22:02 +13:00
Brenda Wallace
d3df1e8f33 Move planting's add photo button to _actions.haml 2017-11-19 18:02:09 +13:00
Shiny
eb77715b70 Merge branch 'dev' into fix/gardens-index 2017-11-19 16:35:56 +13:00
Shiny
252910694d Merge branch 'master' into dev 2017-11-19 16:34:58 +13:00
Brenda Wallace
bd063be3a9 Fix gardens actions, and add specs
A bug slipped into all garden display pages - and there were no tests that caught it.
This adds feature specs for gardens#index, which would have detected the un-initialised
variable in haml
2017-11-19 16:31:17 +13:00
Shiny
9a6d827b6d Merge branch 'dev' into fix/1211 2017-11-19 11:14:09 +13:00
Logan Gingerich
ede5187369 Whitespace fix, spec fix, and spec addition 2017-11-19 11:13:41 +13:00
Logan Gingerich
610a5b7a48 deleted line 70 on plantings view to clean up logic 2017-11-19 11:13:41 +13:00
Logan Gingerich
1fa71c1546 Moved add photo button from garden show view to garden actions 2017-11-19 11:13:41 +13:00
Logan Gingerich
7574eb554e Adds a more prominent add photo button to garden and planting show views 2017-11-19 11:13:41 +13:00
Shiny
eea7e19ecf Merge branch 'dev' into fix/1211 2017-11-18 22:27:04 +13:00
Brenda Wallace
dafaffcd73 Path remains same after sign out for our test cases 2017-11-18 22:25:58 +13:00
Brenda Wallace
3e149a5d1d Feature spec for showing item details on photo adding page 2017-11-18 22:25:58 +13:00
Brenda Wallace
c20d9b78c5 Reduced the tests of signout on photos/new 2017-11-18 22:25:58 +13:00
Brenda Wallace
7906d50d13 Shaved some yaks to remove a rescue from a controller 2017-11-18 22:25:58 +13:00
Brenda Wallace
faed8b019e Removed rescue in a controller 2017-11-18 22:25:58 +13:00
Brenda Wallace
c8974a869f Use the ||= operator 2017-11-18 22:25:58 +13:00
Brenda Wallace
3969f410f1 Tidy up photos logic, and test of signin/out on photos#new 2017-11-18 22:25:58 +13:00
Logan Gingerich
6304f230a5 Refactored and specs updated 2017-11-18 22:25:58 +13:00
Logan Gingerich
73524b8883 Now displays correctly for planting, harvest or garden 2017-11-18 22:25:58 +13:00
Logan Gingerich
fd9fc38def fixes #1433 Says what item you're adding a photo to on photos#new 2017-11-18 22:25:58 +13:00
deppbot
949c7c31d8 Bundle Update on 2017-11-18 2017-11-18 15:27:04 +13:00
pozorvlak
e34dcd03bc Merge pull request #1454 from pozorvlak/dedeprecate_view_specs
De-deprecate controller and view specs
2017-11-17 17:05:07 +00:00
milesgould
d8bf8ae4df De-deprecate controller and view specs
We deprecated controller and view specs on the grounds that they were
brittle, and were a poorer measure of user experience than feature
specs. However, feature specs have their own problems: they're much
slower to run, and flakier (see #901). We also ran into a few cases
where feature specs erroneously passed because they were checking for
the presence of a string that occurred in the error page!

Hence, we're cautiously un-deprecating controller and view specs.

Fixes #1132
2017-11-17 16:51:24 +00:00
Shiny
83fea92353 Merge branch 'dev' into fix/1211 2017-11-15 09:27:17 +13:00
Shiny
1317ce9db0 Merge branch 'dev' into fix/1211 2017-11-13 23:08:38 +13:00
Brenda Wallace
e489831241 Debugging phantom on travis 2017-11-13 23:00:05 +13:00
Brenda Wallace
3d4f5c6917 upgrade leaflet-rails 2017-11-13 21:49:00 +13:00
109 changed files with 659 additions and 797 deletions

View File

@@ -7,12 +7,14 @@ AllCops:
Exclude:
- 'db/schema.rb'
- 'vendor/**/*'
TargetRailsVersion: 4.0
Rails:
Enabled: true
Style/FileName:
Exclude:
- 'Guardfile'
- 'Gemfile'
- 'Gemfile.lock'
@@ -26,12 +28,12 @@ Style/PercentLiteralDelimiters:
'%i': ()
'%w': ()
Style/MultilineMethodCallIndentation:
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: with_first_parameter, with_fixed_indentation
Style/AlignParameters:
Layout/AlignParameters:
EnforcedStyle: with_fixed_indentation
Metrics/LineLength:

View File

@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --no-offense-counts`
# on 2017-11-05 20:41:45 +1300 using RuboCop version 0.47.1.
# on 2017-12-06 11:20:15 +1300 using RuboCop version 0.49.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@@ -18,12 +18,6 @@ Lint/UnusedMethodArgument:
- 'app/controllers/passwords_controller.rb'
- 'app/controllers/registrations_controller.rb'
- 'app/validators/approved_validator.rb'
- 'spec/views/plantings/show.html.haml_spec.rb'
# Cop supports --auto-correct.
Performance/StringReplacement:
Exclude:
- 'spec/rails_helper.rb'
Rails/FilePath:
Exclude:
@@ -62,37 +56,6 @@ Style/AsciiComments:
Exclude:
- 'config/initializers/comfortable_mexican_sofa.rb'
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: percent_q, bare_percent
Style/BarePercentLiterals:
Exclude:
- 'app/helpers/auto_suggest_helper.rb'
- 'spec/support/feature_helpers.rb'
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'spec/controllers/order_items_controller_spec.rb'
- 'spec/features/notifications_spec.rb'
- 'spec/models/ability_spec.rb'
- 'spec/models/comment_spec.rb'
- 'spec/models/follow_spec.rb'
- 'spec/models/member_spec.rb'
- 'spec/models/post_spec.rb'
- 'spec/views/crops/edit.html.haml_spec.rb'
# Cop supports --auto-correct.
Style/BlockEndNewline:
Exclude:
- 'spec/models/ability_spec.rb'
- 'spec/models/member_spec.rb'
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
@@ -101,38 +64,10 @@ Style/ClassAndModuleChildren:
- 'lib/actions/oauth_signup_action.rb'
- 'lib/haml/filters/escaped_markdown.rb'
# Cop supports --auto-correct.
Style/ColonMethodCall:
Exclude:
- 'spec/lib/haml/filters/escaped_markdown_spec.rb'
- 'spec/lib/haml/filters/growstuff_markdown_spec.rb'
# Cop supports --auto-correct.
Style/EachForSimpleLoop:
Exclude:
- 'spec/models/crop_spec.rb'
- 'spec/views/home/_crops.html.haml_spec.rb'
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: format, sprintf, percent
Style/FormatString:
Exclude:
- 'app/helpers/application_helper.rb'
- 'spec/helpers/application_helper_spec.rb'
- 'spec/views/shop/index_spec.rb'
Style/IdenticalConditionalBranches:
Exclude:
- 'app/controllers/follows_controller.rb'
# Cop supports --auto-correct.
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier:
Exclude:
- 'app/helpers/crops_helper.rb'
- 'config/initializers/geocoder.rb'
- 'lib/tasks/growstuff.rake'
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: line_count_dependent, lambda, literal
@@ -146,32 +81,11 @@ Style/MultilineIfModifier:
Exclude:
- 'spec/rails_helper.rb'
Style/MultilineTernaryOperator:
Exclude:
- 'app/controllers/order_items_controller.rb'
# Cop supports --auto-correct.
Style/MutableConstant:
Exclude:
- 'app/models/planting.rb'
# Cop supports --auto-correct.
Style/NegatedIf:
Exclude:
- 'app/helpers/crops_helper.rb'
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
# SupportedStyles: skip_modifier_ifs, always
Style/Next:
Exclude:
- 'lib/tasks/growstuff.rake'
# Cop supports --auto-correct.
Style/NilComparison:
Exclude:
- 'lib/tasks/growstuff.rake'
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles.
# SupportedStyles: predicate, comparison
@@ -187,14 +101,6 @@ Style/ParallelAssignment:
Exclude:
- 'app/mailers/notifier.rb'
# Cop supports --auto-correct.
# Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters:
Exclude:
- 'app/helpers/auto_suggest_helper.rb'
- 'spec/features/signin_spec.rb'
- 'spec/features/signout_spec.rb'
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
@@ -205,23 +111,3 @@ Style/RegexpLiteral:
- 'spec/views/devise/registrations/edit_spec.rb'
- 'spec/views/members/index.html.haml_spec.rb'
- 'spec/views/posts/index.html.haml_spec.rb'
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles.
# SupportedStyles: use_perl_names, use_english_names
Style/SpecialGlobalVars:
EnforcedStyle: use_perl_names
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
# IgnoredMethods: respond_to, define_method
Style/SymbolProc:
Exclude:
- 'lib/tasks/growstuff.rake'
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles, WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray:
EnforcedStyle: percent
MinSize: 4

13
Gemfile
View File

@@ -1,4 +1,5 @@
# frozen_string_literal: true
source 'https://rubygems.org'
ruby '2.4.1'
@@ -32,8 +33,11 @@ gem 'cancancan' # for checking member privileges
gem 'csv_shaper' # CSV export
gem 'figaro' # for handling config via ENV variables
gem 'gibbon', '~>1.2.0' # for Mailchimp newsletter subscriptions
gem 'leaflet-markercluster-rails'
gem 'leaflet-rails', '~> 0.7.7' # Newer versions break tests - see https://travis-ci.org/CloCkWeRX/growstuff/builds/200984350
# Maps
gem 'leaflet-rails'
gem 'rails-assets-leaflet.markercluster', source: 'https://rails-assets.org'
gem 'pg'
gem 'ruby-units' # for unit conversion
gem 'unicorn' # http server
@@ -43,8 +47,8 @@ gem 'comfortable_mexican_sofa' # content management system
gem 'bootstrap-kaminari-views' # bootstrap views for kaminari
gem 'kaminari' # pagination
gem 'activemerchant'
gem 'active_utils'
gem 'activemerchant'
gem 'sidekiq'
# Markdown formatting for updates etc
@@ -131,6 +135,7 @@ group :development, :test do
gem 'coveralls', require: false # coverage analysis
gem 'database_cleaner'
gem 'factory_bot_rails' # for creating test data
gem 'faker'
gem 'haml-i18n-extractor'
gem 'haml-rails' # HTML templating language
gem 'haml_lint' # Checks haml files for goodness
@@ -140,7 +145,7 @@ group :development, :test do
gem 'rainbow', '< 2.2.0' # See https://github.com/sickill/rainbow/issues/44
gem 'rspec-activemodel-mocks'
gem 'rspec-rails' # unit testing framework
gem 'rubocop', '<= 0.47.1', require: false # Pin to rubocop (0.47.1) as 0.48.0 is buggy
gem 'rubocop'
gem 'selenium-webdriver'
gem 'webrat' # provides HTML matchers for view tests
end

View File

@@ -1,5 +1,6 @@
GEM
remote: https://rubygems.org/
remote: https://rails-assets.org/
specs:
actionmailer (4.2.10)
actionpack (= 4.2.10)
@@ -57,7 +58,7 @@ GEM
public_suffix (>= 2.0.2, < 4.0)
arel (6.0.4)
ast (2.3.0)
autoprefixer-rails (7.1.6)
autoprefixer-rails (7.2.2)
execjs
bcrypt (3.1.11)
better_errors (2.2.0)
@@ -80,11 +81,11 @@ GEM
sass (>= 3.3.4)
bootstrap_form (2.7.0)
builder (3.2.3)
bullet (5.6.1)
bullet (5.7.0)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.10.0)
byebug (9.1.0)
cancancan (2.1.1)
cancancan (2.1.2)
capybara (2.16.1)
addressable
mini_mime (>= 0.1.3)
@@ -180,6 +181,8 @@ GEM
factory_bot_rails (4.8.2)
factory_bot (~> 4.8.2)
railties (>= 3.0.0)
faker (1.8.5)
i18n (~> 0.9.1)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
ffi (1.9.18)
@@ -191,7 +194,7 @@ GEM
formatador (0.2.5)
friendly_id (5.2.3)
activerecord (>= 4.0.0)
geocoder (1.4.4)
geocoder (1.4.5)
gibbon (1.2.1)
httparty
multi_json (>= 1.9.0)
@@ -229,11 +232,11 @@ GEM
haml (>= 4.0.6, < 6.0)
html2haml (>= 1.0.1)
railties (>= 4.0.1)
haml_lint (0.25.1)
haml_lint (0.26.0)
haml (>= 4.0, < 5.1)
rainbow
rake (>= 10, < 13)
rubocop (>= 0.47.0)
rubocop (>= 0.49.0)
sysexits (~> 1.1)
hashie (3.5.6)
heroics (0.0.24)
@@ -241,7 +244,7 @@ GEM
excon
moneta
multi_json (>= 1.9.2)
highline (1.7.8)
highline (1.7.10)
html2haml (2.2.0)
erubis (~> 2.7.0)
haml (>= 4.0, < 6)
@@ -273,7 +276,7 @@ GEM
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
js-routes (1.4.1)
js-routes (1.4.2)
railties (>= 3.2)
sprockets-rails
json (2.1.0)
@@ -295,12 +298,11 @@ GEM
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
kgio (2.11.0)
kramdown (1.15.0)
kramdown (1.16.2)
launchy (2.4.3)
addressable (~> 2.3)
leaflet-markercluster-rails (0.7.0)
railties (>= 3.1)
leaflet-rails (0.7.7)
leaflet-rails (1.2.0)
rails (>= 4.2.0)
letter_opener (1.4.1)
launchy (~> 2.2)
listen (3.1.5)
@@ -333,7 +335,7 @@ GEM
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
oauth (0.5.3)
oauth (0.5.4)
oauth2 (1.4.0)
faraday (>= 0.8, < 0.13)
jwt (~> 1.0)
@@ -364,6 +366,7 @@ GEM
cocaine (~> 0.5.5)
mime-types
mimemagic (~> 0.3.0)
parallel (1.12.0)
parser (2.4.0.2)
ast (~> 2.3)
pg (0.21.0)
@@ -400,6 +403,9 @@ GEM
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.10)
sprockets-rails
rails-assets-leaflet (1.2.0)
rails-assets-leaflet.markercluster (1.2.0)
rails-assets-leaflet (>= 1.0.3)
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.8)
@@ -456,14 +462,15 @@ GEM
rspec-mocks (~> 3.7.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.0)
rubocop (0.47.1)
rubocop (0.49.1)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
ruby-units (2.2.0)
ruby-units (2.2.1)
ruby_dep (1.5.0)
ruby_parser (3.10.1)
sexp_processor (~> 4.9)
@@ -479,7 +486,7 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
selenium-webdriver (3.7.0)
selenium-webdriver (3.8.0)
childprocess (~> 0.5)
rubyzip (~> 1.0)
sexp_processor (4.10.0)
@@ -494,8 +501,8 @@ GEM
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
sparkpost_rails (1.4.0)
rails (>= 4.0, < 5.1)
sparkpost_rails (1.5.0)
rails (>= 4.0, < 5.2)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
@@ -514,11 +521,11 @@ GEM
thread_safe (0.3.6)
tilt (2.0.8)
timecop (0.9.1)
tins (1.15.1)
tins (1.16.3)
trollop (1.16.2)
tzinfo (1.2.4)
thread_safe (~> 0.1)
uglifier (3.2.0)
uglifier (4.0.2)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.3.0)
unicorn (5.3.1)
@@ -575,6 +582,7 @@ DEPENDENCIES
elasticsearch-model
elasticsearch-rails
factory_bot_rails
faker
figaro
flickraw
font-awesome-sass
@@ -596,8 +604,7 @@ DEPENDENCIES
js-routes
jsonapi-resources
kaminari
leaflet-markercluster-rails
leaflet-rails (~> 0.7.7)
leaflet-rails
letter_opener
memcachier
newrelic_rpm
@@ -611,13 +618,14 @@ DEPENDENCIES
pry
quiet_assets
rails (~> 4.2.8)
rails-assets-leaflet.markercluster!
rails_12factor
rainbow (< 2.2.0)
rake (>= 10.0.0)
responders
rspec-activemodel-mocks
rspec-rails
rubocop (<= 0.47.1)
rubocop
ruby-units
sass-rails
selenium-webdriver
@@ -635,4 +643,4 @@ RUBY VERSION
ruby 2.4.1p111
BUNDLED WITH
1.15.4
1.16.0

View File

@@ -1,13 +1,13 @@
guard :rspec,
cmd: 'bundle exec rspec --format documentation',
failed_mode: :keep do
cmd: 'bundle exec rspec --format documentation',
failed_mode: :keep do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/libs/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
end
end

0
Rakefile Normal file → Executable file
View File

View File

@@ -2,7 +2,6 @@
@import 'bootstrap-datepicker'
@import 'leaflet'
@import 'leaflet.markercluster'
@import 'leaflet.markercluster.default'
@import 'custom_bootstrap/custom_bootstrap'
@import 'overrides'
@import 'graphs'

View File

@@ -5,7 +5,7 @@ class AccountTypesController < ApplicationController
# GET /account_types
def index
@account_types = AccountType.all
@account_types = AccountType.all.order(:name)
respond_with(@account_types)
end

View File

@@ -5,7 +5,7 @@ class AccountsController < ApplicationController
# GET /accounts
def index
@accounts = Account.all
@accounts = Account.all.order(created_at: :desc)
respond_with(@accounts)
end

View File

@@ -1,5 +1,5 @@
class AlternateNamesController < ApplicationController
before_action :authenticate_member!, except: [:index, :show]
before_action :authenticate_member!, except: %i(index show)
load_and_authorize_resource
respond_to :html, :json
responders :flash
@@ -7,7 +7,7 @@ class AlternateNamesController < ApplicationController
# GET /alternate_names
# GET /alternate_names.json
def index
@alternate_names = AlternateName.all
@alternate_names = AlternateName.all.order(:name)
respond_with(@alternate_names)
end

View File

@@ -1,3 +1,4 @@
require './lib/actions/oauth_signup_action'
class AuthenticationsController < ApplicationController
before_action :authenticate_member!
load_and_authorize_resource

View File

@@ -1,12 +1,12 @@
class CommentsController < ApplicationController
before_action :authenticate_member!, except: [:index, :show]
before_action :authenticate_member!, except: %i(index show)
load_and_authorize_resource
respond_to :html, :json
respond_to :rss, only: :index
responders :flash
def index
@comments = Comment.paginate(page: params[:page])
@comments = Comment.order(created_at: :desc).paginate(page: params[:page])
respond_with(@comments)
end

View File

@@ -1,9 +1,9 @@
require 'will_paginate/array'
class CropsController < ApplicationController
before_action :authenticate_member!, except: [:index, :hierarchy, :search, :show]
before_action :authenticate_member!, except: %i(index hierarchy search show)
load_and_authorize_resource
skip_authorize_resource only: [:hierarchy, :search]
skip_authorize_resource only: %i(hierarchy search)
respond_to :html, :json, :rss, :csv
responders :flash
@@ -50,7 +50,7 @@ class CropsController < ApplicationController
def show
@crop = Crop.includes(:scientific_names, plantings: :photos).find(params[:id])
@posts = @crop.posts.paginate(page: params[:page])
@posts = @crop.posts.order(created_at: :desc).paginate(page: params[:page])
respond_to do |format|
format.html # show.html.haml
@@ -134,7 +134,7 @@ class CropsController < ApplicationController
end
def recreate_names(param_name, name_type)
return unless params[param_name].present?
return if params[param_name].blank?
destroy_names(name_type)
params[param_name].each do |_i, value|
create_name!(name_type, value) unless value.empty?
@@ -159,9 +159,9 @@ class CropsController < ApplicationController
:request_notes,
:reason_for_rejection,
:rejection_notes,
scientific_names_attributes: [:scientific_name,
:_destroy,
:id])
scientific_names_attributes: %i(scientific_name
_destroy
id))
end
def filename
@@ -173,7 +173,7 @@ class CropsController < ApplicationController
include: {
plantings: {
include: {
owner: { only: [:id, :login_name, :location, :latitude, :longitude] }
owner: { only: %i(id login_name location latitude longitude) }
}
},
scientific_names: { only: [:name] },
@@ -185,7 +185,7 @@ class CropsController < ApplicationController
def crops
q = Crop.approved.includes(:scientific_names, plantings: :photos)
q = q.popular unless @sort == 'alpha'
q.includes(:photos).paginate(page: params[:page])
q.order("LOWER(crops.name)").includes(:photos).paginate(page: params[:page])
end
def requested_crops

View File

@@ -5,7 +5,7 @@ class ForumsController < ApplicationController
# GET /forums
# GET /forums.json
def index
@forums = Forum.all
@forums = Forum.all.order(:name)
respond_with(@forums)
end

View File

@@ -1,6 +1,6 @@
class GardensController < ApplicationController
before_action :authenticate_member!, except: [:index, :show]
after_action :expire_homepage, only: [:create, :delete]
before_action :authenticate_member!, except: %i(index show)
after_action :expire_homepage, only: %i(create delete)
load_and_authorize_resource
respond_to :html, :json
@@ -68,6 +68,6 @@ class GardensController < ApplicationController
def gardens
g = @owner ? @owner.gardens : Garden.all
g = g.active unless @show_all
g.joins(:owner).order(:updated_at).paginate(page: params[:page])
g.joins(:owner).order(:name).paginate(page: params[:page])
end
end

View File

@@ -1,6 +1,6 @@
class MembersController < ApplicationController
load_and_authorize_resource except: [:finish_signup, :unsubscribe, :view_follows, :view_followers, :show]
skip_authorize_resource only: [:nearby, :unsubscribe, :finish_signup]
load_and_authorize_resource except: %i(finish_signup unsubscribe view_follows view_followers show)
skip_authorize_resource only: %i(nearby unsubscribe finish_signup)
respond_to :html, :json, :rss
after_action :expire_homepage, only: :create
@@ -62,7 +62,6 @@ class MembersController < ApplicationController
@member.update(@type => false)
flash.now[:notice] = I18n.t('members.unsubscribed', email_type: EMAIL_TYPE_STRING[@type])
rescue ActiveSupport::MessageVerifier::InvalidSignature
flash.now[:alert] = I18n.t('members.unsubscribe.error')
end
@@ -88,16 +87,18 @@ class MembersController < ApplicationController
end
def member_json_fields
[
:id, :login_name,
:slug, :bio, :created_at,
:location, :latitude, :longitude
]
%i(
id login_name
slug bio created_at
location latitude longitude
)
end
def members
q = Member.confirmed
q = q.recently_joined if @sort == 'recently_joined'
q.paginate(page: params[:page])
if @sort == 'recently_joined'
Member.recently_joined
else
Member.order(:login_name)
end.confirmed.paginate(page: params[:page])
end
end

View File

@@ -6,7 +6,7 @@ class NotificationsController < ApplicationController
# GET /notifications
def index
@notifications = Notification.by_recipient(current_member).page(params[:page])
@notifications = Notification.by_recipient(current_member).order(:created_at).page(params[:page])
end
# GET /notifications/1

View File

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

View File

@@ -1,28 +1,35 @@
class OrderItemsController < ApplicationController
before_action :authenticate_member!
load_and_authorize_resource
respond_to :html
responders :flash
# POST /order_items
def create
if params[:order_item][:price]
params[:order_item][:price] = params[:order_item][:price].to_f * 100 # convert to cents
end
@order_item = OrderItem.new(order_item_params)
@order_item.order = current_member.current_order || Order.create(member_id: current_member.id)
respond_to do |format|
if @order_item.save
format.html { redirect_to @order_item.order, notice: 'Added item to your order.' }
else
errors = @order_item.errors.empty? ?
"There was a problem with your order." : @order_item.errors.full_messages.to_sentence
format.html { redirect_to shop_path, alert: errors }
end
if @order_item.save
redirect_to @order_item.order, notice: 'Added item to your order.'
else
redirect_to shop_path, alert: errors
end
end
private
def errors
if @order_item.errors.empty?
"There was a problem with your order."
else
@order_item.errors.full_messages.to_sentence
end
end
def order_item_params
params.require(:order_item).permit(:order_id, :price, :product_id, :quantity)
end

View File

@@ -1,6 +1,6 @@
class PhotosController < ApplicationController
before_action :authenticate_member!, except: [:index, :show]
after_action :expire_homepage, only: [:create, :delete]
before_action :authenticate_member!, except: %i(index show)
after_action :expire_homepage, only: %i(create delete)
load_and_authorize_resource
respond_to :html, :json
responders :flash
@@ -12,7 +12,9 @@ class PhotosController < ApplicationController
else
@photos = Photo.all
end
@photos = @photos.includes(:owner).order(:created_at).paginate(page: params[:page])
@photos = @photos.order(created_at: :desc)
.includes(:owner)
.paginate(page: params[:page])
respond_with(@photos)
end

View File

@@ -7,9 +7,9 @@ class PlacesController < ApplicationController
format.html
# json response is whatever we want to map here
format.json do
render json: Member.located.to_json(only: [
:id, :login_name, :slug, :location, :latitude, :longitude
])
render json: Member.located.to_json(only: %i(
id login_name slug location latitude longitude
))
end
end
end
@@ -22,9 +22,9 @@ class PlacesController < ApplicationController
respond_to do |format|
format.html # show.html.haml
format.json do
render json: @nearby_members.to_json(only: [
:id, :login_name, :slug, :location, :latitude, :longitude
])
render json: @nearby_members.to_json(only: %i(
id login_name slug location latitude longitude
))
end
end
end

View File

@@ -4,7 +4,7 @@ class PlantPartsController < ApplicationController
responders :flash
def index
@plant_parts = PlantPart.all
@plant_parts = PlantPart.all.order(:name)
respond_with(@plant_parts)
end

View File

@@ -96,8 +96,8 @@ class PlantingsController < ApplicationController
end
p = p.current unless @show_all
p.joins(:owner, :crop, :garden)
.order(created_at: :desc)
.includes(:crop, :owner, :garden)
.order(:created_at)
.paginate(page: params[:page])
end
end

View File

@@ -1,8 +1,8 @@
class PostsController < ApplicationController
before_action :authenticate_member!, except: [:index, :show]
before_action :authenticate_member!, except: %i(index show)
load_and_authorize_resource
respond_to :html, :json
respond_to :rss, only: [:index, :show]
respond_to :rss, only: %i(index show)
# GET /posts
# GET /posts.json
@@ -66,6 +66,6 @@ class PostsController < ApplicationController
@author.posts
else
Post
end.includes(:author, comments: :author).paginate(page: params[:page])
end.order(created_at: :desc).includes(:author, comments: :author).paginate(page: params[:page])
end
end

View File

@@ -5,7 +5,7 @@ class ProductsController < ApplicationController
responders :flash
def index
@products = Product.all
@products = Product.all.order(:name)
respond_with @products
end

View File

@@ -5,7 +5,7 @@ class RolesController < ApplicationController
responders :flash
def index
@roles = Role.all
@roles = Role.all.order(:name)
respond_with @roles
end

View File

@@ -1,5 +1,5 @@
class ScientificNamesController < ApplicationController
before_action :authenticate_member!, except: [:index, :show]
before_action :authenticate_member!, except: %i(index show)
load_and_authorize_resource
respond_to :html, :json
responders :flash
@@ -7,7 +7,7 @@ class ScientificNamesController < ApplicationController
# GET /scientific_names
# GET /scientific_names.json
def index
@scientific_names = ScientificName.all
@scientific_names = ScientificName.all.order(:name)
respond_with(@scientific_names)
end

View File

@@ -1,5 +1,5 @@
class SeedsController < ApplicationController
before_action :authenticate_member!, except: [:index, :show]
before_action :authenticate_member!, except: %i(index show)
load_and_authorize_resource
respond_to :html, :json
respond_to :csv, only: :index
@@ -75,7 +75,7 @@ class SeedsController < ApplicationController
crop.seeds
else
Seed
end.includes(:owner, :crop).paginate(page: params[:page])
end.order(created_at: :desc).includes(:owner, :crop).paginate(page: params[:page])
end
def csv_filename

View File

@@ -1,11 +1,11 @@
module ApplicationHelper
def price_in_dollars(price)
sprintf('%.2f', price / 100.0)
format('%.2f', price / 100.0)
end
# 999 cents becomes 9.99 AUD -- for products/orders/etc
def price_with_currency(price)
sprintf('%.2f %s', price / 100.0, Growstuff::Application.config.currency)
format('%.2f %s', price / 100.0, Growstuff::Application.config.currency)
end
def parse_date(str)

View File

@@ -11,7 +11,7 @@ module AutoSuggestHelper
resource = resource.class.name.downcase
source_path = Rails.application.routes.url_helpers.send("#{source}s_search_path")
%Q{
%(
<input id="#{source}" class="auto-suggest #{options[:class]}"
type="text" value="#{default}" data-source-url="#{source_path}",
placeholder="e.g. lettuce">
@@ -20,6 +20,6 @@ module AutoSuggestHelper
</noscript>
<input id="#{resource}_#{source}_id" class="auto-suggest-id"
type="hidden" name="#{resource}[#{source}_id]" value="#{default_id}">
}.html_safe
).html_safe
end
end

View File

@@ -8,9 +8,7 @@ module CropsHelper
total_quantity += seed.quantity if seed.quantity
end
if !seeds.any?
return "You don't have any seeds of this crop."
end
return "You don't have any seeds of this crop." if seeds.none?
if total_quantity != 0
"You have #{total_quantity} #{Seed.model_name.human(count: total_quantity)} of this crop."

View File

@@ -15,7 +15,7 @@ module HarvestsHelper
if harvest.unit == 'individual' # just the number
number_to_human(harvest.quantity, strip_insignificant_zeros: true)
elsif !harvest.unit.blank? # pluralize anything else
elsif harvest.unit.present? # pluralize anything else
pluralize(number_to_human(harvest.quantity, strip_insignificant_zeros: true), harvest.unit)
else
"#{number_to_human(harvest.quantity, strip_insignificant_zeros: true)} #{harvest.unit}"

View File

@@ -10,11 +10,11 @@ module PlantingsHelper
end
def display_planted_from(planting)
!planting.planted_from.blank? ? planting.planted_from : "not specified"
planting.planted_from.present? ? planting.planted_from : "not specified"
end
def display_planting_quantity(planting)
!planting.quantity.blank? ? planting.quantity : "not specified"
planting.quantity.present? ? planting.quantity : "not specified"
end
def display_planting(planting)

View File

@@ -1,6 +1,12 @@
class AccountType < ActiveRecord::Base
#
# Relationships
has_many :products
#
# Validations
validates :name, presence: true, uniqueness: true
def to_s
name
end

View File

@@ -2,7 +2,6 @@ class Comment < ActiveRecord::Base
belongs_to :author, class_name: 'Member'
belongs_to :post
default_scope { order("created_at DESC") }
scope :post_order, -> { reorder("created_at ASC") } # for display on post page
after_create do

View File

@@ -1,6 +1,6 @@
class Crop < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: [:slugged, :finders]
friendly_id :name, use: %i(slugged finders)
##
## Triggers
@@ -24,8 +24,7 @@ class Crop < ActiveRecord::Base
##
## Scopes
default_scope { order("lower(crops.name) asc") }
scope :recent, -> { approved.reorder("created_at desc") }
scope :recent, -> { approved.order(created_at: :desc) }
scope :toplevel, -> { approved.where(parent_id: nil) }
scope :popular, -> { approved.reorder("plantings_count desc, lower(name) asc") }
# ok on sqlite and psql, but not on mysql
@@ -121,7 +120,8 @@ class Crop < ActiveRecord::Base
# later we can choose a default photo based on different criteria,
# eg. popularity
def default_photo
return photos.first if photos.any?
# most recent photo
return photos.order(created_at: :desc).first if photos.any?
# Crop has no photos? Look for the most recent harvest with a photo.
harvest_with_photo = Harvest.where(crop_id: id).joins(:photos).order('harvests.id DESC').limit(1).first

View File

@@ -34,7 +34,7 @@ class CsvImporter
def add_scientific_names(scientific_names)
names_to_add = []
if !scientific_names.blank? # i.e. we actually passed something in, which isn't a given
if scientific_names.present? # i.e. we actually passed something in, which isn't a given
names_to_add = scientific_names.split(/,\s*/)
elsif @crop.parent && !@crop.parent.scientific_names.empty? # pick up from parent
names_to_add = @crop.parent.scientific_names.map(&:name)

View File

@@ -14,7 +14,7 @@ class Garden < ActiveRecord::Base
after_validation :empty_unwanted_geocodes
after_save :mark_inactive_garden_plantings_as_finished
default_scope { joins(:owner).order("lower(name) asc") }
default_scope { joins(:owner) } # Ensures owner exists
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
@@ -62,7 +62,7 @@ class Garden < ActiveRecord::Base
unique_plantings = []
seen_crops = []
plantings.includes(:garden, :crop, :owner, :harvests).each do |p|
plantings.order(created_at: :desc).includes(:garden, :crop, :owner, :harvests).each do |p|
unless seen_crops.include?(p.crop)
unique_plantings.push(p)
seen_crops.push(p.crop)
@@ -88,6 +88,6 @@ class Garden < ActiveRecord::Base
end
def default_photo
photos.first
photos.order(created_at: :desc).first
end
end

View File

@@ -39,7 +39,7 @@ class Harvest < ActiveRecord::Base
##
## Scopes
default_scope { joins(:owner) }
default_scope { joins(:owner) } # Ensures owner exists
##
## Validations
@@ -124,9 +124,11 @@ class Harvest < ActiveRecord::Base
end
def default_photo
photos.first || crop.default_photo
photos.order(created_at: :desc).first || crop.default_photo
end
private
def crop_must_match_planting
return if planting.blank? # only check if we are linked to a planting
errors.add(:planting, "must be the same crop") unless crop == planting.crop

View File

@@ -6,48 +6,40 @@ class Member < ActiveRecord::Base
friendly_id :login_name, use: %i(slugged finders)
#
# Relationshops
has_many :posts, foreign_key: 'author_id'
has_many :comments, foreign_key: 'author_id'
has_many :forums, foreign_key: 'owner_id'
has_many :gardens, foreign_key: 'owner_id'
has_many :plantings, foreign_key: 'owner_id'
has_many :seeds, foreign_key: 'owner_id'
has_many :harvests, foreign_key: 'owner_id'
has_and_belongs_to_many :roles # rubocop:disable Rails/HasAndBelongsToMany
has_many :notifications, foreign_key: 'recipient_id'
has_many :sent_notifications, foreign_key: 'sender_id'
has_many :authentications
has_many :orders
has_one :account
has_one :account_type, through: :account
has_many :photos
has_many :requested_crops, class_name: Crop, foreign_key: 'requester_id'
has_many :likes, dependent: :destroy
has_many :follows, class_name: "Follow", foreign_key: "follower_id", dependent: :destroy
has_many :inverse_follows, class_name: "Follow", foreign_key: "followed_id", dependent: :destroy
has_many :followed, through: :follows
has_many :followers, through: :inverse_follows, source: :follower
default_scope { order("lower(login_name) asc") }
#
# Scopes
scope :confirmed, -> { where.not(confirmed_at: nil) }
scope :located, -> { where.not(location: '').where.not(latitude: nil).where.not(longitude: nil) }
scope :recently_signed_in, -> { reorder(updated_at: :desc) }
scope :recently_joined, -> { reorder(confirmed_at: :desc) }
scope :wants_newsletter, -> { where(newsletter: true) }
scope :interesting, -> { confirmed.located.recently_signed_in.has_plantings }
scope :has_plantings, -> { joins(:plantings).group("members.id") }
has_many :follows, class_name: "Follow", foreign_key: "follower_id"
has_many :followed, through: :follows
has_many :inverse_follows, class_name: "Follow", foreign_key: "followed_id"
has_many :followers, through: :inverse_follows, source: :follower
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
@@ -57,45 +49,42 @@ class Member < ActiveRecord::Base
# set up geocoding
geocoded_by :location
after_validation :geocode
after_validation :empty_unwanted_geocodes
# Virtual attribute for authenticating by either username or email
# This is in addition to a real persisted field like 'username'
attr_accessor :login
#
# Validations
# Requires acceptance of the Terms of Service
validates :tos_agreement, acceptance: { allow_nil: true,
accept: true }
validates :tos_agreement, acceptance: { allow_nil: true, accept: true }
validates :login_name,
length: {
minimum: 2,
maximum: 25,
message: "should be between 2 and 25 characters long"
minimum: 2, maximum: 25, message: "should be between 2 and 25 characters long"
},
exclusion: {
in: %w(growstuff admin moderator staff nearby),
message: "name is reserved"
in: %w(growstuff admin moderator staff nearby), message: "name is reserved"
},
format: {
with: /\A\w+\z/,
message: "may only include letters, numbers, or underscores"
with: /\A\w+\z/, message: "may only include letters, numbers, or underscores"
},
uniqueness: {
case_sensitive: false
}
# Give each new member a default garden
after_create { |member| Garden.create(name: "Garden", owner_id: member.id) }
#
# Triggers
after_validation :geocode
after_validation :empty_unwanted_geocodes
after_save :update_newsletter_subscription
# Give each new member a default garden
# and an account record (for paid accounts etc)
# we use find_or_create to avoid accidentally creating a second one,
# which can happen sometimes especially with FactoryBot associations
after_create { |member| Garden.create(name: "Garden", owner_id: member.id) }
after_create { |member| Account.find_or_create_by(member_id: member.id) }
after_save :update_newsletter_subscription
# allow login via either login_name or email address
def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup

View File

@@ -5,7 +5,6 @@ class Notification < ActiveRecord::Base
validates :subject, length: { maximum: 255 }
default_scope { order('created_at DESC') }
scope :unread, -> { where(read: false) }
scope :by_recipient, ->(recipient) { where(recipient_id: recipient) }

View File

@@ -1,17 +1,22 @@
class Order < ActiveRecord::Base
#
# Relationships
belongs_to :member, with_deleted: true
has_many :order_items, dependent: :destroy
default_scope { order('created_at DESC') }
#
# Validations
validates :referral_code, format: {
with: /\A[a-zA-Z0-9 ]*\z/,
message: "may only include letters and numbers"
}
#
# Teiggers
before_save :standardize_referral_code
#
# Scopes
scope :by_member, ->(member) { where(member: member) }
# total price of an order

View File

@@ -8,7 +8,7 @@ class Photo < ActiveRecord::Base
before_destroy { all_associations.clear }
default_scope { joins(:owner).order(created_at: :desc) }
default_scope { joins(:owner) } # Ensures the owner still exists
def associations?
plantings.any? || harvests.any? || gardens.any? || seeds.any?

View File

@@ -22,7 +22,7 @@ class Planting < ActiveRecord::Base
##
## Scopes
default_scope { joins(:owner).order(created_at: :desc) }
default_scope { joins(:owner) } # Ensures the owner still exists
scope :finished, -> { where(finished: true) }
scope :current, -> { where(finished: false) }
scope :interesting, -> { has_photos.one_per_owner }
@@ -72,7 +72,7 @@ class Planting < ActiveRecord::Base
end
def default_photo
photos.first
photos.order(created_at: :desc).first
end
def planted?

View File

@@ -2,45 +2,27 @@ class Post < ActiveRecord::Base
extend FriendlyId
include Likeable
friendly_id :author_date_subject, use: %i(slugged finders)
#
# Relationships
belongs_to :author, class_name: 'Member'
belongs_to :forum
has_many :comments, dependent: :destroy
has_and_belongs_to_many :crops # rubocop:disable Rails/HasAndBelongsToMany
before_destroy { |post| post.crops.clear }
after_save :update_crops_posts_association
# also has_many notifications, but kinda meaningless to get at them
# from this direction, so we won't set up an association for now.
after_create do
recipients = []
sender = author.id
body.scan(Haml::Filters::GrowstuffMarkdown::MEMBER_REGEX) do |_m|
# find member case-insensitively and add to list of recipients
member = Member.case_insensitive_login_name(Regexp.last_match(1)).first
recipients << member if member && !recipients.include?(member)
end
body.scan(Haml::Filters::GrowstuffMarkdown::MEMBER_AT_REGEX) do |_m|
# find member case-insensitively and add to list of recipients
member = Member.case_insensitive_login_name(Regexp.last_match(1)[1..-1]).first
recipients << member if member && !recipients.include?(member)
end
# don't send notifications to yourself
recipients.map(&:id).each do |recipient|
next unless recipient != sender
Notification.create(
recipient_id: recipient,
sender_id: sender,
subject: "#{author} mentioned you in their post #{subject}",
body: body
)
end
end
#
# Triggers
before_destroy { |post| post.crops.clear }
after_save :update_crops_posts_association
after_create :send_notification
default_scope { joins(:author).order(created_at: :desc) }
default_scope { joins(:author) } # Ensures the owner still exists
validates :subject,
presence: true,
length: { maximum: 255 }
#
# Validations
validates :subject, presence: true, length: { maximum: 255 }
def author_date_subject
# slugs are created before created_at is set
@@ -56,7 +38,7 @@ class Post < ActiveRecord::Base
# i.e. the time of the most recent comment, or of the post itself if
# there are no comments.
def recent_activity
comments.present? ? comments.reorder('created_at DESC').first.created_at : created_at
comments.present? ? comments.order(created_at: :desc).first.created_at : created_at
end
# return posts sorted by recent activity
@@ -78,4 +60,29 @@ class Post < ActiveRecord::Base
crops << crop if crop && !crops.include?(crop)
end
end
def send_notification
recipients = []
sender = author.id
body.scan(Haml::Filters::GrowstuffMarkdown::MEMBER_REGEX) do |_m|
# find member case-insensitively and add to list of recipients
member = Member.case_insensitive_login_name(Regexp.last_match(1)).first
recipients << member if member && !recipients.include?(member)
end
body.scan(Haml::Filters::GrowstuffMarkdown::MEMBER_AT_REGEX) do |_m|
# find member case-insensitively and add to list of recipients
member = Member.case_insensitive_login_name(Regexp.last_match(1)[1..-1]).first
recipients << member if member && !recipients.include?(member)
end
# don't send notifications to yourself
recipients.map(&:id).each do |recipient_id|
next unless recipient_id != sender
Notification.create(
recipient_id: recipient_id,
sender_id: sender,
subject: "#{author} mentioned you in their post #{subject}",
body: body
)
end
end
end

View File

@@ -1,13 +1,12 @@
class Product < ActiveRecord::Base
has_and_belongs_to_many :orders # rubocop:disable Rails/HasAndBelongsToMany
#
# Relationships
belongs_to :account_type
has_and_belongs_to_many :orders # rubocop:disable Rails/HasAndBelongsToMany
validates :paid_months,
numericality: {
only_integer: true,
greater_than_or_equal_to: 0
},
allow_nil: true
#
# Validations
validates :paid_months, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :min_price, presence: true
def to_s

View File

@@ -1,83 +1,52 @@
class Seed < ActiveRecord::Base
extend FriendlyId
include PhotoCapable
friendly_id :seed_slug, use: [:slugged, :finders]
friendly_id :seed_slug, use: %i(slugged finders)
TRADABLE_TO_VALUES = %w(nowhere locally nationally internationally).freeze
ORGANIC_VALUES = ['certified organic', 'non-certified organic', 'conventional/non-organic', 'unknown'].freeze
GMO_VALUES = ['certified GMO-free', 'non-certified GMO-free', 'GMO', 'unknown'].freeze
HEIRLOOM_VALUES = %w(heirloom hybrid unknown).freeze
#
# Relationships
belongs_to :crop
belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id', counter_cache: true
default_scope { joins(:owner).order(created_at: :desc) }
#
# Validations
validates :crop, approved: true
delegate :name, to: :crop
delegate :default_photo, to: :crop
validates :crop, presence: { message: "must be present and exist in our database" }
validates :quantity,
numericality: {
only_integer: true,
greater_than_or_equal_to: 0
},
allow_nil: true
validates :days_until_maturity_min,
numericality: {
only_integer: true,
greater_than_or_equal_to: 0
},
allow_nil: true
validates :days_until_maturity_max,
numericality: {
only_integer: true,
greater_than_or_equal_to: 0
},
allow_nil: true
validates :quantity, allow_nil: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :days_until_maturity_min, allow_nil: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :days_until_maturity_max, allow_nil: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :tradable_to, allow_nil: false, allow_blank: false,
inclusion: { in: TRADABLE_TO_VALUES, message: "You may only trade seed nowhere, "\
"locally, nationally, or internationally" }
validates :organic, allow_nil: false, allow_blank: false,
inclusion: { in: ORGANIC_VALUES, message: "You must say whether the seeds "\
"are organic or not, or that you don't know" }
validates :gmo, allow_nil: false, allow_blank: false,
inclusion: { in: GMO_VALUES, message: "You must say whether the seeds are "\
"genetically modified or not, or that you don't know" }
validates :heirloom, allow_nil: false, allow_blank: false,
inclusion: { in: HEIRLOOM_VALUES, message: "You must say whether the seeds"\
"are heirloom, hybrid, or unknown" }
#
# Scopes
default_scope { joins(:owner) } # Ensure owner exists
scope :tradable, -> { where.not(tradable_to: 'nowhere') }
scope :interesting, -> { tradable.has_location }
scope :has_location, -> { joins(:owner).where.not("members.location": nil) }
TRADABLE_TO_VALUES = %w(nowhere locally nationally internationally).freeze
validates :tradable_to, inclusion: { in: TRADABLE_TO_VALUES,
message: "You may only trade seed nowhere, "\
"locally, nationally, or internationally" },
allow_nil: false,
allow_blank: false
ORGANIC_VALUES = [
'certified organic',
'non-certified organic',
'conventional/non-organic',
'unknown'
].freeze
validates :organic, inclusion: { in: ORGANIC_VALUES,
message: "You must say whether the seeds "\
"are organic or not, or that you don't know" },
allow_nil: false,
allow_blank: false
GMO_VALUES = [
'certified GMO-free',
'non-certified GMO-free',
'GMO',
'unknown'
].freeze
validates :gmo, inclusion: { in: GMO_VALUES,
message: "You must say whether the seeds are "\
"genetically modified or not, or that you don't know" },
allow_nil: false,
allow_blank: false
HEIRLOOM_VALUES = %w(heirloom hybrid unknown).freeze
validates :heirloom, inclusion: { in: HEIRLOOM_VALUES,
message: "You must say whether the seeds are heirloom, hybrid, or unknown" },
allow_nil: false,
allow_blank: false
def tradable?
if tradable_to == 'nowhere'
false
else
true
end
tradable_to != 'nowhere'
end
def seed_slug

View File

@@ -16,7 +16,7 @@
confirm: "Are you sure you want to remove this connection?",
method: :delete, class: "remove"
- else
= link_to 'Connect to Twitter', '/auth/twitter'
= link_to 'Connect to Twitter', '/members/auth/twitter'
.row
.col-md-12
@@ -30,7 +30,7 @@
confirm: "Are you sure you want to remove this connection?",
method: :delete, class: "remove"
- else
= link_to 'Connect to Flickr', '/auth/flickr'
= link_to 'Connect to Flickr', '/members/auth/flickr'
.row
.col-md-12
@@ -44,4 +44,4 @@
confirm: "Are you sure you want to remove this connection?",
method: :delete, class: "remove"
- else
= link_to 'Connect to Facebook', '/auth/facebook'
= link_to 'Connect to Facebook', '/members/auth/facebook'

View File

@@ -0,0 +1,29 @@
.panel.panel-success
.panel-heading
%h3.panel-title
= link_to "#{harvest.owner.login_name}'s #{harvest.crop.name} harvest", harvest
- if can? :edit, harvest
%a.pull-right{ href: edit_harvest_path(harvest), role: "button", id: "edit_harvest_glyphicon" }
%span.glyphicon.glyphicon-pencil{ title: "Edit" }
.panel-body
.row
.col-md-4
= link_to image_tag((harvest.default_photo ? harvest.default_photo.thumbnail_url : 'placeholder_150.png'),
alt: harvest.crop.name, class: 'img'),
harvest
.col-md-8
%dl.dl-horizontal
%dt Crop :
%dd= link_to harvest.crop.name, harvest.crop
%dt Plant part :
%dd= link_to harvest.plant_part, harvest.plant_part
%dt Quantity :
%dd= display_quantity(harvest)
%dt Harvest date :
%dd= harvest.harvested_at
.panel-footer
%dt Description
%dd.truncate
= display_harvest_description(harvest)
= if harvest.description.present?
- link_to "Read more", harvest_path(harvest)

View File

@@ -1,29 +1,9 @@
.panel.panel-success
.panel-heading
%h3.panel-title
= link_to "#{harvest.owner.login_name}'s #{harvest.crop.name} harvest", harvest
- if can? :edit, harvest
%a.pull-right{ href: edit_harvest_path(harvest), role: "button", id: "edit_harvest_glyphicon" }
%span.glyphicon.glyphicon-pencil{ title: "Edit" }
.panel-body
.row
.col-md-4
= link_to image_tag((harvest.default_photo ? harvest.default_photo.thumbnail_url : 'placeholder_150.png'),
alt: harvest.crop.name, class: 'img'),
harvest
.col-md-8
%dl.dl-horizontal
%dt Crop :
%dd= link_to harvest.crop.name, harvest.crop
%dt Plant part :
%dd= link_to harvest.plant_part, harvest.plant_part
%dt Quantity :
%dd= display_quantity(harvest)
%dt Harvest date :
%dd= harvest.harvested_at
.panel-footer
%dt Description
%dd.truncate
= display_harvest_description(harvest)
= if harvest.description.present?
- link_to "Read more", harvest_path(harvest)
.thumbnail
.harvest-thumbnail
- if harvest
= link_to image_tag((harvest.default_photo ? harvest.default_photo.thumbnail_url : 'placeholder_150.png'),
alt: harvest.crop.name, class: 'img'),
harvest
.harvestinfo
.harvest-name
= link_to harvest, harvest

View File

@@ -15,7 +15,7 @@
- unless @harvests.empty?
- @harvests.each do |harvest|
.col-md-6
= render partial: 'harvests/thumbnail', locals: { harvest: harvest }
= render 'harvests/card', harvest: harvest
.pagination
= page_entries_info @harvests

View File

@@ -5,7 +5,7 @@
= render partial: "posts/summary", locals: { posts: posts, howmany: 6 }
- cache cache_key_for(Forum) do
- forums = Forum.all
- forums = Forum.all.order(:name)
- if forums
%ul.list-inline
%li

View File

@@ -2,7 +2,7 @@
%h2= t('.title')
.row
.col-md-8
- Seed.includes(:owner, crop: :photos).interesting.first(6).each do |seed|
- Seed.includes(:owner, crop: :photos).order(created_at: :desc).interesting.first(6).each do |seed|
.col-md-3
.thumbnail
- cache cache_key_for(Crop, seed.id) do

View File

@@ -13,7 +13,7 @@
%small
%br/
Recently planted:
!= member.plantings.first(3).map { |p| link_to p.crop_name, p }.join(", ")
!= member.plantings.order(created_at: :desc).first(3).map { |p| link_to p.crop_name, p }.join(", ")
%p
%small
Joined
@@ -24,4 +24,3 @@
= [localize_plural(member.gardens, Garden),
localize_plural(member.plantings, Planting),
localize_plural(member.seeds, Seed)].join(", ")

View File

@@ -9,7 +9,8 @@
- if plant_part.crops.empty?
No crops are harvested for this plant part (yet).
- else
!= plant_part.crops.map { |c| link_to(c, c) }.join(", ")
- plant_part.crops.limit(100).each do |crop|
= link_to(crop, crop_path(crop))
%p
= link_to "More detail", plant_part
@@ -18,6 +19,3 @@
= link_to 'Edit', edit_plant_part_path(plant_part), class: 'btn btn-default btn-xs'
- if can? :destroy, plant_part
= link_to 'Delete', plant_part, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-default btn-xs'

View File

@@ -16,7 +16,7 @@
%span.glyphicon.glyphicon-ok{ title: "Finished" }
Mark as finished
- if can?(:create, Harvest)
- if can? :edit, planting
= link_to new_planting_harvest_path(planting), class: 'btn btn-default btn-xs' do
%span.glyphicon.glyphicon-leaf{ title: "Harvest" }
Harvest

View File

@@ -1,8 +1,12 @@
- unless planting.harvests.empty?
Harvests:
%ul
- planting.harvests.includes(:crop).each do |harvest|
%li
= harvest.harvested_at ? harvest.harvested_at : "undated"
= link_to harvest, harvest_path(harvest)
= link_to "more harvests from this planting", planting_harvests_path(planting)
- if planting.harvests.empty?
%p no harvests yet
- else
.row
- planting.harvests.order(created_at: :desc).includes(:crop).each do |harvest|
.col-xs-6.col-md-2
= render 'harvests/thumbnail', harvest: harvest
- if can? :edit, planting
.col-xs-6.col-md-2
= link_to new_planting_harvest_path(planting), class: 'btn btn-primary' do
%span.glyphicon.glyphicon-leaf{ title: "Harvest" }
Harvest

View File

@@ -1,15 +1,14 @@
- if planting.crop.perennial
%p Perennial
- elsif !planting.planted?
- if show_explanation == true
Progress: 0% - not planted yet
- if show_explanation
%p Progress: 0% - not planted yet
= render "plantings/progress_bar", status: "not planted", progress: 0
- elsif planting.finished?
= render "plantings/progress_bar", status: 'finished', progress: 100
- elsif planting.finish_predicted_at.nil?
- if show_explanation == true
Progress: Not enough data
%p Progress: Not enough data
= render "plantings/progress_bar", status: "unknown", progress: nil
- else
= render "plantings/progress_bar", status: 'growing', progress: planting.percentage_grown

View File

@@ -9,6 +9,7 @@
= tag("meta", property: "og:url", content: request.original_url)
= tag("meta", property: "og:site_name", content: ENV['GROWSTUFF_SITE_NAME'])
%p= render 'plantings/actions', planting: @planting
.row.planting
.col-md-6
%dl.dl-horizontal.planting-attributes
@@ -45,11 +46,11 @@
%dd
- if @planting.finish_predicted_at.present?
= @planting.finish_predicted_at
- else
- elsif @planting.planted_at.blank?
%strong Set planted date to get predictions
%dt Finished:
%dd= display_finished(@planting)
- if @planting.finished?
%dt Finished:
%dd= display_finished(@planting)
- if @planting.crop.median_lifespan.present?
%dt Expected Lifespan:
%dd #{@planting.crop.median_lifespan} days
@@ -63,10 +64,11 @@
%dt Last Harvest:
%dd #{@planting.days_to_last_harvest} days after planting
%p= render 'plantings/harvests', planting: @planting
%p= render 'plantings/progress', planting: @planting, show_explanation: true
= render 'plantings/actions', planting: @planting
%h2 Progress
%p= render 'plantings/progress', planting: @planting, show_explanation: true
%h2 Harvests
%p= render 'plantings/harvests', planting: @planting
.col-md-6
= render partial: "crops/index_card", locals: { crop: @planting.crop }

View File

@@ -43,7 +43,7 @@ Devise.setup do |config|
# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [:email, :login_name]
config.strip_whitespace_keys = %i(email login_name)
# Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the

View File

@@ -11,6 +11,4 @@ Geocoder.configure(
)
# This configuration takes precedence over environment/test.rb
# Reported as https://github.com/alexreisner/geocoder/issues/509
if Geocoder.config.lookup != :test
Geocoder.configure(lookup: :nominatim)
end
Geocoder.configure(lookup: :nominatim) if Geocoder.config.lookup != :test

View File

@@ -10,44 +10,44 @@ Growstuff::Application.routes.draw do
omniauth_callbacks: "omniauth_callbacks"
}
devise_scope :member do
get '/members/unsubscribe/:message' => 'members#unsubscribe', :as => 'unsubscribe_member'
get '/members/unsubscribe/:message' => 'members#unsubscribe', as: 'unsubscribe_member'
end
match '/members/:id/finish_signup' => 'members#finish_signup', via: [:get, :patch], :as => :finish_signup
match '/members/:id/finish_signup' => 'members#finish_signup', via: %i(get patch), as: :finish_signup
resources :members
resources :photos
delete 'photo_associations' => 'photo_associations#destroy'
resources :authentications, only: [:create, :destroy]
resources :authentications, only: %i(create destroy)
resources :plantings do
resources :harvests
end
get '/plantings/owner/:owner' => 'plantings#index', :as => 'plantings_by_owner'
get '/plantings/crop/:crop' => 'plantings#index', :as => 'plantings_by_crop'
get '/plantings/owner/:owner' => 'plantings#index', as: 'plantings_by_owner'
get '/plantings/crop/:crop' => 'plantings#index', as: 'plantings_by_crop'
resources :gardens
get '/gardens/owner/:owner' => 'gardens#index', :as => 'gardens_by_owner'
get '/gardens/owner/:owner' => 'gardens#index', as: 'gardens_by_owner'
resources :seeds
get '/seeds/owner/:owner' => 'seeds#index', :as => 'seeds_by_owner'
get '/seeds/crop/:crop' => 'seeds#index', :as => 'seeds_by_crop'
get '/seeds/owner/:owner' => 'seeds#index', as: 'seeds_by_owner'
get '/seeds/crop/:crop' => 'seeds#index', as: 'seeds_by_crop'
resources :harvests
get '/harvests/owner/:owner' => 'harvests#index', :as => 'harvests_by_owner'
get '/harvests/crop/:crop' => 'harvests#index', :as => 'harvests_by_crop'
get '/harvests/owner/:owner' => 'harvests#index', as: 'harvests_by_owner'
get '/harvests/crop/:crop' => 'harvests#index', as: 'harvests_by_crop'
resources :posts
get '/posts/author/:author' => 'posts#index', :as => 'posts_by_author'
get '/posts/author/:author' => 'posts#index', as: 'posts_by_author'
resources :scientific_names
resources :alternate_names
get 'crops/requested' => 'crops#requested', :as => 'requested_crops'
get 'crops/wrangle' => 'crops#wrangle', :as => 'wrangle_crops'
get 'crops/hierarchy' => 'crops#hierarchy', :as => 'crops_hierarchy'
get 'crops/search' => 'crops#search', :as => 'crops_search'
get 'crops/requested' => 'crops#requested', as: 'requested_crops'
get 'crops/wrangle' => 'crops#wrangle', as: 'wrangle_crops'
get 'crops/hierarchy' => 'crops#hierarchy', as: 'crops_hierarchy'
get 'crops/search' => 'crops#search', as: 'crops_search'
resources :crops do
get 'photos' => 'photos#index'
end
@@ -59,26 +59,26 @@ Growstuff::Application.routes.draw do
get 'reply', on: :member
end
resources :follows, only: [:create, :destroy]
get '/members/:login_name/follows' => 'members#view_follows', :as => 'member_follows'
get '/members/:login_name/followers' => 'members#view_followers', :as => 'member_followers'
resources :follows, only: %i(create destroy)
get '/members/:login_name/follows' => 'members#view_follows', as: 'member_follows'
get '/members/:login_name/followers' => 'members#view_followers', as: 'member_followers'
get '/places' => 'places#index'
get '/places/search' => 'places#search', :as => 'search_places'
get '/places/:place' => 'places#show', :as => 'place'
get '/places/search' => 'places#search', as: 'search_places'
get '/places/:place' => 'places#show', as: 'place'
# everything for paid accounts etc
resources :account_types
resources :accounts
resources :orders
get 'orders/:id/checkout' => 'orders#checkout', :as => 'checkout_order'
get 'orders/:id/complete' => 'orders#complete', :as => 'complete_order'
get 'orders/:id/cancel' => 'orders#cancel', :as => 'cancel_order'
get 'orders/:id/checkout' => 'orders#checkout', as: 'checkout_order'
get 'orders/:id/complete' => 'orders#complete', as: 'complete_order'
get 'orders/:id/cancel' => 'orders#cancel', as: 'cancel_order'
resources :order_items
resources :products
resources :likes, only: [:create, :destroy]
resources :likes, only: %i(create destroy)
get "home/index"
root to: 'home#index'
@@ -93,7 +93,7 @@ Growstuff::Application.routes.draw do
get '/admin/orders' => 'admin/orders#index'
get '/admin/orders/:action' => 'admin/orders#:action'
get '/admin' => 'admin#index'
get '/admin/newsletter' => 'admin#newsletter', :as => :admin_newsletter
get '/admin/newsletter' => 'admin#newsletter', as: :admin_newsletter
get '/admin/:action' => 'admin#:action'
namespace :api do

View File

@@ -1,5 +1,5 @@
class AddCreationIndexToUpdates < ActiveRecord::Migration
def change
add_index :updates, [:created_at, :user_id]
add_index :updates, %i(created_at user_id)
end
end

View File

@@ -1,6 +1,6 @@
class RenameNotificationFields < ActiveRecord::Migration
def change
change_table :notifications do |t| # rubocop:disable Rails/ReversibleMigration
change_table :notifications do |t|
t.rename :to_id, :recipient_id
t.rename :from_id, :sender_id
end

View File

@@ -4,7 +4,7 @@ class AddCropsPostsTable < ActiveRecord::Migration
t.integer :crop_id
t.integer :post_id
end
add_index :crops_posts, [:crop_id, :post_id]
add_index :crops_posts, %i(crop_id post_id)
add_index :crops_posts, :crop_id
end
end

View File

@@ -1,5 +1,5 @@
class CreateIndexHarvestPhotos < ActiveRecord::Migration
def change
add_index(:harvests_photos, [:harvest_id, :photo_id])
add_index(:harvests_photos, %i(harvest_id photo_id))
end
end

View File

@@ -4,6 +4,6 @@ class AddGardensPhotosTable < ActiveRecord::Migration
t.integer :photo_id
t.integer :garden_id
end
add_index(:gardens_photos, [:garden_id, :photo_id])
add_index(:gardens_photos, %i(garden_id photo_id))
end
end

View File

@@ -33,8 +33,8 @@ class CreateCms < ActiveRecord::Migration
t.boolean :is_shared, null: false, default: false
t.timestamps null: true
end
add_index :comfy_cms_layouts, [:parent_id, :position]
add_index :comfy_cms_layouts, [:site_id, :identifier], unique: true
add_index :comfy_cms_layouts, %i(parent_id position)
add_index :comfy_cms_layouts, %i(site_id identifier), unique: true
# -- Pages --------------------------------------------------------------
create_table :comfy_cms_pages do |t|
@@ -52,8 +52,8 @@ class CreateCms < ActiveRecord::Migration
t.boolean :is_shared, null: false, default: false
t.timestamps null: true
end
add_index :comfy_cms_pages, [:site_id, :full_path]
add_index :comfy_cms_pages, [:parent_id, :position]
add_index :comfy_cms_pages, %i(site_id full_path)
add_index :comfy_cms_pages, %i(parent_id position)
# -- Page Blocks --------------------------------------------------------
create_table :comfy_cms_blocks do |t|
@@ -63,7 +63,7 @@ class CreateCms < ActiveRecord::Migration
t.timestamps null: true
end
add_index :comfy_cms_blocks, [:identifier]
add_index :comfy_cms_blocks, [:blockable_id, :blockable_type]
add_index :comfy_cms_blocks, %i(blockable_id blockable_type)
# -- Snippets -----------------------------------------------------------
create_table :comfy_cms_snippets do |t|
@@ -75,8 +75,8 @@ class CreateCms < ActiveRecord::Migration
t.boolean :is_shared, null: false, default: false
t.timestamps null: true
end
add_index :comfy_cms_snippets, [:site_id, :identifier], unique: true
add_index :comfy_cms_snippets, [:site_id, :position]
add_index :comfy_cms_snippets, %i(site_id identifier), unique: true
add_index :comfy_cms_snippets, %i(site_id position)
# -- Files --------------------------------------------------------------
create_table :comfy_cms_files do |t|
@@ -90,10 +90,10 @@ class CreateCms < ActiveRecord::Migration
t.integer :position, null: false, default: 0
t.timestamps null: true
end
add_index :comfy_cms_files, [:site_id, :label]
add_index :comfy_cms_files, [:site_id, :file_file_name]
add_index :comfy_cms_files, [:site_id, :position]
add_index :comfy_cms_files, [:site_id, :block_id]
add_index :comfy_cms_files, %i(site_id label)
add_index :comfy_cms_files, %i(site_id file_file_name)
add_index :comfy_cms_files, %i(site_id position)
add_index :comfy_cms_files, %i(site_id block_id)
# -- Revisions -----------------------------------------------------------
create_table :comfy_cms_revisions, force: true do |t|
@@ -102,7 +102,7 @@ class CreateCms < ActiveRecord::Migration
t.text :data, text_limit
t.datetime :created_at
end
add_index :comfy_cms_revisions, [:record_type, :record_id, :created_at],
add_index :comfy_cms_revisions, %i(record_type record_id created_at),
name: 'index_cms_revisions_on_rtype_and_rid_and_created_at'
# -- Categories ---------------------------------------------------------
@@ -111,7 +111,7 @@ class CreateCms < ActiveRecord::Migration
t.string :label, null: false
t.string :categorized_type, null: false
end
add_index :comfy_cms_categories, [:site_id, :categorized_type, :label],
add_index :comfy_cms_categories, %i(site_id categorized_type label),
unique: true,
name: 'index_cms_categories_on_site_id_and_cat_type_and_label'
@@ -120,7 +120,7 @@ class CreateCms < ActiveRecord::Migration
t.string :categorized_type, null: false
t.integer :categorized_id, null: false
end
add_index :comfy_cms_categorizations, [:category_id, :categorized_type, :categorized_id],
add_index :comfy_cms_categorizations, %i(category_id categorized_type categorized_id),
unique: true,
name: 'index_cms_categorizations_on_cat_id_and_catd_type_and_catd_id'
end

View File

@@ -4,6 +4,6 @@ class AddPhotosSeedsTable < ActiveRecord::Migration
t.integer :photo_id
t.integer :seed_id
end
add_index(:photos_seeds, [:seed_id, :photo_id])
add_index(:photos_seeds, %i(seed_id photo_id))
end
end

View File

@@ -6,7 +6,7 @@ module Geocodable
private
def empty_unwanted_geocodes
return unless location.blank?
return if location.present?
self.latitude = nil
self.longitude = nil
end

View File

@@ -62,7 +62,7 @@ namespace :growstuff do
# this fixes up anyone who has erroneously wound up with a 0,0 lat/long
task depopulate_null_island: :environment do
Member.find_each do |m|
if m.location and (m.latitude == nil and m.longitude == nil)
if m.location and (m.latitude.nil? and m.longitude.nil?)
m.geocode
m.save
end
@@ -140,9 +140,7 @@ namespace :growstuff do
puts "Giving each member an account record..."
Member.all.each do |m|
unless m.account
Account.create(member_id: m.id)
end
Account.create(member_id: m.id) unless m.account
end
puts "Making Skud a staff account..."
@@ -224,12 +222,11 @@ namespace :growstuff do
task initialize_garden_locations: :environment do
Member.located.find_each do |m|
m.gardens.each do |g|
if g.location.blank?
g.location = m.location
g.latitude = m.latitude
g.longitude = m.longitude
g.save
end
next if g.location.present?
g.location = m.location
g.latitude = m.latitude
g.longitude = m.longitude
g.save
end
end
end
@@ -277,16 +274,12 @@ namespace :growstuff do
desc "October 2014: remove unused photos"
task remove_unused_photos: :environment do
Photo.find_each do |p|
p.destroy_if_unused
end
Photo.find_each(&:destroy_if_unused)
end
desc "October 2014: generate crops_posts records for existing posts"
task generate_crops_posts_records: :environment do
Post.find_each do |p|
p.save
end
Post.find_each(&:save)
end
desc "October 2014: add alternate names for crops"

20
package-lock.json generated
View File

@@ -195,19 +195,13 @@
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=",
"dev": true
},
"coffee-script": {
"version": "1.11.1",
"resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.11.1.tgz",
"integrity": "sha1-vxxHrWREOg2V0S3ysUfMCk2q1uk=",
"dev": true
},
"coffeelint": {
"version": "1.16.0",
"resolved": "https://registry.npmjs.org/coffeelint/-/coffeelint-1.16.0.tgz",
"integrity": "sha1-g9jtHa/eOmd95E57ihi+YHdh5tg=",
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/coffeelint/-/coffeelint-2.0.7.tgz",
"integrity": "sha1-lg/VuXVrhFGU6fl6R1bmKGEha3Q=",
"dev": true,
"requires": {
"coffee-script": "1.11.1",
"coffeescript": "2.0.3",
"glob": "7.1.2",
"ignore": "3.3.7",
"optimist": "0.6.1",
@@ -215,6 +209,12 @@
"strip-json-comments": "1.0.4"
}
},
"coffeescript": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-2.0.3.tgz",
"integrity": "sha512-iIfUN+71IyI2FQABXh1luzZeQgqwUPeWh6lDovJatQQs+30bvyGnBY0r4BnD0hoMAasNuZVHlL1U09Oy1ZfSeg==",
"dev": true
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",

View File

@@ -5,7 +5,7 @@
"main": "index.js",
"dependencies": {},
"devDependencies": {
"coffeelint": "^1.16.0",
"coffeelint": "^2.0.7",
"csslint": "^1.0.5",
"eslint": "^3.17.1",
"jshint": "^2.9.4"

View File

@@ -18,7 +18,7 @@ if ENV['TRAVIS']
end
else
author = `git config github.user`.chomp
if $?.exitstatus.positive?
if $CHILD_STATUS.exitstatus.positive?
abort %(
Couldn't determine your GitHub username, and not in a Travis PR build
Please set it using

View File

@@ -18,7 +18,7 @@ when "on"
when "off"
maintenance_state = false
else
abort "usage: #{$0} (on|off)"
abort "usage: #{$PROGRAM_NAME} (on|off)"
end
puts "Turning #{maintenance_state} maintenance mode on app #{app}"

View File

@@ -1,10 +1,14 @@
#!/bin/bash
set -v
if [ "$(phantomjs --version)" != '2.1.1' ]; then
PHANTOM_URL="https://assets.membergetmember.co/software/phantomjs-2.1.1-linux-x86_64.tar.bz2"
rm -rf "$PWD/travis_phantomjs"
mkdir -p "$PWD/travis_phantomjs"
wget "$PHANTOM_URL" -O "$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2"
tar -xvf "$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis_phantomjs"
cd "$PWD/travis_phantomjs" || exit 1
wget "$PHANTOM_URL"
tar -vjxf phantomjs-2.1.1-linux-x86_64.tar.bz2
fi
phantomjs --version
which phantomjs
phantomjs --version

View File

@@ -1,10 +1,30 @@
require 'rails_helper'
describe AccountTypesController do
# This automatically creates a "Free" account type
login_member(:admin_member)
subject { response }
def valid_attributes
{ "name" => "MyString" }
context 'anon' do
describe '#index' do
before { get :index }
it { is_expected.not_to be_success }
end
end
context 'member' do
login_member(:member)
describe '#index' do
before { get :index }
it { is_expected.not_to be_success }
end
end
context 'admin' do
login_member(:admin_member)
describe '#index' do
let!(:aaa) { FactoryBot.create :account_type, name: 'aaa' }
let!(:zzz) { FactoryBot.create :account_type, name: 'zzz' }
before { get :index }
it { is_expected.to be_success }
it { expect(assigns[:account_types].first).to eql(aaa) }
it { expect(assigns[:account_types].last).to eql(zzz) }
end
end
end

View File

@@ -1,10 +1,11 @@
require 'rails_helper'
describe CommentsController do
subject { response }
let(:member) { FactoryBot.create(:member) }
before(:each) do
@member = FactoryBot.create(:member)
sign_in @member
controller.stub(:current_member) { @member }
sign_in member
controller.stub(:current_member) { member }
end
def valid_attributes
@@ -13,11 +14,14 @@ describe CommentsController do
end
describe "GET RSS feed" do
it "returns an RSS feed" do
get :index, format: "rss"
response.should be_success
response.should render_template("comments/index")
response.content_type.should eq("application/rss+xml")
let!(:first_comment) { FactoryBot.create :comment, created_at: 10.days.ago }
let!(:last_comment) { FactoryBot.create :comment, created_at: 4.minutes.ago }
describe "returns an RSS feed" do
before { get :index, format: "rss" }
it { is_expected.to be_success }
it { is_expected.to render_template("comments/index") }
it { expect(response.content_type).to eq("application/rss+xml") }
it { expect(assigns(:comments)).to eq([last_comment, first_comment]) }
end
end
@@ -48,10 +52,10 @@ describe CommentsController do
before { get :edit, id: comment.to_param }
describe "my comment" do
let!(:comment) { FactoryBot.create :comment, author: @member, post: post }
let!(:comment) { FactoryBot.create :comment, author: member, post: post }
let!(:old_comment) { FactoryBot.create(:comment, post: post, created_at: Time.zone.yesterday) }
it "assigns previous comments as @comments" do
assigns(:comments).should eq([comment, old_comment])
expect(assigns(:comments)).to eq([comment, old_comment])
end
end
@@ -65,7 +69,7 @@ describe CommentsController do
before { put :update, id: comment.to_param, comment: valid_attributes }
describe "my comment" do
let(:comment) { FactoryBot.create :comment, author: @member }
let(:comment) { FactoryBot.create :comment, author: member }
it "redirects to the comment's post" do
expect(response).to redirect_to(comment.post)
end
@@ -78,7 +82,7 @@ describe CommentsController 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: post }
let(:comment) { FactoryBot.create :comment, author: member, post: post }
it "does not change post_id" do
comment.reload
expect(comment.post_id).to eq(post.id)
@@ -90,7 +94,7 @@ describe CommentsController do
before { delete :destroy, id: comment.to_param }
describe "my comment" do
let(:comment) { FactoryBot.create :comment, author: @member }
let(:comment) { FactoryBot.create :comment, author: member }
it "redirects to the post the comment was on" do
expect(response).to redirect_to(comment.post)
end

View File

@@ -11,37 +11,39 @@ describe CropsController do
}
end
subject { response }
describe "GET crop wrangler homepage" do
it 'fetches the crop wrangler homepage' do
get :wrangle
response.should be_success
response.should render_template("crops/wrangle")
expect(assigns[:crop_wranglers]).to eq(Role.crop_wranglers)
describe 'fetches the crop wrangler homepage' do
before { get :wrangle }
it { is_expected.to be_success }
it { is_expected.to render_template("crops/wrangle") }
it { expect(assigns[:crop_wranglers]).to eq(Role.crop_wranglers) }
end
end
describe "GET crop hierarchy " do
it 'fetches the crop hierarchy page' do
get :hierarchy
response.should be_success
response.should render_template("crops/hierarchy")
describe 'fetches the crop hierarchy page' do
before { get :hierarchy }
it { is_expected.to be_success }
it { is_expected.to render_template("crops/hierarchy") }
end
end
describe "GET crop search" do
it 'fetches the crop search page' do
get :search
response.should be_success
response.should render_template("crops/search")
describe 'fetches the crop search page' do
before { get :search }
it { is_expected.to be_success }
it { is_expected.to render_template("crops/search") }
end
end
describe "GET RSS feed" do
it "returns an RSS feed" do
get :index, format: "rss"
response.should be_success
response.should render_template("crops/index")
response.content_type.should eq("application/rss+xml")
describe "returns an RSS feed" do
before { get :index, format: "rss" }
it { is_expected.to be_success }
it { is_expected.to render_template("crops/index") }
it { expect(response.content_type).to eq("application/rss+xml") }
end
end
end

View File

@@ -3,53 +3,48 @@ require 'rails_helper'
describe OrderItemsController do
login_member(:admin_member)
before(:each) do
@member = FactoryBot.create(:member)
sign_in @member
@product = FactoryBot.create(:product)
@order = FactoryBot.create(:order, member: @member)
@order_item = FactoryBot.create(:order_item,
order: @order,
product: @product,
price: @product.min_price)
let(:member) { FactoryBot.create(:member) }
let(:product) { FactoryBot.create(:product) }
let(:order) { FactoryBot.create(:order, member: member) }
let(:order_item) do
FactoryBot.create(:order_item,
order: order,
product: product,
price: product.min_price)
end
describe "POST create" do
it "redirects to order" do
@order = FactoryBot.create(:order, member: @member)
post :create, order_item: {
order_id: @order.id,
product_id: @product.id,
price: @product.min_price
}
response.should redirect_to(OrderItem.last.order)
end
context 'signed in' do
before { sign_in member }
it 'creates an order for you' do
@member = FactoryBot.create(:member)
sign_in @member
@product = FactoryBot.create(:product)
expect {
post :create, order_item: {
product_id: @product.id,
price: @product.min_price
}
}.to change(Order, :count).by(1)
OrderItem.last.order.should be_an_instance_of Order
end
describe "POST create" do
describe "redirects to order" do
before do
post :create, order_item: { order_id: order.id, product_id: product.id, price: product.min_price }
end
it { expect(response).to redirect_to(OrderItem.last.order) }
it { expect(OrderItem.last.order).to be_an_instance_of Order }
end
describe "with non-int price" do
it "converts 3.33 to 333 cents" do
@order = FactoryBot.create(:order, member: @member)
@product = FactoryBot.create(:product, min_price: 1)
expect {
post :create, order_item: {
order_id: @order.id,
product_id: @product.id,
price: 3.33
}
}.to change(OrderItem, :count).by(1)
OrderItem.last.price.should eq 333
describe 'creates an order for you' do
it do
expect do
post :create, order_item: {
product_id: product.id,
price: product.min_price
}
end.to change(Order, :count).by(1)
end
end
describe "with non-int price" do
it "converts 3.33 to 333 cents" do
order = FactoryBot.create(:order, member: member)
product = FactoryBot.create(:product, min_price: 1)
expect do
post :create, order_item: { order_id: order.id, product_id: product.id, price: 3.33 }
end.to change(OrderItem, :count).by(1)
OrderItem.last.price.should eq 333
end
end
end
end

View File

@@ -33,7 +33,7 @@ describe PhotoAssociationsController do
rescue
nil
end
end.not_to change { photo.harvests.count }
end.not_to change(photo.harvests, :count)
end
it { expect { delete :destroy, valid_params }.to raise_error(ActiveRecord::RecordNotFound) }
end

View File

@@ -11,85 +11,83 @@ describe PlantingsController do
end
describe "GET index" do
before do
@member1 = FactoryBot.create(:member)
@member2 = FactoryBot.create(:member)
@tomato = FactoryBot.create(:tomato)
@maize = FactoryBot.create(:maize)
@planting1 = FactoryBot.create(:planting, crop: @tomato, owner: @member1)
@planting2 = FactoryBot.create(:planting, crop: @maize, owner: @member2)
let!(:member1) { FactoryBot.create(:member) }
let!(:member2) { FactoryBot.create(:member) }
let!(:tomato) { FactoryBot.create(:tomato) }
let!(:maize) { FactoryBot.create(:maize) }
let!(:planting1) { FactoryBot.create :planting, crop: tomato, owner: member1, created_at: 1.day.ago }
let!(:planting2) { FactoryBot.create :planting, crop: maize, owner: member2, created_at: 5.days.ago }
describe "assigns all plantings as @plantings" do
before { get :index, {} }
it { expect(assigns(:plantings)).to match [planting1, planting2] }
end
it "assigns all plantings as @plantings" do
get :index, {}
assigns(:plantings).should =~ [@planting1, @planting2]
describe "picks up owner from params and shows owner's plantings only" do
before { get :index, owner: member1.slug }
it { expect(assigns(:owner)).to eq member1 }
it { expect(assigns(:plantings)).to eq [planting1] }
end
it "picks up owner from params and shows owner's plantings only" do
get :index, owner: @member1.slug
assigns(:owner).should eq @member1
assigns(:plantings).should eq [@planting1]
end
it "picks up crop from params and shows the plantings for the crop only" do
get :index, crop: @maize.name
assigns(:crop).should eq @maize
assigns(:plantings).should eq [@planting2]
describe "picks up crop from params and shows the plantings for the crop only" do
before { get :index, crop: maize.name }
it { expect(assigns(:crop)).to eq maize }
it { expect(assigns(:plantings)).to eq [planting2] }
end
end
describe "GET new" do
it "picks up crop from params" do
crop = FactoryBot.create(:crop)
get :new, crop_id: crop.id
assigns(:crop).should eq(crop)
describe "picks up crop from params" do
let(:crop) { FactoryBot.create(:crop) }
before { get :new, crop_id: crop.id }
it { expect(assigns(:crop)).to eq(crop) }
end
it "doesn't die if no crop specified" do
get :new, {}
assigns(:crop).should be_a_new(Crop)
describe "doesn't die if no crop specified" do
before { get :new, {} }
it { expect(assigns(:crop)).to be_a_new(Crop) }
end
it "picks up member's garden from params" do
garden = FactoryBot.create(:garden, owner: member)
get :new, garden_id: garden.id
assigns(:garden).should eq(garden)
describe "picks up member's garden from params" do
let(:garden) { FactoryBot.create(:garden, owner: member) }
before { get :new, garden_id: garden.id }
it { expect(assigns(:garden)).to eq(garden) }
end
it "Doesn't display another member's garden on planting form" do
member = FactoryBot.create(:member) # over-riding member from login_member()
garden = FactoryBot.create(:garden, owner: member)
get :new, garden_id: garden.id
assigns(:garden).should_not eq(garden)
describe "Doesn't display another member's garden on planting form" do
let(:another_member) { FactoryBot.create(:member) } # over-riding member from login_member()
let(:garden) { FactoryBot.create(:garden, owner: another_member) }
before { get :new, garden_id: garden.id }
it { expect(assigns(:garden)).not_to eq(garden) }
end
it "Doesn't display un-approved crops on planting form" do
crop = FactoryBot.create(:crop, approval_status: 'pending')
FactoryBot.create(:garden, owner: member)
get :new, crop_id: crop.id
assigns(:crop).should_not eq(crop)
describe "Doesn't display un-approved crops on planting form" do
let(:crop) { FactoryBot.create(:crop, approval_status: 'pending') }
let!(:garden) { FactoryBot.create(:garden, owner: member) }
before { get :new, crop_id: crop.id }
it { expect(assigns(:crop)).not_to eq(crop) }
end
it "Doesn't display rejected crops on planting form" do
crop = FactoryBot.create(:crop, approval_status: 'rejected', reason_for_rejection: 'nope')
FactoryBot.create(:garden, owner: member)
get :new, crop_id: crop.id
assigns(:crop).should_not eq(crop)
describe "Doesn't display rejected crops on planting form" do
let(:crop) { FactoryBot.create(:crop, approval_status: 'rejected', reason_for_rejection: 'nope') }
let!(:garden) { FactoryBot.create(:garden, owner: member) }
before { get :new, crop_id: crop.id }
it { expect(assigns(:crop)).not_to eq(crop) }
end
it "doesn't die if no garden specified" do
get :new, {}
assigns(:garden).should be_a_new(Garden)
describe "doesn't die if no garden specified" do
before { get :new, {} }
it { expect(assigns(:garden)).to be_a_new(Garden) }
end
it "sets the date of the planting to today" do
get :new, {}
assigns(:planting).planted_at.should == Time.zone.today
describe "sets the date of the planting to today" do
before { get :new, {} }
it { expect(assigns(:planting).planted_at).to eq Time.zone.today }
end
it "sets the owner automatically" do
post :create, planting: valid_attributes
assigns(:planting).owner.should eq subject.current_member
describe "sets the owner automatically" do
before { post :create, planting: valid_attributes }
it { expect(assigns(:planting).owner).to eq subject.current_member }
end
end
end

View File

@@ -1,33 +1,35 @@
require 'rails_helper'
describe ShopController do
before :each do
@product1 = FactoryBot.create(:product)
@product2 = FactoryBot.create(:product)
end
let!(:product1) { FactoryBot.create(:product, name: 'aaa') }
let!(:product2) { FactoryBot.create(:product, name: 'zzz') }
describe "GET index" do
it "assigns all products as @products" do
get :index, {}
assigns(:products).should eq([@product1, @product2])
end
describe 'not logged in' do
before { get :index, {} }
it "assigns a new @order_item to build forms" do
get :index, {}
assigns(:order_item).should be_an_instance_of OrderItem
end
describe "assigns all products as @products ordered by name" do
it { expect(assigns(:products)).to eq([product1, product2]) }
end
it "assigns @order as nil if the user doesn't have one" do
get :index, {}
assigns(:order).should be_nil
end
describe "assigns a new @order_item to build forms" do
it { expect(assigns(:order_item)).to be_an_instance_of OrderItem }
end
it "assigns @order as current_order if there is one" do
@member = FactoryBot.create(:member)
sign_in @member
@order = FactoryBot.create(:order, member: @member)
get :index, {}
assigns(:order).should eq @order
describe "assigns @order as nil if the user doesn't have one" do
it { expect(assigns(:order)).to be_nil }
end
end
describe 'logged in' do
describe "assigns @order as current_order if there is one" do
let(:member) { FactoryBot.create(:member) }
let!(:order) { FactoryBot.create(:order, member: member) }
before do
sign_in member
get :index, {}
end
it { expect(assigns(:order)).to eq order }
end
end
end
end

View File

@@ -2,10 +2,16 @@
FactoryBot.define do
factory :account_type do
name "Free"
name { Faker::Name.unique.name }
is_paid false
is_permanent_paid false
factory :free_account_type do
name "Free"
is_paid false
is_permanent_paid false
end
factory :paid_account_type do
name "Paid"
is_paid true

View File

@@ -2,7 +2,7 @@ FactoryBot.define do
sequence(:email) { |n| "member#{n}@example.com" }
sequence(:login_name) { |n| "member#{n}" }
factory :member, aliases: [:author, :owner, :sender, :recipient, :creator] do
factory :member, aliases: %i(author owner sender recipient creator) do
login_name { generate(:login_name) }
password 'password1'
email { generate(:email) }

View File

@@ -1,7 +1,8 @@
require 'rails_helper'
feature "Planting a crop", js: true do
let!(:garden) { create :garden }
# name is aaa to ensure it is ordered first
let!(:garden) { create :garden, name: 'aaa' }
let!(:planting) { create :planting, garden: garden, owner: garden.owner, planted_at: Date.parse("2013-3-10") }
let!(:tomato) { create :tomato }
let!(:finished_planting) { create :finished_planting, owner: garden.owner, garden: garden, crop: tomato }
@@ -58,7 +59,7 @@ feature "Planting a crop", js: true do
end
scenario "button on index to edit garden" do
first(".garden-info").click_link("Edit")
first(".garden-info").click_link("edit_garden_link")
expect(page).to have_content 'Edit garden'
end
end

View File

@@ -5,13 +5,13 @@ feature "Notifications", :js do
let(:recipient) { create :member }
context "On existing notification" do
let!(:notification) {
let!(:notification) do
create :notification,
sender: sender,
recipient: recipient,
body: "Notification body",
post_id: nil
}
end
background do
login_as recipient

View File

@@ -48,7 +48,7 @@ feature "signin", js: true do
end
describe "redirects to what you were trying to do" do
%w[plantings harvests posts photos gardens seeds].each do |m|
%w(plantings harvests posts photos gardens seeds).each do |m|
it_behaves_like "redirects to what you were trying to do" do
let(:model_name) { m }
end

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
describe ApplicationHelper do
it "formats prices" do
price_in_dollars(999).should eq '9.99'
price_with_currency(999).should eq '9.99 %s' % Growstuff::Application.config.currency
price_with_currency(999).should eq format('9.99 %s', Growstuff::Application.config.currency)
end
it "parses dates" do

View File

@@ -5,7 +5,7 @@ require 'haml/helpers'
describe 'Haml::Filters::Escaped_Markdown' do
it 'is registered as the handler for :escaped_markdown' do
Haml::Filters::defined['escaped_markdown'].should ==
Haml::Filters.defined['escaped_markdown'].should ==
Haml::Filters::EscapedMarkdown
end

View File

@@ -24,7 +24,7 @@ end
describe 'Haml::Filters::Growstuff_Markdown' do
it 'is registered as the handler for :growstuff_markdown' do
Haml::Filters::defined['growstuff_markdown'].should ==
Haml::Filters.defined['growstuff_markdown'].should ==
Haml::Filters::GrowstuffMarkdown
end

View File

@@ -111,19 +111,23 @@ describe Ability do
context "orders" do
let(:order) { FactoryBot.create(:order, member: member) }
let(:strangers_order) {
let(:strangers_order) do
FactoryBot.create(:order,
member: FactoryBot.create(:member)) }
let(:completed_order) {
member: FactoryBot.create(:member))
end
let(:completed_order) do
FactoryBot.create(:completed_order,
member: member) }
member: member)
end
let(:order_item) { FactoryBot.create(:order_item, order: order) }
let(:strangers_order_item) {
let(:strangers_order_item) do
FactoryBot.create(:order_item,
order: strangers_order) }
let(:completed_order_item) {
order: strangers_order)
end
let(:completed_order_item) do
FactoryBot.create(:order_item,
order: completed_order) }
order: completed_order)
end
context "standard member" do
it "can read their own orders" do

View File

@@ -17,9 +17,9 @@ describe Comment do
let(:comment) { FactoryBot.create(:comment) }
it "sends a notification when a comment is posted" do
expect {
expect do
FactoryBot.create(:comment)
}.to change(Notification, :count).by(1)
end.to change(Notification, :count).by(1)
end
it "sets the notification fields" do
@@ -35,9 +35,9 @@ describe Comment do
it "doesn't send notifications to yourself" do
@m = FactoryBot.create(:member)
@p = FactoryBot.create(:post, author: @m)
expect {
expect do
FactoryBot.create(:comment, post: @p, author: @m)
}.to change(Notification, :count).by(0)
end.to change(Notification, :count).by(0)
end
end
@@ -49,10 +49,6 @@ describe Comment do
@c2 = FactoryBot.create(:comment, post: @p, author: @m)
end
it 'is in DESC order by default' do
Comment.all.should eq [@c2, @c1]
end
it 'has a scope for ASC order for displaying on post page' do
Comment.post_order.should eq [@c1, @c2]
end

View File

@@ -39,10 +39,6 @@ describe Crop do
@lowercase = FactoryBot.create(:lowercasecrop, created_at: 2.days.ago)
end
it "should be sorted case-insensitively" do
Crop.first.should == @lowercase
end
it 'recent scope sorts by creation date' do
Crop.recent.first.should == @uppercase
end
@@ -279,17 +275,17 @@ describe Crop do
@crop2 = FactoryBot.create(:crop)
# they need 3+ plantings each to be interesting
(1..3).each do
3.times do
FactoryBot.create(:planting, crop: @crop1)
end
(1..3).each do
3.times do
FactoryBot.create(:planting, crop: @crop2)
end
# crops need 3+ photos to be interesting
@photo = FactoryBot.create(:photo)
[@crop1, @crop2].each do |c|
(1..3).each do
3.times do
c.plantings.first.photos << @photo
c.plantings.first.save
end
@@ -306,13 +302,13 @@ describe Crop do
@crop2 = FactoryBot.create(:crop)
# only crop1 has plantings
(1..3).each do
3.times do
FactoryBot.create(:planting, crop: @crop1)
end
# ... and photos
@photo = FactoryBot.create(:photo)
(1..3).each do
3.times do
@crop1.plantings.first.photos << @photo
@crop1.plantings.first.save
end
@@ -328,16 +324,16 @@ describe Crop do
@crop2 = FactoryBot.create(:crop)
# both crops have plantings
(1..3).each do
3.times do
FactoryBot.create(:planting, crop: @crop1)
end
(1..3).each do
3.times do
FactoryBot.create(:planting, crop: @crop2)
end
# but only crop1 has photos
@photo = FactoryBot.create(:photo)
(1..3).each do
3.times do
@crop1.plantings.first.photos << @photo
@crop1.plantings.first.save
end

View File

@@ -7,16 +7,16 @@ describe Follow do
end
it "sends a notification when a follow is created" do
expect {
expect do
Follow.create(follower_id: @member1.id, followed_id: @member2.id)
}.to change(Notification, :count).by(1)
end.to change(Notification, :count).by(1)
end
it "does not delete any members when follow is deleted" do
expect {
expect do
follow = Follow.create(follower_id: @member1.id, followed_id: @member2.id)
follow.destroy
}.not_to change(Member, :count)
end.not_to change(Member, :count)
end
context "when follow is created" do

View File

@@ -20,10 +20,4 @@ describe Forum do
@post2 = FactoryBot.create(:forum_post, forum: forum)
forum.posts.size.should == 2
end
it "orders posts in reverse chron order" do
@post1 = FactoryBot.create(:forum_post, forum: forum, created_at: 2.days.ago)
@post2 = FactoryBot.create(:forum_post, forum: forum, created_at: 1.day.ago)
forum.posts.first.should eq @post2
end
end

View File

@@ -93,14 +93,6 @@ describe Garden do
end
end
context 'ordering' do
it "should be sorted alphabetically" do
FactoryBot.create(:garden_z)
a = FactoryBot.create(:garden_a)
Garden.first.should == a
end
end
it "destroys plantings when deleted" do
garden = FactoryBot.create(:garden, owner: owner)
@planting1 = FactoryBot.create(:planting, garden: garden, owner: garden.owner)

View File

@@ -140,16 +140,6 @@ describe 'member' do
end
end
context 'ordering' do
before do
FactoryBot.create(:member, login_name: "Zoe")
FactoryBot.create(:member, login_name: "Anna")
end
it "should be sorted by name" do
expect(Member.first.login_name).to eq("Anna")
end
end
context 'invalid login names' do
it "doesn't allow short names" do
member = FactoryBot.build(:invalid_member_shortname)
@@ -363,9 +353,10 @@ describe 'member' do
end
context "update account" do
let(:product) {
let(:product) do
FactoryBot.create(:product,
paid_months: 3)}
paid_months: 3)
end
let(:member) { FactoryBot.create(:member) }
it "sets account_type" do

View File

@@ -20,7 +20,8 @@ describe Notification do
@n2 = FactoryBot.create(:notification, read: true)
Notification.unread.should eq [notification]
@n3 = FactoryBot.create(:notification, read: false)
Notification.unread.should eq [@n3, notification]
Notification.unread.should include @n3
Notification.unread.should include notification
end
it "counts unread" do

View File

@@ -25,11 +25,6 @@ describe Order do
@order.order_items.first.should eq @order_item
end
it 'sorts by created_at DESC' do
@order2 = FactoryBot.create(:order)
Order.all.should eq [@order2, @order]
end
it 'updates the account details' do
@member = FactoryBot.create(:member)
@order = FactoryBot.create(:order, member: @member)

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