mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-25 09:19:15 -04:00
Compare commits
240 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7eb5e0014 | ||
|
|
f08d02f4c5 | ||
|
|
6ed7376c58 | ||
|
|
c8a200bf19 | ||
|
|
a62b668781 | ||
|
|
09f82d5995 | ||
|
|
8d0bec34a6 | ||
|
|
d7ec4eacee | ||
|
|
3a3f4eefbf | ||
|
|
9e00023332 | ||
|
|
3058160a59 | ||
|
|
e3886ce5b5 | ||
|
|
48f8085e2d | ||
|
|
594e466fd4 | ||
|
|
b813669d71 | ||
|
|
d0b8ae3411 | ||
|
|
9c993e9f47 | ||
|
|
d5fece87d0 | ||
|
|
33816d4312 | ||
|
|
00e6aeed5c | ||
|
|
0205b345d0 | ||
|
|
9f8a32e9f8 | ||
|
|
7357524271 | ||
|
|
6aa689b0d8 | ||
|
|
962b3b574d | ||
|
|
d77d1d9a77 | ||
|
|
4bed6da422 | ||
|
|
023c870d49 | ||
|
|
9aff65e956 | ||
|
|
0446c0a405 | ||
|
|
7719d1f896 | ||
|
|
c9558e4d51 | ||
|
|
8a679670e4 | ||
|
|
a7586e9d2b | ||
|
|
811011419e | ||
|
|
dae3ea2789 | ||
|
|
49aa6bb846 | ||
|
|
c154a9b845 | ||
|
|
ad14ecb41b | ||
|
|
08a73ce503 | ||
|
|
6663f3ade4 | ||
|
|
451030761d | ||
|
|
d4e4ca6519 | ||
|
|
284f0cddcd | ||
|
|
4ced7ee7e9 | ||
|
|
b60510e016 | ||
|
|
e85daa405b | ||
|
|
9ab83f7bbc | ||
|
|
329e0106bb | ||
|
|
4743fc7a63 | ||
|
|
c66a5b12a5 | ||
|
|
f98bb32612 | ||
|
|
771443ee85 | ||
|
|
1322ebd8e3 | ||
|
|
9e98db423e | ||
|
|
305702f644 | ||
|
|
1f4f806bb0 | ||
|
|
6a17ba547f | ||
|
|
3ffdc61428 | ||
|
|
bb6e9e32e6 | ||
|
|
229396d9e7 | ||
|
|
0fa02272b0 | ||
|
|
a91b8605c4 | ||
|
|
f1107b518c | ||
|
|
52d93a7ccd | ||
|
|
d3df1e8f33 | ||
|
|
eb77715b70 | ||
|
|
252910694d | ||
|
|
bd063be3a9 | ||
|
|
9a6d827b6d | ||
|
|
ede5187369 | ||
|
|
610a5b7a48 | ||
|
|
1fa71c1546 | ||
|
|
7574eb554e | ||
|
|
eea7e19ecf | ||
|
|
dafaffcd73 | ||
|
|
3e149a5d1d | ||
|
|
c20d9b78c5 | ||
|
|
7906d50d13 | ||
|
|
faed8b019e | ||
|
|
c8974a869f | ||
|
|
3969f410f1 | ||
|
|
6304f230a5 | ||
|
|
73524b8883 | ||
|
|
fd9fc38def | ||
|
|
949c7c31d8 | ||
|
|
e34dcd03bc | ||
|
|
929229379e | ||
|
|
d8bf8ae4df | ||
|
|
ac0e52f15d | ||
|
|
c7f427fe8a | ||
|
|
50fd9ae9b0 | ||
|
|
efe39da878 | ||
|
|
1cd3c64590 | ||
|
|
b591529892 | ||
|
|
cef236d8f8 | ||
|
|
5ad0068142 | ||
|
|
b8a5ff9acf | ||
|
|
90653aa57f | ||
|
|
80a4739f34 | ||
|
|
a6cc530fe5 | ||
|
|
97f19a0038 | ||
|
|
140611d868 | ||
|
|
3fa5ffc544 | ||
|
|
eeafb4caa5 | ||
|
|
c747d46ab5 | ||
|
|
3009ed2d83 | ||
|
|
f68a15c04e | ||
|
|
06295fb9e9 | ||
|
|
c4a1806a87 | ||
|
|
fa5e151af0 | ||
|
|
13e8d1f5a5 | ||
|
|
c1836cc78e | ||
|
|
28fdb6e1ed | ||
|
|
67dec795a0 | ||
|
|
86ea8eab39 | ||
|
|
8884056ff3 | ||
|
|
d01a5d7976 | ||
|
|
66c08650ba | ||
|
|
521873b656 | ||
|
|
83fea92353 | ||
|
|
2060d9ab9e | ||
|
|
1795b27152 | ||
|
|
1317ce9db0 | ||
|
|
93193c9fba | ||
|
|
e489831241 | ||
|
|
df7a9448b0 | ||
|
|
3d4f5c6917 | ||
|
|
1b4d77e017 | ||
|
|
08e7c7dd29 | ||
|
|
5fec826c41 | ||
|
|
c29234c40c | ||
|
|
2f0cb5c815 | ||
|
|
b6cbfe25d2 | ||
|
|
d8f5876518 | ||
|
|
ae2cbf0bec | ||
|
|
c9d5c42814 | ||
|
|
b60f47f502 | ||
|
|
d86e0af5ad | ||
|
|
fc0058d677 | ||
|
|
41110f96d1 | ||
|
|
33822abf93 | ||
|
|
5877da95a6 | ||
|
|
88a119deac | ||
|
|
d07fd1a277 | ||
|
|
c96695258b | ||
|
|
2fbba52bc8 | ||
|
|
a2ae429f6b | ||
|
|
7ca76e69cf | ||
|
|
c6824b1262 | ||
|
|
2a74c057f3 | ||
|
|
85cc9e77c6 | ||
|
|
a0d6d154f0 | ||
|
|
7e9707e3b0 | ||
|
|
4fe0dba28e | ||
|
|
328037b8c0 | ||
|
|
e4ab5114f7 | ||
|
|
a5d43af899 | ||
|
|
2d384c9851 | ||
|
|
205247b136 | ||
|
|
963a182981 | ||
|
|
1090db6d21 | ||
|
|
f187b31653 | ||
|
|
809dd81378 | ||
|
|
62beec23a1 | ||
|
|
a60a5ce591 | ||
|
|
7206f99510 | ||
|
|
bf6475da57 | ||
|
|
c5971cd46b | ||
|
|
2f47eeb7b3 | ||
|
|
928749aaad | ||
|
|
1d64d4d1d2 | ||
|
|
1e86cf7662 | ||
|
|
941dab7c4a | ||
|
|
2696d12771 | ||
|
|
6bf87c243c | ||
|
|
ec63d8086f | ||
|
|
470aacd1c9 | ||
|
|
9997c365d8 | ||
|
|
eaa65fda9e | ||
|
|
e844eade94 | ||
|
|
35e7b6a5b4 | ||
|
|
6c33c335d8 | ||
|
|
26537943e3 | ||
|
|
136c082003 | ||
|
|
b3fd8e32d0 | ||
|
|
9b1b22afa8 | ||
|
|
996706ee78 | ||
|
|
9d11bcc039 | ||
|
|
b1684b0156 | ||
|
|
ec00baef0d | ||
|
|
eb585611fe | ||
|
|
9280049a84 | ||
|
|
53d7fd1479 | ||
|
|
4cc0f77bd0 | ||
|
|
5e5773aa59 | ||
|
|
2422939b4f | ||
|
|
d5a1a683f1 | ||
|
|
f5bb47e4ca | ||
|
|
8359218294 | ||
|
|
285e6edc61 | ||
|
|
f2fac9db1b | ||
|
|
cabc4fd030 | ||
|
|
20fe9e4cc5 | ||
|
|
0b8357a261 | ||
|
|
7104781d1b | ||
|
|
267f27b3f8 | ||
|
|
31a37bf6dc | ||
|
|
d1951b8b65 | ||
|
|
cd99769311 | ||
|
|
71cb3f8c5f | ||
|
|
d540342acb | ||
|
|
f66b0768e2 | ||
|
|
251f44b0c7 | ||
|
|
adf07ce5ef | ||
|
|
54b204c636 | ||
|
|
ff446c2139 | ||
|
|
62d84d7af4 | ||
|
|
92fa09a1d3 | ||
|
|
b09c4aa7a1 | ||
|
|
692ab59285 | ||
|
|
302bdba150 | ||
|
|
aa3057056f | ||
|
|
9ef40532ad | ||
|
|
70ba8c8421 | ||
|
|
3b81affbe5 | ||
|
|
9703d4e983 | ||
|
|
22e1718ce6 | ||
|
|
b90b4e42fb | ||
|
|
202f557e32 | ||
|
|
8364c8c688 | ||
|
|
3a286cd240 | ||
|
|
41dbf6fb1b | ||
|
|
47ecbe3f94 | ||
|
|
0f066ab302 | ||
|
|
8e94ddb4bf | ||
|
|
a9cedc6a8a | ||
|
|
7d6c49d8c3 | ||
|
|
0d8ca89b14 | ||
|
|
82a37d69bc |
@@ -37,9 +37,8 @@ Style/AlignParameters:
|
||||
Metrics/LineLength:
|
||||
Max: 120
|
||||
|
||||
|
||||
# See https://github.com/bbatsov/rubocop/issues/3629
|
||||
Rails/HttpPositionalArguments:
|
||||
# turn these back on in Rails 5
|
||||
Rails/HttpPositionalArguments: # See https://github.com/bbatsov/rubocop/issues/3629
|
||||
Enabled: false
|
||||
|
||||
Style/Documentation:
|
||||
@@ -65,9 +64,9 @@ Metrics/BlockLength:
|
||||
Metrics/MethodLength:
|
||||
Max: 34
|
||||
Metrics/AbcSize:
|
||||
Max: 32
|
||||
Max: 31
|
||||
Metrics/ClassLength:
|
||||
Max: 207
|
||||
Max: 179
|
||||
Metrics/CyclomaticComplexity:
|
||||
Max: 11
|
||||
Metrics/PerceivedComplexity:
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
# This configuration was generated by
|
||||
# `rubocop --auto-gen-config --no-offense-counts`
|
||||
# on 2017-05-28 10:57:55 +1200 using RuboCop version 0.47.1.
|
||||
# on 2017-11-05 20:41:45 +1300 using RuboCop version 0.47.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
|
||||
# versions of RuboCop, may require this file to be generated again.
|
||||
|
||||
|
||||
Lint/HandleExceptions:
|
||||
Exclude:
|
||||
- 'lib/tasks/testing.rake'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
|
||||
Lint/UnusedBlockArgument:
|
||||
Exclude:
|
||||
- 'app/controllers/sessions_controller.rb'
|
||||
- 'config/unicorn.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
|
||||
Lint/UnusedMethodArgument:
|
||||
@@ -57,7 +49,6 @@ Rails/TimeZone:
|
||||
- 'spec/factories/member.rb'
|
||||
- 'spec/factories/post.rb'
|
||||
- 'spec/models/post_spec.rb'
|
||||
- 'spec/views/plantings/index.html.haml_spec.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
@@ -122,13 +113,6 @@ Style/EachForSimpleLoop:
|
||||
- 'spec/models/crop_spec.rb'
|
||||
- 'spec/views/home/_crops.html.haml_spec.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# SupportedStyles: compact, expanded
|
||||
Style/EmptyMethod:
|
||||
Exclude:
|
||||
- 'app/controllers/roles_controller.rb'
|
||||
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# SupportedStyles: format, sprintf, percent
|
||||
Style/FormatString:
|
||||
@@ -146,7 +130,6 @@ Style/IdenticalConditionalBranches:
|
||||
Style/IfUnlessModifier:
|
||||
Exclude:
|
||||
- 'app/helpers/crops_helper.rb'
|
||||
- 'app/models/planting.rb'
|
||||
- 'config/initializers/geocoder.rb'
|
||||
- 'lib/tasks/growstuff.rake'
|
||||
|
||||
@@ -165,7 +148,6 @@ Style/MultilineIfModifier:
|
||||
|
||||
Style/MultilineTernaryOperator:
|
||||
Exclude:
|
||||
- 'app/controllers/notifications_controller.rb'
|
||||
- 'app/controllers/order_items_controller.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
@@ -223,7 +205,6 @@ 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'
|
||||
- 'spec/views/posts/show.html.haml_spec.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: SupportedStyles.
|
||||
@@ -243,4 +224,4 @@ Style/SymbolProc:
|
||||
# SupportedStyles: percent, brackets
|
||||
Style/WordArray:
|
||||
EnforcedStyle: percent
|
||||
MinSize: 5
|
||||
MinSize: 4
|
||||
|
||||
@@ -33,7 +33,7 @@ before_script:
|
||||
if [ "${STATIC_CHECKS}" = "true" ]; then
|
||||
./script/install_linters;
|
||||
else
|
||||
bundle exec rake db:create db:migrate db:test:prepare;
|
||||
RAILS_ENV=test bundle exec rake db:create db:migrate;
|
||||
bundle exec rake assets:precompile;
|
||||
fi
|
||||
- set +e
|
||||
|
||||
14
Gemfile
14
Gemfile
@@ -11,12 +11,18 @@ gem 'coffee-rails'
|
||||
gem 'haml'
|
||||
gem 'sass-rails'
|
||||
|
||||
# API data
|
||||
gem 'jsonapi-resources'
|
||||
|
||||
# CSS framework
|
||||
gem 'bootstrap-sass'
|
||||
gem 'font-awesome-sass'
|
||||
|
||||
gem 'uglifier' # JavaScript compressor
|
||||
|
||||
# planting and harvest predictions
|
||||
gem 'active_median'
|
||||
|
||||
gem 'flickraw'
|
||||
gem 'jquery-rails'
|
||||
gem 'jquery-ui-rails', '~> 5.0.2' # needs careful upgrade with change of location
|
||||
@@ -26,8 +32,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
|
||||
@@ -125,6 +134,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
|
||||
|
||||
79
Gemfile.lock
79
Gemfile.lock
@@ -1,5 +1,6 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
remote: https://rails-assets.org/
|
||||
specs:
|
||||
actionmailer (4.2.10)
|
||||
actionpack (= 4.2.10)
|
||||
@@ -23,6 +24,8 @@ GEM
|
||||
active_link_to (1.0.5)
|
||||
actionpack
|
||||
addressable
|
||||
active_median (0.1.4)
|
||||
activerecord
|
||||
active_merchant-paypal-bogus-gateway (0.1.0)
|
||||
activemerchant
|
||||
active_utils (3.3.9)
|
||||
@@ -31,7 +34,7 @@ GEM
|
||||
activejob (4.2.10)
|
||||
activesupport (= 4.2.10)
|
||||
globalid (>= 0.3.0)
|
||||
activemerchant (1.74.0)
|
||||
activemerchant (1.75.0)
|
||||
activesupport (>= 3.2.14, < 6.x)
|
||||
builder (>= 2.1.2, < 4.0.0)
|
||||
i18n (>= 0.6.9)
|
||||
@@ -82,8 +85,8 @@ GEM
|
||||
activesupport (>= 3.0.0)
|
||||
uniform_notifier (~> 1.10.0)
|
||||
byebug (9.1.0)
|
||||
cancancan (2.0.0)
|
||||
capybara (2.15.4)
|
||||
cancancan (2.1.2)
|
||||
capybara (2.16.1)
|
||||
addressable
|
||||
mini_mime (>= 0.1.3)
|
||||
nokogiri (>= 1.3.3)
|
||||
@@ -93,7 +96,7 @@ GEM
|
||||
capybara-email (2.5.0)
|
||||
capybara (~> 2.4)
|
||||
mail
|
||||
capybara-screenshot (1.0.17)
|
||||
capybara-screenshot (1.0.18)
|
||||
capybara (>= 1.0, < 3)
|
||||
launchy
|
||||
childprocess (0.8.0)
|
||||
@@ -137,7 +140,7 @@ GEM
|
||||
term-ansicolor (~> 1.3)
|
||||
thor (~> 0.19.1)
|
||||
tins (~> 1.6)
|
||||
crass (1.0.2)
|
||||
crass (1.0.3)
|
||||
csv_shaper (1.3.0)
|
||||
activesupport (>= 3.0.0)
|
||||
d3-rails (3.5.17)
|
||||
@@ -178,6 +181,8 @@ GEM
|
||||
factory_bot_rails (4.8.2)
|
||||
factory_bot (~> 4.8.2)
|
||||
railties (>= 3.0.0)
|
||||
faker (1.8.4)
|
||||
i18n (~> 0.5)
|
||||
faraday (0.12.2)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
ffi (1.9.18)
|
||||
@@ -189,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)
|
||||
@@ -239,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)
|
||||
@@ -247,7 +252,7 @@ GEM
|
||||
ruby_parser (~> 3.5)
|
||||
httparty (0.15.6)
|
||||
multi_xml (>= 0.5.2)
|
||||
i18n (0.9.0)
|
||||
i18n (0.9.1)
|
||||
concurrent-ruby (~> 1.0)
|
||||
i18n-tasks (0.9.12)
|
||||
activesupport (>= 4.0.2)
|
||||
@@ -271,10 +276,14 @@ 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)
|
||||
jsonapi-resources (0.9.0)
|
||||
activerecord (>= 4.1)
|
||||
concurrent-ruby
|
||||
railties (>= 4.1)
|
||||
jwt (1.5.6)
|
||||
kaminari (1.1.1)
|
||||
activesupport (>= 4.1.0)
|
||||
@@ -289,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)
|
||||
@@ -305,15 +313,15 @@ GEM
|
||||
crass (~> 1.0.2)
|
||||
nokogiri (>= 1.5.9)
|
||||
lumberjack (1.0.12)
|
||||
mail (2.6.6)
|
||||
mime-types (>= 1.16, < 4)
|
||||
mail (2.7.0)
|
||||
mini_mime (>= 0.1.1)
|
||||
memcachier (0.0.2)
|
||||
method_source (0.9.0)
|
||||
mime-types (3.1)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2016.0521)
|
||||
mimemagic (0.3.2)
|
||||
mini_mime (0.1.4)
|
||||
mini_mime (1.0.0)
|
||||
mini_portile2 (2.3.0)
|
||||
minitest (5.10.3)
|
||||
moneta (0.8.1)
|
||||
@@ -321,7 +329,7 @@ GEM
|
||||
multi_xml (0.6.0)
|
||||
multipart-post (2.0.0)
|
||||
nenv (0.3.0)
|
||||
newrelic_rpm (4.5.0.337)
|
||||
newrelic_rpm (4.6.0.338)
|
||||
nokogiri (1.8.1)
|
||||
mini_portile2 (~> 2.3.0)
|
||||
notiffany (0.1.1)
|
||||
@@ -358,8 +366,8 @@ GEM
|
||||
cocaine (~> 0.5.5)
|
||||
mime-types
|
||||
mimemagic (~> 0.3.0)
|
||||
parser (2.4.0.0)
|
||||
ast (~> 2.2)
|
||||
parser (2.4.0.2)
|
||||
ast (~> 2.3)
|
||||
pg (0.21.0)
|
||||
phantomjs (2.1.1.0)
|
||||
platform-api (2.1.0)
|
||||
@@ -372,10 +380,10 @@ GEM
|
||||
cliver (~> 0.3.1)
|
||||
websocket-driver (>= 0.2.0)
|
||||
powerpack (0.1.1)
|
||||
pry (0.11.2)
|
||||
pry (0.11.3)
|
||||
coderay (~> 1.1.0)
|
||||
method_source (~> 0.9.0)
|
||||
public_suffix (3.0.0)
|
||||
public_suffix (3.0.1)
|
||||
quiet_assets (1.1.0)
|
||||
railties (>= 3.1, < 5.0)
|
||||
rack (1.6.8)
|
||||
@@ -394,6 +402,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)
|
||||
@@ -417,7 +428,7 @@ GEM
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
rainbow (2.1.0)
|
||||
raindrops (0.19.0)
|
||||
rake (12.2.1)
|
||||
rake (12.3.0)
|
||||
rb-fsevent (0.10.2)
|
||||
rb-inotify (0.9.10)
|
||||
ffi (>= 0.5.0, < 2)
|
||||
@@ -441,7 +452,7 @@ GEM
|
||||
rspec-mocks (3.7.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.7.0)
|
||||
rspec-rails (3.7.1)
|
||||
rspec-rails (3.7.2)
|
||||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
railties (>= 3.0)
|
||||
@@ -467,13 +478,13 @@ GEM
|
||||
sass-listen (4.0.0)
|
||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||
rb-inotify (~> 0.9, >= 0.9.7)
|
||||
sass-rails (5.0.6)
|
||||
sass-rails (5.0.7)
|
||||
railties (>= 4.0.0, < 6)
|
||||
sass (~> 3.1)
|
||||
sprockets (>= 2.8, < 4.0)
|
||||
sprockets-rails (>= 2.0, < 4.0)
|
||||
tilt (>= 1.1, < 3)
|
||||
selenium-webdriver (3.6.0)
|
||||
selenium-webdriver (3.8.0)
|
||||
childprocess (~> 0.5)
|
||||
rubyzip (~> 1.0)
|
||||
sexp_processor (4.10.0)
|
||||
@@ -488,8 +499,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)
|
||||
@@ -508,7 +519,7 @@ GEM
|
||||
thread_safe (0.3.6)
|
||||
tilt (2.0.8)
|
||||
timecop (0.9.1)
|
||||
tins (1.15.0)
|
||||
tins (1.16.0)
|
||||
trollop (1.16.2)
|
||||
tzinfo (1.2.4)
|
||||
thread_safe (~> 0.1)
|
||||
@@ -527,7 +538,7 @@ GEM
|
||||
rack-test (>= 0.5.3)
|
||||
websocket-driver (0.7.0)
|
||||
websocket-extensions (>= 0.1.0)
|
||||
websocket-extensions (0.1.2)
|
||||
websocket-extensions (0.1.3)
|
||||
will_paginate (3.1.6)
|
||||
xmlrpc (0.3.0)
|
||||
xpath (2.1.0)
|
||||
@@ -537,6 +548,7 @@ PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
active_median
|
||||
active_merchant-paypal-bogus-gateway
|
||||
active_utils
|
||||
activemerchant
|
||||
@@ -568,6 +580,7 @@ DEPENDENCIES
|
||||
elasticsearch-model
|
||||
elasticsearch-rails
|
||||
factory_bot_rails
|
||||
faker
|
||||
figaro
|
||||
flickraw
|
||||
font-awesome-sass
|
||||
@@ -587,9 +600,9 @@ DEPENDENCIES
|
||||
jquery-rails
|
||||
jquery-ui-rails (~> 5.0.2)
|
||||
js-routes
|
||||
jsonapi-resources
|
||||
kaminari
|
||||
leaflet-markercluster-rails
|
||||
leaflet-rails (~> 0.7.7)
|
||||
leaflet-rails
|
||||
letter_opener
|
||||
memcachier
|
||||
newrelic_rpm
|
||||
@@ -603,6 +616,7 @@ DEPENDENCIES
|
||||
pry
|
||||
quiet_assets
|
||||
rails (~> 4.2.8)
|
||||
rails-assets-leaflet.markercluster!
|
||||
rails_12factor
|
||||
rainbow (< 2.2.0)
|
||||
rake (>= 10.0.0)
|
||||
@@ -622,8 +636,9 @@ DEPENDENCIES
|
||||
will_paginate
|
||||
xmlrpc
|
||||
|
||||
|
||||
RUBY VERSION
|
||||
ruby 2.4.1p111
|
||||
|
||||
BUNDLED WITH
|
||||
1.15.4
|
||||
1.16.0
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
7
app/controllers/api/v1/base_controller.rb
Normal file
7
app/controllers/api/v1/base_controller.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
module Api
|
||||
module V1
|
||||
class BaseController < JSONAPI::ResourceController
|
||||
abstract
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/crops_controller.rb
Normal file
6
app/controllers/api/v1/crops_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class CropsController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/gardens_controller.rb
Normal file
6
app/controllers/api/v1/gardens_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class GardensController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/harvests_controller.rb
Normal file
6
app/controllers/api/v1/harvests_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class HarvestsController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/members_controller.rb
Normal file
6
app/controllers/api/v1/members_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class MembersController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/photos_controller.rb
Normal file
6
app/controllers/api/v1/photos_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class PhotosController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/plantings_controller.rb
Normal file
6
app/controllers/api/v1/plantings_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class PlantingsController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/seeds_controller.rb
Normal file
6
app/controllers/api/v1/seeds_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class SeedsController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -6,7 +6,7 @@ class CommentsController < ApplicationController
|
||||
responders :flash
|
||||
|
||||
def index
|
||||
@comments = Comment.paginate(page: params[:page])
|
||||
@comments = Comment.order(created_at: :desc).paginate(page: params[:page])
|
||||
respond_with(@comments)
|
||||
end
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ class CropsController < ApplicationController
|
||||
return unless params[param_name].present?
|
||||
destroy_names(name_type)
|
||||
params[param_name].each do |_i, value|
|
||||
create_name!(name_type, value)
|
||||
create_name!(name_type, value) unless value.empty?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -154,6 +154,7 @@ class CropsController < ApplicationController
|
||||
:name,
|
||||
:parent_id,
|
||||
:creator_id,
|
||||
:perennial,
|
||||
:approval_status,
|
||||
:request_notes,
|
||||
:reason_for_rejection,
|
||||
@@ -184,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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class HarvestsController < ApplicationController
|
||||
before_action :authenticate_member!, except: [:index, :show]
|
||||
before_action :authenticate_member!, except: %i(index show)
|
||||
after_action :update_crop_medians, only: %i(create update destroy)
|
||||
load_and_authorize_resource
|
||||
respond_to :html, :json
|
||||
respond_to :csv, only: :index
|
||||
@@ -33,6 +34,7 @@ class HarvestsController < ApplicationController
|
||||
|
||||
def create
|
||||
@harvest.crop_id = @harvest.planting.crop_id if @harvest.planting_id
|
||||
@harvest.harvested_at = Time.zone.now if @harvest.harvested_at.blank?
|
||||
@harvest.save
|
||||
respond_with(@harvest)
|
||||
end
|
||||
@@ -71,8 +73,8 @@ class HarvestsController < ApplicationController
|
||||
elsif @planting
|
||||
@planting.harvests
|
||||
else
|
||||
Harvest
|
||||
end.joins(:owner, :crop).paginate(page: params[:page])
|
||||
Harvest.all
|
||||
end.order(harvested_at: :desc).joins(:owner, :crop).paginate(page: params[:page])
|
||||
end
|
||||
|
||||
def csv_filename
|
||||
@@ -83,4 +85,13 @@ class HarvestsController < ApplicationController
|
||||
end
|
||||
"Growstuff-#{specifics}Harvests-#{Time.zone.now.to_s(:number)}.csv"
|
||||
end
|
||||
|
||||
def update_crop_medians
|
||||
# We only update medians to predict plantings
|
||||
# if this harvest is not linked to a planting, then do nothing
|
||||
return if @harvest.planting.nil?
|
||||
|
||||
@harvest.planting.update_harvest_days
|
||||
@harvest.crop.update_harvest_medians
|
||||
end
|
||||
end
|
||||
|
||||
@@ -96,8 +96,10 @@ class MembersController < ApplicationController
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -12,15 +12,17 @@ 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
|
||||
|
||||
def new
|
||||
@type = params[:type]
|
||||
@id = params[:id]
|
||||
|
||||
@photo = Photo.new
|
||||
@item = item_to_link_to
|
||||
@type = item_type
|
||||
@id = item_id
|
||||
retrieve_from_flickr
|
||||
respond_with @photo
|
||||
end
|
||||
@@ -30,9 +32,13 @@ class PhotosController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
find_or_create_photo_from_flickr_photo
|
||||
add_photo_to_collection
|
||||
@photo.save if @photo.present?
|
||||
ActiveRecord::Base.transaction do
|
||||
@photo = find_or_create_photo_from_flickr_photo
|
||||
@item = item_to_link_to
|
||||
raise "Could not find this #{type} owned by you" unless @item
|
||||
collection << @item unless collection.include?(@item)
|
||||
@photo.save! if @photo.present?
|
||||
end
|
||||
respond_with @photo
|
||||
end
|
||||
|
||||
@@ -48,8 +54,14 @@ class PhotosController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def item_id?
|
||||
params.key? :id
|
||||
#
|
||||
# Params
|
||||
def item_id
|
||||
params[:id]
|
||||
end
|
||||
|
||||
def item_type
|
||||
params[:type]
|
||||
end
|
||||
|
||||
def flickr_photo_id_param
|
||||
@@ -61,26 +73,32 @@ class PhotosController < ApplicationController
|
||||
:license_url, :thumbnail_url, :fullsize_url, :link_url)
|
||||
end
|
||||
|
||||
def find_or_create_photo_from_flickr_photo
|
||||
@photo = Photo.find_by(flickr_photo_id: flickr_photo_id_param)
|
||||
@photo = Photo.new(photo_params) unless @photo
|
||||
@photo.owner_id = current_member.id
|
||||
@photo.set_flickr_metadata
|
||||
@photo
|
||||
# Item with photos attached
|
||||
#
|
||||
def item_to_link_to
|
||||
raise "No item id provided" if item_id.nil?
|
||||
raise "No item type provided" if item_type.nil?
|
||||
raise "Missing or invalid type provided" unless photos_supported_on_type?(item_type)
|
||||
item_class = Growstuff::Constants::PhotoModels.get_item(item_type)
|
||||
item_class.find_by!(id: params[:id], owner_id: current_member.id)
|
||||
end
|
||||
|
||||
def add_photo_to_collection
|
||||
raise "Missing or invalid type provided" unless Growstuff::Constants::PhotoModels.types.include?(params[:type])
|
||||
raise "No item id provided" unless item_id?
|
||||
collection = Growstuff::Constants::PhotoModels.get_relation(@photo, params[:type])
|
||||
def collection
|
||||
Growstuff::Constants::PhotoModels.get_relation(@photo, item_type)
|
||||
end
|
||||
|
||||
item_class = Growstuff::Constants::PhotoModels.get_item(params[:type])
|
||||
item = item_class.find_by!(id: params[:id], owner_id: current_member.id)
|
||||
raise "Could not find this item owned by you" unless item
|
||||
def photos_supported_on_type?(_type)
|
||||
Growstuff::Constants::PhotoModels.types.include?(item_type)
|
||||
end
|
||||
|
||||
collection << item unless collection.include?(item)
|
||||
rescue => e
|
||||
flash[:alert] = e.message
|
||||
#
|
||||
# Flickr retrieval
|
||||
def find_or_create_photo_from_flickr_photo
|
||||
photo = Photo.find_by(flickr_photo_id: flickr_photo_id_param)
|
||||
photo ||= Photo.new(photo_params)
|
||||
photo.owner_id = current_member.id
|
||||
photo.set_flickr_metadata
|
||||
photo
|
||||
end
|
||||
|
||||
def retrieve_from_flickr
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
class PlantingsController < ApplicationController
|
||||
before_action :authenticate_member!, except: [:index, :show]
|
||||
after_action :expire_homepage, only: [:create, :update, :destroy]
|
||||
before_action :authenticate_member!, except: %i(index show)
|
||||
after_action :expire_homepage, only: %i(create update destroy)
|
||||
after_action :update_crop_medians, only: %i(create update destroy)
|
||||
after_action :update_planting_medians, only: :update
|
||||
load_and_authorize_resource
|
||||
|
||||
respond_to :html, :json
|
||||
@@ -51,13 +53,11 @@ class PlantingsController < ApplicationController
|
||||
def create
|
||||
@planting = Planting.new(planting_params)
|
||||
@planting.owner = current_member
|
||||
@planting.calc_and_set_days_before_maturity
|
||||
@planting.save
|
||||
@planting.save!
|
||||
respond_with @planting
|
||||
end
|
||||
|
||||
def update
|
||||
@planting.calc_and_set_days_before_maturity
|
||||
@planting.update(planting_params)
|
||||
respond_with @planting
|
||||
end
|
||||
@@ -69,6 +69,14 @@ class PlantingsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def update_crop_medians
|
||||
@planting.crop.update_lifespan_medians
|
||||
end
|
||||
|
||||
def update_planting_medians
|
||||
@planting.update_harvest_days
|
||||
end
|
||||
|
||||
def planting_params
|
||||
params[:planted_at] = parse_date(params[:planted_at]) if params[:planted_at]
|
||||
params.require(:planting).permit(
|
||||
@@ -87,6 +95,9 @@ class PlantingsController < ApplicationController
|
||||
Planting
|
||||
end
|
||||
p = p.current unless @show_all
|
||||
p.joins(:owner, :crop, :garden).order(:created_at).paginate(page: params[:page])
|
||||
p.joins(:owner, :crop, :garden)
|
||||
.order(created_at: :desc)
|
||||
.includes(:crop, :owner, :garden)
|
||||
.paginate(page: params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,7 +5,7 @@ class ProductsController < ApplicationController
|
||||
responders :flash
|
||||
|
||||
def index
|
||||
@products = Product.all
|
||||
@products = Product.all.order(:name)
|
||||
respond_with @products
|
||||
end
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ class RolesController < ApplicationController
|
||||
responders :flash
|
||||
|
||||
def index
|
||||
@roles = Role.all
|
||||
@roles = Role.all.order(:name)
|
||||
respond_with @roles
|
||||
end
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,7 +2,7 @@ class SessionsController < Devise::SessionsController
|
||||
respond_to :json
|
||||
|
||||
def create
|
||||
super do |resource|
|
||||
super do |_resource|
|
||||
if Crop.pending_approval.present? && current_member.role?(:crop_wrangler)
|
||||
flash[:alert] = "There are crops waiting to be wrangled."
|
||||
end
|
||||
|
||||
@@ -1,18 +1,6 @@
|
||||
module PlantingsHelper
|
||||
def display_days_before_maturity(planting)
|
||||
# First try to calc from finished/finished_at
|
||||
if planting.finished? || planting.finished_at.present?
|
||||
planting.days_until_finished.to_s
|
||||
# then try to calc from planted at + maturity
|
||||
elsif planting.planted_at.present? && planting.days_before_maturity.present?
|
||||
planting.days_until_mature.to_s
|
||||
else
|
||||
"unknown"
|
||||
end
|
||||
end
|
||||
|
||||
def display_finished(planting)
|
||||
if !planting.finished_at.nil?
|
||||
if planting.finished_at.present?
|
||||
planting.finished_at
|
||||
elsif planting.finished
|
||||
"Yes (no date specified)"
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
class AccountType < ActiveRecord::Base
|
||||
#
|
||||
# Relationships
|
||||
has_many :products
|
||||
|
||||
#
|
||||
# Validations
|
||||
validates :name, presence: true, uniqueness: true
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,11 +2,14 @@ class Crop < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: [:slugged, :finders]
|
||||
|
||||
has_many :scientific_names, after_add: :update_index, after_remove: :update_index
|
||||
accepts_nested_attributes_for :scientific_names,
|
||||
allow_destroy: true,
|
||||
reject_if: :all_blank
|
||||
##
|
||||
## Triggers
|
||||
before_destroy { |crop| crop.posts.clear }
|
||||
|
||||
##
|
||||
## Relationships
|
||||
has_many :scientific_names, after_add: :update_index, after_remove: :update_index, dependent: :destroy
|
||||
accepts_nested_attributes_for :scientific_names, allow_destroy: true, reject_if: :all_blank
|
||||
has_many :alternate_names, after_add: :update_index, after_remove: :update_index, dependent: :destroy
|
||||
has_many :plantings
|
||||
has_many :photos, through: :plantings
|
||||
@@ -15,33 +18,31 @@ class Crop < ActiveRecord::Base
|
||||
has_many :plant_parts, -> { uniq.reorder("plant_parts.name") }, through: :harvests
|
||||
belongs_to :creator, class_name: 'Member'
|
||||
belongs_to :requester, class_name: 'Member'
|
||||
|
||||
belongs_to :parent, class_name: 'Crop'
|
||||
has_many :varieties, class_name: 'Crop', foreign_key: 'parent_id'
|
||||
has_and_belongs_to_many :posts # rubocop:disable Rails/HasAndBelongsToMany
|
||||
before_destroy { |crop| crop.posts.clear }
|
||||
|
||||
default_scope { order("lower(crops.name) asc") }
|
||||
scope :recent, lambda {
|
||||
approved.reorder("created_at desc")
|
||||
}
|
||||
scope :toplevel, lambda {
|
||||
approved.where(parent_id: nil)
|
||||
}
|
||||
scope :popular, lambda {
|
||||
approved.reorder("plantings_count desc, lower(name) asc")
|
||||
}
|
||||
scope :randomized, lambda {
|
||||
# ok on sqlite and psql, but not on mysql
|
||||
approved.reorder('random()')
|
||||
}
|
||||
##
|
||||
## Scopes
|
||||
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
|
||||
scope :randomized, -> { approved.reorder('random()') }
|
||||
scope :pending_approval, -> { where(approval_status: "pending") }
|
||||
scope :approved, -> { where(approval_status: "approved") }
|
||||
scope :rejected, -> { where(approval_status: "rejected") }
|
||||
|
||||
scope :interesting, -> { approved.has_photos.randomized }
|
||||
scope :has_photos, -> { includes(:photos).where.not(photos: { id: nil }) }
|
||||
|
||||
##
|
||||
## Validations
|
||||
# Reasons are only necessary when rejecting
|
||||
validates :reason_for_rejection, presence: true, if: :rejected?
|
||||
## This validation addresses a race condition
|
||||
validate :approval_status_cannot_be_changed_again
|
||||
validate :must_be_rejected_if_rejected_reasons_present
|
||||
validate :must_have_meaningful_reason_for_rejection
|
||||
## Wikipedia urls are only necessary when approving a crop
|
||||
validates :en_wikipedia_url,
|
||||
format: {
|
||||
@@ -50,16 +51,6 @@ class Crop < ActiveRecord::Base
|
||||
},
|
||||
if: :approved?
|
||||
|
||||
## Reasons are only necessary when rejecting
|
||||
validates :reason_for_rejection, presence: true, if: :rejected?
|
||||
|
||||
## This validation addresses a race condition
|
||||
validate :approval_status_cannot_be_changed_again
|
||||
|
||||
validate :must_be_rejected_if_rejected_reasons_present
|
||||
|
||||
validate :must_have_meaningful_reason_for_rejection
|
||||
|
||||
####################################
|
||||
# Elastic search configuration
|
||||
if ENV["GROWSTUFF_ELASTICSEARCH"] == "true"
|
||||
@@ -110,22 +101,11 @@ class Crop < ActiveRecord::Base
|
||||
Photo.joins(:harvests).where("harvests.crop_id": id)
|
||||
end
|
||||
|
||||
def as_indexed_json(_options = {})
|
||||
as_json(
|
||||
only: [:id, :name, :approval_status],
|
||||
include: {
|
||||
scientific_names: { only: :name },
|
||||
alternate_names: { only: :name }
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
# update the Elasticsearch index (only if we're using it in this
|
||||
# environment)
|
||||
def update_index(_name_obj)
|
||||
__elasticsearch__.index_document if ENV["GROWSTUFF_ELASTICSEARCH"] == "true"
|
||||
end
|
||||
|
||||
# End Elasticsearch section
|
||||
|
||||
def to_s
|
||||
@@ -136,7 +116,6 @@ class Crop < ActiveRecord::Base
|
||||
scientific_names.first.name unless scientific_names.empty?
|
||||
end
|
||||
|
||||
# crop.default_photo
|
||||
# currently returns the first available photo, but exists so that
|
||||
# later we can choose a default photo based on different criteria,
|
||||
# eg. popularity
|
||||
@@ -148,7 +127,6 @@ class Crop < ActiveRecord::Base
|
||||
harvest_with_photo.photos.first if harvest_with_photo
|
||||
end
|
||||
|
||||
# crop.sunniness
|
||||
# returns hash indicating whether this crop is grown in
|
||||
# sun/semi-shade/shade
|
||||
# key: sunniness (eg. 'sun')
|
||||
@@ -157,7 +135,6 @@ class Crop < ActiveRecord::Base
|
||||
count_uses_of_property 'sunniness'
|
||||
end
|
||||
|
||||
# crop.planted_from
|
||||
# returns a hash of propagation methods (seed, seedling, etc),
|
||||
# key: propagation method (eg. 'seed')
|
||||
# value: count of how many times it's been used by plantings
|
||||
@@ -165,7 +142,6 @@ class Crop < ActiveRecord::Base
|
||||
count_uses_of_property 'planted_from'
|
||||
end
|
||||
|
||||
# crop.popular_plant_parts
|
||||
# returns a hash of most harvested plant parts (fruit, seed, etc)
|
||||
# key: plant part (eg. 'fruit')
|
||||
# value: count of how many times it's been used by harvests
|
||||
@@ -177,6 +153,10 @@ class Crop < ActiveRecord::Base
|
||||
.count("harvests.id")
|
||||
end
|
||||
|
||||
def annual?
|
||||
!perennial
|
||||
end
|
||||
|
||||
def interesting?
|
||||
min_plantings = 3 # needs this many plantings to be interesting
|
||||
min_photos = 3 # needs this many photos to be interesting
|
||||
@@ -210,45 +190,24 @@ class Crop < ActiveRecord::Base
|
||||
reason_for_rejection
|
||||
end
|
||||
|
||||
# Crop.search(string)
|
||||
def update_medians
|
||||
plantings.each(&:update_harvest_days)
|
||||
update_lifespan_medians
|
||||
update_harvest_medians
|
||||
end
|
||||
|
||||
def update_lifespan_medians
|
||||
# Median lifespan of plantings
|
||||
update(median_lifespan: Planting.where(crop: self).median(:lifespan))
|
||||
end
|
||||
|
||||
def update_harvest_medians
|
||||
update(median_days_to_first_harvest: Planting.where(crop: self).median(:days_to_first_harvest))
|
||||
update(median_days_to_last_harvest: Planting.where(crop: self).median(:days_to_last_harvest))
|
||||
end
|
||||
|
||||
def self.search(query)
|
||||
if ENV['GROWSTUFF_ELASTICSEARCH'] == "true"
|
||||
search_str = query.nil? ? "" : query.downcase
|
||||
response = __elasticsearch__.search( # Finds documents which match any field, but uses the _score from
|
||||
# the best field insead of adding up _score from each field.
|
||||
query: {
|
||||
multi_match: {
|
||||
query: search_str.to_s,
|
||||
analyzer: "standard",
|
||||
fields: ["name",
|
||||
"scientific_names.scientific_name",
|
||||
"alternate_names.name"]
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
term: { approval_status: "approved" }
|
||||
},
|
||||
size: 50
|
||||
)
|
||||
response.records.to_a
|
||||
else
|
||||
# if we don't have elasticsearch, just do a basic SQL query.
|
||||
# also, make sure it's an actual array not an activerecord
|
||||
# collection, so it matches what we get from elasticsearch and we can
|
||||
# manipulate it in the same ways (eg. deleting elements without deleting
|
||||
# the whole record from the db)
|
||||
matches = Crop.approved.where("name ILIKE ?", "%#{query}%").to_a
|
||||
|
||||
# we want to make sure that exact matches come first, even if not
|
||||
# using elasticsearch (eg. in development)
|
||||
exact_match = Crop.approved.find_by(name: query)
|
||||
if exact_match
|
||||
matches.delete(exact_match)
|
||||
matches.unshift(exact_match)
|
||||
end
|
||||
|
||||
matches
|
||||
end
|
||||
CropSearchService.search(query)
|
||||
end
|
||||
|
||||
def self.case_insensitive_name(name)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Forum < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
validates :name, presence: true
|
||||
friendly_id :name, use: [:slugged, :finders]
|
||||
friendly_id :name, use: %i(slugged finders)
|
||||
|
||||
has_many :posts
|
||||
belongs_to :owner, class_name: "Member"
|
||||
|
||||
@@ -2,7 +2,7 @@ class Garden < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
include Geocodable
|
||||
include PhotoCapable
|
||||
friendly_id :garden_slug, use: [:slugged, :finders]
|
||||
friendly_id :garden_slug, use: %i(slugged finders)
|
||||
|
||||
belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id', counter_cache: true
|
||||
has_many :plantings, dependent: :destroy
|
||||
@@ -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) }
|
||||
|
||||
@@ -41,7 +41,7 @@ class Garden < ActiveRecord::Base
|
||||
"acres" => "acre"
|
||||
}.freeze
|
||||
validates :area_unit, inclusion: { in: AREA_UNITS_VALUES.values,
|
||||
message: "%{value} is not a valid area unit" },
|
||||
message: "%<value>s is not a valid area unit" },
|
||||
allow_nil: true,
|
||||
allow_blank: true
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,28 +1,11 @@
|
||||
class Harvest < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
include ActionView::Helpers::NumberHelper
|
||||
extend FriendlyId
|
||||
include PhotoCapable
|
||||
friendly_id :harvest_slug, use: [:slugged, :finders]
|
||||
|
||||
belongs_to :crop
|
||||
belongs_to :owner, class_name: 'Member', counter_cache: true
|
||||
belongs_to :plant_part
|
||||
belongs_to :planting
|
||||
|
||||
default_scope { joins(:owner).order(created_at: :desc) }
|
||||
validates :crop, approved: true
|
||||
|
||||
validates :crop, presence: { message: "must be present and exist in our database" }
|
||||
|
||||
validates :plant_part, presence: { message: "must be present and exist in our database" }
|
||||
|
||||
validates :quantity,
|
||||
numericality: {
|
||||
only_integer: false,
|
||||
greater_than_or_equal_to: 0
|
||||
},
|
||||
allow_nil: true
|
||||
friendly_id :harvest_slug, use: %i(slugged finders)
|
||||
|
||||
# Constants
|
||||
UNITS_VALUES = {
|
||||
"individual" => "individual",
|
||||
"bunches" => "bunch",
|
||||
@@ -35,29 +18,54 @@ class Harvest < ActiveRecord::Base
|
||||
"baskets" => "basket",
|
||||
"bushels" => "bushel"
|
||||
}.freeze
|
||||
validates :unit, inclusion: { in: UNITS_VALUES.values,
|
||||
message: "%{value} is not a valid unit" },
|
||||
allow_nil: true,
|
||||
allow_blank: true
|
||||
|
||||
validates :weight_quantity,
|
||||
numericality: { only_integer: false },
|
||||
allow_nil: true
|
||||
|
||||
WEIGHT_UNITS_VALUES = {
|
||||
"kg" => "kg",
|
||||
"lb" => "lb",
|
||||
"oz" => "oz"
|
||||
}.freeze
|
||||
validates :weight_unit, inclusion: { in: WEIGHT_UNITS_VALUES.values,
|
||||
message: "%{value} is not a valid unit" },
|
||||
allow_nil: true,
|
||||
allow_blank: true
|
||||
|
||||
##
|
||||
## Triggers
|
||||
after_validation :cleanup_quantities
|
||||
|
||||
before_save :set_si_weight
|
||||
|
||||
##
|
||||
## Relationships
|
||||
belongs_to :crop
|
||||
belongs_to :owner, class_name: 'Member', counter_cache: true
|
||||
belongs_to :plant_part
|
||||
belongs_to :planting
|
||||
|
||||
##
|
||||
## Scopes
|
||||
default_scope { joins(:owner) } # Ensures owner exists
|
||||
|
||||
##
|
||||
## Validations
|
||||
validates :crop, approved: true
|
||||
validates :crop, presence: { message: "must be present and exist in our database" }
|
||||
validates :plant_part, presence: { message: "must be present and exist in our database" }
|
||||
validates :harvested_at, presence: true
|
||||
validates :quantity, allow_nil: true, numericality: {
|
||||
only_integer: false, greater_than_or_equal_to: 0
|
||||
}
|
||||
validates :unit, allow_nil: true, allow_blank: true, inclusion: {
|
||||
in: UNITS_VALUES.values, message: "%<value>s is not a valid unit"
|
||||
}
|
||||
validates :weight_quantity, allow_nil: true, numericality: { only_integer: false }
|
||||
validates :weight_unit, allow_nil: true, allow_blank: true, inclusion: {
|
||||
in: WEIGHT_UNITS_VALUES.values, message: "%<value>s is not a valid unit"
|
||||
}
|
||||
validate :crop_must_match_planting
|
||||
validate :owner_must_match_planting
|
||||
validate :harvest_must_be_after_planting
|
||||
|
||||
def time_from_planting_to_harvest
|
||||
return if planting.blank?
|
||||
harvested_at - planting.planted_at
|
||||
end
|
||||
|
||||
# we're storing the harvest weight in kilograms in the db too
|
||||
# to make data manipulation easier
|
||||
def set_si_weight
|
||||
@@ -116,6 +124,24 @@ 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
|
||||
end
|
||||
|
||||
def owner_must_match_planting
|
||||
return if planting.blank? # only check if we are linked to a planting
|
||||
errors.add(:owner, "of harvest must be the same as planting") unless owner == planting.owner
|
||||
end
|
||||
|
||||
def harvest_must_be_after_planting
|
||||
# only check if we are linked to a planting
|
||||
return unless harvested_at.present? && planting.present? && planting.planted_at.present?
|
||||
errors.add(:planting, "cannot be harvested before planting") unless harvested_at > planting.planted_at
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,50 +4,42 @@ class Member < ActiveRecord::Base
|
||||
include Geocodable
|
||||
extend FriendlyId
|
||||
|
||||
friendly_id :login_name, use: [:slugged, :finders]
|
||||
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
|
||||
|
||||
@@ -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) }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class PlantPart < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: [:slugged, :finders]
|
||||
friendly_id :name, use: %i(slugged finders)
|
||||
|
||||
has_many :harvests
|
||||
has_many :crops, -> { uniq }, through: :harvests
|
||||
|
||||
@@ -1,17 +1,30 @@
|
||||
class Planting < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
include PhotoCapable
|
||||
friendly_id :planting_slug, use: [:slugged, :finders]
|
||||
friendly_id :planting_slug, use: %i(slugged finders)
|
||||
|
||||
# Constants
|
||||
SUNNINESS_VALUES = %w(sun semi-shade shade)
|
||||
PLANTED_FROM_VALUES = [
|
||||
'seed', 'seedling', 'cutting', 'root division', 'runner',
|
||||
'bulb', 'root/tuber', 'bare root plant', 'advanced plant',
|
||||
'graft', 'layering'
|
||||
]
|
||||
|
||||
##
|
||||
## Triggers
|
||||
before_save :calculate_lifespan
|
||||
|
||||
belongs_to :garden
|
||||
belongs_to :owner, class_name: 'Member', counter_cache: true
|
||||
belongs_to :crop, counter_cache: true
|
||||
has_many :harvests, dependent: :destroy
|
||||
|
||||
default_scope { joins(:owner).order(created_at: :desc) }
|
||||
##
|
||||
## Scopes
|
||||
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 }
|
||||
scope :one_per_owner, lambda {
|
||||
joins("JOIN members m ON (m.id=plantings.owner_id)
|
||||
@@ -19,60 +32,26 @@ class Planting < ActiveRecord::Base
|
||||
ON (m.id=p2.owner_id AND plantings.id < p2.id)").where("p2 IS NULL")
|
||||
}
|
||||
|
||||
delegate :name,
|
||||
:en_wikipedia_url,
|
||||
:default_scientific_name,
|
||||
:plantings_count,
|
||||
to: :crop,
|
||||
prefix: true
|
||||
##
|
||||
## Delegations
|
||||
delegate :name, :en_wikipedia_url, :default_scientific_name, :plantings_count,
|
||||
to: :crop, prefix: true
|
||||
|
||||
##
|
||||
## Validations
|
||||
validates :garden, presence: true
|
||||
validates :crop, presence: true
|
||||
validates :crop, approved: { message: "must be present and exist in our database" }
|
||||
|
||||
validates :quantity,
|
||||
numericality: {
|
||||
only_integer: true,
|
||||
greater_than_or_equal_to: 0
|
||||
},
|
||||
allow_nil: true
|
||||
|
||||
SUNNINESS_VALUES = %w(sun semi-shade shade)
|
||||
validates :sunniness, inclusion: { in: SUNNINESS_VALUES,
|
||||
message: "%{value} is not a valid sunniness value" },
|
||||
allow_nil: true,
|
||||
allow_blank: true
|
||||
|
||||
PLANTED_FROM_VALUES = [
|
||||
'seed',
|
||||
'seedling',
|
||||
'cutting',
|
||||
'root division',
|
||||
'runner',
|
||||
'bulb',
|
||||
'root/tuber',
|
||||
'bare root plant',
|
||||
'advanced plant',
|
||||
'graft',
|
||||
'layering'
|
||||
]
|
||||
validates :planted_from, inclusion: { in: PLANTED_FROM_VALUES,
|
||||
message: "%{value} is not a valid planting method" },
|
||||
allow_nil: true,
|
||||
allow_blank: true
|
||||
|
||||
validates :crop, presence: true, approved: { message: "must be present and exist in our database" }
|
||||
validate :finished_must_be_after_planted
|
||||
|
||||
delegate :days_until_finished, to: :predict
|
||||
delegate :days_until_mature, to: :predict
|
||||
delegate :percentage_grown, to: :predict
|
||||
delegate :start_to_finish_diff, to: :predict
|
||||
|
||||
# check that any finished_at date occurs after planted_at
|
||||
def finished_must_be_after_planted
|
||||
return unless planted_at && finished_at # only check if we have both
|
||||
errors.add(:finished_at, "must be after the planting date") unless planted_at < finished_at
|
||||
end
|
||||
validate :owner_must_match_garden_owner
|
||||
validates :quantity, allow_nil: true, numericality: {
|
||||
only_integer: true, greater_than_or_equal_to: 0
|
||||
}
|
||||
validates :sunniness, allow_nil: true, allow_blank: true, inclusion: {
|
||||
in: SUNNINESS_VALUES, message: "%<value>s is not a valid sunniness value"
|
||||
}
|
||||
validates :planted_from, allow_nil: true, allow_blank: true, inclusion: {
|
||||
in: PLANTED_FROM_VALUES, message: "%<value>s is not a valid planting method"
|
||||
}
|
||||
|
||||
def planting_slug
|
||||
[
|
||||
@@ -93,20 +72,71 @@ class Planting < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def default_photo
|
||||
photos.first
|
||||
photos.order(created_at: :desc).first
|
||||
end
|
||||
|
||||
def planted?
|
||||
planted_at.present? && planted_at <= Date.current
|
||||
end
|
||||
|
||||
def calc_and_set_days_before_maturity
|
||||
self.days_before_maturity = predict.predict_days_before_maturity
|
||||
def finish_predicted_at
|
||||
planted_at + crop.median_lifespan.days if crop.median_lifespan.present? && planted_at.present?
|
||||
end
|
||||
|
||||
def calculate_lifespan
|
||||
self.lifespan = (planted_at.present? && finished_at.present? ? finished_at - planted_at : nil)
|
||||
end
|
||||
|
||||
def expected_lifespan
|
||||
if planted_at.present? && finished_at.present?
|
||||
return (finished_at - planted_at).to_i
|
||||
end
|
||||
crop.median_lifespan
|
||||
end
|
||||
|
||||
def days_since_planted
|
||||
(Time.zone.today - planted_at).to_i if planted_at.present?
|
||||
end
|
||||
|
||||
def percentage_grown
|
||||
return 100 if finished
|
||||
return if planted_at.blank? || expected_lifespan.blank?
|
||||
p = (days_since_planted / expected_lifespan.to_f) * 100
|
||||
return p if p <= 100
|
||||
100
|
||||
end
|
||||
|
||||
def update_harvest_days
|
||||
days_to_first_harvest = nil
|
||||
days_to_last_harvest = nil
|
||||
if planted_at.present? && harvests_with_dates.size.positive?
|
||||
days_to_first_harvest = (first_harvest_date - planted_at).to_i
|
||||
days_to_last_harvest = (last_harvest_date - planted_at).to_i if finished?
|
||||
end
|
||||
update(days_to_first_harvest: days_to_first_harvest, days_to_last_harvest: days_to_last_harvest)
|
||||
end
|
||||
|
||||
def first_harvest_date
|
||||
harvests_with_dates.minimum(:harvested_at)
|
||||
end
|
||||
|
||||
def last_harvest_date
|
||||
harvests_with_dates.maximum(:harvested_at)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def predict
|
||||
PlantingPredictions.new(self)
|
||||
def harvests_with_dates
|
||||
harvests.where.not(harvested_at: nil)
|
||||
end
|
||||
|
||||
# check that any finished_at date occurs after planted_at
|
||||
def finished_must_be_after_planted
|
||||
return unless planted_at && finished_at # only check if we have both
|
||||
errors.add(:finished_at, "must be after the planting date") unless planted_at < finished_at
|
||||
end
|
||||
|
||||
def owner_must_match_garden_owner
|
||||
errors.add(:owner, "must be the same as garden") unless owner == garden.owner
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,46 +1,28 @@
|
||||
class Post < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
include Likeable
|
||||
friendly_id :author_date_subject, use: [:slugged, :finders]
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
class Role < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: [:slugged, :finders]
|
||||
friendly_id :name, use: %i(slugged finders)
|
||||
|
||||
has_and_belongs_to_many :members # rubocop:disable Rails/HasAndBelongsToMany
|
||||
|
||||
class << self
|
||||
[:crop_wranglers, :admins].each do |method|
|
||||
%i(crop_wranglers admins).each do |method|
|
||||
define_method method do
|
||||
slug = method.to_s.singularize.dasherize
|
||||
Role.where(slug: slug).try(:first).try(:members)
|
||||
|
||||
@@ -3,81 +3,50 @@ class Seed < ActiveRecord::Base
|
||||
include PhotoCapable
|
||||
friendly_id :seed_slug, use: [: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
|
||||
|
||||
8
app/resources/api/v1/base_resource.rb
Normal file
8
app/resources/api/v1/base_resource.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
module Api
|
||||
module V1
|
||||
class BaseResource < JSONAPI::Resource
|
||||
immutable
|
||||
abstract
|
||||
end
|
||||
end
|
||||
end
|
||||
22
app/resources/api/v1/crop_resource.rb
Normal file
22
app/resources/api/v1/crop_resource.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
module Api
|
||||
module V1
|
||||
class CropResource < BaseResource
|
||||
immutable
|
||||
|
||||
filter :approval_status, default: 'approved'
|
||||
|
||||
has_many :plantings
|
||||
has_many :photos
|
||||
has_many :harvests
|
||||
has_one :parent
|
||||
|
||||
attribute :name
|
||||
attribute :en_wikipedia_url
|
||||
|
||||
attribute :perennial
|
||||
attribute :median_lifespan
|
||||
attribute :median_days_to_first_harvest
|
||||
attribute :median_days_to_last_harvest
|
||||
end
|
||||
end
|
||||
end
|
||||
13
app/resources/api/v1/garden_resource.rb
Normal file
13
app/resources/api/v1/garden_resource.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module Api
|
||||
module V1
|
||||
class GardenResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_many :plantings
|
||||
has_many :photos
|
||||
|
||||
attribute :name
|
||||
end
|
||||
end
|
||||
end
|
||||
19
app/resources/api/v1/harvest_resource.rb
Normal file
19
app/resources/api/v1/harvest_resource.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module Api
|
||||
module V1
|
||||
class HarvestResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :crop
|
||||
has_one :planting
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_many :photos
|
||||
|
||||
attribute :harvested_at
|
||||
attribute :description
|
||||
attribute :unit
|
||||
attribute :weight_quantity
|
||||
attribute :weight_unit
|
||||
attribute :si_weight
|
||||
end
|
||||
end
|
||||
end
|
||||
15
app/resources/api/v1/member_resource.rb
Normal file
15
app/resources/api/v1/member_resource.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
module Api
|
||||
module V1
|
||||
class MemberResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_many :gardens
|
||||
has_many :plantings
|
||||
has_many :harvests
|
||||
has_many :seeds
|
||||
has_many :photos
|
||||
|
||||
attribute :login_name
|
||||
end
|
||||
end
|
||||
end
|
||||
18
app/resources/api/v1/photo_resource.rb
Normal file
18
app/resources/api/v1/photo_resource.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module Api
|
||||
module V1
|
||||
class PhotoResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_many :plantings
|
||||
has_many :gardens
|
||||
has_many :harvests
|
||||
|
||||
attribute :thumbnail_url
|
||||
attribute :fullsize_url
|
||||
attribute :license_name
|
||||
attribute :link_url
|
||||
attribute :title
|
||||
end
|
||||
end
|
||||
end
|
||||
28
app/resources/api/v1/planting_resource.rb
Normal file
28
app/resources/api/v1/planting_resource.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module Api
|
||||
module V1
|
||||
class PlantingResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :garden
|
||||
has_one :crop
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_many :photos
|
||||
has_many :harvests
|
||||
|
||||
attribute :planted_at
|
||||
attribute :finished_at
|
||||
attribute :finished
|
||||
attribute :quantity
|
||||
attribute :description
|
||||
attribute :sunniness
|
||||
attribute :planted_from
|
||||
|
||||
# Predictions
|
||||
attribute :expected_lifespan
|
||||
attribute :finish_predicted_at
|
||||
attribute :percentage_grown
|
||||
attribute :first_harvest_date
|
||||
attribute :last_harvest_date
|
||||
end
|
||||
end
|
||||
end
|
||||
20
app/resources/api/v1/seed_resource.rb
Normal file
20
app/resources/api/v1/seed_resource.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
module Api
|
||||
module V1
|
||||
class SeedResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_one :crop
|
||||
|
||||
attribute :description
|
||||
attribute :quantity
|
||||
attribute :plant_before
|
||||
attribute :tradable_to
|
||||
attribute :days_until_maturity_min
|
||||
attribute :days_until_maturity_max
|
||||
attribute :organic
|
||||
attribute :gmo
|
||||
attribute :heirloom
|
||||
end
|
||||
end
|
||||
end
|
||||
42
app/services/crop_search_service.rb
Normal file
42
app/services/crop_search_service.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
class CropSearchService
|
||||
# Crop.search(string)
|
||||
def self.search(query)
|
||||
if ENV['GROWSTUFF_ELASTICSEARCH'] == "true"
|
||||
search_str = query.nil? ? "" : query.downcase
|
||||
response = Crop.__elasticsearch__.search( # Finds documents which match any field, but uses the _score from
|
||||
# the best field insead of adding up _score from each field.
|
||||
query: {
|
||||
multi_match: {
|
||||
query: search_str.to_s,
|
||||
analyzer: "standard",
|
||||
fields: ["name",
|
||||
"scientific_names.scientific_name",
|
||||
"alternate_names.name"]
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
term: { approval_status: "approved" }
|
||||
},
|
||||
size: 50
|
||||
)
|
||||
response.records.to_a
|
||||
else
|
||||
# if we don't have elasticsearch, just do a basic SQL query.
|
||||
# also, make sure it's an actual array not an activerecord
|
||||
# collection, so it matches what we get from elasticsearch and we can
|
||||
# manipulate it in the same ways (eg. deleting elements without deleting
|
||||
# the whole record from the db)
|
||||
matches = Crop.approved.where("name ILIKE ?", "%#{query}%").to_a
|
||||
|
||||
# we want to make sure that exact matches come first, even if not
|
||||
# using elasticsearch (eg. in development)
|
||||
exact_match = Crop.approved.find_by(name: query)
|
||||
if exact_match
|
||||
matches.delete(exact_match)
|
||||
matches.unshift(exact_match)
|
||||
end
|
||||
|
||||
matches
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,58 +0,0 @@
|
||||
class PlantingPredictions
|
||||
def initialize(planting)
|
||||
@planting = planting
|
||||
end
|
||||
|
||||
def days_until_finished
|
||||
return 0 if @planting.finished?
|
||||
days = (@planting.finished_at - Date.current).to_i
|
||||
days.positive? ? days : 0
|
||||
end
|
||||
|
||||
def days_until_mature
|
||||
days = ((@planting.planted_at + @planting.days_before_maturity) - Date.current).to_i
|
||||
days.positive? ? days : 0
|
||||
end
|
||||
|
||||
def percentage_grown
|
||||
return nil unless @planting.days_before_maturity && @planting.planted?
|
||||
|
||||
days = (Date.current - @planting.planted_at.to_date).to_f
|
||||
|
||||
return 0 if Date.current < @planting.planted_at
|
||||
return 100 if days > @planting.days_before_maturity
|
||||
percent = (days / @planting.days_before_maturity * 100).to_i
|
||||
|
||||
percent = 100 if percent >= 100
|
||||
|
||||
percent
|
||||
end
|
||||
|
||||
def start_to_finish_diff
|
||||
(@planting.finished_at - @planting.planted_at).to_i if @planting.finished_at && @planting.planted_at
|
||||
end
|
||||
|
||||
def predict_days_before_maturity
|
||||
# calculate the number of days, from planted_at, until maturity
|
||||
if @planting.planted_at && @planting.finished_at
|
||||
start_to_finish_diff
|
||||
elsif @planting.crop_id
|
||||
plantings = other_finished_plantings_same_crop
|
||||
PlantingPredictions.mean_days_until_maturity(plantings)
|
||||
end
|
||||
end
|
||||
|
||||
def self.mean_days_until_maturity(plantings)
|
||||
## Given a set of finished plantings, calculate the average/mean time from start to finish
|
||||
differences = plantings.collect(&:start_to_finish_diff)
|
||||
differences.compact.sum / differences.compact.size unless differences.compact.empty?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def other_finished_plantings_same_crop
|
||||
Planting.where(crop_id: @planting.crop_id)
|
||||
.where.not(id: @planting.id)
|
||||
.where.not(finished_at: nil)
|
||||
end
|
||||
end
|
||||
@@ -29,6 +29,16 @@
|
||||
Wranglers: please ensure this is singular, and capitalize
|
||||
proper nouns only.
|
||||
|
||||
.form-group
|
||||
= f.label :perennial, 'Lifespan', class: 'control-label col-md-2'
|
||||
.col-md-8
|
||||
= f.radio_button(:perennial, false)
|
||||
= f.label(:perennial_false, "Annual")
|
||||
%span.help-block Living and reproducing in a single year or less
|
||||
= f.radio_button(:perennial, true)
|
||||
= f.label(:perennial_true, "Perennial")
|
||||
%span.help-block Living more than two years
|
||||
|
||||
.form-group
|
||||
= f.label :en_wikipedia_url, 'Wikipedia URL', class: 'control-label col-md-2'
|
||||
.col-md-8
|
||||
|
||||
@@ -12,11 +12,23 @@
|
||||
%p
|
||||
%b Scientific name:
|
||||
= crop.default_scientific_name
|
||||
%p
|
||||
%b
|
||||
Planted
|
||||
= pluralize(crop.plantings.size, "time")
|
||||
by #{ENV['GROWSTUFF_SITE_NAME']} members
|
||||
|
||||
- if crop.annual? && crop.median_lifespan.present?
|
||||
%p
|
||||
Median Lifespan
|
||||
%b= crop.median_lifespan
|
||||
days
|
||||
- unless crop.median_days_to_first_harvest.nil?
|
||||
%p
|
||||
First harvest expected
|
||||
%b= crop.median_days_to_first_harvest
|
||||
days after planting
|
||||
|
||||
- if crop.annual? && crop.median_days_to_last_harvest.present?
|
||||
%p
|
||||
Last harvest expected
|
||||
%b= crop.median_days_to_last_harvest
|
||||
days after planting
|
||||
|
||||
- if can? :create, Planting
|
||||
= link_to 'Plant this', new_planting_path(params: { crop_id: crop.id }), class: 'btn btn-primary'
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
%h2 Photos of #{crop.name} harvests
|
||||
.row
|
||||
- unless crop.harvest_photos.empty?
|
||||
- crop.harvest_photos.includes(:owner).first(3).each do |p|
|
||||
.col-md-4
|
||||
- unless crop.harvest_photos.empty?
|
||||
%h3 Photos of #{crop.name} harvests
|
||||
.row
|
||||
- crop.harvest_photos.first(6).each do |p|
|
||||
.col-xs-6.col-md-2
|
||||
= render "photos/thumbnail", photo: p
|
||||
|
||||
%h2 Photos of #{crop.name} plants
|
||||
.row
|
||||
- unless crop.photos.empty?
|
||||
- crop.photos.includes(:owner).first(3).each do |p|
|
||||
.col-md-4
|
||||
- unless crop.photos.empty?
|
||||
%h3 Photos of #{crop.name} plants
|
||||
.row
|
||||
- crop.photos.first(6).each do |p|
|
||||
.col-xs-6.col-md-2
|
||||
= render "photos/thumbnail", photo: p
|
||||
.row
|
||||
= link_to "more photos", crop_photos_path(crop_id: crop.id)
|
||||
|
||||
29
app/views/crops/_predictions.html.haml
Normal file
29
app/views/crops/_predictions.html.haml
Normal file
@@ -0,0 +1,29 @@
|
||||
- unless crop.perennial.nil?
|
||||
%p
|
||||
#{crop.name} is
|
||||
- if crop.perennial == true
|
||||
= link_to 'https://en.wikipedia.org/wiki/Annual_vs._perennial_plant_evolution' do
|
||||
a perennial crop
|
||||
(living more than two years)
|
||||
- elsif crop.perennial == false
|
||||
= link_to 'https://en.wikipedia.org/wiki/Annual_vs._perennial_plant_evolution' do
|
||||
an annual crop
|
||||
(living and reproducing in a single year or less)
|
||||
|
||||
- if crop.annual? && crop.median_lifespan.present?
|
||||
%p
|
||||
Median lifespan of #{crop.name} plants is
|
||||
%strong= crop.median_lifespan
|
||||
days
|
||||
|
||||
- if crop.median_days_to_first_harvest.present?
|
||||
%p
|
||||
First harvest expected
|
||||
%strong= crop.median_days_to_first_harvest
|
||||
days after planting
|
||||
|
||||
- if crop.annual? && crop.median_days_to_last_harvest.present?
|
||||
%p
|
||||
Last harvest expected
|
||||
%strong= crop.median_days_to_last_harvest
|
||||
days after planting
|
||||
@@ -20,19 +20,17 @@
|
||||
|
||||
- if can? :create, Seed
|
||||
= link_to 'Add seeds to stash', new_seed_path(params: { crop_id: @crop.id }), class: 'btn btn-default'
|
||||
- if member_signed_in?
|
||||
= display_seed_availability(@current_member, @crop)
|
||||
= link_to "View your seeds", seeds_by_owner_path(owner: current_member.slug)
|
||||
|
||||
.row
|
||||
.col-md-9
|
||||
- unless current_member
|
||||
Learn how to grow #{@crop.name.pluralize} from growers around the world.
|
||||
#{ENV['GROWSTUFF_SITE_NAME']} has tips and advice from real-life growers,
|
||||
including when to plant #{@crop.name.pluralize}, how to harvest
|
||||
#{@crop.name.pluralize}, and more.
|
||||
- if member_signed_in?
|
||||
= display_seed_availability(@current_member, @crop)
|
||||
= link_to "View your seeds", seeds_by_owner_path(owner: current_member.slug)
|
||||
|
||||
= render partial: 'photos', locals: { crop: @crop }
|
||||
%h2 Predictions
|
||||
= render 'predictions', crop: @crop
|
||||
|
||||
%p= render 'crops/photos', crop: @crop
|
||||
|
||||
%h2
|
||||
- if !@crop.plantings.empty?
|
||||
@@ -86,18 +84,18 @@
|
||||
|
||||
%h4 How to grow #{@crop.name.pluralize}
|
||||
|
||||
= render partial: 'grown_for', locals: { crop: @crop }
|
||||
= render partial: 'planting_advice', locals: { crop: @crop }
|
||||
= render 'grown_for', crop: @crop
|
||||
= render 'planting_advice', crop: @crop
|
||||
|
||||
= render partial: 'scientific_names', locals: { crop: @crop }
|
||||
= render partial: 'alternate_names', locals: { crop: @crop }
|
||||
= render 'scientific_names', crop: @crop
|
||||
= render 'alternate_names', crop: @crop
|
||||
|
||||
%h4 #{@crop.name.capitalize} varieties
|
||||
= render partial: 'varieties', locals: { crop: @crop }
|
||||
= render 'varieties', crop: @crop
|
||||
|
||||
= render partial: 'plantings', locals: { crop: @crop }
|
||||
= render partial: 'harvests', locals: { crop: @crop }
|
||||
= render partial: 'find_seeds', locals: { crop: @crop }
|
||||
= render 'plantings', crop: @crop
|
||||
= render 'harvests', crop: @crop
|
||||
= render 'find_seeds', crop: @crop
|
||||
|
||||
|
||||
%h4 Learn more about #{@crop.name.pluralize}
|
||||
|
||||
@@ -21,3 +21,8 @@
|
||||
class: 'btn btn-default', id: 'delete_garden_link' do
|
||||
%span.glyphicon.glyphicon-trash{ title: "Delete" }
|
||||
Delete
|
||||
- if can?(:edit, garden) && can?(:create, Photo)
|
||||
= link_to new_photo_path(type: "garden", id: garden.id),
|
||||
class: 'btn btn-primary' do
|
||||
%span.glyphicon.glyphicon-camera{ title: "Add Photo" }
|
||||
Add Photo
|
||||
|
||||
@@ -91,8 +91,8 @@
|
||||
%p
|
||||
= link_to new_photo_path(type: "garden", id: @garden.id),
|
||||
class: 'btn btn-primary' do
|
||||
%span.glyphicon.glyphicon-camera{ title: "Add Photo" }
|
||||
Add Photo
|
||||
%span.glyphicon.glyphicon-camera{ title: "Add photo" }
|
||||
Add photo
|
||||
- if @garden.photos.size.positive?
|
||||
%h3= localize_plural(@garden.photos, Photo)
|
||||
.row
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
- content_for :title, "New Photo"
|
||||
|
||||
%h3
|
||||
Choose photo for
|
||||
= @item
|
||||
|
||||
- if @flickr_auth
|
||||
%p
|
||||
Connected to Flickr as
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,27 @@
|
||||
- if can?(:edit, planting) || can?(:destroy, planting)
|
||||
- if can? :edit, planting
|
||||
= link_to edit_planting_path(planting), class: 'btn btn-default btn-xs' do
|
||||
%span.glyphicon.glyphicon-pencil{ title: "Edit garden" }
|
||||
%span.glyphicon.glyphicon-pencil{ title: "Edit" }
|
||||
Edit
|
||||
- if can? :destroy, planting
|
||||
= link_to planting, method: :delete,
|
||||
data: { confirm: 'Are you sure?' },
|
||||
class: 'btn btn-default btn-xs' do
|
||||
data: { confirm: 'Are you sure?' }, class: 'btn btn-default btn-xs' do
|
||||
%span.glyphicon.glyphicon-trash{ title: "Delete" }
|
||||
Delete
|
||||
|
||||
- unless planting.finished
|
||||
= link_to "Mark as finished", planting_path(planting, planting: { finished: 1 }),
|
||||
method: :put, class: 'btn btn-default btn-xs append-date'
|
||||
- if can? :create, Harvest
|
||||
= link_to 'Harvest', new_planting_harvest_path(planting), class: 'btn btn-default btn-xs'
|
||||
= link_to planting_path(planting, planting: { finished: 1 }),
|
||||
method: :put, class: 'btn btn-default btn-xs append-date' do
|
||||
|
||||
%span.glyphicon.glyphicon-ok{ title: "Finished" }
|
||||
Mark as finished
|
||||
|
||||
- if can?(:create, Harvest)
|
||||
= link_to new_planting_harvest_path(planting), class: 'btn btn-default btn-xs' do
|
||||
%span.glyphicon.glyphicon-leaf{ title: "Harvest" }
|
||||
Harvest
|
||||
|
||||
- if can?(:edit, planting) && can?(:create, Photo)
|
||||
= link_to new_photo_path(id: planting.id, type: 'planting'), class: 'btn btn-default btn-xs' do
|
||||
%span.glyphicon.glyphicon-camera{ title: "Add photo" }
|
||||
Add photo
|
||||
|
||||
@@ -33,10 +33,8 @@
|
||||
%dt Planted from:
|
||||
%dd= display_planted_from(planting)
|
||||
|
||||
%dt Mature in:
|
||||
%dd
|
||||
= display_days_before_maturity(planting)
|
||||
days
|
||||
%dt Finish expected:
|
||||
%dd= planting.finish_predicted_at if planting.finish_predicted_at.present?
|
||||
|
||||
%p= render 'plantings/progress', planting: planting, show_explanation: true
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
- unless planting.harvests.empty?
|
||||
Harvests:
|
||||
%ul
|
||||
- planting.harvests.each do |harvest|
|
||||
- planting.harvests.includes(:crop).each do |harvest|
|
||||
%li
|
||||
= harvest.harvested_at ? harvest.harvested_at : "undated"
|
||||
= link_to harvest, harvest_path(harvest)
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
- if !planting.planted?
|
||||
- if planting.crop.perennial
|
||||
%p Perennial
|
||||
- elsif !planting.planted?
|
||||
- if show_explanation == true
|
||||
Progress: 0% - not planted yet
|
||||
= render "plantings/progress_bar", status: "not planted", progress: 0
|
||||
|
||||
- elsif planting.finished?
|
||||
- if show_explanation == true
|
||||
Progress: 100%
|
||||
= render "plantings/progress_bar", status: 'finished', progress: 100
|
||||
|
||||
- elsif planting.days_before_maturity.nil?
|
||||
- elsif planting.finish_predicted_at.nil?
|
||||
- if show_explanation == true
|
||||
Progress: Not calculated, days before maturity unknown
|
||||
Progress: Not enough data
|
||||
= render "plantings/progress_bar", status: "unknown", progress: nil
|
||||
|
||||
- else
|
||||
- if show_explanation == true
|
||||
Progress: #{planting.percentage_grown}%
|
||||
= render "plantings/progress_bar", status: 'growing', progress: planting.percentage_grown
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
-# haml-lint:disable InlineStyles
|
||||
%div{ class: "progress-bar progress-bar-#{status}", role: "progressbar", style: "width: #{progress}%" }
|
||||
- if progress >= 30
|
||||
#{progress}%
|
||||
#{sprintf '%.0f', progress}%
|
||||
- if progress < 30
|
||||
#{progress}%
|
||||
#{sprintf '%.0f', progress}%
|
||||
-# haml-lint:enable InlineStyles
|
||||
|
||||
@@ -28,13 +28,11 @@
|
||||
- unless @planting.owner.location.blank?
|
||||
(#{@planting.owner.location})
|
||||
%dt Quantity:
|
||||
%dd
|
||||
= display_planting_quantity(@planting)
|
||||
%dd= display_planting_quantity(@planting)
|
||||
|
||||
- unless @planting.planted_from.blank?
|
||||
%dt Planted from:
|
||||
%dd
|
||||
= display_planted_from(@planting)
|
||||
%dd= display_planted_from(@planting)
|
||||
|
||||
%dt Sun or shade?
|
||||
%dd
|
||||
@@ -42,11 +40,28 @@
|
||||
= image_tag("sunniness_#{sunniness}.png", size: "25x25", alt: sunniness, title: sunniness)
|
||||
= sunniness
|
||||
|
||||
%dt Days until maturity:
|
||||
%dd= display_days_before_maturity(@planting)
|
||||
- unless @planting.crop.perennial
|
||||
%dt Predicted finish:
|
||||
%dd
|
||||
- if @planting.finish_predicted_at.present?
|
||||
= @planting.finish_predicted_at
|
||||
- else
|
||||
%strong Set planted date to get predictions
|
||||
%dt Finished:
|
||||
%dd= display_finished(@planting)
|
||||
|
||||
%dt Finished:
|
||||
%dd= display_finished(@planting)
|
||||
- if @planting.crop.median_lifespan.present?
|
||||
%dt Expected Lifespan:
|
||||
%dd #{@planting.crop.median_lifespan} days
|
||||
- if @planting.lifespan.present?
|
||||
%dt Actual Lifespan:
|
||||
%dd #{@planting.lifespan} days
|
||||
- if @planting.days_to_first_harvest.present?
|
||||
%dt First Harvest:
|
||||
%dd #{@planting.days_to_first_harvest} days after planting
|
||||
- if @planting.days_to_last_harvest.present?
|
||||
%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
|
||||
@@ -67,10 +82,10 @@
|
||||
#{ @planting.description != "" ? strip_tags(@planting.description) : "No description given." }
|
||||
|
||||
- if !@planting.photos.empty? || (can?(:edit, @planting) && can?(:create, Photo))
|
||||
%h2 Pictures
|
||||
%h2 Photos
|
||||
|
||||
.row
|
||||
- @planting.photos.each do |p|
|
||||
- @planting.photos.includes(:owner).each do |p|
|
||||
.col-md-2.six-across
|
||||
= render partial: 'photos/thumbnail', locals: { photo: p }
|
||||
- if can?(:create, Photo) && can?(:edit, @planting)
|
||||
|
||||
6
config/initializers/jsonapi_resources.rb
Normal file
6
config/initializers/jsonapi_resources.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
JSONAPI.configure do |config|
|
||||
# built in paginators are :none, :offset, :paged
|
||||
config.default_paginator = :offset
|
||||
config.default_page_size = 10
|
||||
config.maximum_page_size = 20
|
||||
end
|
||||
@@ -96,8 +96,19 @@ Growstuff::Application.routes.draw do
|
||||
get '/admin/newsletter' => 'admin#newsletter', :as => :admin_newsletter
|
||||
get '/admin/:action' => 'admin#:action'
|
||||
|
||||
get '/.well-known/acme-challenge/:id' => 'pages#letsencrypt'
|
||||
namespace :api do
|
||||
namespace :v1 do
|
||||
jsonapi_resources :photos
|
||||
jsonapi_resources :crops
|
||||
jsonapi_resources :plantings
|
||||
jsonapi_resources :gardens
|
||||
jsonapi_resources :harvests
|
||||
jsonapi_resources :seeds
|
||||
jsonapi_resources :members
|
||||
end
|
||||
end
|
||||
|
||||
get '/.well-known/acme-challenge/:id' => 'pages#letsencrypt'
|
||||
# CMS stuff -- must remain LAST
|
||||
comfy_route :cms, path: '/', sitemap: false
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ worker_processes 3
|
||||
timeout 30
|
||||
preload_app true
|
||||
|
||||
before_fork do |server, worker|
|
||||
before_fork do |_server, _worker|
|
||||
Signal.trap 'TERM' do
|
||||
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
|
||||
Process.kill 'QUIT', Process.pid
|
||||
@@ -13,7 +13,7 @@ before_fork do |server, worker|
|
||||
ActiveRecord::Base.connection.disconnect!
|
||||
end
|
||||
|
||||
after_fork do |server, worker|
|
||||
after_fork do |_server, _worker|
|
||||
Signal.trap 'TERM' do
|
||||
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT'
|
||||
end
|
||||
|
||||
22
db/migrate/20171022032108_all_the_predictions.rb
Normal file
22
db/migrate/20171022032108_all_the_predictions.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
class AllThePredictions < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :crops, :perennial, :boolean, default: false
|
||||
|
||||
# time from planted, to finished
|
||||
add_column :plantings, :lifespan, :integer
|
||||
|
||||
# how old was planting at first harvest
|
||||
add_column :plantings, :days_to_first_harvest, :integer
|
||||
add_column :plantings, :days_to_last_harvest, :integer
|
||||
|
||||
# Keep the median values for the crop
|
||||
add_column :crops, :median_lifespan, :integer
|
||||
add_column :crops, :median_days_to_first_harvest, :integer
|
||||
add_column :crops, :median_days_to_last_harvest, :integer
|
||||
|
||||
remove_column :plantings, :days_before_maturity, :integer
|
||||
|
||||
create_table :median_functions do |t|
|
||||
end
|
||||
end
|
||||
end
|
||||
9
db/migrate/20171028230429_create_median_function.rb
Normal file
9
db/migrate/20171028230429_create_median_function.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class CreateMedianFunction < ActiveRecord::Migration
|
||||
def up
|
||||
ActiveMedian.create_function
|
||||
end
|
||||
|
||||
def down
|
||||
ActiveMedian.drop_function
|
||||
end
|
||||
end
|
||||
13
db/migrate/20171105011017_set_prediction_data.rb
Normal file
13
db/migrate/20171105011017_set_prediction_data.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class SetPredictionData < ActiveRecord::Migration
|
||||
def up
|
||||
say "Updating all plantings time to first harvest"
|
||||
Planting.all.each(&:update_harvest_days)
|
||||
say "Updating crop median time to first harvest, and lifespan"
|
||||
Crop.all.each do |crop|
|
||||
crop.update_lifespan_medians
|
||||
crop.update_harvest_medians
|
||||
end
|
||||
end
|
||||
|
||||
def down; end
|
||||
end
|
||||
25
db/schema.rb
25
db/schema.rb
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170520060252) do
|
||||
ActiveRecord::Schema.define(version: 20171105011017) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -181,19 +181,23 @@ ActiveRecord::Schema.define(version: 20170520060252) do
|
||||
end
|
||||
|
||||
create_table "crops", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "name", null: false
|
||||
t.string "en_wikipedia_url"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "slug"
|
||||
t.integer "parent_id"
|
||||
t.integer "plantings_count", default: 0
|
||||
t.integer "plantings_count", default: 0
|
||||
t.integer "creator_id"
|
||||
t.integer "requester_id"
|
||||
t.string "approval_status", default: "approved"
|
||||
t.string "approval_status", default: "approved"
|
||||
t.text "reason_for_rejection"
|
||||
t.text "request_notes"
|
||||
t.text "rejection_notes"
|
||||
t.boolean "perennial", default: false
|
||||
t.integer "median_lifespan"
|
||||
t.integer "median_days_to_first_harvest"
|
||||
t.integer "median_days_to_last_harvest"
|
||||
end
|
||||
|
||||
add_index "crops", ["name"], name: "index_crops_on_name", using: :btree
|
||||
@@ -290,6 +294,9 @@ ActiveRecord::Schema.define(version: 20170520060252) do
|
||||
add_index "likes", ["likeable_type", "likeable_id"], name: "index_likes_on_likeable_type_and_likeable_id", using: :btree
|
||||
add_index "likes", ["member_id"], name: "index_likes_on_member_id", using: :btree
|
||||
|
||||
create_table "median_functions", force: :cascade do |t|
|
||||
end
|
||||
|
||||
create_table "members", force: :cascade do |t|
|
||||
t.string "email", default: "", null: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
@@ -409,8 +416,8 @@ ActiveRecord::Schema.define(version: 20170520060252) do
|
||||
end
|
||||
|
||||
create_table "plantings", force: :cascade do |t|
|
||||
t.integer "garden_id", null: false
|
||||
t.integer "crop_id", null: false
|
||||
t.integer "garden_id", null: false
|
||||
t.integer "crop_id", null: false
|
||||
t.date "planted_at"
|
||||
t.integer "quantity"
|
||||
t.text "description"
|
||||
@@ -420,9 +427,11 @@ ActiveRecord::Schema.define(version: 20170520060252) do
|
||||
t.string "sunniness"
|
||||
t.string "planted_from"
|
||||
t.integer "owner_id"
|
||||
t.boolean "finished", default: false
|
||||
t.boolean "finished", default: false
|
||||
t.date "finished_at"
|
||||
t.integer "days_before_maturity"
|
||||
t.integer "lifespan"
|
||||
t.integer "days_to_first_harvest"
|
||||
t.integer "days_to_last_harvest"
|
||||
end
|
||||
|
||||
add_index "plantings", ["slug"], name: "index_plantings_on_slug", unique: true, using: :btree
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,22 +1,30 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
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
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe AccountsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::OrdersController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe AdminController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe AuthenticationsController do
|
||||
|
||||
@@ -1,22 +1,11 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
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
|
||||
@@ -25,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
|
||||
|
||||
@@ -60,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
|
||||
|
||||
@@ -77,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
|
||||
@@ -90,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)
|
||||
@@ -102,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
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe CropsController do
|
||||
@@ -23,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
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ForumsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe GardensController, type: :controller do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe HarvestsController do
|
||||
@@ -19,68 +7,67 @@ describe HarvestsController do
|
||||
{
|
||||
owner_id: subject.current_member.id,
|
||||
crop_id: FactoryBot.create(:crop).id,
|
||||
plant_part_id: FactoryBot.create(:plant_part).id
|
||||
plant_part_id: FactoryBot.create(:plant_part).id,
|
||||
harvested_at: '2017-01-01'
|
||||
}
|
||||
end
|
||||
|
||||
describe "GET index" do
|
||||
before do
|
||||
@member1 = FactoryBot.create(:member)
|
||||
@member2 = FactoryBot.create(:member)
|
||||
@tomato = FactoryBot.create(:tomato)
|
||||
@maize = FactoryBot.create(:maize)
|
||||
@harvest1 = FactoryBot.create(:harvest, owner_id: @member1.id, crop_id: @tomato.id)
|
||||
@harvest2 = FactoryBot.create(:harvest, owner_id: @member2.id, crop_id: @maize.id)
|
||||
let(:member1) { FactoryBot.create(:member) }
|
||||
let(:member2) { FactoryBot.create(:member) }
|
||||
let(:tomato) { FactoryBot.create(:tomato) }
|
||||
let(:maize) { FactoryBot.create(:maize) }
|
||||
let(:harvest1) { FactoryBot.create(:harvest, owner_id: member1.id, crop_id: tomato.id) }
|
||||
let(:harvest2) { FactoryBot.create(:harvest, owner_id: member2.id, crop_id: maize.id) }
|
||||
|
||||
describe "assigns all harvests as @harvests" do
|
||||
before { get :index, {} }
|
||||
it { assigns(:harvests).should =~ [harvest1, harvest2] }
|
||||
end
|
||||
|
||||
it "assigns all harvests as @harvests" do
|
||||
get :index, {}
|
||||
assigns(:harvests).should =~ [@harvest1, @harvest2]
|
||||
describe "picks up owner from params and shows owner's harvests only" do
|
||||
before { get :index, owner: member1.slug }
|
||||
it { expect(assigns(:owner)).to eq member1 }
|
||||
it { expect(assigns(:harvests)).to eq [harvest1] }
|
||||
end
|
||||
|
||||
it "picks up owner from params and shows owner's harvests only" do
|
||||
get :index, owner: @member1.slug
|
||||
assigns(:owner).should eq @member1
|
||||
assigns(:harvests).should eq [@harvest1]
|
||||
describe "picks up crop from params and shows the harvests for the crop only" do
|
||||
before { get :index, crop: maize.name }
|
||||
it { expect(assigns(:crop)).to eq maize }
|
||||
it { expect(assigns(:harvests)).to eq [harvest2] }
|
||||
end
|
||||
|
||||
it "picks up crop from params and shows the harvests for the crop only" do
|
||||
get :index, crop: @maize.name
|
||||
assigns(:crop).should eq @maize
|
||||
assigns(:harvests).should eq [@harvest2]
|
||||
end
|
||||
|
||||
it "generates a csv" do
|
||||
get :index, format: "csv"
|
||||
response.status.should eq 200
|
||||
describe "generates a csv" do
|
||||
before { get :index, format: "csv" }
|
||||
it { expect(response.status).to eq 200 }
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET show" do
|
||||
it "assigns the requested harvest as @harvest" do
|
||||
harvest = Harvest.create! valid_attributes
|
||||
get :show, id: harvest.to_param
|
||||
assigns(:harvest).should eq(harvest)
|
||||
let(:harvest) { Harvest.create! valid_attributes }
|
||||
describe "assigns the requested harvest as @harvest" do
|
||||
before { get :show, id: harvest.to_param }
|
||||
it { expect(assigns(:harvest)).to eq(harvest) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET new" do
|
||||
it "assigns a new harvest as @harvest" do
|
||||
get :new, {}
|
||||
assigns(:harvest).should be_a_new(Harvest)
|
||||
before { get :new, {} }
|
||||
|
||||
describe "assigns a new harvest as @harvest" do
|
||||
it { expect(assigns(:harvest)).to be_a_new(Harvest) }
|
||||
end
|
||||
|
||||
it "sets the date of the harvest to today" do
|
||||
get :new, {}
|
||||
assigns(:harvest).harvested_at.should == Time.zone.today
|
||||
describe "sets the date of the harvest to today" do
|
||||
it { expect(assigns(:harvest).harvested_at).to eq(Time.zone.today) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET edit" do
|
||||
it "assigns the requested harvest as @harvest" do
|
||||
harvest = Harvest.create! valid_attributes
|
||||
get :edit, id: harvest.to_param
|
||||
assigns(:harvest).should eq(harvest)
|
||||
let(:harvest) { Harvest.create! valid_attributes }
|
||||
describe "assigns the requested harvest as @harvest" do
|
||||
before { get :edit, id: harvest.to_param }
|
||||
it { expect(assigns(:harvest)).to eq(harvest) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -103,10 +90,10 @@ describe HarvestsController do
|
||||
response.should redirect_to(Harvest.last)
|
||||
end
|
||||
|
||||
it "links to planting" do
|
||||
planting = FactoryBot.create(:planting, owner_id: member.id)
|
||||
post :create, harvest: valid_attributes.merge(planting_id: planting.id)
|
||||
expect(Harvest.last.planting.id).to eq(planting.id)
|
||||
describe "links to planting" do
|
||||
let(:planting) { FactoryBot.create(:planting, owner_id: member.id, garden: member.gardens.first) }
|
||||
before { post :create, harvest: valid_attributes.merge(planting_id: planting.id) }
|
||||
it { expect(Harvest.last.planting.id).to eq(planting.id) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -128,10 +115,13 @@ describe HarvestsController do
|
||||
describe "not my planting" do
|
||||
let(:not_my_planting) { FactoryBot.create(:planting) }
|
||||
let(:harvest) { FactoryBot.create(:harvest) }
|
||||
it "does not save planting_id" do
|
||||
allow(Harvest).to receive(:new).and_return(harvest)
|
||||
post :create, harvest: valid_attributes.merge(planting_id: not_my_planting.id)
|
||||
expect(harvest.planting_id).to eq(nil)
|
||||
|
||||
describe "does not save planting_id" do
|
||||
before do
|
||||
allow(Harvest).to receive(:new).and_return(harvest)
|
||||
post :create, harvest: valid_attributes.merge(planting_id: not_my_planting.id)
|
||||
end
|
||||
it { expect(harvest.planting_id).not_to eq(not_my_planting.id) }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -180,10 +170,12 @@ describe HarvestsController do
|
||||
describe "not my planting" do
|
||||
let(:not_my_planting) { FactoryBot.create(:planting) }
|
||||
let(:harvest) { FactoryBot.create(:harvest) }
|
||||
it "does not save planting_id" do
|
||||
put :update, id: harvest.to_param,
|
||||
harvest: valid_attributes.merge(planting_id: not_my_planting.id)
|
||||
expect(harvest.planting_id).to eq(nil)
|
||||
describe "does not save planting_id" do
|
||||
before do
|
||||
put :update, id: harvest.to_param,
|
||||
harvest: valid_attributes.merge(planting_id: not_my_planting.id)
|
||||
end
|
||||
it { expect(harvest.planting_id).to eq(nil) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe HomeController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe MembersController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe NotificationsController do
|
||||
|
||||
@@ -1,67 +1,50 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
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
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe OrdersController do
|
||||
|
||||
@@ -1,15 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
@@ -34,45 +23,38 @@ describe PhotosController do
|
||||
end
|
||||
|
||||
describe "GET new" do
|
||||
let(:tomato) { FactoryBot.create(:tomato) }
|
||||
let(:planting) { FactoryBot.create(:planting, crop: tomato, owner: member) }
|
||||
let(:garden) { FactoryBot.create(:garden, owner: member) }
|
||||
let(:harvest) { FactoryBot.create(:harvest, owner: member) }
|
||||
let(:member) { FactoryBot.create(:member) }
|
||||
let!(:auth) { FactoryBot.create(:flickr_authentication, member: member) }
|
||||
|
||||
before(:each) do
|
||||
@member = FactoryBot.create(:member)
|
||||
sign_in @member
|
||||
@member.stub(:flickr_photos) { [[], 0] }
|
||||
@member.stub(:flickr_sets) { { "foo" => "bar" } }
|
||||
controller.stub(:current_member) { @member }
|
||||
sign_in member
|
||||
member.stub(:flickr_photos) { [[], 0] }
|
||||
member.stub(:flickr_sets) { { "foo" => "bar" } }
|
||||
controller.stub(:current_member) { member }
|
||||
end
|
||||
|
||||
it "assigns the flickr auth as @flickr_auth" do
|
||||
@auth = FactoryBot.create(:flickr_authentication, member: @member)
|
||||
get :new, {}
|
||||
assigns(:flickr_auth).should be_an_instance_of(Authentication)
|
||||
describe "planting photos" do
|
||||
before(:each) { get :new, type: "planting", id: planting.id }
|
||||
it { assigns(:flickr_auth).should be_an_instance_of(Authentication) }
|
||||
it { assigns(:item).should eq planting }
|
||||
it { expect(flash[:alert]).not_to be_present }
|
||||
it { expect(flash[:alert]).not_to be_present }
|
||||
end
|
||||
|
||||
it "assigns a planting id" do
|
||||
get :new, type: "planting", id: 5
|
||||
assigns(:id).should eq "5"
|
||||
assigns(:type).should eq "planting"
|
||||
expect(flash[:alert]).not_to be_present
|
||||
describe "harvest photos" do
|
||||
before { get :new, type: "harvest", id: harvest.id }
|
||||
it { assigns(:item).should eq harvest }
|
||||
it { expect(flash[:alert]).not_to be_present }
|
||||
end
|
||||
|
||||
it "assigns a harvest id" do
|
||||
get :new, type: "harvest", id: 5
|
||||
assigns(:id).should eq "5"
|
||||
assigns(:type).should eq "harvest"
|
||||
expect(flash[:alert]).not_to be_present
|
||||
end
|
||||
|
||||
it "assigns a garden id" do
|
||||
get :new, type: "garden", id: 5
|
||||
assigns(:id).should eq "5"
|
||||
assigns(:type).should eq "garden"
|
||||
expect(flash[:alert]).not_to be_present
|
||||
end
|
||||
|
||||
it "assigns the current set as @current_set" do
|
||||
get :new, set: 'foo'
|
||||
assigns(:current_set).should eq "foo"
|
||||
expect(flash[:alert]).not_to be_present
|
||||
describe "garden photos" do
|
||||
before { get :new, type: "garden", id: garden.id }
|
||||
it { assigns(:item).should eq garden }
|
||||
it { expect(flash[:alert]).not_to be_present }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -99,11 +81,13 @@ describe PhotosController do
|
||||
Photo.last.plantings.first.should eq planting
|
||||
end
|
||||
|
||||
it "doesn't attach a photo to a planting twice" do
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "planting", id: planting.id
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "planting", id: planting.id
|
||||
expect(flash[:alert]).not_to be_present
|
||||
Photo.last.plantings.size.should eq 1
|
||||
describe "doesn't attach a photo to a planting twice" do
|
||||
before do
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "planting", id: planting.id
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "planting", id: planting.id
|
||||
end
|
||||
it { expect(flash[:alert]).not_to be_present }
|
||||
it { expect(Photo.last.plantings.size).to eq 1 }
|
||||
end
|
||||
|
||||
it "attaches the photo to a harvest" do
|
||||
@@ -121,18 +105,20 @@ describe PhotosController do
|
||||
|
||||
it "doesn't attach photo to a comment" do
|
||||
comment = FactoryBot.create(:comment)
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "comment", id: comment.id
|
||||
expect(flash[:alert]).to be_present
|
||||
expect do
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "comment", id: comment.id
|
||||
end.to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe "for the second time" do
|
||||
let(:planting) { FactoryBot.create :planting, owner: member }
|
||||
it "does not add a photo twice" do
|
||||
expect do
|
||||
post :create, photo: { flickr_photo_id: 1 }
|
||||
post :create, photo: { flickr_photo_id: 1 }, id: planting.id, type: 'planting'
|
||||
end.to change(Photo, :count).by(1)
|
||||
expect do
|
||||
post :create, photo: { flickr_photo_id: 1 }
|
||||
post :create, photo: { flickr_photo_id: 1 }, id: planting.id, type: 'planting'
|
||||
end.to change(Photo, :count).by(0)
|
||||
end
|
||||
end
|
||||
@@ -159,16 +145,18 @@ describe PhotosController do
|
||||
it "does not create the planting/photo link" do
|
||||
# members will be auto-created, and different
|
||||
another_planting = FactoryBot.create(:planting)
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "planting", id: another_planting.id
|
||||
expect(flash[:alert]).to be_present
|
||||
expect do
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "planting", id: another_planting.id
|
||||
end.to raise_error(ActiveRecord::RecordNotFound)
|
||||
Photo.last.plantings.first.should_not eq another_planting
|
||||
end
|
||||
|
||||
it "does not create the harvest/photo link" do
|
||||
# members will be auto-created, and different
|
||||
another_harvest = FactoryBot.create(:harvest)
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "harvest", id: another_harvest.id
|
||||
expect(flash[:alert]).to be_present
|
||||
expect do
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "harvest", id: another_harvest.id
|
||||
end.to raise_error(ActiveRecord::RecordNotFound)
|
||||
Photo.last.harvests.first.should_not eq another_harvest
|
||||
end
|
||||
end
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user