freeform 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/freeform/form/nested.rb +8 -3
- data/lib/freeform/version.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +10264 -0
- data/spec/form/nested_spec.rb +70 -16
- metadata +2 -2
data/spec/form/nested_spec.rb
CHANGED
@@ -23,20 +23,43 @@ describe FreeForm::Nested do
|
|
23
23
|
klass
|
24
24
|
end
|
25
25
|
|
26
|
-
let(:
|
26
|
+
let!(:second_nested_class) do
|
27
27
|
klass = Class.new(Module) do
|
28
28
|
include FreeForm::Property
|
29
29
|
include FreeForm::Nested
|
30
|
+
declared_model :phone
|
30
31
|
|
31
|
-
|
32
|
+
property :number, :on => :phone
|
33
|
+
|
34
|
+
def initialize(h={})
|
35
|
+
h.each {|k,v| send("#{k}=",v)}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
# This wrapper just avoids CONST warnings
|
39
|
+
v, $VERBOSE = $VERBOSE, nil
|
40
|
+
Module.const_set("PhoneNumberForm", klass)
|
41
|
+
$VERBOSE = v
|
42
|
+
klass
|
43
|
+
end
|
32
44
|
|
45
|
+
let(:form_class) do
|
46
|
+
klass = Class.new(Module) do
|
47
|
+
include FreeForm::Property
|
48
|
+
include FreeForm::Nested
|
49
|
+
|
33
50
|
def initialize(h={})
|
34
51
|
h.each {|k,v| send("#{k}=",v)}
|
35
52
|
end
|
36
53
|
|
54
|
+
has_many :mailing_addresses, :class => Module::MailingAddressForm, :default_initializer => :mailing_address_initializer
|
37
55
|
def mailing_address_initializer
|
38
56
|
{ :address => OpenStruct.new(:id => Random.new.rand(1000000)) }
|
39
57
|
end
|
58
|
+
|
59
|
+
has_many :phone_numbers, :class => Module::PhoneNumberForm, :default_initializer => :phone_number_initializer
|
60
|
+
def phone_number_initializer
|
61
|
+
{ :phone => OpenStruct.new(:id => Random.new.rand(1000000)) }
|
62
|
+
end
|
40
63
|
end
|
41
64
|
# This wrapper just avoids CONST warnings
|
42
65
|
v, $VERBOSE = $VERBOSE, nil
|
@@ -51,30 +74,61 @@ describe FreeForm::Nested do
|
|
51
74
|
|
52
75
|
describe "form class" do
|
53
76
|
it "sets nested_form in models" do
|
54
|
-
form_class.models.should eq([:mailing_addresses])
|
77
|
+
form_class.models.should eq([:mailing_addresses, :phone_numbers])
|
55
78
|
end
|
56
79
|
end
|
57
80
|
|
58
81
|
describe "building nested models" do
|
59
82
|
it "initializes with no nested models prebuilt" do
|
60
83
|
form.mailing_addresses.should eq([])
|
84
|
+
form.phone_numbers.should eq([])
|
61
85
|
end
|
62
86
|
|
63
87
|
context "with default initializer" do
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
88
|
+
context "for mailing addresses" do
|
89
|
+
it "allows nested_forms to be built" do
|
90
|
+
form.build_mailing_addresses
|
91
|
+
form.mailing_addresses.should be_an(Array)
|
92
|
+
form.mailing_addresses.should_not be_empty
|
93
|
+
form.mailing_addresses.first.should be_a(Module::MailingAddressForm)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "does not add to other has_many array" do
|
97
|
+
form.build_mailing_addresses
|
98
|
+
form.phone_numbers.should eq([])
|
99
|
+
end
|
100
|
+
|
101
|
+
it "builds unique models" do
|
102
|
+
form = form_class.new
|
103
|
+
form.build_mailing_address
|
104
|
+
form.build_mailing_address
|
105
|
+
address_1 = form.mailing_addresses.first.address
|
106
|
+
address_2 = form.mailing_addresses.last.address
|
107
|
+
address_1.should_not eq(address_2)
|
108
|
+
end
|
69
109
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
110
|
+
|
111
|
+
context "for phone numbers" do
|
112
|
+
it "allows nested_forms to be built" do
|
113
|
+
form.build_phone_number
|
114
|
+
form.phone_numbers.should be_an(Array)
|
115
|
+
form.phone_numbers.should_not be_empty
|
116
|
+
form.phone_numbers.first.should be_a(Module::PhoneNumberForm)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "does not add to other has_many array" do
|
120
|
+
form.build_phone_numbers
|
121
|
+
form.mailing_addresses.should eq([])
|
122
|
+
end
|
123
|
+
|
124
|
+
it "builds unique models" do
|
125
|
+
form = form_class.new
|
126
|
+
form.build_phone_number
|
127
|
+
form.build_phone_number
|
128
|
+
phone_1 = form.phone_numbers.first.phone
|
129
|
+
phone_2 = form.phone_numbers.last.phone
|
130
|
+
phone_1.should_not eq(phone_2)
|
131
|
+
end
|
78
132
|
end
|
79
133
|
end
|
80
134
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freeform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
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: 2014-01-
|
12
|
+
date: 2014-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|