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 /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
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
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
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
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
before :all do | |
@loan_product = LoanProduct.new | |
@loan_product.name = "LP1" | |
@loan_product.max_amount = 1000 | |
@loan_product.min_amount = 1000 | |
@loan_product.max_interest_rate = 100 | |
@loan_product.min_interest_rate = 0.1 | |
@loan_product.installment_frequency = :weekly | |
@loan_product.max_number_of_installments = 25 | |
@loan_product.min_number_of_installments = 25 |
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 is_valid_loan_product(method) | |
loan_attr = self.send(method) | |
return [false, "No #{method} specified"] if not loan_attr or loan_attr==="" | |
return [false, "No loan product chosen"] unless self.loan_product | |
product = self.loan_product | |
#Checking if the loan adheres to minimum and maximums of the loan product | |
{:min => :minimum, :max => :maximum}.each{|k, v| | |
product_attr = product.send("#{k}_#{method}") | |
if method==:interest_rate | |
product_attr = product_attr.to_f/100.round(6) |
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
ReceiptsController | |
unauthenticated user | |
should not be able to access index page | |
POST create | |
does not create a new Receipt | |
customer user | |
GET index | |
assigns all users documents as @documents | |
searches properly |
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
ItemsController | |
unauthorised | |
does not edit | |
does not new | |
does not index | |
does not show | |
does not update | |
authorised | |
index |