has_streak 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1045fc8f29d5a7ca126ac0b6d9e8b5f7ba389c6
4
- data.tar.gz: 938ab0df625a22dd57f1a028ad49a0b6df08130a
3
+ metadata.gz: 63ba6abb764f993e38c848030a927c31a005bc2f
4
+ data.tar.gz: 2613f5a94496a8add316521c1d6379248cc8ec89
5
5
  SHA512:
6
- metadata.gz: a25451bdf1b41daabc65677df48d45818f60b3d6ac8107eacd14cd7305bb83a39d03c983492bf4e541f28981ff23652acb59d02e6cb1d791c98517bc2c448388
7
- data.tar.gz: b604c87825d2c25a26deb4b4573408fe1e7157c736811fb10a231c6c31bf560771dc078ce511f56403e52d0dc8e55e04d5f7e6500d6d68e7222a6f691870bce4
6
+ metadata.gz: 7a30056b442a2d419d4be6a2a62f93bfc45d90f87915a4ccbe05cdd976b50c21f69c2b3796453370b2f261fe08d2150ed3106fe20800639cfed27f263d61cd07
7
+ data.tar.gz: 4824d3ec0ad9fcbd0a22a39c4882cda9dcdebfb210a02397b6e800b4b4fb299abacf83ca7c436e1920282d8eebaa707a87c907c0e1a0f1814721a5b63da07060
@@ -15,14 +15,19 @@ module HasStreak
15
15
  private
16
16
 
17
17
  def get_days(association)
18
- self.send(association).order(:created_at).pluck(:created_at).map(&:to_date).uniq
18
+ self.send(association).order("created_at DESC").pluck(:created_at).map(&:to_date).uniq
19
19
  end
20
20
 
21
21
  def determine_consecutive_days(days)
22
- days.each_with_index.inject(1) do |streak, (day, index)|
23
- streak += 1 if days[index+1] == day.tomorrow
24
- streak
22
+ streak = 1
23
+ days.each_with_index do |day, index|
24
+ if days[index+1] == day.yesterday
25
+ streak += 1
26
+ else
27
+ break
28
+ end
25
29
  end
30
+ streak
26
31
  end
27
32
 
28
33
  end
@@ -1,3 +1,3 @@
1
1
  module HasStreak
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -7,7 +7,7 @@ describe HasStreak::Streakable do
7
7
  it "returns a streak of 3" do
8
8
  user.posts.create(content: "hello", created_at: 2.days.ago)
9
9
  user.posts.create(content: "hello", created_at: 1.day.ago)
10
- user.posts.create(content: "hello")
10
+ user.posts.create(content: "hello", created_at: DateTime.current)
11
11
 
12
12
  expect(user.streak(:posts)).to eq(3)
13
13
  end
@@ -15,7 +15,7 @@ describe HasStreak::Streakable do
15
15
  it "returns streak of one (no streak)" do
16
16
  user.posts.create(content: "hello", created_at: 5.days.ago)
17
17
  user.posts.create(content: "hello", created_at: 2.days.ago)
18
- user.posts.create(content: "hello")
18
+ user.posts.create(content: "hello", created_at: DateTime.current)
19
19
 
20
20
  expect(user.streak(:posts)).to eq(1)
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_streak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garrett Martin