rubocop fixes

This commit is contained in:
Brenda
2019-12-16 21:41:47 +13:00
parent b287a4eb58
commit 2826c2ec20
87 changed files with 606 additions and 524 deletions

View File

@@ -15,6 +15,43 @@ Lint/SuppressedException:
Exclude: Exclude:
- 'lib/tasks/testing.rake' - 'lib/tasks/testing.rake'
Lint/UselessAssignment:
Exclude:
- 'config.rb'
- 'config/compass.rb'
Metrics/AbcSize:
Max: 125
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 59
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 186
Metrics/CyclomaticComplexity:
Max: 29
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 341
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 106
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 107
Metrics/PerceivedComplexity:
Max: 29
# Configuration parameters: EnforcedStyle. # Configuration parameters: EnforcedStyle.
# SupportedStyles: lowercase, uppercase # SupportedStyles: lowercase, uppercase
Naming/HeredocDelimiterCase: Naming/HeredocDelimiterCase:
@@ -35,11 +72,27 @@ Rails/CreateTableWithTimestamps:
- 'db/migrate/20161201154922_add_photos_seeds_table.rb' - 'db/migrate/20161201154922_add_photos_seeds_table.rb'
- 'db/migrate/20171022032108_all_the_predictions.rb' - 'db/migrate/20171022032108_all_the_predictions.rb'
# Configuration parameters: EnforcedStyle.
# SupportedStyles: strict, flexible
Rails/Date:
Exclude:
- 'app/mailers/notifier.rb'
# Configuration parameters: EnforcedStyle. # Configuration parameters: EnforcedStyle.
# SupportedStyles: slashes, arguments # SupportedStyles: slashes, arguments
Rails/FilePath: Rails/FilePath:
Exclude: Exclude:
- 'app/controllers/crops_controller.rb' - 'app/controllers/crops_controller.rb'
- 'config/application.rb'
- 'config/environments/development.rb'
- 'db/seeds.rb'
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/HasAndBelongsToMany:
Exclude:
- 'app/models/member.rb'
- 'app/models/role.rb'
# Configuration parameters: Include. # Configuration parameters: Include.
# Include: app/models/**/*.rb # Include: app/models/**/*.rb
@@ -47,6 +100,44 @@ Rails/HasManyOrHasOneDependent:
Exclude: Exclude:
- 'app/models/member.rb' - 'app/models/member.rb'
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/InverseOf:
Exclude:
- 'app/models/concerns/ownable.rb'
Rails/OutputSafety:
Exclude:
- 'app/helpers/auto_suggest_helper.rb'
- 'app/helpers/gardens_helper.rb'
# Configuration parameters: Include.
# Include: **/Rakefile, **/*.rake
Rails/RakeEnvironment:
Exclude:
- 'lib/tasks/hooks.rake'
- 'lib/tasks/i18n.rake'
- 'lib/tasks/testing.rake'
# Configuration parameters: Include.
# Include: db/migrate/*.rb
Rails/ReversibleMigration:
Exclude:
- 'db/migrate/20191119020643_upgrade_cms.rb'
# Configuration parameters: Blacklist, Whitelist.
# Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters
Rails/SkipsModelValidations:
Exclude:
- 'db/migrate/20190317023129_finished_boolean.rb'
- 'db/seeds.rb'
- 'db/migrate/20190910022329_add_photo_source.rb'
# Configuration parameters: AllowedChars.
Style/AsciiComments:
Exclude:
- 'config/initializers/comfortable_mexican_sofa.rb'
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle. # Configuration parameters: AutoCorrect, EnforcedStyle.
# SupportedStyles: nested, compact # SupportedStyles: nested, compact
@@ -54,6 +145,7 @@ Style/ClassAndModuleChildren:
Exclude: Exclude:
- 'lib/actions/oauth_signup_action.rb' - 'lib/actions/oauth_signup_action.rb'
- 'lib/haml/filters/escaped_markdown.rb' - 'lib/haml/filters/escaped_markdown.rb'
- 'lib/haml/filters/growstuff_markdown.rb'
Style/CommentedKeyword: Style/CommentedKeyword:
Exclude: Exclude:

View File

@@ -12,14 +12,14 @@ class AuthenticationsController < ApplicationController
@authentication = current_member.authentications @authentication = current_member.authentications
.create_with( .create_with(
name: name, name: name,
token: auth['credentials']['token'], token: auth['credentials']['token'],
secret: auth['credentials']['secret'] secret: auth['credentials']['secret']
) )
.find_or_create_by( .find_or_create_by(
provider: auth['provider'], provider: auth['provider'],
uid: auth['uid'], uid: auth['uid'],
name: name name: name
) )
flash[:notice] = "Authentication successful." flash[:notice] = "Authentication successful."

View File

@@ -54,7 +54,7 @@ class ConversationsController < ApplicationController
def set_box def set_box
@boxes = { @boxes = {
'inbox' => { 'total' => mailbox.inbox.size, 'unread' => current_member.receipts.where(is_read: false).count }, 'inbox' => { 'total' => mailbox.inbox.size, 'unread' => current_member.receipts.where(is_read: false).count },
'sent' => { 'total' => mailbox.sentbox.size, 'unread' => 0 }, 'sent' => { 'total' => mailbox.sentbox.size, 'unread' => 0 },
'trash' => { 'total' => mailbox.trash.size, 'unread' => 0 } 'trash' => { 'total' => mailbox.trash.size, 'unread' => 0 }
} }
@box = if params[:box].blank? || !@boxes.keys.include?(params[:box]) @box = if params[:box].blank? || !@boxes.keys.include?(params[:box])

View File

@@ -50,8 +50,8 @@ class CropsController < ApplicationController
@term = params[:term] @term = params[:term]
@crops = CropSearchService.search( @crops = CropSearchService.search(
@term, page: params[:page], @term, page: params[:page],
per_page: 36, per_page: 36,
current_member: current_member current_member: current_member
) )
respond_with @crops respond_with @crops
@@ -202,13 +202,13 @@ class CropsController < ApplicationController
def crop_json_fields def crop_json_fields
{ {
include: { include: {
plantings: { plantings: {
include: { include: {
owner: { only: %i(id login_name location latitude longitude) } owner: { only: %i(id login_name location latitude longitude) }
} }
}, },
scientific_names: { only: [:name] }, scientific_names: { only: [:name] },
alternate_names: { only: [:name] } alternate_names: { only: [:name] }
} }
} }
end end

View File

@@ -28,11 +28,11 @@ class LikesController < ApplicationController
def render_json(like, liked_by_member: true) def render_json(like, liked_by_member: true)
{ {
id: like.likeable.id, id: like.likeable.id,
like_count: like.likeable.likes.count, like_count: like.likeable.likes.count,
liked_by_member: liked_by_member, liked_by_member: liked_by_member,
description: ActionController::Base.helpers.pluralize(like.likeable.likes.count, "like"), description: ActionController::Base.helpers.pluralize(like.likeable.likes.count, "like"),
url: like_path(like, format: :json) url: like_path(like, format: :json)
} }
end end
@@ -40,8 +40,8 @@ class LikesController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { redirect_to like.likeable } format.html { redirect_to like.likeable }
format.json do format.json do
render(json: render_json(like, render(json: render_json(like,
liked_by_member: liked_by_member), liked_by_member: liked_by_member),
status: status_code) status: status_code)
end end
end end

View File

@@ -69,7 +69,7 @@ class MembersController < ApplicationController
EMAIL_TYPE_STRING = { EMAIL_TYPE_STRING = {
send_notification_email: "direct message notifications", send_notification_email: "direct message notifications",
send_planting_reminder: "planting reminders" send_planting_reminder: "planting reminders"
}.freeze }.freeze
def member_params def member_params

View File

@@ -84,7 +84,7 @@ class PhotosController < ApplicationController
def find_or_create_photo_from_flickr_photo def find_or_create_photo_from_flickr_photo
photo = Photo.find_or_initialize_by( photo = Photo.find_or_initialize_by(
source_id: photo_params[:source_id], source_id: photo_params[:source_id],
source: 'flickr' source: 'flickr'
) )
photo.update(photo_params) photo.update(photo_params)
photo.owner_id = current_member.id photo.owner_id = current_member.id

View File

@@ -42,15 +42,15 @@ class PlantingsController < ApplicationController
def new def new
@planting = Planting.new( @planting = Planting.new(
planted_at: Time.zone.today, planted_at: Time.zone.today,
owner: current_member, owner: current_member,
garden: current_member.gardens.first garden: current_member.gardens.first
) )
@seed = Seed.find_by(slug: params[:seed_id]) if params[:seed_id] @seed = Seed.find_by(slug: params[:seed_id]) if params[:seed_id]
@crop = Crop.approved.find_by(id: params[:crop_id]) || Crop.new @crop = Crop.approved.find_by(id: params[:crop_id]) || Crop.new
if params[:garden_id] if params[:garden_id]
@planting.garden = Garden.find_by( @planting.garden = Garden.find_by(
owner: current_member, owner: current_member,
id: params[:garden_id] id: params[:garden_id]
) )
end end

View File

@@ -53,9 +53,9 @@ module ApplicationHelper
return uri.to_s return uri.to_s
end end
Gravatar.new(member.email).image_url(size: size, Gravatar.new(member.email).image_url(size: size,
default: :identicon, default: :identicon,
ssl: true) ssl: true)
end end
# Returns a string with the quantity and the right pluralization for a # Returns a string with the quantity and the right pluralization for a

View File

@@ -1,5 +1,4 @@
module AutoSuggestHelper module AutoSuggestHelper
# rubocop:disable Rails/OutputSafety
def auto_suggest(resource, source, options = {}) def auto_suggest(resource, source, options = {})
if options[:default] && !options[:default].new_record? if options[:default] && !options[:default].new_record?
default = options[:default] default = options[:default]
@@ -22,5 +21,4 @@ module AutoSuggestHelper
type="hidden" name="#{resource}[#{source}_id]" value="#{default_id}"> type="hidden" name="#{resource}[#{source}_id]" value="#{default_id}">
).html_safe ).html_safe
end end
# rubocop:enable Rails/OutputSafety
end end

View File

@@ -17,7 +17,6 @@ module GardensHelper
if plantings.blank? if plantings.blank?
"None" "None"
else else
# rubocop:disable Rails/OutputSafety
output = '<ul class="plantings">' output = '<ul class="plantings">'
plantings.each do |planting| plantings.each do |planting|
output += "<li>" output += "<li>"
@@ -27,7 +26,7 @@ module GardensHelper
end end
output += '</ul>' output += '</ul>'
output.html_safe output.html_safe
# rubocop:enable Rails/OutputSafety
end end
end end
end end

View File

@@ -19,7 +19,7 @@ class Notifier < ApplicationMailer
message = { member_id: @notification.recipient.id, type: :send_notification_email } message = { member_id: @notification.recipient.id, type: :send_notification_email }
@signed_message = verifier.generate(message) @signed_message = verifier.generate(message)
mail(to: @notification.recipient.email, mail(to: @notification.recipient.email,
subject: @notification.subject) subject: @notification.subject)
end end

View File

@@ -11,10 +11,10 @@ class Comment < ApplicationRecord
if recipient != sender if recipient != sender
Notification.create( Notification.create(
recipient_id: recipient, recipient_id: recipient,
sender_id: sender, sender_id: sender,
subject: "#{author} commented on #{post.subject}", subject: "#{author} commented on #{post.subject}",
body: body, body: body,
post_id: post.id post_id: post.id
) )
end end
end end

View File

