mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-11 01:05:01 -04:00
Merge branch 'dev' into bump_ruby_22x
This commit is contained in:
8
Gemfile
8
Gemfile
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
|
||||
|
||||
ruby '2.2.4'
|
||||
|
||||
gem 'rails', '4.1.11'
|
||||
gem 'rails', '~> 4.1.11'
|
||||
|
||||
gem 'bundler', '>=1.1.5'
|
||||
|
||||
@@ -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'
|
||||
@@ -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'
|
||||
@@ -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'
|
||||
|
||||
128
Gemfile.lock
128
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)
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -265,22 +265,22 @@ 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_portile (0.6.1)
|
||||
minitest (5.8.0)
|
||||
mini_portile2 (2.0.0)
|
||||
minitest (5.8.4)
|
||||
multi_json (1.11.2)
|
||||
multi_xml (0.5.5)
|
||||
multipart-post (2.0.0)
|
||||
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)
|
||||
@@ -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,13 +338,13 @@ 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)
|
||||
rake (10.4.2)
|
||||
rake (11.1.2)
|
||||
rb-fsevent (0.9.5)
|
||||
rb-inotify (0.9.5)
|
||||
ffi (>= 0.5.0)
|
||||
@@ -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)
|
||||
@@ -407,7 +408,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)
|
||||
@@ -424,7 +425,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)
|
||||
@@ -434,7 +435,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)
|
||||
@@ -471,7 +472,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)
|
||||
@@ -507,16 +508,19 @@ DEPENDENCIES
|
||||
poltergeist (~> 1.6)
|
||||
pry
|
||||
quiet_assets
|
||||
rails (= 4.1.11)
|
||||
rails (~> 4.1.11)
|
||||
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
|
||||
therubyracer (~> 0.12)
|
||||
uglifier (~> 2.5.3)
|
||||
uglifier (~> 2.7.2)
|
||||
unicorn
|
||||
webrat
|
||||
will_paginate (~> 3.0)
|
||||
|
||||
BUNDLED WITH
|
||||
1.11.2
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) }
|
||||
|
||||
|
||||
@@ -109,6 +109,26 @@ class Planting < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def planted?(current_date = Date.today)
|
||||
planted_at.present? && current_date.to_date >= planted_at
|
||||
end
|
||||
|
||||
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
|
||||
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.
|
||||
@@ -116,7 +136,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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
- if (planting.planted_at.nil? || DateTime.now.to_date < planting.planted_at)
|
||||
- if !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}%"}
|
||||
= "Progress: #{planting.percentage_grown}%"
|
||||
= render partial: "plantings/progress_bar", locals: {status: "success", progress: "#{planting.percentage_grown}%"}
|
||||
|
||||
@@ -38,4 +38,4 @@
|
||||
%dd= "#{display_days_before_maturity(planting)}"
|
||||
|
||||
.col-xs-9.col-md-8
|
||||
= render partial: 'plantings/planting_progress', locals: {:planting => planting}
|
||||
= render partial: 'plantings/planting_progress', locals: {planting: planting}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
- 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']}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -26,7 +27,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 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
|
||||
@@ -61,6 +64,7 @@ feature "Harvesting a crop", :js do
|
||||
visit crop_path(maize)
|
||||
click_link "Harvest this"
|
||||
within "form#new_harvest" do
|
||||
select plant_part.name, from: 'harvest[plant_part_id]'
|
||||
expect(page).to have_selector "input[value='maize']"
|
||||
click_button "Save"
|
||||
end
|
||||
|
||||
@@ -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
|
||||
@@ -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?"
|
||||
@@ -87,7 +90,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
|
||||
|
||||
@@ -95,25 +98,25 @@ 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
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
@@ -169,13 +172,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
|
||||
|
||||
@@ -37,16 +37,62 @@ 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 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(Date.today).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
|
||||
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
|
||||
@@ -267,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
|
||||
@@ -28,6 +28,19 @@ 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
|
||||
controller.stub(:current_user) { @wrangler }
|
||||
render
|
||||
end
|
||||
|
||||
it 'should have an edit button' do
|
||||
rendered.should have_content 'Edit'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user