mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 09:23:58 +08:00
add reference to repository column
This commit is contained in:
parent
ae99c92516
commit
d12f8403e4
7 changed files with 35 additions and 9 deletions
|
@ -6,6 +6,7 @@ class RepositoryColumn < ApplicationRecord
|
|||
optional: true
|
||||
has_many :repository_cells, dependent: :destroy
|
||||
has_many :repository_rows, through: :repository_cells
|
||||
has_many :repository_list_items, dependent: :destroy
|
||||
|
||||
enum data_type: Extends::REPOSITORY_DATA_TYPES
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class RepositoryListItem < ApplicationRecord
|
||||
has_many :repository_list_values, inverse_of: :repository_list_item
|
||||
belongs_to :repository, inverse_of: :repository_list_items
|
||||
belongs_to :repository_column, inverse_of: :repository_list_items
|
||||
belongs_to :created_by,
|
||||
foreign_key: :created_by_id,
|
||||
class_name: 'User'
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
class CreateRepositoryListValues < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
create_table :repository_list_items do |t|
|
||||
t.references :repository, foreign_key: true
|
||||
t.references :repository, index: true, foreign_key: true
|
||||
t.references :repository_column, index: true, foreign_key: true
|
||||
t.text :data, index: true, using: :gin, null: false
|
||||
t.references :created_by,
|
||||
index: true,
|
||||
|
|
|
@ -396,6 +396,7 @@ ActiveRecord::Schema.define(version: 20180207095200) do
|
|||
|
||||
create_table "repository_list_items", force: :cascade do |t|
|
||||
t.bigint "repository_id"
|
||||
t.bigint "repository_column_id"
|
||||
t.text "data", null: false
|
||||
t.bigint "created_by_id"
|
||||
t.bigint "last_modified_by_id"
|
||||
|
@ -404,6 +405,7 @@ ActiveRecord::Schema.define(version: 20180207095200) do
|
|||
t.index ["created_by_id"], name: "index_repository_list_items_on_created_by_id"
|
||||
t.index ["data"], name: "index_repository_list_items_on_data"
|
||||
t.index ["last_modified_by_id"], name: "index_repository_list_items_on_last_modified_by_id"
|
||||
t.index ["repository_column_id"], name: "index_repository_list_items_on_repository_column_id"
|
||||
t.index ["repository_id"], name: "index_repository_list_items_on_repository_id"
|
||||
end
|
||||
|
||||
|
@ -879,6 +881,7 @@ ActiveRecord::Schema.define(version: 20180207095200) do
|
|||
add_foreign_key "repository_date_values", "users", column: "created_by_id"
|
||||
add_foreign_key "repository_date_values", "users", column: "last_modified_by_id"
|
||||
add_foreign_key "repository_list_items", "repositories"
|
||||
add_foreign_key "repository_list_items", "repository_columns"
|
||||
add_foreign_key "repository_list_items", "users", column: "created_by_id"
|
||||
add_foreign_key "repository_list_items", "users", column: "last_modified_by_id"
|
||||
add_foreign_key "repository_list_values", "users", column: "created_by_id"
|
||||
|
|
|
@ -19,6 +19,7 @@ describe RepositoryColumn, type: :model do
|
|||
it { should belong_to(:created_by).class_name('User') }
|
||||
it { should have_many :repository_cells }
|
||||
it { should have_many :repository_rows }
|
||||
it { should have_many :repository_list_items }
|
||||
end
|
||||
|
||||
describe 'Should be a valid object' do
|
||||
|
|
|
@ -10,11 +10,15 @@ RSpec.describe RepositoryListItem, type: :model do
|
|||
it { should have_db_column :repository_id }
|
||||
it { should have_db_column :created_by_id }
|
||||
it { should have_db_column :last_modified_by_id }
|
||||
it { should have_db_column :repository_column_id }
|
||||
end
|
||||
|
||||
describe 'Relations' do
|
||||
it { should have_many(:repository_list_values) }
|
||||
it { should belong_to(:repository) }
|
||||
it { should have_many :repository_list_values }
|
||||
it { should belong_to :repository }
|
||||
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') }
|
||||
end
|
||||
|
||||
describe 'Validations' do
|
||||
|
@ -26,15 +30,25 @@ RSpec.describe RepositoryListItem, type: :model do
|
|||
context 'has a uniq data scoped on repository' do
|
||||
let!(:user) { create :user }
|
||||
let!(:repository_one) { create :repository }
|
||||
let!(:repository_column) do
|
||||
create :repository_column, name: 'My column', repository: repository_one
|
||||
end
|
||||
let!(:repository_two) { create :repository, name: 'New repo' }
|
||||
let!(:repository_column_two) do
|
||||
create :repository_column, name: 'My column', repository: repository_two
|
||||
end
|
||||
let!(:repository_list_item) do
|
||||
create :repository_list_item, data: 'Test', repository: repository_one
|
||||
create :repository_list_item,
|
||||
data: 'Test',
|
||||
repository: repository_one,
|
||||
repository_column: repository_column
|
||||
end
|
||||
|
||||
it 'creates a repository list item in same repository' do
|
||||
new_item = build :repository_list_item,
|
||||
data: 'Test',
|
||||
repository: repository_one
|
||||
repository: repository_one,
|
||||
repository_column: repository_column
|
||||
expect(new_item).to_not be_valid
|
||||
expect(
|
||||
new_item.errors.full_messages.first
|
||||
|
@ -44,7 +58,8 @@ RSpec.describe RepositoryListItem, type: :model do
|
|||
it 'create a repository list item in other repository' do
|
||||
new_item = build :repository_list_item,
|
||||
data: 'Test',
|
||||
repository: repository_two
|
||||
repository: repository_two,
|
||||
repository_column: repository_column_two
|
||||
expect(new_item).to be_valid
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,6 +20,7 @@ RSpec.describe RepositoryListValue, type: :model do
|
|||
|
||||
describe '#data' do
|
||||
let!(:repository) { create :repository }
|
||||
let!(:repository_column) { create :repository_column, name: 'My column' }
|
||||
let!(:repository_column) do
|
||||
create :repository_column, data_type: :RepositoryListValue
|
||||
end
|
||||
|
@ -34,7 +35,8 @@ RSpec.describe RepositoryListValue, type: :model do
|
|||
it 'returns the data of a selected item' do
|
||||
list_item = create :repository_list_item,
|
||||
data: 'my item',
|
||||
repository: repository
|
||||
repository: repository,
|
||||
repository_column: repository_column
|
||||
repository_list_value.repository_list_item = list_item
|
||||
repository_list_value.save
|
||||
expect(repository_list_value.reload.formatted).to eq 'my item'
|
||||
|
@ -49,7 +51,8 @@ RSpec.describe RepositoryListValue, type: :model do
|
|||
}
|
||||
list_item = create :repository_list_item,
|
||||
data: 'new item',
|
||||
repository: repository
|
||||
repository: repository,
|
||||
repository_column: repository_column
|
||||
repository_list_value.repository_list_item = list_item
|
||||
expect(repository_list_value.reload.formatted).to_not eq 'my item'
|
||||
expect(repository_list_value.formatted).to eq ''
|
||||
|
@ -58,7 +61,8 @@ RSpec.describe RepositoryListValue, type: :model do
|
|||
it 'returns an empty string if no item selected' do
|
||||
list_item = create :repository_list_item,
|
||||
data: 'my item',
|
||||
repository: repository
|
||||
repository: repository,
|
||||
repository_column: repository_column
|
||||
expect(repository_list_value.reload.formatted).to eq ''
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue