nested_attributes_uniqueness 0.1.0 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3ec8e669dac67be4f9161042d74a311a8e7b883
4
- data.tar.gz: 4c21d4d03351bf18bdde71f987e5d76e1596035b
3
+ metadata.gz: f071745f7be967c35d40b4d892fc9ae4a1de7426
4
+ data.tar.gz: 74cff35f978dbf9640041d90182be26cd056ee05
5
5
  SHA512:
6
- metadata.gz: 0511876edbe34f270313b475024b624a94e6e9454cd2905b11788b500f582149ad4c44d3ad032c7ed1ba38bcf4b7c695073e13a1aab5424cd6947776b3fd2496
7
- data.tar.gz: 317f3e6b4053c79f478b6d9e00d5cb3b3c508023e01cc3fb9bbf75ff46bd865916917937be8d332ae0a8aa778924afcce3423d81e3652512ba0db1d2b2bd6112
6
+ metadata.gz: a40d64bda765a22ea4f423dea6cd5c5ad279e22008016e38c6553285baafb9844cb7ccd4fbd1d127900d37b7ad27809bf32e2d1b41e8cecb6f422c8a39dbfc98
7
+ data.tar.gz: 8c60f41a079de0c4d5ccbe3d52e0a29b950ad65b661e89d4d9a428b3deab5b96cfba3acb6b5c055f5fd0a7ba716e4040109a4ada0b2cf324b5a05e977f630777
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  NestedAttributesUniqueness
2
2
  -------
3
3
 
4
- This gem provides two class methods `validates_uniqueness_in_memory` and `validates_uniqueness_in_memory_for_tree_polymorphism` which allows us to validate the uniqueness of nested attributes in memory.
4
+ This gem provides two class methods `validates_uniqueness_in_memory` and `validates_uniqueness_in_memory_for_tree_polymorphism` which ensures that the nested attribute uniqueness validation is not only checked against DB records but also against the non-persisted objects in memory.
5
5
 
6
6
  Installation
7
7
  -------
@@ -79,6 +79,7 @@ module NestedAttributesUniqueness
79
79
  collection.each do |record|
80
80
  if (!record.marked_for_destruction? && record.errors.get(attribute).blank?)
81
81
  attribute_value = record.send(attribute)
82
+ next if (options[:allow_blank] && attribute_value.blank?)
82
83
  attribute_value = attribute_value.downcase if options[:case_sensitive] == false
83
84
  key = [attribute_value]
84
85
  key += Array.wrap(options[:scope]).map { |attribute| record.public_send(attribute) }
@@ -109,8 +110,10 @@ module NestedAttributesUniqueness
109
110
  existing_records = record.class.where(query)
110
111
  records_exists = existing_records.present?
111
112
  if options[:scope]
112
- scope_value = record.public_send(options[:scope])
113
- existing_records = existing_records.where(:"#{ options[:scope] }" => scope_value)
113
+ Array.wrap(options[:scope]).each do |attribute|
114
+ scope_value = record.public_send(attribute)
115
+ existing_records = existing_records.where(:"#{ attribute }" => scope_value)
116
+ end
114
117
  records_exists = existing_records.present?
115
118
  end
116
119
  records_exists
@@ -1,3 +1,3 @@
1
1
  module NestedAttributesUniqueness
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nested_attributes_uniqueness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akshay
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2015-09-16 00:00:00.000000000 Z
13
+ date: 2015-09-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler