freeform 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODAyM2M4Y2YyNjA5NGY3NTQ3MzhiY2RlZGEwODc4NDllZjNkYWY3ZQ==
4
+ NTJlZjkyNzA0NTJlNzRhZjkyMjFjOGJmMjQyZjBkNDE5MmRiYzNjNA==
5
5
  data.tar.gz: !binary |-
6
- MGYyOTkyNTNmMjBiZmM1OTg0MzRiODNkMWY4OWQwOTIxZjA2Y2Y4Zg==
6
+ NmZjYjBkNGU2NjBhOGVlMzQ5ZTM2YTcwMDAyMTdjYzViZDFjYjNhOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTBmNzczODc3YTI3MTczNzFmYTQ1MTAwZDE0YmViMTkyZTdjNmQ2NTIyZGU2
10
- NjU1NzFjYTcxZWRmNDM4MTg3YjJkMTY5MjgzMzdkMzdhYjc2Y2EzMWE5YzVh
11
- YzUxY2NmYmUwZGVlYmE3MmE5OTFjYzhhZjE0MWI5NzBiNmRiN2I=
9
+ ZDMwZWJiYjljYzU5NWU3M2FkYzIxOTdkZGRlYzg2YzM4ODVmN2IzNzM2NjUy
10
+ YTdmODEzMDg3ODc5OGJiZmUzOTAxOTllNzBkNzI1OGZlNmVjZjBlNjY3NWM3
11
+ MGYxZDZmMGIwNjAzYWQyMDRlYjAzNDA2Yjg5Y2VkYzY4NTJiMDk=
12
12
  data.tar.gz: !binary |-
13
- Mzk5YzNkMzJhMjdhNDA1ZWJkMjJlZWQ3OTc3ZjU1NmRiY2Q1ODA2YzVlNzk1
14
- ZjIyZjJlZDhlNzZjZDU0MjI0NDFiYTIzZGU1OGM4Mzg3ZjYyODcyNDVkYjI5
15
- ZmE4ZGRhNTQ1YTM3MjQyNDM0YjgwOWRhZDkxMTVmMDU1ZTk0ZjA=
13
+ ZDQzZDlkMjY1ZTYyMzZmODcyOTVkNGViNDFiZmJjMTcwZGQ0ZjIzYmU1MmVl
14
+ OTlkZDA4MTY2ZTEwNjdkMmYzYzU2N2I4OTNhZjdhMzU0MzM2ZDU4Yzc0ODRj
15
+ ZjUwYjYxNDc3YWZjMDJiYWUyZDkwY2VjMjMxODYwNGMzMzQ2ZWE=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- freeform (1.0.2)
4
+ freeform (1.0.3)
5
5
  activemodel
6
6
  formtastic
7
7
  nested_form (~> 0.3.2)
@@ -70,7 +70,7 @@ GEM
70
70
  nested_form (0.3.2)
71
71
  nokogiri (1.6.0)
72
72
  mini_portile (~> 0.5.0)
73
- polyglot (0.3.3)
73
+ polyglot (0.3.4)
74
74
  rack (1.4.5)
75
75
  rack-cache (1.2)
76
76
  rack (>= 0.4)
@@ -70,7 +70,6 @@ module FreeForm
70
70
  args << options
71
71
  hidden_field(:_destroy, :value => 0) << @template.link_to(*args, &block)
72
72
  end
73
-
74
73
  def fields_for_with_nested_attributes(association_name, *args)
75
74
  # TODO Test this better
76
75
  block = args.pop || Proc.new { |fields| @template.render(:partial => "#{association_name.to_s.singularize}_fields", :locals => {:f => fields}) }
@@ -88,14 +87,15 @@ module FreeForm
88
87
  end
89
88
 
90
89
  def fields_for_nested_model(name, object, options, block)
91
- classes = 'fields'
92
- classes << ' marked_for_destruction' if object.respond_to?(:marked_for_destruction?) && object.marked_for_destruction?
93
-
94
90
  perform_wrap = options.fetch(:nested_wrapper, true)
95
91
  perform_wrap &&= options[:wrapper] != false # wrap even if nil
96
92
 
97
93
  if perform_wrap
98
- @template.content_tag(:div, super, :class => classes)
94
+ if object.respond_to?(:marked_for_destruction?) && object.marked_for_destruction?
95
+ @template.content_tag(:div, super, :class => 'fields marked_for_destruction', :style => "display: none;")
96
+ else
97
+ @template.content_tag(:div, super, :class => 'fields')
98
+ end
99
99
  else
100
100
  super
101
101
  end
@@ -108,4 +108,4 @@ module FreeForm
108
108
  assocs.join('_') + '_fields_blueprint'
109
109
  end
110
110
  end
111
- end
111
+ end
@@ -1,3 +1,3 @@
1
1
  module Freeform
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -229,7 +229,45 @@ describe FreeForm::Form do
229
229
  end
230
230
  end
231
231
 
232
- context "with invalid, marked for destruction nested model", :failing => true do
232
+ context "with invalid form, and invalid marked for destruction nested model", :failing => true do
233
+ let(:attributes) do {
234
+ :company_name => "",
235
+ :project_name => "rails app",
236
+ "due_date(1i)" => "2014",
237
+ "due_date(2i)" => "10",
238
+ "due_date(3i)" => "30",
239
+ :tasks_attributes => {
240
+ "0" => {
241
+ :name => "task_1",
242
+ "start_date(1i)" => "2012",
243
+ "start_date(2i)" => "1",
244
+ "start_date(3i)" => "2",
245
+ },
246
+ "1" => {
247
+ :name => "task_2",
248
+ "end_date(1i)" => "2011",
249
+ "end_date(2i)" => "12",
250
+ "end_date(3i)" => "15",
251
+ :_destroy => "1"
252
+ }
253
+ } }
254
+ end
255
+
256
+ before(:each) do
257
+ form.fill(attributes)
258
+ form.valid?
259
+ end
260
+
261
+ it "should not be valid" do
262
+ form.should_not be_valid
263
+ end
264
+
265
+ it "should not have errors" do
266
+ form.errors[:company_name].should eq(["can't be blank"])
267
+ end
268
+ end
269
+
270
+ context "with marked for destruction invalid nested model" do
233
271
  let(:attributes) do {
234
272
  :company_name => "dummycorp",
235
273
  :project_name => "rails app",
@@ -7,8 +7,8 @@ require "spec_helper"
7
7
  form_input_key :milestone
8
8
  form_models :milestone
9
9
  allow_destroy_on_save
10
-
11
- property :name, :on => :milestone
10
+
11
+ property :name, :on => :milestone
12
12
  end
13
13
  # This wrapper just avoids CONST warnings
14
14
  v, $VERBOSE = $VERBOSE, nil
@@ -22,9 +22,9 @@ require "spec_helper"
22
22
  form_input_key :task
23
23
  form_models :task
24
24
  allow_destroy_on_save
25
-
25
+
26
26
  property :name, :on => :task
27
-
27
+
28
28
  has_many :milestones, :class => Module::MilestoneForm, :default_initializer => :milestone_initializer
29
29
 
30
30
  def milestone_initializer
@@ -43,11 +43,11 @@ require "spec_helper"
43
43
  form_input_key :project
44
44
  form_models :project
45
45
  allow_destroy_on_save
46
-
46
+
47
47
  property :name, :on => :project
48
-
48
+
49
49
  has_many :tasks, :class => Module::TaskForm, :default_initializer => :task_initializer
50
-
50
+
51
51
  def task_initializer
52
52
  {:task => Task.new}
53
53
  end
@@ -58,7 +58,7 @@ require "spec_helper"
58
58
  $VERBOSE = v
59
59
  klass
60
60
  end
61
-
61
+
62
62
  let(:form) { form_class.new(:project => Project.new) }
63
63
 
64
64
  let(:template) do
@@ -133,11 +133,11 @@ require "spec_helper"
133
133
  end
134
134
  end
135
135
 
136
- it "wraps nested fields marked for destruction with an additional class" do
136
+ it "wraps nested fields marked for destruction with an additional class, and hides them" do
137
137
  task = form.build_task
138
138
  task.mark_for_destruction
139
139
  fields = subject.fields_for(:tasks) { 'Task' }
140
- fields.should eq('<div class="fields marked_for_destruction">Task</div>')
140
+ fields.should eq('<div class="fields marked_for_destruction" style="display: none;">Task</div>')
141
141
  end
142
142
 
143
143
  it "puts blueprint into data-blueprint attribute" do
@@ -212,4 +212,4 @@ require "spec_helper"
212
212
  end
213
213
  end
214
214
  end
215
- end
215
+ end
Binary file