Skip to content

Commit 93636be

Browse files
committed
Fix identical locations, revive opportunity specs
locations.where doesn't include new records that aren't saved to the db, use `select` instead + Delete extra 'job' fabricator
1 parent ce17796 commit 93636be

File tree

3 files changed

+71
-113
lines changed

3 files changed

+71
-113
lines changed

app/models/opportunity.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ def add_opportunity_locations_to_team
277277
geocoded_all = true
278278
location.split('|').each do |location_string|
279279
# skip if location is anywhere or already exists
280-
if anywhere?(location_string) || team.locations.where('address ILIKE ?',"%location_string%").count > 0
281-
geocoded_all = false
280+
if anywhere?(location_string) || team.locations.select{|v| v.address.include?(location_string)}.count > 0
281+
geocoded_all = false
282282
next
283283
end
284284

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

spec/models/opportunity_spec.rb

Lines changed: 69 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -27,140 +27,102 @@
2727

2828
require 'spec_helper'
2929

30-
RSpec.describe Opportunity, type: :model, skip: true do
31-
# before(:each) do
32-
# FakeWeb.register_uri(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=San+Francisco%2C+CA&language=en&sensor=false', body: File.read(File.join(Rails.root, 'spec', 'fixtures', 'google_maps.json')))
33-
# end
34-
35-
describe 'creating and validating a new opportunity' do
36-
it 'should create a valid opportunity' do
37-
# TODO: Refactor api calls to Sidekiq job
38-
VCR.use_cassette('Opportunity') do
39-
40-
tags = ['rails', 'sinatra', 'JQuery', 'Clean, beautiful code']
41-
opportunity = Fabricate(:opportunity, tags: tags)
42-
opportunity.save!
43-
expect(opportunity.name).not_to be_nil
44-
expect(opportunity.description).not_to be_nil
45-
expect(opportunity.team_id).not_to be_nil
46-
expect(opportunity.tags.size).to eq(tags.size)
47-
expect(opportunity.cached_tags).to eq(tags.join(','))
48-
49-
end
50-
end
51-
52-
it 'can create opportunity with no tags without error' do
53-
# TODO: Refactor api calls to Sidekiq job
54-
VCR.use_cassette('Opportunity') do
55-
56-
skip 'need to upgrade to latest rocket tag'
57-
expect { Fabricate(:opportunity, tags: '') }.not_to raise_error
58-
59-
end
30+
RSpec.describe Opportunity, type: :model do
31+
32+
it 'should create a valid opportunity' do
33+
VCR.use_cassette('Opportunity') do
34+
tags = ['rails', 'sinatra', 'JQuery']
35+
opportunity = Fabricate(:opportunity, tag_list: tags)
36+
opportunity.save!
37+
expect(opportunity.name).not_to be_nil
38+
expect(opportunity.description).not_to be_nil
39+
expect(opportunity.team_id).not_to be_nil
40+
expect(opportunity.tags.size).to eq(tags.size)
41+
expect(opportunity.cached_tags).to eq(tags.map(&:downcase).join(','))
6042
end
6143
end
6244

6345
describe 'destroying opportunity' do
6446
it 'should not destroy the opportunity and only lazy delete it' do
65-
# TODO: Refactor api calls to Sidekiq job
66-
VCR.use_cassette('Opportunity') do
67-
68-
opportunity = Fabricate(:opportunity)
69-
opportunity.save
70-
expect(opportunity.deleted).to be_falsey
71-
opportunity.destroy
72-
expect(opportunity).to be_valid
73-
expect(opportunity.deleted).to be_truthy
74-
expect(opportunity.deleted_at).not_to be_nil
75-
76-
end
47+
VCR.use_cassette('Opportunity') do
48+
opportunity = Fabricate(:opportunity)
49+
opportunity.save
50+
expect(opportunity.deleted).to be_falsey
51+
opportunity.destroy
52+
expect(opportunity).to be_valid
53+
expect(opportunity.deleted).to be_truthy
54+
expect(opportunity.deleted_at).not_to be_nil
55+
end
7756
end
7857
end
7958

8059
describe 'apply for job' do
8160
it 'should create a valid application' do
82-
# TODO: Refactor api calls to Sidekiq job
83-
VCR.use_cassette('Opportunity') do
84-
85-
job = Fabricate(:job)
86-
job.salary = 25_000
87-
user = Fabricate(:user)
88-
job.apply_for(user)
89-
expect(job.applicants.size).to eq(1)
90-
expect(job.applicants.first).to eq(user)
91-
92-
end
61+
VCR.use_cassette('Opportunity') do
62+
job = Fabricate(:opportunity)
63+
job.salary = 25_000
64+
user = Fabricate(:user)
65+
job.apply_for(user)
66+
expect(job.applicants.size).to eq(1)
67+
expect(job.applicants.first).to eq(user)
68+
end
9369
end
9470

9571
it 'should not allow multiple applications' do
96-
# TODO: Refactor api calls to Sidekiq job
97-
VCR.use_cassette('Opportunity') do
98-
99-
job = Fabricate(:job)
100-
user = Fabricate(:user)
101-
expect(user.already_applied_for?(job)).to be_falsey
102-
expect(job.has_application_from?(user)).to be_falsey
103-
job.apply_for(user)
104-
user.apply_to(job)
105-
expect(job.applicants.size).to eq(1)
106-
expect(job.applicants.first).to eq(user)
107-
expect(user.already_applied_for?(job)).to be_truthy
108-
expect(job.has_application_from?(user)).to be_truthy
109-
110-
end
72+
VCR.use_cassette('Opportunity') do
73+
job = Fabricate(:opportunity)
74+
user = Fabricate(:user)
75+
expect(user.already_applied_for?(job)).to be_falsey
76+
expect(job.has_application_from?(user)).to be_falsey
77+
job.apply_for(user)
78+
user.apply_to(job)
79+
expect(job.applicants.size).to eq(1)
80+
expect(job.applicants.first).to eq(user)
81+
expect(user.already_applied_for?(job)).to be_truthy
82+
expect(job.has_application_from?(user)).to be_truthy
83+
end
11184
end
11285
end
11386

11487
describe 'changing job location' do
11588
it 'should set location_city' do
116-
# TODO: Refactor api calls to Sidekiq job
117-
VCR.use_cassette('Opportunity') do
118-
119-
job = Fabricate(:job)
120-
job.location = 'Amsterdam|San Francisco'
121-
job.save
122-
expect(job.location_city.split('|') - ['Amsterdam', 'San Francisco']).to eq([])
123-
124-
end
89+
VCR.use_cassette('Opportunity') do
90+
job = Fabricate(:opportunity)
91+
expect(job.location_city.split('|')).to match_array(['San Francisco'])
92+
job.location = 'Amsterdam|San Francisco'
93+
job.save
94+
expect(job.location_city.split('|')).to match_array(['Amsterdam', 'San Francisco'])
95+
end
12596
end
12697

12798
it 'should not add anywhere to location_city' do
128-
# TODO: Refactor api calls to Sidekiq job
129-
VCR.use_cassette('Opportunity') do
130-
131-
job = Fabricate(:job)
132-
job.location = 'Amsterdam|San Francisco|anywhere'
133-
job.save
134-
expect(job.location_city.split('|') - ['Amsterdam', 'San Francisco']).to eq([])
135-
136-
end
99+
VCR.use_cassette('Opportunity') do
100+
job = Fabricate(:opportunity)
101+
job.location = 'Amsterdam|San Francisco|anywhere'
102+
job.save
103+
expect(job.location_city.split('|')).to match_array(['Amsterdam', 'San Francisco'])
104+
end
137105
end
138106

139107
it 'should update location_city with changes' do
140-
# TODO: Refactor api calls to Sidekiq job
141-
VCR.use_cassette('Opportunity') do
142-
143-
job = Fabricate(:job)
144-
job.location = 'Amsterdam|San Francisco'
145-
job.save
146-
expect(job.location_city.split('|') - ['Amsterdam', 'San Francisco']).to eq([])
147-
job.location = 'Amsterdam'
148-
job.save
149-
expect(job.location_city).to eq('Amsterdam')
150-
151-
end
108+
VCR.use_cassette('Opportunity') do
109+
job = Fabricate(:opportunity)
110+
job.location = 'Amsterdam|San Francisco'
111+
job.save
112+
expect(job.location_city.split('|')).to match_array(['Amsterdam', 'San Francisco'])
113+
job.location = 'Amsterdam'
114+
job.save
115+
expect(job.location_city).to eq('Amsterdam')
116+
end
152117
end
153118

154119
it 'should not add existing locations to the team' do
155-
# TODO: Refactor api calls to Sidekiq job
156-
VCR.use_cassette('Opportunity') do
157-
158-
job = Fabricate(:job)
159-
job.location = 'San Francisco'
160-
job.save
161-
expect(job.team.locations.count).to be === 1
162-
163-
end
120+
VCR.use_cassette('Opportunity') do
121+
job = Fabricate(:opportunity)
122+
job.location = 'San Francisco'
123+
job.save
124+
expect(job.team.locations.count).to eq(1)
125+
end
164126
end
165127
end
166128
end

0 commit comments

Comments
 (0)