From a7ada48f7fd5b14450a2c8afe17bfd8a3193353b Mon Sep 17 00:00:00 2001 From: CaioFML Date: Thu, 2 Apr 2020 00:50:07 -0300 Subject: [PATCH 01/50] =?UTF-8?q?Adiciona=20valida=C3=A7=C3=A3o,=20associa?= =?UTF-8?q?=C3=A7=C3=B5es=20e=20testes=20para=20o=20model=20Key=20Word?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/key_word.rb | 4 ++++ spec/models/key_word_spec.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 spec/models/key_word_spec.rb diff --git a/app/models/key_word.rb b/app/models/key_word.rb index f53e5f8..84bd797 100644 --- a/app/models/key_word.rb +++ b/app/models/key_word.rb @@ -1,4 +1,8 @@ # frozen_string_literal: true class KeyWord < ApplicationRecord + validates_presence_of :tag + + has_many :job_key_words, dependent: :destroy + has_many :jobs, through: :job_key_words end diff --git a/spec/models/key_word_spec.rb b/spec/models/key_word_spec.rb new file mode 100644 index 0000000..89824f4 --- /dev/null +++ b/spec/models/key_word_spec.rb @@ -0,0 +1,12 @@ +require "rails_helper" + +RSpec.describe KeyWord do + describe "associations" do + it { is_expected.to have_many(:job_key_words).dependent(:destroy) } + it { is_expected.to have_many(:jobs).through(:job_key_words) } + end + + describe "validations" do + it { is_expected.to validate_presence_of(:tag) } + end +end From 2a9ae706a3a8b9934c8009de67444e5bcd81b912 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Thu, 2 Apr 2020 10:58:17 -0300 Subject: [PATCH 02/50] update chatbot branch --- app/controllers/chatbot_controller.rb | 24 ++++++++++++++++++++++++ app/services/interpret_service.rb | 12 ++++++++++++ app/services/search_job_service.rb | 11 +++++++++++ config/routes.rb | 2 +- 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 app/controllers/chatbot_controller.rb create mode 100644 app/services/interpret_service.rb create mode 100644 app/services/search_job_service.rb diff --git a/app/controllers/chatbot_controller.rb b/app/controllers/chatbot_controller.rb new file mode 100644 index 0000000..4fb2f9c --- /dev/null +++ b/app/controllers/chatbot_controller.rb @@ -0,0 +1,24 @@ +class ChatBotController < ApplicationController + + def webhook + request.body.rewind + result = JSON.parse(request.body.read)["queryResult"] + + if result["contexts"].present? + response = InterpretService.call(result["action"], result["contexts"][0]["parameters"]) + else + response = InterpretService.call(result["action"], result["parameters"]) + end + + content_type :json, charset: 'utf-8' + { + "fulfillmentText": response, + "payload": { + "telegram": { + "text": response, + "parse_mode": "Markdown" + } + } + }.to_json + end +end diff --git a/app/services/interpret_service.rb b/app/services/interpret_service.rb new file mode 100644 index 0000000..035c09b --- /dev/null +++ b/app/services/interpret_service.rb @@ -0,0 +1,12 @@ +class InterpretService + + def self.call(action, params) + case action + when "search" + SearchJobService.new(params).call() + else + "Desculpe, mas não te entendi. Tente novamente" + end + end + +end \ No newline at end of file diff --git a/app/services/search_job_service.rb b/app/services/search_job_service.rb new file mode 100644 index 0000000..6b2673f --- /dev/null +++ b/app/services/search_job_service.rb @@ -0,0 +1,11 @@ +class SearchJobService + + def initialize(params) + @keyword = params["keyword"] + end + + def call + keyword = KeyWord.find_by(tag: @keyword) + jobs = JobKeyWord.where(key_word: keyword) + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index cefb14f..80c1b85 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true Rails.application.routes.draw do - # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html + post '/chatbot', to: 'chatbot#webhook' end From 4829e583a14dc2f3c5c1e7d12be2aa89251f1613 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Thu, 2 Apr 2020 11:53:29 -0300 Subject: [PATCH 03/50] improve README.md --- README.md | 82 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 69 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7db80e4..d7bc8fd 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,80 @@ -# README +# Search for opportunities job for technology professionals -This README would normally document whatever steps are necessary to get the -application up and running. +*Search for opportunities job* -Things you may want to cover: +> You can try here: *[DevOPs - Docker - Python Web Development with Flask]( [insert app url] )*. -* Ruby version +# Docker Container -* System dependencies +This project was done using docker container, the name is Nameprogramadorhomeofficeapi_app -* Configuration +## Getting Started -* Database creation +These instructions will cover usage information and for the docker container -* Database initialization +### Prerequisities -* How to run the test suite +In order to run this container you'll need docker installed. -* Services (job queues, cache servers, search engines, etc.) +* [Windows](https://docs.docker.com/windows/started) +* [OS X](https://docs.docker.com/mac/started/) +* [Linux](https://docs.docker.com/linux/started/) -* Deployment instructions +## Installation -* ... +clone: +``` +$ git clone git@github.com:OneBitCodeBlog/programador-homeoffice-api.git +$ cd programador-homeoffice-api +``` + +gems install: +``` +$ docker-compose run --rm app bundle install && update +``` +RSpec install: +``` +docker-compose run --rm app bundle exec rails generate rspec:install +``` +generate database: +``` +$ docker-compose run --rm app bundle exec rails db:create db:migrate + +``` +run the app: +``` +$ docker-compose up --build +``` +Access: +* [Windows](http://0.0.0.0:3000/) + +## PS. if an error like that happens + * Listening on tcp://0.0.0.0:3000 +app_1 | bundler: failed to load command: puma (/gems/ruby/2.7.0/bin/puma) +app_1 | Errno::ENOENT: No such file or directory @ rb_sysopen - tmp/pids/server.pid +app_1 | /gems/ruby/2.7.0/gems/puma-4.3.3/lib/puma/launcher.rb:216:in `initialize' +app_1 | /gems/ruby/2.7.0/gems/puma-4.3.3/lib/puma/launcher.rb:216:in `open' +app_1 | /gems/ruby/2.7.0/gems/puma-4.3.3/lib/puma/launcher.rb:216:in `write_pid' +app_1 | /gems/ruby/2.7.0/gems/puma-4.3.3/lib/puma/launcher.rb:105:in `write_state' +app_1 | /gems/ruby/2.7.0/gems/puma-4.3.3/lib/puma/single.rb:103:in `run' +app_1 | /gems/ruby/2.7.0/gems/puma-4.3.3/lib/puma/launcher.rb:172:in `run' +app_1 | /gems/ruby/2.7.0/gems/puma-4.3.3/lib/puma/cli.rb:80:in `run' +app_1 | /gems/ruby/2.7.0/gems/puma-4.3.3/bin/puma:10:in `' +app_1 | /gems/ruby/2.7.0/bin/puma:23:in `load' +app_1 | /gems/ruby/2.7.0/bin/puma:23:in `' +programadorhomeofficeapi_app_1 exited with code 1 + +###Solucion: +in a shell prompt you must create tmp/pips folder in your machine with: +``` +$ mkdir -p tmp/pids/ +``` +now run again: +``` +$ docker-compose up --build +``` +and now, must be working! + +## License + +This project is licensed under the MIT License \ No newline at end of file From 9f323ebbeeaabb1210f36c327ac02de2e726fee7 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Thu, 2 Apr 2020 11:56:01 -0300 Subject: [PATCH 04/50] improve README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d7bc8fd..1fde4c6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ *Search for opportunities job* -> You can try here: *[DevOPs - Docker - Python Web Development with Flask]( [insert app url] )*. +> You can try here: *[]( [insert app url] )*. # Docker Container From 2757cd95e7176ab57d53a8452b277461061579c0 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Thu, 2 Apr 2020 11:56:42 -0300 Subject: [PATCH 05/50] improve README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1fde4c6..e1478bc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ *Search for opportunities job* -> You can try here: *[]( [insert app url] )*. +> You can try here: *insert app url( [insert app url] )*. # Docker Container From 156de6d83ffd5e1236417bd521dee5d40d21bee9 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Thu, 2 Apr 2020 11:57:21 -0300 Subject: [PATCH 06/50] improve README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e1478bc..03e4cae 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ # Docker Container -This project was done using docker container, the name is Nameprogramadorhomeofficeapi_app +This project was done using docker container, the container name is Nameprogramadorhomeofficeapi_app ## Getting Started From 3b451f140336d18c6008808104dbb4b9486caddd Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Thu, 2 Apr 2020 11:58:43 -0300 Subject: [PATCH 07/50] improve README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 03e4cae..76cd58b 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ run the app: $ docker-compose up --build ``` Access: -* [Windows](http://0.0.0.0:3000/) +* [opportunities job here](http://0.0.0.0:3000/) ## PS. if an error like that happens * Listening on tcp://0.0.0.0:3000 From 3a1d93c9c8525e75dc56074577c708c27d44bbd0 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Thu, 2 Apr 2020 11:59:24 -0300 Subject: [PATCH 08/50] improve README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 76cd58b..279216c 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ $ docker-compose up --build Access: * [opportunities job here](http://0.0.0.0:3000/) -## PS. if an error like that happens +## PS. if an error like this happens * Listening on tcp://0.0.0.0:3000 app_1 | bundler: failed to load command: puma (/gems/ruby/2.7.0/bin/puma) app_1 | Errno::ENOENT: No such file or directory @ rb_sysopen - tmp/pids/server.pid @@ -64,7 +64,7 @@ app_1 | /gems/ruby/2.7.0/bin/puma:23:in `load' app_1 | /gems/ruby/2.7.0/bin/puma:23:in `' programadorhomeofficeapi_app_1 exited with code 1 -###Solucion: +### Solucion: in a shell prompt you must create tmp/pips folder in your machine with: ``` $ mkdir -p tmp/pids/ From 86a5348c80bf7f38e88df17492208d51322fac85 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Thu, 2 Apr 2020 12:00:13 -0300 Subject: [PATCH 09/50] improve README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 279216c..f16a901 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ app_1 | /gems/ruby/2.7.0/bin/puma:23:in `load' app_1 | /gems/ruby/2.7.0/bin/puma:23:in `' programadorhomeofficeapi_app_1 exited with code 1 -### Solucion: +### Solution: in a shell prompt you must create tmp/pips folder in your machine with: ``` $ mkdir -p tmp/pids/ From fda355518198137de0445eb8ec185333e423aa9c Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Thu, 2 Apr 2020 12:00:57 -0300 Subject: [PATCH 10/50] improve README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f16a901..c1fd7cc 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ app_1 | /gems/ruby/2.7.0/bin/puma:23:in `load' app_1 | /gems/ruby/2.7.0/bin/puma:23:in `' programadorhomeofficeapi_app_1 exited with code 1 -### Solution: +### you can try this solution: in a shell prompt you must create tmp/pips folder in your machine with: ``` $ mkdir -p tmp/pids/ From 25b18ac92048ce59f6bf226199e87fc04c790f1a Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Thu, 2 Apr 2020 12:17:12 -0300 Subject: [PATCH 11/50] improve README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index c1fd7cc..001bec8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,12 @@ # Search for opportunities job for technology professionals +This project is a search engine for job opportunities for technology professionals. + +# Stack +* stack + * docker + * API: Ruby On Rails + * web client: React ou VueJs + * Chatbot: DialogFlow *Search for opportunities job* From 81aab94af011c40ff736c9d5e9e966d4b148ca8f Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Thu, 2 Apr 2020 12:18:21 -0300 Subject: [PATCH 12/50] improve README.md --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 001bec8..9b30654 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,10 @@ This project is a search engine for job opportunities for technology professionals. # Stack -* stack - * docker - * API: Ruby On Rails - * web client: React ou VueJs - * Chatbot: DialogFlow +* docker +* API: Ruby On Rails +* web client: React ou VueJs +* Chatbot: DialogFlow *Search for opportunities job* From 52756ba09c10424b548b122bf007f110b7b3f20e Mon Sep 17 00:00:00 2001 From: Luan Solino Date: Fri, 3 Apr 2020 03:20:25 -0300 Subject: [PATCH 13/50] service of create user created --- app/controllers/chatbot_controller.rb | 28 +++----- app/services/create_user_service.rb | 14 ++++ app/services/interpret_service.rb | 13 +++- config/environments/development.rb | 1 + .../20200403023247_add_session_id_to_users.rb | 5 ++ db/schema.rb | 64 +++++++++++++++++++ 6 files changed, 104 insertions(+), 21 deletions(-) create mode 100644 app/services/create_user_service.rb create mode 100644 db/migrate/20200403023247_add_session_id_to_users.rb create mode 100644 db/schema.rb diff --git a/app/controllers/chatbot_controller.rb b/app/controllers/chatbot_controller.rb index 4fb2f9c..0530fef 100644 --- a/app/controllers/chatbot_controller.rb +++ b/app/controllers/chatbot_controller.rb @@ -1,24 +1,14 @@ -class ChatBotController < ApplicationController +class ChatbotController < ApplicationController def webhook + request.body.rewind - result = JSON.parse(request.body.read)["queryResult"] - - if result["contexts"].present? - response = InterpretService.call(result["action"], result["contexts"][0]["parameters"]) - else - response = InterpretService.call(result["action"], result["parameters"]) - end - - content_type :json, charset: 'utf-8' - { - "fulfillmentText": response, - "payload": { - "telegram": { - "text": response, - "parse_mode": "Markdown" - } - } - }.to_json + result = JSON.parse(request.body.read) + action = result["queryResult"]["action"] + + response = InterpretService.call(action: action, result: result) + + render :json => response + end end diff --git a/app/services/create_user_service.rb b/app/services/create_user_service.rb new file mode 100644 index 0000000..3acd1b7 --- /dev/null +++ b/app/services/create_user_service.rb @@ -0,0 +1,14 @@ +class CreateUserService + + def initialize(session:, name:) + @session = session + @name = name + end + + def call + User.create!( + name: @name, + session_id: @session + ) + end +end \ No newline at end of file diff --git a/app/services/interpret_service.rb b/app/services/interpret_service.rb index 035c09b..69cf8b9 100644 --- a/app/services/interpret_service.rb +++ b/app/services/interpret_service.rb @@ -1,9 +1,18 @@ class InterpretService - def self.call(action, params) + def self.call(action:, result:) case action when "search" - SearchJobService.new(params).call() + keyword = result["queryResult"]["parameters"]["keyword"] + SearchJobService.new(keyword: keyword).call() + when "alert" + session = result["session"].split('/')[-1] + language = result["queryResult"]["parameters"]["linguagem"] + CreateAlertService.new(session: session, language: language).call + when "input.welcome" + session = result["session"].split('/')[-1] + name = result["queryResult"]["parameters"]["name"] + CreateUserService.new(session: session, name: name).call() else "Desculpe, mas não te entendi. Tente novamente" end diff --git a/config/environments/development.rb b/config/environments/development.rb index f84afae..c2705a7 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true Rails.application.configure do + config.hosts << "8e6a6c23.ngrok.io" # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on diff --git a/db/migrate/20200403023247_add_session_id_to_users.rb b/db/migrate/20200403023247_add_session_id_to_users.rb new file mode 100644 index 0000000..def0b3b --- /dev/null +++ b/db/migrate/20200403023247_add_session_id_to_users.rb @@ -0,0 +1,5 @@ +class AddSessionIdToUsers < ActiveRecord::Migration[6.0] + def change + add_column :users, :session_id, :string + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..0ce1d1f --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,64 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `rails +# db:schema:load`. When creating a new database, `rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 2020_04_03_023247) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "job_key_words", force: :cascade do |t| + t.bigint "job_id" + t.bigint "key_word_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["job_id"], name: "index_job_key_words_on_job_id" + t.index ["key_word_id"], name: "index_job_key_words_on_key_word_id" + end + + create_table "jobs", force: :cascade do |t| + t.string "title" + t.text "description" + t.integer "contract" + t.string "job_link" + t.integer "salary" + t.string "company_name" + t.date "published_date" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + + create_table "key_words", force: :cascade do |t| + t.string "tag" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + + create_table "searches", force: :cascade do |t| + t.bigint "user_id", null: false + t.integer "alarm_rate" + t.bigint "key_word_id", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["key_word_id"], name: "index_searches_on_key_word_id" + t.index ["user_id"], name: "index_searches_on_user_id" + end + + create_table "users", force: :cascade do |t| + t.string "name" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.string "session_id" + end + + add_foreign_key "searches", "key_words" + add_foreign_key "searches", "users" +end From 8ac47574d24a6b1f258fce3ccbf1c60cec621521 Mon Sep 17 00:00:00 2001 From: Luan Solino Date: Fri, 3 Apr 2020 03:21:32 -0300 Subject: [PATCH 14/50] updated search service --- app/services/search_job_service.rb | 25 ++++++++++++++++++++++--- db/seeds.rb | 30 +++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/app/services/search_job_service.rb b/app/services/search_job_service.rb index 6b2673f..4625c27 100644 --- a/app/services/search_job_service.rb +++ b/app/services/search_job_service.rb @@ -1,11 +1,30 @@ class SearchJobService - def initialize(params) - @keyword = params["keyword"] + def initialize(keyword:) + @keyword = keyword end def call keyword = KeyWord.find_by(tag: @keyword) - jobs = JobKeyWord.where(key_word: keyword) + jobs = JobKeyWord.where(key_word: keyword) + hashes = [] + jobs.each do |job| + hashes << { + "card": { + "title": job.job.title, + "subtitle": "#{job.job.description} - Publicado em: #{job.job.published_date.strftime("%d/%m/%Y")}", + "buttons": [ + { + "text": "Ler mais", + "postback": job.job.job_link + } + ] + } + } + end + response = { + "fulfillmentText": "Vagas - Remoto", + "fulfillmentMessages": hashes + } end end \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index 8744e3c..cd17edf 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,4 +5,32 @@ # Examples: # # 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) + +Job.create!( + title: 'Desenvolvedor Full Stack Rails', + description: Faker::Lorem.paragraph, + job_link: Faker::Internet.url, + published_date: Faker::Date.between(from: 2.days.ago, to: Date.today) +) + +Job.create!( + title: 'Desenvolvedor Full Stack Ruby on Rails', + description: Faker::Lorem.paragraph, + job_link: Faker::Internet.url, + published_date: Faker::Date.between(from: 2.days.ago, to: Date.today) +) + +KeyWord.create!( + tag: 'Rails' +) + +JobKeyWord.create!( + job: Job.find(1), + key_word: KeyWord.find(1) +) + +JobKeyWord.create!( + job: Job.find(2), + key_word: KeyWord.find(1) +) \ No newline at end of file From fa17a1e7220258d9c5712d0a25e40a957d8d1bd9 Mon Sep 17 00:00:00 2001 From: Luan Solino Date: Fri, 3 Apr 2020 03:22:12 -0300 Subject: [PATCH 15/50] service of create alert created --- app/services/create_alert_service.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/services/create_alert_service.rb diff --git a/app/services/create_alert_service.rb b/app/services/create_alert_service.rb new file mode 100644 index 0000000..c8b3433 --- /dev/null +++ b/app/services/create_alert_service.rb @@ -0,0 +1,25 @@ +class CreateAlertService + + def initialize(session:, language:) + @session = session + @language = language + end + + def call + Search.create!( + user: User.find_by(session_id: @session), + alarm_rate: 1, + key_word: KeyWord.find_by(tag: @language) + ) + response = { + "fulfillmentText": "Vagas - Remoto", + "fulfillmentMessages": { + "text": { + "text": [ + "Seu alarme foi criado com sucesso. Assim que uma nova vaga para #{@language} surgir você receberá um alerta" + ] + } + } + } + end +end \ No newline at end of file From b9d98387a6728116e1551ed7cc4b31cf7f0c9b56 Mon Sep 17 00:00:00 2001 From: Luan Solino Date: Sat, 4 Apr 2020 00:28:17 -0300 Subject: [PATCH 16/50] creating key_word if not exists in alert_service --- app/services/create_alert_service.rb | 9 ++++++++- config/environments/development.rb | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/services/create_alert_service.rb b/app/services/create_alert_service.rb index c8b3433..37feba2 100644 --- a/app/services/create_alert_service.rb +++ b/app/services/create_alert_service.rb @@ -6,10 +6,17 @@ def initialize(session:, language:) end def call + key_word = KeyWord.find_by(tag: @language) + if key_word.nil? + KeyWord.create!( + tag: @language + ) + key_word = KeyWord.last + end Search.create!( user: User.find_by(session_id: @session), alarm_rate: 1, - key_word: KeyWord.find_by(tag: @language) + key_word: key_word ) response = { "fulfillmentText": "Vagas - Remoto", diff --git a/config/environments/development.rb b/config/environments/development.rb index c2705a7..136567e 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true Rails.application.configure do - config.hosts << "8e6a6c23.ngrok.io" + config.hosts << "019ea77c.ngrok.io" # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on From 167ace6894ee29a3dc2f16cc7b83439ce26d19ff Mon Sep 17 00:00:00 2001 From: Luan Solino Date: Sat, 4 Apr 2020 00:29:57 -0300 Subject: [PATCH 17/50] services of alert list and alert delete created --- app/services/delete_alert_service.rb | 43 ++++++++++++++++++++++++++++ app/services/interpret_service.rb | 7 +++++ app/services/list_alert_service.rb | 31 ++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 app/services/delete_alert_service.rb create mode 100644 app/services/list_alert_service.rb diff --git a/app/services/delete_alert_service.rb b/app/services/delete_alert_service.rb new file mode 100644 index 0000000..09bd60f --- /dev/null +++ b/app/services/delete_alert_service.rb @@ -0,0 +1,43 @@ +class DeleteAlertService + + def initialize(session:, tag:) + @session = session + if tag == 'todos' + @tag = nil + else + @tag = tag + end + end + + def call + hashes = [] + if @tag.nil? + alerts = Search.where(user: User.find_by(session_id: @session)) + alerts.each do |alert| + alert.destroy + hashes << { + "card": { + "title": "Todos seus alertas foram excluídos com sucesso" + } + } + end + else + key_word = KeyWord.find_by(tag: @tag) + alerts = Search.find_by( + user: User.find_by(session_id: @session), + key_word: key_word + ) + alerts.destroy + hashes << { + "card": { + "title": "Seu alerta da palavra chave #{@alert} foi excluído com sucesso" + } + } + end + + response = { + "fulfillmentText": "Vagas - Remoto", + "fulfillmentMessages": hashes + } + end +end \ No newline at end of file diff --git a/app/services/interpret_service.rb b/app/services/interpret_service.rb index 69cf8b9..a19077d 100644 --- a/app/services/interpret_service.rb +++ b/app/services/interpret_service.rb @@ -9,6 +9,13 @@ def self.call(action:, result:) session = result["session"].split('/')[-1] language = result["queryResult"]["parameters"]["linguagem"] CreateAlertService.new(session: session, language: language).call + when "list" + session = result["session"].split('/')[-1] + ListAlertService.new(session: session).call + when "delete" + session = result["session"].split('/')[-1] + tag = result["queryResult"]["parameters"]["IDAlarm"] + DeleteAlertService.new(session: session, tag: tag).call when "input.welcome" session = result["session"].split('/')[-1] name = result["queryResult"]["parameters"]["name"] diff --git a/app/services/list_alert_service.rb b/app/services/list_alert_service.rb new file mode 100644 index 0000000..276a8d8 --- /dev/null +++ b/app/services/list_alert_service.rb @@ -0,0 +1,31 @@ +class ListAlertService + + def initialize(session:) + @session = session + end + + def call + alerts = Search.where(user: User.find_by(session_id: @session)) + hashes = [] + if alerts.blank? + hashes << { + "card": { + "title": "Você não tem nenhum alerta cadastrado" + } + } + else + alerts.each do |alert| + hashes << { + "card": { + "title": "Seus alertas", + "subtitle": "Você tem um alerta para a palavra-chave: #{alert.key_word.tag}", + } + } + end + end + response = { + "fulfillmentText": "Vagas - Remoto", + "fulfillmentMessages": hashes + } + end +end \ No newline at end of file From bb4378dd3c4544f74520b0887503306868ea2a61 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sat, 4 Apr 2020 15:00:46 -0300 Subject: [PATCH 18/50] sync branch local remote --- db/schema.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index d47cd70..7084db7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -<<<<<<< HEAD ActiveRecord::Schema.define(version: 2020_03_31_024104) do -======= -ActiveRecord::Schema.define(version: 2020_04_03_023247) do ->>>>>>> 167ace6894ee29a3dc2f16cc7b83439ce26d19ff # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From baba0cec273134aefd57291fd5e42b5b7acd625d Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sat, 4 Apr 2020 15:17:37 -0300 Subject: [PATCH 19/50] sync branch local remote --- .rspec | 1 - README.md | 2 +- db/schema.rb | 5 +-- spec/rails_helper.rb | 67 +++++++++++++++++++++++++--------- spec/spec_helper.rb | 87 +++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 137 insertions(+), 25 deletions(-) diff --git a/.rspec b/.rspec index 5be63fc..c99d2e7 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1 @@ --require spec_helper ---format documentation diff --git a/README.md b/README.md index 9b30654..54b3185 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ $ cd programador-homeoffice-api gems install: ``` -$ docker-compose run --rm app bundle install && update +$ docker-compose run --rm app bundle install ``` RSpec install: ``` diff --git a/db/schema.rb b/db/schema.rb index 7084db7..0ce1d1f 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: 2020_03_31_024104) do +ActiveRecord::Schema.define(version: 2020_04_03_023247) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -56,10 +56,7 @@ t.string "name" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false -<<<<<<< HEAD -======= t.string "session_id" ->>>>>>> 167ace6894ee29a3dc2f16cc7b83439ce26d19ff end add_foreign_key "searches", "key_words" diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 73b032c..00345af 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,31 +1,64 @@ -# frozen_string_literal: true +# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'spec_helper' +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../config/environment', __dir__) +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! -require "spec_helper" -ENV["RAILS_ENV"] ||= "test" -require File.expand_path("../config/environment", __dir__) -if Rails.env.production? - abort("The Rails environment is running in production mode!") -end -require "rspec/rails" +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } +# Checks for pending migrations and applies them before tests are run. +# If you are not using ActiveRecord, you can remove these lines. begin ActiveRecord::Migration.maintain_test_schema! rescue ActiveRecord::PendingMigrationError => e puts e.to_s.strip exit 1 end - -Shoulda::Matchers.configure do |config| - config.integrate do |with| - with.test_framework :rspec - with.library :rails - end -end - RSpec.configure do |config| - config.include FactoryBot::Syntax::Methods + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. config.use_transactional_fixtures = true + + # You can uncomment this line to turn off ActiveRecord support entirely. + # config.use_active_record = false + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, type: :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a7d360f..ce33d66 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,13 +1,96 @@ -# frozen_string_literal: true - +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true end + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. mocks.verify_partial_doubles = true end + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end end From 3dfe4d415c0f1223ce330cc9f89b2638a2229363 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sat, 4 Apr 2020 15:38:37 -0300 Subject: [PATCH 20/50] set models/key_word --- app/models/key_word.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/key_word.rb b/app/models/key_word.rb index f53e5f8..3edac35 100644 --- a/app/models/key_word.rb +++ b/app/models/key_word.rb @@ -1,4 +1,10 @@ # frozen_string_literal: true class KeyWord < ApplicationRecord -end + enum contract: %i[not_specified clt pj clt_or_pj] + + has_many :job_key_words, dependent: :destroy + has_many :key_words, through: :job_key_words + + validates :tag, :created_at, :updated_at, presence: true + end \ No newline at end of file From cc82269c5f74effe8ed3aafbe4ed75ba468d0ca1 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sat, 4 Apr 2020 15:39:03 -0300 Subject: [PATCH 21/50] set models/key_word --- app/models/key_word.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/key_word.rb b/app/models/key_word.rb index 3edac35..d2136eb 100644 --- a/app/models/key_word.rb +++ b/app/models/key_word.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class KeyWord < ApplicationRecord - enum contract: %i[not_specified clt pj clt_or_pj] has_many :job_key_words, dependent: :destroy has_many :key_words, through: :job_key_words From 5d972cd403a391463b73660ba9fcc84951e26110 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sat, 4 Apr 2020 22:23:52 -0300 Subject: [PATCH 22/50] create spec/models/key_word_spec.rb --- spec/models/key_word_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 spec/models/key_word_spec.rb diff --git a/spec/models/key_word_spec.rb b/spec/models/key_word_spec.rb new file mode 100644 index 0000000..3d338e7 --- /dev/null +++ b/spec/models/key_word_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe Job do + + describe "validations" do + it { is_expected.to validate_presence_of(:tag) } + it { is_expected.to validate_presence_of(:created_at) } + it { is_expected.to validate_presence_of(:updated_at) } + end + + describe "associations" do + it { is_expected.to have_many(:job_key_words).dependent(:destroy) } + it { is_expected.to have_many(:jobs).through(:job_key_words) } + end + +end \ No newline at end of file From f0da14b086105788218daa1eb8a43b9c544b769e Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sun, 5 Apr 2020 01:04:06 -0300 Subject: [PATCH 23/50] merge with controller_jobs branch --- app/models/key_word.rb | 9 --------- spec/models/key_word_spec.rb | 18 ------------------ 2 files changed, 27 deletions(-) delete mode 100644 app/models/key_word.rb delete mode 100644 spec/models/key_word_spec.rb diff --git a/app/models/key_word.rb b/app/models/key_word.rb deleted file mode 100644 index d2136eb..0000000 --- a/app/models/key_word.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class KeyWord < ApplicationRecord - - has_many :job_key_words, dependent: :destroy - has_many :key_words, through: :job_key_words - - validates :tag, :created_at, :updated_at, presence: true - end \ No newline at end of file diff --git a/spec/models/key_word_spec.rb b/spec/models/key_word_spec.rb deleted file mode 100644 index 3d338e7..0000000 --- a/spec/models/key_word_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -RSpec.describe Job do - - describe "validations" do - it { is_expected.to validate_presence_of(:tag) } - it { is_expected.to validate_presence_of(:created_at) } - it { is_expected.to validate_presence_of(:updated_at) } - end - - describe "associations" do - it { is_expected.to have_many(:job_key_words).dependent(:destroy) } - it { is_expected.to have_many(:jobs).through(:job_key_words) } - end - -end \ No newline at end of file From c680ff75eeaa9f920dde1e828059ab6f43d0b144 Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 01:46:08 -0300 Subject: [PATCH 24/50] determina rotas para controller job --- config/routes.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index cefb14f..bbf74a3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true Rails.application.routes.draw do - # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html + namespace :api do + namespace :v1 do + resources :job, only: %i[index show] + end + end end From a834684e9b9bd699bc39af0d9f53d52d717ef827 Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 01:46:18 -0300 Subject: [PATCH 25/50] add active_model_serializer --- Gemfile | 1 + Gemfile.lock | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/Gemfile b/Gemfile index 44e25a6..8be2032 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ gem "puma", "~> 4.1" gem "rack-cors" gem "rails", "~> 6.0.2", ">= 6.0.2.2" gem "redis", "~> 4.0" +gem "active_model_serializers" group :development, :test do gem "byebug", platforms: %i[mri mingw x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index 4ac7e5a..dc7aca0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,6 +37,11 @@ GEM erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) + active_model_serializers (0.10.10) + actionpack (>= 4.1, < 6.1) + activemodel (>= 4.1, < 6.1) + case_transform (>= 0.2) + jsonapi-renderer (>= 0.1.1.beta1, < 0.3) activejob (6.0.2.2) activesupport (= 6.0.2.2) globalid (>= 0.3.6) @@ -61,6 +66,8 @@ GEM msgpack (~> 1.0) builder (3.2.4) byebug (11.1.1) + case_transform (0.2) + activesupport coderay (1.1.2) concurrent-ruby (1.1.6) crass (1.0.6) @@ -79,6 +86,7 @@ GEM i18n (1.8.2) concurrent-ruby (~> 1.0) jaro_winkler (1.5.4) + jsonapi-renderer (0.2.2) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -200,6 +208,7 @@ PLATFORMS ruby DEPENDENCIES + active_model_serializers bootsnap (>= 1.4.2) byebug factory_bot_rails From 287ee57a872773141d407071b26a4db650c1fcc3 Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 02:17:04 -0300 Subject: [PATCH 26/50] =?UTF-8?q?Adiciona=20inflex=C3=A3o=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/initializers/inflections.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index aa7435f..4af48f7 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -15,3 +15,7 @@ # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.acronym 'RESTful' # end + +ActiveSupport::Inflector.inflections do |inflect| + inflect.acronym "API" +end From d1eb383e977493df75551a05e6c1e1e5ec04cd4d Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 02:18:56 -0300 Subject: [PATCH 27/50] Defini rotas para Jobs --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index bbf74a3..aad3008 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,7 @@ Rails.application.routes.draw do namespace :api do namespace :v1 do - resources :job, only: %i[index show] + resources :jobs, only: %i[index show] end end end From 0fb358655648b9b1bd79fe02f7873f5d29328826 Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 02:19:45 -0300 Subject: [PATCH 28/50] Serializa Job --- app/serializers/job_serializer.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 app/serializers/job_serializer.rb diff --git a/app/serializers/job_serializer.rb b/app/serializers/job_serializer.rb new file mode 100644 index 0000000..365e2ae --- /dev/null +++ b/app/serializers/job_serializer.rb @@ -0,0 +1,7 @@ +class JobSerializer < ActiveModel::Serializer + attributes :id, :title, :description, :contract, + :job_link, :salary, :company_name, :published_date + + has_many :job_key_words + has_many :key_words +end From 254979a5b1c4978630b35e326e8257c78bc324f5 Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 02:19:56 -0300 Subject: [PATCH 29/50] Cria Factory para Job --- spec/factories/jobs.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 spec/factories/jobs.rb diff --git a/spec/factories/jobs.rb b/spec/factories/jobs.rb new file mode 100644 index 0000000..7b1802e --- /dev/null +++ b/spec/factories/jobs.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :job do + title { Faker::Lorem.sentence } + description { Faker::Lorem.paragraph } + job_link { Faker::Internet.url } + published_date { Date.today } + end +end From 4427b38c925c398d9cfcd40ec8ad70af29ff7872 Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 02:38:32 -0300 Subject: [PATCH 30/50] Adiciona default para contract --- db/migrate/20200405053502_change_default_for_job_contract.rb | 5 +++++ db/schema.rb | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20200405053502_change_default_for_job_contract.rb diff --git a/db/migrate/20200405053502_change_default_for_job_contract.rb b/db/migrate/20200405053502_change_default_for_job_contract.rb new file mode 100644 index 0000000..3ee22a3 --- /dev/null +++ b/db/migrate/20200405053502_change_default_for_job_contract.rb @@ -0,0 +1,5 @@ +class ChangeDefaultForJobContract < ActiveRecord::Migration[6.0] + def change + change_column :jobs, :contract, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index bb58b23..a55a64b 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: 2020_03_31_024104) do +ActiveRecord::Schema.define(version: 2020_04_05_053502) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -27,7 +27,7 @@ create_table "jobs", force: :cascade do |t| t.string "title" t.text "description" - t.integer "contract" + t.integer "contract", default: 0 t.string "job_link" t.integer "salary" t.string "company_name" From 359967cd567930f67f4c49729b9276f40a6472cb Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 02:56:15 -0300 Subject: [PATCH 31/50] corrige job_serializer --- app/serializers/job_serializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/serializers/job_serializer.rb b/app/serializers/job_serializer.rb index 365e2ae..09c01c7 100644 --- a/app/serializers/job_serializer.rb +++ b/app/serializers/job_serializer.rb @@ -3,5 +3,5 @@ class JobSerializer < ActiveModel::Serializer :job_link, :salary, :company_name, :published_date has_many :job_key_words - has_many :key_words + has_many :key_words, through: :job_key_words end From f81c7b5c03d80f3b3887b4e713e2508db3f29654 Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 03:07:44 -0300 Subject: [PATCH 32/50] Adiciona para rodar testes aleatoriamente --- spec/spec_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a7d360f..2ec1a03 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,5 +9,7 @@ mocks.verify_partial_doubles = true end + config.order = :random + config.shared_context_metadata_behavior = :apply_to_host_groups end From 9ef2f3e2befcef9a4850d31466357d0fe457be56 Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 03:31:30 -0300 Subject: [PATCH 33/50] corrige job serializer --- app/serializers/job_serializer.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/serializers/job_serializer.rb b/app/serializers/job_serializer.rb index 09c01c7..3ef1ca9 100644 --- a/app/serializers/job_serializer.rb +++ b/app/serializers/job_serializer.rb @@ -2,6 +2,5 @@ class JobSerializer < ActiveModel::Serializer attributes :id, :title, :description, :contract, :job_link, :salary, :company_name, :published_date - has_many :job_key_words - has_many :key_words, through: :job_key_words + has_many :key_words end From 44cce51e73e71892f146943495a903542dac4f82 Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 03:32:14 -0300 Subject: [PATCH 34/50] testa action index em request spec --- app/controllers/api/v1/jobs_controller.rb | 11 ++++++++ spec/requests/api/v1/jobs_request_spec.rb | 32 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 app/controllers/api/v1/jobs_controller.rb create mode 100644 spec/requests/api/v1/jobs_request_spec.rb diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb new file mode 100644 index 0000000..58cc6f8 --- /dev/null +++ b/app/controllers/api/v1/jobs_controller.rb @@ -0,0 +1,11 @@ +module API + module V1 + class JobsController < ApplicationController + def index + @jobs = Job.all + + render json: @jobs + end + end + end +end diff --git a/spec/requests/api/v1/jobs_request_spec.rb b/spec/requests/api/v1/jobs_request_spec.rb new file mode 100644 index 0000000..f7dee13 --- /dev/null +++ b/spec/requests/api/v1/jobs_request_spec.rb @@ -0,0 +1,32 @@ +require "rails_helper" + +RSpec.describe "Jobs", type: :request do + describe "GET #index" do + subject(:index) { get api_v1_jobs_url } + + let!(:job) do + create(:job).tap do |job| + create(:job_key_word, job: job) + end + end + + let(:parsed_response) { JSON.parse(response.body) } + let(:response_body) do + JSON.parse(JobSerializer.new(job).to_json) + end + + it "responds with 200" do + index + + expect(response).to have_http_status :ok + end + + it "responds with json" do + index + + expect(parsed_response).to match_array [response_body] + end + end + + describe "GET #show" +end From a87ed632511a5585028aa4be60232a1286c0ca23 Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 03:32:25 -0300 Subject: [PATCH 35/50] cria factory para job_key_words e key_words --- spec/factories/job_key_words.rb | 6 ++++++ spec/factories/key_words.rb | 5 +++++ 2 files changed, 11 insertions(+) create mode 100644 spec/factories/job_key_words.rb create mode 100644 spec/factories/key_words.rb diff --git a/spec/factories/job_key_words.rb b/spec/factories/job_key_words.rb new file mode 100644 index 0000000..d398a8c --- /dev/null +++ b/spec/factories/job_key_words.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :job_key_word do + association :job, strategy: :build + association :key_word, strategy: :build + end +end diff --git a/spec/factories/key_words.rb b/spec/factories/key_words.rb new file mode 100644 index 0000000..a4e270d --- /dev/null +++ b/spec/factories/key_words.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :key_word do + tag { Faker::Lorem.word } + end +end From 393886ec0778076ec8e455630907934b431a858a Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 05:22:33 -0300 Subject: [PATCH 36/50] Adiciona adapter para :json_api --- config/initializers/ams.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 config/initializers/ams.rb diff --git a/config/initializers/ams.rb b/config/initializers/ams.rb new file mode 100644 index 0000000..2d476eb --- /dev/null +++ b/config/initializers/ams.rb @@ -0,0 +1 @@ +ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::JsonApi \ No newline at end of file From 87cc6a311ddaf3688d4ffdbdcbd426381d24be68 Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 05:22:42 -0300 Subject: [PATCH 37/50] Adiciona kaminari --- Gemfile | 1 + Gemfile.lock | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/Gemfile b/Gemfile index 8be2032..24245d4 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,7 @@ gem "rack-cors" gem "rails", "~> 6.0.2", ">= 6.0.2.2" gem "redis", "~> 4.0" gem "active_model_serializers" +gem "kaminari" group :development, :test do gem "byebug", platforms: %i[mri mingw x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index dc7aca0..f27ee41 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,6 +87,18 @@ GEM concurrent-ruby (~> 1.0) jaro_winkler (1.5.4) jsonapi-renderer (0.2.2) + kaminari (1.2.0) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.2.0) + kaminari-activerecord (= 1.2.0) + kaminari-core (= 1.2.0) + kaminari-actionview (1.2.0) + actionview + kaminari-core (= 1.2.0) + kaminari-activerecord (1.2.0) + activerecord + kaminari-core (= 1.2.0) + kaminari-core (1.2.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -213,6 +225,7 @@ DEPENDENCIES byebug factory_bot_rails faker + kaminari listen (>= 3.0.5, < 3.2) pg (>= 0.18, < 2.0) pry From d1b4486056389ac09dcd536ef60eaf6467bfb36d Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 06:05:04 -0300 Subject: [PATCH 38/50] Chama classe correta do ams --- config/initializers/ams.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/ams.rb b/config/initializers/ams.rb index 2d476eb..8957206 100644 --- a/config/initializers/ams.rb +++ b/config/initializers/ams.rb @@ -1 +1 @@ -ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::JsonApi \ No newline at end of file +ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::JsonApi \ No newline at end of file From 90efe1d94028abc29d2e350c64cbba8cd3bc2ef5 Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 06:05:21 -0300 Subject: [PATCH 39/50] testes index completos --- app/controllers/api/v1/jobs_controller.rb | 6 ++- spec/requests/api/v1/jobs_request_spec.rb | 50 ++++++++++++++++++----- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb index 58cc6f8..0fa36ba 100644 --- a/app/controllers/api/v1/jobs_controller.rb +++ b/app/controllers/api/v1/jobs_controller.rb @@ -2,7 +2,11 @@ module API module V1 class JobsController < ApplicationController def index - @jobs = Job.all + page = params[:page] + page_number = page.try(:[], :number) + per_page = page.try(:[], :size) + + @jobs = Job.all.page(page_number).per(per_page) render json: @jobs end diff --git a/spec/requests/api/v1/jobs_request_spec.rb b/spec/requests/api/v1/jobs_request_spec.rb index f7dee13..302416b 100644 --- a/spec/requests/api/v1/jobs_request_spec.rb +++ b/spec/requests/api/v1/jobs_request_spec.rb @@ -4,27 +4,55 @@ describe "GET #index" do subject(:index) { get api_v1_jobs_url } - let!(:job) do + before do + job + index + end + + shared_examples "request index" do + it "responds with 200" do + expect(response).to have_http_status :ok + end + + it "responds with json" do + expect(parsed_response["data"].first["attributes"].keys) + .to match_array json_attributes + end + + it "shows links for pagination" do + expect(parsed_response["links"].keys).to match_array json_links + end + end + + let(:job) do create(:job).tap do |job| create(:job_key_word, job: job) end end let(:parsed_response) { JSON.parse(response.body) } - let(:response_body) do - JSON.parse(JobSerializer.new(job).to_json) + let(:job_attributes) { job.attributes } + let(:json_links) { %w[self first prev next last] } + let(:json_attributes) do + %w[ + title + description + contract + job-link + salary + company-name + published-date + ] end - it "responds with 200" do - index - - expect(response).to have_http_status :ok - end + include_examples "request index" - it "responds with json" do - index + context "with pagination params" do + subject(:index) do + get api_v1_jobs_url, params: { page: { number: 1, size: 1 } } + end - expect(parsed_response).to match_array [response_body] + include_examples "request index" end end From 18b6c91eb62d7307ac87ffdb1da513332ae0c001 Mon Sep 17 00:00:00 2001 From: CaioFML Date: Sun, 5 Apr 2020 06:31:36 -0300 Subject: [PATCH 40/50] cria #show e testes de request para show --- app/controllers/api/v1/jobs_controller.rb | 8 +++ spec/requests/api/v1/jobs_request_spec.rb | 73 ++++++++++++++++------- 2 files changed, 60 insertions(+), 21 deletions(-) diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb index 0fa36ba..74b5209 100644 --- a/app/controllers/api/v1/jobs_controller.rb +++ b/app/controllers/api/v1/jobs_controller.rb @@ -10,6 +10,14 @@ def index render json: @jobs end + + def show + @job = Job.find(params[:id]) + + render json: @job + rescue ActiveRecord::RecordNotFound + head :not_found + end end end end diff --git a/spec/requests/api/v1/jobs_request_spec.rb b/spec/requests/api/v1/jobs_request_spec.rb index 302416b..7106995 100644 --- a/spec/requests/api/v1/jobs_request_spec.rb +++ b/spec/requests/api/v1/jobs_request_spec.rb @@ -1,6 +1,25 @@ require "rails_helper" RSpec.describe "Jobs", type: :request do + let(:job) do + create(:job).tap do |job| + create(:job_key_word, job: job) + end + end + + let(:parsed_response) { JSON.parse(response.body) } + let(:json_attributes) do + %w[ + title + description + contract + job-link + salary + company-name + published-date + ] + end + describe "GET #index" do subject(:index) { get api_v1_jobs_url } @@ -13,39 +32,24 @@ it "responds with 200" do expect(response).to have_http_status :ok end - + it "responds with json" do expect(parsed_response["data"].first["attributes"].keys) .to match_array json_attributes end - - it "shows links for pagination" do - expect(parsed_response["links"].keys).to match_array json_links - end end - let(:job) do - create(:job).tap do |job| - create(:job_key_word, job: job) + shared_examples "pagination" do + it "shows links for pagination" do + expect(parsed_response["links"].keys).to match_array json_links end end - let(:parsed_response) { JSON.parse(response.body) } let(:job_attributes) { job.attributes } let(:json_links) { %w[self first prev next last] } - let(:json_attributes) do - %w[ - title - description - contract - job-link - salary - company-name - published-date - ] - end include_examples "request index" + include_examples "pagination" context "with pagination params" do subject(:index) do @@ -53,8 +57,35 @@ end include_examples "request index" + include_examples "pagination" end end - describe "GET #show" + describe "GET #show" do + subject(:show) { get api_v1_job_url(job_id) } + + before do + job + show + end + + let(:job_id) { job.id } + + it "responds with 200" do + expect(response).to have_http_status :ok + end + + it "responds with json" do + expect(parsed_response["data"]["attributes"].keys) + .to match_array json_attributes + end + + context "without parameter id" do + let(:job_id) { 1234 } + + it "returns 404" do + expect(response).to have_http_status :not_found + end + end + end end From 87e9604a7fd85c827d867eae642f33804f8847a5 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sun, 5 Apr 2020 09:45:29 -0300 Subject: [PATCH 41/50] merging chatbot with controller_jobs --- spec/models/key_word_spec.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spec/models/key_word_spec.rb b/spec/models/key_word_spec.rb index f1f8909..cebe751 100644 --- a/spec/models/key_word_spec.rb +++ b/spec/models/key_word_spec.rb @@ -4,11 +4,9 @@ describe "associations" do it { is_expected.to have_many(:job_key_words).dependent(:destroy) } it { is_expected.to have_many(:jobs).through(:job_key_words) } - it { is_expected.to have_many(:searches).dependent(:destroy) } - it { is_expected.to have_many(:users).through(:searches) } end describe "validations" do it { is_expected.to validate_presence_of(:tag) } end -end +end \ No newline at end of file From fd0d45272791965aca8fc4c673b10e689c673608 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sun, 5 Apr 2020 09:49:42 -0300 Subject: [PATCH 42/50] merging chatbot with controller_jobs --- config/routes.rb | 4 ---- docker-compose.yml | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 19ce2bf..aad3008 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,13 +1,9 @@ # frozen_string_literal: true Rails.application.routes.draw do -<<<<<<< HEAD - post '/chatbot', to: 'chatbot#webhook' -======= namespace :api do namespace :v1 do resources :jobs, only: %i[index show] end end ->>>>>>> c8d0479a3f74306a0735073fb3315c89a9bc32fc end diff --git a/docker-compose.yml b/docker-compose.yml index caf85f3..38d0d1d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,3 +32,4 @@ volumes: redis: postgres: gems: + routes.rb:12 \ No newline at end of file From 5da2d1428378f8ead936bca5d6a274cfd8aa3c15 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sun, 5 Apr 2020 09:51:25 -0300 Subject: [PATCH 43/50] merging chatbot with controller_jobs --- docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 38d0d1d..29635ad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,5 +31,4 @@ services: volumes: redis: postgres: - gems: - routes.rb:12 \ No newline at end of file + gems: \ No newline at end of file From 682650dfa69149ce83224635d418b64e93565cca Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sun, 5 Apr 2020 09:55:08 -0300 Subject: [PATCH 44/50] fix some merge conflicts --- spec/spec_helper.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 52d42bf..ce33d66 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -37,16 +37,11 @@ mocks.verify_partial_doubles = true end -<<<<<<< HEAD # This option will default to `:apply_to_host_groups` in RSpec 4 (and will # have no way to turn it off -- the option exists only for backwards # compatibility in RSpec 3). It causes shared context metadata to be # inherited by the metadata hash of host groups and examples, rather than # triggering implicit auto-inclusion in groups with matching metadata. -======= - config.order = :random - ->>>>>>> c8d0479a3f74306a0735073fb3315c89a9bc32fc config.shared_context_metadata_behavior = :apply_to_host_groups # The settings below are suggested to provide a good initial experience From 0b1df5f9ebb5083f4d2cb2e32f9513269d4c71cc Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sun, 5 Apr 2020 09:56:21 -0300 Subject: [PATCH 45/50] fix some merge conflicts --- spec/spec_helper.rb | 89 ++------------------------------------------- 1 file changed, 4 insertions(+), 85 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ce33d66..0dd2047 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,96 +1,15 @@ -# This file was generated by the `rails generate rspec:install` command. Conventionally, all -# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. -# The generated `.rspec` file contains `--require spec_helper` which will cause -# this file to always be loaded, without a need to explicitly require it in any -# files. -# -# Given that it is always loaded, you are encouraged to keep this file as -# light-weight as possible. Requiring heavyweight dependencies from this file -# will add to the boot time of your test suite on EVERY test run, even for an -# individual file that may not need all of that loaded. Instead, consider making -# a separate helper file that requires the additional dependencies and performs -# the additional setup, and require it from the spec files that actually need -# it. -# -# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +# frozen_string_literal: true + RSpec.configure do |config| - # rspec-expectations config goes here. You can use an alternate - # assertion/expectation library such as wrong or the stdlib/minitest - # assertions if you prefer. config.expect_with :rspec do |expectations| - # This option will default to `true` in RSpec 4. It makes the `description` - # and `failure_message` of custom matchers include text for helper methods - # defined using `chain`, e.g.: - # be_bigger_than(2).and_smaller_than(4).description - # # => "be bigger than 2 and smaller than 4" - # ...rather than: - # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true end - # rspec-mocks config goes here. You can use an alternate test double - # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| - # Prevents you from mocking or stubbing a method that does not exist on - # a real object. This is generally recommended, and will default to - # `true` in RSpec 4. mocks.verify_partial_doubles = true end - # This option will default to `:apply_to_host_groups` in RSpec 4 (and will - # have no way to turn it off -- the option exists only for backwards - # compatibility in RSpec 3). It causes shared context metadata to be - # inherited by the metadata hash of host groups and examples, rather than - # triggering implicit auto-inclusion in groups with matching metadata. - config.shared_context_metadata_behavior = :apply_to_host_groups - -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode - config.disable_monkey_patching! - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = "doc" - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 config.order = :random - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end -end + config.shared_context_metadata_behavior = :apply_to_host_groups +end \ No newline at end of file From 1a314b4d62695d68212fb4ce784527f8b3484057 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sun, 5 Apr 2020 09:56:21 -0300 Subject: [PATCH 46/50] fix some merge conflicts in spec/spec_helper.rb --- spec/spec_helper.rb | 89 ++------------------------------------------- 1 file changed, 4 insertions(+), 85 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ce33d66..0dd2047 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,96 +1,15 @@ -# This file was generated by the `rails generate rspec:install` command. Conventionally, all -# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. -# The generated `.rspec` file contains `--require spec_helper` which will cause -# this file to always be loaded, without a need to explicitly require it in any -# files. -# -# Given that it is always loaded, you are encouraged to keep this file as -# light-weight as possible. Requiring heavyweight dependencies from this file -# will add to the boot time of your test suite on EVERY test run, even for an -# individual file that may not need all of that loaded. Instead, consider making -# a separate helper file that requires the additional dependencies and performs -# the additional setup, and require it from the spec files that actually need -# it. -# -# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +# frozen_string_literal: true + RSpec.configure do |config| - # rspec-expectations config goes here. You can use an alternate - # assertion/expectation library such as wrong or the stdlib/minitest - # assertions if you prefer. config.expect_with :rspec do |expectations| - # This option will default to `true` in RSpec 4. It makes the `description` - # and `failure_message` of custom matchers include text for helper methods - # defined using `chain`, e.g.: - # be_bigger_than(2).and_smaller_than(4).description - # # => "be bigger than 2 and smaller than 4" - # ...rather than: - # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true end - # rspec-mocks config goes here. You can use an alternate test double - # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| - # Prevents you from mocking or stubbing a method that does not exist on - # a real object. This is generally recommended, and will default to - # `true` in RSpec 4. mocks.verify_partial_doubles = true end - # This option will default to `:apply_to_host_groups` in RSpec 4 (and will - # have no way to turn it off -- the option exists only for backwards - # compatibility in RSpec 3). It causes shared context metadata to be - # inherited by the metadata hash of host groups and examples, rather than - # triggering implicit auto-inclusion in groups with matching metadata. - config.shared_context_metadata_behavior = :apply_to_host_groups - -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode - config.disable_monkey_patching! - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = "doc" - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 config.order = :random - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end -end + config.shared_context_metadata_behavior = :apply_to_host_groups +end \ No newline at end of file From 06f6c760efec06d1656b16029bf78b010bd3bb87 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sun, 5 Apr 2020 10:01:55 -0300 Subject: [PATCH 47/50] fix some merge conflicts --- db/schema.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 11eedf8..f011329 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -<<<<<<< HEAD -ActiveRecord::Schema.define(version: 2020_04_03_023247) do -======= ActiveRecord::Schema.define(version: 2020_04_05_053502) do ->>>>>>> c8d0479a3f74306a0735073fb3315c89a9bc32fc # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From b6f78f5ca348d45778b3b3af79d650808ba3dedb Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sun, 5 Apr 2020 10:05:28 -0300 Subject: [PATCH 48/50] sync Gemfile with the controller_jobs branch --- Gemfile | 2 +- Gemfile.lock | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 24245d4..37e1ddd 100644 --- a/Gemfile +++ b/Gemfile @@ -30,4 +30,4 @@ group :development do gem "spring-watcher-listen", "~> 2.0.0" end -gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby] +gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby] \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index f27ee41..eebb287 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,6 +87,7 @@ GEM concurrent-ruby (~> 1.0) jaro_winkler (1.5.4) jsonapi-renderer (0.2.2) +<<<<<<< HEAD kaminari (1.2.0) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.0) @@ -99,6 +100,8 @@ GEM activerecord kaminari-core (= 1.2.0) kaminari-core (1.2.0) +======= +>>>>>>> a834684... add active_model_serializer listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) From c837c8946ac7fab4e16de32c4f0deb6d9f8d631b Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sun, 5 Apr 2020 10:07:41 -0300 Subject: [PATCH 49/50] sync Gemfile with the controller_jobs branch --- Gemfile.lock | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index eebb287..2a6f4da 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,7 +87,6 @@ GEM concurrent-ruby (~> 1.0) jaro_winkler (1.5.4) jsonapi-renderer (0.2.2) -<<<<<<< HEAD kaminari (1.2.0) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.0) @@ -100,8 +99,6 @@ GEM activerecord kaminari-core (= 1.2.0) kaminari-core (1.2.0) -======= ->>>>>>> a834684... add active_model_serializer listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -123,7 +120,7 @@ GEM nokogiri (1.10.9) mini_portile2 (~> 2.4.0) parallel (1.19.1) - parser (2.7.0.5) + parser (2.7.1.0) ast (~> 2.4.0) pg (1.2.3) pry (0.13.0) @@ -186,14 +183,14 @@ GEM rspec-mocks (~> 3.9) rspec-support (~> 3.9) rspec-support (3.9.2) - rubocop (0.80.1) + rubocop (0.81.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.7.0.1) rainbow (>= 2.2.2, < 4.0) rexml ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 1.7) + unicode-display_width (>= 1.4.0, < 2.0) ruby-progressbar (1.10.1) ruby_dep (1.5.0) shoulda-matchers (4.3.0) @@ -211,9 +208,9 @@ GEM sprockets (>= 3.0.0) thor (1.0.1) thread_safe (0.3.6) - tzinfo (1.2.6) + tzinfo (1.2.7) thread_safe (~> 0.1) - unicode-display_width (1.6.1) + unicode-display_width (1.7.0) websocket-driver (0.7.1) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.4) @@ -247,4 +244,4 @@ RUBY VERSION ruby 2.7.0p0 BUNDLED WITH - 2.1.4 + 2.1.2 From ff6cfd5462dd42cce01d13dde7f4236152c4a2a1 Mon Sep 17 00:00:00 2001 From: "toti.cavalcanti" Date: Sun, 5 Apr 2020 10:17:42 -0300 Subject: [PATCH 50/50] sync merging rails_helper.rb --- spec/rails_helper.rb | 69 ++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 51 deletions(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 00345af..cf009b0 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,64 +1,31 @@ -# This file is copied to spec/ when you run 'rails generate rspec:install' -require 'spec_helper' -ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../config/environment', __dir__) -# Prevent database truncation if the environment is production -abort("The Rails environment is running in production mode!") if Rails.env.production? -require 'rspec/rails' -# Add additional requires below this line. Rails is not loaded until this point! +# frozen_string_literal: true -# Requires supporting ruby files with custom matchers and macros, etc, in -# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are -# run as spec files by default. This means that files in spec/support that end -# in _spec.rb will both be required and run as specs, causing the specs to be -# run twice. It is recommended that you do not name files matching this glob to -# end with _spec.rb. You can configure this pattern with the --pattern -# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. -# -# The following line is provided for convenience purposes. It has the downside -# of increasing the boot-up time by auto-requiring all files in the support -# directory. Alternatively, in the individual `*_spec.rb` files, manually -# require only the support files necessary. -# -# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } +require "spec_helper" +ENV["RAILS_ENV"] ||= "test" +require File.expand_path("../config/environment", __dir__) +if Rails.env.production? + abort("The Rails environment is running in production mode!") +end +require "rspec/rails" -# Checks for pending migrations and applies them before tests are run. -# If you are not using ActiveRecord, you can remove these lines. begin ActiveRecord::Migration.maintain_test_schema! rescue ActiveRecord::PendingMigrationError => e puts e.to_s.strip exit 1 end + +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end + RSpec.configure do |config| - # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.include FactoryBot::Syntax::Methods config.fixture_path = "#{::Rails.root}/spec/fixtures" - - # If you're not using ActiveRecord, or you'd prefer not to run each of your - # examples within a transaction, remove the following line or assign false - # instead of true. config.use_transactional_fixtures = true - - # You can uncomment this line to turn off ActiveRecord support entirely. - # config.use_active_record = false - - # RSpec Rails can automatically mix in different behaviours to your tests - # based on their file location, for example enabling you to call `get` and - # `post` in specs under `spec/controllers`. - # - # You can disable this behaviour by removing the line below, and instead - # explicitly tag your specs with their type, e.g.: - # - # RSpec.describe UsersController, type: :controller do - # # ... - # end - # - # The different available types are documented in the features, such as in - # https://relishapp.com/rspec/rspec-rails/docs config.infer_spec_type_from_file_location! - - # Filter lines from Rails gems in backtraces. config.filter_rails_from_backtrace! - # arbitrary gems may also be filtered via: - # config.filter_gems_from_backtrace("gem name") -end +end \ No newline at end of file