Compare commits

..

25 Commits

Author SHA1 Message Date
Cesy
1ad171f37b Merge pull request #1335 from Growstuff/dev
Release 25
2017-05-15 20:43:16 +01:00
deppbot
06896dacd5 Bundle Update on 2017-05-13 2017-05-14 18:20:44 +12:00
Shiny
ff90d6430d Merge branch 'master' into dev 2017-05-13 11:35:26 +12:00
Brenda Wallace
4dbdbc4285 Pull haml gem back to version 4 2017-05-13 11:31:32 +12:00
deppbot
0f1c8e0658 Bundle Update on 2017-05-03 2017-05-13 11:31:32 +12:00
Daniel O'Connor
c9ec116c9b Merge pull request #1333 from Br3nda/garden-photos-fixup
Fix up of photo display on garden#show
2017-05-11 17:25:51 +09:30
Brenda Wallace
e61c3f619b Revert "Only show first 5 photos on gardens#show"
This reverts commit 93b25a5c32.
2017-05-07 16:10:14 +12:00
Brenda Wallace
93b25a5c32 Only show first 5 photos on gardens#show 2017-05-07 14:41:14 +12:00
Brenda Wallace
f7ca32d888 Moved garden photos to right/bottom 2017-05-06 13:30:57 +12:00
Brenda Wallace
d57c46066a updated view spec to find glypicon 2017-05-06 13:27:23 +12:00
Brenda Wallace
1e6cb2cfe4 don't eager load harvests 2017-05-06 12:15:03 +12:00
Brenda Wallace
67ae80056a Removed unnecesary div wrap 2017-05-06 12:08:23 +12:00
Brenda Wallace
13fa3c69e8 fixes places
card -> thumbnail
2017-05-06 12:06:28 +12:00
Brenda Wallace
caad557b2a Updating specs to click glypicons 2017-05-06 12:03:57 +12:00
Brenda Wallace
0f030d2c27 Planting thumbnail links to planting
fixes #1308
2017-05-06 11:48:17 +12:00
Brenda Wallace
66d548c9c1 Added some glypicons to gardenshow 2017-05-06 11:47:24 +12:00
Brenda Wallace
c168bb4a2b More fix up to alignment and thumbnail row counts gardens#show 2017-05-06 11:39:02 +12:00
Brenda Wallace
811db2961a Quick fix up of photo display on garden#show 2017-05-05 23:38:19 +12:00
Brenda Wallace
42cea2ebde Fixed spec for days_before_maturity 2017-04-28 20:48:25 +12:00
Brenda Wallace
ccc5eb3c9a Make calc_and_set_days_before_maturity public 2017-04-28 20:48:25 +12:00
Brenda Wallace
0e71a4fcb3 Removed un-needed rubocop ignores 2017-04-28 20:48:25 +12:00
Brenda Wallace
4ea681984f Call calc_and_set_days_before_maturity from controller 2017-04-28 20:48:25 +12:00
Brenda Wallace
dadc5b96c6 Reduced duplicate code further, with responders gem
This makes locale-friendly flash notices
2017-04-28 20:48:25 +12:00
Brenda Wallace
787fca138b Added helpful comment about days_until_maturity 2017-04-28 20:48:25 +12:00
Brenda Wallace
b820615081 Moved planting maturity to planting model. simplified controller 2017-04-28 20:48:25 +12:00
12 changed files with 231 additions and 230 deletions

View File

@@ -68,7 +68,6 @@ Rails/OutputSafety:
# update_counters
Rails/SkipsModelValidations:
Exclude:
- 'app/controllers/plantings_controller.rb'
- 'db/seeds.rb'
# Configuration parameters: EnforcedStyle, SupportedStyles.
@@ -228,10 +227,6 @@ Style/NegatedIf:
Exclude:
- 'app/helpers/crops_helper.rb'
Style/NestedTernaryOperator:
Exclude:
- 'app/controllers/plantings_controller.rb'
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
# SupportedStyles: skip_modifier_ifs, always

View File

