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 ...@@ -17,12 +17,8 @@ module TokenAuthenticatable
end end
define_method("ensure_#{token_field}") do define_method("ensure_#{token_field}") do
current_token = read_attribute(token_field) send("reset_#{token_field}!") if read_attribute(token_field).blank?
if current_token.blank? read_attribute(token_field)
write_attribute(token_field, generate_token_for(token_field))
else
current_token
end
end end
define_method("reset_#{token_field}!") do define_method("reset_#{token_field}!") do
......
...@@ -35,6 +35,10 @@ describe ApplicationSetting, 'TokenAuthenticatable' do ...@@ -35,6 +35,10 @@ describe ApplicationSetting, 'TokenAuthenticatable' do
it { is_expected.to be_a String } it { is_expected.to be_a String }
it { is_expected.to_not be_blank } 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
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