Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Issue365 add jobs #366

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
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
100 changes: 54 additions & 46 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,100 +1,108 @@
RAILS_CONTAINER := web
DOCKER := docker
DOCKER_COMPOSE := docker-compose
include Makefile.in

.PHONY: all
all: run

.PHONY: nuke
nuke:
${DOCKER} system prune -a --volumes

.PHONY: minty-fresh
minty-fresh:
${DOCKER_COMPOSE} down --rmi all --volumes

.PHONY: rmi
rmi:
${DOCKER} images -q | xargs docker rmi -f

.PHONY: rmdi
rmdi:
${DOCKER} images -a --filter=dangling=true -q | xargs ${DOCKER} rmi

.PHONY: rm-exited-containers
rm-exited-containers:
${DOCKER} ps -a -q -f status=exited | xargs ${DOCKER} rm -v
.PHONY: setup
setup: build db_create db_migrate

.PHONY: fresh-restart
fresh-restart: minty-fresh setup test run
.PHONY: console
console:
$(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rails console

.PHONY: console-sandbox
console-sandbox:
docker-compose run ${RAILS_CONTAINER} rails console --sandbox
$(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rails console --sandbox


#### Utility
.PHONY: run
run:
docker-compose up --build
$(DOCKER_COMPOSE) up --build

.PHONY: bg
bg:
docker-compose up --build -d
$(DOCKER_COMPOSE) up --build -d

.PHONY: open
open:
open http://localhost:3000

.PHONY: build
build:
docker-compose build

.PHONY: console
console:
docker-compose run ${RAILS_CONTAINER} rails console
$(DOCKER_COMPOSE) build

.PHONY: routes
routes:
docker-compose run ${RAILS_CONTAINER} rake routes
$(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake routes

.PHONY: bundle
bundle:
$(DOCKER_COMPOSE) run $(RAILS_CONTAINER) bash -c 'cd /app && bundle'

#### Database
.PHONY: db_create
db_create:
docker-compose run ${RAILS_CONTAINER} rake db:create
$(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake db:create

.PHONY: db_migrate
db_migrate:
docker-compose run ${RAILS_CONTAINER} rake db:migrate
$(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake db:migrate

.PHONY: db_status
db_status:
docker-compose run ${RAILS_CONTAINER} rake db:migrate:status
$(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake db:migrate:status

.PHONY: db_rollback
db_rollback:
docker-compose run ${RAILS_CONTAINER} rake db:rollback
$(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake db:rollback

.PHONY: db_seed
db_seed:
docker-compose run ${RAILS_CONTAINER} rake db:seed
$(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake db:seed

#### Tests and Linting
.PHONY: test
test: bg
docker-compose run operationcode-psql bash -c "while ! psql --host=operationcode-psql --username=postgres -c 'SELECT 1'; do sleep 5; done;"
docker-compose run ${RAILS_CONTAINER} bash -c 'export RAILS_ENV=test && rake db:test:prepare && rake test && rubocop'
$(DOCKER_COMPOSE) run operationcode-psql bash -c "while ! psql --host=operationcode-psql --username=postgres -c 'SELECT 1'; do sleep 5; done;"
Copy link
Member

Choose a reason for hiding this comment

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

I'm starting to feel odd about this.

As this gets bigger it should really be things in their own target, or in a bash script. Large makefiles with lots of distractions are hard to understand. Plus hiding tests behind a very long bash script means I can't pass in parameters to run test groups.

$(DOCKER_COMPOSE) run $(RAILS_CONTAINER) bash -c 'export RAILS_ENV=test && rake db:test:prepare && rake test || echo -e "$(RED)Unit tests have failed$(NC)" '
$(DOCKER_COMPOSE) run $(RAILS_CONTAINER) bash -c 'rubocop' || echo -e "$(RED)Linting has failed$(NC)"

.PHONY: rubocop
rubocop:
docker-compose run ${RAILS_CONTAINER} rubocop
$(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rubocop

.PHONY: rubocop_auto_correct
rubocop_auto_correct:
docker-compose run ${RAILS_CONTAINER} rubocop -a --auto-correct
$(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rubocop -a --auto-correct

.PHONY: bundle
bundle:
docker-compose run ${RAILS_CONTAINER} bash -c 'cd /app && bundle'

setup: build db_create db_migrate
#### Cleanup
.PHONY: nuke
nuke:
$(DOCKER) system prune -a --volumes

.PHONY: minty-fresh
minty-fresh:
$(DOCKER_COMPOSE) down --rmi all --volumes

.PHONY: rmi
rmi:
$(DOCKER) images -q | xargs docker rmi -f

.PHONY: rmdi
rmdi:
$(DOCKER) images -a --filter=dangling=true -q | xargs $(DOCKER) rmi

.PHONY: rm-exited-containers
rm-exited-containers:
$(DOCKER) ps -a -q -f status=exited | xargs $(DOCKER) rm -v

.PHONY: fresh-restart
fresh-restart: minty-fresh setup test run


#### Deployment
publish: build
bin/publish

Expand Down
10 changes: 10 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RAILS_CONTAINER:= web
DOCKER_COMPOSE:= docker-compose
DOCKER:= docker
RED=\033[0;31m
GREEN=\032[0;32m
NC=\033[0m


.DELETE_ON_ERROR:
.SILENT:
29 changes: 29 additions & 0 deletions apiary.apib
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,35 @@ API endpoints that Operation Code's Rails backend makes available to its React f
errors: "Some error message"
}

## Jobs | Collection [/api/v1/jobs]

## List all Jobs [GET]

+ Response 200 (application/json)

[
{
"id": 1,
"title": "A great job",
"source_url": "www.applyhere.com",
"source": "Company A",
"city": "Virginia Beach",
"state": "VA",
"country": "USA",
"description": "Our job is fun!",
"is_open": false,
"remote": false,
"created_at": "2018-06-01T16:21:59.462Z",
"updated_at": "2018-06-01T16:21:59.462Z"
}
]

+ Response 422 (application/json)

{
errors: "Some error message"
}


## Location | Create [/api/v1/code_schools/:code_school_id/locations{?code_school_id,va_accepted,address1,address2,city,state,zip}]

Expand Down
36 changes: 36 additions & 0 deletions app/admin/job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ActiveAdmin.register Job do
permit_params :title, :source_url, :source, :city, :state, :country, :description, :is_open, :remote

index do
selectable_column
id_column

column :title
column :source_url
column :source
column :city
column :state
column :country
column :description
column :is_open
column :remote

actions
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you pls add a form for creating/updating. Here is an example:

https://github.com/OperationCode/operationcode_backend/blob/master/app/admin/code_school.rb#L28-L45

Copy link
Collaborator Author

@leenyburger leenyburger Jun 4, 2018

Choose a reason for hiding this comment

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

When I add the form and try to add a job I get the following error: "

"exception": "#<ActionView::Template::Error: To use the :country input, please install a country_select plugin, like this one: https://github.com/stefanpenner/country_select>",

Should I install that gem, or are we already using something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

@hpjaj I don't see where you responded here. If @leenyburger issue has been addressed, disregard just getting visibility.


form do |f|
f.inputs do
f.input :title
f.input :source_url
f.input :source
f.input :city
f.input :state
f.input :country
f.input :description
f.input :is_open
f.input :remote
end

f.actions
end
end
11 changes: 11 additions & 0 deletions app/controllers/api/v1/jobs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Api
module V1
class JobsController < ApiController
def index
render json: Job.is_open, status: :ok
rescue StandardError => e
render json: { errors: e.message }, status: :unprocessable_entity
end
end
end
end
10 changes: 10 additions & 0 deletions app/models/job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Job < ApplicationRecord
Copy link
Member

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
Collaborator

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

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_open, -> { where(closed_at: nil) }
scope :is_closed, -> { where.not(closed_at: nil) }

def self.with_tags(*args)
tagged_with(args, any: true)
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
end
resources :email_list_recipients, only: :create
resources :events, only: :index
resources :jobs, only: :index
resources :mentors, only: [:index, :create, :show]
resources :requests, only: [:index, :create, :show, :update]
resources :resources, only: [:index, :create, :show, :update, :destroy] do
Expand Down
17 changes: 17 additions & 0 deletions db/migrate/20180531004341_create_jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreateJobs < ActiveRecord::Migration[5.0]
def change
create_table :jobs do |t|
t.string :title
t.string :source_url
t.string :source
t.string :city
t.string :state
t.string :country
t.text :description
t.datetime :closed_at, default: nil
t.boolean :remote, default: false

t.timestamps
end
end
end
14 changes: 14 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@
t.index ["user_id"], name: "index_git_hub_users_on_user_id", using: :btree
end

create_table "jobs", force: :cascade do |t|
t.string "title"
t.string "source_url"
t.string "source"
t.string "city"
t.string "state"
t.string "country"
t.text "description"
t.datetime "closed_at", default: nil
t.boolean "remote", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "locations", force: :cascade do |t|
t.boolean "va_accepted"
t.string "address1"
Expand Down
6 changes: 6 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
TeamMember.destroy_all
AdminUser.destroy_all
Role.destroy_all
Job.destroy_all

FactoryGirl.create(:user)
FactoryGirl.create(:user)
Expand All @@ -31,6 +32,9 @@
Service.create!(:name => service)
end

Copy link
Collaborator

Choose a reason for hiding this comment

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

# Create jobs
Job.create!(title: "A great job", source_url: "www.applyhere.com", source: "Company A", city: "Virginia Beach", state: "VA", country: "USA", description: "Our job is fun!", is_open: true, remote: false)

# Create team members
Copy link
Collaborator

Choose a reason for hiding this comment

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

SeedTeamMembers.seed_all

Expand All @@ -53,6 +57,7 @@
admin_users = AdminUser.count
scholarship_count = Scholarship.count
scholarship_app = ScholarshipApplication.count
jobs = Job.count

puts 'Seeding complete. Created:'
p "#{users} users"
Expand All @@ -62,3 +67,4 @@
p "#{admin_users} admin users"
p "#{scholarship_count} scholarships"
p "#{scholarship_app} scholarship applications"
p "#{jobs} jobs"
16 changes: 16 additions & 0 deletions test/controllers/api/v1/jobs_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'test_helper'

class Api::V1::JobsControllerTest < ActionDispatch::IntegrationTest
test 'index endpoint should return job parameters in JSON format' do
jobs = []
5.times do
jobs << create(:job)
end
get api_v1_jobs_url, as: :json
i = 0
response.parsed_body.each do |response|
assert_equal true, response['title'] == jobs[i].title
i += 1
end
end
end
13 changes: 13 additions & 0 deletions test/factories/jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FactoryGirl.define do
factory :job do
title Faker::Lorem.characters(7)
source_url Faker::Internet.url
source Faker::Lorem.characters(7)
city Faker::Address.city
state Faker::Address.state
country Faker::Address.country
description Faker::Lorem.paragraph
Copy link
Collaborator

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

closed_at nil
remote false
end
end
17 changes: 17 additions & 0 deletions test/models/job_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'test_helper'

class JobTest < ActiveSupport::TestCase
setup do
@job = create :job
end

test 'should be valid' do
assert @job.valid?
end

test '.with_tags returns job with tag' do
@job.tag_list.add('front-end')
@job.save!
assert_equal Job.with_tags('front-end'), [@job]
end
end