aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/api
diff options
context:
space:
mode:
authorRobert2017-07-26 08:13:43 +0200
committerRobert2017-07-26 14:35:42 +0200
commitd385a6da731dc6b3ec0ec5bec1e94eb2dcff5efb (patch)
tree0e2113f5292a7929d3a3e34d06121302b0f70949 /spec/models/api
parentfe46c7832fa1e0c6af450f0937aea3534c0f6b01 (diff)
downloadchouette-core-d385a6da731dc6b3ec0ec5bec1e94eb2dcff5efb.tar.bz2
Refs: #3507@4h; Finished Basic WorkbenchImportWorker
- speced but missing error treatment
Diffstat (limited to 'spec/models/api')
-rw-r--r--spec/models/api/v1/api_key_spec.rb31
1 files changed, 27 insertions, 4 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