freeform 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,20 +23,43 @@ describe FreeForm::Nested do
23
23
  klass
24
24
  end
25
25
 
26
- let(:form_class) do
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
- has_many :mailing_addresses, :class => Module::MailingAddressForm, :default_initializer => :mailing_address_initializer
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
- it "allows nested_forms to be built" do
65
- form.build_mailing_addresses
66
- form.mailing_addresses.should be_an(Array)
67
- form.mailing_addresses.should_not be_empty
68
- form.mailing_addresses.first.should be_a(Module::MailingAddressForm)
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
- it "builds unique models" do
72
- form = form_class.new
73
- form.build_mailing_address
74
- form.build_mailing_address
75
- address_1 = form.mailing_addresses.first.address
76
- address_2 = form.mailing_addresses.last.address
77
- address_1.should_not eq(address_2)
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.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-09 00:00:00.000000000 Z
12
+ date: 2014-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel