schema_expectations 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd5eeeafd64927fadc0781314d97e9c104efcc63
4
- data.tar.gz: 67ea5f0dec0ac25d66dadc768a233e3446f961a1
3
+ metadata.gz: de04e4a86866e356d2225b0b4236407b34a0795c
4
+ data.tar.gz: 5127ab4ef41da535ff54de06928081ca9c887e63
5
5
  SHA512:
6
- metadata.gz: 746d0312374307e14a451bd7186d6561c99de12d7247728fcdec00e8bda23976ee330046c33b90ef90fdd24ae03c09733a9933d0e62be52e0e79ef18512e20cc
7
- data.tar.gz: 1cec0c037a5ea1fbb5dd6fa0b21c5f6914f104b55cb9a38a45dde97895247c501ba3acd269f20a635cfd8b1958819c0a282b9c474e385803ed00641e6ab422bd
6
+ metadata.gz: 35aa646038fd59a9e88c76d6f8698a5669a0c602f37eaad56e95c772059bfe1de37087253726f15c7301c5b8f5abec6ba00fcedbb620dfe1480995008975d129
7
+ data.tar.gz: 71f5edb70e04ea2ab32c47c09ffd2132798ee8f57be0454481c2a7d0559a883051bb747a4ea65d9098fffbf495f22242deb3527410446ca1df583a1207988f49
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # Schema Expectations Changelog
2
2
 
3
3
  ### git master
4
+
5
+ ### 0.4.0 (Febuary 20, 2015)
6
+
7
+ - include matchers in non-model specs as well
8
+ - include model names in failure messages
9
+ - fixed a bug in column reflector (test class name was used directly)
10
+
11
+ ### 0.3.0 (Febuary 20, 2015)
12
+
4
13
  - added `validate_schema_uniqueness`
5
14
 
6
15
  ### 0.2.0 (Febuary 18, 2015)
data/TODO.md ADDED
@@ -0,0 +1,2 @@
1
+ - `validates :attribute, if: :attribute_changed?` should have an exception as not conditional
2
+ - `:absence` validation should absolve a model of needing uniqueness validation on the relevant column
@@ -89,7 +89,7 @@ module SchemaExpectations
89
89
  end
90
90
 
91
91
  def all_timestamp_attributes
92
- @all_timestamp_attributes ||= Record.new.send(:all_timestamp_attributes).map(&:to_sym)
92
+ @all_timestamp_attributes ||= @model.new.send(:all_timestamp_attributes).map(&:to_sym)
93
93
  end
94
94
 
95
95
  def unique_indexes
@@ -2,5 +2,5 @@ require 'rspec/core'
2
2
  require 'schema_expectations/rspec_matchers'
3
3
 
4
4
  RSpec.configure do |config|
5
- config.include SchemaExpectations::RSpecMatchers, type: :model
5
+ config.include SchemaExpectations::RSpecMatchers
6
6
  end
@@ -53,16 +53,16 @@ module SchemaExpectations
53
53
  errors = []
54
54
 
55
55
  (@present_column_names - @not_null_column_names).each do |column_name|
56
- errors << "#{column_name} has unconditional presence validation but is missing NOT NULL"
56
+ errors << "#{@model.name} #{column_name} has unconditional presence validation but is missing NOT NULL"
57
57
  end
58
58
 
59
59
  (@not_null_column_names - @present_column_names).each do |column_name|
60
60
  conditions = validator_allow_nil_conditions_for_column_name(column_name) ||
61
61
  validator_conditions_for_column_name(column_name)
62
62
  if conditions
63
- errors << "#{column_name} is NOT NULL but its presence validator was conditional: #{conditions.inspect}"
63
+ errors << "#{@model.name} #{column_name} is NOT NULL but its presence validator was conditional: #{conditions.inspect}"
64
64
  else
65
- errors << "#{column_name} is NOT NULL but has no presence validation"
65
+ errors << "#{@model.name} #{column_name} is NOT NULL but has no presence validation"
66
66
  end
