diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index f77db1557..0742342cf 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -21,12 +21,13 @@ class RepositoryRowsController < ApplicationController @all_rows_count = datatable_service.all_count @columns_mappings = datatable_service.mappings @repository_rows = datatable_service.repository_rows - .where(archived: (params[:archived] || false)) .preload(:repository_columns, :created_by, repository_cells: @repository.cell_preload_includes) .page(page) .per(per_page) + + @repository_rows = @repository_rows.where(archived: params[:archived]) unless @repository.archived? end def create diff --git a/app/models/repository_row.rb b/app/models/repository_row.rb index fbc550d70..49032962b 100644 --- a/app/models/repository_row.rb +++ b/app/models/repository_row.rb @@ -30,14 +30,8 @@ class RepositoryRow < ApplicationRecord length: { maximum: Constants::NAME_MAX_LENGTH } validates :created_by, presence: true - scope :active, lambda { - joins(:repository) - .where('repositories.archived = FALSE AND repository_rows.archived = FALSE') - } - scope :archived, lambda { - joins(:repository) - .where('repositories.archived = TRUE OR repository_rows.archived = TRUE') - } + scope :active, -> { where(archived: false) } + scope :archived, -> { where(archived: true) } def self.viewable_by_user(user, teams) where(repository: Repository.viewable_by_user(user, teams)) diff --git a/spec/controllers/repository_rows_controller_spec.rb b/spec/controllers/repository_rows_controller_spec.rb index e1132bd07..10d4bf671 100644 --- a/spec/controllers/repository_rows_controller_spec.rb +++ b/spec/controllers/repository_rows_controller_spec.rb @@ -84,7 +84,8 @@ describe RepositoryRowsController, type: :controller do search: { value: '' }, length: '10', start: '1', - repository_id: repository.id } + repository_id: repository.id, + archived: false } get :index, params: params, format: :json response_body = JSON.parse(response.body) expect(response_body['data'].length).to eq 10 @@ -97,7 +98,8 @@ describe RepositoryRowsController, type: :controller do search: { value: '' }, length: '10', start: '11', - repository_id: repository.id } + repository_id: repository.id, + archived: false } get :index, params: params, format: :json response_body = JSON.parse(response.body) expect(response_body['data'].length).to eq 10 @@ -110,7 +112,8 @@ describe RepositoryRowsController, type: :controller do search: { value: '' }, length: '25', start: '1', - repository_id: repository.id } + repository_id: repository.id, + archived: false } get :index, params: params, format: :json response_body = JSON.parse(response.body) expect(response_body['data'].length).to eq 25 diff --git a/spec/models/repository_row_spec.rb b/spec/models/repository_row_spec.rb index 15c1a931e..a1e145eb0 100644 --- a/spec/models/repository_row_spec.rb +++ b/spec/models/repository_row_spec.rb @@ -43,56 +43,6 @@ describe RepositoryRow, type: :model do end end - describe 'Scopes' do - describe '.archived' do - before do - create :repository_row, repository: repository - create :repository_row, repository: repository - create :repository_row, :archived, repository: repository - end - - context 'when repository is active' do - let(:repository) { create :repository } - - it 'includes only archived rows within active repository' do - expect(repository.repository_rows.archived.count).to be_eql(1) - end - end - - context 'when repository is archived' do - let(:repository) { create :repository, :archived } - - it 'includes all rows within archived repository' do - expect(repository.repository_rows.archived.count).to be_eql(3) - end - end - end - - describe '.active' do - before do - create :repository_row, repository: repository - create :repository_row, repository: repository - create :repository_row, :archived, repository: repository - end - - context 'when repository is active' do - let(:repository) { create :repository } - - it 'includes only active rows from active repository scope' do - expect(repository.repository_rows.active.count).to be_eql(2) - end - end - - context 'when repository is archived' do - let(:repository) { create :repository, :archived } - - it 'includes 0 rows from archived repository' do - expect(repository.repository_rows.active.count).to be_eql(0) - end - end - end - end - describe '.archived' do context 'when archived' do let(:repository_row) { build :repository_row, :archived }