Skip to content

Commit

Permalink
Simplify status scope and use it consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Apr 15, 2024
1 parent 2cd0b75 commit 6a2825c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/controllers/v1/docs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion app/models/purl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions app/models/statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions spec/models/purl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a2825c

Please sign in to comment.