67
67
  end
68
68
 
@@ -70,7 +70,7 @@ module SchemaExpectations
70
70
  end
71
71
 
72
72
  def failure_message_when_negated
73
- 'should not match NOT NULL with its presence validation but does'
73
+ "#{@model.name} should not match NOT NULL with its presence validation but does"
74
74
  end
75
75
 
76
76
  def description
@@ -57,16 +57,16 @@ module SchemaExpectations
57
57
  errors = []
58
58
 
59
59
  (@validator_unique_scopes - @schema_unique_scopes).each do |scope|
60
- errors << "scope #{scope.inspect} has unconditional uniqueness validation but is missing a unique database index"
60
+ errors << "#{@model.name} scope #{scope.inspect} has unconditional uniqueness validation but is missing a unique database index"
61
61
  end
62
62
 
63
63
  (@schema_unique_scopes - @validator_unique_scopes).each do |scope|
64
64
  conditions = validator_conditions_for_scope(scope) ||
65
65
  validator_allow_empty_conditions_for_scope(scope)
66
66
  if conditions
67
- errors << "scope #{scope.inspect} has a unique index but its uniqueness validator was conditional: #{conditions.inspect}"
67
+ errors << "#{@model.name} scope #{scope.inspect} has a unique index but its uniqueness validator was conditional: #{conditions.inspect}"
68
68
  else
69
- errors << "scope #{scope.inspect} has a unique index but no uniqueness validation"
69
+ errors << "#{@model.name} scope #{scope.inspect} has a unique index but no uniqueness validation"
70
70
  end
71
71
  end
72
72
 
@@ -74,7 +74,7 @@ module SchemaExpectations
74
74
  end
75
75
 
76
76
  def failure_message_when_negated
77
- 'should not match unique indexes with its uniqueness validation but does'
77
+ "#{@model.name} should not match unique indexes with its uniqueness validation but does"
78
78
  end
79
79
 
80
80
  def description
@@ -1,3 +1,3 @@
1
1
  module SchemaExpectations
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -37,7 +37,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaNullableMatcher, :acti
37
37
  end.to raise_error do |error|
38
38
  expect(error).to be_a RSpec::Expectations::ExpectationNotMetError
39
39
  not_null_columns.sort.zip(error.message.split(', ')) do |column, message|
40
- expect(message).to eq "#{column} is NOT NULL but has no presence validation"
40
+ expect(message).to eq "Record #{column} is NOT NULL but has no presence validation"
41
41
  end
42
42
  end
43
43
  end
@@ -86,11 +86,11 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaNullableMatcher, :acti
86
86
  errors = error.message.split(', ')
87
87
 
88
88
  nullable_columns.sort.zip(errors.take(nullable_columns.size)) do |column, message|
89
- expect(message).to eq "#{column} has unconditional presence validation but is missing NOT NULL"
89
+ expect(message).to eq "Record #{column} has unconditional presence validation but is missing NOT NULL"
90
90
  end
91
91
 
92
92
  not_null_columns.sort.zip(errors.drop(nullable_columns.size)) do |column, message|
93
- expect(message).to eq "#{column} is NOT NULL but has no presence validation"
93
+ expect(message).to eq "Record #{column} is NOT NULL but has no presence validation"
94
94
  end
95
95
  end
96
96
  end
@@ -122,7 +122,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaNullableMatcher, :acti
122
122
  end.to raise_error do |error|
123
123
  expect(error).to be_a RSpec::Expectations::ExpectationNotMetError
124
124
  nullable_columns.sort.zip(error.message.split(', ')) do |column, message|
125
- expect(message).to eq "#{column} has unconditional presence validation but is missing NOT NULL"
125
+ expect(message).to eq "Record #{column} has unconditional presence validation but is missing NOT NULL"
126
126
  end
127
127
  end
128
128
  end
@@ -145,7 +145,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaNullableMatcher, :acti
145
145
 
146
146
  expect do
147
147
  is_expected.to_not validate_schema_nullable
