-
-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4114 from isidzukuri/3729_wider_spread_of_dates_i…
…n_the_seed 3729 wider spread of dates in the seed
- Loading branch information
Showing
4 changed files
with
66 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class DispersedPastDatesGenerator | ||
DAYS_RANGES = [0..6, 7..30, 31..300, 350..700].freeze | ||
|
||
def initialize | ||
@current_index = 0 | ||
end | ||
|
||
def next | ||
day = Time.zone.today - rand(DAYS_RANGES[@current_index]).days | ||
@current_index = if DAYS_RANGES.size - 1 > @current_index | ||
@current_index.next | ||
else | ||
0 | ||
end | ||
|
||
day | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
load "lib/dispersed_past_dates_generator.rb" | ||
|
||
RSpec.describe DispersedPastDatesGenerator do | ||
describe "constants" do | ||
it "has 4 day ranges for generation of past dates" do | ||
expect(described_class::DAYS_RANGES).to eq([0..6, 7..30, 31..300, 350..700]) | ||
end | ||
end | ||
|
||
describe "#next" do | ||
let(:dates_generator) { described_class.new } | ||
|
||
it "returns equally dispersed dates between all time ranges" do | ||
expect(dates_generator.next).to be_between(Time.zone.today - 6.days, Time.zone.today) | ||
expect(dates_generator.next).to be_between(Time.zone.today - 30.days, Time.zone.today - 7.days) | ||
expect(dates_generator.next).to be_between(Time.zone.today - 300.days, Time.zone.today - 31.days) | ||
expect(dates_generator.next).to be_between(Time.zone.today - 700.days, Time.zone.today - 350.days) | ||
expect(dates_generator.next).to be_between(Time.zone.today - 6.days, Time.zone.today) | ||
expect(dates_generator.next).to be_between(Time.zone.today - 30.days, Time.zone.today - 7.days) | ||
expect(dates_generator.next).to be_between(Time.zone.today - 300.days, Time.zone.today - 31.days) | ||
expect(dates_generator.next).to be_between(Time.zone.today - 700.days, Time.zone.today - 350.days) | ||
end | ||
end | ||
end |
This file contains 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