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/.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/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/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index e237ae27d..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 - DateTime.now).to_i) <= 0 ? 0 : p.to_i - elsif planting.days_before_maturity.nil? + ((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) - 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.to_s end 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']) 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 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 diff --git a/spec/helpers/plantings_helper_spec.rb b/spec/helpers/plantings_helper_spec.rb index 9485af81d..e776501b4 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 "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" + 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 "5" + end + end + describe "display_planting" do let!(:member) { FactoryGirl.build(:member, login_name: 'crop_lady') }