简体   繁体   中英

How to make integrations tests in Rails afther create the model user with devise

I am doing an integration test that worked before installing devise. Now throw error for a duplicate key. Trying to insert a user. The thing is that I am doing and testing the tests is for a Category model that does not even have an association. I leave the code and the error. Thank you

require 'test_helper'

class CreateCategoriesTest < ActionDispatch::IntegrationTest

 test "get new category form and create category" do
  get new_category_path
  assert_template 'categories/new'
  assert_difference 'Category.count', 1 do
     post categories_path, params: { category: { name: "measure tension", description: "This is the Category for measure tension"} }
     follow_redirect!
  end
  assert_template 'categories/index'
  assert_match "measure tension", response.body
 end

end

The error is as follows:

Running via Spring preloader in process 14544
Run options: --seed 57420

# Running:

E

Error:
CreateCategoriesTest#test_get_new_category_form_and_create_category:
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  llave duplicada viola restricción de unicidad «index_users_on_email»
DETAIL:  Ya existe la llave (email)=().
: DELETE FROM "categories";
DELETE FROM "users";
INSERT INTO "categories" ("id", "name", "description", "created_at", "updated_at") VALUES (980190962, 'MyString', 'MyText', '2020-03-06 20:25:00.457344', '2020-03-06 20:25:00.457344'), (298486374, 'MyString', 'MyText', '2020-03-06 20:25:00.457344', '2020-03-06 20:25:00.457344');
INSERT INTO "users" ("id", "email", "encrypted_password", "reset_password_token", "reset_password_sent_at", "remember_created_at", "created_at", "updated_at") VALUES (980190962, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, '2020-03-06 20:25:00.463209', '2020-03-06 20:25:00.463209'), (298486374, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, '2020-03-06 20:25:00.463209', '2020-03-06 20:25:00.463209')


Error:
CreateCategoriesTest#test_get_new_category_form_and_create_category:
NoMethodError: undefined method `each' for nil:NilClass



bin/rails test test/integration/create_categories_test.rb:5



Finished in 0.023791s, 42.0323 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips

Thakns to kevinluo201 I solved my problem by configuring two different email users in users.yml Although also in test_helper.rb the line "fixtures: all" is commented. You can also run the tests.

The users.yml:

one:
 email: email1@example.com

two: 
 email: email2@example.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM