$ rubocop --only HashSyntax --auto-correct

483 files inspected, 2018 offenses detected, 2018 offenses corrected
This commit is contained in:
Daniel O'Connor
2016-04-14 10:06:02 +09:30
committed by Mackenzie Morgan
parent 8659ebca2d
commit 4b4e0cf69a
271 changed files with 1719 additions and 1721 deletions

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

@@ -1,5 +1,5 @@
class AlternateNamesController < ApplicationController
before_filter :authenticate_member!, :except => [:index, :show]
before_filter :authenticate_member!, except: [:index, :show]
load_and_authorize_resource
# GET /alternate_names

View File

@@ -35,7 +35,7 @@ class ApplicationController < ActionController::Base
# CanCan error handling
rescue_from CanCan::AccessDenied do |exception|
redirect_to request.referer || root_url, :alert => exception.message
redirect_to request.referer || root_url, alert: exception.message
end
def set_locale

View File

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

View File

@@ -1,16 +1,16 @@
class CommentsController < ApplicationController
before_filter :authenticate_member!, :except => [:index, :show]
before_filter :authenticate_member!, except: [:index, :show]
load_and_authorize_resource
# GET /comments
# GET /comments.json
def index
@comments = Comment.paginate(:page => params[:page])
@comments = Comment.paginate(page: params[:page])
respond_to do |format|
format.html # index.html.erb
format.json { render json: @comments }
format.rss { render :layout => false }
format.rss { render layout: false }
end
end
@@ -39,7 +39,7 @@ class CommentsController < ApplicationController
end
else
redirect_to request.referer || root_url,
:alert => "Can't post a comment on a non-existent post"
alert: "Can't post a comment on a non-existent post"
end
end

View File

