has_streak 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/has_streak/streakable.rb +6 -2
- data/lib/has_streak/version.rb +1 -1
- data/spec/streakable_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f880252922b84672c995aa76b7f180897815304c
|
4
|
+
data.tar.gz: 8ab7cbd023e5f781c3e676d8d4ce8c691c21051a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d647f916680de1f3f46eec9e10e9d5a4bc63c5d9d577ce65eb5afbdba76c203d00970e1f78db785ca4385c62930d8c3b2775cc890d5b08c59d46f54534ed704
|
7
|
+
data.tar.gz: 02b26ca94095f04b80bf0a482c9101a330a62bb3b86f487632e2fca4e494d1e8c185344f93894deb33f6c1cb3a524e3143062880174fbbd09616239c66e58805
|
@@ -19,9 +19,9 @@ module HasStreak
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def determine_consecutive_days(days)
|
22
|
-
streak = 1
|
22
|
+
streak = first_day_in_collection_is_today?(days) ? 1 : 0
|
23
23
|
days.each_with_index do |day, index|
|
24
|
-
break unless days
|
24
|
+
break unless first_day_in_collection_is_today?(days)
|
25
25
|
if days[index+1] == day.yesterday
|
26
26
|
streak += 1
|
27
27
|
else
|
@@ -31,6 +31,10 @@ module HasStreak
|
|
31
31
|
streak
|
32
32
|
end
|
33
33
|
|
34
|
+
def first_day_in_collection_is_today?(days)
|
35
|
+
days.first == Date.current
|
36
|
+
end
|
37
|
+
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
data/lib/has_streak/version.rb
CHANGED
data/spec/streakable_spec.rb
CHANGED
@@ -11,12 +11,12 @@ describe HasStreak::Streakable do
|
|
11
11
|
expect(user.streak(:posts)).to eq(3)
|
12
12
|
end
|
13
13
|
|
14
|
-
it "returns streak of
|
14
|
+
it "returns streak of zero" do
|
15
15
|
user.posts.create(content: "hello", created_at: 4.days.ago)
|
16
16
|
user.posts.create(content: "hello", created_at: 3.days.ago)
|
17
17
|
user.posts.create(content: "hello", created_at: 2.days.ago)
|
18
18
|
|
19
|
-
expect(user.streak(:posts)).to eq(
|
19
|
+
expect(user.streak(:posts)).to eq(0)
|
20
20
|
end
|
21
21
|
|
22
22
|
context "spanning two months" do
|