validate_attributes 0.0.1 → 0.0.2
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 +4 -4
 - data/lib/validate_attributes/version.rb +1 -1
 - data/lib/validate_attributes.rb +5 -4
 - data/spec/validate_attributes_spec.rb +13 -0
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f0ef32269028ad47448aebcac5b90d33ab5143d0
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 4115d5bc3547df367aeef55f7c5fc87bf3616511
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 57460bf5fea66ab7c84e672fcf3dec198495421c73a01c886d5e516a6bae88cb38e842e414680a94a74bd5fb9b82f81547f9df7bd8c6f8e4f4e76a8507b0f11e
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 37cc4b0250c4cbd2a61fe952a06118554ff6f01a41a3cba429b0ba6a7006857cb7209e286998f3279cd2ce9af43e562c046cad3182897d5e231ab8bd3734ac2a
         
     | 
    
        data/lib/validate_attributes.rb
    CHANGED
    
    | 
         @@ -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  
     | 
| 
       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 
     | 
| 
      
 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. 
     | 
| 
      
 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:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-01-07 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: activemodel
         
     |