validatious-on-rails 0.4.7 → 0.4.8

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.
@@ -62,8 +62,6 @@ v2.Validator.add({acceptEmpty: false, fn: function(field, value, params) { retur
62
62
 
63
63
  v2.Rails.initializeLastResult(name, field_element.id);
64
64
 
65
- console.log(v2.Rails.lastRemoteValidationResult[name][field_element.id]);
66
-
67
65
  var xmlHttpRequest = new XMLHttpRequest;
68
66
  xmlHttpRequest.open('GET', url, true);
69
67
  xmlHttpRequest.onreadystatechange = function() {
@@ -79,9 +79,19 @@ module ValidatiousOnRails
79
79
  return validators
80
80
  end
81
81
 
82
+ added_validations = []
83
+
82
84
  # Iterate thorugh the validations for the current class,
83
85
  # and collect validation options.
84
86
  klass.reflect_on_validations_for(attribute_method.to_sym).each do |validation|
87
+ validation_id = [validation.macro.to_sym, validation.name.to_sym].hash
88
+ if added_validations.include?(validation_id)
89
+ ValidatiousOnRails.log "Duplicate validation detected on #{object_or_class}##{attribute_method}: #{validation.macro}." <<
90
+ " All except the first one will be ignored. Please remove the redundant ones, or try to merge them into just one.", :warn
91
+ next
92
+ end
93
+ added_validations << validation_id
94
+
85
95
  validates_type = validation.macro.to_s.sub(/^validates?_/, '')
86
96
  if validation.options[:client_side].nil?
87
97
  validation.options[:client_side] = ::ValidatiousOnRails.client_side_validations_by_default
@@ -68,6 +68,7 @@ build_model :bogus_items do
68
68
 
69
69
  validates_presence_of :name, :body, :variant, :file_path, :dummie
70
70
  validates_uniqueness_of :name
71
+ validates_uniqueness_of :name # test dupplication (that should be ignored)
71
72
  validates_confirmation_of :name
72
73
  validates_acceptance_of :signed, :accept => true
73
74
  validates_format_of :url,
@@ -216,7 +216,10 @@ class ModelValidationsTest < ::ActiveSupport::TestCase
216
216
  end
217
217
 
218
218
  test "uniqueness_of" do
219
- # TODO: not implemented
219
+ validators = ::ValidatiousOnRails::ModelValidations.uniqueness_of(validation(:validates_uniqueness_of))
220
+ assert_validator_class 'uniqueness_false_false', validators
221
+ # Ignore duplicates (Note: defined two times in TestHelper).
222
+ assert_equal 1, [*validators].collect { |v| v.to_class.split(' ') }.flatten.select { |c| c == 'uniqueness_false_false'}.size
220
223
  end
221
224
 
222
225
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validatious-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Grimfelt