Skip to content

Instantly share code, notes, and snippets.

@knwang
knwang / user_views_candidates.feature
Created October 5, 2011 00:36
Proofing_oven: User views candidates feature show page
@http://www.pivotaltracker.com/story/show/18733537 @candidates
Feature: User views candidates
In order to hire amazing people
As a signed in user
I want to see a list of candidates
- Candidates page displays all candidates
- Sorted by last name, first name
- Fields displayed include:
-- Name (last, first)
@knwang
knwang / candidates_controller.rb
Created October 5, 2011 02:56
Proofing_oven: Candidates Controller with sorting
class CandidatesController < ApplicationController
expose(:candidates) { Candidate.order(:first_name) }
end
@knwang
knwang / user_searches_candidates_by_name.feature
Created October 7, 2011 21:25
Proofing_oven: User searches candidates by name feature
@http://www.pivotaltracker.com/story/show/16870693 @candidates @filtering
Feature: User searches for candidate by name
In order to locate a candidate
As a user viewing candidates
I want search by name
- Candidates page displays text field for search
- Submitting form filters on first and last name
Background:
@knwang
knwang / index.html.haml
Created October 7, 2011 21:38
Proofing_oven: Candidates list view with search box
.search
= form_tag search_candidates_path, method: :post do
%fieldset
= text_field_tag :search, params[:search]
= submit_tag "Search"
%table.standard
%thead
%tr
- ["Name", "Phone", "Email", "Github", "Twitter", "Local", "Willing to Relocate"].each do |th|
@knwang
knwang / routes.rb
Created October 7, 2011 21:42
Proofing_oven: routes with search
ProofingOven::Application.routes.draw do
match 'ui(/:action)', controller: 'ui'
root to: 'ui#index'
resources :candidates, only: [:index] do
collection do
post :search
end
end
@knwang
knwang / candidate_spec.rb
Created October 8, 2011 18:38
Proofing_oven: Candidate Spec with search
require 'spec_helper'
describe Candidate do
subject { Fabricate(:candidate, first_name: "Joe", last_name: "Doe") }
describe "#full_name" do
its(:full_name) { should == "Joe Doe" }
end
describe "#search" do
@knwang
knwang / AddFullNameColumnToCandidates.rb
Created October 8, 2011 18:55
Proofing_oven: add full_name column migration
class AddFullNameColumnToCandidates < ActiveRecord::Migration
def self.up
add_column :candidates, :full_name, :string
end
def self.down
remove_column :candidates, :full_name
end
end
@knwang
knwang / candidate.rb
Created October 8, 2011 19:02
Proofing_oven: candidate model with search
class Candidate < ActiveRecord::Base
before_save :denormalize_name
def self.search(term)
term.blank? ? Candidate.all : where("full_name like ?", "%#{term}%")
end
private
@knwang
knwang / candidates_controller.rb
Created October 8, 2011 20:13
Proofing_oven: candidate controller with search
class CandidatesController < ApplicationController
expose(:candidates) { Candidate.order(:first_name) }
expose(:search_term) { params[:search] }
expose(:search_results) { Candidate.search(search_term) if search_term }
def search
render :index
end
end
@knwang
knwang / candidate.rb
Created October 8, 2011 20:34
Proofing_oven: Candidate Model refactored
class Candidate < ActiveRecord::Base
scope :search, ->(term) { term.blank? ? {} : where("full_name like ?", "%#{term}%") }
before_save :denormalize_name
private
def denormalize_name
self.full_name = [first_name, last_name].join(' ')