2015-11-04 17:27:01 +01:00
|
|
|
require 'spec_helper'
|
2015-10-23 16:19:55 +02:00
|
|
|
|
2015-11-04 17:27:01 +01:00
|
|
|
describe Administrateur, type: :model do
|
2015-10-23 16:19:55 +02:00
|
|
|
describe 'database column' do
|
|
|
|
it { is_expected.to have_db_column(:email) }
|
|
|
|
it { is_expected.to have_db_column(:encrypted_password) }
|
|
|
|
it { is_expected.to have_db_column(:reset_password_token) }
|
|
|
|
it { is_expected.to have_db_column(:reset_password_sent_at) }
|
|
|
|
it { is_expected.to have_db_column(:remember_created_at) }
|
|
|
|
it { is_expected.to have_db_column(:sign_in_count) }
|
|
|
|
it { is_expected.to have_db_column(:current_sign_in_at) }
|
|
|
|
it { is_expected.to have_db_column(:last_sign_in_at) }
|
|
|
|
it { is_expected.to have_db_column(:current_sign_in_ip) }
|
|
|
|
it { is_expected.to have_db_column(:last_sign_in_ip) }
|
|
|
|
it { is_expected.to have_db_column(:created_at) }
|
|
|
|
it { is_expected.to have_db_column(:updated_at) }
|
2015-12-14 17:28:36 +01:00
|
|
|
it { is_expected.to have_db_column(:api_token) }
|
2015-10-23 16:19:55 +02:00
|
|
|
end
|
2015-11-10 10:23:15 +01:00
|
|
|
|
|
|
|
describe 'assocations' do
|
2016-05-20 15:39:17 +02:00
|
|
|
it { is_expected.to have_and_belong_to_many(:gestionnaires) }
|
2015-11-10 10:23:15 +01:00
|
|
|
it { is_expected.to have_many(:procedures) }
|
|
|
|
end
|
|
|
|
|
2015-12-14 17:28:36 +01:00
|
|
|
describe 'after_save' do
|
|
|
|
subject { described_class.new(email: 'toto@tps.com', password: 'password') }
|
|
|
|
before do
|
|
|
|
subject.save
|
|
|
|
end
|
|
|
|
it { expect(subject.api_token).not_to be_blank }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'generate_api_token' do
|
|
|
|
let(:token) { 'bullshit' }
|
|
|
|
let(:new_token) { 'pocket_master' }
|
|
|
|
let!(:admin_1) { create(:administrateur, email: 'toto@tps.com', password: 'password', api_token: token) }
|
|
|
|
before do
|
|
|
|
allow(SecureRandom).to receive(:hex).and_return(token, new_token)
|
|
|
|
admin_1.renew_api_token
|
|
|
|
end
|
|
|
|
it 'generate a token who does not already exist' do
|
|
|
|
expect(admin_1.api_token).to eq(new_token)
|
|
|
|
end
|
|
|
|
end
|
2015-10-23 16:19:55 +02:00
|
|
|
end
|