strong_form 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/lib/strong_form/form.rb +14 -7
  4. data/lib/strong_form/version.rb +1 -1
  5. data/spec/dummy/app/controllers/base_controller.rb +6 -0
  6. data/spec/dummy/app/views/base/fields_for_explicit.html.haml +8 -0
  7. data/spec/dummy/db/test.sqlite3 +0 -0
  8. data/spec/dummy/log/test.log +3300 -0
  9. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +2 -0
  10. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/E6haN18CCNhwDqtCBl2Mpdw36x9r9ueGqUWs5VkbbTU.cache +0 -0
  11. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/GqaM_izIT4HEPtrrNPj4ANWSh8woB-_LdCA8qnBAd68.cache +1 -0
  12. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/HhLqAaTvuYuwgjUND4mK5eBePxjyKPD64_aN_YMacfI.cache +0 -0
  13. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/NAGh3C2mQEdEaSImUSF06RDZMijLl6U8J2gcPr98NBQ.cache +1 -0
  14. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +3 -0
  15. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/QAU-vbHgg5D5c2OqGQEbvMqbF8DrpkBBYysiKXPtnTU.cache +1 -0
  16. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/TiYC0B8qsZlVddPO1rQyU-8_89k5BCfzYKeyNrvdP5U.cache +0 -0
  17. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/VguhC2w9-v1gjhSO3Ebw85Km_5BpzzIOPF-U1DXsJGA.cache +1 -0
  18. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/WdRXDAtbmRw9NcGpokami_cV1EmCGTdVQtM81zUAAK4.cache +0 -0
  19. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/_755PJXlyHuPZVD39OTDgPWSWiMVLQtyH5LNgULt-8o.cache +1 -0
  20. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +3 -0
  21. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +2 -0
  22. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/wSf8vKqXPWbfIazZqmHp1Vxib6afMKucOf0932u3eI8.cache +1 -0
  23. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/yOB9v7Yv4mV6xh92Y_4FWXIorQHkty60pktkCG4Tx5k.cache +0 -0
  24. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/zZx1C1nvQBmUxUZz7VTS6ifX81mMFt1JqGwLPPaGL8E.cache +1 -0
  25. data/spec/examples.txt +57 -53
  26. data/spec/features/strong_form_spec.rb +21 -0
  27. metadata +36 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82f53b420bc975c8584fb569a392689859becd54
4
- data.tar.gz: b31cbffcc7c257df3a7a7a9186b611577889394c
3
+ metadata.gz: 6626016366a5ba97f7bcaa7fac2477926c1a7375
4
+ data.tar.gz: 5fcc3a6cbbcb4cd8a1c935fb2c7f1a501d6442b9
5
5
  SHA512:
6
- metadata.gz: 7abaa1c497d56fd47477830e5a8f592fc16567e040440e0983c57c08ddc5e9bc180b620d53a4d58b78c5b8f2b5510099d6fd696365f99530a715e822591762e4
7
- data.tar.gz: 73773f063fef71ad8145bb700a169cd376042452bd0c5993daf2d7ab34e7329fa5e6d58c4ddee1ea90ebcbf7ba6eb13ed60fa615961801731502b6ca4d928712
6
+ metadata.gz: ba49e910f1db4bae7ca1a0441e6c39aad3e4d7829419a3f489000ed8e70d588cf09f624a7d91140d1000f26db89937c3fd91dd94068e0f8c9682edcdaf931c07
7
+ data.tar.gz: ac81fb50f77cf8c4cd05d28e17dd305908e89411cd4ba2a60a615a0aa4fe9b0b63d51c8d8ab6e746bb3cff7aa59075b9aa6d8fe2399ccfe2e7fcb7e30ef45d31
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.0.5
6
+
7
+ ### Bugs fixed
8
+
9
+ * Make `fields_for` work with `permitted_attributes` even if parent form was not
10
+ initialized with them.
11
+
5
12
  ## 0.0.4
6
13
 
7
14
  ### Bugs fixed
@@ -6,14 +6,15 @@ module ActionView
6
6
  attr_accessor :_strong_form_permitted_attributes
7
7
 
8
8
  def form_for(record, options = {}, &block)
9
+ object = record.is_a?(Array) ? record.last : record
9
10
  # explicilty passed
10
11
  if options.key?(:permitted_attributes)
11
12
  self._strong_form_permitted_attributes = options.delete(:permitted_attributes)
12
- record.permitted_attributes =
13
- _strong_form_permitted_attributes if record.respond_to?(:permitted_attributes=)
13
+ object.permitted_attributes =
14
+ _strong_form_permitted_attributes if object.respond_to?(:permitted_attributes=)
14
15
  # assigned to object
15
- elsif record.respond_to?(:permitted_attributes)
16
- self._strong_form_permitted_attributes = record.permitted_attributes
16
+ elsif object.respond_to?(:permitted_attributes)
17
+ self._strong_form_permitted_attributes = object.permitted_attributes
17
18
  end
18
19
 
19
20
  orig_form_for(record, options, &block)
@@ -44,9 +45,15 @@ module ActionView
44
45
 
45
46
  # https://github.com/rails/rails/blob/4-2-stable/actionview/lib/action_view/helpers/form_helper.rb#L712
46
47
  def fields_for(record_name, record_object = nil, options = {}, &block)
47
- assign_child_permitted_attributes!(
48
- record_name, record_object, options[:parent_builder].object.permitted_attributes
49
- ) if _strong_form_permitted_attributes && record_object.respond_to?(:permitted_attributes=) && record_object.permitted_attributes.nil?
48
+ if _strong_form_permitted_attributes &&
49
+ record_object.respond_to?(:permitted_attributes=) &&
50
+ record_object.permitted_attributes.nil?
51
+ assign_child_permitted_attributes!(
52
+ record_name, record_object, options[:parent_builder].object.permitted_attributes
53
+ )
54
+ elsif options.key?(:permitted_attributes) && record_object.respond_to?(:permitted_attributes=)
55
+ record_object.permitted_attributes = options[:permitted_attributes]
56
+ end
50
57
 
51
58
  builder = instantiate_builder(record_name, record_object, options)
52
59
  capture(builder, &block)
@@ -1,3 +1,3 @@
1
1
  module StrongForm
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -11,6 +11,12 @@ class BaseController < ApplicationController
11
11
  @user.build_tag
12
12
  end
13
13
 
14
+ def fields_for_explicit
15
+ @user = User.new
16
+ @user.addresses.build
17
+ @user.build_tag
18
+ end
19
+
14
20
  def deep_fields_for
15
21
  @user = User.new
16
22
  (@user.addresses.build).tags.build
@@ -0,0 +1,8 @@
1
+ = form_for @user, url: '/somewhere' do |f|
2
+ = render 'user_fields', f: f
3
+
4
+ = f.fields_for :addresses, permitted_attributes: %i(street) do |af|
5
+ = render 'address_fields', f: af
6
+
7
+ = f.fields_for :tag do |tf|
8
+ = render 'tag_fields', f: tf
Binary file