Skip to content

Instantly share code, notes, and snippets.

View skamithi's full-sized avatar

Stanley Karunditu skamithi

  • Raleigh, North Carolina
View GitHub Profile
@skamithi
skamithi / gist:98507
Created April 20, 2009 12:13
how to override a function in rails
How to override a function in rails from Yuhuda Katz. I'm new to ruby and this always confuses me. nice to have a good example from a guru.
class Foo < ActiveRecord::Base
include FooBar
end
module FooBar
def self.included(base)
base.extend(ClassMethods)
end
@skamithi
skamithi / rails.sh
Created April 23, 2012 00:24
Sample Rails init startup script on ubuntu
### /etc/default/rails ###
APP_USER=vagrant
RVM_SETTING="1.9.3-p125@rails32"
RAILSDIR=/home/vagrant/rails
# Example: STAGES=("vagrant_staging", "vagrant_production")
STAGES=("vagrant_staging")
# Example APPS=("myapp1" "myapp2")
APPS=("myapp")
@skamithi
skamithi / application_controller.rb
Created April 25, 2012 14:53
Adding Opensearch to my Rails 3.2 app
#app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
def opensearch
response.headers['Content-Type'] = 'application/opensearchdescription+xml; charset=utf-8'
end
@skamithi
skamithi / .vimrc
Last active October 4, 2015 05:27
my rails related vimrc
runtime bundle/pathogen/autoload/pathogen.vim
call pathogen#infect()
call pathogen#helptags()
syntax on
filetype plugin indent on
set number
set tabstop=2
set shiftwidth=2
set expandtab
set textwidth=80
@skamithi
skamithi / mock_geo.rb
Created May 20, 2012 03:16
mocking geocode in my rails3 project
## /spec/support/mock_geo.rb
## MockGeo takes an address in the following format and can produce
## fake google geocode output
## All country and state information resolves to North Carolina, USA
## Include "gem jbuilder in :test and :development group" if not already in the project.
## Example
## Output for address string *MUST* be in this format
## a = '102 My Street, My Town, , NC, 99903' OR
# a = '102 my street, my town, nc'
## b = MockGeo.new(:addr => a)
@skamithi
skamithi / search_field_steps.rb
Created January 1, 2013 18:21
Cucumber steps to check if search field is cleared but is still focused after the clear.
When /^I click the clear search button$/ do
find('#search_icon').click
end
Then /^the search field should be focused$/ do
page.execute_script <<-JS
if (jQuery('#search_form input[type=search]').is(':focus')) {
jQuery('#search_form').append("<div id='search_form_is_focused' />");
}
JS
@skamithi
skamithi / .gitignore
Last active December 17, 2015 15:19
Setting up Chef-Solo
*/.gitkeep
tmp/
@skamithi
skamithi / login_helper_cucumber.rb
Last active February 25, 2017 01:27
bypassing sorcery authentication for rspec feature and cucumber tests for my external authentication setup.
# feature/support/login_helper.rb
require 'spec/support/login_helper'
Before do
extend LoginHelper
@user = FactoryGirl.create(:user)
login_as @user
end
@skamithi
skamithi / capybara.rb
Created June 4, 2013 12:14
Capybara 2.0 / Rspec. Ability to launch browser when testing view specs. Not integration test..just regular view specs
#spec/support/capybara.rb
require 'capybara/rspec'
# Using chrome as browser to test in capybara.
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
@skamithi
skamithi / capybara-element-not-visible-spec.rb
Last active December 18, 2015 12:59
capybara 2.0 test for element not visible for either cucumber or rspec feature tests.
context 'my element' do
before do
a =<< EOF
jQuery ->
$('body').append('<div id=empty_or_hidden_element></div>')
EOF
page.execute_script CoffeeScript.compile(a)
end
it 'should not be displayed' do