@@ -4,10 +4,10 @@ module CropSearch
included do included do
#################################### ####################################
# Elastic search configuration # Elastic search configuration
searchkick word_start: %i(name alternate_names scientific_names), searchkick word_start: %i(name alternate_names scientific_names),
case_sensitive: false, case_sensitive: false,
merge_mappings: true, merge_mappings: true,
mappings: { mappings: {
properties: { properties: {
created_at: { type: :integer } created_at: { type: :integer }
} }
@@ -22,19 +22,19 @@ module CropSearch
def search_data def search_data
{ {
name: name, name: name,
slug: slug, slug: slug,
alternate_names: alternate_names.pluck(:name), alternate_names: alternate_names.pluck(:name),
scientific_names: scientific_names.pluck(:name), scientific_names: scientific_names.pluck(:name),
# boost the crops that are planted the most # boost the crops that are planted the most
plantings_count: plantings_count, plantings_count: plantings_count,
# boost this crop for these members # boost this crop for these members
planters_ids: plantings.pluck(:owner_id), planters_ids: plantings.pluck(:owner_id),
has_photos: photos.size.positive?, has_photos: photos.size.positive?,
photo: default_photo&.thumbnail_url, photo: default_photo&.thumbnail_url,
scientific_name: default_scientific_name&.name, scientific_name: default_scientific_name&.name,
description: description, description: description,
created_at: created_at.to_i created_at: created_at.to_i
} }
end end
end end

View File

@@ -1,7 +1,7 @@
module MemberFlickr module MemberFlickr
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do # rubocop:disable Metrics/BlockLength included do
# Authenticates against Flickr and returns an object we can use for subsequent api calls # Authenticates against Flickr and returns an object we can use for subsequent api calls
def flickr def flickr
if @flickr.nil? if @flickr.nil?
@@ -24,13 +24,13 @@ module MemberFlickr
result = if set result = if set
flickr.photosets.getPhotos( flickr.photosets.getPhotos(
photoset_id: set, photoset_id: set,
page: page_num, page: page_num,
per_page: 30 per_page: 30
) )
else else
flickr.people.getPhotos( flickr.people.getPhotos(
user_id: 'me', user_id: 'me',
page: page_num, page: page_num,
per_page: 30 per_page: 30
) )
end end

View File

@@ -1,7 +1,7 @@
module MemberNewsletter module MemberNewsletter
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do # rubocop:disable Metrics/BlockLength included do
after_save :update_newsletter_subscription after_save :update_newsletter_subscription
before_destroy :newsletter_unsubscribe before_destroy :newsletter_unsubscribe
@@ -29,9 +29,9 @@ module MemberNewsletter
return true if Rails.env.test? && !testing return true if Rails.env.test? && !testing
gibbon.lists.subscribe( gibbon.lists.subscribe(
id: Rails.application.config.newsletter_list_id, id: Rails.application.config.newsletter_list_id,
email: { email: email }, email: { email: email },
merge_vars: { login_name: login_name }, merge_vars: { login_name: login_name },
double_optin: false # they already confirmed their email with us double_optin: false # they already confirmed their email with us
) )
end end
@@ -39,7 +39,7 @@ module MemberNewsletter
def newsletter_unsubscribe(gibbon = Gibbon::API.new, testing = false) def newsletter_unsubscribe(gibbon = Gibbon::API.new, testing = false)
return true if Rails.env.test? && !testing return true if Rails.env.test? && !testing
gibbon.lists.unsubscribe(id: Rails.application.config.newsletter_list_id, gibbon.lists.unsubscribe(id: Rails.application.config.newsletter_list_id,
email: { email: email }) email: { email: email })
end end
end end

View File

@@ -1,7 +1,7 @@
module OpenFarmData module OpenFarmData
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do # rubocop:disable Metrics/BlockLength included do
def update_openfarm_data! def update_openfarm_data!
OpenfarmService.new.update_crop(self) OpenfarmService.new.update_crop(self)
end end

View File

@@ -2,7 +2,7 @@ module Ownable
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
belongs_to :owner, class_name: 'Member', # rubocop:disable Rails/InverseOf belongs_to :owner, class_name: 'Member',
foreign_key: 'owner_id', counter_cache: true foreign_key: 'owner_id', counter_cache: true
default_scope { joins(:owner).merge(Member.kept) } # Ensures the owner still exists default_scope { joins(:owner).merge(Member.kept) } # Ensures the owner still exists

View File

@@ -1,7 +1,7 @@
module PredictHarvest module PredictHarvest
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do # rubocop:disable Metrics/BlockLength included do
# dates # dates
def first_harvest_date def first_harvest_date
harvests_with_dates.minimum(:harvested_at) harvests_with_dates.minimum(:harvested_at)

View File

@@ -1,7 +1,7 @@
module PredictPlanting module PredictPlanting
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do # rubocop:disable Metrics/BlockLength included do
## Triggers ## Triggers
before_save :calculate_lifespan before_save :calculate_lifespan

View File

@@ -48,10 +48,10 @@ class Crop < ApplicationRecord
## Wikipedia urls are only necessary when approving a crop ## Wikipedia urls are only necessary when approving a crop
validates :en_wikipedia_url, validates :en_wikipedia_url,
format: { format: {
with: %r{\Ahttps?:\/\/en\.wikipedia\.org\/wiki\/[[:alnum:]%_\.()-]+\z}, with: %r{\Ahttps?:\/\/en\.wikipedia\.org\/wiki\/[[:alnum:]%_\.()-]+\z},
message: 'is not a valid English Wikipedia URL' message: 'is not a valid English Wikipedia URL'
}, },
if: :approved? if: :approved?
def to_s def to_s
name name

View File

@@ -11,7 +11,7 @@ class CsvImporter
@crop = Crop.find_or_create_by(name: name) @crop = Crop.find_or_create_by(name: name)
@crop.update( @crop.update(
en_wikipedia_url: en_wikipedia_url, en_wikipedia_url: en_wikipedia_url,
creator_id: cropbot.id creator_id: cropbot.id
) )
add_parent(parent_name) if parent_name add_parent(parent_name) if parent_name

View File

@@ -6,9 +6,9 @@ class Follow < ApplicationRecord
after_create do after_create do
Notification.create( Notification.create(
recipient_id: followed_id, recipient_id: followed_id,
sender_id: follower_id, sender_id: follower_id,
subject: "#{follower.login_name} is now following you", subject: "#{follower.login_name} is now following you",
body: "#{follower.login_name} just followed you on #{ENV['GROWSTUFF_SITE_NAME']}. " body: "#{follower.login_name} just followed you on #{ENV['GROWSTUFF_SITE_NAME']}. "
) )
end end
end end

View File

@@ -32,7 +32,7 @@ class Garden < ApplicationRecord
validates :area, validates :area,
numericality: { only_integer: false, greater_than_or_equal_to: 0 }, numericality: { only_integer: false, greater_than_or_equal_to: 0 },
allow_nil: true allow_nil: true
scope :located, lambda { scope :located, lambda {
where.not(gardens: { location: '' }) where.not(gardens: { location: '' })
@@ -41,12 +41,12 @@ class Garden < ApplicationRecord
} }
AREA_UNITS_VALUES = { AREA_UNITS_VALUES = {
"square metres" => "square metre", "square metres" => "square metre",
"square feet" => "square foot", "square feet" => "square foot",
"hectares" => "hectare", "hectares" => "hectare",
"acres" => "acre" "acres" => "acre"
}.freeze }.freeze
validates :area_unit, inclusion: { in: AREA_UNITS_VALUES.values, validates :area_unit, inclusion: { in: AREA_UNITS_VALUES.values,
message: "%<value>s is not a valid area unit" }, message: "%<value>s is not a valid area unit" },
allow_blank: true allow_blank: true
after_validation :cleanup_area after_validation :cleanup_area

View File

@@ -9,15 +9,15 @@ class Harvest < ApplicationRecord
# Constants # Constants
UNITS_VALUES = { UNITS_VALUES = {
"individual" => "individual", "individual" => "individual",
"bunches" => "bunch", "bunches" => "bunch",
"sprigs" => "sprig", "sprigs" => "sprig",
"handfuls" => "handful", "handfuls" => "handful",
"litres" => "litre", "litres" => "litre",
"pints" => "pint", "pints" => "pint",
"quarts" => "quart", "quarts" => "quart",
"buckets" => "bucket", "buckets" => "bucket",
"baskets" => "basket", "baskets" => "basket",
"bushels" => "bushel" "bushels" => "bushel"
}.freeze }.freeze
WEIGHT_UNITS_VALUES = { WEIGHT_UNITS_VALUES = {

View File

@@ -17,7 +17,7 @@ class Member < ApplicationRecord
has_many :plantings, foreign_key: 'owner_id', dependent: :destroy, inverse_of: :owner has_many :plantings, foreign_key: 'owner_id', dependent: :destroy, inverse_of: :owner
has_many :seeds, foreign_key: 'owner_id', dependent: :destroy, inverse_of: :owner has_many :seeds, foreign_key: 'owner_id', dependent: :destroy, inverse_of: :owner
has_many :harvests, foreign_key: 'owner_id', dependent: :destroy, inverse_of: :owner has_many :harvests, foreign_key: 'owner_id', dependent: :destroy, inverse_of: :owner
has_and_belongs_to_many :roles # rubocop:disable Rails/HasAndBelongsToMany has_and_belongs_to_many :roles
has_many :notifications, foreign_key: 'recipient_id', inverse_of: :recipient has_many :notifications, foreign_key: 'recipient_id', inverse_of: :recipient
has_many :sent_notifications, foreign_key: 'sender_id', inverse_of: :sender has_many :sent_notifications, foreign_key: 'sender_id', inverse_of: :sender
has_many :authentications, dependent: :destroy has_many :authentications, dependent: :destroy
@@ -76,13 +76,13 @@ class Member < ApplicationRecord
# Requires acceptance of the Terms of Service # Requires acceptance of the Terms of Service
validates :tos_agreement, acceptance: { allow_nil: true, accept: true } validates :tos_agreement, acceptance: { allow_nil: true, accept: true }
validates :login_name, validates :login_name,
length: { length: {
minimum: 2, maximum: 25, message: "should be between 2 and 25 characters long" minimum: 2, maximum: 25, message: "should be between 2 and 25 characters long"
}, },
exclusion: { exclusion: {
in: %w(growstuff admin moderator staff nearby), message: "name is reserved" in: %w(growstuff admin moderator staff nearby), message: "name is reserved"
}, },
format: { format: {
with: /\A\w+\z/, message: "may only include letters, numbers, or underscores" with: /\A\w+\z/, message: "may only include letters, numbers, or underscores"
}, },
uniqueness: { uniqueness: {

View File

@@ -13,8 +13,8 @@ class Photo < ApplicationRecord
# creates a relationship for each assignee type # creates a relationship for each assignee type
PHOTO_CAPABLE.each do |type| PHOTO_CAPABLE.each do |type|
has_many type.downcase.pluralize.to_s.to_sym, has_many type.downcase.pluralize.to_s.to_sym,
through: :photo_associations, through: :photo_associations,
source: :photographable, source: :photographable,
source_type: type source_type: type
end end
@@ -31,13 +31,13 @@ class Photo < ApplicationRecord
licenses = flickr.photos.licenses.getInfo licenses = flickr.photos.licenses.getInfo
license = licenses.find { |l| l.id == info.license } license = licenses.find { |l| l.id == info.license }
{ {
title: calculate_title(info), title: calculate_title(info),
license_name: license.name, license_name: license.name,
license_url: license.url, license_url: license.url,
thumbnail_url: FlickRaw.url_q(info), thumbnail_url: FlickRaw.url_q(info),
fullsize_url: FlickRaw.url_z(info), fullsize_url: FlickRaw.url_z(info),
link_url: FlickRaw.url_photopage(info), link_url: FlickRaw.url_photopage(info),
date_taken: info.dates.taken date_taken: info.dates.taken
} }
end end

View File

@@ -21,14 +21,14 @@ class Planting < ApplicationRecord
# #
# Ancestry of food # Ancestry of food
belongs_to :parent_seed, class_name: 'Seed', # parent belongs_to :parent_seed, class_name: 'Seed', # parent
foreign_key: 'parent_seed_id', foreign_key: 'parent_seed_id',
optional: true, optional: true,
inverse_of: :child_plantings inverse_of: :child_plantings
has_many :child_seeds, class_name: 'Seed', # children has_many :child_seeds, class_name: 'Seed', # children
foreign_key: 'parent_planting_id', foreign_key: 'parent_planting_id',
inverse_of: :parent_planting, inverse_of: :parent_planting,
dependent: :nullify dependent: :nullify
## ##
## Scopes ## Scopes

View File

@@ -87,9 +87,9 @@ class Post < ApplicationRecord
Notification.create( Notification.create(
recipient_id: recipient_id, recipient_id: recipient_id,
sender_id: sender, sender_id: sender,
subject: "#{author} mentioned you in their post #{subject}", subject: "#{author} mentioned you in their post #{subject}",
body: body body: body
) )
end end
end end

View File

@@ -3,7 +3,7 @@ class Role < ApplicationRecord
friendly_id :name, use: %i(slugged finders) friendly_id :name, use: %i(slugged finders)
validates :name, uniqueness: true, presence: true validates :name, uniqueness: true, presence: true
has_and_belongs_to_many :members # rubocop:disable Rails/HasAndBelongsToMany has_and_belongs_to_many :members
class << self class << self
%i(crop_wranglers admins).each do |method| %i(crop_wranglers admins).each do |method|

View File

@@ -23,23 +23,23 @@ class Seed < ApplicationRecord
# Validations # Validations
validates :crop, approved: true validates :crop, approved: true
validates :crop, presence: { message: "must be present and exist in our database" } validates :crop, presence: { message: "must be present and exist in our database" }
validates :quantity, allow_nil: true, validates :quantity, allow_nil: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 } numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :days_until_maturity_min, allow_nil: true, validates :days_until_maturity_min, allow_nil: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 } numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :days_until_maturity_max, allow_nil: true, validates :days_until_maturity_max, allow_nil: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 } numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :tradable_to, allow_blank: false, validates :tradable_to, allow_blank: false,
inclusion: { in: TRADABLE_TO_VALUES, message: "You may only trade seed nowhere, "\ inclusion: { in: TRADABLE_TO_VALUES, message: "You may only trade seed nowhere, "\
"locally, nationally, or internationally" } "locally, nationally, or internationally" }
validates :organic, allow_blank: false, validates :organic, allow_blank: false,
inclusion: { in: ORGANIC_VALUES, message: "You must say whether the seeds "\ inclusion: { in: ORGANIC_VALUES, message: "You must say whether the seeds "\
"are organic or not, or that you don't know" } "are organic or not, or that you don't know" }
validates :gmo, allow_blank: false, validates :gmo, allow_blank: false,
inclusion: { in: GMO_VALUES, message: "You must say whether the seeds are "\ inclusion: { in: GMO_VALUES, message: "You must say whether the seeds are "\
"genetically modified or not, or that you don't know" } "genetically modified or not, or that you don't know" }
validates :heirloom, allow_blank: false, validates :heirloom, allow_blank: false,
inclusion: { in: HEIRLOOM_VALUES, message: "You must say whether the seeds"\ inclusion: { in: HEIRLOOM_VALUES, message: "You must say whether the seeds"\
"are heirloom, hybrid, or unknown" } "are heirloom, hybrid, or unknown" }
# #

View File

@@ -2,12 +2,12 @@ class CropSearchService
# Crop.search(string) # Crop.search(string)
def self.search(query, page: 1, per_page: 12, current_member: nil) def self.search(query, page: 1, per_page: 12, current_member: nil)
search_params = { search_params = {
page: page, page: page,
per_page: per_page, per_page: per_page,
fields: %i(name^5 alternate_names scientific_names), fields: %i(name^5 alternate_names scientific_names),
match: :word_start, match: :word_start,
boost_by: [:plantings_count], boost_by: [:plantings_count],
includes: %i(scientific_names alternate_names), includes: %i(scientific_names alternate_names),
misspellings: { edit_distance: 2 } misspellings: { edit_distance: 2 }
} }
# prioritise crops the member has planted # prioritise crops the member has planted
@@ -20,22 +20,22 @@ class CropSearchService
body = { body = {
"query": { "query": {
"function_score": { "function_score": {
"query": { "query_string": { "query": 'has_photos:true' } }, "query": { "query_string": { "query": 'has_photos:true' } },
"random_score": { "seed": DateTime.now.to_i } "random_score": { "seed": DateTime.now.to_i }
} }
} }
} }
Crop.search( Crop.search(
limit: limit, limit: limit,
load: false, load: false,
body: body body: body
) )
end end
def self.recent(limit) def self.recent(limit)
Crop.search( Crop.search(
limit: limit, limit: limit,
load: false, load: false,
boost_by: { created_at: { factor: 100 } } # default factor is 1 boost_by: { created_at: { factor: 100 } } # default factor is 1
) )
end end

View File

@@ -52,14 +52,14 @@ class OpenfarmService
next if Photo.find_by(source_id: picture.fetch('id'), source: 'openfarm') next if Photo.find_by(source_id: picture.fetch('id'), source: 'openfarm')
photo = Photo.new( photo = Photo.new(
source_id: picture.fetch('id'), source_id: picture.fetch('id'),
source: 'openfarm', source: 'openfarm',
owner: @cropbot, owner: @cropbot,
thumbnail_url: data.fetch('thumbnail_url'), thumbnail_url: data.fetch('thumbnail_url'),
fullsize_url: data.fetch('image_url'), fullsize_url: data.fetch('image_url'),
title: 'Open Farm photo', title: 'Open Farm photo',
license_name: 'No rights reserved', license_name: 'No rights reserved',
link_url: "https://openfarm.cc/en/crops/#{name_to_slug(crop.name)}" link_url: "https://openfarm.cc/en/crops/#{name_to_slug(crop.name)}"
) )
if photo.valid? if photo.valid?
Photo.transaction do Photo.transaction do

View File

@@ -1,5 +1,4 @@
# Require any additional compass plugins here. # Require any additional compass plugins here.
# rubocop:disable Lint/UselessAssignment
# Set this to the root of your project when deployed: # Set this to the root of your project when deployed:
http_path = "/" http_path = "/"
css_dir = "app/assets/stylesheets" css_dir = "app/assets/stylesheets"
@@ -21,4 +20,3 @@ images_dir = "app/assets/images"
preferred_syntax = :sass preferred_syntax = :sass
# and then run: # and then run:
# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass # sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass
# rubocop:enable Lint/UselessAssignment

View File

@@ -1,4 +1,2 @@
# Require any additional compass plugins here. # Require any additional compass plugins here.
# rubocop:disable Lint/UselessAssignment
project_type = :rails project_type = :rails
# rubocop:enable Lint/UselessAssignment

View File

@@ -57,12 +57,12 @@ Rails.application.configure do
# Use a different cache store in production. # Use a different cache store in production.
config.cache_store = :mem_cache_store, config.cache_store = :mem_cache_store,
(ENV["MEMCACHIER_SERVERS"] || "").split(","), (ENV["MEMCACHIER_SERVERS"] || "").split(","),
{ username: ENV["MEMCACHIER_USERNAME"], { username: ENV["MEMCACHIER_USERNAME"],
password: ENV["MEMCACHIER_PASSWORD"], password: ENV["MEMCACHIER_PASSWORD"],
failover: true, failover: true,
socket_timeout: 1.5, socket_timeout: 1.5,
socket_failure_delay: 0.2, socket_failure_delay: 0.2,
down_retry_delay: 60 } down_retry_delay: 60 }
# Use a real queuing backend for Active Job (and separate queues per environment) # Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque # config.active_job.queue_adapter = :resque
@@ -90,12 +90,12 @@ Rails.application.configure do
config.action_mailer.default_url_options = { host: ENV['HOST'] } config.action_mailer.default_url_options = { host: ENV['HOST'] }
config.action_mailer.smtp_settings = { config.action_mailer.smtp_settings = {
user_name: ENV['SENDGRID_USERNAME'], user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'], password: ENV['SENDGRID_PASSWORD'],
domain: ENV['GROWSTUFF_EMAIL_DOMAIN'], domain: ENV['GROWSTUFF_EMAIL_DOMAIN'],
address: 'smtp.sendgrid.net', address: 'smtp.sendgrid.net',
port: 587, port: 587,
authentication: :plain, authentication: :plain,
enable_starttls_auto: true enable_starttls_auto: true
} }
ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.delivery_method = :smtp

View File

@@ -59,7 +59,7 @@ Geocoder.configure(lookup: :test)
Geocoder::Lookup::Test.add_stub( Geocoder::Lookup::Test.add_stub(
"Amundsen-Scott Base, Antarctica", [ "Amundsen-Scott Base, Antarctica", [
{ {
'latitude' => -90.0, 'latitude' => -90.0,
'longitude' => 0.0 'longitude' => 0.0
} }
] ]
@@ -68,12 +68,12 @@ Geocoder::Lookup::Test.add_stub(
Geocoder::Lookup::Test.add_stub( Geocoder::Lookup::Test.add_stub(
"Philippines", [ "Philippines", [
{ {
'latitude' => 12.7503486, 'latitude' => 12.7503486,
'longitude' => 122.7312101, 'longitude' => 122.7312101,
'address' => 'Manila, Mnl, Philippines', 'address' => 'Manila, Mnl, Philippines',
'state' => 'Manila', 'state' => 'Manila',
'state_code' => 'Mnl', 'state_code' => 'Mnl',
'country' => 'Philippines', 'country' => 'Philippines',
'country_code' => 'PH' 'country_code' => 'PH'
} }
] ]
@@ -82,7 +82,7 @@ Geocoder::Lookup::Test.add_stub(
Geocoder::Lookup::Test.add_stub( Geocoder::Lookup::Test.add_stub(
"Greenwich, UK", [ "Greenwich, UK", [
{ {
'latitude' => 51.483061, 'latitude' => 51.483061,
'longitude' => -0.004151 'longitude' => -0.004151
} }
] ]
@@ -91,7 +91,7 @@ Geocoder::Lookup::Test.add_stub(
Geocoder::Lookup::Test.add_stub( Geocoder::Lookup::Test.add_stub(
"Edinburgh", [ "Edinburgh", [
{ {
'latitude' => 55.953252, 'latitude' => 55.953252,
'longitude' => -3.188267 'longitude' => -3.188267
} }
] ]
@@ -107,15 +107,15 @@ end
OmniAuth.config.test_mode = true OmniAuth.config.test_mode = true
# Fake the omniauth # Fake the omniauth
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new(provider: 'facebook', OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new(provider: 'facebook',
uid: '123545', uid: '123545',
info: { info: {
name: "John Testerson", name: "John Testerson",
nickname: 'JohnnyT', nickname: 'JohnnyT',
email: 'example.oauth.facebook@example.com', email: 'example.oauth.facebook@example.com',
image: 'http://findicons.com/files/icons/1072/face_avatars/300/i04.png' image: 'http://findicons.com/files/icons/1072/face_avatars/300/i04.png'
}, },
credentials: { credentials: {
token: "token", token: "token",
secret: "donttell" secret: "donttell"
}) })

View File

@@ -54,12 +54,9 @@ ComfortableMexicanSofa.configure do |config|
# a previous version using this system. You can control how many revisions per # a previous version using this system. You can control how many revisions per
# object you want to keep. Set it to 0 if you wish to turn this feature off. # object you want to keep. Set it to 0 if you wish to turn this feature off.
# config.revisions_limit = 25 # config.revisions_limit = 25
# rubocop:disable Style/AsciiComments
# Locale definitions. If you want to define your own locale merge # Locale definitions. If you want to define your own locale merge
# {:locale => 'Locale Title'} with this. # {:locale => 'Locale Title'} with this.
# config.locales = {:en => 'English', :es => 'Español'} # config.locales = {:en => 'English', :es => 'Español'}
# rubocop:enable Style/AsciiComments
# Admin interface will respect the locale of the site being managed. However you can # Admin interface will respect the locale of the site being managed. However you can
# force it to English by setting this to `:en` # force it to English by setting this to `:en`

View File

@@ -1,12 +1,12 @@
require 'geocodable' require 'geocodable'
Geocoder.configure( Geocoder.configure(
units: :km, units: :km,
timeout: 10, timeout: 10,
http_headers: { http_headers: {
"User-Agent" => "User-Agent" =>
"#{Rails.application.config.user_agent} #{Rails.application.config.user_agent_email}", "#{Rails.application.config.user_agent} #{Rails.application.config.user_agent_email}",
"From" => Rails.application.config.user_agent_email "From" => Rails.application.config.user_agent_email
} }
) )
# This configuration takes precedence over environment/test.rb # This configuration takes precedence over environment/test.rb

View File

@@ -7,9 +7,9 @@ Rails.application.routes.draw do
resources :plant_parts resources :plant_parts
devise_for :members, controllers: { devise_for :members, controllers: {
registrations: "registrations", registrations: "registrations",
passwords: "passwords", passwords: "passwords",
sessions: "sessions", sessions: "sessions",
omniauth_callbacks: "omniauth_callbacks" omniauth_callbacks: "omniauth_callbacks"
} }
devise_scope :member do devise_scope :member do

View File

@@ -113,7 +113,7 @@ class CreateCms < ActiveRecord::Migration[4.2]
end end
add_index :comfy_cms_categories, %i(site_id categorized_type label), add_index :comfy_cms_categories, %i(site_id categorized_type label),
unique: true, unique: true,
name: 'index_cms_categories_on_site_id_and_cat_type_and_label' name: 'index_cms_categories_on_site_id_and_cat_type_and_label'
create_table :comfy_cms_categorizations, force: true do |t| create_table :comfy_cms_categorizations, force: true do |t|
t.integer :category_id, null: false t.integer :category_id, null: false
@@ -122,7 +122,7 @@ class CreateCms < ActiveRecord::Migration[4.2]
end end
add_index :comfy_cms_categorizations, %i(category_id categorized_type categorized_id), add_index :comfy_cms_categorizations, %i(category_id categorized_type categorized_id),
unique: true, unique: true,
name: 'index_cms_categorizations_on_cat_id_and_catd_type_and_catd_id' name: 'index_cms_categorizations_on_cat_id_and_catd_type_and_catd_id'
end end
def self.down def self.down

View File

@@ -7,16 +7,16 @@ class SeedUsage < ActiveRecord::Migration[4.2]
# plantings can be grown from a seed # plantings can be grown from a seed
add_column(:plantings, :parent_seed_id, :integer) add_column(:plantings, :parent_seed_id, :integer)
add_foreign_key(:plantings, :seeds, add_foreign_key(:plantings, :seeds,
column: :parent_seed_id, column: :parent_seed_id,
primary_key: :id, primary_key: :id,
name: :parent_seed, name: :parent_seed,
on_delete: :nullify) on_delete: :nullify)
# seeds can be harvest from planting # seeds can be harvest from planting
add_column(:seeds, :parent_planting_id, :integer) add_column(:seeds, :parent_planting_id, :integer)
add_foreign_key(:seeds, :plantings, add_foreign_key(:seeds, :plantings,
column: :parent_planting_id, column: :parent_planting_id,
primary_key: :id, primary_key: :id,
name: :parent_planting, name: :parent_planting,
on_delete: :nullify) on_delete: :nullify)
end end
end end

View File

@@ -57,9 +57,9 @@ def load_test_users # rubocop:disable Metrics/AbcSize
(1..member_size).each do |i| (1..member_size).each do |i|
@user = Member.new( @user = Member.new(
login_name: "test#{i}", login_name: "test#{i}",
email: "test#{i}@example.com", email: "test#{i}@example.com",
password: "password#{i}", password: "password#{i}",
tos_agreement: true tos_agreement: true
) )
@user.skip_confirmation! @user.skip_confirmation!
@@ -79,11 +79,11 @@ def load_test_users # rubocop:disable Metrics/AbcSize
# Create a planting by the member # Create a planting by the member
Planting.create( Planting.create(
owner_id: @user.id, owner_id: @user.id,
garden_id: @user.gardens.first.id, garden_id: @user.gardens.first.id,
planted_at: Time.zone.today, planted_at: Time.zone.today,
crop_id: Crop.find(i % Crop.all.size + 1).id, crop_id: Crop.find(i % Crop.all.size + 1).id,
sunniness: select_random_item(Planting::SUNNINESS_VALUES), sunniness: select_random_item(Planting::SUNNINESS_VALUES),
planted_from: select_random_item(Planting::PLANTED_FROM_VALUES) planted_from: select_random_item(Planting::PLANTED_FROM_VALUES)
) )
end end
@@ -94,9 +94,9 @@ end
def load_admin_users def load_admin_users
puts "Adding admin and crop wrangler members..." puts "Adding admin and crop wrangler members..."
@admin_user = Member.new( @admin_user = Member.new(
login_name: "admin1", login_name: "admin1",
email: "admin1@example.com", email: "admin1@example.com",
password: "password1", password: "password1",
tos_agreement: true tos_agreement: true
) )
@admin_user.skip_confirmation! @admin_user.skip_confirmation!
@@ -104,9 +104,9 @@ def load_admin_users
@admin_user.save! @admin_user.save!
@wrangler_user = Member.new( @wrangler_user = Member.new(
login_name: "wrangler1", login_name: "wrangler1",
email: "wrangler1@example.com", email: "wrangler1@example.com",
password: "password1", password: "password1",
tos_agreement: true tos_agreement: true
) )
@wrangler_user.skip_confirmation! @wrangler_user.skip_confirmation!
@@ -118,9 +118,9 @@ def create_cropbot
return if Member.find_by(login_name: 'cropbot') return if Member.find_by(login_name: 'cropbot')
@cropbot_user = Member.new( @cropbot_user = Member.new(
login_name: "cropbot", login_name: "cropbot",
email: Rails.application.config.bot_email, email: Rails.application.config.bot_email,
password: SecureRandom.urlsafe_base64(64), password: SecureRandom.urlsafe_base64(64),
tos_agreement: true tos_agreement: true
) )
@cropbot_user.skip_confirmation! @cropbot_user.skip_confirmation!

View File

@@ -41,14 +41,14 @@ class Growstuff::OauthSignupAction
authentication = member.authentications authentication = member.authentications
.create_with( .create_with(
name: name, name: name,
token: auth['credentials']['token'], token: auth['credentials']['token'],
secret: auth['credentials']['secret'] secret: auth['credentials']['secret']
) )
.find_or_create_by( .find_or_create_by(
provider: auth['provider'], provider: auth['provider'],
uid: auth['uid'], uid: auth['uid'],
name: name, name: name,
member_id: member.id member_id: member.id
) )

View File

@@ -1,6 +1,6 @@
require 'bluecloth' require 'bluecloth'
module Haml::Filters # rubocop:disable Style/ClassAndModuleChildren module Haml::Filters
module GrowstuffMarkdown module GrowstuffMarkdown
include Haml::Filters::Base include Haml::Filters::Base

View File

@@ -15,25 +15,25 @@ RSpec.describe Api::V1::PlantingsController, type: :controller do
let!(:my_planting) { FactoryBot.create(:planting, owner: member, planted_at: '2000-01-01') } let!(:my_planting) { FactoryBot.create(:planting, owner: member, planted_at: '2000-01-01') }
let(:expected_attributes) do let(:expected_attributes) do
{ {
'crop-name' => my_planting.crop.name, 'crop-name' => my_planting.crop.name,
'crop-slug' => my_planting.crop.slug, 'crop-slug' => my_planting.crop.slug,
'description' => my_planting.description, 'description' => my_planting.description,
'expected-lifespan' => nil, 'expected-lifespan' => nil,
'finish-predicted-at' => nil, 'finish-predicted-at' => nil,
'finished' => my_planting.finished, 'finished' => my_planting.finished,
'finished-at' => my_planting.finished_at, 'finished-at' => my_planting.finished_at,
'first-harvest-date' => nil, 'first-harvest-date' => nil,
'last-harvest-date' => nil, 'last-harvest-date' => nil,
'latitude' => my_planting.garden.latitude, 'latitude' => my_planting.garden.latitude,
'longitude' => my_planting.garden.longitude, 'longitude' => my_planting.garden.longitude,
'location' => my_planting.garden.location, 'location' => my_planting.garden.location,
'percentage-grown' => nil, 'percentage-grown' => nil,
'planted-at' => '2000-01-01', 'planted-at' => '2000-01-01',
'planted-from' => my_planting.planted_from, 'planted-from' => my_planting.planted_from,
'quantity' => my_planting.quantity, 'quantity' => my_planting.quantity,
'slug' => my_planting.slug, 'slug' => my_planting.slug,
'sunniness' => nil, 'sunniness' => nil,
'thumbnail' => nil 'thumbnail' => nil
} }
end end
@@ -49,25 +49,25 @@ RSpec.describe Api::V1::PlantingsController, type: :controller do
let(:expected_attributes) do let(:expected_attributes) do
{ {
'crop-name' => my_planting.crop.name, 'crop-name' => my_planting.crop.name,
'crop-slug' => my_planting.crop.slug, 'crop-slug' => my_planting.crop.slug,
'description' => my_planting.description, 'description' => my_planting.description,
'expected-lifespan' => nil, 'expected-lifespan' => nil,
'finish-predicted-at' => nil, 'finish-predicted-at' => nil,
'finished' => my_planting.finished, 'finished' => my_planting.finished,
'finished-at' => my_planting.finished_at, 'finished-at' => my_planting.finished_at,
'first-harvest-date' => nil, 'first-harvest-date' => nil,
'last-harvest-date' => nil, 'last-harvest-date' => nil,
'latitude' => my_planting.garden.latitude, 'latitude' => my_planting.garden.latitude,
'longitude' => my_planting.garden.longitude, 'longitude' => my_planting.garden.longitude,
'location' => my_planting.garden.location, 'location' => my_planting.garden.location,
'percentage-grown' => nil, 'percentage-grown' => nil,
'planted-at' => '2000-01-01', 'planted-at' => '2000-01-01',
'planted-from' => my_planting.planted_from, 'planted-from' => my_planting.planted_from,
'quantity' => my_planting.quantity, 'quantity' => my_planting.quantity,
'slug' => my_planting.slug, 'slug' => my_planting.slug,
'sunniness' => nil, 'sunniness' => nil,
'thumbnail' => photo.thumbnail_url 'thumbnail' => photo.thumbnail_url
} }
end end
let(:photo) { FactoryBot.create(:photo, owner: my_planting.owner) } let(:photo) { FactoryBot.create(:photo, owner: my_planting.owner) }

View File

@@ -7,9 +7,9 @@ describe AuthenticationsController do
controller.stub(:current_member) { @member } controller.stub(:current_member) { @member }
@auth = FactoryBot.create(:authentication, member: @member) @auth = FactoryBot.create(:authentication, member: @member)
request.env['omniauth.auth'] = { request.env['omniauth.auth'] = {
'provider' => 'foo', 'provider' => 'foo',
'uid' => 'bar', 'uid' => 'bar',
'info' => { 'nickname' => 'blah' }, 'info' => { 'nickname' => 'blah' },
'credentials' => { 'token' => 'blah', 'secret' => 'blah' } 'credentials' => { 'token' => 'blah', 'secret' => 'blah' }
} }
end end

View File

@@ -5,9 +5,9 @@ describe ForumsController do
def valid_attributes def valid_attributes
{ {
"name" => "MyString", "name" => "MyString",
"description" => "Something", "description" => "Something",
"owner_id" => 1 "owner_id" => 1
} }
end end

View File

@@ -5,10 +5,10 @@ describe HarvestsController do
def valid_attributes def valid_attributes
{ {
owner_id: subject.current_member.id, owner_id: subject.current_member.id,
crop_id: FactoryBot.create(:crop).id, crop_id: FactoryBot.create(:crop).id,
plant_part_id: FactoryBot.create(:plant_part).id, plant_part_id: FactoryBot.create(:plant_part).id,
harvested_at: '2017-01-01' harvested_at: '2017-01-01'
} }
end end
@@ -187,7 +187,7 @@ describe HarvestsController do
describe "does not save planting_id" do describe "does not save planting_id" do
before do before do
put :update, params: { id: harvest.to_param, put :update, params: { id: harvest.to_param,
harvest: valid_attributes.merge(planting_id: not_my_planting.id) } harvest: valid_attributes.merge(planting_id: not_my_planting.id) }
end end

View File

@@ -6,8 +6,8 @@ describe PhotoAssociationsController do
describe "destroy" do describe "destroy" do
let(:valid_params) do let(:valid_params) do
{ {
id: harvest.id, id: harvest.id,
type: 'harvest', type: 'harvest',
photo_id: photo.id photo_id: photo.id
} }
end end

View File

@@ -71,12 +71,12 @@ describe PhotosController do
describe "POST create" do describe "POST create" do
before do before do
Photo.any_instance.stub(:flickr_metadata).and_return(title: "A Heartbreaking work of staggering genius", Photo.any_instance.stub(:flickr_metadata).and_return(title: "A Heartbreaking work of staggering genius",
license_name: "CC-BY", license_name: "CC-BY",
license_url: "http://example.com/aybpl", license_url: "http://example.com/aybpl",
thumbnail_url: "http://example.com/thumb.jpg", thumbnail_url: "http://example.com/thumb.jpg",
fullsize_url: "http://example.com/full.jpg", fullsize_url: "http://example.com/full.jpg",
link_url: "http://example.com") link_url: "http://example.com")
end end
let(:member) { FactoryBot.create(:member) } let(:member) { FactoryBot.create(:member) }

View File

@@ -6,7 +6,7 @@ describe PlantingsController do
def valid_attributes def valid_attributes
{ {
garden_id: FactoryBot.create(:garden, owner: subject.current_member).id, garden_id: FactoryBot.create(:garden, owner: subject.current_member).id,
crop_id: FactoryBot.create(:crop).id crop_id: FactoryBot.create(:crop).id
} }
end end

View File

@@ -123,8 +123,8 @@ describe "crop detail page", js: true do
context 'predictions' do context 'predictions' do
let!(:planting) do let!(:planting) do
FactoryBot.create(:planting, crop: crop, FactoryBot.create(:planting, crop: crop,
planted_at: 100.days.ago, planted_at: 100.days.ago,
finished_at: 1.day.ago) finished_at: 1.day.ago)
end end

View File

@@ -78,11 +78,11 @@ describe "Gardens#index", :js do
# time to finished = 90 days # time to finished = 90 days
FactoryBot.create(:harvest, FactoryBot.create(:harvest,
harvested_at: 50.days.ago, harvested_at: 50.days.ago,
crop: crop, crop: crop,
planting: FactoryBot.create(:planting, planting: FactoryBot.create(:planting,
crop: crop, crop: crop,
planted_at: 100.days.ago, planted_at: 100.days.ago,
finished_at: 10.days.ago)) finished_at: 10.days.ago))
crop.plantings.each(&:update_harvest_days!) crop.plantings.each(&:update_harvest_days!)
crop.update_lifespan_medians crop.update_lifespan_medians
crop.update_harvest_medians crop.update_harvest_medians
@@ -95,9 +95,9 @@ describe "Gardens#index", :js do
describe 'harvest still growing' do describe 'harvest still growing' do
let!(:planting) do let!(:planting) do
FactoryBot.create :planting, FactoryBot.create :planting,
crop: crop, crop: crop,
owner: member, owner: member,
garden: garden, garden: garden,
planted_at: Time.zone.today planted_at: Time.zone.today
end end

View File

@@ -19,9 +19,9 @@ describe 'Test with visual testing', type: :feature, js: true do
let(:tomato_photo) do let(:tomato_photo) do
FactoryBot.create :photo, FactoryBot.create :photo,
title: 'look at my tomatoes', title: 'look at my tomatoes',
owner: member, owner: member,
fullsize_url: 'https://farm1.staticflickr.com/177/432250619_2fe19d067d_z.jpg', fullsize_url: 'https://farm1.staticflickr.com/177/432250619_2fe19d067d_z.jpg',
thumbnail_url: 'https://farm1.staticflickr.com/177/432250619_2fe19d067d_q.jpg' thumbnail_url: 'https://farm1.staticflickr.com/177/432250619_2fe19d067d_q.jpg'
end end
let(:post_body) do let(:post_body) do
@@ -69,12 +69,12 @@ rest of the garden.
Timecop.freeze(Time.zone.local(2019, 1, 1)) Timecop.freeze(Time.zone.local(2019, 1, 1))
{ {
chard: 'https://farm9.staticflickr.com/8516/8519911893_1759c28965_q.jpg', chard: 'https://farm9.staticflickr.com/8516/8519911893_1759c28965_q.jpg',
apple: 'https://farm5.staticflickr.com/4748/38932178855_6fe9bcdb48_q.jpg', apple: 'https://farm5.staticflickr.com/4748/38932178855_6fe9bcdb48_q.jpg',
pear: 'https://farm1.staticflickr.com/113/250984726_0fc31fea6d_q.jpg', pear: 'https://farm1.staticflickr.com/113/250984726_0fc31fea6d_q.jpg',
popcorn: 'https://farm8.staticflickr.com/7893/33150160528_24a689c6bc_q.jpg', popcorn: 'https://farm8.staticflickr.com/7893/33150160528_24a689c6bc_q.jpg',
eggplant: 'https://farm8.staticflickr.com/7856/47068736892_1af9b8a4ba_q.jpg', eggplant: 'https://farm8.staticflickr.com/7856/47068736892_1af9b8a4ba_q.jpg',
maize: 'https://farm66.staticflickr.com/65535/46739264475_7cb55b2cbb_q.jpg' maize: 'https://farm66.staticflickr.com/65535/46739264475_7cb55b2cbb_q.jpg'
}.each do |crop_type, photo_url| }.each do |crop_type, photo_url|
crop = FactoryBot.create crop_type, creator: someone_else crop = FactoryBot.create crop_type, creator: someone_else
crop.reindex crop.reindex
@@ -110,9 +110,9 @@ rest of the garden.
planting = FactoryBot.create :planting, planted_at: 1.year.ago, sunniness: 'sun', planted_from: 'seed', crop: tomato planting = FactoryBot.create :planting, planted_at: 1.year.ago, sunniness: 'sun', planted_from: 'seed', crop: tomato
FactoryBot.create(:harvest, FactoryBot.create(:harvest,
crop: tomato, crop: tomato,
plant_part: FactoryBot.create(:plant_part, name: 'berry'), plant_part: FactoryBot.create(:plant_part, name: 'berry'),
planting: planting, planting: planting,
harvested_at: 1.day.ago) harvested_at: 1.day.ago)
post = FactoryBot.create :post, subject: 'tomatoes are delicious' post = FactoryBot.create :post, subject: 'tomatoes are delicious'

View File

@@ -4,7 +4,7 @@ describe HarvestsHelper do
describe "display_quantity" do describe "display_quantity" do
it "blank" do it "blank" do
harvest = FactoryBot.create(:harvest, harvest = FactoryBot.create(:harvest,
quantity: nil, quantity: nil,
weight_quantity: nil) weight_quantity: nil)
result = helper.display_quantity(harvest) result = helper.display_quantity(harvest)
result.should eq 'not specified' result.should eq 'not specified'
@@ -12,8 +12,8 @@ describe HarvestsHelper do
it '3 individual' do it '3 individual' do
harvest = FactoryBot.create(:harvest, harvest = FactoryBot.create(:harvest,
quantity: 3, quantity: 3,
unit: 'individual', unit: 'individual',
weight_quantity: nil) weight_quantity: nil)
result = helper.display_quantity(harvest) result = helper.display_quantity(harvest)
result.should eq '3' result.should eq '3'
@@ -21,8 +21,8 @@ describe HarvestsHelper do
it '1 bunch' do it '1 bunch' do
harvest = FactoryBot.create(:harvest, harvest = FactoryBot.create(:harvest,
quantity: 1, quantity: 1,
unit: 'bunch', unit: 'bunch',
weight_quantity: nil) weight_quantity: nil)
result = helper.display_quantity(harvest) result = helper.display_quantity(harvest)
result.should eq '1 bunch' result.should eq '1 bunch'
@@ -30,8 +30,8 @@ describe HarvestsHelper do
it '3 bunches' do it '3 bunches' do
harvest = FactoryBot.create(:harvest, harvest = FactoryBot.create(:harvest,
quantity: 3, quantity: 3,
unit: 'bunch', unit: 'bunch',
weight_quantity: nil) weight_quantity: nil)
result = helper.display_quantity(harvest) result = helper.display_quantity(harvest)
result.should eq '3 bunches' result.should eq '3 bunches'
@@ -39,30 +39,30 @@ describe HarvestsHelper do
it '3 kg' do it '3 kg' do
harvest = FactoryBot.create(:harvest, harvest = FactoryBot.create(:harvest,
quantity: nil, quantity: nil,
unit: nil, unit: nil,
weight_quantity: 3, weight_quantity: 3,
weight_unit: 'kg') weight_unit: 'kg')
result = helper.display_quantity(harvest) result = helper.display_quantity(harvest)
result.should eq '3 kg' result.should eq '3 kg'
end end
it '3 individual weighing 3 kg' do it '3 individual weighing 3 kg' do
harvest = FactoryBot.create(:harvest, harvest = FactoryBot.create(:harvest,
quantity: 3, quantity: 3,
unit: 'individual', unit: 'individual',
weight_quantity: 3, weight_quantity: 3,
weight_unit: 'kg') weight_unit: 'kg')
result = helper.display_quantity(harvest) result = helper.display_quantity(harvest)
result.should eq '3, weighing 3 kg' result.should eq '3, weighing 3 kg'
end end
it '3 bunches weighing 3 kg' do it '3 bunches weighing 3 kg' do
harvest = FactoryBot.create(:harvest, harvest = FactoryBot.create(:harvest,
quantity: 3, quantity: 3,
unit: 'bunch', unit: 'bunch',
weight_quantity: 3, weight_quantity: 3,
weight_unit: 'kg') weight_unit: 'kg')
result = helper.display_quantity(harvest) result = helper.display_quantity(harvest)
result.should eq '3 bunches, weighing 3 kg' result.should eq '3 bunches, weighing 3 kg'
end end

View File

@@ -6,18 +6,18 @@ describe PlantingsHelper do
it "does not have a quantity nor a planted from value provided" do it "does not have a quantity nor a planted from value provided" do
planting = FactoryBot.build(:planting, planting = FactoryBot.build(:planting,
quantity: nil, quantity: nil,
planted_from: '', planted_from: '',
owner: member) owner: member)
result = helper.display_planting(planting) result = helper.display_planting(planting)
expect(result).to eq "crop_lady planted magic bean." expect(result).to eq "crop_lady planted magic bean."
end end
it "does not have a quantity provided" do it "does not have a quantity provided" do
planting = FactoryBot.build(:planting, planting = FactoryBot.build(:planting,
quantity: nil, quantity: nil,
planted_from: 'seed', planted_from: 'seed',
owner: member) owner: member)
result = helper.display_planting(planting) result = helper.display_planting(planting)
expect(result).to eq "crop_lady planted seeds." expect(result).to eq "crop_lady planted seeds."
end end
@@ -25,18 +25,18 @@ describe PlantingsHelper do
context "when quantity is greater than 1" do context "when quantity is greater than 1" do
it "does not have a planted from value provided" do it "does not have a planted from value provided" do
planting = FactoryBot.build(:planting, planting = FactoryBot.build(:planting,
quantity: 10, quantity: 10,
planted_from: '', planted_from: '',
owner: member) owner: member)
result = helper.display_planting(planting) result = helper.display_planting(planting)
expect(result).to eq "crop_lady planted 10 units." expect(result).to eq "crop_lady planted 10 units."
end end
it "does have a planted from value provided" do it "does have a planted from value provided" do
planting = FactoryBot.build(:planting, planting = FactoryBot.build(:planting,
quantity: 5, quantity: 5,
planted_from: 'seed', planted_from: 'seed',
owner: member) owner: member)
result = helper.display_planting(planting) result = helper.display_planting(planting)
expect(result).to eq "crop_lady planted 5 seeds." expect(result).to eq "crop_lady planted 5 seeds."
end end
@@ -45,18 +45,18 @@ describe PlantingsHelper do
context "when quantity is 1" do context "when quantity is 1" do
it "does not have a planted from value provided" do it "does not have a planted from value provided" do
planting = FactoryBot.build(:planting, planting = FactoryBot.build(:planting,
quantity: 1, quantity: 1,
planted_from: '', planted_from: '',
owner: member) owner: member)
result = helper.display_planting(planting) result = helper.display_planting(planting)
expect(result).to eq "crop_lady planted 1 unit." expect(result).to eq "crop_lady planted 1 unit."
end end
it "does have a planted from value provided" do it "does have a planted from value provided" do
planting = FactoryBot.build(:planting, planting = FactoryBot.build(:planting,
quantity: 1, quantity: 1,
planted_from: 'seed', planted_from: 'seed',
owner: member) owner: member)
result = helper.display_planting(planting) result = helper.display_planting(planting)
expect(result).to eq "crop_lady planted 1 seed." expect(result).to eq "crop_lady planted 1 seed."
end end

View File

@@ -8,16 +8,16 @@ describe 'Growstuff::OauthSignupAction' do
context 'with a valid authentication' do context 'with a valid authentication' do
before do before do
@auth = OmniAuth::AuthHash.new('provider' => 'facebook', @auth = OmniAuth::AuthHash.new('provider' => 'facebook',
'uid' => '123545', 'uid' => '123545',
'info' => { 'info' => {
'name' => "John Testerson's Brother", 'name' => "John Testerson's Brother",
'nickname' => 'JohnnyB', 'nickname' => 'JohnnyB',
'email' => 'example.oauth.facebook@example.com', 'email' => 'example.oauth.facebook@example.com',
'image' => 'http://findicons.com/files/icons/1072/face_avatars/300/i04.png' 'image' => 'http://findicons.com/files/icons/1072/face_avatars/300/i04.png'
}, },
'credentials' => { 'credentials' => {
'token' => "token", 'token' => "token",
'secret' => "donttell" 'secret' => "donttell"
}) })
end end
@@ -74,8 +74,8 @@ describe 'Growstuff::OauthSignupAction' do
@auth['info']['email'] = 'never.used.oauth@yahoo.com' @auth['info']['email'] = 'never.used.oauth@yahoo.com'
Member.where(email: @auth['info']['email']).delete_all Member.where(email: @auth['info']['email']).delete_all
@existing_member = create :member, email: @auth['info']['email'], @existing_member = create :member, email: @auth['info']['email'],
login_name: 'existing', login_name: 'existing',
preferred_avatar_uri: 'http://cl.jroo.me/z3/W/H/K/e/a.baa-very-cool-hat-you-.jpg' preferred_avatar_uri: 'http://cl.jroo.me/z3/W/H/K/e/a.baa-very-cool-hat-you-.jpg'
@member = @action.find_or_create_from_authorization(@auth) @member = @action.find_or_create_from_authorization(@auth)
@@ -118,13 +118,13 @@ describe 'Growstuff::OauthSignupAction' do
Member.where(email: @auth['info']['email']).delete_all Member.where(email: @auth['info']['email']).delete_all
Authentication.delete_all Authentication.delete_all
@existing_member = create :member, email: @auth['info']['email'], @existing_member = create :member, email: @auth['info']['email'],
login_name: 'schrodingerscat', login_name: 'schrodingerscat',
preferred_avatar_uri: 'http://cl.jroo.me/z3/W/H/K/e/a.baa-very-cool-hat-you-.jpg' preferred_avatar_uri: 'http://cl.jroo.me/z3/W/H/K/e/a.baa-very-cool-hat-you-.jpg'
@existing_authentication = @existing_member.authentications.create(provider: 'facebook', @existing_authentication = @existing_member.authentications.create(provider: 'facebook',
uid: '123545', uid: '123545',
name: "John Testerson's Brother", name: "John Testerson's Brother",
member_id: @existing_member.id) member_id: @existing_member.id)
@member = @action.find_or_create_from_authorization(@auth) @member = @action.find_or_create_from_authorization(@auth)

View File

@@ -20,13 +20,13 @@ describe Ability do
ability.should_not be_able_to(:create, ability.should_not be_able_to(:create,
FactoryBot.create(:notification, FactoryBot.create(:notification,
recipient: member, recipient: member,
sender: member)) sender: member))
end end
it "member can send messages to someone else" do it "member can send messages to someone else" do
ability.should be_able_to(:create, ability.should be_able_to(:create,
FactoryBot.create(:notification, FactoryBot.create(:notification,
recipient: FactoryBot.create(:member), recipient: FactoryBot.create(:member),
sender: member)) sender: member))
end end
end end

View File

@@ -10,8 +10,8 @@ describe AlternateName do
it 'is possible to add multiple alternate names to a crop' do it 'is possible to add multiple alternate names to a crop' do
crop = an.crop crop = an.crop
an2 = AlternateName.create( an2 = AlternateName.create(
name: "really alternative tomato", name: "really alternative tomato",
crop_id: crop.id, crop_id: crop.id,
creator_id: an.creator.id creator_id: an.creator.id
) )
crop.alternate_names << an2 crop.alternate_names << an2

View File

@@ -271,20 +271,20 @@ describe Crop do
@root = FactoryBot.create(:plant_part, name: 'root') @root = FactoryBot.create(:plant_part, name: 'root')
@bulb = FactoryBot.create(:plant_part, name: 'bulb') @bulb = FactoryBot.create(:plant_part, name: 'bulb')
@harvest1 = FactoryBot.create(:harvest, @harvest1 = FactoryBot.create(:harvest,
crop: crop, crop: crop,
plant_part: @fruit) plant_part: @fruit)
@harvest2 = FactoryBot.create(:harvest, @harvest2 = FactoryBot.create(:harvest,
crop: crop, crop: crop,
plant_part: @fruit) plant_part: @fruit)
@harvest3 = FactoryBot.create(:harvest, @harvest3 = FactoryBot.create(:harvest,
crop: crop, crop: crop,
plant_part: @seed) plant_part: @seed)
@harvest4 = FactoryBot.create(:harvest, @harvest4 = FactoryBot.create(:harvest,
crop: crop, crop: crop,
plant_part: @root) plant_part: @root)
crop.popular_plant_parts.should == { [@fruit.id, @fruit.name] => 2, crop.popular_plant_parts.should == { [@fruit.id, @fruit.name] => 2,
[@seed.id, @seed.name] => 1, [@seed.id, @seed.name] => 1,
[@root.id, @root.name] => 1 } [@root.id, @root.name] => 1 }
end end
end end
@@ -540,15 +540,15 @@ describe Crop do
context "crop rejections" do context "crop rejections" do
let!(:rejected_reason) do let!(:rejected_reason) do
FactoryBot.create(:crop, name: 'tomato', FactoryBot.create(:crop, name: 'tomato',
approval_status: 'rejected', approval_status: 'rejected',
reason_for_rejection: 'not edible') reason_for_rejection: 'not edible')
end end
let!(:rejected_other) do let!(:rejected_other) do
FactoryBot.create(:crop, name: 'tomato', FactoryBot.create(:crop, name: 'tomato',
approval_status: 'rejected', approval_status: 'rejected',
reason_for_rejection: 'other', reason_for_rejection: 'other',
rejection_notes: 'blah blah blah') rejection_notes: 'blah blah blah')
end end
describe "rejecting a crop" do describe "rejecting a crop" do

View File

@@ -150,74 +150,74 @@ describe Harvest do
let(:crop) { FactoryBot.create(:crop, name: "apricot") } let(:crop) { FactoryBot.create(:crop, name: "apricot") }
it "apricots" do it "apricots" do
@h = FactoryBot.create(:harvest, crop: crop, @h = FactoryBot.create(:harvest, crop: crop,
quantity: nil, quantity: nil,
unit: nil, unit: nil,
weight_quantity: nil, weight_quantity: nil,
weight_unit: nil) weight_unit: nil)
expect(@h.to_s).to eq "apricots" expect(@h.to_s).to eq "apricots"
end end
it "1 individual apricot" do it "1 individual apricot" do
@h = FactoryBot.create(:harvest, crop: crop, @h = FactoryBot.create(:harvest, crop: crop,
quantity: 1, quantity: 1,
unit: 'individual', unit: 'individual',
weight_quantity: nil, weight_quantity: nil,
weight_unit: nil) weight_unit: nil)
expect(@h.to_s).to eq "1 individual apricot" expect(@h.to_s).to eq "1 individual apricot"
end end
it "10 individual apricots" do it "10 individual apricots" do
@h = FactoryBot.create(:harvest, crop: crop, @h = FactoryBot.create(:harvest, crop: crop,
quantity: 10, quantity: 10,
unit: 'individual', unit: 'individual',
weight_quantity: nil, weight_quantity: nil,
weight_unit: nil) weight_unit: nil)
expect(@h.to_s).to eq "10 individual apricots" expect(@h.to_s).to eq "10 individual apricots"
end end
it "1 bushel of apricots" do it "1 bushel of apricots" do
@h = FactoryBot.create(:harvest, crop: crop, @h = FactoryBot.create(:harvest, crop: crop,
quantity: 1, quantity: 1,
unit: 'bushel', unit: 'bushel',
weight_quantity: nil, weight_quantity: nil,
weight_unit: nil) weight_unit: nil)
expect(@h.to_s).to eq "1 bushel of apricots" expect(@h.to_s).to eq "1 bushel of apricots"
end end
it "1.5 bushels of apricots" do it "1.5 bushels of apricots" do
@h = FactoryBot.create(:harvest, crop: crop, @h = FactoryBot.create(:harvest, crop: crop,
quantity: 1.5, quantity: 1.5,
unit: 'bushel', unit: 'bushel',
weight_quantity: nil, weight_quantity: nil,
weight_unit: nil) weight_unit: nil)
expect(@h.to_s).to eq "1.5 bushels of apricots" expect(@h.to_s).to eq "1.5 bushels of apricots"
end end
it "10 bushels of apricots" do it "10 bushels of apricots" do
@h = FactoryBot.create(:harvest, crop: crop, @h = FactoryBot.create(:harvest, crop: crop,
quantity: 10, quantity: 10,
unit: 'bushel', unit: 'bushel',
weight_quantity: nil, weight_quantity: nil,
weight_unit: nil) weight_unit: nil)
expect(@h.to_s).to eq "10 bushels of apricots" expect(@h.to_s).to eq "10 bushels of apricots"
end end
it "apricots weighing 1.2 kg" do it "apricots weighing 1.2 kg" do
@h = FactoryBot.create(:harvest, crop: crop, @h = FactoryBot.create(:harvest, crop: crop,
quantity: nil, quantity: nil,
unit: nil, unit: nil,
weight_quantity: 1.2, weight_quantity: 1.2,
weight_unit: 'kg') weight_unit: 'kg')
expect(@h.to_s).to eq "apricots weighing 1.2 kg" expect(@h.to_s).to eq "apricots weighing 1.2 kg"
end end
it "10 bushels of apricots weighing 100 kg" do it "10 bushels of apricots weighing 100 kg" do
@h = FactoryBot.create(:harvest, crop: crop, @h = FactoryBot.create(:harvest, crop: crop,
quantity: 10, quantity: 10,
unit: 'bushel', unit: 'bushel',
weight_quantity: 100, weight_quantity: 100,
weight_unit: 'kg') weight_unit: 'kg')
expect(@h.to_s).to eq "10 bushels of apricots weighing 100 kg" expect(@h.to_s).to eq "10 bushels of apricots weighing 100 kg"
end end
end end

View File

@@ -11,10 +11,10 @@ describe PlantPart do
@tomato = FactoryBot.create(:tomato) @tomato = FactoryBot.create(:tomato)
@pp1 = FactoryBot.create(:plant_part) @pp1 = FactoryBot.create(:plant_part)
@h1 = FactoryBot.create(:harvest, @h1 = FactoryBot.create(:harvest,
crop: @tomato, crop: @tomato,
plant_part: @pp1) plant_part: @pp1)
@h2 = FactoryBot.create(:harvest, @h2 = FactoryBot.create(:harvest,
crop: @maize, crop: @maize,
plant_part: @pp1) plant_part: @pp1)
@pp1.crops.should include @tomato @pp1.crops.should include @tomato
@pp1.crops.should include @maize @pp1.crops.should include @maize
@@ -24,10 +24,10 @@ describe PlantPart do
@maize = FactoryBot.create(:maize) @maize = FactoryBot.create(:maize)
@pp1 = FactoryBot.create(:plant_part) @pp1 = FactoryBot.create(:plant_part)
@h1 = FactoryBot.create(:harvest, @h1 = FactoryBot.create(:harvest,
crop: @maize, crop: @maize,
plant_part: @pp1) plant_part: @pp1)
@h2 = FactoryBot.create(:harvest, @h2 = FactoryBot.create(:harvest,
crop: @maize, crop: @maize,
plant_part: @pp1) plant_part: @pp1)
@pp1.crops.should eq [@maize] @pp1.crops.should eq [@maize]
end end

View File

@@ -177,8 +177,8 @@ describe Planting do
before do before do
FactoryBot.create(:harvest, FactoryBot.create(:harvest,
planting: planting, planting: planting,
crop: planting.crop, crop: planting.crop,
harvested_at: 10.days.ago) harvested_at: 10.days.ago)
planting.update_harvest_days! planting.update_harvest_days!
planting.crop.update_harvest_medians planting.crop.update_harvest_medians
@@ -443,8 +443,8 @@ describe Planting do
# this one is newer, and has the same owner, through the garden # this one is newer, and has the same owner, through the garden
@planting2 = FactoryBot.create(:planting, @planting2 = FactoryBot.create(:planting,
created_at: 1.minute.ago, created_at: 1.minute.ago,
garden: @planting1.garden, garden: @planting1.garden,
owner: @planting1.owner) owner: @planting1.owner)
@planting2.photos << FactoryBot.create(:photo, owner: @planting2.owner) @planting2.photos << FactoryBot.create(:photo, owner: @planting2.owner)
@planting2.save @planting2.save

View File

@@ -71,7 +71,7 @@ describe Post do
end end
it "sets recent activity to comment time" do it "sets recent activity to comment time" do
comment = FactoryBot.create(:comment, post: post, comment = FactoryBot.create(:comment, post: post,
created_at: 1.hour.ago) created_at: 1.hour.ago)
post.recent_activity.to_i.should eq comment.created_at.to_i post.recent_activity.to_i.should eq comment.created_at.to_i
end end

View File

@@ -6,16 +6,16 @@ RSpec.describe 'Crops', type: :request do
let(:headers) { { 'Accept' => 'application/vnd.api+json' } } let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
let!(:crop) { FactoryBot.create :crop } let!(:crop) { FactoryBot.create :crop }
let(:crop_encoded_as_json_api) do let(:crop_encoded_as_json_api) do
{ "id" => crop.id.to_s, { "id" => crop.id.to_s,
"type" => "crops", "type" => "crops",
"links" => { "self" => resource_url }, "links" => { "self" => resource_url },
"attributes" => attributes, "attributes" => attributes,
"relationships" => { "relationships" => {
"plantings" => plantings_as_json_api, "plantings" => plantings_as_json_api,
"parent" => parent_as_json_api, "parent" => parent_as_json_api,
"harvests" => harvests_as_json_api, "harvests" => harvests_as_json_api,
"seeds" => seeds_as_json_api, "seeds" => seeds_as_json_api,
"photos" => photos_as_json_api "photos" => photos_as_json_api
} } } }
end end
@@ -23,43 +23,43 @@ RSpec.describe 'Crops', type: :request do
let(:seeds_as_json_api) do let(:seeds_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/seeds", { "self" => "#{resource_url}/relationships/seeds",
"related" => "#{resource_url}/seeds" } } "related" => "#{resource_url}/seeds" } }
end end
let(:harvests_as_json_api) do let(:harvests_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/harvests", { "self" => "#{resource_url}/relationships/harvests",
"related" => "#{resource_url}/harvests" } } "related" => "#{resource_url}/harvests" } }
end end
let(:parent_as_json_api) do let(:parent_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/parent", { "self" => "#{resource_url}/relationships/parent",
"related" => "#{resource_url}/parent" } } "related" => "#{resource_url}/parent" } }
end end
let(:plantings_as_json_api) do let(:plantings_as_json_api) do
{ "links" => { "links" =>
{ "self" => { "self" =>
"#{resource_url}/relationships/plantings", "#{resource_url}/relationships/plantings",
"related" => "#{resource_url}/plantings" } } "related" => "#{resource_url}/plantings" } }
end end
let(:photos_as_json_api) do let(:photos_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/photos", { "self" => "#{resource_url}/relationships/photos",
"related" => "#{resource_url}/photos" } } "related" => "#{resource_url}/photos" } }
end end
let(:attributes) do let(:attributes) do
{ {
"name" => crop.name, "name" => crop.name,
"en-wikipedia-url" => crop.en_wikipedia_url, "en-wikipedia-url" => crop.en_wikipedia_url,
"perennial" => false, "perennial" => false,
"median-lifespan" => nil, "median-lifespan" => nil,
"median-days-to-first-harvest" => nil, "median-days-to-first-harvest" => nil,
"median-days-to-last-harvest" => nil "median-days-to-last-harvest" => nil
} }
end end

View File

@@ -6,35 +6,35 @@ RSpec.describe 'Gardens', type: :request do
let(:headers) { { 'Accept' => 'application/vnd.api+json' } } let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
let!(:garden) { FactoryBot.create :garden } let!(:garden) { FactoryBot.create :garden }
let(:garden_encoded_as_json_api) do let(:garden_encoded_as_json_api) do
{ "id" => garden.id.to_s, { "id" => garden.id.to_s,
"type" => "gardens", "type" => "gardens",
"links" => { "self" => resource_url }, "links" => { "self" => resource_url },
"attributes" => { "name" => garden.name }, "attributes" => { "name" => garden.name },
"relationships" => "relationships" =>
{ {
"owner" => owner_as_json_api, "owner" => owner_as_json_api,
"plantings" => plantings_as_json_api, "plantings" => plantings_as_json_api,
"photos" => photos_as_json_api "photos" => photos_as_json_api
} } } }
end end
let(:resource_url) { "http://www.example.com/api/v1/gardens/#{garden.id}" } let(:resource_url) { "http://www.example.com/api/v1/gardens/#{garden.id}" }
let(:plantings_as_json_api) do let(:plantings_as_json_api) do
{ "links" => { "links" =>
{ "self" => { "self" =>
"#{resource_url}/relationships/plantings", "#{resource_url}/relationships/plantings",
"related" => "#{resource_url}/plantings" } } "related" => "#{resource_url}/plantings" } }
end end
let(:owner_as_json_api) do let(:owner_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/owner", { "self" => "#{resource_url}/relationships/owner",
"related" => "#{resource_url}/owner" } } "related" => "#{resource_url}/owner" } }
end end
let(:photos_as_json_api) do let(:photos_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/photos", { "self" => "#{resource_url}/relationships/photos",
"related" => "#{resource_url}/photos" } } "related" => "#{resource_url}/photos" } }
end end

