Skip to content

Instantly share code, notes, and snippets.

View aakashd's full-sized avatar

aakash dharmadhikari aakashd

View GitHub Profile
@aakashd
aakashd / gist:2899980
Created June 9, 2012 07:30
output of stub_spec.rb
A method stub
ignores when expected message is received with no args
allows a stub and an expectation
instructs an instance to respond_to the message
calculates return value by executing block passed to #and_return
handles multiple stubbed methods
ignores when expected message is not received
instructs a class object to respond_to the message
overrides a pre-existing method
keeps returning last value in consecutive calls
#with rspec
payment.should be_cancelled
#bad example
assert_equal 4, payment.code
#good example
assert_equal Payment::Status::CANCELLED, payment.code
@aakashd
aakashd / my ideal test
Created May 17, 2012 11:43
An ideals test structure
context "context of a small business scenario"
should "exact business requirement" do
<on doing this>
<this happens>
end
end
@aakashd
aakashd / application_controller_spec.rb
Created April 11, 2012 11:39
Specs for application controller
require 'spec_helper'
class DummyApplicationController < ApplicationController
before_filter :require_authentication, :only => :authenticated_resource
before_filter :check_if_self, :only => :dummy_method_to_test_check_for_self
def get_action
render :nothing => true
end
def authenticated_resource
@aakashd
aakashd / app_auth_headers.rb
Created July 22, 2011 18:42
Custom auth header for ActiveResource requests
class AppAuthHeaders
cattr_accessor :remember_token
def self.headers
remember_token.blank? ? {"Authorization" => ""} : {"Authorization" => "RememberToken #{self.remember_token}"}
end
end
class BuildPostProcessor
def notify_on_failure(&block)
on_failure_notifier = BuildNotification.new
@build_statuses[:failure] << [block, on_failure_notifier]
end
def on_success_build_artifacts(artifacts_builder)
@build_statuses[:success] << artifacts_builder.new
yield(artifacts_builder.new)
end
<p>
<%= address_form.label :street_1 %><br />
<%= address_form.text_field :street_1 %>
</p>
<p>
<%= address_form.label :street_2 %><br />
<%= address_form.text_field :street_2 %>
</p>
<p>
<%= address_form.label :landmark %><br />
class Address < ActiveRecord::Base
belongs_to :listing
belongs_to :neighbourhood
belongs_to :creator, :class_name => User, :foreign_key => 'creator_id'
belongs_to :updater, :class_name => User, :foreign_key => 'updater_id'
end
# == Schema Information
#
partial included in listing form
<p>
<% form.fields_for :address do |address_form| %>
<%= render :partial => '/addresses/address_form', :object => address_form %>
<% end %>
</p>
neighbourhood select in address form