I initiated the test environment in my rails app, and when I test the user model with the default code, it throws the following error:
Test code:
test "the truth" do
assert true
end
1) Error:
UserTest#test_the_truth:
ActiveRecord::RecordNotUnique: Mysql2::Error: Duplicate entry '' for key 'index_users_on_email': INSERT INTO `users` (`created_at`, `updated_at`, `id`) VALUES ('2014-02-01 17:45:51', '2014-02-01 17:45:51', 298486374)
and inside my user model, I have the following associations
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates :user_name , :email, :first_name ,:last_name , :presence => true
has_many :invitations
has_many :incoming_friends, -> { where(:status => '1') }, :class_name => "User", :foreign_key => "friend_id", :through => :invitations
has_many :outgoing_friends, -> { where(:status => '1') }, :class_name => "User", :foreign_key => "user_id", :through => :invitations
Firstly, check your user model fixture in test/fixtures/users.yml. If you have empty declarations of one and two:
one: {}
# column: value
#
two: {}
# column: value
it can cause a problems, because there is a lack of attributes. Remove this part or comment it:
#one: {}
# column: value
#
#two: {}
# column: value
And try run it again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With