microscope 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81b294b8462eb03ab74fca0b27959a77b87bb010
4
- data.tar.gz: 8f7f4334cc65cc34ab1f35da5fcf4c7afaeb9320
3
+ metadata.gz: 7602cb25b5b12f243c0380bb3f66a8d126bc0d53
4
+ data.tar.gz: 592d56ccc94f58eccfbae50646beb09f7b06547e
5
5
  SHA512:
6
- metadata.gz: 09b3471cabc1469f2741374d6b549a1208aaf3501797bf06dd05d1a274472ea32a8cdb40792649fdda7a91ae1c509d6fd9522bcb573e9ceff387c6c73a063ff5
7
- data.tar.gz: e2e9f91784041a92efc3c23b34b29fbf0d20177ec790f2ae76a9ab7a6bcbcbfca1d5f4dfe5628a75d6b04744e705dde51e1f568a9cf33fef7e9d1ae1a6d96f6b
6
+ metadata.gz: da0941107f2b282149fbb7321d7cf402aa354b4407657b3cf57d3f2dbebb88f6f255bbb6a21f9d5692fbc3fdc3659a5ad75e7b7c611871f8306cc188d7a30933
7
+ data.tar.gz: 0b78e8dfb69a15ebf94759b503d1c8ff1f00b7d7c1de145efd227ebf3694ed6778930ef4158e19bdac81e0e1672ed987fe4a1e11fe87ffc5ec54f6a2987ccdff
@@ -21,5 +21,10 @@ module Microscope
21
21
  participle
22
22
  end
23
23
  end
24
+
25
+ # Convert a value to its boolean representation
26
+ def self.value_to_boolean(value)
27
+ ![nil, false, 0, '0', 'f', 'F', 'false', 'FALSE'].include?(value.presence)
28
+ end
24
29
  end
25
30
  end
@@ -11,6 +11,14 @@ module Microscope
11
11
  !value.nil? && value <= Date.today
12
12
  end
13
13
 
14
+ define_method "#{cropped_field}=" do |value|
15
+ if Microscope::InstanceMethod.value_to_boolean(value)
16
+ self.#{field.name} = Date.today
17
+ else
18
+ self.#{field.name} = nil
19
+ end
20
+ end
21
+
14
22
  define_method "not_#{cropped_field}?" do
15
23
  !#{cropped_field}?
16
24
  end
@@ -11,6 +11,14 @@ module Microscope
11
11
  !value.nil? && value <= Time.now
12
12
  end
13
13
 
14
+ define_method "#{cropped_field}=" do |value|
15
+ if Microscope::InstanceMethod.value_to_boolean(value)
16
+ self.#{field.name} = Time.now
17
+ else
18
+ self.#{field.name} = nil
19
+ end
20
+ end
21
+
14
22
  define_method "not_#{cropped_field}?" do
15
23
  !#{cropped_field}?
16
24
  end
@@ -1,3 +1,3 @@
1
1
  module Microscope
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
3
3
  end
@@ -25,6 +25,24 @@ describe Microscope::InstanceMethod::DateInstanceMethod do
25
25
  end
26
26
  end
27
27
 
28
+ describe '#started=' do
29
+ before { subject.started = value }
30
+
31
+ context 'with present argument' do
32
+ subject { Event.create(started_on: 2.months.ago) }
33
+ let(:value) { '0' }
34
+
35
+ it { should_not be_started }
36
+ end
37
+
38
+ context 'with blank argument' do
39
+ subject { Event.create }
40
+ let(:value) { '1' }
41
+
42
+ it { should be_started }
43
+ end
44
+ end
45
+
28
46
  describe '#not_started?' do
29
47
  context 'with negative result' do
30
48
  subject { Event.create(started_on: 2.months.ago) }
@@ -5,7 +5,6 @@ describe Microscope::InstanceMethod::DatetimeInstanceMethod do
5
5
  run_migration do
6
6
  create_table(:events, force: true) do |t|
7
7
  t.datetime :started_at, default: nil
8
- t.datetime :featured_at, default: nil
9
8
  end
10
9
  end
11
10
 
@@ -24,6 +23,24 @@ describe Microscope::InstanceMethod::DatetimeInstanceMethod do
24
23
  end
25
24
  end
26
25
 
26
+ describe '#started=' do
27
+ before { subject.started = value }
28
+
29
+ context 'with present argument' do
30
+ subject { Event.create(started_at: 2.months.ago) }
31
+ let(:value) { '0' }
32
+
33
+ it { should_not be_started }
34
+ end
35
+
36
+ context 'with blank argument' do
37
+ subject { Event.create }
38
+ let(:value) { '1' }
39
+
40
+ it { should be_started }
41
+ end
42
+ end
43
+
27
44
  describe '#not_started?' do
28
45
  context 'with negative result' do
29
46
  subject { Event.create(started_at: 2.months.ago) }
@@ -43,6 +60,5 @@ describe Microscope::InstanceMethod::DatetimeInstanceMethod do
43
60
  let(:event) { Event.create(started_at: nil) }
44
61
  it { expect { event.start! }.to change { event.reload.started_at }.from(nil).to(stubbed_date) }
45
62
  it { expect(event).to respond_to(:start!) }
46
- it { expect(event).to respond_to(:feature!) }
47
63
  end
48
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: microscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Prévost