From ada2703584b1af9325ec88aa48b3d11f56a24011 Mon Sep 17 00:00:00 2001 From: Colleen Schnettler Date: Fri, 1 Jun 2018 13:24:25 -0400 Subject: [PATCH 01/16] Apiary doc no sematic issues, added jobs controller, model, test, endpoint --- apiary.apib | 29 + app/admin/job.rb | 23 + app/controllers/api/v1/jobs_controller.rb | 11 + .../api/v1/users/jobs_controller.rb | 11 + app/models/job.rb | 2 + config/database.yml | 2 +- config/routes.rb | 1 + db/migrate/20180531004341_create_jobs.rb | 17 + db/schema.rb | 523 +++++++++--------- db/seeds.rb | 3 + .../api/v1/jobs_controller_test.rb | 20 + test/factories/jobs.rb | 13 + test/models/job_test.rb | 7 + 13 files changed, 407 insertions(+), 255 deletions(-) create mode 100644 app/admin/job.rb create mode 100644 app/controllers/api/v1/jobs_controller.rb create mode 100644 app/controllers/api/v1/users/jobs_controller.rb create mode 100644 app/models/job.rb create mode 100644 db/migrate/20180531004341_create_jobs.rb create mode 100644 test/controllers/api/v1/jobs_controller_test.rb create mode 100644 test/factories/jobs.rb create mode 100644 test/models/job_test.rb diff --git a/apiary.apib b/apiary.apib index 7d82194e..386999e1 100644 --- a/apiary.apib +++ b/apiary.apib @@ -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!", + "status": "active", + "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}] diff --git a/app/admin/job.rb b/app/admin/job.rb new file mode 100644 index 00000000..031c3f58 --- /dev/null +++ b/app/admin/job.rb @@ -0,0 +1,23 @@ +ActiveAdmin.register Job do +# See permitted parameters documentation: +# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters +# +permit_params :title, :source_url, :source, :city, :state, :country, :description, :status, :remote + + index do + selectable_column + id_column + + column :title + column :source_url + column :source + column :city + column :state + column :country + column :description + column :status + column :remote + + actions + end +end diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb new file mode 100644 index 00000000..a09ceaad --- /dev/null +++ b/app/controllers/api/v1/jobs_controller.rb @@ -0,0 +1,11 @@ +module Api + module V1 + class JobsController < ApiController + def index + render json: Job.all, status: :ok + rescue StandardError => e + render json: { errors: e.message }, status: :unprocessable_entity + end + end + end +end diff --git a/app/controllers/api/v1/users/jobs_controller.rb b/app/controllers/api/v1/users/jobs_controller.rb new file mode 100644 index 00000000..a09ceaad --- /dev/null +++ b/app/controllers/api/v1/users/jobs_controller.rb @@ -0,0 +1,11 @@ +module Api + module V1 + class JobsController < ApiController + def index + render json: Job.all, status: :ok + rescue StandardError => e + render json: { errors: e.message }, status: :unprocessable_entity + end + end + end +end diff --git a/app/models/job.rb b/app/models/job.rb new file mode 100644 index 00000000..12f5bd6a --- /dev/null +++ b/app/models/job.rb @@ -0,0 +1,2 @@ +class Job < ApplicationRecord +end diff --git a/config/database.yml b/config/database.yml index 47e2907f..57c1d361 100644 --- a/config/database.yml +++ b/config/database.yml @@ -20,7 +20,7 @@ default: &default # For details on connection pooling, see rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - user: postgres + user: leenyburger host: <%= ENV['POSTGRES_HOST'].present? ? ENV['POSTGRES_HOST'] : 'operationcode-psql' %> password: <%= OperationCode.fetch_secret_with name: :postgres_password %> diff --git a/config/routes.rb b/config/routes.rb index ddd701aa..c07331c2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,6 +24,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 diff --git a/db/migrate/20180531004341_create_jobs.rb b/db/migrate/20180531004341_create_jobs.rb new file mode 100644 index 00000000..7e557d66 --- /dev/null +++ b/db/migrate/20180531004341_create_jobs.rb @@ -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.string :status + t.boolean :remote, default: false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 9feae23c..de9215c3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,298 +10,313 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180430161218) do +ActiveRecord::Schema.define(version: 20180531004341) do + # These are extensions that must be enabled in order to support this database - enable_extension 'plpgsql' + enable_extension "plpgsql" + + create_table "active_admin_comments", force: :cascade do |t| + t.string "namespace" + t.text "body" + t.string "resource_type" + t.integer "resource_id" + t.string "author_type" + t.integer "author_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id", using: :btree + t.index ["namespace"], name: "index_active_admin_comments_on_namespace", using: :btree + t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id", using: :btree + end - create_table 'active_admin_comments', force: :cascade do |t| - t.string 'namespace' - t.text 'body' - t.string 'resource_type' - t.integer 'resource_id' - t.string 'author_type' - t.integer 'author_id' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['author_type', 'author_id'], name: 'index_active_admin_comments_on_author_type_and_author_id', using: :btree - t.index ['namespace'], name: 'index_active_admin_comments_on_namespace', using: :btree - t.index ['resource_type', 'resource_id'], name: 'index_active_admin_comments_on_resource_type_and_resource_id', using: :btree + create_table "admin_users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.inet "current_sign_in_ip" + t.inet "last_sign_in_ip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "role_id" + t.index ["email"], name: "index_admin_users_on_email", unique: true, using: :btree + t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true, using: :btree + t.index ["role_id"], name: "index_admin_users_on_role_id", using: :btree end - create_table 'admin_users', force: :cascade do |t| - t.string 'email', default: '', null: false - t.string 'encrypted_password', default: '', null: false - t.string 'reset_password_token' - t.datetime 'reset_password_sent_at' - t.datetime 'remember_created_at' - t.integer 'sign_in_count', default: 0, null: false - t.datetime 'current_sign_in_at' - t.datetime 'last_sign_in_at' - t.inet 'current_sign_in_ip' - t.inet 'last_sign_in_ip' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.integer 'role_id' - t.index ['email'], name: 'index_admin_users_on_email', unique: true, using: :btree - t.index ['reset_password_token'], name: 'index_admin_users_on_reset_password_token', unique: true, using: :btree - t.index ['role_id'], name: 'index_admin_users_on_role_id', using: :btree + create_table "code_schools", force: :cascade do |t| + t.string "name" + t.string "url" + t.string "logo" + t.boolean "full_time" + t.boolean "hardware_included" + t.boolean "has_online" + t.boolean "online_only" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "notes" + t.boolean "mooc", default: false, null: false + t.boolean "is_partner", default: false, null: false + t.string "rep_name" + t.string "rep_email" end - create_table 'code_schools', force: :cascade do |t| - t.string 'name' - t.string 'url' - t.string 'logo' - t.boolean 'full_time' - t.boolean 'hardware_included' - t.boolean 'has_online' - t.boolean 'online_only' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.text 'notes' - t.boolean 'mooc', default: false, null: false - t.boolean 'is_partner', default: false, null: false - t.string 'rep_name' - t.string 'rep_email' + create_table "events", force: :cascade do |t| + t.string "name" + t.text "description" + t.string "url" + t.datetime "start_date" + t.datetime "end_date" + t.string "address1" + t.string "address2" + t.string "city" + t.string "state" + t.string "zip" + t.boolean "scholarship_available" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "source_id" + t.string "source_type" + t.datetime "source_updated" + t.string "group" + t.index ["source_id"], name: "index_events_on_source_id", using: :btree + t.index ["source_type"], name: "index_events_on_source_type", using: :btree end - create_table 'events', force: :cascade do |t| - t.string 'name' - t.text 'description' - t.string 'url' - t.datetime 'start_date' - t.datetime 'end_date' - t.string 'address1' - t.string 'address2' - t.string 'city' - t.string 'state' - t.string 'zip' - t.boolean 'scholarship_available' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.string 'source_id' - t.string 'source_type' - t.datetime 'source_updated' - t.string 'group' - t.index ['source_id'], name: 'index_events_on_source_id', using: :btree - t.index ['source_type'], name: 'index_events_on_source_type', using: :btree + create_table "git_hub_statistics", force: :cascade do |t| + t.integer "git_hub_user_id" + t.string "source_id" + t.string "source_type" + t.string "state" + t.integer "additions" + t.integer "deletions" + t.string "repository" + t.string "url" + t.string "title" + t.string "number" + t.date "completed_on" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["git_hub_user_id"], name: "index_git_hub_statistics_on_git_hub_user_id", using: :btree end - create_table 'git_hub_statistics', force: :cascade do |t| - t.integer 'git_hub_user_id' - t.string 'source_id' - t.string 'source_type' - t.string 'state' - t.integer 'additions' - t.integer 'deletions' - t.string 'repository' - t.string 'url' - t.string 'title' - t.string 'number' - t.date 'completed_on' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['git_hub_user_id'], name: 'index_git_hub_statistics_on_git_hub_user_id', using: :btree + create_table "git_hub_users", force: :cascade do |t| + t.integer "user_id" + t.string "git_hub_login" + t.string "avatar_url" + t.string "api_url" + t.string "html_url" + t.integer "git_hub_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_git_hub_users_on_user_id", using: :btree end - create_table 'git_hub_users', force: :cascade do |t| - t.integer 'user_id' - t.string 'git_hub_login' - t.string 'avatar_url' - t.string 'api_url' - t.string 'html_url' - t.integer 'git_hub_id' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['user_id'], name: 'index_git_hub_users_on_user_id', using: :btree + 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.string "status" + 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' - t.string 'address2' - t.string 'city' - t.string 'state' - t.integer 'zip' - t.integer 'code_school_id' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['code_school_id'], name: 'index_locations_on_code_school_id', using: :btree + create_table "locations", force: :cascade do |t| + t.boolean "va_accepted" + t.string "address1" + t.string "address2" + t.string "city" + t.string "state" + t.integer "zip" + t.integer "code_school_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["code_school_id"], name: "index_locations_on_code_school_id", using: :btree end - create_table 'requests', force: :cascade do |t| - t.integer 'service_id' - t.string 'language' - t.text 'details' - t.integer 'user_id' - t.integer 'assigned_mentor_id' - t.integer 'requested_mentor_id' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.string 'status' - t.index ['assigned_mentor_id'], name: 'index_requests_on_assigned_mentor_id', using: :btree - t.index ['requested_mentor_id'], name: 'index_requests_on_requested_mentor_id', using: :btree - t.index ['service_id'], name: 'index_requests_on_service_id', using: :btree - t.index ['user_id'], name: 'index_requests_on_user_id', using: :btree + create_table "requests", force: :cascade do |t| + t.integer "service_id" + t.string "language" + t.text "details" + t.integer "user_id" + t.integer "assigned_mentor_id" + t.integer "requested_mentor_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "status" + t.index ["assigned_mentor_id"], name: "index_requests_on_assigned_mentor_id", using: :btree + t.index ["requested_mentor_id"], name: "index_requests_on_requested_mentor_id", using: :btree + t.index ["service_id"], name: "index_requests_on_service_id", using: :btree + t.index ["user_id"], name: "index_requests_on_user_id", using: :btree end - create_table 'resources', force: :cascade do |t| - t.string 'name' - t.string 'url' - t.string 'category' - t.string 'language' - t.boolean 'paid' - t.text 'notes' - t.integer 'votes_count', default: 0, null: false - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false + create_table "resources", force: :cascade do |t| + t.string "name" + t.string "url" + t.string "category" + t.string "language" + t.boolean "paid" + t.text "notes" + t.integer "votes_count", default: 0, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table 'roles', force: :cascade do |t| - t.string 'title' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false + create_table "roles", force: :cascade do |t| + t.string "title" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table 'scholarship_applications', force: :cascade do |t| - t.text 'reason' - t.boolean 'terms_accepted' - t.integer 'user_id' - t.integer 'scholarship_id' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['scholarship_id'], name: 'index_scholarship_applications_on_scholarship_id', using: :btree - t.index ['user_id'], name: 'index_scholarship_applications_on_user_id', using: :btree + create_table "scholarship_applications", force: :cascade do |t| + t.text "reason" + t.boolean "terms_accepted" + t.integer "user_id" + t.integer "scholarship_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["scholarship_id"], name: "index_scholarship_applications_on_scholarship_id", using: :btree + t.index ["user_id"], name: "index_scholarship_applications_on_user_id", using: :btree end - create_table 'scholarships', force: :cascade do |t| - t.string 'name' - t.text 'description' - t.string 'location' - t.text 'terms' - t.datetime 'open_time' - t.datetime 'close_time' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false + create_table "scholarships", force: :cascade do |t| + t.string "name" + t.text "description" + t.string "location" + t.text "terms" + t.datetime "open_time" + t.datetime "close_time" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table 'services', force: :cascade do |t| - t.string 'name' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false + create_table "services", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table 'slack_users', force: :cascade do |t| - t.string 'slack_id' - t.string 'slack_name' - t.string 'slack_real_name' - t.string 'slack_display_name' - t.string 'slack_email' - t.integer 'user_id' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['slack_email'], name: 'index_slack_users_on_slack_email', using: :btree - t.index ['slack_id'], name: 'index_slack_users_on_slack_id', using: :btree - t.index ['user_id'], name: 'index_slack_users_on_user_id', using: :btree + create_table "slack_users", force: :cascade do |t| + t.string "slack_id" + t.string "slack_name" + t.string "slack_real_name" + t.string "slack_display_name" + t.string "slack_email" + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["slack_email"], name: "index_slack_users_on_slack_email", using: :btree + t.index ["slack_id"], name: "index_slack_users_on_slack_id", using: :btree + t.index ["user_id"], name: "index_slack_users_on_user_id", using: :btree end - create_table 'taggings', force: :cascade do |t| - t.integer 'tag_id' - t.string 'taggable_type' - t.integer 'taggable_id' - t.string 'tagger_type' - t.integer 'tagger_id' - t.string 'context', limit: 128 - t.datetime 'created_at' - t.index ['context'], name: 'index_taggings_on_context', using: :btree - t.index ['tag_id', 'taggable_id', 'taggable_type', 'context', 'tagger_id', 'tagger_type'], name: 'taggings_idx', unique: true, using: :btree - t.index ['tag_id'], name: 'index_taggings_on_tag_id', using: :btree - t.index ['taggable_id', 'taggable_type', 'context'], name: 'index_taggings_on_taggable_id_and_taggable_type_and_context', using: :btree - t.index ['taggable_id', 'taggable_type', 'tagger_id', 'context'], name: 'taggings_idy', using: :btree - t.index ['taggable_id'], name: 'index_taggings_on_taggable_id', using: :btree - t.index ['taggable_type'], name: 'index_taggings_on_taggable_type', using: :btree - t.index ['tagger_id', 'tagger_type'], name: 'index_taggings_on_tagger_id_and_tagger_type', using: :btree - t.index ['tagger_id'], name: 'index_taggings_on_tagger_id', using: :btree + create_table "taggings", force: :cascade do |t| + t.integer "tag_id" + t.string "taggable_type" + t.integer "taggable_id" + t.string "tagger_type" + t.integer "tagger_id" + t.string "context", limit: 128 + t.datetime "created_at" + t.index ["context"], name: "index_taggings_on_context", using: :btree + t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true, using: :btree + t.index ["tag_id"], name: "index_taggings_on_tag_id", using: :btree + t.index ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree + t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy", using: :btree + t.index ["taggable_id"], name: "index_taggings_on_taggable_id", using: :btree + t.index ["taggable_type"], name: "index_taggings_on_taggable_type", using: :btree + t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type", using: :btree + t.index ["tagger_id"], name: "index_taggings_on_tagger_id", using: :btree end - create_table 'tags', force: :cascade do |t| - t.string 'name' - t.integer 'taggings_count', default: 0 - t.index ['name'], name: 'index_tags_on_name', unique: true, using: :btree + create_table "tags", force: :cascade do |t| + t.string "name" + t.integer "taggings_count", default: 0 + t.index ["name"], name: "index_tags_on_name", unique: true, using: :btree end - create_table 'team_members', force: :cascade do |t| - t.string 'name' - t.string 'role' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.text 'description' - t.string 'group' - t.string 'image_src' - t.string 'email', limit: 255 + create_table "team_members", force: :cascade do |t| + t.string "name" + t.string "role" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "description" + t.string "group" + t.string "image_src" + t.string "email", limit: 255 end - create_table 'users', force: :cascade do |t| - t.string 'email' - t.string 'zip' - t.float 'latitude' - t.float 'longitude' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.string 'encrypted_password', default: '', null: false - t.string 'reset_password_token' - t.datetime 'reset_password_sent_at' - t.datetime 'remember_created_at' - t.integer 'sign_in_count', default: 0, null: false - t.datetime 'current_sign_in_at' - t.datetime 'last_sign_in_at' - t.inet 'current_sign_in_ip' - t.inet 'last_sign_in_ip' - t.boolean 'mentor', default: false - t.string 'first_name' - t.string 'last_name' - t.string 'timezone' - t.text 'bio' - t.boolean 'verified', default: false, null: false - t.string 'state' - t.string 'address_1' - t.string 'address_2' - t.string 'city' - t.string 'username' - t.boolean 'volunteer', default: false - t.string 'branch_of_service' - t.float 'years_of_service' - t.string 'pay_grade' - t.string 'military_occupational_specialty' - t.string 'github' - t.string 'twitter' - t.string 'linkedin' - t.string 'employment_status' - t.string 'education' - t.string 'company_role' - t.string 'company_name' - t.string 'education_level' - t.string 'interests' - t.boolean 'scholarship_info', default: false - t.integer 'role_id' - t.index ['email'], name: 'index_users_on_email', unique: true, using: :btree - t.index ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true, using: :btree - t.index ['role_id'], name: 'index_users_on_role_id', using: :btree + create_table "users", force: :cascade do |t| + t.string "email" + t.string "zip" + t.float "latitude" + t.float "longitude" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.inet "current_sign_in_ip" + t.inet "last_sign_in_ip" + t.boolean "mentor", default: false + t.string "first_name" + t.string "last_name" + t.string "timezone" + t.text "bio" + t.boolean "verified", default: false, null: false + t.string "state" + t.string "address_1" + t.string "address_2" + t.string "city" + t.string "username" + t.boolean "volunteer", default: false + t.string "branch_of_service" + t.float "years_of_service" + t.string "pay_grade" + t.string "military_occupational_specialty" + t.string "github" + t.string "twitter" + t.string "linkedin" + t.string "employment_status" + t.string "education" + t.string "company_role" + t.string "company_name" + t.string "education_level" + t.string "interests" + t.boolean "scholarship_info", default: false + t.integer "role_id" + t.index ["email"], name: "index_users_on_email", unique: true, using: :btree + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + t.index ["role_id"], name: "index_users_on_role_id", using: :btree end - create_table 'votes', force: :cascade do |t| - t.integer 'user_id' - t.integer 'resource_id' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['resource_id'], name: 'index_votes_on_resource_id', using: :btree - t.index ['user_id'], name: 'index_votes_on_user_id', using: :btree + create_table "votes", force: :cascade do |t| + t.integer "user_id" + t.integer "resource_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["resource_id"], name: "index_votes_on_resource_id", using: :btree + t.index ["user_id"], name: "index_votes_on_user_id", using: :btree end - add_foreign_key 'git_hub_statistics', 'git_hub_users' - add_foreign_key 'locations', 'code_schools' - add_foreign_key 'requests', 'users' - add_foreign_key 'scholarship_applications', 'scholarships' - add_foreign_key 'scholarship_applications', 'users' - add_foreign_key 'votes', 'resources' - add_foreign_key 'votes', 'users' + add_foreign_key "git_hub_statistics", "git_hub_users" + add_foreign_key "locations", "code_schools" + add_foreign_key "requests", "users" + add_foreign_key "scholarship_applications", "scholarships" + add_foreign_key "scholarship_applications", "users" + add_foreign_key "votes", "resources" + add_foreign_key "votes", "users" end diff --git a/db/seeds.rb b/db/seeds.rb index c60ddfcc..365673a0 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -31,6 +31,9 @@ Service.create!(:name => service) end +# 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!", status: "active", remote: "false") + # Create team members SeedTeamMembers.seed_all diff --git a/test/controllers/api/v1/jobs_controller_test.rb b/test/controllers/api/v1/jobs_controller_test.rb new file mode 100644 index 00000000..3f706ef6 --- /dev/null +++ b/test/controllers/api/v1/jobs_controller_test.rb @@ -0,0 +1,20 @@ +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| + byebug + assert_equal true, response["title"] == jobs[i].title + byebug + i += 1 + end + end +end + diff --git a/test/factories/jobs.rb b/test/factories/jobs.rb new file mode 100644 index 00000000..1da0319f --- /dev/null +++ b/test/factories/jobs.rb @@ -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 + status "active" + remote false + end +end diff --git a/test/models/job_test.rb b/test/models/job_test.rb new file mode 100644 index 00000000..50793169 --- /dev/null +++ b/test/models/job_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class JobTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From a1ffefed2a0ff8467acc8a6cd3f038acee179dd5 Mon Sep 17 00:00:00 2001 From: Colleen Schnettler Date: Fri, 1 Jun 2018 13:31:45 -0400 Subject: [PATCH 02/16] Added acts_as_taggable to job model --- app/models/job.rb | 1 + test/controllers/api/v1/jobs_controller_test.rb | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/job.rb b/app/models/job.rb index 12f5bd6a..fa00c1ff 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -1,2 +1,3 @@ class Job < ApplicationRecord + acts_as_taggable_on end diff --git a/test/controllers/api/v1/jobs_controller_test.rb b/test/controllers/api/v1/jobs_controller_test.rb index 3f706ef6..c909c375 100644 --- a/test/controllers/api/v1/jobs_controller_test.rb +++ b/test/controllers/api/v1/jobs_controller_test.rb @@ -10,9 +10,7 @@ class Api::V1::JobsControllerTest < ActionDispatch::IntegrationTest get api_v1_jobs_url, as: :json i = 0 response.parsed_body.each do |response| - byebug assert_equal true, response["title"] == jobs[i].title - byebug i += 1 end end From 777af570805a995d19f48da6837c6155d9349392 Mon Sep 17 00:00:00 2001 From: Colleen Schnettler Date: Fri, 1 Jun 2018 13:35:18 -0400 Subject: [PATCH 03/16] Fixed database user name issue --- config/database.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/database.yml b/config/database.yml index 57c1d361..47e2907f 100644 --- a/config/database.yml +++ b/config/database.yml @@ -20,7 +20,7 @@ default: &default # For details on connection pooling, see rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - user: leenyburger + user: postgres host: <%= ENV['POSTGRES_HOST'].present? ? ENV['POSTGRES_HOST'] : 'operationcode-psql' %> password: <%= OperationCode.fetch_secret_with name: :postgres_password %> From 8543559d2676b59fa05100e301d6ed569c3fa053 Mon Sep 17 00:00:00 2001 From: Colleen Schnettler Date: Fri, 1 Jun 2018 13:47:42 -0400 Subject: [PATCH 04/16] Fixed sytax errors --- app/admin/job.rb | 2 +- db/schema.rb | 1 - test/controllers/api/v1/jobs_controller_test.rb | 6 ++---- test/factories/jobs.rb | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/admin/job.rb b/app/admin/job.rb index 031c3f58..51dca883 100644 --- a/app/admin/job.rb +++ b/app/admin/job.rb @@ -2,7 +2,7 @@ # See permitted parameters documentation: # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters # -permit_params :title, :source_url, :source, :city, :state, :country, :description, :status, :remote + permit_params :title, :source_url, :source, :city, :state, :country, :description, :status, :remote index do selectable_column diff --git a/db/schema.rb b/db/schema.rb index de9215c3..955804a3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,6 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 20180531004341) do - # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/test/controllers/api/v1/jobs_controller_test.rb b/test/controllers/api/v1/jobs_controller_test.rb index c909c375..53340175 100644 --- a/test/controllers/api/v1/jobs_controller_test.rb +++ b/test/controllers/api/v1/jobs_controller_test.rb @@ -1,8 +1,7 @@ require 'test_helper' class Api::V1::JobsControllerTest < ActionDispatch::IntegrationTest - - test "index endpoint should return job parameters in JSON format" do + test 'index endpoint should return job parameters in JSON format' do jobs = [] 5.times do jobs << create(:job) @@ -10,9 +9,8 @@ class Api::V1::JobsControllerTest < ActionDispatch::IntegrationTest get api_v1_jobs_url, as: :json i = 0 response.parsed_body.each do |response| - assert_equal true, response["title"] == jobs[i].title + assert_equal true, response['title'] == jobs[i].title i += 1 end end end - diff --git a/test/factories/jobs.rb b/test/factories/jobs.rb index 1da0319f..ce61eebc 100644 --- a/test/factories/jobs.rb +++ b/test/factories/jobs.rb @@ -7,7 +7,7 @@ state Faker::Address.state country Faker::Address.country description Faker::Lorem.paragraph - status "active" + status 'active' remote false end end From 6f022f03247aa8194e6b5319f4ac149c1ce5d8d3 Mon Sep 17 00:00:00 2001 From: Colleen Schnettler Date: Fri, 1 Jun 2018 13:56:51 -0400 Subject: [PATCH 05/16] Removed extraneous comments --- app/admin/job.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/admin/job.rb b/app/admin/job.rb index 51dca883..c5193ecc 100644 --- a/app/admin/job.rb +++ b/app/admin/job.rb @@ -1,7 +1,4 @@ ActiveAdmin.register Job do -# See permitted parameters documentation: -# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters -# permit_params :title, :source_url, :source, :city, :state, :country, :description, :status, :remote index do From e2c5b197a6127deb87e634ecdda9661dcafc3873 Mon Sep 17 00:00:00 2001 From: Colleen Schnettler Date: Mon, 4 Jun 2018 10:54:58 -0400 Subject: [PATCH 06/16] Added test for job acts as taggable, updated admin --- app/admin/job.rb | 16 ++++++++++++++++ .../api/v1/users/jobs_controller.rb | 11 ----------- app/models/job.rb | 6 +++++- db/seeds.rb | 3 +++ test/models/job_test.rb | 18 +++++++++++++++--- 5 files changed, 39 insertions(+), 15 deletions(-) delete mode 100644 app/controllers/api/v1/users/jobs_controller.rb diff --git a/app/admin/job.rb b/app/admin/job.rb index c5193ecc..3af7982b 100644 --- a/app/admin/job.rb +++ b/app/admin/job.rb @@ -17,4 +17,20 @@ actions end + + 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 :status + f.input :remote + end + + f.actions + end end diff --git a/app/controllers/api/v1/users/jobs_controller.rb b/app/controllers/api/v1/users/jobs_controller.rb deleted file mode 100644 index a09ceaad..00000000 --- a/app/controllers/api/v1/users/jobs_controller.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Api - module V1 - class JobsController < ApiController - def index - render json: Job.all, status: :ok - rescue StandardError => e - render json: { errors: e.message }, status: :unprocessable_entity - end - end - end -end diff --git a/app/models/job.rb b/app/models/job.rb index fa00c1ff..f36959a4 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -1,3 +1,7 @@ class Job < ApplicationRecord - acts_as_taggable_on + acts_as_taggable + + def self.with_tags(*args) + tagged_with(args, any: true) + end end diff --git a/db/seeds.rb b/db/seeds.rb index 365673a0..6f64707f 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -14,6 +14,7 @@ TeamMember.destroy_all AdminUser.destroy_all Role.destroy_all +Job.destroy_all FactoryGirl.create(:user) FactoryGirl.create(:user) @@ -56,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" @@ -65,3 +67,4 @@ p "#{admin_users} admin users" p "#{scholarship_count} scholarships" p "#{scholarship_app} scholarship applications" +p "#{jobs} jobs" diff --git a/test/models/job_test.rb b/test/models/job_test.rb index 50793169..fdf4fd98 100644 --- a/test/models/job_test.rb +++ b/test/models/job_test.rb @@ -1,7 +1,19 @@ require 'test_helper' class JobTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + + 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 + From a1bcd87f57948636df323c3ec4e34e060d7ea9ea Mon Sep 17 00:00:00 2001 From: Colleen Schnettler Date: Mon, 4 Jun 2018 11:39:40 -0400 Subject: [PATCH 07/16] Fixed formatting errors: --- test/models/job_test.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/models/job_test.rb b/test/models/job_test.rb index fdf4fd98..17f144ca 100644 --- a/test/models/job_test.rb +++ b/test/models/job_test.rb @@ -1,19 +1,17 @@ require 'test_helper' class JobTest < ActiveSupport::TestCase - setup do @job = create :job end - test "should be valid" do + test 'should be valid' do assert @job.valid? end - test ".with_tags returns job with tag" do + 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 - From b9e40d6ed3c48546b2cffab0d65f71c1a8c3a5b2 Mon Sep 17 00:00:00 2001 From: wimo7083 Date: Fri, 5 Oct 2018 13:48:51 -0600 Subject: [PATCH 08/16] slight modifications --- Makefile | 54 ++++++++---------------- Makefile.in | 9 ++++ apiary.apib | 2 +- app/admin/job.rb | 6 +-- db/migrate/20180531004341_create_jobs.rb | 2 +- db/schema.rb | 6 ++- db/seeds.rb | 2 +- test/factories/jobs.rb | 2 +- 8 files changed, 38 insertions(+), 45 deletions(-) create mode 100644 Makefile.in diff --git a/Makefile b/Makefile index b9f79c8c..f3668354 100644 --- a/Makefile +++ b/Makefile @@ -1,72 +1,54 @@ -RAILS_CONTAINER := web - -.PHONY: all +include Makefile.in all: run -.PHONY: console-sandbox - console-sandbox: - docker-compose run ${RAILS_CONTAINER} rails console --sandbox +console-sandbox: + $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rails console --sandbox -.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 + $(DOCKER_COMPOSE) build -.PHONY: console console: - docker-compose run ${RAILS_CONTAINER} rails console + $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rails console -.PHONY: routes routes: - docker-compose run ${RAILS_CONTAINER} rake routes + $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake routes -.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 -.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;" + $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) bash -c 'export RAILS_ENV=test && rake db:test:prepare && rake test && rubocop' || echo -e "$(RED)Tests have 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' + $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) bash -c 'cd /app && bundle' setup: build db_create db_migrate diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 00000000..d2eca37a --- /dev/null +++ b/Makefile.in @@ -0,0 +1,9 @@ +RAILS_CONTAINER:= web +DOCKER_COMPOSE:= docker-compose +RED=\033[0;31m +NC=\033[0m + + +.PHONY: all run bg open build console routes db_create db_migrate db_rollback db_seed db_status test rubocop bundle build publish +.DELETE_ON_ERROR: +.SILENT: diff --git a/apiary.apib b/apiary.apib index 386999e1..0537474a 100644 --- a/apiary.apib +++ b/apiary.apib @@ -451,7 +451,7 @@ API endpoints that Operation Code's Rails backend makes available to its React f "state": "VA", "country": "USA", "description": "Our job is fun!", - "status": "active", + "open": false, "remote": false, "created_at": "2018-06-01T16:21:59.462Z", "updated_at": "2018-06-01T16:21:59.462Z" diff --git a/app/admin/job.rb b/app/admin/job.rb index 3af7982b..9e9c6d57 100644 --- a/app/admin/job.rb +++ b/app/admin/job.rb @@ -1,5 +1,5 @@ ActiveAdmin.register Job do - permit_params :title, :source_url, :source, :city, :state, :country, :description, :status, :remote + permit_params :title, :source_url, :source, :city, :state, :country, :description, :open, :remote index do selectable_column @@ -12,7 +12,7 @@ column :state column :country column :description - column :status + column :open column :remote actions @@ -27,7 +27,7 @@ f.input :state f.input :country f.input :description - f.input :status + f.input :open f.input :remote end diff --git a/db/migrate/20180531004341_create_jobs.rb b/db/migrate/20180531004341_create_jobs.rb index 7e557d66..1d42c75f 100644 --- a/db/migrate/20180531004341_create_jobs.rb +++ b/db/migrate/20180531004341_create_jobs.rb @@ -8,7 +8,7 @@ def change t.string :state t.string :country t.text :description - t.string :status + t.boolean :active, default: true t.boolean :remote, default: false t.timestamps diff --git a/db/schema.rb b/db/schema.rb index 955804a3..be2450f4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,8 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180531004341) do +ActiveRecord::Schema.define(version: 20180711212702) do + # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -123,7 +124,7 @@ t.string "state" t.string "country" t.text "description" - t.string "status" + t.boolean "active", default: true t.boolean "remote", default: false t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -297,6 +298,7 @@ t.string "interests" t.boolean "scholarship_info", default: false t.integer "role_id" + t.string "military_status" t.index ["email"], name: "index_users_on_email", unique: true, using: :btree t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree t.index ["role_id"], name: "index_users_on_role_id", using: :btree diff --git a/db/seeds.rb b/db/seeds.rb index 6f64707f..5cda5c31 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -33,7 +33,7 @@ end # 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!", status: "active", remote: "false") +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!", open: true, remote: "false") # Create team members SeedTeamMembers.seed_all diff --git a/test/factories/jobs.rb b/test/factories/jobs.rb index ce61eebc..6260265c 100644 --- a/test/factories/jobs.rb +++ b/test/factories/jobs.rb @@ -7,7 +7,7 @@ state Faker::Address.state country Faker::Address.country description Faker::Lorem.paragraph - status 'active' + open true remote false end end From 263375bc2425452351429d18e90e00bb4ead0d6d Mon Sep 17 00:00:00 2001 From: wimo7083 Date: Fri, 5 Oct 2018 14:22:50 -0600 Subject: [PATCH 09/16] fixed test issues with variable change --- .rubocop.yml | 13 +++++-- Makefile | 46 ++++++++++++++++++++++-- Makefile.in | 3 +- app/admin/job.rb | 4 +-- db/migrate/20180531004341_create_jobs.rb | 2 +- db/schema.rb | 5 ++- db/seeds.rb | 2 +- test/factories/jobs.rb | 2 +- 8 files changed, 63 insertions(+), 14 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 8f346897..8c6cedc9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,9 @@ inherit_from: .rubocop_todo.yml +AllCops: + Exclude: + - 'db/schema.rb' + # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes @@ -7,7 +11,10 @@ Style/StringLiterals: Exclude: - 'db/**/*' -# Configuration parameters: CountComments, ExcludedMethods. -Metrics/BlockLength: +#turn off end of line checks, git will fix this +EndOfLine: + Enabled: false + +Metrics/ClassLength: Exclude: - - 'db/schema.rb' + - 'test/models/user_test.rb' \ No newline at end of file diff --git a/Makefile b/Makefile index f3668354..3af54365 100644 --- a/Makefile +++ b/Makefile @@ -1,52 +1,94 @@ include Makefile.in + +.PHONY: all all: run +.PHONY: nuke +nuke: + $(DOCKER) system prune -a --volumes + +.PHONY: +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 + +.PHONY: console-sandbox console-sandbox: - $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rails console --sandbox + $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rails console --sandbox +.PHONY: run run: $(DOCKER_COMPOSE) up --build +.PHONY: bg bg: $(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 +.PHONY: routes routes: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake routes +.PHONY: db_create db_create: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake db:create +.PHONY: db_migrate db_migrate: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake db:migrate +.PHONY: db_status db_status: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake db:migrate:status +.PHONY: db_rollback db_rollback: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake db:rollback +.PHONY: db_seed db_seed: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake db:seed +.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' || echo -e "$(RED)Tests have failed$(NC)" + $(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 +.PHONY: rubocop_auto_correct rubocop_auto_correct: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rubocop -a --auto-correct +.PHONY: bundle bundle: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) bash -c 'cd /app && bundle' diff --git a/Makefile.in b/Makefile.in index d2eca37a..49f66a6d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,9 +1,10 @@ RAILS_CONTAINER:= web DOCKER_COMPOSE:= docker-compose +DOCKER:= docker RED=\033[0;31m +GREEN=\032[0;32m NC=\033[0m -.PHONY: all run bg open build console routes db_create db_migrate db_rollback db_seed db_status test rubocop bundle build publish .DELETE_ON_ERROR: .SILENT: diff --git a/app/admin/job.rb b/app/admin/job.rb index 9e9c6d57..4889de08 100644 --- a/app/admin/job.rb +++ b/app/admin/job.rb @@ -12,7 +12,7 @@ column :state column :country column :description - column :open + column :is_open column :remote actions @@ -27,7 +27,7 @@ f.input :state f.input :country f.input :description - f.input :open + f.input :is_open f.input :remote end diff --git a/db/migrate/20180531004341_create_jobs.rb b/db/migrate/20180531004341_create_jobs.rb index 1d42c75f..a97e39ad 100644 --- a/db/migrate/20180531004341_create_jobs.rb +++ b/db/migrate/20180531004341_create_jobs.rb @@ -8,7 +8,7 @@ def change t.string :state t.string :country t.text :description - t.boolean :active, default: true + t.boolean :is_open, default: true t.boolean :remote, default: false t.timestamps diff --git a/db/schema.rb b/db/schema.rb index be2450f4..84871bd7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180711212702) do +ActiveRecord::Schema.define(version: 20180531004341) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -124,7 +124,7 @@ t.string "state" t.string "country" t.text "description" - t.boolean "active", default: true + t.boolean "is_open", default: true t.boolean "remote", default: false t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -298,7 +298,6 @@ t.string "interests" t.boolean "scholarship_info", default: false t.integer "role_id" - t.string "military_status" t.index ["email"], name: "index_users_on_email", unique: true, using: :btree t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree t.index ["role_id"], name: "index_users_on_role_id", using: :btree diff --git a/db/seeds.rb b/db/seeds.rb index 5cda5c31..ccbd1a21 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -33,7 +33,7 @@ end # 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!", open: true, remote: "false") +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 SeedTeamMembers.seed_all diff --git a/test/factories/jobs.rb b/test/factories/jobs.rb index 6260265c..5f5515a2 100644 --- a/test/factories/jobs.rb +++ b/test/factories/jobs.rb @@ -7,7 +7,7 @@ state Faker::Address.state country Faker::Address.country description Faker::Lorem.paragraph - open true + is_open true remote false end end From 75eed144f698264c89b157ed67e24248a0ee04ee Mon Sep 17 00:00:00 2001 From: wimo7083 Date: Fri, 5 Oct 2018 14:26:18 -0600 Subject: [PATCH 10/16] fix dangling is_open --- app/admin/job.rb | 2 +- db/seeds.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/admin/job.rb b/app/admin/job.rb index 4889de08..07de9d85 100644 --- a/app/admin/job.rb +++ b/app/admin/job.rb @@ -1,5 +1,5 @@ ActiveAdmin.register Job do - permit_params :title, :source_url, :source, :city, :state, :country, :description, :open, :remote + permit_params :title, :source_url, :source, :city, :state, :country, :description, :is_open, :remote index do selectable_column diff --git a/db/seeds.rb b/db/seeds.rb index ccbd1a21..d4bcfdec 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -33,7 +33,7 @@ end # 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") +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 SeedTeamMembers.seed_all From 8960e38fb905e0d2c2f2d1621dc3e851b06f8066 Mon Sep 17 00:00:00 2001 From: wimo7083 Date: Fri, 5 Oct 2018 14:57:13 -0600 Subject: [PATCH 11/16] start adding expiration --- Makefile | 86 ++++++++++++++++++++--------------------------- app/models/job.rb | 1 + db/schema.rb | 2 +- 3 files changed, 38 insertions(+), 51 deletions(-) diff --git a/Makefile b/Makefile index 8bb60aef..f8894b09 100644 --- a/Makefile +++ b/Makefile @@ -3,55 +3,12 @@ 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: fresh-restart -fresh-restart: minty-fresh setup test run - -.PHONY: nuke -nuke: - $(DOCKER) system prune -a --volumes - -.PHONY: -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 +.PHONY: setup +setup: build db_create db_migrate .PHONY: console-sandbox console-sandbox: - $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rails console --sandbox + $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rails console --sandbox .PHONY: run run: @@ -77,6 +34,13 @@ console: routes: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake routes +.PHONY: bundle +bundle: + $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) bash -c 'cd /app && bundle' + + + +#### Database Targets .PHONY: db_create db_create: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake db:create @@ -97,6 +61,7 @@ db_rollback: 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;" @@ -111,12 +76,33 @@ rubocop: rubocop_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 Targets +.PHONY: nuke +nuke: + $(DOCKER) system prune -a --volumes + +.PHONY: +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 targets publish: build bin/publish diff --git a/app/models/job.rb b/app/models/job.rb index f36959a4..f9191cb7 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -1,6 +1,7 @@ class Job < ApplicationRecord acts_as_taggable + scope :is_available, -> { where(is_open: true) } def self.with_tags(*args) tagged_with(args, any: true) end diff --git a/db/schema.rb b/db/schema.rb index d0b0689a..76151cd6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180531004341) do +ActiveRecord::Schema.define(version: 20180711212702) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From c85f56df80f7ba1102ae0a388dbea1d6aeb7732f Mon Sep 17 00:00:00 2001 From: wimo7083 Date: Fri, 5 Oct 2018 15:03:57 -0600 Subject: [PATCH 12/16] section makefile- its getting large, and update apiary --- Makefile | 18 +++++++++--------- apiary.apib | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index f8894b09..9ed83d98 100644 --- a/Makefile +++ b/Makefile @@ -6,10 +6,16 @@ all: run .PHONY: setup setup: build db_create db_migrate +.PHONY: console +console: + $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rails console + .PHONY: console-sandbox console-sandbox: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rails console --sandbox + +#### Utility .PHONY: run run: $(DOCKER_COMPOSE) up --build @@ -26,10 +32,6 @@ open: build: $(DOCKER_COMPOSE) build -.PHONY: console -console: - $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rails console - .PHONY: routes routes: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake routes @@ -38,9 +40,7 @@ routes: bundle: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) bash -c 'cd /app && bundle' - - -#### Database Targets +#### Database .PHONY: db_create db_create: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rake db:create @@ -77,7 +77,7 @@ rubocop_auto_correct: $(DOCKER_COMPOSE) run $(RAILS_CONTAINER) rubocop -a --auto-correct -#### Cleanup Targets +#### Cleanup .PHONY: nuke nuke: $(DOCKER) system prune -a --volumes @@ -102,7 +102,7 @@ rm-exited-containers: fresh-restart: minty-fresh setup test run -#### Deployment targets +#### Deployment publish: build bin/publish diff --git a/apiary.apib b/apiary.apib index 194d7cb5..705e0ca7 100644 --- a/apiary.apib +++ b/apiary.apib @@ -451,7 +451,7 @@ API endpoints that Operation Code's Rails backend makes available to its React f "state": "VA", "country": "USA", "description": "Our job is fun!", - "open": false, + "is_open": false, "remote": false, "created_at": "2018-06-01T16:21:59.462Z", "updated_at": "2018-06-01T16:21:59.462Z" From f6de002c40db05298ddbe32b9bccb02353e884d7 Mon Sep 17 00:00:00 2001 From: wimo7083 Date: Fri, 5 Oct 2018 15:19:18 -0600 Subject: [PATCH 13/16] changed to scoped call with default being active --- app/controllers/api/v1/jobs_controller.rb | 2 +- app/models/job.rb | 4 +++- db/migrate/20180531004341_create_jobs.rb | 2 +- db/schema.rb | 2 +- test/factories/jobs.rb | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb index a09ceaad..291311ef 100644 --- a/app/controllers/api/v1/jobs_controller.rb +++ b/app/controllers/api/v1/jobs_controller.rb @@ -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 diff --git a/app/models/job.rb b/app/models/job.rb index f9191cb7..75faf331 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -1,7 +1,9 @@ class Job < ApplicationRecord 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 diff --git a/db/migrate/20180531004341_create_jobs.rb b/db/migrate/20180531004341_create_jobs.rb index a97e39ad..af096024 100644 --- a/db/migrate/20180531004341_create_jobs.rb +++ b/db/migrate/20180531004341_create_jobs.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 76151cd6..6a7dca95 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/test/factories/jobs.rb b/test/factories/jobs.rb index 5f5515a2..40c03bd3 100644 --- a/test/factories/jobs.rb +++ b/test/factories/jobs.rb @@ -7,7 +7,7 @@ state Faker::Address.state country Faker::Address.country description Faker::Lorem.paragraph - is_open true + closed_at nil remote false end end From ef27d874235eae20e3e4bc28066a55f51bdf60df Mon Sep 17 00:00:00 2001 From: wimo7083 Date: Fri, 5 Oct 2018 15:22:00 -0600 Subject: [PATCH 14/16] re-add phony for target --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9ed83d98..e7d5f0c8 100644 --- a/Makefile +++ b/Makefile @@ -83,7 +83,7 @@ nuke: $(DOCKER) system prune -a --volumes .PHONY: -minty-fresh: +minty-fresh: minty-fresh $(DOCKER_COMPOSE) down --rmi all --volumes .PHONY: rmi From d8c8336e895d9073ba8b0fe9c1b2180064954155 Mon Sep 17 00:00:00 2001 From: wimo7083 Date: Fri, 5 Oct 2018 15:24:38 -0600 Subject: [PATCH 15/16] wrong location --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e7d5f0c8..0cd41d79 100644 --- a/Makefile +++ b/Makefile @@ -82,8 +82,8 @@ rubocop_auto_correct: nuke: $(DOCKER) system prune -a --volumes -.PHONY: -minty-fresh: minty-fresh +.PHONY: minty-fresh +minty-fresh: $(DOCKER_COMPOSE) down --rmi all --volumes .PHONY: rmi From 9ea4d554bac0890976165c8d2f75369be5bca144 Mon Sep 17 00:00:00 2001 From: wimo7083 Date: Sat, 6 Oct 2018 14:11:09 -0600 Subject: [PATCH 16/16] completed scope and added block scope for mocking --- app/models/job.rb | 8 ++++++++ test/factories/jobs.rb | 14 +++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/models/job.rb b/app/models/job.rb index 75faf331..b521d688 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -4,6 +4,14 @@ class Job < ApplicationRecord scope :is_open, -> { where(closed_at: nil) } scope :is_closed, -> { where.not(closed_at: nil) } + def open? + closed_at.nil? + end + + def closed? + !open? + end + def self.with_tags(*args) tagged_with(args, any: true) end diff --git a/test/factories/jobs.rb b/test/factories/jobs.rb index 40c03bd3..9f9ae1db 100644 --- a/test/factories/jobs.rb +++ b/test/factories/jobs.rb @@ -1,12 +1,12 @@ 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 + 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 } closed_at nil remote false end