2019-05-07 19:47:50 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-07 22:28:28 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe RepositoryListItem, type: :model do
|
2019-05-07 19:47:50 +08:00
|
|
|
let(:repository_list_item) { build :repository_list_item }
|
|
|
|
|
|
|
|
it 'is valid' do
|
|
|
|
expect(repository_list_item).to be_valid
|
|
|
|
end
|
|
|
|
|
2018-02-07 22:28:28 +08:00
|
|
|
it 'should be of class RepositoryListItem' do
|
|
|
|
expect(subject.class).to eq RepositoryListItem
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Database table' do
|
2018-02-09 23:28:21 +08:00
|
|
|
it { should have_db_column :data }
|
|
|
|
it { should have_db_column :created_by_id }
|
|
|
|
it { should have_db_column :last_modified_by_id }
|
2018-02-12 16:05:41 +08:00
|
|
|
it { should have_db_column :repository_column_id }
|
2018-02-07 22:28:28 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Relations' do
|
2018-02-12 16:05:41 +08:00
|
|
|
it { should have_many :repository_list_values }
|
|
|
|
it { should belong_to :repository_column }
|
|
|
|
it { should belong_to(:created_by).class_name('User') }
|
|
|
|
it { should belong_to(:last_modified_by).class_name('User') }
|
2018-02-07 22:28:28 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Validations' do
|
2019-05-07 19:47:50 +08:00
|
|
|
describe '#data' do
|
|
|
|
it { is_expected.to validate_presence_of(:data) }
|
|
|
|
it { is_expected.to validate_length_of(:data).is_at_most(Constants::TEXT_MAX_LENGTH) }
|
|
|
|
it {
|
|
|
|
expect(repository_list_item).to validate_uniqueness_of(:data)
|
|
|
|
.scoped_to(:repository_column_id).case_insensitive
|
|
|
|
}
|
2018-02-09 21:11:56 +08:00
|
|
|
end
|
2018-02-07 22:28:28 +08:00
|
|
|
end
|
|
|
|
end
|