Spacing fixes

This commit is contained in:
Brenda Wallace
2016-11-26 12:13:17 +13:00
parent 62e7c716dd
commit 723ebff923
82 changed files with 177 additions and 371 deletions

View File

@@ -610,31 +610,6 @@ Style/EmptyLiteral:
Exclude:
- 'app/models/member.rb'
# Offense count: 23
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
Style/ExtraSpacing:
Exclude:
- 'app/controllers/harvests_controller.rb'
- 'app/controllers/seeds_controller.rb'
- 'app/models/ability.rb'
- 'app/models/crop.rb'
- 'app/models/member.rb'
- 'app/models/post.rb'
- 'bin/rails'
- 'config.ru'
- 'config/environments/test.rb'
- 'db/migrate/20150201052245_create_cms.rb'
- 'script/rails'
- 'spec/features/crops/browse_crops_spec.rb'
- 'spec/lib/actions/oauth_signup_action_spec.rb'
- 'spec/models/planting_spec.rb'
- 'spec/models/role_spec.rb'
- 'spec/views/crops/_planting_advice.html.haml_spec.rb'
- 'spec/views/devise/shared/_links_spec.rb'
- 'spec/views/gardens/show.html.haml_spec.rb'
- 'spec/views/photos/new.html.haml_spec.rb'
# Offense count: 1
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: for, each
@@ -714,16 +689,6 @@ Style/Lambda:
- 'spec/controllers/member_controller_spec.rb'
- 'spec/models/photo_spec.rb'
# Offense count: 6
# Cop supports --auto-correct.
Style/LeadingCommentSpace:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/controllers/omniauth_callbacks_controller.rb'
- 'app/controllers/plantings_controller.rb'
- 'app/controllers/posts_controller.rb'
- 'app/controllers/seeds_controller.rb'
- 'spec/factories/crop.rb'
# Offense count: 3
# Cop supports --auto-correct.
@@ -1032,166 +997,6 @@ Style/SelfAssignment:
Exclude:
- 'app/helpers/crops_helper.rb'
# Offense count: 20
# Cop supports --auto-correct.
Style/SpaceAfterComma:
Exclude:
- 'app/models/crop.rb'
- 'db/seeds.rb'
- 'lib/actions/oauth_signup_action.rb'
- 'spec/models/harvest_spec.rb'
- 'spec/rails_helper.rb'
# Offense count: 6
# Cop supports --auto-correct.
Style/SpaceAfterNot:
Exclude:
- 'app/helpers/harvests_helper.rb'
- 'app/models/crop.rb'
- 'app/models/garden.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleInsidePipes, SupportedStyles.
# SupportedStyles: space, no_space
Style/SpaceAroundBlockParameters:
Exclude:
- 'spec/custom_matchers.rb'
# Offense count: 14
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space
Style/SpaceAroundEqualsInParameterDefault:
Exclude:
- 'app/helpers/application_helper.rb'
- 'app/helpers/auto_suggest_helper.rb'
- 'app/models/crop.rb'
- 'app/models/member.rb'
- 'app/models/order.rb'
- 'app/models/planting.rb'
- 'spec/lib/haml/filters/growstuff_markdown_spec.rb'
- 'spec/support/controller_macros.rb'
- 'spec/support/feature_helpers.rb'
# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Style/SpaceAroundOperators:
Exclude:
- 'app/controllers/harvests_controller.rb'
- 'app/controllers/seeds_controller.rb'
- 'app/models/planting.rb'
- 'app/models/post.rb'
- 'config/environments/test.rb'
- 'db/seeds.rb'
- 'spec/views/crops/_planting_advice.html.haml_spec.rb'
- 'spec/views/gardens/show.html.haml_spec.rb'
- 'spec/views/harvests/index.html.haml_spec.rb'
- 'spec/views/plantings/index.html.haml_spec.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space
Style/SpaceBeforeBlockBraces:
Exclude:
- 'app/models/crop.rb'
- 'app/models/post.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/SpaceBeforeComma:
Exclude:
- 'spec/controllers/member_controller_spec.rb'
# Offense count: 16
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
Style/SpaceInsideBlockBraces:
Exclude:
- 'app/helpers/crops_helper.rb'
- 'app/models/crop.rb'
- 'app/models/member.rb'
- 'app/models/post.rb'
- 'spec/factories/member.rb'
- 'spec/rails_helper.rb'
- 'spec/support/elasticsearch_helpers.rb'
- 'spec/views/notifications/new.html.haml_spec.rb'
# Offense count: 43
# Cop supports --auto-correct.
Style/SpaceInsideBrackets:
Exclude:
- 'app/models/crop.rb'
- 'config/initializers/devise.rb'
- 'spec/controllers/member_controller_spec.rb'
- 'spec/factories/member.rb'
- 'spec/models/crop_spec.rb'
- 'spec/models/member_spec.rb'
- 'spec/views/crops/index.html.haml_spec.rb'
- 'spec/views/crops/wrangle.html.haml_spec.rb'
- 'spec/views/forums/index.html.haml_spec.rb'
- 'spec/views/members/index.html.haml_spec.rb'
- 'spec/views/notifications/index.html.haml_spec.rb'
- 'spec/views/orders/index.html.haml_spec.rb'
- 'spec/views/plantings/index.rss.haml_spec.rb'
- 'spec/views/seeds/index.rss.haml_spec.rb'
# Offense count: 137
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
# SupportedStyles: space, no_space, compact
Style/SpaceInsideHashLiteralBraces:
Exclude:
- 'app/controllers/admin/orders_controller.rb'
- 'app/controllers/crops_controller.rb'
- 'app/models/crop.rb'
- 'app/models/harvest.rb'
- 'app/models/member.rb'
- 'app/models/planting.rb'
- 'app/models/seed.rb'
- 'db/migrate/20150201052245_create_cms.rb'
- 'lib/geocodable.rb'
- 'spec/controllers/admin/orders_controller_spec.rb'
- 'spec/controllers/comments_controller_spec.rb'
- 'spec/controllers/gardens_controller_spec.rb'
- 'spec/controllers/harvests_controller_spec.rb'
- 'spec/controllers/member_controller_spec.rb'
- 'spec/controllers/notifications_controller_spec.rb'
- 'spec/controllers/order_items_controller_spec.rb'
- 'spec/controllers/orders_controller_spec.rb'
- 'spec/controllers/plantings_controller_spec.rb'
- 'spec/controllers/seeds_controller_spec.rb'
- 'spec/views/notifications/show.html.haml_spec.rb'
- 'spec/views/photos/new.html.haml_spec.rb'
- 'spec/views/posts/_single.html.haml_spec.rb'
- 'spec/views/posts/show.html.haml_spec.rb'
# Offense count: 5
# Cop supports --auto-correct.
Style/SpaceInsideParens:
Exclude:
- 'app/models/crop.rb'
- 'config/environments/test.rb'
- 'spec/lib/haml/filters/growstuff_markdown_spec.rb'
- 'spec/views/posts/edit.html.haml_spec.rb'
# Offense count: 12
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space
Style/SpaceInsideStringInterpolation:
Exclude:
- 'app/controllers/follows_controller.rb'
- 'app/controllers/robots_controller.rb'
- 'spec/controllers/robots_controller_spec.rb'
- 'spec/features/crops/crop_detail_page_spec.rb'
- 'spec/features/rss/plantings_spec.rb'
- 'spec/features/rss/posts_spec.rb'
- 'spec/features/rss/seeds_spec.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles.

View File

