fragmented_validation 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -8
- data/lib/fragmented_validation/core.rb +6 -6
- data/lib/fragmented_validation/version.rb +1 -1
- data/spec/fragmented_validation_spec.rb +5 -5
- metadata +1 -1
data/README.md
CHANGED
@@ -19,23 +19,30 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
Usage
|
21
21
|
============
|
22
|
+
|
23
|
+
## Getting Started
|
24
|
+
|
22
25
|
### Include the FragmentedValidation module by calling the 'fragmented_validation' in your model.
|
23
|
-
e.g.
|
24
26
|
|
25
|
-
class User < ActiveRecord::Base
|
26
|
-
fragmented_validation
|
27
|
-
..
|
28
|
-
#### Validate single attribute
|
29
27
|
|
30
|
-
|
28
|
+
|
29
|
+
class User < ActiveRecord::Base
|
30
|
+
fragmented_validation
|
31
|
+
end
|
32
|
+
|
33
|
+
### Validate single attribute
|
34
|
+
|
35
|
+
person.email_valid?
|
31
36
|
|
32
37
|
#### Validate multiple attributes
|
33
38
|
|
34
|
-
|
39
|
+
|
40
|
+
|
41
|
+
person.fragmented_validation_on(:username, :email)
|
35
42
|
|
36
43
|
or
|
37
44
|
|
38
|
-
|
45
|
+
person.fragmented_validation_except(:password)
|
39
46
|
|
40
47
|
Contributing
|
41
48
|
============
|
@@ -45,3 +52,5 @@ Contributing
|
|
45
52
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
46
53
|
4. Push to the branch (`git push origin my-new-feature`)
|
47
54
|
5. Create new Pull Request
|
55
|
+
|
56
|
+
|
@@ -11,22 +11,22 @@ module FragmentedValidation
|
|
11
11
|
attributes = self.new.attributes.keys
|
12
12
|
attributes.each do |key|
|
13
13
|
define_method "valid_#{key}?" do
|
14
|
-
|
14
|
+
fragmented_validation_on key
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
module InstanceMethods
|
21
|
-
def
|
22
|
-
|
21
|
+
def fragmented_validation_on(*attrs)
|
22
|
+
fragmented_validation(attrs)
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
|
25
|
+
def fragmented_validation_except(*attrs)
|
26
|
+
fragmented_validation(attributes.keys - attrs.map{|att| att.to_s})
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def fragmented_validation(*attrs)
|
30
30
|
valid?
|
31
31
|
_errors = {}
|
32
32
|
attrs.flatten.uniq.each do |attr|
|
@@ -13,19 +13,19 @@ describe FragmentedValidation do
|
|
13
13
|
person.should respond_to(:valid_username?, :valid_password?)
|
14
14
|
end
|
15
15
|
|
16
|
-
describe "#
|
16
|
+
describe "#fragmented_validation" do
|
17
17
|
it "should only validate the passed attribute names" do
|
18
18
|
person.password = ""
|
19
19
|
person.username = ""
|
20
20
|
|
21
|
-
person.
|
21
|
+
person.fragmented_validation(:username, :password).should be_false
|
22
22
|
person.errors[:email].should be_empty
|
23
23
|
person.errors[:password].should_not be_empty
|
24
24
|
person.errors[:username].should_not be_empty
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should ignore unknown attributes" do
|
28
|
-
person.
|
28
|
+
person.fragmented_validation(:ghost_method, :bad_method).should be_true
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -34,7 +34,7 @@ describe FragmentedValidation do
|
|
34
34
|
person.password = ""
|
35
35
|
person.username = "myusername"
|
36
36
|
person.email = "test@mail.com"
|
37
|
-
person.
|
37
|
+
person.fragmented_validation_except(:password).should be_true
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -45,7 +45,7 @@ describe FragmentedValidation do
|
|
45
45
|
person.username = "myusername"
|
46
46
|
person.email = ""
|
47
47
|
|
48
|
-
person.
|
48
|
+
person.fragmented_validation_on(:username, :password).should be_true
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|