time_for_a_boolean 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/time_for_a_boolean/railtie.rb +2 -0
- 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 +19 -0
- 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: 277793114b162bb1a4753e9400c14ae68708e217
|
4
|
+
data.tar.gz: 5eae5941a38459c5a383dd8eb4561a8d839eb7e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d084a3437da16608c2539cd5b8d9f11e6b0e5f1d0956c6d77c84aa15ee3f7cfde0bb3934ebf3d96ea3d70cd072e6deef1ffb781b225a2b29e3a668a575f77228
|
7
|
+
data.tar.gz: dfdc83188a96c03337bd9dbcef49700c2e15772703dfdbdb61087d193e59889965768fb184c217dd041a029248b309bc03ad1c062d2c8c45bb53e8b5989dbebb
|
data/lib/time_for_a_boolean.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'active_record/connection_adapters/column'
|
2
2
|
require 'time_for_a_boolean/version'
|
3
3
|
require 'time_for_a_boolean/railtie'
|
4
4
|
|
@@ -10,7 +10,7 @@ module TimeForABoolean
|
|
10
10
|
end
|
11
11
|
alias_method "#{attribute}?", attribute
|
12
12
|
define_method("#{attribute}=") do |value|
|
13
|
-
if value
|
13
|
+
if ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(value)
|
14
14
|
send("#{attribute}_at=", -> { DateTime.current }.())
|
15
15
|
else
|
16
16
|
send("#{attribute}_at=", nil)
|
@@ -82,6 +82,25 @@ describe TimeForABoolean do
|
|
82
82
|
|
83
83
|
expect(object.attribute_at).to be_nil
|
84
84
|
end
|
85
|
+
|
86
|
+
it 'works with other representations of true' do
|
87
|
+
klass.time_for_a_boolean :attribute
|
88
|
+
klass.send(:attr_accessor, :attribute_at)
|
89
|
+
|
90
|
+
object.attribute = '1'
|
91
|
+
|
92
|
+
expect(object.attribute_at).to be_kind_of(DateTime)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'works with other representations of false' do
|
96
|
+
klass.time_for_a_boolean :attribute
|
97
|
+
klass.send(:attr_accessor, :attribute_at)
|
98
|
+
|
99
|
+
object.attribute_at = DateTime.now
|
100
|
+
object.attribute = '0'
|
101
|
+
|
102
|
+
expect(object.attribute_at).to be_nil
|
103
|
+
end
|
85
104
|
end
|
86
105
|
|
87
106
|
def klass
|