redtape 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/redtape.rb +5 -5
- data/lib/redtape/version.rb +1 -1
- data/spec/form_spec.rb +19 -0
- metadata +20 -4
data/lib/redtape.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "redtape/version"
|
2
2
|
|
3
3
|
require 'active_model'
|
4
|
+
require 'active_support/core_ext/class/attribute'
|
4
5
|
|
5
6
|
module Redtape
|
6
7
|
class Form
|
@@ -8,13 +9,12 @@ module Redtape
|
|
8
9
|
include ActiveModel::Conversion
|
9
10
|
include ActiveModel::Validations
|
10
11
|
|
11
|
-
attr_accessor :model_accessors
|
12
|
-
|
13
12
|
validate :models_correct
|
13
|
+
class_attribute :model_accessors
|
14
14
|
|
15
15
|
def self.validates_and_saves(*args)
|
16
16
|
attr_accessor *args
|
17
|
-
|
17
|
+
self.model_accessors = args
|
18
18
|
end
|
19
19
|
|
20
20
|
def initialize(attrs = {})
|
@@ -25,7 +25,7 @@ module Redtape
|
|
25
25
|
|
26
26
|
def models_correct
|
27
27
|
populate
|
28
|
-
|
28
|
+
self.class.model_accessors.each do |accessor|
|
29
29
|
begin
|
30
30
|
model = send(accessor)
|
31
31
|
if model.invalid?
|
@@ -51,7 +51,7 @@ module Redtape
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def persist!
|
54
|
-
|
54
|
+
self.class.model_accessors.each do |accessor|
|
55
55
|
model = send(accessor)
|
56
56
|
unless model.save
|
57
57
|
return false
|
data/lib/redtape/version.rb
CHANGED
data/spec/form_spec.rb
CHANGED
@@ -112,4 +112,23 @@ describe Redtape::Form do
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
context "given another Form subclass" do
|
116
|
+
before do
|
117
|
+
Class.new(Redtape::Form) do
|
118
|
+
validates_and_saves :test_object
|
119
|
+
end.new(:test_object => :foo)
|
120
|
+
end
|
121
|
+
|
122
|
+
subject {
|
123
|
+
TestRegistrationForm.new
|
124
|
+
}
|
125
|
+
|
126
|
+
context "TestRegistrationForm still saves User" do
|
127
|
+
before do
|
128
|
+
subject.save
|
129
|
+
end
|
130
|
+
|
131
|
+
specify { subject.should_not be_valid }
|
132
|
+
end
|
133
|
+
end
|
115
134
|
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.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: 2012-11-
|
12
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: virtus
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: activesupport
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
94
110
|
description: ! 'A handy dandy way to avoid using #accepts_nested_attributes_for'
|
95
111
|
email:
|
96
112
|
- evan.light@tripledogdare.net
|
@@ -115,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
131
|
version: '0'
|
116
132
|
segments:
|
117
133
|
- 0
|
118
|
-
hash: -
|
134
|
+
hash: -1709053097785266848
|
119
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
136
|
none: false
|
121
137
|
requirements:
|
@@ -124,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
140
|
version: '0'
|
125
141
|
segments:
|
126
142
|
- 0
|
127
|
-
hash: -
|
143
|
+
hash: -1709053097785266848
|
128
144
|
requirements: []
|
129
145
|
rubyforge_project:
|
130
146
|
rubygems_version: 1.8.24
|