formtastic 3.1.2 → 4.0.0
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 +7 -0
- data/.gitattributes +1 -0
- data/.github/workflows/test.yml +61 -0
- data/.gitignore +3 -2
- data/CHANGELOG.md +52 -0
- data/Gemfile.lock +105 -0
- data/MIT-LICENSE +1 -1
- data/{README.textile → README.md} +178 -167
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +20 -1
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +10 -16
- data/gemfiles/rails_5.2/Gemfile +5 -0
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_6.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic.rb +9 -11
- data/lib/formtastic/actions.rb +6 -3
- data/lib/formtastic/deprecation.rb +1 -38
- data/lib/formtastic/engine.rb +3 -1
- data/lib/formtastic/form_builder.rb +11 -24
- data/lib/formtastic/helpers.rb +1 -1
- data/lib/formtastic/helpers/action_helper.rb +1 -48
- data/lib/formtastic/helpers/enum.rb +13 -0
- data/lib/formtastic/helpers/errors_helper.rb +2 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +13 -9
- data/lib/formtastic/helpers/form_helper.rb +1 -1
- data/lib/formtastic/helpers/input_helper.rb +23 -77
- data/lib/formtastic/helpers/inputs_helper.rb +27 -22
- data/lib/formtastic/i18n.rb +1 -1
- data/lib/formtastic/inputs.rb +32 -29
- data/lib/formtastic/inputs/base/choices.rb +1 -1
- data/lib/formtastic/inputs/base/collections.rb +43 -10
- data/lib/formtastic/inputs/base/database.rb +7 -2
- data/lib/formtastic/inputs/base/errors.rb +4 -4
- data/lib/formtastic/inputs/base/hints.rb +1 -1
- data/lib/formtastic/inputs/base/html.rb +7 -6
- data/lib/formtastic/inputs/base/naming.rb +4 -4
- data/lib/formtastic/inputs/base/options.rb +2 -3
- data/lib/formtastic/inputs/base/timeish.rb +5 -1
- data/lib/formtastic/inputs/base/validations.rb +38 -12
- data/lib/formtastic/inputs/check_boxes_input.rb +13 -5
- data/lib/formtastic/inputs/color_input.rb +0 -1
- data/lib/formtastic/inputs/country_input.rb +3 -1
- data/lib/formtastic/inputs/radio_input.rb +20 -0
- data/lib/formtastic/inputs/select_input.rb +29 -1
- data/lib/formtastic/inputs/time_zone_input.rb +16 -6
- data/lib/formtastic/localizer.rb +20 -22
- data/lib/formtastic/namespaced_class_finder.rb +1 -1
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/formtastic/form/form_generator.rb +1 -1
- data/lib/generators/formtastic/input/input_generator.rb +46 -0
- data/lib/generators/templates/formtastic.rb +14 -13
- data/lib/generators/templates/input.rb +19 -0
- data/sample/basic_inputs.html +1 -1
- data/script/integration-template.rb +74 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +1 -1
- data/spec/actions/button_action_spec.rb +8 -8
- data/spec/actions/generic_action_spec.rb +60 -60
- data/spec/actions/input_action_spec.rb +7 -7
- data/spec/actions/link_action_spec.rb +10 -10
- data/spec/builder/custom_builder_spec.rb +37 -21
- data/spec/builder/error_proc_spec.rb +4 -4
- data/spec/builder/semantic_fields_for_spec.rb +27 -27
- data/spec/fast_spec_helper.rb +12 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
- data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
- data/spec/helpers/action_helper_spec.rb +328 -10
- data/spec/helpers/actions_helper_spec.rb +17 -17
- data/spec/helpers/form_helper_spec.rb +37 -37
- data/spec/helpers/input_helper_spec.rb +975 -2
- data/spec/helpers/inputs_helper_spec.rb +120 -105
- data/spec/helpers/reflection_helper_spec.rb +3 -3
- data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
- data/spec/i18n_spec.rb +26 -26
- data/spec/input_class_finder_spec.rb +1 -1
- data/spec/inputs/base/collections_spec.rb +76 -0
- data/spec/inputs/base/validations_spec.rb +480 -0
- data/spec/inputs/boolean_input_spec.rb +55 -55
- data/spec/inputs/check_boxes_input_spec.rb +155 -108
- data/spec/inputs/color_input_spec.rb +51 -63
- data/spec/inputs/country_input_spec.rb +20 -20
- data/spec/inputs/custom_input_spec.rb +2 -6
- data/spec/inputs/datalist_input_spec.rb +1 -1
- data/spec/inputs/date_picker_input_spec.rb +42 -42
- data/spec/inputs/date_select_input_spec.rb +51 -37
- data/spec/inputs/datetime_picker_input_spec.rb +46 -46
- data/spec/inputs/datetime_select_input_spec.rb +53 -37
- data/spec/inputs/email_input_spec.rb +5 -5
- data/spec/inputs/file_input_spec.rb +6 -6
- data/spec/inputs/hidden_input_spec.rb +18 -18
- data/spec/inputs/include_blank_spec.rb +8 -8
- data/spec/inputs/label_spec.rb +20 -20
- data/spec/inputs/number_input_spec.rb +112 -112
- data/spec/inputs/password_input_spec.rb +5 -5
- data/spec/inputs/phone_input_spec.rb +5 -5
- data/spec/inputs/placeholder_spec.rb +5 -5
- data/spec/inputs/radio_input_spec.rb +84 -58
- data/spec/inputs/range_input_spec.rb +66 -66
- data/spec/inputs/readonly_spec.rb +50 -0
- data/spec/inputs/search_input_spec.rb +5 -5
- data/spec/inputs/select_input_spec.rb +149 -93
- data/spec/inputs/string_input_spec.rb +23 -23
- data/spec/inputs/text_input_spec.rb +16 -16
- data/spec/inputs/time_picker_input_spec.rb +43 -43
- data/spec/inputs/time_select_input_spec.rb +67 -54
- data/spec/inputs/time_zone_input_spec.rb +54 -28
- data/spec/inputs/url_input_spec.rb +5 -5
- data/spec/inputs/with_options_spec.rb +7 -7
- data/spec/localizer_spec.rb +17 -17
- data/spec/namespaced_class_finder_spec.rb +2 -2
- data/spec/schema.rb +21 -0
- data/spec/spec_helper.rb +165 -253
- data/spec/support/custom_macros.rb +72 -75
- data/spec/support/shared_examples.rb +0 -1232
- data/spec/support/test_environment.rb +23 -9
- metadata +69 -176
- data/.travis.yml +0 -29
- data/Appraisals +0 -29
- data/CHANGELOG +0 -31
- data/DEPRECATIONS +0 -49
- data/gemfiles/rails_3.2.gemfile +0 -7
- data/gemfiles/rails_4.0.4.gemfile +0 -7
- data/gemfiles/rails_4.1.gemfile +0 -7
- data/gemfiles/rails_4.2.gemfile +0 -7
- data/gemfiles/rails_4.gemfile +0 -7
- data/gemfiles/rails_edge.gemfile +0 -10
- data/lib/formtastic/util.rb +0 -57
- data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
- data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
- data/spec/support/deferred_garbage_collection.rb +0 -21
- data/spec/util_spec.rb +0 -66
data/lib/formtastic/localizer.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Formtastic
|
|
2
|
-
# Implementation for looking up localized values within Formtastic using I18n, if no
|
|
2
|
+
# Implementation for looking up localized values within Formtastic using I18n, if no
|
|
3
3
|
# explicit value (like the `:label` option) is set and I18n-lookups are enabled in the
|
|
4
4
|
# configuration.
|
|
5
5
|
#
|
|
@@ -28,50 +28,50 @@ module Formtastic
|
|
|
28
28
|
def get(key)
|
|
29
29
|
cache[key]
|
|
30
30
|
end
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
def has_key?(key)
|
|
33
33
|
cache.has_key?(key)
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
def set(key, result)
|
|
37
37
|
cache[key] = result
|
|
38
38
|
end
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
def cache
|
|
41
41
|
@cache ||= {}
|
|
42
42
|
end
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
def clear!
|
|
45
45
|
cache.clear
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
attr_accessor :builder
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
def self.cache
|
|
52
52
|
@cache ||= Cache.new
|
|
53
53
|
end
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
def initialize(current_builder)
|
|
56
|
-
self.builder = current_builder
|
|
56
|
+
self.builder = current_builder
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def localize(key, value, type, options = {}) # @private
|
|
60
60
|
key = value if value.is_a?(::Symbol)
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
if value.is_a?(::String)
|
|
63
63
|
escape_html_entities(value)
|
|
64
64
|
else
|
|
65
65
|
use_i18n = value.nil? ? i18n_lookups_by_default : (value != false)
|
|
66
66
|
use_cache = i18n_cache_lookups
|
|
67
67
|
cache = self.class.cache
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
if use_i18n
|
|
70
70
|
model_name, nested_model_name = normalize_model_name(builder.model_name.underscore)
|
|
71
71
|
|
|
72
72
|
action_name = builder.template.params[:action].to_s rescue ''
|
|
73
73
|
attribute_name = key.to_s
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
# look in the cache first
|
|
76
76
|
if use_cache
|
|
77
77
|
cache_key = [::I18n.locale, action_name, model_name, nested_model_name, attribute_name, key, value, type, options]
|
|
@@ -86,7 +86,7 @@ module Formtastic
|
|
|
86
86
|
i18n_path.gsub!('%{model}', model_name)
|
|
87
87
|
i18n_path.gsub!('%{nested_model}', nested_model_name) unless nested_model_name.nil?
|
|
88
88
|
i18n_path.gsub!('%{attribute}', attribute_name)
|
|
89
|
-
i18n_path.
|
|
89
|
+
i18n_path.tr!('..', '.')
|
|
90
90
|
i18n_path.to_sym
|
|
91
91
|
end
|
|
92
92
|
defaults << ''
|
|
@@ -101,9 +101,9 @@ module Formtastic
|
|
|
101
101
|
# This is effectively what Rails label helper does for i18n lookup
|
|
102
102
|
options[:scope] = [:helpers, type]
|
|
103
103
|
options[:default] = defaults
|
|
104
|
-
i18n_value = ::I18n.t(default_key, options)
|
|
104
|
+
i18n_value = ::I18n.t(default_key, **options)
|
|
105
105
|
end
|
|
106
|
-
|
|
106
|
+
|
|
107
107
|
# save the result to the cache
|
|
108
108
|
result = (i18n_value.is_a?(::String) && i18n_value.present?) ? escape_html_entities(i18n_value) : nil
|
|
109
109
|
cache.set(cache_key, result) if use_cache
|
|
@@ -115,16 +115,14 @@ module Formtastic
|
|
|
115
115
|
protected
|
|
116
116
|
|
|
117
117
|
def normalize_model_name(name)
|
|
118
|
-
if
|
|
119
|
-
#
|
|
120
|
-
|
|
121
|
-
elsif name =~ /(.+)\[(.+)\]/
|
|
122
|
-
# Rails 3 (and 3.1?) nested builder case with :post rather than @post
|
|
118
|
+
if name =~ /(.+)\[(.+)\]/
|
|
119
|
+
# Nested builder case with :post rather than @post
|
|
120
|
+
# TODO: check if this is no longer required with a minimum of Rails 4.1
|
|
123
121
|
[$1, $2]
|
|
124
122
|
elsif builder.respond_to?(:options) && builder.options.key?(:as)
|
|
125
123
|
[builder.options[:as].to_s]
|
|
126
124
|
elsif builder.respond_to?(:options) && builder.options.key?(:parent_builder)
|
|
127
|
-
# Rails 3.0 nested builder work-around case, where :parent_builder is provided by f.semantic_form_for
|
|
125
|
+
# Rails 3.0+ nested builder work-around case, where :parent_builder is provided by f.semantic_form_for
|
|
128
126
|
[builder.options[:parent_builder].object_name.to_s, name]
|
|
129
127
|
else
|
|
130
128
|
# Non-nested case
|
|
@@ -143,7 +141,7 @@ module Formtastic
|
|
|
143
141
|
def i18n_lookups_by_default
|
|
144
142
|
builder.i18n_lookups_by_default
|
|
145
143
|
end
|
|
146
|
-
|
|
144
|
+
|
|
147
145
|
def i18n_cache_lookups
|
|
148
146
|
builder.i18n_cache_lookups
|
|
149
147
|
end
|
|
@@ -29,7 +29,7 @@ module Formtastic
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def self.use_const_defined?
|
|
32
|
-
defined?(Rails) && ::Rails.application && ::Rails.application.config.eager_load
|
|
32
|
+
defined?(Rails) && ::Rails.application && ::Rails.application.config.respond_to?(:eager_load) && ::Rails.application.config.eager_load
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
# @param namespaces [Array<Module>]
|
data/lib/formtastic/version.rb
CHANGED
|
@@ -75,7 +75,7 @@ module Formtastic
|
|
|
75
75
|
# Skips Active Record Timestamps.
|
|
76
76
|
def content_columns
|
|
77
77
|
model.content_columns.select do |column|
|
|
78
|
-
!Formtastic::
|
|
78
|
+
!Formtastic::FormBuilder.skipped_columns.include? column.name.to_sym
|
|
79
79
|
end
|
|
80
80
|
end
|
|
81
81
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module Formtastic
|
|
2
|
+
|
|
3
|
+
# Modify existing inputs, subclass them, or create your own from scratch.
|
|
4
|
+
# @example
|
|
5
|
+
# !!!shell
|
|
6
|
+
# $ rails generate formtastic:input HatSize
|
|
7
|
+
|
|
8
|
+
# @example Define input name using underscore convention
|
|
9
|
+
# !!!shell
|
|
10
|
+
# $ rails generate formtastic:input hat_size
|
|
11
|
+
|
|
12
|
+
# @example Override an existing input behavior
|
|
13
|
+
# !!!shell
|
|
14
|
+
# $ rails generate formtastic:input string --extend
|
|
15
|
+
|
|
16
|
+
# @example Extend an existing input behavior
|
|
17
|
+
# !!!shell
|
|
18
|
+
# $ rails generate formtastic:input FlexibleText --extend string
|
|
19
|
+
class InputGenerator < Rails::Generators::NamedBase
|
|
20
|
+
|
|
21
|
+
argument :name, :type => :string, :required => true, :banner => 'FILE_NAME'
|
|
22
|
+
|
|
23
|
+
source_root File.expand_path('../../../templates', __FILE__)
|
|
24
|
+
|
|
25
|
+
class_option :extend
|
|
26
|
+
|
|
27
|
+
def create
|
|
28
|
+
normalize_file_name
|
|
29
|
+
define_extension_sentence
|
|
30
|
+
template "input.rb", "app/inputs/#{name.underscore}_input.rb"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
protected
|
|
34
|
+
|
|
35
|
+
def normalize_file_name
|
|
36
|
+
name.chomp!("Input") if name.ends_with?("Input")
|
|
37
|
+
name.chomp!("_input") if name.ends_with?("_input")
|
|
38
|
+
name.chomp!("input") if name.ends_with?("input")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def define_extension_sentence
|
|
42
|
+
@extension_sentence = "< Formtastic::Inputs::#{name.camelize}Input" if options[:extend] == "extend"
|
|
43
|
+
@extension_sentence ||= "< Formtastic::Inputs::#{options[:extend].camelize}Input" if options[:extend]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
# Defaults to true.
|
|
18
18
|
# Formtastic::FormBuilder.include_blank_for_select_by_default = true
|
|
19
19
|
|
|
20
|
-
# Set the string that will be appended to the labels/fieldsets which are required
|
|
20
|
+
# Set the string that will be appended to the labels/fieldsets which are required.
|
|
21
21
|
# It accepts string or procs and the default is a localized version of
|
|
22
22
|
# '<abbr title="required">*</abbr>'. In other words, if you configure formtastic.required
|
|
23
23
|
# in your locale, it will replace the abbr title properly. But if you don't want to use
|
|
24
|
-
# abbr tag, you can simply give a string as below
|
|
24
|
+
# abbr tag, you can simply give a string as below.
|
|
25
25
|
# Formtastic::FormBuilder.required_string = "(required)"
|
|
26
26
|
|
|
27
|
-
# Set the string that will be appended to the labels/fieldsets which are optional
|
|
28
|
-
# Defaults to an empty string ("") and also accepts procs (see required_string above)
|
|
27
|
+
# Set the string that will be appended to the labels/fieldsets which are optional.
|
|
28
|
+
# Defaults to an empty string ("") and also accepts procs (see required_string above).
|
|
29
29
|
# Formtastic::FormBuilder.optional_string = "(optional)"
|
|
30
30
|
|
|
31
31
|
# Set the way inline errors will be displayed.
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
# Formtastic::FormBuilder.inline_errors = :sentence
|
|
34
34
|
# Formtastic uses the following classes as default for hints, inline_errors and error list
|
|
35
35
|
|
|
36
|
-
# If you override the class here, please ensure to override it in your stylesheets as well
|
|
36
|
+
# If you override the class here, please ensure to override it in your stylesheets as well.
|
|
37
37
|
# Formtastic::FormBuilder.default_hint_class = "inline-hints"
|
|
38
38
|
# Formtastic::FormBuilder.default_inline_error_class = "inline-errors"
|
|
39
39
|
# Formtastic::FormBuilder.default_error_list_class = "errors"
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
# can change it to any class you want.
|
|
71
71
|
# Formtastic::Helpers::FormHelper.default_form_class = 'formtastic'
|
|
72
72
|
|
|
73
|
-
# Formtastic will infer a class name from the model, array, string
|
|
73
|
+
# Formtastic will infer a class name from the model, array, string or symbol you pass to the
|
|
74
74
|
# form builder. You can customize the way that class is presented by overriding
|
|
75
75
|
# this proc.
|
|
76
76
|
# Formtastic::Helpers::FormHelper.default_form_model_class_proc = proc { |model_class_name| model_class_name }
|
|
@@ -85,15 +85,14 @@
|
|
|
85
85
|
# Formtastic::FormBuilder.use_required_attribute = false
|
|
86
86
|
|
|
87
87
|
# You can opt-in to new HTML5 browser validations (for things like email and url inputs) by setting
|
|
88
|
-
# this to true. Doing so will
|
|
88
|
+
# this to true. Doing so will omit the `novalidate` attribute from the `<form>` tag.
|
|
89
89
|
# See http://diveintohtml5.org/forms.html#validation for more info.
|
|
90
90
|
# Formtastic::FormBuilder.perform_browser_validations = true
|
|
91
91
|
|
|
92
92
|
# By creating custom input class finder, you can change how input classes are looked up.
|
|
93
93
|
# For example you can make it to search for TextInputFilter instead of TextInput.
|
|
94
|
-
# See
|
|
95
|
-
#
|
|
96
|
-
Formtastic::FormBuilder.input_class_finder = Formtastic::InputClassFinder
|
|
94
|
+
# See https://github.com/formtastic/formtastic/wiki/Custom-Class-Finders
|
|
95
|
+
# Formtastic::FormBuilder.input_class_finder = Formtastic::InputClassFinder
|
|
97
96
|
|
|
98
97
|
# Define custom namespaces in which to look up your Input classes. Default is
|
|
99
98
|
# to look up in the global scope and in Formtastic::Inputs.
|
|
@@ -101,10 +100,12 @@ Formtastic::FormBuilder.input_class_finder = Formtastic::InputClassFinder
|
|
|
101
100
|
|
|
102
101
|
# By creating custom action class finder, you can change how action classes are looked up.
|
|
103
102
|
# For example you can make it to search for MyButtonAction instead of ButtonAction.
|
|
104
|
-
# See
|
|
105
|
-
#
|
|
106
|
-
Formtastic::FormBuilder.action_class_finder = Formtastic::ActionClassFinder
|
|
103
|
+
# See https://github.com/formtastic/formtastic/wiki/Custom-Class-Finders
|
|
104
|
+
# Formtastic::FormBuilder.action_class_finder = Formtastic::ActionClassFinder
|
|
107
105
|
|
|
108
106
|
# Define custom namespaces in which to look up your Action classes. Default is
|
|
109
107
|
# to look up in the global scope and in Formtastic::Actions.
|
|
110
108
|
# Formtastic::FormBuilder.action_namespaces = [ ::Object, ::MyActionsModule, ::Formtastic::Actions ]
|
|
109
|
+
|
|
110
|
+
# Which columns to skip when automatically rendering a form without any fields specified.
|
|
111
|
+
# Formtastic::FormBuilder.skipped_columns = [:created_at, :updated_at, :created_on, :updated_on, :lock_version, :version]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class <%= name.camelize %>Input <%= @extension_sentence %>
|
|
2
|
+
<%- if !options[:extend] -%>
|
|
3
|
+
include Formtastic::Inputs::Base
|
|
4
|
+
<%- end -%>
|
|
5
|
+
|
|
6
|
+
<%- if !options[:extend] || (options[:extend] == "extend") -%>
|
|
7
|
+
def to_html
|
|
8
|
+
# Add your custom input definition here.
|
|
9
|
+
<%- if options[:extend] == "extend" -%>
|
|
10
|
+
super
|
|
11
|
+
<%- end -%>
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
<%- else -%>
|
|
15
|
+
def input_html_options
|
|
16
|
+
# Add your custom input extension here.
|
|
17
|
+
end
|
|
18
|
+
<%- end -%>
|
|
19
|
+
end
|
data/sample/basic_inputs.html
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
<li class="input url stringish optional" id="gem_url_input">
|
|
37
37
|
<label class="label" for="gem_url">URL</label>
|
|
38
38
|
<input id="gem_url" name="gem[url]" type="url">
|
|
39
|
-
<p class="inline-hints">Example: https://github.com/
|
|
39
|
+
<p class="inline-hints">Example: https://github.com/formtastic/formtastic</p>
|
|
40
40
|
</li>
|
|
41
41
|
|
|
42
42
|
<li class="input password stringish required" id="gem_password_input">
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
gem 'formtastic', path: '..'
|
|
2
|
+
gem 'bcrypt', '~> 3.1.7'
|
|
3
|
+
gem 'rails-dom-testing', group: :test
|
|
4
|
+
gem 'rexml', '~> 3.2' # to compensate for missing dependency in selenium-webdriver
|
|
5
|
+
|
|
6
|
+
# to speed up bundle install, reuse the bundle path
|
|
7
|
+
def bundle_path
|
|
8
|
+
File.expand_path ENV.fetch('BUNDLE_PATH', 'vendor/bundle')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
if Rails.version >= '6.2'
|
|
12
|
+
gsub_file 'Gemfile', /gem 'rails'.*/, "gem 'rails', '~> #{Rails.version}', github: 'rails/rails'"
|
|
13
|
+
elsif Rails.version >= '6.1'
|
|
14
|
+
gsub_file 'Gemfile', /gem 'rails'.*/, "gem 'rails', '~> #{Rails.version}', github: 'rails/rails', branch: '6-1-stable'"
|
|
15
|
+
elsif Rails.version >= '6.0'
|
|
16
|
+
gsub_file 'Gemfile', /gem 'rails'.*/, "gem 'rails', '~> #{Rails.version}', github: 'rails/rails', branch: '6-0-stable'"
|
|
17
|
+
elsif Rails.version >= '5.2'
|
|
18
|
+
gsub_file 'Gemfile', /gem 'rails'.*/, "gem 'rails', '~> #{Rails.version}', github: 'rails/rails', branch: '5-2-stable'"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
### Ensure Dummy App's Ruby version matches the current environments Ruby Version
|
|
22
|
+
ruby_version = "ruby '#{RUBY_VERSION}'"
|
|
23
|
+
gsub_file 'Gemfile', /ruby '\d+.\d+.\d+'/, ruby_version
|
|
24
|
+
|
|
25
|
+
if bundle_install?
|
|
26
|
+
def run_bundle
|
|
27
|
+
previous_bundle_path = bundle_path
|
|
28
|
+
|
|
29
|
+
require "bundler"
|
|
30
|
+
Bundler.with_clean_env do
|
|
31
|
+
system("bundle install --jobs=3 --retry=3 --path=#{previous_bundle_path}")
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
in_root do
|
|
37
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
formtastic = -> do
|
|
41
|
+
generate(:scaffold, 'user name:string password:digest')
|
|
42
|
+
generate('formtastic:install')
|
|
43
|
+
generate('formtastic:form', 'user name password:password --force')
|
|
44
|
+
|
|
45
|
+
rails_command('db:migrate')
|
|
46
|
+
|
|
47
|
+
in_root do
|
|
48
|
+
inject_into_class 'app/models/user.rb', 'User', " has_secure_password\n"
|
|
49
|
+
inject_into_file 'app/assets/stylesheets/application.css', " *= require formtastic\n", before: ' *= require_self'
|
|
50
|
+
inject_into_class 'test/controllers/users_controller_test.rb', 'UsersControllerTest', <<-RUBY
|
|
51
|
+
|
|
52
|
+
test "should show form" do
|
|
53
|
+
get edit_user_path(@user)
|
|
54
|
+
|
|
55
|
+
assert_select 'form' do
|
|
56
|
+
assert_select 'li.input.string' do
|
|
57
|
+
assert_select 'input#user_name[type=text]'
|
|
58
|
+
end
|
|
59
|
+
assert_select 'li.input.password' do
|
|
60
|
+
assert_select 'input#user_password[type=password]'
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
assert_select 'fieldset.actions' do
|
|
64
|
+
assert_select 'li.action.input_action' do
|
|
65
|
+
assert_select 'input[type=submit]'
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end # test "should show form"
|
|
70
|
+
RUBY
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
after_bundle(&formtastic)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
|
|
3
|
+
set -e
|
|
4
|
+
set -o verbose
|
|
5
|
+
|
|
6
|
+
test_app=dummy
|
|
7
|
+
|
|
8
|
+
rm -rf ${test_app}
|
|
9
|
+
|
|
10
|
+
bundle exec rails new ${test_app} \
|
|
11
|
+
--template=$(dirname "$0")/integration-template.rb \
|
|
12
|
+
--skip-bootsnap \
|
|
13
|
+
--skip-javascript \
|
|
14
|
+
--skip-spring \
|
|
15
|
+
--skip-turbolinks
|
|
16
|
+
|
|
17
|
+
cd ${test_app} && export BUNDLE_GEMFILE=Gemfile
|
|
18
|
+
|
|
19
|
+
bundle exec rake test
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
|
-
describe 'ButtonAction', 'when submitting' do
|
|
4
|
+
RSpec.describe 'ButtonAction', 'when submitting' do
|
|
5
5
|
|
|
6
6
|
include FormtasticSpecHelper
|
|
7
7
|
|
|
@@ -15,12 +15,12 @@ describe 'ButtonAction', 'when submitting' do
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it 'should render a submit type of button' do
|
|
18
|
-
output_buffer.
|
|
18
|
+
expect(output_buffer).to have_tag('li.action.button_action button[@type="submit"]')
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
describe 'ButtonAction', 'when resetting' do
|
|
23
|
+
RSpec.describe 'ButtonAction', 'when resetting' do
|
|
24
24
|
|
|
25
25
|
include FormtasticSpecHelper
|
|
26
26
|
|
|
@@ -34,16 +34,16 @@ describe 'ButtonAction', 'when resetting' do
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it 'should render a reset type of button' do
|
|
37
|
-
output_buffer.
|
|
37
|
+
expect(output_buffer).to have_tag('li.action.button_action button[@type="reset"]', :text => "Reset Post")
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it 'should not render a value attribute' do
|
|
41
|
-
output_buffer.
|
|
41
|
+
expect(output_buffer).not_to have_tag('li.action.button_action button[@value]')
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
describe 'InputAction', 'when cancelling' do
|
|
46
|
+
RSpec.describe 'InputAction', 'when cancelling' do
|
|
47
47
|
|
|
48
48
|
include FormtasticSpecHelper
|
|
49
49
|
|
|
@@ -53,11 +53,11 @@ describe 'InputAction', 'when cancelling' do
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
it 'should raise an error' do
|
|
56
|
-
|
|
56
|
+
expect {
|
|
57
57
|
concat(semantic_form_for(@new_post) do |builder|
|
|
58
58
|
concat(builder.action(:cancel, :as => :button))
|
|
59
59
|
end)
|
|
60
|
-
}.
|
|
60
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
end
|