Created
January 30, 2012 10:49
-
-
Save melvinram/1703830 to your computer and use it in GitHub Desktop.
This file contains 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
FactoryGirl.define do | |
factory :order do | |
email '[email protected]' | |
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 |
This file contains 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 :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 |
This file contains 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 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