Consistently use Ruby 1.9 hash syntax

This commit is contained in:
Erik Michaels-Ober 2014-03-25 10:47:44 +01:00
parent de32570df8
commit 3b3fa3b127
27 changed files with 10118 additions and 10115 deletions

View File

@ -35,7 +35,7 @@ Documentation:
# Enforce Ruby 1.8-compatible hash syntax # Enforce Ruby 1.8-compatible hash syntax
HashSyntax: HashSyntax:
EnforcedStyle: hash_rockets EnforcedStyle: ruby19
# No spaces inside hash literals # No spaces inside hash literals
SpaceInsideHashLiteralBraces: SpaceInsideHashLiteralBraces:

View File

@ -32,8 +32,8 @@ group :production do
end end
group :test do group :test do
gem 'coveralls', :require => false gem 'coveralls', require: false
gem 'simplecov', :require => false gem 'simplecov', require: false
gem 'sqlite3' gem 'sqlite3'
gem 'webmock' gem 'webmock'
end end

View File

@ -6,7 +6,7 @@ class AddressesController < ApplicationController
unless @address.blank? unless @address.blank?
respond_with @address respond_with @address
else else
render(:json => {:errors => {:address => [t("errors.not_found", :thing => t("defaults.address"))]}}, :status => 404) render(json: {errors: {address: [t("errors.not_found", thing: t("defaults.address"))]}}, status: 404)
end end
end end
end end

View File

@ -1,7 +1,7 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception. # Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery :with => :exception protect_from_forgery with: :exception
before_filter :set_flash_from_params before_filter :set_flash_from_params
before_filter :set_locale before_filter :set_locale

View File

@ -3,16 +3,16 @@ class PasswordsController < Devise::PasswordsController
self.resource = resource_class.send_reset_password_instructions(resource_params) self.resource = resource_class.send_reset_password_instructions(resource_params)
yield resource if block_given? yield resource if block_given?
if successfully_sent?(resource) if successfully_sent?(resource)
render(:json => {:success => true}) render(json: {success: true})
else else
render(:json => {:errors => resource.errors}, :status => 500) render(json: {errors: resource.errors}, status: 500)
end end
end end
def edit def edit
self.resource = resource_class.new self.resource = resource_class.new
resource.reset_password_token = params[:reset_password_token] resource.reset_password_token = params[:reset_password_token]
render("edit", :layout => "info_window") render("edit", layout: "info_window")
end end
def update def update
@ -22,7 +22,7 @@ class PasswordsController < Devise::PasswordsController
resource.unlock_access! if unlockable?(resource) resource.unlock_access! if unlockable?(resource)
sign_in(resource_name, resource) sign_in(resource_name, resource)
end end
redirect_to(:controller => "main", :action => "index") redirect_to(controller: "main", action: "index")
end end
private private

View File

@ -7,9 +7,9 @@ class RemindersController < ApplicationController
if @reminder.save if @reminder.save
ThingMailer.reminder(@reminder.thing).deliver ThingMailer.reminder(@reminder.thing).deliver
@reminder.update_attribute(:sent, true) @reminder.update_attribute(:sent, true)
render(:json => @reminder) render(json: @reminder)
else else
render(:json => {:errors => @reminder.errors}, :status => 500) render(json: {errors: @reminder.errors}, status: 500)
end end
end end

View File

@ -1,5 +1,5 @@
class SessionsController < Devise::SessionsController class SessionsController < Devise::SessionsController
skip_before_filter :verify_authenticity_token, :only => [:destroy] skip_before_filter :verify_authenticity_token, only: [:destroy]
def new def new
redirect_to(root_path) redirect_to(root_path)
@ -10,9 +10,9 @@ class SessionsController < Devise::SessionsController
if resource if resource
sign_in(resource_name, resource) sign_in(resource_name, resource)
yield resource if block_given? yield resource if block_given?
render(:json => resource) render(json: resource)
else else
render(:json => {:errors => {:password => [t("errors.password")]}}, :status => 401) render(json: {errors: {password: [t("errors.password")]}}, status: 401)
end end
end end
@ -21,6 +21,6 @@ class SessionsController < Devise::SessionsController
sign_out(resource_name) if signed_in sign_out(resource_name) if signed_in
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name) Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
yield resource if block_given? yield resource if block_given?
render(:json => {:success => signed_in}) render(json: {success: signed_in})
end end
end end

