foreign_key_validation 1.1.0 → 1.1.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 +8 -8
- data/README.md +3 -2
- data/lib/foreign_key_validation/collector.rb +1 -3
- data/lib/foreign_key_validation/version.rb +1 -1
- data/lib/foreign_key_validation.rb +3 -2
- data/spec/config_spec.rb +28 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjZkZDY5NzBlNGQ2ZTQ0MThkMjc5OWY4MGU3ZDVjZDVkMTg5NjdiNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmU5Y2NmNGQ3M2YyNjFlOWI4YmI3M2JlZTZhYTM3NDA0MWU0NzFmYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmY4NTllNGJhZTc0ODhlNmE0YjM3ZmYyNWU0OTZhMDQzOGYwMzVjZDkwYzIy
|
10
|
+
Y2VhOWNiZGE4MDczNTU4OGRlYWZmNmY0ODQ0YTU1ZmU5Mjg4MDZjNDY4NGNk
|
11
|
+
ZDM4NjgxYzM4NDQwODk1NzlmYWZkNzRkYmQ5NDczMzYzNGU4Y2Y=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2QwMTRkNzg4ZWE5MjVmOTc3N2I4NTM1YTk5OTg2Zjk4N2VkODE0OTJlYWYx
|
14
|
+
ODUxOTdjMDBhZWNmMzcwNmJiZGExOTI0MTExY2I0NGZmYTU1MzBiNDkwZmE4
|
15
|
+
MWE0MTM1YmJhYmFlODMzM2FlNzZiZGEwYTM4MmRmOGVhNDNhN2E=
|
data/README.md
CHANGED
@@ -37,11 +37,12 @@ This would only check `model.project.admin_user_id` to match `model.admin_user_i
|
|
37
37
|
|
38
38
|
## Configuration
|
39
39
|
|
40
|
-
You can customize the behaviour of the gem by calling the `configure` method on the module with a block (e.g. initializer).
|
40
|
+
You can customize the default behaviour of the gem by calling the `configure` method on the module with a block (e.g. initializer).
|
41
41
|
|
42
42
|
ForeignKeyValidation.configure do |config|
|
43
43
|
config.error_message = proc { |key, name, object| "My custom msg!" }
|
44
|
-
config.inject_subclasses = true
|
44
|
+
config.inject_subclasses = false # default: true
|
45
|
+
config.validate_against = :admin # default: :user
|
45
46
|
end
|
46
47
|
|
47
48
|
## Note
|
@@ -3,8 +3,6 @@ module ForeignKeyValidation
|
|
3
3
|
class Collector
|
4
4
|
attr_accessor :options
|
5
5
|
|
6
|
-
DEFAULT_VALIDATE_AGAINST = :user
|
7
|
-
|
8
6
|
def initialize(opt={})
|
9
7
|
self.options = opt
|
10
8
|
end
|
@@ -21,7 +19,7 @@ module ForeignKeyValidation
|
|
21
19
|
end
|
22
20
|
|
23
21
|
def validate_against
|
24
|
-
@validate_against ||= (options[:on] ||
|
22
|
+
@validate_against ||= (options[:on] || ForeignKeyValidation.configuration.validate_against).to_s
|
25
23
|
end
|
26
24
|
|
27
25
|
def validate_with
|
@@ -10,8 +10,9 @@ module ForeignKeyValidation
|
|
10
10
|
|
11
11
|
DEFAULT_CONFIG = {
|
12
12
|
inject_subclasses: true,
|
13
|
-
|
14
|
-
|
13
|
+
validate_against: :user,
|
14
|
+
error_message: proc { |key, reflection_name, object|
|
15
|
+
"#{key} of #{reflection_name} does not match #{object.class.name.tableize} #{key}."
|
15
16
|
}
|
16
17
|
}
|
17
18
|
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ForeignKeyValidation do
|
4
|
+
|
5
|
+
describe ".configuration" do
|
6
|
+
|
7
|
+
subject { ForeignKeyValidation }
|
8
|
+
|
9
|
+
it "initializes configuration as open struct" do
|
10
|
+
expect(subject.configuration).to be_instance_of OpenStruct
|
11
|
+
end
|
12
|
+
|
13
|
+
it "defaults to true for injecting subclasses" do
|
14
|
+
expect(subject.configuration.inject_subclasses).to eq true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "defaults to proc for error messages" do
|
18
|
+
expect(subject.configuration.error_message).to be_a Proc
|
19
|
+
expect(subject.configuration.error_message.call).to match /does not match/
|
20
|
+
end
|
21
|
+
|
22
|
+
it "defaults to :user for validate against key" do
|
23
|
+
expect(subject.configuration.validate_against).to eq :user
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreign_key_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcus Geißler
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- lib/foreign_key_validation/validator.rb
|
169
169
|
- lib/foreign_key_validation/version.rb
|
170
170
|
- spec/collector/base_spec.rb
|
171
|
+
- spec/config_spec.rb
|
171
172
|
- spec/model_extension/validation_with_config_block_spec.rb
|
172
173
|
- spec/model_extension/validation_with_custom_attrs_spec.rb
|
173
174
|
- spec/model_extension/validation_with_exceptions_spec.rb
|
@@ -205,6 +206,7 @@ specification_version: 4
|
|
205
206
|
summary: Protect the foreign keys in your Rails models.
|
206
207
|
test_files:
|
207
208
|
- spec/collector/base_spec.rb
|
209
|
+
- spec/config_spec.rb
|
208
210
|
- spec/model_extension/validation_with_config_block_spec.rb
|
209
211
|
- spec/model_extension/validation_with_custom_attrs_spec.rb
|
210
212
|
- spec/model_extension/validation_with_exceptions_spec.rb
|