-
-
Save radar/749140 to your computer and use it in GitHub Desktop.
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 Bid do | |
| before(:each) do | |
| @user = Factory(:user) | |
| @user.funds = 10 | |
| @user.save() | |
| @prediction = Factory(:prediction) | |
| @attr= { | |
| :user_id => @user.id, | |
| :prediction_id => @prediction.id, | |
| :txn => 10, | |
| :bet => true | |
| } | |
| end | |
| it "should create a new instance given valid attributes" do | |
| @user.bids.create(@attr) | |
| @user.save() | |
| @user.bids.size.should == 1 | |
| @user.funds.should == 0 | |
| end | |
| it "should not create a new instance if funds is below txn" do | |
| @user.funds = 9 | |
| @user.save() | |
| @user.bids.create(@attr) | |
| @user.save() | |
| @user.bids.size.should == 0 | |
| @user.funds.should == 1 | |
| end | |
| it "should not create a new instance if prediction id is empty" do | |
| @user.bids.create(@attr.merge(:prediction_id => nil)) | |
| @user.save() | |
| @user.bids.size.should == 0 | |
| 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
| class Bid < ActiveRecord::Base | |
| belongs_to :user | |
| validate :check_fund | |
| validates_presence_of :prediction_id | |
| def check_fund | |
| errors.add(:user, "'s funds is insufficent") unless user.funds >= self.txn | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment