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

Fix/sidekiq notifications #176

Merged
merged 2 commits into from
Feb 21, 2024
Merged
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
9 changes: 7 additions & 2 deletions app/models/user_skill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
# id :bigint not null, primary key
# last_applied_in_year :integer
# level :string
# years_of_experience :float
# created_at :datetime not null
# updated_at :datetime not null
# skill_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_user_skills_on_skill_id (skill_id)
# index_user_skills_on_user_id (user_id)
# index_user_skills_on_skill_id (skill_id)
# index_user_skills_on_user_id (user_id)
# index_user_skills_on_user_id_and_skill_id (user_id,skill_id) UNIQUE
#
# Foreign Keys
#
Expand All @@ -29,4 +31,7 @@ class UserSkill < ApplicationRecord
VALID_LEVELS = %w[beginner intermediate advanced].freeze
validates :level, presence: true, inclusion: { in: VALID_LEVELS }
validates :last_applied_in_year, presence: true
validates :years_of_experience, presence: true

validates :user_id, uniqueness: { scope: :skill_id }
end
5 changes: 5 additions & 0 deletions app/views/user_skills/_user_skill.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

# _user_service_identifier.json.jbuilder

json.extract! user_skill, :id, :last_applied_in_year, :level, :years_of_experience
2 changes: 2 additions & 0 deletions app/views/users/_user.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ json.permissions user.permissions, partial: 'permissions/permission', as: :permi
# Render the user_service_identifiers partial for each identifier
json.user_service_identifiers user.user_service_identifiers,
partial: 'user_service_identifiers/user_service_identifier', as: :user_service_identifier

json.user_skills user.user_skills, partial: 'user_skills/user_skill', as: :user_skill
10 changes: 6 additions & 4 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
end

config.error_handlers << proc do |ex, ctx_hash, _cfg|
job = ctx_hash[:job]['class']
args = ctx_hash[:job]['args']
if Rails.env.production?
job = ctx_hash[:job]['class']
args = ctx_hash[:job]['args']

message = "There was an error with the job: #{job} with arguments: #{args.join(',')}.\nThe error message is: #{ex}"
RubyNotificationsClient::Channel.new.send(message, ENV.fetch('ERROR_NOTIFICATION_CHANNEL', nil))
message = "There was an error with the job: #{job} with arguments: #{args.join(',')}.\nThe error message is: #{ex}"
RubyNotificationsClient::Channel.new.send(message, ENV.fetch('ERROR_NOTIFICATION_CHANNEL', nil))
end
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddYearsOfExperienceToUserSkill < ActiveRecord::Migration[7.0]
def change
add_column :user_skills, :years_of_experience, :float
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddUniqueIndexToUserSkillsOnUserIdAndSkillId < ActiveRecord::Migration[7.0]
def change
add_index :user_skills, %i[user_id skill_id], unique: true
end
end
5 changes: 4 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions spec/factories/user_skills.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
# id :bigint not null, primary key
# last_applied_in_year :integer
# level :string
# years_of_experience :float
# created_at :datetime not null
# updated_at :datetime not null
# skill_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_user_skills_on_skill_id (skill_id)
# index_user_skills_on_user_id (user_id)
# index_user_skills_on_skill_id (skill_id)
# index_user_skills_on_user_id (user_id)
# index_user_skills_on_user_id_and_skill_id (user_id,skill_id) UNIQUE
#
# Foreign Keys
#
Expand All @@ -28,5 +30,6 @@
skill
level { UserSkill::VALID_LEVELS.sample }
last_applied_in_year { 2020 }
years_of_experience { 1.5 }
end
end
15 changes: 13 additions & 2 deletions spec/models/user_skill_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
# id :bigint not null, primary key
# last_applied_in_year :integer
# level :string
# years_of_experience :float
# created_at :datetime not null
# updated_at :datetime not null
# skill_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_user_skills_on_skill_id (skill_id)
# index_user_skills_on_user_id (user_id)
# index_user_skills_on_skill_id (skill_id)
# index_user_skills_on_user_id (user_id)
# index_user_skills_on_user_id_and_skill_id (user_id,skill_id) UNIQUE
#
# Foreign Keys
#
Expand All @@ -28,11 +30,20 @@
context 'validations' do
it { should validate_presence_of(:level) }
it { should validate_presence_of(:last_applied_in_year) }
it { should validate_presence_of(:years_of_experience) }
it { should validate_inclusion_of(:level).in_array(UserSkill::VALID_LEVELS) }
end

context 'associations' do
it { should belong_to(:user) }
it { should belong_to(:skill) }

it 'validates that :user_id is case-sensitively unique within the scope of :skill_id' do
user = create(:user)
skill = create(:skill)
create(:user_skill, user:, skill:)
new_user_skill = UserSkill.new(user_id: user.id, skill_id: skill.id)
expect(new_user_skill).to validate_uniqueness_of(:user_id).scoped_to(:skill_id).case_insensitive
end
end
end
Loading