Skip to content

Instantly share code, notes, and snippets.

View osiro's full-sized avatar

Vinny Osiro osiro

View GitHub Profile
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'spree/testing_support/factories'
require 'spree_product_contributors/factories'
require 'capybara/poltergeist'
require 'simplecov'
require 'email_spec'
$ cap deploy
* 11:23:28 == Currently executing `stages:ensure'
Using the default stage: staging
* 11:23:28 == Currently executing `defaults:check_variables'
* 11:23:28 == Currently executing `deploy'
* 11:23:28 == Currently executing `deploy:pre_deploy'
* 11:23:28 == Currently executing `defaults:confirm'
Getting a list of remote git refs...
1. 0.6.6
2. 0.6.5
e = FactoryGirl.build_stubbed(:employee_profile)
=> #<EmployeeProfile id: 1012, user_id: 1010, joined_at: "2006-10-30", terminated_at: "2014-10-28", status: "F", base_hours_per_week: #<BigDecimal:101675550,'0.8070517643 283242E1',27(45)>, clinic_id: 1011, employee_position_id: 1007, modality_id: 1008, leave_group_id: 1009, exec_staff_wages: "Administration", created_at: nil, updated_at: nil>
e.persisted?
=> true
e.user
=> #<User id: 1010, email: "2malvina@hermiston.us", encrypted_password: "$2a$10$kXLvkcy5u9biitZZ94lbs.WA2KEVMaQb2D5dtBZTmgns...", sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: nil, updated_at: nil, archived: false, job_type_id: nil, full_name: "Aiden Mitchell", supervisor_id: nil, username: "2austen_osinski", role_id: 3, job_type: nil, time_format: "12">
e.user.persisted?
=> true
EmployeeProfile.find_by(id: 1012)
=> nil
EXPLAIN SELECT * FROM users WHERE LOWER(full_name) LIKE 'vinny%';
QUERY PLAN
----------------------------------------------------------------------------
Seq Scan on users (cost=10000000000.00..10000000001.01 rows=1 width=1784)
Filter: (lower((full_name)::text) ~~ 'vinny%'::text)
- # TODO add in data for project creator (John Smith) and location (Perth, WA)
.project-tiles
.recent-projects
- if projects.count(:all) > 0 # just "count" raises an exception: https://github.com/Casecommons/pg_search/issues/127
- projects.each do |project|
%article.project{ data: { project: { id: project.id } } }
.project-thumbnail
= link_to project_path(project) do
= image_tag(project.thumbnail.url)
.project-details
require 'feature_helper'
feature "project coordinators can view a project" do
background do
sign_in_as :user
end
scenario "successfully viewing a project", js: true do
create_project_for_user
em-funding_development=# EXPLAIN ANALYZE SELECT "projects".*, ((ts_rank((to_tsvector('english', coalesce("projects"."title"::text, '')) || to_tsvector('english', coalesce("projects"."description"::text, ''))), (to_tsquery('english', ''' ' || 'qui' || ' ''')), 0))) AS pg_search_rank FROM "projects" WHERE (((to_tsvector('english', coalesce("projects"."title"::text, '')) || to_tsvector('english', coalesce("projects"."description"::text, ''))) @@ (to_tsquery('english', ''' ' || 'qui' || ' ''')))) ORDER BY pg_search_rank DESC, "projects"."id" ASC;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=12.09..12.10 rows=2 width=292) (actual time=0.242..0.242 rows=2 loops=1)
Sort Key: (ts_rank((to_tsvector('english'::regconfig, COALESCE((title)::text, ''::text))
CREATE INDEX
index_project_tsearch_title_description ON projects
USING gin((
to_tsvector('english'::regconfig, COALESCE((title)::text, ''::text)) ||
to_tsvector('english'::regconfig, COALESCE((description)::text, ''::text))
));
class Project < ActiveRecord::Base
include PgSearch
pg_search_scope :search_by_content,
against: [:title, :description],
using: { tsearch: { any_word: true, dictionary: "english" } }
end
SELECT
"projects".*,
((
ts_rank(
(
to_tsvector('english', coalesce("projects"."title"::text, '')) ||
to_tsvector('english', coalesce("projects"."description"::text, ''))
),
(
to_tsquery('english', ''' ' || 'qui' || ' ''')), 0)