Permalink
Browse files

test is passing

  • Loading branch information...
1 parent bb48929 commit 6a07be337b147990e526224aed61b1a6143bb87f Neeraj Singh committed Jun 30, 2011
Showing with 26 additions and 0 deletions.
  1. +26 −0 test/rails_root/test/unit/user_phone_test.rb
@@ -16,6 +16,32 @@ def test_pie_chart_for_user_with_phones_vs_users_without_phones
end
assert_equal 8, User.count
assert_equal 3, PhoneNumber.count
+
+ main_klass = User
+ hm_klass = PhoneNumber
+ hm_relationship = :phone_numbers
+ require 'ruby-debug'; debugger
+ foreign_key = main_klass.reflections[hm_relationship].instance_variable_get('@active_record').name.foreign_key
+
+ sql = %Q{
+
+ select count(*)
+ from #{main_klass.table_name}
+ where users.id NOT IN (
+ select #{hm_klass.table_name}.#{foreign_key}
+ from #{hm_klass.table_name}
+ )
+
+ }
+
+ u = User.find_by_sql(sql).first
+ puts u
+
+ u2 = u['count(*)']
+ puts u2
+
+
+ assert_equal 5, u2
end
end

0 comments on commit 6a07be3

Please sign in to comment.