View File

@@ -6,15 +6,15 @@ RSpec.describe 'Harvests', type: :request do
let(:headers) { { 'Accept' => 'application/vnd.api+json' } } let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
let!(:harvest) { FactoryBot.create :harvest } let!(:harvest) { FactoryBot.create :harvest }
let(:harvest_encoded_as_json_api) do let(:harvest_encoded_as_json_api) do
{ "id" => harvest.id.to_s, { "id" => harvest.id.to_s,
"type" => "harvests", "type" => "harvests",
"links" => { "self" => resource_url }, "links" => { "self" => resource_url },
"attributes" => attributes, "attributes" => attributes,
"relationships" => { "relationships" => {
"crop" => crop_as_json_api, "crop" => crop_as_json_api,
"planting" => planting_as_json_api, "planting" => planting_as_json_api,
"owner" => owner_as_json_api, "owner" => owner_as_json_api,
"photos" => photos_as_json_api "photos" => photos_as_json_api
} } } }
end end
@@ -22,38 +22,38 @@ RSpec.describe 'Harvests', type: :request do
let(:crop_as_json_api) do let(:crop_as_json_api) do
{ "links" => { "links" =>
{ "self" => { "self" =>
"#{resource_url}/relationships/crop", "#{resource_url}/relationships/crop",
"related" => "#{resource_url}/crop" } } "related" => "#{resource_url}/crop" } }
end end
let(:owner_as_json_api) do let(:owner_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/owner", { "self" => "#{resource_url}/relationships/owner",
"related" => "#{resource_url}/owner" } } "related" => "#{resource_url}/owner" } }
end end
let(:planting_as_json_api) do let(:planting_as_json_api) do
{ "links" => { "links" =>
{ "self" => { "self" =>
"#{resource_url}/relationships/planting", "#{resource_url}/relationships/planting",
"related" => "#{resource_url}/planting" } } "related" => "#{resource_url}/planting" } }
end end
let(:photos_as_json_api) do let(:photos_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/photos", { "self" => "#{resource_url}/relationships/photos",
"related" => "#{resource_url}/photos" } } "related" => "#{resource_url}/photos" } }
end end
let(:attributes) do let(:attributes) do
{ {
"harvested-at" => "2015-09-17", "harvested-at" => "2015-09-17",
"description" => harvest.description, "description" => harvest.description,
"unit" => harvest.unit, "unit" => harvest.unit,
"weight-quantity" => harvest.weight_quantity.to_s, "weight-quantity" => harvest.weight_quantity.to_s,
"weight-unit" => harvest.weight_unit, "weight-unit" => harvest.weight_unit,
"si-weight" => harvest.si_weight "si-weight" => harvest.si_weight
} }
end end

