reform 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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66d8c635567dc8211aecd707abdb5e087091a31c
4
- data.tar.gz: 651a3fe9eef9a320329de238b7fdb8782d0d5400
3
+ metadata.gz: be845dd1b0e8a941df46ef6ed8d582b440b44acf
4
+ data.tar.gz: 4a4d7e81be355c4164fb884060eb07194bad0af6
5
5
  SHA512:
6
- metadata.gz: 11fd15d412d2184659d601891e612a7e103e3c9a90240356dea9124fd17c8f8422a4018ca46c4bb66cfc3074199e37b046032b77859d186887db161e0d91b02a
7
- data.tar.gz: 752b5e00845adf198af51a556c9f7c2ef63bd86ca08fce45585c8ccbf2e22e7a1ee9fb1081a2fd7edc06025233c7c345c8774ff8d473955a9d0e80b40c522c37
6
+ metadata.gz: 0c3c10fbedfb3cf9df5afdfbd98088a1ef948b9aa7b8730d294673b624309786658a450dcdafdd4571ef35ffbbfd3e3e724accd1bc2e250f9345c323f57640c6
7
+ data.tar.gz: 3c24007806a3469ce08ecc1ff13c40bf7e271b46d8fdaa8e098e2da0ed1a62571c51fcd7e0feca928c56c01c49bda1d632cb47c8aa7f2fdf9c9255274fbb2c5d
data/CHANGES.md CHANGED
@@ -1,3 +1,27 @@
1
+ ## 1.0.4
2
+
3
+ Reverting what I did in 1.0.3. Leave your code as it is. You may override a writers like `#title=` to sanitize or filter incoming data, as in
4
+
5
+ ```ruby
6
+ def title=(v)
7
+ super(v.strip)
8
+ end
9
+ ```
10
+
11
+ This setter will only be called in `#validate`.
12
+
13
+ Readers still work the same, meaning that
14
+
15
+ ```ruby
16
+ def title
17
+ super.downcase
18
+ end
19
+ ```
20
+
21
+ will result in lowercased title when rendering the form (and only then).
22
+
23
+ The reason for this confusion is that you don't blog enough about Reform. Only after introducing all those deprecation warnings, people started to contact me to ask what's going on. This gave me the feedback I needed to decide what's the best way for filtering incoming data.
24
+
1
25
  ## 1.0.3
2
26
 
3
27
  * Systematically use `fields` when saving the form. This avoids calling presentational readers that might have been defined by the user.
Binary file
@@ -52,9 +52,7 @@ module Reform::Form::Save
52
52
 
53
53
  require "active_support/hash_with_indifferent_access" # DISCUSS: replace?
54
54
  def to_nested_hash
55
- source = deprecate_potential_readers_used_in_sync_or_save(fields) # TODO: remove in 1.1.
56
-
57
- map = mapper.new(source).extend(NestedHash)
55
+ map = mapper.new(fields).extend(NestedHash)
58
56
 
59
57
  ActiveSupport::HashWithIndifferentAccess.new(map.to_hash)
60
58
  end
@@ -52,47 +52,10 @@ module Reform::Form::Sync
52
52
  # reading from fields allows using readers in form for presentation
53
53
  # and writers still pass to fields in #validate????
54
54
  def sync! # semi-public.
55
- source = deprecate_potential_readers_used_in_sync_or_save(fields) # TODO: remove in 1.1.
56
-
57
- input_representer = mapper.new(source).extend(InputRepresenter) # FIXME: take values from self.fields!
55
+ input_representer = mapper.new(fields).extend(InputRepresenter)
58
56
 
59
57
  input = input_representer.to_hash
60
58
 
61
59
  mapper.new(aliased_model).extend(Writer).from_hash(input)
62
60
  end
63
-
64
- def deprecate_potential_readers_used_in_sync_or_save(fields) # TODO: remove in 1.1.
65
- readers = []
66
-
67
- mapper.representable_attrs.each do |definition|
68
- return fields if definition[:presentation_accessors]
69
-
70
- name = definition.name
71
- next if method(name).source_location.inspect =~ /forwardable/ # defined by Reform, not overridden by user.
72
-
73
- readers << name
74
- end
75
- return fields if readers.size == 0
76
-
77
- warn "[Reform] Deprecation: You're overriding the following readers: #{readers.join(', ')}. In Reform 1.1, those readers will be used for presentation in the view, only. In case you are using the readers deliberately to modify incoming data for #save or #sync: this won't work anymore. If you just use the custom readers in the form view, add `presentation_accessors: true` to a property to suppress this message and use the new behaviour."
78
-
79
- self # old mode
80
- end
81
- def deprecate_potential_writers_used_in_validate(fields) # TODO: remove in 1.1.
82
- readers = []
83
-
84
- mapper.representable_attrs.each do |definition|
85
- return fields if definition[:presentation_accessors]
86
-
87
- name = definition.setter
88
- next if method(name).source_location.inspect =~ /forwardable/ # defined by Reform, not overridden by user.
89
-
90
- readers << name
91
- end
92
- return fields if readers.size == 0
93
-
94
- warn "[Reform] Deprecation: You're overriding the following writers: #{readers.join(', ')}. In Reform 1.1, those writers will be used for presentation in the view, only. In case you are using the writers deliberately to modify incoming data for #setup or #validate: this won't work anymore. Add `presentation_accessors: true` to a property to suppress this message and use the new behaviour."
95
-
96
- self # old mode
97
- end
98
61
  end
@@ -99,14 +99,12 @@ module Reform::Form::Validate
99
99
 
100
100
  private
101
101
  def populate!(params)
102
- target = deprecate_potential_writers_used_in_validate(fields) # TODO: remove in 1.1.
103
-
104
- mapper.new(target).extend(Populator).from_hash(params, :parent_form => self) # TODO: remove model(form) once we found out how to synchronize the model correctly. see https://github.com/apotonick/reform/issues/86#issuecomment-43402047
102
+ # populate only happens for nested forms, if you override that setter it's your fault.
103
+ mapper.new(fields).extend(Populator).from_hash(params, :parent_form => self) # TODO: remove model(form) once we found out how to synchronize the model correctly. see https://github.com/apotonick/reform/issues/86#issuecomment-43402047
105
104
  end
106
105
 
107
106
  def deserialize!(params)
108
- target = deprecate_potential_writers_used_in_validate(fields) # TODO: remove in 1.1.
109
-
110
- mapper.new(target).extend(Update).from_hash(params)
107
+ # using self here will call the form's setters like title= which might be overridden.
108
+ mapper.new(self).extend(Update).from_hash(params)
111
109
  end
112
110
  end
@@ -1,3 +1,3 @@
1
1
  module Reform
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -307,58 +307,7 @@ class ReadonlyAttributesTest < MiniTest::Spec
307
307
  end
308
308
 
309
309
 
310
- # TODO: formatter: lambda { |args| 1 }
311
- # to define reader for presentation layer (e.g. default value for #weight).
312
310
  class OverridingAccessorsTest < BaseTest
313
- class SongForm < Reform::Form
314
- property :title, :presentation_accessors => true
315
-
316
- def title=(v)
317
- super v*2
318
- end
319
-
320
- def title
321
- super.downcase
322
- end
323
- end
324
-
325
- let (:song) { Song.new("Pray") }
326
- subject { SongForm.new(song) }
327
-
328
- # override reader for presentation.
329
- it { subject.title.must_equal "pray" }
330
-
331
- # overridden writer only works when called explicitely.
332
- it do
333
- subject.title = "Swing Life Away"
334
- subject.title.must_equal "swing life awayswing life away"
335
- end
336
-
337
-
338
- describe "#save" do
339
- before { subject.validate("title" => "Hey Little World") }
340
-
341
- # for presentation, always use overridden accessor
342
- it { subject.title.must_equal "hey little world" }
343
-
344
- # the reader is not used when saving/syncing.
345
- it do
346
- subject.save do |f, hash|
347
- hash["title"].must_equal "Hey Little World"
348
- end
349
- end
350
-
351
- # the reader is not used when saving/syncing.
352
- it do
353
- song.extend(Saveable)
354
- subject.save
355
- song.title.must_equal "Hey Little World"
356
- end
357
- end
358
- end
359
-
360
-
361
- class OLDOverridingAccessorsTest < BaseTest # TODO: remove in 1.1
362
311
  class SongForm < Reform::Form
363
312
  property :title
364
313
 
@@ -387,15 +336,15 @@ class OLDOverridingAccessorsTest < BaseTest # TODO: remove in 1.1
387
336
  # the reader is not used when saving/syncing.
388
337
  it do
389
338
  subject.save do |f, hash|
390
- hash["title"].must_equal "hey little worldhey little world"
339
+ hash["title"].must_equal "Hey Little WorldHey Little World"
391
340
  end
392
341
  end
393
342
 
394
- # reader and writer used when saving/syncing.
343
+ # no reader or writer used when saving/syncing.
395
344
  it do
396
345
  song.extend(Saveable)
397
346
  subject.save
398
- song.title.must_equal "hey little worldhey little world"
347
+ song.title.must_equal "Hey Little WorldHey Little World"
399
348
  end
400
349
  end
401
350
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reform
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-13 00:00:00.000000000 Z
12
+ date: 2014-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: representable