ensure rss token on read

we do this on attribute read since migrating all existing users is not a
feasible solution.
This commit is contained in:
Alexis Reigel 2017-05-23 22:47:05 +02:00
parent dfc2542f55
commit 2f277d10ac
2 changed files with 13 additions and 4 deletions

View file

@ -153,7 +153,7 @@ class User < ActiveRecord::Base
before_validation :set_public_email, if: ->(user) { user.public_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
after_save :ensure_namespace_correct
after_initialize :set_projects_limit
@ -1005,6 +1005,13 @@ class User < ActiveRecord::Base
save
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
# override, from Devise::Validatable

View file

@ -448,9 +448,11 @@ describe User, models: true do
end
describe 'rss token' do
it 'has rss token' do
user = create(:user)
expect(user.rss_token).not_to be_blank
it 'ensures an rss token on read' do
user = create(:user, rss_token: nil)
rss_token = user.rss_token
expect(rss_token).not_to be_blank
expect(user.reload.rss_token).to eq rss_token
end
end