formtastic 3.1.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +1 -0
  3. data/.github/workflows/test.yml +61 -0
  4. data/.gitignore +3 -2
  5. data/CHANGELOG.md +52 -0
  6. data/Gemfile.lock +105 -0
  7. data/MIT-LICENSE +1 -1
  8. data/{README.textile → README.md} +178 -167
  9. data/RELEASE_PROCESS +3 -1
  10. data/Rakefile +20 -1
  11. data/app/assets/stylesheets/formtastic.css +1 -1
  12. data/bin/appraisal +8 -0
  13. data/formtastic.gemspec +10 -16
  14. data/gemfiles/rails_5.2/Gemfile +5 -0
  15. data/gemfiles/rails_6.0/Gemfile +5 -0
  16. data/gemfiles/rails_6.1/Gemfile +5 -0
  17. data/gemfiles/rails_edge/Gemfile +13 -0
  18. data/lib/formtastic.rb +9 -11
  19. data/lib/formtastic/actions.rb +6 -3
  20. data/lib/formtastic/deprecation.rb +1 -38
  21. data/lib/formtastic/engine.rb +3 -1
  22. data/lib/formtastic/form_builder.rb +11 -24
  23. data/lib/formtastic/helpers.rb +1 -1
  24. data/lib/formtastic/helpers/action_helper.rb +1 -48
  25. data/lib/formtastic/helpers/enum.rb +13 -0
  26. data/lib/formtastic/helpers/errors_helper.rb +2 -2
  27. data/lib/formtastic/helpers/fieldset_wrapper.rb +13 -9
  28. data/lib/formtastic/helpers/form_helper.rb +1 -1
  29. data/lib/formtastic/helpers/input_helper.rb +23 -77
  30. data/lib/formtastic/helpers/inputs_helper.rb +27 -22
  31. data/lib/formtastic/i18n.rb +1 -1
  32. data/lib/formtastic/inputs.rb +32 -29
  33. data/lib/formtastic/inputs/base/choices.rb +1 -1
  34. data/lib/formtastic/inputs/base/collections.rb +43 -10
  35. data/lib/formtastic/inputs/base/database.rb +7 -2
  36. data/lib/formtastic/inputs/base/errors.rb +4 -4
  37. data/lib/formtastic/inputs/base/hints.rb +1 -1
  38. data/lib/formtastic/inputs/base/html.rb +7 -6
  39. data/lib/formtastic/inputs/base/naming.rb +4 -4
  40. data/lib/formtastic/inputs/base/options.rb +2 -3
  41. data/lib/formtastic/inputs/base/timeish.rb +5 -1
  42. data/lib/formtastic/inputs/base/validations.rb +38 -12
  43. data/lib/formtastic/inputs/check_boxes_input.rb +13 -5
  44. data/lib/formtastic/inputs/color_input.rb +0 -1
  45. data/lib/formtastic/inputs/country_input.rb +3 -1
  46. data/lib/formtastic/inputs/radio_input.rb +20 -0
  47. data/lib/formtastic/inputs/select_input.rb +29 -1
  48. data/lib/formtastic/inputs/time_zone_input.rb +16 -6
  49. data/lib/formtastic/localizer.rb +20 -22
  50. data/lib/formtastic/namespaced_class_finder.rb +1 -1
  51. data/lib/formtastic/version.rb +1 -1
  52. data/lib/generators/formtastic/form/form_generator.rb +1 -1
  53. data/lib/generators/formtastic/input/input_generator.rb +46 -0
  54. data/lib/generators/templates/formtastic.rb +14 -13
  55. data/lib/generators/templates/input.rb +19 -0
  56. data/sample/basic_inputs.html +1 -1
  57. data/script/integration-template.rb +74 -0
  58. data/script/integration.sh +19 -0
  59. data/spec/action_class_finder_spec.rb +1 -1
  60. data/spec/actions/button_action_spec.rb +8 -8
  61. data/spec/actions/generic_action_spec.rb +60 -60
  62. data/spec/actions/input_action_spec.rb +7 -7
  63. data/spec/actions/link_action_spec.rb +10 -10
  64. data/spec/builder/custom_builder_spec.rb +37 -21
  65. data/spec/builder/error_proc_spec.rb +4 -4
  66. data/spec/builder/semantic_fields_for_spec.rb +27 -27
  67. data/spec/fast_spec_helper.rb +12 -0
  68. data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
  69. data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
  70. data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
  71. data/spec/helpers/action_helper_spec.rb +328 -10
  72. data/spec/helpers/actions_helper_spec.rb +17 -17
  73. data/spec/helpers/form_helper_spec.rb +37 -37
  74. data/spec/helpers/input_helper_spec.rb +975 -2
  75. data/spec/helpers/inputs_helper_spec.rb +120 -105
  76. data/spec/helpers/reflection_helper_spec.rb +3 -3
  77. data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
  78. data/spec/i18n_spec.rb +26 -26
  79. data/spec/input_class_finder_spec.rb +1 -1
  80. data/spec/inputs/base/collections_spec.rb +76 -0
  81. data/spec/inputs/base/validations_spec.rb +480 -0
  82. data/spec/inputs/boolean_input_spec.rb +55 -55
  83. data/spec/inputs/check_boxes_input_spec.rb +155 -108
  84. data/spec/inputs/color_input_spec.rb +51 -63
  85. data/spec/inputs/country_input_spec.rb +20 -20
  86. data/spec/inputs/custom_input_spec.rb +2 -6
  87. data/spec/inputs/datalist_input_spec.rb +1 -1
  88. data/spec/inputs/date_picker_input_spec.rb +42 -42
  89. data/spec/inputs/date_select_input_spec.rb +51 -37
  90. data/spec/inputs/datetime_picker_input_spec.rb +46 -46
  91. data/spec/inputs/datetime_select_input_spec.rb +53 -37
  92. data/spec/inputs/email_input_spec.rb +5 -5
  93. data/spec/inputs/file_input_spec.rb +6 -6
  94. data/spec/inputs/hidden_input_spec.rb +18 -18
  95. data/spec/inputs/include_blank_spec.rb +8 -8
  96. data/spec/inputs/label_spec.rb +20 -20
  97. data/spec/inputs/number_input_spec.rb +112 -112
  98. data/spec/inputs/password_input_spec.rb +5 -5
  99. data/spec/inputs/phone_input_spec.rb +5 -5
  100. data/spec/inputs/placeholder_spec.rb +5 -5
  101. data/spec/inputs/radio_input_spec.rb +84 -58
  102. data/spec/inputs/range_input_spec.rb +66 -66
  103. data/spec/inputs/readonly_spec.rb +50 -0
  104. data/spec/inputs/search_input_spec.rb +5 -5
  105. data/spec/inputs/select_input_spec.rb +149 -93
  106. data/spec/inputs/string_input_spec.rb +23 -23
  107. data/spec/inputs/text_input_spec.rb +16 -16
  108. data/spec/inputs/time_picker_input_spec.rb +43 -43
  109. data/spec/inputs/time_select_input_spec.rb +67 -54
  110. data/spec/inputs/time_zone_input_spec.rb +54 -28
  111. data/spec/inputs/url_input_spec.rb +5 -5
  112. data/spec/inputs/with_options_spec.rb +7 -7
  113. data/spec/localizer_spec.rb +17 -17
  114. data/spec/namespaced_class_finder_spec.rb +2 -2
  115. data/spec/schema.rb +21 -0
  116. data/spec/spec_helper.rb +165 -253
  117. data/spec/support/custom_macros.rb +72 -75
  118. data/spec/support/shared_examples.rb +0 -1232
  119. data/spec/support/test_environment.rb +23 -9
  120. metadata +69 -176
  121. data/.travis.yml +0 -29
  122. data/Appraisals +0 -29
  123. data/CHANGELOG +0 -31
  124. data/DEPRECATIONS +0 -49
  125. data/gemfiles/rails_3.2.gemfile +0 -7
  126. data/gemfiles/rails_4.0.4.gemfile +0 -7
  127. data/gemfiles/rails_4.1.gemfile +0 -7
  128. data/gemfiles/rails_4.2.gemfile +0 -7
  129. data/gemfiles/rails_4.gemfile +0 -7
  130. data/gemfiles/rails_edge.gemfile +0 -10
  131. data/lib/formtastic/util.rb +0 -57
  132. data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
  133. data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
  134. data/spec/support/deferred_garbage_collection.rb +0 -21
  135. data/spec/util_spec.rb +0 -66
