Skip to content

Instantly share code, notes, and snippets.

@melvinram
Created January 30, 2012 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melvinram/1703830 to your computer and use it in GitHub Desktop.
Save melvinram/1703830 to your computer and use it in GitHub Desktop.
FactoryGirl.define do
factory :order do
email 'some@email.com'
delivery_fee 6.99
amount 206.99
paid 0
comments 'This is some comment to order'
discount_client 5
association :delivery
association :payment
association :shop
association :user
end
end
class Order < ActiveRecord::Base
belongs_to :shop
belongs_to :user
belongs_to :delivery
belongs_to :payment
has_many :order_items
validates :shop_id, :presence => true,
:numericality => { :only_integer => true }
validates :user_id, :presence => true,
:numericality => { :only_integer => true }
validates :deleted_at, :timeliness => { :after => :created_at, :allow_blank => true }
validates :delivery_fee, :presence => true,
:format => { :with => /^[\d]{1,10}(\.\d{1,2})?$/},
:numericality => { :greater_than_or_equal_to => 0, :only_integer => false }
validates :delivery_id, :presence => true,
:numericality => { :only_integer => true }
validates :discount_value, :allow_nil => true,
:format => { :with => /^[\d]{1,10}(\.\d{1,2})?$/},
:numericality => { :greater_than_or_equal_to => 0, :only_integer => false }
validates :discount_percent, :allow_nil => true,
:numericality => { :greater_than_or_equal_to => 0, :less_than_or_equal_to => 100, :only_integer => false, }
validates :discount_client, :allow_nil => true,
:numericality => { :greater_than_or_equal_to => 0, :less_than_or_equal_to => 100, :only_integer => false }
validates :discount_name, :allow_blank => true,
:length => { :minimum => 3, :maximum => 255 }
validates :payment_id, :presence => true,
:numericality => { :only_integer => true }
validates :paid, :allow_nil => true,
:format => { :with => /^[\d]{1,10}(\.\d{1,2})?$/},
:numericality => { :greater_than_or_equal_to => 0, :only_integer => false }
validates :email, :presence => true,
:email => true
end
describe Order do
subject { build :order }
it { should be_valid }
describe '.undeleted' do
it 'should return all order that have deleted_at set to nil' do
create :order
build(:order).errors.should == ""
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment