Skip to content

Commit

Permalink
FIX: make update_emails work with non-en locales
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA committed Aug 31, 2018
1 parent 38fe506 commit 8229dd6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/mozilla_iam/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ def set(key, value)
end

require_relative "profile/update_groups"
# require_relative "profile/update_emails"
require_relative "profile/update_emails"
2 changes: 2 additions & 0 deletions lib/mozilla_iam/profile/update_emails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def store_taken_email_or_raise(e, taken_emails)
end

def update_emails
locale, I18n.locale = I18n.locale, :en
emails = attr(:secondary_emails)
taken_emails = []
@user.user_emails.where(primary: false).where.not(email: emails).delete_all
Expand All @@ -22,6 +23,7 @@ def update_emails
end
end
set(:taken_emails, taken_emails)
I18n.locale = locale
end
end
end
2 changes: 1 addition & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# name: mozilla-iam
# about: A plugin to integrate Discourse with Mozilla's Identity and Access Management (IAM) system
# version: 0.2.4
# version: 0.2.5
# authors: Leo McArdle
# url: https://github.com/mozilla/discourse-mozilla-iam

Expand Down
23 changes: 23 additions & 0 deletions spec/components/mozilla_iam/profile/update_emails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,26 @@ def mock_profile_emails(*secondary)
end
end
end

describe MozillaIAM::Profile, type: :request do
describe "#update_emails" do
context "with a non english locale set" do
it "shouldn't fail" do
SiteSetting.allow_user_locale = true
user = Fabricate(:user, locale: :es)
authenticate_user(user)
sign_in(user)

Fabricate(:user, email: "taken@email.com")
described_class.any_instance.stubs(:attr).with(:secondary_emails).returns(["taken@email.com"])
described_class.stubs(:refresh_methods).returns([:update_emails])
user.custom_fields["mozilla_iam_last_refresh"] = Time.now - 1.day
user.save_custom_fields

get "/"
expect(response.status).to eq 200
expect(I18n.locale).to eq :es
end
end
end
end

0 comments on commit 8229dd6

Please sign in to comment.