diff options
| author | Xinhui | 2017-08-17 15:47:55 +0200 |
|---|---|---|
| committer | Xinhui | 2017-08-17 16:03:13 +0200 |
| commit | 24862b2b1baa94c80fd7206bfe2244019604dbf5 (patch) | |
| tree | 5f6905f8b76287f061f7ba98258d0ad43fa11bf9 /spec/models/api | |
| parent | 27d0fc5da357c6ba7b7b3288399c7934c30265f2 (diff) | |
| download | chouette-core-24862b2b1baa94c80fd7206bfe2244019604dbf5.tar.bz2 | |
Model ApiKey add belongs_to organisation
Diffstat (limited to 'spec/models/api')
| -rw-r--r-- | spec/models/api/v1/api_key_spec.rb | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/spec/models/api/v1/api_key_spec.rb b/spec/models/api/v1/api_key_spec.rb index 5f39a65e4..b700429d3 100644 --- a/spec/models/api/v1/api_key_spec.rb +++ b/spec/models/api/v1/api_key_spec.rb @@ -1,34 +1,25 @@ -describe Api::V1::ApiKey, :type => :model do +require 'rails_helper' - let(:referential){ create :referential } +RSpec.describe Api::V1::ApiKey, type: :model do + subject { create(:api_key) } - subject { described_class.create( :name => "test", :referential => referential)} + it { should validate_presence_of :organisation } - it "validity test" do - expect_it.to be_valid - expect(subject.referential).to eq(referential) + it 'should have a valid factory' do + expect(build(:api_key)).to be_valid end - context 'Creation' do - let( :name ){ SecureRandom.urlsafe_base64 } - - it 'can be created from a referential with a name, iff needed' do - # 1st time create a new record - expect{ described_class.from(referential, name: name) }.to change{ described_class.count }.by(1) - expect( described_class.last.attributes.values_at(*%w{referential_id name}) ).to eq([ - referential.id, name - ]) - - # 2nd time get the same record - expect{ described_class.from(referential, name: name) }.not_to change{ described_class.count } - expect( described_class.last.attributes.values_at(*%w{referential_id name}) ).to eq([ - referential.id, name - ]) + describe '#referential_from_token' do + it 'should return referential' do + referential = Api::V1::ApiKey.referential_from_token(subject.token) + expect(referential).to eq(subject.referential) end + end - it 'cannot be created without a referential' do - expect{ described_class.from(nil, name:name) rescue nil }.not_to change{ described_class.count } + describe '#organisation_from_token' do + it 'should return organisation' do + organisation = Api::V1::ApiKey.organisation_from_token(subject.token) + expect(organisation).to eq(subject.organisation) end end end - |
