This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[["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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
OlderNewer