From e35b15c8682ebb9d37e00128a3c05044164eeb70 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 21:02:54 +1030 Subject: [PATCH 01/34] Only render an edit control if the permission exists --- app/views/scientific_names/show.html.haml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/scientific_names/show.html.haml b/app/views/scientific_names/show.html.haml index 1c0a76357..dffbdffc3 100644 --- a/app/views/scientific_names/show.html.haml +++ b/app/views/scientific_names/show.html.haml @@ -9,6 +9,8 @@ %b Crop: = link_to @scientific_name.crop, @scientific_name.crop -= link_to 'Edit', edit_scientific_name_path(@scientific_name), :class => 'btn btn-default btn-xs' -\| + +- if can? :edit, @scientific_name + = link_to 'Edit', edit_scientific_name_path(@scientific_name), :class => 'btn btn-default btn-xs' + \| = link_to 'Back', scientific_names_path From 9fa72fa5f7979d43dcc256996dfbbace7bf726d2 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 21:02:02 +1030 Subject: [PATCH 02/34] Only render a pipe if there are multiple options like edit rights available --- app/views/alternate_names/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/alternate_names/show.html.haml b/app/views/alternate_names/show.html.haml index 06012457b..fc2b7b335 100644 --- a/app/views/alternate_names/show.html.haml +++ b/app/views/alternate_names/show.html.haml @@ -11,5 +11,5 @@ - if can? :edit, @alternate_name = link_to 'Edit', edit_alternate_name_path(@alternate_name), :class => 'btn btn-default btn-xs' -\| + \| = link_to 'Back', alternate_names_path From 32af1b28a80d0a63622b0a808ac0ebd748142089 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 22:03:59 +1030 Subject: [PATCH 03/34] Update the expectations: an edit link is visible to crop wranglers (which used to be an expectation about the id appearing in a link) --- spec/views/scientific_names/show.html.haml_spec.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/views/scientific_names/show.html.haml_spec.rb b/spec/views/scientific_names/show.html.haml_spec.rb index c16fbe444..d3db043e8 100644 --- a/spec/views/scientific_names/show.html.haml_spec.rb +++ b/spec/views/scientific_names/show.html.haml_spec.rb @@ -28,6 +28,18 @@ describe "scientific_names/show" do render # Run the generator again with the --webrat flag if you want to use webrat matchers rendered.should match(/Zea mays/) - rendered.should match(@scientific_name.id.to_s) + end + + context 'signed in' do + + before :each do + @wrangler = FactoryGirl.create(:crop_wrangling_member) + sign_in @wrangler + render + end + + it 'should have an edit button' do + rendered.should have_content 'Edit' + end end end From bfffaab77fc0c2f3c47ca94e2b9d551d86ce33ba Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 22:26:36 +1030 Subject: [PATCH 04/34] Have to stub the controller load_and_authorize_resource behaviour, as these tests aren't run in that context. --- spec/views/scientific_names/show.html.haml_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/views/scientific_names/show.html.haml_spec.rb b/spec/views/scientific_names/show.html.haml_spec.rb index d3db043e8..a36646658 100644 --- a/spec/views/scientific_names/show.html.haml_spec.rb +++ b/spec/views/scientific_names/show.html.haml_spec.rb @@ -35,6 +35,7 @@ describe "scientific_names/show" do before :each do @wrangler = FactoryGirl.create(:crop_wrangling_member) sign_in @wrangler + controller.stub(:current_user) { @wrangler } render end From f23cb78dcbf5a72340f09bd09e0d8384e7d0309b Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 22:59:44 +1030 Subject: [PATCH 05/34] #840 Eager load photos, which are used in the .interesting? call; so we don't have to do a photos.size call on every single crop. --- app/models/crop.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index 2000ebfbb..fe593fe37 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -207,7 +207,7 @@ class Crop < ActiveRecord::Base def Crop.interesting howmany = 12 # max number to find interesting_crops = Array.new - Crop.randomized.each do |c| + Crop.includes(:photos).randomized.each do |c| break if interesting_crops.size == howmany next unless c.interesting? interesting_crops.push(c) From b57cb581dd900f1a4ece59bfb0dba326740dd5f4 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 23:05:56 +1030 Subject: [PATCH 06/34] #840 Eager load photos --- app/models/planting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/planting.rb b/app/models/planting.rb index 900156b2a..14e9017cb 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -116,7 +116,7 @@ class Planting < ActiveRecord::Base interesting_plantings = Array.new seen_owners = Hash.new(false) # keep track of which owners we've seen already - Planting.all.each do |p| + Planting.includes(:photos).each do |p| break if interesting_plantings.size == howmany # got enough yet? if require_photo next unless p.photos.present? # skip those without photos, if required From 049886459a482372121a1ee072a38458c49bf872 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 23:13:31 +1030 Subject: [PATCH 07/34] Name: nokogiri Version: 1.6.5 Advisory: CVE-2015-1819 Criticality: Unknown URL: https://github.com/sparklemotion/nokogiri/issues/1374 Title: Nokogiri gem contains several vulnerabilities in libxml2 and libxslt Solution: upgrade to ~> 1.6.6.4, >= 1.6.7.rc4 Name: nokogiri Version: 1.6.5 Advisory: CVE-2015-7499 Criticality: Medium URL: https://groups.google.com/forum/#!topic/ruby-security-ann/Dy7YiKb_pMM Title: Nokogiri gem contains a heap-based buffer overflow vulnerability in libxml2 Solution: upgrade to >= 1.6.7.2 Name: nokogiri Version: 1.6.5 Advisory: CVE-2015-5312 Criticality: High URL: https://groups.google.com/forum/#!topic/ruby-security-ann/aSbgDiwb24s Title: Nokogiri gem contains several vulnerabilities in libxml2 Solution: upgrade to >= 1.6.7.1 --- Gemfile.lock | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8a6ac680d..a0193fad7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -271,7 +271,7 @@ GEM method_source (0.8.2) mime-types (2.6.1) mimemagic (0.3.0) - mini_portile (0.6.1) + mini_portile2 (2.0.0) minitest (5.8.0) multi_json (1.11.2) multi_xml (0.5.5) @@ -279,8 +279,8 @@ GEM nenv (0.2.0) netrc (0.10.3) newrelic_rpm (3.9.8.273) - nokogiri (1.6.5) - mini_portile (~> 0.6.0) + nokogiri (1.6.7.2) + mini_portile2 (~> 2.0.0.rc2) notiffany (0.0.6) nenv (~> 0.1) shellany (~> 0.0) @@ -520,3 +520,6 @@ DEPENDENCIES unicorn webrat will_paginate (~> 3.0) + +BUNDLED WITH + 1.11.2 From a76d2a3eb039070a5725659f6d886de819283cb8 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 23:16:21 +1030 Subject: [PATCH 08/34] Name: devise Version: 3.4.1 Advisory: CVE-2015-8314 Criticality: Unknown URL: http://blog.plataformatec.com.br/2016/01/improve-remember-me-cookie-expiration-in-devise/ Title: Devise Gem for Ruby Unauthorized Access Using Remember Me Cookie Solution: upgrade to >= 3.5.4 --- Gemfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a0193fad7..5821aba4d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -53,7 +53,7 @@ GEM autoprefixer-rails (5.1.1) execjs json - bcrypt (3.1.9) + bcrypt (3.1.11) better_errors (2.0.0) coderay (>= 1.0.0) erubis (>= 2.6.6) @@ -272,7 +272,7 @@ GEM mime-types (2.6.1) mimemagic (0.3.0) mini_portile2 (2.0.0) - minitest (5.8.0) + minitest (5.8.4) multi_json (1.11.2) multi_xml (0.5.5) multipart-post (2.0.0) @@ -344,7 +344,7 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) raindrops (0.13.0) - rake (10.4.2) + rake (11.1.2) rb-fsevent (0.9.5) rb-inotify (0.9.5) ffi (>= 0.5.0) @@ -434,7 +434,7 @@ GEM kgio (~> 2.6) rack raindrops (~> 0.7) - warden (1.2.3) + warden (1.2.6) rack (>= 1.0) webrat (0.7.3) nokogiri (>= 1.2.0) From a10f6e4783d9a9c6d75c35490b5a6a641f2bf33b Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 23:17:55 +1030 Subject: [PATCH 09/34] Name: actionpack Version: 4.1.11 Advisory: CVE-2015-7581 Criticality: Unknown URL: https://groups.google.com/forum/#!topic/rubyonrails-security/dthJ5wL69JE Title: Object leak vulnerability for wildcard controller routes in Action Pack Solution: upgrade to >= 4.2.5.1, ~> 4.2.5, >= 4.1.14.1, ~> 4.1.14 Name: actionpack Version: 4.1.11 Advisory: CVE-2016-0751 Criticality: Unknown URL: https://groups.google.com/forum/#!topic/rubyonrails-security/9oLY_FCzvoc Title: Possible Object Leak and Denial of Service attack in Action Pack Solution: upgrade to ~> 5.0.0.beta1.1, >= 4.2.5.1, ~> 4.2.5, >= 4.1.14.1, ~> 4.1.14, ~> 3.2.22.1 Name: actionpack Version: 4.1.11 Advisory: CVE-2015-7576 Criticality: Unknown URL: https://groups.google.com/forum/#!topic/rubyonrails-security/ANv0HDHEC3k Title: Timing attack vulnerability in basic authentication in Action Controller. Solution: upgrade to ~> 5.0.0.beta1.1, >= 4.2.5.1, ~> 4.2.5, >= 4.1.14.1, ~> 4.1.14, ~> 3.2.22.1 Name: actionpack Version: 4.1.11 Advisory: CVE-2016-2098 Criticality: Unknown URL: https://groups.google.com/forum/#!topic/rubyonrails-security/ly-IH-fxr_Q Title: Possible remote code execution vulnerability in Action Pack Solution: upgrade to ~> 3.2.22.2, >= 4.2.5.2, ~> 4.2.5, >= 4.1.14.2, ~> 4.1.14 Name: actionview Version: 4.1.11 Advisory: CVE-2016-2097 Criticality: Unknown URL: https://groups.google.com/forum/#!topic/rubyonrails-security/ddY6HgqB2z4 Title: Possible Information Leak Vulnerability in Action View Solution: upgrade to ~> 3.2.22.2, >= 4.1.14.2, ~> 4.1.14 Name: actionview Version: 4.1.11 Advisory: CVE-2016-0752 Criticality: Unknown URL: https://groups.google.com/forum/#!topic/rubyonrails-security/335P1DcLG00 Title: Possible Information Leak Vulnerability in Action View Solution: upgrade to ~> 5.0.0.beta1.1, >= 4.2.5.1, ~> 4.2.5, >= 4.1.14.1, ~> 4.1.14, ~> 3.2.22.1 Name: activemodel Version: 4.1.11 Advisory: CVE-2016-0753 Criticality: Unknown URL: https://groups.google.com/forum/#!topic/rubyonrails-security/6jQVC1geukQ Title: Possible Input Validation Circumvention in Active Model Solution: upgrade to ~> 5.0.0.beta1.1, >= 4.2.5.1, ~> 4.2.5, >= 4.1.14.1, ~> 4.1.14 Name: activerecord Version: 4.1.11 Advisory: CVE-2015-7577 Criticality: Unknown URL: https://groups.google.com/forum/#!topic/rubyonrails-security/cawsWcQ6c8g Title: Nested attributes rejection proc bypass in Active Record Solution: upgrade to ~> 5.0.0.beta1.1, >= 4.2.5.1, ~> 4.2.5, >= 4.1.14.1, ~> 4.1.14, ~> 3.2.22.1 --- Gemfile.lock | 60 ++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5821aba4d..33e1e89bd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,29 +20,29 @@ PATH GEM remote: https://rubygems.org/ specs: - actionmailer (4.1.11) - actionpack (= 4.1.11) - actionview (= 4.1.11) + actionmailer (4.1.15) + actionpack (= 4.1.15) + actionview (= 4.1.15) mail (~> 2.5, >= 2.5.4) - actionpack (4.1.11) - actionview (= 4.1.11) - activesupport (= 4.1.11) + actionpack (4.1.15) + actionview (= 4.1.15) + activesupport (= 4.1.15) rack (~> 1.5.2) rack-test (~> 0.6.2) - actionview (4.1.11) - activesupport (= 4.1.11) + actionview (4.1.15) + activesupport (= 4.1.15) builder (~> 3.1) erubis (~> 2.7.0) active_link_to (1.0.2) actionpack - activemodel (4.1.11) - activesupport (= 4.1.11) + activemodel (4.1.15) + activesupport (= 4.1.15) builder (~> 3.1) - activerecord (4.1.11) - activemodel (= 4.1.11) - activesupport (= 4.1.11) + activerecord (4.1.15) + activemodel (= 4.1.15) + activesupport (= 4.1.15) arel (~> 5.0.0) - activesupport (4.1.11) + activesupport (4.1.15) i18n (~> 0.6, >= 0.6.9) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) @@ -265,11 +265,11 @@ GEM rb-fsevent (>= 0.9.3) rb-inotify (>= 0.9) lumberjack (1.0.9) - mail (2.6.3) - mime-types (>= 1.16, < 3) + mail (2.6.4) + mime-types (>= 1.16, < 4) memcachier (0.0.2) method_source (0.8.2) - mime-types (2.6.1) + mime-types (2.99.1) mimemagic (0.3.0) mini_portile2 (2.0.0) minitest (5.8.4) @@ -320,15 +320,15 @@ GEM rack (1.5.5) rack-test (0.6.3) rack (>= 1.0) - rails (4.1.11) - actionmailer (= 4.1.11) - actionpack (= 4.1.11) - actionview (= 4.1.11) - activemodel (= 4.1.11) - activerecord (= 4.1.11) - activesupport (= 4.1.11) + rails (4.1.15) + actionmailer (= 4.1.15) + actionpack (= 4.1.15) + actionview (= 4.1.15) + activemodel (= 4.1.15) + activerecord (= 4.1.15) + activesupport (= 4.1.15) bundler (>= 1.3.0, < 2.0) - railties (= 4.1.11) + railties (= 4.1.15) sprockets-rails (~> 2.0) rails-i18n (4.0.3) i18n (~> 0.6) @@ -338,9 +338,9 @@ GEM rails_stdout_logging rails_serve_static_assets (0.0.2) rails_stdout_logging (0.0.3) - railties (4.1.11) - actionpack (= 4.1.11) - activesupport (= 4.1.11) + railties (4.1.15) + actionpack (= 4.1.15) + activesupport (= 4.1.15) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) raindrops (0.13.0) @@ -407,7 +407,7 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.3.2) + sprockets-rails (2.3.3) actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) @@ -507,7 +507,7 @@ DEPENDENCIES poltergeist (~> 1.6) pry quiet_assets - rails (= 4.1.11) + rails (~> 4.1.11) rails_12factor rake (>= 10.0.0) rspec-activemodel-mocks From c1fde41f1fe5fff7193322f2bab1c3c0a552a4a3 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 23:23:56 +1030 Subject: [PATCH 10/34] Name: devise Version: 3.4.1 Advisory: CVE-2015-8314 Criticality: Unknown URL: http://blog.plataformatec.com.br/2016/01/improve-remember-me-cookie-expiration-in-devise/ Title: Devise Gem for Ruby Unauthorized Access Using Remember Me Cookie Solution: upgrade to >= 3.5.4 --- Gemfile | 4 ++-- Gemfile.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 4108dc32f..8b382daa7 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' ruby '2.1.7' -gem 'rails', '4.1.11' +gem 'rails', '~> 4.1.11' gem 'bundler', '>=1.1.5' @@ -61,7 +61,7 @@ gem 'bluecloth' gem 'will_paginate', '~> 3.0' # user signup/login/etc -gem 'devise', '~> 3.4.1' +gem 'devise', '~> 3.5.0' # nicely formatted URLs gem 'friendly_id', '~> 5.0.4' diff --git a/Gemfile.lock b/Gemfile.lock index 33e1e89bd..b7069318c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -132,7 +132,7 @@ GEM database_cleaner (1.5.0) debug_inspector (0.0.2) debugger-linecache (1.2.0) - devise (3.4.1) + devise (3.5.6) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 3.2.6, < 5) @@ -471,7 +471,7 @@ DEPENDENCIES csv_shaper dalli database_cleaner (~> 1.5.0) - devise (~> 3.4.1) + devise (~> 3.5.0) elasticsearch-model elasticsearch-rails factory_girl_rails (~> 4.5.0) From 03ae327e306202b5c26fba0b6fcf8eca1fe09e49 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 23:27:15 +1030 Subject: [PATCH 11/34] Name: uglifier Version: 2.5.3 Advisory: 126747 Criticality: Unknown URL: https://github.com/mishoo/UglifyJS2/issues/751 Title: uglifier incorrectly handles non-boolean comparisons during minification Solution: upgrade to >= 2.7.2 --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b7069318c..d17579c88 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -162,7 +162,7 @@ GEM multi_json erubis (2.7.0) excon (0.43.0) - execjs (2.2.2) + execjs (2.6.0) factory_girl (4.5.0) activesupport (>= 3.0.0) factory_girl_rails (4.5.0) @@ -424,7 +424,7 @@ GEM tins (1.3.3) tzinfo (1.2.2) thread_safe (~> 0.1) - uglifier (2.5.3) + uglifier (2.7.2) execjs (>= 0.3.0) json (>= 1.8.0) unf (0.1.4) @@ -516,7 +516,7 @@ DEPENDENCIES sass-rails (~> 4.0.4) selenium-webdriver therubyracer (~> 0.12) - uglifier (~> 2.5.3) + uglifier (~> 2.7.2) unicorn webrat will_paginate (~> 3.0) From 4e7e82c8a8aecb4fd4c3d5ee32a8da02b68fb9a1 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 23:39:05 +1030 Subject: [PATCH 12/34] Fix CVE-2015-7551 (https://www.ruby-lang.org/en/news/2015/12/16/unsafe-tainted-string-usage-in-fiddle-and-dl-cve-2015-7551/) --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 04b10b4f1..ebf14b469 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.1.7 +2.1.8 From 3748f954c52314266bb5b9aaa072e3d989f5b529 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 23:54:29 +1030 Subject: [PATCH 13/34] Name: uglifier Version: 2.5.3 Advisory: 126747 Criticality: Unknown URL: https://github.com/mishoo/UglifyJS2/issues/751 Title: uglifier incorrectly handles non-boolean comparisons during minification Solution: upgrade to >= 2.7.2 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 8b382daa7..f2f722b19 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,7 @@ gem 'less-rails', '~> 2.5.0' # CSS framework gem 'less-rails-bootstrap', '~> 3.2.0' -gem 'uglifier', '~> 2.5.3' # JavaScript compressor +gem 'uglifier', '~> 2.7.2' # JavaScript compressor gem 'jquery-rails' gem 'jquery-ui-rails', '~> 5.0.2' From df952a1779a99a9d8bdf7f10cf9162f4a9a964ec Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Tue, 29 Mar 2016 00:00:07 +1030 Subject: [PATCH 14/34] Bump rspec to fix https://github.com/rspec/rspec-rails/issues/1532 --- Gemfile | 2 +- Gemfile.lock | 41 +++++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index f2f722b19..46874457f 100644 --- a/Gemfile +++ b/Gemfile @@ -113,7 +113,7 @@ end group :development, :test do gem 'haml-rails' # HTML templating language - gem 'rspec-rails', '~> 3.1.0' # unit testing framework + gem 'rspec-rails', '~> 3.4.0' # unit testing framework gem 'rspec-activemodel-mocks' gem 'byebug' # debugging gem 'database_cleaner', '~> 1.5.0' diff --git a/Gemfile.lock b/Gemfile.lock index d17579c88..6143e8f3c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -355,30 +355,31 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 3.0) netrc (~> 0.7) - rspec (3.1.0) - rspec-core (~> 3.1.0) - rspec-expectations (~> 3.1.0) - rspec-mocks (~> 3.1.0) + rspec (3.4.0) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) rspec-activemodel-mocks (1.0.1) activemodel (>= 3.0) activesupport (>= 3.0) rspec-mocks (>= 2.99, < 4.0) - rspec-core (3.1.7) - rspec-support (~> 3.1.0) - rspec-expectations (3.1.2) + rspec-core (3.4.4) + rspec-support (~> 3.4.0) + rspec-expectations (3.4.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.1.0) - rspec-mocks (3.1.3) - rspec-support (~> 3.1.0) - rspec-rails (3.1.0) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.1.0) - rspec-expectations (~> 3.1.0) - rspec-mocks (~> 3.1.0) - rspec-support (~> 3.1.0) - rspec-support (3.1.2) + rspec-support (~> 3.4.0) + rspec-mocks (3.4.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-rails (3.4.2) + actionpack (>= 3.0, < 4.3) + activesupport (>= 3.0, < 4.3) + railties (>= 3.0, < 4.3) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-support (~> 3.4.0) + rspec-support (3.4.1) ruby-units (1.4.5) ruby_parser (3.1.3) sexp_processor (~> 4.1) @@ -511,7 +512,7 @@ DEPENDENCIES rails_12factor rake (>= 10.0.0) rspec-activemodel-mocks - rspec-rails (~> 3.1.0) + rspec-rails (~> 3.4.0) ruby-units sass-rails (~> 4.0.4) selenium-webdriver From d9f04d1fa9b870bb755a155e8aa72f3fb6820b51 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 3 Apr 2016 00:02:15 +1030 Subject: [PATCH 15/34] Fixes #853 --- app/views/harvests/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/harvests/_form.html.haml b/app/views/harvests/_form.html.haml index 0b61ae03e..67dbda1e0 100644 --- a/app/views/harvests/_form.html.haml +++ b/app/views/harvests/_form.html.haml @@ -13,7 +13,7 @@ .col-md-4 = auto_suggest @harvest, :crop, :class => 'form-control col-md-2', :default => @crop .col-md-4 - = collection_select(:harvest, :plant_part_id, PlantPart.all, :id, :name, { :selected => @harvest.plant_part_id, :include_blank => 'e.g. fruit' }, { :class => 'form-control' }) + = collection_select(:harvest, :plant_part_id, PlantPart.all, :id, :name, { :selected => @harvest.plant_part_id }, { :class => 'form-control', :prompt => 'e.g. fruit', :required => "required" }) %span.help-block.col-md-8 Can't find what you're looking for? = link_to "Request new crops.", new_crop_path From 99a3be08eb0473062f172c66f0762ad50615cdcc Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 3 Apr 2016 00:05:55 +1030 Subject: [PATCH 16/34] Fixes #853 --- app/models/harvest.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/harvest.rb b/app/models/harvest.rb index 4339a30fa..7bbd2b6ee 100644 --- a/app/models/harvest.rb +++ b/app/models/harvest.rb @@ -24,6 +24,8 @@ class Harvest < ActiveRecord::Base 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, From de8bcc38d367c697a8c4755691f51708ff8cab03 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 3 Apr 2016 00:13:38 +1030 Subject: [PATCH 17/34] #857 Add length validations to models --- app/models/garden.rb | 6 +++++- app/models/notification.rb | 2 ++ app/models/post.rb | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/garden.rb b/app/models/garden.rb index 0514f2a96..15bbaa9de 100644 --- a/app/models/garden.rb +++ b/app/models/garden.rb @@ -28,10 +28,14 @@ class Garden < ActiveRecord::Base scope :active, -> { where(:active => true) } scope :inactive, -> { where(:active => false) } + validates :location, + :length => { :maximum => 255 } + validates :name, :format => { :with => /\S/ - } + }, + :length => { :maximum => 255 } validates :area, :numericality => { diff --git a/app/models/notification.rb b/app/models/notification.rb index 3825d7b12..01f157df9 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -3,6 +3,8 @@ class Notification < ActiveRecord::Base belongs_to :recipient, :class_name => 'Member' belongs_to :post + validates :subject, :length => { :maximum => 255 } + default_scope { order('created_at DESC') } scope :unread, -> { where(:read => false) } diff --git a/app/models/post.rb b/app/models/post.rb index 3a1b372af..6aaf8b72d 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -41,7 +41,9 @@ class Post < ActiveRecord::Base validates :subject, :format => { :with => /\S/ - } + }, + :length => { :maximum => 255 } + def author_date_subject # slugs are created before created_at is set From a9330f2d77a4c9634fd6ea38006036e8ffc0ce13 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 3 Apr 2016 00:15:45 +1030 Subject: [PATCH 18/34] #857 Add length validations to UI --- app/views/gardens/_form.html.haml | 4 ++-- app/views/notifications/_form.html.haml | 2 +- app/views/posts/_form.html.haml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/gardens/_form.html.haml b/app/views/gardens/_form.html.haml index 09c3b99ef..74b33249d 100644 --- a/app/views/gardens/_form.html.haml +++ b/app/views/gardens/_form.html.haml @@ -11,7 +11,7 @@ .form-group.required = f.label :name, :class => 'control-label col-md-2' .col-md-8 - = f.text_field :name, :class => 'form-control' + = f.text_field :name, :class => 'form-control', :maxlength => 255, :required => "required" .form-group = f.label :description, :class => 'control-label col-md-2' @@ -21,7 +21,7 @@ .form-group = f.label :location, :class => 'control-label col-md-2' .col-md-8 - = f.text_field :location, :value => @garden.location || current_member.location, :class => 'form-control', :placeholder => 'optional' + = f.text_field :location, :value => @garden.location || current_member.location, :class => 'form-control', :placeholder => 'optional', :maxlength => 255 %span.help-block If you have a location set in your profile, it will be used when you create a new garden. diff --git a/app/views/notifications/_form.html.haml b/app/views/notifications/_form.html.haml index 6e73c7444..094be410d 100644 --- a/app/views/notifications/_form.html.haml +++ b/app/views/notifications/_form.html.haml @@ -13,7 +13,7 @@ To: = link_to @recipient, @recipient = label_tag :notification, "Subject:" - = f.text_field :subject, :value => @subject, :class => 'form-control' + = f.text_field :subject, :value => @subject, :class => 'form-control', :maxlength => 255 = label_tag :body, "Type your message here:" = f.text_area :body, :rows => 12, :class => 'form-control' %span.help-block diff --git a/app/views/posts/_form.html.haml b/app/views/posts/_form.html.haml index 1ef7efb51..607b76bd8 100644 --- a/app/views/posts/_form.html.haml +++ b/app/views/posts/_form.html.haml @@ -8,7 +8,7 @@ .form-group = label_tag :post, "Subject", :class => 'control-label' - = f.text_field :subject, :class => 'form-control', :autofocus => 'autofocus' + = f.text_field :subject, :class => 'form-control', :autofocus => 'autofocus', :maxlength => 255 .form-group - if @post.forum || @forum From a800630b0101753caf1002619c1a770a15e6a5e1 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Thu, 7 Apr 2016 09:43:45 +0930 Subject: [PATCH 19/34] Ensure we choose a plant part --- spec/features/harvests/harvesting_a_crop_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/features/harvests/harvesting_a_crop_spec.rb b/spec/features/harvests/harvesting_a_crop_spec.rb index 802f67a4d..6316b7d70 100644 --- a/spec/features/harvests/harvesting_a_crop_spec.rb +++ b/spec/features/harvests/harvesting_a_crop_spec.rb @@ -26,7 +26,9 @@ feature "Harvesting a crop", :js do scenario "Creating a new harvest", :js do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" + within "form#new_harvest" do + select "whole plant", from: '#harvest_plant_part_id' fill_in "When?", with: "2014-06-15" fill_in "How many?", with: 42 fill_in "Weighing (in total):", with: 42 From aa2a761a58469ad9dc4edbb2a0be6818401b6da7 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Thu, 7 Apr 2016 09:46:29 +0930 Subject: [PATCH 20/34] Ensure we choose a plant part --- spec/features/harvests/harvesting_a_crop_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/features/harvests/harvesting_a_crop_spec.rb b/spec/features/harvests/harvesting_a_crop_spec.rb index 6316b7d70..94ea55390 100644 --- a/spec/features/harvests/harvesting_a_crop_spec.rb +++ b/spec/features/harvests/harvesting_a_crop_spec.rb @@ -63,6 +63,7 @@ feature "Harvesting a crop", :js do visit crop_path(maize) click_link "Harvest this" within "form#new_harvest" do + select "whole plant", from: '#harvest_plant_part_id' expect(page).to have_selector "input[value='maize']" click_button "Save" end From c3a883de16c8b5a4de17903df2ac1134737ee071 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Thu, 7 Apr 2016 09:47:53 +0930 Subject: [PATCH 21/34] Ensure we choose a plant part --- spec/controllers/harvests_controller_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/controllers/harvests_controller_spec.rb b/spec/controllers/harvests_controller_spec.rb index f8f87042a..b1e6312cd 100644 --- a/spec/controllers/harvests_controller_spec.rb +++ b/spec/controllers/harvests_controller_spec.rb @@ -23,7 +23,8 @@ describe HarvestsController do def valid_attributes { :owner_id => subject.current_member.id, - :crop_id => FactoryGirl.create(:crop).id + :crop_id => FactoryGirl.create(:crop).id, + :plant_part_id => FactoryGirl.create(:plant_part).id } end From a7f9e113d6d64450d763c130eb13e84fd972bf47 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Thu, 7 Apr 2016 09:59:06 +0930 Subject: [PATCH 22/34] Target the name attribute --- spec/features/harvests/harvesting_a_crop_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/harvests/harvesting_a_crop_spec.rb b/spec/features/harvests/harvesting_a_crop_spec.rb index 94ea55390..7ea134ad4 100644 --- a/spec/features/harvests/harvesting_a_crop_spec.rb +++ b/spec/features/harvests/harvesting_a_crop_spec.rb @@ -28,7 +28,7 @@ feature "Harvesting a crop", :js do select_from_autocomplete "maize" within "form#new_harvest" do - select "whole plant", from: '#harvest_plant_part_id' + select "whole plant", from: 'harvest[plant_part_id]' fill_in "When?", with: "2014-06-15" fill_in "How many?", with: 42 fill_in "Weighing (in total):", with: 42 @@ -63,7 +63,7 @@ feature "Harvesting a crop", :js do visit crop_path(maize) click_link "Harvest this" within "form#new_harvest" do - select "whole plant", from: '#harvest_plant_part_id' + select "whole plant", from: 'harvest[plant_part_id]' expect(page).to have_selector "input[value='maize']" click_button "Save" end From da588b7fdb79f95b8c5a282b7f330480b59a49e0 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Thu, 7 Apr 2016 10:08:21 +0930 Subject: [PATCH 23/34] Create the plant part instead of assuming it's seeded --- spec/features/harvests/harvesting_a_crop_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/features/harvests/harvesting_a_crop_spec.rb b/spec/features/harvests/harvesting_a_crop_spec.rb index 7ea134ad4..100bcc98f 100644 --- a/spec/features/harvests/harvesting_a_crop_spec.rb +++ b/spec/features/harvests/harvesting_a_crop_spec.rb @@ -3,6 +3,7 @@ require 'rails_helper' feature "Harvesting a crop", :js do let(:member) { create :member } let!(:maize) { create :maize } + let!(:plant_part) { create :plant_part } background do login_as member @@ -28,7 +29,7 @@ feature "Harvesting a crop", :js do select_from_autocomplete "maize" within "form#new_harvest" do - select "whole plant", from: 'harvest[plant_part_id]' + select plant_part.name, from: 'harvest[plant_part_id]' fill_in "When?", with: "2014-06-15" fill_in "How many?", with: 42 fill_in "Weighing (in total):", with: 42 @@ -63,7 +64,7 @@ feature "Harvesting a crop", :js do visit crop_path(maize) click_link "Harvest this" within "form#new_harvest" do - select "whole plant", from: 'harvest[plant_part_id]' + select plant_part.name, from: 'harvest[plant_part_id]' expect(page).to have_selector "input[value='maize']" click_button "Save" end From a3ad9189b19682024333ba842f3058858fc645b9 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Thu, 7 Apr 2016 10:41:35 +0930 Subject: [PATCH 24/34] Fix WARNING: Using the `raise_error` matcher without providing a specific error or message risks false positives, since `raise_error` will match when Ruby raises a `NoMethodError`, `NameError` or `ArgumentError`, potentially allowing the expectation to pass without even executing the method you are intending to call. Actual error raised was #. Instead consider providing a specific error class or message. This message can be supressed by setting: `RSpec::Expectations.configuration.warn_about_potential_false_positives = false`. Called from /home/travis/build/Growstuff/growstuff/spec/controllers/member_controller_spec.rb:65:in `block (3 levels) in '. --- spec/controllers/member_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/controllers/member_controller_spec.rb b/spec/controllers/member_controller_spec.rb index 55231ead8..4bd1f6826 100644 --- a/spec/controllers/member_controller_spec.rb +++ b/spec/controllers/member_controller_spec.rb @@ -62,12 +62,12 @@ describe MembersController do end it "doesn't show completely nonsense members" do - lambda { get :show, {:id => 9999} }.should raise_error + lambda { get :show, {:id => 9999} }.should raise_error(ActiveRecord::RecordNotFound) end it "doesn't show unconfirmed members" do @member2 = FactoryGirl.create(:unconfirmed_member) - lambda { get :show, {:id => @member2.id} }.should raise_error + lambda { get :show, {:id => @member2.id} }.should raise_error(ActiveRecord::RecordNotFound) end end From e8d7ed0c2d36d335af990bd10492527a2b6f0b8f Mon Sep 17 00:00:00 2001 From: hcbviolet Date: Fri, 8 Apr 2016 17:34:58 -0700 Subject: [PATCH 25/34] Edit display_harvest_description method for no description --- app/helpers/harvests_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/harvests_helper.rb b/app/helpers/harvests_helper.rb index b4c5bead4..16371b4e9 100644 --- a/app/helpers/harvests_helper.rb +++ b/app/helpers/harvests_helper.rb @@ -38,8 +38,8 @@ module HarvestsHelper end def display_harvest_description(harvest) - if harvest.description.nil? - "no description provided." + if harvest.description.empty? + "No description provided." else truncate(harvest.description, length: 130, separator: ' ', omission: '... ') { link_to "Read more", harvest_path(harvest) } end From 7bb7a18b66ee0886af0764956b4469ae14d6c0f7 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sat, 9 Apr 2016 21:45:13 +0930 Subject: [PATCH 26/34] Fixes #850 Refactors percentage grown to model, stops rendering progress bars in situations it doesn't make sense. Adds specs. --- app/models/planting.rb | 20 +++++++++ .../plantings/_planting_progress.html.haml | 12 ++---- app/views/plantings/_thumbnail.html.haml | 2 +- spec/models/planting_spec.rb | 42 +++++++++++++++++++ 4 files changed, 67 insertions(+), 9 deletions(-) diff --git a/app/models/planting.rb b/app/models/planting.rb index 900156b2a..2e9e22149 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -109,6 +109,26 @@ class Planting < ActiveRecord::Base end end + def planted?(current_date = DateTime.now) + planted_at.present? && current_date.to_date >= planted_at + end + + def percentage_grown(current_date = DateTime.now) + return nil unless days_before_maturity && planted?(current_date) + + return 0 if current_date < planted_at + return 100 if days > days_before_maturity + + days = current_date - planted_at + percent = (days/days_before_maturity*100).to_i + + if percent >= 100 + percent = 100 + end + + percent + end + # return a list of interesting plantings, for the homepage etc. # we can't do this via a scope (as far as we know) so sadly we have to # do it this way. diff --git a/app/views/plantings/_planting_progress.html.haml b/app/views/plantings/_planting_progress.html.haml index eea698c82..57cdaeaf6 100644 --- a/app/views/plantings/_planting_progress.html.haml +++ b/app/views/plantings/_planting_progress.html.haml @@ -1,14 +1,10 @@ -- if (planting.planted_at.nil? || DateTime.now.to_date < planting.planted_at) +- unless planting.planted? = "Progress: 0% - not planted yet" - = render partial: "plantings/progress_bar", locals: {status: "warning", progress: "100%"} - elsif planting.finished? = "Progress: 100%" = render partial: "plantings/progress_bar", locals: {status: "success", progress: "100%"} - elsif planting.days_before_maturity.nil? - = "Progress: 0% - Days before maturity unknown" - = render partial: "plantings/progress_bar", locals: {status: "danger", progress: "100%"} + = "Progress: Not calculated, days before maturity unknown" - else - - if (percent = (((DateTime.now - planting.planted_at)/planting.days_before_maturity*100).to_i)) >= 100 - - percent = 100 - = "Progress: #{percent}%" - = render partial: "plantings/progress_bar", locals: {status: "success", progress: "#{percent}%"} \ No newline at end of file + = "Progress: #{planting.percentage_grown}%" + = render partial: "plantings/progress_bar", locals: {status: "success", progress: "#{planting.percentage_grown}%"} \ No newline at end of file diff --git a/app/views/plantings/_thumbnail.html.haml b/app/views/plantings/_thumbnail.html.haml index 9790cb127..fbc859963 100644 --- a/app/views/plantings/_thumbnail.html.haml +++ b/app/views/plantings/_thumbnail.html.haml @@ -38,4 +38,4 @@ %dd= "#{display_days_before_maturity(planting)}" .col-xs-9.col-md-8 - = render partial: 'plantings/planting_progress', locals: {:planting => planting} \ No newline at end of file + = render partial: 'plantings/planting_progress', locals: {planting: planting} \ No newline at end of file diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 659636c5e..1575c9320 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -37,6 +37,48 @@ describe Planting do Planting.first.should eq @planting2 end + describe '#planted?' do + it "should be false for future plantings" + it "should be false for never planted" + it "should be false for future plantings" + end + + describe '#percentage_grown' do + it 'should not be more than 100%' do + @planting = FactoryGirl.build(:planting, days_before_maturity: 1, planted_at: 1.day.ago) + + now_later_than_planting = 2.days.from_now + + @planting.percentage_grown(now_later_than_planting).should be 100 + end + + it 'should not be less than 0%' do + @planting = FactoryGirl.build(:planting, days_before_maturity: 1, planted_at: 1.day.ago) + + now_earlier_than_planting = 2.days.ago + + @planting.percentage_grown(now_earlier_than_planting).should be 0 + end + + it 'should reflect the current growth' do + @planting = FactoryGirl.build(:planting, days_before_maturity: 10, planted_at: 4.days.ago) + + @planting.percentage_grown.should be 40 + end + + it 'should not be calculated for unplanted plantings' do + @planting = FactoryGirl.build(:planting, planted_at: nil) + + @planting.planted?.should be false + @planting.percentage_grown.should be nil + end + it 'should not be calculated for plantings with an unknown days before maturity' do + @planting = FactoryGirl.build(:planting, days_before_maturity: nil) + + @planting.percentage_grown.should be nil + end + end + context 'delegation' do it 'system name' do planting.crop_name.should eq planting.crop.name From 69fb98146b296bdc6cec5a0070c355a1e167001d Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sat, 9 Apr 2016 22:01:05 +0930 Subject: [PATCH 27/34] Adjust logic --- app/views/plantings/_planting_progress.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/plantings/_planting_progress.html.haml b/app/views/plantings/_planting_progress.html.haml index 57cdaeaf6..7fe6d52f7 100644 --- a/app/views/plantings/_planting_progress.html.haml +++ b/app/views/plantings/_planting_progress.html.haml @@ -1,4 +1,4 @@ -- unless planting.planted? +- if !planting.planted? = "Progress: 0% - not planted yet" - elsif planting.finished? = "Progress: 100%" From 5cfa051d75e54ddfd3c56021b876d1a85784c369 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sat, 9 Apr 2016 22:43:17 +0930 Subject: [PATCH 28/34] Update expectations --- spec/features/plantings/planting_a_crop_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 753bbe457..06b4480ea 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -42,7 +42,7 @@ feature "Planting a crop", :js do end expect(page).to have_content "Planting was successfully created" - expect(page).to have_content "Progress: 0% - Days before maturity unknown" + expect(page).to have_content "Progress: Not calculated, days before maturity unknown" end scenario "Clicking link to owner's profile" do @@ -87,7 +87,7 @@ feature "Planting a crop", :js do end expect(page).to have_content "Planting was successfully created" - expect(page).to have_content "Progress: 0% - Days before maturity unknown" + expect(page).to have_content "Progress: Not calculated, days before maturity unknown" expect(page).to have_content "Days until maturity: unknown" end @@ -106,7 +106,7 @@ feature "Planting a crop", :js do expect(page).to have_content "Planting was successfully created" expect(page).to_not have_content "Progress: 0% - not planted yet" - expect(page).to_not have_content "Progress: 0% - Days before maturity unknown" + expect(page).to_not have_content "Progress: Not calculated, days before maturity unknown" end it "should show that planting is 100% complete (no date specified)" do @@ -169,13 +169,13 @@ feature "Planting a crop", :js do scenario "Editing a planting to fill in the finished date" do visit planting_path(planting) - expect(page).to have_content "Progress: 0% - Days before maturity unknown" + expect(page).to have_content "Progress: Not calculated, days before maturity unknown" click_link "Edit" check "finished" fill_in "Finished date", with: "2015-06-25" click_button "Save" expect(page).to have_content "Planting was successfully updated" - expect(page).to_not have_content "Progress: 0% - Days before maturity unknown" + expect(page).to_not have_content "Progress: Not calculated, days before maturity unknown" end scenario "Marking a planting as finished" do From 3644a8124f4ddfae4383d3dff005a327ff2a3e50 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sat, 9 Apr 2016 22:54:03 +0930 Subject: [PATCH 29/34] Tweak specs, implementation properly --- app/models/planting.rb | 8 ++++---- spec/models/planting_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/planting.rb b/app/models/planting.rb index 2e9e22149..b9566c62b 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -109,17 +109,17 @@ class Planting < ActiveRecord::Base end end - def planted?(current_date = DateTime.now) + def planted?(current_date = Date.today) planted_at.present? && current_date.to_date >= planted_at end - def percentage_grown(current_date = DateTime.now) + def percentage_grown(current_date = Date.today) return nil unless days_before_maturity && planted?(current_date) + days = (current_date.to_date - planted_at.to_date).to_i + return 0 if current_date < planted_at return 100 if days > days_before_maturity - - days = current_date - planted_at percent = (days/days_before_maturity*100).to_i if percent >= 100 diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 1575c9320..90b4da713 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -57,13 +57,13 @@ describe Planting do now_earlier_than_planting = 2.days.ago - @planting.percentage_grown(now_earlier_than_planting).should be 0 + @planting.percentage_grown(now_earlier_than_planting).should be nil end it 'should reflect the current growth' do @planting = FactoryGirl.build(:planting, days_before_maturity: 10, planted_at: 4.days.ago) - @planting.percentage_grown.should be 40 + @planting.percentage_grown(Date.today).should be 40 end it 'should not be calculated for unplanted plantings' do From 82553d6e0a42273918f5681959d1eb070e666475 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 11 Apr 2016 09:29:06 +0930 Subject: [PATCH 30/34] Avoid time travel in favour of calculating a number of past/future dates --- .../plantings/planting_a_crop_spec.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 06b4480ea..fc255d313 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -53,16 +53,19 @@ feature "Planting a crop", :js do describe "Progress bar status on planting creation" do before do - DateTime.stub(:now) { DateTime.new(2015, 10, 20, 10, 34) } login_as member visit new_planting_path + + @a_past_date = 15.days.ago.strftime("%Y-%m-%d") + @right_now = Date.today.strftime("%Y-%m-%d") + @a_future_date = 1.years.from_now.strftime("%Y-%m-%d") end it "should show that it is not planted yet" do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do - fill_in "When", with: "2015-12-15" + fill_in "When", with: @a_future_date fill_in "How many?", with: 42 select "cutting", from: "Planted from:" select "semi-shade", from: "Sun or shade?" @@ -78,7 +81,7 @@ feature "Planting a crop", :js do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do - fill_in "When", with: "2015-9-15" + fill_in "When", with: @a_past_date fill_in "How many?", with: 42 select "cutting", from: "Planted from:" select "semi-shade", from: "Sun or shade?" @@ -95,12 +98,12 @@ feature "Planting a crop", :js do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do - fill_in "When", with: "2015-10-15" + fill_in "When", with: @right_now fill_in "How many?", with: 42 select "cutting", from: "Planted from:" select "semi-shade", from: "Sun or shade?" fill_in "Tell us more about it", with: "It's rad." - fill_in "Finished date", with: "2015-10-30" + fill_in "Finished date", with: @a_future_date click_button "Save" end @@ -113,7 +116,7 @@ feature "Planting a crop", :js do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do - fill_in "When", with: "2015-10-15" + fill_in "When", with: @right_now fill_in "How many?", with: 42 select "cutting", from: "Planted from:" select "semi-shade", from: "Sun or shade?" @@ -132,12 +135,12 @@ feature "Planting a crop", :js do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do - fill_in "When", with: "2015-10-15" + fill_in "When", with: @a_past_date fill_in "How many?", with: 42 select "cutting", from: "Planted from:" select "semi-shade", from: "Sun or shade?" fill_in "Tell us more about it", with: "It's rad." - fill_in "Finished date", with: "2015-10-19" + fill_in "Finished date", with: @right_now click_button "Save" end From e3c689ba6b943164406365e0dc9f6837989a0fc9 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 11 Apr 2016 09:51:52 +0930 Subject: [PATCH 31/34] Fixes #851 Correct the link to be specific to the author --- app/views/posts/index.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/posts/index.html.haml b/app/views/posts/index.html.haml index 4a5846f55..8cc176f9a 100644 --- a/app/views/posts/index.html.haml +++ b/app/views/posts/index.html.haml @@ -30,11 +30,11 @@ - if @author Subscribe to = succeed "." do - = link_to "#{@author}'s posts RSS feed", posts_path(:format => 'rss') + = link_to "#{@author}'s posts RSS feed", posts_by_author_path(format: 'rss', author: @author) - else Subscribe to the #{ENV['GROWSTUFF_SITE_NAME']} - = link_to "posts RSS feed", posts_path(:format => 'rss') + = link_to "posts RSS feed", posts_by_author(:format => 'rss') or = succeed "." do = link_to "comments RSS feed", comments_path(:format => 'rss') From 3ff3ffa4573858bf4481c5f11532ae7e0b10b372 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 11 Apr 2016 09:55:03 +0930 Subject: [PATCH 32/34] Don't update that link, geesh. Need more coffee! --- app/views/posts/index.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/posts/index.html.haml b/app/views/posts/index.html.haml index 8cc176f9a..9eee54694 100644 --- a/app/views/posts/index.html.haml +++ b/app/views/posts/index.html.haml @@ -34,7 +34,7 @@ - else Subscribe to the #{ENV['GROWSTUFF_SITE_NAME']} - = link_to "posts RSS feed", posts_by_author(:format => 'rss') + = link_to "posts RSS feed", posts_path(:format => 'rss') or = succeed "." do = link_to "comments RSS feed", comments_path(:format => 'rss') From 12ad16a05a5bf6ba1ed9af003d2ea74693f772d5 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Wed, 13 Apr 2016 08:41:05 +0930 Subject: [PATCH 33/34] Newlines --- spec/models/planting_spec.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 90b4da713..dfccd8352 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -72,6 +72,7 @@ describe Planting do @planting.planted?.should be false @planting.percentage_grown.should be nil end + it 'should not be calculated for plantings with an unknown days before maturity' do @planting = FactoryGirl.build(:planting, days_before_maturity: nil) @@ -83,12 +84,15 @@ describe Planting do it 'system name' do planting.crop_name.should eq planting.crop.name end + it 'wikipedia url' do planting.crop_en_wikipedia_url.should eq planting.crop.en_wikipedia_url end + it 'default scientific name' do planting.crop_default_scientific_name.should eq planting.crop.default_scientific_name end + it 'plantings count' do planting.crop_plantings_count.should eq planting.crop.plantings_count end @@ -309,13 +313,11 @@ describe Planting do @f = FactoryGirl.build(:planting, :planted_at => '2013-01-01', :finished_at => nil) @f.should be_valid end + it 'allows just the finished date' do @f = FactoryGirl.build(:planting, :finished_at => '2013-01-01', :planted_at => nil) @f.should be_valid end - end - end - -end +end \ No newline at end of file From cf0a6466996e3dd9ee04d37cf3f56f869228cecd Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Thu, 14 Apr 2016 09:59:36 +0930 Subject: [PATCH 34/34] Add EOF newlines --- app/views/plantings/_planting_progress.html.haml | 2 +- app/views/plantings/_thumbnail.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/plantings/_planting_progress.html.haml b/app/views/plantings/_planting_progress.html.haml index 7fe6d52f7..a9c851709 100644 --- a/app/views/plantings/_planting_progress.html.haml +++ b/app/views/plantings/_planting_progress.html.haml @@ -7,4 +7,4 @@ = "Progress: Not calculated, days before maturity unknown" - else = "Progress: #{planting.percentage_grown}%" - = render partial: "plantings/progress_bar", locals: {status: "success", progress: "#{planting.percentage_grown}%"} \ No newline at end of file + = render partial: "plantings/progress_bar", locals: {status: "success", progress: "#{planting.percentage_grown}%"} diff --git a/app/views/plantings/_thumbnail.html.haml b/app/views/plantings/_thumbnail.html.haml index fbc859963..df62f7a9c 100644 --- a/app/views/plantings/_thumbnail.html.haml +++ b/app/views/plantings/_thumbnail.html.haml @@ -38,4 +38,4 @@ %dd= "#{display_days_before_maturity(planting)}" .col-xs-9.col-md-8 - = render partial: 'plantings/planting_progress', locals: {planting: planting} \ No newline at end of file + = render partial: 'plantings/planting_progress', locals: {planting: planting}