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 8420193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:49:31+00:00 2026-06-10T02:49:31+00:00

I have the following test: test should get create do sign_in(FactoryGirl.create(:user)) assert_difference(‘Inquery.count’) do post

  • 0

I have the following test:

    test "should get create" do
   sign_in(FactoryGirl.create(:user))
    assert_difference('Inquery.count') do
      post :create, FactoryGirl.build(:inquery)
    end
    assert_not_nil assigns(:inquery)
    assert_response :redirect
  end

and I keep getting:

 2) Error:
test_should_get_create(InqueriesControllerTest):
ActiveRecord::RecordInvalid: Validation failed: Email has already been taken, License number has already been taken

What I don’t understand is why I get this error in this particular test, when I have a very similar test:

 test "should get create" do
    sign_in(FactoryGirl.create(:user, admin: true))
    assert_difference('Event.count') do
      post :create, FactoryGirl.build(:event)
    end
    assert_not_nil assigns(:event)
    assert_response :success
  end

and this does just fine. The obvious difference is the admin: true line, but that has no effect as I suspected.

Added:

User_factory.rb

 factory :user do
   first_name "John"
   last_name "Doe"
   email "example@example.com"
   password "foobar"
   password_confirmation "foobar"
   license_number '12345'
   state 'AZ'
   specialty 'Neurosurgery'
  end
  • 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-06-10T02:49:33+00:00Added an answer on June 10, 2026 at 2:49 am

    Your User is failing validations because your factory is setting up a new user for your test, but your database isn’t being cleared in between. Change your factory to look like this, so that email and license_number are unique each time you create a User:

    factory :user do
      first_name "John"
      last_name "Doe"
      sequence(:email) { |n| "example#{n}@example.com" }
      password "foobar"
      password_confirmation "foobar"
      sequence(:license_number) { |n| "12345#{n}" }
      state 'AZ'
      specialty 'Neurosurgery'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following spec to test controller method: context #create do it should redirect
I have following Rspec test: describe Productlimit do before(:each) do @productlimit = Factory.create(:productlimit, :user
For my test I have the following: test should update holder do holder =
I have the following code require 'test_helper' class ApplicationControllerTest < ActionController::TestCase test should display
I have following code: os.chdir(os.path.dirname(os.path.realpath(__file__)) + /../test) path.append(os.getcwd()) os.chdir(os.path.dirname(os.path.realpath(__file__))) Which should add /../test to
I have following string: Test, User < test@test.com >, Another, Test < another@test.com >,
I have the following routes in my app: GET /admin/comments(.:format) {:controller=>admin/comments, :action=>index} admin_comments POST
I have this test from michael hartl book describe follower/following counts do let(:user) {
Hiho, I have the following test: test should annoy Chuck Norris do son =
I have the following test: it should respond with a json object do xhr

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.