microscope 0.6 → 0.6.1

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: 7b92f3130f66038fbee86f9e5adaa467e6800dfe
4
- data.tar.gz: 4ee59ea3ff8050b8abd0cc6bb0d9bb668ebaf3ce
3
+ metadata.gz: e1d8b3f9466f8a555fcd4133c7cc541bfbe2e437
4
+ data.tar.gz: 0370c547769ffd68344c9a5746e0ab2f02d2ba54
5
5
  SHA512:
6
- metadata.gz: 08464cec95542735521be16501b95f2d0a8d65cdaeb2bb1baa6b172af3f510e9de8847fec80bd57f8d28b6d0828758e50896b0bf5cc033d646503e4238e765fd
7
- data.tar.gz: 5aca9e965185926b4c12ba062b828df3de172e07503c53393cddeef4abea512800f088b7c37a96b35501c1e80eeb14d54fd976a623f9af4f8f5cb31dac9c9352
6
+ metadata.gz: 4328b4effc602616f1c6c2e80cf31213beb914a810a373d81f7c1142552fafa77bb8c457f286bd7359d5bdd0d702d80f39614dda799c61033ca00e9742e29026
7
+ data.tar.gz: 6da051c7e8ea9c78a947bb5eb6938ab57c61640afeb7d11bf323a2f1d0a10f24e1414d6ffc30d68a4cc4713d520052705e325c700c49746a7eabdb115a8c2cf9
@@ -15,6 +15,15 @@ module Microscope
15
15
  save!
16
16
  end
17
17
  alias_method 'un#{infinitive_verb}!', 'not_#{infinitive_verb}!'
18
+
19
+ define_method "mark_as_#{field.name}" do
20
+ send("#{field.name}=", true)
21
+ end
22
+
23
+ define_method "mark_as_not_#{field.name}" do
24
+ send("#{field.name}=", false)
25
+ end
26
+ alias_method 'mark_as_un#{field.name}', 'mark_as_not_#{field.name}'
18
27
  RUBY
19
28
  end
20
29
  end
@@ -1,50 +1,12 @@
1
1
  module Microscope
2
2
  class InstanceMethod
3
- class DateInstanceMethod < InstanceMethod
3
+ class DateInstanceMethod < DatetimeInstanceMethod
4
4
  def initialize(*args)
5
5
  super
6
6
 
7
7
  @now = 'Date.today'
8
8
  @cropped_field_regex = /_on$/
9
9
  end