View File

@@ -6,16 +6,16 @@ RSpec.describe 'Members', type: :request do
let(:headers) { { 'Accept' => 'application/vnd.api+json' } } let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
let!(:member) { FactoryBot.create :member } let!(:member) { FactoryBot.create :member }
let(:member_encoded_as_json_api) do let(:member_encoded_as_json_api) do
{ "id" => member.id.to_s, { "id" => member.id.to_s,
"type" => "members", "type" => "members",
"links" => { "self" => resource_url }, "links" => { "self" => resource_url },
"attributes" => attributes, "attributes" => attributes,
"relationships" => { "relationships" => {
"gardens" => gardens_as_json_api, "gardens" => gardens_as_json_api,
"harvests" => harvests_as_json_api, "harvests" => harvests_as_json_api,
"photos" => photos_as_json_api, "photos" => photos_as_json_api,
"plantings" => plantings_as_json_api, "plantings" => plantings_as_json_api,
"seeds" => seeds_as_json_api "seeds" => seeds_as_json_api
} } } }
end end
@@ -23,38 +23,38 @@ RSpec.describe 'Members', type: :request do
let(:harvests_as_json_api) do let(:harvests_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/harvests", { "self" => "#{resource_url}/relationships/harvests",
"related" => "#{resource_url}/harvests" } } "related" => "#{resource_url}/harvests" } }
end end
let(:photos_as_json_api) do let(:photos_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/photos", { "self" => "#{resource_url}/relationships/photos",
"related" => "#{resource_url}/photos" } } "related" => "#{resource_url}/photos" } }
end end
let(:seeds_as_json_api) do let(:seeds_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/seeds", { "self" => "#{resource_url}/relationships/seeds",
"related" => "#{resource_url}/seeds" } } "related" => "#{resource_url}/seeds" } }
end end
let(:plantings_as_json_api) do let(:plantings_as_json_api) do
{ "links" => { "links" =>
{ "self" => { "self" =>
"#{resource_url}/relationships/plantings", "#{resource_url}/relationships/plantings",
"related" => "#{resource_url}/plantings" } } "related" => "#{resource_url}/plantings" } }
end end
let(:gardens_as_json_api) do let(:gardens_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/gardens", { "self" => "#{resource_url}/relationships/gardens",
"related" => "#{resource_url}/gardens" } } "related" => "#{resource_url}/gardens" } }
end end
let(:attributes) do let(:attributes) do
{ {
"login-name" => member.login_name, "login-name" => member.login_name,
"slug" => member.slug "slug" => member.slug
} }
end end
@@ -83,7 +83,7 @@ RSpec.describe 'Members', type: :request do
it '#update' do it '#update' do
expect do expect do
post "/api/v1/members/#{member.id}", params: { post "/api/v1/members/#{member.id}", params: {
'member' => { 'login_name' => 'can i modify this' } 'member' => { 'login_name' => 'can i modify this' }
}, },
headers: headers headers: headers

