mongoid-rspec-callbacks-dazzl 1.0.0.pre.892077720 → 1.0.0.pre.892495119
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/matchers/delegates.rb +66 -0
- data/lib/mongoid_rspec_callbacks_dazzl.rb +1 -0
- data/spec/member_spec.rb +8 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/studio_spec.rb +1 -0
- data/spec/support/models/band.rb +3 -0
- data/spec/support/models/member.rb +12 -0
- data/spec/support/models/studio.rb +2 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d5d7309afc9501cfe6867dcca64f286c5d0ae20e8a16bc18582a4dd29bf4f0c
|
4
|
+
data.tar.gz: fa1e1e3ec307422e0af1b6b7ec09de79706e8ed6f7c4324edee2a82e9bfe0202
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57b8400a7530eff80577b9ad9b21f727c84d2a7c3e40955cd898808f50d3ca1ffeb1944c4ea0b9465335d3bca6c539e43ebf2d35fa4fb69f593e3a82c572e36e
|
7
|
+
data.tar.gz: 49cb58da1ae06fdd36d17baf119da34779bda8abc351b60986b29439c68f90f631939f470cec22d5f80302c9f50d31acc6f5ea16e7f2e2462946043b5d0122f3
|
data/README.md
CHANGED
@@ -63,3 +63,12 @@ describe User do
|
|
63
63
|
:send_email_to_subscribers) }
|
64
64
|
end
|
65
65
|
```
|
66
|
+
|
67
|
+
## delegate Matchers
|
68
|
+
|
69
|
+
```
|
70
|
+
describe User do
|
71
|
+
it { is_expected.to delegate(:name).to(:author) }
|
72
|
+
it { is_expected.to delegate(:day).to(:created_at).with_prefix(:date) }
|
73
|
+
end
|
74
|
+
```
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mongoid
|
4
|
+
module Matchers
|
5
|
+
# Create an matcher for delegate method
|
6
|
+
#
|
7
|
+
# Usage:
|
8
|
+
#
|
9
|
+
# it { is_expected.to delegate(:name).to(:author) }
|
10
|
+
# it { is_expected.to delegate(:day).to(:created_at).with_prefix(:date) }
|
11
|
+
class HaveDelegateMatcher
|
12
|
+
# Set methods to look for
|
13
|
+
def initialize(*args)
|
14
|
+
@delegated = args[0]
|
15
|
+
@method = @delegated
|
16
|
+
end
|
17
|
+
|
18
|
+
def to(to)
|
19
|
+
@to = to
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def with_prefix(prefix)
|
24
|
+
@prefix = prefix
|
25
|
+
@method = :"#{@prefix}_#{@method}"
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def matches?(klass)
|
30
|
+
@delegator = klass
|
31
|
+
@delegator.methods.include?(@method)
|
32
|
+
end
|
33
|
+
|
34
|
+
def description
|
35
|
+
"delegate : #{@method}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def failure_message
|
39
|
+
"expected #{@delegator} have delegator #{_method}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def failure_message_when_negated
|
43
|
+
"expected #{@delegator} have not to delegator :#{@method} #{prefix?}"
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def _method
|
49
|
+
if @prefix
|
50
|
+
":#{@delegated} with prefix :#{@prefix}"
|
51
|
+
else
|
52
|
+
":#{@delegated}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def prefix?
|
57
|
+
@prefix ? ' with prefix' : ''
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def delegate(*args)
|
62
|
+
p "Args : #{args}"
|
63
|
+
HaveDelegateMatcher.new(*args)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/member_spec.rb
ADDED
data/spec/spec_helper.rb
CHANGED
data/spec/studio_spec.rb
CHANGED
@@ -5,4 +5,5 @@ require 'spec_helper'
|
|
5
5
|
describe Studio do
|
6
6
|
it { is_expected.to association_callback(:has_many, :remove, :after, :send_notification_subscribers) }
|
7
7
|
it { is_expected.to association_callback(:has_many, :remove, :before, :send_notification_unsubscribers) }
|
8
|
+
it { is_expected.to delegate(:leader).to(:band) }
|
8
9
|
end
|
data/spec/support/models/band.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Member
|
4
|
+
include Mongoid::Document
|
5
|
+
include Mongoid::Timestamps
|
6
|
+
|
7
|
+
delegate :day, prefix: 'date', to: :created_at
|
8
|
+
delegate :lastday, prefix: 'update', to: :updated_at
|
9
|
+
|
10
|
+
belongs_to :band
|
11
|
+
belongs_to :leader, class_name: 'band'
|
12
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-rspec-callbacks-dazzl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.
|
4
|
+
version: 1.0.0.pre.892495119
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VAILLANT Jeremy
|
@@ -213,14 +213,17 @@ files:
|
|
213
213
|
- Rakefile
|
214
214
|
- lib/matchers/association_callbacks.rb
|
215
215
|
- lib/matchers/callbacks.rb
|
216
|
+
- lib/matchers/delegates.rb
|
216
217
|
- lib/matchers/set_callbacks.rb
|
217
218
|
- lib/mongoid-rspec-callbacks-dazzl/info.rb
|
218
219
|
- lib/mongoid_rspec_callbacks_dazzl.rb
|
219
220
|
- spec/band_spec.rb
|
221
|
+
- spec/member_spec.rb
|
220
222
|
- spec/profile_spec.rb
|
221
223
|
- spec/spec_helper.rb
|
222
224
|
- spec/studio_spec.rb
|
223
225
|
- spec/support/models/band.rb
|
226
|
+
- spec/support/models/member.rb
|
224
227
|
- spec/support/models/profile.rb
|
225
228
|
- spec/support/models/studio.rb
|
226
229
|
- spec/support/models/user.rb
|