motion_model 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -402,8 +402,6 @@ module MotionModel
402
402
  # in place if not.
403
403
  def save(*)
404
404
  call_hooks 'save' do
405
- @dirty = false
406
-
407
405
  # Existing object implies update in place
408
406
  action = 'add'
409
407
  set_auto_date_field 'created_at'
@@ -414,6 +412,7 @@ module MotionModel
414
412
  else
415
413
  collection << self
416
414
  end
415
+ @dirty = false
417
416
  self.class.issue_notification(self, :action => action)
418
417
  end
419
418
  end
@@ -120,9 +120,13 @@ module MotionModel
120
120
  result
121
121
  end
122
122
 
123
- # Validates that something has been entered in a field
123
+ # Validates that something has been endntered in a field.
124
+ # Should catch Fixnums, Bignums and Floats. Nils and Strings should
125
+ # be handled as well, Arrays, Hashes and other datatypes will not.
124
126
  def validate_presence(field, value, setting)
125
- if value.is_a?(String) || value.nil?
127
+ if(value.is_a?(Numeric))
128
+ return true
129
+ elsif value.is_a?(String) || value.nil?
126
130
  result = value.nil? || ((value.length == 0) == setting)
127
131
  additional_message = setting ? "non-empty" : "non-empty"
128
132
  add_message(field, "incorrect value supplied for #{field.to_s.humanize} -- should be #{additional_message}.") if result
@@ -1,4 +1,4 @@
1
1
 
2
2
  module MotionModel
3
- VERSION = "0.3.7"
3
+ VERSION = "0.3.8"
4
4
  end
@@ -3,13 +3,17 @@ class ValidatableTask
3
3
  include MotionModel::Validatable
4
4
  columns :name => :string,
5
5
  :email => :string,
6
- :some_day => :string
6
+ :some_day => :string,
7
+ :some_float => :float,
8
+ :some_int => :int
7
9
 
8
10
  validate :name, :presence => true
9
11
  validate :name, :length => 2..10
10
12
  validate :email, :email => true
11
13
  validate :some_day, :format => /\A\d?\d-\d?\d-\d\d\Z/
12
14
  validate :some_day, :length => 8..10
15
+ validate :some_float, :presence => true
16
+ validate :some_int, :presence => true
13
17
  end
14
18
 
15
19
  describe "validations" do
@@ -17,7 +21,9 @@ describe "validations" do
17
21
  @valid_tasks = {
18
22
  :name => 'bob',
19
23
  :email => 'bob@domain.com',
20
- :some_day => '12-12-12'
24
+ :some_day => '12-12-12',
25
+ :some_float => 1.080,
26
+ :some_int => 99
21
27
  }
22
28
  end
23
29
 
@@ -39,6 +45,33 @@ describe "validations" do
39
45
  task.name = 'bob'
40
46
  task.valid?.should === true
41
47
  end
48
+
49
+ it "is false if the float is nil" do
50
+ task = ValidatableTask.new(@valid_tasks.except(:some_float))
51
+ task.valid?.should === false
52
+ end
53
+
54
+ it "is true if the float is filled in" do
55
+ task = ValidatableTask.new(@valid_tasks)
56
+ task.valid?.should === true
57
+ end
58
+
59
+ it "is false if the integer is nil" do
60
+ task = ValidatableTask.new(@valid_tasks.except(:some_int))
61
+ task.valid?.should === false
62
+ end
63
+
64
+ it "is true if the integer is filled in" do
65
+ task = ValidatableTask.new(@valid_tasks)
66
+ task.valid?.should === true
67
+ end
68
+
69
+ it "is true if the Numeric datatypes are zero" do
70
+ task = ValidatableTask.new(@valid_tasks)
71
+ task.some_float = 0
72
+ task.some_int = 0
73
+ task.valid?.should === true
74
+ end
42
75
  end
43
76
 
44
77
  describe "length" do
@@ -99,7 +132,6 @@ describe "validations" do
99
132
  task = ValidatableTask.new
100
133
  task.validate_for(:some_day, 'a-12-12').should == false
101
134
  end
102
-
103
135
  end
104
136
  end
105
137
 
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.3.7
4
+ version: 0.3.8
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-02-08 00:00:00.000000000 Z
12
+ date: 2013-02-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bubble-wrap