mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 04:04:21 +08:00
427d54b2b0
Zeitwerk simplifies working with dependencies in dev and makes it easier reloading class chains. We no longer need to use Rails "require_dependency" anywhere and instead can just use standard Ruby patterns to require files. This is a far reaching change and we expect some followups here.
38 lines
1.1 KiB
Ruby
38 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe UserEmail do
|
|
context "validation" do
|
|
it "allows only one primary email" do
|
|
user = Fabricate(:user)
|
|
expect {
|
|
Fabricate(:secondary_email, user: user, primary: true)
|
|
}.to raise_error(ActiveRecord::RecordInvalid)
|
|
end
|
|
|
|
it "allows multiple secondary emails" do
|
|
user = Fabricate(:user)
|
|
Fabricate(:secondary_email, user: user, primary: false)
|
|
Fabricate(:secondary_email, user: user, primary: false)
|
|
expect(user.user_emails.count).to eq 3
|
|
end
|
|
end
|
|
|
|
context "indexes" do
|
|
it "allows only one primary email" do
|
|
user = Fabricate(:user)
|
|
expect {
|
|
Fabricate.build(:secondary_email, user: user, primary: true).save(validate: false)
|
|
}.to raise_error(ActiveRecord::RecordNotUnique)
|
|
end
|
|
|
|
it "allows multiple secondary emails" do
|
|
user = Fabricate(:user)
|
|
Fabricate.build(:secondary_email, user: user, primary: false).save(validate: false)
|
|
Fabricate.build(:secondary_email, user: user, primary: false).save(validate: false)
|
|
expect(user.user_emails.count).to eq 3
|
|
end
|
|
end
|
|
end
|