View File

@@ -6,15 +6,15 @@ RSpec.describe 'Photos', type: :request do
let(:headers) { { 'Accept' => 'application/vnd.api+json' } } let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
let!(:photo) { FactoryBot.create :photo } let!(:photo) { FactoryBot.create :photo }
let(:photo_encoded_as_json_api) do let(:photo_encoded_as_json_api) do
{ "id" => photo.id.to_s, { "id" => photo.id.to_s,
"type" => "photos", "type" => "photos",
"links" => { "self" => resource_url }, "links" => { "self" => resource_url },
"attributes" => attributes, "attributes" => attributes,
"relationships" => { "relationships" => {
"owner" => owner_as_json_api, "owner" => owner_as_json_api,
"plantings" => plantings_as_json_api, "plantings" => plantings_as_json_api,
"harvests" => harvests_as_json_api, "harvests" => harvests_as_json_api,
"gardens" => gardens_as_json_api "gardens" => gardens_as_json_api
} } } }
end end
@@ -22,25 +22,25 @@ RSpec.describe 'Photos', type: :request do
let(:owner_as_json_api) do let(:owner_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/owner", { "self" => "#{resource_url}/relationships/owner",
"related" => "#{resource_url}/owner" } } "related" => "#{resource_url}/owner" } }
end end
let(:harvests_as_json_api) do let(:harvests_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/harvests", { "self" => "#{resource_url}/relationships/harvests",
"related" => "#{resource_url}/harvests" } } "related" => "#{resource_url}/harvests" } }
end end
let(:gardens_as_json_api) do let(:gardens_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/gardens", { "self" => "#{resource_url}/relationships/gardens",
"related" => "#{resource_url}/gardens" } } "related" => "#{resource_url}/gardens" } }
end end
let(:plantings_as_json_api) do let(:plantings_as_json_api) do
{ "links" => { "links" =>
{ "self" => { "self" =>
"#{resource_url}/relationships/plantings", "#{resource_url}/relationships/plantings",
"related" => "#{resource_url}/plantings" } } "related" => "#{resource_url}/plantings" } }
end end
@@ -48,10 +48,10 @@ RSpec.describe 'Photos', type: :request do
let(:attributes) do let(:attributes) do
{ {
"thumbnail-url" => photo.thumbnail_url, "thumbnail-url" => photo.thumbnail_url,
"fullsize-url" => photo.fullsize_url, "fullsize-url" => photo.fullsize_url,
"link-url" => photo.link_url, "link-url" => photo.link_url,
"license-name" => photo.license_name, "license-name" => photo.license_name,
"title" => photo.title "title" => photo.title
} }
end end

