redtape 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/redtape.rb +13 -6
- data/lib/redtape/version.rb +1 -1
- data/spec/form_spec.rb +22 -0
- metadata +4 -4
data/lib/redtape.rb
CHANGED
@@ -27,12 +27,11 @@ module Redtape
|
|
27
27
|
@@model_accessors.each do |accessor|
|
28
28
|
begin
|
29
29
|
model = send(accessor)
|
30
|
-
|
31
|
-
model
|
32
|
-
errors.add(k, v)
|
33
|
-
end
|
30
|
+
if model.invalid?
|
31
|
+
own_your_errors_in(model)
|
34
32
|
end
|
35
|
-
rescue
|
33
|
+
rescue MethodMissingError => e
|
34
|
+
fail MethodMissing Error, "#{self.class} is missing 'validates_and_saves :#{accessor}'"
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
@@ -62,7 +61,15 @@ module Redtape
|
|
62
61
|
end
|
63
62
|
|
64
63
|
def populate
|
65
|
-
fail NotImplementedError, "Implement populate in your subclass"
|
64
|
+
fail NotImplementedError, "Implement #populate in your subclass"
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def own_your_errors_in(model)
|
70
|
+
model.errors.each do |k, v|
|
71
|
+
errors.add(k, v)
|
72
|
+
end
|
66
73
|
end
|
67
74
|
end
|
68
75
|
end
|
data/lib/redtape/version.rb
CHANGED
data/spec/form_spec.rb
CHANGED
@@ -43,6 +43,27 @@ class TestRegistrationForm < Redtape::Form
|
|
43
43
|
end
|
44
44
|
|
45
45
|
describe Redtape::Form do
|
46
|
+
context "given a Form where the Form fields are a proper subset of the modeled fields" do
|
47
|
+
context "where across all involved objects" do
|
48
|
+
context "all field names are unique" do
|
49
|
+
context "and the data is invalid" do
|
50
|
+
context "in a root object" do
|
51
|
+
it "reports an error on the model as <field_name>"
|
52
|
+
end
|
53
|
+
context "in a nested belongs_to/has_one" do
|
54
|
+
it "reports an error on the model as <model_name>_<field_name>"
|
55
|
+
end
|
56
|
+
context "in a nested has_many" do
|
57
|
+
it "reports an error on the model as <model_name>_<field_name>"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "some field names overlap" do
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
46
67
|
context "given a Form accepting a first and last name that creates a User" do
|
47
68
|
context "with valid data" do
|
48
69
|
subject {
|
@@ -82,4 +103,5 @@ describe Redtape::Form do
|
|
82
103
|
end
|
83
104
|
end
|
84
105
|
end
|
106
|
+
|
85
107
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redtape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.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: 2012-11-
|
12
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: virtus
|
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: '0'
|
116
116
|
segments:
|
117
117
|
- 0
|
118
|
-
hash:
|
118
|
+
hash: -1115838229263662025
|
119
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
120
|
none: false
|
121
121
|
requirements:
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
segments:
|
126
126
|
- 0
|
127
|
-
hash:
|
127
|
+
hash: -1115838229263662025
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project:
|
130
130
|
rubygems_version: 1.8.24
|