Finish refactoring out hydrants

[Delivers #18318099]
This commit is contained in:
Erik Michaels-Ober 2011-09-15 14:41:26 -07:00
parent 688b408308
commit d313d707b2
43 changed files with 13448 additions and 13454 deletions

View File

@ -4,4 +4,4 @@
require File.expand_path('../config/application', __FILE__)
AdoptAHydrant::Application.load_tasks
AdoptAThing::Application.load_tasks

View File

@ -9,12 +9,12 @@ $(function() {
zoom: zoomLevel
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var activeHydrantId;
var activeThingId;
var activeMarker;
var activeInfoWindow;
var isWindowOpen = false;
var hydrantIds = [];
function addMarker(hydrantId, point, image_path) {
var thingIds = [];
function addMarker(thingId, point, image_path) {
var image = new google.maps.MarkerImage(image_path,
new google.maps.Size(27.0, 37.0),
new google.maps.Point(0, 0),
@ -43,13 +43,13 @@ $(function() {
isWindowOpen = false;
});
activeInfoWindow = infoWindow;
activeHydrantId = hydrantId;
activeThingId = thingId;
activeMarker = marker;
$.ajax({
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': hydrantId
'thing_id': thingId
},
success: function(data) {
// Prevent race condition, which could lead to multiple windows being open at the same time.
@ -61,12 +61,12 @@ $(function() {
}
});
});
hydrantIds.push(hydrantId);
thingIds.push(thingId);
}
function addMarkersAround(lat, lng) {
$.ajax({
type: 'GET',
url: '/hydrants.json',
url: '/things.json',
data: {
'commit': $('#address_form input[type="submit"]').val(),
'utf8': '✓',
@ -84,21 +84,21 @@ $(function() {
$('#address_label').removeClass('error', 500);
$('#address').removeClass('error', 500);
var i = -1;
$(data).each(function(index, hydrant) {
if($.inArray(hydrant.id, hydrantIds) == -1) {
$(data).each(function(index, thing) {
if($.inArray(thing.id, thingIds) == -1) {
i += 1;
} else {
// continue
return true;
}
setTimeout(function() {
point = new google.maps.LatLng(hydrant.lat, hydrant.lng);
if(hydrant.user_id) {
point = new google.maps.LatLng(thing.lat, thing.lng);
if(thing.user_id) {
image_path = '<%= image_path 'markers/green.png' %>';
} else {
image_path = '<%= image_path 'markers/red.png' %>';
}
addMarker(hydrant.id, point, image_path);
addMarker(thing.id, point, image_path);
}, i * 100);
});
center = new google.maps.LatLng(lat, lng);
@ -273,7 +273,7 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId,
'thing_id': activeThingId,
'flash': {
'notice': "Thanks for signing up!"
}
@ -328,7 +328,7 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId,
'thing_id': activeThingId,
'flash': {
'notice': "Signed in!"
}
@ -396,16 +396,16 @@ $(function() {
$(submitButton).attr("disabled", true);
$.ajax({
type: 'POST',
url: '/hydrants.json',
url: '/things.json',
data: {
'id': $('#hydrant_id').val(),
'id': $('#thing_id').val(),
'commit': submitButton.val(),
'utf8': '✓',
'authenticity_token': $('#adoption_form input[name="authenticity_token"]').val(),
'_method': 'put',
'hydrant': {
'user_id': $('#hydrant_user_id').val(),
'name': $('#hydrant_name').val()
'thing': {
'user_id': $('#thing_user_id').val(),
'name': $('#thing_name').val()
}
},
beforeSend: function() {
@ -422,9 +422,9 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId,
'thing_id': activeThingId,
'flash': {
'notice': "You just adopted " + $('#hydrant_name').val() + "!"
'notice': "You just adopted " + $('#thing_name').val() + "!"
}
},
success: function(data) {
@ -450,16 +450,16 @@ $(function() {
$(submitButton).attr("disabled", true);
$.ajax({
type: 'POST',
url: '/hydrants.json',
url: '/things.json',
data: {
'id': $('#hydrant_id').val(),
'id': $('#thing_id').val(),
'commit': submitButton.val(),
'utf8': '✓',
'authenticity_token': $('#abandon_form input[name="authenticity_token"]').val(),
'_method': 'put',
'hydrant': {
'user_id': $('#hydrant_user_id').val(),
'name': $('#hydrant_name').val()
'thing': {
'user_id': $('#thing_user_id').val(),
'name': $('#thing_name').val()
}
},
beforeSend: function() {
@ -476,7 +476,7 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId,
'thing_id': activeThingId,
'flash': {
'notice': "Hydrant abandoned!"
}
@ -504,16 +504,16 @@ $(function() {
$(submitButton).attr("disabled", true);
$.ajax({
type: 'POST',
url: '/hydrants.json',
url: '/things.json',
data: {
'id': $('#hydrant_id').val(),
'id': $('#thing_id').val(),
'commit': submitButton.val(),
'utf8': '✓',
'authenticity_token': $('#steal_form input[name="authenticity_token"]').val(),
'_method': 'put',
'hydrant': {
'user_id': $('#hydrant_user_id').val(),
'name': $('#hydrant_name').val()
'thing': {
'user_id': $('#thing_user_id').val(),
'name': $('#thing_name').val()
}
},
beforeSend: function() {
@ -530,7 +530,7 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId,
'thing_id': activeThingId,
'flash': {
'notice': "Hydrant stolen!"
}
@ -622,7 +622,7 @@ $(function() {
url: '/users.json',
data: {
'id': $('#id').val(),
'hydrant_id': activeHydrantId,
'thing_id': activeThingId,
'commit': submitButton.val(),
'utf8': '✓',
'authenticity_token': $('#edit_form input[name="authenticity_token"]').val(),
@ -716,7 +716,7 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId,
'thing_id': activeThingId,
'flash': {
'notice': "Signed out."
}
@ -765,7 +765,7 @@ $(function() {
'commit': submitButton.val(),
'utf8': '✓',
'authenticity_token': $('#back_form input[name="authenticity_token"]').val(),
'hydrant_id': activeHydrantId
'thing_id': activeThingId
},
beforeSend: function() {
$('#info_window').hide();
@ -795,7 +795,7 @@ $(function() {
'reminder': {
'from_user_id': $('#reminder_from_user_id').val(),
'to_user_id': $('#reminder_to_user_id').val(),
'hydrant_id': activeHydrantId
'thing_id': activeThingId
}
},
beforeSend: function() {
@ -812,7 +812,7 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId,
'thing_id': activeThingId,
'flash': {
'notice': "Reminder sent!"
}

View File

@ -1,21 +0,0 @@
class HydrantsController < ApplicationController
respond_to :json
def show
@hydrants = Hydrant.find_closest(params[:lat], params[:lng], params[:limit] || 20)
unless @hydrants.blank?
respond_with @hydrants
else
render(:json => {"errors" => {"address" => [t("errors.not_found", :thing => t("defaults.thing"))]}}, :status => 404)
end
end
def update
@hydrant = Hydrant.find(params[:id])
if @hydrant.update_attributes(params[:hydrant])
respond_with @hydrant
else
render(:json => {"errors" => @hydrant.errors}, :status => 500)
end
end
end

View File

@ -1,15 +1,15 @@
class InfoWindowController < ApplicationController
def index
@hydrant = Hydrant.find_by_id(params[:hydrant_id])
if @hydrant.adopted?
if user_signed_in? && current_user.id == @hydrant.user_id
@thing = Thing.find_by_id(params[:thing_id])
if @thing.adopted?
if user_signed_in? && current_user.id == @thing.user_id
render("users/thank_you")
else
render("users/profile")
end
else
if user_signed_in?
render("hydrants/adopt")
render("things/adopt")
else
render("sessions/new")
end

View File

@ -4,7 +4,7 @@ class RemindersController < ApplicationController
def create
@reminder = Reminder.new(params[:reminder])
if @reminder.save
HydrantMailer.reminder_email(@reminder.hydrant).deliver
ThingMailer.reminder_email(@reminder.thing).deliver
@reminder.update_attribute(:sent, true)
render(:json => @reminder)
else

View File

@ -0,0 +1,21 @@
class ThingsController < ApplicationController
respond_to :json
def show
@things = Thing.find_closest(params[:lat], params[:lng], params[:limit] || 20)
unless @things.blank?
respond_with @things
else
render(:json => {"errors" => {"address" => [t("errors.not_found", :thing => t("defaults.thing"))]}}, :status => 404)
end
end
def update
@thing = Thing.find(params[:id])
if @thing.update_attributes(params[:thing])
respond_with @thing
else
render(:json => {"errors" => @thing.errors}, :status => 500)
end
end
end

View File

@ -7,7 +7,7 @@ class UsersController < Devise::RegistrationsController
if resource.update_with_password(params[resource_name])
sign_in(resource_name, resource, :bypass => true)
flash[:notice] = "Profile updated!"
redirect_to(:controller => "info_window", :action => "index", :hydrant_id => params[:hydrant_id])
redirect_to(:controller => "info_window", :action => "index", :thing_id => params[:thing_id])
else
clean_up_passwords(resource)
render(:json => {"errors" => resource.errors}, :status => 500)

View File

@ -1,13 +0,0 @@
class HydrantMailer < ActionMailer::Base
default :from => "hello@#{default_url_options[:host]}"
def reminder_email(hydrant)
@hydrant = hydrant
@user = hydrant.user
mail({
:to => hydrant.user.email,
:from => "reminder@#{default_url_options[:host]}",
:subject => ["Remember to Shovel", hydrant.name].compact.join(' '),
})
end
end

View File

@ -0,0 +1,13 @@
class ThingMailer < ActionMailer::Base
default :from => "hello@#{default_url_options[:host]}"
def reminder_email(thing)
@thing = thing
@user = thing.user
mail({
:to => thing.user.email,
:from => "reminder@#{default_url_options[:host]}",
:subject => ["Remember to Shovel", thing.name].compact.join(' '),
})
end
end

View File

@ -1,6 +1,6 @@
class Reminder < ActiveRecord::Base
validates_presence_of :from_user, :to_user, :hydrant
validates_presence_of :from_user, :to_user, :thing
belongs_to :from_user, :class_name => "User"
belongs_to :to_user, :class_name => "User"
belongs_to :hydrant
belongs_to :thing
end

View File

@ -1,4 +1,4 @@
class Hydrant < ActiveRecord::Base
class Thing < ActiveRecord::Base
include Geokit::Geocoders
validates_presence_of :lat, :lng
belongs_to :user
@ -7,11 +7,11 @@ class Hydrant < ActiveRecord::Base
def self.find_closest(lat, lng, limit=20)
query = <<-SQL
SELECT *, (3959 * ACOS(COS(RADIANS(?)) * COS(RADIANS(lat)) * COS(radians(lng) - RADIANS(?)) + SIN(RADIANS(?)) * SIN(RADIANS(lat)))) AS distance
FROM hydrants
FROM things
ORDER BY distance
LIMIT ?
SQL
Hydrant.find_by_sql([query, lat.to_f, lng.to_f, lat.to_f, limit.to_i])
find_by_sql([query, lat.to_f, lng.to_f, lat.to_f, limit.to_i])
end
def reverse_geocode

View File

@ -2,7 +2,7 @@ class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :name, :organization, :voice_number, :sms_number, :password, :password_confirmation, :remember_me
validates_presence_of :name
has_many :hydrants
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
end

View File

@ -1,7 +0,0 @@
Hello <%= @hydrant.user.name.split.first %>,
Did you remember to shovel <%= ['out', @hydrant.name, 'the'].compact.join(' ') %> fire hydrant you adopted at <%= @hydrant.street_address %>? If not, please shovel your hydrant as soon as possible!
If you've already shoveled, thank you for serving your city!
Boston Fire Department

View File

@ -242,4 +242,4 @@
%p
Last updated August 10, 2011.
= render :partial => 'hydrants/back'
= render :partial => 'things/back'

View File

@ -0,0 +1,7 @@
Hello <%= @thing.user.name.split.first %>,
Did you remember to shovel <%= ['out', @thing.name, 'the'].compact.join(' ') %> fire hydrant you adopted at <%= @thing.street_address %>? If not, please shovel your hydrant as soon as possible!
If you've already shoveled, thank you for serving your city!
Boston Fire Department

View File

@ -1,4 +1,4 @@
= form_for :hydrant, :url => hydrants_path, :method => :put, :html => {:id => "abandon_form"} do |f|
= form_for :hydrant, :url => things_path, :method => :put, :html => {:id => "abandon_form"} do |f|
= f.hidden_field "id"
= f.hidden_field "user_id", :value => ""
= f.hidden_field "name", :value => ""

View File

@ -1,4 +1,4 @@
= form_for :hydrant, :url => hydrants_path, :method => :put, :html => {:id => "steal_form"} do |f|
= form_for :hydrant, :url => things_path, :method => :put, :html => {:id => "steal_form"} do |f|
= f.hidden_field "id"
= f.hidden_field "user_id", :value => ""
= f.hidden_field "name", :value => ""

View File

@ -1,4 +1,4 @@
= form_for :hydrant, :url => hydrants_path, :method => :put, :html => {:id => "adoption_form"} do |f|
= form_for :hydrant, :url => things_path, :method => :put, :html => {:id => "adoption_form"} do |f|
%h2
= t("titles.adopt", :thing => t("defaults.thing").titleize)
= f.hidden_field "id"

View File

@ -1,5 +1,5 @@
= form_for :reminder, :url => reminders_path, :html => {:id => "reminder_form", :method => "post"} do |f|
= f.hidden_field "from_user_id", :value => current_user.id
= f.hidden_field "to_user_id", :value => @hydrant.user.id
= f.hidden_field "hydrant_id", :value => @hydrant.id
= f.hidden_field "to_user_id", :value => @thing.user.id
= f.hidden_field "thing_id", :value => @thing.id
= f.submit t("buttons.send_reminder")

View File

@ -31,4 +31,4 @@
= t("captions.current_password")
= f.password_field "current_password", :tabindex => 7
= f.submit t("buttons.update"), :tabindex => 8
= render :partial => 'hydrants/back'
= render :partial => 'things/back'

View File

@ -1,12 +1,12 @@
%h2
= t("titles.adopted", :thing_name => @hydrant.name ? @hydrant.name.titleize : t("defaults.this_thing", :thing => t("defaults.thing")))
= t("titles.adopted", :thing_name => @thing.name ? @thing.name.titleize : t("defaults.this_thing", :thing => t("defaults.thing")))
%br
= t("titles.byline", :name => @hydrant.user.name)
= t("titles.byline", :name => @thing.user.name)
%br
= t("titles.ofline", :organization => @hydrant.user.organization) unless @hydrant.user.organization.blank?
= t("titles.ofline", :organization => @thing.user.organization) unless @thing.user.organization.blank?
- if user_signed_in?
= render :partial => 'users/reminder'
= render :partial => 'hydrants/steal'
= render :partial => 'things/steal'
= render :partial => 'users/edit_profile'
= render :partial => 'sessions/sign_out'
- else

View File

@ -1,5 +1,5 @@
%h2
= t("titles.thank_you", :thing => t("defaults.thing"))
= render :partial => 'hydrants/abandon'
= render :partial => 'things/abandon'
= render :partial => 'users/edit_profile'
= render :partial => 'sessions/sign_out'

View File

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

View File

@ -9,7 +9,7 @@ if defined?(Bundler)
Bundler.require(:default, :assets, Rails.env)
end
module AdoptAHydrant
module AdoptAThing
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers

View File

@ -1,20 +1,13 @@
development:
development: &DEVELOPMENT
adapter: postgresql
database: adopt_a_hydrant_development
database: adopt_a_thing_production
username: postgres
password:
database: adopt_a_thing_development
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
<<: *DEVELOPMENT
database: adopt_a_thing_test

View File

@ -2,4 +2,4 @@
require File.expand_path('../application', __FILE__)
# Initialize the rails application
AdoptAHydrant::Application.initialize!
AdoptAThing::Application.initialize!

View File

@ -1,4 +1,4 @@
AdoptAHydrant::Application.configure do
AdoptAThing::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on

View File

@ -1,4 +1,4 @@
AdoptAHydrant::Application.configure do
AdoptAThing::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
@ -48,7 +48,7 @@ AdoptAHydrant::Application.configure do
# Disable delivery errors, bad email addresses will be ignored
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 => 'AdoptAThing.org'}
# Enable threaded mode
# config.threadsafe!

View File

@ -1,4 +1,4 @@
AdoptAHydrant::Application.configure do
AdoptAThing::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# The test environment is used exclusively to run your application's

View File

@ -4,4 +4,4 @@
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
AdoptAHydrant::Application.config.secret_token = '4dc0354d5050c89c7f151a0bae3d2a7506a7ca66435ae9e0eb6754cb4be808089c7726c65dc8ae9b49870507fbe0de1fa36fa703491078b2c7122897892d6f69'
AdoptAThing::Application.config.secret_token = '4dc0354d5050c89c7f151a0bae3d2a7506a7ca66435ae9e0eb6754cb4be808089c7726c65dc8ae9b49870507fbe0de1fa36fa703491078b2c7122897892d6f69'

View File

@ -1,8 +1,8 @@
# Be sure to restart your server when you modify this file.
AdoptAHydrant::Application.config.session_store :cookie_store, :key => '_adopt-a-hydrant_session'
AdoptAThing::Application.config.session_store :cookie_store, :key => '_adopt-a-hydrant_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
# AdoptAHydrant::Application.config.session_store :active_record_store
# AdoptAThing::Application.config.session_store :active_record_store

View File

@ -1,4 +1,4 @@
AdoptAHydrant::Application.routes.draw do
AdoptAThing::Application.routes.draw do
devise_for :users, :controllers => {
:passwords => 'passwords',
:registrations => 'users',
@ -8,8 +8,8 @@ AdoptAHydrant::Application.routes.draw do
get 'info_window' => 'info_window#index', :as => 'info_window'
get 'sitemap' => 'sitemaps#index', :as => 'sitemap'
get 'tos' => 'info_window#tos', :as => 'tos'
resource :hydrants
resource :reminders
resource :things
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
root :to => 'main#index'
end

View File

@ -1,6 +1,6 @@
class CreateHydrants < ActiveRecord::Migration
class CreateThings < ActiveRecord::Migration
def change
create_table :hydrants do |t|
create_table :things do |t|
t.timestamps
t.string :name
t.decimal :lat, :null => false, :precision => 16, :scale => 14
@ -9,6 +9,6 @@ class CreateHydrants < ActiveRecord::Migration
t.integer :user_id
end
add_index :hydrants, :city_id, :unique => true
add_index :things, :city_id, :unique => true
end
end

View File

@ -4,13 +4,13 @@ class CreateReminders < ActiveRecord::Migration
t.timestamps
t.integer :from_user_id, :null => false
t.integer :to_user_id, :null => false
t.integer :hydrant_id, :null => false
t.integer :thing_id, :null => false
t.boolean :sent, :default => false
end
add_index :reminders, :from_user_id
add_index :reminders, :to_user_id
add_index :reminders, :hydrant_id
add_index :reminders, :thing_id
add_index :reminders, :sent
end
end

View File

@ -1,3 +1,4 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
@ -12,18 +13,6 @@
ActiveRecord::Schema.define(:version => 4) do
create_table "hydrants", :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.integer "city_id"
t.integer "user_id"
end
add_index "hydrants", ["city_id"], :name => "index_hydrants_on_city_id", :unique => true
create_table "rails_admin_histories", :force => true do |t|
t.string "message"
t.string "username"
@ -42,15 +31,27 @@ ActiveRecord::Schema.define(:version => 4) do
t.datetime "updated_at"
t.integer "from_user_id", :null => false
t.integer "to_user_id", :null => false
t.integer "hydrant_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", ["hydrant_id"], :name => "index_reminders_on_hydrant_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"
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.integer "city_id"
t.integer "user_id"
end
add_index "things", ["city_id"], :name => "index_things_on_city_id", :unique => true
create_table "users", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"

26508
db/seeds.rb

File diff suppressed because it is too large Load Diff

View File

@ -2,4 +2,4 @@
reminder_1:
from_user: erik
to_user: dan
hydrant: hydrant_1
thing: thing_1

View File

@ -1,50 +1,50 @@
---
hydrant_1:
thing_1:
city_id: 1
lat: 42.383339
lng: -71.049226
hydrant_2:
thing_2:
city_id: 2,
lat: 42.381021
lng: -71.075964
hydrant_3:
thing_3:
city_id: 3
lat: 42.380106
lng: -71.073419
hydrant_4:
thing_4:
city_id: 4
lat: 42.377728
lng: -71.070918
hydrant_5:
thing_5:
city_id: 5
lat: 42.377281
lng: -71.071576
hydrant_6:
thing_6:
city_id: 6
lat: 42.375331
lng: -71.065169
hydrant_7:
thing_7:
city_id: 7
lat: 42.373212
lng: -71.056064
hydrant_8:
thing_8:
city_id: 8
lat: 42.374992
lng: -71.038888
hydrant_9:
thing_9:
city_id: 9
lat: 42.345635
lng: -71.139308
hydrant_10:
thing_10:
city_id: 10
lat: 42.371378
lng: -71.038005

View File

@ -1,23 +0,0 @@
require 'test_helper'
class HydrantsControllerTest < ActionController::TestCase
setup do
@hydrant = hydrants(:hydrant_1)
end
# test 'should list hydrants' do
# skip 'Cannot test query on sqlite3 test database'
# get :show, :format => 'json', :lat => 42.358431, :lng => -71.059773
# assert_not_nil assigns :hydrants
# assert_response :success
# end
test 'should update hydrant' do
assert_not_equal 'Birdsill', @hydrant.name
put :update, :format => 'json', :id => @hydrant.id, :hydrant => {:name => 'Birdsill'}
@hydrant.reload
assert_equal 'Birdsill', @hydrant.name
assert_not_nil assigns :hydrant
assert_response :success
end
end

View File

@ -3,16 +3,16 @@ require 'test_helper'
class InfoWindowControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup do
@hydrant = hydrants(:hydrant_1)
@thing = things(:thing_1)
@user = users(:erik)
end
test 'should thank the user if the user the hydrant is adopted by the user' do
sign_in @user
@hydrant.user_id = @user.id
@hydrant.save!
get :index, :hydrant_id => @hydrant.id
assert_not_nil assigns :hydrant
@thing.user_id = @user.id
@thing.save!
get :index, :thing_id => @thing.id
assert_not_nil assigns :thing
assert_response :success
assert_template 'users/thank_you'
assert_select 'h2', 'Thank you for adopting this hydrant!'
@ -25,7 +25,7 @@ class InfoWindowControllerTest < ActionController::TestCase
assert_select '[value=?]', 'Edit profile'
end
assert_select 'form#abandon_form' do
assert_select '[action=?]', "/hydrants"
assert_select '[action=?]', "/things"
assert_select '[method=?]', 'post'
end
assert_select 'input[name="_method"]' do
@ -47,10 +47,10 @@ class InfoWindowControllerTest < ActionController::TestCase
end
test 'should show the profile if the hydrant is adopted' do
@hydrant.user_id = @user.id
@hydrant.save!
get :index, :hydrant_id => @hydrant.id
assert_not_nil assigns :hydrant
@thing.user_id = @user.id
@thing.save!
get :index, :thing_id => @thing.id
assert_not_nil assigns :thing
assert_response :success
assert_template 'users/profile'
assert_select 'h2', /This hydrant has been adopted\s+by #{@user.name}\s+of #{@user.organization}/
@ -58,13 +58,13 @@ class InfoWindowControllerTest < ActionController::TestCase
test 'should show adoption form if hydrant is not adopted' do
sign_in @user
get :index, :hydrant_id => @hydrant.id
assert_not_nil assigns :hydrant
get :index, :thing_id => @thing.id
assert_not_nil assigns :thing
assert_response :success
assert_template :adopt
assert_select 'h2', 'Adopt this Hydrant'
assert_select 'form#adoption_form' do
assert_select '[action=?]', "/hydrants"
assert_select '[action=?]', "/things"
assert_select '[method=?]', 'post'
end
assert_select 'input[name="_method"]' do
@ -94,8 +94,8 @@ class InfoWindowControllerTest < ActionController::TestCase
end
test 'should show sign-in form if signed out' do
get :index, :hydrant_id => @hydrant.id
assert_not_nil assigns :hydrant
get :index, :thing_id => @thing.id
assert_not_nil assigns :thing
assert_response :success
assert_template 'sessions/new'
assert_select 'form#combo_form' do

View File

@ -2,16 +2,16 @@ require 'test_helper'
class RemindersControllerTest < ActionController::TestCase
setup do
@hydrant = hydrants(:hydrant_1)
@thing = things(:thing_1)
@dan = users(:dan)
@erik = users(:erik)
@hydrant.user = @dan
@hydrant.save!
@thing.user = @dan
@thing.save!
end
test 'should send a reminder email' do
num_deliveries = ActionMailer::Base.deliveries.size
post :create, :format => :json, :reminder => {:hydrant_id => @hydrant.id, :from_user_id => @erik.id, :to_user_id => @dan.id}
post :create, :format => :json, :reminder => {:thing_id => @thing.id, :from_user_id => @erik.id, :to_user_id => @dan.id}
assert_equal num_deliveries + 1, ActionMailer::Base.deliveries.size
assert_response :success
email = ActionMailer::Base.deliveries.last

View File

@ -0,0 +1,23 @@
require 'test_helper'
class ThingsControllerTest < ActionController::TestCase
setup do
@thing = things(:thing_1)
end
# test 'should list hydrants' do
# skip 'Cannot test query on sqlite3 test database'
# 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'}
@thing.reload
assert_equal 'Birdsill', @thing.name
assert_not_nil assigns :thing
assert_response :success
end
end