Commit 9f94ec6d by Quang Vinh Nguyen

Merge branch 'add-job-controller' into 'master'

Add job controller

See merge request !6
parents 9095b92a 753933f5
{
"editor.tabSize": 2
}
\ No newline at end of file
......@@ -6,6 +6,11 @@ ruby '2.5.1'
gem 'devise', '4.4.3'
gem 'redis'
gem 'json'
gem 'bootstrap'
gem 'jquery-rails'
gem 'kaminari'
gem 'rsolr'
gem 'rsolr-ext'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0'
......
......@@ -48,6 +48,8 @@ GEM
io-like (~> 0.3.0)
arel (9.0.0)
ast (2.4.0)
autoprefixer-rails (8.6.2)
execjs
bcrypt (3.1.12)
bcrypt (3.1.12-java)
bcrypt (3.1.12-x64-mingw32)
......@@ -57,6 +59,10 @@ GEM
msgpack (~> 1.0)
bootsnap (1.3.0-java)
msgpack (~> 1.0)
bootstrap (4.1.1)
autoprefixer-rails (>= 6.0.3)
popper_js (>= 1.12.9, < 2)
sass (>= 3.5.2)
builder (3.2.3)
byebug (10.0.2)
capybara (3.2.1)
......@@ -99,6 +105,8 @@ GEM
railties (>= 3.0.0)
faker (1.8.7)
i18n (>= 0.7)
faraday (0.15.2)
multipart-post (>= 1.2, < 3)
ffi (1.9.25)
ffi (1.9.25-java)
ffi (1.9.25-x64-mingw32)
......@@ -109,11 +117,28 @@ GEM
concurrent-ruby (~> 1.0)
io-like (0.3.0)
jaro_winkler (1.5.1)
jaro_winkler (1.5.1-java)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
jquery-rails (4.3.3)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.1.0)
json (2.1.0-java)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.1.1)
kaminari-actionview (1.1.1)
actionview
kaminari-core (= 1.1.1)
kaminari-activerecord (1.1.1)
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
......@@ -135,6 +160,7 @@ GEM
msgpack (1.2.4-x64-mingw32)
msgpack (1.2.4-x86-mingw32)
multi_json (1.13.1)
multipart-post (2.0.0)
mysql2 (0.5.1)
mysql2 (0.5.1-x64-mingw32)
mysql2 (0.5.1-x86-mingw32)
......@@ -152,6 +178,7 @@ GEM
parallel (1.12.1)
parser (2.5.1.0)
ast (~> 2.4.0)
popper_js (1.12.9)
powerpack (0.1.1)
pry (0.11.3)
coderay (~> 1.1.0)
......@@ -199,6 +226,11 @@ GEM
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
rsolr (2.2.1)
builder (>= 2.1.2)
faraday (>= 0.9.0)
rsolr-ext (1.0.3)
rsolr (>= 1.0.2)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
......@@ -227,7 +259,6 @@ GEM
ruby-progressbar (1.9.0)
ruby_dep (1.5.0)
rubyzip (1.2.1)
safe_yaml (1.0.4)
sass (3.5.6)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
......@@ -296,6 +327,7 @@ PLATFORMS
DEPENDENCIES
bootsnap (>= 1.1.0)
bootstrap
byebug
capybara (>= 2.15, < 4.0)
chromedriver-helper
......@@ -305,16 +337,19 @@ DEPENDENCIES
factory_girl_rails (= 4.9.0)
faker (= 1.8.7)
jbuilder (~> 2.5)
jquery-rails
json
kaminari
listen (>= 3.0.5, < 3.2)
mysql2 (>= 0.4.4, < 0.6.0)
pry
puma (~> 3.11)
rails (~> 5.2.0)
redis
rsolr
rsolr-ext
rspec-rails
rubocop (= 0.57.1)
safe_yaml
sass-rails (~> 5.0)
selenium-webdriver
shoulda-matchers (~> 3.1)
......
......@@ -14,3 +14,6 @@
//= require activestorage
//= require turbolinks
//= require_tree .
//= require jquery3
//= require popper
//= require bootstrap
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
......@@ -10,6 +10,5 @@
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/
@import "bootstrap";
// Place all the styles related to the Jobs controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the StaticPages controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class ApplicationController < ActionController::Base
def index
render html: "Yep, It's working ..."
end
end
class JobsController < ApplicationController
def index
# @jobs = Job.search(params[:search]).order('created_at DESC').page(params[:page])
@job_ids = get_jobs_rsolr(params[:search] || '*')
@jobs = Job.where(id: @job_ids).order('created_at DESC').page(params[:page])
end
def show
@job = Job.find(params[:id])
end
def city
@cities = City.all.select { |city| city.jobs.any? }
end
def jobs_in_city
@city = City.find_by(slug: params[:slug])
@jobs = @city.jobs.page(params[:page])
end
def home
@jobs = Job.all.order(updated_at: :desc).take(5)
@cities = City.all.select{ |city| city.jobs.any? }.take(8)
end
def get_jobs_rsolr(title = '*')
solr = RSolr.connect url: 'http://localhost:8983/solr/gettingstarted/'
search_params = { q: "search_text:*#{title.downcase}*", rows: 5_000 }
response_solr = solr.get 'select', params: search_params
if response_solr['response']['docs'].any?
response_solr['response']['docs'].collect do |row|
row['job_id']
end
end
end
end
class StaticPagesController < ApplicationController
def home
@jobs = Job.all.order(updated_at: :desc).take(5)
@cities = City.all.take(6)
end
end
module JobsHelper
end
module StaticPagesHelper
end
class CitiesJob < ApplicationRecord
belongs_to :job, foreign_key: 'job_id'
belongs_to :city, foreign_key: 'city_id'
validates :job_id, presence: true
validates :city_id, presence: true
end
# frozen_string_literal: true
class City < ApplicationRecord
has_many :jobs, dependent: :destroy
has_many :cities_jobs, foreign_key: 'city_id',
dependent: :destroy
has_many :jobs, through: :cities_jobs
validates :name, presence: true, length: { maximum: 255 },
uniqueness: { case_sensitive: false }
......
class IndustriesJob < ApplicationRecord
belongs_to :job, foreign_key: 'job_id'
belongs_to :industry, foreign_key: 'industry_id'
validates :job_id, presence: true
validates :industry_id, presence: true
end
class Industry < ApplicationRecord
has_many :jobs, dependent: :destroy
has_many :industries_jobs, foreign_key: 'industry_id',
dependent: :destroy
has_many :jobs, through: :industries_jobs
validates :name, presence: true, length: { maximum: 255 },
uniqueness: { case_sensitive: false }
......
......@@ -2,8 +2,14 @@
class Job < ApplicationRecord
belongs_to :company, foreign_key: 'company_id'
belongs_to :city, foreign_key: 'city_id'
belongs_to :industry, foreign_key: 'industry_id'
has_many :cities_jobs, foreign_key: 'job_id',
dependent: :destroy
has_many :cities, through: :cities_jobs
has_many :industries_jobs, foreign_key: 'job_id',
dependent: :destroy
has_many :industries, through: :industries_jobs
has_many :entries, dependent: :destroy
has_many :favorite_jobs, dependent: :destroy
......@@ -26,4 +32,10 @@ class Job < ApplicationRecord
validates :welfare, presence: true, length: { maximum: 1000 }
validates :condition, presence: true, length: { maximum: 1000 }
validates :link, presence: true
paginates_per 10
def self.search(search)
where("title LIKE ?", "%#{search}%")
end
end
<li>
<div class="card" style="width: 40rem;">
<div class="card-body">
<h5 class="card-title"><%= job.title %></h5>
<p class="card-text">some job description</p>
<p>Update date: <%= time_ago_in_words(job.created_at) %> ago. </p>
<!-- <a href="#" class="card-link">Show job</a> -->
<%= link_to 'Show job', job, class: 'card-link' %>
</div>
</div>
</li>
<h3>show all <%= pluralize(@cities.count, 'city') %></h3>
<ul class='list-group'>
<% @cities.each do |city| %>
<li class = 'list-group-item'>
<%= city.name %>
<%= link_to pluralize(city.jobs.count, 'job'),
controller: 'jobs',
action: 'jobs_in_city',
slug: city.slug %>
</li>
<% end %>
</ul>
\ No newline at end of file
<div class='container'>
<div class='container'>
<nav class='navbar navbar-light bg-light'>
<%= form_tag( jobs_path,
method: 'get',
class: 'form-inline') do %>
<%= text_field_tag :search, params[:search],
placeholder: 'Search Jobs',
class: 'form-control mr-sm-2'%>
<%= submit_tag 'Search', name: nil,
class: 'btn btn-outline-success my-2 my-sm-0' %>
<% end %>
</nav>
</div>
<div class='jobs-list'>
<ul>
<%= render @jobs %>
</ul>
</div>
<h4> Cities list </h4>
<div class='cities-list'>
<ul>
<% @cities.each do |city| %>
<li>
<%= city.name %>
<%= link_to pluralize(city.jobs.count, 'job'),
controller: 'jobs',
action: 'jobs_in_city',
slug: city.slug %>
</li>
<% end %>
</ul>
</div
</div>
<h3>Search result: <%= pluralize(@job_ids.length, 'job') unless @job_ids.blank?%></h3>
<nav class='navbar navbar-light bg-light'>
<%= form_tag(jobs_path, method: 'get',
class: 'form-inline') do %>
<%= text_field_tag :search, params[:search],
placeholder: 'Search Jobs',
class: 'form-control mr-sm-2'%>
<%= submit_tag 'Search', name: nil,
class: 'btn btn-outline-success my-2 my-sm-0' %>
<% end %>
</nav>
<ul class='jobs'>
<%= paginate @jobs, outer_window: 3 %>
<%= render @jobs %>
</ul>
\ No newline at end of file
<h4><%= @city.name %>: <%= pluralize(@city.jobs.count, 'job') %></h4>
<div class='container'>
<div class='jobs-list'>
<ul>
<%= paginate @jobs, outer_window: 3 %>
<%= render @jobs %>
</ul>
</div>
</div>
\ No newline at end of file
<div class="row">
<aside class="col-md-16">
<section class="user_info">
<h2>Job detail</h2>
<h4>
<%= @job.title %>
</h4>
<p>
<%= @job.description %>
</p>
</section>
</aside>
</div>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<%= link_to 'Venjobs', root_path, class: 'navbar-brand' %>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<%= link_to 'Home', root_path, class: 'nav-link' %>
</li>
<li class="nav-item active">
<%= link_to 'City', city_jobs_path, class: 'nav-link' %>
</li>
</ul>
</div>
</nav>
......@@ -10,21 +10,12 @@
</head>
<body>
<% if notice %>
<p class="alert alert-success"><%= notice %></p>
<% end %>
<% if alert %>
<p class="alert alert-danger"><%= alert %></p>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |message_type, message| %>
<%= content_tag(:div, message, class: "alert alert-#{message_type}") %>
<% end %>
<!--
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %> alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<%= value %>
</div>
<% end %>
-->
<%= yield %>
</div>
</body>
</html>
<div class='container'>
<div class='jobs-list'>
<ul>
<% @jobs.each do |job| %>
<li>
<div class="card">
<h5 class="card-header"><%= job.title %></h5>
<div class="card-body">
<h5 class="card-title"><%= job.company.name %></h5>
<p class="card-text"><% job.description %></p>
<%= link_to 'Show job', job, class: 'card-link' %>
</div>
</div>
</li>
<% end %>
</ul>
</div>
<h4> Cities list </h4>
<div class='cities-list'>
<ul>
<% @cities.each do |city| %>
<li>
<%= city.code %> -- <%= city.name %>
<%= link_to 'Show', controller: 'jobs', action: 'jobs_in_city', slug: city.slug %>
</li>
<% end %>
</ul>
</div
</div>
# frozen_string_literal: true
Kaminari.configure do |config|
# config.default_per_page = 25
# config.max_per_page = nil
# config.window = 4
# config.outer_window = 0
# config.left = 0
# config.right = 0
# config.page_method_name = :page
# config.param_name = :page
# config.params_on_first_page = false
end
Rails.application.routes.draw do
root to: 'jobs#home'
resources :jobs do
collection do
get 'home'
get 'city'
get 'city/:slug', to: 'jobs#jobs_in_city'
get 'search'
end
end
devise_for :users
root to: 'application#index'
end
......@@ -11,5 +11,6 @@ class CreateCities < ActiveRecord::Migration[5.2]
t.timestamps
end
add_index :cities, [:name, :slug]
end
end
class CreateIndustries < ActiveRecord::Migration[5.2]
def change
create_table :industries do |t|
t.string :code
t.string :name
t.string :slug
t.timestamps
end
add_index :industries, :name
end
end
......@@ -3,8 +3,6 @@ class CreateJobs < ActiveRecord::Migration[5.2]
create_table :jobs do |t|
t.string :title, index: true
t.references :company, foreign_key: true
t.references :city, foreign_key: true
t.references :industry, foreign_key: true
t.string :position
t.decimal :salary, precision: 12, scale: 2
t.datetime :expiry_date
......
class CreateIndustriesJobs < ActiveRecord::Migration[5.2]
def change
create_table :industries_jobs do |t|
t.references :job, foreign_key: true
t.references :industry, foreign_key: true
t.timestamps
end
add_index :industries_jobs, [:job_id, :industry_id], unique: true
end
end
class CreateCitiesJobs < ActiveRecord::Migration[5.2]
def change
create_table :cities_jobs do |t|
t.references :job, foreign_key: true
t.references :city, foreign_key: true
t.timestamps
end
add_index :cities_jobs, [:job_id, :city_id], unique: true
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_06_12_070531) do
ActiveRecord::Schema.define(version: 2018_06_19_011959) do
create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
......@@ -22,6 +22,17 @@ ActiveRecord::Schema.define(version: 2018_06_12_070531) do
t.integer "parent_code"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["name", "slug"], name: "index_cities_on_name_and_slug"
end
create_table "cities_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "job_id"
t.bigint "city_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["city_id"], name: "index_cities_jobs_on_city_id"
t.index ["job_id", "city_id"], name: "index_cities_jobs_on_job_id_and_city_id", unique: true
t.index ["job_id"], name: "index_cities_jobs_on_job_id"
end
create_table "companies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
......@@ -55,16 +66,27 @@ ActiveRecord::Schema.define(version: 2018_06_12_070531) do
end
create_table "industries", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "code"
t.string "name"
t.string "slug"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["name"], name: "index_industries_on_name"
end
create_table "industries_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "job_id"
t.bigint "industry_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["industry_id"], name: "index_industries_jobs_on_industry_id"
t.index ["job_id", "industry_id"], name: "index_industries_jobs_on_job_id_and_industry_id", unique: true
t.index ["job_id"], name: "index_industries_jobs_on_job_id"
end
create_table "jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "title"
t.bigint "company_id"
t.bigint "city_id"
t.bigint "industry_id"
t.string "position"
t.decimal "salary", precision: 12, scale: 2
t.datetime "expiry_date"
......@@ -76,9 +98,7 @@ ActiveRecord::Schema.define(version: 2018_06_12_070531) do
t.text "link"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["city_id"], name: "index_jobs_on_city_id"
t.index ["company_id"], name: "index_jobs_on_company_id"
t.index ["industry_id"], name: "index_jobs_on_industry_id"
t.index ["title", "update_date"], name: "index_jobs_on_title_and_update_date"
t.index ["title"], name: "index_jobs_on_title"
end
......@@ -104,11 +124,13 @@ ActiveRecord::Schema.define(version: 2018_06_12_070531) do
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
add_foreign_key "cities_jobs", "cities"
add_foreign_key "cities_jobs", "jobs"
add_foreign_key "entries", "jobs"
add_foreign_key "entries", "users"
add_foreign_key "favorite_jobs", "jobs"
add_foreign_key "favorite_jobs", "users"
add_foreign_key "jobs", "cities"
add_foreign_key "industries_jobs", "industries"
add_foreign_key "industries_jobs", "jobs"
add_foreign_key "jobs", "companies"
add_foreign_key "jobs", "industries"
end
# frozen_string_literal: true
namespace :importdb do
require 'pry'
require 'json'
......@@ -7,19 +9,17 @@ namespace :importdb do
desc 'import data to cities table'
task cities: :environment do
provs = Redis.new
provs_hash_arr = provs.smembers 'cities'
provs_hash = JSON.parse(provs_hash_arr[0])
provs_hash.each do |code, prov|
City.create!( name: prov['name'],
slug: prov['slug'],
city_type: prov['type'],
name_with_type: prov['name_with_type'],
code: prov['code'])
city_redis = Redis.new
city_yaml_arr = city_redis.smembers('cities')
city_yaml_arr.each do |row|
city = YAML.safe_load(row)
next if City.find_by(name: city[1])
City.create!( code: city[0],
name: city[1],
slug: city[2])
end
end
desc 'import data to companies table'
task companies: :environment do
Company.create!(
......@@ -35,11 +35,14 @@ namespace :importdb do
desc 'seed industries data'
task industries: :environment do
path = Rails.root.join('db', 'industries.csv')
CSV.foreach(path) do |csv|
Industry.create(
name: csv[1]
)
inds_redis = Redis.new
inds_yaml_arr = inds_redis.smembers('industry')
inds_yaml_arr.each do |row|
ind = YAML.safe_load(row)
next if Industry.find_by(name: ind[1])
Industry.create!( code: ind[0],
name: ind[1],
slug: ind[2] )
end
end
......@@ -47,14 +50,13 @@ namespace :importdb do
task jobs: :environment do
jobs_redis = Redis.new
jobs_yaml_arr = jobs_redis.smembers 'crawled'
jobs_yaml_arr.each do |row|
job = YAML.load(row)
jobs_yaml_arr.each_with_index do |row,id|
# break if id == 3
job = YAML.safe_load(row)
next if job[1].blank? || !!Job.find_by(title: job[1]) || !!Job.find_by(link: job[14])
Job.create!(
job_new = Job.create!(
title: job[1],
company_id: 1,
city_id: 1,
industry_id: 1,
position: 'NA',
salary: '1_000',
expiry_date: Time.now,
......@@ -63,8 +65,29 @@ namespace :importdb do
published: true,
welfare: 'NA',
condition: 'NA',
link: job[14],
link: job[14]
)
# import job industry
industry_arr = job[5].split('+').map { |ind| ind.strip }
if industry_arr.any?
industry_arr.each do |ind|
ind_id = Industry.find_by(name: ind).id || Industry.first.id
job_new.industries_jobs.create!(industry_id: ind_id)
end
else
job_new.industries_jobs.create!(industry_id: City.first.id)
end
# import job industry
city_arr = job[3].split(',').map { |city| city.strip }
if city_arr.any?
city_arr.each do |city|
city_id = City.find_by(name: city).id || City.first.id
job_new.cities_jobs.create!(city_id: city_id)
end
else
job_new.cities_jobs.create!(city_id: City.first.id)
end
end
end
end
# frozen_string_literal: true
namespace :update do
desc 'update solr index from database'
task solr: :environment do
solr = RSolr.connect url: 'http://localhost:8983/solr/gettingstarted/'
jobs = Job.all
if jobs.any?
jobs.each_with_index do |job, _id|
# break if id == 102
# check is job_id is exist and not update job to solr
response_solr = solr.get 'select', params: { q: "job_id: #{job['id']}" }
next if response_solr['response']['docs'].any?
# hash of job attribute array: city_name, ...
h = {}
h['city_id'] = job.cities.collect { |city| city['id'].to_s }
h['city_name'] = job.cities.collect { |city| city['name'].downcase }
h['city_slug'] = job.cities.collect { |city| city['slug'] }
h['industry_id'] = job.industries.collect { |ind| ind['id'].to_s }
h['industry_name'] = job.industries.collect { |ind| ind['name'].downcase }
h['industry_slug'] = job.industries.collect { |ind| ind['slug'] }
doc = {
job_id: job.id,
job_title: job.title.downcase,
job_city_id: h['city_id'],
job_city_name: h['city_name'],
job_city_slug: h['city_slug'],
job_industry_id: h['industry_id'],
job_industry_name: h['industry_name'],
job_industry_slug: h['industry_slug']
}
solr.add [doc]
end
solr.commit
end
end
end
require 'rails_helper'
RSpec.describe JobsController, type: :controller do
describe "GET #index" do
it "returns http success" do
get :index
expect(response).to have_http_status(:success)
end
end
end
require 'rails_helper'
RSpec.describe StaticPagesController, type: :controller do
describe "GET #home" do
it "returns http success" do
get :home
expect(response).to have_http_status(:success)
end
end
end
FactoryGirl.define do
factory :cities_job do
job nil
city nil
end
end
FactoryGirl.define do
factory :industries_job do
job nil
industry nil
end
end
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the JobsHelper. For example:
#
# describe JobsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe JobsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the StaticPagesHelper. For example:
#
# describe StaticPagesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe StaticPagesHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end
require 'rails_helper'
RSpec.describe CitiesJob, type: :model do
describe 'db schema' do
context 'index' do
it do
should have_db_index(:job_id)
should have_db_index(:city_id)
end
end
context 'foreign key' do
it do
should belong_to(:job).with_foreign_key('job_id')
should belong_to(:city).with_foreign_key('city_id')
end
end
end
describe 'validations' do
it do
should validate_presence_of(:job_id)
should validate_presence_of(:city_id)
end
end
end
......@@ -16,7 +16,8 @@ RSpec.describe City, type: :model do
should have_db_column(:parent_code).of_type(:integer)
end
it { should have_many(:jobs).dependent(:destroy) }
it { should have_many(:cities_jobs).dependent(:destroy) }
it { should have_many(:jobs).through(:cities_jobs) }
end
it 'right values input' do
......
require 'rails_helper'
RSpec.describe IndustriesJob, type: :model do
describe 'db schema' do
context 'index' do
it do
should have_db_index(:job_id)
should have_db_index(:industry_id)
end
end
context 'foreign key' do
it do
should belong_to(:job).with_foreign_key('job_id')
should belong_to(:industry).with_foreign_key('industry_id')
end
end
end
describe 'validations' do
it do
should validate_presence_of(:job_id)
should validate_presence_of(:industry_id)
end
end
end
......@@ -7,7 +7,8 @@ RSpec.describe Industry, type: :model do
describe 'db schema' do
it { should have_db_column(:name).of_type(:string) }
it { should have_many(:jobs).dependent(:destroy) }
it { should have_many(:industries_jobs).dependent(:destroy) }
it { should have_many(:jobs).through(:industries_jobs) }
end
it 'right values input' do
......
......@@ -19,22 +19,22 @@ RSpec.describe Job, type: :model do
it { should have_many(:entries).dependent(:destroy) }
it { should have_many(:favorite_jobs).dependent(:destroy) }
it { should have_many(:cities_jobs).dependent(:destroy) }
it { should have_many(:cities).through(:cities_jobs) }
it { should have_many(:industries_jobs).dependent(:destroy) }
it { should have_many(:industries).through(:industries_jobs) }
end
context 'index' do
it do
should have_db_index(:title)
should have_db_index(:city_id)
should have_db_index(:company_id)
should have_db_index(:industry_id)
end
end
context 'foreign key' do
it do
should belong_to(:company).with_foreign_key('company_id')
should belong_to(:city).with_foreign_key('city_id')
should belong_to(:industry).with_foreign_key('industry_id')
end
end
end
......@@ -45,9 +45,7 @@ RSpec.describe Job, type: :model do
let(:job) do
FactoryGirl.create(
:job,
company_id: company.id,
city_id: city.id,
industry_id: industry.id
company_id: company.id
)
end
......
require 'rails_helper'
RSpec.describe "jobs/index.html.erb", type: :view do
pending "add some examples to (or delete) #{__FILE__}"
end
require 'rails_helper'
RSpec.describe "static_pages/home.html.erb", type: :view do
pending "add some examples to (or delete) #{__FILE__}"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment