Commit 76f7e804 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix method that ensures authentication token

Until now, `ensure_#{token_filed_name}` method didn't persist new token in database.

This closes #4235.
parent 3b61dc47
......@@ -17,12 +17,8 @@ module TokenAuthenticatable
end
define_method("ensure_#{token_field}") do
current_token = read_attribute(token_field)
if current_token.blank?
write_attribute(token_field, generate_token_for(token_field))
else
current_token
end
send("reset_#{token_field}!") if read_attribute(token_field).blank?
read_attribute(token_field)
end
define_method("reset_#{token_field}!") do
......
......@@ -35,6 +35,10 @@ describe ApplicationSetting, 'TokenAuthenticatable' do
it { is_expected.to be_a String }
it { is_expected.to_not be_blank }
it 'should persist new token' do
expect(subject).to eq described_class.current[token_field]
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