dynamic_fields_for_rails 0.6.0 → 0.6.1

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: 39ce07752b91f9b87a528d75977b9b8799e8d29b
4
- data.tar.gz: 6a224cdbfc0211b7c5b024b1be2304b6f6c6fa8e
3
+ metadata.gz: 9e9c96aafaa7815eeb5d912b05545d2105bc1e0d
4
+ data.tar.gz: 5516ca291712045ed502ce6b65993f66c6885ac1
5
5
  SHA512:
6
- metadata.gz: cd0c01e71cfc7a0a485dc6bc9a760a149ebd26824cc08cff4d0434f628f4b41752dcc8ba0dafcfbe268281e4b21e888e94b653335592909230e34ddd4ba4cea4
7
- data.tar.gz: 876e4a5e905c4fd069c0843b1966f6b02bf08cfba83e83f0be6c553b9ec0f0e2bf89c2ac3676206fbdc902e88169fc86bed747b2a4ec3fa40bae34c28e5b2b1c
6
+ metadata.gz: 3ab5977c622212bc81202f2a39340cc2175323ca5e8d64a2fe377909185f7050d4dd589c74234aad3168debaa35cf6781acf026e23d18601eeaffdfae7f9ed1a
7
+ data.tar.gz: aeb17864856b38b3b600c12fb3d4ca3c57cb6aa1227f84a1bd156b3ff837df0f2f996df165971d70f3313a182987a94d9b238b13b5f9a0d899ecd32bc1277fcb
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ notifications:
5
+ webhooks: https://mortik.slack.com/services/hooks/travis?token=aqp1ZDxk4YATzbB2XC8b36kn
data/Rakefile CHANGED
@@ -10,5 +10,4 @@ Rake::TestTask.new(:test) do |t|
10
10
  t.verbose = false
11
11
  end
12
12
 
13
-
14
- task :default => :test
13
+ task default: :test
@@ -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]').val('1')
7
- $(this).closest('.fields').hide()
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
- link_to('#', class: css_classes, data: {id: id, fields: fields.gsub("\n", ""), target: target}, &block)
20
+ link_to('#', class: css_classes, data: { id: id, fields: fields.delete("\n"), target: target }, &block)
22
21
  else
23
- link_to(name, '#', class: css_classes, data: {id: id, fields: fields.gsub("\n", ""), target: target})
24
- end
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
- link << link_to('#', class: css_classes, title: name, &block)
36
- else
37
- link << link_to(name, '#', class: css_classes)
38
- end
39
- return link.join('').html_safe
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 = %q{Dynamic fields helper for Rails.}
12
- spec.summary = %q{Helper for nested forms with dynamic fields.}
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,7 +1,7 @@
1
1
  require "dynamic_fields_for_rails/version"
2
2
 
3
3
  module DynamicFieldsForRails
4
- class Engine < Rails::Engine
4
+ class Engine < Rails::Engine
5
5
  end
6
6
 
7
7
  mattr_accessor :add_css_classes
@@ -1,3 +1,3 @@
1
1
  module DynamicFieldsForRails
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1".freeze
3
3
  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
@@ -1,4 +1,4 @@
1
1
  class Parent < ActiveRecord::Base
2
- has_many :children
2
+ has_many :children
3
3
  accepts_nested_attributes_for :children, allow_destroy: true
4
- end
4
+ end
data/test/dummy/config.ru CHANGED
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
4
  run Dummy::Application
@@ -7,4 +7,4 @@ if File.exist?(gemfile)
7
7
  Bundler.setup
8
8
  end
9
9
 
10
- $:.unshift File.expand_path('../../../../lib', __FILE__)
10
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -22,4 +22,3 @@ Dummy::Application.configure do
22
22
  # Only use best-standards-support built into browsers
23
23
  config.action_dispatch.best_standards_support = :builtin
24
24
  end
25
-
@@ -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 = false
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, :key => '_dummy_session'
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
@@ -1,8 +1,5 @@
1
1
  class CreateParents < ActiveRecord::Migration
2
2
  def change
3
- create_table :parents do |t|
4
-
5
- t.timestamps
6
- end
3
+ create_table :parents, &:timestamps
7
4
  end
8
5
  end
@@ -1,7 +1,7 @@
1
1
  class CreateChildren < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :children do |t|
4
- t.integer :parent_id
4
+ t.integer :parent_id
5
5
  t.timestamps
6
6
  end
7
7
  end
@@ -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(:version => 20130423140307) do
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", :null => false
19
- t.datetime "updated_at", :null => false
17
+ t.datetime "created_at", null: false
18
+ t.datetime "updated_at", null: false
20
19
  end
21
20
 
22
- create_table "parents", :force => true do |t|
23
- t.datetime "created_at", :null => false
24
- t.datetime "updated_at", :null => false
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
@@ -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', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
6
  require 'rails/commands'
@@ -4,4 +4,4 @@ class DynamicFieldsForHelperTest < ActiveSupport::TestCase
4
4
  test "truth" do
5
5
  assert_kind_of Module, DynamicFieldsForHelper
6
6
  end
7
- end
7
+ end
@@ -5,30 +5,30 @@ class LinkToAddFieldsTest < ActionView::TestCase
5
5
 
6
6
  include DynamicFieldsForHelper
7
7
 
8
- def form_for(*)
8
+ def form_for(*)
9
9
  @output_buffer = super
10
10
  end
11
11
 
12
- def setup
13
- @parent = Parent.create
14
- @parent.children.build
15
- end
12
+ def setup
13
+ @parent = Parent.create
14
+ @parent.children.build
15
+ end
16
16
 
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
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
- assert_match /<a(.*)class=\"add_fields(.*)\"(.*)>Test<\/a>/, @output_buffer
23
- end
22
+ assert_match(%r{<a(.*)class=\"add_fields(.*)\"(.*)>Test<\/a>}, @output_buffer)
23
+ end
24
24
 
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
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
- assert_match /<a(.*)class=\"add_fields(.*)\"(.*)><div>Test<\/div><\/a>/, @output_buffer
33
- end
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
- def form_for(*)
8
+ def form_for(*)
9
9
  @output_buffer = super
10
10
  end
11
11
 
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 /<input(.*)name=\"parent\[children_attributes\](.*)\[_destroy\]\"(.*)value=\"false\" \/>/, @output_buffer
25
- assert_match /<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 /<input(.*)name=\"parent\[children_attributes\](.*)\[_destroy\]\"(.*)value=\"false\" \/>/, @output_buffer
38
- assert_match /<a(.*)class=\"remove_fields(.*)\"(.*)><div>Test<\/div><\/a>/, @output_buffer
39
- end
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', __FILE__)
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.0
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: 2014-08-18 00:00:00.000000000 Z
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.2.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.