10
-
11
- def apply
12
- return unless @field_name =~ @cropped_field_regex
13
-
14
- cropped_field = field.name.gsub(@cropped_field_regex, '')
15
- infinitive_verb = self.class.past_participle_to_infinitive(cropped_field)
16
-
17
- model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
18
- define_method "#{cropped_field}?" do
19
- value = send("#{field.name}")
20
- !value.nil? && value <= #{@now}
21
- end
22
-
23
- define_method "#{cropped_field}=" do |value|
24
- if Microscope::InstanceMethod.value_to_boolean(value)
25
- self.#{field.name} ||= #{@now}
26
- else
27
- self.#{field.name} = nil
28
- end
29
- end
30
-
31
- define_method "not_#{cropped_field}?" do
32
- !#{cropped_field}?
33
- end
34
- alias_method 'un#{cropped_field}?', 'not_#{cropped_field}?'
35
-
36
- define_method "#{infinitive_verb}!" do
37
- send("#{field.name}=", #{@now})
38
- save!
39
- end
40
-
41
- define_method "not_#{infinitive_verb}!" do
42
- send("#{field.name}=", nil)
43
- save!
44
- end
45
- alias_method 'un#{infinitive_verb}!', 'not_#{infinitive_verb}!'
46
- RUBY
47
- end
48
10
  end
49
11
  end
50
12
  end
@@ -43,6 +43,15 @@ module Microscope
43
43
  save!
44
44
  end
45
45
  alias_method 'un#{infinitive_verb}!', 'not_#{infinitive_verb}!'
46
+
47
+ define_method "mark_as_#{cropped_field}" do
48
+ self.#{cropped_field}= true
49
+ end
50
+
51
+ define_method "mark_as_not_#{cropped_field}" do
52
+ self.#{cropped_field}= false
53
+ end
54
+ alias_method 'mark_as_un#{cropped_field}', 'mark_as_not_#{cropped_field}'
46
55
  RUBY
47
56
  end
48
57
  end
@@ -1,3 +1,3 @@
1
1
  module Microscope
2
- VERSION = '0.6'
2
+ VERSION = '0.6.1'
3
3
  end
@@ -21,4 +21,17 @@ describe Microscope::InstanceMethod::BooleanInstanceMethod do
21
21
  it { expect { animal.not_feed! }.to change { animal.reload.fed? }.from(true).to(false) }
22
22
  it { expect(animal).to respond_to(:unfeed!) }
23
23
  end
24
+
25
+ describe '#mark_as_fed' do
26
+ let(:animal) { Animal.create(fed: false) }
27
+ it { expect { animal.mark_as_fed }.to_not change { animal.reload.fed? } }
28
+ it { expect { animal.mark_as_fed }.to change { animal.fed? }.from(false).to(true) }
29
+ end
30
+
31
+ describe '#mark_as_not_fed' do
32
+ let(:animal) { Animal.create(fed: true) }
33
+ it { expect { animal.mark_as_not_fed }.to_not change { animal.reload.fed? } }
34
+ it { expect { animal.mark_as_not_fed }.to change { animal.fed? }.from(true).to(false) }
35
+ it { expect(animal).to respond_to(:mark_as_unfed) }
36
+ end
24
37
  end
@@ -85,11 +85,29 @@ describe Microscope::InstanceMethod::DateInstanceMethod do
85
85
  it { expect { event.start! }.to change { event.reload.started_on }.from(nil).to(stubbed_date) }
86
86
  end
87
87
 
88
- describe '#start!' do
88
+ describe '#not_start!' do
89
89
  let(:stubbed_date) { Date.parse('2020-03-18 08:00:00') }
90
90
 
91
91
  let(:event) { Event.create(started_on: stubbed_date) }
92
92
  it { expect { event.not_start! }.to change { event.reload.started_on }.from(stubbed_date).to(nil) }
93
93
  it { expect(event).to respond_to(:unstart!) }
94
94
  end
95
+
96
+ describe '#mark_as_started' do
97
+ let(:stubbed_date) { Date.parse('2020-03-18 08:00:00') }
98
+ before { Date.stub(:today).and_return(stubbed_date) }
99
+
100
+ let(:event) { Event.create(started_on: nil) }
101
+ it { expect { event.mark_as_started }.to_not change { event.reload.started_on } }
102
+ it { expect { event.mark_as_started }.to change { event.started_on }.from(nil).to(stubbed_date) }
103
+ end
104
+
105
+ describe '#mark_as_not_started' do
106
+ let(:stubbed_date) { Date.parse('2020-03-18 08:00:00') }
107
+
108
+ let(:event) { Event.create(started_on: stubbed_date) }
109
+ it { expect { event.mark_as_not_started }.to_not change { event.reload.started_on } }
110
+ it { expect { event.mark_as_not_started }.to change { event.started_on }.from(stubbed_date).to(nil) }
111
+ it { expect(event).to respond_to(:mark_as_unstarted) }
112
+ end
95
113
  end
@@ -81,4 +81,21 @@ describe Microscope::InstanceMethod::DatetimeInstanceMethod do
81
81
  it { expect { event.not_start! }.to change { event.reload.started_at }.from(stubbed_date).to(nil) }
82
82
  it { expect(event).to respond_to(:unstart!) }
83
83
  end
84
+
85
+ describe '#mark_as_started' do
86
+ let(:stubbed_date) { Time.parse('2020-03-18 08:00:00') }
87
+ before { Time.stub(:now).and_return(stubbed_date) }
88
+
89
+ let(:event) { Event.create(started_at: nil) }
90
+ it { expect { event.mark_as_started }.to_not change { event.reload.started_at } }
91
+ it { expect { event.mark_as_started }.to change { event.started_at }.from(nil).to(stubbed_date) }
92
+ end
93
+
94
+ describe '#mark_as_not_started' do
95
+ let(:stubbed_date) { Time.parse('2020-03-18 08:00:00') }
96
+
97
+ let(:event) { Event.create(started_at: stubbed_date) }
98
+ it { expect { event.mark_as_not_started }.to_not change { event.reload.started_at } }
99
+ it { expect { event.mark_as_not_started }.to change { event.started_at }.from(stubbed_date).to(nil) }
100
+ end
84
101
  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.6'
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Prévost
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-22 00:00:00.000000000 Z
12
+ date: 2014-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport