diff options
| author | mo khan <mo@mokhan.ca> | 2016-05-21 10:49:52 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2016-05-21 10:50:37 -0600 |
| commit | 9ac4cdaba4e4df09f89ffdecaabf69555d62e0d3 (patch) | |
| tree | 41b2b343cf6f8347b0f90681b48eccfbfdbf26b9 | |
| parent | f7329510e820c2f6f58f5c12cf5ae1d177fbbb27 (diff) | |
hound happy.
| -rw-r--r-- | app/models/gym.rb | 4 | ||||
| -rw-r--r-- | app/models/search.rb | 11 | ||||
| -rw-r--r-- | spec/jobs/import_gyms_job_spec.rb | 6 | ||||
| -rw-r--r-- | spec/models/user_session_spec.rb | 12 |
4 files changed, 17 insertions, 16 deletions
diff --git a/app/models/gym.rb b/app/models/gym.rb index 3e6d532..8a97710 100644 --- a/app/models/gym.rb +++ b/app/models/gym.rb @@ -20,7 +20,7 @@ class Gym < ActiveRecord::Base "OR UPPER(locations.city) LIKE :query", "OR UPPER(locations.region) LIKE :query", "OR UPPER(locations.country) LIKE :query" - ].join(' ') + ].join(" ") joins(:location).where(sql, { query: "%#{query.upcase}%" }) end @@ -64,7 +64,7 @@ class Gym < ActiveRecord::Base return if city.blank? return [] if Rails.env.test? (1..pages).each do |page| - Gym.search_yelp(q: 'gym', city: city, page: page).each(&:save!) + Gym.search_yelp(q: "gym", city: city, page: page).each(&:save!) end end diff --git a/app/models/search.rb b/app/models/search.rb index 57bd263..8a2c9f7 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -6,7 +6,7 @@ class Search @client = client end - def search(q, categories = [], city, page, per_page, &block) + def search(q, city, categories = [], page = 1, per_page = 20, &block) return [] if city.blank? cache(key: key_for(q, city, page, per_page)) do @@ -17,16 +17,17 @@ class Search private def key_for(*args) - args.join('-') + args.join("-") end def results_for(q, city, categories, page, per_page) - client.search(city, { + client.search( + city, category_filter: categories.join(","), limit: per_page, offset: offset_for(page, per_page), term: q, - }).businesses + ).businesses end def paginate(results) @@ -45,6 +46,6 @@ class Search end def self.yelp(q, categories = [], city, page, per_page, &block) - Yelp.new.search(q, categories, city, page, per_page, &block) + Yelp.new.search(q, city, categories, page, per_page, &block) end end diff --git a/spec/jobs/import_gyms_job_spec.rb b/spec/jobs/import_gyms_job_spec.rb index 69e3969..8900f4d 100644 --- a/spec/jobs/import_gyms_job_spec.rb +++ b/spec/jobs/import_gyms_job_spec.rb @@ -4,19 +4,19 @@ describe ImportGymsJob do subject { ImportGymsJob.new } let(:location) { build(:portland) } - it 'imports all the gyms in the city' do + it "imports all the gyms in the city" do allow(Gym).to receive(:import) subject.perform(location) expect(Gym).to have_received(:import).with(location.city) end - it 'skips the import if no location is present' do + it "skips the import if no location is present" do allow(Gym).to receive(:import) subject.perform(nil) expect(Gym).to_not have_received(:import) end - it 'skips the import of gyms in the city are already present' do + it "skips the import of gyms in the city are already present" do allow(Gym).to receive(:import) create(:gym, location: location) diff --git a/spec/models/user_session_spec.rb b/spec/models/user_session_spec.rb index 7878354..8cc1c18 100644 --- a/spec/models/user_session_spec.rb +++ b/spec/models/user_session_spec.rb @@ -11,12 +11,12 @@ describe UserSession do end describe "#access" do - let(:request) { double(ip: '192.168.1.1', user_agent: 'blah') } + let(:request) { double(ip: "192.168.1.1", user_agent: "blah") } let(:location) { build(:location) } let(:because) { subject.access(request) } before :each do - allow(Location).to receive(:build_from_ip).with('192.168.1.1').and_return(location) + allow(Location).to receive(:build_from_ip).with("192.168.1.1").and_return(location) because end @@ -54,16 +54,16 @@ describe UserSession do end it "returns nil if the id is not active" do - expect(UserSession.authenticate('blah')).to be_nil + expect(UserSession.authenticate("blah")).to be_nil end end describe "#after_create" do - it 'schedules a job to import gyms in city' do + it "schedules a job to import gyms in city" do allow(ImportGymsJob).to receive(:perform_later) - subject.location = create(:portland) + subject.location = location = create(:portland) subject.save! - expect(ImportGymsJob).to have_received(:perform_later).with(subject.location) + expect(ImportGymsJob).to have_received(:perform_later).with(location) end end end |