148
- end.to raise_error 'should not match NOT NULL with its presence validation but does'
148
+ end.to raise_error 'Record should not match NOT NULL with its presence validation but does'
149
149
  end
150
150
 
151
151
  specify 'when primary_key is not id' do
@@ -180,7 +180,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaNullableMatcher, :acti
180
180
  end.to raise_error do |error|
181
181
  expect(error).to be_a RSpec::Expectations::ExpectationNotMetError
182
182
  not_null_columns.sort.zip(error.message.split(', ')) do |column, message|
183
- expect(message).to eq "#{column} is NOT NULL but its presence validator was conditional: {:on=>:create}"
183
+ expect(message).to eq "Record #{column} is NOT NULL but its presence validator was conditional: {:on=>:create}"
184
184
  end
185
185
  end
186
186
  end
@@ -193,7 +193,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaNullableMatcher, :acti
193
193
  end.to raise_error do |error|
194
194
  expect(error).to be_a RSpec::Expectations::ExpectationNotMetError
195
195
  not_null_columns.sort.zip(error.message.split(', ')) do |column, message|
196
- expect(message).to match /\A#{column} is NOT NULL but its presence validator was conditional: {:if=>\#<Proc:.*>}\z/
196
+ expect(message).to match /\ARecord #{column} is NOT NULL but its presence validator was conditional: {:if=>\#<Proc:.*>}\z/
197
197
  end
198
198
  end
199
199
  end
@@ -206,7 +206,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaNullableMatcher, :acti
206
206
  end.to raise_error do |error|
207
207
  expect(error).to be_a RSpec::Expectations::ExpectationNotMetError
208
208
  not_null_columns.sort.zip(error.message.split(', ')) do |column, message|
209
- expect(message).to match /\A#{column} is NOT NULL but its presence validator was conditional: {:unless=>\#<Proc:.*>}\z/
209
+ expect(message).to match /\ARecord #{column} is NOT NULL but its presence validator was conditional: {:unless=>\#<Proc:.*>}\z/
210
210
  end
211
211
  end
212
212
  end
@@ -219,7 +219,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaNullableMatcher, :acti
219
219
  end.to raise_error do |error|
220
220
  expect(error).to be_a RSpec::Expectations::ExpectationNotMetError
221
221
  not_null_columns.sort.zip(error.message.split(', ')) do |column, message|
222
- expect(message).to eq "#{column} is NOT NULL but its presence validator was conditional: {:allow_nil=>true}"
222
+ expect(message).to eq "Record #{column} is NOT NULL but its presence validator was conditional: {:allow_nil=>true}"
223
223
  end
224
224
  end
225
225
  end
@@ -232,7 +232,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaNullableMatcher, :acti
232
232
  end.to raise_error do |error|
233
233
  expect(error).to be_a RSpec::Expectations::ExpectationNotMetError
234
234
  not_null_columns.sort.zip(error.message.split(', ')) do |column, message|
235
- expect(message).to eq "#{column} is NOT NULL but its presence validator was conditional: {:allow_blank=>true}"
235
+ expect(message).to eq "Record #{column} is NOT NULL but its presence validator was conditional: {:allow_blank=>true}"
236
236
  end
237
237
  end
238
238
  end
@@ -34,7 +34,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaUniquenessMatcher, :ac
34
34
  specify 'error messages' do
35
35
  expect { is_expected.to validate_schema_uniqueness }.to(
36
36
  raise_error(RSpec::Expectations::ExpectationNotMetError,
37
- "scope #{unique_scope.inspect} has a unique index but no uniqueness validation")
37
+ "Record scope #{unique_scope.inspect} has a unique index but no uniqueness validation")
38
38
  )
39
39
  end
40
40
 
@@ -81,7 +81,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaUniquenessMatcher, :ac
81
81
  specify 'error messages' do
82
82
  expect { is_expected.to validate_schema_uniqueness }.to(
83
83
  raise_error(RSpec::Expectations::ExpectationNotMetError,
84
- "scope [:index_not_unique] has unconditional uniqueness validation but is missing a unique database index")
84
+ "Record scope [:index_not_unique] has unconditional uniqueness validation but is missing a unique database index")
85
85
  )
86
86
  end
87
87
 
@@ -107,7 +107,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaUniquenessMatcher, :ac
107
107
  specify 'error messages' do
108
108
  expect { is_expected.to validate_schema_uniqueness }.to(
109
109
  raise_error(RSpec::Expectations::ExpectationNotMetError,
110
- "scope [:no_index] has unconditional uniqueness validation but is missing a unique database index")
110
+ "Record scope [:no_index] has unconditional uniqueness validation but is missing a unique database index")
111
111
  )
112
112
  end
113
113
 
@@ -127,7 +127,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaUniquenessMatcher, :ac
127
127
 
128
128
  expect do
129
129
  is_expected.to_not validate_schema_uniqueness
130
- end.to raise_error 'should not match unique indexes with its uniqueness validation but does'
130
+ end.to raise_error 'Record should not match unique indexes with its uniqueness validation but does'
131
131
  end
132
132
 
133
133
  specify 'allows validators with allow_nil: true' do
@@ -142,7 +142,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaUniquenessMatcher, :ac
142
142
 
143
143
  expect { is_expected.to validate_schema_uniqueness }.to(
144
144
  raise_error(RSpec::Expectations::ExpectationNotMetError,
145
- "scope #{unique_scope.inspect} has a unique index but its uniqueness validator was conditional: {:on=>:create}")
145
+ "Record scope #{unique_scope.inspect} has a unique index but its uniqueness validator was conditional: {:on=>:create}")
146
146
  )
147
147
  end
148
148
 
@@ -151,7 +151,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaUniquenessMatcher, :ac
151
151
 
152
152
  expect { is_expected.to validate_schema_uniqueness }.to(
153
153
  raise_error(RSpec::Expectations::ExpectationNotMetError,
154
- /\Ascope #{Regexp.escape(unique_scope.inspect)} has a unique index but its uniqueness validator was conditional: {:if=>\#<Proc:.*>}\z/)
154
+ /\ARecord scope #{Regexp.escape(unique_scope.inspect)} has a unique index but its uniqueness validator was conditional: {:if=>\#<Proc:.*>}\z/)
155
155
  )
156
156
  end
157
157
 
@@ -160,7 +160,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaUniquenessMatcher, :ac
160
160
 
161
161
  expect { is_expected.to validate_schema_uniqueness }.to(
162
162
  raise_error(RSpec::Expectations::ExpectationNotMetError,
163
- /\Ascope #{Regexp.escape(unique_scope.inspect)} has a unique index but its uniqueness validator was conditional: {:unless=>\#<Proc:.*>}\z/)
163
+ /\ARecord scope #{Regexp.escape(unique_scope.inspect)} has a unique index but its uniqueness validator was conditional: {:unless=>\#<Proc:.*>}\z/)
164
164
  )
165
165
  end
166
166
 
@@ -169,7 +169,7 @@ describe SchemaExpectations::RSpecMatchers::ValidateSchemaUniquenessMatcher, :ac
169
169
 
170
170
  expect { is_expected.to validate_schema_uniqueness }.to(
171
171
  raise_error(RSpec::Expectations::ExpectationNotMetError,
172
- "scope #{unique_scope.inspect} has a unique index but its uniqueness validator was conditional: {:allow_blank=>true}")
172
+ "Record scope #{unique_scope.inspect} has a unique index but its uniqueness validator was conditional: {:allow_blank=>true}")
173
173
  )
174
174
  end
175
175
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_expectations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emma Borhanian
@@ -262,6 +262,7 @@ files:
262
262
  - MIT-LICENSE
263
263
  - README.md
264
264
  - Rakefile
265
+ - TODO.md
265
266
  - gemfiles/activerecord_3.1.gemfile
266
267
  - gemfiles/activerecord_3.2.gemfile
267
268
  - gemfiles/activerecord_4.0.gemfile