Skip to content

Commit

Permalink
Merge pull request #65 from sandbergja/distinct_employers
Browse files Browse the repository at this point in the history
Don't duplicate employers in the employer listings, helps with #63
  • Loading branch information
cbeer authored Apr 11, 2022
2 parents fc42d3c + 4d208cc commit 1383ebe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/employer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Employer < ApplicationRecord

default_scope { order(name: :asc) }

scope :with_published_jobs, -> { joins(:jobs).where(jobs: { published: true }) }
scope :with_published_jobs, -> { joins(:jobs).where(jobs: { published: true }).distinct }

validates :name, presence: true

Expand Down
6 changes: 5 additions & 1 deletion spec/models/employer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require 'rails_helper'

RSpec.describe Employer, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
it 'uses distinct when listing employers' do
employer = described_class.create name: 'The Library'
(1..5).each { |job| Job.create employer: employer, title: job, description: job, job_type: job, published: true }
expect(described_class.with_published_jobs.count).to eq(1)
end
end

0 comments on commit 1383ebe

Please sign in to comment.