time_for_a_boolean 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: 26332da2835fdd1d1ccdd0d65721aea37327a29f
4
- data.tar.gz: 0f8f8f69c3dd56a234a1ad1420e4e3c0a0f83982
3
+ metadata.gz: 277793114b162bb1a4753e9400c14ae68708e217
4
+ data.tar.gz: 5eae5941a38459c5a383dd8eb4561a8d839eb7e2
5
5
  SHA512:
6
- metadata.gz: 1490cd3fc6b4b3dc779df13307203929a899fb0f0b0d761a0b91aa810ffe22d0c777199984425364dd2e3d7fe3784bfd2196dae3455007dcd0a70a6316b23ab5
7
- data.tar.gz: bfa8129fedc1befc242375792de263b43e477f551bc178c82c174e14bfbdcc749068d65cb500440489a381108262e223f733b1038bb86523545b3432f0deee65
6
+ metadata.gz: d084a3437da16608c2539cd5b8d9f11e6b0e5f1d0956c6d77c84aa15ee3f7cfde0bb3934ebf3d96ea3d70cd072e6deef1ffb781b225a2b29e3a668a575f77228
7
+ data.tar.gz: dfdc83188a96c03337bd9dbcef49700c2e15772703dfdbdb61087d193e59889965768fb184c217dd041a029248b309bc03ad1c062d2c8c45bb53e8b5989dbebb
@@ -1,3 +1,5 @@
1
+ require "rails/railtie"
2
+
1
3
  module TimeForABoolean
2
4
  class Railtie < ::Rails::Railtie
3
5
  initializer 'time_for_a_boolean' do
@@ -1,3 +1,3 @@
1
1
  module TimeForABoolean
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'rails'
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_for_a_boolean
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
  - Caleb Thompson