Merge branch 'dev' into scopify

This commit is contained in:
Mackenzie
2016-11-30 16:47:22 -05:00
committed by GitHub
8 changed files with 75 additions and 14 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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'])

View File

@@ -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

View File

@@ -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

View File

@@ -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') }