merch_calendar 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe MerchCalendar::MerchWeek do
4
+ let!(:fiscal_calendar_options) { { calendar: MerchCalendar::StitchFixFiscalYearCalendar.new } }
4
5
 
5
6
  describe ".find" do
6
7
  it "returns an array of weeks" do
7
8
  weeks = described_class.find(2014,1)
8
9
  expect(weeks).to be_an Array
9
10
  expect(weeks.size).to eq 4
11
+ expect(weeks[0].calendar.class).to eq MerchCalendar::RetailCalendar
10
12
  end
11
13
 
12
14
  it "with year, month, week" do
@@ -16,6 +18,25 @@ describe MerchCalendar::MerchWeek do
16
18
  expect(mw.merch_month).to eq 12
17
19
  expect(mw.week).to eq 1
18
20
  end
21
+ context "using the Fiscal Calendar instead of the Retail Calendar" do
22
+ it "returns an array of weeks" do
23
+ weeks = described_class.find(2019, 7, nil, fiscal_calendar_options)
24
+ expect(weeks).to be_an Array
25
+ expect(weeks.size).to eq 5
26
+ expect(weeks[0].calendar.class).to eq MerchCalendar::StitchFixFiscalYearCalendar
27
+ end
28
+
29
+ it "with year, month, week" do
30
+ mw = described_class.find(2019, 7, 5, fiscal_calendar_options)
31
+ expect(mw.year).to eq 2019
32
+ expect(mw.month).to eq 7
33
+ expect(mw.merch_month).to eq 12
34
+ expect(mw.week).to eq 5
35
+ expect(mw.end_of_week).to eq Date.new(2019,8,3)
36
+ expect(mw.start_of_week).to eq Date.new(2019,7,28)
37
+ expect(mw.calendar.class).to eq MerchCalendar::StitchFixFiscalYearCalendar
38
+ end
39
+ end
19
40
  end
20
41
 
21
42
  describe ".from_date" do
@@ -23,9 +44,10 @@ describe MerchCalendar::MerchWeek do
23
44
  context "parameters" do
24
45
  context "allows valid date types" do
25
46
  it "allows a date string" do
26
- mw = described_class.from_date("1990-10-01")
27
- expect(mw.date.to_s).to eq "1990-10-01"
47
+ mw = described_class.from_date("2018-10-01")
48
+ expect(mw.date.to_s).to eq "2018-10-01"
28
49
  expect(mw.date.month).to eq 10
50
+ expect(mw.merch_month).to eq 8
29
51
  end
30
52
  end
31
53
 
@@ -40,6 +62,17 @@ describe MerchCalendar::MerchWeek do
40
62
  it { expect{described_class.from_date("2015")}.to raise_error(ArgumentError) }
41
63
  it { expect{described_class.from_date("2015-04")}.to raise_error(ArgumentError) }
42
64
  end
65
+
66
+ context "wants to know a date in a Fiscal Calendar" do
67
+ it "allows calendar to be passed and translate date to what it looks like in a FY year" do
68
+ mw = described_class.from_date("2019-08-04", fiscal_calendar_options)
69
+ expect(mw.date.to_s).to eq "2019-08-04"
70
+ expect(mw.date.month).to eq 8
71
+ expect(mw.merch_month).to eq 1
72
+ expect(mw.year).to eq 2020
73
+ expect(mw.calendar.class).to eq MerchCalendar::StitchFixFiscalYearCalendar
74
+ end
75
+ end
43
76
  end
44
77
  end
45
78
 
@@ -47,65 +80,111 @@ describe MerchCalendar::MerchWeek do
47
80
  it "returns a merch week based on today's date" do
48
81
  mw = described_class.today
49
82
  expect(mw.date.to_s).to eq Date.today.to_s
83
+ expect(mw.calendar.class).to eq MerchCalendar::RetailCalendar
84
+ end
85
+
86
+ context "passing in the Fiscal Calendar into options" do
87
+ it "returns a merch week based on today's date" do
88
+ mw = described_class.today(fiscal_calendar_options)
89
+ expect(mw.date.to_s).to eq Date.today.to_s
90
+ expect(mw.calendar.class).to eq MerchCalendar::StitchFixFiscalYearCalendar
91
+ end
50
92
  end
