At a bit of a confused here, I am running rspec test on my rails app and have a model spec:
it { should validate_uniqueness_of(:email).case_insensitive }
which is 1 of3 tests for the email object and it keeps failing with the following error:
1) User should validate that :email is case-insensitively unique
Failure/Error: it { should validate_uniqueness_of(:email).case_insensitive }
ArgumentError:
SMTP To address may not be blank: []
# ./spec/models/user_spec.rb:43:in `block (2 levels) in <top (required)>'
I cant understand why testing that email address in a model would require any SMTP TO address.
Not sure what to look at any help would be great as its my only failing test :(
Only other stuff I would think might help is I running:
It seems to throw errors about seemingly unrelated elements. Yet the problem is actually in the code you added to send emails. You need to look back through your code where you are actually sending an email and check your "To:" property.
In my case, I got complaints about factories that made no sense... At least not at first.
An error occurred in a `before(:suite)` hook.
Failure/Error: FactoryBot.lint
FactoryBot::InvalidFactoryError:
The following factories are invalid:
* attachment - SMTP To address may not be blank: [] (ArgumentError)
* distance - SMTP To address may not be blank: [] (ArgumentError)
* structure - SMTP To address may not be blank: [] (ArgumentError)
Then I dug deeper. I tracked down the error to the mailer code, or so I thought:
admins = @organization.users.where(role: "org_admin").map(&:email)
mail(to: admins, subject: "New Structure Created")
But then other tests still failed.
As it turns out, sometimes the actual value being passed for the to:
field was missing due to some tests where admins
and emails were not present (because they did not need to be for those tests). So I "protected" the call to the mailer with a simple if
check:
mail(to: admins, subject: "New Structure Created") if admins.any?