Skip to content

Instantly share code, notes, and snippets.

View szymon-przybyl's full-sized avatar

Szymon Przybył szymon-przybyl

View GitHub Profile
@szymon-przybyl
szymon-przybyl / gist:1078859
Created July 12, 2011 20:10
UsersConroller#create spec
describe 'POST create' do
context 'with valid params' do
before(:each) { User.any_instance.stub!(:valid?).and_return(true) }
it 'creates new user and redirects to the home page with a notice' do
post :create, :user => Factory.attributes_for(:user, :username => 'dude')
assigns[:user].should be_persisted
assigns[:user].username.should eq('dude')
flash[:notice].should_not be_nil
response.should redirect_to(root_url)
end
class Order < ActiveRecord::Base
belongs_to :product
belongs_to :user
validates_presence_of :user, :product, :product_quantity
validates_numericality_of :product_quantity,
:only_integer => true, :greater_than => 0, :less_than_or_equal_to => 10000, :allow_blank => true
validate :enough_product_quantity,
# if does not work
specify 'with product_quantity greater than associated product quantity' do
Factory(:order,
:product => Factory(:product, :quantity => 10),
:product_quantity => 11
).should have(1).error_on(:product_quantity)
end
class Game
include Mongoid::Document
def self.my_method
puts "test"
end
end
class Deer < Game
my_method