Add with_home_location trait for user factories.
authorAndy Allan <git@gravitystorm.co.uk>
Thu, 2 Feb 2017 12:08:36 +0000 (12:08 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Thu, 2 Feb 2017 12:08:36 +0000 (12:08 +0000)
test/factories/user.rb
test/models/user_test.rb

index ccbb84f93c5f4245a27014c0e21c24f9672fce30..79b9a2a1664b84941293500ab5e10b8672132f23 100644 (file)
@@ -3,5 +3,10 @@ FactoryGirl.define do
     sequence(:email) { |n| "user#{n}@example.com" }
     sequence(:display_name) { |n| "User #{n}" }
     pass_crypt Digest::MD5.hexdigest("test")
+
+    trait :with_home_location do
+      home_lat { rand(-90.0...90.0) }
+      home_lon { rand(-180.0...180.0) }
+    end
   end
 end
index 6ecc8c7960b5ef5df660b46bd9268ced8b5e653f..5eacd98b9ca5143b33bdeb6365951ff2152356e2 100644 (file)
@@ -240,7 +240,7 @@ class UserTest < ActiveSupport::TestCase
   end
 
   def test_delete
-    user = users(:normal_user)
+    user = create(:user, :with_home_location, :description => "foo")
     user.delete
     assert_equal "user_#{user.id}", user.display_name
     assert user.description.blank?
@@ -253,7 +253,7 @@ class UserTest < ActiveSupport::TestCase
   end
 
   def test_to_xml
-    user = users(:normal_user)
+    user = build(:user, :with_home_location)
     xml = user.to_xml
     assert_select Nokogiri::XML::Document.parse(xml.to_s), "user" do
       assert_select "[display_name=?]", user.display_name
@@ -263,7 +263,7 @@ class UserTest < ActiveSupport::TestCase
   end
 
   def test_to_xml_node
-    user = users(:normal_user)
+    user = build(:user, :with_home_location)
     xml = user.to_xml_node
     assert_select Nokogiri::XML::DocumentFragment.parse(xml.to_s), "user" do
       assert_select "[display_name=?]", user.display_name