51
93
  end
52
94
 
53
95
  describe "#to_s" do
54
96
  let(:merch_week) { described_class.from_date("2014-01-01") }
97
+ let(:fiscal_week) { described_class.from_date("2019-08-01", fiscal_calendar_options) }
55
98
 
56
99
  it ":short / default format" do
57
100
  expect(merch_week.to_s(:short)).to eq "Dec W5"
58
101
  expect(merch_week.to_s).to eq "Dec W5"
59
102
  expect("#{merch_week}").to eq "Dec W5"
103
+
104
+ expect(fiscal_week.to_s(:short)).to eq "Jul W5"
105
+ expect(fiscal_week.to_s).to eq "Jul W5"
60
106
  end
61
107
 
62
108
  it ":long format" do
63
109
  expect(merch_week.to_s(:long)).to eq "2013:48 Dec W5"
110
+ expect(fiscal_week.to_s(:long)).to eq "2019:53 Jul W5"
64
111
  end
65
112
 
66
113
  it ":elasticsearch format" do
67
114
  expect(merch_week.to_s(:elasticsearch)).to eq "2013-12w05"
115
+ expect(fiscal_week.to_s(:elasticsearch)).to eq "2019-07w05"
68
116
  end
69
117
  end
70
118
 
71
- it "#end_of_week" do
72
- mw = described_class.find(2014,1,1)
119
+ describe "#end_of_week" do
120
+ it "returns the end of the week based on the Retail Calendar" do
121
+ mw = described_class.find(2014,1,1)
122
+ expect(mw.end_of_week).to eq (mw.start_of_week + 6)
123
+ end
73
124
 
74
- expect(mw.end_of_week).to eq (mw.start_of_week + 6)
125
+ it "returns the end of the week based on the Retail Calendar" do
126
+ mw = described_class.find(2019,1,1, fiscal_calendar_options)
127
+ expect(mw.end_of_week).to eq (mw.start_of_week + 6)
128
+ end
75
129
  end
76
130
 
77
-
78
131
  describe "#end_of_month" do
79
- it "for a 4 week month" do
80
- mw = described_class.find(2014, 2, 1)
81
- expect(mw.end_of_month - mw.start_of_month + 1).to eq (4*7)
82
- end
132
+ context "using the Retail Calendar" do
133
+ it "for a 4 week month" do
134
+ mw = described_class.find(2017, 2, 1)
135
+ expect(mw.end_of_month - mw.start_of_month + 1).to eq (4*7)
136
+ end
137
+
138
+ it "for a 5 week month" do
139
+ mw = described_class.find(2017, 3, 1)
140
+ expect(mw.end_of_month - mw.start_of_month + 1).to eq (5*7)
141
+ end
83
142
 
84
- it "for a 5 week month" do
85
- mw = described_class.find(2014, 3, 1)
86
- expect(mw.end_of_month - mw.start_of_month + 1).to eq (5*7)
143
+ it "for a 4-5-5 quarter" do
144
+ mw = described_class.find(2017, 11, 1)
145
+ expect(mw.end_of_month - mw.start_of_month + 1).to eq (4*7)
146
+
147
+ mw = described_class.find(2017, 12, 1)
148
+ expect(mw.end_of_month - mw.start_of_month + 1).to eq (5*7)
149
+
150
+ mw = described_class.find(2017, 1, 1)
151
+ expect(mw.end_of_month - mw.start_of_month + 1).to eq (5*7)
152
+ end
87
153
  end
154
+
155
+ context "using the Stitch Fix Fiscal Calendar" do
156
+ it "for a 4 week month" do
157
+ mw = described_class.find(2017, 2, 1, fiscal_calendar_options)
158
+ expect(mw.end_of_month - mw.start_of_month + 1).to eq (4*7)
159
+ end
160
+
161
+ it "for a 5 week month" do
162
+ mw = described_class.find(2017, 3, 1, fiscal_calendar_options)
163
+ expect(mw.end_of_month - mw.start_of_month + 1).to eq (5*7)
164
+ end
88
165
 
