Commit 2f277d10 authored by Alexis Reigel's avatar Alexis Reigel

ensure rss token on read

we do this on attribute read since migrating all existing users is not a
feasible solution.
parent dfc2542f
...@@ -153,7 +153,7 @@ class User < ActiveRecord::Base ...@@ -153,7 +153,7 @@ class User < ActiveRecord::Base
before_validation :set_public_email, if: ->(user) { user.public_email_changed? } before_validation :set_public_email, if: ->(user) { user.public_email_changed? }
after_update :update_emails_with_primary_email, if: ->(user) { user.email_changed? } after_update :update_emails_with_primary_email, if: ->(user) { user.email_changed? }
before_save :ensure_authentication_token, :ensure_incoming_email_token, :ensure_rss_token before_save :ensure_authentication_token, :ensure_incoming_email_token
before_save :ensure_external_user_rights before_save :ensure_external_user_rights
after_save :ensure_namespace_correct after_save :ensure_namespace_correct
after_initialize :set_projects_limit after_initialize :set_projects_limit
...@@ -1005,6 +1005,13 @@ class User < ActiveRecord::Base ...@@ -1005,6 +1005,13 @@ class User < ActiveRecord::Base
save save
end end
# each existing user needs to have an `rss_token`.
# we do this on read since migrating all existing users is not a feasible
# solution.
def rss_token
ensure_rss_token!
end
protected protected
# override, from Devise::Validatable # override, from Devise::Validatable
......
...@@ -448,9 +448,11 @@ describe User, models: true do ...@@ -448,9 +448,11 @@ describe User, models: true do
end end
describe 'rss token' do describe 'rss token' do
it 'has rss token' do it 'ensures an rss token on read' do
user = create(:user) user = create(:user, rss_token: nil)
expect(user.rss_token).not_to be_blank rss_token = user.rss_token
expect(rss_token).not_to be_blank
expect(user.reload.rss_token).to eq rss_token
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment