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:
parent
3b61dc47ec
commit
76f7e80455
2 changed files with 6 additions and 6 deletions
|
@ -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
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue