From 63d89be698ed3785cca3e00581c93e4262bc9e1d Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Mon, 20 Jun 2016 10:34:11 -0400 Subject: [PATCH 01/11] lets encrypt challenge page --- config/routes.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index b8fee2796..5401ed568 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -83,6 +83,8 @@ 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' + # CMS stuff -- must remain LAST comfy_route :cms, path: '/', sitemap: false From 5bc6af87c58bc8c3b2df18dc6c854f2433ee0ba2 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Mon, 20 Jun 2016 10:46:40 -0400 Subject: [PATCH 02/11] challenge code --- app/controllers/pages_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 app/controllers/pages_controller.rb diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb new file mode 100644 index 000000000..1c3f8f92e --- /dev/null +++ b/app/controllers/pages_controller.rb @@ -0,0 +1,6 @@ +class PagesController < ApplicationController + def letsencrypt + # use your code here, not mine + render text: "B4-cHp8zD8RDI8ihZYvqzb2mV6RPSmrQ-clntqc-5Is.dlIPqFhMDCLyQEccczY3roHZ1UWu6UqVeyb9mkRxheU" + end +end From 628ebd6841cd528124681153a2c1c4150fb6a8a2 Mon Sep 17 00:00:00 2001 From: Cesy Date: Tue, 21 Jun 2016 15:05:45 +0100 Subject: [PATCH 03/11] Revert "lets encrypt challenge page" --- config/routes.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 5401ed568..b8fee2796 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -83,8 +83,6 @@ 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' - # CMS stuff -- must remain LAST comfy_route :cms, path: '/', sitemap: false From 7261fae9f26ce6052851855cfafa796dddd8061d Mon Sep 17 00:00:00 2001 From: Cesy Date: Tue, 21 Jun 2016 15:06:02 +0100 Subject: [PATCH 04/11] Revert "challenge code" --- app/controllers/pages_controller.rb | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 app/controllers/pages_controller.rb diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb deleted file mode 100644 index 1c3f8f92e..000000000 --- a/app/controllers/pages_controller.rb +++ /dev/null @@ -1,6 +0,0 @@ -class PagesController < ApplicationController - def letsencrypt - # use your code here, not mine - render text: "B4-cHp8zD8RDI8ihZYvqzb2mV6RPSmrQ-clntqc-5Is.dlIPqFhMDCLyQEccczY3roHZ1UWu6UqVeyb9mkRxheU" - end -end From 9aa4fa8031af3373cc9a2f05410574a9d577646d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 30 Nov 2016 10:25:23 +1300 Subject: [PATCH 05/11] Fixes for two calls to deprecated methods --- .rubocop_todo.yml | 7 ------- app/controllers/robots_controller.rb | 2 +- config/boot.rb | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 93b7ab7c0..2fdd20f71 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -32,13 +32,6 @@ Lint/AssignmentInCondition: Exclude: - 'app/models/member.rb' -# Offense count: 2 -# Cop supports --auto-correct. -Lint/DeprecatedClassMethods: - Exclude: - - 'app/controllers/robots_controller.rb' - - 'config/boot.rb' - # Offense count: 1 Lint/HandleExceptions: Exclude: diff --git a/app/controllers/robots_controller.rb b/app/controllers/robots_controller.rb index d74ffe20f..eb846d23d 100644 --- a/app/controllers/robots_controller.rb +++ b/app/controllers/robots_controller.rb @@ -3,7 +3,7 @@ class RobotsController < ApplicationController def robots filename = "config/robots.#{subdomain}.txt" if subdomain && subdomain != 'www' - file_to_render = File.exists?(filename.to_s) ? filename : DEFAULT_FILENAME + file_to_render = File.exist?(filename.to_s) ? filename : DEFAULT_FILENAME render file: file_to_render, layout: false, content_type: 'text/plain' end diff --git a/config/boot.rb b/config/boot.rb index 4489e5868..f2830ae31 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -3,4 +3,4 @@ require 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) From 900e7361c6e3c5ba51d69ce70ad86725e51e25ee Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 30 Nov 2016 09:00:10 +1300 Subject: [PATCH 06/11] Check we have a planted_at ts before doing maths with it --- app/helpers/plantings_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index fb6e2e7dc..898a0272f 100644 --- a/app/helpers/plantings_helper.rb +++ b/app/helpers/plantings_helper.rb @@ -5,7 +5,7 @@ module PlantingsHelper 0 elsif !planting.finished_at.nil? ((p = planting.finished_at - DateTime.now).to_i) <= 0 ? 0 : p.to_i - elsif planting.days_before_maturity.nil? + elsif planting.planted_at.nil? || planting.days_before_maturity.nil? "unknown" else ((p = (planting.planted_at + planting.days_before_maturity) - DateTime.now).to_i <= 0) ? 0 : p.to_i From 77c64d59258b7692231a7bf21b63570be9bf5359 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 29 Nov 2016 13:51:04 +0000 Subject: [PATCH 07/11] Test PlantingHelper.display_days_before_maturity This ensures that #1079 is fixed. --- spec/helpers/plantings_helper_spec.rb | 63 +++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/spec/helpers/plantings_helper_spec.rb b/spec/helpers/plantings_helper_spec.rb index 9485af81d..48a1ea5ad 100644 --- a/spec/helpers/plantings_helper_spec.rb +++ b/spec/helpers/plantings_helper_spec.rb @@ -1,6 +1,69 @@ require 'rails_helper' describe PlantingsHelper do + describe "display_days_before_maturity" do + it "handles nil planted_at, nil finished_at, non-nil days_until_maturity" do + planting = FactoryGirl.build(:planting, + quantity: 5, + planted_at: nil, + finished_at: nil, + days_before_maturity: 17 + ) + result = helper.display_days_before_maturity(planting) + expect(result).to eq "unknown" + end + + it "handles non-nil planted_at and d_b_m, nil finished_at" do + planting = FactoryGirl.build(:planting, + quantity: 5, + planted_at: Date.current, + finished_at: nil, + days_before_maturity: 17 + ) + result = helper.display_days_before_maturity(planting) + expect(result).to eq 16 + end + + it "handles completed plantings" do + planting = FactoryGirl.build(:planting, finished: true) + result = helper.display_days_before_maturity(planting) + expect(result).to eq 0 + end + + it "handles plantings that should have finished" do + planting = FactoryGirl.build(:planting, + quantity: 5, + planted_at: Date.new(0, 1, 1), + finished_at: nil, + days_before_maturity: 17 + ) + result = helper.display_days_before_maturity(planting) + expect(result).to eq 0 + end + + it "handles nil d_b_m and nil finished_at" do + planting = FactoryGirl.build(:planting, + quantity: 5, + planted_at: Date.new(2012, 5, 12), + finished_at: nil, + days_before_maturity: nil + ) + result = helper.display_days_before_maturity(planting) + expect(result).to eq "unknown" + end + + it "handles finished_at dates in the future" do + planting = FactoryGirl.build(:planting, + quantity: 5, + planted_at: Date.current, + finished_at: Date.current + 5, + days_before_maturity: nil + ) + result = helper.display_days_before_maturity(planting) + expect(result).to eq 4 + end + end + describe "display_planting" do let!(:member) { FactoryGirl.build(:member, login_name: 'crop_lady') } From b0b864a5d41278e6695c003a5114425f7ca25d2d Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 29 Nov 2016 13:53:26 +0000 Subject: [PATCH 08/11] Fix off-by-one bug in display_days_before_maturity We were counting from DateTime.now rather than Date.current, causing us to under-count by a day. --- app/helpers/plantings_helper.rb | 4 ++-- spec/helpers/plantings_helper_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index a9cfebf61..964b8fb76 100644 --- a/app/helpers/plantings_helper.rb +++ b/app/helpers/plantings_helper.rb @@ -3,11 +3,11 @@ module PlantingsHelper if planting.finished? 0 elsif !planting.finished_at.nil? - ((p = planting.finished_at - DateTime.now).to_i) <= 0 ? 0 : p.to_i + ((p = planting.finished_at - Date.current).to_i) <= 0 ? 0 : p.to_i elsif planting.planted_at.nil? || planting.days_before_maturity.nil? "unknown" else - ((p = (planting.planted_at + planting.days_before_maturity) - DateTime.now).to_i <= 0) ? 0 : p.to_i + ((p = (planting.planted_at + planting.days_before_maturity) - Date.current).to_i <= 0) ? 0 : p.to_i end end diff --git a/spec/helpers/plantings_helper_spec.rb b/spec/helpers/plantings_helper_spec.rb index 48a1ea5ad..2370bf53a 100644 --- a/spec/helpers/plantings_helper_spec.rb +++ b/spec/helpers/plantings_helper_spec.rb @@ -21,7 +21,7 @@ describe PlantingsHelper do days_before_maturity: 17 ) result = helper.display_days_before_maturity(planting) - expect(result).to eq 16 + expect(result).to eq 17 end it "handles completed plantings" do @@ -60,7 +60,7 @@ describe PlantingsHelper do days_before_maturity: nil ) result = helper.display_days_before_maturity(planting) - expect(result).to eq 4 + expect(result).to eq 5 end end From 9400225f65b283a6bf1ff4bca5dc1a9dcb87e8a3 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Wed, 30 Nov 2016 09:56:31 +0000 Subject: [PATCH 09/11] Return a string from display_days_before_maturity Sometimes we were returning a string, and sometimes we were returning an integer. We're only ever displaying the result, and this seems a little more consistent. --- app/helpers/plantings_helper.rb | 6 +++--- spec/helpers/plantings_helper_spec.rb | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index 964b8fb76..f4d8d45be 100644 --- a/app/helpers/plantings_helper.rb +++ b/app/helpers/plantings_helper.rb @@ -1,13 +1,13 @@ module PlantingsHelper def display_days_before_maturity(planting) if planting.finished? - 0 + "0" elsif !planting.finished_at.nil? - ((p = planting.finished_at - Date.current).to_i) <= 0 ? 0 : p.to_i + ((p = planting.finished_at - Date.current).to_i) <= 0 ? "0" : p.to_i.to_s elsif planting.planted_at.nil? || planting.days_before_maturity.nil? "unknown" else - ((p = (planting.planted_at + planting.days_before_maturity) - Date.current).to_i <= 0) ? 0 : p.to_i + ((p = (planting.planted_at + planting.days_before_maturity) - Date.current).to_i <= 0) ? "0" : p.to_i.to_s end end diff --git a/spec/helpers/plantings_helper_spec.rb b/spec/helpers/plantings_helper_spec.rb index 2370bf53a..e776501b4 100644 --- a/spec/helpers/plantings_helper_spec.rb +++ b/spec/helpers/plantings_helper_spec.rb @@ -21,13 +21,13 @@ describe PlantingsHelper do days_before_maturity: 17 ) result = helper.display_days_before_maturity(planting) - expect(result).to eq 17 + expect(result).to eq "17" end it "handles completed plantings" do planting = FactoryGirl.build(:planting, finished: true) result = helper.display_days_before_maturity(planting) - expect(result).to eq 0 + expect(result).to eq "0" end it "handles plantings that should have finished" do @@ -35,10 +35,10 @@ describe PlantingsHelper do quantity: 5, planted_at: Date.new(0, 1, 1), finished_at: nil, - days_before_maturity: 17 + days_before_maturity: "17" ) result = helper.display_days_before_maturity(planting) - expect(result).to eq 0 + expect(result).to eq "0" end it "handles nil d_b_m and nil finished_at" do @@ -60,7 +60,7 @@ describe PlantingsHelper do days_before_maturity: nil ) result = helper.display_days_before_maturity(planting) - expect(result).to eq 5 + expect(result).to eq "5" end end From 184154893607123c7829127b4a2e7e3e42abde21 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Wed, 30 Nov 2016 11:01:25 +0000 Subject: [PATCH 10/11] Precompile assets in test According to https://github.com/teampoltergeist/poltergeist/issues/677#issuecomment-222919584, a possible cause of the "Request failed to reach server" problem (#901) is that assets are being compiled on-demand, causing enough of a slowdown for PhantomJS to think the connection has failed. This turns off lazy asset compilation in the test environment and precompiles assets before testing on Travis. We should also turn off lazy asset compilation in production - see http://stackoverflow.com/questions/8821864/config-assets-compile-true-in-rails-production-why-not Our Heroku deployments already run `rake assets:precompile`. --- .travis.yml | 1 + config/environments/test.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3aefec912..5f2219acd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ before_install: - phantomjs --version before_script: - bundle exec rake db:create db:migrate db:test:prepare + - bundle exec rake assets:precompile script: - bundle exec rubocop --display-cop-names --rails - script/gemfile_check diff --git a/config/environments/test.rb b/config/environments/test.rb index 35836c90b..dd3a3816c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -6,6 +6,10 @@ Growstuff::Application.configure do # preloads Rails for running tests, you may have to set it to true. config.eager_load = false + # Do not compile assets on-demand. On-demand compilation slows down the test + # suite and causes random test failures. + config.assets.compile = false + # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped From 6be96406254ce678c9da0255b3854e607264f44a Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Wed, 30 Nov 2016 11:35:35 +0000 Subject: [PATCH 11/11] Run tests with `rake` when DB does not yet exist Previously, `rake spec` ran the tests whether or not the `growstuff_test` database existed or not, but `rake` crashed unless it had already been created. The problem was that `rake` was trying to load the environment, which required the presence of a DB; `rake spec` was running this with the `dev` environment, so succeeded if `growstuff_dev` existed, but `rake` was running everything with the `test` environment, so would fail if `growstuff_test` did not exist. This patch adds `db:create` to the dependencies of the `spec` task, forcing an unadorned `rake` to create all necessary databases first. --- lib/tasks/testing.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/testing.rake b/lib/tasks/testing.rake index a7908d590..b41172efb 100644 --- a/lib/tasks/testing.rake +++ b/lib/tasks/testing.rake @@ -2,7 +2,7 @@ require 'rake' begin require 'rspec/core/rake_task' task(:spec).clear - RSpec::Core::RakeTask.new(spec: 'db:test:prepare') do |t| + RSpec::Core::RakeTask.new(spec: ['db:create', 'db:test:prepare']) do |t| t.verbose = false end rescue LoadError