Consistently use Ruby 1.9 hash syntax
This commit is contained in:
parent
de32570df8
commit
3b3fa3b127
|
@ -35,7 +35,7 @@ Documentation:
|
|||
|
||||
# Enforce Ruby 1.8-compatible hash syntax
|
||||
HashSyntax:
|
||||
EnforcedStyle: hash_rockets
|
||||
EnforcedStyle: ruby19
|
||||
|
||||
# No spaces inside hash literals
|
||||
SpaceInsideHashLiteralBraces:
|
||||
|
|
4
Gemfile
4
Gemfile
|
@ -32,8 +32,8 @@ group :production do
|
|||
end
|
||||
|
||||
group :test do
|
||||
gem 'coveralls', :require => false
|
||||
gem 'simplecov', :require => false
|
||||
gem 'coveralls', require: false
|
||||
gem 'simplecov', require: false
|
||||
gem 'sqlite3'
|
||||
gem 'webmock'
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ class AddressesController < ApplicationController
|
|||
unless @address.blank?
|
||||
respond_with @address
|
||||
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
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class ApplicationController < ActionController::Base
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# 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_locale
|
||||
|
||||
|
|
|
@ -3,16 +3,16 @@ class PasswordsController < Devise::PasswordsController
|
|||
self.resource = resource_class.send_reset_password_instructions(resource_params)
|
||||
yield resource if block_given?
|
||||
if successfully_sent?(resource)
|
||||
render(:json => {:success => true})
|
||||
render(json: {success: true})
|
||||
else
|
||||
render(:json => {:errors => resource.errors}, :status => 500)
|
||||
render(json: {errors: resource.errors}, status: 500)
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
self.resource = resource_class.new
|
||||
resource.reset_password_token = params[:reset_password_token]
|
||||
render("edit", :layout => "info_window")
|
||||
render("edit", layout: "info_window")
|
||||
end
|
||||
|
||||
def update
|
||||
|
@ -22,7 +22,7 @@ class PasswordsController < Devise::PasswordsController
|
|||
resource.unlock_access! if unlockable?(resource)
|
||||
sign_in(resource_name, resource)
|
||||
end
|
||||
redirect_to(:controller => "main", :action => "index")
|
||||
redirect_to(controller: "main", action: "index")
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -7,9 +7,9 @@ class RemindersController < ApplicationController
|
|||
if @reminder.save
|
||||
ThingMailer.reminder(@reminder.thing).deliver
|
||||
@reminder.update_attribute(:sent, true)
|
||||
render(:json => @reminder)
|
||||
render(json: @reminder)
|
||||
else
|
||||
render(:json => {:errors => @reminder.errors}, :status => 500)
|
||||
render(json: {errors: @reminder.errors}, status: 500)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class SessionsController < Devise::SessionsController
|
||||
skip_before_filter :verify_authenticity_token, :only => [:destroy]
|
||||
skip_before_filter :verify_authenticity_token, only: [:destroy]
|
||||
|
||||
def new
|
||||
redirect_to(root_path)
|
||||
|
@ -10,9 +10,9 @@ class SessionsController < Devise::SessionsController
|
|||
if resource
|
||||
sign_in(resource_name, resource)
|
||||
yield resource if block_given?
|
||||
render(:json => resource)
|
||||
render(json: resource)
|
||||
else
|
||||
render(:json => {:errors => {:password => [t("errors.password")]}}, :status => 401)
|
||||
render(json: {errors: {password: [t("errors.password")]}}, status: 401)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -21,6 +21,6 @@ class SessionsController < Devise::SessionsController
|
|||
sign_out(resource_name) if signed_in
|
||||
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
||||
yield resource if block_given?
|
||||
render(:json => {:success => signed_in})
|
||||
render(json: {success: signed_in})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ class ThingsController < ApplicationController
|
|||
unless @things.blank?
|
||||
respond_with @things
|
||||
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
|
||||
|
||||
|
@ -15,7 +15,7 @@ class ThingsController < ApplicationController
|
|||
if @thing.update_attributes(thing_params)
|
||||
respond_with @thing
|
||||
else
|
||||
render(:json => {:errors => @thing.errors}, :status => 500)
|
||||
render(json: {errors: @thing.errors}, status: 500)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class UsersController < Devise::RegistrationsController
|
||||
def edit
|
||||
render("sidebar/edit_profile", :layout => "sidebar")
|
||||
render("sidebar/edit_profile", layout: "sidebar")
|
||||
end
|
||||
|
||||
def update
|
||||
|
@ -8,12 +8,12 @@ class UsersController < Devise::RegistrationsController
|
|||
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
|
||||
if update_resource(resource, account_update_params)
|
||||
yield resource if block_given?
|
||||
sign_in(resource_name, resource, :bypass => true)
|
||||
sign_in(resource_name, resource, bypass: true)
|
||||
flash[:notice] = "Profile updated!"
|
||||
redirect_to(:controller => "sidebar", :action => "search")
|
||||
redirect_to(controller: "sidebar", action: "search")
|
||||
else
|
||||
clean_up_passwords(resource)
|
||||
render(:json => {:errors => resource.errors}, :status => 500)
|
||||
render(json: {errors: resource.errors}, status: 500)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -22,10 +22,10 @@ class UsersController < Devise::RegistrationsController
|
|||
if resource.save
|
||||
yield resource if block_given?
|
||||
sign_in(resource_name, resource)
|
||||
render(:json => resource)
|
||||
render(json: resource)
|
||||
else
|
||||
clean_up_passwords(resource)
|
||||
render(:json => {:errors => resource.errors}, :status => 500)
|
||||
render(json: {errors: resource.errors}, status: 500)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
class ThingMailer < ActionMailer::Base
|
||||
default :from => "adoptahydrant@cityofboston.gov"
|
||||
default from: "adoptahydrant@cityofboston.gov"
|
||||
|
||||
def reminder(thing)
|
||||
@thing = thing
|
||||
@user = thing.user
|
||||
mail(
|
||||
{
|
||||
:to => thing.user.email,
|
||||
:subject => ["Remember to shovel", thing.name].compact.join(' '),
|
||||
to: thing.user.email,
|
||||
subject: ["Remember to shovel", thing.name].compact.join(' '),
|
||||
}
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class Reminder < ActiveRecord::Base
|
||||
include ActiveModel::ForbiddenAttributesProtection
|
||||
validates_presence_of :from_user, :to_user, :thing
|
||||
belongs_to :from_user, :class_name => "User"
|
||||
belongs_to :to_user, :class_name => "User"
|
||||
belongs_to :from_user, class_name: "User"
|
||||
belongs_to :to_user, class_name: "User"
|
||||
belongs_to :thing
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'geokit'
|
|||
|
||||
class Thing < ActiveRecord::Base
|
||||
include ActiveModel::ForbiddenAttributesProtection
|
||||
validates_uniqueness_of :city_id, :allow_nil => true
|
||||
validates_uniqueness_of :city_id, allow_nil: true
|
||||
validates_presence_of :lat, :lng
|
||||
belongs_to :user
|
||||
has_many :reminders
|
||||
|
|
|
@ -5,13 +5,13 @@ class User < ActiveRecord::Base
|
|||
# :lockable, :timeoutable and :omniauthable
|
||||
devise :database_authenticatable, :registerable, :recoverable, :rememberable,
|
||||
:trackable, :validatable
|
||||
validates_formatting_of :email, :using => :email
|
||||
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 :zip, :using => :us_zip, :allow_blank => true
|
||||
validates_formatting_of :email, using: :email
|
||||
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 :zip, using: :us_zip, allow_blank: true
|
||||
validates_presence_of :name
|
||||
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_to, class_name: "Reminder", foreign_key: "to_user_id"
|
||||
has_many :reminders_from, class_name: "Reminder", foreign_key: "from_user_id"
|
||||
has_many :things
|
||||
before_validation :remove_non_digits_from_phone_numbers
|
||||
def remove_non_digits_from_phone_numbers
|
||||
|
|
|
@ -15,7 +15,7 @@ AdoptAThing::Application.configure do
|
|||
|
||||
# Don't care if the mailer can't send.
|
||||
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.
|
||||
config.active_support.deprecation = :log
|
||||
|
|
|
@ -65,7 +65,7 @@ AdoptAThing::Application.configure do
|
|||
# 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.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
|
||||
# the I18n.default_locale when a translation can not be found).
|
||||
|
|
|
@ -30,7 +30,7 @@ AdoptAThing::Application.configure do
|
|||
# The :test delivery method accumulates sent emails in the
|
||||
# ActionMailer::Base.deliveries array.
|
||||
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.
|
||||
config.active_support.deprecation = :stderr
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
AdoptAThing::Application.routes.draw do
|
||||
devise_for :users, :controllers => {
|
||||
devise_for :users, controllers: {
|
||||
passwords: 'passwords',
|
||||
registrations: 'users',
|
||||
sessions: 'sessions',
|
||||
}
|
||||
|
||||
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'
|
||||
|
||||
scope '/sidebar', controller: :sidebar do
|
||||
|
@ -17,6 +17,6 @@ AdoptAThing::Application.routes.draw do
|
|||
|
||||
resource :reminders
|
||||
resource :things
|
||||
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
|
||||
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
|
||||
root to: 'main#index'
|
||||
end
|
||||
|
|
73
db/schema.rb
73
db/schema.rb
|
@ -9,55 +9,58 @@
|
|||
# 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).
|
||||
#
|
||||
# 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 "username"
|
||||
t.integer "item"
|
||||
t.string "table"
|
||||
t.integer "month", :limit => 2
|
||||
t.integer "year", :limit => 8
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "month", limit: 2
|
||||
t.integer "year", limit: 8
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
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|
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "from_user_id", :null => false
|
||||
t.integer "to_user_id", :null => false
|
||||
t.integer "thing_id", :null => false
|
||||
t.boolean "sent", :default => false
|
||||
create_table "reminders", force: true do |t|
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "from_user_id", null: false
|
||||
t.integer "to_user_id", null: false
|
||||
t.integer "thing_id", null: false
|
||||
t.boolean "sent", default: false
|
||||
end
|
||||
|
||||
add_index "reminders", ["from_user_id"], :name => "index_reminders_on_from_user_id"
|
||||
add_index "reminders", ["sent"], :name => "index_reminders_on_sent"
|
||||
add_index "reminders", ["thing_id"], :name => "index_reminders_on_thing_id"
|
||||
add_index "reminders", ["to_user_id"], :name => "index_reminders_on_to_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", using: :btree
|
||||
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", using: :btree
|
||||
|
||||
create_table "things", :force => true do |t|
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
create_table "things", force: true do |t|
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "name"
|
||||
t.decimal "lat", :precision => 16, :scale => 14, :null => false
|
||||
t.decimal "lng", :precision => 17, :scale => 14, :null => false
|
||||
t.decimal "lat", precision: 16, scale: 14, null: false
|
||||
t.decimal "lng", precision: 17, scale: 14, null: false
|
||||
t.integer "city_id"
|
||||
t.integer "user_id"
|
||||
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|
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "name", :null => false
|
||||
create_table "users", force: true do |t|
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "name", null: false
|
||||
t.string "organization"
|
||||
t.string "email", :null => false
|
||||
t.string "email", null: false
|
||||
t.string "voice_number"
|
||||
t.string "sms_number"
|
||||
t.string "address_1"
|
||||
|
@ -65,19 +68,19 @@ ActiveRecord::Schema.define(:version => 5) do
|
|||
t.string "city"
|
||||
t.string "state"
|
||||
t.string "zip"
|
||||
t.boolean "admin", :default => false
|
||||
t.string "encrypted_password", :default => "", :null => false
|
||||
t.boolean "admin", default: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
t.string "reset_password_token"
|
||||
t.datetime "reset_password_sent_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 "last_sign_in_at"
|
||||
t.string "current_sign_in_ip"
|
||||
t.string "last_sign_in_ip"
|
||||
end
|
||||
|
||||
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
||||
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :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, using: :btree
|
||||
|
||||
end
|
||||
|
|
|
@ -3,20 +3,20 @@ require 'test_helper'
|
|||
class AddressesControllerTest < ActionController::TestCase
|
||||
test 'should return latitude and longitude for a valid address' do
|
||||
stub_request(:get, "http://maps.google.com/maps/api/geocode/json").
|
||||
with(:query => {:address => "City Hall, Boston, MA", :sensor => "false"}).
|
||||
to_return(:body => File.read(File.expand_path('../../fixtures/city_hall.json', __FILE__)))
|
||||
get :show, :address => 'City Hall', :city_state => "Boston, MA", :format => 'json'
|
||||
with(query: {address: "City Hall, Boston, MA", sensor: "false"}).
|
||||
to_return(body: File.read(File.expand_path('../../fixtures/city_hall.json', __FILE__)))
|
||||
get :show, address: 'City Hall', city_state: "Boston, MA", format: 'json'
|
||||
assert_not_nil assigns :address
|
||||
end
|
||||
|
||||
test 'should return an error for an invalid address' do
|
||||
stub_request(:get, "http://maps.google.com/maps/api/geocode/json").
|
||||
with(:query => {:address => ", ", :sensor => "false"}).
|
||||
to_return(:body => File.read(File.expand_path('../../fixtures/unknown_address.json', __FILE__)))
|
||||
with(query: {address: ", ", sensor: "false"}).
|
||||
to_return(body: File.read(File.expand_path('../../fixtures/unknown_address.json', __FILE__)))
|
||||
stub_request(:get, "http://geocoder.us/service/csv/geocode").
|
||||
with(:query => {:address => ", "}).
|
||||
to_return(:body => File.read(File.expand_path('../../fixtures/unknown_address.json', __FILE__)))
|
||||
get :show, :address => '', :city_state => '', :format => 'json'
|
||||
with(query: {address: ", "}).
|
||||
to_return(body: File.read(File.expand_path('../../fixtures/unknown_address.json', __FILE__)))
|
||||
get :show, address: '', city_state: '', format: 'json'
|
||||
assert_response :missing
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ class InfoWindowControllerTest < ActionController::TestCase
|
|||
sign_in @user
|
||||
@thing.user_id = @user.id
|
||||
@thing.save!
|
||||
get :index, :thing_id => @thing.id
|
||||
get :index, thing_id: @thing.id
|
||||
assert_not_nil assigns :thing
|
||||
assert_response :success
|
||||
assert_template 'users/thank_you'
|
||||
|
@ -33,7 +33,7 @@ class InfoWindowControllerTest < ActionController::TestCase
|
|||
test 'should show the profile if the hydrant is adopted' do
|
||||
@thing.user_id = @user.id
|
||||
@thing.save!
|
||||
get :index, :thing_id => @thing.id
|
||||
get :index, thing_id: @thing.id
|
||||
assert_not_nil assigns :thing
|
||||
assert_response :success
|
||||
assert_template 'users/profile'
|
||||
|
@ -42,7 +42,7 @@ class InfoWindowControllerTest < ActionController::TestCase
|
|||
|
||||
test 'should show adoption form if hydrant is not adopted' do
|
||||
sign_in @user
|
||||
get :index, :thing_id => @thing.id
|
||||
get :index, thing_id: @thing.id
|
||||
assert_not_nil assigns :thing
|
||||
assert_response :success
|
||||
assert_template :adopt
|
||||
|
@ -62,7 +62,7 @@ class InfoWindowControllerTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
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_response :success
|
||||
assert_template 'users/sign_in'
|
||||
|
|
|
@ -9,7 +9,7 @@ class PasswordsControllerTest < ActionController::TestCase
|
|||
|
||||
test 'should send password reset instructions if email address is found' do
|
||||
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_response :success
|
||||
email = ActionMailer::Base.deliveries.last
|
||||
|
@ -18,30 +18,30 @@ class PasswordsControllerTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
test 'should render edit view' do
|
||||
get :edit, :reset_password_token => 'token'
|
||||
get :edit, reset_password_token: 'token'
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test 'should reset user password with an valid reset password token' do
|
||||
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
|
||||
assert @user.valid_password?('new_password')
|
||||
assert_response :redirect
|
||||
assert_redirected_to :controller => 'main', :action => 'index'
|
||||
assert_redirected_to controller: 'main', action: 'index'
|
||||
end
|
||||
|
||||
test 'should not reset user password with an invalid reset password token' do
|
||||
@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
|
||||
assert !@user.valid_password?('new_password')
|
||||
assert_response :redirect
|
||||
assert_redirected_to :controller => 'main', :action => 'index'
|
||||
assert_redirected_to controller: 'main', action: 'index'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,14 +10,14 @@ class RemindersControllerTest < ActionController::TestCase
|
|||
@thing.user = @dan
|
||||
@thing.save!
|
||||
stub_request(:get, "http://maps.google.com/maps/api/geocode/json").
|
||||
with(:query => {:latlng => "42.383339,-71.049226", :sensor => "false"}).
|
||||
to_return(:body => File.read(File.expand_path('../../fixtures/city_hall.json', __FILE__)))
|
||||
with(query: {latlng: "42.383339,-71.049226", sensor: "false"}).
|
||||
to_return(body: File.read(File.expand_path('../../fixtures/city_hall.json', __FILE__)))
|
||||
end
|
||||
|
||||
test 'should send a reminder email' do
|
||||
sign_in @user
|
||||
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_response :success
|
||||
email = ActionMailer::Base.deliveries.last
|
||||
|
|
|
@ -19,18 +19,18 @@ class SessionsControllerTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
test 'should empty session on sign out' do
|
||||
sign_in @user
|
||||
get :destroy, :format => :json
|
||||
get :destroy, format: :json
|
||||
assert_equal {}, session
|
||||
assert_response :success
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'test_helper'
|
|||
|
||||
class SitemapsControllerTest < ActionController::TestCase
|
||||
test 'should return an XML sitemap' do
|
||||
get :index, :format => 'xml'
|
||||
get :index, format: 'xml'
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,14 +6,14 @@ class ThingsControllerTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
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_response :success
|
||||
end
|
||||
|
||||
test 'should update hydrant' do
|
||||
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
|
||||
assert_equal 'Birdsill', @thing.name
|
||||
assert_not_nil assigns :thing
|
||||
|
|
|
@ -15,8 +15,8 @@ class UsersControllerTest < ActionController::TestCase
|
|||
assert_select '[action=?]', '/users'
|
||||
assert_select '[method=?]', 'post'
|
||||
end
|
||||
assert_select 'input', :count => 15
|
||||
assert_select 'label', :count => 12
|
||||
assert_select 'input', count: 15
|
||||
assert_select 'label', count: 12
|
||||
assert_select 'input[name="commit"]' do
|
||||
assert_select '[type=?]', 'submit'
|
||||
assert_select '[value=?]', 'Update'
|
||||
|
@ -27,26 +27,26 @@ class UsersControllerTest < ActionController::TestCase
|
|||
test 'should update user if password is correct' do
|
||||
sign_in @user
|
||||
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
|
||||
assert_equal 'New Name', @user.name
|
||||
assert_response :redirect
|
||||
assert_redirected_to :controller => 'sidebar', :action => 'search'
|
||||
assert_redirected_to controller: 'sidebar', action: 'search'
|
||||
end
|
||||
|
||||
test 'should return error if password is incorrect' do
|
||||
sign_in @user
|
||||
put :update, :user => {:name => 'New Name', :current_password => 'incorrect'}
|
||||
put :update, user: {name: 'New Name', current_password: 'incorrect'}
|
||||
assert_response :error
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue