Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
changed to scoped call with default being active
  • Loading branch information
wimo7083
wimo7083 committed Oct 5, 2018
commit f6de002c40db05298ddbe32b9bccb02353e884d7
2 changes: 1 addition & 1 deletion app/controllers/api/v1/jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Api
module V1
class JobsController < ApiController
def index
render json: Job.all, status: :ok
render json: Job.is_open, status: :ok
rescue StandardError => e
render json: { errors: e.message }, status: :unprocessable_entity
end
Expand Down
4 changes: 3 additions & 1 deletion app/models/job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class Job < ApplicationRecord

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does having this in the models section of the code base make it clear enough that this is separate from Sidekiq Jobs?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, yes. Though, it might be helpful to rename the background jobs from Job(s) to Worker(s).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you don't want JobJobs?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you mention it, maybe WorkJobber.

acts_as_taggable

scope :is_available, -> { where(is_open: true) }
scope :is_open, -> { where(closed_at: nil) }
scope :is_closed, -> { where.not(closed_at: nil) }

def self.with_tags(*args)
tagged_with(args, any: true)
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20180531004341_create_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def change
t.string :state
t.string :country
t.text :description
t.boolean :is_open, default: true
t.datetime :closed_at, default: nil
t.boolean :remote, default: false

t.timestamps
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
t.string "state"
t.string "country"
t.text "description"
t.boolean "is_open", default: true
t.datetime "closed_at", default: nil
t.boolean "remote", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
Expand Down
2 changes: 1 addition & 1 deletion test/factories/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
state Faker::Address.state
country Faker::Address.country
description Faker::Lorem.paragraph

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the attributes being set above this comment should get assigned with block to evaluate the Faker data lazily each time the factory is used instead of at test load time. Otherwise all jobs created with this factory will have the same values.

e.g. title { Faker::Lorem.characters(7) }

is_open true
closed_at nil
remote false
end
end