89
- it "for a 4 to 5 week month in a leap year" do
90
- mw = described_class.find(2011, 1, 1)
91
- expect(mw.end_of_month - mw.start_of_month + 1).to eq (4*7)
166
+ it "for a 4-5-5 quarter" do
167
+ mw = described_class.find(2019, 5, 1, fiscal_calendar_options)
168
+ expect(mw.end_of_month - mw.start_of_month + 1).to eq (4*7)
92
169
 
93
- mw = described_class.find(2012, 1, 1)
94
- expect(mw.end_of_month - mw.start_of_month + 1).to eq (5*7)
170
+ mw = described_class.find(2019, 6, 1, fiscal_calendar_options)
171
+ expect(mw.end_of_month - mw.start_of_month + 1).to eq (5*7)
172
+
173
+ mw = described_class.find(2019, 7, 1, fiscal_calendar_options)
174
+ expect(mw.end_of_month - mw.start_of_month + 1).to eq (5*7)
175
+ end
95
176
  end
96
177
  end
97
178
 
98
179
  describe "#season" do
99
- context "Fall/Winter" do
180
+ context "when it comes from the Retail calendar" do
100
181
  it { expect(described_class.from_date("2011-08-06").season).to eq "Fall/Winter" }
101
182
  it { expect(described_class.from_date("2011-09-06").season).to eq "Fall/Winter" }
102
183
  it { expect(described_class.from_date("2011-10-06").season).to eq "Fall/Winter" }
103
184
  it { expect(described_class.from_date("2011-11-06").season).to eq "Fall/Winter" }
104
185
  it { expect(described_class.from_date("2011-12-06").season).to eq "Fall/Winter" }
105
186
  it { expect(described_class.from_date("2012-01-06").season).to eq "Fall/Winter" }
106
- end
107
-
108
- context "Spring/Summer" do
187
+
109
188
  it { expect(described_class.from_date("2011-02-06").season).to eq "Spring/Summer" }
110
189
  it { expect(described_class.from_date("2011-03-06").season).to eq "Spring/Summer" }
111
190
  it { expect(described_class.from_date("2011-04-06").season).to eq "Spring/Summer" }
@@ -113,63 +192,136 @@ describe MerchCalendar::MerchWeek do
113
192
  it { expect(described_class.from_date("2011-06-06").season).to eq "Spring/Summer" }
114
193
  it { expect(described_class.from_date("2011-07-06").season).to eq "Spring/Summer" }
115
194
  end
195
+
196
+ context "when it comes from the Stitch Fix Fiscal Calendar" do
197
+ it { expect(described_class.from_date("2012-08-06", fiscal_calendar_options).season).to eq "Fall/Winter" }
198
+ it { expect(described_class.from_date("2012-09-06", fiscal_calendar_options).season).to eq "Fall/Winter" }
199
+ it { expect(described_class.from_date("2012-10-06", fiscal_calendar_options).season).to eq "Fall/Winter" }
200
+ it { expect(described_class.from_date("2012-11-06", fiscal_calendar_options).season).to eq "Fall/Winter" }
201
+ it { expect(described_class.from_date("2012-12-06", fiscal_calendar_options).season).to eq "Fall/Winter" }
202
+ it { expect(described_class.from_date("2012-01-06", fiscal_calendar_options).season).to eq "Fall/Winter" }
203
+
204
+ it { expect(described_class.from_date("2011-02-06", fiscal_calendar_options).season).to eq "Spring/Summer" }
205
+ it { expect(described_class.from_date("2011-03-06", fiscal_calendar_options).season).to eq "Spring/Summer" }
206
+ it { expect(described_class.from_date("2011-04-06", fiscal_calendar_options).season).to eq "Spring/Summer" }
207
+ it { expect(described_class.from_date("2011-05-06", fiscal_calendar_options).season).to eq "Spring/Summer" }
208
+ it { expect(described_class.from_date("2011-06-06", fiscal_calendar_options).season).to eq "Spring/Summer" }
209
+ it { expect(described_class.from_date("2011-07-06", fiscal_calendar_options).season).to eq "Spring/Summer" }
210
+ end
116
211
  end
