mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 14:45:56 +08:00
Assets spec and factories updated
This commit is contained in:
parent
d553fee2b3
commit
6321c0f5c0
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AssetTextDatum < ApplicationRecord
|
||||
include SearchableModel
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :asset_text_datum do
|
||||
data "Sample name\tSample type\n" + "sample6\tsample\n" + "\n"
|
||||
asset
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :asset do
|
||||
association :created_by, factory: :project_user
|
||||
association :team, factory: :team
|
||||
team
|
||||
file_file_name 'sample_file.txt'
|
||||
file_content_type 'text/plain'
|
||||
file_file_size 69
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Asset, type: :model do
|
||||
let(:asset) { build :asset }
|
||||
|
||||
it 'should be of class Asset' do
|
||||
expect(subject.class).to eq Asset
|
||||
end
|
||||
|
||||
it 'is valid' do
|
||||
expect(asset).to be_valid
|
||||
end
|
||||
|
||||
describe 'Database table' do
|
||||
it { should have_db_column :id }
|
||||
it { should have_db_column :created_at }
|
||||
|
@ -38,13 +46,13 @@ describe Asset, type: :model do
|
|||
it { should have_one :repository_cell }
|
||||
end
|
||||
|
||||
describe 'Should be a valid object' do
|
||||
it { should validate_presence_of :file }
|
||||
it 'should validate the presence of estimated size' do
|
||||
asset = build :asset, estimated_size: nil
|
||||
expect(asset).to_not be_valid
|
||||
describe 'Validations' do
|
||||
describe '#file' do
|
||||
it { is_expected.to validate_presence_of(:file) }
|
||||
end
|
||||
|
||||
describe '#estimated_size' do
|
||||
it { expect(asset).to validate_presence_of(:estimated_size) }
|
||||
end
|
||||
# should validate_presence_of :estimated_size }
|
||||
it { should validate_inclusion_of(:file_present).in_array([true, false]) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe AssetTextDatum, type: :model do
|
||||
let(:asset_text_datum) { build :asset_text_datum }
|
||||
|
||||
it 'is valid' do
|
||||
expect(asset_text_datum).to be_valid
|
||||
end
|
||||
|
||||
it 'should be of class Activity' do
|
||||
expect(subject.class).to eq AssetTextDatum
|
||||
end
|
||||
|
@ -17,16 +25,14 @@ describe AssetTextDatum, type: :model do
|
|||
it { should belong_to :asset }
|
||||
end
|
||||
|
||||
describe 'Should be a valid object' do
|
||||
let(:asset) { create :asset }
|
||||
describe 'Validations' do
|
||||
describe '#data' do
|
||||
it { is_expected.to validate_presence_of(:data) }
|
||||
end
|
||||
|
||||
it { should validate_presence_of :data }
|
||||
it { should validate_presence_of :asset }
|
||||
|
||||
it 'should have uniq asset' do
|
||||
create :asset_text_datum, asset: asset
|
||||
new_atd = build :asset_text_datum, asset: asset
|
||||
expect(new_atd).to_not be_valid
|
||||
describe '#asset' do
|
||||
it { is_expected.to validate_presence_of(:asset) }
|
||||
it { expect(asset_text_datum).to validate_uniqueness_of(:asset) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue