Permalink
Browse files

Finish refactoring out hydrants

[Delivers #18318099]
  • Loading branch information...
sferik committed Sep 15, 2011
1 parent 688b408 commit d313d707b2d619efae9c5a727b335cda689832c7
Showing with 13,448 additions and 13,454 deletions.
  1. +1 −1 Rakefile
  2. +38 −38 app/assets/javascripts/main.js.erb
  3. +0 −21 app/controllers/hydrants_controller.rb
  4. +4 −4 app/controllers/info_window_controller.rb
  5. +1 −1 app/controllers/reminders_controller.rb
  6. +21 −0 app/controllers/things_controller.rb
  7. +1 −1 app/controllers/users_controller.rb
  8. +0 −13 app/mailers/hydrant_mailer.rb
  9. +13 −0 app/mailers/thing_mailer.rb
  10. +2 −2 app/models/reminder.rb
  11. +3 −3 app/models/{hydrant.rb → thing.rb}
  12. +1 −1 app/models/user.rb
  13. +0 −7 app/views/hydrant_mailer/reminder_email.text.erb
  14. +1 −1 app/views/info_window/tos.html.haml
  15. +7 −0 app/views/thing_mailer/reminder_email.text.erb
  16. +1 −1 app/views/{hydrants → things}/_abandon.html.haml
  17. 0 app/views/{hydrants → things}/_back.html.haml
  18. +1 −1 app/views/{hydrants → things}/_steal.html.haml
  19. +1 −1 app/views/{hydrants → things}/adopt.html.haml
  20. +2 −2 app/views/users/_reminder.html.haml
  21. +1 −1 app/views/users/edit.html.haml
  22. +4 −4 app/views/users/profile.html.haml
  23. +1 −1 app/views/users/thank_you.html.haml
  24. +1 −1 config.ru
  25. +1 −1 config/application.rb
  26. +5 −12 config/database.yml
  27. +1 −1 config/environment.rb
  28. +1 −1 config/environments/development.rb
  29. +2 −2 config/environments/production.rb
  30. +1 −1 config/environments/test.rb
  31. +1 −1 config/initializers/secret_token.rb
  32. +2 −2 config/initializers/session_store.rb
  33. +2 −2 config/routes.rb
  34. +3 −3 db/migrate/{00000000000002_create_hydrants.rb → 00000000000002_create_things.rb}
  35. +2 −2 db/migrate/00000000000003_create_reminders.rb
  36. +15 −14 db/schema.rb
  37. +13,254 −13,254 db/seeds.rb
  38. +1 −1 test/fixtures/reminders.yml
  39. +10 −10 test/fixtures/{hydrants.yml → things.yml}
  40. +0 −23 test/functional/hydrants_controller_test.rb
  41. +15 −15 test/functional/info_window_controller_test.rb
  42. +4 −4 test/functional/reminders_controller_test.rb
  43. +23 −0 test/functional/things_controller_test.rb
View
@@ -4,4 +4,4 @@
require File.expand_path('../config/application', __FILE__)
-AdoptAHydrant::Application.load_tasks
+AdoptAThing::Application.load_tasks
@@ -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!"
}
@@ -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
@@ -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
@@ -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
@@ -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
@@ -7,7 +7,7 @@ def update
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)
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Oops, something went wrong.

0 comments on commit d313d70

Please sign in to comment.