View File

@@ -6,15 +6,15 @@ RSpec.describe 'Plantings', type: :request do
let(:headers) { { 'Accept' => 'application/vnd.api+json' } } let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
let!(:planting) { FactoryBot.create :planting } let!(:planting) { FactoryBot.create :planting }
let(:planting_encoded_as_json_api) do let(:planting_encoded_as_json_api) do
{ "id" => planting.id.to_s, { "id" => planting.id.to_s,
"type" => "plantings", "type" => "plantings",
"links" => { "self" => resource_url }, "links" => { "self" => resource_url },
"attributes" => attributes, "attributes" => attributes,
"relationships" => { "relationships" => {
"garden" => garden_as_json_api, "garden" => garden_as_json_api,
"crop" => crop_as_json_api, "crop" => crop_as_json_api,
"owner" => owner_as_json_api, "owner" => owner_as_json_api,
"photos" => photos_as_json_api, "photos" => photos_as_json_api,
"harvests" => harvests_as_json_api "harvests" => harvests_as_json_api
} } } }
end end
@@ -23,55 +23,55 @@ RSpec.describe 'Plantings', type: :request do
let(:harvests_as_json_api) do let(:harvests_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/harvests", { "self" => "#{resource_url}/relationships/harvests",
"related" => "#{resource_url}/harvests" } } "related" => "#{resource_url}/harvests" } }
end end
let(:photos_as_json_api) do let(:photos_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/photos", { "self" => "#{resource_url}/relationships/photos",
"related" => "#{resource_url}/photos" } } "related" => "#{resource_url}/photos" } }
end end
let(:owner_as_json_api) do let(:owner_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/owner", { "self" => "#{resource_url}/relationships/owner",
"related" => "#{resource_url}/owner" } } "related" => "#{resource_url}/owner" } }
end end
let(:crop_as_json_api) do let(:crop_as_json_api) do
{ "links" => { "links" =>
{ "self" => { "self" =>
"#{resource_url}/relationships/crop", "#{resource_url}/relationships/crop",
"related" => "#{resource_url}/crop" } } "related" => "#{resource_url}/crop" } }
end end
let(:garden_as_json_api) do let(:garden_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/garden", { "self" => "#{resource_url}/relationships/garden",
"related" => "#{resource_url}/garden" } } "related" => "#{resource_url}/garden" } }
end end
let(:attributes) do let(:attributes) do
{ {
"slug" => planting.slug, "slug" => planting.slug,
"planted-at" => "2014-07-30", "planted-at" => "2014-07-30",
"finished-at" => nil, "finished-at" => nil,
"finished" => false, "finished" => false,
"quantity" => 33, "quantity" => 33,
"description" => planting.description, "description" => planting.description,
"crop-name" => planting.crop.name, "crop-name" => planting.crop.name,
"crop-slug" => planting.crop.slug, "crop-slug" => planting.crop.slug,
"sunniness" => nil, "sunniness" => nil,
"planted-from" => nil, "planted-from" => nil,
"expected-lifespan" => nil, "expected-lifespan" => nil,
"finish-predicted-at" => nil, "finish-predicted-at" => nil,
"percentage-grown" => nil, "percentage-grown" => nil,
"first-harvest-date" => nil, "first-harvest-date" => nil,
"last-harvest-date" => nil, "last-harvest-date" => nil,
"thumbnail" => nil, "thumbnail" => nil,
"location" => planting.garden.location, "location" => planting.garden.location,
"longitude" => planting.garden.longitude, "longitude" => planting.garden.longitude,
"latitude" => planting.garden.latitude "latitude" => planting.garden.latitude
} }
end end

View File

@@ -6,13 +6,13 @@ RSpec.describe 'Photos', type: :request do
let(:headers) { { 'Accept' => 'application/vnd.api+json' } } let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
let!(:seed) { FactoryBot.create :seed } let!(:seed) { FactoryBot.create :seed }
let(:seed_encoded_as_json_api) do let(:seed_encoded_as_json_api) do
{ "id" => seed.id.to_s, { "id" => seed.id.to_s,
"type" => "seeds", "type" => "seeds",
"links" => { "self" => resource_url }, "links" => { "self" => resource_url },
"attributes" => attributes, "attributes" => attributes,
"relationships" => { "relationships" => {
"owner" => owner_as_json_api, "owner" => owner_as_json_api,
"crop" => crop_as_json_api "crop" => crop_as_json_api
} } } }
end end
@@ -20,27 +20,27 @@ RSpec.describe 'Photos', type: :request do
let(:owner_as_json_api) do let(:owner_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/owner", { "self" => "#{resource_url}/relationships/owner",
"related" => "#{resource_url}/owner" } } "related" => "#{resource_url}/owner" } }
end end
let(:crop_as_json_api) do let(:crop_as_json_api) do
{ "links" => { "links" =>
{ "self" => "#{resource_url}/relationships/crop", { "self" => "#{resource_url}/relationships/crop",
"related" => "#{resource_url}/crop" } } "related" => "#{resource_url}/crop" } }
end end
let(:attributes) do let(:attributes) do
{ {
"description" => seed.description, "description" => seed.description,
"quantity" => seed.quantity, "quantity" => seed.quantity,
"plant-before" => "2013-07-15", "plant-before" => "2013-07-15",
"tradable-to" => seed.tradable_to, "tradable-to" => seed.tradable_to,
"days-until-maturity-min" => seed.days_until_maturity_min, "days-until-maturity-min" => seed.days_until_maturity_min,
"days-until-maturity-max" => seed.days_until_maturity_max, "days-until-maturity-max" => seed.days_until_maturity_max,
"organic" => seed.organic, "organic" => seed.organic,
"gmo" => seed.gmo, "gmo" => seed.gmo,
"heirloom" => seed.heirloom "heirloom" => seed.heirloom
} }
end end

