warp 1.2.0 → 1.2.1
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/CHANGELOG.md +3 -0
- data/README.md +3 -3
- data/lib/warp/model_matchers/attribute_matcher.rb +2 -2
- data/lib/warp/model_matchers/validation_matcher.rb +25 -27
- data/lib/warp/version.rb +1 -1
- data/spec/support/model_helpers.rb +4 -0
- data/spec/warp/model_helpers/validation_matcher_spec.rb +6 -6
- 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: 60b73b1325558e48f2447ef0632539a6dbbc4e58
|
4
|
+
data.tar.gz: 17fd79a36fc52445ef884ee478d38dd7d52f0e43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97ce3a52507bcd0ac44192f4f1b8c56b237eb5282cc2dd019785d2ee24b7af29067ab93eb12ca871fc848c660f60da7f1960ace71230cb7901ae0fd1c30d7b65
|
7
|
+
data.tar.gz: cef1710d60cc88e08622c00207d6a2ad021c393a04b877e42d9c7c7b5d5ca6ca2912e3baaffa9115c61c4c716f4067b7c8066b89d9a4c404ccd56e346627d27b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -74,12 +74,12 @@ specify { expect(controller).to set_flash(:notice).to("Your order has been proce
|
|
74
74
|
|
75
75
|
### Association Matchers
|
76
76
|
|
77
|
-
####
|
77
|
+
#### belong_to(association)
|
78
78
|
|
79
|
-
Ensures that a `
|
79
|
+
Ensures that a `belong_to` association is present:
|
80
80
|
|
81
81
|
```ruby
|
82
|
-
specify { expect(comment).to
|
82
|
+
specify { expect(comment).to belong_to(:post) }
|
83
83
|
```
|
84
84
|
|
85
85
|
Works with either model classes or model objects.
|
@@ -1,42 +1,41 @@
|
|
1
1
|
module Warp
|
2
2
|
module ModelMatchers
|
3
3
|
class ValidationMatcher < Warp::ModelMatchers::Matcher
|
4
|
-
VALIDATORS =
|
5
|
-
ActiveModel::Validations::AcceptanceValidator,
|
6
|
-
ActiveModel::Validations::ConfirmationValidator,
|
7
|
-
ActiveModel::Validations::ExclusionValidator,
|
8
|
-
ActiveModel::Validations::FormatValidator,
|
9
|
-
ActiveModel::Validations::InclusionValidator,
|
10
|
-
ActiveModel::Validations::LengthValidator,
|
11
|
-
ActiveModel::Validations::NumericalityValidator,
|
12
|
-
ActiveModel::Validations::PresenceValidator
|
13
|
-
|
4
|
+
VALIDATORS = {
|
5
|
+
acceptance: [ActiveModel::Validations::AcceptanceValidator],
|
6
|
+
confirmation: [ActiveModel::Validations::ConfirmationValidator],
|
7
|
+
exclusion: [ActiveModel::Validations::ExclusionValidator],
|
8
|
+
format: [ActiveModel::Validations::FormatValidator],
|
9
|
+
inclusion: [ActiveModel::Validations::InclusionValidator],
|
10
|
+
length: [ActiveModel::Validations::LengthValidator],
|
11
|
+
numericality: [ActiveModel::Validations::NumericalityValidator],
|
12
|
+
presence: [ActiveModel::Validations::PresenceValidator]
|
13
|
+
}
|
14
14
|
|
15
15
|
# AbsenceValidator added in Rails 4
|
16
16
|
if defined?(ActiveModel::Validations::AbsenceValidator)
|
17
|
-
VALIDATORS
|
17
|
+
VALIDATORS[:absence] = [ActiveModel::Validations::AbsenceValidator]
|
18
18
|
end
|
19
19
|
|
20
20
|
if defined?(ActiveRecord)
|
21
|
-
VALIDATORS.
|
22
|
-
ActiveRecord::Validations::AssociatedValidator,
|
23
|
-
ActiveRecord::Validations::UniquenessValidator
|
24
|
-
|
21
|
+
VALIDATORS.merge!({
|
22
|
+
associated: [ActiveRecord::Validations::AssociatedValidator],
|
23
|
+
uniqueness: [ActiveRecord::Validations::UniquenessValidator]
|
24
|
+
})
|
25
25
|
end
|
26
26
|
|
27
27
|
# In Rails 4 PresenceValidator is subclassed by AR
|
28
28
|
if defined?(ActiveRecord::Validations::PresenceValidator)
|
29
|
-
VALIDATORS
|
30
|
-
VALIDATORS.push(ActiveRecord::Validations::PresenceValidator)
|
29
|
+
VALIDATORS[:presence] << ActiveRecord::Validations::PresenceValidator
|
31
30
|
end
|
32
31
|
|
33
32
|
VALIDATORS.freeze
|
34
33
|
|
35
|
-
attr_reader :attr_name, :
|
34
|
+
attr_reader :attr_name, :validator_classes, :validator_options, :display_options
|
36
35
|
|
37
|
-
def initialize(attr_name,
|
36
|
+
def initialize(attr_name, validator_classes, validator_options, display_options)
|
38
37
|
@attr_name = attr_name
|
39
|
-
@
|
38
|
+
@validator_classes = validator_classes
|
40
39
|
@validator_options = validator_options
|
41
40
|
@display_options = display_options
|
42
41
|
end
|
@@ -45,7 +44,7 @@ module Warp
|
|
45
44
|
@model_or_instance = model_or_instance
|
46
45
|
|
47
46
|
validators.any? do |validator|
|
48
|
-
if values_match?(validator_class, validator.class)
|
47
|
+
if validator_classes.any? {|validator_class| values_match?(validator_class, validator.class) }
|
49
48
|
validator_options.nil? || values_match?(validator_options, validator.options)
|
50
49
|
else
|
51
50
|
false
|
@@ -62,7 +61,7 @@ module Warp
|
|
62
61
|
end
|
63
62
|
|
64
63
|
def description
|
65
|
-
str = "have validator #{
|
64
|
+
str = "have validator #{validator_classes.map(&:name).join(", or ")} on :#{attr_name}"
|
66
65
|
str << " with options #{description_of(display_options)}" if display_options.present?
|
67
66
|
str
|
68
67
|
end
|
@@ -74,15 +73,14 @@ module Warp
|
|
74
73
|
end
|
75
74
|
end
|
76
75
|
|
77
|
-
ValidationMatcher::VALIDATORS.each do |validator|
|
78
|
-
|
79
|
-
method_name = (validator_name == :associated) ? "validate_associated" : "validate_#{validator_name}_of"
|
76
|
+
ValidationMatcher::VALIDATORS.each do |validator, validator_classes|
|
77
|
+
method_name = (validator == :associated) ? "validate_associated" : "validate_#{validator}_of"
|
80
78
|
|
81
79
|
define_method method_name do |attr_name, *options|
|
82
80
|
display_options = options.first
|
83
81
|
options = display_options.try(:dup) || {}
|
84
82
|
|
85
|
-
case
|
83
|
+
case validator
|
86
84
|
when :uniqueness
|
87
85
|
options = {case_sensitive: true}.merge(options)
|
88
86
|
when :acceptance
|
@@ -91,7 +89,7 @@ module Warp
|
|
91
89
|
|
92
90
|
options = nil if options.empty?
|
93
91
|
|
94
|
-
ValidationMatcher.new(attr_name,
|
92
|
+
ValidationMatcher.new(attr_name, validator_classes, options, display_options)
|
95
93
|
end
|
96
94
|
end
|
97
95
|
end
|
data/lib/warp/version.rb
CHANGED
@@ -10,7 +10,7 @@ describe Warp::ModelMatchers::ValidationMatcher do
|
|
10
10
|
let(:matcher) { send(matcher_method, attr_name) }
|
11
11
|
let(:matcher_with_options) { send(matcher_method, attr_name, matcher_options) }
|
12
12
|
|
13
|
-
let(:
|
13
|
+
let(:validator_names) { matcher.validator_classes.map(&:name).join(", or ") }
|
14
14
|
|
15
15
|
with_contexts do
|
16
16
|
context "with model" do
|
@@ -111,7 +111,7 @@ describe Warp::ModelMatchers::ValidationMatcher do
|
|
111
111
|
specify { expect(subject).to_not match(model_or_instance) }
|
112
112
|
|
113
113
|
describe_failure_message do
|
114
|
-
specify { expect(subject).to eq "expected TestModel to have validator #{
|
114
|
+
specify { expect(subject).to eq "expected TestModel to have validator #{validator_names} on :#{attr_name}" }
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -123,7 +123,7 @@ describe Warp::ModelMatchers::ValidationMatcher do
|
|
123
123
|
specify { expect(subject).to match(model_or_instance) }
|
124
124
|
|
125
125
|
describe_failure_message_when_negated do
|
126
|
-
specify { expect(subject).to eq "expected TestModel to not have validator #{
|
126
|
+
specify { expect(subject).to eq "expected TestModel to not have validator #{validator_names} on :#{attr_name}" }
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
@@ -135,7 +135,7 @@ describe Warp::ModelMatchers::ValidationMatcher do
|
|
135
135
|
specify { expect(subject).to_not match(model_or_instance) }
|
136
136
|
|
137
137
|
describe_failure_message do
|
138
|
-
specify { expect(subject).to eq "expected TestModel to have validator #{
|
138
|
+
specify { expect(subject).to eq "expected TestModel to have validator #{validator_names} on :#{attr_name} with options #{matcher_options.inspect}" }
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
@@ -148,7 +148,7 @@ describe Warp::ModelMatchers::ValidationMatcher do
|
|
148
148
|
specify { expect(subject).to_not match(model_or_instance) }
|
149
149
|
|
150
150
|
describe_failure_message do
|
151
|
-
specify { expect(subject).to eq "expected TestModel to have validator #{
|
151
|
+
specify { expect(subject).to eq "expected TestModel to have validator #{validator_names} on :#{attr_name} with options #{matcher_options.inspect}" }
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
@@ -160,7 +160,7 @@ describe Warp::ModelMatchers::ValidationMatcher do
|
|
160
160
|
specify { expect(subject).to match(model_or_instance) }
|
161
161
|
|
162
162
|
describe_failure_message_when_negated do
|
163
|
-
specify { expect(subject).to eq "expected TestModel to not have validator #{
|
163
|
+
specify { expect(subject).to eq "expected TestModel to not have validator #{validator_names} on :#{attr_name} with options #{matcher_options.inspect}" }
|
164
164
|
end
|
165
165
|
end
|
166
166
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Drake-Brockman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|