@@ -8,7 +8,7 @@ class Admin::OrdersController < ApplicationController
def search
authorize! :manage, :all
@orders = Order.search({by: params[:search_by], for: params[:search_text]})
@orders = Order.search({ by: params[:search_by], for: params[:search_text] })
if @orders.empty?
flash[:alert] = "Couldn't find order with #{params[:search_by]} = #{params[:search_text]}"

View File

@@ -73,7 +73,7 @@ class ApplicationController < ActionController::Base
:bio, :location, :latitude, :longitude,
# email settings
:show_email, :newsletter, :send_notification_email, :send_planting_reminder,
#update password
# update password
:current_password
)
end

View File

@@ -11,11 +11,11 @@ class CropsController < ApplicationController
@sort = params[:sort]
if @sort == 'alpha'
# alphabetical order
@crops = Crop.includes(:scientific_names, {plantings: :photos})
@crops = Crop.includes(:scientific_names, { plantings: :photos })
@paginated_crops = @crops.approved.paginate(page: params[:page])
else
# default to sorting by popularity
@crops = Crop.popular.includes(:scientific_names, {plantings: :photos})
@crops = Crop.popular.includes(:scientific_names, { plantings: :photos })
@paginated_crops = @crops.approved.paginate(page: params[:page])
end
@@ -77,7 +77,7 @@ class CropsController < ApplicationController
# GET /crops/1
# GET /crops/1.json
def show
@crop = Crop.includes(:scientific_names, {plantings: :photos}).find(params[:id])
@crop = Crop.includes(:scientific_names, { plantings: :photos }).find(params[:id])
@posts = @crop.posts.paginate(page: params[:page])
respond_to do |format|

View File

@@ -8,7 +8,7 @@ class FollowsController < ApplicationController
@follow = current_member.follows.build(followed_id: follow_params[:followed_id])
if @follow.save
flash[:notice] = "Followed #{ @follow.followed.login_name }"
flash[:notice] = "Followed #{@follow.followed.login_name}"
redirect_to :back
else
flash[:error] = "Already following or error while following."
@@ -22,7 +22,7 @@ class FollowsController < ApplicationController
unfollowed_name = @follow.followed.login_name
@follow.destroy
flash[:notice] = "Unfollowed #{ unfollowed_name }"
flash[:notice] = "Unfollowed #{unfollowed_name}"
redirect_to root_path
end

View File

@@ -32,7 +32,7 @@ class HarvestsController < ApplicationController
@harvest = Harvest.new('harvested_at' => Date.today)
# using find_by_id here because it returns nil, unlike find
@crop = Crop.find_by_id(params[:crop_id]) || Crop.new
@crop = Crop.find_by_id(params[:crop_id]) || Crop.new
respond_to do |format|
format.html # new.html.erb

View File

@@ -28,7 +28,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
@authentication = action.establish_authentication(auth, member)
unless action.member_created?
sign_in_and_redirect member, event: :authentication #this will throw if @user is not activated
sign_in_and_redirect member, event: :authentication # this will throw if @user is not activated
set_flash_message(:notice, :success, kind: auth['provider']) if is_navigational_format?
else
raise "Invalid provider" unless ['facebook', 'twitter', 'flickr'].index(auth['provider'].to_s)

View File

@@ -18,7 +18,7 @@ class PlantingsController < ApplicationController
respond_to do |format|
format.html { @plantings = @plantings.paginate(page: params[:page]) }
format.json { render json: @plantings }
format.rss { render layout: false } #index.rss.builder
format.rss { render layout: false } # index.rss.builder
format.csv do
specifics = (@owner ? "#{@owner.login_name}-" : @crop ? "#{@crop.name}-" : nil)
@filename = "Growstuff-#{specifics}Plantings-#{Time.zone.now.to_s(:number)}.csv"

View File

@@ -16,7 +16,7 @@ class PostsController < ApplicationController
respond_to do |format|
format.html # index.html.haml
format.json { render json: @posts }
format.rss { render layout: false } #index.rss.builder
format.rss { render layout: false } # index.rss.builder
end
end

View File

@@ -2,7 +2,7 @@ class RobotsController < ApplicationController
DEFAULT_FILENAME = 'config/robots.txt'.freeze
def robots
filename = "config/robots.#{ subdomain }.txt" if subdomain && subdomain != 'www'
filename = "config/robots.#{subdomain}.txt" if subdomain && subdomain != 'www'
file_to_render = File.exists?(filename.to_s) ? filename : DEFAULT_FILENAME
render file: file_to_render, layout: false, content_type: 'text/plain'
end

View File

@@ -18,7 +18,7 @@ class SeedsController < ApplicationController
respond_to do |format|
format.html # index.html.erb
format.json { render json: @seeds }
format.rss { render layout: false } #index.rss.builder
format.rss { render layout: false } # index.rss.builder
format.csv do
if @owner
@filename = "Growstuff-#{@owner}-Seeds-#{Time.zone.now.to_s(:number)}.csv"
@@ -49,7 +49,7 @@ class SeedsController < ApplicationController
@seed = Seed.new
# using find_by_id here because it returns nil, unlike find
@crop = Crop.find_by_id(params[:crop_id]) || Crop.new
@crop = Crop.find_by_id(params[:crop_id]) || Crop.new
respond_to do |format|
format.html # new.html.erb

View File

@@ -38,7 +38,7 @@ module ApplicationHelper
end
# Produces a cache key for uniquely identifying cached fragments.
def cache_key_for(klass, identifier="all")
def cache_key_for(klass, identifier = "all")
count = klass.count
max_updated_at = klass.maximum(:updated_at).try(:utc).try(:to_s, :number)
"#{klass.name.downcase.pluralize}/#{identifier}-#{count}-#{max_updated_at}"

View File

@@ -1,5 +1,5 @@
module AutoSuggestHelper
def auto_suggest(resource, source, options={})
def auto_suggest(resource, source, options = {})
if options[:default] && !options[:default].new_record?
default = options[:default]
default_id = options[:default].try(:id)

View File

@@ -2,7 +2,7 @@ module CropsHelper
def display_seed_availability(member, crop)
total_quantity = 0
seeds = member.seeds.select {|seed| seed.crop.name == crop.name }
seeds = member.seeds.select { |seed| seed.crop.name == crop.name }
seeds.each do |seed|
total_quantity = total_quantity + seed.quantity if seed.quantity

View File

@@ -15,10 +15,10 @@ module HarvestsHelper
end
def display_human_quantity(harvest)
if ! harvest.quantity.blank? && harvest.quantity > 0
if !harvest.quantity.blank? && harvest.quantity > 0
if harvest.unit == 'individual' # just the number
number_to_human(harvest.quantity, strip_insignificant_zeros: true)
elsif ! harvest.unit.blank? # pluralize anything else
elsif !harvest.unit.blank? # pluralize anything else
return pluralize(number_to_human(harvest.quantity, strip_insignificant_zeros: true), harvest.unit)
else
return "#{number_to_human(harvest.quantity, strip_insignificant_zeros: true)} #{harvest.unit}"
@@ -29,7 +29,7 @@ module HarvestsHelper
end
def display_weight(harvest)
if ! harvest.weight_quantity.blank? && harvest.weight_quantity > 0
if !harvest.weight_quantity.blank? && harvest.weight_quantity > 0
return "#{number_to_human(harvest.weight_quantity, strip_insignificant_zeros: true)} #{harvest.weight_unit}"
else
return nil

View File

