Skip to content

Commit d562af5

Browse files
authored
Merge pull request #4 from tgaeta/add-migration-to-add-job-location
Track Location of the Job: Hybrid | In office | Remote
2 parents 83d9f1e + 31e5bcc commit d562af5

File tree

10 files changed

+63
-18
lines changed

10 files changed

+63
-18
lines changed

app/controllers/job_applications_controller.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,19 @@ def set_job_application
9696
end
9797

9898
def job_application_params
99-
params.require(:job_application).permit(:date_applied, :company_name, :method_of_contact, :email_address, :point_of_contact, :website_link, :position_type, :position_title, :claimed_for_unemployment, :status)
99+
params.require(:job_application).permit(:date_applied, :company_name, :method_of_contact, :email_address, :point_of_contact, :website_link, :position_type, :position_title, :claimed_for_unemployment, :status, :location)
100100
end
101101

102102
def filter_and_sort_job_applications
103103
job_applications = JobApplication.all
104104

105105
job_applications = job_applications.search(params[:search]) if params[:search].present?
106+
job_applications = job_applications.by_location(params[:location]) if params[:location].present?
106107
job_applications = job_applications.by_method_of_contact(params[:method_of_contact]) if params[:method_of_contact].present?
107108
job_applications = job_applications.by_position_type(params[:position_type]) if params[:position_type].present?
109+
job_applications = job_applications.by_status(params[:status]) if params[:status].present?
108110
job_applications = job_applications.claimed_for_unemployment if params[:claimed_for_unemployment] == "true"
109111
job_applications = job_applications.not_claimed_for_unemployment if params[:claimed_for_unemployment] == "false"
110-
job_applications = job_applications.by_status(params[:status]) if params[:status].present?
111112

112113
sort_column = sort_column(params[:sort])
113114
sort_direction = sort_direction(params[:direction])
@@ -122,7 +123,7 @@ def filter_and_sort_job_applications
122123
end
123124

124125
def sort_column(column)
125-
%w[date_applied company_name position_title created_at claimed_for_unemployment status].include?(column) ? column : "created_at"
126+
%w[date_applied company_name position_title created_at claimed_for_unemployment location status].include?(column) ? column : "created_at"
126127
end
127128

128129
def sort_direction(direction)

app/models/job_application.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class JobApplication < ApplicationRecord
22
attribute :status, :string
3+
attribute :location, :string
34

45
validates :date_applied, :company_name, :method_of_contact, :position_type, :position_title, presence: true
56
validates :email_address, presence: true, if: -> { method_of_contact == "email" }
@@ -13,6 +14,7 @@ class JobApplication < ApplicationRecord
1314
}
1415
validates :claimed_for_unemployment, inclusion: {in: [true, false]}
1516
validates :status, inclusion: {in: %w[hired interviewing job_offer no_response not_hired]}
17+
validates :location, inclusion: {in: %w[hybrid in_office remote]}
1618

1719
enum method_of_contact: {
1820
email: "email",
@@ -33,7 +35,13 @@ class JobApplication < ApplicationRecord
3335
no_response: "no response",
3436
not_hired: "not hired"
3537
}
38+
enum location: {
39+
hybrid: "hybrid",
40+
in_office: "in office",
41+
remote: "remote"
42+
}
3643

44+
scope :by_location, ->(location) { where(location: location) }
3745
scope :by_method_of_contact, ->(method) { where(method_of_contact: method) }
3846
scope :by_position_type, ->(type) { where(position_type: type) }
3947
scope :by_status, ->(status) { where(status: status) }
@@ -45,6 +53,7 @@ class JobApplication < ApplicationRecord
4553
email_address ILIKE :query OR
4654
point_of_contact ILIKE :query OR
4755
website_link ILIKE :query OR
56+
location ILIKE :query OR
4857
status ILIKE :query", query: "%#{query}%")
4958
}
5059
end