View File

@ -6,7 +6,7 @@ class ThingsController < ApplicationController
unless @things.blank? unless @things.blank?
respond_with @things respond_with @things
else else
render(:json => {:errors => {:address => [t("errors.not_found", :thing => t("defaults.thing"))]}}, :status => 404) render(json: {errors: {address: [t("errors.not_found", thing: t("defaults.thing"))]}}, status: 404)
end end
end end
@ -15,7 +15,7 @@ class ThingsController < ApplicationController
if @thing.update_attributes(thing_params) if @thing.update_attributes(thing_params)
respond_with @thing respond_with @thing
else else
render(:json => {:errors => @thing.errors}, :status => 500) render(json: {errors: @thing.errors}, status: 500)
end end
end end

View File

@ -1,6 +1,6 @@
class UsersController < Devise::RegistrationsController class UsersController < Devise::RegistrationsController
def edit def edit
render("sidebar/edit_profile", :layout => "sidebar") render("sidebar/edit_profile", layout: "sidebar")
end end
def update def update
@ -8,12 +8,12 @@ class UsersController < Devise::RegistrationsController
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email) prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
if update_resource(resource, account_update_params) if update_resource(resource, account_update_params)
yield resource if block_given? yield resource if block_given?
sign_in(resource_name, resource, :bypass => true) sign_in(resource_name, resource, bypass: true)
flash[:notice] = "Profile updated!" flash[:notice] = "Profile updated!"
redirect_to(:controller => "sidebar", :action => "search") redirect_to(controller: "sidebar", action: "search")
else else
clean_up_passwords(resource) clean_up_passwords(resource)
render(:json => {:errors => resource.errors}, :status => 500) render(json: {errors: resource.errors}, status: 500)
end end
end end
@ -22,10 +22,10 @@ class UsersController < Devise::RegistrationsController
if resource.save if resource.save
yield resource if block_given? yield resource if block_given?
sign_in(resource_name, resource) sign_in(resource_name, resource)
render(:json => resource) render(json: resource)
else else
clean_up_passwords(resource) clean_up_passwords(resource)
render(:json => {:errors => resource.errors}, :status => 500) render(json: {errors: resource.errors}, status: 500)
end end
end end

View File

@ -1,13 +1,13 @@
class ThingMailer < ActionMailer::Base class ThingMailer < ActionMailer::Base
default :from => "adoptahydrant@cityofboston.gov" default from: "adoptahydrant@cityofboston.gov"
def reminder(thing) def reminder(thing)
@thing = thing @thing = thing
@user = thing.user @user = thing.user
mail( mail(
{ {
:to => thing.user.email, to: thing.user.email,
:subject => ["Remember to shovel", thing.name].compact.join(' '), subject: ["Remember to shovel", thing.name].compact.join(' '),
} }
) )
end end

View File

@ -1,7 +1,7 @@
class Reminder < ActiveRecord::Base class Reminder < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection include ActiveModel::ForbiddenAttributesProtection
validates_presence_of :from_user, :to_user, :thing validates_presence_of :from_user, :to_user, :thing
belongs_to :from_user, :class_name => "User" belongs_to :from_user, class_name: "User"
belongs_to :to_user, :class_name => "User" belongs_to :to_user, class_name: "User"
belongs_to :thing belongs_to :thing
end end

View File

@ -2,7 +2,7 @@ require 'geokit'
class Thing < ActiveRecord::Base class Thing < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection include ActiveModel::ForbiddenAttributesProtection
validates_uniqueness_of :city_id, :allow_nil => true validates_uniqueness_of :city_id, allow_nil: true
validates_presence_of :lat, :lng validates_presence_of :lat, :lng
belongs_to :user belongs_to :user
has_many :reminders has_many :reminders

View File

