microscope 0.5.7 → 0.5.8
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 +4 -4
- data/lib/microscope/scope/boolean_scope.rb +1 -0
- data/lib/microscope/scope/datetime_scope.rb +1 -0
- data/lib/microscope/version.rb +1 -1
- data/spec/microscope/instance_method/date_instance_method_spec.rb +19 -19
- data/spec/microscope/instance_method/datetime_instance_method_spec.rb +15 -15
- data/spec/microscope/scope/boolean_scope_spec.rb +5 -6
- data/spec/microscope/scope/date_scope_spec.rb +7 -10
- data/spec/microscope/scope/datetime_scope_spec.rb +7 -10
- data/spec/microscope_spec.rb +72 -74
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d0dca4213a2ae5d3f283756406aed55a4d28e55
|
4
|
+
data.tar.gz: 10c15290f3784a35e3273954fa5451cf91dd5ea5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f567999f9639db99ed40340ce3f46260e81733f7fcdf753a09f8d133e7c8cd25dcee76c1be31c7ecf29d40a3e40e414c695f78dcaeb8121eb7564e92e140edd5
|
7
|
+
data.tar.gz: f4f8caa7fd050625cdaf7b1505808fa045c3df34e79017083a488829ecee460c44ef18c319f56b42f2268067db199fc630ef47cac9b72876487a3bc7149384e3
|
@@ -5,6 +5,7 @@ module Microscope
|
|
5
5
|
model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
6
6
|
scope "#{@field_name}", lambda { where("#{@field_name}" => true) }
|
7
7
|
scope "not_#{@field_name}", lambda { where("#{@field_name}" => false) }
|
8
|
+
scope "un#{@field_name}", lambda { not_#{@field_name} }
|
8
9
|
RUBY
|
9
10
|
end
|
10
11
|
end
|
@@ -48,6 +48,7 @@ module Microscope
|
|
48
48
|
<<-RUBY
|
49
49
|
scope "#{cropped_field}", lambda { where('#{quoted_field} IS NOT NULL AND #{quoted_field} <= ?', #{@now}) }
|
50
50
|
scope "not_#{cropped_field}", lambda { where('#{quoted_field} IS NULL OR #{quoted_field} > ?', #{@now}) }
|
51
|
+
scope "un#{cropped_field}", lambda { not_#{cropped_field} }
|
51
52
|
RUBY
|
52
53
|
end
|
53
54
|
end
|
data/lib/microscope/version.rb
CHANGED
@@ -20,55 +20,55 @@ describe Microscope::InstanceMethod::DateInstanceMethod do
|
|
20
20
|
|
21
21
|
describe '#started?' do
|
22
22
|
context 'with positive result' do
|
23
|
-
|
24
|
-
it {
|
25
|
-
it {
|
23
|
+
let(:event) { Event.create(started_on: 2.months.ago) }
|
24
|
+
it { expect(event).to be_started }
|
25
|
+
it { expect(event).to_not be_not_started }
|
26
26
|
end
|
27
27
|
|
28
28
|
context 'with negative result' do
|
29
|
-
|
30
|
-
it {
|
31
|
-
it {
|
29
|
+
let(:event) { Event.create(started_on: 1.month.from_now) }
|
30
|
+
it { expect(event).to_not be_started }
|
31
|
+
it { expect(event).to be_not_started }
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe '#started=' do
|
36
|
-
before {
|
36
|
+
before { event.started = value }
|
37
37
|
|
38
38
|
context 'with blank argument' do
|
39
|
-
|
39
|
+
let(:event) { Event.create(started_on: 2.months.ago) }
|
40
40
|
let(:value) { '0' }
|
41
41
|
|
42
|
-
it {
|
42
|
+
it { expect(event).to_not be_started }
|
43
43
|
end
|
44
44
|
|
45
45
|
context 'with present argument' do
|
46
|
-
|
46
|
+
let(:event) { Event.create }
|
47
47
|
let(:value) { '1' }
|
48
48
|
|
49
|
-
it {
|
49
|
+
it { expect(event).to be_started }
|
50
50
|
end
|
51
51
|
|
52
52
|
context 'with present argument, twice' do
|
53
|
-
|
53
|
+
let(:event) { Event.create(started_on: time) }
|
54
54
|
let(:time) { 2.months.ago }
|
55
55
|
let(:value) { '1' }
|
56
56
|
|
57
|
-
it { expect(
|
58
|
-
it { expect(
|
59
|
-
it { expect(
|
57
|
+
it { expect(event.started_on.day).to eql time.day }
|
58
|
+
it { expect(event.started_on.month).to eql time.month }
|
59
|
+
it { expect(event.started_on.year).to eql time.year }
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
describe '#not_started?' do
|
64
64
|
context 'with negative result' do
|
65
|
-
|
66
|
-
it {
|
65
|
+
let(:event) { Event.create(started_on: 2.months.ago) }
|
66
|
+
it { expect(event).to_not be_not_started }
|
67
67
|
end
|
68
68
|
|
69
69
|
context 'with positive result' do
|
70
|
-
|
71
|
-
it {
|
70
|
+
let(:event) { Event.create(started_on: 1.month.from_now) }
|
71
|
+
it { expect(event).to be_not_started }
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -13,51 +13,51 @@ describe Microscope::InstanceMethod::DatetimeInstanceMethod do
|
|
13
13
|
|
14
14
|
describe '#started?' do
|
15
15
|
context 'with positive result' do
|
16
|
-
|
17
|
-
it {
|
16
|
+
let(:event) { Event.create(started_at: 2.months.ago) }
|
17
|
+
it { expect(event).to be_started }
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'with negative result' do
|
21
|
-
|
22
|
-
it {
|
21
|
+
let(:event) { Event.create(started_at: 1.month.from_now) }
|
22
|
+
it { expect(event).to_not be_started }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
describe '#started=' do
|
27
|
-
before {
|
27
|
+
before { event.started = value }
|
28
28
|
|
29
29
|
context 'with blank argument' do
|
30
|
-
|
30
|
+
let(:event) { Event.create(started_at: 2.months.ago) }
|
31
31
|
let(:value) { '0' }
|
32
32
|
|
33
|
-
it {
|
33
|
+
it { expect(event).to_not be_started }
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'with present argument' do
|
37
|
-
|
37
|
+
let(:event) { Event.create }
|
38
38
|
let(:value) { '1' }
|
39
39
|
|
40
|
-
it {
|
40
|
+
it { expect(event).to be_started }
|
41
41
|
end
|
42
42
|
|
43
43
|
context 'with present argument, twice' do
|
44
|
-
|
44
|
+
let(:event) { Event.create(started_at: time) }
|
45
45
|
let(:time) { 2.months.ago }
|
46
46
|
let(:value) { '1' }
|
47
47
|
|
48
|
-
it { expect(
|
48
|
+
it { expect(event.started_at).to eql time }
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe '#not_started?' do
|
53
53
|
context 'with negative result' do
|
54
|
-
|
55
|
-
it {
|
54
|
+
let(:event) { Event.create(started_at: 2.months.ago) }
|
55
|
+
it { expect(event).to_not be_not_started }
|
56
56
|
end
|
57
57
|
|
58
58
|
context 'with positive result' do
|
59
|
-
|
60
|
-
it {
|
59
|
+
let(:event) { Event.create(started_at: 1.month.from_now) }
|
60
|
+
it { expect(event).to be_not_started }
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Microscope::Scope::BooleanScope do
|
4
|
-
subject { User }
|
5
|
-
|
6
4
|
before do
|
7
5
|
run_migration do
|
8
6
|
create_table(:users, force: true) do |t|
|
@@ -19,8 +17,8 @@ describe Microscope::Scope::BooleanScope do
|
|
19
17
|
@user2 = User.create(active: false)
|
20
18
|
end
|
21
19
|
|
22
|
-
|
23
|
-
|
20
|
+
it { expect(User.active).to have(1).items }
|
21
|
+
it { expect(User.active).to include(@user1) }
|
24
22
|
end
|
25
23
|
|
26
24
|
describe 'negative scope' do
|
@@ -29,7 +27,8 @@ describe Microscope::Scope::BooleanScope do
|
|
29
27
|
@user2 = User.create(active: true)
|
30
28
|
end
|
31
29
|
|
32
|
-
|
33
|
-
|
30
|
+
it { expect(User.not_active).to have(1).items }
|
31
|
+
it { expect(User.not_active).to include(@user1) }
|
32
|
+
it { expect(User.unactive.to_a).to eql User.not_active.to_a }
|
34
33
|
end
|
35
34
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Microscope::Scope::DateScope do
|
4
|
-
subject { Event }
|
5
|
-
|
6
4
|
before do
|
7
5
|
run_migration do
|
8
6
|
create_table(:events, force: true) do |t|
|
@@ -80,24 +78,23 @@ describe Microscope::Scope::DateScope do
|
|
80
78
|
end
|
81
79
|
|
82
80
|
it { expect(Event.not_started.to_a).to eql [@event1, @event2] }
|
81
|
+
it { expect(Event.unstarted.to_a).to eql Event.not_started.to_a }
|
83
82
|
end
|
84
83
|
|
85
84
|
describe 'boolean instance method' do
|
86
85
|
context 'for positive record' do
|
87
|
-
|
88
|
-
it {
|
86
|
+
let(:event) { Event.create(started_on: 3.months.ago) }
|
87
|
+
it { expect(event).to be_started }
|
89
88
|
end
|
90
89
|
|
91
90
|
context 'for negative record' do
|
92
|
-
|
93
|
-
it {
|
91
|
+
let(:event) { Event.create(started_on: 2.months.from_now) }
|
92
|
+
it { expect(event).to_not be_started }
|
94
93
|
end
|
95
94
|
end
|
96
95
|
|
97
96
|
context 'for field that does not match the pattern' do
|
98
|
-
|
99
|
-
|
100
|
-
it { should_not respond_to(:published_date) }
|
101
|
-
it { should_not respond_to(:not_published_date) }
|
97
|
+
it { expect(Event).to_not respond_to(:published_date) }
|
98
|
+
it { expect(Event).to_not respond_to(:not_published_date) }
|
102
99
|
end
|
103
100
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Microscope::Scope::DatetimeScope do
|
4
|
-
subject { Event }
|
5
|
-
|
6
4
|
before do
|
7
5
|
run_migration do
|
8
6
|
create_table(:events, force: true) do |t|
|
@@ -80,24 +78,23 @@ describe Microscope::Scope::DatetimeScope do
|
|
80
78
|
end
|
81
79
|
|
82
80
|
it { expect(Event.not_started.to_a).to eql [@event1, @event2] }
|
81
|
+
it { expect(Event.unstarted.to_a).to eql Event.not_started.to_a }
|
83
82
|
end
|
84
83
|
|
85
84
|
describe 'boolean instance method' do
|
86
85
|
context 'for positive record' do
|
87
|
-
|
88
|
-
it {
|
86
|
+
let(:event) { Event.create(started_at: 3.months.ago) }
|
87
|
+
it { expect(event).to be_started }
|
89
88
|
end
|
90
89
|
|
91
90
|
context 'for negative record' do
|
92
|
-
|
93
|
-
it {
|
91
|
+
let(:event) { Event.create(started_at: 2.months.from_now) }
|
92
|
+
it { expect(event).to_not be_started }
|
94
93
|
end
|
95
94
|
end
|
96
95
|
|
97
96
|
context 'for field that does not match the pattern' do
|
98
|
-
|
99
|
-
|
100
|
-
it { should_not respond_to(:published_date) }
|
101
|
-
it { should_not respond_to(:not_published_date) }
|
97
|
+
it { expect(Event).to_not respond_to(:published_date) }
|
98
|
+
it { expect(Event).to_not respond_to(:not_published_date) }
|
102
99
|
end
|
103
100
|
end
|
data/spec/microscope_spec.rb
CHANGED
@@ -2,8 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Microscope do
|
4
4
|
describe :acts_as_microscope do
|
5
|
-
subject { User }
|
6
|
-
|
7
5
|
before do
|
8
6
|
run_migration do
|
9
7
|
create_table(:users, force: true) do |t|
|
@@ -28,32 +26,32 @@ describe Microscope do
|
|
28
26
|
microscope 'User', except: [:admin, :removed_at, :ended_on]
|
29
27
|
end
|
30
28
|
|
31
|
-
it {
|
32
|
-
it {
|
33
|
-
it {
|
34
|
-
it {
|
35
|
-
it {
|
36
|
-
it {
|
37
|
-
it {
|
38
|
-
it {
|
39
|
-
it {
|
40
|
-
it {
|
41
|
-
it {
|
42
|
-
it {
|
43
|
-
it {
|
44
|
-
it {
|
29
|
+
it { expect(User).to respond_to :active }
|
30
|
+
it { expect(User).to respond_to :not_active }
|
31
|
+
it { expect(User).to respond_to :moderator }
|
32
|
+
it { expect(User).to respond_to :not_moderator }
|
33
|
+
it { expect(User).to_not respond_to :admin }
|
34
|
+
it { expect(User).to_not respond_to :not_admin }
|
35
|
+
it { expect(User).to respond_to :published }
|
36
|
+
it { expect(User).to respond_to :not_published }
|
37
|
+
it { expect(User).to_not respond_to :removed }
|
38
|
+
it { expect(User).to_not respond_to :not_removed }
|
39
|
+
it { expect(User).to respond_to :started }
|
40
|
+
it { expect(User).to respond_to :not_started }
|
41
|
+
it { expect(User).to_not respond_to :ended }
|
42
|
+
it { expect(User).to_not respond_to :not_ended }
|
45
43
|
|
46
44
|
context 'for single instance' do
|
47
|
-
|
48
|
-
|
49
|
-
it {
|
50
|
-
it {
|
51
|
-
it {
|
52
|
-
it {
|
53
|
-
it {
|
54
|
-
it {
|
55
|
-
it {
|
56
|
-
it {
|
45
|
+
let(:user) { User.new }
|
46
|
+
|
47
|
+
it { expect(user).to respond_to :published? }
|
48
|
+
it { expect(user).to respond_to :not_published? }
|
49
|
+
it { expect(user).to_not respond_to :removed? }
|
50
|
+
it { expect(user).to_not respond_to :not_removed? }
|
51
|
+
it { expect(user).to respond_to :started? }
|
52
|
+
it { expect(user).to respond_to :not_started? }
|
53
|
+
it { expect(user).to_not respond_to :ended? }
|
54
|
+
it { expect(user).to_not respond_to :not_ended? }
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
@@ -62,32 +60,32 @@ describe Microscope do
|
|
62
60
|
microscope 'User', only: [:admin, :removed_at, :ended_on]
|
63
61
|
end
|
64
62
|
|
65
|
-
it {
|
66
|
-
it {
|
67
|
-
it {
|
68
|
-
it {
|
69
|
-
it {
|
70
|
-
it {
|
71
|
-
it {
|
72
|
-
it {
|
73
|
-
it {
|
74
|
-
it {
|
75
|
-
it {
|
76
|
-
it {
|
77
|
-
it {
|
78
|
-
it {
|
63
|
+
it { expect(User).to_not respond_to :active }
|
64
|
+
it { expect(User).to_not respond_to :not_active }
|
65
|
+
it { expect(User).to_not respond_to :moderator }
|
66
|
+
it { expect(User).to_not respond_to :not_moderator }
|
67
|
+
it { expect(User).to respond_to :admin }
|
68
|
+
it { expect(User).to respond_to :not_admin }
|
69
|
+
it { expect(User).to_not respond_to :published }
|
70
|
+
it { expect(User).to_not respond_to :not_published }
|
71
|
+
it { expect(User).to respond_to :removed }
|
72
|
+
it { expect(User).to respond_to :not_removed }
|
73
|
+
it { expect(User).to_not respond_to :started }
|
74
|
+
it { expect(User).to_not respond_to :not_started }
|
75
|
+
it { expect(User).to respond_to :ended }
|
76
|
+
it { expect(User).to respond_to :not_ended }
|
79
77
|
|
80
78
|
context 'for single instance' do
|
81
|
-
|
82
|
-
|
83
|
-
it {
|
84
|
-
it {
|
85
|
-
it {
|
86
|
-
it {
|
87
|
-
it {
|
88
|
-
it {
|
89
|
-
it {
|
90
|
-
it {
|
79
|
+
let(:user) { User.new }
|
80
|
+
|
81
|
+
it { expect(user).to respond_to :removed? }
|
82
|
+
it { expect(user).to respond_to :not_removed? }
|
83
|
+
it { expect(user).to_not respond_to :published? }
|
84
|
+
it { expect(user).to_not respond_to :not_published? }
|
85
|
+
it { expect(user).to respond_to :ended? }
|
86
|
+
it { expect(user).to respond_to :not_ended? }
|
87
|
+
it { expect(user).to_not respond_to :started? }
|
88
|
+
it { expect(user).to_not respond_to :not_started? }
|
91
89
|
end
|
92
90
|
end
|
93
91
|
|
@@ -96,32 +94,32 @@ describe Microscope do
|
|
96
94
|
microscope 'User', only: [:admin, :started_on], except: [:active]
|
97
95
|
end
|
98
96
|
|
99
|
-
it {
|
100
|
-
it {
|
101
|
-
it {
|
102
|
-
it {
|
103
|
-
it {
|
104
|
-
it {
|
105
|
-
it {
|
106
|
-
it {
|
107
|
-
it {
|
108
|
-
it {
|
109
|
-
it {
|
110
|
-
it {
|
111
|
-
it {
|
112
|
-
it {
|
97
|
+
it { expect(User).to_not respond_to :active }
|
98
|
+
it { expect(User).to_not respond_to :not_active }
|
99
|
+
it { expect(User).to_not respond_to :moderator }
|
100
|
+
it { expect(User).to_not respond_to :not_moderator }
|
101
|
+
it { expect(User).to respond_to :admin }
|
102
|
+
it { expect(User).to respond_to :not_admin }
|
103
|
+
it { expect(User).to respond_to :started }
|
104
|
+
it { expect(User).to respond_to :not_started }
|
105
|
+
it { expect(User).to_not respond_to :published }
|
106
|
+
it { expect(User).to_not respond_to :not_published }
|
107
|
+
it { expect(User).to_not respond_to :removed }
|
108
|
+
it { expect(User).to_not respond_to :not_removed }
|
109
|
+
it { expect(User).to_not respond_to :ended }
|
110
|
+
it { expect(User).to_not respond_to :not_ended }
|
113
111
|
|
114
112
|
context 'for single instance' do
|
115
|
-
|
116
|
-
|
117
|
-
it {
|
118
|
-
it {
|
119
|
-
it {
|
120
|
-
it {
|
121
|
-
it {
|
122
|
-
it {
|
123
|
-
it {
|
124
|
-
it {
|
113
|
+
let(:user) { User.new }
|
114
|
+
|
115
|
+
it { expect(user).to respond_to :started? }
|
116
|
+
it { expect(user).to respond_to :not_started? }
|
117
|
+
it { expect(user).to_not respond_to :removed? }
|
118
|
+
it { expect(user).to_not respond_to :not_removed? }
|
119
|
+
it { expect(user).to_not respond_to :published? }
|
120
|
+
it { expect(user).to_not respond_to :not_published? }
|
121
|
+
it { expect(user).to_not respond_to :ended? }
|
122
|
+
it { expect(user).to_not respond_to :not_ended? }
|
125
123
|
end
|
126
124
|
end
|
127
125
|
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.
|
4
|
+
version: 0.5.8
|
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-
|
12
|
+
date: 2014-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|