diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2015-12-23 10:47:18 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2015-12-23 10:47:18 +0100 |
commit | 37731ba1a1a926f1e4bd6dc620066822f3a4b0da (patch) | |
tree | 7320531dcb995992f9337b7a7d99d99adef41a96 /spec/models/concerns | |
parent | 76f7e80455f1f5b5b052c7d8caf519713b016eea (diff) | |
download | gitlab-ce-37731ba1a1a926f1e4bd6dc620066822f3a4b0da.tar.gz |
Add method that persist ensured token in `TokenAuthenticatable`
Diffstat (limited to 'spec/models/concerns')
-rw-r--r-- | spec/models/concerns/token_authenticatable_spec.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/spec/models/concerns/token_authenticatable_spec.rb b/spec/models/concerns/token_authenticatable_spec.rb index 07ec3a80e60..30c0a04b840 100644 --- a/spec/models/concerns/token_authenticatable_spec.rb +++ b/spec/models/concerns/token_authenticatable_spec.rb @@ -2,7 +2,8 @@ require 'spec_helper' shared_examples 'TokenAuthenticatable' do describe 'dynamically defined methods' do - it { expect(described_class).to be_private_method_defined(:generate_token_for) } + it { expect(described_class).to be_private_method_defined(:generate_token) } + it { expect(described_class).to be_private_method_defined(:write_new_token) } it { expect(described_class).to respond_to("find_by_#{token_field}") } it { is_expected.to respond_to("ensure_#{token_field}") } it { is_expected.to respond_to("reset_#{token_field}!") } @@ -24,17 +25,21 @@ describe ApplicationSetting, 'TokenAuthenticatable' do it_behaves_like 'TokenAuthenticatable' describe 'generating new token' do - subject { described_class.new } - let(:token) { subject.send(token_field) } - context 'token is not generated yet' do - it { expect(token).to be nil } + describe 'token field accessor' do + subject { described_class.new.send(token_field) } + it { is_expected.to_not be_blank } + end describe 'ensured token' do subject { described_class.new.send("ensure_#{token_field}") } it { is_expected.to be_a String } it { is_expected.to_not be_blank } + end + + describe 'ensured! token' do + subject { described_class.new.send("ensure_#{token_field}!") } it 'should persist new token' do expect(subject).to eq described_class.current[token_field] @@ -44,7 +49,9 @@ describe ApplicationSetting, 'TokenAuthenticatable' do context 'token is generated' do before { subject.send("reset_#{token_field}!") } - it { expect(token).to be_a String } + it 'persists a new token 'do + expect(subject.send(:read_attribute, token_field)).to be_a String + end end end |