data/.travis.yml DELETED
@@ -1,29 +0,0 @@
1
- language: ruby
2
- before_install:
3
- - gem update --system
4
- - gem update bundler
5
- rvm:
6
- - 1.9.3
7
- - 2.0.0
8
- - 2.1
9
- gemfile:
10
- - gemfiles/rails_3.2.gemfile
11
- - gemfiles/rails_4.gemfile
12
- - gemfiles/rails_4.0.4.gemfile
13
- - gemfiles/rails_4.1.gemfile
14
- - gemfiles/rails_4.2.gemfile
15
- - gemfiles/rails_edge.gemfile
16
- env:
17
- - DEFER_GC=false RAILS_EDGE=true
18
- script: "bundle exec rake spec"
19
- matrix:
20
- allow_failures:
21
- - rvm: 1.9.3
22
- gemfile: gemfiles/rails_edge.gemfile
23
- env: DEFER_GC=false RAILS_EDGE=true
24
- - rvm: 2.0.0
25
- gemfile: gemfiles/rails_edge.gemfile
26
- env: DEFER_GC=false RAILS_EDGE=true
27
- - rvm: 2.1
28
- gemfile: gemfiles/rails_edge.gemfile
29
- env: DEFER_GC=false RAILS_EDGE=true
data/Appraisals DELETED
@@ -1,29 +0,0 @@
1
- appraise 'rails-3.2' do
2
- gem 'rails', '~> 3.2.0'
3
- end
4
-
5
- appraise 'rails-4' do
6
- gem 'rails', '~> 4.0.0'
7
- end
8
-
9
- # Special case for a change in I18n
10
- appraise 'rails-4.0.4' do
11
- gem 'rails', '4.0.4'
12
- end
13
-
14
- appraise 'rails-4.1' do
15
- gem 'rails', '~>4.1.0'
16
- end
17
-
18
- appraise 'rails-4.2' do
19
- gem 'rails', '~>4.2.0.beta4'
20
- end
21
-
22
- if ENV["RAILS_EDGE"] == "true"
23
- appraise 'rails-edge' do
24
- gem 'rails', :git => 'git://github.com/rails/rails.git'
25
- gem 'rack', :github => 'rack/rack'
26
- gem 'i18n', :github => 'svenfuchs/i18n'
27
- gem 'arel', :github => 'rails/arel'
28
- end
29
- end
data/CHANGELOG DELETED
@@ -1,31 +0,0 @@
1
- 3.1.1
2
-
3
- * Fixed class custom input & action class loading in test environments
4
- * Added documentation of custom input & action class finders
5
- * Added a link to documentation & wiki from custom class deprecation warnings
6
-
7
- 3.1.0
8
-
9
- * Performance and documentation improvements
10
-
11
- 3.1.0.rc2
12
-
13
- * Deprecated :member_value and :member_label options
14
-
15
- 3.1.0.rc1
16
-
17
- * Deprecated support for Rails version < 4.1.0
18
- * Fixed synchronization issues with custom_namespace configuration
19
- * Fixed bug where boolean (checkbox) inputs were not being correctly checked (also in 2.3.1)
20
- * Fixed (silenced) Rails 5 deprecation on column_for_attribute that we're handling fine
21
- * Added new DatalistInput (:as => :datalist) for HTML5 datalists
22
- * Added configurable namespaces for custom inputs
23
- * Various performance and documentation improvements
24
-
25
- ---
26
-
27
- See 3.0-stable branch for 3.0.x changes
28
- https://github.com/justinfrench/formtastic/blob/3.0-stable/CHANGELOG
29
-
30
- See 2.3-stable branch for 2.3.x and earlier releases
31
- https://github.com/justinfrench/formtastic/blob/2.3-stable/CHANGELOG
data/DEPRECATIONS DELETED
@@ -1,49 +0,0 @@
1
- This document is for tracking deprecations and removals of
2
- Formtastic features and compatibilities.
3
-
4
- v4.0 (planned)
5
-
6
- * Remove support for Rails < 4.1
7
- * Remove support for country_select 1.x syntax (they want to remove it in 3.0)
8
-
9
- v3.1 (master)
10
-
11
- * Deprecate support for Rails < 4.1
12
- * Deprecate :member_value option
13
- * Deprecate :member_label option
14
-
15
- v3.0
16
-
17
- * Remove support for Ruby version < 1.9.3
18
- * Remove support for Rails version < 3.2.13
19
- * Remove deprecated option :value (#1025)
20
- * Remove deprecated option :hint_class (#1025)
21
- * Remove deprecated option :error_class (#1025)
22
- * Remove deprecated option :group_by (#1025)
23
- * Remove deprecated option :group_label (#1025)
24
- * Remove deprecated option :find_options (#1025)
25
- * Deprecate support for Rails < 4.0.4
26
-
27
- v2.3
28
-
29
- * Remove deprecated date, time and datetime inputs
30
- * Deprecate :error_class option
31
- * Deprecate support for Rails < 3.2.13
32
-
33
- v2.2
34
-
35
- * Remove deprecated buttons DSL, ButtonHelper and commit_button helper
36
- * Deprecate :value option
37
- * Deprecate :hint_class option
38
- * Deprecate :error_class option
39
- * Deprecate :group_by and :group_label options
40
- * Deprecate :find_options option
41
-
42
- v2.1
43
-
44
- * Remove the previously deprecated :label_method, :value_method & :group_label_method options
45
- * Remove the previously deprecated :as => :numeric
46
- * Remove the previously deprecated inline_errors_for and related methods
47
- * Remove the previously deprecated SemanticFormHelper and SemanticFormBuilder
48
- * Deprecate the Buttons DSL (f.buttons, f.commit_button) in favor of the new Actions DSL — see above
49
-
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 3.2.0"
6
-
7
- gemspec :path => "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "4.0.4"
6
-
7
- gemspec :path => "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~>4.1.0"
6
-
7
- gemspec :path => "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~>4.2.0.beta4"
6
-
7
- gemspec :path => "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 4.0.0"
6
-
7
- gemspec :path => "../"
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", :git => "git://github.com/rails/rails.git"
6
- gem "rack", :github => "rack/rack"
7
- gem "i18n", :github => "svenfuchs/i18n"
8
- gem "arel", :github => "rails/arel"
9
-
10
- gemspec :path => "../"
@@ -1,57 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # Adapted from the rails3 compatibility shim in Haml 2.2
4
- module Formtastic
5
- # @private
6
- module Util
7
- extend self
8
- ## Rails XSS Safety
9
-
10
- # Returns the given text, marked as being HTML-safe.
11
- # With older versions of the Rails XSS-safety mechanism,
12
- # this destructively modifies the HTML-safety of `text`.
13
- #
14
- # @param text [String]
15
- # @return [String] `text`, marked as HTML-safe
16
- def html_safe(text)
17
- if text.respond_to?(:html_safe)
18
- text.html_safe
19
- else
20
- text
21
- end
22
- end
23
-
24
- def rails3?
25
- match?(rails_version, "~> 3.0")
26
- end
27
-
28
- def rails4?
29
- match?(rails_version, "~> 4.0")
30
- end
31
-
32
- def rails4_0?
33
- match?(rails_version, "~> 4.0.0")
34
- end
35
-
36
- def rails4_1?
37
- match?(rails_version, "~> 4.1.0")
38
- end
39
-
40
- def deprecated_version_of_rails?
41
- match?(rails_version, "< #{minimum_version_of_rails}")
42
- end
43
-
44
- def minimum_version_of_rails
45
- "4.1.0"
46
- end
47
-
48
- def rails_version
49
- ::Rails::VERSION::STRING
50
- end
51
-
52
- def match?(version, dependency)
53
- Gem::Dependency.new("formtastic", dependency).match?("formtastic", version)
54
- end
55
-
56
- end
57
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'with action class finder' do
4
- include_context 'form builder'
5
-
6
- before {
7
- allow(Formtastic::FormBuilder)
8
- .to receive(:action_class_finder).and_return(Formtastic::ActionClassFinder)
9
- }
10
-
11
- it_behaves_like 'Action Helper'
12
-
13
- describe 'instantiating an action class' do
14
- it "should delegate to ActionClassFinder" do
15
- concat(semantic_form_for(@new_post) do |builder|
16
- Formtastic::ActionClassFinder.any_instance.should_receive(:find).
17
- with(:button).and_call_original
18
-
19
- builder.action(:submit, :as => :button)
20
- end)
21
- end
22
-
23
- describe 'when instantiated multiple times with the same action type' do
24
- it "should be cached" do
25
- concat(semantic_form_for(@new_post) do |builder|
26
- Formtastic::ActionClassFinder.should_receive(:new).once.and_call_original
27
- builder.action(:submit, :as => :button)
28
- builder.action(:submit, :as => :button)
29
- end)
30
- end
31
- end
32
-
33
- context 'of unknown action' do
34
- it "should try to load class named as the action" do
35
- expect {
36
- semantic_form_for(@new_post) do |builder|
37
- builder.action(:destroy)
38
- end
39
- }.to raise_error(Formtastic::UnknownActionError, 'Unable to find action class DestroyAction')
40
- end
41
- end
42
- end
43
- end
@@ -1,36 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe 'with input class finder' do
5
- include_context 'form builder'
6
-
7
- before {
8
- allow(Formtastic::FormBuilder)
9
- .to receive(:input_class_finder).and_return(Formtastic::InputClassFinder)
10
- }
11
- it_behaves_like 'Input Helper' # from spec/support/shared_examples.rb
12
-
13
-
14
- describe 'instantiating an input class' do
15
- describe 'when instantiated multiple times with the same input type' do
16
-
17
- it "should be cached (not calling the internal methods)" do
18
- # TODO this is really tied to the underlying implementation
19
- concat(semantic_form_for(@new_post) do |builder|
20
- Formtastic::InputClassFinder.should_receive(:new).once.and_call_original
21
- builder.input(:title, :as => :string)
22
- builder.input(:title, :as => :string)
23
- end)
24
- end
25
- end
26
-
27
- it "should delegate to InputClassFinder" do
28
- concat(semantic_form_for(@new_post) do |builder|
29
- Formtastic::InputClassFinder.any_instance.should_receive(:find).
30
- with(:string).and_call_original
31
-
32
- builder.input(:title, :as => :string)
33
- end)
34
- end
35
- end
36
- end
@@ -1,21 +0,0 @@
1
- # Taken from http://makandra.com/notes/950-speed-up-rspec-by-deferring-garbage-collection
2
- class DeferredGarbageCollection
3
-
4
- DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 10.0).to_f
5
-
6
- @@last_gc_run = Time.now
7
-
8
- def self.start
9
- GC.disable if DEFERRED_GC_THRESHOLD > 0
10
- end
11
-
12
- def self.reconsider
13
- if DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD
14
- GC.enable
15
- GC.start
16
- GC.disable
17
- @@last_gc_run = Time.now
18
- end
19
- end
20
-
21
- end
data/spec/util_spec.rb DELETED
@@ -1,66 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe 'Formtastic::Util' do
5
-
6
- describe '.deprecated_version_of_rails?' do
7
-
8
- subject { Formtastic::Util.deprecated_version_of_rails? }
9
-
10
- context '4.0.0' do
11
- before { allow(Formtastic::Util).to receive(:rails_version) { "4.0.0" } }
12
- it 'should be true' do
13
- expect(subject).to be_truthy
14
- end
15
- end
16
-
17
- context '4.0.3' do
18
- before { allow(Formtastic::Util).to receive(:rails_version) { "4.0.3" } }
19
- it 'should be true' do
20
- expect(subject).to be_truthy
21
- end
22
- end
23
-
24
- context '4.0.4' do
25
- before { allow(Formtastic::Util).to receive(:rails_version) { "4.0.4" } }
26
- it 'should be false' do
27
- expect(subject).to be_truthy
28
- end
29
- end
30
-
31
- context '4.0.5' do
32
- before { allow(Formtastic::Util).to receive(:rails_version) { "4.0.5" } }
33
- it 'should be false' do
34
- expect(subject).to be_truthy
35
- end
36
- end
37
-
38
- context '4.1.0' do
39
- before { allow(Formtastic::Util).to receive(:rails_version) { "4.1.0" } }
40
- it 'should be false' do
41
- expect(subject).to be_falsey
42
- end
43
- end
44
-
45
- context '4.1.1' do
46
- before { allow(Formtastic::Util).to receive(:rails_version) { "4.1.1" } }
47
- it 'should be false' do
48
- expect(subject).to be_falsey
49
- end
50
- end
51
-
52
- context '4.2.0' do
53
- before { allow(Formtastic::Util).to receive(:rails_version) { "4.2.0" } }
54
- it 'should be false' do
55
- expect(subject).to be_falsey
56
- end
57
- end
58
-
59
- context '5.0.0' do
60
- before { allow(Formtastic::Util).to receive(:rails_version) { "5.0.0" } }
61
- it 'should be true' do
62
- expect(subject).to be_falsey
63
- end
64
- end
65
- end
66
- end