Skip to content

Commit 4261203

Browse files
committed
Merge pull request coderwall#310 from rohitpaulk/fix-teams-problems
Fix teams problems
2 parents 71e19f2 + 93636be commit 4261203

File tree

10 files changed

+119
-171
lines changed

10 files changed

+119
-171
lines changed

app/models/opportunity.rb

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Opportunity < ActiveRecord::Base
4646
validates :tag_list, with: :tags_within_length
4747
validates :location, presence: true, allow_blank: false
4848
validates :location_city, presence: true, allow_blank: false, unless: lambda { location && anywhere?(location) }
49-
validates :salary, presence: true, numericality: true, inclusion: 0..800_000, allow_blank: true
49+
validates :salary, presence: true, numericality: {only_integer: true, greater_than: 0, less_than_or_equal_to: 800000}, allow_blank: true
5050

5151
before_validation :set_location_city
5252
before_save :update_cached_tags
@@ -71,22 +71,6 @@ def self.human_attribute_name(attr,options={})
7171
HUMANIZED_ATTRIBUTES[attr.to_sym] || super
7272
end
7373

74-
def self.parse_salary(salary_string)
75-
salary_string.match(/(\d+)\s*([kK]?)/)
76-
number, thousands = Regexp.last_match[1], Regexp.last_match[2]
77-
78-
if number.nil?
79-
0
80-
else
81-
salary = number.to_i
82-
if thousands.downcase == 'k' || salary < 1000
83-
salary * 1000
84-
else
85-
salary
86-
end
87-
end
88-
end
89-
9074
def self.based_on(tags)
9175
query_string = "tags:#{tags.join(' OR ')}"
9276
failover_scope = Opportunity.joins('inner join taggings on taggings.taggable_id = opportunities.id').joins('inner join tags on taggings.tag_id = tags.id').where("taggings.taggable_type = 'Opportunity' AND taggings.context = 'tags'").where('lower(tags.name) in (?)', tags.map(&:downcase)).group('opportunities.id').order('count(opportunities.id) desc')
@@ -293,8 +277,8 @@ def add_opportunity_locations_to_team
293277
geocoded_all = true
294278
location.split('|').each do |location_string|
295279
# skip if location is anywhere or already exists
296-
if anywhere?(location_string) || team.locations.where('address ILIKE ?',"%location_string%").count > 0
297-
geocoded_all = false
280+
if anywhere?(location_string) || team.locations.select{|v| v.address.include?(location_string)}.count > 0
281+
geocoded_all = false
298282
next
299283
end
300284

app/models/user.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,17 +336,17 @@ def team_ids
336336
end
337337

338338
def following_team?(team)
339-
followed_teams.collect(&:team_id).include?(team.id.to_s)
339+
followed_teams.collect(&:team_id).include?(team.id)
340340
end
341341

342342
def follow_team!(team)
343-
followed_teams.create!(team_id: team.id.to_s)
343+
followed_teams.create!(team: team)
344344
generate_event(team: team)
345345
end
346346

347347
def unfollow_team!(team)
348-
followed_teams = self.followed_teams.where(team_id: team.id.to_s).all
349-
followed_teams.each(&:destroy)
348+
followed_teams = self.followed_teams.where(team_id: team.id)
349+
followed_teams.destroy_all
350350
end
351351

352352
def teams_being_followed

app/views/opportunities/_form.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
%fieldset
2525
-if @team.locations.any?
2626
=j.label :location do
27-
== Select one or more locations where the candidate must be located or #{link_to('add/manage team locations', edit_team_locations_path(@team))}
27+
== Select one or more locations where the candidate must be located or #{link_to('add/manage team locations', teamname_edit_path(slug: @team.slug, anchor: "locations"))}
2828
=j.select(:location, @team.cities+["anywhere"], {selected: (@job.location.blank? ? [] : @job.location.split("|"))}, {multiple: true})
2929
-else
3030
=j.label :location, 'Specify the city/location where the candidate must be located'
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-if target.errors.any?
22
.errors
3-
%h4==#{pluralize(target.errors.count, "error")} prohibited this user from being saved:
3+
%h4
4+
= "#{pluralize(target.errors.count, "error")} prohibited this #{target.class.model_name.human.downcase} from being saved:"
45
%ul
56
-target.errors.full_messages.each do |message|
67
%li=raw message

app/views/teams/_locations.html.haml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
.add-map-location= link_to_add_fields('Add new location', f, :locations)
1414
-if @team.has_locations?
1515
.location-list
16-
= f.fields_for :team_locations do |fields|
16+
= f.fields_for :locations do |fields|
1717
.item
18-
= fields.hidden_field :id
1918
%fieldset
2019
= fields.label :name, 'Location Name'
2120
= fields.text_field :name

config/routes.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# == Route Map
22
#
3-
# GET /.json(.:format) #<Proc:0x00000009e29dd0@/home/vagrant/web/config/routes.rb:270>
4-
# GET /teams/.json(.:format) #<Proc:0x00000009e32750@/home/vagrant/web/config/routes.rb:271>
3+
# GET /.json(.:format) #<Proc:0x00000008e12370@/home/vagrant/web/config/routes.rb:270>
4+
# GET /teams/.json(.:format) #<Proc:0x00000008e324e0@/home/vagrant/web/config/routes.rb:271>
55
# /mail_view MailPreview
66
# protips_update GET|PUT /protips/update(.:format) protips#update
77
# protip_update GET|PUT /protip/update(.:format) protip#update
@@ -139,13 +139,6 @@
139139
# team_member GET /teams/:team_id/members/:id(.:format) members#show
140140
# PUT /teams/:team_id/members/:id(.:format) members#update
141141
# DELETE /teams/:team_id/members/:id(.:format) members#destroy
142-
# team_locations GET /teams/:team_id/locations(.:format) locations#index
143-
# POST /teams/:team_id/locations(.:format) locations#create
144-
# new_team_location GET /teams/:team_id/locations/new(.:format) locations#new
145-
# edit_team_location GET /teams/:team_id/locations/:id/edit(.:format) locations#edit
146-
# team_location GET /teams/:team_id/locations/:id(.:format) locations#show
147-
# PUT /teams/:team_id/locations/:id(.:format) locations#update
148-
# DELETE /teams/:team_id/locations/:id(.:format) locations#destroy
149142
# apply_team_opportunity POST /teams/:team_id/opportunities/:id/apply(.:format) opportunities#apply
150143
# activate_team_opportunity GET /teams/:team_id/opportunities/:id/activate(.:format) opportunities#activate
151144
# deactivate_team_opportunity GET /teams/:team_id/opportunities/:id/deactivate(.:format) opportunities#deactivate
@@ -405,7 +398,7 @@
405398
get 'search'
406399
end
407400
resources :members
408-
resources :locations, as: :locations
401+
409402
resources :opportunities do
410403
member do
411404
post 'apply'

spec/controllers/teams_controller_spec.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
require 'spec_helper'
22

3-
RSpec.describe TeamsController, type: :controller, skip: true do
3+
RSpec.describe TeamsController, type: :controller do
44
let(:current_user) { Fabricate(:user) }
55
let(:team) { Fabricate(:team) }
66

77
before { controller.send :sign_in, current_user }
88

99
it 'allows user to follow team' do
10-
post :follow, id: team.id
10+
post :follow, id: team.id, format: :js
11+
12+
expect(response).to be_success
13+
current_user.reload
1114
expect(current_user.following_team?(team)).to eq(true)
1215
end
1316

1417
it 'allows user to stop follow team' do
1518
current_user.follow_team!(team)
19+
current_user.reload
20+
expect(current_user.following_team?(team)).to eq(true)
1621
post :follow, id: team.id
1722
current_user.reload
1823
expect(current_user.following_team?(team)).to eq(false)
@@ -27,6 +32,12 @@
2732
end
2833

2934
describe 'GET #show' do
35+
before do
36+
url = 'http://maps.googleapis.com/maps/api/geocode/json?address=San%20Francisco,%20CA&language=en&sensor=false'
37+
@body ||= File.read(File.join(Rails.root, 'spec', 'fixtures', 'google_maps.json'))
38+
stub_request(:get, url).to_return(body: @body)
39+
end
40+
3041
it 'responds successfully with an HTTP 200 status code' do
3142
team = Fabricate(:team) do
3243
name Faker::Company.name
@@ -36,11 +47,13 @@
3647
expect(response).to be_success
3748
expect(response).to have_http_status(200)
3849
end
50+
3951
it 'sets job_page to true if job is found' do
40-
opporunity = Fabricate(:opportunity)
52+
opportunity = Fabricate(:opportunity)
4153
get :show, slug: opportunity.team.slug, job_id: opportunity.public_id
4254
expect(assigns(:job_page)).to eq(true)
4355
end
56+
4457
it 'sets job_page to false if job is not found' do
4558
team = Fabricate(:team)
4659
get :show, slug: team.slug, job_id: 'not-a-real-job-slug'
@@ -85,7 +98,7 @@
8598
end
8699

87100
it 'adds current user to the team' do
88-
expect(team).to receive(:add_user).with(current_user)
101+
expect(team).to receive(:add_user).with(current_user, 'active', 'admin')
89102
response
90103
end
91104

spec/fabricators/opportunity_fabricator.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,3 @@
3636
remote false
3737
expires_at { Time.now + 1.year }
3838
end
39-
40-
Fabricator(:job, from: :opportunity, class_name: :opportunity) do
41-
42-
end

0 commit comments

Comments
 (0)