View File

@@ -15,11 +15,11 @@ RSpec.configure do |config|
config.swagger_docs = { config.swagger_docs = {
'v1/swagger.yaml' => { 'v1/swagger.yaml' => {
openapi: '3.0.1', openapi: '3.0.1',
info: { info: {
title: 'API V1', title: 'API V1',
version: 'v1' version: 'v1'
}, },
paths: {} paths: {}
} }
} }

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
describe "admin/roles/edit" do describe "admin/roles/edit" do
before do before do
@role = assign(:role, stub_model(Role, @role = assign(:role, stub_model(Role,
name: "MyString", name: "MyString",
description: "MyText")) description: "MyText"))
end end

View File

@@ -5,10 +5,10 @@ describe "admin/roles/index" do
controller.stub(:current_user) { nil } controller.stub(:current_user) { nil }
assign(:roles, [ assign(:roles, [
stub_model(Role, stub_model(Role,
name: "Name", name: "Name",
description: "MyText"), description: "MyText"),
stub_model(Role, stub_model(Role,
name: "Name", name: "Name",
description: "MyText") description: "MyText")
]) ])
end end

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
describe "admin/roles/new" do describe "admin/roles/new" do
before do before do
assign(:role, stub_model(Role, assign(:role, stub_model(Role,
name: "MyString", name: "MyString",
description: "MyText").as_new_record) description: "MyText").as_new_record)
end end

View File

@@ -5,7 +5,7 @@ describe "crops/_grown_for" do
let(:plant_path) { FactoryBot.create(:plant_part) } let(:plant_path) { FactoryBot.create(:plant_part) }
let!(:harvest) do let!(:harvest) do
FactoryBot.create(:harvest, FactoryBot.create(:harvest,
crop: crop, crop: crop,
plant_part: plant_path) plant_part: plant_path)
end end

View File

@@ -3,9 +3,9 @@ require 'rails_helper'
describe "forums/edit" do describe "forums/edit" do
before do before do
@forum = assign(:forum, stub_model(Forum, @forum = assign(:forum, stub_model(Forum,
name: "MyString", name: "MyString",
description: "MyText", description: "MyText",
owner_id: 1)) owner_id: 1))
end end
it "renders the edit forum form" do it "renders the edit forum form" do

View File

@@ -10,7 +10,7 @@ describe "harvests/edit" do
assert_select "form", action: harvests_path, method: "post" do assert_select "form", action: harvests_path, method: "post" do
assert_select "input#crop", class: "ui-autocomplete-input" assert_select "input#crop", class: "ui-autocomplete-input"
assert_select "input#harvest_crop_id", name: "harvest[crop_id]" assert_select "input#harvest_crop_id", name: "harvest[crop_id]"
assert_select 'input', id: "harvest_plant_part_id_#{PlantPart.first.id}", assert_select 'input', id: "harvest_plant_part_id_#{PlantPart.first.id}",
name: "harvest[plant_part_id]" name: "harvest[plant_part_id]"
assert_select "input#harvest_quantity", name: "harvest[quantity]" assert_select "input#harvest_quantity", name: "harvest[quantity]"
assert_select "input#harvest_weight_quantity", name: "harvest[quantity]" assert_select "input#harvest_weight_quantity", name: "harvest[quantity]"

View File

@@ -13,12 +13,12 @@ describe "harvests/index" do
harvests = WillPaginate::Collection.create(page, per_page, total_entries) do |pager| harvests = WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
pager.replace([ pager.replace([
FactoryBot.create(:harvest, FactoryBot.create(:harvest,
crop: @tomato, crop: @tomato,
owner: @member), owner: @member),
FactoryBot.create(:harvest, FactoryBot.create(:harvest,
crop: @maize, crop: @maize,
plant_part: @pp, plant_part: @pp,
owner: @member) owner: @member)
]) ])
end end
assign(:harvests, harvests) assign(:harvests, harvests)

View File

@@ -13,13 +13,13 @@ describe 'harvests/index.rss.haml' do
harvests = WillPaginate::Collection.create(page, per_page, total_entries) do |pager| harvests = WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
pager.replace([ pager.replace([
FactoryBot.create(:harvest, FactoryBot.create(:harvest,
crop: @tomato, crop: @tomato,
owner: @member), owner: @member),
FactoryBot.create(:harvest, FactoryBot.create(:harvest,
crop: @maize, crop: @maize,
plant_part: @pp, plant_part: @pp,
owner: @member, owner: @member,
quantity: 2) quantity: 2)
]) ])
end end
assign(:harvests, harvests) assign(:harvests, harvests)

View File

@@ -10,7 +10,7 @@ describe "harvests/new" do
assert_select "form", action: harvests_path, method: "post" do assert_select "form", action: harvests_path, method: "post" do
assert_select "input#crop", class: "ui-autocomplete-input" assert_select "input#crop", class: "ui-autocomplete-input"
assert_select "input#harvest_crop_id", name: "harvest[crop_id]" assert_select "input#harvest_crop_id", name: "harvest[crop_id]"
assert_select 'input', id: "harvest_plant_part_id_#{PlantPart.first.id}", assert_select 'input', id: "harvest_plant_part_id_#{PlantPart.first.id}",
name: "harvest[plant_part_id]" name: "harvest[plant_part_id]"
# some browsers interpret <input type="number"> without a step as "integer" # some browsers interpret <input type="number"> without a step as "integer"
assert_select "input#harvest_quantity[step=any]", name: "harvest[quantity]" assert_select "input#harvest_quantity[step=any]", name: "harvest[quantity]"

View File

@@ -3,9 +3,9 @@ require 'rails_helper'
describe "photos/edit" do describe "photos/edit" do
before do before do
@photo = assign(:photo, stub_model(Photo, @photo = assign(:photo, stub_model(Photo,
owner_id: 1, owner_id: 1,
flickr_photo_id: 1, flickr_photo_id: 1,
thumbnail_url: "MyString", thumbnail_url: "MyString",
fullsize_url: "MyString")) fullsize_url: "MyString"))
end end
end end

View File

@@ -9,9 +9,9 @@ describe "plantings/_form" do
@crop = @lowercase # needed to render the form @crop = @lowercase # needed to render the form
@planting = FactoryBot.create(:planting, @planting = FactoryBot.create(:planting,
garden: @garden, garden: @garden,
crop: @crop, crop: @crop,
owner: @member, owner: @member,
planted_at: Date.new(2013, 3, 1)) planted_at: Date.new(2013, 3, 1))
@gardens = @member.gardens @gardens = @member.gardens

View File

@@ -4,7 +4,7 @@ describe "plantings/edit" do
before do before do
@member = FactoryBot.create(:member, @member = FactoryBot.create(:member,
login_name: 'right', login_name: 'right',
email: 'right@example.com') email: 'right@example.com')
# creating two crops to make sure that the correct one is selected # creating two crops to make sure that the correct one is selected
# in the form. # in the form.

View File

@@ -15,21 +15,21 @@ describe "plantings/index" do
pager.replace([ pager.replace([
FactoryBot.create(:planting, FactoryBot.create(:planting,
garden: garden, garden: garden,
crop: tomato, crop: tomato,
owner: member), owner: member),
FactoryBot.create(:planting, FactoryBot.create(:planting,
garden: garden, garden: garden,
crop: maize, crop: maize,
owner: garden.owner, owner: garden.owner,
description: '', description: '',
planted_at: Time.zone.local(2013, 1, 13)), planted_at: Time.zone.local(2013, 1, 13)),
FactoryBot.create(:planting, FactoryBot.create(:planting,
garden: garden, garden: garden,
owner: garden.owner, owner: garden.owner,
crop: tomato, crop: tomato,
planted_at: Time.zone.local(2013, 1, 13), planted_at: Time.zone.local(2013, 1, 13),
finished_at: Time.zone.local(2013, 1, 20), finished_at: Time.zone.local(2013, 1, 20),
finished: true) finished: true)
]) ])
end end
assign(:plantings, plantings) assign(:plantings, plantings)

View File

@@ -32,7 +32,7 @@ describe "posts/edit" do
before do before do
@forum = assign(:forum, FactoryBot.create(:forum)) @forum = assign(:forum, FactoryBot.create(:forum))
assign(:post, FactoryBot.create(:post, assign(:post, FactoryBot.create(:post,
forum: @forum, forum: @forum,
author: @author)) author: @author))
render render
end end