117
212
 
118
213
 
119
- context "logic" do
214
+ describe "logic for Retail Calendar" do
120
215
  [
121
- OpenStruct.new(date: "2011-05-01", year: 2011, month: 5, week: 1, quarter: 4, year_week: 14, start_date: "2011-01-30"),
216
+ OpenStruct.new(date: "2011-05-01", year: 2011, month: 5, week: 1, quarter: 2, year_week: 14, start_date: "2011-01-30"),
122
217
 
123
- OpenStruct.new(date: "2014-08-31", year: 2014, month: 9, week: 1, quarter: 1, year_week: 31, start_date: "2014-02-02"),
124
- OpenStruct.new(date: "2017-12-30", year: 2017, month: 12, week: 5, quarter: 2, year_week: 48, start_date: "2017-01-29"),
125
- OpenStruct.new(date: "2014-01-01", year: 2013, month: 12, week: 5, quarter: 2, year_week: 48, start_date: "2013-02-03"),
126
- OpenStruct.new(date: "2014-01-04", year: 2013, month: 12, week: 5, quarter: 2, year_week: 48, start_date: "2013-02-03"),
127
- OpenStruct.new(date: "2014-01-05", year: 2013, month: 1, week: 1, quarter: 2, year_week: 49, start_date: "2013-02-03"),
128
- OpenStruct.new(date: "2014-01-12", year: 2013, month: 1, week: 2, quarter: 2, year_week: 50, start_date: "2013-02-03"),
129
- OpenStruct.new(date: "2014-01-19", year: 2013, month: 1, week: 3, quarter: 2, year_week: 51, start_date: "2013-02-03"),
130
- OpenStruct.new(date: "2014-01-26", year: 2013, month: 1, week: 4, quarter: 2, year_week: 52, start_date: "2013-02-03"),
218
+ OpenStruct.new(date: "2014-08-31", year: 2014, month: 9, week: 1, quarter: 3, year_week: 31, start_date: "2014-02-02"),
219
+ OpenStruct.new(date: "2014-01-01", year: 2013, month: 12, week: 5, quarter: 4, year_week: 48, start_date: "2013-02-03"),
220
+ OpenStruct.new(date: "2014-01-04", year: 2013, month: 12, week: 5, quarter: 4, year_week: 48, start_date: "2013-02-03"),
221
+ OpenStruct.new(date: "2014-01-05", year: 2013, month: 1, week: 1, quarter: 4, year_week: 49, start_date: "2013-02-03"),
222
+ OpenStruct.new(date: "2014-01-12", year: 2013, month: 1, week: 2, quarter: 4, year_week: 50, start_date: "2013-02-03"),
223
+ OpenStruct.new(date: "2014-01-19", year: 2013, month: 1, week: 3, quarter: 4, year_week: 51, start_date: "2013-02-03"),
224
+ OpenStruct.new(date: "2014-01-26", year: 2013, month: 1, week: 4, quarter: 4, year_week: 52, start_date: "2013-02-03"),
131
225
 
132
226
  # 2013
133
- OpenStruct.new(date: "2013-02-03", year: 2013, month: 2, week: 1, quarter: 3, year_week: 1, start_date: "2013-02-03"),
227
+ OpenStruct.new(date: "2013-02-03", year: 2013, month: 2, week: 1, quarter: 1, year_week: 1, start_date: "2013-02-03"),
228
+
229
+ #2014
230
+ OpenStruct.new(date: "2014-02-02", year: 2014, month: 2, week: 1, quarter: 1, year_week: 1, start_date: "2014-02-02"),
231
+ OpenStruct.new(date: "2014-02-01", year: 2013, month: 1, week: 4, quarter: 4, year_week: 52, start_date: "2013-02-03"),
232
+ OpenStruct.new(date: "2015-01-31", year: 2014, month: 1, week: 4, quarter: 4, year_week: 52, start_date: "2014-02-02"),
233
+
234
+ #2015
235
+ OpenStruct.new(date: "2015-02-01", year: 2015, month: 2, week: 1, quarter: 1, year_week: 1, start_date: "2015-02-01"),
236
+
237
+ #2017
238
+ OpenStruct.new(date: "2017-12-30", year: 2017, month: 12, week: 5, quarter: 4, year_week: 48, start_date: "2017-01-29")
239
+ ].each do |date_check|
240
+
241
+ context "using date '#{date_check.date}'" do
242
+ let(:merch_week) { described_class.from_date(date_check.date) }
134
243
 
