oveits / ProvisioningEngine

Ruby on Rails based ProvisioningEngine Frontend for provisioning of legacy systems via Apache Camel Backend (SOAP/XML+SPML+File import)
3 stars 6 forks source link

travisCI fails with 'FactoryGirl.create...Validation failed: Email has already been taken' message #27

Closed oveits closed 8 years ago

oveits commented 8 years ago

Admin::SystemSettingsController System Settings links dashboard  should have menu item to System Settings (FAILED - 1)

Failures:

1) Admin::SystemSettingsController System Settings links dashboard should have menu item to System Settings Failure/Error: @admin = FactoryGirl.create(:admin_user)  ActiveRecord::RecordInvalid:  Validation failed: Email has already been taken # ./spec/requests/system_settings_spec.rb:16:in `block (2 levels) in <top (required)>'

oveits commented 8 years ago

I found a similar topic on from: http://stackoverflow.com/questions/7145256/find-or-create-record-through-factory-girl-association:

According to this, I am trying with replacing following code:

# spec/factories/admin_user.rb
FactoryGirl.define do
    factory :admin_user do
      email "admin@example.com"
      password "password"

    end # factory :target do
  end # FactoryGirl.define do

by an initialization using the find_or_create_by method:

FactoryGirl.define do
    factory :admin_user do
      email "admin@example.com"
      password "password"

      # from: http://stackoverflow.com/questions/7145256/find-or-create-record-through-factory-girl-association
      initialize_with { admin_user = AdminUser.find_or_create_by(email: email)
                        admin_user.update_attributes(password: password)
                        admin_user }
    end # factory :target do
  end # FactoryGirl.define do
oveits commented 8 years ago

Actually, https://github.com/oveits/ProvisioningEngine/commit/bbb71a19fd7cb2509af44931126d83f10e6e21b8 has resolved the problem (but I did not recognize right away, therefore the wrong labeling I do not want to change).