dynamic_fieldsets 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -1
- data/CHANGELOG +4 -0
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/app/helpers/dynamic_fieldsets/nested_model_helper.rb +3 -3
- data/app/views/dynamic_fieldsets/fields/_form.html.erb +3 -3
- data/app/views/dynamic_fieldsets/fieldset_children/_dependency_clause_fields.html.erb +1 -1
- data/app/views/dynamic_fieldsets/fieldset_children/_dependency_group_fields.html.erb +1 -1
- data/app/views/dynamic_fieldsets/fieldset_children/_form.html.erb +1 -1
- data/dynamic_fieldsets.gemspec +2 -2
- data/spec/dynamic_fieldsets_helper_spec.rb +4 -0
- data/spec/dynamic_fieldsets_in_model_spec.rb +5 -0
- data/spec/field_with_field_options_spec.rb +22 -0
- data/spec/field_with_multiple_answers_spec.rb +18 -0
- data/spec/field_with_single_answer_spec.rb +19 -0
- data/spec/models/dependency_clause_spec.rb +4 -0
- data/spec/models/dependency_group_spec.rb +4 -0
- data/spec/models/dependency_spec.rb +4 -0
- data/spec/models/field_record_spec.rb +4 -0
- data/spec/models/field_spec.rb +196 -101
- data/spec/models/fieldset_associator_spec.rb +4 -0
- metadata +3 -3
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--colour
|
1
|
+
--colour --profile
|
data/CHANGELOG
CHANGED
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.10
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module DynamicFieldsets
|
2
2
|
module NestedModelHelper
|
3
3
|
# returns a link with an onclick call to remove_fields using link_to_function
|
4
|
-
def
|
4
|
+
def df_link_to_remove_fields(name, f)
|
5
5
|
f.hidden_field(:_destroy) + link_to_function(name, {:onclick => "remove_fields(this)"})
|
6
6
|
end
|
7
7
|
|
8
8
|
# returns a link with an onclick call to add_fields
|
9
9
|
# the field information is rendered from a partial and stored as a string until it is needed
|
10
|
-
def
|
10
|
+
def df_link_to_add_fields(name, f, association, method = "add_fields")
|
11
11
|
new_object = f.object.class.reflect_on_association(association).klass.new
|
12
12
|
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
|
13
13
|
render(association.to_s.singularize + "_fields", {:f => builder, :obj => new_object})
|
14
14
|
end
|
15
|
-
link_to_function(name,
|
15
|
+
link_to_function(name, "#{method}(this, '#{association}', '#{escape_javascript(fields)}')", {:class => name.underscore.gsub(' ', '_')})
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -33,7 +33,7 @@
|
|
33
33
|
<%= render :partial => "field_option_fields", :locals => {:f => field_option_form} %>
|
34
34
|
<% end %>
|
35
35
|
<% end %>
|
36
|
-
<p><%=
|
36
|
+
<p><%= df_link_to_add_fields "Add Field Option", f, :field_options %></p>
|
37
37
|
|
38
38
|
<div class="field">
|
39
39
|
<%= f.label :required %>
|
@@ -49,14 +49,14 @@
|
|
49
49
|
<%= render :partial => "field_default_fields", :locals => {:f => field_default_form, :obj => field_default} %>
|
50
50
|
<% end %>
|
51
51
|
<% end %>
|
52
|
-
<p><%=
|
52
|
+
<p><%= df_link_to_add_fields "Add Default Value", f, :field_defaults %></p>
|
53
53
|
|
54
54
|
<% @field.field_html_attributes.each do |field_html_attribute| %>
|
55
55
|
<%= f.fields_for :field_html_attributes, field_html_attribute do |field_html_attribute_form| %>
|
56
56
|
<%= render :partial => "field_html_attribute_fields", :locals => {:f => field_html_attribute_form} %>
|
57
57
|
<% end %>
|
58
58
|
<% end %>
|
59
|
-
<p><%=
|
59
|
+
<p><%= df_link_to_add_fields "Add Html Attribute", f, :field_html_attributes %></p>
|
60
60
|
|
61
61
|
<div class="actions">
|
62
62
|
<%= f.submit %>
|
@@ -17,7 +17,7 @@
|
|
17
17
|
<% end %>
|
18
18
|
<% end %>
|
19
19
|
<tr>
|
20
|
-
<td colspan='4'><%=
|
20
|
+
<td colspan='4'><%= df_link_to_add_fields "Add Rule", f, :dependencies, "add_fields_to_table" %></td>
|
21
21
|
</tr>
|
22
22
|
</table>
|
23
23
|
AND<br />
|
@@ -10,7 +10,7 @@
|
|
10
10
|
<%= render :partial => "dependency_clause_fields", :locals => {:f => dependency_clause_form, :obj => dependency_clause} %>
|
11
11
|
<% end %>
|
12
12
|
<% end %>
|
13
|
-
<p><%=
|
13
|
+
<p><%= df_link_to_add_fields "Add Clause", f, :dependency_clauses %></p>
|
14
14
|
</div>
|
15
15
|
</p>
|
16
16
|
</div>
|
@@ -25,7 +25,7 @@
|
|
25
25
|
<%= f.fields_for :dependency_group, @fieldset_child.dependency_group do |dependency_group_form| %>
|
26
26
|
<%= render :partial => "dependency_group_fields", :locals => {:f => dependency_group_form, :obj => @fieldset_child.dependency_group} %>
|
27
27
|
<% end %>
|
28
|
-
<p><%=
|
28
|
+
<p><%= df_link_to_add_fields "Add Dependency", f, :dependency_group %></p>
|
29
29
|
|
30
30
|
<div class="actions">
|
31
31
|
<%= f.submit %>
|
data/dynamic_fieldsets.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "dynamic_fieldsets"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeremiah Hemphill", "Ethan Pemble", "John Carter"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-05-30"
|
13
13
|
s.description = "Dynamic fieldsets for rails controllers"
|
14
14
|
s.email = "jeremiah@cloudspace.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -46,4 +46,26 @@ describe FieldWithFieldOptions do
|
|
46
46
|
it "needs tests"
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
|
51
|
+
describe "options" do
|
52
|
+
before do
|
53
|
+
pending "This code has been moved here from the field model"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return options from the field options table if enabled" do
|
57
|
+
field = DynamicFieldsets::Field.new
|
58
|
+
field_option = mock_model(DynamicFieldsets::FieldOption)
|
59
|
+
field_option.stub!(:enabled).and_return(true)
|
60
|
+
field.should_receive(:field_options).and_return([field_option])
|
61
|
+
field.options.should include field_option
|
62
|
+
end
|
63
|
+
it "should not return disabled options from the field options table" do
|
64
|
+
field = DynamicFieldsets::Field.new
|
65
|
+
field_option = mock_model(DynamicFieldsets::FieldOption)
|
66
|
+
field_option.stub!(:enabled).and_return(false)
|
67
|
+
field.should_receive(:field_options).and_return([field_option])
|
68
|
+
field.options.should_not include field_option
|
69
|
+
end
|
70
|
+
end
|
49
71
|
end
|
@@ -47,4 +47,22 @@ describe FieldWithMultipleAnswers do
|
|
47
47
|
it "needs tests"
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
describe "defaults" do
|
52
|
+
before(:each) do
|
53
|
+
pending "this code has been moved from the field model"
|
54
|
+
@field = DynamicFieldsets::Field.new
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return an array if the type supports multiple options" do
|
58
|
+
@field.stub!(:options?).and_return(true)
|
59
|
+
@field.should_receive(:field_defaults).and_return(["default value"])
|
60
|
+
@field.defaults.should == ["default value"]
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return nil if the type does not support multiple options" do
|
64
|
+
@field.stub!(:options?).and_return(false)
|
65
|
+
@field.defaults.should be_nil
|
66
|
+
end
|
67
|
+
end
|
50
68
|
end
|
@@ -48,4 +48,23 @@ describe DynamicFieldsets::FieldWithSingleAnswer do
|
|
48
48
|
it "needs tests"
|
49
49
|
end
|
50
50
|
end
|
51
|
+
|
52
|
+
describe "default" do
|
53
|
+
before(:each) do
|
54
|
+
pending "this code has been moved from the field model"
|
55
|
+
@field = DynamicFieldsets::Field.new
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return a string if the type does not support multiple options" do
|
59
|
+
@field.stub!(:options?).and_return(false)
|
60
|
+
@field.should_receive(:field_defaults).and_return(["default value"])
|
61
|
+
@field.default.should == "default value"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return nil if the type supports multiple options" do
|
65
|
+
@field.stub!(:options?).and_return(true)
|
66
|
+
@field.default.should be_nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
51
70
|
end
|
@@ -2,6 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe DynamicFieldsets::DependencyGroup do
|
4
4
|
include DependencyGroupHelper
|
5
|
+
before(:each) do
|
6
|
+
pending "total rewrite"
|
7
|
+
end
|
8
|
+
|
5
9
|
|
6
10
|
it "should respond to fieldset_child" do
|
7
11
|
DynamicFieldsets::DependencyGroup.new.should respond_to :fieldset_child
|
data/spec/models/field_spec.rb
CHANGED
@@ -16,18 +16,6 @@ describe DynamicFieldsets::Field do
|
|
16
16
|
it { should respond_to :enabled }
|
17
17
|
end
|
18
18
|
|
19
|
-
describe "associations" do
|
20
|
-
before do
|
21
|
-
pending "shoulda installation"
|
22
|
-
end
|
23
|
-
|
24
|
-
it { should have_many :fieldset_children }
|
25
|
-
it { should have_many :parent_fieldsets }
|
26
|
-
it { should have_many :field_options }
|
27
|
-
it { should have_many :field_defaults }
|
28
|
-
it { should have_many :field_html_attributes }
|
29
|
-
end
|
30
|
-
|
31
19
|
describe "validations" do
|
32
20
|
before(:each) do
|
33
21
|
@field = DynamicFieldsets::Field.new
|
@@ -59,65 +47,169 @@ describe DynamicFieldsets::Field do
|
|
59
47
|
@field.required = false
|
60
48
|
@field.should have(0).error_on(:required)
|
61
49
|
end
|
62
|
-
|
63
|
-
# this validation now comes from the field option mixin
|
64
|
-
# whenever we get around to tests, this needs to be moved over.
|
65
|
-
# lets see how long this takes (JH 2-27-2012)
|
66
|
-
it "should require options if the type is one that requires options" do
|
67
|
-
pending "this needs to be moved to the field option mixin"
|
68
|
-
@field.type = "select"
|
69
|
-
@field.should have(1).error_on(:field_options)
|
70
|
-
end
|
71
50
|
end
|
72
51
|
|
73
52
|
# Scopes and Static Methods
|
74
53
|
|
75
54
|
it { DynamicFieldsets::Field.should respond_to :descendants }
|
76
55
|
describe ".descendants" do
|
77
|
-
it "should call super if cache classes is on"
|
78
|
-
|
56
|
+
it "should call super if cache classes is on" do
|
57
|
+
::Rails.application.config.stub(:cache_classes).and_return(true)
|
58
|
+
ActiveRecord::Base.should_receive(:descendants)
|
59
|
+
DynamicFieldsets::Field.descendants
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not call super if cache classes is off" do
|
63
|
+
::Rails.application.config.stub(:cache_classes).and_return(false)
|
64
|
+
ActiveRecord::Base.should_not_receive(:descendants)
|
65
|
+
DynamicFieldsets::Field.descendants
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should call the config if cache classes is off" do
|
69
|
+
::Rails.application.config.stub(:cache_classes).and_return(false)
|
70
|
+
DynamicFieldsets.config.should_receive(:available_field_types).and_return([])
|
71
|
+
DynamicFieldsets::Field.descendants
|
72
|
+
end
|
79
73
|
end
|
80
74
|
|
81
75
|
it { DynamicFieldsets::Field.should respond_to :descendant_collection }
|
82
76
|
describe ".descendant_collection" do
|
83
|
-
it "should call descendants"
|
84
|
-
|
77
|
+
it "should call descendants" do
|
78
|
+
DynamicFieldsets::Field.should_receive(:descendants).and_return([])
|
79
|
+
DynamicFieldsets::Field.descendant_collection
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should convert the class names to humanized strings" do
|
83
|
+
output = DynamicFieldsets::Field.descendant_collection
|
84
|
+
output.should include ["Checkbox field", "DynamicFieldsets::CheckboxField"]
|
85
|
+
output.should include ["Text field", "DynamicFieldsets::TextField"]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe ".display_type" do
|
90
|
+
it "should humanize and remove the namespace" do
|
91
|
+
@field.stub(:type).and_return("DynamicFieldsets::TextField")
|
92
|
+
@field.display_type.should == "Text field"
|
93
|
+
end
|
85
94
|
end
|
86
95
|
|
87
96
|
describe "form partial methods" do
|
88
97
|
it { should respond_to :form_partial }
|
89
98
|
describe ".form_partial" do
|
90
|
-
it "
|
99
|
+
it "should use the underscored model name" do
|
100
|
+
@field.form_partial.should == "/dynamic_fieldsets/form_partials/field"
|
101
|
+
end
|
91
102
|
end
|
92
103
|
|
93
104
|
it { should respond_to :form_header_partial }
|
94
105
|
describe ".form_header_partial" do
|
95
|
-
it "
|
106
|
+
it "should use the generic input_header partial" do
|
107
|
+
@field.form_header_partial.should == "/dynamic_fieldsets/form_partials/input_header"
|
108
|
+
end
|
96
109
|
end
|
97
110
|
|
98
111
|
it { should respond_to :use_form_header_partial? }
|
99
112
|
describe ".use_form_header_partial?" do
|
100
|
-
it "
|
113
|
+
it "should default to true" do
|
114
|
+
@field.use_form_header_partial?.should be_true
|
115
|
+
end
|
101
116
|
end
|
102
117
|
|
103
118
|
it { should respond_to :form_footer_partial }
|
104
119
|
describe ".form_footer_partial" do
|
105
|
-
it "
|
120
|
+
it "should use the generic input_footer partial" do
|
121
|
+
@field.form_footer_partial.should == "/dynamic_fieldsets/form_partials/input_footer"
|
122
|
+
end
|
106
123
|
end
|
107
124
|
|
108
125
|
it { should respond_to :use_form_footer_partial? }
|
109
126
|
describe ".use_form_footer_partial?" do
|
110
|
-
it "
|
127
|
+
it "should default to true" do
|
128
|
+
@field.use_form_footer_partial?.should be_true
|
129
|
+
end
|
111
130
|
end
|
112
131
|
|
113
132
|
it { should respond_to :form_partial_locals }
|
114
133
|
describe ".form_partial_locals" do
|
115
|
-
|
134
|
+
before(:each) do
|
135
|
+
@fsa = DynamicFieldsets::FieldsetAssociator.new
|
136
|
+
@fsa.stub(:id).and_return(1)
|
137
|
+
|
138
|
+
@fieldset_child = DynamicFieldsets::FieldsetAssociator.new
|
139
|
+
@fieldset_child.stub(:id).and_return(2)
|
140
|
+
|
141
|
+
@arguments = {
|
142
|
+
:fsa => @fsa,
|
143
|
+
:fieldset_child => @fieldset_child,
|
144
|
+
}
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should include these keys in the output" do
|
148
|
+
output = @field.form_partial_locals(@arguments)
|
149
|
+
expected_keys = [:fsa, :fieldset_child, :attrs, :object, :method, :name, :id]
|
150
|
+
expected_keys.each do |key|
|
151
|
+
output.keys.should include key
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
it "fsa should match the fsa in the args" do
|
156
|
+
output = @field.form_partial_locals(@arguments)
|
157
|
+
output[:fsa] = @fsa
|
158
|
+
end
|
159
|
+
|
160
|
+
it "fieldset_child should match the fieldset_child in the args" do
|
161
|
+
output = @field.form_partial_locals(@arguments)
|
162
|
+
output[:fieldset_child] = @fieldset_child
|
163
|
+
end
|
164
|
+
|
165
|
+
it "attrs should call html_attribute_hash" do
|
166
|
+
@field.should_receive(:html_attribute_hash).and_return({:hello => "world"})
|
167
|
+
output = @field.form_partial_locals(@arguments)
|
168
|
+
output[:attrs].should == {:hello => "world"}
|
169
|
+
end
|
170
|
+
|
171
|
+
it "object should use the config option and fsa id" do
|
172
|
+
DynamicFieldsets::config.should_receive(:form_fieldset_associator_prefix).and_return("hello")
|
173
|
+
@fsa.should_receive(:id).and_return(10)
|
174
|
+
|
175
|
+
output = @field.form_partial_locals(@arguments)
|
176
|
+
output[:object].should == "hello10"
|
177
|
+
end
|
178
|
+
|
179
|
+
it "method should use the config option and fieldset child id" do
|
180
|
+
DynamicFieldsets::config.should_receive(:form_field_prefix).and_return("hello")
|
181
|
+
@fieldset_child.should_receive(:id).and_return(10)
|
182
|
+
|
183
|
+
output = @field.form_partial_locals(@arguments)
|
184
|
+
output[:method].should == "hello10"
|
185
|
+
end
|
186
|
+
|
187
|
+
it "name should match object[method]" do
|
188
|
+
output = @field.form_partial_locals(@arguments)
|
189
|
+
output[:name].should == "#{output[:object]}[#{output[:method]}]"
|
190
|
+
end
|
191
|
+
|
192
|
+
it "id should match object_method" do
|
193
|
+
output = @field.form_partial_locals(@arguments)
|
194
|
+
output[:id].should == "#{output[:object]}_#{output[:method]}"
|
195
|
+
end
|
116
196
|
end
|
117
197
|
|
118
198
|
it { should respond_to :html_attribute_hash }
|
119
199
|
describe ".html_attribute_hash" do
|
120
|
-
it "
|
200
|
+
it "should call field_html_attributes" do
|
201
|
+
@field.should_receive(:field_html_attributes).and_return([])
|
202
|
+
@field.html_attribute_hash
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should pull the attribute names and values and put them in a hash" do
|
206
|
+
@attr = DynamicFieldsets::FieldHtmlAttribute.new
|
207
|
+
@attr.stub(:attribute_name => "key")
|
208
|
+
@attr.stub(:value => "value")
|
209
|
+
|
210
|
+
@field.stub(:field_html_attributes).and_return([@attr])
|
211
|
+
@field.html_attribute_hash.should == {:key => "value"}
|
212
|
+
end
|
121
213
|
end
|
122
214
|
end
|
123
215
|
|
@@ -125,37 +217,76 @@ describe DynamicFieldsets::Field do
|
|
125
217
|
|
126
218
|
it { should respond_to :show_partial }
|
127
219
|
describe ".show_partial" do
|
128
|
-
it "
|
220
|
+
it "should default to the missing partial partial" do
|
221
|
+
@field.show_partial.should == "/dynamic_fieldsets/show_partials/show_incomplete"
|
222
|
+
end
|
129
223
|
end
|
130
224
|
|
131
225
|
it { should respond_to :show_header_partial }
|
132
226
|
describe ".show_header_partial" do
|
133
|
-
it "
|
227
|
+
it "should default to the incomplete header partial" do
|
228
|
+
@field.show_header_partial.should == "/dynamic_fieldsets/show_partials/show_incomplete_header"
|
229
|
+
end
|
134
230
|
end
|
135
231
|
|
136
232
|
it { should respond_to :use_show_header_partial? }
|
137
233
|
describe ".use_show_header_partial?" do
|
138
|
-
it "
|
234
|
+
it "should default to false" do
|
235
|
+
@field.use_show_header_partial?.should be_false
|
236
|
+
end
|
139
237
|
end
|
140
238
|
|
141
239
|
it { should respond_to :show_footer_partial }
|
142
240
|
describe ".show_footer_partial" do
|
143
|
-
it "
|
241
|
+
it "should default to the incomplete footer partial" do
|
242
|
+
@field.show_footer_partial.should == "/dynamic_fieldsets/show_partials/show_incomplete_footer"
|
243
|
+
end
|
144
244
|
end
|
145
245
|
|
146
246
|
it { should respond_to :use_show_footer_partial? }
|
147
247
|
describe ".use_show_footer_partial?" do
|
148
|
-
it "
|
248
|
+
it "should default to false" do
|
249
|
+
@field.use_show_footer_partial?.should be_false
|
250
|
+
end
|
149
251
|
end
|
150
252
|
|
151
253
|
it { should respond_to :show_partial_locals }
|
152
254
|
describe ".show_partial_locals" do
|
153
|
-
|
154
|
-
|
155
|
-
|
255
|
+
before(:each) do
|
256
|
+
@arguments = {
|
257
|
+
:value => "hello",
|
258
|
+
:value => ["hello", "world"]
|
259
|
+
}
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should include value in the output" do
|
263
|
+
output = @field.show_partial_locals(@arguments)
|
264
|
+
output[:value].should == @arguments[:value]
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should include values in the output" do
|
268
|
+
output = @field.show_partial_locals(@arguments)
|
269
|
+
output[:values].should == @arguments[:values]
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should call label and include it in the output" do
|
273
|
+
@field.should_receive(:label).and_return("hello")
|
274
|
+
output = @field.show_partial_locals(@arguments)
|
275
|
+
output[:label].should == "hello"
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
# note that this gets overriden based on the number of answers
|
156
280
|
it { should respond_to :get_value_for_show }
|
157
281
|
describe ".get_value_for_show" do
|
158
|
-
it "
|
282
|
+
it "should return nil if the value is nil" do
|
283
|
+
@field.get_value_for_show(nil).should be_nil
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should return the value of the value key otherwise" do
|
287
|
+
val = { :value => "hello" }
|
288
|
+
@field.get_value_for_show(val).should == "hello"
|
289
|
+
end
|
159
290
|
end
|
160
291
|
end
|
161
292
|
|
@@ -171,6 +302,7 @@ describe DynamicFieldsets::Field do
|
|
171
302
|
@field.should_receive(:field_defaults).and_return(["default value"])
|
172
303
|
@field.has_defaults?.should be_true
|
173
304
|
end
|
305
|
+
|
174
306
|
it "should return false if the field default has no values" do
|
175
307
|
@field.should_receive(:field_defaults).and_return([])
|
176
308
|
@field.has_defaults?.should be_false
|
@@ -215,17 +347,37 @@ describe DynamicFieldsets::Field do
|
|
215
347
|
|
216
348
|
it { should respond_to :collect_default_values }
|
217
349
|
describe ".collect_default_values" do
|
218
|
-
it "
|
350
|
+
it "should call field_defaults" do
|
351
|
+
@field.should_receive(:field_defaults).and_return([])
|
352
|
+
@field.collect_default_values
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should collect the values of the returned defaults" do
|
356
|
+
@field.stub(:field_defaults).and_return([{:value => "hello" }])
|
357
|
+
@field.collect_default_values.should == ["hello"]
|
358
|
+
end
|
219
359
|
end
|
220
360
|
|
221
361
|
it { should respond_to :get_values_using_fsa_and_fsc }
|
222
362
|
describe ".get_values_using_fsa_and_fsc" do
|
223
|
-
it "
|
363
|
+
it "should return nil (must be overriden)" do
|
364
|
+
# just passing nils because the args are not needed in the test
|
365
|
+
@field.get_values_using_fsa_and_fsc(nil, nil).should be_nil
|
366
|
+
end
|
224
367
|
end
|
225
368
|
|
226
369
|
it { should respond_to :collect_field_records_by_fsa_and_fsc }
|
227
370
|
describe ".collect_field_records_by_fsa_and_fsc" do
|
228
|
-
it "
|
371
|
+
it "should return an array of field record values" do
|
372
|
+
record = mock_model(DynamicFieldsets::FieldRecord)
|
373
|
+
record.stub(:value).and_return("hello")
|
374
|
+
|
375
|
+
DynamicFieldsets::FieldRecord.stub!(:where).and_return([record])
|
376
|
+
|
377
|
+
fsa = mock_model(DynamicFieldsets::FieldsetAssociator)
|
378
|
+
fsc = mock_model(DynamicFieldsets::FieldsetChild)
|
379
|
+
@field.collect_field_records_by_fsa_and_fsc(fsa, fsc).should == [{ :value => "hello" }]
|
380
|
+
end
|
229
381
|
end
|
230
382
|
|
231
383
|
it { should respond_to :update_field_records }
|
@@ -234,61 +386,4 @@ describe DynamicFieldsets::Field do
|
|
234
386
|
lambda { @field.update_field_records }.should raise_exception
|
235
387
|
end
|
236
388
|
end
|
237
|
-
|
238
|
-
describe "options" do
|
239
|
-
before do
|
240
|
-
pending "This code has been moved to the field option mixin"
|
241
|
-
end
|
242
|
-
|
243
|
-
it "should return options from the field options table if enabled" do
|
244
|
-
field = DynamicFieldsets::Field.new
|
245
|
-
field_option = mock_model(DynamicFieldsets::FieldOption)
|
246
|
-
field_option.stub!(:enabled).and_return(true)
|
247
|
-
field.should_receive(:field_options).and_return([field_option])
|
248
|
-
field.options.should include field_option
|
249
|
-
end
|
250
|
-
it "should not return disabled options from the field options table" do
|
251
|
-
field = DynamicFieldsets::Field.new
|
252
|
-
field_option = mock_model(DynamicFieldsets::FieldOption)
|
253
|
-
field_option.stub!(:enabled).and_return(false)
|
254
|
-
field.should_receive(:field_options).and_return([field_option])
|
255
|
-
field.options.should_not include field_option
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
describe "default" do
|
260
|
-
before(:each) do
|
261
|
-
pending "this code has been moved to the single answer mixin"
|
262
|
-
@field = DynamicFieldsets::Field.new
|
263
|
-
end
|
264
|
-
|
265
|
-
it "should return a string if the type does not support multiple options" do
|
266
|
-
@field.stub!(:options?).and_return(false)
|
267
|
-
@field.should_receive(:field_defaults).and_return(["default value"])
|
268
|
-
@field.default.should == "default value"
|
269
|
-
end
|
270
|
-
|
271
|
-
it "should return nil if the type supports multiple options" do
|
272
|
-
@field.stub!(:options?).and_return(true)
|
273
|
-
@field.default.should be_nil
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
describe "defaults" do
|
278
|
-
before(:each) do
|
279
|
-
pending "this code has been moved to the multiple answer mixin"
|
280
|
-
@field = DynamicFieldsets::Field.new
|
281
|
-
end
|
282
|
-
|
283
|
-
it "should return an array if the type supports multiple options" do
|
284
|
-
@field.stub!(:options?).and_return(true)
|
285
|
-
@field.should_receive(:field_defaults).and_return(["default value"])
|
286
|
-
@field.defaults.should == ["default value"]
|
287
|
-
end
|
288
|
-
|
289
|
-
it "should return nil if the type does not support multiple options" do
|
290
|
-
@field.stub!(:options?).and_return(false)
|
291
|
-
@field.defaults.should be_nil
|
292
|
-
end
|
293
|
-
end
|
294
389
|
end
|
@@ -2,6 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe DynamicFieldsets::FieldsetAssociator do
|
4
4
|
include FieldsetAssociatorHelper
|
5
|
+
before(:each) do
|
6
|
+
pending "total rewrite"
|
7
|
+
end
|
8
|
+
|
5
9
|
|
6
10
|
it "should respond to fieldset" do
|
7
11
|
DynamicFieldsets::FieldsetAssociator.new.should respond_to :fieldset
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dynamic_fieldsets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeremiah Hemphill
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2012-
|
15
|
+
date: 2012-05-30 00:00:00 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rails
|
@@ -431,7 +431,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
431
431
|
requirements:
|
432
432
|
- - ">="
|
433
433
|
- !ruby/object:Gem::Version
|
434
|
-
hash:
|
434
|
+
hash: -1949793338758347934
|
435
435
|
segments:
|
436
436
|
- 0
|
437
437
|
version: "0"
|