FIX: remove primary emails from secondary_emails attr

This commit is contained in:
Leo McArdle 2018-08-24 17:12:22 +01:00
Родитель 46fa806fa1
Коммит 12368b4b06
2 изменённых файлов: 22 добавлений и 1 удалений

Просмотреть файл

@ -28,7 +28,15 @@ module MozillaIAM
def process_emails
emails = @raw[:emails]
if emails
emails.select { |x| x[:verified] && !x[:primary] }.map { |x| x[:value] }.uniq
primary = emails.select do |x|
x[:verified] &&
x[:primary]
end.map { |x| x[:value] }
emails.select do |x|
x[:verified] &&
!x[:primary] &&
primary.exclude?(x[:value])
end.map { |x| x[:value] }.uniq
else
[]
end

Просмотреть файл

@ -90,6 +90,19 @@ describe MozillaIAM::API::Person do
expect(profile.secondary_emails).to contain_exactly("second@example.com", "third@example.com")
end
end
context "with a primary email in profile as secondary" do
let(:profile) { described_class.new({ emails: [
{ verified: true, value: "first@example.com", primary: true },
{ verified: true, value: "first@example.com", primary: false },
{ verified: true, value: "second@example.com", primary: false },
{ verified: true, value: "third@example.com", primary: false },
] }) }
it "doesn't return primary email in secondary emails" do
expect(profile.secondary_emails).to contain_exactly("second@example.com", "third@example.com")
end
end
end
end
end