Skip to content

Commit cfd7849

Browse files
committed
Merge pull request coderwall#271 from nicolasiensen/bounties/441
Add remote filter for opportunities list #441
2 parents e50ba19 + 67f873c commit cfd7849

9 files changed

+57
-12
lines changed

app/controllers/opportunities_controller.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def edit
2929
end
3030

3131
def create
32-
opportunity_create_params = params.require(:opportunity).permit(:name, :team_id, :opportunity_type, :description, :tags, :location, :link, :salary, :apply)
32+
opportunity_create_params = params.require(:opportunity).permit(:name, :team_id, :opportunity_type, :description, :tags, :location, :link, :salary, :apply, :remote)
3333
@job = Opportunity.new(opportunity_create_params)
3434
respond_to do |format|
3535
if @job.save
@@ -166,7 +166,15 @@ def geocode_location(location)
166166

167167
def get_jobs_for(chosen_location, tag, page)
168168
scope = Opportunity
169-
scope = scope.by_city(chosen_location) unless chosen_location.nil?
169+
170+
if chosen_location.present?
171+
if chosen_location == "Remote"
172+
scope = scope.where(remote: true)
173+
else
174+
scope = scope.by_city(chosen_location)
175+
end
176+
end
177+
170178
scope = scope.by_tag(tag) unless tag.nil?
171179
# TODO: Verify that there are no unmigrated teams
172180
scope = scope.where('team_id is not null')

app/helpers/opportunities_helper.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ def add_job_or_signin_path
99
end
1010

1111
def job_location_string(location)
12-
location == "Worldwide" ? location : "in #{location}"
12+
if location == "Worldwide"
13+
"Jobs Worldwide"
14+
elsif location == "Remote"
15+
"Remote Jobs"
16+
else
17+
"Jobs in #{location}"
18+
end
1319
end
1420

1521
def google_maps_image_url(location)

app/views/opportunities/_form.html.haml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
=j.label :location, 'Specify the city/location where the candidate must be located'
3131
=j.text_field :location
3232

33+
%fieldset
34+
=j.label :remote do
35+
=j.check_box :remote
36+
Allow remote
37+
3338
%fieldset
3439
=j.label :link, 'Link to full job posting on your career site (ex: http://example.com/career)'
3540
=j.text_field :link
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
%li.cf
22
%a.job.track{ href: job_path(slug: opportunity.team.slug, job_id: opportunity.public_id), 'data-action' => 'view job', 'data-from' => 'jobs page', 'data-properties' => { team: opportunity.team.name, public_id: opportunity.public_id }.to_json }
33
%h2= opportunity.title
4-
%h3= opportunity.opportunity_type.capitalize
4+
%h3
5+
= opportunity.opportunity_type
6+
- if opportunity.remote?
7+
and remote
58
%p= opportunity.description
69
.team.cf
710
.details
811
%a.team-name.track{ href: friendly_team_path(opportunity.team), 'data-action' => 'view job', 'data-from' => 'jobs page', 'data-properties' => { team: opportunity.team.name, public_id: opportunity.public_id}.to_json }
912
%h4= opportunity.team.name
10-
%p.location= (params[:location] != 'Worldwide' && params[:location]) || opportunity.locations.first
13+
%p.location= opportunity.locations.first || "Worldwide"
1114
%p.tag-line= opportunity.team.hiring_tagline || opportunity.team.about
1215
.team-avatar= link_to image_tag(opportunity.team.avatar_url), friendly_team_path(opportunity.team)

app/views/opportunities/index.html.haml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
%a.filter{ href: '/' }
1515
%h3= params[:skill].try(:titleize)
1616
%h1
17-
Jobs
1817
%span= job_location_string(params[:location].titleize)
1918
%ul.location-drop-down.hide
19+
%li
20+
%a{ href: jobs_path(location: 'remote', skill: params[:skill]), class: "remote", 'data-action' => "view remote jobs", 'data-from' => 'jobs page', 'data-properties' => { 'location' => "Remote" }.to_json } Remote
2021
- @locations.each do |location|
2122
%li
2223
%a{ href: jobs_path(location: location.parameterize, skill: params[:skill]), class: location.downcase, 'data-action' => "view jobs in #{location.downcase}", 'data-from' => 'jobs page', 'data-properties' => { 'location' => params[:location] }.to_json }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddRemoteToOpportunity < ActiveRecord::Migration
2+
def change
3+
add_column :opportunities, :remote, :boolean
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended to check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(:version => 20141111082038) do
14+
ActiveRecord::Schema.define(:version => 20141221211825) do
1515

1616
add_extension "citext"
1717
add_extension "hstore"
@@ -211,6 +211,7 @@
211211
t.boolean "apply", :default => false
212212
t.string "public_id"
213213
t.integer "team_id"
214+
t.boolean "remote"
214215
end
215216

216217
create_table "pictures", :force => true do |t|

spec/controllers/opportunity_controlller_spec.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,24 @@
22

33
RSpec.describe OpportunitiesController, type: :controller do
44

5-
it 'render #index' do
6-
get :index
7-
expect(response.status).to eq(200)
8-
expect(response).to render_template(['opportunities/index', 'layouts/jobs'])
9-
end
5+
describe "GET index" do
6+
it "should respond with 200" do
7+
get :index
8+
expect(response.status).to eq(200)
9+
end
10+
11+
it "should render the opportunities index template with jobs layout" do
12+
get :index
13+
expect(response).to render_template(['opportunities/index', 'layouts/jobs'])
14+
end
1015

16+
context "when it's filtered by remote opportunities" do
17+
before { @opportunity = Fabricate(:opportunity, remote: true, location: "Anywhere") }
18+
19+
it "should assign the remote opportunities to @jobs" do
20+
get :index, location: 'remote'
21+
expect(assigns(:jobs)).to be_include(@opportunity)
22+
end
23+
end
24+
end
1125
end

spec/fabricators/opportunity_fabricator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
location 'San Francisco, CA'
77
cached_tags 'java, python'
88
team_id { Fabricate(:team, paid_job_posts: 1).id }
9+
remote false
10+
expires_at { Time.now + 1.year }
911
end
1012

1113
Fabricator(:job, from: :opportunity, class_name: :opportunity) do

0 commit comments

Comments
 (0)