From 837437309e865f7504b4a4802bbdfe622f7a86b1 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 9 Apr 2020 17:11:58 +0200 Subject: [PATCH] Fix failing tests [SCI-4516] --- .../inventory_checklist_items_controller.rb | 3 +- .../api/v1/inventory_list_items_controller.rb | 3 +- .../v1/inventory_status_items_controller.rb | 3 +- app/models/my_module.rb | 21 ++--- app/models/repository_checklist_value.rb | 3 +- app/models/repository_list_value.rb | 3 +- app/models/repository_status_item.rb | 2 +- app/models/repository_status_value.rb | 3 +- .../create_column_service.rb | 6 +- .../update_checklist_column_service.rb | 1 - .../update_list_column_service.rb | 1 - .../my_module_assigning_service.rb | 87 ++++++++----------- .../my_module_unassigning_service.rb | 10 +-- ...samples_to_repository_migration_service.rb | 8 +- app/utilities/first_time_data_generator.rb | 6 +- spec/factories/repository_checklist_items.rb | 3 +- spec/factories/repository_list_items.rb | 3 +- spec/factories/repository_status_items.rb | 1 - spec/models/my_module_repository_row_spec.rb | 5 -- spec/models/repository_checklist_item_spec.rb | 2 - spec/models/repository_list_item_spec.rb | 2 - spec/models/repository_list_value_spec.rb | 2 +- spec/models/repository_row_spec.rb | 2 +- spec/models/repository_spec.rb | 1 - spec/models/repository_status_item_spec.rb | 5 -- spec/models/repository_status_value_spec.rb | 2 +- .../api/v1/inventory_cells_controller_spec.rb | 29 ++----- ...ventory_checklist_items_controller_spec.rb | 6 +- .../v1/inventory_columns_controller_spec.rb | 6 +- .../api/v1/inventory_items_controller_spec.rb | 3 +- .../inventory_list_items_controller_spec.rb | 6 +- .../inventory_status_items_controller_spec.rb | 4 +- .../repository_actions/duplicate_rows_spec.rb | 1 - .../delete_column_service_spec.rb | 4 +- .../update_column_service_spec.rb | 4 +- .../update_list_column_service_spec.rb | 4 +- .../repository_datatable_service_spec.rb | 1 - spec/services/repository_zip_export_spec.rb | 4 +- 38 files changed, 89 insertions(+), 171 deletions(-) diff --git a/app/controllers/api/v1/inventory_checklist_items_controller.rb b/app/controllers/api/v1/inventory_checklist_items_controller.rb index 999a69486..28b4d8469 100644 --- a/app/controllers/api/v1/inventory_checklist_items_controller.rb +++ b/app/controllers/api/v1/inventory_checklist_items_controller.rb @@ -67,8 +67,7 @@ module Api params.require(:data).require(:attributes) params.permit(data: { attributes: %i(data) })[:data].merge( created_by: @current_user, - last_modified_by: @current_user, - repository: @inventory + last_modified_by: @current_user ) end diff --git a/app/controllers/api/v1/inventory_list_items_controller.rb b/app/controllers/api/v1/inventory_list_items_controller.rb index 0bff724cb..c4b87bff2 100644 --- a/app/controllers/api/v1/inventory_list_items_controller.rb +++ b/app/controllers/api/v1/inventory_list_items_controller.rb @@ -71,8 +71,7 @@ module Api params.require(:data).require(:attributes) params.permit(data: { attributes: %i(data) })[:data].merge( created_by: @current_user, - last_modified_by: @current_user, - repository: @inventory + last_modified_by: @current_user ) end diff --git a/app/controllers/api/v1/inventory_status_items_controller.rb b/app/controllers/api/v1/inventory_status_items_controller.rb index 8e36adad7..ccd0675c3 100644 --- a/app/controllers/api/v1/inventory_status_items_controller.rb +++ b/app/controllers/api/v1/inventory_status_items_controller.rb @@ -61,8 +61,7 @@ module Api params.require(:data).require(:attributes) params.permit(data: { attributes: %i(status icon) })[:data].merge( created_by: @current_user, - last_modified_by: @current_user, - repository: @inventory + last_modified_by: @current_user ) end diff --git a/app/models/my_module.rb b/app/models/my_module.rb index b0f44fb3e..875116180 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -40,21 +40,12 @@ class MyModule < ApplicationRecord has_many :my_module_tags, inverse_of: :my_module, dependent: :destroy has_many :tags, through: :my_module_tags has_many :task_comments, foreign_key: :associated_id, dependent: :destroy - has_many :inputs, - class_name: 'Connection', - foreign_key: 'input_id', - inverse_of: :to, - dependent: :destroy - has_many :outputs, - class_name: 'Connection', - foreign_key: 'output_id', - inverse_of: :from, - dependent: :destroy - has_many :my_modules, through: :outputs, source: :to - has_many :my_module_antecessors, - through: :inputs, - source: :from, - class_name: 'MyModule' + + has_many :inputs, class_name: 'Connection', foreign_key: 'input_id', inverse_of: :to, dependent: :destroy + has_many :outputs, class_name: 'Connection', foreign_key: 'output_id', inverse_of: :from, dependent: :destroy + has_many :my_modules, through: :outputs, source: :to, class_name: 'MyModule' + has_many :my_module_antecessors, through: :inputs, source: :from, class_name: 'MyModule' + has_many :sample_my_modules, inverse_of: :my_module, dependent: :destroy diff --git a/app/models/repository_checklist_value.rb b/app/models/repository_checklist_value.rb index f6bd915f4..cded875af 100644 --- a/app/models/repository_checklist_value.rb +++ b/app/models/repository_checklist_value.rb @@ -83,8 +83,7 @@ class RepositoryChecklistValue < ApplicationRecord if checklist_item.blank? checklist_item = column.repository_checklist_items.new(data: text, created_by: value.created_by, - last_modified_by: value.last_modified_by, - repository: column.repository) + last_modified_by: value.last_modified_by) return nil unless checklist_item.save end diff --git a/app/models/repository_list_value.rb b/app/models/repository_list_value.rb index bd7df2c91..b99b08345 100644 --- a/app/models/repository_list_value.rb +++ b/app/models/repository_list_value.rb @@ -73,8 +73,7 @@ class RepositoryListValue < ApplicationRecord if list_item.blank? list_item = column.repository_list_items.new(data: text, created_by: value.created_by, - last_modified_by: value.last_modified_by, - repository: column.repository) + last_modified_by: value.last_modified_by) return nil unless list_item.save end diff --git a/app/models/repository_status_item.rb b/app/models/repository_status_item.rb index 3b6ee3e56..0a5fef8f8 100644 --- a/app/models/repository_status_item.rb +++ b/app/models/repository_status_item.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class RepositoryStatusItem < ApplicationRecord - validates :repository, :repository_column, :icon, presence: true + validates :repository_column, :icon, presence: true validates :status, presence: true, length: { minimum: Constants::NAME_MIN_LENGTH, maximum: Constants::NAME_MAX_LENGTH } belongs_to :repository_column diff --git a/app/models/repository_status_value.rb b/app/models/repository_status_value.rb index 1751ba8a6..adaf72475 100644 --- a/app/models/repository_status_value.rb +++ b/app/models/repository_status_value.rb @@ -69,8 +69,7 @@ class RepositoryStatusValue < ApplicationRecord status_item = column.repository_status_items.new(icon: icon, status: status, created_by: value.created_by, - last_modified_by: value.last_modified_by, - repository: column.repository) + last_modified_by: value.last_modified_by) return nil unless status_item.save end diff --git a/app/services/repository_columns/create_column_service.rb b/app/services/repository_columns/create_column_service.rb index cea9f3cb1..f2de883bf 100644 --- a/app/services/repository_columns/create_column_service.rb +++ b/app/services/repository_columns/create_column_service.rb @@ -26,15 +26,15 @@ module RepositoryColumns def column_attributes @params[:repository_status_items_attributes]&.map do |m| - m.merge!(repository_id: @repository.id, created_by_id: @user.id, last_modified_by_id: @user.id) + m.merge!(created_by_id: @user.id, last_modified_by_id: @user.id) end @params[:repository_list_items_attributes]&.map do |m| - m.merge!(repository_id: @repository.id, created_by_id: @user.id, last_modified_by_id: @user.id) + m.merge!(created_by_id: @user.id, last_modified_by_id: @user.id) end @params[:repository_checklist_items_attributes]&.map do |m| - m.merge!(repository_id: @repository.id, created_by_id: @user.id, last_modified_by_id: @user.id) + m.merge!(created_by_id: @user.id, last_modified_by_id: @user.id) end @params.merge(repository_id: @repository.id, created_by_id: @user.id, data_type: @column_type) diff --git a/app/services/repository_columns/update_checklist_column_service.rb b/app/services/repository_columns/update_checklist_column_service.rb index 7fbee82bb..38ac6ceb4 100644 --- a/app/services/repository_columns/update_checklist_column_service.rb +++ b/app/services/repository_columns/update_checklist_column_service.rb @@ -35,7 +35,6 @@ module RepositoryColumns to_be_created.each do |item| RepositoryChecklistItem.create!( - repository: @repository, repository_column: @column, data: item, created_by: @user, diff --git a/app/services/repository_columns/update_list_column_service.rb b/app/services/repository_columns/update_list_column_service.rb index 6dceb9315..de8e2e842 100644 --- a/app/services/repository_columns/update_list_column_service.rb +++ b/app/services/repository_columns/update_list_column_service.rb @@ -35,7 +35,6 @@ module RepositoryColumns to_be_created.each do |item| RepositoryListItem.create!( - repository: @repository, repository_column: @column, data: item, created_by: @user, diff --git a/app/services/repository_rows/my_module_assigning_service.rb b/app/services/repository_rows/my_module_assigning_service.rb index c1bc175d0..214d01745 100644 --- a/app/services/repository_rows/my_module_assigning_service.rb +++ b/app/services/repository_rows/my_module_assigning_service.rb @@ -11,58 +11,20 @@ module RepositoryRows @repository = repository @user = user @params = params - @assigned_rows_names = [] + @assigned_rows_names = Set[] @errors = {} end def call return self unless valid? - downstream_modules = [] - downstream_records = {} - ActiveRecord::Base.transaction do - unassigned_rows = @repository.repository_rows - .joins("LEFT OUTER JOIN my_module_repository_rows "\ - "ON repository_rows.id = my_module_repository_rows.repository_row_id "\ - "AND my_module_repository_rows.my_module_id = #{@my_module.id.to_i}") - .where(my_module_repository_rows: { id: nil }) - .where(id: @params[:selected_rows]) - - unassigned_rows.find_each do |repository_row| - MyModuleRepositoryRow.create!(my_module: @my_module, repository_row: repository_row, assigned_by: @user) - @assigned_rows_names << repository_row.name - - next unless @params[:downstream] == 'true' - - unassigned_downstream_modules = @my_module.downstream_modules - .left_outer_joins(:my_module_repository_rows) - .where.not(my_module_repository_rows: { repository_row: record }) - - unassigned_downstream_modules.each do |downstream_module| - next if my_module.repository_rows.include?(repository_row) - - downstream_records[my_module.id] = [] unless downstream_records[downstream_module.id] - MyModuleRepositoryRow.create!( - my_module: downstream_module, - repository_row: repository_row, - assigned_by: @user - ) - downstream_records[downstream_module.id] << repository_row.name - downstream_modules.push(downstream_module) - end - - if @assigned_rows_names.present? - @assigned_rows_names.uniq! - log_activity(@my_module, - repository: @repository.id, - record_names: @assigned_rows_names.join(', ')) - downstream_modules.uniq.each do |downstream_module| - log_activity(downstream_module, - repository: @repository.id, - record_names: downstream_records[my_module.id].join(', ')) - end + if params[:downstream] == 'true' + @my_module.downstream_modules.each do |downstream_module| + assign_repository_rows_to_my_module(downstream_module) end + else + assign_repository_rows_to_my_module(@my_module) end rescue ActiveRecord::RecordInvalid => e @errors[e.record.class.name.underscore] = e.record.errors.full_messages @@ -78,16 +40,35 @@ module RepositoryRows private - def log_activity(my_module = nil, message_items = {}) - message_items = { my_module: my_module.id }.merge(message_items) + def assign_repository_rows_to_my_module(my_module) + assigned_names = [] + unassigned_rows = @repository.repository_rows + .joins("LEFT OUTER JOIN my_module_repository_rows "\ + "ON repository_rows.id = my_module_repository_rows.repository_row_id "\ + "AND my_module_repository_rows.my_module_id = #{my_module.id.to_i}") + .where(my_module_repository_rows: { id: nil }) + .where(id: @params[:selected_rows]) - Activities::CreateActivityService - .call(activity_type: :assign_repository_record, - owner: current_user, - team: my_module.experiment.project.team, - project: my_module.experiment.project, - subject: my_module, - message_items: message_items) + return [] unless unassigned_rows.any? + + unassigned_rows.find_each do |repository_row| + MyModuleRepositoryRow.create!(my_module: my_module, + repository_row: repository_row, + assigned_by: @user) + assigned_names << repository_row.name + end + + return [] if assigned_names.blank? + + Activities::CreateActivityService.call(activity_type: :assign_repository_record, + owner: @user, + team: my_module.experiment.project.team, + project: my_module.experiment.project, + subject: my_module, + message_items: { my_module: my_module.id, + repository: @repository.id, + record_names: assigned_names.join(', ') }) + @assigned_rows_names.merge(assigned_names) end def valid? diff --git a/app/services/repository_rows/my_module_unassigning_service.rb b/app/services/repository_rows/my_module_unassigning_service.rb index 16152ce47..c8e5dcd6e 100644 --- a/app/services/repository_rows/my_module_unassigning_service.rb +++ b/app/services/repository_rows/my_module_unassigning_service.rb @@ -11,7 +11,7 @@ module RepositoryRows @repository = repository @user = user @params = params - @unassigned_rows_names = [] + @unassigned_rows_names = Set[] @errors = {} end @@ -19,14 +19,14 @@ module RepositoryRows return self unless valid? ActiveRecord::Base.transaction do - @unassigned_rows_names = unassign_repository_rows_from_my_module(@my_module) - if params[:downstream] == 'true' @my_module.downstream_modules.each do |downstream_module| unassign_repository_rows_from_my_module(downstream_module) end + else + unassign_repository_rows_from_my_module(@my_module) end - rescue ActiveRecord::RecordInvalid => e + rescue StandardError => e @errors[e.record.class.name.underscore] = e.record.errors.full_messages raise ActiveRecord::Rollback end @@ -65,7 +65,7 @@ module RepositoryRows repository: @repository.id, record_names: unassigned_names.join(', ') }) - unassigned_names + @unassigned_rows_names.merge(unassigned_names) end def valid? diff --git a/app/services/tasks/samples_to_repository_migration_service.rb b/app/services/tasks/samples_to_repository_migration_service.rb index 0b15a6b65..4b2a3a2f8 100644 --- a/app/services/tasks/samples_to_repository_migration_service.rb +++ b/app/services/tasks/samples_to_repository_migration_service.rb @@ -83,7 +83,6 @@ module Tasks last_modified_by = item['last_modified_by_id'] || team.created_by_id timestamp = conn.quote(Time.now.to_s(:db)) values = [ - repository.id, sample_group.id, conn.quote(item.fetch('name') { "sample group item (#{index})" }), created_by, @@ -93,8 +92,7 @@ module Tasks ] list_item_sql = <<-SQL INSERT INTO repository_list_items - (repository_id, - repository_column_id, + (repository_column_id, data, created_by_id, last_modified_by_id, @@ -109,7 +107,6 @@ module Tasks last_modified_by = item['last_modified_by_id'] || team.created_by_id timestamp = conn.quote(Time.now.to_s(:db)) values = [ - repository.id, sample_type.id, conn.quote(item.fetch('name') { "sample type item (#{index})" }), created_by, @@ -119,8 +116,7 @@ module Tasks ] list_item_sql = <<-SQL INSERT INTO repository_list_items - (repository_id, - repository_column_id, + (repository_column_id, data, created_by_id, last_modified_by_id, diff --git a/app/utilities/first_time_data_generator.rb b/app/utilities/first_time_data_generator.rb index 16a623d6b..50d0cf2c0 100644 --- a/app/utilities/first_time_data_generator.rb +++ b/app/utilities/first_time_data_generator.rb @@ -75,8 +75,7 @@ module FirstTimeDataGenerator data: name, created_by: user, last_modified_by: user, - repository_column: repository_column_sample_types, - repository: repository + repository_column: repository_column_sample_types ) # Check if it already exists @@ -96,8 +95,7 @@ module FirstTimeDataGenerator data: name, created_by: user, last_modified_by: user, - repository_column: repository_column_sample_groups, - repository: repository + repository_column: repository_column_sample_groups ) # Check if it already exists diff --git a/spec/factories/repository_checklist_items.rb b/spec/factories/repository_checklist_items.rb index 29822f487..7d0e49659 100644 --- a/spec/factories/repository_checklist_items.rb +++ b/spec/factories/repository_checklist_items.rb @@ -3,8 +3,7 @@ FactoryBot.define do factory :repository_checklist_item do data { Faker::Lorem.paragraph } - repository - repository_column { create :repository_column, :checklist_type, repository: repository } + repository_column { create :repository_column, :checklist_type } created_by { create :user } last_modified_by { created_by } end diff --git a/spec/factories/repository_list_items.rb b/spec/factories/repository_list_items.rb index 8df714008..22d08ce9f 100644 --- a/spec/factories/repository_list_items.rb +++ b/spec/factories/repository_list_items.rb @@ -3,8 +3,7 @@ FactoryBot.define do factory :repository_list_item do data { Faker::Lorem.paragraph } - repository - repository_column { create :repository_column, :list_type, repository: repository } + repository_column { create :repository_column, :list_type } created_by { create :user } last_modified_by { created_by } end diff --git a/spec/factories/repository_status_items.rb b/spec/factories/repository_status_items.rb index 76c62f7a4..27cc2ae11 100644 --- a/spec/factories/repository_status_items.rb +++ b/spec/factories/repository_status_items.rb @@ -4,7 +4,6 @@ FactoryBot.define do factory :repository_status_item do sequence(:icon) { '😀' } sequence(:status) { |n| "status-#{n}" } - repository repository_column created_by { create :user } end diff --git a/spec/models/my_module_repository_row_spec.rb b/spec/models/my_module_repository_row_spec.rb index 99317c05a..5b794d864 100644 --- a/spec/models/my_module_repository_row_spec.rb +++ b/spec/models/my_module_repository_row_spec.rb @@ -27,9 +27,4 @@ describe MyModuleRepositoryRow, type: :model do it { should belong_to(:assigned_by).class_name('User').optional } it { should belong_to(:repository_row) } end - - describe 'Validations' do - it { should validate_presence_of :repository_row } - it { should validate_presence_of :my_module } - end end diff --git a/spec/models/repository_checklist_item_spec.rb b/spec/models/repository_checklist_item_spec.rb index 06c060db0..d52489dcc 100644 --- a/spec/models/repository_checklist_item_spec.rb +++ b/spec/models/repository_checklist_item_spec.rb @@ -15,14 +15,12 @@ RSpec.describe RepositoryChecklistItem, type: :model do describe 'Database table' do it { should have_db_column :data } - 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 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') } diff --git a/spec/models/repository_list_item_spec.rb b/spec/models/repository_list_item_spec.rb index f5fa000b3..985c127b3 100644 --- a/spec/models/repository_list_item_spec.rb +++ b/spec/models/repository_list_item_spec.rb @@ -15,7 +15,6 @@ RSpec.describe RepositoryListItem, type: :model do describe 'Database table' do it { should have_db_column :data } - 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 } @@ -23,7 +22,6 @@ RSpec.describe RepositoryListItem, type: :model do describe 'Relations' do 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') } diff --git a/spec/models/repository_list_value_spec.rb b/spec/models/repository_list_value_spec.rb index 188e0499f..0ed5ccbea 100644 --- a/spec/models/repository_list_value_spec.rb +++ b/spec/models/repository_list_value_spec.rb @@ -90,7 +90,7 @@ RSpec.describe RepositoryListValue, type: :model do let(:user) { create :user } let(:column) { create :repository_column } let(:cell) { build :repository_cell, repository_column: column } - let(:list_item) { create :repository_list_item, repository: column.repository, repository_column: column } + let(:list_item) { create :repository_list_item, repository_column: column } let(:attributes) do { repository_cell: cell, diff --git a/spec/models/repository_row_spec.rb b/spec/models/repository_row_spec.rb index a1b04db6f..aa95c8a2f 100644 --- a/spec/models/repository_row_spec.rb +++ b/spec/models/repository_row_spec.rb @@ -23,7 +23,7 @@ describe RepositoryRow, type: :model do end describe 'Relations' do - it { should belong_to(:repository).optional } + it { should belong_to(:repository) } it { should belong_to(:created_by).class_name('User') } it { should belong_to(:last_modified_by).class_name('User') } it { should have_many :repository_cells } diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index af62afce8..8f912b0bb 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -27,7 +27,6 @@ describe Repository, type: :model do it { should have_many :repository_rows } it { should have_many :repository_table_states } it { should have_many :report_elements } - it { should have_many(:repository_list_items).dependent(:destroy) } it { should have_many(:team_repositories).dependent(:destroy) } it { should have_many(:teams_shared_with) } end diff --git a/spec/models/repository_status_item_spec.rb b/spec/models/repository_status_item_spec.rb index b6a892bbf..a0708d379 100644 --- a/spec/models/repository_status_item_spec.rb +++ b/spec/models/repository_status_item_spec.rb @@ -10,10 +10,6 @@ describe RepositoryStatusItem do end describe 'Validations' do - describe '#repository' do - it { is_expected.to validate_presence_of(:repository) } - end - describe '#icon' do it { is_expected.to validate_presence_of(:icon) } end @@ -25,7 +21,6 @@ describe RepositoryStatusItem do end describe 'Associations' do - it { is_expected.to belong_to(:repository) } it { is_expected.to belong_to(:repository_column) } it { is_expected.to belong_to(:created_by).optional } it { is_expected.to belong_to(:last_modified_by).optional } diff --git a/spec/models/repository_status_value_spec.rb b/spec/models/repository_status_value_spec.rb index 8e2f799c1..056654e18 100644 --- a/spec/models/repository_status_value_spec.rb +++ b/spec/models/repository_status_value_spec.rb @@ -60,7 +60,7 @@ describe RepositoryStatusValue do let(:user) { create :user } let(:column) { create :repository_column } let(:cell) { build :repository_cell, repository_column: column } - let(:list_item) { create :repository_status_item, repository: column.repository, repository_column: column } + let(:list_item) { create :repository_status_item, repository_column: column } let(:attributes) do { repository_cell: cell, diff --git a/spec/requests/api/v1/inventory_cells_controller_spec.rb b/spec/requests/api/v1/inventory_cells_controller_spec.rb index 444642cbe..85c0d663a 100644 --- a/spec/requests/api/v1/inventory_cells_controller_spec.rb +++ b/spec/requests/api/v1/inventory_cells_controller_spec.rb @@ -10,38 +10,27 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do create(:user_team, user: @user, team: @team, role: 2) # valid_inventory - @valid_inventory = create(:repository, name: Faker::Name.unique.name, - created_by: @user, team: @team) + @valid_inventory = create(:repository, name: Faker::Name.unique.name, created_by: @user, team: @team) # unaccessable_inventory - @wrong_inventory = create(:repository, name: Faker::Name.unique.name, - created_by: @user, team: @wrong_team) + @wrong_inventory = create(:repository, name: Faker::Name.unique.name, created_by: @user, team: @wrong_team) + create(:repository_row, repository: @wrong_inventory) @text_column = create(:repository_column, name: Faker::Name.unique.name, repository: @valid_inventory, data_type: :RepositoryTextValue) @list_column = create(:repository_column, name: Faker::Name.unique.name, repository: @valid_inventory, data_type: :RepositoryListValue) - list_item = - create(:repository_list_item, repository: @valid_inventory, - repository_column: @list_column, data: Faker::Name.unique.name) - second_list_item = - create(:repository_list_item, repository: @valid_inventory, - repository_column: @list_column, data: Faker::Name.unique.name) + list_item = create(:repository_list_item, repository_column: @list_column, data: Faker::Name.unique.name) + second_list_item = create(:repository_list_item, repository_column: @list_column, data: Faker::Name.unique.name) @status_column = create(:repository_column, repository: @valid_inventory, data_type: :RepositoryStatusValue) - status_item = create(:repository_status_item, - repository: @valid_inventory, - repository_column: @status_column) - second_status_item = create(:repository_status_item, - repository: @valid_inventory, - repository_column: @status_column) + status_item = create(:repository_status_item, repository_column: @status_column) + second_status_item = create(:repository_status_item, repository_column: @status_column) @checklist_column = create(:repository_column, name: Faker::Name.unique.name, repository: @valid_inventory, data_type: :RepositoryChecklistValue) - checklist_items = - create_list(:repository_checklist_item, 3, repository: @valid_inventory, repository_column: @checklist_column) + checklist_items = create_list(:repository_checklist_item, 3, repository_column: @checklist_column) checklist_item = - create(:repository_checklist_item, repository: @valid_inventory, - repository_column: @checklist_column, data: Faker::Name.unique.name) + create(:repository_checklist_item, repository_column: @checklist_column, data: Faker::Name.unique.name) @file_column = create(:repository_column, name: Faker::Name.unique.name, repository: @valid_inventory, data_type: :RepositoryAssetValue) asset = create(:asset) diff --git a/spec/requests/api/v1/inventory_checklist_items_controller_spec.rb b/spec/requests/api/v1/inventory_checklist_items_controller_spec.rb index 2144bb59b..4287d82b5 100644 --- a/spec/requests/api/v1/inventory_checklist_items_controller_spec.rb +++ b/spec/requests/api/v1/inventory_checklist_items_controller_spec.rb @@ -24,10 +24,8 @@ RSpec.describe 'Api::V1::InventoryChecklistItemsController', type: :request do name: Faker::Name.unique.name, repository: @wrong_inventory, data_type: :RepositoryChecklistValue) - create_list(:repository_checklist_item, 10, repository: @valid_inventory, - repository_column: @checklist_column) - create(:repository_checklist_item, repository: @wrong_inventory, - repository_column: @wrong_checklist_column) + create_list(:repository_checklist_item, 10, repository_column: @checklist_column) + create(:repository_checklist_item, repository_column: @wrong_checklist_column) @valid_headers = { 'Authorization': 'Bearer ' + generate_token(@user.id) } diff --git a/spec/requests/api/v1/inventory_columns_controller_spec.rb b/spec/requests/api/v1/inventory_columns_controller_spec.rb index 6aef00ada..e926cfa18 100644 --- a/spec/requests/api/v1/inventory_columns_controller_spec.rb +++ b/spec/requests/api/v1/inventory_columns_controller_spec.rb @@ -20,12 +20,10 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do repository: @valid_inventory, data_type: :RepositoryTextValue) list_column = create(:repository_column, name: Faker::Name.unique.name, repository: @valid_inventory, data_type: :RepositoryListValue) - create(:repository_list_item, repository: @valid_inventory, - repository_column: list_column, data: Faker::Name.unique.name) + create(:repository_list_item, repository_column: list_column, data: Faker::Name.unique.name) status_column = create(:repository_column, name: Faker::Name.unique.name, repository: @valid_inventory, data_type: :RepositoryStatusValue) - create(:repository_status_item, repository: @valid_inventory, - repository_column: status_column, status: Faker::Name.unique.name, icon: 'icon') + create(:repository_status_item, repository_column: status_column, status: Faker::Name.unique.name, icon: 'icon') create(:repository_column, name: Faker::Name.unique.name, repository: @valid_inventory, data_type: :RepositoryAssetValue) diff --git a/spec/requests/api/v1/inventory_items_controller_spec.rb b/spec/requests/api/v1/inventory_items_controller_spec.rb index 8cdbea142..53dda8a16 100644 --- a/spec/requests/api/v1/inventory_items_controller_spec.rb +++ b/spec/requests/api/v1/inventory_items_controller_spec.rb @@ -21,8 +21,7 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do list_column = create(:repository_column, name: Faker::Name.unique.name, repository: @valid_inventory, data_type: :RepositoryListValue) list_item = - create(:repository_list_item, repository: @valid_inventory, - repository_column: list_column, data: Faker::Name.unique.name) + create(:repository_list_item, repository_column: list_column, data: Faker::Name.unique.name) file_column = create(:repository_column, name: Faker::Name.unique.name, repository: @valid_inventory, data_type: :RepositoryAssetValue) asset = create(:asset) diff --git a/spec/requests/api/v1/inventory_list_items_controller_spec.rb b/spec/requests/api/v1/inventory_list_items_controller_spec.rb index 92907cd87..c3ee56b38 100644 --- a/spec/requests/api/v1/inventory_list_items_controller_spec.rb +++ b/spec/requests/api/v1/inventory_list_items_controller_spec.rb @@ -24,10 +24,8 @@ RSpec.describe 'Api::V1::InventoryListItemsController', type: :request do name: Faker::Name.unique.name, repository: @wrong_inventory, data_type: :RepositoryListValue) - create_list(:repository_list_item, 10, repository: @valid_inventory, - repository_column: @list_column) - create(:repository_list_item, repository: @wrong_inventory, - repository_column: @wrong_list_column) + create_list(:repository_list_item, 10, repository_column: @list_column) + create(:repository_list_item, repository_column: @wrong_list_column) @valid_headers = { 'Authorization': 'Bearer ' + generate_token(@user.id) } diff --git a/spec/requests/api/v1/inventory_status_items_controller_spec.rb b/spec/requests/api/v1/inventory_status_items_controller_spec.rb index 81845253d..520381d85 100644 --- a/spec/requests/api/v1/inventory_status_items_controller_spec.rb +++ b/spec/requests/api/v1/inventory_status_items_controller_spec.rb @@ -12,12 +12,12 @@ RSpec.describe 'Api::V1::InventoryStatusItemsController', type: :request do @wrong_inventory = create(:repository, name: Faker::Name.unique.name, created_by: @user, team: @team2) @status_column = create(:repository_column, name: Faker::Name.unique.name, repository: @inventory, data_type: :RepositoryStatusValue) - create_list(:repository_status_item, 10, repository: @inventory, repository_column: @status_column) + create_list(:repository_status_item, 10, repository_column: @status_column) @list_column = create(:repository_column, name: Faker::Name.unique.name, repository: @inventory, data_type: :RepositoryListValue) @wrong_column = create(:repository_column, name: Faker::Name.unique.name, repository: @wrong_inventory, data_type: :RepositoryStatusValue) - @wrong_status_item = create(:repository_status_item, repository: @wrong_inventory, repository_column: @wrong_column) + @wrong_status_item = create(:repository_status_item, repository_column: @wrong_column) @valid_headers = { 'Authorization': 'Bearer ' + generate_token(@user.id) } end diff --git a/spec/services/repository_actions/duplicate_rows_spec.rb b/spec/services/repository_actions/duplicate_rows_spec.rb index 24f969caf..dbee10557 100644 --- a/spec/services/repository_actions/duplicate_rows_spec.rb +++ b/spec/services/repository_actions/duplicate_rows_spec.rb @@ -32,7 +32,6 @@ describe RepositoryActions::DuplicateRows do } create :repository_list_value, repository_list_item: create(:repository_list_item, - repository: repository, repository_column: list_column, data: "list item (#{index})"), repository_cell_attributes: { diff --git a/spec/services/repository_columns/delete_column_service_spec.rb b/spec/services/repository_columns/delete_column_service_spec.rb index 14714005b..5465f8698 100644 --- a/spec/services/repository_columns/delete_column_service_spec.rb +++ b/spec/services/repository_columns/delete_column_service_spec.rb @@ -27,7 +27,7 @@ describe RepositoryColumns::DeleteColumnService do context 'when RepositoryColumn has RepositoryListItems' do before do 3.times do - create(:repository_list_item, repository: repository, repository_column: repository_column) + create(:repository_list_item, repository_column: repository_column) end end @@ -39,7 +39,7 @@ describe RepositoryColumns::DeleteColumnService do context 'when RepositoryColumn has RepositoryStatusItems' do before do 3.times do - create(:repository_status_item, repository: repository, repository_column: repository_column) + create(:repository_status_item, repository_column: repository_column) end end diff --git a/spec/services/repository_columns/update_column_service_spec.rb b/spec/services/repository_columns/update_column_service_spec.rb index 698521346..9a152bb8d 100644 --- a/spec/services/repository_columns/update_column_service_spec.rb +++ b/spec/services/repository_columns/update_column_service_spec.rb @@ -8,7 +8,7 @@ describe RepositoryColumns::UpdateColumnService do let(:team) { create :team } let(:repository) { create :repository, team: team } let(:column) { create :repository_column, :status_type } - let(:status_item) { create(:repository_status_item, repository: repository, repository_column: column) } + let(:status_item) { create(:repository_status_item, repository_column: column) } let(:service_call) do RepositoryColumns::UpdateColumnService.call(column: column, user: user, @@ -80,7 +80,7 @@ describe RepositoryColumns::UpdateColumnService do context 'when updates column\'s list items' do let(:column) { create :repository_column, :list_type } - let(:list_item) { create(:repository_list_item, repository: repository, repository_column: column) } + let(:list_item) { create(:repository_list_item, repository_column: column) } let(:params) do { diff --git a/spec/services/repository_columns/update_list_column_service_spec.rb b/spec/services/repository_columns/update_list_column_service_spec.rb index 8568d60f5..b5e84459a 100644 --- a/spec/services/repository_columns/update_list_column_service_spec.rb +++ b/spec/services/repository_columns/update_list_column_service_spec.rb @@ -8,7 +8,7 @@ describe RepositoryColumns::UpdateListColumnService do let(:team) { create :team } let(:repository) { create :repository, team: team } let(:column) { create :repository_column, :list_type } - let(:list_item) { create(:repository_list_item, repository: repository, repository_column: column) } + let(:list_item) { create(:repository_list_item, repository_column: column) } let(:service_call) do RepositoryColumns::UpdateListColumnService.call(column: column, user: user, @@ -32,7 +32,7 @@ describe RepositoryColumns::UpdateListColumnService do context 'when changing list items' do let(:column) { create :repository_column, :list_type } - let(:list_item) { create(:repository_list_item, repository: repository, repository_column: column) } + let(:list_item) { create(:repository_list_item, repository_column: column) } context 'when adding list item' do let(:params) do diff --git a/spec/services/repository_datatable_service_spec.rb b/spec/services/repository_datatable_service_spec.rb index 111f3380b..a9ff67eaf 100644 --- a/spec/services/repository_datatable_service_spec.rb +++ b/spec/services/repository_datatable_service_spec.rb @@ -34,7 +34,6 @@ describe RepositoryDatatableService do let!(:list_item) do create :repository_list_item, data: 'bug', - repository: repository, repository_column: repository_column, created_by: user, last_modified_by: user diff --git a/spec/services/repository_zip_export_spec.rb b/spec/services/repository_zip_export_spec.rb index 8e5699810..bd08a2367 100644 --- a/spec/services/repository_zip_export_spec.rb +++ b/spec/services/repository_zip_export_spec.rb @@ -15,9 +15,7 @@ describe RepositoryZipExport, type: :background_job do data_type: 'RepositoryListValue' end let!(:repository_list_item) do - create :repository_list_item, data: 'item one', - repository: repository, - repository_column: sample_group_column + create :repository_list_item, data: 'item one', repository_column: sample_group_column end let!(:custom_column) do create :repository_column, repository: repository,