microscope 0.2 → 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.
- data/README.md +6 -0
- data/gemfiles/Gemfile.activerecord-3.2.x +2 -2
- data/gemfiles/Gemfile.activerecord-4.0 +2 -2
- data/lib/microscope/mixin.rb +6 -0
- data/lib/microscope/version.rb +1 -1
- data/spec/microscope/mixin_spec.rb +46 -2
- metadata +4 -4
data/README.md
CHANGED
@@ -53,6 +53,12 @@ Event.started_before(2.days.ago)
|
|
53
53
|
|
54
54
|
Event.started_between(2.days.ago..3.days.from_now)
|
55
55
|
# SELECT * FROM `events` where `events`.`started_on` BETWEEN '2013-07-03' AND '2013-07-08'
|
56
|
+
|
57
|
+
Event.started
|
58
|
+
# SELECT * FROM `events` where `events`.`started_at` IS NOT NULL AND `events`.`started_at` <= '2013-07-05 15:43:42'
|
59
|
+
|
60
|
+
Event.not_started
|
61
|
+
# SELECT * FROM `events` where `events`.`started_at` IS NULL OR `events`.`started_at` > '2013-07-05 15:43:42'
|
56
62
|
```
|
57
63
|
|
58
64
|
### Options
|
data/lib/microscope/mixin.rb
CHANGED
@@ -34,6 +34,9 @@ module Microscope
|
|
34
34
|
scope "#{cropped_field}_after_now", lambda { where("#{field} > ?", Time.now) }
|
35
35
|
|
36
36
|
scope "#{cropped_field}_between", lambda { |range| where(field => range) }
|
37
|
+
|
38
|
+
scope "#{cropped_field}", lambda { where("#{field} IS NOT NULL AND #{field} <= ?", Time.now) }
|
39
|
+
scope "not_#{cropped_field}", lambda { where("#{field} IS NULL OR #{field} > ?", Time.now) }
|
37
40
|
end
|
38
41
|
|
39
42
|
date_fields = model_columns.select { |c| c.type == :date }.map(&:name)
|
@@ -49,6 +52,9 @@ module Microscope
|
|
49
52
|
scope "#{cropped_field}_after_today", lambda { where("#{field} > ?", Date.today) }
|
50
53
|
|
51
54
|
scope "#{cropped_field}_between", lambda { |range| where(field => range) }
|
55
|
+
|
56
|
+
scope "#{cropped_field}", lambda { where("#{field} IS NOT NULL AND #{field} <= ?", Date.today) }
|
57
|
+
scope "not_#{cropped_field}", lambda { where("#{field} IS NULL OR #{field} > ?", Date.today) }
|
52
58
|
end
|
53
59
|
end
|
54
60
|
end
|
data/lib/microscope/version.rb
CHANGED
@@ -90,7 +90,7 @@ describe Microscope::Mixin do
|
|
90
90
|
before do
|
91
91
|
run_migration do
|
92
92
|
create_table(:events, force: true) do |t|
|
93
|
-
t.datetime :started_at, default:
|
93
|
+
t.datetime :started_at, default: nil
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -142,6 +142,28 @@ describe Microscope::Mixin do
|
|
142
142
|
|
143
143
|
it { expect(Event.started_between(4.months.ago..2.months.ago).to_a).to eql [@event] }
|
144
144
|
end
|
145
|
+
|
146
|
+
describe 'super-boolean positive scope', focus: true do
|
147
|
+
before do
|
148
|
+
@event1 = Event.create(started_at: 1.month.ago)
|
149
|
+
@event2 = Event.create(started_at: 3.months.ago)
|
150
|
+
Event.create(started_at: 2.months.from_now)
|
151
|
+
Event.create(started_at: nil)
|
152
|
+
end
|
153
|
+
|
154
|
+
it { expect(Event.started.to_a).to eql [@event1, @event2] }
|
155
|
+
end
|
156
|
+
|
157
|
+
describe 'super-boolean negative scope' do
|
158
|
+
before do
|
159
|
+
Event.create(started_at: 1.month.ago)
|
160
|
+
Event.create(started_at: 3.months.ago)
|
161
|
+
@event1 = Event.create(started_at: 2.months.from_now)
|
162
|
+
@event2 = Event.create(started_at: nil)
|
163
|
+
end
|
164
|
+
|
165
|
+
it { expect(Event.not_started.to_a).to eql [@event1, @event2] }
|
166
|
+
end
|
145
167
|
end
|
146
168
|
|
147
169
|
describe 'Date scopes' do
|
@@ -150,7 +172,7 @@ describe Microscope::Mixin do
|
|
150
172
|
before do
|
151
173
|
run_migration do
|
152
174
|
create_table(:events, force: true) do |t|
|
153
|
-
t.date :started_on, default:
|
175
|
+
t.date :started_on, default: nil
|
154
176
|
end
|
155
177
|
end
|
156
178
|
|
@@ -202,5 +224,27 @@ describe Microscope::Mixin do
|
|
202
224
|
|
203
225
|
it { expect(Event.started_between(4.months.ago..2.months.ago).to_a).to eql [@event] }
|
204
226
|
end
|
227
|
+
|
228
|
+
describe 'super-boolean positive scope' do
|
229
|
+
before do
|
230
|
+
@event1 = Event.create(started_on: 1.month.ago)
|
231
|
+
@event2 = Event.create(started_on: 3.months.ago)
|
232
|
+
Event.create(started_on: 2.months.from_now)
|
233
|
+
Event.create(started_on: nil)
|
234
|
+
end
|
235
|
+
|
236
|
+
it { expect(Event.started.to_a).to eql [@event1, @event2] }
|
237
|
+
end
|
238
|
+
|
239
|
+
describe 'super-boolean negative scope' do
|
240
|
+
before do
|
241
|
+
Event.create(started_on: 1.month.ago)
|
242
|
+
Event.create(started_on: 3.months.ago)
|
243
|
+
@event1 = Event.create(started_on: 2.months.from_now)
|
244
|
+
@event2 = Event.create(started_on: nil)
|
245
|
+
end
|
246
|
+
|
247
|
+
it { expect(Event.not_started.to_a).to eql [@event1, @event2] }
|
248
|
+
end
|
205
249
|
end
|
206
250
|
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.
|
4
|
+
version: '0.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-08-
|
13
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -150,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
segments:
|
152
152
|
- 0
|
153
|
-
hash: -
|
153
|
+
hash: -1281633982724090897
|
154
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
155
|
none: false
|
156
156
|
requirements:
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
version: '0'
|
160
160
|
segments:
|
161
161
|
- 0
|
162
|
-
hash: -
|
162
|
+
hash: -1281633982724090897
|
163
163
|
requirements: []
|
164
164
|
rubyforge_project:
|
165
165
|
rubygems_version: 1.8.23
|