Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

WIP - fixing centers and center_meeting_days once and for all

  • Loading branch information...
commit 03ea9d8ebf79b881978cc33f12d51e07bc0f766b 1 parent 05153ae
Siddharth Sharma authored
145 app/models/center.rb
View
@@ -2,14 +2,8 @@ class Center
include DataMapper::Resource
include DateParser
- attr_accessor :meeting_day_change_date
-
- before :save, :convert_blank_to_nil
- after :save, :handle_meeting_date_change
- before :save, :set_meeting_change_date
- before :create, :set_meeting_change_date
before :valid?, :convert_blank_to_nil
-
+ before :valid?, :handle_meeting_days
DAYS = [:none, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday]
@@ -19,7 +13,7 @@ class Center
property :address, Text, :lazy => true
property :contact_number, String, :length => 40, :lazy => true
property :landmark, String, :length => 100, :lazy => true
- property :meeting_day, Enum.send('[]', *DAYS), :nullable => false, :default => :none, :index => true
+ property :meeting_day, Enum.send('[]', *DAYS), :nullable => true, :default => :none, :index => true # DEPRECATED
property :meeting_time_hours, Integer, :length => 2, :index => true
property :meeting_time_minutes, Integer, :length => 2, :index => true
property :meeting_calendar, Text # this is a comma separated list of dates and takes precedence over everything else.
@@ -44,8 +38,6 @@ class Center
validates_with_method :meeting_time_hours, :method => :hours_valid?
validates_with_method :meeting_time_minutes, :method => :minutes_valid?
- # validates_with_method :creation_date_ok
-
def self.from_csv(row, headers)
hour, minute = row[headers[:center_meeting_time_in_24h_format]].split(":")
branch = Branch.first(:name => row[headers[:branch]].strip)
@@ -70,12 +62,23 @@ def self.meeting_days
DAYS
end
+ def get_meeting_dates(to = SEP_DATE,from = creation_date)
+ # DEPRECATED - Please use Center#meeting_dates. get_meeting_dates is non-idiomatic ruby
+ meeting_dates(to, from)
+ end
+
+
# get a list of meeting dates between from and to if to is a Date. Else gets "to" meeting dates if to is an integer
- #
# a center must take the responsibility that center_meeting_days never overlap.
- def get_meeting_dates(to = Date.new(2100,12,31),from = creation_date)
- # to can be a date or a number
- # first find the date_Vectors for all center_meeting_days as a hash {:valid_from => DateVector}
+ # to can be a date or a number
+ def meeting_dates(to = nil,from = nil)
+ debugger
+ # sometimes loans from another center might be moved to this center. they can be created before this centers creation date
+ # therefore, we refer to the loan history table first and if there are no rows there, we refer to the creation date for the 'from' date if none is specified
+ min_max_dates = LoanHistory.all(:center_id => self.id).aggregate(:date.min, :date.max)
+ from ||= (min_max_dates[0] || self.creation_date)
+ to ||= (min_max_dates[1] || SEP_DATE)
+ # first refer to the meeting_calendar
unless self.meeting_calendar.blank?
ds = self.meeting_calendar.split(/[\s,]/).reject(&:blank?).map{|d| Date.parse(d) rescue nil}.compact.select{|d| d >= from}.sort
if to
@@ -84,6 +87,8 @@ def get_meeting_dates(to = Date.new(2100,12,31),from = creation_date)
end
return ds
end
+
+ # then check the date vectors
select = to.class == Date ? {:valid_from.lte => to} : {}
dvs = center_meeting_days.all(select).map{|cmd| [cmd.valid_from, cmd.date_vector]}.to_hash
@@ -122,7 +127,7 @@ def self.catalog(user=nil)
result = {}
branch_names = {}
- if user.staff_member
+ if (user or Nothing).staff_member
staff_member = user.staff_member
[staff_member.centers.branches, staff_member.branches].flatten.each{|b| branch_names[b.id] = b.name }
centers = [staff_member.centers, staff_member.branches.centers].flatten
@@ -140,7 +145,8 @@ def self.catalog(user=nil)
end
-
+
+ # returns the meeting day for a given date
def meeting_day_for(date)
@meeting_days ||= self.center_meeting_days(:order => [:valid_from])
if @meeting_days.length==0
@@ -155,36 +161,26 @@ def meeting_day_for(date)
end
def next_meeting_date_from(date)
+ # first refer to the LoanHistory. Sometimes, some funky loans might be in here and we don't want to depend on center meeting dates in
+ # the first instance
r_date = (LoanHistory.first(:center_id => self.id, :date.gt => date, :order => [:date], :limit => 1) or Nothing).date
- unless r_date
- number = get_meeting_date(date, :next)
- if meeting_day != :none and (date + number - get_meeting_date(date + number, :previous)).cweek == (date + number).cweek
- r_date = (date + number + get_meeting_date(date + number, :next)).holiday_bump
- else
- r_date = (date + number).holiday_bump
- end
- end
- r_date
-
+ return r_date if r_date
+ #oops...no loans in this center. use center_meeting_dates
+ debugger
+ self.meeting_dates(1, date)[0]
end
def previous_meeting_date_from(date)
+ #likewise for this (see comment above)
r_date = (LoanHistory.first(:center_id => self.id, :date.lte => date, :order => [:date.desc], :limit => 1) or Nothing).date
- unless r_date
- number = get_meeting_date(date, :previous)
- if meeting_day != :none and (date - number - get_meeting_date(date - number, :previous)).cweek == (date - number).cweek
- r_date = (date - number - get_meeting_date(date - number, :previous)).holiday_bump
- else
- r_date = (date - number).holiday_bump
- end
- end
- r_date
-
+ return r_date if r_date
+ #oops...no loans in this center. use center_meeting_dates
+ self.meeting_dates(date)[-1]
end
def meeting_day?(date)
- LoanHistory.all(:date => date).aggregate(:center_id).include?(self.id)
+ Center.meeting_days.include?(date)
end
def meeting_time
@@ -192,6 +188,7 @@ def meeting_time
end
def self.paying_today(user, date = Date.today, branch_id = nil)
+ # returns a list of centers paying today
selection = {:date => date}.merge(branch_id ? {:branch_id => branch_id} : {})
center_ids = LoanHistory.all(selection).aggregate(:center_id)
centers = center_ids.blank? ? [] : Center.all(:id => center_ids)
@@ -219,6 +216,7 @@ def location
end
def self.meeting_today(date=Date.today, user=nil)
+ # this makes no sense
user = User.first
center_ids = LoanHistory.all(:date => date).aggregate(:center_id)
# restrict branch manager and center managers to their own branches
@@ -229,6 +227,9 @@ def self.meeting_today(date=Date.today, user=nil)
Center.all(:id => center_ids)
end
+
+ private
+
def hours_valid?
return true if (0..23).include? meeting_time_hours.to_i
[false, "Hours of the meeting time should be within 0-23"]
@@ -239,14 +240,9 @@ def minutes_valid?
end
def manager_is_an_active_staff_member?
return true if manager and manager.active
- [false, "Receiving staff member is currently not active"]
+ [false, "Cannot set #{self.manager.name} as center manager because this staff member is not currently not active"]
end
- def creation_date_ok
- return true if clients.map{|c| c.loans}.count == 0
- return true if creation_date <= loans.aggregate(:applied_on.min)
- return [false, "Creation date cannot be after the first loan application date"]
- end
def handle_meeting_date_change
# no need to do all this if meeting date was not changed
@@ -284,45 +280,40 @@ def handle_meeting_date_change
return true
end
- def set_meeting_change_date
- if self.new?
- self.meeting_day_change_date = self.creation_date
- else
- # Check if meeting date was changed.
- if self.dirty_attributes.map{|x| x.first.name}.include?(:meeting_day)
- if self.meeting_day_change_date.class==String and not self.meeting_day_change_date.blank?
- self.meeting_day_change_date = parse_date(self.meeting_day_change_date)
- else
- # if meeting_day was indeed changed and no meeting_change_date is foudn then set it as today's date
- self.meeting_day_change_date ||= Date.today
- end
- else
- # If meeting_day was not changed then set meeting_day_change_date as nil.
- self.meeting_day_change_date = nil
+ def handle_meeting_days
+ # this function creates the first center meeting day for the center when only a meeting day is specified.
+ # we will soon deprecate the meeting_day field and work only with center_meeting_days
+ if center_meeting_days.blank?
+ unless meeting_day == :none
+ cmd = CenterMeetingDay.new(:valid_from => nil, :valid_upto => nil, :center_id => self.id, :meeting_day => (meeting_day || :none))
+ self.center_meeting_days << cmd
end
end
- end
- def get_meeting_date(date, direction)
- number = 1
- if direction == :next
- nwday = (date + number).wday
- while (meet_day = Center.meeting_days.index(meeting_day_for(date + number)) and meet_day > 0 and nwday != meet_day)
- number += 1
- nwday = (date + number).wday
- nwday = 7 if nwday == 0
- end
- else
- nwday = (date - number).wday
- while (meet_day = Center.meeting_days.index(meeting_day_for(date - number)) and meet_day > 0 and nwday != meet_day)
- number += 1
- nwday = (date - number).wday
- nwday = 7 if nwday == 0
- end
- end
- return number
end
+ # def get_meeting_date(date, direction)
+ # DEPRECATED. Commenting out right now so that we can restore it if it is being referenced from somewhere
+ # TODO remove this from the codebase if nothing borks by 2012-02-28
+ # number = 1
+ # if direction == :next
+ # nwday = (date + number).wday
+ # while (meet_day = Center.meeting_days.index(meeting_day_for(date + number)) and meet_day > 0 and nwday != meet_day)
+ # number += 1
+ # nwday = (date + number).wday
+ # nwday = 7 if nwday == 0
+ # end
+ # else
+ # nwday = (date - number).wday
+ # while (meet_day = Center.meeting_days.index(meeting_day_for(date - number)) and meet_day > 0 and nwday != meet_day)
+ # number += 1
+ # nwday = (date - number).wday
+ # nwday = 7 if nwday == 0
+ # end
+ # end
+ # return number
+ # end
+
def convert_blank_to_nil
self.attributes.each{|k, v|
if v.is_a?(String) and v.empty? and self.class.properties.find{|x| x.name == k}.type==Integer
3  app/models/center_meeting_day.rb
View
@@ -98,8 +98,9 @@ def to_s
def valid_from_is_lesser_than_valid_upto
+ return true if self.valid_from.blank? and self.valid_upto.blank? # neither is set
self.valid_from = Date.parse(self.valid_from) unless self.valid_from.is_a? Date
- self.valid_upto = (self.valid_upto.blank? ? Date.new(2100,12,31) : Date.parse(self.valid_upto)) if self.valid_upto.class == String
+ self.valid_upto = (self.valid_upto.blank? ? SEP_DATE : Date.parse(self.valid_upto)) if self.valid_upto.class == String
if self.valid_from and self.valid_upto
return [false, "Valid from date cannot be before than valid upto date"] if self.valid_from > self.valid_upto
3  app/models/loan.rb
View
@@ -1248,10 +1248,7 @@ def calculate_history
actual_outstanding_principal = outstanding ? actual[:balance].round(2) : 0
actual_outstanding_total = outstanding ? actual[:total_balance].round(2) : 0
actual_outstanding_interest = outstanding ? (actual_outstanding_total - actual_outstanding_principal) : 0
-<<<<<<< HEAD
-=======
->>>>>>> e8b0fb3120ed49f25dac950f47aa21be9b15129f
_apo = [0,total_principal_paid.round(2) - total_principal_due.round(2)].max # advance principal outstanding at the start
_api = [0,total_interest_paid.round(2) - total_interest_due.round(2)].max
advance_principal_outstanding = outstanding ? _apo : 0
3  config/constants.rb
View
@@ -122,3 +122,6 @@
# in order to avoid overrunning the SQL max packet size, we split the cacher update into chunks
# 2500 should be good for the standard SQL max_packet_size of 16MB
CHUNK_SIZE = 2500
+
+
+SEP_DATE = Date.new(2100,12,31) # SEP = Someone Else's Problem http://en.wikipedia.org/wiki/Somebody_Else's_Problem i.e. a date so far in the future as to represent infinity
2  spec/factories.rb
View
@@ -582,7 +582,7 @@
name 'home'
title 'Home page'
route '/'
- type Types.first
+ type BookmarkTypes.first
share_with User::ROLES.first
association :user
274 spec/models/center_spec.rb
View
@@ -11,10 +11,12 @@
@branch = Factory(:branch, :manager => @manager)
@branch.should be_valid
+
end
before(:each) do
Center.all.destroy!
+ CenterMeetingDay.all.destroy!
@center = Center.new(:name => "Munnar hill center")
@center.manager = @manager
@center.branch = @branch
@@ -35,141 +37,143 @@
@center.should_not be_valid
end
- # The following specs are currently failing because the method that sets up center_meeting_days
- # is borked. This is documented in the Center model itself.
-# it "should have meeting_days" do
-# @center.center_meeting_days.length.should eql(1)
-# @center.should be_valid
-# end
-#
-# it "should have meeting date change should create a new center_meeting_day entry" do
-# @center.meeting_day = :tuesday
-# @center.save
-# @center.center_meeting_days.length.should eql(2)
-# @center.should be_valid
-# end
-#
-# it "meeting date change should happen on the date specified" do
-# @center.meeting_day_change_date = Date.new(2010, 10, 12)
-# @center.meeting_day = :tuesday
-# @center.save
-# @center = Center.get(@center.id)
-# @center.meeting_day_for(Date.new(2010, 10, 12)).should eql(:tuesday)
-# @center.meeting_day_for(Date.new(2010, 10, 11)).should eql(:monday)
-# @center.meeting_day_for(Date.new(2010, 10, 13)).should eql(:tuesday)
-# end
-#
-# it "meeting date change should happen on the date specified" do
-# @center.meeting_day_change_date = Date.new(2010, 10, 12)
-# @center.meeting_day = :tuesday
-# @center.save
-# @center = Center.get(@center.id)
-#
-# @center.next_meeting_date_from(Date.new(2010, 10, 12)).weekday.should eql(:tuesday)
-# @center.previous_meeting_date_from(Date.new(2010, 10, 11)).weekday.should eql(:monday)
-#
-# @center.next_meeting_date_from(Date.new(2010, 10, 13)).weekday.should eql(:tuesday)
-# @center.previous_meeting_date_from(Date.new(2010, 10, 13)).weekday.should eql(:monday)
-#
-# @center.next_meeting_date_from(Date.new(2010, 10, 11)).weekday.should eql(:tuesday)
-# @center.previous_meeting_date_from(Date.new(2010, 10, 11)).weekday.should eql(:monday)
-# end
-#
-# it "next and previous meeting dates should be correct" do
-# center = Center.create(:branch => @branch, :name => "center 75", :code => "c75", :creation_date => Date.new(2010, 03, 17),
-# :meeting_day => :wednesday, :manager => @manager)
-# center.should be_valid
-#
-# center.next_meeting_date_from(Date.new(2010, 6, 30)).should == Date.new(2010, 7, 7)
-# center.next_meeting_date_from(Date.new(2010, 7, 1)).should == Date.new(2010, 7, 7)
-# center.next_meeting_date_from(Date.new(2010, 7, 3)).should == Date.new(2010, 7, 7)
-# center.next_meeting_date_from(Date.new(2010, 7, 5)).should == Date.new(2010, 7, 7)
-# center.next_meeting_date_from(Date.new(2010, 7, 6)).should == Date.new(2010, 7, 7)
-#
-# center.meeting_day_change_date = Date.new(2010, 7, 8)
-# center.meeting_day = :tuesday
-# center.save
-# center = Center.get(center.id)
-#
-# center.previous_meeting_date_from(Date.new(2010, 7, 7)).should == Date.new(2010, 6, 30)
-# center.previous_meeting_date_from(Date.new(2010, 7, 12)).should == Date.new(2010, 7, 07)
-# center.previous_meeting_date_from(Date.new(2010, 7, 6)).should == Date.new(2010, 6, 30)
-# center.previous_meeting_date_from(Date.new(2010, 7, 1)).should == Date.new(2010, 6, 30)
-#
-# center.next_meeting_date_from(Date.new(2010, 7, 7)).should == Date.new(2010, 7, 13)
-# center.next_meeting_date_from(Date.new(2010, 7, 10)).should == Date.new(2010, 7, 13)
-# center.next_meeting_date_from(Date.new(2010, 7, 12)).should == Date.new(2010, 7, 13)
-#
-# center.next_meeting_date_from(Date.new(2010, 7, 10)).should == Date.new(2010, 7, 13)
-# center.next_meeting_date_from(Date.new(2010, 7, 11)).should == Date.new(2010, 7, 13)
-# center.next_meeting_date_from(Date.new(2010, 7, 12)).should == Date.new(2010, 7, 13)
-#
-# center.next_meeting_date_from(Date.new(2010, 7, 13)).should == Date.new(2010, 7, 20)
-# center.next_meeting_date_from(Date.new(2010, 7, 15)).should == Date.new(2010, 7, 20)
-# center.next_meeting_date_from(Date.new(2010, 7, 19)).should == Date.new(2010, 7, 20)
-#
-# center.previous_meeting_date_from(Date.new(2010, 7, 20)).should == Date.new(2010, 7, 13)
-# center.previous_meeting_date_from(Date.new(2010, 7, 19)).should == Date.new(2010, 7, 13)
-# center.previous_meeting_date_from(Date.new(2010, 7, 14)).should == Date.new(2010, 7, 13)
-#
-# center.previous_meeting_date_from(Date.new(2010, 7, 13)).should == Date.new(2010, 7, 7)
-# center.previous_meeting_date_from(Date.new(2010, 7, 12)).should == Date.new(2010, 7, 7)
-# center.previous_meeting_date_from(Date.new(2010, 7, 8)).should == Date.new(2010, 7, 7)
-#
-# center.meeting_day_change_date = Date.new(2010, 10, 17)
-# center.meeting_day = :friday
-# center.save
-#
-# center = Center.get(center.id)
-#
-# center.next_meeting_date_from(Date.new(2010, 10, 12)).should == Date.new(2010, 10, 22)
-# center.next_meeting_date_from(Date.new(2010, 10, 13)).should == Date.new(2010, 10, 22)
-# center.next_meeting_date_from(Date.new(2010, 10, 15)).should == Date.new(2010, 10, 22)
-# center.next_meeting_date_from(Date.new(2010, 10, 17)).should == Date.new(2010, 10, 22)
-# center.next_meeting_date_from(Date.new(2010, 10, 20)).should == Date.new(2010, 10, 22)
-# center.next_meeting_date_from(Date.new(2010, 10, 21)).should == Date.new(2010, 10, 22)
-#
-# center.previous_meeting_date_from(Date.new(2010, 10, 12)).should == Date.new(2010, 10, 5)
-# center.previous_meeting_date_from(Date.new(2010, 10, 22)).should == Date.new(2010, 10, 12)
-# center.next_meeting_date_from(Date.new(2010, 10, 22)).should == Date.new(2010, 10, 29)
-#
-#
-# center = Center.create(:branch => @branch, :name => "center 77", :code => "c77", :creation_date => Date.new(2010, 03, 15),
-# :meeting_day => :monday, :manager => @manager)
-# center.should be_valid
-#
-# center.next_meeting_date_from(Date.new(2010, 3, 15)).should == Date.new(2010, 3, 22)
-# center.next_meeting_date_from(Date.new(2010, 3, 22)).should == Date.new(2010, 3, 29)
-# center.previous_meeting_date_from(Date.new(2010, 3, 29)).should == Date.new(2010, 3, 22)
-# center.previous_meeting_date_from(Date.new(2010, 3, 22)).should == Date.new(2010, 3, 15)
-#
-# center.meeting_day_change_date = Date.new(2010, 7, 14)
-# center.meeting_day = :friday
-# center.save
-# center = Center.get(center.id)
-#
-# center.next_meeting_date_from(Date.new(2010, 7, 12)).should == Date.new(2010, 7, 23)
-# center.next_meeting_date_from(Date.new(2010, 7, 15)).should == Date.new(2010, 7, 23)
-# center.next_meeting_date_from(Date.new(2010, 7, 5)).should == Date.new(2010, 7, 12)
-#
-# center.previous_meeting_date_from(Date.new(2010, 7, 23)).should == Date.new(2010, 7, 12)
-# center.previous_meeting_date_from(Date.new(2010, 7, 20)).should == Date.new(2010, 7, 12)
-# center.previous_meeting_date_from(Date.new(2010, 7, 13)).should == Date.new(2010, 7, 12)
-# center.previous_meeting_date_from(Date.new(2010, 7, 14)).should == Date.new(2010, 7, 12)
-#
-# center.meeting_day_change_date = Date.new(2010, 8, 1)
-# center.meeting_day = :none
-# center.save
-#
-# center = Center.get(center.id)
-# center.next_meeting_date_from(Date.new(2010, 7, 2)).should == Date.new(2010, 7, 5)
-# center.next_meeting_date_from(Date.new(2010, 7, 1)).should == Date.new(2010, 7, 5)
-# center.next_meeting_date_from(Date.new(2010, 7, 21)).should == Date.new(2010, 7, 23)
-# center.next_meeting_date_from(Date.new(2010, 7, 31)).should == Date.new(2010, 8, 1)
-# center.next_meeting_date_from(Date.new(2010, 8, 1)).should == Date.new(2010, 8, 2)
-# center.previous_meeting_date_from(Date.new(2010, 8, 2)).should == Date.new(2010, 8, 1)
-# center.previous_meeting_date_from(Date.new(2010, 8, 10)).should == Date.new(2010, 8, 9)
-# end
+ it "should catalog correctly" do
+ @branch_1 = Factory(:branch, :name => "Branch 1", :manager => @manager)
+ @branch_2 = Factory(:branch, :name => "Branch 2", :manager => @manager)
+ @b1c1 = Factory(:center, :name => "b1c1", :branch => @branch_1)
+ @b1c2 = Factory(:center, :name => "b1c2", :branch => @branch_1)
+ @b2c1 = Factory(:center, :name => "b2c1", :branch => @branch_2)
+ @b2c2 = Factory(:center, :name => "b2c2", :branch => @branch_2)
+ Center.catalog.should == {"Hyderabad center 1"=>{3=>"Munnar hill center"}, "Branch 1"=>{5=>"b1c2", 4=>"b1c1"}, "Branch 2"=>{6=>"b2c1", 7=>"b2c2"}}
+ end
+
+
+ # testing of center meeting days.
+ # upon creation, a CenterMeetingDate is assigned to the center. It has blank valid_from and valid_upto fields.
+ # The default date vector returned for this center is from creation_date until SEP_DATE (someone else's problem date) field
+ # after this, center meeting days may be added and removed at will.
+
+
+ it "should have meeting_days" do
+ @center.center_meeting_days.length.should eql(1)
+ @center.center_meeting_days.first.meeting_day.should == :monday
+ end
+
+ it "should give correct meeting days in this instance" do
+ start_date = Date.new(2010,1,1)
+ start_date = start_date - start_date.cwday + 8
+ start_date.weekday.should == :monday
+ date = start_date
+ result = [date]
+ while date <= SEP_DATE
+ date += 7
+ result << date if date <= SEP_DATE
+ end
+ @center.meeting_dates.should == result
+ end
+
+
+ it "meeting date change should happen on the date specified" do
+ end
+
+ it "meeting date change should happen on the date specified" do
+ end
+
+ it "next and previous meeting dates should be correct" do
+ center = Center.create(:branch => @branch, :name => "center 75", :code => "c75", :creation_date => Date.new(2010, 03, 17),
+ :meeting_day => :wednesday, :manager => @manager)
+ center.should be_valid
+
+ center.next_meeting_date_from(Date.new(2010, 6, 30)).should == Date.new(2010, 7, 7)
+ center.next_meeting_date_from(Date.new(2010, 7, 1)).should == Date.new(2010, 7, 7)
+ center.next_meeting_date_from(Date.new(2010, 7, 3)).should == Date.new(2010, 7, 7)
+ center.next_meeting_date_from(Date.new(2010, 7, 5)).should == Date.new(2010, 7, 7)
+ center.next_meeting_date_from(Date.new(2010, 7, 6)).should == Date.new(2010, 7, 7)
+
+ center.meeting_day_change_date = Date.new(2010, 7, 8)
+ center.meeting_day = :tuesday
+ center.save
+ center = Center.get(center.id)
+
+ center.previous_meeting_date_from(Date.new(2010, 7, 7)).should == Date.new(2010, 6, 30)
+ center.previous_meeting_date_from(Date.new(2010, 7, 12)).should == Date.new(2010, 7, 07)
+ center.previous_meeting_date_from(Date.new(2010, 7, 6)).should == Date.new(2010, 6, 30)
+ center.previous_meeting_date_from(Date.new(2010, 7, 1)).should == Date.new(2010, 6, 30)
+
+ center.next_meeting_date_from(Date.new(2010, 7, 7)).should == Date.new(2010, 7, 13)
+ center.next_meeting_date_from(Date.new(2010, 7, 10)).should == Date.new(2010, 7, 13)
+ center.next_meeting_date_from(Date.new(2010, 7, 12)).should == Date.new(2010, 7, 13)
+
+ center.next_meeting_date_from(Date.new(2010, 7, 10)).should == Date.new(2010, 7, 13)
+ center.next_meeting_date_from(Date.new(2010, 7, 11)).should == Date.new(2010, 7, 13)
+ center.next_meeting_date_from(Date.new(2010, 7, 12)).should == Date.new(2010, 7, 13)
+
+ center.next_meeting_date_from(Date.new(2010, 7, 13)).should == Date.new(2010, 7, 20)
+ center.next_meeting_date_from(Date.new(2010, 7, 15)).should == Date.new(2010, 7, 20)
+ center.next_meeting_date_from(Date.new(2010, 7, 19)).should == Date.new(2010, 7, 20)
+
+ center.previous_meeting_date_from(Date.new(2010, 7, 20)).should == Date.new(2010, 7, 13)
+ center.previous_meeting_date_from(Date.new(2010, 7, 19)).should == Date.new(2010, 7, 13)
+ center.previous_meeting_date_from(Date.new(2010, 7, 14)).should == Date.new(2010, 7, 13)
+
+ center.previous_meeting_date_from(Date.new(2010, 7, 13)).should == Date.new(2010, 7, 7)
+ center.previous_meeting_date_from(Date.new(2010, 7, 12)).should == Date.new(2010, 7, 7)
+ center.previous_meeting_date_from(Date.new(2010, 7, 8)).should == Date.new(2010, 7, 7)
+
+ center.meeting_day_change_date = Date.new(2010, 10, 17)
+ center.meeting_day = :friday
+ center.save
+
+ center = Center.get(center.id)
+
+ center.next_meeting_date_from(Date.new(2010, 10, 12)).should == Date.new(2010, 10, 22)
+ center.next_meeting_date_from(Date.new(2010, 10, 13)).should == Date.new(2010, 10, 22)
+ center.next_meeting_date_from(Date.new(2010, 10, 15)).should == Date.new(2010, 10, 22)
+ center.next_meeting_date_from(Date.new(2010, 10, 17)).should == Date.new(2010, 10, 22)
+ center.next_meeting_date_from(Date.new(2010, 10, 20)).should == Date.new(2010, 10, 22)
+ center.next_meeting_date_from(Date.new(2010, 10, 21)).should == Date.new(2010, 10, 22)
+
+ center.previous_meeting_date_from(Date.new(2010, 10, 12)).should == Date.new(2010, 10, 5)
+ center.previous_meeting_date_from(Date.new(2010, 10, 22)).should == Date.new(2010, 10, 12)
+ center.next_meeting_date_from(Date.new(2010, 10, 22)).should == Date.new(2010, 10, 29)
+
+
+ center = Center.create(:branch => @branch, :name => "center 77", :code => "c77", :creation_date => Date.new(2010, 03, 15),
+ :meeting_day => :monday, :manager => @manager)
+ center.should be_valid
+
+ center.next_meeting_date_from(Date.new(2010, 3, 15)).should == Date.new(2010, 3, 22)
+ center.next_meeting_date_from(Date.new(2010, 3, 22)).should == Date.new(2010, 3, 29)
+ center.previous_meeting_date_from(Date.new(2010, 3, 29)).should == Date.new(2010, 3, 22)
+ center.previous_meeting_date_from(Date.new(2010, 3, 22)).should == Date.new(2010, 3, 15)
+
+ center.meeting_day_change_date = Date.new(2010, 7, 14)
+ center.meeting_day = :friday
+ center.save
+ center = Center.get(center.id)
+
+ center.next_meeting_date_from(Date.new(2010, 7, 12)).should == Date.new(2010, 7, 23)
+ center.next_meeting_date_from(Date.new(2010, 7, 15)).should == Date.new(2010, 7, 23)
+ center.next_meeting_date_from(Date.new(2010, 7, 5)).should == Date.new(2010, 7, 12)
+
+ center.previous_meeting_date_from(Date.new(2010, 7, 23)).should == Date.new(2010, 7, 12)
+ center.previous_meeting_date_from(Date.new(2010, 7, 20)).should == Date.new(2010, 7, 12)
+ center.previous_meeting_date_from(Date.new(2010, 7, 13)).should == Date.new(2010, 7, 12)
+ center.previous_meeting_date_from(Date.new(2010, 7, 14)).should == Date.new(2010, 7, 12)
+
+ center.meeting_day_change_date = Date.new(2010, 8, 1)
+ center.meeting_day = :none
+ center.save
+
+ center = Center.get(center.id)
+ center.next_meeting_date_from(Date.new(2010, 7, 2)).should == Date.new(2010, 7, 5)
+ center.next_meeting_date_from(Date.new(2010, 7, 1)).should == Date.new(2010, 7, 5)
+ center.next_meeting_date_from(Date.new(2010, 7, 21)).should == Date.new(2010, 7, 23)
+ center.next_meeting_date_from(Date.new(2010, 7, 31)).should == Date.new(2010, 8, 1)
+ center.next_meeting_date_from(Date.new(2010, 8, 1)).should == Date.new(2010, 8, 2)
+ center.previous_meeting_date_from(Date.new(2010, 8, 2)).should == Date.new(2010, 8, 1)
+ center.previous_meeting_date_from(Date.new(2010, 8, 10)).should == Date.new(2010, 8, 9)
+ end
it "should not be valid with a name shorter than 3 characters" do
@center.name = "ok"
14 spec/spec_failing_examples.txt
View
@@ -1,13 +1 @@
-Loan .status should give status accoring to changing properties up to it written off
-Loan .status should give status accoring to changing properties up to it is repaid
-Loan .payments_hash should give correct results
-Loan history should be correct
-Loan should write the history correctly into the db
-Loan should not be deleteable if verified
-Loan .installment_dates should correctly deal with holidays
-Loan should have correct takeover schedule and balances
-Loan should change with center meeting date change
-Loan should change with center meeting date change
-Loan should not be valid if duplicated
-Loan should repay properly
-Loan should not disburse if loan fees are not paid
+Center next and previous meeting dates should be correct
Please sign in to comment.
Something went wrong with that request. Please try again.