mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-24 01:32:40 -04:00
Merge branch 'dev' into fix/1211
This commit is contained in:
3
Gemfile
3
Gemfile
@@ -11,6 +11,9 @@ gem 'coffee-rails'
|
||||
gem 'haml'
|
||||
gem 'sass-rails'
|
||||
|
||||
# API data
|
||||
gem 'jsonapi-resources'
|
||||
|
||||
# CSS framework
|
||||
gem 'bootstrap-sass'
|
||||
gem 'font-awesome-sass'
|
||||
|
||||
@@ -277,6 +277,10 @@ GEM
|
||||
railties (>= 3.2)
|
||||
sprockets-rails
|
||||
json (2.1.0)
|
||||
jsonapi-resources (0.9.0)
|
||||
activerecord (>= 4.1)
|
||||
concurrent-ruby
|
||||
railties (>= 4.1)
|
||||
jwt (1.5.6)
|
||||
kaminari (1.1.1)
|
||||
activesupport (>= 4.1.0)
|
||||
@@ -420,7 +424,7 @@ GEM
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
rainbow (2.1.0)
|
||||
raindrops (0.19.0)
|
||||
rake (12.2.1)
|
||||
rake (12.3.0)
|
||||
rb-fsevent (0.10.2)
|
||||
rb-inotify (0.9.10)
|
||||
ffi (>= 0.5.0, < 2)
|
||||
@@ -591,6 +595,7 @@ DEPENDENCIES
|
||||
jquery-rails
|
||||
jquery-ui-rails (~> 5.0.2)
|
||||
js-routes
|
||||
jsonapi-resources
|
||||
kaminari
|
||||
leaflet-markercluster-rails
|
||||
leaflet-rails
|
||||
|
||||
7
app/controllers/api/v1/base_controller.rb
Normal file
7
app/controllers/api/v1/base_controller.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
module Api
|
||||
module V1
|
||||
class BaseController < JSONAPI::ResourceController
|
||||
abstract
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/crops_controller.rb
Normal file
6
app/controllers/api/v1/crops_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class CropsController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/gardens_controller.rb
Normal file
6
app/controllers/api/v1/gardens_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class GardensController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/harvests_controller.rb
Normal file
6
app/controllers/api/v1/harvests_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class HarvestsController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/members_controller.rb
Normal file
6
app/controllers/api/v1/members_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class MembersController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/photos_controller.rb
Normal file
6
app/controllers/api/v1/photos_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class PhotosController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/plantings_controller.rb
Normal file
6
app/controllers/api/v1/plantings_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class PlantingsController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/seeds_controller.rb
Normal file
6
app/controllers/api/v1/seeds_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class SeedsController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -17,10 +17,8 @@ class PhotosController < ApplicationController
|
||||
end
|
||||
|
||||
def new
|
||||
@type = params[:type]
|
||||
@id = params[:id]
|
||||
|
||||
@photo = Photo.new
|
||||
@item = item_to_link_to
|
||||
retrieve_from_flickr
|
||||
respond_with @photo
|
||||
end
|
||||
@@ -30,9 +28,13 @@ class PhotosController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
find_or_create_photo_from_flickr_photo
|
||||
add_photo_to_collection
|
||||
@photo.save if @photo.present?
|
||||
ActiveRecord::Base.transaction do
|
||||
@photo = find_or_create_photo_from_flickr_photo
|
||||
@item = item_to_link_to
|
||||
raise "Could not find this #{type} owned by you" unless @item
|
||||
collection << @item unless collection.include?(@item)
|
||||
@photo.save! if @photo.present?
|
||||
end
|
||||
respond_with @photo
|
||||
end
|
||||
|
||||
@@ -48,8 +50,14 @@ class PhotosController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def item_id?
|
||||
params.key? :id
|
||||
#
|
||||
# Params
|
||||
def item_id
|
||||
params[:id]
|
||||
end
|
||||
|
||||
def item_type
|
||||
params[:type]
|
||||
end
|
||||
|
||||
def flickr_photo_id_param
|
||||
@@ -61,26 +69,32 @@ class PhotosController < ApplicationController
|
||||
:license_url, :thumbnail_url, :fullsize_url, :link_url)
|
||||
end
|
||||
|
||||
def find_or_create_photo_from_flickr_photo
|
||||
@photo = Photo.find_by(flickr_photo_id: flickr_photo_id_param)
|
||||
@photo = Photo.new(photo_params) unless @photo
|
||||
@photo.owner_id = current_member.id
|
||||
@photo.set_flickr_metadata
|
||||
@photo
|
||||
# Item with photos attached
|
||||
#
|
||||
def item_to_link_to
|
||||
raise "No item id provided" if item_id.nil?
|
||||
raise "No item type provided" if item_type.nil?
|
||||
raise "Missing or invalid type provided" unless photos_supported_on_type?(item_type)
|
||||
item_class = Growstuff::Constants::PhotoModels.get_item(item_type)
|
||||
item_class.find_by!(id: params[:id], owner_id: current_member.id)
|
||||
end
|
||||
|
||||
def add_photo_to_collection
|
||||
raise "Missing or invalid type provided" unless Growstuff::Constants::PhotoModels.types.include?(params[:type])
|
||||
raise "No item id provided" unless item_id?
|
||||
collection = Growstuff::Constants::PhotoModels.get_relation(@photo, params[:type])
|
||||
def collection
|
||||
Growstuff::Constants::PhotoModels.get_relation(@photo, item_type)
|
||||
end
|
||||
|
||||
item_class = Growstuff::Constants::PhotoModels.get_item(params[:type])
|
||||
item = item_class.find_by!(id: params[:id], owner_id: current_member.id)
|
||||
raise "Could not find this item owned by you" unless item
|
||||
def photos_supported_on_type?(_type)
|
||||
Growstuff::Constants::PhotoModels.types.include?(item_type)
|
||||
end
|
||||
|
||||
collection << item unless collection.include?(item)
|
||||
rescue => e
|
||||
flash[:alert] = e.message
|
||||
#
|
||||
# Flickr retrieval
|
||||
def find_or_create_photo_from_flickr_photo
|
||||
photo = Photo.find_by(flickr_photo_id: flickr_photo_id_param)
|
||||
photo ||= Photo.new(photo_params)
|
||||
photo.owner_id = current_member.id
|
||||
photo.set_flickr_metadata
|
||||
photo
|
||||
end
|
||||
|
||||
def retrieve_from_flickr
|
||||
|
||||
@@ -102,22 +102,11 @@ class Crop < ActiveRecord::Base
|
||||
Photo.joins(:harvests).where("harvests.crop_id": id)
|
||||
end
|
||||
|
||||
def as_indexed_json(_options = {})
|
||||
as_json(
|
||||
only: [:id, :name, :approval_status],
|
||||
include: {
|
||||
scientific_names: { only: :name },
|
||||
alternate_names: { only: :name }
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
# update the Elasticsearch index (only if we're using it in this
|
||||
# environment)
|
||||
def update_index(_name_obj)
|
||||
__elasticsearch__.index_document if ENV["GROWSTUFF_ELASTICSEARCH"] == "true"
|
||||
end
|
||||
|
||||
# End Elasticsearch section
|
||||
|
||||
def to_s
|
||||
@@ -128,7 +117,6 @@ class Crop < ActiveRecord::Base
|
||||
scientific_names.first.name unless scientific_names.empty?
|
||||
end
|
||||
|
||||
# crop.default_photo
|
||||
# currently returns the first available photo, but exists so that
|
||||
# later we can choose a default photo based on different criteria,
|
||||
# eg. popularity
|
||||
@@ -140,7 +128,6 @@ class Crop < ActiveRecord::Base
|
||||
harvest_with_photo.photos.first if harvest_with_photo
|
||||
end
|
||||
|
||||
# crop.sunniness
|
||||
# returns hash indicating whether this crop is grown in
|
||||
# sun/semi-shade/shade
|
||||
# key: sunniness (eg. 'sun')
|
||||
@@ -149,7 +136,6 @@ class Crop < ActiveRecord::Base
|
||||
count_uses_of_property 'sunniness'
|
||||
end
|
||||
|
||||
# crop.planted_from
|
||||
# returns a hash of propagation methods (seed, seedling, etc),
|
||||
# key: propagation method (eg. 'seed')
|
||||
# value: count of how many times it's been used by plantings
|
||||
@@ -157,7 +143,6 @@ class Crop < ActiveRecord::Base
|
||||
count_uses_of_property 'planted_from'
|
||||
end
|
||||
|
||||
# crop.popular_plant_parts
|
||||
# returns a hash of most harvested plant parts (fruit, seed, etc)
|
||||
# key: plant part (eg. 'fruit')
|
||||
# value: count of how many times it's been used by harvests
|
||||
@@ -170,7 +155,7 @@ class Crop < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def annual?
|
||||
perennial != true
|
||||
!perennial
|
||||
end
|
||||
|
||||
def interesting?
|
||||
@@ -206,13 +191,10 @@ class Crop < ActiveRecord::Base
|
||||
reason_for_rejection
|
||||
end
|
||||
|
||||
# # Crop.search(string)
|
||||
def self.search(query)
|
||||
CropSearchService.search(query)
|
||||
end
|
||||
|
||||
def self.case_insensitive_name(name)
|
||||
where(["lower(crops.name) = :value", { value: name.downcase }])
|
||||
def update_medians
|
||||
plantings.each(&:update_harvest_days)
|
||||
update_lifespan_medians
|
||||
update_harvest_medians
|
||||
end
|
||||
|
||||
def update_lifespan_medians
|
||||
@@ -225,6 +207,14 @@ class Crop < ActiveRecord::Base
|
||||
update(median_days_to_last_harvest: Planting.where(crop: self).median(:days_to_last_harvest))
|
||||
end
|
||||
|
||||
def self.search(query)
|
||||
CropSearchService.search(query)
|
||||
end
|
||||
|
||||
def self.case_insensitive_name(name)
|
||||
where(["lower(crops.name) = :value", { value: name.downcase }])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def count_uses_of_property(col_name)
|
||||
|
||||
@@ -58,6 +58,7 @@ class Harvest < ActiveRecord::Base
|
||||
in: WEIGHT_UNITS_VALUES.values, message: "%<value>s is not a valid unit"
|
||||
}
|
||||
validate :crop_must_match_planting
|
||||
validate :owner_must_match_planting
|
||||
validate :harvest_must_be_after_planting
|
||||
|
||||
def time_from_planting_to_harvest
|
||||
@@ -131,6 +132,11 @@ class Harvest < ActiveRecord::Base
|
||||
errors.add(:planting, "must be the same crop") unless crop == planting.crop
|
||||
end
|
||||
|
||||
def owner_must_match_planting
|
||||
return if planting.blank? # only check if we are linked to a planting
|
||||
errors.add(:owner, "of harvest must be the same as planting") unless owner == planting.owner
|
||||
end
|
||||
|
||||
def harvest_must_be_after_planting
|
||||
# only check if we are linked to a planting
|
||||
return unless harvested_at.present? && planting.present? && planting.planted_at.present?
|
||||
|
||||
@@ -6,17 +6,9 @@ class Planting < ActiveRecord::Base
|
||||
# Constants
|
||||
SUNNINESS_VALUES = %w(sun semi-shade shade)
|
||||
PLANTED_FROM_VALUES = [
|
||||
'seed',
|
||||
'seedling',
|
||||
'cutting',
|
||||
'root division',
|
||||
'runner',
|
||||
'bulb',
|
||||
'root/tuber',
|
||||
'bare root plant',
|
||||
'advanced plant',
|
||||
'graft',
|
||||
'layering'
|
||||
'seed', 'seedling', 'cutting', 'root division', 'runner',
|
||||
'bulb', 'root/tuber', 'bare root plant', 'advanced plant',
|
||||
'graft', 'layering'
|
||||
]
|
||||
|
||||
##
|
||||
@@ -50,6 +42,7 @@ class Planting < ActiveRecord::Base
|
||||
validates :garden, presence: true
|
||||
validates :crop, presence: true, approved: { message: "must be present and exist in our database" }
|
||||
validate :finished_must_be_after_planted
|
||||
validate :owner_must_match_garden_owner
|
||||
validates :quantity, allow_nil: true, numericality: {
|
||||
only_integer: true, greater_than_or_equal_to: 0
|
||||
}
|
||||
@@ -123,12 +116,6 @@ class Planting < ActiveRecord::Base
|
||||
update(days_to_first_harvest: days_to_first_harvest, days_to_last_harvest: days_to_last_harvest)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def harvests_with_dates
|
||||
harvests.where.not(harvested_at: nil)
|
||||
end
|
||||
|
||||
def first_harvest_date
|
||||
harvests_with_dates.minimum(:harvested_at)
|
||||
end
|
||||
@@ -137,9 +124,19 @@ class Planting < ActiveRecord::Base
|
||||
harvests_with_dates.maximum(:harvested_at)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def harvests_with_dates
|
||||
harvests.where.not(harvested_at: nil)
|
||||
end
|
||||
|
||||
# check that any finished_at date occurs after planted_at
|
||||
def finished_must_be_after_planted
|
||||
return unless planted_at && finished_at # only check if we have both
|
||||
errors.add(:finished_at, "must be after the planting date") unless planted_at < finished_at
|
||||
end
|
||||
|
||||
def owner_must_match_garden_owner
|
||||
errors.add(:owner, "must be the same as garden") unless owner == garden.owner
|
||||
end
|
||||
end
|
||||
|
||||
8
app/resources/api/v1/base_resource.rb
Normal file
8
app/resources/api/v1/base_resource.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
module Api
|
||||
module V1
|
||||
class BaseResource < JSONAPI::Resource
|
||||
immutable
|
||||
abstract
|
||||
end
|
||||
end
|
||||
end
|
||||
22
app/resources/api/v1/crop_resource.rb
Normal file
22
app/resources/api/v1/crop_resource.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
module Api
|
||||
module V1
|
||||
class CropResource < BaseResource
|
||||
immutable
|
||||
|
||||
filter :approval_status, default: 'approved'
|
||||
|
||||
has_many :plantings
|
||||
has_many :photos
|
||||
has_many :harvests
|
||||
has_one :parent
|
||||
|
||||
attribute :name
|
||||
attribute :en_wikipedia_url
|
||||
|
||||
attribute :perennial
|
||||
attribute :median_lifespan
|
||||
attribute :median_days_to_first_harvest
|
||||
attribute :median_days_to_last_harvest
|
||||
end
|
||||
end
|
||||
end
|
||||
13
app/resources/api/v1/garden_resource.rb
Normal file
13
app/resources/api/v1/garden_resource.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module Api
|
||||
module V1
|
||||
class GardenResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_many :plantings
|
||||
has_many :photos
|
||||
|
||||
attribute :name
|
||||
end
|
||||
end
|
||||
end
|
||||
19
app/resources/api/v1/harvest_resource.rb
Normal file
19
app/resources/api/v1/harvest_resource.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module Api
|
||||
module V1
|
||||
class HarvestResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :crop
|
||||
has_one :planting
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_many :photos
|
||||
|
||||
attribute :harvested_at
|
||||
attribute :description
|
||||
attribute :unit
|
||||
attribute :weight_quantity
|
||||
attribute :weight_unit
|
||||
attribute :si_weight
|
||||
end
|
||||
end
|
||||
end
|
||||
15
app/resources/api/v1/member_resource.rb
Normal file
15
app/resources/api/v1/member_resource.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
module Api
|
||||
module V1
|
||||
class MemberResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_many :gardens
|
||||
has_many :plantings
|
||||
has_many :harvests
|
||||
has_many :seeds
|
||||
has_many :photos
|
||||
|
||||
attribute :login_name
|
||||
end
|
||||
end
|
||||
end
|
||||
18
app/resources/api/v1/photo_resource.rb
Normal file
18
app/resources/api/v1/photo_resource.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module Api
|
||||
module V1
|
||||
class PhotoResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_many :plantings
|
||||
has_many :gardens
|
||||
has_many :harvests
|
||||
|
||||
attribute :thumbnail_url
|
||||
attribute :fullsize_url
|
||||
attribute :license_name
|
||||
attribute :link_url
|
||||
attribute :title
|
||||
end
|
||||
end
|
||||
end
|
||||
28
app/resources/api/v1/planting_resource.rb
Normal file
28
app/resources/api/v1/planting_resource.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module Api
|
||||
module V1
|
||||
class PlantingResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :garden
|
||||
has_one :crop
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_many :photos
|
||||
has_many :harvests
|
||||
|
||||
attribute :planted_at
|
||||
attribute :finished_at
|
||||
attribute :finished
|
||||
attribute :quantity
|
||||
attribute :description
|
||||
attribute :sunniness
|
||||
attribute :planted_from
|
||||
|
||||
# Predictions
|
||||
attribute :expected_lifespan
|
||||
attribute :finish_predicted_at
|
||||
attribute :percentage_grown
|
||||
attribute :first_harvest_date
|
||||
attribute :last_harvest_date
|
||||
end
|
||||
end
|
||||
end
|
||||
20
app/resources/api/v1/seed_resource.rb
Normal file
20
app/resources/api/v1/seed_resource.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
module Api
|
||||
module V1
|
||||
class SeedResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_one :crop
|
||||
|
||||
attribute :description
|
||||
attribute :quantity
|
||||
attribute :plant_before
|
||||
attribute :tradable_to
|
||||
attribute :days_until_maturity_min
|
||||
attribute :days_until_maturity_max
|
||||
attribute :organic
|
||||
attribute :gmo
|
||||
attribute :heirloom
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -10,20 +10,20 @@
|
||||
an annual crop
|
||||
(living and reproducing in a single year or less)
|
||||
|
||||
- unless crop.median_lifespan.nil?
|
||||
- if crop.annual? && crop.median_lifespan.present?
|
||||
%p
|
||||
Median lifespan of #{crop.name} plants is
|
||||
%b= crop.median_lifespan
|
||||
%strong= crop.median_lifespan
|
||||
days
|
||||
|
||||
- unless crop.median_days_to_first_harvest.nil?
|
||||
- if crop.median_days_to_first_harvest.present?
|
||||
%p
|
||||
First harvest expected
|
||||
%b= crop.median_days_to_first_harvest
|
||||
%strong= crop.median_days_to_first_harvest
|
||||
days after planting
|
||||
|
||||
- if crop.perennial == false && crop.median_days_to_last_harvest.present?
|
||||
- if crop.annual? && crop.median_days_to_last_harvest.present?
|
||||
%p
|
||||
Last harvest expected
|
||||
%b= crop.median_days_to_last_harvest
|
||||
%strong= crop.median_days_to_last_harvest
|
||||
days after planting
|
||||
|
||||
@@ -91,8 +91,8 @@
|
||||
%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
|
||||
%span.glyphicon.glyphicon-camera{ title: "Add photo" }
|
||||
Add photo
|
||||
- if @garden.photos.size.positive?
|
||||
%h3= localize_plural(@garden.photos, Photo)
|
||||
.row
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
- content_for :title, "New Photo"
|
||||
|
||||
%h3
|
||||
Choose photo for
|
||||
= @item
|
||||
|
||||
- if @flickr_auth
|
||||
%p
|
||||
Connected to Flickr as
|
||||
|
||||
6
config/initializers/jsonapi_resources.rb
Normal file
6
config/initializers/jsonapi_resources.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
JSONAPI.configure do |config|
|
||||
# built in paginators are :none, :offset, :paged
|
||||
config.default_paginator = :offset
|
||||
config.default_page_size = 10
|
||||
config.maximum_page_size = 20
|
||||
end
|
||||
@@ -96,8 +96,19 @@ 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'
|
||||
namespace :api do
|
||||
namespace :v1 do
|
||||
jsonapi_resources :photos
|
||||
jsonapi_resources :crops
|
||||
jsonapi_resources :plantings
|
||||
jsonapi_resources :gardens
|
||||
jsonapi_resources :harvests
|
||||
jsonapi_resources :seeds
|
||||
jsonapi_resources :members
|
||||
end
|
||||
end
|
||||
|
||||
get '/.well-known/acme-challenge/:id' => 'pages#letsencrypt'
|
||||
# CMS stuff -- must remain LAST
|
||||
comfy_route :cms, path: '/', sitemap: false
|
||||
end
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe AccountTypesController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe AccountsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::OrdersController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe AdminController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe AuthenticationsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe CommentsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe CropsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ForumsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe GardensController, type: :controller do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe HarvestsController do
|
||||
@@ -25,63 +13,61 @@ describe HarvestsController do
|
||||
end
|
||||
|
||||
describe "GET index" do
|
||||
before do
|
||||
@member1 = FactoryBot.create(:member)
|
||||
@member2 = FactoryBot.create(:member)
|
||||
@tomato = FactoryBot.create(:tomato)
|
||||
@maize = FactoryBot.create(:maize)
|
||||
@harvest1 = FactoryBot.create(:harvest, owner_id: @member1.id, crop_id: @tomato.id)
|
||||
@harvest2 = FactoryBot.create(:harvest, owner_id: @member2.id, crop_id: @maize.id)
|
||||
let(:member1) { FactoryBot.create(:member) }
|
||||
let(:member2) { FactoryBot.create(:member) }
|
||||
let(:tomato) { FactoryBot.create(:tomato) }
|
||||
let(:maize) { FactoryBot.create(:maize) }
|
||||
let(:harvest1) { FactoryBot.create(:harvest, owner_id: member1.id, crop_id: tomato.id) }
|
||||
let(:harvest2) { FactoryBot.create(:harvest, owner_id: member2.id, crop_id: maize.id) }
|
||||
|
||||
describe "assigns all harvests as @harvests" do
|
||||
before { get :index, {} }
|
||||
it { assigns(:harvests).should =~ [harvest1, harvest2] }
|
||||
end
|
||||
|
||||
it "assigns all harvests as @harvests" do
|
||||
get :index, {}
|
||||
assigns(:harvests).should =~ [@harvest1, @harvest2]
|
||||
describe "picks up owner from params and shows owner's harvests only" do
|
||||
before { get :index, owner: member1.slug }
|
||||
it { expect(assigns(:owner)).to eq member1 }
|
||||
it { expect(assigns(:harvests)).to eq [harvest1] }
|
||||
end
|
||||
|
||||
it "picks up owner from params and shows owner's harvests only" do
|
||||
get :index, owner: @member1.slug
|
||||
assigns(:owner).should eq @member1
|
||||
assigns(:harvests).should eq [@harvest1]
|
||||
describe "picks up crop from params and shows the harvests for the crop only" do
|
||||
before { get :index, crop: maize.name }
|
||||
it { expect(assigns(:crop)).to eq maize }
|
||||
it { expect(assigns(:harvests)).to eq [harvest2] }
|
||||
end
|
||||
|
||||
it "picks up crop from params and shows the harvests for the crop only" do
|
||||
get :index, crop: @maize.name
|
||||
assigns(:crop).should eq @maize
|
||||
assigns(:harvests).should eq [@harvest2]
|
||||
end
|
||||
|
||||
it "generates a csv" do
|
||||
get :index, format: "csv"
|
||||
response.status.should eq 200
|
||||
describe "generates a csv" do
|
||||
before { get :index, format: "csv" }
|
||||
it { expect(response.status).to eq 200 }
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET show" do
|
||||
it "assigns the requested harvest as @harvest" do
|
||||
harvest = Harvest.create! valid_attributes
|
||||
get :show, id: harvest.to_param
|
||||
assigns(:harvest).should eq(harvest)
|
||||
let(:harvest) { Harvest.create! valid_attributes }
|
||||
describe "assigns the requested harvest as @harvest" do
|
||||
before { get :show, id: harvest.to_param }
|
||||
it { expect(assigns(:harvest)).to eq(harvest) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET new" do
|
||||
it "assigns a new harvest as @harvest" do
|
||||
get :new, {}
|
||||
assigns(:harvest).should be_a_new(Harvest)
|
||||
before { get :new, {} }
|
||||
|
||||
describe "assigns a new harvest as @harvest" do
|
||||
it { expect(assigns(:harvest)).to be_a_new(Harvest) }
|
||||
end
|
||||
|
||||
it "sets the date of the harvest to today" do
|
||||
get :new, {}
|
||||
assigns(:harvest).harvested_at.should == Time.zone.today
|
||||
describe "sets the date of the harvest to today" do
|
||||
it { expect(assigns(:harvest).harvested_at).to eq(Time.zone.today) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET edit" do
|
||||
it "assigns the requested harvest as @harvest" do
|
||||
harvest = Harvest.create! valid_attributes
|
||||
get :edit, id: harvest.to_param
|
||||
assigns(:harvest).should eq(harvest)
|
||||
let(:harvest) { Harvest.create! valid_attributes }
|
||||
describe "assigns the requested harvest as @harvest" do
|
||||
before { get :edit, id: harvest.to_param }
|
||||
it { expect(assigns(:harvest)).to eq(harvest) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -104,10 +90,10 @@ describe HarvestsController do
|
||||
response.should redirect_to(Harvest.last)
|
||||
end
|
||||
|
||||
it "links to planting" do
|
||||
planting = FactoryBot.create(:planting, owner_id: member.id)
|
||||
post :create, harvest: valid_attributes.merge(planting_id: planting.id)
|
||||
expect(Harvest.last.planting.id).to eq(planting.id)
|
||||
describe "links to planting" do
|
||||
let(:planting) { FactoryBot.create(:planting, owner_id: member.id, garden: member.gardens.first) }
|
||||
before { post :create, harvest: valid_attributes.merge(planting_id: planting.id) }
|
||||
it { expect(Harvest.last.planting.id).to eq(planting.id) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -129,10 +115,13 @@ describe HarvestsController do
|
||||
describe "not my planting" do
|
||||
let(:not_my_planting) { FactoryBot.create(:planting) }
|
||||
let(:harvest) { FactoryBot.create(:harvest) }
|
||||
it "does not save planting_id" do
|
||||
allow(Harvest).to receive(:new).and_return(harvest)
|
||||
post :create, harvest: valid_attributes.merge(planting_id: not_my_planting.id)
|
||||
expect(harvest.planting_id).to eq(nil)
|
||||
|
||||
describe "does not save planting_id" do
|
||||
before do
|
||||
allow(Harvest).to receive(:new).and_return(harvest)
|
||||
post :create, harvest: valid_attributes.merge(planting_id: not_my_planting.id)
|
||||
end
|
||||
it { expect(harvest.planting_id).not_to eq(not_my_planting.id) }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -181,10 +170,12 @@ describe HarvestsController do
|
||||
describe "not my planting" do
|
||||
let(:not_my_planting) { FactoryBot.create(:planting) }
|
||||
let(:harvest) { FactoryBot.create(:harvest) }
|
||||
it "does not save planting_id" do
|
||||
put :update, id: harvest.to_param,
|
||||
harvest: valid_attributes.merge(planting_id: not_my_planting.id)
|
||||
expect(harvest.planting_id).to eq(nil)
|
||||
describe "does not save planting_id" do
|
||||
before do
|
||||
put :update, id: harvest.to_param,
|
||||
harvest: valid_attributes.merge(planting_id: not_my_planting.id)
|
||||
end
|
||||
it { expect(harvest.planting_id).to eq(nil) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe HomeController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe MembersController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe NotificationsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe OrderItemsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe OrdersController do
|
||||
|
||||
@@ -1,15 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
@@ -34,45 +23,38 @@ describe PhotosController do
|
||||
end
|
||||
|
||||
describe "GET new" do
|
||||
let(:tomato) { FactoryBot.create(:tomato) }
|
||||
let(:planting) { FactoryBot.create(:planting, crop: tomato, owner: member) }
|
||||
let(:garden) { FactoryBot.create(:garden, owner: member) }
|
||||
let(:harvest) { FactoryBot.create(:harvest, owner: member) }
|
||||
let(:member) { FactoryBot.create(:member) }
|
||||
let!(:auth) { FactoryBot.create(:flickr_authentication, member: member) }
|
||||
|
||||
before(:each) do
|
||||
@member = FactoryBot.create(:member)
|
||||
sign_in @member
|
||||
@member.stub(:flickr_photos) { [[], 0] }
|
||||
@member.stub(:flickr_sets) { { "foo" => "bar" } }
|
||||
controller.stub(:current_member) { @member }
|
||||
sign_in member
|
||||
member.stub(:flickr_photos) { [[], 0] }
|
||||
member.stub(:flickr_sets) { { "foo" => "bar" } }
|
||||
controller.stub(:current_member) { member }
|
||||
end
|
||||
|
||||
it "assigns the flickr auth as @flickr_auth" do
|
||||
@auth = FactoryBot.create(:flickr_authentication, member: @member)
|
||||
get :new, {}
|
||||
assigns(:flickr_auth).should be_an_instance_of(Authentication)
|
||||
describe "planting photos" do
|
||||
before(:each) { get :new, type: "planting", id: planting.id }
|
||||
it { assigns(:flickr_auth).should be_an_instance_of(Authentication) }
|
||||
it { assigns(:item).should eq planting }
|
||||
it { expect(flash[:alert]).not_to be_present }
|
||||
it { expect(flash[:alert]).not_to be_present }
|
||||
end
|
||||
|
||||
it "assigns a planting id" do
|
||||
get :new, type: "planting", id: 5
|
||||
assigns(:id).should eq "5"
|
||||
assigns(:type).should eq "planting"
|
||||
expect(flash[:alert]).not_to be_present
|
||||
describe "harvest photos" do
|
||||
before { get :new, type: "harvest", id: harvest.id }
|
||||
it { assigns(:item).should eq harvest }
|
||||
it { expect(flash[:alert]).not_to be_present }
|
||||
end
|
||||
|
||||
it "assigns a harvest id" do
|
||||
get :new, type: "harvest", id: 5
|
||||
assigns(:id).should eq "5"
|
||||
assigns(:type).should eq "harvest"
|
||||
expect(flash[:alert]).not_to be_present
|
||||
end
|
||||
|
||||
it "assigns a garden id" do
|
||||
get :new, type: "garden", id: 5
|
||||
assigns(:id).should eq "5"
|
||||
assigns(:type).should eq "garden"
|
||||
expect(flash[:alert]).not_to be_present
|
||||
end
|
||||
|
||||
it "assigns the current set as @current_set" do
|
||||
get :new, set: 'foo'
|
||||
assigns(:current_set).should eq "foo"
|
||||
expect(flash[:alert]).not_to be_present
|
||||
describe "garden photos" do
|
||||
before { get :new, type: "garden", id: garden.id }
|
||||
it { assigns(:item).should eq garden }
|
||||
it { expect(flash[:alert]).not_to be_present }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -99,11 +81,13 @@ describe PhotosController do
|
||||
Photo.last.plantings.first.should eq planting
|
||||
end
|
||||
|
||||
it "doesn't attach a photo to a planting twice" do
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "planting", id: planting.id
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "planting", id: planting.id
|
||||
expect(flash[:alert]).not_to be_present
|
||||
Photo.last.plantings.size.should eq 1
|
||||
describe "doesn't attach a photo to a planting twice" do
|
||||
before do
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "planting", id: planting.id
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "planting", id: planting.id
|
||||
end
|
||||
it { expect(flash[:alert]).not_to be_present }
|
||||
it { expect(Photo.last.plantings.size).to eq 1 }
|
||||
end
|
||||
|
||||
it "attaches the photo to a harvest" do
|
||||
@@ -121,18 +105,20 @@ describe PhotosController do
|
||||
|
||||
it "doesn't attach photo to a comment" do
|
||||
comment = FactoryBot.create(:comment)
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "comment", id: comment.id
|
||||
expect(flash[:alert]).to be_present
|
||||
expect do
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "comment", id: comment.id
|
||||
end.to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe "for the second time" do
|
||||
let(:planting) { FactoryBot.create :planting, owner: member }
|
||||
it "does not add a photo twice" do
|
||||
expect do
|
||||
post :create, photo: { flickr_photo_id: 1 }
|
||||
post :create, photo: { flickr_photo_id: 1 }, id: planting.id, type: 'planting'
|
||||
end.to change(Photo, :count).by(1)
|
||||
expect do
|
||||
post :create, photo: { flickr_photo_id: 1 }
|
||||
post :create, photo: { flickr_photo_id: 1 }, id: planting.id, type: 'planting'
|
||||
end.to change(Photo, :count).by(0)
|
||||
end
|
||||
end
|
||||
@@ -159,16 +145,18 @@ describe PhotosController do
|
||||
it "does not create the planting/photo link" do
|
||||
# members will be auto-created, and different
|
||||
another_planting = FactoryBot.create(:planting)
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "planting", id: another_planting.id
|
||||
expect(flash[:alert]).to be_present
|
||||
expect do
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "planting", id: another_planting.id
|
||||
end.to raise_error(ActiveRecord::RecordNotFound)
|
||||
Photo.last.plantings.first.should_not eq another_planting
|
||||
end
|
||||
|
||||
it "does not create the harvest/photo link" do
|
||||
# members will be auto-created, and different
|
||||
another_harvest = FactoryBot.create(:harvest)
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "harvest", id: another_harvest.id
|
||||
expect(flash[:alert]).to be_present
|
||||
expect do
|
||||
post :create, photo: { flickr_photo_id: photo.flickr_photo_id }, type: "harvest", id: another_harvest.id
|
||||
end.to raise_error(ActiveRecord::RecordNotFound)
|
||||
Photo.last.harvests.first.should_not eq another_harvest
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe PlacesController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe PlantPartsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe PlantingsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe PostsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ProductsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe RegistrationsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe RolesController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ScientificNamesController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe SeedsController do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project.
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ShopController do
|
||||
|
||||
@@ -2,15 +2,20 @@
|
||||
|
||||
FactoryBot.define do
|
||||
factory :harvest do
|
||||
crop
|
||||
crop { planting.present? ? planting.crop : FactoryBot.create(:crop) }
|
||||
plant_part
|
||||
owner
|
||||
planting nil
|
||||
owner { planting.present? ? planting.owner : FactoryBot.create(:member) }
|
||||
harvested_at Time.zone.local(2015, 9, 17)
|
||||
quantity "3"
|
||||
unit "individual"
|
||||
weight_quantity 6
|
||||
weight_unit "kg"
|
||||
description "A lovely harvest"
|
||||
|
||||
factory :harvest_with_planting do
|
||||
planting
|
||||
end
|
||||
end
|
||||
|
||||
trait :long_description do
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
FactoryBot.define do
|
||||
factory :planting do
|
||||
garden
|
||||
owner
|
||||
garden { FactoryBot.create :garden, owner: owner }
|
||||
crop
|
||||
planted_at Time.zone.local(2014, 7, 30)
|
||||
quantity 33
|
||||
|
||||
@@ -169,41 +169,56 @@ feature "crop detail page", js: true do
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples "lots of harvests" do
|
||||
def planting
|
||||
FactoryBot.create :planting, crop: crop, planted_at: 100.days.ago, finished_at: 1.day.ago
|
||||
shared_examples "predicts harvest" do
|
||||
describe 'with harvest history data' do
|
||||
before do
|
||||
# 50 days to harvest
|
||||
FactoryBot.create(:harvest, harvested_at: 150.days.ago, crop: planting.crop,
|
||||
planting: FactoryBot.create(:planting, planted_at: 200.days.ago, crop: crop))
|
||||
# 20 days to harvest
|
||||
FactoryBot.create(:harvest, harvested_at: 180.days.ago, crop: planting.crop,
|
||||
planting: FactoryBot.create(:planting, planted_at: 200.days.ago, crop: crop))
|
||||
# 10 days to harvest
|
||||
FactoryBot.create(:harvest, harvested_at: 190.days.ago, crop: planting.crop,
|
||||
planting: FactoryBot.create(:planting, planted_at: 200.days.ago, crop: crop))
|
||||
end
|
||||
it "predicts harvest" do
|
||||
is_expected.to have_text("First harvest expected 20 days after planting")
|
||||
end
|
||||
end
|
||||
before do
|
||||
# 50 days to harvest
|
||||
FactoryBot.create(:harvest, harvested_at: 50.days.ago, crop: crop, planting: planting)
|
||||
# 20 days to harvest
|
||||
FactoryBot.create(:harvest, harvested_at: 80.days.ago, crop: crop, planting: planting)
|
||||
# 10 days to harvest
|
||||
FactoryBot.create(:harvest, harvested_at: 90.days.ago, crop: crop, planting: planting)
|
||||
planting.crop.plantings.each(&:update_harvest_days)
|
||||
planting.crop.update_lifespan_medians
|
||||
planting.crop.update_harvest_medians
|
||||
end
|
||||
it { is_expected.to have_text("First harvest expected 20 days after planting") }
|
||||
it { is_expected.to have_text "Median lifespan of #{crop.name} plants is 99 days" }
|
||||
end
|
||||
|
||||
subject do
|
||||
# Update the medians after all the
|
||||
# data has been loaded
|
||||
crop.reload
|
||||
crop.update_medians
|
||||
|
||||
visit crop_path(crop)
|
||||
page
|
||||
end
|
||||
|
||||
context 'predictions' do
|
||||
let!(:planting) do
|
||||
FactoryBot.create(:planting, crop: crop,
|
||||
planted_at: 100.days.ago,
|
||||
finished_at: 1.day.ago)
|
||||
end
|
||||
context 'crop is an annual' do
|
||||
let(:crop) { FactoryBot.create :annual_crop }
|
||||
let(:crop) { FactoryBot.create(:annual_crop) }
|
||||
|
||||
describe 'with no harvests' do
|
||||
end
|
||||
|
||||
describe 'with harvests' do
|
||||
include_examples "lots of harvests"
|
||||
include_examples "predicts harvest"
|
||||
end
|
||||
it do
|
||||
|
||||
it "predicts lifespan" do
|
||||
is_expected.to have_text "Median lifespan of #{crop.name} plants is 99 days"
|
||||
end
|
||||
|
||||
it "describes annual crops" do
|
||||
is_expected.to have_text(
|
||||
"#{crop.name} is an annual crop (living and reproducing in a single year or less)"
|
||||
)
|
||||
@@ -217,9 +232,12 @@ feature "crop detail page", js: true do
|
||||
end
|
||||
|
||||
describe 'with harvests' do
|
||||
include_examples "lots of harvests"
|
||||
include_examples "predicts harvest"
|
||||
end
|
||||
|
||||
it "describes perennial crops" do
|
||||
is_expected.to have_text("#{crop.name} is a perennial crop (living more than two years)")
|
||||
end
|
||||
it { is_expected.to have_text("#{crop.name} is a perennial crop (living more than two years)") }
|
||||
end
|
||||
|
||||
context 'crop perennial value is null' do
|
||||
@@ -229,7 +247,7 @@ feature "crop detail page", js: true do
|
||||
end
|
||||
|
||||
describe 'with harvests' do
|
||||
include_examples "lots of harvests"
|
||||
include_examples "predicts harvest"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,9 +2,9 @@ require 'rails_helper'
|
||||
|
||||
feature "Planting a crop", js: true do
|
||||
let!(:garden) { create :garden }
|
||||
let!(:planting) { create :planting, garden: garden, planted_at: Date.parse("2013-3-10") }
|
||||
let!(:planting) { create :planting, garden: garden, owner: garden.owner, planted_at: Date.parse("2013-3-10") }
|
||||
let!(:tomato) { create :tomato }
|
||||
let!(:finished_planting) { create :finished_planting, garden: garden, crop: tomato }
|
||||
let!(:finished_planting) { create :finished_planting, owner: garden.owner, garden: garden, crop: tomato }
|
||||
|
||||
background do
|
||||
login_as garden.owner
|
||||
|
||||
51
spec/features/photos/new_photo_spec.rb
Normal file
51
spec/features/photos/new_photo_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature "new photo page" do
|
||||
let(:photo) { FactoryBot.create :photo }
|
||||
|
||||
context "signed in member" do
|
||||
let(:member) { FactoryBot.create :member }
|
||||
|
||||
background { login_as member }
|
||||
|
||||
context "viewing a planting" do
|
||||
let(:planting) { FactoryBot.create :planting, owner: member }
|
||||
|
||||
scenario "add photo" do
|
||||
visit planting_path(planting)
|
||||
click_link "Add photo"
|
||||
expect(page).to have_text planting.crop.name
|
||||
end
|
||||
end
|
||||
|
||||
context "viewing a harvest" do
|
||||
let(:harvest) { FactoryBot.create :harvest, owner: member }
|
||||
|
||||
scenario "add photo" do
|
||||
visit harvest_path(harvest)
|
||||
click_link "Add photo"
|
||||
expect(page).to have_text harvest.crop.name
|
||||
end
|
||||
end
|
||||
|
||||
context "viewing a garden" do
|
||||
let(:garden) { FactoryBot.create :garden, owner: member }
|
||||
|
||||
scenario "add photo" do
|
||||
visit garden_path(garden)
|
||||
click_link "Add photo"
|
||||
expect(page).to have_text garden.name
|
||||
end
|
||||
end
|
||||
|
||||
pending "viewing a seed" do
|
||||
let(:seed) { FactoryBot.create :seed, owner: member }
|
||||
|
||||
scenario "add photo" do
|
||||
visit seed_path(seed)
|
||||
click_link "Add photo"
|
||||
expect(page).to have_text seed.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5,7 +5,9 @@ feature "Planting a crop", :js, :elasticsearch do
|
||||
let(:member) { create :member }
|
||||
let!(:maize) { create :maize }
|
||||
let(:garden) { create :garden, owner: member }
|
||||
let!(:planting) { create :planting, garden: garden, planted_at: Date.parse("2013-3-10") }
|
||||
let!(:planting) do
|
||||
create :planting, garden: garden, owner: member, planted_at: Date.parse("2013-3-10")
|
||||
end
|
||||
|
||||
background do
|
||||
login_as member
|
||||
|
||||
@@ -13,17 +13,37 @@ feature "signout" do
|
||||
expect(current_path).to eq crops_path
|
||||
end
|
||||
|
||||
scenario "after signout, redirect to signin page if page needs authentication" do
|
||||
models = %w[plantings harvests posts photos gardens seeds]
|
||||
models.each do |model|
|
||||
visit "/#{model}/new"
|
||||
shared_examples "sign-in redirects" do |path|
|
||||
scenario "after signout, redirect to signin page if page needs authentication" do
|
||||
visit path
|
||||
expect(current_path).to eq new_member_session_path
|
||||
expect(page).to have_http_status(200)
|
||||
fill_in 'Login', with: member.login_name
|
||||
fill_in 'Password', with: member.password
|
||||
click_button 'Sign in'
|
||||
expect(current_path).to eq "/#{model}/new"
|
||||
expect(page).to have_http_status(200)
|
||||
expect(current_path).to eq path
|
||||
click_link 'Sign out'
|
||||
expect(page).to have_http_status(200)
|
||||
expect(current_path).to eq new_member_session_path
|
||||
end
|
||||
end
|
||||
|
||||
let(:path) {}
|
||||
describe 'after signout, redirect to signin page if page needs authentication' do
|
||||
include_examples "sign-in redirects", "/plantings/new"
|
||||
include_examples "sign-in redirects", "/harvests/new"
|
||||
include_examples "sign-in redirects", "/posts/new"
|
||||
include_examples "sign-in redirects", "/gardens/new"
|
||||
include_examples "sign-in redirects", "/seeds/new"
|
||||
end
|
||||
|
||||
scenario 'photos' do
|
||||
garden = FactoryBot.create :garden, owner: member
|
||||
visit "/photos/new?id=#{garden.id}&type=garden"
|
||||
expect(current_path).to eq new_member_session_path
|
||||
expect(page).to have_http_status(200)
|
||||
# photos/new needs id&type params,
|
||||
# but these are stripped after signing in
|
||||
end
|
||||
end
|
||||
|
||||
@@ -348,7 +348,23 @@ describe Crop do
|
||||
end
|
||||
end
|
||||
|
||||
let(:maize) { FactoryBot.create(:maize) }
|
||||
let(:pp1) { FactoryBot.create(:plant_part) }
|
||||
let(:pp2) { FactoryBot.create(:plant_part) }
|
||||
|
||||
context "harvests" do
|
||||
let(:h1) do
|
||||
FactoryBot.create(:harvest,
|
||||
crop: maize,
|
||||
plant_part: pp1)
|
||||
end
|
||||
|
||||
let(:h2) do
|
||||
FactoryBot.create(:harvest,
|
||||
crop: maize,
|
||||
plant_part: pp2)
|
||||
end
|
||||
|
||||
it "has harvests" do
|
||||
crop = FactoryBot.create(:crop)
|
||||
harvest = FactoryBot.create(:harvest, crop: crop)
|
||||
@@ -356,20 +372,6 @@ describe Crop do
|
||||
end
|
||||
end
|
||||
|
||||
it 'has plant_parts' do
|
||||
@maize = FactoryBot.create(:maize)
|
||||
@pp1 = FactoryBot.create(:plant_part)
|
||||
@pp2 = FactoryBot.create(:plant_part)
|
||||
@h1 = FactoryBot.create(:harvest,
|
||||
crop: @maize,
|
||||
plant_part: @pp1)
|
||||
@h2 = FactoryBot.create(:harvest,
|
||||
crop: @maize,
|
||||
plant_part: @pp2)
|
||||
@maize.plant_parts.should include @pp1
|
||||
@maize.plant_parts.should include @pp2
|
||||
end
|
||||
|
||||
it "doesn't duplicate plant_parts" do
|
||||
@maize = FactoryBot.create(:maize)
|
||||
@pp1 = FactoryBot.create(:plant_part)
|
||||
@@ -385,9 +387,7 @@ describe Crop do
|
||||
context "search", :elasticsearch do
|
||||
let(:mushroom) { FactoryBot.create(:crop, name: 'mushroom') }
|
||||
|
||||
before do
|
||||
sync_elasticsearch([mushroom])
|
||||
end
|
||||
before { sync_elasticsearch([mushroom]) }
|
||||
|
||||
it "finds exact matches" do
|
||||
Crop.search('mushroom').should eq [mushroom]
|
||||
|
||||
@@ -64,30 +64,30 @@ describe Garden do
|
||||
let(:walnut) { FactoryBot.create(:walnut) }
|
||||
|
||||
it "should fetch < 4 featured plantings if insufficient exist" do
|
||||
@p1 = FactoryBot.create(:planting, crop: tomato, garden: garden)
|
||||
@p2 = FactoryBot.create(:planting, crop: maize, garden: garden)
|
||||
@p1 = FactoryBot.create(:planting, crop: tomato, garden: garden, owner: garden.owner)
|
||||
@p2 = FactoryBot.create(:planting, crop: maize, garden: garden, owner: garden.owner)
|
||||
|
||||
garden.featured_plantings.should eq [@p2, @p1]
|
||||
end
|
||||
|
||||
it "should fetch most recent 4 featured plantings" do
|
||||
@p1 = FactoryBot.create(:planting, crop: tomato, garden: garden)
|
||||
@p2 = FactoryBot.create(:planting, crop: maize, garden: garden)
|
||||
@p3 = FactoryBot.create(:planting, crop: chard, garden: garden)
|
||||
@p4 = FactoryBot.create(:planting, crop: apple, garden: garden)
|
||||
@p5 = FactoryBot.create(:planting, crop: walnut, garden: garden)
|
||||
@p1 = FactoryBot.create(:planting, crop: tomato, garden: garden, owner: garden.owner)
|
||||
@p2 = FactoryBot.create(:planting, crop: maize, garden: garden, owner: garden.owner)
|
||||
@p3 = FactoryBot.create(:planting, crop: chard, garden: garden, owner: garden.owner)
|
||||
@p4 = FactoryBot.create(:planting, crop: apple, garden: garden, owner: garden.owner)
|
||||
@p5 = FactoryBot.create(:planting, crop: walnut, garden: garden, owner: garden.owner)
|
||||
|
||||
garden.featured_plantings.should eq [@p5, @p4, @p3, @p2]
|
||||
end
|
||||
|
||||
it "should skip repeated plantings" do
|
||||
@p1 = FactoryBot.create(:planting, crop: tomato, garden: garden)
|
||||
@p2 = FactoryBot.create(:planting, crop: maize, garden: garden)
|
||||
@p3 = FactoryBot.create(:planting, crop: chard, garden: garden)
|
||||
@p4 = FactoryBot.create(:planting, crop: apple, garden: garden)
|
||||
@p5 = FactoryBot.create(:planting, crop: walnut, garden: garden)
|
||||
@p6 = FactoryBot.create(:planting, crop: apple, garden: garden)
|
||||
@p7 = FactoryBot.create(:planting, crop: pear, garden: garden)
|
||||
@p1 = FactoryBot.create(:planting, crop: tomato, garden: garden, owner: garden.owner)
|
||||
@p2 = FactoryBot.create(:planting, crop: maize, garden: garden, owner: garden.owner)
|
||||
@p3 = FactoryBot.create(:planting, crop: chard, garden: garden, owner: garden.owner)
|
||||
@p4 = FactoryBot.create(:planting, crop: apple, garden: garden, owner: garden.owner)
|
||||
@p5 = FactoryBot.create(:planting, crop: walnut, garden: garden, owner: garden.owner)
|
||||
@p6 = FactoryBot.create(:planting, crop: apple, garden: garden, owner: garden.owner)
|
||||
@p7 = FactoryBot.create(:planting, crop: pear, garden: garden, owner: garden.owner)
|
||||
|
||||
garden.featured_plantings.should eq [@p7, @p6, @p5, @p3]
|
||||
end
|
||||
@@ -103,8 +103,8 @@ describe Garden do
|
||||
|
||||
it "destroys plantings when deleted" do
|
||||
garden = FactoryBot.create(:garden, owner: owner)
|
||||
@planting1 = FactoryBot.create(:planting, garden: garden)
|
||||
@planting2 = FactoryBot.create(:planting, garden: garden)
|
||||
@planting1 = FactoryBot.create(:planting, garden: garden, owner: garden.owner)
|
||||
@planting2 = FactoryBot.create(:planting, garden: garden, owner: garden.owner)
|
||||
garden.plantings.size.should eq(2)
|
||||
all = Planting.count
|
||||
garden.destroy
|
||||
@@ -185,8 +185,8 @@ describe Garden do
|
||||
|
||||
it "marks plantings as finished when garden is inactive" do
|
||||
garden = FactoryBot.create(:garden)
|
||||
p1 = FactoryBot.create(:planting, garden: garden)
|
||||
p2 = FactoryBot.create(:planting, garden: garden)
|
||||
p1 = FactoryBot.create(:planting, garden: garden, owner: garden.owner)
|
||||
p2 = FactoryBot.create(:planting, garden: garden, owner: garden.owner)
|
||||
|
||||
p1.finished.should eq false
|
||||
p2.finished.should eq false
|
||||
@@ -203,8 +203,8 @@ describe Garden do
|
||||
it "doesn't mark the wrong plantings as finished" do
|
||||
g1 = FactoryBot.create(:garden)
|
||||
g2 = FactoryBot.create(:garden)
|
||||
p1 = FactoryBot.create(:planting, garden: g1)
|
||||
p2 = FactoryBot.create(:planting, garden: g2)
|
||||
p1 = FactoryBot.create(:planting, garden: g1, owner: g1.owner)
|
||||
p2 = FactoryBot.create(:planting, garden: g2, owner: g2.owner)
|
||||
|
||||
# mark the garden as inactive
|
||||
g1.active = false
|
||||
|
||||
@@ -4,7 +4,7 @@ describe Planting do
|
||||
let(:crop) { FactoryBot.create(:tomato) }
|
||||
let(:garden_owner) { FactoryBot.create(:member) }
|
||||
let(:garden) { FactoryBot.create(:garden, owner: garden_owner) }
|
||||
let(:planting) { FactoryBot.create(:planting, crop: crop, garden: garden) }
|
||||
let(:planting) { FactoryBot.create(:planting, crop: crop, garden: garden, owner: garden.owner) }
|
||||
let(:finished_planting) do
|
||||
FactoryBot.create :planting, planted_at: 4.days.ago, finished_at: 2.days.ago, finished: true
|
||||
end
|
||||
@@ -120,7 +120,10 @@ describe Planting do
|
||||
describe 'planting has first harvest' do
|
||||
let(:planting) { FactoryBot.create :planting, planted_at: 100.days.ago }
|
||||
before do
|
||||
FactoryBot.create :harvest, planting: planting, crop: planting.crop, harvested_at: 10.days.ago
|
||||
FactoryBot.create(:harvest,
|
||||
planting: planting,
|
||||
crop: planting.crop,
|
||||
harvested_at: 10.days.ago)
|
||||
planting.update_harvest_days
|
||||
planting.crop.update_harvest_medians
|
||||
end
|
||||
@@ -148,12 +151,6 @@ describe Planting do
|
||||
planting.owner.should be_an_instance_of Member
|
||||
end
|
||||
|
||||
it "owner isn't necessarily the garden owner" do
|
||||
# a new owner should be created automatically by FactoryBot
|
||||
# note that formerly, the planting belonged to an owner through the garden
|
||||
planting.owner.should_not eq garden_owner
|
||||
end
|
||||
|
||||
it "generates a location" do
|
||||
planting.location.should eq "#{garden_owner.login_name}'s #{garden.name}"
|
||||
end
|
||||
@@ -355,7 +352,8 @@ describe Planting do
|
||||
# this one is newer, and has the same owner, through the garden
|
||||
@planting2 = FactoryBot.create(:planting,
|
||||
created_at: 1.minute.ago,
|
||||
owner_id: @planting1.owner.id)
|
||||
garden: @planting1.garden,
|
||||
owner: @planting1.owner)
|
||||
@planting2.photos << FactoryBot.create(:photo)
|
||||
@planting2.save
|
||||
|
||||
|
||||
87
spec/requests/api/v1/crop_request_spec.rb
Normal file
87
spec/requests/api/v1/crop_request_spec.rb
Normal file
@@ -0,0 +1,87 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Plantings', type: :request do
|
||||
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
|
||||
let!(:crop) { FactoryBot.create :crop }
|
||||
let(:crop_encoded_as_json_api) do
|
||||
{ "id" => crop.id.to_s,
|
||||
"type" => "crops",
|
||||
"links" => { "self" => resource_url },
|
||||
"attributes" => attributes,
|
||||
"relationships" => {
|
||||
"plantings" => plantings_as_json_api,
|
||||
"parent" => parent_as_json_api,
|
||||
"photos" => photos_as_json_api,
|
||||
"harvests" => harvests_as_json_api
|
||||
} }
|
||||
end
|
||||
|
||||
let(:resource_url) { "http://www.example.com/api/v1/crops/#{crop.id}" }
|
||||
|
||||
let(:harvests_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/harvests",
|
||||
"related" => "#{resource_url}/harvests" } }
|
||||
end
|
||||
|
||||
let(:parent_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/parent",
|
||||
"related" => "#{resource_url}/parent" } }
|
||||
end
|
||||
|
||||
let(:plantings_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" =>
|
||||
"#{resource_url}/relationships/plantings",
|
||||
"related" => "#{resource_url}/plantings" } }
|
||||
end
|
||||
|
||||
let(:photos_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/photos",
|
||||
"related" => "#{resource_url}/photos" } }
|
||||
end
|
||||
|
||||
let(:attributes) do
|
||||
{
|
||||
"name" => crop.name,
|
||||
"en-wikipedia-url" => crop.en_wikipedia_url,
|
||||
"perennial" => false,
|
||||
"median-lifespan" => nil,
|
||||
"median-days-to-first-harvest" => nil,
|
||||
"median-days-to-last-harvest" => nil
|
||||
}
|
||||
end
|
||||
|
||||
subject { JSON.parse response.body }
|
||||
describe '#index' do
|
||||
before { get '/api/v1/crops', {}, headers }
|
||||
it { expect(subject['data']).to include(crop_encoded_as_json_api) }
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
before { get "/api/v1/crops/#{crop.id}", {}, headers }
|
||||
it { expect(subject['data']['attributes']).to eq(attributes) }
|
||||
it { expect(subject['data']['relationships']).to include("plantings" => plantings_as_json_api) }
|
||||
it { expect(subject['data']['relationships']).to include("harvests" => harvests_as_json_api) }
|
||||
it { expect(subject['data']['relationships']).to include("photos" => photos_as_json_api) }
|
||||
it { expect(subject['data']['relationships']).to include("parent" => parent_as_json_api) }
|
||||
it { expect(subject['data']).to eq(crop_encoded_as_json_api) }
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
before { post '/api/v1/crops', { 'crop' => { 'name' => 'can i make this' } }, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
before { post "/api/v1/crops/#{crop.id}", { 'crop' => { 'name' => 'can i modify this' } }, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
|
||||
describe '#delete' do
|
||||
before { delete "/api/v1/crops/#{crop.id}", {}, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
end
|
||||
64
spec/requests/api/v1/gardens_request_spec.rb
Normal file
64
spec/requests/api/v1/gardens_request_spec.rb
Normal file
@@ -0,0 +1,64 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Gardens', type: :request do
|
||||
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
|
||||
let!(:garden) { FactoryBot.create :garden }
|
||||
let(:garden_encoded_as_json_api) do
|
||||
{ "id" => garden.id.to_s,
|
||||
"type" => "gardens",
|
||||
"links" => { "self" => resource_url },
|
||||
"attributes" => { "name" => garden.name },
|
||||
"relationships" =>
|
||||
{
|
||||
"owner" => owner_as_json_api,
|
||||
"plantings" => plantings_as_json_api,
|
||||
"photos" => photos_as_json_api
|
||||
} }
|
||||
end
|
||||
let(:resource_url) { "http://www.example.com/api/v1/gardens/#{garden.id}" }
|
||||
|
||||
let(:plantings_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" =>
|
||||
"#{resource_url}/relationships/plantings",
|
||||
"related" => "#{resource_url}/plantings" } }
|
||||
end
|
||||
|
||||
let(:owner_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/owner",
|
||||
"related" => "#{resource_url}/owner" } }
|
||||
end
|
||||
|
||||
let(:photos_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/photos",
|
||||
"related" => "#{resource_url}/photos" } }
|
||||
end
|
||||
|
||||
subject { JSON.parse response.body }
|
||||
scenario '#index' do
|
||||
get '/api/v1/gardens', {}, headers
|
||||
expect(subject['data']).to include(garden_encoded_as_json_api)
|
||||
end
|
||||
|
||||
scenario '#show' do
|
||||
get "/api/v1/gardens/#{garden.id}", {}, headers
|
||||
expect(subject['data']).to include(garden_encoded_as_json_api)
|
||||
end
|
||||
|
||||
scenario '#create' do
|
||||
post '/api/v1/gardens', { 'garden' => { 'name' => 'can i make this' } }, headers
|
||||
expect(response.code).to eq "404"
|
||||
end
|
||||
|
||||
scenario '#update' do
|
||||
post "/api/v1/gardens/#{garden.id}", { 'garden' => { 'name' => 'can i modify this' } }, headers
|
||||
expect(response.code).to eq "404"
|
||||
end
|
||||
|
||||
scenario '#delete' do
|
||||
delete "/api/v1/gardens/#{garden.id}", {}, headers
|
||||
expect(response.code).to eq "404"
|
||||
end
|
||||
end
|
||||
88
spec/requests/api/v1/harvest_request_spec.rb
Normal file
88
spec/requests/api/v1/harvest_request_spec.rb
Normal file
@@ -0,0 +1,88 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Harvests', type: :request do
|
||||
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
|
||||
let!(:harvest) { FactoryBot.create :harvest }
|
||||
let(:harvest_encoded_as_json_api) do
|
||||
{ "id" => harvest.id.to_s,
|
||||
"type" => "harvests",
|
||||
"links" => { "self" => resource_url },
|
||||
"attributes" => attributes,
|
||||
"relationships" => {
|
||||
"crop" => crop_as_json_api,
|
||||
"planting" => planting_as_json_api,
|
||||
"owner" => owner_as_json_api,
|
||||
"photos" => photos_as_json_api
|
||||
} }
|
||||
end
|
||||
|
||||
let(:resource_url) { "http://www.example.com/api/v1/harvests/#{harvest.id}" }
|
||||
|
||||
let(:crop_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" =>
|
||||
"#{resource_url}/relationships/crop",
|
||||
"related" => "#{resource_url}/crop" } }
|
||||
end
|
||||
|
||||
let(:owner_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/owner",
|
||||
"related" => "#{resource_url}/owner" } }
|
||||
end
|
||||
|
||||
let(:planting_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" =>
|
||||
"#{resource_url}/relationships/planting",
|
||||
"related" => "#{resource_url}/planting" } }
|
||||
end
|
||||
|
||||
let(:photos_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/photos",
|
||||
"related" => "#{resource_url}/photos" } }
|
||||
end
|
||||
|
||||
let(:attributes) do
|
||||
{
|
||||
"harvested-at" => "2015-09-17",
|
||||
"description" => harvest.description,
|
||||
"unit" => harvest.unit,
|
||||
"weight-quantity" => harvest.weight_quantity.to_s,
|
||||
"weight-unit" => harvest.weight_unit,
|
||||
"si-weight" => harvest.si_weight
|
||||
}
|
||||
end
|
||||
|
||||
subject { JSON.parse response.body }
|
||||
describe '#index' do
|
||||
before { get '/api/v1/harvests', {}, headers }
|
||||
it { expect(subject['data']).to include(harvest_encoded_as_json_api) }
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
before { get "/api/v1/harvests/#{harvest.id}", {}, headers }
|
||||
it { expect(subject['data']['attributes']).to eq(attributes) }
|
||||
it { expect(subject['data']['relationships']).to include("planting" => planting_as_json_api) }
|
||||
it { expect(subject['data']['relationships']).to include("crop" => crop_as_json_api) }
|
||||
it { expect(subject['data']['relationships']).to include("photos" => photos_as_json_api) }
|
||||
it { expect(subject['data']['relationships']).to include("owner" => owner_as_json_api) }
|
||||
it { expect(subject['data']).to eq(harvest_encoded_as_json_api) }
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
before { post '/api/v1/harvests', { 'harvest' => { 'description' => 'can i make this' } }, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
before { post "/api/v1/harvests/#{harvest.id}", { 'harvest' => { 'description' => 'can i modify this' } }, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
|
||||
describe '#delete' do
|
||||
before { delete "/api/v1/harvests/#{harvest.id}", {}, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
end
|
||||
88
spec/requests/api/v1/member_request_spec.rb
Normal file
88
spec/requests/api/v1/member_request_spec.rb
Normal file
@@ -0,0 +1,88 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Members', type: :request do
|
||||
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
|
||||
let!(:member) { FactoryBot.create :member }
|
||||
let(:member_encoded_as_json_api) do
|
||||
{ "id" => member.id.to_s,
|
||||
"type" => "members",
|
||||
"links" => { "self" => resource_url },
|
||||
"attributes" => attributes,
|
||||
"relationships" => {
|
||||
"gardens" => gardens_as_json_api,
|
||||
"harvests" => harvests_as_json_api,
|
||||
"photos" => photos_as_json_api,
|
||||
"plantings" => plantings_as_json_api,
|
||||
"seeds" => seeds_as_json_api
|
||||
} }
|
||||
end
|
||||
|
||||
let(:resource_url) { "http://www.example.com/api/v1/members/#{member.id}" }
|
||||
|
||||
let(:harvests_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/harvests",
|
||||
"related" => "#{resource_url}/harvests" } }
|
||||
end
|
||||
|
||||
let(:photos_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/photos",
|
||||
"related" => "#{resource_url}/photos" } }
|
||||
end
|
||||
|
||||
let(:seeds_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/seeds",
|
||||
"related" => "#{resource_url}/seeds" } }
|
||||
end
|
||||
|
||||
let(:plantings_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" =>
|
||||
"#{resource_url}/relationships/plantings",
|
||||
"related" => "#{resource_url}/plantings" } }
|
||||
end
|
||||
let(:gardens_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/gardens",
|
||||
"related" => "#{resource_url}/gardens" } }
|
||||
end
|
||||
|
||||
let(:attributes) do
|
||||
{
|
||||
"login-name" => member.login_name
|
||||
}
|
||||
end
|
||||
|
||||
subject { JSON.parse response.body }
|
||||
describe '#index' do
|
||||
before { get '/api/v1/members', {}, headers }
|
||||
it { expect(subject['data']).to include(member_encoded_as_json_api) }
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
before { get "/api/v1/members/#{member.id}", {}, headers }
|
||||
it { expect(subject['data']['relationships']).to include("gardens" => gardens_as_json_api) }
|
||||
it { expect(subject['data']['relationships']).to include("plantings" => plantings_as_json_api) }
|
||||
it { expect(subject['data']['relationships']).to include("seeds" => seeds_as_json_api) }
|
||||
it { expect(subject['data']['relationships']).to include("harvests" => harvests_as_json_api) }
|
||||
it { expect(subject['data']['relationships']).to include("photos" => photos_as_json_api) }
|
||||
it { expect(subject['data']).to eq(member_encoded_as_json_api) }
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
before { post '/api/v1/members', { 'member' => { 'login_name' => 'can i make this' } }, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
before { post "/api/v1/members/#{member.id}", { 'member' => { 'login_name' => 'can i modify this' } }, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
|
||||
describe '#delete' do
|
||||
before { delete "/api/v1/members/#{member.id}", {}, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
end
|
||||
85
spec/requests/api/v1/photos_request_spec.rb
Normal file
85
spec/requests/api/v1/photos_request_spec.rb
Normal file
@@ -0,0 +1,85 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Photos', type: :request do
|
||||
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
|
||||
let!(:photo) { FactoryBot.create :photo }
|
||||
let(:photo_encoded_as_json_api) do
|
||||
{ "id" => photo.id.to_s,
|
||||
"type" => "photos",
|
||||
"links" => { "self" => resource_url },
|
||||
"attributes" => attributes,
|
||||
"relationships" => {
|
||||
"owner" => owner_as_json_api,
|
||||
"plantings" => plantings_as_json_api,
|
||||
"harvests" => harvests_as_json_api,
|
||||
"gardens" => gardens_as_json_api
|
||||
} }
|
||||
end
|
||||
|
||||
let(:resource_url) { "http://www.example.com/api/v1/photos/#{photo.id}" }
|
||||
|
||||
let(:owner_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/owner",
|
||||
"related" => "#{resource_url}/owner" } }
|
||||
end
|
||||
|
||||
let(:harvests_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/harvests",
|
||||
"related" => "#{resource_url}/harvests" } }
|
||||
end
|
||||
|
||||
let(:gardens_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/gardens",
|
||||
"related" => "#{resource_url}/gardens" } }
|
||||
end
|
||||
|
||||
let(:plantings_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" =>
|
||||
"#{resource_url}/relationships/plantings",
|
||||
"related" => "#{resource_url}/plantings" } }
|
||||
end
|
||||
|
||||
let(:attributes) do
|
||||
{
|
||||
"thumbnail-url" => photo.thumbnail_url,
|
||||
"fullsize-url" => photo.fullsize_url,
|
||||
"link-url" => photo.link_url,
|
||||
"license-name" => photo.license_name,
|
||||
"title" => photo.title
|
||||
}
|
||||
end
|
||||
|
||||
subject { JSON.parse response.body }
|
||||
describe '#index' do
|
||||
before { get '/api/v1/photos', {}, headers }
|
||||
it { expect(subject['data']).to include(photo_encoded_as_json_api) }
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
before { get "/api/v1/photos/#{photo.id}", {}, headers }
|
||||
it { expect(subject['data']['attributes']).to eq(attributes) }
|
||||
it { expect(subject['data']['relationships']).to include("plantings" => plantings_as_json_api) }
|
||||
it { expect(subject['data']['relationships']).to include("harvests" => harvests_as_json_api) }
|
||||
it { expect(subject['data']['relationships']).to include("owner" => owner_as_json_api) }
|
||||
it { expect(subject['data']).to eq(photo_encoded_as_json_api) }
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
before { post '/api/v1/photos', { 'photo' => { 'name' => 'can i make this' } }, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
before { post "/api/v1/photos/#{photo.id}", { 'photo' => { 'name' => 'can i modify this' } }, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
|
||||
describe '#delete' do
|
||||
before { delete "/api/v1/photos/#{photo.id}", {}, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
end
|
||||
99
spec/requests/api/v1/plantings_request_spec.rb
Normal file
99
spec/requests/api/v1/plantings_request_spec.rb
Normal file
@@ -0,0 +1,99 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Plantings', type: :request do
|
||||
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
|
||||
let!(:planting) { FactoryBot.create :planting }
|
||||
let(:planting_encoded_as_json_api) do
|
||||
{ "id" => planting.id.to_s,
|
||||
"type" => "plantings",
|
||||
"links" => { "self" => resource_url },
|
||||
"attributes" => attributes,
|
||||
"relationships" => {
|
||||
"garden" => garden_as_json_api,
|
||||
"crop" => crop_as_json_api,
|
||||
"owner" => owner_as_json_api,
|
||||
"photos" => photos_as_json_api,
|
||||
"harvests" => harvests_as_json_api
|
||||
} }
|
||||
end
|
||||
|
||||
let(:resource_url) { "http://www.example.com/api/v1/plantings/#{planting.id}" }
|
||||
|
||||
let(:harvests_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/harvests",
|
||||
"related" => "#{resource_url}/harvests" } }
|
||||
end
|
||||
|
||||
let(:photos_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/photos",
|
||||
"related" => "#{resource_url}/photos" } }
|
||||
end
|
||||
|
||||
let(:owner_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/owner",
|
||||
"related" => "#{resource_url}/owner" } }
|
||||
end
|
||||
|
||||
let(:crop_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" =>
|
||||
"#{resource_url}/relationships/crop",
|
||||
"related" => "#{resource_url}/crop" } }
|
||||
end
|
||||
let(:garden_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/garden",
|
||||
"related" => "#{resource_url}/garden" } }
|
||||
end
|
||||
|
||||
let(:attributes) do
|
||||
{
|
||||
"planted-at" => "2014-07-30",
|
||||
"finished-at" => nil,
|
||||
"finished" => false,
|
||||
"quantity" => 33,
|
||||
"description" => planting.description,
|
||||
"sunniness" => nil,
|
||||
"planted-from" => nil,
|
||||
"expected-lifespan" => nil,
|
||||
"finish-predicted-at" => nil,
|
||||
"percentage-grown" => nil,
|
||||
"first-harvest-date" => nil,
|
||||
"last-harvest-date" => nil
|
||||
}
|
||||
end
|
||||
|
||||
subject { JSON.parse response.body }
|
||||
scenario '#index' do
|
||||
get '/api/v1/plantings', {}, headers
|
||||
expect(subject['data']).to include(planting_encoded_as_json_api)
|
||||
end
|
||||
|
||||
scenario '#show' do
|
||||
get "/api/v1/plantings/#{planting.id}", {}, headers
|
||||
expect(subject['data']['relationships']).to include("garden" => garden_as_json_api)
|
||||
expect(subject['data']['relationships']).to include("crop" => crop_as_json_api)
|
||||
expect(subject['data']['relationships']).to include("owner" => owner_as_json_api)
|
||||
expect(subject['data']['relationships']).to include("harvests" => harvests_as_json_api)
|
||||
expect(subject['data']['relationships']).to include("photos" => photos_as_json_api)
|
||||
expect(subject['data']).to eq(planting_encoded_as_json_api)
|
||||
end
|
||||
|
||||
scenario '#create' do
|
||||
post '/api/v1/plantings', { 'planting' => { 'description' => 'can i make this' } }, headers
|
||||
expect(response.code).to eq "404"
|
||||
end
|
||||
|
||||
scenario '#update' do
|
||||
post "/api/v1/plantings/#{planting.id}", { 'planting' => { 'description' => 'can i modify this' } }, headers
|
||||
expect(response.code).to eq "404"
|
||||
end
|
||||
|
||||
scenario '#delete' do
|
||||
delete "/api/v1/plantings/#{planting.id}", {}, headers
|
||||
expect(response.code).to eq "404"
|
||||
end
|
||||
end
|
||||
73
spec/requests/api/v1/seeds_request_spec.rb
Normal file
73
spec/requests/api/v1/seeds_request_spec.rb
Normal file
@@ -0,0 +1,73 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Photos', type: :request do
|
||||
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
|
||||
let!(:seed) { FactoryBot.create :seed }
|
||||
let(:seed_encoded_as_json_api) do
|
||||
{ "id" => seed.id.to_s,
|
||||
"type" => "seeds",
|
||||
"links" => { "self" => resource_url },
|
||||
"attributes" => attributes,
|
||||
"relationships" => {
|
||||
"owner" => owner_as_json_api,
|
||||
"crop" => crop_as_json_api
|
||||
} }
|
||||
end
|
||||
|
||||
let(:resource_url) { "http://www.example.com/api/v1/seeds/#{seed.id}" }
|
||||
|
||||
let(:owner_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/owner",
|
||||
"related" => "#{resource_url}/owner" } }
|
||||
end
|
||||
|
||||
let(:crop_as_json_api) do
|
||||
{ "links" =>
|
||||
{ "self" => "#{resource_url}/relationships/crop",
|
||||
"related" => "#{resource_url}/crop" } }
|
||||
end
|
||||
|
||||
let(:attributes) do
|
||||
{
|
||||
"description" => seed.description,
|
||||
"quantity" => seed.quantity,
|
||||
"plant-before" => "2013-07-15",
|
||||
"tradable-to" => seed.tradable_to,
|
||||
"days-until-maturity-min" => seed.days_until_maturity_min,
|
||||
"days-until-maturity-max" => seed.days_until_maturity_max,
|
||||
"organic" => seed.organic,
|
||||
"gmo" => seed.gmo,
|
||||
"heirloom" => seed.heirloom
|
||||
}
|
||||
end
|
||||
|
||||
subject { JSON.parse response.body }
|
||||
describe '#index' do
|
||||
before { get '/api/v1/seeds', {}, headers }
|
||||
it { expect(subject['data']).to include(seed_encoded_as_json_api) }
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
before { get "/api/v1/seeds/#{seed.id}", {}, headers }
|
||||
it { expect(subject['data']['attributes']).to eq(attributes) }
|
||||
it { expect(subject['data']['relationships']).to include("owner" => owner_as_json_api) }
|
||||
it { expect(subject['data']['relationships']).to include("crop" => crop_as_json_api) }
|
||||
it { expect(subject['data']).to eq(seed_encoded_as_json_api) }
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
before { post '/api/v1/seeds', { 'seed' => { 'name' => 'can i make this' } }, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
before { post "/api/v1/seeds/#{seed.id}", { 'seed' => { 'name' => 'can i modify this' } }, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
|
||||
describe '#delete' do
|
||||
before { delete "/api/v1/seeds/#{seed.id}", {}, headers }
|
||||
it { expect(response.code).to eq "404" }
|
||||
end
|
||||
end
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "account_types/edit" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "account_types/index" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "account_types/new" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "account_types/show" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "accounts/edit" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "accounts/index" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "accounts/new" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "accounts/show" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'admin/index.html.haml', type: "view" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'admin/newsletter.html.haml', type: "view" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'admin/orders/index.html.haml', type: "view" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "comments/edit" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "comments/index" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'comments/index.rss.haml' do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "comments/new" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "comments/show" do
|
||||
|
||||
@@ -1,29 +1,17 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "crops/_grown_for" do
|
||||
before(:each) do
|
||||
@crop = FactoryBot.create(:crop)
|
||||
@pp = FactoryBot.create(:plant_part)
|
||||
@harvest = FactoryBot.create(:harvest,
|
||||
crop: @crop,
|
||||
plant_part: @pp)
|
||||
let(:crop) { FactoryBot.create(:crop) }
|
||||
let(:plant_path) { FactoryBot.create(:plant_part) }
|
||||
let!(:harvest) do
|
||||
FactoryBot.create(:harvest,
|
||||
crop: crop,
|
||||
plant_part: plant_path)
|
||||
end
|
||||
|
||||
it 'shows plant parts' do
|
||||
render partial: 'crops/grown_for', locals: { crop: @crop }
|
||||
rendered.should have_content @pp.name
|
||||
assert_select "a", href: plant_part_path(@pp)
|
||||
render partial: 'crops/grown_for', locals: { crop: crop }
|
||||
rendered.should have_content plant_path.name
|
||||
assert_select "a", href: plant_part_path(plant_path)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,70 +1,62 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "crops/_planting_advice" do
|
||||
before(:each) do
|
||||
@owner = FactoryBot.create(:member)
|
||||
@crop = FactoryBot.create(:crop)
|
||||
@garden = FactoryBot.create(:garden, owner: @owner)
|
||||
@planting = FactoryBot.create(:planting,
|
||||
garden: @garden,
|
||||
crop: @crop)
|
||||
let(:planting) { FactoryBot.create(:planting) }
|
||||
subject { rendered }
|
||||
|
||||
shared_examples "render planting_advice" do
|
||||
before { render 'crops/planting_advice', crop: planting.crop }
|
||||
end
|
||||
|
||||
context "sunniness" do
|
||||
it "doesn't show sunniness if none are set" do
|
||||
render partial: 'crops/planting_advice', locals: { crop: @crop }
|
||||
rendered.should have_content "Plant in: not known."
|
||||
describe "sunniness" do
|
||||
context "with no sunniness set" do
|
||||
include_examples "render planting_advice"
|
||||
it "doesn't show sunniness" do
|
||||
is_expected.to have_content "Plant in: not known."
|
||||
end
|
||||
end
|
||||
|
||||
it "shows sunniness frequencies" do
|
||||
FactoryBot.create(:sunny_planting, crop: @crop)
|
||||
render partial: 'crops/planting_advice', locals: { crop: @crop }
|
||||
rendered.should have_content "Plant in:"
|
||||
rendered.should have_content "sun (1)"
|
||||
context "with sunniness frequencies" do
|
||||
before { FactoryBot.create(:sunny_planting, crop: planting.crop) }
|
||||
include_examples "render planting_advice"
|
||||
it { is_expected.to have_content "Plant in:" }
|
||||
it { is_expected.to have_content "sun (1)" }
|
||||
end
|
||||
|
||||
it "shows multiple sunniness frequencies" do
|
||||
FactoryBot.create(:sunny_planting, crop: @crop)
|
||||
FactoryBot.create(:sunny_planting, crop: @crop)
|
||||
FactoryBot.create(:shady_planting, crop: @crop)
|
||||
render partial: 'crops/planting_advice', locals: { crop: @crop }
|
||||
rendered.should have_content "Plant in:"
|
||||
rendered.should have_content "sun (2), shade (1)"
|
||||
context "with multiple sunniness frequencies" do
|
||||
before do
|
||||
FactoryBot.create_list(:sunny_planting, 2, crop: planting.crop)
|
||||
FactoryBot.create(:shady_planting, crop: planting.crop)
|
||||
end
|
||||
include_examples "render planting_advice"
|
||||
it { is_expected.to have_content "Plant in:" }
|
||||
it { is_expected.to have_content "sun (2), shade (1)" }
|
||||
end
|
||||
end
|
||||
|
||||
context "planted from" do
|
||||
it "doesn't show planted_from if none are set" do
|
||||
render partial: 'crops/planting_advice', locals: { crop: @crop }
|
||||
rendered.should have_content "Plant from: not known."
|
||||
describe "planted from" do
|
||||
context "when none are set" do
|
||||
include_examples "render planting_advice"
|
||||
it "doesn't show planted_from " do
|
||||
is_expected.to have_content "Plant from: not known."
|
||||
end
|
||||
end
|
||||
|
||||
it "shows planted_from frequencies" do
|
||||
FactoryBot.create(:seed_planting, crop: @crop)
|
||||
render partial: 'crops/planting_advice', locals: { crop: @crop }
|
||||
rendered.should have_content "Plant from:"
|
||||
rendered.should have_content "seed (1)"
|
||||
context "with planted_from frequencies" do
|
||||
before { FactoryBot.create(:seed_planting, crop: planting.crop) }
|
||||
include_examples "render planting_advice"
|
||||
it { is_expected.to have_content "Plant from:" }
|
||||
it { is_expected.to have_content "seed (1)" }
|
||||
end
|
||||
|
||||
it "shows multiple planted_from frequencies" do
|
||||
FactoryBot.create(:seed_planting, crop: @crop)
|
||||
FactoryBot.create(:seed_planting, crop: @crop)
|
||||
FactoryBot.create(:cutting_planting, crop: @crop)
|
||||
render partial: 'crops/planting_advice', locals: { crop: @crop }
|
||||
rendered.should have_content "Plant from:"
|
||||
rendered.should have_content "seed (2), cutting (1)"
|
||||
context "with multiple planted_from frequencies" do
|
||||
before do
|
||||
FactoryBot.create_list(:seed_planting, 2, crop: planting.crop)
|
||||
FactoryBot.create(:cutting_planting, crop: planting.crop)
|
||||
end
|
||||
include_examples "render planting_advice"
|
||||
it { is_expected.to have_content "Plant from:" }
|
||||
it { is_expected.to have_content "seed (2), cutting (1)" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "crops/_popover" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "crops/edit" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "crops/hierarchy" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "crops/index" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'crops/index.rss.haml' do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "crops/new" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "crops/wrangle" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'devise/mailer/confirmation_instructions.html.haml', type: "view" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'devise/mailer/reset_password_instructions.html.haml', type: "view" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
describe 'devise/mailer/unlock_instructions.html.haml', type: "view" do
|
||||
context "logged in" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'devise/registrations/edit.html.haml', type: "view" do
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
## DEPRECATION NOTICE: Do not add new tests to this file!
|
||||
##
|
||||
## View and controller tests are deprecated in the Growstuff project
|
||||
## We no longer write new view and controller tests, but instead write
|
||||
## feature tests (in spec/features) using Capybara (https://github.com/jnicklas/capybara).
|
||||
## These test the full stack, behaving as a browser, and require less complicated setup
|
||||
## to run. Please feel free to delete old view/controller tests as they are reimplemented
|
||||
## in feature tests.
|
||||
##
|
||||
## If you submit a pull request containing new view or controller tests, it will not be
|
||||
## merged.
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'devise/registrations/new.html.haml', type: "view" do
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user