Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
require 'spec_helper'
describe "ActiveRecord" do
describe "association" do
it "should point to the same object" do
user = create(:user)
user.current_location.should == nil
user.update_location(latitude: 11, longitude: 22)
user.current_location.should_not == nil
location = UserLocation.first
location.id.should == user.current_location.id
location.object_id.should == user.current_location.object_id #fails on this line
end
end
end
class User < ActiveRecord::Base
has_many :locations, :class_name => 'UserLocation', :order => 'created_at DESC'
has_one :current_location, :class_name => 'UserLocation', :conditions => {:is_active => true}
has_many :past_locations, :class_name => 'UserLocation', :conditions => {:is_active => false}, :order => 'created_at DESC'
def clear_location
unless current_location.nil?
current_location.is_active = false
current_location.save
reload
end
end
def self.clear_all_locations
UserLocation.where(:is_active => true).each do |user_location|
user_location.user.clear_location
end
end
end
class UserLocation < ActiveRecord::Base
geocoded_by nil
belongs_to :user
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.