]> git.openstreetmap.org Git - rails.git/commitdiff
Convert class method tests to use User factory.
authorAndy Allan <git@gravitystorm.co.uk>
Thu, 2 Feb 2017 13:05:37 +0000 (13:05 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Thu, 2 Feb 2017 13:05:43 +0000 (13:05 +0000)
Also improve the tests by being explicit about which results should
be returned, rather than just hoping that the fixtures cover all
possibilities.

test/models/user_test.rb

index 356f469c0c7314a25a2056c4fc397fe908ca28e6..90499e1b1f8167aa9f50fe2b4bdcbfef6272e2ad 100644 (file)
@@ -161,32 +161,50 @@ class UserTest < ActiveSupport::TestCase
   end
 
   def test_visible
-    assert_equal 23, User.visible.count
+    pending = create(:user, :pending)
+    active = create(:user, :active)
+    confirmed = create(:user, :confirmed)
+    suspended = create(:user, :suspended)
+    deleted = create(:user, :deleted)
+
+    assert User.visible.find(pending.id)
+    assert User.visible.find(active.id)
+    assert User.visible.find(confirmed.id)
     assert_raise ActiveRecord::RecordNotFound do
-      User.visible.find(users(:suspended_user).id)
+      User.visible.find(suspended.id)
     end
     assert_raise ActiveRecord::RecordNotFound do
-      User.visible.find(users(:deleted_user).id)
+      User.visible.find(deleted.id)
     end
   end
 
   def test_active
-    assert_equal 22, User.active.count
+    pending = create(:user, :pending)
+    active = create(:user, :active)
+    confirmed = create(:user, :confirmed)
+    suspended = create(:user, :suspended)
+    deleted = create(:user, :deleted)
+
+    assert User.active.find(active.id)
+    assert User.active.find(confirmed.id)
     assert_raise ActiveRecord::RecordNotFound do
-      User.active.find(users(:inactive_user).id)
+      User.active.find(pending.id)
     end
     assert_raise ActiveRecord::RecordNotFound do
-      User.active.find(users(:suspended_user).id)
+      User.active.find(suspended.id)
     end
     assert_raise ActiveRecord::RecordNotFound do
-      User.active.find(users(:deleted_user).id)
+      User.active.find(deleted.id)
     end
   end
 
   def test_identifiable
-    assert_equal 24, User.identifiable.count
+    public_user = create(:user, :data_public => true)
+    private_user = create(:user, :data_public => false)
+
+    assert User.identifiable.find(public_user.id)
     assert_raise ActiveRecord::RecordNotFound do
-      User.identifiable.find(users(:normal_user).id)
+      User.identifiable.find(private_user.id)
     end
   end