@ -5,13 +5,13 @@ class User < ActiveRecord::Base
# :lockable, :timeoutable and :omniauthable # :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :recoverable, :rememberable, devise :database_authenticatable, :registerable, :recoverable, :rememberable,
:trackable, :validatable :trackable, :validatable
validates_formatting_of :email, :using => :email validates_formatting_of :email, using: :email
validates_formatting_of :sms_number, :using => :us_phone, :allow_blank => true validates_formatting_of :sms_number, using: :us_phone, allow_blank: true
validates_formatting_of :voice_number, :using => :us_phone, :allow_blank => true validates_formatting_of :voice_number, using: :us_phone, allow_blank: true
validates_formatting_of :zip, :using => :us_zip, :allow_blank => true validates_formatting_of :zip, using: :us_zip, allow_blank: true
validates_presence_of :name validates_presence_of :name
has_many :reminders_to, :class_name => "Reminder", :foreign_key => "to_user_id" has_many :reminders_to, class_name: "Reminder", foreign_key: "to_user_id"
has_many :reminders_from, :class_name => "Reminder", :foreign_key => "from_user_id" has_many :reminders_from, class_name: "Reminder", foreign_key: "from_user_id"
has_many :things has_many :things
before_validation :remove_non_digits_from_phone_numbers before_validation :remove_non_digits_from_phone_numbers
def remove_non_digits_from_phone_numbers def remove_non_digits_from_phone_numbers

View File

@ -15,7 +15,7 @@ AdoptAThing::Application.configure do
# Don't care if the mailer can't send. # Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = {:host => 'localhost:3000'} config.action_mailer.default_url_options = {host: 'localhost:3000'}
# Print deprecation notices to the Rails logger. # Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log config.active_support.deprecation = :log

View File

@ -65,7 +65,7 @@ AdoptAThing::Application.configure do
# Set this to true and configure the email server for immediate delivery to raise delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors.
config.action_mailer.raise_delivery_errors = true config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = {:host => 'adoptahydrant.org'} config.action_mailer.default_url_options = {host: 'adoptahydrant.org'}
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found). # the I18n.default_locale when a translation can not be found).
@ -82,10 +82,10 @@ AdoptAThing::Application.configure do
end end
ActionMailer::Base.smtp_settings = { ActionMailer::Base.smtp_settings = {
address: "smtp.sendgrid.net", address: "smtp.sendgrid.net",
port: "25", port: "25",
authentication: :plain, authentication: :plain,
user_name: ENV['SENDGRID_USERNAME'], user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'], password: ENV['SENDGRID_PASSWORD'],
domain: ENV['SENDGRID_DOMAIN'], domain: ENV['SENDGRID_DOMAIN'],
} }

View File

@ -30,7 +30,7 @@ AdoptAThing::Application.configure do
# The :test delivery method accumulates sent emails in the # The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array. # ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test config.action_mailer.delivery_method = :test
config.action_mailer.default_url_options = {:host => 'localhost:3000'} config.action_mailer.default_url_options = {host: 'localhost:3000'}
# Print deprecation notices to the stderr. # Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr config.active_support.deprecation = :stderr

View File

@ -1,12 +1,12 @@
AdoptAThing::Application.routes.draw do AdoptAThing::Application.routes.draw do
devise_for :users, :controllers => { devise_for :users, controllers: {
passwords: 'passwords', passwords: 'passwords',
registrations: 'users', registrations: 'users',
sessions: 'sessions', sessions: 'sessions',
} }
get '/address', to: 'addresses#show', as: 'address' get '/address', to: 'addresses#show', as: 'address'
get '/info_window', to:'info_window#index', as: 'info_window' get '/info_window', to: 'info_window#index', as: 'info_window'
get '/sitemap', to: 'sitemaps#index', as: 'sitemap' get '/sitemap', to: 'sitemaps#index', as: 'sitemap'
scope '/sidebar', controller: :sidebar do scope '/sidebar', controller: :sidebar do
@ -17,6 +17,6 @@ AdoptAThing::Application.routes.draw do
resource :reminders resource :reminders
resource :things resource :things
mount RailsAdmin::Engine => '/admin', as: 'rails_admin' mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
root to: 'main#index' root to: 'main#index'
end end

View File

