validate_attributes 0.0.1 → 0.0.2

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: 2dd292f2cac2625e8a5c75fc64171e107e66b9e3
4
- data.tar.gz: bf2ca88c970f976f2222aa07dcf2c90f36fa9d19
3
+ metadata.gz: f0ef32269028ad47448aebcac5b90d33ab5143d0
4
+ data.tar.gz: 4115d5bc3547df367aeef55f7c5fc87bf3616511
5
5
  SHA512:
6
- metadata.gz: 4e0ac6cc3c630fdce881fca7403941ce7c7ec83d1d1a6e890b60e21b39dc2bdeb9d689dfb7cd9d087a92cde1e636cb303127819bbfdfd7008108b6e1d2ee00ca
7
- data.tar.gz: 8e85704abd93124ed81aab6d7f50dae3c71d08b0b79726d686bcd5d2603f31fbe4c7c1a80da54ab97cb881409c0de0ea0714bd823022d1098be915f04bcd3935
6
+ metadata.gz: 57460bf5fea66ab7c84e672fcf3dec198495421c73a01c886d5e516a6bae88cb38e842e414680a94a74bd5fb9b82f81547f9df7bd8c6f8e4f4e76a8507b0f11e
7
+ data.tar.gz: 37cc4b0250c4cbd2a61fe952a06118554ff6f01a41a3cba429b0ba6a7006857cb7209e286998f3279cd2ce9af43e562c046cad3182897d5e231ab8bd3734ac2a
@@ -1,3 +1,3 @@
1
1
  module ValidateAttributes
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -6,6 +6,7 @@ module ValidateAttributes
6
6
 
7
7
  def validate_attributes(options = {})
8
8
  return valid? if options.empty?
9
+ errors.clear # Clean old validations as we're interested only on those
9
10
 
10
11
  _attributes = extract_attributes(options)
11
12
 
@@ -30,9 +31,7 @@ module ValidateAttributes
30
31
  self.class.validators_on(attr).each do |validator|
31
32
  fields = validator.validate(self)
32
33
  rejected = fields.reject {|f| attrs.include?(f.to_sym) }
33
- rejected.each do |f|
34
- errors[f].clear
35
- end
34
+ rejected.each { |f| errors[f].clear }
36
35
  end
37
36
  end
38
37
 
@@ -61,4 +60,6 @@ module ValidateAttributes
61
60
  end
62
61
  end
63
62
 
64
- ActiveModel::Validations.send(:include, ValidateAttributes)
63
+ module ActiveModel::Validations
64
+ include ValidateAttributes
65
+ end
@@ -101,5 +101,18 @@ RSpec.describe ValidateAttributes do
101
101
  end
102
102
  end
103
103
 
104
+ context "After a previous validation" do
105
+ it "still validates only the attributes" do
106
+ post = Post.new
107
+ expect(post).to be_invalid
108
+ expect(post.errors[:title]).to_not be_blank
109
+ expect(post.errors[:content]).to_not be_blank
110
+
111
+ post.validate_attributes(:only => :title)
112
+ expect(post.errors[:title]).to_not be_blank
113
+ expect(post.errors[:content]).to be_blank
114
+ end
115
+ end
116
+
104
117
 
105
118
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validate_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Rios
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-27 00:00:00.000000000 Z
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel