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 RepositoryListValue, type: :model do
|
2019-05-07 19:47:50 +08:00
|
|
|
let(:repository_list_value) { build :repository_list_value }
|
|
|
|
|
|
|
|
it 'is valid' do
|
|
|
|
expect(repository_list_value).to be_valid
|
|
|
|
end
|
|
|
|
|
2018-02-07 22:28:28 +08:00
|
|
|
it 'should be of class RepositoryListValue' do
|
|
|
|
expect(subject.class).to eq RepositoryListValue
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Database table' do
|
|
|
|
it { should have_db_column :created_by_id }
|
|
|
|
it { should have_db_column :last_modified_by_id }
|
2018-02-09 23:28:21 +08:00
|
|
|
it { should have_db_column :repository_list_item_id }
|
2018-02-07 22:28:28 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Relations' do
|
|
|
|
it { should belong_to(:created_by).class_name('User') }
|
|
|
|
it { should belong_to(:last_modified_by).class_name('User') }
|
2018-02-09 23:28:21 +08:00
|
|
|
it { should belong_to(:repository_list_item) }
|
2018-02-07 22:28:28 +08:00
|
|
|
it { should accept_nested_attributes_for(:repository_cell) }
|
|
|
|
end
|
|
|
|
|
2018-03-06 23:32:39 +08:00
|
|
|
describe '#formatted' do
|
2019-05-07 19:47:50 +08:00
|
|
|
let(:list_item) { create :repository_list_item, data: 'my item' }
|
2018-02-07 22:28:28 +08:00
|
|
|
|
2018-03-06 23:32:39 +08:00
|
|
|
it 'returns the formatted data of a selected item' do
|
2019-05-07 19:47:50 +08:00
|
|
|
repository_list_value = create :repository_list_value, repository_list_item: list_item
|
|
|
|
|
2018-02-09 18:38:52 +08:00
|
|
|
expect(repository_list_value.reload.formatted).to eq 'my item'
|
2018-02-07 22:28:28 +08:00
|
|
|
end
|
|
|
|
end
|
2018-03-06 23:32:39 +08:00
|
|
|
|
|
|
|
describe '#data' do
|
2019-05-07 19:47:50 +08:00
|
|
|
let(:list_item) { create :repository_list_item, data: 'my item' }
|
|
|
|
let(:repository_list_value) { create :repository_list_value, repository_list_item: list_item }
|
2018-03-06 23:32:39 +08:00
|
|
|
|
|
|
|
it 'returns the data of a selected item' do
|
|
|
|
expect(repository_list_value.reload.data).to eq 'my item'
|
|
|
|
end
|
|
|
|
|
2019-05-07 19:47:50 +08:00
|
|
|
# Not sure if this test make sense, because validation will fail before hit this function. Updated in SCI-3183
|
|
|
|
it 'retuns only the item related to the list' do
|
|
|
|
repository_list_value.repository_list_item = nil
|
|
|
|
repository_list_value.save(validate: false)
|
|
|
|
|
|
|
|
expect(repository_list_value.reload.data).to be_nil
|
2018-03-06 23:32:39 +08:00
|
|
|
end
|
|
|
|
end
|
2018-02-07 22:28:28 +08:00
|
|
|
end
|