From 6a2825cbfa14af84b40a377a04225d91255ab3e3 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Mon, 15 Apr 2024 11:00:30 -0500 Subject: [PATCH] Simplify status scope and use it consistently --- app/controllers/v1/docs_controller.rb | 4 ++-- app/models/purl.rb | 2 +- app/models/statistics.rb | 8 ++++---- spec/models/purl_spec.rb | 10 ++-------- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/controllers/v1/docs_controller.rb b/app/controllers/v1/docs_controller.rb index e335dd06..7e5f8968 100644 --- a/app/controllers/v1/docs_controller.rb +++ b/app/controllers/v1/docs_controller.rb @@ -9,7 +9,7 @@ def stats # API call to get a full list of all purls modified between two times def changes @changes = Purl.published - .where(deleted_at: nil) + .status('public') .where(updated_at: @first_modified..@last_modified) .target(params[:target]) .includes(:collections, :release_tags) @@ -20,7 +20,7 @@ def changes # API call to get a full list of all purl deletes between two times def deletes @deletes = Purl.where(updated_at: @first_modified..@last_modified) - .where.not(deleted_at: nil) + .status('deleted') .target(params[:target]) .page(page_params[:page]) .per(per_page_params[:per_page]) diff --git a/app/models/purl.rb b/app/models/purl.rb index bdcec84d..07b49537 100644 --- a/app/models/purl.rb +++ b/app/models/purl.rb @@ -21,7 +21,7 @@ class Purl < ApplicationRecord } scope :status, lambda { |status| - case status['status'] + case status when 'deleted' where.not deleted_at: nil when 'public' diff --git a/app/models/statistics.rb b/app/models/statistics.rb index 7ddc81ca..913f0700 100644 --- a/app/models/statistics.rb +++ b/app/models/statistics.rb @@ -4,12 +4,12 @@ def published end def deleted - Purl.status('status' => 'deleted').count + Purl.status('deleted').count end def changes Purl.published - .where(deleted_at: nil) + .status('public') .count end @@ -18,7 +18,7 @@ def deletes end def histogram - collect_histogram_data(Purl.published.where(deleted_at: nil)) + collect_histogram_data(Purl.published.status('public')) end def release_tags @@ -48,7 +48,7 @@ def collect_histogram_data(target) def released_to_searchworks @released_to_searchworks ||= Purl.published - .where(deleted_at: nil) + .status('public') .target('Searchworks') .where('release_tags.release_type=?', true) end diff --git a/spec/models/purl_spec.rb b/spec/models/purl_spec.rb index 5dd8dee3..03b27909 100644 --- a/spec/models/purl_spec.rb +++ b/spec/models/purl_spec.rb @@ -60,23 +60,17 @@ describe '.status' do context 'when passed "deleted"' do it 'returns objects that have been deleted' do - objects = described_class.status('status' => 'deleted') + objects = described_class.status('deleted') expect(objects.count).to eq 3 end end context 'when passed "collection"' do it 'returns objects that are still public' do - objects = described_class.status('status' => 'public') + objects = described_class.status('public') expect(objects.count).to eq 5 end end - - context 'anything else' do - it 'returns everything' do - expect(described_class.status('yolo').count).to eq described_class.all.count - end - end end describe '.target' do