Permalink
Browse files

Fixed User to geocode on update

  • Loading branch information...
1 parent d14de05 commit 88941b1e8d11a027eed329c51808e15ec90f74b8 @jferris committed Oct 19, 2008
Showing with 19 additions and 1 deletion.
  1. +2 −0 app/models/user.rb
  2. +17 −1 test/unit/user_test.rb
View
@@ -12,6 +12,8 @@ class User < ActiveRecord::Base
has_many :purchases
+ before_validation_on_update :auto_geocode_address
+
def self.find_or_create_by_openid(openid_identity, registration, user)
User.find_by_openid_identity(openid_identity) ||
User.new(:openid_identity => openid_identity,
View
@@ -16,6 +16,11 @@ class UserTest < Test::Unit::TestCase
assert_equal "Joe", @user.first_name
end
+ should "geocode when saving with a new location" do
+ @user.expects(:auto_geocode_address)
+ @user.update_attributes!(:location => '100 Commonwealth Ave, Boston, MA')
+ end
+
context "with some Purchases" do
setup do
[:month,:week,:day,:hour].each do |time_ago|
@@ -138,7 +143,18 @@ class UserTest < Test::Unit::TestCase
@user = Factory(:user, :openid_identity => nil, :email => 'foo@example.com')
end
- should_require_attributes :email, :location, :latitude, :longitude
+ should_require_attributes :email, :location
+
+ [:latitude, :longitude].each do |field|
+ should "require #{field}" do
+ assert_valid @user
+
+ @user.send(:"#{field}=", nil)
+ @user.location = nil
+
+ assert !@user.valid?
+ end
+ end
end
context "an OpenID and location" do

0 comments on commit 88941b1

Please sign in to comment.