@ -9,55 +9,58 @@
# from scratch. The latter is a flawed and unsustainable approach (the more migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues). # you'll amass, the slower it'll run and the greater likelihood for issues).
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(:version => 5) do ActiveRecord::Schema.define(version: 5) do
create_table "rails_admin_histories", :force => true do |t| # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "rails_admin_histories", force: true do |t|
t.string "message" t.string "message"
t.string "username" t.string "username"
t.integer "item" t.integer "item"
t.string "table" t.string "table"
t.integer "month", :limit => 2 t.integer "month", limit: 2
t.integer "year", :limit => 8 t.integer "year", limit: 8
t.datetime "created_at", :null => false t.datetime "created_at"
t.datetime "updated_at", :null => false t.datetime "updated_at"
end end
add_index "rails_admin_histories", ["item", "table", "month", "year"], :name => "index_rails_admin_histories" add_index "rails_admin_histories", ["item", "table", "month", "year"], name: "index_rails_admin_histories", using: :btree
create_table "reminders", :force => true do |t| create_table "reminders", force: true do |t|
t.datetime "created_at", :null => false t.datetime "created_at"
t.datetime "updated_at", :null => false t.datetime "updated_at"
t.integer "from_user_id", :null => false t.integer "from_user_id", null: false
t.integer "to_user_id", :null => false t.integer "to_user_id", null: false
t.integer "thing_id", :null => false t.integer "thing_id", null: false
t.boolean "sent", :default => false t.boolean "sent", default: false
end end
add_index "reminders", ["from_user_id"], :name => "index_reminders_on_from_user_id" add_index "reminders", ["from_user_id"], name: "index_reminders_on_from_user_id", using: :btree
add_index "reminders", ["sent"], :name => "index_reminders_on_sent" add_index "reminders", ["sent"], name: "index_reminders_on_sent", using: :btree
add_index "reminders", ["thing_id"], :name => "index_reminders_on_thing_id" add_index "reminders", ["thing_id"], name: "index_reminders_on_thing_id", using: :btree
add_index "reminders", ["to_user_id"], :name => "index_reminders_on_to_user_id" add_index "reminders", ["to_user_id"], name: "index_reminders_on_to_user_id", using: :btree
create_table "things", :force => true do |t| create_table "things", force: true do |t|
t.datetime "created_at", :null => false t.datetime "created_at"
t.datetime "updated_at", :null => false t.datetime "updated_at"
t.string "name" t.string "name"
t.decimal "lat", :precision => 16, :scale => 14, :null => false t.decimal "lat", precision: 16, scale: 14, null: false
t.decimal "lng", :precision => 17, :scale => 14, :null => false t.decimal "lng", precision: 17, scale: 14, null: false
t.integer "city_id" t.integer "city_id"
t.integer "user_id" t.integer "user_id"
end end
add_index "things", ["city_id"], :name => "index_things_on_city_id", :unique => true add_index "things", ["city_id"], name: "index_things_on_city_id", unique: true, using: :btree
create_table "users", :force => true do |t| create_table "users", force: true do |t|
t.datetime "created_at", :null => false t.datetime "created_at"
t.datetime "updated_at", :null => false t.datetime "updated_at"
t.string "name", :null => false t.string "name", null: false
t.string "organization" t.string "organization"
t.string "email", :null => false t.string "email", null: false
t.string "voice_number" t.string "voice_number"
t.string "sms_number" t.string "sms_number"
t.string "address_1" t.string "address_1"
@ -65,19 +68,19 @@ ActiveRecord::Schema.define(:version => 5) do
t.string "city" t.string "city"
t.string "state" t.string "state"
t.string "zip" t.string "zip"
t.boolean "admin", :default => false t.boolean "admin", default: false
t.string "encrypted_password", :default => "", :null => false t.string "encrypted_password", default: "", null: false
t.string "reset_password_token" t.string "reset_password_token"
t.datetime "reset_password_sent_at" t.datetime "reset_password_sent_at"
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0, :null => false t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at" t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at"
t.string "current_sign_in_ip" t.string "current_sign_in_ip"
t.string "last_sign_in_ip" t.string "last_sign_in_ip"
end end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end end

19998
db/seeds.rb

File diff suppressed because it is too large Load Diff

View File

@ -3,20 +3,20 @@ require 'test_helper'
class AddressesControllerTest < ActionController::TestCase class AddressesControllerTest < ActionController::TestCase
test 'should return latitude and longitude for a valid address' do test 'should return latitude and longitude for a valid address' do
stub_request(:get, "http://maps.google.com/maps/api/geocode/json"). stub_request(:get, "http://maps.google.com/maps/api/geocode/json").
with(:query => {:address => "City Hall, Boston, MA", :sensor => "false"}). with(query: {address: "City Hall, Boston, MA", sensor: "false"}).
to_return(:body => File.read(File.expand_path('../../fixtures/city_hall.json', __FILE__))) to_return(body: File.read(File.expand_path('../../fixtures/city_hall.json', __FILE__)))
get :show, :address => 'City Hall', :city_state => "Boston, MA", :format => 'json' get :show, address: 'City Hall', city_state: "Boston, MA", format: 'json'
assert_not_nil assigns :address assert_not_nil assigns :address
end end
test 'should return an error for an invalid address' do test 'should return an error for an invalid address' do
stub_request(:get, "http://maps.google.com/maps/api/geocode/json"). stub_request(:get, "http://maps.google.com/maps/api/geocode/json").
with(:query => {:address => ", ", :sensor => "false"}). with(query: {address: ", ", sensor: "false"}).
to_return(:body => File.read(File.expand_path('../../fixtures/unknown_address.json', __FILE__))) to_return(body: File.read(File.expand_path('../../fixtures/unknown_address.json', __FILE__)))
stub_request(:get, "http://geocoder.us/service/csv/geocode"). stub_request(:get, "http://geocoder.us/service/csv/geocode").
with(:query => {:address => ", "}). with(query: {address: ", "}).
to_return(:body => File.read(File.expand_path('../../fixtures/unknown_address.json', __FILE__))) to_return(body: File.read(File.expand_path('../../fixtures/unknown_address.json', __FILE__)))
get :show, :address => '', :city_state => '', :format => 'json' get :show, address: '', city_state: '', format: 'json'
assert_response :missing assert_response :missing
end end
end end

View File

@ -11,7 +11,7 @@ class InfoWindowControllerTest < ActionController::TestCase
sign_in @user sign_in @user
@thing.user_id = @user.id @thing.user_id = @user.id
@thing.save! @thing.save!
get :index, :thing_id => @thing.id get :index, thing_id: @thing.id
assert_not_nil assigns :thing assert_not_nil assigns :thing
assert_response :success assert_response :success
assert_template 'users/thank_you' assert_template 'users/thank_you'
@ -33,7 +33,7 @@ class InfoWindowControllerTest < ActionController::TestCase
test 'should show the profile if the hydrant is adopted' do test 'should show the profile if the hydrant is adopted' do
@thing.user_id = @user.id @thing.user_id = @user.id
@thing.save! @thing.save!
get :index, :thing_id => @thing.id get :index, thing_id: @thing.id
assert_not_nil assigns :thing assert_not_nil assigns :thing
assert_response :success assert_response :success
assert_template 'users/profile' assert_template 'users/profile'
@ -42,7 +42,7 @@ class InfoWindowControllerTest < ActionController::TestCase
test 'should show adoption form if hydrant is not adopted' do test 'should show adoption form if hydrant is not adopted' do
sign_in @user sign_in @user
get :index, :thing_id => @thing.id get :index, thing_id: @thing.id
assert_not_nil assigns :thing assert_not_nil assigns :thing
assert_response :success assert_response :success
assert_template :adopt assert_template :adopt
@ -62,7 +62,7 @@ class InfoWindowControllerTest < ActionController::TestCase
end end
test 'should show sign-in form if signed out' do test 'should show sign-in form if signed out' do
get :index, :thing_id => @thing.id get :index, thing_id: @thing.id
assert_not_nil assigns :thing assert_not_nil assigns :thing
assert_response :success assert_response :success
assert_template 'users/sign_in' assert_template 'users/sign_in'

View File

@ -9,7 +9,7 @@ class PasswordsControllerTest < ActionController::TestCase
test 'should send password reset instructions if email address is found' do test 'should send password reset instructions if email address is found' do
num_deliveries = ActionMailer::Base.deliveries.size num_deliveries = ActionMailer::Base.deliveries.size
post :create, :user => {:email => @user.email} post :create, user: {email: @user.email}
assert_equal num_deliveries + 1, ActionMailer::Base.deliveries.size assert_equal num_deliveries + 1, ActionMailer::Base.deliveries.size
assert_response :success assert_response :success
email = ActionMailer::Base.deliveries.last email = ActionMailer::Base.deliveries.last
@ -18,30 +18,30 @@ class PasswordsControllerTest < ActionController::TestCase
end end
test 'should not send password reset instructions if email address is not found' do test 'should not send password reset instructions if email address is not found' do
post :create, :user => {:email => 'not_found@example.com'} post :create, user: {email: 'not_found@example.com'}
assert_response :error assert_response :error
end end
test 'should render edit view' do test 'should render edit view' do
get :edit, :reset_password_token => 'token' get :edit, reset_password_token: 'token'
assert_response :success assert_response :success
end end
test 'should reset user password with an valid reset password token' do test 'should reset user password with an valid reset password token' do
token = @user.send_reset_password_instructions token = @user.send_reset_password_instructions
put :update, :user => {:reset_password_token => token, :password => 'new_password'} put :update, user: {reset_password_token: token, password: 'new_password'}
@user.reload @user.reload
assert @user.valid_password?('new_password') assert @user.valid_password?('new_password')
assert_response :redirect assert_response :redirect
assert_redirected_to :controller => 'main', :action => 'index' assert_redirected_to controller: 'main', action: 'index'
end end
test 'should not reset user password with an invalid reset password token' do test 'should not reset user password with an invalid reset password token' do
@user.send_reset_password_instructions @user.send_reset_password_instructions
put :update, :user => {:reset_password_token => 'invalid_token', :password => 'new_password'} put :update, user: {reset_password_token: 'invalid_token', password: 'new_password'}
@user.reload @user.reload
assert !@user.valid_password?('new_password') assert !@user.valid_password?('new_password')
assert_response :redirect assert_response :redirect
assert_redirected_to :controller => 'main', :action => 'index' assert_redirected_to controller: 'main', action: 'index'
end end
end end

View File

@ -10,14 +10,14 @@ class RemindersControllerTest < ActionController::TestCase
@thing.user = @dan @thing.user = @dan
@thing.save! @thing.save!
stub_request(:get, "http://maps.google.com/maps/api/geocode/json"). stub_request(:get, "http://maps.google.com/maps/api/geocode/json").
with(:query => {:latlng => "42.383339,-71.049226", :sensor => "false"}). with(query: {latlng: "42.383339,-71.049226", sensor: "false"}).
to_return(:body => File.read(File.expand_path('../../fixtures/city_hall.json', __FILE__))) to_return(body: File.read(File.expand_path('../../fixtures/city_hall.json', __FILE__)))
end end
test 'should send a reminder email' do test 'should send a reminder email' do
sign_in @user sign_in @user
num_deliveries = ActionMailer::Base.deliveries.size num_deliveries = ActionMailer::Base.deliveries.size
post :create, :format => :json, :reminder => {:thing_id => @thing.id, :to_user_id => @dan.id} post :create, format: :json, reminder: {thing_id: @thing.id, to_user_id: @dan.id}
assert_equal num_deliveries + 1, ActionMailer::Base.deliveries.size assert_equal num_deliveries + 1, ActionMailer::Base.deliveries.size
assert_response :success assert_response :success
email = ActionMailer::Base.deliveries.last email = ActionMailer::Base.deliveries.last

View File

