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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c7c3c6f9e427418e76e0be7e7a5f14fe6cc669b
4
- data.tar.gz: 1ce6c0bf3dec5650c89f3016f27bd3735840808b
3
+ metadata.gz: 60b73b1325558e48f2447ef0632539a6dbbc4e58
4
+ data.tar.gz: 17fd79a36fc52445ef884ee478d38dd7d52f0e43
5
5
  SHA512:
6
- metadata.gz: f53d6173f69d9da373f3632bb406a002ff55417ef7f1adba46eb01e5c6ff2576f6eb9d7101d2a9388ec2c2652d65166b09c2d2d2cf2941c659e17ce1a04ecc31
7
- data.tar.gz: 6a9eaf01f40faf8866608e8f03c1b0579702f8f92f18fbe3d1e5d82caeac436b57aaa1a325a9e89cbc3284000fe738dce3d2e72a87138afec123ed8a21e8bc25
6
+ metadata.gz: 97ce3a52507bcd0ac44192f4f1b8c56b237eb5282cc2dd019785d2ee24b7af29067ab93eb12ca871fc848c660f60da7f1960ace71230cb7901ae0fd1c30d7b65
7
+ data.tar.gz: cef1710d60cc88e08622c00207d6a2ad021c393a04b877e42d9c7c7b5d5ca6ca2912e3baaffa9115c61c4c716f4067b7c8066b89d9a4c404ccd56e346627d27b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ - 1.2.1
2
+ - Altered model matchers to be more robust against non-ActiveRecord objects.
3
+
1
4
  - 1.2.0
2
5
  - Updated model descriptions and failure messages.
3
6
 
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
- #### belongs_to(association)
77
+ #### belong_to(association)
78
78
 
79
- Ensures that a `belongs_to` association is present:
79
+ Ensures that a `belong_to` association is present:
80
80
 
81
81
  ```ruby
82
- specify { expect(comment).to belongs_to(:post) }
82
+ specify { expect(comment).to belong_to(:post) }
83
83
  ```
84
84
 
85
85
  Works with either model classes or model objects.
@@ -24,11 +24,11 @@
24
24
  def failure_message_when_negated
25
25
  "expected #{model_name} to not #{description}"
26
26
  end
27
-
27
+
28
28
  private
29
29
 
30
30
  def attributes
31
- model.column_names.map(&:to_sym)
31
+ model.attribute_names.map(&:to_sym)
32
32
  end
33
33
  end
34
34
 
@@ -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 << ActiveModel::Validations::AbsenceValidator
17
+ VALIDATORS[:absence] = [ActiveModel::Validations::AbsenceValidator]
18
18
  end
19
19
 
20
20
  if defined?(ActiveRecord)
21
- VALIDATORS.concat [
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.delete(ActiveModel::Validations::PresenceValidator)
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, :validator_class, :validator_options, :display_options
34
+ attr_reader :attr_name, :validator_classes, :validator_options, :display_options
36
35
 
37
- def initialize(attr_name, validator_class, validator_options, display_options)
36
+ def initialize(attr_name, validator_classes, validator_options, display_options)
38
37
  @attr_name = attr_name
39
- @validator_class = validator_class
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 #{validator_class.name} on :#{attr_name}"
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
- validator_name = validator.name.match(/::(?<name>\w+)Validator/)[:name].underscore.to_sym
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 validator_name
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, validator, options, display_options)
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
@@ -2,7 +2,7 @@ module Warp
2
2
  module VERSION
3
3
  MAJOR = 1
4
4
  MINOR = 2
5
- PATCH = 0
5
+ PATCH = 1
6
6
 
7
7
  BETA = nil
8
8
 
@@ -14,6 +14,10 @@ module ModelHelpers
14
14
  @columns ||= []
15
15
  end
16
16
 
17
+ def self.attribute_names
18
+ @columns.map(&:name)
19
+ end
20
+
17
21
  def self.attribute_method?(method)
18
22
  method = method.to_s.sub("=", "")
19
23
  columns.any? {|c| c.name == method }
@@ -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(:validator_name) { matcher.validator_class.name }
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 #{validator_name} on :#{attr_name}" }
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 #{validator_name} on :#{attr_name}" }
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 #{validator_name} on :#{attr_name} with options #{matcher_options.inspect}" }
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 #{validator_name} on :#{attr_name} with options #{matcher_options.inspect}" }
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 #{validator_name} on :#{attr_name} with options #{matcher_options.inspect}" }
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.0
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-12 00:00:00.000000000 Z
11
+ date: 2014-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec