Fix method that ensures authentication token

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

This closes #4235.
This commit is contained in:
Grzegorz Bizon 2015-12-23 09:29:04 +01:00
parent 3b61dc47ec
commit 76f7e80455
2 changed files with 6 additions and 6 deletions

View File

@ -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

View File

@ -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