Revert scrope

This commit is contained in:
Urban Rotnik 2020-06-24 11:22:28 +02:00
parent 8dc48e9f95
commit 2f4bf95373
4 changed files with 10 additions and 62 deletions

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -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 }