135
- # 2014
136
- OpenStruct.new(date: "2014-02-02", year: 2014, month: 2, week: 1, quarter: 3, year_week: 1, start_date: "2014-02-02"),
137
- OpenStruct.new(date: "2015-01-31", year: 2014, month: 1, week: 4, quarter: 2, year_week: 52, start_date: "2014-02-02"),
244
+ describe "#year_week" do
245
+ it { expect(merch_week.year_week).to eq date_check.year_week }
246
+ end
138
247
 
139
- OpenStruct.new(date: "2014-02-01", year: 2013, month: 1, week: 4, quarter: 2, year_week: 52, start_date: "2013-02-03"),
248
+ describe "#month" do
249
+ it { expect(merch_week.month).to eq date_check.month }
250
+ end
140
251
 
141
- OpenStruct.new(date: "2015-02-01", year: 2015, month: 2, week: 1, quarter: 3, year_week: 1, start_date: "2015-02-01"),
252
+ describe "#quarter" do
253
+ it { expect(merch_week.quarter).to eq date_check.quarter }
254
+ end
142
255
 
256
+ describe "#week" do
257
+ it { expect(merch_week.week).to eq date_check.week }
258
+ end
259
+
260
+ describe "#start_of_year" do
261
+ it { expect(merch_week.start_of_year.to_s).to eq date_check.start_date }
262
+ end
263
+
264
+ describe "#year" do
265
+ it { expect(merch_week.year).to eq date_check.year }
266
+ end
267
+ end
268
+ end
269
+ end
270
+
271
+ describe "logic for Stitch Fix Fiscal Calendar" do
272
+ [
273
+ #2018
274
+ OpenStruct.new(date: "2018-07-26", year: 2018, month: 7, week: 4, quarter: 4, year_week: 52, start_date: "2017-07-30"),
275
+
276
+ #2019
277
+ OpenStruct.new(date: "2018-07-31", year: 2019, month: 8, week: 1, quarter: 1, year_week: 1, start_date: "2018-07-29"),
278
+ OpenStruct.new(date: "2019-02-01", year: 2019, month: 2, week: 1, quarter: 3, year_week: 27, start_date: "2018-07-29"),
279
+ OpenStruct.new(date: "2019-08-02", year: 2019, month: 7, week: 5, quarter: 4, year_week: 53, start_date: "2018-07-29"),
280
+
281
+ # 2020
282
+ OpenStruct.new(date: "2019-08-08", year: 2020, month: 8, week: 1, quarter: 1, year_week: 1, start_date: "2019-08-04"),
283
+ OpenStruct.new(date: "2020-05-05", year: 2020, month: 5, week: 1, quarter: 4, year_week: 40, start_date: "2019-08-04"),
284
+ OpenStruct.new(date: "2020-08-01", year: 2020, month: 7, week: 4, quarter: 4, year_week: 52, start_date: "2019-08-04"),
285
+
286
+ #2023
287
+ OpenStruct.new(date: "2022-07-31", year: 2023, month: 8, week: 1, quarter: 1, year_week: 1, start_date: "2022-07-31"),
288
+ OpenStruct.new(date: "2023-04-22", year: 2023, month: 4, week: 3, quarter: 3, year_week: 38, start_date: "2022-07-31"),
289
+ OpenStruct.new(date: "2023-07-25", year: 2023, month: 7, week: 4, quarter: 4, year_week: 52, start_date: "2022-07-31"),
290
+
291
+ #2024
292
+ OpenStruct.new(date: "2023-08-01", year: 2024, month: 8, week: 1, quarter: 1, year_week: 1, start_date: "2023-07-30"),
293
+ OpenStruct.new(date: "2023-11-08", year: 2024, month: 11, week: 2, quarter: 2, year_week: 15, start_date: "2023-07-30"),
294
+ OpenStruct.new(date: "2024-07-29", year: 2024, month: 7, week: 5, quarter: 4, year_week: 53, start_date: "2023-07-30"),
295
+
143
296
  ].each do |date_check|
