Skip to content

Instantly share code, notes, and snippets.

View jraczak's full-sized avatar

Justin Raczak jraczak

View GitHub Profile
# define search method to be used in Rails controller
def search(query=nil, options={})
options ||= {}
# setup empty search definition
@search_definition = {
query: {},
filter: {},
facets: {},
### elasticsearch_searchable.rb ###
require 'active_support/concern'
module ElasticsearchSearchable
extend ActiveSupport::Concern
included do
require 'elasticsearch/model'
@jraczak
jraczak / gist:09581f190929b16861c7
Created February 9, 2015 00:41
Recent activity spec for the user profile page
describe "#recent_activity" do
subject { FactoryGirl.create(:user) }
let!(:unowned_score) { FactoryGirl.create(:venue_score) }
let!(:unowned_tip) { FactoryGirl.create(:tip) }
let!(:unowned_list) { FactoryGirl.create(:list) }
context "when venue scores have been submitted" do
let!(:venue_score) { FactoryGirl.create(:venue_score, user: subject) }
it "should include venue scores" do
subject.recent_activity.any? { |activity| activity.class == VenueScore }.should == true
@jraczak
jraczak / gist:2cf0f44a2ae17cd9268b
Created December 6, 2014 22:50
New post version
def add_liked_venue_categories(venue_category_name, venue_subcategories)
params[:venue_subcategories].each do |vsc|
current_user.liked_venue_categories[params[:venue_category_name]] << vsc
end
user.save!
end
# Route is: post "/add_liked_cuisines" => "users#add_liked_venue_categories"
source 'http://rubygems.org'
gem 'rails', '3.2.2'
gem "pg"
gem "inherited_resources"
gem "slim-rails"
#gem "devise", "~> 2.1.0"
gem "devise" #, "~> 3.0.0"
gem "cancan"
require 'spec_helper'
describe "Homepage" do
it "should have the content 'Find new places to love'" do
visit '/'
expect(page).to have_content('Find new places to love')
end
end
require 'rubygems'
require 'spork'
# Requires for Sauce Labs testing
require 'rails/all'
require 'active_support'
require 'rspec/rails'
require 'capybara/rails'
require 'capybara/rspec'
#Capybara.default_driver = :sauce
2014-09-17T01:21:00.235370+00:00 app[web.1]: Started GET "/venues/search?utf8=%E2%9C%93&q=burgers&zip=san+francisco+ca" for 75.101.56.109 at 2014-09-17 01:21:00 +0000
2014-09-17T01:21:00.241916+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "q"=>"burgers", "zip"=>"san francisco ca"}
2014-09-17T01:21:00.288485+00:00 app[web.1]: Google geocoding. address: san francisco ca, args []
2014-09-17T01:21:00.241880+00:00 app[web.1]: Processing by VenuesController#search as HTML
2014-09-17T01:21:00.288332+00:00 app[web.1]:
2014-09-17T01:21:00.235334+00:00 app[web.1]:
2014-09-17T01:21:00.366311+00:00 app[web.1]: Google geocoding. Result: %7B%0A+++%22results%22+%3A+%5B%0A++++++%7B%0A+++++++++%22address_components%22+%3A+%5B%0A++++++++++++%7B%0A+++++++++++++++%22long_name%22+%3A+%22San+Francisco%22%2C%0A+++++++++++++++%22short_name%22+%3A+%22SF%22%2C%0A+++++++++++++++%22types%22+%3A+%5B+%22locality%22%2C+%22political%22+%5D%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A+++++++++++++++%22long_name%22+%3A+%22San+Francisco+County
class VenueSearch < ActiveRecord::Base
def self.search(params)
if params[:zip].present?
logger.info "The zip code is present"
logger.debug(Geocoder.coordinates(params[:zip]))
#lat, long = Geocoder.coordinates(params[:zip])
coords = Geokit::Geocoders::GoogleGeocoder.geocode(params[:zip])
lat = coords.lat
long = coords.lng
else
2014-09-17T00:59:46.549418+00:00 app[web.1]: Started GET "/venues/search?utf8=%E2%9C%93&q=burgers&zip=san+francisco+ca" for 75.101.56.109 at 2014-09-17 00:59:46 +0000
2014-09-17T00:59:46.578880+00:00 app[web.1]:
2014-09-17T00:59:46.603560+00:00 app[web.1]: Google Geocoding API error: request denied.
2014-09-17T00:59:46.753376+00:00 app[web.1]: SOLR Request (148.0ms) [ path=select parameters={fq: ["type:Venue", "{!geofilt sfield=location_ll pt=, d=12.427999999999999}"], sort: "geodist(location_ll,,) asc", q: "burgers", fl: "* score", qf: "name_text^5.0 name_without_punc_text^5.0 category_text^3.5 tips_text", defType: "edismax", mm: 2, start: 0, rows: 30} ]
2014-09-17T00:59:46.760030+00:00 app[web.1]: User Load (2.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 10 LIMIT 1
2014-09-17T00:59:46.552973+00:00 app[web.1]: The zip code is present
2014-09-17T00:59:46.911553+00:00 app[web.1]: ** [Airbrake] Failure: Net::HTTPClientError
2014-09-17T00:59:46.911564+00:00 app[web.1]: ** [Airbrake] Environment