@ -19,18 +19,18 @@ class SessionsControllerTest < ActionController::TestCase
end end
test 'should authenticate user if password is correct' do test 'should authenticate user if password is correct' do
post :create, :user => {:email => @user.email, :password => 'correct'}, :format => :json post :create, user: {email: @user.email, password: 'correct'}, format: :json
assert_response :success assert_response :success
end end
test 'should return error if password is incorrect' do test 'should return error if password is incorrect' do
post :create, :user => {:email => @user.email, :password => 'incorrect'}, :format => :json post :create, user: {email: @user.email, password: 'incorrect'}, format: :json
assert_response 401 assert_response 401
end end
test 'should empty session on sign out' do test 'should empty session on sign out' do
sign_in @user sign_in @user
get :destroy, :format => :json get :destroy, format: :json
assert_equal {}, session assert_equal {}, session
assert_response :success assert_response :success
end end

View File

@ -2,7 +2,7 @@ require 'test_helper'
class SitemapsControllerTest < ActionController::TestCase class SitemapsControllerTest < ActionController::TestCase
test 'should return an XML sitemap' do test 'should return an XML sitemap' do
get :index, :format => 'xml' get :index, format: 'xml'
assert_response :success assert_response :success
end end
end end

View File

@ -6,14 +6,14 @@ class ThingsControllerTest < ActionController::TestCase
end end
test 'should list hydrants' do test 'should list hydrants' do
get :show, :format => 'json', :lat => 42.358431, :lng => -71.059773 get :show, format: 'json', lat: 42.358431, lng: -71.059773
assert_not_nil assigns :things assert_not_nil assigns :things
assert_response :success assert_response :success
end end
test 'should update hydrant' do test 'should update hydrant' do
assert_not_equal 'Birdsill', @thing.name assert_not_equal 'Birdsill', @thing.name
put :update, :format => 'json', :id => @thing.id, :thing => {:name => 'Birdsill'} put :update, format: 'json', id: @thing.id, thing: {name: 'Birdsill'}
@thing.reload @thing.reload
assert_equal 'Birdsill', @thing.name assert_equal 'Birdsill', @thing.name
assert_not_nil assigns :thing assert_not_nil assigns :thing

View File

@ -15,8 +15,8 @@ class UsersControllerTest < ActionController::TestCase
assert_select '[action=?]', '/users' assert_select '[action=?]', '/users'
assert_select '[method=?]', 'post' assert_select '[method=?]', 'post'
end end
assert_select 'input', :count => 15 assert_select 'input', count: 15
assert_select 'label', :count => 12 assert_select 'label', count: 12
assert_select 'input[name="commit"]' do assert_select 'input[name="commit"]' do
assert_select '[type=?]', 'submit' assert_select '[type=?]', 'submit'
assert_select '[value=?]', 'Update' assert_select '[value=?]', 'Update'
@ -27,26 +27,26 @@ class UsersControllerTest < ActionController::TestCase
test 'should update user if password is correct' do test 'should update user if password is correct' do
sign_in @user sign_in @user
assert_not_equal 'New Name', @user.name assert_not_equal 'New Name', @user.name
put :update, :user => {:name => 'New Name', :current_password => 'correct'} put :update, user: {name: 'New Name', current_password: 'correct'}
@user.reload @user.reload
assert_equal 'New Name', @user.name assert_equal 'New Name', @user.name
assert_response :redirect assert_response :redirect
assert_redirected_to :controller => 'sidebar', :action => 'search' assert_redirected_to controller: 'sidebar', action: 'search'
end end
test 'should return error if password is incorrect' do test 'should return error if password is incorrect' do
sign_in @user sign_in @user
put :update, :user => {:name => 'New Name', :current_password => 'incorrect'} put :update, user: {name: 'New Name', current_password: 'incorrect'}
assert_response :error assert_response :error
end end
test 'should create user if information is valid' do test 'should create user if information is valid' do
post :create, :user => {:email => 'user@example.com', :name => 'User', :password => 'correct', :password_confirmation => 'correct'} post :create, user: {email: 'user@example.com', name: 'User', password: 'correct', password_confirmation: 'correct'}
assert_response :success assert_response :success
end end
test 'should return error if information is invalid' do test 'should return error if information is invalid' do
post :create, :user => {:email => 'user@example.com', :name => 'User', :password => 'correct', :password_confirmation => 'incorrect'} post :create, user: {email: 'user@example.com', name: 'User', password: 'correct', password_confirmation: 'incorrect'}
assert_response :error assert_response :error
end end
end end