reform 0.2.2 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7858098ed982e9c00c56016f1678e26f4c43b9e6
4
- data.tar.gz: e518cbde390737b8308ce6aa41d398b6b48b2533
3
+ metadata.gz: 9ce0b79a877613cd7bcd9cfd868d0a33414c531a
4
+ data.tar.gz: f0e06d22099e1d335f692e865aff069428e9dc75
5
5
  SHA512:
6
- metadata.gz: 0d4cb6de758aeb2892ee47bb69c8f9bb061f184b8088b9eac294ed3add2e72d364b5425206b9720c671892b1926be13bff7d9a3d7a3ac818381468c9115db695
7
- data.tar.gz: 868a33c66a5a2225da3a12596f7c1f703e10403a1ef7353393d237ae368b6be55148d9eb8a2fe3bdda8e1744100d3e6d668b224226001997e19d029269747d2f
6
+ metadata.gz: 4f9f35619dea63561e09239ff40ec7765695a9f93638a32f1f5b743f6752aafce757497af1c28e9244fcb03cdaaf19cf07616dccb093881ce7b3b39b0d3f8af1
7
+ data.tar.gz: 30d28814ca8b99abba0385efb9c3ca391066402a39f81f45cacba4e927d52beb1e74516072fdb42a3946f4964099395bd48b12bd6ceb0aa1c2da0eb019c7927d
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.2.3
2
+
3
+ * `#form_for` now properly recognizes a nested form when declared using `:form` (instead of an inline form).
4
+ * Multiparameter dates as they're constructed from the Rails date helper are now processed automatically. As soon as an incoming attribute name is `property_name(1i)` or the like, it's compiled into a Date. That happens in `MultiParameterAttributes`. If a component (year/month/day) is missing, the date is considered `nil`.
5
+
1
6
  ## 0.2.2
2
7
 
3
8
  * Fix a bug where `form.save do .. end` would call `model.save` even though a block was given. This no longer happens, if there's a block to `#save`, you have to manually save data (ActiveRecord environment, only).
data/README.md CHANGED
@@ -455,10 +455,16 @@ class SongForm < Reform::Form
455
455
  end
456
456
  ```
457
457
 
458
+ ## Multiparameter Dates
459
+
460
+ Composed multi-parameter dates as created by the Rails date helper are processed automatically. As soon as Reform detects an incoming `release_date(i1)` or the like it is gonna be converted into a date.
461
+
462
+ Note that the date will be `nil` when one of the components (year/month/day) is missing.
463
+
464
+
458
465
  ## Security
459
466
 
460
- By explicitely defining the form layout using `::property` there is no more need for protecting from unwanted input. `strong_parameter` or `
461
- attr_accessible` become obsolete. Reform will simply ignore undefined incoming parameters.
467
+ By explicitely defining the form layout using `::property` there is no more need for protecting from unwanted input. `strong_parameter` or `attr_accessible` become obsolete. Reform will simply ignore undefined incoming parameters.
462
468
 
463
469
 
464
470
  ## Additional Features
data/database.sqlite3 CHANGED
Binary file
data/lib/reform/form.rb CHANGED
@@ -36,6 +36,7 @@ module Reform
36
36
  end
37
37
 
38
38
  def setup_form_definition(definition)
39
+ # TODO: allow Definition.form?
39
40
  definition.options[:form] ||= definition.options.delete(:extend)
40
41
 
41
42
  definition.options[:parse_strategy] = :sync
@@ -8,8 +8,8 @@ module Reform::Form::ActiveModel
8
8
 
9
9
  module ClassMethods
10
10
  def property(name, options={})
11
- add_nested_attribute_compat(name) if block_given? # TODO: fix that in Rails FB#1832 work.
12
11
  super
12
+ add_nested_attribute_compat(name) if options[:form] # TODO: fix that in Rails FB#1832 work.
13
13
  end
14
14
 
15
15
  private
@@ -21,9 +21,14 @@ class Reform::Form
21
21
 
22
22
  private
23
23
  def params_to_date(year, month, day)
24
- day ||= 1 # FIXME: is that really what we want? test.
24
+ return nil if blank_date_parameter?(year, month, day)
25
+
25
26
  Date.new(year.to_i, month.to_i, day.to_i) # TODO: test fails.
26
27
  end
28
+
29
+ def blank_date_parameter?(year, month, day)
30
+ year.blank? || month.blank? || day.blank?
31
+ end
27
32
  end
28
33
 
29
34
  def validate(params)
@@ -1,3 +1,3 @@
1
1
  module Reform
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -48,12 +48,20 @@ class FormBuilderCompatTest < MiniTest::Spec
48
48
  property :release_date
49
49
  validates :title, :presence => true
50
50
  end
51
+
52
+ class LabelForm < Reform::Form
53
+ property :name
54
+ end
55
+
56
+ property :label, :form => LabelForm
51
57
  end
52
58
  }
53
59
 
54
60
  let (:song) { OpenStruct.new }
55
61
  let (:form) { form_class.new(OpenStruct.new(
56
- :artist => Artist.new(:name => "Propagandhi"), :songs => [song])) }
62
+ :artist => Artist.new(:name => "Propagandhi"),
63
+ :songs => [song],
64
+ :label => OpenStruct.new)) }
57
65
 
58
66
  it "respects _attributes params hash" do
59
67
  form.validate("artist_attributes" => {"name" => "Blink 182"},
@@ -75,14 +83,40 @@ class FormBuilderCompatTest < MiniTest::Spec
75
83
  it "defines _attributes= setter so Rails' FB works properly" do
76
84
  form.must_respond_to("artist_attributes=")
77
85
  form.must_respond_to("songs_attributes=")
86
+ form.must_respond_to("label_attributes=")
78
87
  end
79
88
 
80
- it "accepts deconstructed date parameters" do
81
- form.validate("artist_attributes" => {"name" => "Blink 182"},
82
- "songs_attributes" => {"0" => {"title" => "Damnit", "release_date(1i)" => "1997",
83
- "release_date(2i)" => "9", "release_date(3i)" => "27"}})
89
+ describe "deconstructed date parameters" do
90
+ let(:form_attributes) do
91
+ {
92
+ "artist_attributes" => {"name" => "Blink 182"},
93
+ "songs_attributes" => {"0" => {"title" => "Damnit", "release_date(1i)" => release_year,
94
+ "release_date(2i)" => release_month, "release_date(3i)" => release_day}}
95
+ }
96
+ end
97
+ let(:release_year) { "1997" }
98
+ let(:release_month) { "9" }
99
+ let(:release_day) { "27" }
100
+
101
+ describe "with valid parameters" do
102
+ it "creates a date" do
103
+ form.validate(form_attributes)
84
104
 
85
- form.songs.first.release_date.must_equal Date.new(1997, 9, 27)
105
+ form.songs.first.release_date.must_equal Date.new(1997, 9, 27)
106
+ end
107
+ end
108
+
109
+ %w(year month day).each do |date_attr|
110
+ describe "when the #{date_attr} is missing" do
111
+ let(:"release_#{date_attr}") { "" }
112
+
113
+ it "rejects the date" do
114
+ form.validate(form_attributes)
115
+
116
+ form.songs.first.release_date.must_be_nil
117
+ end
118
+ end
119
+ end
86
120
  end
87
121
 
88
122
  it "returns flat errors hash" do
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: 0.2.2
4
+ version: 0.2.3
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: 2013-12-03 00:00:00.000000000 Z
12
+ date: 2013-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: representable