144
297
 
145
298
  context "using date '#{date_check.date}'" do
146
- let(:merch_week) { described_class.from_date(date_check.date) }
299
+ let(:merch_week) { described_class.from_date(date_check.date, fiscal_calendar_options) }
147
300
 
148
- it "#year_week" do
149
- expect(merch_week.year_week).to eq date_check.year_week
301
+ describe "#year_week" do
302
+ it { expect(merch_week.year_week).to eq date_check.year_week }
150
303
  end
151
304
 
152
- it "#month" do
153
- expect(merch_week.month).to eq date_check.month
305
+ describe "#month" do
306
+ it { expect(merch_week.month).to eq date_check.month }
154
307
  end
155
308
 
156
- it "#quarter" do
157
- expect(merch_week.quarter).to eq date_check.quarter
309
+ describe "#quarter" do
310
+ it { expect(merch_week.quarter).to eq date_check.quarter }
158
311
  end
159
312
 
160
- it "#week" do
161
- expect(merch_week.week).to eq date_check.week
313
+ describe "#week" do
314
+ it { expect(merch_week.week).to eq date_check.week }
162
315
  end
163
316
 
164
- it "#start_of_year" do
165
- expect(merch_week.start_of_year.to_s).to eq date_check.start_date
317
+ describe "#start_of_year" do
318
+ it { expect(merch_week.start_of_year.to_s).to eq date_check.start_date }
166
319
  end
167
320
 
168
- it "#year" do
169
- expect(merch_week.year).to eq date_check.year
321
+ describe "#year" do
322
+ it { expect(merch_week.year).to eq date_check.year }
170
323
  end
171
324
  end
172
325
  end
173
326
  end
174
-
175
327
  end
@@ -5,11 +5,14 @@ RSpec.describe MerchCalendar::RetailCalendar do
5
5
  it "returns 53 for a leap year" do
6
6
  expect(subject.weeks_in_year(2012)).to eq 53
7
7
  expect(subject.weeks_in_year(2017)).to eq 53
8
+ expect(subject.weeks_in_year(2023)).to eq 53
8
9
  end
9
10
 
10
11
  it "returns 52 for a normal year" do
11
12
  expect(subject.weeks_in_year(2013)).to eq 52
12
13
  expect(subject.weeks_in_year(2018)).to eq 52
14
+ expect(subject.weeks_in_year(2019)).to eq 52
15
+ expect(subject.weeks_in_year(2020)).to eq 52
13
16
  end
14
17
  end
15
18
 
@@ -42,6 +45,13 @@ RSpec.describe MerchCalendar::RetailCalendar do
42
45
  it "returns the correct date" do
43
46
  expect(subject.start_of_quarter(2017, 1)).to eq Date.new(2017, 1, 29)
44
47
  expect(subject.start_of_quarter(2018, 1)).to eq Date.new(2018, 2, 4)
48
+ expect(subject.start_of_quarter(2019, 2)).to eq Date.new(2019, 5, 5)
49
+ expect(subject.start_of_quarter(2019, 3)).to eq Date.new(2019, 8, 4)
50
+ expect(subject.start_of_quarter(2019, 4)).to eq Date.new(2019, 11, 3)
51
+ end
52
+
53
+ it "raises an error when there is an invalid quarter" do
54
+ expect { subject.start_of_quarter(2019, 5) }.to raise_error "invalid quarter"
45
55
  end
46
56
  end
47
57
 
@@ -49,6 +59,50 @@ RSpec.describe MerchCalendar::RetailCalendar do
49
59
  it "returns the correct date" do
50
60
  expect(subject.end_of_quarter(2017, 1)).to eq Date.new(2017, 4, 29)
51
61
  expect(subject.end_of_quarter(2018, 1)).to eq Date.new(2018, 5, 5)
