2018-02-07 22:28:28 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe RepositoryListValue, type: :model do
|
|
|
|
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
|
2018-02-09 21:11:56 +08:00
|
|
|
let!(:repository) { create :repository }
|
2018-02-07 22:28:28 +08:00
|
|
|
let!(:repository_column) do
|
2019-03-13 16:06:48 +08:00
|
|
|
create :repository_column,
|
|
|
|
name: 'My column',
|
|
|
|
data_type: :RepositoryListValue,
|
|
|
|
repository: repository
|
|
|
|
end
|
|
|
|
let!(:repository_row) do
|
|
|
|
create :repository_row, name: 'My row', repository: repository
|
2018-02-07 22:28:28 +08:00
|
|
|
end
|
|
|
|
let!(:repository_list_value) do
|
2018-08-24 20:25:06 +08:00
|
|
|
build :repository_list_value, repository_cell_attributes: {
|
2018-02-07 22:28:28 +08:00
|
|
|
repository_column: repository_column,
|
|
|
|
repository_row: repository_row
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-03-06 23:32:39 +08:00
|
|
|
it 'returns the formatted data of a selected item' do
|
2018-02-07 22:28:28 +08:00
|
|
|
list_item = create :repository_list_item,
|
2018-02-09 23:28:21 +08:00
|
|
|
data: 'my item',
|
2018-02-12 16:05:41 +08:00
|
|
|
repository: repository,
|
|
|
|
repository_column: repository_column
|
2018-02-09 23:28:21 +08:00
|
|
|
repository_list_value.repository_list_item = list_item
|
2018-08-24 20:25:06 +08:00
|
|
|
repository_list_value.save!
|
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
|
|
|
|
let!(:repository) { create :repository }
|
|
|
|
let!(:repository_column) do
|
2019-03-13 16:06:48 +08:00
|
|
|
create :repository_column,
|
|
|
|
name: 'My column',
|
|
|
|
data_type: :RepositoryListValue,
|
|
|
|
repository: repository
|
|
|
|
end
|
|
|
|
let!(:repository_row) do
|
|
|
|
create :repository_row, name: 'My row', repository: repository
|
2018-03-06 23:32:39 +08:00
|
|
|
end
|
|
|
|
let!(:repository_list_value) do
|
2018-08-24 20:25:06 +08:00
|
|
|
build :repository_list_value, repository_cell_attributes: {
|
2018-03-06 23:32:39 +08:00
|
|
|
repository_column: repository_column,
|
|
|
|
repository_row: repository_row
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the data of a selected item' do
|
|
|
|
list_item = create :repository_list_item,
|
|
|
|
data: 'my item',
|
|
|
|
repository: repository,
|
|
|
|
repository_column: repository_column
|
|
|
|
repository_list_value.repository_list_item = list_item
|
2018-08-24 20:25:06 +08:00
|
|
|
repository_list_value.save!
|
2018-03-06 23:32:39 +08:00
|
|
|
expect(repository_list_value.reload.data).to eq 'my item'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'retuns only the the item related to the list' do
|
2018-08-24 20:25:06 +08:00
|
|
|
repository_column_two = create :repository_column, name: 'New column'
|
2018-03-06 23:32:39 +08:00
|
|
|
list_item = create :repository_list_item,
|
|
|
|
data: 'new item',
|
|
|
|
repository: repository,
|
2018-08-24 20:25:06 +08:00
|
|
|
repository_column: repository_column_two
|
|
|
|
repository_list_value_two = build :repository_list_value,
|
|
|
|
repository_cell_attributes: {
|
|
|
|
repository_column: repository_column,
|
|
|
|
repository_row: repository_row
|
|
|
|
}
|
|
|
|
repository_list_value_two.repository_list_item = list_item
|
|
|
|
saved = repository_list_value_two.save
|
|
|
|
expect(saved).to eq false
|
2018-03-06 23:32:39 +08:00
|
|
|
end
|
|
|
|
end
|
2018-02-07 22:28:28 +08:00
|
|
|
end
|