time_for_a_boolean 0.0.2 → 0.0.3
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/time_for_a_boolean/version.rb +1 -1
- data/lib/time_for_a_boolean.rb +2 -2
- data/spec/time_for_a_boolean_spec.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26332da2835fdd1d1ccdd0d65721aea37327a29f
|
4
|
+
data.tar.gz: 0f8f8f69c3dd56a234a1ad1420e4e3c0a0f83982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1490cd3fc6b4b3dc779df13307203929a899fb0f0b0d761a0b91aa810ffe22d0c777199984425364dd2e3d7fe3784bfd2196dae3455007dcd0a70a6316b23ab5
|
7
|
+
data.tar.gz: bfa8129fedc1befc242375792de263b43e477f551bc178c82c174e14bfbdcc749068d65cb500440489a381108262e223f733b1038bb86523545b3432f0deee65
|
data/lib/time_for_a_boolean.rb
CHANGED
@@ -6,12 +6,12 @@ module TimeForABoolean
|
|
6
6
|
def time_for_a_boolean(attribute)
|
7
7
|
define_method(attribute) do
|
8
8
|
!send("#{attribute}_at").nil? &&
|
9
|
-
send("#{attribute}_at") <= -> { DateTime.
|
9
|
+
send("#{attribute}_at") <= -> { DateTime.current }.()
|
10
10
|
end
|
11
11
|
alias_method "#{attribute}?", attribute
|
12
12
|
define_method("#{attribute}=") do |value|
|
13
13
|
if value
|
14
|
-
send("#{attribute}_at=", -> { DateTime.
|
14
|
+
send("#{attribute}_at=", -> { DateTime.current }.())
|
15
15
|
else
|
16
16
|
send("#{attribute}_at=", nil)
|
17
17
|
end
|
@@ -26,7 +26,7 @@ describe TimeForABoolean do
|
|
26
26
|
it 'calls nil? on the backing timestamp' do
|
27
27
|
klass.time_for_a_boolean :attribute
|
28
28
|
timestamp = double(nil?: true)
|
29
|
-
object.
|
29
|
+
allow(object).to receive(:attribute_at).and_return(timestamp)
|
30
30
|
|
31
31
|
object.attribute
|
32
32
|
|
@@ -35,23 +35,23 @@ describe TimeForABoolean do
|
|
35
35
|
|
36
36
|
it 'is true if the attribute is not nil' do
|
37
37
|
klass.time_for_a_boolean :attribute
|
38
|
-
object.
|
38
|
+
allow(object).to receive(:attribute_at).and_return(DateTime.now - 10)
|
39
39
|
|
40
|
-
expect(object.attribute).to
|
40
|
+
expect(object.attribute).to be_truthy
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'is false if the attribute is nil' do
|
44
44
|
klass.time_for_a_boolean :attribute
|
45
|
-
object.
|
45
|
+
allow(object).to receive(:attribute_at)
|
46
46
|
|
47
|
-
expect(object.attribute).to
|
47
|
+
expect(object.attribute).to be_falsey
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'is false if the attribute time is in the future' do
|
51
51
|
klass.time_for_a_boolean :attribute
|
52
|
-
object.
|
52
|
+
allow(object).to receive(:attribute_at).and_return(Time.now + 86400) # one day in the future
|
53
53
|
|
54
|
-
expect(object.attribute).to
|
54
|
+
expect(object.attribute).to be_falsey
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_for_a_boolean
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|