mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 20:25:33 +08:00
4ea21fa2d0
This change both speeds up specs (less strings to allocate) and helps catch cases where methods in Discourse are mutating inputs. Overall we will be migrating everything to use #frozen_string_literal: true it will take a while, but this is the first and safest move in this direction
39 lines
1.2 KiB
Ruby
39 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
require_dependency 'user_email'
|
|
|
|
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
|