@@ -1,9 +1,9 @@
require 'will_paginate/array'
class CropsController < ApplicationController
before_filter :authenticate_member!, :except => [:index, :hierarchy, :search, :show]
before_filter :authenticate_member!, except: [:index, :hierarchy, :search, :show]
load_and_authorize_resource
skip_authorize_resource :only => [:hierarchy, :search]
skip_authorize_resource only: [:hierarchy, :search]
# GET /crops
# GET /crops.json
@@ -11,25 +11,25 @@ class CropsController < ApplicationController
@sort = params[:sort]
if @sort == 'alpha'
# alphabetical order
@crops = Crop.includes(:scientific_names, {:plantings => :photos})
@paginated_crops = @crops.approved.paginate(:page => params[:page])
@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})
@paginated_crops = @crops.approved.paginate(:page => params[:page])
@crops = Crop.popular.includes(:scientific_names, {plantings: :photos})
@paginated_crops = @crops.approved.paginate(page: params[:page])
end
respond_to do |format|
format.html
format.json { render :json => @crops }
format.json { render json: @crops }
format.rss do
@crops = Crop.recent.includes(:scientific_names, :creator)
render :rss => @crops
render rss: @crops
end
format.csv do
@filename = "Growstuff-Crops-#{Time.zone.now.to_s(:number)}.csv"
@crops = Crop.includes(:scientific_names, :plantings, :seeds, :creator)
render :csv => @crops
render csv: @crops
end
end
end
@@ -46,7 +46,7 @@ class CropsController < ApplicationController
@crops = Crop.recent
end
@crops = @crops.paginate(:page => params[:page])
@crops = @crops.paginate(page: params[:page])
@crop_wranglers = Role.crop_wranglers
respond_to do |format|
@@ -66,25 +66,25 @@ class CropsController < ApplicationController
def search
@term = params[:term]
@matches = Crop.search(@term)
@paginated_matches = @matches.paginate(:page => params[:page])
@paginated_matches = @matches.paginate(page: params[:page])
respond_to do |format|
format.html
format.json { render :json => @matches }
format.json { render json: @matches }
end
end
# GET /crops/1
# GET /crops/1.json
def show
@crop = Crop.includes(:scientific_names, {:plantings => :photos}).find(params[:id])
@posts = @crop.posts.paginate(:page => params[:page])
@crop = Crop.includes(:scientific_names, {plantings: :photos}).find(params[:id])
@posts = @crop.posts.paginate(page: params[:page])
respond_to do |format|
format.html # show.html.haml
format.json do
render :json => @crop.to_json(:include => {
:plantings => { :include => { :owner => { :only => [:id, :login_name, :location, :latitude, :longitude] }}}
render json: @crop.to_json(include: {
plantings: { include: { owner: { only: [:id, :login_name, :location, :latitude, :longitude] }}}
})
end
end
@@ -207,6 +207,6 @@ class CropsController < ApplicationController
private
def crop_params
params.require(:crop).permit(:en_wikipedia_url, :name, :parent_id, :creator_id, :approval_status, :request_notes, :reason_for_rejection, :rejection_notes, :scientific_names_attributes => [:scientific_name, :_destroy, :id])
params.require(:crop).permit(:en_wikipedia_url, :name, :parent_id, :creator_id, :approval_status, :request_notes, :reason_for_rejection, :rejection_notes, scientific_names_attributes: [:scientific_name, :_destroy, :id])
end
end

View File

@@ -1,12 +1,12 @@
class FollowsController < ApplicationController
before_filter :authenticate_member!
load_and_authorize_resource
skip_load_resource :only => :create
skip_load_resource only: :create
# POST /follows
def create
@follow = current_member.follows.build(:followed_id => follow_params[:followed_id])
@follow = current_member.follows.build(followed_id: follow_params[:followed_id])
if @follow.save
flash[:notice] = "Followed #{ @follow.followed.login_name }"

View File

@@ -1,15 +1,15 @@
class GardensController < ApplicationController
before_filter :authenticate_member!, :except => [:index, :show]
before_filter :authenticate_member!, except: [:index, :show]
load_and_authorize_resource
# GET /gardens
# GET /gardens.json
def index
@gardens = Garden.paginate(:page => params[:page])
@gardens = Garden.paginate(page: params[:page])
@owner = Member.find_by_slug(params[:owner])
if @owner
@gardens = @owner.gardens.paginate(:page => params[:page])
@gardens = @owner.gardens.paginate(page: params[:page])
end
respond_to do |format|
@@ -87,7 +87,7 @@ class GardensController < ApplicationController
expire_fragment("homepage_stats")
respond_to do |format|
format.html { redirect_to gardens_by_owner_path(:owner => @garden.owner), notice: 'Garden was successfully deleted.' }
format.html { redirect_to gardens_by_owner_path(owner: @garden.owner), notice: 'Garden was successfully deleted.' }
format.json { head :no_content }
end
end

View File

@@ -1,5 +1,5 @@
class HarvestsController < ApplicationController
before_filter :authenticate_member!, :except => [:index, :show]
before_filter :authenticate_member!, except: [:index, :show]
load_and_authorize_resource
@@ -17,12 +17,12 @@ class HarvestsController < ApplicationController
end
respond_to do |format|
format.html { @harvests = @harvests.paginate(:page => params[:page]) }
format.html { @harvests = @harvests.paginate(page: params[:page]) }
format.json { render json: @harvests }
format.csv do
specifics = (@owner ? "#{@owner.login_name}-" : @crop ? "#{@crop.name}-" : nil)
@filename = "Growstuff-#{specifics}Harvests-#{Time.zone.now.to_s(:number)}.csv"
render :csv => @harvests
render csv: @harvests
end
end
end

View File

@@ -1,21 +1,21 @@
class MembersController < ApplicationController
load_and_authorize_resource
skip_authorize_resource :only => [:nearby, :unsubscribe]
skip_authorize_resource only: [:nearby, :unsubscribe]
after_action :expire_cache_fragments, :only => :create
after_action :expire_cache_fragments, only: :create
def index
@sort = params[:sort]
if @sort == 'recently_joined'
@members = Member.confirmed.recently_joined.paginate(:page => params[:page])
@members = Member.confirmed.recently_joined.paginate(page: params[:page])
else
@members = Member.confirmed.paginate(:page => params[:page])
@members = Member.confirmed.paginate(page: params[:page])
end
respond_to do |format|
format.html # index.html.haml
format.json { render :json => @members.to_json(:only => [:id, :login_name, :slug, :bio, :created_at, :location, :latitude, :longitude]) }
format.json { render json: @members.to_json(only: [:id, :login_name, :slug, :bio, :created_at, :location, :latitude, :longitude]) }
end
end
@@ -31,22 +31,22 @@ class MembersController < ApplicationController
respond_to do |format|
format.html # show.html.haml
format.json { render :json => @member.to_json(:only => [:id, :login_name, :bio, :created_at, :slug, :location, :latitude, :longitude]) }
format.json { render json: @member.to_json(only: [:id, :login_name, :bio, :created_at, :slug, :location, :latitude, :longitude]) }
format.rss { render(
:layout => false,
:locals => { :member => @member }
layout: false,
locals: { member: @member }
)}
end
end
def view_follows
@member = Member.confirmed.find(params[:login_name])
@follows = @member.followed.paginate(:page => params[:page])
@follows = @member.followed.paginate(page: params[:page])
end
def view_followers
@member = Member.confirmed.find(params[:login_name])
@followers = @member.followers.paginate(:page => params[:page])
@followers = @member.followers.paginate(page: params[:page])
end
EMAIL_TYPE_STRING = {

View File

@@ -8,7 +8,7 @@ class OrderItemsController < ApplicationController
params[:order_item][:price] = params[:order_item][:price].to_f * 100 # convert to cents
end
@order_item = OrderItem.new(order_item_params)
@order_item.order = current_member.current_order || Order.create(:member_id => current_member.id)
@order_item.order = current_member.current_order || Order.create(member_id: current_member.id)
respond_to do |format|
if @order_item.save

View File

@@ -34,15 +34,15 @@ class OrdersController < ApplicationController
@order = Order.find(params[:id])
respond_to do |format|
if @order.update_attributes(:referral_code => params[:referral_code])
if @order.update_attributes(referral_code: params[:referral_code])
response = EXPRESS_GATEWAY.setup_purchase(
@order.total,
:items => @order.activemerchant_items,
:currency => Growstuff::Application.config.currency,
:no_shipping => true,
:ip => request.remote_ip,
:return_url => complete_order_url,
:cancel_return_url => shop_url
items: @order.activemerchant_items,
currency: Growstuff::Application.config.currency,
no_shipping: true,
ip: request.remote_ip,
return_url: complete_order_url,
cancel_return_url: shop_url
)
format.html { redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token) }
else
@@ -58,10 +58,10 @@ class OrdersController < ApplicationController
if (params[:token] && params['PayerID'])
purchase = EXPRESS_GATEWAY.purchase(
@order.total,
:currency => Growstuff::Application.config.currency,
:ip => request.remote_ip,
:payer_id => params['PayerID'],
:token => params[:token]
currency: Growstuff::Application.config.currency,
ip: request.remote_ip,
payer_id: params['PayerID'],
token: params[:token]
)
if purchase.success?
@order.completed_at = Time.zone.now

View File

@@ -1,11 +1,11 @@
class PhotosController < ApplicationController
before_filter :authenticate_member!, :except => [:index, :show]
before_filter :authenticate_member!, except: [:index, :show]
load_and_authorize_resource
# GET /photos
# GET /photos.json
def index
@photos = Photo.paginate(:page => params[:page])
@photos = Photo.paginate(page: params[:page])
respond_to do |format|
format.html # index.html.erb

View File

@@ -5,7 +5,7 @@ class PlacesController < ApplicationController
respond_to do |format|
format.html
# json response is whatever we want to map here
format.json { render :json => Member.located.to_json(:only => [:id, :login_name, :slug, :location, :latitude, :longitude]) }
format.json { render json: Member.located.to_json(only: [:id, :login_name, :slug, :location, :latitude, :longitude]) }
end
end
@@ -16,7 +16,7 @@ class PlacesController < ApplicationController
@nearby_members = Member.nearest_to(params[:place])
respond_to do |format|
format.html # show.html.haml
format.json { render :json => @nearby_members.to_json(:only => [:id, :login_name, :slug, :location, :latitude, :longitude]) }
format.json { render json: @nearby_members.to_json(only: [:id, :login_name, :slug, :location, :latitude, :longitude]) }
end
end

View File

@@ -1,5 +1,5 @@
class PlantingsController < ApplicationController
before_filter :authenticate_member!, :except => [:index, :show]
before_filter :authenticate_member!, except: [:index, :show]
load_and_authorize_resource
# GET /plantings
@@ -8,21 +8,21 @@ class PlantingsController < ApplicationController
@owner = Member.find_by_slug(params[:owner])
@crop = Crop.find_by_slug(params[:crop])
if @owner
@plantings = @owner.plantings.includes(:owner, :crop, :garden).paginate(:page => params[:page])
@plantings = @owner.plantings.includes(:owner, :crop, :garden).paginate(page: params[:page])
elsif @crop
@plantings = @crop.plantings.includes(:owner, :crop, :garden).paginate(:page => params[:page])
@plantings = @crop.plantings.includes(:owner, :crop, :garden).paginate(page: params[:page])
else
@plantings = Planting.includes(:owner, :crop, :garden).paginate(:page => params[:page])
@plantings = Planting.includes(:owner, :crop, :garden).paginate(page: params[:page])
end
respond_to do |format|
format.html { @plantings = @plantings.paginate(:page => params[:page]) }
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"
render :csv => @plantings
render csv: @plantings
end
end
end

View File

@@ -1,5 +1,5 @@
class PostsController < ApplicationController
before_filter :authenticate_member!, :except => [:index, :show]
before_filter :authenticate_member!, except: [:index, :show]
load_and_authorize_resource
# GET /posts
@@ -8,29 +8,29 @@ class PostsController < ApplicationController
def index
@author = Member.find_by_slug(params[:author])
if @author
@posts = @author.posts.includes(:author, { :comments => :author }).paginate(:page => params[:page])
@posts = @author.posts.includes(:author, { comments: :author }).paginate(page: params[:page])
else
@posts = Post.includes(:author, { :comments => :author }).paginate(:page => params[:page])
@posts = Post.includes(:author, { comments: :author }).paginate(page: params[:page])
end
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
# GET /posts/1
# GET /posts/1.json
def show
@post = Post.includes(:author, { :comments => :author }).find(params[:id])
@post = Post.includes(:author, { comments: :author }).find(params[:id])
respond_to do |format|
format.html # show.html.haml
format.json { render json: @post }
format.rss { render(
:layout => false,
:locals => { :post => @post }
layout: false,
locals: { post: @post }
)}
end
end

View File

@@ -28,7 +28,7 @@ class RegistrationsController < Devise::RegistrationsController
if successfully_updated
set_flash_message :notice, :updated
# Sign in the member bypassing validation in case their password changed
sign_in @member, :bypass => true
sign_in @member, bypass: true
redirect_to edit_member_registration_path
else
render "edit"

View File

@@ -1,5 +1,5 @@
class ScientificNamesController < ApplicationController
before_filter :authenticate_member!, :except => [:index, :show]
before_filter :authenticate_member!, except: [:index, :show]
load_and_authorize_resource
# GET /scientific_names

View File

@@ -1,5 +1,5 @@
class SeedsController < ApplicationController
before_filter :authenticate_member!, :except => [:index, :show]
before_filter :authenticate_member!, except: [:index, :show]
load_and_authorize_resource
# GET /seeds
@@ -8,17 +8,17 @@ class SeedsController < ApplicationController
@owner = Member.find_by_slug(params[:owner])
@crop = Crop.find_by_slug(params[:crop])
if @owner
@seeds = @owner.seeds.includes(:owner, :crop).paginate(:page => params[:page])
@seeds = @owner.seeds.includes(:owner, :crop).paginate(page: params[:page])
elsif @crop
@seeds = @crop.seeds.includes(:owner, :crop).paginate(:page => params[:page])
@seeds = @crop.seeds.includes(:owner, :crop).paginate(page: params[:page])
else
@seeds = Seed.includes(:owner, :crop).paginate(:page => params[:page])
@seeds = Seed.includes(:owner, :crop).paginate(page: params[:page])
end
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"
@@ -27,7 +27,7 @@ class SeedsController < ApplicationController
@filename = "Growstuff-Seeds-#{Time.zone.now.to_s(:number)}.csv"
@seeds = Seed.includes(:owner, :crop)
end
render :csv => @seeds
render csv: @seeds
end
end
end

View File

@@ -21,7 +21,7 @@ module ApplicationHelper
link = "http://www.wolframalpha.com/input/?i=#{pid}+#{currency}"
return link_to "(convert)",
link,
:target => "_blank"
target: "_blank"
end
# Produces a cache key for uniquely identifying cached fragments.
@@ -46,8 +46,8 @@ module ApplicationHelper
return member.preferred_avatar_uri if member.preferred_avatar_uri.present?
Gravatar.new(member.email).image_url({
:size => size,
:default => :identicon
size: size,
default: :identicon
})
end
end

View File

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

View File

@@ -2,7 +2,7 @@ module NotificationsHelper
def reply_link(notification)
if notification.post
# comment on the post in question
new_comment_url(:post_id => notification.post.id)
new_comment_url(post_id: notification.post.id)
else
# by default, reply link sends a PM in return
reply_notification_url(notification)

View File

@@ -17,8 +17,8 @@ class Notifier < ActionMailer::Base
# Encrypting
@signed_message = verifier.generate ({ member_id: @notification.recipient.id, type: :send_notification_email })
mail(:to => @notification.recipient.email,
:subject => @notification.subject)
mail(to: @notification.recipient.email,
subject: @notification.subject)
end
def planting_reminder(member)
@@ -31,24 +31,24 @@ class Notifier < ActionMailer::Base
@signed_message = verifier.generate ({ member_id: @member.id, type: :send_planting_reminder })
if @member.send_planting_reminder
mail(:to => @member.email,
:subject => "What have you planted lately?")
mail(to: @member.email,
subject: "What have you planted lately?")
end
end
def new_crop_request(member, request)
@member, @request = member, request
mail(:to => @member.email, :subject => "#{@request.requester.login_name} has requested #{@request.name} as a new crop")
mail(to: @member.email, subject: "#{@request.requester.login_name} has requested #{@request.name} as a new crop")
end
def crop_request_approved(member, crop)
@member, @crop = member, crop
mail(:to => @member.email, :subject => "#{crop.name.capitalize} has been approved")
mail(to: @member.email, subject: "#{crop.name.capitalize} has been approved")
end
def crop_request_rejected(member, crop)
@member, @crop = member, crop
mail(:to => @member.email, :subject => "#{crop.name.capitalize} has been rejected")
mail(to: @member.email, subject: "#{crop.name.capitalize} has been rejected")
end
end

View File

@@ -24,7 +24,7 @@ class Ability
# nobody should be able to view unapproved crops unless they
# are wranglers or admins
cannot :read, Crop
can :read, Crop, :approval_status => "approved"
can :read, Crop, approval_status: "approved"
# scientific names should only be viewable if associated crop is approved
cannot :read, ScientificName
can :read, ScientificName do |sn|
@@ -38,15 +38,15 @@ class Ability
if member
# members can see even rejected or pending crops if they requested it
can :read, Crop, :requester_id => member.id
can :read, Crop, requester_id: member.id
# managing your own user settings
can :update, Member, :id => member.id
can :update, Member, id: member.id
# can read/delete notifications that were sent to them
can :read, Notification, :recipient_id => member.id
can :destroy, Notification, :recipient_id => member.id
can :reply, Notification, :recipient_id => member.id
can :read, Notification, recipient_id: member.id
can :destroy, Notification, recipient_id: member.id
can :reply, Notification, recipient_id: member.id
# can send a private message to anyone but themselves
# note: sadly, we can't test for this from the view, but it works
# for the model/controller
@@ -68,58 +68,58 @@ class Ability
# can create & destroy their own authentications against other sites.
can :create, Authentication
can :destroy, Authentication, :member_id => member.id
can :destroy, Authentication, member_id: member.id
# anyone can create a post, or comment on a post,
# but only the author can edit/destroy it.
can :create, Post
can :update, Post, :author_id => member.id
can :destroy, Post, :author_id => member.id
can :update, Post, author_id: member.id
can :destroy, Post, author_id: member.id
can :create, Comment
can :update, Comment, :author_id => member.id
can :destroy, Comment, :author_id => member.id
can :update, Comment, author_id: member.id
can :destroy, Comment, author_id: member.id
# same deal for gardens and plantings
can :create, Garden
can :update, Garden, :owner_id => member.id
can :destroy, Garden, :owner_id => member.id
can :update, Garden, owner_id: member.id
can :destroy, Garden, owner_id: member.id
can :create, Planting
can :update, Planting, :garden => { :owner_id => member.id }
can :destroy, Planting, :garden => { :owner_id => member.id }
can :update, Planting, garden: { owner_id: member.id }
can :destroy, Planting, garden: { owner_id: member.id }
can :create, Harvest
can :update, Harvest, :owner_id => member.id
can :destroy, Harvest, :owner_id => member.id
can :update, Harvest, owner_id: member.id
can :destroy, Harvest, owner_id: member.id
can :create, Photo
can :update, Photo, :owner_id => member.id
can :destroy, Photo, :owner_id => member.id
can :update, Photo, owner_id: member.id
can :destroy, Photo, owner_id: member.id
can :create, Seed
can :update, Seed, :owner_id => member.id
can :destroy, Seed, :owner_id => member.id
can :update, Seed, owner_id: member.id
can :destroy, Seed, owner_id: member.id
# orders/shop/etc
can :create, Order
can :read, Order, :member_id => member.id
can :complete, Order, :member_id => member.id, :completed_at => nil
can :checkout, Order, :member_id => member.id, :completed_at => nil
can :cancel, Order, :member_id => member.id, :completed_at => nil
can :destroy, Order, :member_id => member.id, :completed_at => nil
can :read, Order, member_id: member.id
can :complete, Order, member_id: member.id, completed_at: nil
can :checkout, Order, member_id: member.id, completed_at: nil
can :cancel, Order, member_id: member.id, completed_at: nil
can :destroy, Order, member_id: member.id, completed_at: nil
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 }
cannot :destroy, OrderItem, :order => { :member_id => member.id, :completed_at => nil }
cannot :read, OrderItem, order: { member_id: member.id }
cannot :update, OrderItem, order: { member_id: member.id, completed_at: nil }
cannot :destroy, OrderItem, order: { member_id: member.id, completed_at: nil }
# following/unfollowing permissions
can :create, Follow
cannot :create, Follow, :followed_id => member.id # can't follow yourself
cannot :create, Follow, followed_id: member.id # can't follow yourself
can :destroy, Follow
cannot :destroy, Follow, :followed_id => member.id # can't unfollow yourself
cannot :destroy, Follow, followed_id: member.id # can't unfollow yourself
if member.has_role? :admin

View File

@@ -2,8 +2,8 @@ class Account < ActiveRecord::Base
belongs_to :member
belongs_to :account_type
validates :member_id, :uniqueness => {
:message => 'already has account details associated with it'
validates :member_id, uniqueness: {
message: 'already has account details associated with it'
}
before_create do |account|

View File

@@ -1,5 +1,5 @@
class AlternateName < ActiveRecord::Base
after_commit { |an| an.crop.__elasticsearch__.index_document if an.crop && ENV['GROWSTUFF_ELASTICSEARCH'] == "true" }
belongs_to :crop
belongs_to :creator, :class_name => 'Member'
belongs_to :creator, class_name: 'Member'
end

View File

@@ -1,5 +1,5 @@
class Comment < ActiveRecord::Base
belongs_to :author, :class_name => 'Member'
belongs_to :author, class_name: 'Member'
belongs_to :post
default_scope { order("created_at DESC") }
@@ -11,11 +11,11 @@ class Comment < ActiveRecord::Base
# don't send notifications to yourself
if recipient != sender
Notification.create(
:recipient_id => recipient,
:sender_id => sender,
:subject => "#{self.author} commented on #{self.post.subject}",
:body => self.body,
:post_id => self.post.id
recipient_id: recipient,
sender_id: sender,
subject: "#{self.author} commented on #{self.post.subject}",
body: self.body,
post_id: self.post.id
)
end
end

View File

@@ -4,42 +4,42 @@ class Crop < ActiveRecord::Base
has_many :scientific_names, after_add: :update_index, after_remove: :update_index
accepts_nested_attributes_for :scientific_names,
:allow_destroy => true,
:reject_if => :all_blank
allow_destroy: true,
reject_if: :all_blank
has_many :alternate_names, after_add: :update_index, after_remove: :update_index, dependent: :destroy
has_many :plantings
has_many :photos, :through => :plantings
has_many :photos, through: :plantings
has_many :seeds
has_many :harvests
has_many :plant_parts, -> { uniq }, :through => :harvests
belongs_to :creator, :class_name => 'Member'
belongs_to :requester, :class_name => 'Member'
has_many :plant_parts, -> { uniq }, through: :harvests
belongs_to :creator, class_name: 'Member'
belongs_to :requester, class_name: 'Member'
belongs_to :parent, :class_name => 'Crop'
has_many :varieties, :class_name => 'Crop', :foreign_key => 'parent_id'
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}
default_scope { order("lower(name) asc") }
scope :recent, -> { where(:approval_status => "approved").reorder("created_at desc") }
scope :toplevel, -> { where(:approval_status => "approved", :parent_id => nil) }
scope :popular, -> { where(:approval_status => "approved").reorder("plantings_count desc, lower(name) asc") }
scope :randomized, -> { where(:approval_status => "approved").reorder('random()') } # ok on sqlite and psql, but not on mysql
scope :pending_approval, -> { where(:approval_status => "pending") }
scope :approved, -> { where(:approval_status => "approved") }
scope :rejected, -> { where(:approval_status => "rejected") }
scope :recent, -> { where(approval_status: "approved").reorder("created_at desc") }
scope :toplevel, -> { where(approval_status: "approved", parent_id: nil) }
scope :popular, -> { where(approval_status: "approved").reorder("plantings_count desc, lower(name) asc") }
scope :randomized, -> { where(approval_status: "approved").reorder('random()') } # ok on sqlite and psql, but not on mysql
scope :pending_approval, -> { where(approval_status: "pending") }
scope :approved, -> { where(approval_status: "approved") }
scope :rejected, -> { where(approval_status: "rejected") }
## Wikipedia urls are only necessary when approving a crop
validates :en_wikipedia_url,
:format => {
:with => /\Ahttps?:\/\/en\.wikipedia\.org\/wiki/,
:message => 'is not a valid English Wikipedia URL'
format: {
with: /\Ahttps?:\/\/en\.wikipedia\.org\/wiki/,
message: 'is not a valid English Wikipedia URL'
},
:if => :approved?
if: :approved?
## Reasons are only necessary when rejecting
validates :reason_for_rejection, :presence => true, :if => :rejected?
validates :reason_for_rejection, presence: true, if: :rejected?
## This validation addresses a race condition
validate :approval_status_cannot_be_changed_again
@@ -231,14 +231,14 @@ class Crop < ActiveRecord::Base
crop = Crop.find_or_create_by(name: name)
crop.update_attributes(
:en_wikipedia_url => en_wikipedia_url,
:creator_id => cropbot.id
en_wikipedia_url: en_wikipedia_url,
creator_id: cropbot.id
)
if parent
parent = Crop.find_by_name(parent)
if parent
crop.update_attributes(:parent_id => parent.id)
crop.update_attributes(parent_id: parent.id)
else
logger.warn("Warning: parent crop #{parent} not found")
end
@@ -264,13 +264,13 @@ class Crop < ActiveRecord::Base
raise "cropbot account not found: run rake db:seed" unless cropbot
names_to_add.each do |n|
if self.scientific_names.exists?(:scientific_name => n)
if self.scientific_names.exists?(scientific_name: n)
logger.warn("Warning: skipping duplicate scientific name #{n} for #{self}")
else
self.scientific_names.create(
:scientific_name => n,
:creator_id => cropbot.id
scientific_name: n,
creator_id: cropbot.id
)
end
end
@@ -286,12 +286,12 @@ class Crop < ActiveRecord::Base
names_to_add = alternate_names.split(%r{,\s*})
names_to_add.each do |n|
if self.alternate_names.exists?(:name => n)
if self.alternate_names.exists?(name: n)
logger.warn("Warning: skipping duplicate alternate name #{n} for #{self}")
else
self.alternate_names.create(
:name => n,
:creator_id => cropbot.id
name: n,
creator_id: cropbot.id
)
end
end

View File

@@ -1,14 +1,14 @@
class Follow < ActiveRecord::Base
belongs_to :follower, class_name: "Member"
belongs_to :followed, class_name: "Member"
validates :follower_id, uniqueness: { :scope => :followed_id }
validates :follower_id, uniqueness: { scope: :followed_id }
after_create do
Notification.create(
:recipient_id => self.followed_id,
:sender_id => self.follower_id,
:subject => "#{self.follower.login_name} is now following you",
:body => "#{self.follower.login_name} just followed you on #{ENV["GROWSTUFF_SITE_NAME"]}. "
recipient_id: self.followed_id,
sender_id: self.follower_id,
subject: "#{self.follower.login_name} is now following you",
body: "#{self.follower.login_name} just followed you on #{ENV["GROWSTUFF_SITE_NAME"]}. "
)
end

View File

@@ -3,7 +3,7 @@ class Forum < ActiveRecord::Base
friendly_id :name, use: [:slugged, :finders]
has_many :posts
belongs_to :owner, :class_name => "Member"
belongs_to :owner, class_name: "Member"
def to_s
return name

View File

@@ -3,9 +3,9 @@ class Garden < ActiveRecord::Base
extend FriendlyId
friendly_id :garden_slug, use: [:slugged, :finders]
belongs_to :owner, :class_name => 'Member', :foreign_key => 'owner_id'
has_many :plantings, -> { order(created_at: :desc) }, :dependent => :destroy
has_many :crops, :through => :plantings
belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id'
has_many :plantings, -> { order(created_at: :desc) }, dependent: :destroy
has_many :crops, through: :plantings
has_and_belongs_to_many :photos
@@ -25,23 +25,23 @@ class Garden < ActiveRecord::Base
after_save :mark_inactive_garden_plantings_as_finished
default_scope { order("lower(name) asc") }
scope :active, -> { where(:active => true) }
scope :inactive, -> { where(:active => false) }
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
validates :location,
:length => { :maximum => 255 }
length: { maximum: 255 }
validates :name,
:format => {
:with => /\S/
format: {
with: /\S/
},
:length => { :maximum => 255 }
length: { maximum: 255 }
validates :area,
:numericality => {
:only_integer => false,
:greater_than_or_equal_to => 0 },
:allow_nil => true
numericality: {
only_integer: false,
greater_than_or_equal_to: 0 },
allow_nil: true
AREA_UNITS_VALUES = {
"square metres" => "square metre",
@@ -49,10 +49,10 @@ class Garden < ActiveRecord::Base
"hectares" => "hectare",
"acres" => "acre"
}
validates :area_unit, :inclusion => { :in => AREA_UNITS_VALUES.values,
:message => "%{value} is not a valid area unit" },
:allow_nil => true,
:allow_blank => true
validates :area_unit, inclusion: { in: AREA_UNITS_VALUES.values,
message: "%{value} is not a valid area unit" },
allow_nil: true,
allow_blank: true
after_validation :cleanup_area

View File

@@ -4,7 +4,7 @@ class Harvest < ActiveRecord::Base
friendly_id :harvest_slug, use: [:slugged, :finders]
belongs_to :crop
belongs_to :owner, :class_name => 'Member'
belongs_to :owner, class_name: 'Member'
belongs_to :plant_part
has_and_belongs_to_many :photos
@@ -20,17 +20,17 @@ class Harvest < ActiveRecord::Base
default_scope { order('created_at DESC') }
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 :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 => {
:only_integer => false,
:greater_than_or_equal_to => 0 },
:allow_nil => true
numericality: {
only_integer: false,
greater_than_or_equal_to: 0 },
allow_nil: true
UNITS_VALUES = {
"individual" => "individual",
@@ -44,24 +44,24 @@ class Harvest < ActiveRecord::Base
"baskets" => "basket",
"bushels" => "bushel"
}
validates :unit, :inclusion => { :in => UNITS_VALUES.values,
:message => "%{value} is not a valid unit" },
:allow_nil => true,
:allow_blank => true
validates :unit, inclusion: { in: UNITS_VALUES.values,
message: "%{value} is not a valid unit" },
allow_nil: true,
allow_blank: true
validates :weight_quantity,
:numericality => { :only_integer => false },
:allow_nil => true
numericality: { only_integer: false },
allow_nil: true
WEIGHT_UNITS_VALUES = {
"kg" => "kg",
"lb" => "lb",
"oz" => "oz"
}
validates :weight_unit, :inclusion => { :in => WEIGHT_UNITS_VALUES.values,
:message => "%{value} is not a valid unit" },
:allow_nil => true,
:allow_blank => true
validates :weight_unit, inclusion: { in: WEIGHT_UNITS_VALUES.values,
message: "%{value} is not a valid unit" },
allow_nil: true,
allow_blank: true
after_validation :cleanup_quantities
@@ -104,7 +104,7 @@ class Harvest < ActiveRecord::Base
# 2 buckets of apricots, weighing 10kg
string = ''
if self.quantity
string += "#{number_to_human(self.quantity.to_s, :strip_insignificant_zeros => true)} "
string += "#{number_to_human(self.quantity.to_s, strip_insignificant_zeros: true)} "
if self.unit == 'individual'
string += 'individual '
else
@@ -125,7 +125,7 @@ class Harvest < ActiveRecord::Base
end
if self.weight_quantity
string += " weighing #{number_to_human(self.weight_quantity, :strip_insignificant_zeros => true)} #{self.weight_unit}"
string += " weighing #{number_to_human(self.weight_quantity, strip_insignificant_zeros: true)} #{self.weight_unit}"
end
return string

View File

@@ -4,26 +4,26 @@ class Member < ActiveRecord::Base
friendly_id :login_name, use: [:slugged, :finders]
has_many :posts, :foreign_key => 'author_id'
has_many :comments, :foreign_key => 'author_id'
has_many :forums, :foreign_key => 'owner_id'
has_many :posts, foreign_key: 'author_id'
has_many :comments, foreign_key: 'author_id'
has_many :forums, foreign_key: 'owner_id'
has_many :gardens, :foreign_key => 'owner_id'
has_many :plantings, :foreign_key => 'owner_id'
has_many :gardens, foreign_key: 'owner_id'
has_many :plantings, foreign_key: 'owner_id'
has_many :seeds, :foreign_key => 'owner_id'
has_many :harvests, :foreign_key => 'owner_id'
has_many :seeds, foreign_key: 'owner_id'
has_many :harvests, foreign_key: 'owner_id'
has_and_belongs_to_many :roles
has_many :notifications, :foreign_key => 'recipient_id'
has_many :sent_notifications, :foreign_key => 'sender_id'
has_many :notifications, foreign_key: 'recipient_id'
has_many :sent_notifications, foreign_key: 'sender_id'
has_many :authentications
has_many :orders
has_one :account
has_one :account_type, :through => :account
has_one :account_type, through: :account
has_many :photos
@@ -33,13 +33,13 @@ class Member < ActiveRecord::Base
scope :located, -> { where("location <> '' and latitude IS NOT NULL and longitude IS NOT NULL") }
scope :recently_signed_in, -> { reorder('updated_at DESC') }
scope :recently_joined, -> { reorder("confirmed_at desc") }
scope :wants_newsletter, -> { where(:newsletter => true) }
scope :wants_newsletter, -> { where(newsletter: true) }
has_many :follows, :class_name => "Follow", :foreign_key => "follower_id"
has_many :followed, :through => :follows
has_many :follows, class_name: "Follow", foreign_key: "follower_id"
has_many :followed, through: :follows
has_many :inverse_follows, :class_name => "Follow", :foreign_key => "followed_id"
has_many :followers, :through => :inverse_follows, :source => :follower
has_many :inverse_follows, class_name: "Follow", foreign_key: "followed_id"
has_many :followers, through: :inverse_follows, source: :follower
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
@@ -58,34 +58,34 @@ class Member < ActiveRecord::Base
attr_accessor :login
# Requires acceptance of the Terms of Service
validates_acceptance_of :tos_agreement, :allow_nil => false,
:accept => true
validates_acceptance_of :tos_agreement, allow_nil: false,
accept: true
validates :login_name,
:length => {
:minimum => 2,
:maximum => 25,
:message => "should be between 2 and 25 characters long"
length: {
minimum: 2,
maximum: 25,
message: "should be between 2 and 25 characters long"
},
:exclusion => {
:in => %w(growstuff admin moderator staff nearby),
:message => "name is reserved"
exclusion: {
in: %w(growstuff admin moderator staff nearby),
message: "name is reserved"
},
:format => {
:with => /\A\w+\z/,
:message => "may only include letters, numbers, or underscores"
format: {
with: /\A\w+\z/,
message: "may only include letters, numbers, or underscores"
},
:uniqueness => {
:case_sensitive => false
uniqueness: {
case_sensitive: false
}
# 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
@@ -93,7 +93,7 @@ class Member < ActiveRecord::Base
def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
if login = conditions.delete(:login)
where(conditions).where(["lower(login_name) = :value OR lower(email) = :value", { :value => login.downcase }]).first
where(conditions).where(["lower(login_name) = :value OR lower(email) = :value", { value: login.downcase }]).first
else
where(conditions).first
end
@@ -108,7 +108,7 @@ class Member < ActiveRecord::Base
end
def current_order
orders.where(:completed_at => nil).first
orders.where(completed_at: nil).first
end
# when purchasing a product that gives you a paid account, this method
@@ -163,15 +163,15 @@ class Member < ActiveRecord::Base
result = false
if set
result = flickr.photosets.getPhotos(
:photoset_id => set,
:page => page_num,
:per_page => 30
photoset_id: set,
page: page_num,
per_page: 30
)
else
result = flickr.people.getPhotos(
:user_id => 'me',
:page => page_num,
:per_page => 30
user_id: 'me',
page: page_num,
per_page: 30
)
end
if result
@@ -239,10 +239,10 @@ class Member < ActiveRecord::Base
return true if (Rails.env.test? && !testing)
gb = Gibbon::API.new
res = gb.lists.subscribe({
:id => Gibbon::API.api_key,
:email => { :email => email },
:merge_vars => { :login_name => login_name },
:double_optin => false # they already confirmed their email with us
id: Gibbon::API.api_key,
email: { email: email },
merge_vars: { login_name: login_name },
double_optin: false # they already confirmed their email with us
})
end
@@ -250,17 +250,17 @@ class Member < ActiveRecord::Base
return true if (Rails.env.test? && !testing)
gb = Gibbon::API.new
res = gb.lists.unsubscribe({
:id => ENV['GROWSTUFF_MAILCHIMP_NEWSLETTER_ID'],
:email => { :email => email }
id: ENV['GROWSTUFF_MAILCHIMP_NEWSLETTER_ID'],
email: { email: email }
})
end
def already_following?(member)
self.follows.exists?(:followed_id => member.id)
self.follows.exists?(followed_id: member.id)
end
def get_follow(member)
self.follows.where(:followed_id => member.id).first if already_following?(member)
self.follows.where(followed_id: member.id).first if already_following?(member)
end
end

View File

@@ -1,12 +1,12 @@
class Notification < ActiveRecord::Base
belongs_to :sender, :class_name => 'Member'
belongs_to :recipient, :class_name => 'Member'
belongs_to :sender, class_name: 'Member'
belongs_to :recipient, class_name: 'Member'
belongs_to :post
validates :subject, :length => { :maximum => 255 }
validates :subject, length: { maximum: 255 }
default_scope { order('created_at DESC') }
scope :unread, -> { where(:read => false) }
scope :unread, -> { where(read: false) }
before_create :replace_blank_subject
after_create :send_email

View File

@@ -1,13 +1,13 @@
class Order < ActiveRecord::Base
belongs_to :member
has_many :order_items, :dependent => :destroy
has_many :order_items, dependent: :destroy
default_scope { order('created_at DESC') }
validates :referral_code, :format => {
:with => /\A[a-zA-Z0-9 ]*\z/,
:message => "may only include letters and numbers"
validates :referral_code, format: {
with: /\A[a-zA-Z0-9 ]*\z/,
message: "may only include letters and numbers"
}
before_save :standardize_referral_code
@@ -27,9 +27,9 @@ class Order < ActiveRecord::Base
items = []
order_items.each do |i|
items.push({
:name => i.product.name,
:quantity => i.quantity,
:amount => i.price
name: i.product.name,
quantity: i.quantity,
amount: i.price
})
end
return items
@@ -87,7 +87,7 @@ class Order < ActiveRecord::Base
end
when "referral_code"
# coerce to uppercase
return Order.where(:referral_code => args[:for].upcase)
return Order.where(referral_code: args[:for].upcase)
end
end
return []

View File

@@ -4,7 +4,7 @@ class OrderItem < ActiveRecord::Base
validate :price_must_be_greater_than_minimum
validates_uniqueness_of :order_id, :message => "may only have one item."
validates_uniqueness_of :order_id, message: "may only have one item."
def price_must_be_greater_than_minimum
@product = Product.find(product_id)

View File

@@ -1,5 +1,5 @@
class Photo < ActiveRecord::Base
belongs_to :owner, :class_name => 'Member'
belongs_to :owner, class_name: 'Member'
has_and_belongs_to_many :plantings
has_and_belongs_to_many :harvests
@@ -23,16 +23,16 @@ class Photo < ActiveRecord::Base
# for easier stubbing and testing.
def flickr_metadata
flickr = owner.flickr
info = flickr.photos.getInfo(:photo_id => flickr_photo_id)
info = flickr.photos.getInfo(photo_id: flickr_photo_id)
licenses = flickr.photos.licenses.getInfo()
license = licenses.find { |l| l.id == info.license }
return {
:title => info.title || "Untitled",
:license_name => license.name,
:license_url => license.url,
:thumbnail_url => FlickRaw.url_q(info),
:fullsize_url => FlickRaw.url_z(info),
:link_url => FlickRaw.url_photopage(info)
title: info.title || "Untitled",
license_name: license.name,
license_url: license.url,
thumbnail_url: FlickRaw.url_q(info),
fullsize_url: FlickRaw.url_z(info),
link_url: FlickRaw.url_photopage(info)
}
end

View File

@@ -1,9 +1,9 @@
class PlantPart < ActiveRecord::Base
extend FriendlyId
friendly_id :name, :use => [:slugged, :finders]
friendly_id :name, use: [:slugged, :finders]
has_many :harvests
has_many :crops, -> { uniq }, :through => :harvests
has_many :crops, -> { uniq }, through: :harvests
def to_s
return name

View File

@@ -3,8 +3,8 @@ class Planting < ActiveRecord::Base
friendly_id :planting_slug, use: [:slugged, :finders]
belongs_to :garden
belongs_to :owner, :class_name => 'Member', :counter_cache => true
belongs_to :crop, :counter_cache => true
belongs_to :owner, class_name: 'Member', counter_cache: true
belongs_to :crop, counter_cache: true
has_and_belongs_to_many :photos
@@ -18,33 +18,33 @@ class Planting < ActiveRecord::Base
end
default_scope { order("created_at desc") }
scope :finished, -> { where(:finished => true) }
scope :current, -> { where(:finished => false) }
scope :finished, -> { where(finished: true) }
scope :current, -> { where(finished: false) }
delegate :name,
:en_wikipedia_url,
:default_scientific_name,
:plantings_count,
:to => :crop,
:prefix => true
to: :crop,
prefix: true
default_scope { order("created_at desc") }
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,
:numericality => {
:only_integer => true,
:greater_than_or_equal_to => 0 },
:allow_nil => true
numericality: {
only_integer: true,
greater_than_or_equal_to: 0 },
allow_nil: true
SUNNINESS_VALUES = %w(sun semi-shade shade)
validates :sunniness, :inclusion => { :in => SUNNINESS_VALUES,
:message => "%{value} is not a valid sunniness value" },
:allow_nil => true,
:allow_blank => true
validates :sunniness, inclusion: { in: SUNNINESS_VALUES,
message: "%{value} is not a valid sunniness value" },
allow_nil: true,
allow_blank: true
PLANTED_FROM_VALUES = [
'seed',
@@ -59,10 +59,10 @@ class Planting < ActiveRecord::Base
'graft',
'layering'
]
validates :planted_from, :inclusion => { :in => PLANTED_FROM_VALUES,
:message => "%{value} is not a valid planting method" },
:allow_nil => true,
:allow_blank => true
validates :planted_from, inclusion: { in: PLANTED_FROM_VALUES,
message: "%{value} is not a valid planting method" },
allow_nil: true,
allow_blank: true
validate :finished_must_be_after_planted
@@ -95,7 +95,7 @@ class Planting < ActiveRecord::Base
end
def calculate_days_before_maturity(planting, crop)
p_crop = Planting.where(:crop_id => crop).where.not(:id => planting)
p_crop = Planting.where(crop_id: crop).where.not(id: planting)
differences = p_crop.collect do |p|
if p.finished and !p.finished_at.nil?
(p.finished_at - p.planted_at).to_i

View File

@@ -1,9 +1,9 @@
class Post < ActiveRecord::Base
extend FriendlyId
friendly_id :author_date_subject, use: [:slugged, :finders]
belongs_to :author, :class_name => 'Member'
belongs_to :author, class_name: 'Member'
belongs_to :forum
has_many :comments, :dependent => :destroy
has_many :comments, dependent: :destroy
has_and_belongs_to_many :crops
before_destroy {|post| post.crops.clear}
after_save :update_crops_posts_association
@@ -27,10 +27,10 @@ class Post < ActiveRecord::Base
recipients.map{ |r| r.id }.each do |recipient|
if recipient != sender
Notification.create(
:recipient_id => recipient,
:sender_id => sender,
:subject => "#{self.author} mentioned you in their post #{self.subject}",
:body => self.body,
recipient_id: recipient,
sender_id: sender,
subject: "#{self.author} mentioned you in their post #{self.subject}",
body: self.body,
)
end
end
@@ -39,10 +39,10 @@ class Post < ActiveRecord::Base
default_scope { order("created_at desc") }
validates :subject,
:format => {
:with => /\S/
format: {
with: /\S/
},
:length => { :maximum => 255 }
length: { maximum: 255 }
def author_date_subject

View File

@@ -3,10 +3,10 @@ class Product < ActiveRecord::Base
belongs_to :account_type
validates :paid_months,
:numericality => {
:only_integer => true,
:greater_than_or_equal_to => 0 },
:allow_nil => true
numericality: {
only_integer: true,
greater_than_or_equal_to: 0 },
allow_nil: true
def to_s
name

View File

@@ -1,5 +1,5 @@
class ScientificName < ActiveRecord::Base
after_commit { |sn| sn.crop.__elasticsearch__.index_document if sn.crop && ENV['GROWSTUFF_ELASTICSEARCH'] == "true" }
belongs_to :crop
belongs_to :creator, :class_name => 'Member'
belongs_to :creator, class_name: 'Member'
end

View File

@@ -3,62 +3,62 @@ class Seed < ActiveRecord::Base
friendly_id :seed_slug, use: [:slugged, :finders]
belongs_to :crop
belongs_to :owner, :class_name => 'Member', :foreign_key => 'owner_id'
belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id'
default_scope { order("created_at desc") }
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,
:numericality => {
:only_integer => true,
:greater_than_or_equal_to => 0 },
:allow_nil => true
numericality: {
only_integer: true,
greater_than_or_equal_to: 0 },
allow_nil: true
validates :days_until_maturity_min,
:numericality => {
:only_integer => true,
:greater_than_or_equal_to => 0 },
:allow_nil => true
numericality: {
only_integer: true,
greater_than_or_equal_to: 0 },
allow_nil: true
validates :days_until_maturity_max,
:numericality => {
:only_integer => true,
:greater_than_or_equal_to => 0 },
:allow_nil => true
numericality: {
only_integer: true,
greater_than_or_equal_to: 0 },
allow_nil: true
scope :tradable, -> { where("tradable_to != 'nowhere'") }
TRADABLE_TO_VALUES = %w(nowhere locally nationally internationally)
validates :tradable_to, :inclusion => { :in => TRADABLE_TO_VALUES,
:message => "You may only trade seed nowhere, locally, nationally, or internationally" },
:allow_nil => false,
:allow_blank => false
validates :tradable_to, inclusion: { in: TRADABLE_TO_VALUES,
message: "You may only trade seed nowhere, locally, nationally, or internationally" },
allow_nil: false,
allow_blank: false
ORGANIC_VALUES = [
'certified organic',
'non-certified organic',
'conventional/non-organic',
'unknown']
validates :organic, :inclusion => { :in => ORGANIC_VALUES,
:message => "You must say whether the seeds are organic or not, or that you don't know" },
:allow_nil => false,
:allow_blank => false
validates :organic, inclusion: { in: ORGANIC_VALUES,
message: "You must say whether the seeds are organic or not, or that you don't know" },
allow_nil: false,
allow_blank: false
GMO_VALUES = [
'certified GMO-free',
'non-certified GMO-free',
'GMO',
'unknown']
validates :gmo, :inclusion => { :in => GMO_VALUES,
:message => "You must say whether the seeds are genetically modified or not, or that you don't know" },
:allow_nil => false,
:allow_blank => false
validates :gmo, inclusion: { in: GMO_VALUES,
message: "You must say whether the seeds are genetically modified or not, or that you don't know" },
allow_nil: false,
allow_blank: false
HEIRLOOM_VALUES = %w(heirloom hybrid unknown)
validates :heirloom, :inclusion => { :in => HEIRLOOM_VALUES,
:message => "You must say whether the seeds are heirloom, hybrid, or unknown" },
:allow_nil => false,
:allow_blank => false
validates :heirloom, inclusion: { in: HEIRLOOM_VALUES,
message: "You must say whether the seeds are heirloom, hybrid, or unknown" },
allow_nil: false,
allow_blank: false
def tradable?
if self.tradable_to == 'nowhere'

View File

@@ -5,7 +5,7 @@ require 'openssl'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
Bundler.require(*Rails.groups(assets: %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
@@ -84,9 +84,9 @@ module Growstuff
config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {
:location => '/usr/sbin/sendmail',
:arguments => '-i -t',
:openssl_verify_mode => 'none'
location: '/usr/sbin/sendmail',
arguments: '-i -t',
openssl_verify_mode: 'none'
}
# Growstuff-specific configuration variables

View File

@@ -3,13 +3,14 @@ development:
database: growstuff_dev
host: localhost
user: postgres
password: password
password: postgres
test:
adapter: postgresql
database: growstuff_test
host: localhost
user: postgres
password: postgres
production:
adapter: postgresql

View File

@@ -44,15 +44,15 @@ Growstuff::Application.configure do
# config.action_view.raise_on_missing_translations = true
# Growstuff config
config.action_mailer.default_url_options = { :host => 'localhost:8080' }
config.action_mailer.default_url_options = { host: 'localhost:8080' }
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.smtp_settings = {
:port => '587',
:address => 'smtp.mandrillapp.com',
:user_name => ENV['GROWSTUFF_MANDRILL_USERNAME'],
:password => ENV['GROWSTUFF_MANDRILL_APIKEY'],
:authentication => :login
port: '587',
address: 'smtp.mandrillapp.com',
user_name: ENV['GROWSTUFF_MANDRILL_USERNAME'],
password: ENV['GROWSTUFF_MANDRILL_APIKEY'],
authentication: :login
}
config.host = 'localhost:8080'
@@ -65,9 +65,9 @@ Growstuff::Application.configure do
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
:login => ENV['GROWSTUFF_PAYPAL_USERNAME'] || 'dummy',
:password => ENV['GROWSTUFF_PAYPAL_PASSWORD'] || 'dummy',
:signature => ENV['GROWSTUFF_PAYPAL_SIGNATURE'] || 'dummy'
login: ENV['GROWSTUFF_PAYPAL_USERNAME'] || 'dummy',
password: ENV['GROWSTUFF_PAYPAL_PASSWORD'] || 'dummy',
signature: ENV['GROWSTUFF_PAYPAL_SIGNATURE'] || 'dummy'
}
::STANDARD_GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(paypal_options)
::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)

View File

@@ -67,15 +67,15 @@ Growstuff::Application.configure do
config.active_record.dump_schema_after_migration = false
# Growstuff configuration
config.action_mailer.default_url_options = { :host => 'growstuff.org' }
config.action_mailer.default_url_options = { host: 'growstuff.org' }
config.action_mailer.smtp_settings = {
:port => '587',
:address => 'smtp.mandrillapp.com',
:user_name => ENV['GROWSTUFF_MANDRILL_USERNAME'],
:password => ENV['GROWSTUFF_MANDRILL_APIKEY'],
:domain => 'heroku.com',
:authentication => :plain
port: '587',
address: 'smtp.mandrillapp.com',
user_name: ENV['GROWSTUFF_MANDRILL_USERNAME'],
password: ENV['GROWSTUFF_MANDRILL_APIKEY'],
domain: 'heroku.com',
authentication: :plain
}
config.action_mailer.delivery_method = :smtp
@@ -93,9 +93,9 @@ Growstuff::Application.configure do
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :production
paypal_options = {
:login => ENV['GROWSTUFF_PAYPAL_USERNAME'],
:password => ENV['GROWSTUFF_PAYPAL_PASSWORD'],
:signature => ENV['GROWSTUFF_PAYPAL_SIGNATURE']
login: ENV['GROWSTUFF_PAYPAL_USERNAME'],
password: ENV['GROWSTUFF_PAYPAL_PASSWORD'],
signature: ENV['GROWSTUFF_PAYPAL_SIGNATURE']
}
::STANDARD_GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(paypal_options)
::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)

View File

@@ -69,15 +69,15 @@ Growstuff::Application.configure do
config.active_record.dump_schema_after_migration = false
# Growstuff configuration
config.action_mailer.default_url_options = { :host => 'staging.growstuff.org' }
config.action_mailer.default_url_options = { host: 'staging.growstuff.org' }
config.action_mailer.smtp_settings = {
:port => '587',
:address => 'smtp.mandrillapp.com',
:user_name => ENV['GROWSTUFF_MANDRILL_USERNAME'],
:password => ENV['GROWSTUFF_MANDRILL_APIKEY'],
:domain => 'heroku.com',
:authentication => :plain
port: '587',
address: 'smtp.mandrillapp.com',
user_name: ENV['GROWSTUFF_MANDRILL_USERNAME'],
password: ENV['GROWSTUFF_MANDRILL_APIKEY'],
domain: 'heroku.com',
authentication: :plain
}
config.action_mailer.delivery_method = :smtp
@@ -91,9 +91,9 @@ Growstuff::Application.configure do
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
:login => ENV['GROWSTUFF_PAYPAL_USERNAME'],
:password => ENV['GROWSTUFF_PAYPAL_PASSWORD'],
:signature => ENV['GROWSTUFF_PAYPAL_SIGNATURE']
login: ENV['GROWSTUFF_PAYPAL_USERNAME'],
password: ENV['GROWSTUFF_PAYPAL_PASSWORD'],
signature: ENV['GROWSTUFF_PAYPAL_SIGNATURE']
}
::STANDARD_GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(paypal_options)
::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)

View File

@@ -40,7 +40,7 @@ Growstuff::Application.configure do
# config.action_view.raise_on_missing_translations = true
# Growstuff config
config.action_mailer.default_url_options = { :host => 'localhost:8080' }
config.action_mailer.default_url_options = { host: 'localhost:8080' }
Growstuff::Application.configure do
config.host = 'test.example.com'
@@ -56,7 +56,7 @@ Growstuff::Application.configure do
end
Geocoder.configure(:lookup => :test)
Geocoder.configure(lookup: :test)
Geocoder::Lookup::Test.add_stub(
"Amundsen-Scott Base, Antarctica", [

View File

@@ -97,7 +97,7 @@ end
module CmsDeviseAuth
def authenticate
unless current_member && current_member.has_role?(:admin)
redirect_to root_path, :alert => 'Permission denied. Please sign in as an admin user to use the CMS admin area.'
redirect_to root_path, alert: 'Permission denied. Please sign in as an admin user to use the CMS admin area.'
end
end
end

View File

@@ -1,9 +1,9 @@
require 'geocodable'
Geocoder.configure(
:units => :km,
:timeout => 10,
:http_headers => {
units: :km,
timeout: 10,
http_headers: {
"User-Agent" =>
"#{Growstuff::Application.config.user_agent} #{Growstuff::Application.config.user_agent_email}",
"From" => Growstuff::Application.config.user_agent_email
@@ -12,5 +12,5 @@ Geocoder.configure(
# This configuration takes precedence over environment/test.rb
# Reported as https://github.com/alexreisner/geocoder/issues/509
if Geocoder.config.lookup != :test
Geocoder.configure(:lookup => :nominatim)
Geocoder.configure(lookup: :nominatim)
end

View File

@@ -4,7 +4,7 @@ Growstuff::Application.routes.draw do
resources :plant_parts
devise_for :members, :controllers => { :registrations => "registrations", :passwords => "passwords" }
devise_for :members, controllers: { registrations: "registrations", passwords: "passwords" }
devise_scope :member do
get '/members/unsubscribe/:message' => 'members#unsubscribe', :as => 'unsubscribe_member'
end
@@ -13,7 +13,7 @@ Growstuff::Application.routes.draw do
resources :photos
resources :authentications, :only => [:create, :destroy]
resources :authentications, only: [:create, :destroy]
resources :plantings
get '/plantings/owner/:owner' => 'plantings#index', :as => 'plantings_by_owner'
@@ -48,7 +48,7 @@ Growstuff::Application.routes.draw do
get 'reply', on: :member
end
resources :follows, :only => [:create, :destroy]
resources :follows, only: [:create, :destroy]
get '/members/:login_name/follows' => 'members#view_follows', :as => 'member_follows'
get '/members/:login_name/followers' => 'members#view_followers', :as => 'member_followers'
@@ -69,7 +69,7 @@ Growstuff::Application.routes.draw do
resources :products
get "home/index"
root :to => 'home#index'
root to: 'home#index'
get 'auth/:provider/callback' => 'authentications#create'
@@ -85,7 +85,7 @@ Growstuff::Application.routes.draw do
get '/shop' => 'shop#index'
get '/shop/:action' => 'shop#:action'
comfy_route :cms_admin, :path => '/admin/cms'
comfy_route :cms_admin, path: '/admin/cms'
get '/admin/orders' => 'admin/orders#index'
get '/admin/orders/:action' => 'admin/orders#:action'
get '/admin' => 'admin#index'
@@ -93,6 +93,6 @@ Growstuff::Application.routes.draw do
get '/admin/:action' => 'admin#:action'
# CMS stuff -- must remain LAST
comfy_route :cms, :path => '/', :sitemap => false
comfy_route :cms, path: '/', sitemap: false
end

View File

@@ -2,8 +2,8 @@ class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
@@ -13,7 +13,7 @@ class DeviseCreateUsers < ActiveRecord::Migration
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.integer :sign_in_count, default: 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
@@ -26,7 +26,7 @@ class DeviseCreateUsers < ActiveRecord::Migration
t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
t.integer :failed_attempts, default: 0 # Only if lock strategy is :failed_attempts
t.string :unlock_token # Only if unlock strategy is :email or :both
t.datetime :locked_at
@@ -37,10 +37,10 @@ class DeviseCreateUsers < ActiveRecord::Migration
t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
add_index :users, :confirmation_token, :unique => true
add_index :users, :unlock_token, :unique => true
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
add_index :users, :confirmation_token, unique: true
add_index :users, :unlock_token, unique: true
# add_index :users, :authentication_token, :unique => true
end
end

View File

@@ -2,13 +2,13 @@ class RequireSystemNameForCrops < ActiveRecord::Migration
def up
change_table :crops do |t|
t.index :system_name
t.change :system_name, :string, :null => false
t.change :system_name, :string, null: false
end
end
def down
change_table :crops do |t|
t.change :system_name, :string, :null => true
t.change :system_name, :string, null: true
t.remove_index :system_name
end
end

View File

@@ -1,9 +1,9 @@
class CreateGardens < ActiveRecord::Migration
def change
create_table :gardens do |t|
t.string :name, :null => false
t.string :name, null: false
t.integer :user_id
t.string :slug, :null => false
t.string :slug, null: false
t.timestamps
end

View File

@@ -1,8 +1,8 @@
class CreateScientificNames < ActiveRecord::Migration
def change
create_table :scientific_names do |t|
t.string :scientific_name, :null => false
t.integer :crop_id, :null => false
t.string :scientific_name, null: false
t.integer :crop_id, null: false
t.timestamps
end

View File

@@ -1,9 +1,9 @@
class CreateUpdates < ActiveRecord::Migration
def change
create_table :updates do |t|
t.integer :user_id, :null => false
t.string :subject, :null => false
t.text :body, :null => false
t.integer :user_id, null: false
t.string :subject, null: false
t.text :body, null: false
t.timestamps
end

View File

@@ -1,8 +1,8 @@
class CreatePlantings < ActiveRecord::Migration
def change
create_table :plantings do |t|
t.integer :garden_id, :null => false
t.integer :crop_id, :null => false
t.integer :garden_id, null: false
t.integer :crop_id, null: false
t.datetime :planted_at
t.integer :quantity
t.text :description

View File

@@ -1,17 +1,17 @@
class RequireFieldsForComments < ActiveRecord::Migration
def up
change_table :comments do |t|
t.change :post_id, :integer, :null => false
t.change :author_id, :integer, :null => false
t.change :body, :text, :null => false
t.change :post_id, :integer, null: false
t.change :author_id, :integer, null: false
t.change :body, :text, null: false
end
end
def down
change_table :comments do |t|
t.change :post_id, :integer, :null => true
t.change :author_id, :integer, :null => true
t.change :body, :text, :null => true
t.change :post_id, :integer, null: true
t.change :author_id, :integer, null: true
t.change :body, :text, null: true
end
end
end

View File

@@ -2,7 +2,7 @@ class CreateNotifications < ActiveRecord::Migration
def change
create_table :notifications do |t|
t.integer :from_id
t.integer :to_id, :null => false
t.integer :to_id, null: false
t.string :subject
t.text :body
t.boolean :read

View File

@@ -1,9 +1,9 @@
class CreateForums < ActiveRecord::Migration
def change
create_table :forums do |t|
t.string :name, :null => false
t.text :description, :null => false
t.integer :owner_id, :null => false
t.string :name, null: false
t.text :description, null: false
t.integer :owner_id, null: false
t.timestamps
end

View File

@@ -1,7 +1,7 @@
class CreateRoles < ActiveRecord::Migration
def change
create_table :roles do |t|
t.string :name, :null => false
t.string :name, null: false
t.text :description
t.timestamps

View File

@@ -1,6 +1,6 @@
class AddMembersRolesTable < ActiveRecord::Migration
def change
create_table :members_roles, :id => false do |t|
create_table :members_roles, id: false do |t|
t.integer :member_id
t.integer :role_id
end

View File

@@ -1,13 +1,13 @@
class DefaultReadToFalse < ActiveRecord::Migration
def up
change_table :notifications do |t|
t.change :read, :boolean, :default => false
t.change :read, :boolean, default: false
end
end
def down
change_table :notifications do |t|
t.change :read, :boolean, :default => nil
t.change :read, :boolean, default: nil
end
end
end

View File

@@ -1,5 +1,5 @@
class AddSendEmailToMember < ActiveRecord::Migration
def change
add_column :members, :send_notification_email, :boolean, :default => true
add_column :members, :send_notification_email, :boolean, default: true
end
end

View File

@@ -1,8 +1,8 @@
class CreateAuthentications < ActiveRecord::Migration
def change
create_table :authentications do |t|
t.integer :member_id, :null => false
t.string :provider, :null => false
t.integer :member_id, null: false
t.string :provider, null: false
t.string :uid
t.string :token
t.string :secret

View File

@@ -1,3 +1,3 @@
class MakePostSubjectNonNull < ActiveRecord::Migration
change_column :posts, :subject, :string, :null => false
change_column :posts, :subject, :string, null: false
end

View File

@@ -1,9 +1,9 @@
class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.string :name, :null => false
t.string :description, :null => false
t.decimal :min_price, :null => false
t.string :name, null: false
t.string :description, null: false
t.decimal :min_price, null: false
t.timestamps
end

View File

@@ -1,7 +1,7 @@
class CreateOrders < ActiveRecord::Migration
def change
create_table :orders do |t|
t.string :member_id, :null => false
t.string :member_id, null: false
t.timestamps
end

View File

@@ -1,6 +1,6 @@
class AddOrdersProductsTable < ActiveRecord::Migration
def change
create_table :orders_products, :id => false do |t|
create_table :orders_products, id: false do |t|
t.integer :order_id
t.integer :product_id
end

View File

@@ -1,10 +1,10 @@
class CreatePhotos < ActiveRecord::Migration
def change
create_table :photos do |t|
t.integer :owner_id, :null => false
t.integer :flickr_photo_id, :null => false
t.string :thumbnail_url, :null => false
t.string :fullsize_url, :null => false
t.integer :owner_id, null: false
t.integer :flickr_photo_id, null: false
t.string :thumbnail_url, null: false
t.string :fullsize_url, null: false
t.timestamps
end

View File

@@ -5,9 +5,9 @@ class AddMetadataToPhotos < ActiveRecord::Migration
t.string :license_name
t.string :license_url
t.string :link_url
t.change :title, :string, :null => false
t.change :license_name, :string, :null => false
t.change :link_url, :string, :null => false
t.change :title, :string, null: false
t.change :license_name, :string, null: false
t.change :link_url, :string, null: false
end
end

View File

@@ -1,7 +1,7 @@
class CreateAccountDetails < ActiveRecord::Migration
def change
create_table :account_details do |t|
t.integer :member_id, :null => false
t.integer :member_id, null: false
t.integer :account_type_id
t.datetime :paid_until

View File

@@ -1,9 +1,9 @@
class RequireAccountTypeName < ActiveRecord::Migration
def up
change_column :account_types, :name, :string, :null => false
change_column :account_types, :name, :string, null: false
end
def down
change_column :account_types, :name, :string, :null => true
change_column :account_types, :name, :string, null: true
end
end

View File

@@ -1,6 +1,6 @@
class AddPhotosPlantingsTable < ActiveRecord::Migration
def change
create_table :photos_plantings, :id => false do |t|
create_table :photos_plantings, id: false do |t|
t.integer :photo_id
t.integer :planting_id
end

View File

@@ -1,8 +1,8 @@
class CreateSeeds < ActiveRecord::Migration
def change
create_table :seeds do |t|
t.integer :owner_id, :null => false
t.integer :crop_id, :null => false
t.integer :owner_id, null: false
t.integer :crop_id, null: false
t.text :description
t.integer :quantity
t.date :use_by

View File

@@ -1,8 +1,8 @@
class CreateHarvests < ActiveRecord::Migration
def change
create_table :harvests do |t|
t.integer :crop_id, :null => false
t.integer :owner_id, :null => false
t.integer :crop_id, null: false
t.integer :owner_id, null: false
t.date :harvested_at
t.decimal :quantity
t.string :units

View File

@@ -1,6 +1,6 @@
class AddFieldsToGardens < ActiveRecord::Migration
def change
add_column :gardens, :active, :boolean, :default => true
add_column :gardens, :active, :boolean, default: true
add_column :gardens, :location, :string
add_column :gardens, :latitude, :float
add_column :gardens, :longitude, :float

View File

@@ -1,9 +1,9 @@
class DefaultPlantingsCountToZero < ActiveRecord::Migration
def up
change_column :crops, :plantings_count, :integer, :default => 0
change_column :crops, :plantings_count, :integer, default: 0
end
def down
change_column :crops, :plantings_count, :integer, :default => nil
change_column :crops, :plantings_count, :integer, default: nil
end
end

View File

@@ -1,6 +1,6 @@
class AddFinishedToPlanting < ActiveRecord::Migration
def change
add_column :plantings, :finished, :boolean, :default => false
add_column :plantings, :finished, :boolean, default: false
add_column :plantings, :finished_at, :date
end
end

View File

@@ -1,6 +1,6 @@
class AddHarvestsPhotosTable < ActiveRecord::Migration
def change
create_table :harvests_photos, :id => false do |t|
create_table :harvests_photos, id: false do |t|
t.integer :photo_id
t.integer :harvest_id
end

View File

@@ -1,6 +1,6 @@
class AddCropsPostsTable < ActiveRecord::Migration
def change
create_table :crops_posts, :id => false do |t|
create_table :crops_posts, id: false do |t|
t.integer :crop_id
t.integer :post_id
end

View File

@@ -1,5 +1,5 @@
class AddSendPlantingReminderToMember < ActiveRecord::Migration
def change
add_column :members, :send_planting_reminder, :boolean, :default => true
add_column :members, :send_planting_reminder, :boolean, default: true
end
end

View File

@@ -1,9 +1,9 @@
class CreateAlternateNames < ActiveRecord::Migration
def change
create_table :alternate_names do |t|
t.string :name, :null => false
t.integer :crop_id, :null => false
t.integer :creator_id, :null => false
t.string :name, null: false
t.integer :crop_id, null: false
t.integer :creator_id, null: false
t.timestamps
end

View File

@@ -2,8 +2,8 @@ class AddPropertiesToSeeds < ActiveRecord::Migration
def change
add_column :seeds, :days_until_maturity_min, :integer
add_column :seeds, :days_until_maturity_max, :integer
add_column :seeds, :organic, :text, :default => 'unknown'
add_column :seeds, :gmo, :text, :default => 'unknown'
add_column :seeds, :heirloom, :text, :default => 'unknown'
add_column :seeds, :organic, :text, default: 'unknown'
add_column :seeds, :gmo, :text, default: 'unknown'
add_column :seeds, :heirloom, :text, default: 'unknown'
end
end

View File

@@ -1,6 +1,6 @@
class AddGardensPhotosTable < ActiveRecord::Migration
def change
create_table :gardens_photos, :id => false do |t|
create_table :gardens_photos, id: false do |t|
t.integer :photo_id
t.integer :garden_id
end

View File

@@ -6,52 +6,52 @@ class CreateCms < ActiveRecord::Migration
when 'PostgreSQL'
{ }
else
{ :limit => 16777215 }
{ limit: 16777215 }
end
# -- Sites --------------------------------------------------------------
create_table :comfy_cms_sites do |t|
t.string :label, :null => false
t.string :identifier, :null => false
t.string :hostname, :null => false
t.string :label, null: false
t.string :identifier, null: false
t.string :hostname, null: false
t.string :path
t.string :locale, :null => false, :default => 'en'
t.boolean :is_mirrored, :null => false, :default => false
t.string :locale, null: false, default: 'en'
t.boolean :is_mirrored, null: false, default: false
end
add_index :comfy_cms_sites, :hostname
add_index :comfy_cms_sites, :is_mirrored
# -- Layouts ------------------------------------------------------------
create_table :comfy_cms_layouts do |t|
t.integer :site_id, :null => false
t.integer :site_id, null: false
t.integer :parent_id
t.string :app_layout
t.string :label, :null => false
t.string :identifier, :null => false
t.string :label, null: false
t.string :identifier, null: false
t.text :content, text_limit
t.text :css, text_limit
t.text :js, text_limit
t.integer :position, :null => false, :default => 0
t.boolean :is_shared, :null => false, :default => false
t.integer :position, null: false, default: 0
t.boolean :is_shared, null: false, default: false
t.timestamps
end
add_index :comfy_cms_layouts, [:parent_id, :position]
add_index :comfy_cms_layouts, [:site_id, :identifier], :unique => true
add_index :comfy_cms_layouts, [:site_id, :identifier], unique: true
# -- Pages --------------------------------------------------------------
create_table :comfy_cms_pages do |t|
t.integer :site_id, :null => false
t.integer :site_id, null: false
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.string :full_path, null: false
t.text :content_cache, text_limit
t.integer :position, :null => false, :default => 0
t.integer :children_count, :null => false, :default => 0
t.boolean :is_published, :null => false, :default => true
t.boolean :is_shared, :null => false, :default => false
t.integer :position, null: false, default: 0
t.integer :children_count, null: false, default: 0
t.boolean :is_published, null: false, default: true
t.boolean :is_shared, null: false, default: false
t.timestamps
end
add_index :comfy_cms_pages, [:site_id, :full_path]
@@ -59,9 +59,9 @@ class CreateCms < ActiveRecord::Migration
# -- Page Blocks --------------------------------------------------------
create_table :comfy_cms_blocks do |t|
t.string :identifier, :null => false
t.string :identifier, null: false
t.text :content, text_limit
t.references :blockable, :polymorphic => true
t.references :blockable, polymorphic: true
t.timestamps
end
add_index :comfy_cms_blocks, [:identifier]
@@ -69,27 +69,27 @@ class CreateCms < ActiveRecord::Migration
# -- Snippets -----------------------------------------------------------
create_table :comfy_cms_snippets do |t|
t.integer :site_id, :null => false
t.string :label, :null => false
t.string :identifier, :null => false
t.integer :site_id, null: false
t.string :label, null: false
t.string :identifier, null: false
t.text :content, text_limit
t.integer :position, :null => false, :default => 0
t.boolean :is_shared, :null => false, :default => false
t.integer :position, null: false, default: 0
t.boolean :is_shared, null: false, default: false
t.timestamps
end
add_index :comfy_cms_snippets, [:site_id, :identifier], :unique => true
add_index :comfy_cms_snippets, [:site_id, :identifier], unique: true
add_index :comfy_cms_snippets, [:site_id, :position]
# -- 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
t.string :file_content_type, :null => false
t.integer :file_file_size, :null => false
t.string :description, :limit => 2048
t.integer :position, :null => false, :default => 0
t.string :label, null: false
t.string :file_file_name, null: false
t.string :file_content_type, null: false
t.integer :file_file_size, null: false
t.string :description, limit: 2048
t.integer :position, null: false, default: 0
t.timestamps
end
add_index :comfy_cms_files, [:site_id, :label]
@@ -98,31 +98,31 @@ class CreateCms < ActiveRecord::Migration
add_index :comfy_cms_files, [:site_id, :block_id]
# -- Revisions -----------------------------------------------------------
create_table :comfy_cms_revisions, :force => true do |t|
t.string :record_type, :null => false
t.integer :record_id, :null => false
create_table :comfy_cms_revisions, force: true do |t|
t.string :record_type, null: false
t.integer :record_id, null: false
t.text :data, text_limit
t.datetime :created_at
end
add_index :comfy_cms_revisions, [:record_type, :record_id, :created_at],
:name => 'index_cms_revisions_on_rtype_and_rid_and_created_at'
name: 'index_cms_revisions_on_rtype_and_rid_and_created_at'
# -- Categories ---------------------------------------------------------
create_table :comfy_cms_categories, :force => true do |t|
t.integer :site_id, :null => false
t.string :label, :null => false
t.string :categorized_type, :null => false
create_table :comfy_cms_categories, force: true do |t|
t.integer :site_id, null: false
t.string :label, null: false
t.string :categorized_type, null: false
end
add_index :comfy_cms_categories, [:site_id, :categorized_type, :label], :unique => true,
:name => 'index_cms_categories_on_site_id_and_cat_type_and_label'
add_index :comfy_cms_categories, [:site_id, :categorized_type, :label], unique: true,
name: 'index_cms_categories_on_site_id_and_cat_type_and_label'
create_table :comfy_cms_categorizations, :force => true do |t|
t.integer :category_id, :null => false
t.string :categorized_type, :null => false
t.integer :categorized_id, :null => false
create_table :comfy_cms_categorizations, force: true do |t|
t.integer :category_id, null: false
t.string :categorized_type, null: false
t.integer :categorized_id, null: false
end
add_index :comfy_cms_categorizations, [:category_id, :categorized_type, :categorized_id], :unique => true,
:name => 'index_cms_categorizations_on_cat_id_and_catd_type_and_catd_id'
add_index :comfy_cms_categorizations, [:category_id, :categorized_type, :categorized_id], unique: true,
name: 'index_cms_categorizations_on_cat_id_and_catd_type_and_catd_id'
end
def self.down

View File

@@ -39,22 +39,22 @@ end
def load_roles
puts "Creating admin role..."
@admin = Role.create(:name => 'Admin')
@admin = Role.create(name: 'Admin')
puts "Creating crop wrangler role..."
@wrangler = Role.create(:name => 'Crop Wrangler')
@wrangler = Role.create(name: 'Crop Wrangler')
end
def load_basic_account_types
puts "Adding 'free' and 'staff' account types..."
AccountType.create!(
:name => "Free",
:is_paid => false,
:is_permanent_paid => false
name: "Free",
is_paid: false,
is_permanent_paid: false
)
AccountType.create!(
:name => "Staff",
:is_paid => true,
:is_permanent_paid => true
name: "Staff",
is_paid: true,
is_permanent_paid: true
)
end
@@ -75,10 +75,10 @@ def load_test_users
(1..member_size).each do |i|
@user = Member.new(
:login_name => "test#{i}",
:email => "test#{i}@example.com",
:password => "password#{i}",
:tos_agreement => true
login_name: "test#{i}",
email: "test#{i}@example.com",
password: "password#{i}",
tos_agreement: true
)
@user.skip_confirmation!
@user.save!
@@ -112,20 +112,20 @@ end
def load_admin_users
puts "Adding admin and crop wrangler members..."
@admin_user = Member.new(
:login_name => "admin1",
:email => "admin1@example.com",
:password => "password1",
:tos_agreement => true
login_name: "admin1",
email: "admin1@example.com",
password: "password1",
tos_agreement: true
)
@admin_user.skip_confirmation!
@admin_user.roles << @admin
@admin_user.save!
@wrangler_user = Member.new(
:login_name => "wrangler1",
:email => "wrangler1@example.com",
:password => "password1",
:tos_agreement => true
login_name: "wrangler1",
email: "wrangler1@example.com",
password: "password1",
tos_agreement: true
)
@wrangler_user.skip_confirmation!
@wrangler_user.roles << @wrangler
@@ -134,10 +134,10 @@ end
def create_cropbot
@cropbot_user = Member.new(
:login_name => "cropbot",
:email => Growstuff::Application.config.bot_email,
:password => SecureRandom.urlsafe_base64(64),
:tos_agreement => true
login_name: "cropbot",
email: Growstuff::Application.config.bot_email,
password: SecureRandom.urlsafe_base64(64),
tos_agreement: true
)
@cropbot_user.skip_confirmation!
@cropbot_user.roles << @wrangler
@@ -149,31 +149,31 @@ end
def load_paid_account_types
puts "Adding 'paid' and 'seed' account types..."
@paid_account = AccountType.create!(
:name => "Paid",
:is_paid => true,
:is_permanent_paid => false
name: "Paid",
is_paid: true,
is_permanent_paid: false
)
@seed_account = AccountType.create!(
:name => "Seed",
:is_paid => true,
:is_permanent_paid => true
name: "Seed",
is_paid: true,
is_permanent_paid: true
)
end
def load_products
puts "Adding products..."
Product.create!(
:name => "Annual subscription",
:description => "Paid account, 1 year",
:min_price => 3000,
:account_type_id => @paid_account.id,
:paid_months => 12
name: "Annual subscription",
description: "Paid account, 1 year",
min_price: 3000,
account_type_id: @paid_account.id,
paid_months: 12
)
Product.create!(
:name => "Seed account",
:description => "Paid account, in perpetuity",
:min_price => 15000,
:account_type_id => @seed_account.id,
name: "Seed account",
description: "Paid account, in perpetuity",
min_price: 15000,
account_type_id: @seed_account.id,
)
end

View File

@@ -16,7 +16,7 @@ module Haml::Filters
# find crop case-insensitively
crop = Crop.where('lower(name) = ?', crop_str.downcase).first
if crop
url = Rails.application.routes.url_helpers.crop_url(crop, :host => Growstuff::Application.config.host)
url = Rails.application.routes.url_helpers.crop_url(crop, host: Growstuff::Application.config.host)
"[#{crop_str}](#{url})"
else
crop_str
@@ -29,7 +29,7 @@ module Haml::Filters
# find member case-insensitively
member = Member.where('lower(login_name) = ?', member_str.downcase).first
if member
url = Rails.application.routes.url_helpers.member_url(member, :only_path => true)
url = Rails.application.routes.url_helpers.member_url(member, only_path: true)
"[#{member_str}](#{url})"
else
member_str
@@ -42,7 +42,7 @@ module Haml::Filters
# find member case-insensitively
member = Member.where('lower(login_name) = ?', member_str[1..-1].downcase).first
if member
url = Rails.application.routes.url_helpers.member_url(member, :only_path => true)
url = Rails.application.routes.url_helpers.member_url(member, only_path: true)
"[#{member_str}](#{url})"
else
member_str

View File

@@ -3,7 +3,7 @@ namespace :growstuff do
desc "Add an admin user, by name"
# usage: rake growstuff:admin_user name=skud
task :admin_user => :environment do
task admin_user: :environment do
member = Member.find_by_login_name(ENV['name']) or raise "Usage: rake growstuff:admin_user name=whoever (login name is case-sensitive)"
admin = Role.find('admin')
member.roles << admin
@@ -12,7 +12,7 @@ namespace :growstuff do
desc "Add a crop wrangler user, by name"
# usage: rake growstuff:cropwrangler_user name=skud
task :cropwrangler_user => :environment do
task cropwrangler_user: :environment do
member = Member.find_by_login_name(ENV['name']) or raise "Usage: rake growstuff:cropwrangler_user name=whoever (login name is case-sensitive)"
cw = Role.find('crop-wrangler')
member.roles << cw
@@ -21,7 +21,7 @@ namespace :growstuff do
desc "Upload crops from a CSV file"
# usage: rake growstuff:import_crops file=filename.csv
task :import_crops => :environment do
task import_crops: :environment do
require 'csv'
@file = ENV['file'] or raise "Usage: rake growstuff:import_crops file=file.csv"
@@ -38,7 +38,7 @@ namespace :growstuff do
desc "Send planting reminder email"
# usage: rake growstuff:send_planting_reminder
task :send_planting_reminder => :environment do
task send_planting_reminder: :environment do
# Heroku scheduler only lets us run things daily, so this checks
# whether it's the right day to actually do the deed.
# Note that Heroku scheduler runs on UTC.
@@ -56,7 +56,7 @@ namespace :growstuff do
desc "Depopulate Null Island"
# this fixes up anyone who has erroneously wound up with a 0,0 lat/long
task :depopulate_null_island => :environment do
task depopulate_null_island: :environment do
Member.find_each do |m|
if m.location and (m.latitude == nil and m.longitude == nil)
m.geocode
@@ -69,7 +69,7 @@ namespace :growstuff do
namespace :oneoff do
desc "May 2013: replace any empty notification subjects with (no subject)"
task :empty_subjects => :environment do
task empty_subjects: :environment do
# this is inefficient as it checks every Notification, but the
# site is small and there aren't many of them, so it shouldn't matter
@@ -81,7 +81,7 @@ namespace :growstuff do
end
desc "May 2013: replace any empty garden names with Garden"
task :empty_garden_names => :environment do
task empty_garden_names: :environment do
# this is inefficient as it checks every Garden, but the
# site is small and there aren't many of them, so it shouldn't matter
@@ -96,48 +96,48 @@ namespace :growstuff do
desc "June 2013: create account types and products."
task :setup_shop => :environment do
task setup_shop: :environment do
puts "Adding account types..."
AccountType.find_or_create_by(
:name => "Free",
:is_paid => false,
:is_permanent_paid => false
name: "Free",
is_paid: false,
is_permanent_paid: false
)
@paid_account = AccountType.find_or_create_by(
:name => "Paid",
:is_paid => true,
:is_permanent_paid => false
name: "Paid",
is_paid: true,
is_permanent_paid: false
)
@seed_account = AccountType.find_or_create_by(
:name => "Seed",
:is_paid => true,
:is_permanent_paid => true
name: "Seed",
is_paid: true,
is_permanent_paid: true
)
@staff_account = AccountType.find_or_create_by(
:name => "Staff",
:is_paid => true,
:is_permanent_paid => true
name: "Staff",
is_paid: true,
is_permanent_paid: true
)
puts "Adding products..."
Product.find_or_create_by(
:name => "Annual subscription",
:description => "An annual subscription gives you access to paid account features for one year. Does not auto-renew.",
:min_price => 3000,
:account_type_id => @paid_account.id,
:paid_months => 12
name: "Annual subscription",
description: "An annual subscription gives you access to paid account features for one year. Does not auto-renew.",
min_price: 3000,
account_type_id: @paid_account.id,
paid_months: 12
)
Product.find_or_create_by(
:name => "Seed account",
:description => "A seed account helps Growstuff grow in its early days. It gives you all the features of a paid account, in perpetuity. This account type never expires.",
:min_price => 15000,
:account_type_id => @seed_account.id,
name: "Seed account",
description: "A seed account helps Growstuff grow in its early days. It gives you all the features of a paid account, in perpetuity. This account type never expires.",
min_price: 15000,
account_type_id: @seed_account.id,
)
puts "Giving each member an account record..."
Member.all.each do |m|
unless m.account
Account.create(:member_id => m.id)
Account.create(member_id: m.id)
end
end
@@ -152,7 +152,7 @@ namespace :growstuff do
end
desc "June 2013: replace nil account_types with free accounts"
task :nil_account_type => :environment do
task nil_account_type: :environment do
free = AccountType.find_by_name("Free")
raise "Free account type not found: run rake growstuff:oneoff:setup_shop"\
@@ -166,7 +166,7 @@ namespace :growstuff do
end
desc "July 2013: replace nil seed.tradable_to with nowhere"
task :tradable_to_nowhere => :environment do
task tradable_to_nowhere: :environment do
Seed.all.each do |s|
unless s.tradable_to
@@ -177,7 +177,7 @@ namespace :growstuff do
end
desc "August 2013: set up plantings_count cache on crop"
task :reset_crop_plantings_count => :environment do
task reset_crop_plantings_count: :environment do
Crop.find_each do |c|
Crop.reset_counters c.id, :plantings
@@ -185,7 +185,7 @@ namespace :growstuff do
end
desc "August 2013: set default creator on existing crops"
task :set_default_crop_creator => :environment do
task set_default_crop_creator: :environment do
cropbot = Member.find_by_login_name("cropbot")
raise "cropbot not found: create cropbot member on site or run rake db:seed" unless cropbot
@@ -207,7 +207,7 @@ namespace :growstuff do
end
desc "August 2013: set planting owner"
task :set_planting_owner => :environment do
task set_planting_owner: :environment do
Planting.find_each do |p|
p.owner = p.garden.owner
p.save
@@ -215,14 +215,14 @@ namespace :growstuff do
end
desc "August 2013: initialize member planting counter"
task :initialize_member_planting_count => :environment do
task initialize_member_planting_count: :environment do
Member.find_each do |m|
Member.reset_counters m.id, :plantings
end
end
desc "October 2013: set garden locations to member locations"
task :initialize_garden_locations => :environment do
task initialize_garden_locations: :environment do
Member.located.find_each do |m|
m.gardens.each do |g|
if g.location.blank?
@@ -236,7 +236,7 @@ namespace :growstuff do
end
desc "October 2013: import initial plant parts"
task :import_plant_parts => :environment do
task import_plant_parts: :environment do
plant_parts = [
'fruit',
'flower',
@@ -257,7 +257,7 @@ namespace :growstuff do
end
desc "July 2014: set planting_count to 0 by default, not nil"
task :zero_plantings_count => :environment do
task zero_plantings_count: :environment do
Crop.find_each do |c|
if c.plantings_count.nil?
c.plantings_count = 0
@@ -267,7 +267,7 @@ namespace :growstuff do
end
desc "August 2014: fix ping to pint in database"
task :ping_to_pint => :environment do
task ping_to_pint: :environment do
Harvest.find_each do |h|
if h.unit == "ping"
h.unit = "pint"
@@ -277,21 +277,21 @@ namespace :growstuff do
end
desc "October 2014: remove unused photos"
task :remove_unused_photos => :environment do
task remove_unused_photos: :environment do
Photo.find_each do |p|
p.destroy_if_unused
end
end
desc "October 2014: generate crops_posts records for existing posts"
task :generate_crops_posts_records => :environment do
task generate_crops_posts_records: :environment do
Post.find_each do |p|
p.save
end
end
desc "October 2014: add alternate names for crops"
task :add_alternate_names => :environment do
task add_alternate_names: :environment do
require 'csv'
file = "db/seeds/alternate_names_201410.csv"
puts "Loading alternate names from #{file}..."
@@ -316,7 +316,7 @@ namespace :growstuff do
end
desc "January 2015: fill in si_weight column"
task :populate_si_weight => :environment do
task populate_si_weight: :environment do
Harvest.find_each do |h|
h.set_si_weight
h.save
@@ -324,7 +324,7 @@ namespace :growstuff do
end
desc "January 2015: build Elasticsearch index"
task :elasticsearch_create_index => :environment do
task elasticsearch_create_index: :environment do
Crop.__elasticsearch__.create_index! force: true
Crop.import
end

View File

@@ -1,5 +1,5 @@
desc "Install git hooks"
task :hooks do
FileUtils.symlink '../../script/pre-commit.sh', '.git/hooks/pre-commit',
:force => true
force: true
end

View File

@@ -2,7 +2,7 @@ require 'rake'
begin
require 'rspec/core/rake_task'
task(:spec).clear
RSpec::Core::RakeTask.new(:spec => 'db:test:prepare') do |t|
RSpec::Core::RakeTask.new(spec: 'db:test:prepare') do |t|
t.verbose = false
end
rescue LoadError

View File

@@ -3,7 +3,7 @@
require 'heroku-api'
require 'yaml'
heroku = Heroku::API.new(:api_key => ENV['HEROKU_API_KEY'])
heroku = Heroku::API.new(api_key: ENV['HEROKU_API_KEY'])
branch = ENV['TRAVIS_BRANCH']
travis_config = YAML.load_file('.travis.yml')
if travis_config['deploy']['app'].has_key? branch

View File

@@ -24,13 +24,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

@@ -22,7 +22,7 @@ describe AuthenticationsController do
@member = FactoryGirl.create(:member)
sign_in @member
controller.stub(:current_member) { @member }
@auth = FactoryGirl.create(:authentication, :member => @member)
@auth = FactoryGirl.create(:authentication, member: @member)
request.env['omniauth.auth'] = {
'provider' => 'foo',
'uid' => 'bar',

View File

@@ -26,12 +26,12 @@ describe CommentsController do
def valid_attributes
@post = FactoryGirl.create(:post)
{ :post_id => @post.id, :author_id => @member.id, :body => "some text" }
{ post_id: @post.id, author_id: @member.id, body: "some text" }
end
describe "GET RSS feed" do
it "returns an RSS feed" do
get :index, :format => "rss"
get :index, format: "rss"
response.should be_success
response.should render_template("comments/index")
response.content_type.should eq("application/rss+xml")
@@ -41,14 +41,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}
old_comment = FactoryGirl.create(:comment, post: post)
get :new, {post_id: post.id}
assigns(:comments).should eq [old_comment]
end
@@ -61,9 +61,9 @@ describe CommentsController do
describe "GET edit" do
it "assigns previous comments as @comments" 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}
old_comment = FactoryGirl.create(:comment, post: post)
comment = FactoryGirl.create(:comment, post: post, author: @member)
get :edit, {id: comment.to_param}
assigns(:comments).should eq([comment, old_comment])
end
end
@@ -72,7 +72,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
@@ -82,7 +82,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

@@ -22,9 +22,9 @@ describe CropsController do
def valid_attributes
{
:name => "Tomato",
:en_wikipedia_url => 'http://en.wikipedia.org/wiki/Tomato',
:approval_status => 'approved'
name: "Tomato",
en_wikipedia_url: 'http://en.wikipedia.org/wiki/Tomato',
approval_status: 'approved'
}
end
@@ -55,7 +55,7 @@ describe CropsController do
describe "GET RSS feed" do
it "returns an RSS feed" do
get :index, :format => "rss"
get :index, format: "rss"
response.should be_success
response.should render_template("crops/index")
response.content_type.should eq("application/rss+xml")

View File

@@ -22,7 +22,7 @@ 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

@@ -22,9 +22,9 @@ describe HarvestsController do
def valid_attributes
{
:owner_id => subject.current_member.id,
:crop_id => FactoryGirl.create(:crop).id,
:plant_part_id => FactoryGirl.create(:plant_part).id
owner_id: subject.current_member.id,
crop_id: FactoryGirl.create(:crop).id,
plant_part_id: FactoryGirl.create(:plant_part).id
}
end
@@ -34,8 +34,8 @@ describe HarvestsController do
@member2 = FactoryGirl.create(:member)
@tomato = FactoryGirl.create(:tomato)
@maize = FactoryGirl.create(:maize)
@harvest1 = FactoryGirl.create(:harvest, :owner_id => @member1.id, :crop_id => @tomato.id)
@harvest2 = FactoryGirl.create(:harvest, :owner_id => @member2.id, :crop_id => @maize.id)
@harvest1 = FactoryGirl.create(:harvest, owner_id: @member1.id, crop_id: @tomato.id)
@harvest2 = FactoryGirl.create(:harvest, owner_id: @member2.id, crop_id: @maize.id)
end
it "assigns all harvests as @harvests" do
@@ -44,19 +44,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
@@ -64,7 +64,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
@@ -79,7 +79,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
@@ -88,18 +88,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
@@ -108,14 +108,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
@@ -130,18 +130,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
@@ -151,7 +151,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
@@ -159,7 +159,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
@@ -169,13 +169,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

@@ -20,9 +20,9 @@ describe MembersController do
before :each do
@member = FactoryGirl.create(:member)
@posts = [ FactoryGirl.create(:post, :author => @member) ]
@twitter_auth = FactoryGirl.create(:authentication, :member => @member)
@flickr_auth = FactoryGirl.create(:flickr_authentication, :member => @member)
@posts = [ FactoryGirl.create(:post, author: @member) ]
@twitter_auth = FactoryGirl.create(:authentication, member: @member)
@flickr_auth = FactoryGirl.create(:flickr_authentication, member: @member)
end
describe "GET index" do
@@ -34,7 +34,7 @@ describe MembersController do
describe "GET JSON index" do
it "provides JSON for members" do
get :index, :format => 'json'
get :index, format: 'json'
response.should be_success
end
end
@@ -42,39 +42,39 @@ 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
describe "GET member's RSS feed" do
it "returns an RSS feed" do
get :show, { :id => @member.to_param, :format => "rss" }
get :show, { id: @member.to_param, format: "rss" }
response.should be_success
response.should render_template("members/show")
response.content_type.should eq("application/rss+xml")

Some files were not shown because too many files have changed in this diff Show More