62
+ expect(subject.end_of_quarter(2019, 2)).to eq Date.new(2019, 8, 3)
63
+ expect(subject.end_of_quarter(2019, 3)).to eq Date.new(2019, 11, 2)
64
+ expect(subject.end_of_quarter(2019, 4)).to eq Date.new(2020, 2, 1)
65
+ end
66
+
67
+ it "raises an error when there is an invalid quarter" do
68
+ expect { subject.end_of_quarter(2019, 5) }.to raise_error "invalid quarter"
69
+ end
70
+ end
71
+
72
+ describe "#quarter" do
73
+ it "returns the correct quarter number" do
74
+ expect(subject.quarter(5)).to eq 2
75
+ expect(subject.quarter(7)).to eq 3
76
+ expect(subject.quarter(2)).to eq 1
77
+ expect(subject.quarter(11)).to eq 4
78
+ end
79
+
80
+ it "raises an error when there is an invalid merch month" do
81
+ expect { subject.quarter(13) }.to raise_error "invalid merch month"
82
+ end
83
+ end
84
+
85
+ describe "#season" do
86
+ context "for merch_months in the Spring and Summer Season" do
87
+ it { expect(subject.season(1)).to eq "Spring/Summer" }
88
+ it { expect(subject.season(2)).to eq "Spring/Summer" }
89
+ it { expect(subject.season(3)).to eq "Spring/Summer" }
90
+ it { expect(subject.season(4)).to eq "Spring/Summer" }
91
+ it { expect(subject.season(5)).to eq "Spring/Summer" }
92
+ it { expect(subject.season(6)).to eq "Spring/Summer" }
93
+ end
94
+
95
+ context "for merch_months in the Fall and Winter Season" do
96
+ it { expect(subject.season(7)).to eq "Fall/Winter" }
97
+ it { expect(subject.season(8)).to eq "Fall/Winter" }
98
+ it { expect(subject.season(9)).to eq "Fall/Winter" }
99
+ it { expect(subject.season(10)).to eq "Fall/Winter" }
100
+ it { expect(subject.season(11)).to eq "Fall/Winter" }
101
+ it { expect(subject.season(12)).to eq "Fall/Winter" }
102
+ end
103
+
104
+ it "raises an error when there is an invalid merch month" do
105
+ expect { subject.season(13) }.to raise_error "invalid merch month"
52
106
  end
53
107
  end
54
108
 
@@ -84,6 +138,7 @@ RSpec.describe MerchCalendar::RetailCalendar do
84
138
  start_merch_date = MerchCalendar.start_of_month(start_date.year, merch_month: start_date.month)
85
139
 
86
140
  merch_months = subject.merch_months_in(start_date, end_date)
141
+
87
142
  expect(merch_months.count).to be(1)
88
143
  expect(merch_months.first.year).to eq start_merch_date.year
89
144
  expect(merch_months.first.month).to eq start_merch_date.month
@@ -96,7 +151,6 @@ RSpec.describe MerchCalendar::RetailCalendar do
96
151
 
97
152
  merch_months = subject.merch_months_in(start_date, end_date)
98
153
  expect(merch_months.count).to be 11
99
-
100
154
  merch_months.each do |merch_month|
101
155
  expect(merch_month.year).to be 2014
102
156
  end
@@ -114,6 +168,91 @@ RSpec.describe MerchCalendar::RetailCalendar do
114
168
  expect(merch_months[10].strftime('%Y-%m-%d')).to eq '2014-11-30'
115
169
  end
116
170
  end
