Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve resume skills description #744

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: %i[mri mingw x64_mingw]
# Use sqlite3 as the database for Active Record
gem 'debug'
Copy link
Contributor

Choose a reason for hiding this comment

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

Вроде в задачу не входило добавление гемов)

gem 'factory_bot_rails'
gem 'rubocop-performance'
gem 'rubocop-rails'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ GEM
activesupport (>= 4.2)
crass (1.0.6)
date (3.3.4)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
devise (4.9.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -574,6 +577,7 @@ DEPENDENCIES
capybara
cocoon
counter_culture
debug
devise
devise-bootstrap-views
devise-i18n
Expand Down
63 changes: 36 additions & 27 deletions app/models/resume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@
#
# Table name: resumes
#
# id :integer not null, primary key
# about_myself :text
# answers_count :integer default(0), not null
# awards_description :text
# city :string
# contact :string
# contact_email :string
# contact_phone :string
# contact_telegram :string
# english_fluency :string
# evaluated_ai :boolean
# evaluated_ai_state :string
# github_url :string
# hexlet_url :string
# impressions_count :integer default(0)
# locale :string
# name :string not null
# projects_description :text
# relocation :string
# skills_description :text
# state :string
# summary :text
# url :string
# created_at :datetime not null
# updated_at :datetime not null
# user_id :integer not null
# id :integer not null, primary key
# about_myself :text
# answers_count :integer default(0), not null
# awards_description :text
# city :string
# contact :string
# contact_email :string
# contact_phone :string
# contact_telegram :string
# english_fluency :string
# evaluated_ai :boolean
# evaluated_ai_state :string
# github_url :string
# hexlet_url :string
# impressions_count :integer default(0)
# locale :string
# name :string not null
# projects_description :text
# relocation :string
# skills_description :text(250)
# skills_description_old :text
# state :string
# summary :text
# url :string
# created_at :datetime not null
# updated_at :datetime not null
# user_id :integer not null
#
# Indexes
#
Expand All @@ -43,6 +44,7 @@ class Resume < ApplicationRecord
include StateConcern
extend Enumerize
extend TagResumePresenter
include ResumePresenter

mark_as_outdated :hexlet_url, :awards_description

Expand All @@ -58,10 +60,11 @@ class Resume < ApplicationRecord
validates :name, presence: true
validates :github_url, presence: true, unless: :draft?
validates :summary, length: { minimum: 200 }, presence: true, unless: :draft?
validates :skills_description, presence: true, unless: :draft?
validates :skills_description, length: { maximum: 250 }, presence: true, unless: :draft?
eKulshan marked this conversation as resolved.
Show resolved Hide resolved
validates :contact_email, presence: true, unless: :draft?
validates :contact_email, 'valid_email_2/email': true
validates :contact_phone, phone: true
validate :skills_description_valid_format, unless: :draft?

belongs_to :user
has_many :answers, inverse_of: :resume, dependent: :destroy
Expand Down Expand Up @@ -128,6 +131,12 @@ def initialize(attribute = nil)
super(attrs_with_defaults)
end

def skills_description_valid_format
return unless skills.size > 10 || skills.any? { |element| element.size > 25 }
Copy link
Contributor

Choose a reason for hiding this comment

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

почему или, должно же быть и - длинна скила не больше 25 и не больше 10 скилов


errors.add(:skills_description)
end

def to_s
name
end
Expand Down
7 changes: 7 additions & 0 deletions app/presenters/resume_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module ResumePresenter
def skills
Copy link
Contributor

Choose a reason for hiding this comment

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

У модели резюме уже есть метод skills, через который работает гем ActsAsTaggableOn, тут ты его переопределил, нужно выбрать другое имя метода

skills_description&.split("\n") || []
end
end
9 changes: 8 additions & 1 deletion app/views/web/resumes/_information.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ hr.my-auto
.col-sm-3
b = han('resume', 'skills_description')
.col-sm-9.hexlet-cv-content
== markdown2html @resume.skills_description
- if @resume.skills_description.nil?
== markdown2html @resume.skills_description_old
- else
.row
- @resume.skills.each_slice(5) do |skills_slice|
.col-6
- skills_slice.each do |skill|
li = skill[0..24]
- if @resume.projects_description
.row.mb-3
.col-sm-3
Expand Down
9 changes: 8 additions & 1 deletion app/views/web/shared/_resume_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@
.mt-3
.mb-3
= f.input :summary, input_html: { rows: 10 }
- if resume.skills_description.nil? && resume.skills_description_old
.row.bg-body-tertiary.rounded-3.border.mb-3.align-items-center
.col-3
strong = t('.skill_description_new_requirements')
eKulshan marked this conversation as resolved.
Show resolved Hide resolved
.col-9
p.fw-bold = t('.skill_description_prev_input')
== markdown2html @resume.skills_description_old
.mb-3
= f.input :skills_description, input_html: { rows: 5 }
= f.input :skills_description, input_html: { rows: 10 }
.mb-3
= f.input :projects_description, as: :text, input_html: { rows: 10 }

Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ en:
models:
resume:
attributes:
skills_description:
invalid: is not in the correct format
contact_email:
invalid: is not in the correct format
contact_phone:
Expand Down
4 changes: 3 additions & 1 deletion config/locales/en.views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ en:
contacts: Contacts
main: Main
add: Add
additionally: Additionally
additionally: Additionally
skill_description_new_requirements: 'To improve the skills readability, we have changed the filling requirements'
skill_description_prev_input: 'Your previous input'
work_fields:
remove_work: Delete work experience
education_fields:
Expand Down
6 changes: 4 additions & 2 deletions config/locales/ru.activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ru:
answer/comment: Комментарий
attributes:
user:
password: пароль
password: Пароль
resume_answer_likes_count: Количество лайков
first_name: Имя
last_name: Фамилия
Expand Down Expand Up @@ -161,10 +161,12 @@ ru:
models:
resume:
attributes:
skills_description:
invalid: имеют не верный формат
contact_email:
invalid: имеет не верный формат
contact_phone:
invalid: имеет неверное формат
invalid: имеет не верный формат
resume/answer/like:
attributes:
user:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/ru.views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ ru:
main: Основное
add: Заполнить
additionally: Дополнительно
skill_description_new_requirements: 'Для повышения читаемости навыков, мы изменили требования по заполнению.'
skill_description_prev_input: 'Ваш предыдущий ввод'
work_fields:
remove_work: Удалить опыт работы
education_fields:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ en:
projects_description: Indicate the projects in which you participated
summary: *markdown_tips
about_myself: *markdown_tips
skills_description: *markdown_tips
skills_description: 'One skill per line, no more than 10, skill length 25 characters max'
city: Specify the city of your residence
direction_list: |
Specify your direction. Here you need to specify only what you can say about the X-developer, for example: Java-developer. The maximum length is 40 characters. Separate tags with commas.
Expand Down
2 changes: 1 addition & 1 deletion config/locales/simple_form.ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ ru:
salary_to: Обязательно к заполнению, если не указан нижний уровень зарплаты и зарплата не по договоренности
resume:
summary: *markdown_tips
skills_description: *markdown_tips
skills_description: 'Один навык - одна строка, не более 10, длинна навыка не более 25 символов'
city: Укажите город вашего проживания
direction_list: |
Укажите ваше направление. Здесь нужно указывать только то, про что можно сказать X-разработчик, например: Java-разработчик. Максимальная длина 40 символов. Тэги разделяйте запятыми.
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20240508043924_update_resume_skill_description.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class UpdateResumeSkillDescription < ActiveRecord::Migration[7.0]
def change
rename_column :resumes, :skills_description, :skills_description_old
add_column :resumes, :skills_description, :text
end
eKulshan marked this conversation as resolved.
Show resolved Hide resolved
end
5 changes: 3 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_01_19_100332) do
ActiveRecord::Schema[7.0].define(version: 2024_05_08_043924) do
create_table "career_items", force: :cascade do |t|
t.integer "order"
t.integer "career_id", null: false
Expand Down Expand Up @@ -215,7 +215,7 @@
t.datetime "updated_at", null: false
t.string "url"
t.text "summary"
t.text "skills_description"
t.text "skills_description_old"
t.string "github_url"
t.text "awards_description"
t.string "english_fluency"
Expand All @@ -233,6 +233,7 @@
t.string "evaluated_ai_state"
t.text "projects_description"
t.text "about_myself"
t.text "skills_description", limit: 250
Copy link
Contributor

Choose a reason for hiding this comment

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

прогони плиз еще раз миграцию, в схеме осталась валидация на длину на уровне базы

t.index ["user_id"], name: "index_resumes_on_user_id"
end

Expand Down
24 changes: 24 additions & 0 deletions test/controllers/web/account/resumes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,28 @@ class Web::Account::ResumesControllerTest < ActionDispatch::IntegrationTest
resume = Resume.find_by(name: attrs[:name])
assert { !resume }
end

test '#create fail with invalid skills_description format' do
attrs = FactoryBot.attributes_for :resume
attrs[:skills_description] = "Too_many_skills\n" * 15

params = {
publish: true,
resume: attrs
}

post(account_resumes_path, params:)
Copy link
Contributor

Choose a reason for hiding this comment

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

в параметры добавь пожалуйста locale, что бы тест прогонялся для двух локалей

post account_resumes_path, params:, locale: I18n.locale

assert_response :unprocessable_entity

resume = Resume.find_by(name: attrs[:name])
assert { !resume }

attrs[:skills_description] = 'Invalid_skill_lenght' * 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Если тестируешь два разных кейса то лучше разделить на два теста


post(account_resumes_path, params:)
assert_response :unprocessable_entity

resume = Resume.find_by(name: attrs[:name])
assert { !resume }
end
end
55 changes: 28 additions & 27 deletions test/factories/resumes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@
#
# Table name: resumes
#
# id :integer not null, primary key
# about_myself :text
# answers_count :integer default(0), not null
# awards_description :text
# city :string
# contact :string
# contact_email :string
# contact_phone :string
# contact_telegram :string
# english_fluency :string
# evaluated_ai :boolean
# evaluated_ai_state :string
# github_url :string
# hexlet_url :string
# impressions_count :integer default(0)
# locale :string
# name :string not null
# projects_description :text
# relocation :string
# skills_description :text
# state :string
# summary :text
# url :string
# created_at :datetime not null
# updated_at :datetime not null
# user_id :integer not null
# id :integer not null, primary key
# about_myself :text
# answers_count :integer default(0), not null
# awards_description :text
# city :string
# contact :string
# contact_email :string
# contact_phone :string
# contact_telegram :string
# english_fluency :string
# evaluated_ai :boolean
# evaluated_ai_state :string
# github_url :string
# hexlet_url :string
# impressions_count :integer default(0)
# locale :string
# name :string not null
# projects_description :text
# relocation :string
# skills_description :text(250)
# skills_description_old :text
# state :string
# summary :text
# url :string
# created_at :datetime not null
# updated_at :datetime not null
# user_id :integer not null
#
# Indexes
#
Expand All @@ -43,7 +44,7 @@
factory :resume do
name { Faker::Job.title }
summary
skills_description
skills_description { Array.new(10) { Faker::Hobby.activity }.join("\n") }
github_url
contact
contact_email { 'test@emil.com' }
Expand Down
Loading
Loading