Add method to generate subscriptions_token
Note that we only update a user with a new token if the user has not yet been assigned one.
This commit is contained in:
@@ -415,6 +415,10 @@ class User < ApplicationRecord
|
||||
devise_mailer.send(notification, self, *args).deliver_later
|
||||
end
|
||||
|
||||
def add_subscriptions_token
|
||||
update!(subscriptions_token: SecureRandom.base58(32)) if subscriptions_token.blank?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def clean_document_number
|
||||
|
||||
@@ -823,4 +823,22 @@ describe User do
|
||||
expect(other_user_legislation_proposal.reload).to be_hidden
|
||||
end
|
||||
end
|
||||
|
||||
describe "#add_subscriptions_token" do
|
||||
let(:user) { build(:user, subscriptions_token: nil) }
|
||||
|
||||
it "generates a subscriptions token when the user doesn't have one" do
|
||||
user.add_subscriptions_token
|
||||
|
||||
expect(user.subscriptions_token).to be_present
|
||||
end
|
||||
|
||||
it "keeps the existing subscriptions token when the user already has one" do
|
||||
user.update!(subscriptions_token: "already_set")
|
||||
|
||||
user.add_subscriptions_token
|
||||
|
||||
expect(user.subscriptions_token).to eq "already_set"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user