motion_model 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,7 +18,7 @@ module MotionModel
18
18
  ex = ValidationSpecificationError.new('validation type not present or not a hash')
19
19
  raise ex
20
20
  end
21
-
21
+
22
22
  validations << {field => validation_type}
23
23
  end
24
24
  alias_method :validates, :validate
@@ -56,7 +56,7 @@ module MotionModel
56
56
  end
57
57
 
58
58
  # This has two functions:
59
- #
59
+ #
60
60
  # * First, it triggers validations.
61
61
  #
62
62
  # * Second, it returns the result of performing the validations.
@@ -88,7 +88,8 @@ module MotionModel
88
88
 
89
89
  def validate_each(validations) #nodoc
90
90
  validations.each_pair do |field, validation|
91
- @valid &&= validate_one field, validation
91
+ result = validate_one field, validation
92
+ @valid &&= result
92
93
  end
93
94
  end
94
95
 
@@ -123,7 +124,7 @@ module MotionModel
123
124
  end
124
125
  result
125
126
  end
126
-
127
+
127
128
  def validate_one(field, validation) #nodoc
128
129
  result = true
129
130
  validation.each_pair do |validation_type, setting|
@@ -141,7 +142,7 @@ module MotionModel
141
142
  # Should catch Fixnums, Bignums and Floats. Nils and Strings should
142
143
  # be handled as well, Arrays, Hashes and other datatypes will not.
143
144
  def validate_presence(field, value, setting)
144
- if(value.is_a?(Numeric))
145
+ if(value.is_a?(Numeric))
145
146
  return true
146
147
  elsif value.is_a?(String) || value.nil?
147
148
  result = value.nil? || ((value.length == 0) == setting)
data/motion/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # or forward port their code to take advantage
5
5
  # of adapters.
6
6
  module MotionModel
7
- VERSION = "0.4.5"
7
+ VERSION = "0.4.6"
8
8
  end
@@ -2,7 +2,7 @@ class ValidatableTask
2
2
  include MotionModel::Model
3
3
  include MotionModel::ArrayModelAdapter
4
4
  include MotionModel::Validatable
5
- columns :name => :string,
5
+ columns :name => :string,
6
6
  :email => :string,
7
7
  :some_day => :string,
8
8
  :some_float => :float,
@@ -37,7 +37,7 @@ describe "validations" do
37
37
  it "contains correct error message if name is blank" do
38
38
  task = ValidatableTask.new(@valid_tasks.except(:name))
39
39
  task.valid?
40
- task.error_messages_for(:name).first.should ==
40
+ task.error_messages_for(:name).first.should ==
41
41
  "incorrect value supplied for name -- should be non-empty."
42
42
  end
43
43
 
@@ -52,6 +52,18 @@ describe "validations" do
52
52
  task.valid?.should === false
53
53
  end
54
54
 
55
+ it "contains multiple error messages if name and some_float are blank" do
56
+ task = ValidatableTask.new(@valid_tasks.except(:name, :some_float))
57
+ task.valid?
58
+ task.error_messages.length.should == 3
59
+ task.error_messages_for(:name).length.should == 2
60
+ task.error_messages_for(:some_float).length.should == 1
61
+
62
+ task.error_messages_for(:name).should.include 'incorrect value supplied for name -- should be non-empty.'
63
+ task.error_messages_for(:name).should.include "incorrect value supplied for name -- should be between 2 and 10 characters long."
64
+ task.error_messages_for(:some_float).should.include "incorrect value supplied for some_float -- should be non-empty."
65
+ end
66
+
55
67
  it "is true if the float is filled in" do
56
68
  task = ValidatableTask.new(@valid_tasks)
57
69
  task.valid?.should === true
@@ -86,7 +98,7 @@ describe "validations" do
86
98
  task = ValidatableTask.create(@valid_tasks.except(:name))
87
99
  task.name = '1'
88
100
  task.valid?.should === false
89
- task.error_messages_for(:name).first.should ==
101
+ task.error_messages_for(:name).first.should ==
90
102
  "incorrect value supplied for name -- should be between 2 and 10 characters long."
91
103
  end
92
104
 
@@ -94,7 +106,7 @@ describe "validations" do
94
106
  task = ValidatableTask.create(@valid_tasks.except(:name))
95
107
  task.name = '123456709AB'
96
108
  task.valid?.should === false
97
- task.error_messages_for(:name).first.should ==
109
+ task.error_messages_for(:name).first.should ==
98
110
  "incorrect value supplied for name -- should be between 2 and 10 characters long."
99
111
  end
100
112
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-15 00:00:00.000000000 Z
12
+ date: 2013-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bubble-wrap