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 Game do | |
let!(:player1) { FactoryGirl.create(:user) } | |
let!(:player2) { FactoryGirl.create(:user) } | |
let(:started_game) { FactoryGirl.build(:game).tap { |g| g.users << player1 ; g.users << player2 ; g.start! }} | |
it { should have_many :moves } | |
it { should have_and_belong_to_many :users} |
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
it "should not be valid if scheduled disbursal date and scheduled first payment date are not center meeting dates" do | |
@loan.scheduled_disbursal_date = @center.meeting_day | |
@loan.should be_valid | |
@loan.scheduled_first_payment_date = @center.meeting_day | |
@loan.should be_valid | |
@loan.scheduled_disbursal_date = @center.meeting_day + 1 | |
@loan.should_not be_valid | |
@loan.scheduled_disbursal_date = @center.meeting_day - 1 | |
@loan.should_not be_valid | |
@loan.scheduled_first_payment_date = @center.meeting_day + 1 |
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
def scheduled_dates_must_be_center_meeting_days #this function is only for repayment dates | |
return [false, "Not client defined"] unless client | |
center = client.center | |
failed = [] | |
correct_weekday = nil | |
["scheduled_first_payment_date"].each do |d| | |
# if the loan disbursal date is set and it is not being set right now, no need to check as the loan has been already disbursed | |
# hence we need not check it again | |
if self.disbursal_date and not self.dirty_attributes.keys.find{|da| da.name == :disbursal_date} | |
return true |
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 "scheduled first payment date must be a center meeting date" do | |
let(:center) { FactoryGirl.create(:center) } | |
subject { FactoryGirl.build(:loan, | |
:center => center, | |
:scheduled_first_payment_date => Date.new(2012,2,2) } | |
before { center.stub(:center_meeting_dates).and_return([Date.new(2012,2,1)]) | |
it { should_not be_valid } |
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
# POST /games/1/join_game {:id => <game_id>, :user_id => <player_id> } | |
def join_game | |
@game = Game.find(params[:id]) | |
@game.players << User.find(:user_id) | |
... | |
end | |
# POST /games/1/leave_game {:id => <game_id>, :user_id => <player_id> } | |
def leave_game | |
@game = Game.find(params[:id]) |
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
# routes.rb | |
... | |
resources :games do | |
resources :players | |
resources :moves | |
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
# POST {:id => <article_id>, :action => :update, :set_state => :published, :article => {:title => "foo"}} | |
def update | |
@article = Article.find(params[:id]) | |
@article.update!(params) # we call a method in Article which deals with our params | |
... | |
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
# things controller | |
def update | |
@thing = Thing.find(params[:id]) | |
@thing.update_attributes(params[:thing]) | |
... | |
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
# let the argument errors come from the typecast. | |
# one should not worry about the class of the object, just its capabilities. | |
def initialize(hash = {}) | |
@name = hash[:name].to_s | |
@price = hash[:price].to_f | |
@quantity = Integer(hash[:quantity] || 1) | |
@list = List.new(hash[:list]) | |
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 QuotationsIndexParams | |
include Virtus | |
include DataMapper::Validations | |
attribute :scope, String, :default => 'pending' | |
attribute :sort, String, :default => 'poolability' | |
attribute :quotation, Hash, :default => {} | |
attribute :date, Date | |
validates_within :scope, :set => [nil,'all','pending','to_call','to_pool', 'cabbed'] | |