dynamic_fields_for_rails 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/Rakefile +1 -2
- data/app/assets/javascripts/dynamic_fields_for.coffee +6 -2
- data/app/helpers/dynamic_fields_for_helper.rb +10 -11
- data/dynamic_fields_for_rails.gemspec +6 -6
- data/lib/dynamic_fields_for_rails.rb +1 -1
- data/lib/dynamic_fields_for_rails/version.rb +1 -1
- data/test/config/active_record.rb +2 -1
- data/test/dummy/app/models/child.rb +1 -1
- data/test/dummy/app/models/parent.rb +2 -2
- data/test/dummy/config.ru +1 -1
- data/test/dummy/config/boot.rb +1 -1
- data/test/dummy/config/environments/development.rb +0 -1
- data/test/dummy/config/environments/test.rb +1 -1
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/dummy/db/migrate/20130423140255_create_parents.rb +1 -4
- data/test/dummy/db/migrate/20130423140307_create_children.rb +1 -1
- data/test/dummy/db/schema.rb +7 -9
- data/test/dummy/script/rails +2 -2
- data/test/dynamic_fields_for_helper_test.rb +1 -1
- data/test/link_to_add_fields_test.rb +19 -19
- data/test/link_to_delete_fields_test.rb +29 -29
- data/test/test_helper.rb +3 -3
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e9c96aafaa7815eeb5d912b05545d2105bc1e0d
|
4
|
+
data.tar.gz: 5516ca291712045ed502ce6b65993f66c6885ac1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ab5977c622212bc81202f2a39340cc2175323ca5e8d64a2fe377909185f7050d4dd589c74234aad3168debaa35cf6781acf026e23d18601eeaffdfae7f9ed1a
|
7
|
+
data.tar.gz: aeb17864856b38b3b600c12fb3d4ca3c57cb6aa1227f84a1bd156b3ff837df0f2f996df165971d70f3313a182987a94d9b238b13b5f9a0d899ecd32bc1277fcb
|
data/.travis.yml
ADDED
data/Rakefile
CHANGED
@@ -3,8 +3,12 @@ $ ->
|
|
3
3
|
$(document).off 'click', 'form .add_fields'
|
4
4
|
|
5
5
|
$(document).on 'click', 'form .remove_fields', (event) ->
|
6
|
-
$(this).prev('input[type=hidden]')
|
7
|
-
$
|
6
|
+
$deleteField = $(this).prev('input[type=hidden]')
|
7
|
+
if $deleteField.length > 0
|
8
|
+
$deleteField.val('1')
|
9
|
+
$(this).closest('.fields').hide()
|
10
|
+
else
|
11
|
+
$(this).closest('.fields').remove()
|
8
12
|
$(document).trigger('dynamicFieldsFor.remove', @)
|
9
13
|
event.preventDefault()
|
10
14
|
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module DynamicFieldsForHelper
|
3
|
-
|
4
3
|
def link_to_add_fields(form, association, options = {}, &block)
|
5
4
|
partial = options[:partial] || nil
|
6
5
|
name = options[:name] || nil
|
@@ -18,10 +17,10 @@ module DynamicFieldsForHelper
|
|
18
17
|
end
|
19
18
|
css_classes = css_classes(DynamicFieldsForRails.add_css_classes, css_classes)
|
20
19
|
if block_given?
|
21
|
-
|
20
|
+
link_to('#', class: css_classes, data: { id: id, fields: fields.delete("\n"), target: target }, &block)
|
22
21
|
else
|
23
|
-
|
24
|
-
|
22
|
+
link_to(name, '#', class: css_classes, data: { id: id, fields: fields.delete("\n"), target: target })
|
23
|
+
end
|
25
24
|
end
|
26
25
|
|
27
26
|
def link_to_delete_fields(fields, options = {}, &block)
|
@@ -29,14 +28,14 @@ module DynamicFieldsForHelper
|
|
29
28
|
css_classes = options[:class] || nil
|
30
29
|
|
31
30
|
link = []
|
32
|
-
link << fields.hidden_field(:_destroy)
|
31
|
+
link << fields.hidden_field(:_destroy) unless fields.object.new_record?
|
33
32
|
css_classes = css_classes(DynamicFieldsForRails.delete_css_classes, css_classes)
|
34
|
-
if block_given?
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
link << if block_given?
|
34
|
+
link_to('#', class: css_classes, title: name, &block)
|
35
|
+
else
|
36
|
+
link_to(name, '#', class: css_classes)
|
37
|
+
end
|
38
|
+
link.join('').html_safe
|
40
39
|
end
|
41
40
|
|
42
41
|
protected
|
@@ -8,20 +8,20 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = DynamicFieldsForRails::VERSION
|
9
9
|
spec.authors = ["Marten Klitzke"]
|
10
10
|
spec.email = ["m.klitzke@gmail.com"]
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
11
|
+
spec.description = 'Dynamic fields helper for Rails.'
|
12
|
+
spec.summary = 'Helper for nested forms with dynamic fields.'
|
13
13
|
spec.homepage = "https://github.com/mortik/dynamic_fields_for_rails"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files = `git ls-files`.split(
|
16
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
spec.add_development_dependency "mocha"
|
24
|
-
spec.add_development_dependency "sqlite3"
|
22
|
+
spec.add_development_dependency "rake", '~> 0'
|
23
|
+
spec.add_development_dependency "mocha", '~> 0'
|
24
|
+
spec.add_development_dependency "sqlite3", '~> 0'
|
25
25
|
|
26
26
|
spec.add_dependency "rails", '>= 3.0.0', '< 5.0'
|
27
27
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:disable ClassAndModuleChildren
|
1
2
|
class ActiveRecord::Base
|
2
3
|
mattr_accessor :shared_connection
|
3
4
|
@@shared_connection = nil
|
@@ -6,4 +7,4 @@ class ActiveRecord::Base
|
|
6
7
|
@@shared_connection || retrieve_connection
|
7
8
|
end
|
8
9
|
end
|
9
|
-
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
|
10
|
+
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
|
@@ -1,2 +1,2 @@
|
|
1
1
|
class Child < ActiveRecord::Base
|
2
|
-
end
|
2
|
+
end
|
data/test/dummy/config.ru
CHANGED
data/test/dummy/config/boot.rb
CHANGED
@@ -16,7 +16,7 @@ Dummy::Application.configure do
|
|
16
16
|
config.action_dispatch.show_exceptions = false
|
17
17
|
|
18
18
|
# Disable request forgery protection in test environment
|
19
|
-
config.action_controller.allow_forgery_protection
|
19
|
+
config.action_controller.allow_forgery_protection = false
|
20
20
|
|
21
21
|
# Tell Action Mailer not to deliver emails to the real world.
|
22
22
|
# The :test delivery method accumulates sent emails in the
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Be sure to restart your server when you modify this file.
|
2
2
|
|
3
|
-
Dummy::Application.config.session_store :cookie_store, :
|
3
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
4
4
|
|
5
5
|
# Use the database for sessions instead of the cookie-based default,
|
6
6
|
# which shouldn't be used to store highly confidential information
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,17 +11,15 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:
|
15
|
-
|
16
|
-
create_table "children", :force => true do |t|
|
14
|
+
ActiveRecord::Schema.define(version: 20_130_423_140_307) do
|
15
|
+
create_table "children", force: true do |t|
|
17
16
|
t.integer "parent_id"
|
18
|
-
t.datetime "created_at", :
|
19
|
-
t.datetime "updated_at", :
|
17
|
+
t.datetime "created_at", null: false
|
18
|
+
t.datetime "updated_at", null: false
|
20
19
|
end
|
21
20
|
|
22
|
-
create_table "parents", :
|
23
|
-
t.datetime "created_at", :
|
24
|
-
t.datetime "updated_at", :
|
21
|
+
create_table "parents", force: true do |t|
|
22
|
+
t.datetime "created_at", null: false
|
23
|
+
t.datetime "updated_at", null: false
|
25
24
|
end
|
26
|
-
|
27
25
|
end
|
data/test/dummy/script/rails
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
3
|
|
4
|
-
APP_PATH = File.expand_path('../../config/application',
|
5
|
-
require File.expand_path('../../config/boot',
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
6
|
require 'rails/commands'
|
@@ -5,30 +5,30 @@ class LinkToAddFieldsTest < ActionView::TestCase
|
|
5
5
|
|
6
6
|
include DynamicFieldsForHelper
|
7
7
|
|
8
|
-
|
8
|
+
def form_for(*)
|
9
9
|
@output_buffer = super
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def setup
|
13
|
+
@parent = Parent.create
|
14
|
+
@parent.children.build
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
test "generates a add fields link" do
|
18
|
+
form_for(@parent, url: '/') do |form|
|
19
|
+
link_to_add_fields(form, 'children', name: "Test")
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
assert_match(%r{<a(.*)class=\"add_fields(.*)\"(.*)>Test<\/a>}, @output_buffer)
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
test "generates a add fields link with block if it is given" do
|
26
|
+
form_for(@parent, url: '/') do |form|
|
27
|
+
link_to_add_fields form, 'children' do
|
28
|
+
content_tag "div", "Test"
|
29
|
+
end
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
assert_match(%r{<a(.*)class=\"add_fields(.*)\"(.*)><div>Test<\/div><\/a>}, @output_buffer)
|
33
|
+
end
|
34
34
|
end
|
@@ -5,36 +5,36 @@ class LinkToDeleteFieldsTest < ActionView::TestCase
|
|
5
5
|
|
6
6
|
include DynamicFieldsForHelper
|
7
7
|
|
8
|
-
|
8
|
+
def form_for(*)
|
9
9
|
@output_buffer = super
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
12
|
+
def setup
|
13
|
+
@parent = Parent.create
|
14
|
+
@parent.children.build
|
15
|
+
end
|
16
|
+
|
17
|
+
test "generates a delete fields link" do
|
18
|
+
form_for(@parent, url: '/') do |form|
|
19
|
+
form.fields_for :children, @parent.children do |fields|
|
20
|
+
link_to_delete_fields(fields, name: "Test")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
assert_match(%r{<input(.*)name=\"parent\[children_attributes\](.*)\[_destroy\]\"(.*)value=\"false\" \/>}, @output_buffer)
|
25
|
+
assert_match(%r{<a(.*)class=\"remove_fields(.*)\"(.*)>Test<\/a>}, @output_buffer)
|
26
|
+
end
|
27
|
+
|
28
|
+
test "generates a deletes fields link with block if it is given" do
|
29
|
+
form_for(@parent, url: '/') do |form|
|
30
|
+
form.fields_for :children, @parent.children do |fields|
|
31
|
+
link_to_delete_fields fields do
|
32
|
+
content_tag "div", "Test"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_match(%r{<input(.*)name=\"parent\[children_attributes\](.*)\[_destroy\]\"(.*)value=\"false\" \/>}, @output_buffer)
|
38
|
+
assert_match(%r{<a(.*)class=\"remove_fields(.*)\"(.*)><div>Test<\/div><\/a>}, @output_buffer)
|
39
|
+
end
|
40
40
|
end
|
data/test/test_helper.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'bundler/setup'
|
3
3
|
|
4
4
|
ENV['RAILS_ENV'] = 'test'
|
5
|
-
require File.expand_path('../dummy/config/environment.rb',
|
5
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
6
6
|
require "rails/test_help"
|
7
7
|
require "mocha/setup"
|
8
8
|
require "active_support/test_case"
|
@@ -10,8 +10,8 @@ require "active_support/inflector"
|
|
10
10
|
|
11
11
|
Rails.backtrace_cleaner.remove_silencers!
|
12
12
|
|
13
|
-
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
13
|
+
ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')
|
14
14
|
|
15
15
|
# Load support files
|
16
16
|
Dir[File.join(ENGINE_RAILS_ROOT, 'test/support/**/*.rb')].each { |f| require f }
|
17
|
-
Dir[File.join(ENGINE_RAILS_ROOT, 'test/config/**/*.rb')].each { |f| require f }
|
17
|
+
Dir[File.join(ENGINE_RAILS_ROOT, 'test/config/**/*.rb')].each { |f| require f }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_fields_for_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Klitzke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,42 +28,42 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mocha
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
@@ -94,6 +94,7 @@ extensions: []
|
|
94
94
|
extra_rdoc_files: []
|
95
95
|
files:
|
96
96
|
- ".gitignore"
|
97
|
+
- ".travis.yml"
|
97
98
|
- Gemfile
|
98
99
|
- LICENSE.txt
|
99
100
|
- README.md
|
@@ -172,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
173
|
version: '0'
|
173
174
|
requirements: []
|
174
175
|
rubyforge_project:
|
175
|
-
rubygems_version: 2.
|
176
|
+
rubygems_version: 2.5.1
|
176
177
|
signing_key:
|
177
178
|
specification_version: 4
|
178
179
|
summary: Helper for nested forms with dynamic fields.
|