Commit 5a23925b authored by Alexandre Friquet's avatar Alexandre Friquet
Browse files

Beginning rewrite: refs #86.

parent f348b749
......@@ -24,13 +24,13 @@ class Season
FIRST_MONTH = 8
FIRST_DAY = 15
attr_reader :begining
attr_reader :beginning
attr_reader :end
def initialize(date)
year = (date < Season.birthdate.change(year: date.year) ? date.year-1 : date.year)
@begining = Season.birthdate.change(year: year)
@end = @begining + 1.year - 1.day
@beginning = Season.birthdate.change(year: year)
@end = @beginning + 1.year - 1.day
return self
end
......@@ -77,12 +77,12 @@ class Season
end
def shorten
shorten_year = @begining.year.% 100
shorten_year = @beginning.year.% 100
"#{shorten_year}#{shorten_year+1}"
end
def short_label
"#{@begining.year}-#{@begining.year+1}"
"#{@beginning.year}-#{@beginning.year+1}"
end
def label
......
......@@ -34,7 +34,7 @@ class Subscription < ApplicationRecord
scope :by_adherent_name, -> { joins(:adherent).order('adherents.first_name','adherents.last_name') }
scope :billed, -> { where.not(billed_at: nil) }
scope :of_medicosocial_org, ->(member) { joins(:adherent).where(adherents: {medico_social_org: member}) }
scope :for_season, ->(season) { where(created_at: (season.begining..season.end) )}
scope :for_season, ->(season) { where(created_at: (season.beginning..season.end) )}
def self.with_multiactivities_pass
all.reject { |sub| !sub.multipass? }
......
......@@ -26,20 +26,20 @@ RSpec.describe Season, type: :model do
context "regarding initialization" do
context "when season birthdate not provided" do
context "sets the begining ot the season to" do
context "sets the beginning ot the season to" do
scenario "15/08/2017 when date 19/09/2017 is given" do
season = Season.new(Date.new(2017,9,19))
expect(season.begining).to eq Date.new(2017,8,15)
expect(season.beginning).to eq Date.new(2017,8,15)
expect(season.end).to eq Date.new(2018,8,14)
end
scenario "15/08/2017 when date 15/08/2017 is given" do
season = Season.new(Date.new(2017,8,15))
expect(season.begining).to eq Date.new(2017,8,15)
expect(season.beginning).to eq Date.new(2017,8,15)
expect(season.end).to eq Date.new(2018,8,14)
end
scenario "15/08/2016 when date 14/08/2017 is given" do
season = Season.new(Date.new(2017,8,14))
expect(season.begining).to eq Date.new(2016,8,15)
expect(season.beginning).to eq Date.new(2016,8,15)
expect(season.end).to eq Date.new(2017,8,14)
end
end
......@@ -49,20 +49,20 @@ RSpec.describe Season, type: :model do
before { @settings.update_attribute(:season_birthdate, Date.new(1970,9,1)) }
context "sets the begining ot the season to" do
context "sets the beginning ot the season to" do
scenario "01/09/2017 when date 19/09/2017 is given" do
season = Season.new(Date.new(2017,9,19))
expect(season.begining).to eq Date.new(2017,9,1)
expect(season.beginning).to eq Date.new(2017,9,1)
expect(season.end).to eq Date.new(2018,8,31)
end
scenario "01/09/2017 when date 01/09/2017 is given" do
season = Season.new(Date.new(2017,9,1))
expect(season.begining).to eq Date.new(2017,9,1)
expect(season.beginning).to eq Date.new(2017,9,1)
expect(season.end).to eq Date.new(2018,8,31)
end
scenario "01/09/2016 when date 31/08/2017 is given" do
season = Season.new(Date.new(2017,8,31))
expect(season.begining).to eq Date.new(2016,9,1)
expect(season.beginning).to eq Date.new(2016,9,1)
expect(season.end).to eq Date.new(2017,8,31)
end
end
......@@ -182,7 +182,7 @@ RSpec.describe Season, type: :model do
result = Season.from_short_label(short_label)
# Then
expect(result).to be_a Season
expect(result.begining).to eq Date.new(2017,9,1)
expect(result.beginning).to eq Date.new(2017,9,1)
expect(result.end).to eq Date.new(2018,8,31)
end
end
......
......@@ -86,7 +86,7 @@ RSpec.describe Subscription, type: :model do
expect(Subscription.of_medicosocial_org(medicosocial_org)).to eq [sub1]
end
it ".for_season returns subscription between begining and end of a season" do
it ".for_season returns subscription between beginning and end of a season" do
# Given
season = Season.new(Date.new(2017,9,1))
sub1 = create :subscription, created_at: DateTime.new(2017,1,1,10,10,0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment