motion_model 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +22 -7
- data/motion/adapters/array_finder_query.rb +1 -1
- data/motion/adapters/array_model_adapter.rb +1 -0
- data/motion/model/formotion.rb +2 -0
- data/motion/validatable.rb +6 -1
- data/motion/version.rb +1 -1
- data/spec/finder_spec.rb +5 -0
- data/spec/formotion_spec.rb +13 -0
- data/spec/model_hook_spec.rb +6 -0
- data/spec/validation_spec.rb +15 -0
- metadata +5 -11
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTY0YmQxMmY0NmY3OWZmNjQ0M2ZkMGY0YTViOWEwZTE2N2JiZjM1YQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTU5OTViYjhmYzg5ODE0ZDUyNDM2M2QyMjNjYTNmMjZkYjM1MjJkNA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTg2NzFmZjdiODVhNjJiODk2YzRiOWQ5OTI4ZmZlYjU2MmQ2MjY2M2I5OWY1
|
10
|
+
OWQzN2MyZWRiYmFjNTdmMzhlMTYwMzdkMDNkZWZjZDNmNjBhMTNhYzk5NGNh
|
11
|
+
M2E5MTAyYTU0MzVmYmViMjIzN2ZiZmY2ZTE5MjU3YTM5ZjRkMDE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDI5Njc4YTVkYmZkMGY1YzkwMGJiNjI0NDM0MzdiMzQ3YjcwMDZiODBjZmQ4
|
14
|
+
Y2Y0MDI1Y2Q1MTZjYTI3MjJmMmYwODI5YjExMGQ3NGE1MTA0YTQ5YzBmMTEz
|
15
|
+
MmIyNjNhZjY1MDg0MmNlZTcwM2ZmNGYwZTljZmQyNGMxZTkzMjM=
|
data/README.md
CHANGED
@@ -244,8 +244,8 @@ Here are some sample validations:
|
|
244
244
|
|
245
245
|
validate :field_name, :presence => true
|
246
246
|
validate :field_name, :length => 5..8 # specify a range
|
247
|
-
validate :field_name, :email
|
248
|
-
validate :field_name, :format
|
247
|
+
validate :field_name, :email => true
|
248
|
+
validate :field_name, :format => /\A\d?\d-\d?\d-\d\d\Z/ # expected string format would be like '12-12-12'
|
249
249
|
|
250
250
|
The framework is sufficiently flexible that you can add in custom validators like so:
|
251
251
|
|
@@ -278,7 +278,7 @@ of save:
|
|
278
278
|
|
279
279
|
Method | Meaning
|
280
280
|
-----------------------|---------------------------
|
281
|
-
`save(options)` |Just saves the data if it is valid (passes validations) or if you have specified `:validate => false`
|
281
|
+
`save(options)` |Just saves the data if it is valid (passes validations) or if you have specified `:validate => false` for `options`
|
282
282
|
`save!` |Saves the data if it is valid, otherwise raises a `MotionModel::Validatable::RecordInvalid` exception
|
283
283
|
|
284
284
|
Model Instances and Unique IDs
|
@@ -689,19 +689,19 @@ If you want to pass additional information on to Formotion, simply include it in
|
|
689
689
|
|
690
690
|
There are two alternate syntaxes for calling this. The initial, or "legacy" syntax is as follows:
|
691
691
|
|
692
|
-
```
|
692
|
+
```ruby
|
693
693
|
to_formotion(form_title, expose_auto_date_fields, first_section_title)
|
694
694
|
```
|
695
695
|
|
696
696
|
In the legacy syntax, all arguments are optional and sensible defaults are chosen. However, when you want to tune how your form is presented, the syntax gets a bit burdensome. The alternate syntax is:
|
697
697
|
|
698
|
-
```
|
698
|
+
```ruby
|
699
699
|
to_formotion(options)
|
700
700
|
```
|
701
701
|
|
702
702
|
The options hash looks a lot like a Formotion hash might, except without the data. Here is an example:
|
703
703
|
|
704
|
-
```
|
704
|
+
```ruby
|
705
705
|
{title: 'A very fine form',
|
706
706
|
sections: [
|
707
707
|
{title: 'First Section',
|
@@ -715,7 +715,7 @@ The options hash looks a lot like a Formotion hash might, except without the dat
|
|
715
715
|
|
716
716
|
Note that in this syntax, you can specify a button in the fields array:
|
717
717
|
|
718
|
-
```
|
718
|
+
```ruby
|
719
719
|
{title: 'A very fine form',
|
720
720
|
sections: [
|
721
721
|
{title: 'First Section',
|
@@ -729,6 +729,21 @@ Note that in this syntax, you can specify a button in the fields array:
|
|
729
729
|
|
730
730
|
This specifies exactly what titles and fields appear where and in what order.
|
731
731
|
|
732
|
+
Finally, you can specify a button:
|
733
|
+
|
734
|
+
```ruby
|
735
|
+
{title: 'A very fine form',
|
736
|
+
sections: [
|
737
|
+
{title: 'First Section',
|
738
|
+
fields: [:name, :gender]
|
739
|
+
},
|
740
|
+
{title: 'Second Section',
|
741
|
+
fields: [:address, :city, :state, {type: :submit, title: 'Ok'}],
|
742
|
+
{type: :button, title: 'add now!!!'}
|
743
|
+
}
|
744
|
+
]}
|
745
|
+
```
|
746
|
+
|
732
747
|
### How Values Are Produced for Formotion
|
733
748
|
|
734
749
|
MotionModel has sensible defaults for each type supported, so any field of `:date`
|
@@ -39,7 +39,7 @@ module MotionModel
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def translate_case(item, case_sensitive)#nodoc
|
42
|
-
item = item.
|
42
|
+
item = item.downcase if case_sensitive === false && item.respond_to?(:downcase)
|
43
43
|
item
|
44
44
|
end
|
45
45
|
|
data/motion/model/formotion.rb
CHANGED
data/motion/validatable.rb
CHANGED
@@ -14,8 +14,13 @@ module MotionModel
|
|
14
14
|
raise ex
|
15
15
|
end
|
16
16
|
|
17
|
+
unless validation_type.is_a?(Hash)
|
18
|
+
ex = ValidationSpecificationError.new('validation_type is not a hash')
|
19
|
+
raise ex
|
20
|
+
end
|
21
|
+
|
17
22
|
if validation_type == {}
|
18
|
-
ex = ValidationSpecificationError.new('
|
23
|
+
ex = ValidationSpecificationError.new('validation_type hash is empty')
|
19
24
|
raise ex
|
20
25
|
end
|
21
26
|
|
data/motion/version.rb
CHANGED
data/spec/finder_spec.rb
CHANGED
@@ -87,6 +87,11 @@ describe 'finders' do
|
|
87
87
|
results.length.should == 3
|
88
88
|
end
|
89
89
|
|
90
|
+
it 'handles case-insensitive queries as default' do
|
91
|
+
task = Task.create :name => 'camelCase'
|
92
|
+
Task.find(:name).eq('camelcase').all.length.should == 1
|
93
|
+
end
|
94
|
+
|
90
95
|
it 'handles case-sensitive queries' do
|
91
96
|
task = Task.create :name => 'Bob'
|
92
97
|
Task.find(:name).eq('bob', :case_sensitive => true).all.length.should == 0
|
data/spec/formotion_spec.rb
CHANGED
@@ -180,5 +180,18 @@ describe "formotion" do
|
|
180
180
|
result[:sections][0][:rows][2].should.has_key?(:type)
|
181
181
|
result[:sections][0][:rows][2][:type].should == :submit
|
182
182
|
end
|
183
|
+
|
184
|
+
it "creates date as a float in the formotion hash" do
|
185
|
+
result = @subject.new_to_formotion(
|
186
|
+
sections: [
|
187
|
+
{title: 'name', fields: [:name, :date, {title: 'Submit', type: :submit}]},
|
188
|
+
{title: 'address', fields: [:location]}
|
189
|
+
]
|
190
|
+
)
|
191
|
+
date_row = result[:sections][0][:rows][1]
|
192
|
+
date_row.should.has_key?(:type)
|
193
|
+
date_row[:type].should == :date
|
194
|
+
date_row[:value].class.should == Float
|
195
|
+
end
|
183
196
|
end
|
184
197
|
end
|
data/spec/model_hook_spec.rb
CHANGED
@@ -58,5 +58,11 @@ describe "lifecycle hooks" do
|
|
58
58
|
it "calls after_save hook on save" do
|
59
59
|
lambda{@task.save}.should.change{@task.after_save_called}
|
60
60
|
end
|
61
|
+
|
62
|
+
it "calls after_save hook on update" do
|
63
|
+
task = Task.last
|
64
|
+
task.instance_variable_set("@after_save_called", false)
|
65
|
+
lambda{task.save}.should.change{task.after_save_called}
|
66
|
+
end
|
61
67
|
end
|
62
68
|
end
|
data/spec/validation_spec.rb
CHANGED
@@ -146,6 +146,21 @@ describe "validations" do
|
|
146
146
|
task.validate_for(:some_day, 'a-12-12').should == false
|
147
147
|
end
|
148
148
|
end
|
149
|
+
|
150
|
+
describe "validation syntax" do
|
151
|
+
it "validates correctly when the expected hash syntax is used" do
|
152
|
+
task = ValidatableTask.new(@valid_tasks)
|
153
|
+
task.valid?.should == true
|
154
|
+
end
|
155
|
+
|
156
|
+
it "raises a ValidationSpecificationError when a non-Hash validation_type argument is passed to validate" do
|
157
|
+
lambda { ValidatableTask::validate(:field_name, :not_a_hash) }.should.raise
|
158
|
+
end
|
159
|
+
|
160
|
+
it "raises a ValidationSpecificationError when no validation_type argument is passed to validate" do
|
161
|
+
lambda { ValidatableTask::validate(:field_name) }.should.raise
|
162
|
+
end
|
163
|
+
end
|
149
164
|
end
|
150
165
|
|
151
166
|
class VTask
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Steve Ross
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-03-20 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bubble-wrap
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: motion-support
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -93,27 +88,26 @@ files:
|
|
93
88
|
- spec/validation_spec.rb
|
94
89
|
homepage: https://github.com/sxross/MotionModel
|
95
90
|
licenses: []
|
91
|
+
metadata: {}
|
96
92
|
post_install_message:
|
97
93
|
rdoc_options: []
|
98
94
|
require_paths:
|
99
95
|
- lib
|
100
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
-
none: false
|
102
97
|
requirements:
|
103
98
|
- - ! '>='
|
104
99
|
- !ruby/object:Gem::Version
|
105
100
|
version: '0'
|
106
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
-
none: false
|
108
102
|
requirements:
|
109
103
|
- - ! '>='
|
110
104
|
- !ruby/object:Gem::Version
|
111
105
|
version: '0'
|
112
106
|
requirements: []
|
113
107
|
rubyforge_project:
|
114
|
-
rubygems_version: 1.
|
108
|
+
rubygems_version: 2.1.10
|
115
109
|
signing_key:
|
116
|
-
specification_version:
|
110
|
+
specification_version: 4
|
117
111
|
summary: Simple model and validation mixins for RubyMotion
|
118
112
|
test_files:
|
119
113
|
- spec/adapter_spec.rb
|