Commit 9ac4cda

mo khan <mo@mokhan.ca>
2016-05-21 16:49:52
hound happy.
1 parent f732951
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
 
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
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)
 
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