@@ -8,7 +8,7 @@ gem 'rails', '~> 4.2.7'
gem 'bundler', '>=1.1.5'
gem 'coffee-rails', '~> 4.1.0'
gem 'haml'
gem 'haml', '~> 4.0.7'
gem 'sass-rails', '~> 5.0.4'
# CSS framework
@@ -85,8 +85,8 @@ gem "hashie", ">= 3.5.3"
gem 'rake', '>= 10.0.0'
# # CMS
# gem 'comfortable_mexican_sofa', '~> 1.12.0'
# locale based flash notices for controllers
gem "responders"
group :production, :staging do
gem 'bonsai-elasticsearch-rails' # Integration with Bonsa-Elasticsearch on heroku

View File

@@ -31,8 +31,8 @@ GEM
activejob (4.2.8)
activesupport (= 4.2.8)
globalid (>= 0.3.0)
activemerchant (1.64.0)
activesupport (>= 3.2.14, < 5.1)
activemerchant (1.66.0)
activesupport (>= 3.2.14, < 6.x)
builder (>= 2.1.2, < 4.0.0)
i18n (>= 0.6.9)
nokogiri (~> 1.4)
@@ -52,7 +52,7 @@ GEM
public_suffix (~> 2.0, >= 2.0.2)
arel (6.0.4)
ast (2.3.0)
autoprefixer-rails (6.7.7.2)
autoprefixer-rails (7.0.1)
execjs
bcrypt (3.1.11)
better_errors (2.1.1)
@@ -80,7 +80,7 @@ GEM
uniform_notifier (~> 1.10.0)
byebug (9.0.6)
cancancan (1.16.0)
capybara (2.13.0)
capybara (2.14.0)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
@@ -93,9 +93,9 @@ GEM
capybara-screenshot (1.0.14)
capybara (>= 1.0, < 3)
launchy
childprocess (0.6.3)
childprocess (0.7.0)
ffi (~> 1.0, >= 1.0.11)
climate_control (0.1.0)
climate_control (0.2.0)
cliver (0.3.2)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
@@ -140,7 +140,7 @@ GEM
railties (>= 3.1)
dalli (2.7.6)
database_cleaner (1.5.3)
debug_inspector (0.0.2)
debug_inspector (0.0.3)
devise (4.2.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
@@ -216,13 +216,13 @@ GEM
highline
tilt
trollop (= 1.16.2)
haml-rails (0.9.0)
haml-rails (1.0.0)
actionpack (>= 4.0.1)
activesupport (>= 4.0.1)
haml (>= 4.0.6, < 5.0)
haml (>= 4.0.6, < 6.0)
html2haml (>= 1.0.1)
railties (>= 4.0.1)
haml_lint (0.24.0)
haml_lint (0.25.1)
haml (>= 4.0, < 5.1)
rainbow
rake (>= 10, < 13)
@@ -233,12 +233,12 @@ GEM
excon (~> 0.45)
multi_json (~> 1.8)
highline (1.7.8)
html2haml (2.1.0)
html2haml (2.2.0)
erubis (~> 2.7.0)
haml (~> 4.0)
haml (>= 4.0, < 6)
nokogiri (>= 1.6.0)
ruby_parser (~> 3.5)
httparty (0.14.0)
httparty (0.15.2)
multi_xml (>= 0.5.2)
i18n (0.8.1)
i18n-tasks (0.9.12)
@@ -251,12 +251,12 @@ GEM
parser (>= 2.2.3.0)
term-ansicolor (>= 1.3.2)
terminal-table (>= 1.5.1)
jasmine (2.5.2)
jasmine-core (>= 2.5.1, < 3.0.0)
jasmine (2.6.0)
jasmine-core (>= 2.6.0, < 3.0.0)
phantomjs
rack (>= 1.2.1)
rake
jasmine-core (2.5.2)
jasmine-core (2.6.1)
jquery-rails (4.3.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
@@ -286,8 +286,8 @@ GEM
ruby_dep (~> 1.2)
loofah (2.0.3)
nokogiri (>= 1.5.9)
lumberjack (1.0.11)
mail (2.6.4)
lumberjack (1.0.12)
mail (2.6.5)
mime-types (>= 1.16, < 4)
memcachier (0.0.2)
method_source (0.8.2)
@@ -296,13 +296,13 @@ GEM
mime-types-data (3.2016.0521)
mimemagic (0.3.2)
mini_portile2 (2.1.0)
minitest (5.10.1)
minitest (5.10.2)
multi_json (1.11.3)
multi_xml (0.6.0)
multipart-post (2.0.0)
nenv (0.3.0)
newrelic_rpm (4.1.0.333)
nokogiri (1.7.1)
nokogiri (1.7.2)
mini_portile2 (~> 2.1.0)
notiffany (0.1.1)
nenv (~> 0.1)
@@ -344,7 +344,7 @@ GEM
phantomjs (2.1.1.0)
plupload-rails (1.2.1)
rails (>= 3.1)
poltergeist (1.14.0)
poltergeist (1.15.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
@@ -356,8 +356,8 @@ GEM
public_suffix (2.0.5)
quiet_assets (1.1.0)
railties (>= 3.1, < 5.0)
rack (1.6.5)
rack-protection (1.5.3)
rack (1.6.6)
rack-protection (2.0.0)
rack
rack-test (0.6.3)
rack (>= 1.0)
@@ -400,33 +400,34 @@ GEM
rb-inotify (0.9.8)
ffi (>= 0.5.0)
redis (3.3.3)
responders (2.3.0)
railties (>= 4.2.0, < 5.1)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-activemodel-mocks (1.0.3)
activemodel (>= 3.0)
activesupport (>= 3.0)
rspec-mocks (>= 2.99, < 4.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-rails (3.5.2)
rspec-support (~> 3.6.0)
rspec-rails (3.6.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
rubocop (0.47.1)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
@@ -452,11 +453,11 @@ GEM
websocket (~> 1.0)
sexp_processor (4.9.0)
shellany (0.0.1)
sidekiq (4.2.10)
sidekiq (5.0.0)
concurrent-ruby (~> 1.0)
connection_pool (~> 2.2, >= 2.2.0)
rack-protection (>= 1.5.0)
redis (~> 3.2, >= 3.2.1)
redis (~> 3.3, >= 3.3.3)
simplecov (0.12.0)
docile (~> 1.1.0)
json (>= 1.8, < 3)
@@ -550,7 +551,7 @@ DEPENDENCIES
gravatar-ultimate
guard
guard-rspec
haml
haml (~> 4.0.7)
haml-i18n-extractor
haml-rails
haml_lint
@@ -579,6 +580,7 @@ DEPENDENCIES
rails_12factor
rainbow (< 2.2.0)
rake (>= 10.0.0)
responders
rspec-activemodel-mocks
rspec-rails
rubocop (<= 0.47.1)
@@ -592,6 +594,7 @@ DEPENDENCIES
webrat
will_paginate (~> 3.0)
RUBY VERSION
ruby 2.3.4p301

View File

@@ -1,126 +1,81 @@
class PlantingsController < ApplicationController
before_action :authenticate_member!, except: [:index, :show]
after_action :expire_homepage, only: [:create, :update, :destroy]
load_and_authorize_resource
# GET /plantings
# GET /plantings.json
respond_to :html, :json
respond_to :csv, :rss, only: [:index]
responders :flash
def index
@owner = Member.find_by(slug: params[:owner]) if params[:owner]
@crop = Crop.find_by(slug: params[:crop]) if params[:crop]
@show_all = params[:all] == '1'
@plantings = plantings
respond_to do |format|
format.html { @plantings = @plantings.paginate(page: params[:page]) }
format.json { render json: @plantings }
format.rss { render layout: false } # index.rss.builder
format.csv do
specifics = (@owner ? "#{@owner.login_name}-" : @crop ? "#{@crop.name}-" : nil)
@filename = "Growstuff-#{specifics}Plantings-#{Time.zone.now.to_s(:number)}.csv"
render csv: @plantings
end
end
@plantings = plantings.paginate(page: params[:page])
specifics = if @owner
"#{@owner.login_name}-"
elsif @crop
"#{@crop.name}-"
end
@filename = "Growstuff-#{specifics}Plantings-#{Time.zone.now.to_s(:number)}.csv"
respond_with(@plantings)
end
# GET /plantings/1
# GET /plantings/1.json
def show
@planting = Planting.includes(:owner, :crop, :garden, :photos).friendly.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @planting }
end
@planting = Planting.includes(:owner, :crop, :garden, :photos)
.friendly
.find(params[:id])
respond_with(@planting)
end
# GET /plantings/new
# GET /plantings/new.json
def new
@planting = Planting.new('planted_at' => Time.zone.today)
@planting = Planting.new(planted_at: Time.zone.today)
# using find_by_id here because it returns nil, unlike find
@crop = Crop.approved.find_by(id: params[:crop_id]) || Crop.new
@garden = Garden.find_by(owner: current_member, id: params[:garden_id]) || Garden.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @planting }
end
respond_with(@planting)
end
# GET /plantings/1/edit
def edit
# the following are needed to display the form but aren't used
@crop = Crop.new
@garden = Garden.new
end
# POST /plantings
# POST /plantings.json
def create
params[:planted_at] = parse_date(params[:planted_at])
@planting = Planting.new(planting_params)
@planting.owner = current_member
respond_to do |format|
if @planting.save
@planting.update_attribute(:days_before_maturity,
update_days_before_maturity(@planting, planting_params[:crop_id]))
format.html { redirect_to @planting, notice: 'Planting was successfully created.' }
format.json { render json: @planting, status: :created, location: @planting }
expire_fragment("homepage_stats")
else
format.html { render action: "new" }
format.json { render json: @planting.errors, status: :unprocessable_entity }
end
end
@planting.calc_and_set_days_before_maturity
@planting.save
respond_with(@planting)
end
# PUT /plantings/1
# PUT /plantings/1.json
def update
params[:planted_at] = parse_date(params[:planted_at])
respond_to do |format|
if @planting.update(planting_params)
@planting.update_attribute(:days_before_maturity,
update_days_before_maturity(@planting, planting_params[:crop_id]))
format.html { redirect_to @planting, notice: 'Planting was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @planting.errors, status: :unprocessable_entity }
end
end
@planting.calc_and_set_days_before_maturity
@planting.update(planting_params)
respond_with(@planting)
end
# DELETE /plantings/1
# DELETE /plantings/1.json
def destroy
@garden = @planting.garden
@planting.destroy
expire_fragment("homepage_stats")
respond_to do |format|
format.html { redirect_to @garden }
format.json { head :no_content }
end
respond_with(@planting.garden)
end
private
def planting_params
params.require(:planting).permit(:crop_id, :description, :garden_id, :planted_at,
:quantity, :sunniness, :planted_from, :owner_id, :finished,
:finished_at)
end
def update_days_before_maturity(planting, crop_id)
if planting.finished_at.nil?
planting.calculate_days_before_maturity(planting, crop_id)
else
(planting.finished_at - planting.planted_at).to_i
end
params[:planted_at] = parse_date(params[:planted_at]) if params[:planted_at]
params.require(:planting).permit(
:crop_id, :description, :garden_id, :planted_at,
:quantity, :sunniness, :planted_from, :finished,
:finished_at
)
end
def plantings

View File

@@ -92,21 +92,6 @@ class Planting < ActiveRecord::Base
photos.first
end
def calculate_days_before_maturity(planting, crop)
p_crop = Planting.where(crop_id: crop).where.not(id: planting)
differences = p_crop.collect do |p|
if p.finished && !p.finished_at.nil?
(p.finished_at - p.planted_at).to_i
end
end
if differences.compact.empty?
nil
else
differences.compact.sum / differences.compact.size
end
end
def planted?(current_date = Date.current)
planted_at.present? && current_date.to_date >= planted_at
end
@@ -137,4 +122,29 @@ class Planting < ActiveRecord::Base
percent
end
def start_to_finish_diff
(finished_at - planted_at).to_i
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
def calc_and_set_days_before_maturity
# calculate the number of days, from planted_at, until maturity
if planted_at && finished_at
self.days_before_maturity = start_to_finish_diff
else
self.days_before_maturity = Planting.mean_days_until_maturity other_finished_plantings_same_crop
end
end
private
def other_finished_plantings_same_crop
Planting.where(crop_id: crop).where.not(id: id).where.not(finished_at: nil)
end
end

View File

@@ -15,7 +15,9 @@
%p.btn-group
- if can? :edit, @garden
- if @garden.active
= link_to "Plant something", new_planting_path(garden_id: @garden.id), class: 'btn btn-primary'
= link_to new_planting_path(garden_id: @garden.id), class: 'btn btn-primary' do
%span.glyphicon.glyphicon-grain{ title: "Plant" }
Plant something
= link_to "Mark as inactive", garden_path(@garden, garden: { active: 0 }),
method: :put, class: 'btn btn-default',
data: { confirm: 'All plantings associated with this garden will be marked as finished. Are you sure?' }
@@ -23,12 +25,14 @@
= link_to "Mark as active", garden_path(@garden, garden: { active: 1 }),
method: :put,
class: 'btn btn-default'
= link_to 'Edit garden', edit_garden_path(@garden), class: 'btn btn-default'
= link_to edit_garden_path(@garden), class: 'btn btn-default', id: 'edit_garden_link' do
%span.glyphicon.glyphicon-pencil{ title: "Edit garden" }
- if can?(:destroy, @garden)
= link_to 'Delete garden', @garden,
= link_to @garden,
method: :delete,
data: { confirm: 'All plantings associated with this garden will also be deleted. Are you sure?' },
class: 'btn btn-default'
class: 'btn btn-default', id: 'delete_garden_link' do
%span.glyphicon.glyphicon-trash{ title: "Delete" }
- unless @garden.active
.alert.alert-warning
@@ -49,35 +53,23 @@
Why not
= link_to 'tell us more.', edit_garden_path(@garden)
- if !@garden.photos.empty? || (can?(:edit, @garden) && can?(:create, Photo))
.row-fluid
%h3 Photos
%p= localize_plural(@garden.photos, Photo)
.row-fluid
%ul.thumbnails
- @garden.photos.includes(:owner).each do |p|
.col-md-2.six-across
= render partial: 'photos/thumbnail', locals: { photo: p }
.row-fluid
- if can?(:create, Photo) && can?(:edit, @garden)
%p
= link_to "Add photo", new_photo_path(type: "garden", id: @garden.id), class: 'btn btn-primary'
.row-fluid
%h3 What's planted here?
- if @garden.plantings.current.empty?
%p Nothing is currently planted here.
%h3 What's planted here?
.row
- if @garden.plantings.size.positive?
- @garden.plantings.current.includes(:crop, :owner, :garden).each do |planting|
.col-xs-12.col-md-6
= render partial: "plantings/thumbnail", locals: { planting: planting }
- else
- @garden.plantings.current.includes(:crop, :owner, :harvests, :garden).each.with_index do |planting_current, _|
= render partial: "plantings/thumbnail", locals: { planting: planting_current }
.row-fluid
%h3 Previously planted in this garden
- if @garden.plantings.finished.empty?
%p Nothing has been planted here.
- else
- @garden.plantings.finished.each.with_index do |planting_finished|
= render partial: "plantings/thumbnail", locals: { planting: planting_finished }
.col-md-12
%p Nothing is currently planted here.
%h3 Previously planted in this garden
- if @garden.plantings.finished.size.positive?
.row
- @garden.plantings.finished.includes(:crop, :owner, :garden).each do |planting|
.col-xs-12.col-md-6
= render partial: "plantings/thumbnail", locals: { planting: planting }
- else
%p Nothing has been planted here.
.col-md-3
%h4 About this garden
%p
@@ -107,9 +99,24 @@
- @garden.owner.gardens.inactive.each do |othergarden|
%li
- if @garden == othergarden
= @garden
= @garden.name
- else
= link_to othergarden, garden_path(othergarden)
- if @garden.owner == current_member
= link_to 'Add New Garden', new_garden_path, class: 'btn btn-default btn-xs'
%p
= link_to new_garden_path, class: 'btn btn-default btn-xs' do
Add New Garden
- if can?(:edit, @garden) && can?(:create, Photo)
%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
- if @garden.photos.size.positive?
%h3= localize_plural(@garden.photos, Photo)
.row
- @garden.photos.includes(:owner).each do |photo|
.col-xs-6
= render partial: 'photos/thumbnail', locals: { photo: photo }

View File

@@ -45,10 +45,8 @@
- plantings.first(10).each.with_index do |planting, index|
.col-xs-12.col-lg-6
= render partial: "plantings/thumbnail", locals: { planting: planting, index: index }
.row
= link_to "View all plantings >>", plantings_path
= link_to "View all plantings >>", plantings_path
- else
.row
%p No nearby plantings found
%p No nearby plantings found
- else
%p No results found

View File

@@ -1,13 +1,13 @@
.panel.panel-success.planting-thumbnail
.panel-heading
%h3.panel-title= link_to planting.crop.name, planting.crop
%h3.panel-title= link_to planting.crop.name, planting_path(planting)
.panel-body
.row
.col-xs-12.col-md-4
.col-xs-12.col-md-5
= link_to image_tag((planting.default_photo ? planting.default_photo.thumbnail_url : 'placeholder_150.png'),
alt: planting.crop_id, class: 'img'),
alt: planting.crop_id, class: 'img img-responsive'),
planting
.col-xs-7.col-md-6
.col-xs-12.col-md-7
%dl.dl-horizontal.planting-attributes
%dt Owner:
%dd= link_to planting.owner.login_name, planting.owner
@@ -29,33 +29,34 @@
%dt Planted from:
%dd= display_planted_from(planting)
.row
.col-xs-12.col-md-4
%dl
%dt Mature in:
%dd
= display_days_before_maturity(planting)
days
.col-xs-12.col-md-8
= link_to 'Details', planting, class: 'btn btn-default btn-xs'
- if can? :edit, planting
= link_to edit_planting_path(planting), class: 'btn btn-default btn-xs' do
%span.glyphicon.glyphicon-pencil{ title: "Edit" }
- if can?(:edit, planting) && can?(:create, Harvest)
= link_to 'Harvest', new_planting_harvest_path(planting), class: 'btn btn-default btn-xs'
- if can?(:edit, planting) && !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? :destroy, planting
= link_to planting, method: :delete,
data: { confirm: 'Are you sure?' },
class: 'btn btn-default btn-xs' do
%span.glyphicon.glyphicon-trash{ title: "Delete" }
%p= render partial: 'plantings/planting_progress', locals: { planting: planting }
= link_to 'Details', planting_path(planting),
class: 'btn btn-default btn-xs'
- if can? :edit, planting
= link_to edit_planting_path(planting),
class: 'btn btn-default btn-xs' do
%span.glyphicon.glyphicon-pencil{ title: "Edit" }
- if can?(:edit, planting) && can?(:create, Harvest)
= link_to 'Harvest', new_planting_harvest_path(planting),
class: 'btn btn-default btn-xs'
- if can?(:edit, planting) && !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? :destroy, planting
= link_to planting, method: :delete,
data: { confirm: 'Are you sure?' },
class: 'btn btn-default btn-xs' do
%span.glyphicon.glyphicon-trash{ title: "Delete" }
.row
.col-xs-12.col-md-12
%p= render partial: 'plantings/planting_progress', locals: { planting: planting }

View File

@@ -67,7 +67,7 @@ feature "Planting a crop", js: true do
visit new_garden_path
fill_in "Name", with: "New garden"
click_button "Save"
click_link "Edit garden"
click_link 'edit_garden_link'
fill_in "Name", with: "Different name"
click_button "Save"
expect(page).to have_content "Garden was successfully updated"
@@ -79,7 +79,7 @@ feature "Planting a crop", js: true do
fill_in "Name", with: "New garden"
click_button "Save"
visit garden_path(Garden.last)
click_link "Delete garden"
click_link 'delete_garden_link'
expect(page).to have_content "Garden was successfully deleted"
expect(page).to have_content "#{garden.owner}'s gardens"
end

View File

@@ -42,7 +42,7 @@ feature "Planting a crop", :js, :elasticsearch do
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
expect(page).to have_content "planting was successfully created"
expect(page).to have_content "Progress: Not calculated, days before maturity unknown"
end
@@ -74,7 +74,7 @@ feature "Planting a crop", :js, :elasticsearch do
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
expect(page).to have_content "planting was successfully created"
expect(page).to have_content "Progress: 0% - not planted yet"
end
@@ -90,7 +90,7 @@ feature "Planting a crop", :js, :elasticsearch do
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
expect(page).to have_content "planting was successfully created"
expect(page).to have_content "Progress: Not calculated, days before maturity unknown"
expect(page).to have_content "Days until maturity: unknown"
end
@@ -108,7 +108,7 @@ feature "Planting a crop", :js, :elasticsearch do
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
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: Not calculated, days before maturity unknown"
end
@@ -126,7 +126,7 @@ feature "Planting a crop", :js, :elasticsearch do
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
expect(page).to have_content "planting was successfully created"
expect(page).to have_content "Progress: 100%"
expect(page).to have_content "Yes (no date specified)"
expect(page).to have_content "Days until maturity: 0"
@@ -145,7 +145,7 @@ feature "Planting a crop", :js, :elasticsearch do
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
expect(page).to have_content "planting was successfully created"
expect(page).to have_content "Progress: 100%"
expect(page).to have_content "Days until maturity: 0"
end
@@ -159,7 +159,7 @@ feature "Planting a crop", :js, :elasticsearch do
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
expect(page).to have_content "planting was successfully created"
expect(page).to have_content "maize"
end
@@ -168,7 +168,7 @@ feature "Planting a crop", :js, :elasticsearch do
click_link "Edit"
fill_in "Tell us more about it", with: "Some extra notes"
click_button "Save"
expect(page).to have_content "Planting was successfully updated"
expect(page).to have_content "planting was successfully updated"
end
scenario "Editing a planting to fill in the finished date" do
@@ -178,7 +178,7 @@ feature "Planting a crop", :js, :elasticsearch do
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 have_content "planting was successfully updated"
expect(page).to_not have_content "Progress: Not calculated, days before maturity unknown"
end
@@ -211,7 +211,7 @@ feature "Planting a crop", :js, :elasticsearch do
within "form#new_planting" do
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
expect(page).to have_content "planting was successfully created"
expect(page).to have_content "Finished: August 30, 2014"
# shouldn't be on the page
@@ -230,7 +230,7 @@ feature "Planting a crop", :js, :elasticsearch do
check "Mark as finished"
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
expect(page).to have_content "planting was successfully created"
expect(page).to have_content "Finished: Yes (no date specified)"
expect(page).to have_content "Progress: 100%"
end

View File

@@ -4,9 +4,41 @@ describe Planting do
let(:crop) { FactoryGirl.create(:tomato) }
let(:garden_owner) { FactoryGirl.create(:member) }
let(:garden) { FactoryGirl.create(:garden, owner: garden_owner) }
let(:planting) {
FactoryGirl.create(:planting,
crop: crop, garden: garden)}
let(:planting) { FactoryGirl.create(:planting, crop: crop, garden: garden) }
let(:finished_planting) { FactoryGirl.create :planting, planted_at: 4.days.ago, finished_at: 2.days.ago }
describe 'maturity calculations' do
describe 'start_to_finish_diff' do
it { expect(finished_planting.start_to_finish_diff).to eq(2) }
end
describe 'other_finished_plantings_same_crop' do
before do
# eight finished plantings
8.times { FactoryGirl.create :planting, crop: crop, planted_at: 10.days.ago, finished_at: 2.days.ago }
# eight not finished plantings
8.times { FactoryGirl.create :planting, crop: crop, finished_at: nil }
end
let!(:planting_with_diff_crop) { FactoryGirl.create :planting, planted_at: 10.days.ago, finished_at: 2.days.ago }
it { expect(planting.send(:other_finished_plantings_same_crop).size).to eq(8) }
it { expect(planting.send(:other_finished_plantings_same_crop)).not_to include(planting) }
it { expect(planting.send(:other_finished_plantings_same_crop)).not_to include(planting_with_diff_crop) }
end
describe 'mean_days_until_maturity' do
let(:plantings) do
FactoryGirl.create_list(:planting, 10, crop: crop, planted_at: 12.days.ago, finished_at: 2.days.ago)
end
it { expect(plantings.size).to eq(10) }
it { expect(Planting.mean_days_until_maturity(plantings)).to eq(10) }
end
describe 'saving planting calculates days_before_maturity' do
before { 5.times { FactoryGirl.create :planting, planted_at: 30.days.ago, finished_at: 9.days.ago, crop: crop } }
before { planting.calc_and_set_days_before_maturity }
it { expect(planting.days_before_maturity).to eq(21) }
end
end
it 'has an owner' do
planting.owner.should be_an_instance_of Member

View File

@@ -53,7 +53,7 @@ describe "gardens/show" do
end
it 'should have an edit button' do
rendered.should have_content 'Edit'
rendered.should have_link 'edit_garden_link'
end
it "shows a 'plant something' button" do