Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6224749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:43:26+00:00 2026-05-24T08:43:26+00:00

I can’t get my any test to run because every user I try to

  • 0

I can’t get my any test to run because every user I try to fabricate generates validation errors.

I have the following test.

class BillTest < ActiveSupport::TestCase

  def setup
    load_all_sponsors
    @the_bill = Bill.new(:govtrack_name => "h1")
    @user1 = Fabricate(:user1)
    @user2 = Fabricate(:user2)

My fabrications are defined by:

Fabricator(:user) do
   email      'another_user_here@domain.com'
   name       'anew user'
   roles_mask 1
   password   "secret"
   password_confirmation "secret"
   polco_groups {[Fabricate(:polco_group, :name => 'foreign', :type => :custom)]}
end

Fabricator(:admin, :class_name => :user) do
  email 'admin@yourdomain.com'
  name  'Administrator'
  roles_mask  5
  password   "secret"
  password_confirmation "secret"
end

Fabricator(:registered, :class_name => :user) do
   email      'registered_user@domain.com'
   name       'Tim TheRegistered'
   roles_mask 2
   password   "the_secret"
   password_confirmation "the_secret"
   polco_groups {[Fabricate(:polco_group, {:name => 'AL', :type => :state}),
              Fabricate(:polco_group, {:name => 'AL01', :type => :district}),
              Fabricate(:polco_group, {:name => "Kirk\'s Kids" , :type => :custom})]}
end

Fabricator(:user1, :class_name => :user) do
   email      'user1@domain.com'
   name       'User1'
   roles_mask 2
   password   "the_big_secret"
   password_confirmation "the_big_secret"
   polco_groups {[Fabricate(:polco_group, {:name => 'AL', :type => :state}),
              Fabricate(:polco_group, {:name => 'AL01', :type => :district}),
              Fabricate(:polco_group, {:name => "Kirk\'s Kids" , :type => :custom})]}
end

Fabricator(:user2, :class_name => :user) do
   email      'user2@domain.com'
   name       'User2'
   roles_mask 2
   password   "the_big_secret"
   password_confirmation "the_big_secret"
   polco_groups {[Fabricate(:polco_group, {:name => 'AL', :type => :state}),
              Fabricate(:polco_group, {:name => 'FL01', :type => :district}),
              Fabricate(:polco_group, {:name => "Ft. Sam Washington 1st Grade" , :type => :custom})]}
end

No matter which test runs, I get the same error

  9) Error:
test_update_from_directory(BillTest):
Mongoid::Errors::Validations: Validation failed - Email is already taken, Email is already taken, Name is already taken.
    test/unit/bill_test.rb:8:in `setup'

I have tried a number of different fabricators, inheriting in all kinds of different ways and nothing gets past this error. I’m pretty desperate for help on this one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:43:27+00:00Added an answer on May 24, 2026 at 8:43 am

    You should be user the “ffaker” gem to generate email addresses and the like in your specs. Also, you should be inheriting fields form previously defined fabricators, as illustrated below.

    Fabricator(:user) do
     email      { Faker::Internet.email }
     name       { Faker::Name.name }
     roles_mask 1
     password   "secret"
     password_confirmation "secret"
     polco_groups {[Fabricate(:polco_group, :name => 'foreign', :type => :custom)]}
    end
    
    Fabricator(:admin, :from => :user) do
      roles_mask  5
    end
    
    Fabricator(:registered, :from => :user) do
      roles_mask 2
      polco_groups {[Fabricate(:polco_group, :name => 'AL', :type => :state),
              Fabricate(:polco_group, :name => 'AL01', :type => :district),
              Fabricate(:polco_group, :name => "Kirk\'s Kids" , :type => :custom)]}
    end
    
    Fabricator(:user1, :from => :registered)
    
    Fabricator(:user2, :from => :registered) do
      polco_groups {[Fabricate(:polco_group, {:name => 'AL', :type => :state}),
              Fabricate(:polco_group, {:name => 'FL01', :type => :district}),
              Fabricate(:polco_group, {:name => "Ft. Sam Washington 1st Grade" , :type => :custom})]}
    end
    

    It is unrelated to your issue, but it looks like user1 and user2 should just be calls to Fabricate and not actually defined as Fabricators. I don’t recommend putting that much explicit information in the Fabricator. You should only be defining was is necessary to generate a valid object. Any specific data should be in the service of a particular spec.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can i get the source code for a WAMP stack installer somewhere? Any help
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can a LINQ enabled app run on a machine that only has the .NET
Can I get a 'when to use' for these and others? <% %> <%#
I have a jquery bug and I've been looking for hours now, I can't
Can I run this in a Windows command prompt like I can run it
Can't figure out how to do this in a pretty way : I have
Can you have submenus with the top level set to checkable in WPF? I
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Can someone explain the usage of the dollar sign here.. var updateProgressDiv = $get('updateProgressDiv');

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.