Skip to content
This repository
Browse code

test is passing

  • Loading branch information...
commit 6a07be337b147990e526224aed61b1a6143bb87f 1 parent bb48929
Neeraj Singh authored
26  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
16 16
     end
17 17
     assert_equal 8, User.count
18 18
     assert_equal 3, PhoneNumber.count
  19
+
  20
+    main_klass = User
  21
+    hm_klass = PhoneNumber
  22
+    hm_relationship = :phone_numbers
  23
+    require 'ruby-debug'; debugger
  24
+    foreign_key = main_klass.reflections[hm_relationship].instance_variable_get('@active_record').name.foreign_key
  25
+
  26
+    sql  = %Q{
  27
+      
  28
+      select count(*) 
  29
+      from #{main_klass.table_name}
  30
+      where users.id NOT IN (
  31
+        select #{hm_klass.table_name}.#{foreign_key}
  32
+        from #{hm_klass.table_name}
  33
+      )
  34
+    
  35
+    }
  36
+
  37
+    u = User.find_by_sql(sql).first
  38
+    puts u
  39
+
  40
+    u2 = u['count(*)']
  41
+    puts u2
  42
+
  43
+
  44
+    assert_equal 5, u2
19 45
   end
20 46
 end
21 47
 

0 notes on commit 6a07be3

Please sign in to comment.
Something went wrong with that request. Please try again.