scinote-web/spec/models/sample_custom_field_spec.rb

48 lines
1.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-08-30 00:49:07 +08:00
require 'rails_helper'
describe SampleCustomField, type: :model do
it 'is valid' do
# Need this records because of after_create callback
sample = create :sample
create :samples_table, user: sample.user, team: sample.team
custom_field = create :custom_field, user: sample.user, team: sample.team
sample_custom_filed = create :sample_custom_field, sample: sample, custom_field: custom_field
expect(sample_custom_filed).to be_valid
end
2017-08-30 00:49:07 +08:00
it 'should be of class SampleCustomField' do
expect(subject.class).to eq SampleCustomField
end
describe 'Database table' do
it { should have_db_column :value }
it { should have_db_column :custom_field_id }
it { should have_db_column :sample_id }
it { should have_db_column :created_at }
it { should have_db_column :updated_at }
end
describe 'Relations' do
it { should belong_to :custom_field }
it { should belong_to :sample }
end
describe 'Validations' do
describe '#value' do
it { is_expected.to validate_presence_of :value }
it { is_expected.to validate_length_of(:value).is_at_most(Constants::NAME_MAX_LENGTH) }
end
describe '#custom_field' do
it { is_expected.to validate_presence_of :custom_field }
end
describe '#sample' do
it { is_expected.to validate_presence_of :sample }
2017-08-30 00:49:07 +08:00
end
end
end