Skip to content

Instantly share code, notes, and snippets.

# undefined method `should_respond_with' for #<UserSessionsController>
require 'test_helper'
class UserSessionsControllerTest < ActionController::TestCase
should_have_before_filter :require_no_user, :only => [:new, :create]
should_have_before_filter :require_user, :only => :destroy
# Controller
def index
@results = SexOffender.all
end
# View
<% if @results.blank? %>
<span>no sex offenders were found</span>
class Order < AR:Base
has_one :credit_card_payment
has_one :paypal_express_payment
has_one :horse_shoe_payment
validates_presence_of :payment_type, :in => [:credit_card_express, :paypal_express, :horse_shoe]
def payment_proxy
@eladmeidar
eladmeidar / gist:171394
Created August 20, 2009 21:21
self referencial HABTM hell
validates_presence_of :number, :description
validates_uniqueness_of :number
has_and_belongs_to_many :alternates, :class_name => 'PartNumber',
:join_table => 'alternate_part_numbers',
:foreign_key => 'part_number_id',
:association_foreign_key => 'alternate_part_number_id'
has_and_belongs_to_many :alternate_for, :class_name => 'PartNumber',
:join_table => 'alternate_part_numbers',
:foreign_key => 'alternate_part_number_id',
require 'test_helper'
class PartNumberTest < ActiveSupport::TestCase
should_have_and_belong_to_many :alternates
should_have_and_belong_to_many :alternate_for
should_validate_presence_of :number
should_validate_presence_of :description
should_validate_uniqueness_of :number
OAuth::Consumer.class_eval do
def get_request_token(request_options = {}, *arguments)
response = token_request(http_method, (request_token_url? ?
request_token_url : request_token_path), nil, request_options,
*arguments)
OAuth::RequestToken.from_hash(self, response)
end
end
## on part.rb
# i use pn as a virtual attribute.
def pn=(part_number)
@part_number = PartNumber.find_by_number(part_number)
logger.info "NEW PART NUMBER "
if @part_number.blank?
#self.part_number_id = PartNumber.create(:number => part_number, :description => 'none').id
self.build_part_number(:number => part_number, :description => 'no description')
## controller
Company.search({:warehouses_parts_quantity_greater_than => 0}).all
## error
ActiveRecord::ConfigurationError: Association named 'condition' was not found; perhaps you misspelled it?
## Models
Company has many warehouses,
Warehouse has many parts
## source
<table class="table">
<thead>
<tr>
<th>Part Number</th>
<th style="width:70px;">Quantity</th>
<th>Condition</th>
<th style="width:70px;">Price</th>
<th></th>
@eladmeidar
eladmeidar / RCov output
Created August 30, 2009 06:09
Rcov shows 25.0% coverage for UsersController, well.. i am pretty sure i covered all the actions thu... it happens on *some* other functional tests too.
|app/controllers/users_controller.rb | 42 | 36 | 25.0% |