mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-25 05:27:33 +08:00
Add factories and validation tests for repositories and related models
Repositories, cells, columns, values (date, text, asset, list), rows, items
This commit is contained in:
parent
a7558d83be
commit
3adf2bb736
27 changed files with 292 additions and 220 deletions
|
|
@ -6,7 +6,7 @@ class Report < ApplicationRecord
|
||||||
validates :name,
|
validates :name,
|
||||||
length: { minimum: Constants::NAME_MIN_LENGTH,
|
length: { minimum: Constants::NAME_MIN_LENGTH,
|
||||||
maximum: Constants::NAME_MAX_LENGTH },
|
maximum: Constants::NAME_MAX_LENGTH },
|
||||||
uniqueness: { scope: [:user, :project], case_sensitive: false }
|
uniqueness: { scope: %i(user_id project_id), case_sensitive: false }
|
||||||
validates :description, length: { maximum: Constants::TEXT_MAX_LENGTH }
|
validates :description, length: { maximum: Constants::TEXT_MAX_LENGTH }
|
||||||
validates :project, presence: true
|
validates :project, presence: true
|
||||||
validates :user, presence: true
|
validates :user, presence: true
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,7 @@ class Repository < ApplicationRecord
|
||||||
attribute :discarded_by_id, :integer
|
attribute :discarded_by_id, :integer
|
||||||
|
|
||||||
belongs_to :team, optional: true
|
belongs_to :team, optional: true
|
||||||
belongs_to :created_by,
|
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||||
foreign_key: :created_by_id,
|
|
||||||
class_name: 'User',
|
|
||||||
optional: true
|
|
||||||
has_many :repository_columns, dependent: :destroy
|
has_many :repository_columns, dependent: :destroy
|
||||||
has_many :repository_rows, dependent: :destroy
|
has_many :repository_rows, dependent: :destroy
|
||||||
has_many :repository_table_states,
|
has_many :repository_table_states,
|
||||||
|
|
@ -21,7 +18,7 @@ class Repository < ApplicationRecord
|
||||||
auto_strip_attributes :name, nullify: false
|
auto_strip_attributes :name, nullify: false
|
||||||
validates :name,
|
validates :name,
|
||||||
presence: true,
|
presence: true,
|
||||||
uniqueness: { scope: :team, case_sensitive: false },
|
uniqueness: { scope: :team_id, case_sensitive: false },
|
||||||
length: { maximum: Constants::NAME_MAX_LENGTH }
|
length: { maximum: Constants::NAME_MAX_LENGTH }
|
||||||
validates :team, presence: true
|
validates :team, presence: true
|
||||||
validates :created_by, presence: true
|
validates :created_by, presence: true
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class RepositoryCell < ActiveRecord::Base
|
class RepositoryCell < ActiveRecord::Base
|
||||||
attr_accessor :importing
|
attr_accessor :importing
|
||||||
|
|
||||||
|
|
@ -57,7 +59,7 @@ class RepositoryCell < ActiveRecord::Base
|
||||||
private
|
private
|
||||||
|
|
||||||
def repository_column_data_type
|
def repository_column_data_type
|
||||||
if value_type != repository_column.data_type
|
if !repository_column || value_type != repository_column.data_type
|
||||||
errors.add(:value_type, 'must match column data type')
|
errors.add(:value_type, 'must match column data type')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class RepositoryColumn < ApplicationRecord
|
class RepositoryColumn < ApplicationRecord
|
||||||
belongs_to :repository, optional: true
|
belongs_to :repository
|
||||||
belongs_to :created_by,
|
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||||
foreign_key: :created_by_id,
|
|
||||||
class_name: 'User',
|
|
||||||
optional: true
|
|
||||||
has_many :repository_cells, dependent: :destroy
|
has_many :repository_cells, dependent: :destroy
|
||||||
has_many :repository_rows, through: :repository_cells
|
has_many :repository_rows, through: :repository_cells
|
||||||
has_many :repository_list_items, dependent: :destroy
|
has_many :repository_list_items, dependent: :destroy
|
||||||
|
|
@ -14,7 +13,7 @@ class RepositoryColumn < ApplicationRecord
|
||||||
validates :name,
|
validates :name,
|
||||||
presence: true,
|
presence: true,
|
||||||
length: { maximum: Constants::NAME_MAX_LENGTH },
|
length: { maximum: Constants::NAME_MAX_LENGTH },
|
||||||
uniqueness: { scope: :repository, case_sensitive: true }
|
uniqueness: { scope: :repository_id, case_sensitive: true }
|
||||||
validates :created_by, presence: true
|
validates :created_by, presence: true
|
||||||
validates :repository, presence: true
|
validates :repository, presence: true
|
||||||
validates :data_type, presence: true
|
validates :data_type, presence: true
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,13 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class RepositoryDateValue < ApplicationRecord
|
class RepositoryDateValue < ApplicationRecord
|
||||||
belongs_to :created_by,
|
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||||
foreign_key: :created_by_id,
|
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User'
|
||||||
class_name: 'User',
|
|
||||||
optional: true
|
|
||||||
belongs_to :last_modified_by,
|
|
||||||
foreign_key: :last_modified_by_id,
|
|
||||||
class_name: 'User',
|
|
||||||
optional: true
|
|
||||||
has_one :repository_cell, as: :value, dependent: :destroy
|
has_one :repository_cell, as: :value, dependent: :destroy
|
||||||
accepts_nested_attributes_for :repository_cell
|
accepts_nested_attributes_for :repository_cell
|
||||||
|
|
||||||
validates :repository_cell, presence: true
|
validates :repository_cell, presence: true
|
||||||
validates :data,
|
validates :data, presence: true
|
||||||
presence: true
|
|
||||||
|
|
||||||
def formatted
|
def formatted
|
||||||
data
|
data
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,13 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class RepositoryListItem < ApplicationRecord
|
class RepositoryListItem < ApplicationRecord
|
||||||
has_many :repository_list_values, inverse_of: :repository_list_item
|
has_many :repository_list_values, inverse_of: :repository_list_item
|
||||||
belongs_to :repository, inverse_of: :repository_list_items
|
belongs_to :repository, inverse_of: :repository_list_items
|
||||||
belongs_to :repository_column, inverse_of: :repository_list_items
|
belongs_to :repository_column, inverse_of: :repository_list_items
|
||||||
belongs_to :created_by,
|
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||||
foreign_key: :created_by_id,
|
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User'
|
||||||
class_name: 'User'
|
|
||||||
belongs_to :last_modified_by,
|
|
||||||
foreign_key: :last_modified_by_id,
|
|
||||||
class_name: 'User'
|
|
||||||
validates :data,
|
validates :data,
|
||||||
presence: true,
|
presence: true,
|
||||||
uniqueness: { scope: :repository_column, case_sensitive: false },
|
uniqueness: { scope: :repository_column_id, case_sensitive: false },
|
||||||
length: { maximum: Constants::TEXT_MAX_LENGTH }
|
length: { maximum: Constants::TEXT_MAX_LENGTH }
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,11 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class RepositoryRow < ApplicationRecord
|
class RepositoryRow < ApplicationRecord
|
||||||
include SearchableModel
|
include SearchableModel
|
||||||
|
|
||||||
belongs_to :repository, optional: true
|
belongs_to :repository, optional: true
|
||||||
belongs_to :created_by,
|
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||||
foreign_key: :created_by_id,
|
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User'
|
||||||
class_name: 'User',
|
|
||||||
optional: true
|
|
||||||
belongs_to :last_modified_by,
|
|
||||||
foreign_key: :last_modified_by_id,
|
|
||||||
class_name: 'User',
|
|
||||||
optional: true
|
|
||||||
has_many :repository_cells, -> { order(:id) }, dependent: :destroy
|
has_many :repository_cells, -> { order(:id) }, dependent: :destroy
|
||||||
has_many :repository_columns, through: :repository_cells
|
has_many :repository_columns, through: :repository_cells
|
||||||
has_many :my_module_repository_rows,
|
has_many :my_module_repository_rows,
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class RepositoryTextValue < ApplicationRecord
|
class RepositoryTextValue < ApplicationRecord
|
||||||
belongs_to :created_by,
|
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||||
foreign_key: :created_by_id,
|
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User'
|
||||||
class_name: 'User',
|
|
||||||
optional: true
|
|
||||||
belongs_to :last_modified_by,
|
|
||||||
foreign_key: :last_modified_by_id,
|
|
||||||
class_name: 'User',
|
|
||||||
optional: true
|
|
||||||
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value
|
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value
|
||||||
accepts_nested_attributes_for :repository_cell
|
accepts_nested_attributes_for :repository_cell
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :asset do
|
factory :asset do
|
||||||
association :created_by, factory: :project_user
|
|
||||||
team
|
|
||||||
file_file_name 'sample_file.txt'
|
file_file_name 'sample_file.txt'
|
||||||
file_content_type 'text/plain'
|
file_content_type 'text/plain'
|
||||||
file_file_size 69
|
file_file_size 69
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :repository_asset_value do
|
factory :repository_asset_value do
|
||||||
created_by { User.first || create(:user) }
|
asset
|
||||||
last_modified_by { User.first || create(:user) }
|
after(:build) do |repository_asset_value|
|
||||||
|
repository_asset_value.repository_cell ||= build(:repository_cell,
|
||||||
|
:asset_value,
|
||||||
|
repository_asset_value: repository_asset_value)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,33 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :repository_cell do
|
factory :repository_cell do
|
||||||
repository_row
|
repository_row
|
||||||
repository_column
|
|
||||||
value 'RepositoryTextValue'
|
trait :text_value do
|
||||||
|
repository_column { create :repository_column, :text_type, repository: repository_row.repository }
|
||||||
|
after(:build) do |repository_cell|
|
||||||
|
repository_cell.value ||= build(:repository_text_value, repository_cell: repository_cell)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :date_value do
|
||||||
|
repository_column { create :repository_column, :date_type, repository: repository_row.repository }
|
||||||
|
after(:build) do |repository_cell|
|
||||||
|
repository_cell.value ||= build(:repository_date_value, repository_cell: repository_cell)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :list_value do
|
||||||
|
repository_column { create :repository_column, :list_type, repository: repository_row.repository }
|
||||||
|
after(:build) do |repository_cell|
|
||||||
|
repository_cell.value ||= build(:repository_list_value, repository_cell: repository_cell)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :asset_value do
|
||||||
|
repository_column { create :repository_column, :asset_type, repository: repository_row.repository }
|
||||||
|
after(:build) do |repository_cell|
|
||||||
|
repository_cell.value ||= build(:repository_asset_value, repository_cell: repository_cell)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,21 @@ FactoryBot.define do
|
||||||
created_by { create :user }
|
created_by { create :user }
|
||||||
repository
|
repository
|
||||||
data_type :RepositoryTextValue
|
data_type :RepositoryTextValue
|
||||||
|
|
||||||
|
trait :text_type do
|
||||||
|
data_type :RepositoryTextValue
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :date_type do
|
||||||
|
data_type :RepositoryDateValue
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :list_type do
|
||||||
|
data_type :RepositoryListValue
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :asset_type do
|
||||||
|
data_type :RepositoryAssetValue
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
14
spec/factories/repository_date_values.rb
Normal file
14
spec/factories/repository_date_values.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
FactoryBot.define do
|
||||||
|
factory :repository_date_value do
|
||||||
|
created_by { create :user }
|
||||||
|
last_modified_by { created_by }
|
||||||
|
data { Time.now }
|
||||||
|
after(:build) do |repository_date_value|
|
||||||
|
repository_date_value.repository_cell ||= build(:repository_cell,
|
||||||
|
:date_value,
|
||||||
|
repository_date_value: repository_date_value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :repository_list_item do
|
factory :repository_list_item do
|
||||||
data { Faker::Name.unique.name }
|
data { Faker::Lorem.paragraph }
|
||||||
repository { Repository.first || create(:repository) }
|
repository
|
||||||
created_by { User.first || association(:project_user) }
|
repository_column { create :repository_column, :list_type, repository: repository }
|
||||||
last_modified_by { User.first || association(:project_user) }
|
created_by { create :user }
|
||||||
|
last_modified_by { created_by }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,17 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :repository_list_value do
|
factory :repository_list_value do
|
||||||
created_by { User.first || association(:project_user) }
|
created_by { create :user }
|
||||||
last_modified_by { User.first || association(:project_user) }
|
last_modified_by { created_by }
|
||||||
|
repository_list_item
|
||||||
|
after(:build) do |repository_list_value|
|
||||||
|
repository_list_value.repository_cell ||= build(:repository_cell,
|
||||||
|
:list_value,
|
||||||
|
repository_list_value: repository_list_value)
|
||||||
|
|
||||||
|
repository_list_value.repository_cell.repository_column.repository_list_items =
|
||||||
|
[repository_list_value.repository_list_item]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
FactoryBot.define do
|
|
||||||
factory :repository_text_value do
|
|
||||||
created_by { User.first || association(:project_user) }
|
|
||||||
last_modified_by { User.first || association(:project_user) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
14
spec/factories/repository_text_values.rb
Normal file
14
spec/factories/repository_text_values.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
FactoryBot.define do
|
||||||
|
factory :repository_text_value do
|
||||||
|
created_by { create :user }
|
||||||
|
last_modified_by { created_by }
|
||||||
|
data { Faker::Lorem.paragraph }
|
||||||
|
after(:build) do |repository_text_value|
|
||||||
|
repository_text_value.repository_cell ||= build(:repository_cell,
|
||||||
|
:text_value,
|
||||||
|
repository_text_value: repository_text_value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Report, type: :model do
|
describe Report, type: :model do
|
||||||
|
let(:report) { build :report }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(report).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class Report' do
|
it 'should be of class Report' do
|
||||||
expect(subject.class).to eq Report
|
expect(subject.class).to eq Report
|
||||||
end
|
end
|
||||||
|
|
@ -25,7 +33,7 @@ describe Report, type: :model do
|
||||||
it { should have_many :report_elements }
|
it { should have_many :report_elements }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Should be a valid object' do
|
describe 'Validations' do
|
||||||
it { should validate_presence_of :project }
|
it { should validate_presence_of :project }
|
||||||
it { should validate_presence_of :user }
|
it { should validate_presence_of :user }
|
||||||
it do
|
it do
|
||||||
|
|
@ -38,14 +46,8 @@ describe Report, type: :model do
|
||||||
.is_at_most(Constants::NAME_MAX_LENGTH)
|
.is_at_most(Constants::NAME_MAX_LENGTH)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have uniq name scoped to user, project' do
|
it do
|
||||||
r = create :report, name: 'Same Name'
|
expect(report).to validate_uniqueness_of(:name).scoped_to(:user_id, :project_id).case_insensitive
|
||||||
new_report = build :report,
|
|
||||||
name: 'Same Name',
|
|
||||||
user: r.user,
|
|
||||||
project: r.project
|
|
||||||
|
|
||||||
expect(new_report).to_not be_valid
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe RepositoryAssetValue, type: :model do
|
describe RepositoryAssetValue, type: :model do
|
||||||
|
let(:repository_asset_value) { build :repository_asset_value }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(repository_asset_value).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class RepositoryAssetValue' do
|
it 'should be of class RepositoryAssetValue' do
|
||||||
expect(subject.class).to eq RepositoryAssetValue
|
expect(subject.class).to eq RepositoryAssetValue
|
||||||
end
|
end
|
||||||
|
|
@ -21,28 +29,16 @@ describe RepositoryAssetValue, type: :model do
|
||||||
it { should accept_nested_attributes_for(:repository_cell) }
|
it { should accept_nested_attributes_for(:repository_cell) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Should be a valid object' do
|
describe 'Validations' do
|
||||||
it { should validate_presence_of :repository_cell }
|
it { should validate_presence_of :repository_cell }
|
||||||
it { should validate_presence_of :asset }
|
it { should validate_presence_of :asset }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#data' do
|
describe '#data' do
|
||||||
let!(:repository) { create :repository }
|
|
||||||
let!(:repository_row) { create :repository_row, repository: repository }
|
|
||||||
let!(:repository_column) do
|
|
||||||
create :repository_column,
|
|
||||||
data_type: :RepositoryAssetValue,
|
|
||||||
repository: repository
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns the asset' do
|
it 'returns the asset' do
|
||||||
asset = create :asset, file_file_name: 'my file'
|
asset = create :asset, file_file_name: 'my file'
|
||||||
repository_asset_value = create :repository_asset_value,
|
repository_asset_value = create :repository_asset_value, asset: asset
|
||||||
asset: asset,
|
|
||||||
repository_cell_attributes: {
|
|
||||||
repository_column: repository_column,
|
|
||||||
repository_row: repository_row
|
|
||||||
}
|
|
||||||
expect(repository_asset_value.reload.formatted).to eq 'my file'
|
expect(repository_asset_value.reload.formatted).to eq 'my file'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,38 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe RepositoryCell, type: :model do
|
describe RepositoryCell, type: :model do
|
||||||
|
let(:repository_cell) { build :repository_cell }
|
||||||
|
let(:repository_cell_t) { build :repository_cell, :text_value }
|
||||||
|
let(:repository_cell_d) { build :repository_cell, :date_value }
|
||||||
|
let(:repository_cell_l) { build :repository_cell, :list_value }
|
||||||
|
let(:repository_cell_a) { build :repository_cell, :asset_value }
|
||||||
|
|
||||||
|
context 'when do not have value' do
|
||||||
|
it 'is not valid' do
|
||||||
|
expect(repository_cell).not_to be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when have value' do
|
||||||
|
it 'is valid for text value' do
|
||||||
|
expect(repository_cell_t).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is valid for data value' do
|
||||||
|
expect(repository_cell_d).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is valid for list value' do
|
||||||
|
expect(repository_cell_l).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is valid for asset value' do
|
||||||
|
expect(repository_cell_a).to be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class RepositoryCell' do
|
it 'should be of class RepositoryCell' do
|
||||||
expect(subject.class).to eq RepositoryCell
|
expect(subject.class).to eq RepositoryCell
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe RepositoryColumn, type: :model do
|
describe RepositoryColumn, type: :model do
|
||||||
|
let(:repository_column) { build :repository_column }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(repository_column).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class RepositoryColumn' do
|
it 'should be of class RepositoryColumn' do
|
||||||
expect(subject.class).to eq RepositoryColumn
|
expect(subject.class).to eq RepositoryColumn
|
||||||
end
|
end
|
||||||
|
|
@ -22,19 +30,23 @@ describe RepositoryColumn, type: :model do
|
||||||
it { should have_many :repository_list_items }
|
it { should have_many :repository_list_items }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Should be a valid object' do
|
describe 'Validations' do
|
||||||
it { should validate_presence_of :name }
|
describe '#name' do
|
||||||
it { should validate_presence_of :created_by }
|
it { is_expected.to validate_presence_of :name }
|
||||||
it { should validate_presence_of :repository }
|
it { is_expected.to(validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)) }
|
||||||
it { should validate_presence_of :data_type }
|
it { expect(repository_column).to validate_uniqueness_of(:name).scoped_to(:repository_id) }
|
||||||
it do
|
|
||||||
should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)
|
|
||||||
end
|
end
|
||||||
it 'have uniq name scoped to repository' do
|
|
||||||
r = create :repository_column, name: 'Repo One'
|
|
||||||
ct = build :repository_column, name: 'Repo One', repository: r.repository
|
|
||||||
|
|
||||||
expect(ct).to_not be_valid
|
describe '#created_by' do
|
||||||
|
it { is_expected.to validate_presence_of :created_by }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#repository' do
|
||||||
|
it { is_expected.to validate_presence_of :repository }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#data_type' do
|
||||||
|
it { is_expected.to validate_presence_of :data_type }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe RepositoryDateValue, type: :model do
|
describe RepositoryDateValue, type: :model do
|
||||||
|
let(:repository_date_value) { build :repository_date_value }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(repository_date_value).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class RepositoryDateValue' do
|
it 'should be of class RepositoryDateValue' do
|
||||||
expect(subject.class).to eq RepositoryDateValue
|
expect(subject.class).to eq RepositoryDateValue
|
||||||
end
|
end
|
||||||
|
|
@ -19,7 +27,7 @@ describe RepositoryDateValue, type: :model do
|
||||||
it { should have_one :repository_cell }
|
it { should have_one :repository_cell }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Should be a valid object' do
|
describe 'Validations' do
|
||||||
it { should validate_presence_of :repository_cell }
|
it { should validate_presence_of :repository_cell }
|
||||||
it { should validate_presence_of :data }
|
it { should validate_presence_of :data }
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe RepositoryListItem, type: :model do
|
RSpec.describe RepositoryListItem, type: :model do
|
||||||
|
let(:repository_list_item) { build :repository_list_item }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(repository_list_item).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class RepositoryListItem' do
|
it 'should be of class RepositoryListItem' do
|
||||||
expect(subject.class).to eq RepositoryListItem
|
expect(subject.class).to eq RepositoryListItem
|
||||||
end
|
end
|
||||||
|
|
@ -22,46 +30,13 @@ RSpec.describe RepositoryListItem, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Validations' do
|
describe 'Validations' do
|
||||||
let!(:user) { create :user }
|
describe '#data' do
|
||||||
let!(:repository_one) { create :repository }
|
it { is_expected.to validate_presence_of(:data) }
|
||||||
it { should validate_presence_of(:data) }
|
it { is_expected.to validate_length_of(:data).is_at_most(Constants::TEXT_MAX_LENGTH) }
|
||||||
it do
|
it {
|
||||||
should validate_length_of(:data).is_at_most(Constants::TEXT_MAX_LENGTH)
|
expect(repository_list_item).to validate_uniqueness_of(:data)
|
||||||
end
|
.scoped_to(:repository_column_id).case_insensitive
|
||||||
|
}
|
||||||
context 'has a uniq data scoped on repository column' do
|
|
||||||
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,
|
|
||||||
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_column: repository_column
|
|
||||||
expect(new_item).to_not be_valid
|
|
||||||
expect(
|
|
||||||
new_item.errors.full_messages.first
|
|
||||||
).to eq 'Data has already been taken'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'create a repository list item in other repository' do
|
|
||||||
new_item = build :repository_list_item,
|
|
||||||
data: 'Test',
|
|
||||||
repository: repository_two,
|
|
||||||
repository_column: repository_column_two
|
|
||||||
expect(new_item).to be_valid
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe RepositoryListValue, type: :model do
|
RSpec.describe RepositoryListValue, type: :model do
|
||||||
|
let(:repository_list_value) { build :repository_list_value }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(repository_list_value).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class RepositoryListValue' do
|
it 'should be of class RepositoryListValue' do
|
||||||
expect(subject.class).to eq RepositoryListValue
|
expect(subject.class).to eq RepositoryListValue
|
||||||
end
|
end
|
||||||
|
|
@ -19,76 +27,29 @@ RSpec.describe RepositoryListValue, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#formatted' do
|
describe '#formatted' do
|
||||||
let!(:repository) { create :repository }
|
let(:list_item) { create :repository_list_item, data: 'my item' }
|
||||||
let!(:repository_column) do
|
|
||||||
create :repository_column,
|
|
||||||
name: 'My column',
|
|
||||||
data_type: :RepositoryListValue,
|
|
||||||
repository: repository
|
|
||||||
end
|
|
||||||
let!(:repository_row) do
|
|
||||||
create :repository_row, name: 'My row', repository: repository
|
|
||||||
end
|
|
||||||
let!(:repository_list_value) do
|
|
||||||
build :repository_list_value, repository_cell_attributes: {
|
|
||||||
repository_column: repository_column,
|
|
||||||
repository_row: repository_row
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns the formatted data of a selected item' do
|
it 'returns the formatted data of a selected item' do
|
||||||
list_item = create :repository_list_item,
|
repository_list_value = create :repository_list_value, repository_list_item: list_item
|
||||||
data: 'my item',
|
|
||||||
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'
|
expect(repository_list_value.reload.formatted).to eq 'my item'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#data' do
|
describe '#data' do
|
||||||
let!(:repository) { create :repository }
|
let(:list_item) { create :repository_list_item, data: 'my item' }
|
||||||
let!(:repository_column) do
|
let(:repository_list_value) { create :repository_list_value, repository_list_item: list_item }
|
||||||
create :repository_column,
|
|
||||||
name: 'My column',
|
|
||||||
data_type: :RepositoryListValue,
|
|
||||||
repository: repository
|
|
||||||
end
|
|
||||||
let!(:repository_row) do
|
|
||||||
create :repository_row, name: 'My row', repository: repository
|
|
||||||
end
|
|
||||||
let!(:repository_list_value) do
|
|
||||||
build :repository_list_value, repository_cell_attributes: {
|
|
||||||
repository_column: repository_column,
|
|
||||||
repository_row: repository_row
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns the data of a selected item' do
|
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
|
|
||||||
repository_list_value.save!
|
|
||||||
expect(repository_list_value.reload.data).to eq 'my item'
|
expect(repository_list_value.reload.data).to eq 'my item'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'retuns only the the item related to the list' do
|
# Not sure if this test make sense, because validation will fail before hit this function. Updated in SCI-3183
|
||||||
repository_column_two = create :repository_column, name: 'New column'
|
it 'retuns only the item related to the list' do
|
||||||
list_item = create :repository_list_item,
|
repository_list_value.repository_list_item = nil
|
||||||
data: 'new item',
|
repository_list_value.save(validate: false)
|
||||||
repository: repository,
|
|
||||||
repository_column: repository_column_two
|
expect(repository_list_value.reload.data).to be_nil
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe RepositoryRow, type: :model do
|
describe RepositoryRow, type: :model do
|
||||||
|
let(:repository_row) { build :repository_row }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(repository_row).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class RepositoryRow' do
|
it 'should be of class RepositoryRow' do
|
||||||
expect(subject.class).to eq RepositoryRow
|
expect(subject.class).to eq RepositoryRow
|
||||||
end
|
end
|
||||||
|
|
@ -24,11 +32,14 @@ describe RepositoryRow, type: :model do
|
||||||
it { should have_many :my_modules }
|
it { should have_many :my_modules }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Should be a valid object' do
|
describe 'Validations' do
|
||||||
it { should validate_presence_of :name }
|
describe '#name' do
|
||||||
it { should validate_presence_of :created_by }
|
it { is_expected.to validate_presence_of :name }
|
||||||
it do
|
it { is_expected.to(validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)) }
|
||||||
should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)
|
end
|
||||||
|
|
||||||
|
describe '#created_by' do
|
||||||
|
it { is_expected.to validate_presence_of :created_by }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Repository, type: :model do
|
describe Repository, type: :model do
|
||||||
|
let(:repository) { build :repository }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(repository).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class Repository' do
|
it 'should be of class Repository' do
|
||||||
expect(subject.class).to eq Repository
|
expect(subject.class).to eq Repository
|
||||||
end
|
end
|
||||||
|
|
@ -22,24 +30,18 @@ describe Repository, type: :model do
|
||||||
it { should have_many(:repository_list_items).dependent(:destroy) }
|
it { should have_many(:repository_list_items).dependent(:destroy) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Should be a valid object' do
|
describe 'Validations' do
|
||||||
it { should validate_presence_of :team }
|
describe '#created_by' do
|
||||||
it { should validate_presence_of :created_by }
|
it { is_expected.to validate_presence_of :created_by }
|
||||||
it do
|
|
||||||
should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)
|
|
||||||
end
|
|
||||||
let(:team) { create :team }
|
|
||||||
|
|
||||||
it 'should have uniq name scoped to team' do
|
|
||||||
create :repository, name: 'Repository One', team: team
|
|
||||||
repo = build :repository, name: 'Repository One', team: team
|
|
||||||
expect(repo).to_not be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have uniq name scoped to team calse insensitive' do
|
describe '#name' do
|
||||||
create :repository, name: 'Repository One', team: team
|
it { is_expected.to validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH) }
|
||||||
repo = build :repository, name: 'REPOSITORY ONE', team: team
|
it { expect(repository).to validate_uniqueness_of(:name).scoped_to(:team_id).case_insensitive }
|
||||||
expect(repo).to_not be_valid
|
end
|
||||||
|
|
||||||
|
describe '#team' do
|
||||||
|
it { is_expected.to validate_presence_of :team }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe RepositoryTextValue, type: :model do
|
describe RepositoryTextValue, type: :model do
|
||||||
|
let(:repository_text_value) { build :repository_text_value }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(repository_text_value).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class RepositoryTextValue' do
|
it 'should be of class RepositoryTextValue' do
|
||||||
expect(subject.class).to eq RepositoryTextValue
|
expect(subject.class).to eq RepositoryTextValue
|
||||||
end
|
end
|
||||||
|
|
@ -19,7 +27,7 @@ describe RepositoryTextValue, type: :model do
|
||||||
it { should have_one :repository_cell }
|
it { should have_one :repository_cell }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Should be a valid object' do
|
describe 'Validations' do
|
||||||
it { should validate_presence_of :repository_cell }
|
it { should validate_presence_of :repository_cell }
|
||||||
it { should validate_presence_of :data }
|
it { should validate_presence_of :data }
|
||||||
it do
|
it do
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue