Fixes tests

This commit is contained in:
aignatov-bio 2019-12-06 14:16:20 +01:00
parent d8676596f1
commit 643abc3fd7
6 changed files with 50 additions and 7 deletions

View file

@ -7,8 +7,8 @@ class RepositoryCheckboxItem < ApplicationRecord
maximum: Constants::NAME_MAX_LENGTH }
belongs_to :repository, inverse_of: :repository_checklist_items
belongs_to :repository_column
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User', optional: true,
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User',
inverse_of: :created_repository_checkbox_types
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User', optional: true,
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User',
inverse_of: :modified_repository_checkbox_types
end

View file

@ -1,10 +1,10 @@
# frozen_string_literal: true
class RepositoryCheckboxValue < ApplicationRecord
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User', optional: true,
inverse_of: :created_repository_checkbox_value
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User', optional: true,
inverse_of: :modified_repository_checkbox_value
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User',
inverse_of: :created_repository_checkbox_values
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User',
inverse_of: :modified_repository_checkbox_values
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value
accepts_nested_attributes_for :repository_cell

View file

@ -45,5 +45,12 @@ FactoryBot.define do
repository_cell.value ||= build(:repository_date_time_range_value, repository_cell: repository_cell)
end
end
trait :checkbox_value do
repository_column { create :repository_column, :date_time_range_type, repository: repository_row.repository }
after(:build) do |repository_cell|
repository_cell.value ||= build(:repository_checkbox_value, repository_cell: repository_cell)
end
end
end
end

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
FactoryBot.define do
factory :repository_checkbox_value do
created_by { create :user }
last_modified_by { created_by }
repository_checkboxes_items { [] }
end
end

View file

@ -31,7 +31,7 @@ RSpec.describe RepositoryCheckboxItem, type: :model do
describe 'Validations' do
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 { is_expected.to validate_length_of(:data).is_at_most(Constants::NAME_MAX_LENGTH) }
it {
expect(repository_checkbox_item).to validate_uniqueness_of(:data)
.scoped_to(:repository_column_id).case_insensitive

View file

@ -0,0 +1,27 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe RepositoryCheckboxValue, type: :model do
let(:repository_checkbox_value) { build :repository_checkbox_value }
it 'is valid' do
expect(repository_checkbox_value).to be_valid
end
it 'should be of class RepositoryCheckboxValue' do
expect(subject.class).to eq RepositoryCheckboxValue
end
describe 'Database table' do
it { should have_db_column :created_by_id }
it { should have_db_column :last_modified_by_id }
it { should have_db_column :repository_checkboxes_items }
end
describe 'Relations' do
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it { should accept_nested_attributes_for(:repository_cell) }
end
end