171
+
172
+ describe "#merch_year_from_date" do
173
+ it "returns the correct merch calendar year" do
174
+ expect(subject.merch_year_from_date(Date.new(2012, 1, 28))).to eq 2011
175
+ expect(subject.merch_year_from_date(Date.new(2012, 1, 29))).to eq 2012
176
+ expect(subject.merch_year_from_date(Date.new(2018, 1, 24))).to eq 2017
177
+ expect(subject.merch_year_from_date(Date.new(2018, 2, 3))).to eq 2017
178
+ expect(subject.merch_year_from_date(Date.new(2018, 2, 4))).to eq 2018
179
+ expect(subject.merch_year_from_date(Date.new(2019, 2, 2))).to eq 2018
180
+ expect(subject.merch_year_from_date(Date.new(2019, 2, 3))).to eq 2019
181
+ end
182
+ end
183
+
184
+ describe "#merch_to_julian" do
185
+ it "converts merch months to julian months" do
186
+ expect(subject.merch_to_julian(1)).to eq 2
187
+ expect(subject.merch_to_julian(2)).to eq 3
188
+ expect(subject.merch_to_julian(3)).to eq 4
189
+ expect(subject.merch_to_julian(4)).to eq 5
190
+ expect(subject.merch_to_julian(5)).to eq 6
191
+ expect(subject.merch_to_julian(6)).to eq 7
192
+ expect(subject.merch_to_julian(7)).to eq 8
193
+ expect(subject.merch_to_julian(8)).to eq 9
194
+ expect(subject.merch_to_julian(9)).to eq 10
195
+ expect(subject.merch_to_julian(10)).to eq 11
196
+ expect(subject.merch_to_julian(11)).to eq 12
197
+ expect(subject.merch_to_julian(12)).to eq 1
198
+ end
117
199
 
118
- end
200
+ it "raises an error for invalid merch months" do
201
+ expect { subject.merch_to_julian(13) }.to raise_error ArgumentError
202
+ expect { subject.merch_to_julian(0) }.to raise_error ArgumentError
203
+ end
204
+ end
205
+
206
+ describe "#julian_to_merch" do
207
+ it "converts julian months to merch months" do
208
+ expect(subject.julian_to_merch(2)).to eq 1
209
+ expect(subject.julian_to_merch(3)).to eq 2
210
+ expect(subject.julian_to_merch(4)).to eq 3
211
+ expect(subject.julian_to_merch(5)).to eq 4
212
+ expect(subject.julian_to_merch(6)).to eq 5
213
+ expect(subject.julian_to_merch(7)).to eq 6
214
+ expect(subject.julian_to_merch(8)).to eq 7
215
+ expect(subject.julian_to_merch(9)).to eq 8
216
+ expect(subject.julian_to_merch(10)).to eq 9
217
+ expect(subject.julian_to_merch(11)).to eq 10
218
+ expect(subject.julian_to_merch(12)).to eq 11
219
+ expect(subject.julian_to_merch(1)).to eq 12
220
+ end
221
+
222
+ it "raises an error for invalid merch months" do
223
+ expect { subject.julian_to_merch(13) }.to raise_error ArgumentError
224
+ expect { subject.julian_to_merch(0) }.to raise_error ArgumentError
225
+ end
226
+ end
227
+
228
+ describe "#weeks_for_month" do
229
+ it "returns 4 weeks for a 4-week month Retail Year 2019 for Aug" do
230
+ weeks = subject.weeks_for_month(2018, 2)
231
+ expect(weeks.size).to eq 4
232
+ end
119
233
 
234
+ it "returns 5 weeks for a 5-week month Retail Year 2019 for Sept" do
235
+ weeks = subject.weeks_for_month(2018, 3)
236
+ expect(weeks.size).to eq 5
237
+ end
238
+
239
+ it "returns 5 weeks during a 4-5-5 quarter" do
240
+ weeks = subject.weeks_for_month(2017, julian_month: 11)
241
+ expect(weeks.size).to eq 4
242
+
243
+ weeks = subject.weeks_for_month(2017, merch_month: 11)
244
+ expect(weeks.size).to eq 5
245
+
246
+ weeks = subject.weeks_for_month(2017, 1)
247
+ expect(weeks.size).to eq 5
248
+
249
+ weeks = subject.weeks_for_month(2018, 2)
250
+ expect(weeks.size).to eq 4
251
+ end
252
+
253
+ it "raises an ArgumentError if the param is not a hash with a key we care about or Fixnum" do
254
+ expect { subject.weeks_for_month(2018, "3") }.to raise_error ArgumentError
255
+ expect { subject.weeks_for_month(2018, some_month: 4) }.to raise_error ArgumentError
256
+ end
257
+ end
258
+ end