app/views/job_applications/_form.html.erb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,17 @@
5252
</div>
5353
<div>
5454
<%= form.label :status, class: 'block text-sm font-medium text-gray-700 mb-2' %>
55-
<%= form.select :status, JobApplication.statuses.keys.map { |k| [k.humanize, k] }, { include_blank: 'Select a status' }, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
56-
<div class="mt-8">
57-
<%= form.label :claimed_for_unemployment, class: 'flex items-center' do %>
58-
<%= form.check_box :claimed_for_unemployment, class: 'h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded mr-2' %>
59-
<span class="text-sm font-medium text-gray-700">Claimed for Unemployment</span>
60-
<% end %>
61-
</div>
55+
<%= form.select :status, JobApplication.statuses.keys.map { |k| [k.humanize, k] }, { include_blank: false }, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
56+
</div>
57+
<div>
58+
<%= form.label :location, class: 'block text-sm font-medium text-gray-700 mb-2' %>
59+
<%= form.select :location, JobApplication.locations.keys.map { |k| [k.humanize, k] }, { include_blank: false }, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
60+
</div>
61+
<div class="mt-8">
62+
<%= form.label :claimed_for_unemployment, class: 'flex items-center' do %>
63+
<%= form.check_box :claimed_for_unemployment, class: 'h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded mr-2' %>
64+
<span class="text-sm font-medium text-gray-700">Claimed for Unemployment</span>
65+
<% end %>
6266
</div>
6367
</div>
6468
<div class="flex items-center justify-end mt-6">

app/views/job_applications/_job_application.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
2727
<%= job_application.status.humanize %>
2828
</td>
29+
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
30+
<%= job_application.location.humanize %>
31+
</td>
2932
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
3033
<% if job_application.website_link.present? %>
3134
<%= link_to 'Visit',

app/views/job_applications/_job_applications_table.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<th class="px-5 py-3">
3232
<%= sort_link_to 'Status', 'status' %>
3333
</th>
34+
<th class="px-5 py-3">
35+
<%= sort_link_to 'Location', 'location' %>
36+
</th>
3437
<th class="px-5 py-3">
3538
Website
3639
</th>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddLocationToJobApplications < ActiveRecord::Migration[7.1]
2+
def change
3+
add_column :job_applications, :location, :string, null: false, default: "remote"
4+
add_check_constraint :job_applications, "location IN ('remote', 'in office', 'hybrid')", name: "check_valid_location"
5+
end
6+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/seeds.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "faker"
22

33
JobApplication.destroy_all
4-
50.times do
4+
20.times do
55
method_of_contact = %w[email internet_job_application recruiter].sample
66
email_address = (method_of_contact == "email") ? Faker::Internet.email : nil
77
website_link = (method_of_contact == "internet_job_application") ? "https://example.com/" : nil
@@ -16,6 +16,7 @@
1616
position_title: Faker::Job.title,
1717
website_link: website_link,
1818
claimed_for_unemployment: [true, false].sample,
19-
status: %w[interviewing no_response not_hired job_offer].sample
19+
status: %w[interviewing no_response not_hired job_offer].sample,
20+
location: %w[remote in_office hybrid].sample
2021
)
2122
end

test/factories/job_applications_factory.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
FactoryBot.define do
22
factory :job_application do
3-
date_applied { Date.new(2023, 1, 1) }
3+
claimed_for_unemployment { false }
44
company_name { "Example Company" }
5+
date_applied { Date.new(2023, 1, 1) }
6+
email_address { "[email protected]" }
7+
location { "remote" }
58
method_of_contact { "email" }
6-
position_type { "full_time" }
9+
point_of_contact { "John Doe" }
710
position_title { "Software Engineer" }
8-
claimed_for_unemployment { false }
11+
position_type { "full_time" }
912
status { "interviewing" }
10-
email_address { "[email protected]" }
11-
point_of_contact { "John Doe" }
1213

1314
trait :with_website do
1415
method_of_contact { "internet_job_application" }

test/models/job_application_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ def setup
6060
assert_not_nil @job_application.errors[:website_link]
6161
end
6262

63+
test "job application validates location inclusion" do
64+
assert_raises(ArgumentError) do
65+
build(:job_application, location: "invalid_location")
66+
end
67+
end
68+
6369
test "job application validates status inclusion" do
6470
assert_raises(ArgumentError) do
6571
build(:job_application, status: "invalid_status")
@@ -84,6 +90,15 @@ def setup
8490
assert_equal 1, JobApplication.by_method_of_contact("internet_job_application").count
8591
end
8692

93+
test "by_location scope finds job applications by location" do
94+
JobApplication.destroy_all
95+
create(:job_application, location: "remote")
96+
create(:job_application, location: "in_office")
97+
98+
assert_equal 1, JobApplication.by_location("remote").count
99+
assert_equal 1, JobApplication.by_location("in_office").count
100+
end
101+
87102
test "by_position_type scope finds job applications by position_type" do
88103
JobApplication.destroy_all
89104
create(:job_application, position_type: "full_time")

0 commit comments

Comments
 (0)