Commit 9095b92a by Quang Vinh Nguyen

Merge branch 'add_user_table' into 'master'

add user table and import data

See merge request !5
parents bdc9df2d 41ecfd29
...@@ -4,6 +4,8 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ...@@ -4,6 +4,8 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1' ruby '2.5.1'
gem 'devise', '4.4.3' gem 'devise', '4.4.3'
gem 'redis'
gem 'json'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0' gem 'rails', '~> 5.2.0'
...@@ -57,6 +59,7 @@ group :development do ...@@ -57,6 +59,7 @@ group :development do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring' gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0' gem 'spring-watcher-listen', '~> 2.0.0'
gem 'pry'
end end
group :test do group :test do
......
...@@ -71,6 +71,7 @@ GEM ...@@ -71,6 +71,7 @@ GEM
chromedriver-helper (1.2.0) chromedriver-helper (1.2.0)
archive-zip (~> 0.10) archive-zip (~> 0.10)
nokogiri (~> 1.8) nokogiri (~> 1.8)
coderay (1.1.2)
coffee-rails (4.2.2) coffee-rails (4.2.2)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
railties (>= 4.0.0) railties (>= 4.0.0)
...@@ -111,6 +112,8 @@ GEM ...@@ -111,6 +112,8 @@ GEM
jbuilder (2.7.0) jbuilder (2.7.0)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
multi_json (>= 1.2) multi_json (>= 1.2)
json (2.1.0)
json (2.1.0-java)
listen (3.1.5) listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4) rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7) rb-inotify (~> 0.9, >= 0.9.7)
...@@ -150,6 +153,13 @@ GEM ...@@ -150,6 +153,13 @@ GEM
parser (2.5.1.0) parser (2.5.1.0)
ast (~> 2.4.0) ast (~> 2.4.0)
powerpack (0.1.1) powerpack (0.1.1)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry (0.11.3-java)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
spoon (~> 0.0)
public_suffix (3.0.2) public_suffix (3.0.2)
puma (3.11.4) puma (3.11.4)
puma (3.11.4-java) puma (3.11.4-java)
...@@ -185,6 +195,7 @@ GEM ...@@ -185,6 +195,7 @@ GEM
rb-fsevent (0.10.3) rb-fsevent (0.10.3)
rb-inotify (0.9.10) rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2) ffi (>= 0.5.0, < 2)
redis (4.0.1)
responders (2.4.0) responders (2.4.0)
actionpack (>= 4.2.0, < 5.3) actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3)
...@@ -216,6 +227,7 @@ GEM ...@@ -216,6 +227,7 @@ GEM
ruby-progressbar (1.9.0) ruby-progressbar (1.9.0)
ruby_dep (1.5.0) ruby_dep (1.5.0)
rubyzip (1.2.1) rubyzip (1.2.1)
safe_yaml (1.0.4)
sass (3.5.6) sass (3.5.6)
sass-listen (~> 4.0.0) sass-listen (~> 4.0.0)
sass-listen (4.0.0) sass-listen (4.0.0)
...@@ -232,6 +244,8 @@ GEM ...@@ -232,6 +244,8 @@ GEM
rubyzip (~> 1.2) rubyzip (~> 1.2)
shoulda-matchers (3.1.2) shoulda-matchers (3.1.2)
activesupport (>= 4.0.0) activesupport (>= 4.0.0)
spoon (0.0.6)
ffi
spring (2.0.2) spring (2.0.2)
activesupport (>= 4.2) activesupport (>= 4.2)
spring-watcher-listen (2.0.1) spring-watcher-listen (2.0.1)
...@@ -291,12 +305,16 @@ DEPENDENCIES ...@@ -291,12 +305,16 @@ DEPENDENCIES
factory_girl_rails (= 4.9.0) factory_girl_rails (= 4.9.0)
faker (= 1.8.7) faker (= 1.8.7)
jbuilder (~> 2.5) jbuilder (~> 2.5)
json
listen (>= 3.0.5, < 3.2) listen (>= 3.0.5, < 3.2)
mysql2 (>= 0.4.4, < 0.6.0) mysql2 (>= 0.4.4, < 0.6.0)
pry
puma (~> 3.11) puma (~> 3.11)
rails (~> 5.2.0) rails (~> 5.2.0)
redis
rspec-rails rspec-rails
rubocop (= 0.57.1) rubocop (= 0.57.1)
safe_yaml
sass-rails (~> 5.0) sass-rails (~> 5.0)
selenium-webdriver selenium-webdriver
shoulda-matchers (~> 3.1) shoulda-matchers (~> 3.1)
......
# frozen_string_literal: true # frozen_string_literal: true
class City < ApplicationRecord class City < ApplicationRecord
validates :name, presence: true, length: { maximum: 50 }, has_many :jobs, dependent: :destroy
validates :name, presence: true, length: { maximum: 255 },
uniqueness: { case_sensitive: false } uniqueness: { case_sensitive: false }
validates :city_type, length: { maximum: 50 } validates :city_type, length: { maximum: 255 }
validates :slug, length: { maximum: 50 } validates :slug, length: { maximum: 255 }
validates :name_with_type, length: { maximum: 50 } validates :name_with_type, length: { maximum: 255 }
validates :path, length: { maximum: 50 } validates :path, length: { maximum: 255 }
end end
class Company < ApplicationRecord class Company < ApplicationRecord
has_many :jobs, dependent: :destroy
validates :name, presence: true, length: { maximum: 255 }, validates :name, presence: true, length: { maximum: 255 },
uniqueness: { case_sensitive: false } uniqueness: { case_sensitive: false }
validates :description, presence: true validates :description, presence: true, length: { maximum: 1000 }
validates :address, presence: true, length: { maximum: 255 } validates :address, presence: true, length: { maximum: 255 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
validates :email, length: { maximum: 255 }, validates :email, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX } format: { with: VALID_EMAIL_REGEX }
VALID_PHONE_REGEX = /\A^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}\z/ VALID_PHONE_REGEX = /\A^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}\z/
validates :phone, length: { maximum: 20 }, validates :phone, length: { maximum: 50 },
format: { with: VALID_PHONE_REGEX } format: { with: VALID_PHONE_REGEX }
validates :fax, length: { maximum: 20 } validates :fax, length: { maximum: 50 }
validates :number_of_employees, length: { maximum: 20 } validates :number_of_employees, length: { maximum: 255 }
end end
class Entry < ApplicationRecord
belongs_to :user, foreign_key: 'user_id'
belongs_to :job, foreign_key: 'job_id'
end
class FavoriteJob < ApplicationRecord
belongs_to :user, foreign_key: 'user_id'
belongs_to :job, foreign_key: 'job_id'
end
class Industry < ApplicationRecord class Industry < ApplicationRecord
has_many :jobs, dependent: :destroy
validates :name, presence: true, length: { maximum: 255 }, validates :name, presence: true, length: { maximum: 255 },
uniqueness: { case_sensitive: false } uniqueness: { case_sensitive: false }
end end
# frozen_string_literal: true
class Job < ApplicationRecord class Job < ApplicationRecord
belongs_to :company, foreign_key: 'company_id' belongs_to :company, foreign_key: 'company_id'
belongs_to :city, foreign_key: 'city_id' belongs_to :city, foreign_key: 'city_id'
belongs_to :industry, foreign_key: 'industry_id' belongs_to :industry, foreign_key: 'industry_id'
has_many :entries, dependent: :destroy
has_many :favorite_jobs, dependent: :destroy
validates :title, presence: true, length: { maximum: 255 },
uniqueness: { case_sensitive: false }
validates :position, presence: true, length: { maximum: 255 }
VALID_NUMBER_REGEX = /\A((\d{0,12}(\.\d{0,2})?)|(\.\d{0,2}))\z/
validates :salary, presence: true,
format: { with: VALID_NUMBER_REGEX },
numericality: {
greater_than: 0.00,
less_than: 999_999_999_999.99
}
validates :expiry_date, presence: true
validates :description, presence: true, length: { maximum: 1000 }
validates :update_date, presence: true
validates :published, presence: true, inclusion: { in: [true, false] }
validates :welfare, presence: true, length: { maximum: 1000 }
validates :condition, presence: true, length: { maximum: 1000 }
validates :link, presence: true
end end
...@@ -4,4 +4,21 @@ class User < ApplicationRecord ...@@ -4,4 +4,21 @@ class User < ApplicationRecord
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :recoverable, :rememberable, :trackable, :validatable,
:confirmable :confirmable
has_many :entries, dependent: :destroy
has_many :favorite_jobs, dependent: :destroy
validates :name, presence: true, length: { maximum: 255 }
validates :prefix, presence: true
VALID_PHONE_REGEX = /\A^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}\z/
validates :phone, length: { maximum: 50 },
format: { with: VALID_PHONE_REGEX }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
validates :email, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX }
validates :password, presence: true, length: { minimum: 8 }
end end
1,Ngành Kế Toán, buôn bán - kinh doanh
2,Ngành kiểm toán, buôn bán - kinh doanh
3,Ngành Thương mại Điện Tử, buôn bán - kinh doanh
4,Ngành Tài Chính – Ngân hàng, buôn bán - kinh doanh
5,Quản Trị Kinh Doanh., buôn bán - kinh doanh
6,Kinh tế - Tài chính, buôn bán - kinh doanh
7,Ngành marketing, buôn bán - kinh doanh
8,Ngành Bảo hiểm., buôn bán - kinh doanh
9,Ngành quảng cáo, buôn bán - kinh doanh
10,Ngành Quảng trị nhân sự, buôn bán - kinh doanh
11,Quản trị khách sạn, buôn bán - kinh doanh
12,Chứng khoán, buôn bán - kinh doanh
13,Thanh toán quốc tế, buôn bán - kinh doanh
\ No newline at end of file
class CreateCities < ActiveRecord::Migration[5.2] class CreateCities < ActiveRecord::Migration[5.2]
def change def change
create_table :cities do |t| create_table :cities do |t|
t.string :name, limit: 50 t.string :name
t.string :city_type, limit: 50 t.string :city_type
t.string :slug, limit: 50 t.string :slug
t.string :name_with_type, limit: 50 t.string :name_with_type
t.string :path, limit: 50 t.string :path
t.integer :code t.integer :code
t.integer :parent_code t.integer :parent_code
......
class CreateIndustries < ActiveRecord::Migration[5.2] class CreateIndustries < ActiveRecord::Migration[5.2]
def change def change
create_table :industries do |t| create_table :industries do |t|
t.string :name, limit: 255 t.string :name
t.timestamps t.timestamps
end end
......
class CreateCompanies < ActiveRecord::Migration[5.2] class CreateCompanies < ActiveRecord::Migration[5.2]
def change def change
create_table :companies do |t| create_table :companies do |t|
t.string :name, limit: 255 t.string :name
t.text :description, limit: 1000 t.text :description
t.string :address, limit: 255 t.string :address
t.string :email, limit: 255 t.string :email
t.string :phone, limit: 20 t.string :phone
t.string :fax, limit: 20 t.string :fax
t.string :number_of_employees, limit: 20 t.string :number_of_employees
t.timestamps t.timestamps
end end
......
...@@ -5,7 +5,7 @@ class CreateJobs < ActiveRecord::Migration[5.2] ...@@ -5,7 +5,7 @@ class CreateJobs < ActiveRecord::Migration[5.2]
t.references :company, foreign_key: true t.references :company, foreign_key: true
t.references :city, foreign_key: true t.references :city, foreign_key: true
t.references :industry, foreign_key: true t.references :industry, foreign_key: true
t.string :position, limit: 55 t.string :position
t.decimal :salary, precision: 12, scale: 2 t.decimal :salary, precision: 12, scale: 2
t.datetime :expiry_date t.datetime :expiry_date
t.text :description t.text :description
...@@ -13,7 +13,8 @@ class CreateJobs < ActiveRecord::Migration[5.2] ...@@ -13,7 +13,8 @@ class CreateJobs < ActiveRecord::Migration[5.2]
t.boolean :published t.boolean :published
t.text :welfare t.text :welfare
t.text :condition t.text :condition
t.text :link
t.timestamps t.timestamps
end end
add_index :jobs, [ :title, :update_date ] add_index :jobs, [ :title, :update_date ]
......
...@@ -5,7 +5,7 @@ class DeviseCreateUsers < ActiveRecord::Migration[5.2] ...@@ -5,7 +5,7 @@ class DeviseCreateUsers < ActiveRecord::Migration[5.2]
create_table :users do |t| create_table :users do |t|
t.string :name, null: false, default: '' t.string :name, null: false, default: ''
t.string :title, default: '' t.string :prefix, default: ''
t.string :phone, default: '' t.string :phone, default: ''
t.boolean :registration, default: false t.boolean :registration, default: false
......
class CreateFavoriteJobs < ActiveRecord::Migration[5.2]
def change
create_table :favorite_jobs do |t|
t.references :user, foreign_key: true
t.references :job, foreign_key: true
t.timestamps
end
end
end
class CreateEntries < ActiveRecord::Migration[5.2]
def change
create_table :entries do |t|
t.references :user, foreign_key: true
t.references :job, foreign_key: true
t.timestamps
end
end
end
...@@ -10,14 +10,14 @@ ...@@ -10,14 +10,14 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_06_07_084045) do ActiveRecord::Schema.define(version: 2018_06_12_070531) do
create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name", limit: 50 t.string "name"
t.string "city_type", limit: 50 t.string "city_type"
t.string "slug", limit: 50 t.string "slug"
t.string "name_with_type", limit: 50 t.string "name_with_type"
t.string "path", limit: 50 t.string "path"
t.integer "code" t.integer "code"
t.integer "parent_code" t.integer "parent_code"
t.datetime "created_at", null: false t.datetime "created_at", null: false
...@@ -29,11 +29,29 @@ ActiveRecord::Schema.define(version: 2018_06_07_084045) do ...@@ -29,11 +29,29 @@ ActiveRecord::Schema.define(version: 2018_06_07_084045) do
t.text "description" t.text "description"
t.string "address" t.string "address"
t.string "email" t.string "email"
t.string "phone", limit: 20 t.string "phone"
t.string "fax", limit: 20 t.string "fax"
t.string "number_of_employees", limit: 20 t.string "number_of_employees"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "entries", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "user_id"
t.bigint "job_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["job_id"], name: "index_entries_on_job_id"
t.index ["user_id"], name: "index_entries_on_user_id"
end
create_table "favorite_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "user_id"
t.bigint "job_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["job_id"], name: "index_favorite_jobs_on_job_id"
t.index ["user_id"], name: "index_favorite_jobs_on_user_id"
end end
create_table "industries", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "industries", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
...@@ -47,7 +65,7 @@ ActiveRecord::Schema.define(version: 2018_06_07_084045) do ...@@ -47,7 +65,7 @@ ActiveRecord::Schema.define(version: 2018_06_07_084045) do
t.bigint "company_id" t.bigint "company_id"
t.bigint "city_id" t.bigint "city_id"
t.bigint "industry_id" t.bigint "industry_id"
t.string "position", limit: 55 t.string "position"
t.decimal "salary", precision: 12, scale: 2 t.decimal "salary", precision: 12, scale: 2
t.datetime "expiry_date" t.datetime "expiry_date"
t.text "description" t.text "description"
...@@ -55,6 +73,7 @@ ActiveRecord::Schema.define(version: 2018_06_07_084045) do ...@@ -55,6 +73,7 @@ ActiveRecord::Schema.define(version: 2018_06_07_084045) do
t.boolean "published" t.boolean "published"
t.text "welfare" t.text "welfare"
t.text "condition" t.text "condition"
t.text "link"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["city_id"], name: "index_jobs_on_city_id" t.index ["city_id"], name: "index_jobs_on_city_id"
...@@ -66,7 +85,7 @@ ActiveRecord::Schema.define(version: 2018_06_07_084045) do ...@@ -66,7 +85,7 @@ ActiveRecord::Schema.define(version: 2018_06_07_084045) do
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name", default: "", null: false t.string "name", default: "", null: false
t.string "title", default: "" t.string "prefix", default: ""
t.string "phone", default: "" t.string "phone", default: ""
t.boolean "registration", default: false t.boolean "registration", default: false
t.string "email", default: "", null: false t.string "email", default: "", null: false
...@@ -85,6 +104,10 @@ ActiveRecord::Schema.define(version: 2018_06_07_084045) do ...@@ -85,6 +104,10 @@ ActiveRecord::Schema.define(version: 2018_06_07_084045) do
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end end
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 "jobs", "cities"
add_foreign_key "jobs", "companies" add_foreign_key "jobs", "companies"
add_foreign_key "jobs", "industries" add_foreign_key "jobs", "industries"
......
...@@ -5,3 +5,13 @@ ...@@ -5,3 +5,13 @@
# #
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first) # Character.create(name: 'Luke', movie: movies.first)
Company.create!(
name: Faker::Company.name,
description: Faker::Lorem.paragraph,
address: Faker::Address.street_address,
email: Faker::Internet.email,
phone: '123-456-7890', #Faker::PhoneNumber.phone_number,
fax: '123-456-7890', #Faker::PhoneNumber.phone_number,
number_of_employees: '1000 - 2000'
)
\ No newline at end of file
namespace :importdb do
require 'pry'
require 'json'
require 'redis'
require 'csv'
require 'yaml'
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'])
end
end
desc 'import data to companies table'
task companies: :environment do
Company.create!(
name: Faker::Company.name,
description: Faker::Lorem.paragraph,
address: Faker::Address.street_address,
email: Faker::Internet.email,
phone: '123-456-7890',
fax: '123-456-7890',
number_of_employees: '1000 - 2000'
)
end
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]
)
end
end
desc 'seed jobs data'
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)
next if job[1].blank? || !!Job.find_by(title: job[1]) || !!Job.find_by(link: job[14])
Job.create!(
title: job[1],
company_id: 1,
city_id: 1,
industry_id: 1,
position: 'NA',
salary: '1_000',
expiry_date: Time.now,
description: 'NA',
update_date: Time.now,
published: true,
welfare: 'NA',
condition: 'NA',
link: job[14],
)
end
end
end
...@@ -8,4 +8,4 @@ FactoryGirl.define do ...@@ -8,4 +8,4 @@ FactoryGirl.define do
code '89' code '89'
parent_code '89' parent_code '89'
end end
end end
\ No newline at end of file
...@@ -8,4 +8,4 @@ FactoryGirl.define do ...@@ -8,4 +8,4 @@ FactoryGirl.define do
fax '123-456-7890' #Faker::PhoneNumber.phone_number fax '123-456-7890' #Faker::PhoneNumber.phone_number
number_of_employees '1000 - 2000' number_of_employees '1000 - 2000'
end end
end end
\ No newline at end of file
FactoryGirl.define do
factory :entry do
user nil
job nil
end
end
FactoryGirl.define do
factory :favorite_job do
user nil
job nil
end
end
...@@ -2,4 +2,4 @@ FactoryGirl.define do ...@@ -2,4 +2,4 @@ FactoryGirl.define do
factory :industry do factory :industry do
name Faker::Company.industry name Faker::Company.industry
end end
end end
\ No newline at end of file
FactoryGirl.define do FactoryGirl.define do
factory :job do factory :job do
title Faker::Lorem.sentence title Faker::Lorem.sentence
company_id 1
city_id 1
industry_id 1
position Faker::Lorem.word position Faker::Lorem.word
salary Faker::Number.decimal(5, 2) salary Faker::Number.decimal(5, 2)
expiry_date 1.month.from_now expiry_date 1.month.from_now
description Faker::Lorem.paragraph description Faker::Lorem.paragraph
update_date Time.now update_date Time.now
published Faker::Boolean.boolean published true
welfare Faker::Lorem.paragraph welfare Faker::Lorem.paragraph
condition Faker::Lorem.paragraph condition Faker::Lorem.paragraph
link Faker::Internet.url
end end
end end
\ No newline at end of file
FactoryGirl.define do
factory :user, class: 'User' do
name Faker::Name.name
prefix Faker::Name.prefix
phone '123-456-7890'
registration true
email Faker::Internet.email
password 'password'
password_confirmation 'password'
end
end
\ No newline at end of file
...@@ -15,22 +15,24 @@ RSpec.describe City, type: :model do ...@@ -15,22 +15,24 @@ RSpec.describe City, type: :model do
should have_db_column(:code).of_type(:integer) should have_db_column(:code).of_type(:integer)
should have_db_column(:parent_code).of_type(:integer) should have_db_column(:parent_code).of_type(:integer)
end end
it { should have_many(:jobs).dependent(:destroy) }
end end
it 'should be validates' do it 'right values input' do
expect(city).to be_valid expect(city).to be_valid
end end
describe 'validations' do describe 'validations' do
it do it do
should validate_presence_of(:name) should validate_presence_of(:name)
should validate_length_of(:name).is_at_most(50) should validate_length_of(:name).is_at_most(255)
should validate_uniqueness_of(:name).case_insensitive should validate_uniqueness_of(:name).case_insensitive
should validate_length_of(:city_type).is_at_most(50) should validate_length_of(:city_type).is_at_most(255)
should validate_length_of(:slug).is_at_most(50) should validate_length_of(:slug).is_at_most(255)
should validate_length_of(:name_with_type).is_at_most(50) should validate_length_of(:name_with_type).is_at_most(255)
should validate_length_of(:path).is_at_most(50) should validate_length_of(:path).is_at_most(255)
end end
end end
end end
...@@ -15,9 +15,11 @@ RSpec.describe Company, type: :model do ...@@ -15,9 +15,11 @@ RSpec.describe Company, type: :model do
should have_db_column(:fax).of_type(:string) should have_db_column(:fax).of_type(:string)
should have_db_column(:number_of_employees).of_type(:string) should have_db_column(:number_of_employees).of_type(:string)
end end
it { should have_many(:jobs).dependent(:destroy) }
end end
it 'should be validates' do it 'right values input' do
expect(company).to be_valid expect(company).to be_valid
end end
...@@ -28,6 +30,7 @@ RSpec.describe Company, type: :model do ...@@ -28,6 +30,7 @@ RSpec.describe Company, type: :model do
should validate_uniqueness_of(:name).case_insensitive should validate_uniqueness_of(:name).case_insensitive
should validate_presence_of(:description) should validate_presence_of(:description)
should validate_length_of(:description).is_at_most(1000)
should validate_presence_of(:address) should validate_presence_of(:address)
should validate_length_of(:address).is_at_most(255) should validate_length_of(:address).is_at_most(255)
...@@ -42,7 +45,7 @@ RSpec.describe Company, type: :model do ...@@ -42,7 +45,7 @@ RSpec.describe Company, type: :model do
should allow_value(valid_address).for(:email) should allow_value(valid_address).for(:email)
end end
should validate_length_of(:phone).is_at_most(20) should validate_length_of(:phone).is_at_most(50)
valid_phone_numbers = ['123-456-7890', valid_phone_numbers = ['123-456-7890',
'(123) 456-7890', '(123) 456-7890',
'123 456 7890', '123 456 7890',
...@@ -52,8 +55,8 @@ RSpec.describe Company, type: :model do ...@@ -52,8 +55,8 @@ RSpec.describe Company, type: :model do
should allow_value(phone_number).for(:phone) should allow_value(phone_number).for(:phone)
end end
should validate_length_of(:fax).is_at_most(20) should validate_length_of(:fax).is_at_most(50)
should validate_length_of(:number_of_employees).is_at_most(20) should validate_length_of(:number_of_employees).is_at_most(255)
end end
end end
end end
require 'rails_helper'
RSpec.describe Entry, type: :model do
describe 'db schema' do
context 'index' do
it do
should have_db_index(:job_id)
should have_db_index(:user_id)
end
end
context 'foreign key' do
it do
should belong_to(:job).with_foreign_key('job_id')
should belong_to(:user).with_foreign_key('user_id')
end
end
end
end
require 'rails_helper'
RSpec.describe FavoriteJob, type: :model do
describe 'db schema' do
context 'index' do
it do
should have_db_index(:job_id)
should have_db_index(:user_id)
end
end
context 'foreign key' do
it do
should belong_to(:job).with_foreign_key('job_id')
should belong_to(:user).with_foreign_key('user_id')
end
end
end
end
...@@ -7,9 +7,10 @@ RSpec.describe Industry, type: :model do ...@@ -7,9 +7,10 @@ RSpec.describe Industry, type: :model do
describe 'db schema' do describe 'db schema' do
it { should have_db_column(:name).of_type(:string) } it { should have_db_column(:name).of_type(:string) }
it { should have_many(:jobs).dependent(:destroy) }
end end
it 'should be validates' do it 'right values input' do
expect(industry).to be_valid expect(industry).to be_valid
end end
...@@ -21,6 +22,3 @@ RSpec.describe Industry, type: :model do ...@@ -21,6 +22,3 @@ RSpec.describe Industry, type: :model do
end end
end end
end end
...@@ -16,6 +16,9 @@ RSpec.describe Job, type: :model do ...@@ -16,6 +16,9 @@ RSpec.describe Job, type: :model do
should have_db_column(:welfare).of_type(:text) should have_db_column(:welfare).of_type(:text)
should have_db_column(:condition).of_type(:text) should have_db_column(:condition).of_type(:text)
end end
it { should have_many(:entries).dependent(:destroy) }
it { should have_many(:favorite_jobs).dependent(:destroy) }
end end
context 'index' do context 'index' do
...@@ -36,18 +39,56 @@ RSpec.describe Job, type: :model do ...@@ -36,18 +39,56 @@ RSpec.describe Job, type: :model do
end end
end end
let(:company) { FactoryGirl.create(:company) }
let(:city) { FactoryGirl.create(:city) }
let(:industry) { FactoryGirl.create(:industry) }
let(:job) do let(:job) do
Job.new(title: 'dev', FactoryGirl.create(
company_id: 1, :job,
city_id: 1, company_id: company.id,
industry_id: 1, city_id: city.id,
position: 'junior', industry_id: industry.id
salary: 2000.00, )
expiry_date: 1.month.from_now, end
description: 'abcdef',
update_date: Time.now, it 'right values input' do
published: true, expect(job).to be_valid
welfare: 'abc', end
condition: 'def')
describe 'validate' do
it do
should validate_presence_of(:title)
should validate_length_of(:title).is_at_most(255)
should validate_uniqueness_of(:title).case_insensitive
should validate_presence_of(:position)
should validate_length_of(:position).is_at_most(255)
should validate_presence_of(:salary)
should allow_value('123456.67').for(:salary)
should validate_numericality_of(:salary)
.is_greater_than(0.00)
should validate_numericality_of(:salary)
.is_less_than(999_999_999_999.99)
should validate_presence_of(:expiry_date)
should validate_presence_of(:description)
should validate_length_of(:description).is_at_most(1000)
should validate_presence_of(:update_date)
should validate_presence_of(:published)
# should allow_value(true, false).for(:published)
# should validate_inclusion_of(:published).in_array([true, false])
should validate_presence_of(:welfare)
should validate_length_of(:welfare).is_at_most(1000)
should validate_presence_of(:condition)
should validate_length_of(:condition).is_at_most(1000)
should validate_presence_of(:link)
end
end end
end end
require 'rails_helper' require 'rails_helper'
RSpec.describe User, type: :model do RSpec.describe User, type: :model do
pending "add some examples to (or delete) #{__FILE__}" let(:user) { FactoryGirl.create(:user) }
describe 'db schema' do
it do
should have_db_column(:name).of_type(:string)
should have_db_column(:prefix).of_type(:string)
should have_db_column(:phone).of_type(:string)
should have_db_column(:registration).of_type(:boolean)
should have_db_column(:email).of_type(:string)
should have_db_column(:encrypted_password).of_type(:string)
should have_db_column(:reset_password_token).of_type(:string)
should have_db_column(:reset_password_sent_at).of_type(:datetime)
should have_db_column(:remember_created_at).of_type(:datetime)
should have_db_column(:confirmation_token).of_type(:string)
should have_db_column(:confirmed_at).of_type(:datetime)
should have_db_column(:confirmation_sent_at).of_type(:datetime)
should have_db_column(:unconfirmed_email).of_type(:string)
end
it { should have_many(:entries).dependent(:destroy) }
it { should have_many(:favorite_jobs).dependent(:destroy) }
end
# it 'right values input' do
# expect(user).to be_valid
# end
describe 'validations' do
it do
should validate_presence_of(:name)
should validate_length_of(:name).is_at_most(255)
should validate_presence_of(:prefix)
should validate_length_of(:phone).is_at_most(50)
valid_phone_numbers = ['123-456-7890',
'(123) 456-7890',
'123 456 7890',
'123.456.7890',
'+91 (123) 456-7890']
valid_phone_numbers.each do |phone_number|
should allow_value(phone_number).for(:phone)
end
should validate_length_of(:email).is_at_most(255)
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
valid_addresses = %w[ user@example.com
USER@foo.COM
A_US-ER@foo.bar.org
first.last@foo.jp
alice+bob@baz.cn ]
valid_addresses.each do |valid_address|
should allow_value(valid_address).for(:email)
end
should validate_presence_of(:password)
should validate_length_of(:password).is_at_least(8)
end
end
end 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