Skip to content

Instantly share code, notes, and snippets.

Ogredude ogredude

Block or report user

Report or block ogredude

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View seeds.rb
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => cities.first)
Size.create(:name => "Fine", :attack => 8, :special_attack => -16, :hide => 16, :height => "6 in. or less", :weight => "1/8 lb. or less", :tall_reach => "0 ft.", :long_reach => "0 ft.")
Size.create(:name => "Diminutve", :attack => 4, :special_attack => -12, :hide => 12, :height => "6 in.–1 ft.", :weight => "1/8 lb.–1 lb.", :tall_reach => "0 ft.", :long_reach => "0 ft.")
Size.create(:name => "Tiny", :attack => 2, :special_attack => -8, :hide => 8, :height => "1 ft.–2 ft.", :weight => "1 lb.–8 lb.", :tall_reach => "0 ft.", :long_reach => "0 ft.")
View address_spec.rb
require 'spec_helper'
describe Address do
[:street, :city, :zip].each do |attr|
it "must have a #{attr}" do
address = Factory.build(:address, attr.to_sym => nil)
address.should_not be_valid
address.errors[attr].should_not be_empty
View .autotest
module Autotest::Growl
def self.growl title, msg, img, pri=0, stick=""
system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{stick}"
end
Autotest.add_hook :ran_command do |autotest|
filtered = autotest.results.grep(/\d+\s.*examples?/)
output = filtered.empty? ? '' : filtered.last.slice(/(\d+)\s.*examples?,\s(\d+)\s.*failures?(?:,\s(\d+)\s.*pending)?/)
if output =~ /[1-9]\sfailures?/
growl "Test Results", "#{output}", '~/Library/autotest/rails_fail.png', 2
elsif output =~ /pending/
View Output from autotest -v when department.rb changes
[["app/models/department.rb", Wed Jun 29 13:10:07 -0600 2011]]
No tests matched app/models/dealership.rb
[["app/models/department.rb", Wed Jun 29 13:10:07 -0600 2011]]
No tests matched app/models/department.rb
View .autotest
module Autotest::Growl
def self.growl title, msg, img, pri=0, stick=""
system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{stick}"
end
Autotest.add_hook :ran_command do |autotest|
filtered = autotest.results.grep(/\d+\s.*examples?/)
output = filtered.empty? ? '' : filtered.last.slice(/(\d+)\s.*examples?,\s(\d+)\s.*failures?(?:,\s(\d+)\s.*pending)?/)
if output =~ /[1-9]\sfailures?/
growl "Test Results", "#{output}", '~/Library/autotest/rails_fail.png', 2
elsif output =~ /pending/
View Spec results
Failures:
1) Item
Failure/Error: it {should have_many(:orders).through(:line_items)}
Expected Item to have a has_many association called orders (Item does not have any relationship to line_items)
# ./spec/models/item_spec.rb:4
View order.rb
class Order < ActiveRecord::Base
belongs_to :person
has_and_belongs_to_many :items
validate :requires_at_least_one_item
def requires_at_least_one_item
errors.add(:items, "requires at least one Item") if items.empty?
end
end
View Description
An Order belongs to a Customer using the Person model.
An Order has and belongs to many Items.
Given a Person, I want to find all the items they bought.
The problem: How do I write a test for the last sentence in this spec?
View wants_controller_spec.rb
describe "PUT want" do
it "should add selected items to want list" do
item = Factory(:item)
expect {
put :want, :item_ids => [item.id]
}.to change(Want, :count).by(1)
response.should redirect_to(auction_house_auction_path(item.auction.auction_house.id, item.auction.id))
end
end
@ogredude
ogredude / do_not_want.rb
Created Jul 7, 2011
Is there a better way to do this?
View do_not_want.rb
# The goal is to end up with a list of items in the store that the user did NOT check. Items the user checked are in the params[:item_ids] array.
# There's got to be a better way... But how?
store.items.each do |i|
does_not_want << i.item_id unless params[:item_ids].include?(i.item_id)
end
You can’t perform that action at this time.