Permalink
Browse files

making test pass

  • Loading branch information...
1 parent 6a07be3 commit d1f266e47b5b86aebb907ba5454b6f10b6f1d93b Neeraj Singh committed Jun 30, 2011
Showing with 17 additions and 20 deletions.
  1. +17 −20 test/rails_root/test/unit/user_phone_test.rb
View
37 test/rails_root/test/unit/user_phone_test.rb
@@ -8,20 +8,8 @@ def setup
PhoneNumber.delete_all
end
- def test_pie_chart_for_user_with_phones_vs_users_without_phones
- 5.times { Factory(:user) }
- 3.times do
- user = Factory(:user)
- Factory(:phone_number, :user => user)
- 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
+ def count_of_main_klass_records_not_in_hm_klass(main_klass, hm_klass, hm_relationship_name)
+ foreign_key = main_klass.reflections[hm_relationship_name].instance_variable_get('@active_record').name.foreign_key
sql = %Q{
@@ -33,15 +21,24 @@ def test_pie_chart_for_user_with_phones_vs_users_without_phones
)
}
+ record = main_klass.find_by_sql(sql).first
+ record['count(*)']
+ end
- u = User.find_by_sql(sql).first
- puts u
-
- u2 = u['count(*)']
- puts u2
+ def test_pie_chart_for_user_with_phones_vs_users_without_phones
+ 5.times { Factory(:user) }
+ 3.times do
+ user = Factory(:user)
+ Factory(:phone_number, :user => user)
+ end
+ assert_equal 8, User.count
+ assert_equal 3, PhoneNumber.count
+ main_klass = User
+ hm_klass = PhoneNumber
+ hm_relationship = :phone_numbers
- assert_equal 5, u2
+ assert_equal 5, count_of_main_klass_records_not_in_hm_klass(User, PhoneNumber, :phone_numbers)
end
end

0 comments on commit d1f266e

Please sign in to comment.