diff options
| author | Robert | 2017-07-26 08:13:43 +0200 |
|---|---|---|
| committer | Robert | 2017-07-26 14:35:42 +0200 |
| commit | d385a6da731dc6b3ec0ec5bec1e94eb2dcff5efb (patch) | |
| tree | 0e2113f5292a7929d3a3e34d06121302b0f70949 /spec/models | |
| parent | fe46c7832fa1e0c6af450f0937aea3534c0f6b01 (diff) | |
| download | chouette-core-d385a6da731dc6b3ec0ec5bec1e94eb2dcff5efb.tar.bz2 | |
Refs: #3507@4h; Finished Basic WorkbenchImportWorker
- speced but missing error treatment
Diffstat (limited to 'spec/models')
| -rw-r--r-- | spec/models/api/v1/api_key_spec.rb | 31 | ||||
| -rw-r--r-- | spec/models/organisation_spec.rb | 2 |
2 files changed, 27 insertions, 6 deletions
diff --git a/spec/models/api/v1/api_key_spec.rb b/spec/models/api/v1/api_key_spec.rb index 8a34c9221..5f39a65e4 100644 --- a/spec/models/api/v1/api_key_spec.rb +++ b/spec/models/api/v1/api_key_spec.rb @@ -1,11 +1,34 @@ describe Api::V1::ApiKey, :type => :model do - let!(:referential){create(:referential)} - subject { Api::V1::ApiKey.create( :name => "test", :referential => referential)} - it "test" do - expect(subject).to be_valid + let(:referential){ create :referential } + + subject { described_class.create( :name => "test", :referential => referential)} + + it "validity test" do + expect_it.to be_valid expect(subject.referential).to eq(referential) + 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 + ]) + end + it 'cannot be created without a referential' do + expect{ described_class.from(nil, name:name) rescue nil }.not_to change{ described_class.count } + end end end diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 1cce7e846..b16324a56 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe Organisation, :type => :model do it { should validate_presence_of(:name) } it { should validate_uniqueness_of(:code) } |
