Skip to content

Instantly share code, notes, and snippets.

View jasdeepsingh's full-sized avatar
🏠
Working from home

jasdeep singh jasdeepsingh

🏠
Working from home
View GitHub Profile
@jasdeepsingh
jasdeepsingh / user.rb
Created November 3, 2011 00:07
User Model
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :lockable, :timeoutable, :confirmable and :activatable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :token_authenticatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation
# Self defined attributes.
@jasdeepsingh
jasdeepsingh / contacts_controller.rb
Created November 3, 2011 00:11
Contacts Controller
class ContactsController < ApplicationController
before_filter :check_unauthorized , :only => [:make_friend_request, :confirm_friend_request, :change_contact_type]
before_filter :decode_data , :only => [:make_friend_request, :confirm_friend_request, :change_contact_type]
before_filter :check_expired_friend_requests , :only => [:get_contacts]
def confirm_friend_request
response = FriendRequest.confirm_friend_request(@data["user_key"], session[:user_key], @data["status"], session[:authorization_type], @data["encrypt_key"])
render :json => response
end
@jasdeepsingh
jasdeepsingh / version_ordering.rb
Created November 30, 2011 05:11
Version Ordering Problem
#!/usr/bin/env ruby
# ================================
# = Author: Jasdeep Singh Narang =
# = Date: 29th November 2011 =
# = Problem: Version Ordering =
# ================================
def sort(version_list)
version_list.sort!{|first,second| parse_version(first) <=> parse_version(second) }
@jasdeepsingh
jasdeepsingh / Gemfile
Created December 18, 2011 17:38
Setting up Rails TDD Environment with Rspec
# In console:
# Ignores the setting up of Test::Unit by default
$ rails new app_name -T
# In Gemfile add the following gems:
group :test, :development do
gem 'turn'
gem 'rspec-rails'
gem 'capybara'
gem 'guard-rspec'
@jasdeepsingh
jasdeepsingh / Prawn.rb
Created January 13, 2012 21:40
Prawn: undefined method fetch for # [Model Object] <Bus#x89df798f>
## A message like this is a clear indication of the fact that super in your PDF rendering class needs you use brackets as follows:
class ListingPDF < Prawn::Document
def initialize(bus, view)
super # should be super()
@listing = bus
@view = view
end
Surround these with : e.g. :calling:
+1
-1
bulb
calling
clap
cop
email
feet
@jasdeepsingh
jasdeepsingh / coffee.bash
Created April 10, 2012 15:17
Coffee Watch
# -o = Output Directory
# -c = Compile
# Off course, you'll need Node on your machine to do this.
coffee -w -o public/javascripts/ -c app/assets/coffeescripts/
@jasdeepsingh
jasdeepsingh / database.yml
Created October 13, 2012 02:03
database.yml
# Development Database Postgres
development:
adapter: postgresql
encoding: utf8
database: couponous_development
host: localhost
username: postgres
password: pxd123
# Warning: The database defined as "test" will be erased and

Intro

Problem: I learned how to run RSpec to test classes and modules in my gem. But, if I wanted to test my gem as if it were already included in a Rails app, I couldn't find much info about it online.

I usually do unit tests with RSpec, and I test the whole stack with Cucumber. So here we will just setup Cucumber to run the Rails app that you embed in your gem.

Before we begin:

  • This tutorial is for people who already know how to make gems, and who have used RSpec and Cucumber before in a Rails app.
  • MyGem and my_gem below refer to the name of the gem we are creating. Replace this with your own name.
@jasdeepsingh
jasdeepsingh / automate.rb
Created May 9, 2013 21:39
Scripting for Benefit
#!/usr/bin/ruby
require 'rubygems'
require 'net/http'
require 'uri'
require 'nokogiri'
require 'mail'
url = ###/tracktest.php
refnum = # my application reference number.