@@ -108,7 +108,7 @@ class Ability
can :cancel, Order, member_id: member.id, completed_at: nil
can :destroy, Order, member_id: member.id, completed_at: nil
can :create, OrderItem
can :create, OrderItem
# for now, let's not let people mess with individual order items
cannot :read, OrderItem, order: { member_id: member.id }
cannot :update, OrderItem, order: { member_id: member.id, completed_at: nil }

View File

@@ -19,7 +19,7 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength
belongs_to :parent, class_name: 'Crop'
has_many :varieties, class_name: 'Crop', foreign_key: 'parent_id'
has_and_belongs_to_many :posts
before_destroy {|crop| crop.posts.clear}
before_destroy { |crop| crop.posts.clear }
default_scope { order("lower(name) asc") }
scope :recent, lambda {
@@ -31,7 +31,7 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength
scope :popular, lambda {
where(approval_status: "approved").reorder("plantings_count desc, lower(name) asc")
}
scope :randomized, lambda {
scope :randomized, lambda {
# ok on sqlite and psql, but not on mysql
where(approval_status: "approved").reorder('random()')
}
@@ -69,12 +69,12 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength
analysis: {
tokenizer: {
gs_edgeNGram_tokenizer: {
type: "edgeNGram", # edgeNGram: NGram match from the start of a token
type: "edgeNGram", # edgeNGram: NGram match from the start of a token
min_gram: 3,
max_gram: 10,
# token_chars: Elasticsearch will split on characters
# that dont belong to any of these classes
token_chars: [ "letter", "digit" ]
token_chars: ["letter", "digit"]
}
},
analyzer: {
@@ -103,7 +103,7 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength
end
end
def as_indexed_json(options={})
def as_indexed_json(options = {})
self.as_json(
only: [:id, :name, :approval_status],
include: {
@@ -210,11 +210,11 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength
end
def approval_statuses
[ 'rejected', 'pending', 'approved' ]
['rejected', 'pending', 'approved']
end
def reasons_for_rejection
[ "already in database", "not edible", "not enough information", "other" ]
["already in database", "not edible", "not enough information", "other"]
end
# Crop.interesting
@@ -239,7 +239,7 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength
# - scientific name (optional, can be picked up from parent if it has one)
def Crop.create_from_csv(row)
name,en_wikipedia_url,parent,scientific_names,alternate_names = row
name, en_wikipedia_url, parent, scientific_names, alternate_names = row
cropbot = Member.find_by_login_name('cropbot')
raise "cropbot account not found: run rake db:seed" unless cropbot
@@ -265,10 +265,10 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength
def add_scientific_names_from_csv(scientific_names)
names_to_add = []
if ! scientific_names.blank? # i.e. we actually passed something in, which isn't a given
if !scientific_names.blank? # i.e. we actually passed something in, which isn't a given
names_to_add = scientific_names.split(%r{,\s*})
elsif parent && parent.scientific_names.size > 0 # pick up from parent
names_to_add = parent.scientific_names.map{|s| s.scientific_name}
names_to_add = parent.scientific_names.map { |s| s.scientific_name }
else
logger.warn("Warning: no scientific name (not even on parent crop) for #{self}")
end
@@ -293,7 +293,7 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength
def add_alternate_names_from_csv(alternate_names)
names_to_add = []
if ! alternate_names.blank? # i.e. we actually passed something in, which isn't a given
if !alternate_names.blank? # i.e. we actually passed something in, which isn't a given
cropbot = Member.find_by_login_name('cropbot')
raise "cropbot account not found: run rake db:seed" unless cropbot
@@ -325,7 +325,7 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength
def self.search(query)
if ENV['GROWSTUFF_ELASTICSEARCH'] == "true"
search_str = query.nil? ? "" : query.downcase
response = __elasticsearch__.search( {
response = __elasticsearch__.search({
# Finds documents which match any field, but uses the _score from
# the best field insead of adding up _score from each field.
query: {
@@ -338,7 +338,7 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength
}
},
filter: {
term: {approval_status: "approved"}
term: { approval_status: "approved" }
},
size: 50
}

View File

@@ -76,7 +76,7 @@ class Garden < ActiveRecord::Base
seen_crops = []
plantings.each do |p|
if (! seen_crops.include?(p.crop))
if (!seen_crops.include?(p.crop))
unique_plantings.push(p)
seen_crops.push(p.crop)
end

View File

@@ -22,9 +22,9 @@ class Harvest < ActiveRecord::Base
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 :plant_part, presence: {message: "must be present and exist in our database"}
validates :plant_part, presence: { message: "must be present and exist in our database" }
validates :quantity,
numericality: {

View File

@@ -4,7 +4,7 @@ class Member < ActiveRecord::Base
friendly_id :login_name, use: [:slugged, :finders]
has_many :posts, foreign_key: 'author_id'
has_many :posts, foreign_key: 'author_id'
has_many :comments, foreign_key: 'author_id'
has_many :forums, foreign_key: 'owner_id'
@@ -79,12 +79,12 @@ class Member < ActiveRecord::Base
}
# Give each new member a default garden
after_create {|member| Garden.create(name: "Garden", owner_id: member.id) }
after_create { |member| Garden.create(name: "Garden", owner_id: member.id) }
# and an account record (for paid accounts etc)
# we use find_or_create to avoid accidentally creating a second one,
# which can happen sometimes especially with FactoryGirl associations
after_create {|member| Account.find_or_create_by(member_id: member.id) }
after_create { |member| Account.find_or_create_by(member_id: member.id) }
after_save :update_newsletter_subscription
@@ -158,7 +158,7 @@ class Member < ActiveRecord::Base
# Fetches a collection of photos from Flickr
# Returns a [[page of photos], total] pair.
# Total is needed for pagination.
def flickr_photos(page_num=1, set=nil)
def flickr_photos(page_num = 1, set = nil)
result = false
result = if set
flickr.photosets.getPhotos(
@@ -212,7 +212,7 @@ class Member < ActiveRecord::Base
def Member.nearest_to(place)
nearby_members = []
if place
latitude, longitude = Geocoder.coordinates(place, params: {limit: 1})
latitude, longitude = Geocoder.coordinates(place, params: { limit: 1 })
if latitude && longitude
nearby_members = Member.located.sort_by { |x| x.distance_from([latitude, longitude]) }
end
@@ -234,7 +234,7 @@ class Member < ActiveRecord::Base
end
end
def newsletter_subscribe(testing=false)
def newsletter_subscribe(testing = false)
return true if (Rails.env.test? && !testing)
gb = Gibbon::API.new
res = gb.lists.subscribe({
@@ -245,7 +245,7 @@ class Member < ActiveRecord::Base
})
end
def newsletter_unsubscribe(testing=false)
def newsletter_unsubscribe(testing = false)
return true if (Rails.env.test? && !testing)
gb = Gibbon::API.new
res = gb.lists.unsubscribe({

View File

@@ -62,7 +62,7 @@ class Order < ActiveRecord::Base
# search orders (used by admin/orders)
# usage: Order.search({ :by => 'member', :for => 'Skud' })
# can search by: member, order_id, paypal_token, paypal_payer_id,
def Order.search(args={})
def Order.search(args = {})
if args[:for]
case args[:by]
when "member"

View File

@@ -32,7 +32,7 @@ class Planting < ActiveRecord::Base
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,
numericality: {
@@ -105,7 +105,7 @@ class Planting < ActiveRecord::Base
if differences.compact.empty?
nil
else
differences.compact.sum/differences.compact.size
differences.compact.sum / differences.compact.size
end
end
@@ -120,7 +120,7 @@ class Planting < ActiveRecord::Base
return 0 if current_date < planted_at
return 100 if days > days_before_maturity
percent = (days/days_before_maturity*100).to_i
percent = (days / days_before_maturity * 100).to_i
if percent >= 100
percent = 100
@@ -132,7 +132,7 @@ class Planting < ActiveRecord::Base
# return a list of interesting plantings, for the homepage etc.
# we can't do this via a scope (as far as we know) so sadly we have to
# do it this way.
def Planting.interesting(howmany=12, require_photo=true)
def Planting.interesting(howmany = 12, require_photo = true)
interesting_plantings = []
seen_owners = Hash.new(false) # keep track of which owners we've seen already

View File

@@ -5,14 +5,14 @@ class Post < ActiveRecord::Base
belongs_to :forum
has_many :comments, dependent: :destroy
has_and_belongs_to_many :crops
before_destroy {|post| post.crops.clear}
before_destroy { |post| post.crops.clear }
after_save :update_crops_posts_association
# also has_many notifications, but kinda meaningless to get at them
# from this direction, so we won't set up an association for now.
after_create do
recipients = []
sender = self.author.id
sender = self.author.id
self.body.scan(Haml::Filters::GrowstuffMarkdown::MEMBER_REGEX) do |m|
# find member case-insensitively and add to list of recipients
member = Member.where('lower(login_name) = ?', $1.downcase).first
@@ -24,7 +24,7 @@ class Post < ActiveRecord::Base
recipients << member if member && !recipients.include?(member)
end
# don't send notifications to yourself
recipients.map{ |r| r.id }.each do |recipient|
recipients.map { |r| r.id }.each do |recipient|
if recipient != sender
Notification.create(
recipient_id: recipient,

View File

@@ -9,7 +9,7 @@ class Seed < ActiveRecord::Base
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,
numericality: {
only_integer: true,

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'

View File

@@ -1,4 +1,4 @@
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
require ::File.expand_path('../config/environment', __FILE__)
run Growstuff::Application

View File

@@ -26,7 +26,7 @@ Growstuff::Application.configure do
config.action_dispatch.show_exceptions = true
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
@@ -100,7 +100,7 @@ Geocoder::Lookup::Test.add_stub(
)
# Unknown location
Geocoder::Lookup::Test.add_stub( "Tatooine", [])
Geocoder::Lookup::Test.add_stub("Tatooine", [])
Capybara.configure do |config|
config.always_include_port = true

View File

@@ -26,7 +26,7 @@ Devise.setup do |config|
# session. If you need permissions, you should implement that in a before filter.
# You can also supply a hash where the value is a boolean determining whether
# or not authentication should be aborted when the value is not present.
config.authentication_keys = [ :login ]
config.authentication_keys = [:login]
# Configure parameters from the request object used for authentication. Each entry
# given should be a request method and it will automatically be passed to the
@@ -38,12 +38,12 @@ Devise.setup do |config|
# Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [ :email ]
config.case_insensitive_keys = [:email]
# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [ :email, :login_name ]
config.strip_whitespace_keys = [:email, :login_name]
# Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the
@@ -102,7 +102,7 @@ Devise.setup do |config|
config.reconfirmable = true
# Defines which key will be used when confirming an account
config.confirmation_keys = [ :login ]
config.confirmation_keys = [:login]
# ==> Configuration for :rememberable
# The time the user will be remembered without asking for credentials again.
@@ -158,7 +158,7 @@ Devise.setup do |config|
# ==> Configuration for :recoverable
#
# Defines which key will be used when recovering the password for an account
config.reset_password_keys = [ :login ]
config.reset_password_keys = [:login]
# Time interval you can reset your password with a reset password key.
# Don't put a too small interval or your users won't have the time to

View File

@@ -2,7 +2,7 @@ class CreateCms < ActiveRecord::Migration
def self.up # rubocop:disable Metrics/MethodLength
text_limit = case ActiveRecord::Base.connection.adapter_name
when 'PostgreSQL'
{ }
{}
else
{ limit: 16777215 }
end
@@ -42,7 +42,7 @@ class CreateCms < ActiveRecord::Migration
t.integer :layout_id
t.integer :parent_id
t.integer :target_page_id
t.string :label, null: false
t.string :label, null: false
t.string :slug
t.string :full_path, null: false
t.text :content_cache, text_limit
@@ -80,7 +80,7 @@ class CreateCms < ActiveRecord::Migration
# -- Files --------------------------------------------------------------
create_table :comfy_cms_files do |t|
t.integer :site_id, null: false
t.integer :site_id, null: false
t.integer :block_id
t.string :label, null: false
t.string :file_file_name, null: false

View File

@@ -87,7 +87,7 @@ def load_test_users
suburb_file.pos = 0 if suburb_file.eof?
row = CSV.parse(suburb_file.readline)
suburb,country,state,latitude,longitude = row[0]
suburb, country, state, latitude, longitude = row[0]
# Using 'update_column' method instead of 'update' so that
# it avoids accessing Geocoding service for faster processing
@user.gardens.first.update_columns(location: suburb, latitude: latitude, longitude: longitude)
@@ -198,7 +198,7 @@ def load_plant_parts
end
def select_random_item(array)
array[rand(0..array.size-1) % array.size]
array[rand(0..array.size - 1) % array.size]
end
load_data

View File

@@ -11,14 +11,14 @@ class Growstuff::OauthSignupAction
def find_or_create_from_authorization(auth)
member ||= Member.where(email: auth.info.email).first_or_create do |m|
m.email = auth.info.email
m.password = Devise.friendly_token[0,20]
m.password = Devise.friendly_token[0, 20]
# First, try the nickname or friendly generate from the email
m.login_name = auth.info.nickname || auth.info.email.split("@").first.gsub(/[^A-Za-z]+/, '_').underscore
# Do we have a collision with an existing account? Generate a 20 character long random name
# so the user can update it later
m.login_name = Devise.friendly_token[0,20] if Member.where(login_name: m.login_name).any?
m.login_name = Devise.friendly_token[0, 20] if Member.where(login_name: m.login_name).any?
m.preferred_avatar_uri = auth.info.image # assuming the user model has an image
m.skip_confirmation!

View File

@@ -8,7 +8,7 @@ module Geocodable
def geocode
unless self.location.blank?
self.latitude, self.longitude =
Geocoder.coordinates(location, params: {limit: 1})
Geocoder.coordinates(location, params: { limit: 1 })
end
end

View File

@@ -2,6 +2,6 @@
# This command will automatically be run when you run "rails"
# with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'

View File

@@ -18,13 +18,13 @@ describe Admin::OrdersController do
describe "GET search" do
it "assigns @orders" do
order = FactoryGirl.create(:order)
get :search, {search_by: 'order_id', search_text: order.id}
get :search, { search_by: 'order_id', search_text: order.id }
assigns(:orders).should eq([order])
end
it "sets an error message if nothing found" do
order = FactoryGirl.create(:order)
get :search, {search_by: 'order_id', search_text: 'foo'}
get :search, { search_by: 'order_id', search_text: 'foo' }
flash[:alert].should match /Couldn't find order with/
end
end

View File

@@ -36,14 +36,14 @@ describe CommentsController do
describe "GET new" do
it "picks up post from params" do
post = FactoryGirl.create(:post)
get :new, {post_id: post.id}
get :new, { post_id: post.id }
assigns(:post).should eq(post)
end
it "assigns the old comments as @comments" do
post = FactoryGirl.create(:post)
old_comment = FactoryGirl.create(:comment, post: post)
get :new, {post_id: post.id}
get :new, { post_id: post.id }
assigns(:comments).should eq [old_comment]
end
@@ -58,7 +58,7 @@ describe CommentsController do
post = FactoryGirl.create(:post)
old_comment = FactoryGirl.create(:comment, post: post)
comment = FactoryGirl.create(:comment, post: post, author: @member)
get :edit, {id: comment.to_param}
get :edit, { id: comment.to_param }
assigns(:comments).should eq([comment, old_comment])
end
end
@@ -67,7 +67,7 @@ describe CommentsController do
describe "with valid params" do
it "redirects to the comment's post" do
comment = Comment.create! valid_attributes
put :update, {id: comment.to_param, comment: valid_attributes}
put :update, { id: comment.to_param, comment: valid_attributes }
response.should redirect_to(comment.post)
end
end
@@ -77,7 +77,7 @@ describe CommentsController do
it "redirects to the post the comment was on" do
comment = Comment.create! valid_attributes
post = comment.post
delete :destroy, {id: comment.to_param}
delete :destroy, { id: comment.to_param }
response.should redirect_to(post)
end
end

View File

@@ -17,6 +17,6 @@ describe GardensController do
def valid_attributes
member = FactoryGirl.create(:member)
{name: 'My Garden', owner_id: member.id }
{ name: 'My Garden', owner_id: member.id }
end
end

View File

@@ -39,19 +39,19 @@ describe HarvestsController do
end
it "picks up owner from params and shows owner's harvests only" do
get :index, {owner: @member1.slug}
get :index, { owner: @member1.slug }
assigns(:owner).should eq @member1
assigns(:harvests).should eq [@harvest1]
end
it "picks up crop from params and shows the harvests for the crop only" do
get :index, {crop: @maize.name}
get :index, { crop: @maize.name }
assigns(:crop).should eq @maize
assigns(:harvests).should eq [@harvest2]
end
it "generates a csv" do
get :index, {format: "csv"}
get :index, { format: "csv" }
response.status.should eq 200
end
end
@@ -59,7 +59,7 @@ describe HarvestsController do
describe "GET show" do
it "assigns the requested harvest as @harvest" do
harvest = Harvest.create! valid_attributes
get :show, {id: harvest.to_param}
get :show, { id: harvest.to_param }
assigns(:harvest).should eq(harvest)
end
end
@@ -74,7 +74,7 @@ describe HarvestsController do
describe "GET edit" do
it "assigns the requested harvest as @harvest" do
harvest = Harvest.create! valid_attributes
get :edit, {id: harvest.to_param}
get :edit, { id: harvest.to_param }
assigns(:harvest).should eq(harvest)
end
end
@@ -83,18 +83,18 @@ describe HarvestsController do
describe "with valid params" do
it "creates a new Harvest" do
expect {
post :create, {harvest: valid_attributes}
post :create, { harvest: valid_attributes }
}.to change(Harvest, :count).by(1)
end
it "assigns a newly created harvest as @harvest" do
post :create, {harvest: valid_attributes}
post :create, { harvest: valid_attributes }
assigns(:harvest).should be_a(Harvest)
assigns(:harvest).should be_persisted
end
it "redirects to the created harvest" do
post :create, {harvest: valid_attributes}
post :create, { harvest: valid_attributes }
response.should redirect_to(Harvest.last)
end
end
@@ -103,14 +103,14 @@ describe HarvestsController do
it "assigns a newly created but unsaved harvest as @harvest" do
# Trigger the behavior that occurs when invalid params are submitted
Harvest.any_instance.stub(:save).and_return(false)
post :create, {harvest: { "crop_id" => "invalid value" }}
post :create, { harvest: { "crop_id" => "invalid value" } }
assigns(:harvest).should be_a_new(Harvest)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Harvest.any_instance.stub(:save).and_return(false)
post :create, {harvest: { "crop_id" => "invalid value" }}
post :create, { harvest: { "crop_id" => "invalid value" } }
response.should render_template("new")
end
end
@@ -125,18 +125,18 @@ describe HarvestsController do
# receives the :update message with whatever params are
# submitted in the request.
Harvest.any_instance.should_receive(:update).with({ "crop_id" => "1" })
put :update, {id: harvest.to_param, harvest: { "crop_id" => "1" }}
put :update, { id: harvest.to_param, harvest: { "crop_id" => "1" } }
end
it "assigns the requested harvest as @harvest" do
harvest = Harvest.create! valid_attributes
put :update, {id: harvest.to_param, harvest: valid_attributes}
put :update, { id: harvest.to_param, harvest: valid_attributes }
assigns(:harvest).should eq(harvest)
end
it "redirects to the harvest" do
harvest = Harvest.create! valid_attributes
put :update, {id: harvest.to_param, harvest: valid_attributes}
put :update, { id: harvest.to_param, harvest: valid_attributes }
response.should redirect_to(harvest)
end
end
@@ -146,7 +146,7 @@ describe HarvestsController do
harvest = Harvest.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Harvest.any_instance.stub(:save).and_return(false)
put :update, {id: harvest.to_param, harvest: { "crop_id" => "invalid value" }}
put :update, { id: harvest.to_param, harvest: { "crop_id" => "invalid value" } }
assigns(:harvest).should eq(harvest)
end
@@ -154,7 +154,7 @@ describe HarvestsController do
harvest = Harvest.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Harvest.any_instance.stub(:save).and_return(false)
put :update, {id: harvest.to_param, harvest: { "crop_id" => "invalid value" }}
put :update, { id: harvest.to_param, harvest: { "crop_id" => "invalid value" } }
response.should render_template("edit")
end
end
@@ -164,13 +164,13 @@ describe HarvestsController do
it "destroys the requested harvest" do
harvest = Harvest.create! valid_attributes
expect {
delete :destroy, {id: harvest.to_param}
delete :destroy, { id: harvest.to_param }
}.to change(Harvest, :count).by(-1)
end
it "redirects to the harvests list" do
harvest = Harvest.create! valid_attributes
delete :destroy, {id: harvest.to_param}
delete :destroy, { id: harvest.to_param }
response.should redirect_to(harvests_url)
end
end

View File

@@ -15,7 +15,7 @@ require 'rails_helper'
describe MembersController do
before :each do
@member = FactoryGirl.create(:member)
@posts = [ FactoryGirl.create(:post, author: @member) ]
@posts = [FactoryGirl.create(:post, author: @member)]
@twitter_auth = FactoryGirl.create(:authentication, member: @member)
@flickr_auth = FactoryGirl.create(:flickr_authentication, member: @member)
end
@@ -36,32 +36,32 @@ describe MembersController do
describe "GET show" do
it "provides JSON for member profile" do
get :show, { id: @member.id , format: 'json' }
get :show, { id: @member.id, format: 'json' }
response.should be_success
end
it "assigns @posts with the member's posts" do
get :show, {id: @member.id}
get :show, { id: @member.id }
assigns(:posts).should eq(@posts)
end
it "assigns @twitter_auth" do
get :show, {id: @member.id}
get :show, { id: @member.id }
assigns(:twitter_auth).should eq(@twitter_auth)
end
it "assigns @flickr_auth" do
get :show, {id: @member.id}
get :show, { id: @member.id }
assigns(:flickr_auth).should eq(@flickr_auth)
end
it "doesn't show completely nonsense members" do
lambda { get :show, {id: 9999} }.should raise_error(ActiveRecord::RecordNotFound)
lambda { get :show, { id: 9999 } }.should raise_error(ActiveRecord::RecordNotFound)
end
it "doesn't show unconfirmed members" do
@member2 = FactoryGirl.create(:unconfirmed_member)
lambda { get :show, {id: @member2.id} }.should raise_error(ActiveRecord::RecordNotFound)
lambda { get :show, { id: @member2.id } }.should raise_error(ActiveRecord::RecordNotFound)
end
end

View File

@@ -51,14 +51,14 @@ describe NotificationsController do
describe "GET show" do
it "assigns the requested notification as @notification" do
notification = FactoryGirl.create(:notification, recipient_id: subject.current_member.id)
get :show, {id: notification.to_param}
get :show, { id: notification.to_param }
assigns(:notification).should eq(notification)
end
it "assigns the reply link for a post comment" do
notification = FactoryGirl.create(:notification, recipient_id: subject.current_member.id)
get :show, {id: notification.to_param}
get :show, { id: notification.to_param }
assigns(:reply_link).should_not be_nil
assigns(:reply_link).should eq new_comment_url(
post_id: notification.post.id
@@ -67,7 +67,7 @@ describe NotificationsController do
it "marks notifications as read" do
notification = FactoryGirl.create(:notification, recipient_id: subject.current_member.id)
get :show, {id: notification.to_param}
get :show, { id: notification.to_param }
# we need to fetch it from the db again, can't test against the old one
n = Notification.find(notification.id)
n.read.should eq true
@@ -77,7 +77,7 @@ describe NotificationsController do
describe "GET reply" do
it "marks notifications as read" do
notification = FactoryGirl.create(:notification, recipient_id: subject.current_member.id)
get :reply, {id: notification.to_param}
get :reply, { id: notification.to_param }
# we need to fetch it from the db again, can't test against the old one
n = Notification.find(notification.id)
n.read.should eq true
@@ -87,7 +87,7 @@ describe NotificationsController do
describe "GET new" do
it "assigns a recipient" do
@recipient = FactoryGirl.create(:member)
get :new, {recipient_id: @recipient.id }
get :new, { recipient_id: @recipient.id }
assigns(:recipient).should be_an_instance_of(Member)
end
end

View File

@@ -30,11 +30,11 @@ describe OrderItemsController do
describe "POST create" do
it "redirects to order" do
@order = FactoryGirl.create(:order, member: @member)
post :create, {order_item: {
post :create, { order_item: {
order_id: @order.id,
product_id: @product.id,
price: @product.min_price
}}
} }
response.should redirect_to(OrderItem.last.order)
end
@@ -43,10 +43,10 @@ describe OrderItemsController do
sign_in @member
@product = FactoryGirl.create(:product)
expect {
post :create, {order_item: {
post :create, { order_item: {
product_id: @product.id,
price: @product.min_price
}}
} }
}.to change(Order, :count).by(1)
OrderItem.last.order.should be_an_instance_of Order
end
@@ -56,11 +56,11 @@ describe OrderItemsController do
@order = FactoryGirl.create(:order, member: @member)
@product = FactoryGirl.create(:product, min_price: 1)
expect {
post :create, {order_item: {
post :create, { order_item: {
order_id: @order.id,
product_id: @product.id,
price: 3.33
}}
} }
}.to change(OrderItem, :count).by(1)
OrderItem.last.price.should eq 333
end

View File

@@ -28,7 +28,7 @@ describe OrdersController do
member = FactoryGirl.create(:member)
sign_in member
order = Order.create!(member_id: member.id)
get :checkout, {id: order.to_param, referral_code: 'FOOBAR'}
get :checkout, { id: order.to_param, referral_code: 'FOOBAR' }
order.reload
order.referral_code.should eq 'FOOBAR'
end
@@ -37,7 +37,7 @@ describe OrdersController do
member = FactoryGirl.create(:member)
sign_in member
order = Order.create!(member_id: member.id)
get :checkout, {id: order.to_param}
get :checkout, { id: order.to_param }
response.status.should eq 302
response.redirect_url.should match /paypal\.com/
end
@@ -48,7 +48,7 @@ describe OrdersController do
member = FactoryGirl.create(:member)
sign_in member
order = Order.create!(member_id: member.id)
get :complete, {id: order.to_param}
get :complete, { id: order.to_param }
assigns(:order).should eq(order)
end
end
@@ -58,7 +58,7 @@ describe OrdersController do
member = FactoryGirl.create(:member)
sign_in member
order = Order.create!(member_id: member.id)
delete :destroy, {id: order.id}
delete :destroy, { id: order.id }
response.should redirect_to(shop_url)
end
end

View File

@@ -38,13 +38,13 @@ describe PlantingsController do
end
it "picks up owner from params and shows owner's plantings only" do
get :index, {owner: @member1.slug}
get :index, { owner: @member1.slug }
assigns(:owner).should eq @member1
assigns(:plantings).should eq [@planting1]
end
it "picks up crop from params and shows the plantings for the crop only" do
get :index, {crop: @maize.name}
get :index, { crop: @maize.name }
assigns(:crop).should eq @maize
assigns(:plantings).should eq [@planting2]
end
@@ -53,7 +53,7 @@ describe PlantingsController do
describe "GET new" do
it "picks up crop from params" do
crop = FactoryGirl.create(:crop)
get :new, {crop_id: crop.id}
get :new, { crop_id: crop.id }
assigns(:crop).should eq(crop)
end
@@ -65,7 +65,7 @@ describe PlantingsController do
it "picks up garden from params" do
member = FactoryGirl.create(:member)
garden = FactoryGirl.create(:garden, owner: member)
get :new, {garden_id: garden.id}
get :new, { garden_id: garden.id }
assigns(:garden).should eq(garden)
end

View File

@@ -6,7 +6,7 @@ describe RobotsController do
let(:staging_filename) { 'config/robots.staging.txt' }
before do
@request.host = "#{ subdomain }.localhost.com"
@request.host = "#{subdomain}.localhost.com"
end
context 'subdomain is staging' do

View File

@@ -16,7 +16,7 @@ describe SeedsController do
describe "GET index" do
it "picks up owner from params" do
owner = FactoryGirl.create(:member)
get :index, {owner: owner.slug}
get :index, { owner: owner.slug }
assigns(:owner).should eq(owner)
end
end

View File

@@ -1,6 +1,6 @@
require 'rspec/expectations'
RSpec::Matchers.define :have_optional do | expected |
RSpec::Matchers.define :have_optional do |expected|
match do |actual|
actual.has_selector? "#{expected} + span", text: '(Optional)'
end

View File

@@ -58,7 +58,7 @@ FactoryGirl.define do
creator "cropbot"
end
#for testing crop request
# for testing crop request
factory :crop_request do
name "Ultra berry"
en_wikipedia_url ""

View File

@@ -60,12 +60,12 @@ FactoryGirl.define do
end
factory :admin_member do
roles { [ FactoryGirl.create(:admin) ] }
roles { [FactoryGirl.create(:admin)] }
end
factory :crop_wrangling_member do
roles { [ FactoryGirl.create(:crop_wrangler) ] }
sequence(:login_name) {|n| "wrangler#{n}"}
roles { [FactoryGirl.create(:crop_wrangler)] }
sequence(:login_name) { |n| "wrangler#{n}" }
end
factory :invalid_member_shortname do

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
feature "browse crops" do
let(:tomato) { create :tomato }
let(:maize) { create :maize }
let(:pending_crop) { create :crop_request }
let(:pending_crop) { create :crop_request }
let(:rejected_crop) { create :rejected_crop }
scenario "has a form for sorting by" do

View File

@@ -111,23 +111,23 @@ feature "crop detail page", js: true do
background { subject }
scenario "has seed heading with SEO" do
expect(page).to have_content "Find #{ crop.name } seeds"
expect(page).to have_content "Find #{crop.name} seeds"
end
scenario "has harvest heading with SEO" do
expect(page).to have_content "#{ crop.name.capitalize } harvests"
expect(page).to have_content "#{crop.name.capitalize} harvests"
end
scenario "has planting heading with SEO" do
expect(page).to have_content "See who's planted #{ crop.name.pluralize }"
expect(page).to have_content "See who's planted #{crop.name.pluralize}"
end
scenario "has planting advice with SEO" do
expect(page).to have_content "How to grow #{ crop.name }"
expect(page).to have_content "How to grow #{crop.name}"
end
scenario "has a link to Wikipedia with SEO" do
expect(page).to have_content "Learn more about #{ crop.name }"
expect(page).to have_content "Learn more about #{crop.name}"
expect(page).to have_link "Wikipedia (English)", href: crop.en_wikipedia_url
end

View File

@@ -9,6 +9,6 @@ feature 'Plantings RSS feed' do
scenario 'The index title is what we expect' do
visit plantings_path(format: 'rss')
expect(page).to have_content "Recent plantings from "\
"#{ @owner ? @owner : 'all members' } (#{ENV['GROWSTUFF_SITE_NAME']})"
"#{@owner ? @owner : 'all members'} (#{ENV['GROWSTUFF_SITE_NAME']})"
end
end

View File

@@ -9,6 +9,6 @@ feature 'Posts RSS feed' do
scenario 'The index title is what we expect' do
visit posts_path(format: 'rss')
expect(page).to have_content "Recent posts from "\
"#{ @author ? @author : 'all members' } (#{ENV['GROWSTUFF_SITE_NAME']})"
"#{@author ? @author : 'all members'} (#{ENV['GROWSTUFF_SITE_NAME']})"
end
end

View File

@@ -9,6 +9,6 @@ feature 'Seeds RSS feed' do
scenario 'The index title is what we expect' do
visit seeds_path(format: 'rss')
expect(page).to have_content "Recent seeds from "\
"#{ @owner ? @owner : 'all members' } (#{ENV['GROWSTUFF_SITE_NAME']})"
"#{@owner ? @owner : 'all members'} (#{ENV['GROWSTUFF_SITE_NAME']})"
end
end

View File

@@ -28,7 +28,7 @@ describe 'Growstuff::OauthSignupAction' do
before :each do
@auth['info']['email'] = 'no.existing.user@gmail.com'
Member.where(email: @auth['info']['email']).delete_all
Member.where(email: @auth['info']['email']).delete_all
@member = @action.find_or_create_from_authorization(@auth)
@authentication = @action.establish_authentication(@auth, @member)

View File

@@ -6,7 +6,7 @@ def input_link(name)
return "[#{name}](crop)"
end
def output_link(crop, name=nil)
def output_link(crop, name = nil)
url = Rails.application.routes.url_helpers.crop_url(crop, host: Growstuff::Application.config.host)
if name
return "<a href=\"#{url}\">#{name}</a>"
@@ -19,7 +19,7 @@ def input_member_link(name)
return "[#{name}](member)"
end
def output_member_link(member, name=nil)
def output_member_link(member, name = nil)
url = Rails.application.routes.url_helpers.member_url(member, only_path: true)
if name
return "<a href=\"#{url}\">#{name}</a>"
@@ -47,7 +47,7 @@ describe 'Haml::Filters::Growstuff_Markdown' do
it "doesn't convert escaped crop links" do
@crop = FactoryGirl.create(:crop)
rendered = Haml::Filters::GrowstuffMarkdown.render( "\\" << input_link(@crop.name))
rendered = Haml::Filters::GrowstuffMarkdown.render("\\" << input_link(@crop.name))
rendered.should match /\[#{@crop.name}\]\(crop\)/
end

View File

@@ -100,7 +100,7 @@ describe Crop do
it 'toplevel scope works' do
@tomato = FactoryGirl.create(:tomato)
@roma = FactoryGirl.create(:roma, parent_id: @tomato.id)
Crop.toplevel.should eq [ @tomato ]
Crop.toplevel.should eq [@tomato]
end
end

View File

@@ -45,7 +45,8 @@ describe Harvest do
context 'units' do
it 'all valid units should work' do
['individual','bunch','sprig','handful','litre','pint','quart','bucket','basket','bushel', nil, ''].each do |s|
['individual', 'bunch', 'sprig', 'handful', 'litre',
'pint', 'quart', 'bucket', 'basket', 'bushel', nil, ''].each do |s|
@harvest = FactoryGirl.build(:harvest, unit: s)
@harvest.should be_valid
end

View File

@@ -275,7 +275,7 @@ describe 'member' do
@member2.updated_at = 2.days.ago
@member3.updated_at = 1.days.ago
Member.interesting.should eq [ @member3, @member2, @member1 ]
Member.interesting.should eq [@member3, @member2, @member1]
end
end

View File

@@ -300,7 +300,7 @@ describe Planting do
context "finished date validation" do
it 'requires finished date after planting date' do
@f = FactoryGirl.build(:finished_planting, planted_at: '2014-01-01', finished_at: '2013-01-01')
@f = FactoryGirl.build(:finished_planting, planted_at: '2014-01-01', finished_at: '2013-01-01')
@f.should_not be_valid
end

View File

@@ -1,7 +1,7 @@
require 'rails_helper'
describe Role do
let(:member) { FactoryGirl.create(:member) }
let(:member) { FactoryGirl.create(:member) }
subject do
role = FactoryGirl.create(:role, name: 'Crop Wrangler')

View File

@@ -37,7 +37,7 @@ if ENV['GROWSTUFF_CAPYBARA_DRIVER'].present?
end
Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
"screenshot_#{example.description.gsub(' ', '-').gsub(/^.*\/spec\//,'')}"
"screenshot_#{example.description.gsub(' ', '-').gsub(/^.*\/spec\//, '')}"
end
Capybara.app_host = 'http://localhost'
@@ -59,7 +59,7 @@ include Warden::Test::Helpers
# require only the support files necessary.
#
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
Dir[Rails.root.join("spec/features/shared_examples/**/*.rb")].each {|f| require f}
Dir[Rails.root.join("spec/features/shared_examples/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.

View File

@@ -1,6 +1,6 @@
# Taken unashamedly from https://github.com/plataformatec/devise/wiki/How-To%3a-Controllers-and-Views-tests-with-Rails-3-%28and-rspec%29
module ControllerMacros
def login_member(member_factory=:member)
def login_member(member_factory = :member)
let(:member) { member = FactoryGirl.create(member_factory || :member) }
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:member]

View File

@@ -1,7 +1,7 @@
module ElasticsearchHelpers
def sync_elasticsearch(crops)
if ENV['GROWSTUFF_ELASTICSEARCH'] == "true"
crops.each {|crop| crop.__elasticsearch__.index_document}
crops.each { |crop| crop.__elasticsearch__.index_document }
Crop.__elasticsearch__.refresh_index!
end
end

View File

@@ -1,5 +1,5 @@
module FeatureHelpers
def fill_autocomplete(field, options={})
def fill_autocomplete(field, options = {})
fill_in field, with: options[:with]
page.execute_script %Q{ $('##{field}').trigger('focus'); }

View File

@@ -14,7 +14,7 @@ require 'rails_helper'
describe "crops/_planting_advice" do
before(:each) do
@owner = FactoryGirl.create(:member)
@owner = FactoryGirl.create(:member)
@crop = FactoryGirl.create(:crop)
@garden = FactoryGirl.create(:garden, owner: @owner)
@planting = FactoryGirl.create(:planting,

View File

@@ -22,7 +22,7 @@ describe "crops/index" do
@maize = FactoryGirl.create(:maize)
assign(:crops, [@tomato, @maize])
paginated_crops = WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
pager.replace([ @tomato, @maize ])
pager.replace([@tomato, @maize])
end
assign(:paginated_crops, paginated_crops)
end

View File

@@ -22,7 +22,7 @@ describe "crops/wrangle" do
@tomato = FactoryGirl.create(:tomato)
@maize = FactoryGirl.create(:maize)
crops = WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
pager.replace([ @tomato, @maize ])
pager.replace([@tomato, @maize])
end
assign(:crops, crops)
assign(:crop_wranglers, Role.crop_wranglers)

View File

@@ -12,14 +12,14 @@ describe 'devise/shared/_links.haml', type: "view" do
it 'should have a sign-in link if not in sessions' do
@view.stub(:controller_name).and_return("anything but sessions")
@view.stub(:resource_name).and_return("member")
@view.stub(devise_mapping: devise_mapping(false, false, false, false, false))
@view.stub(devise_mapping: devise_mapping(false, false, false, false, false))
render
end
it "shouldn't have a sign-in link if in sessions" do
@view.stub(:controller_name).and_return("sessions")
@view.stub(:resource_name).and_return("member")
@view.stub(devise_mapping: devise_mapping(false, false, false, false, false))
@view.stub(devise_mapping: devise_mapping(false, false, false, false, false))
render
end
end

View File

@@ -18,7 +18,7 @@ describe "forums/index" do
controller.stub(:current_user) { @admin }
@forum1 = FactoryGirl.create(:forum)
@forum2 = FactoryGirl.create(:forum)
assign(:forums, [ @forum1, @forum2 ])
assign(:forums, [@forum1, @forum2])
end
it "renders a list of forums" do

View File

@@ -14,7 +14,7 @@ require 'rails_helper'
describe "gardens/show" do
before(:each) do
@owner = FactoryGirl.create(:member)
@owner = FactoryGirl.create(:member)
controller.stub(:current_user) { @owner }
@garden = FactoryGirl.create(:garden, owner: @owner)
@planting = FactoryGirl.create(:planting, garden: @garden)

View File

@@ -15,7 +15,7 @@ require 'rails_helper'
describe "harvests/index" do
before(:each) do
controller.stub(:current_user) { nil }
@member = FactoryGirl.create(:member)
@member = FactoryGirl.create(:member)
@tomato = FactoryGirl.create(:tomato)
@maize = FactoryGirl.create(:maize)
@pp = FactoryGirl.create(:plant_part)

View File

@@ -20,7 +20,7 @@ describe "members/index" do
total_entries = 2
@member = FactoryGirl.create(:london_member)
members = WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
pager.replace([ @member, @member ])
pager.replace([@member, @member])
end
assign(:members, members)
render

View File

@@ -22,7 +22,7 @@ describe "notifications/index" do
before(:each) do
@notification = FactoryGirl.create(:notification, sender: @member,
recipient: @member)
assign(:notifications, Kaminari.paginate_array([ @notification, @notification ]).page(1))
assign(:notifications, Kaminari.paginate_array([@notification, @notification]).page(1))
render
end

View File

@@ -18,7 +18,7 @@ describe "notifications/new" do
@sender = FactoryGirl.create(:member)
assign(:notification, FactoryGirl.create(:notification, recipient_id: @recipient.id, sender_id: @sender.id))
sign_in @sender
controller.stub(:current_user) { @sender}
controller.stub(:current_user) { @sender }
end
it "renders new message form" do

View File

@@ -32,6 +32,6 @@ describe "notifications/show" do
end
it "includes a reply button" do
assert_select "a", {href: @reply_link}, "Reply"
assert_select "a", { href: @reply_link }, "Reply"
end
end

View File

@@ -18,7 +18,7 @@ describe "orders/index" do
sign_in @member
@order1 = FactoryGirl.create(:order, member: @member)
@order2 = FactoryGirl.create(:completed_order, member: @member)
assign(:orders, [ @order1, @order2 ])
assign(:orders, [@order1, @order2])
end
it "shows your current account status" do

View File

@@ -35,7 +35,7 @@ describe "photos/new" do
context "user has photosets" do
before(:each) do
assign(:sets, {"foo" => "bar"}) # Hash of names => IDs
assign(:sets, { "foo" => "bar" }) # Hash of names => IDs
end
it "shows a dropdown with sets from Flickr" do
@@ -44,7 +44,7 @@ describe "photos/new" do
end
it "shows the current photoset" do
assign(:current_set, "bar") # the ID of the set
assign(:current_set, "bar") # the ID of the set
render
assert_select "h2", "foo" # the name of the set
end

View File

@@ -15,7 +15,7 @@ require 'rails_helper'
describe "plantings/index" do
before(:each) do
controller.stub(:current_user) { nil }
@member = FactoryGirl.create(:member)
@member = FactoryGirl.create(:member)
@garden = FactoryGirl.create(:garden, owner: @member)
@tomato = FactoryGirl.create(:tomato)
@maize = FactoryGirl.create(:maize)

View File

@@ -50,7 +50,7 @@ describe 'plantings/index.rss.haml' do
context "one person's plantings" do
before :each do
@planting = FactoryGirl.create(:planting)
assign(:plantings, [@planting ])
assign(:plantings, [@planting])
assign(:owner, @planting.owner)
render
end

View File

@@ -32,7 +32,7 @@ describe "posts/_single" do
end
it "doesn't contain a link to new comment" do
assert_select("a", {href: new_comment_path(post_id: @post.id)}, false)
assert_select("a", { href: new_comment_path(post_id: @post.id) }, false)
end
end
@@ -45,7 +45,7 @@ describe "posts/_single" do
end
it "contains link to new comment" do
assert_select("a", {href: new_comment_path(post_id: @post.id)}, "Reply")
assert_select("a", { href: new_comment_path(post_id: @post.id) }, "Reply")
end
it "does not contain an edit link" do

View File

@@ -43,7 +43,7 @@ describe "posts/edit" do
context "forum specified" do
before(:each) do
@forum = assign(:forum, FactoryGirl.create(:forum))
assign(:post, FactoryGirl.create( :post,
assign(:post, FactoryGirl.create(:post,
forum: @forum,
author: @author
))

View File

@@ -114,7 +114,7 @@ describe "posts/show" do
end
it 'shows a comment button' do
assert_select "a", {href: new_comment_path(post_id: @post.id)}, "Comment"
assert_select "a", { href: new_comment_path(post_id: @post.id) }, "Comment"
end
end
end

View File

@@ -21,7 +21,7 @@ describe 'seeds/index.rss.haml' do
before(:each) do
@seed = FactoryGirl.create(:seed)
@tradable = FactoryGirl.create(:tradable_seed)
assign(:seeds, [ @seed, @tradable ])
assign(:seeds, [@seed, @tradable])
render
end
@@ -49,7 +49,7 @@ describe 'seeds/index.rss.haml' do
context "one member's seeds" do
before(:each) do
@seed = FactoryGirl.create(:seed)
assign(:seeds, [ @seed ])
assign(:seeds, [@seed])
assign(:owner, @seed.owner)
render
end