formtastic 3.1.5 → 4.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitattributes +1 -0
- data/.gitignore +3 -2
- data/.travis.yml +28 -40
- data/CHANGELOG.md +49 -0
- data/DEPRECATIONS +1 -1
- data/Gemfile.lock +104 -0
- data/README.md +628 -629
- data/Rakefile +20 -1
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +8 -14
- data/gemfiles/rails_5.2/Gemfile +5 -0
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic.rb +5 -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 +8 -24
- data/lib/formtastic/helpers/action_helper.rb +1 -48
- data/lib/formtastic/helpers/errors_helper.rb +2 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +7 -3
- data/lib/formtastic/helpers/input_helper.rb +18 -76
- data/lib/formtastic/helpers/inputs_helper.rb +12 -3
- data/lib/formtastic/i18n.rb +1 -1
- data/lib/formtastic/inputs.rb +32 -29
- data/lib/formtastic/inputs/base/collections.rb +1 -5
- data/lib/formtastic/inputs/base/errors.rb +4 -4
- data/lib/formtastic/inputs/base/hints.rb +1 -1
- data/lib/formtastic/inputs/base/timeish.rb +5 -1
- data/lib/formtastic/inputs/base/validations.rb +19 -9
- data/lib/formtastic/inputs/check_boxes_input.rb +3 -3
- data/lib/formtastic/inputs/color_input.rb +0 -1
- data/lib/formtastic/inputs/select_input.rb +1 -1
- data/lib/formtastic/localizer.rb +5 -7
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/templates/formtastic.rb +4 -6
- data/script/integration-template.rb +71 -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 +36 -20
- data/spec/builder/error_proc_spec.rb +4 -4
- data/spec/builder/semantic_fields_for_spec.rb +27 -27
- data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
- data/spec/generators/formtastic/input/input_generator_spec.rb +31 -31
- 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 +33 -33
- 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 +6 -6
- data/spec/inputs/base/validations_spec.rb +157 -19
- data/spec/inputs/boolean_input_spec.rb +55 -55
- data/spec/inputs/check_boxes_input_spec.rb +96 -95
- 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 +63 -65
- data/spec/inputs/range_input_spec.rb +66 -66
- data/spec/inputs/readonly_spec.rb +4 -4
- data/spec/inputs/search_input_spec.rb +5 -5
- data/spec/inputs/select_input_spec.rb +92 -96
- 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 +19 -19
- 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 +163 -223
- data/spec/support/custom_macros.rb +72 -75
- data/spec/support/shared_examples.rb +0 -1301
- data/spec/support/test_environment.rb +23 -9
- metadata +33 -123
- data/Appraisals +0 -43
- data/CHANGELOG +0 -54
- data/gemfiles/rails_3.2.gemfile +0 -9
- data/gemfiles/rails_4.0.4.gemfile +0 -8
- data/gemfiles/rails_4.1.gemfile +0 -8
- data/gemfiles/rails_4.2.gemfile +0 -8
- data/gemfiles/rails_4.gemfile +0 -8
- data/gemfiles/rails_5.0.gemfile +0 -8
- data/gemfiles/rails_edge.gemfile +0 -15
- 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/util_spec.rb +0 -66
@@ -215,7 +215,7 @@ module Formtastic
|
|
215
215
|
# <%= f.input :title ... %>
|
216
216
|
# <%= f.input :body ... %>
|
217
217
|
# <% end %>
|
218
|
-
# <%= f.inputs
|
218
|
+
# <%= f.inputs :name => 'Advanced options:' do %>
|
219
219
|
# <%= f.input :user ... %>
|
220
220
|
# <%= f.input :categories ... %>
|
221
221
|
# <% end %>
|
@@ -310,7 +310,7 @@ module Formtastic
|
|
310
310
|
def default_columns_for_object
|
311
311
|
cols = association_columns(:belongs_to)
|
312
312
|
cols += content_columns
|
313
|
-
cols -=
|
313
|
+
cols -= skipped_columns
|
314
314
|
cols.compact
|
315
315
|
end
|
316
316
|
|
@@ -350,12 +350,21 @@ module Formtastic
|
|
350
350
|
end
|
351
351
|
end
|
352
352
|
|
353
|
+
# Collects all foreign key columns
|
354
|
+
def foreign_key_columns # @private
|
355
|
+
if @object.present? && @object.class.respond_to?(:reflect_on_all_associations)
|
356
|
+
@object.class.reflect_on_all_associations(:belongs_to).map(&:foreign_key)
|
357
|
+
else
|
358
|
+
[]
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
353
362
|
# Collects content columns (non-relation columns) for the current form object class.
|
354
363
|
def content_columns # @private
|
355
364
|
# TODO: NameError is raised by Inflector.constantize. Consider checking if it exists instead.
|
356
365
|
begin klass = model_name.constantize; rescue NameError; return [] end
|
357
366
|
return [] unless klass.respond_to?(:content_columns)
|
358
|
-
klass.content_columns.collect { |c| c.name.to_sym }.compact
|
367
|
+
klass.content_columns.collect { |c| c.name.to_sym }.compact - foreign_key_columns
|
359
368
|
end
|
360
369
|
|
361
370
|
# Deals with :for option when it's supplied to inputs methods. Additional
|
data/lib/formtastic/i18n.rb
CHANGED
@@ -23,7 +23,7 @@ module Formtastic
|
|
23
23
|
options = args.extract_options!
|
24
24
|
options.reverse_merge!(:default => DEFAULT_VALUES[key])
|
25
25
|
options[:scope] = [DEFAULT_SCOPE, options[:scope]].flatten.compact
|
26
|
-
::I18n.translate(key, *
|
26
|
+
::I18n.translate(key, *args, **options)
|
27
27
|
end
|
28
28
|
alias :t :translate
|
29
29
|
|
data/lib/formtastic/inputs.rb
CHANGED
@@ -4,36 +4,39 @@ module Formtastic
|
|
4
4
|
|
5
5
|
autoload :Base
|
6
6
|
autoload :Basic
|
7
|
-
autoload :BooleanInput
|
8
|
-
autoload :CheckBoxesInput
|
9
|
-
autoload :ColorInput
|
10
|
-
autoload :CountryInput
|
11
|
-
autoload :DatalistInput
|
12
|
-
autoload :DateInput
|
13
|
-
autoload :DatePickerInput
|
14
|
-
autoload :DatetimePickerInput
|
15
|
-
autoload :DateSelectInput
|
16
|
-
autoload :DatetimeInput
|
17
|
-
autoload :DatetimeSelectInput
|
18
|
-
autoload :EmailInput
|
19
|
-
autoload :FileInput
|
20
|
-
autoload :HiddenInput
|
21
|
-
autoload :NumberInput
|
22
|
-
autoload :NumericInput
|
23
|
-
autoload :PasswordInput
|
24
|
-
autoload :PhoneInput
|
25
|
-
autoload :RadioInput
|
26
|
-
autoload :RangeInput
|
27
|
-
autoload :SearchInput
|
28
|
-
autoload :SelectInput
|
29
|
-
autoload :StringInput
|
30
|
-
autoload :TextInput
|
31
|
-
autoload :TimeInput
|
32
|
-
autoload :TimePickerInput
|
33
|
-
autoload :TimeSelectInput
|
34
|
-
autoload :TimeZoneInput
|
35
7
|
autoload :Timeish
|
36
|
-
|
8
|
+
|
9
|
+
eager_autoload do
|
10
|
+
autoload :BooleanInput
|
11
|
+
autoload :CheckBoxesInput
|
12
|
+
autoload :ColorInput
|
13
|
+
autoload :CountryInput
|
14
|
+
autoload :DatalistInput
|
15
|
+
autoload :DateInput
|
16
|
+
autoload :DatePickerInput
|
17
|
+
autoload :DatetimePickerInput
|
18
|
+
autoload :DateSelectInput
|
19
|
+
autoload :DatetimeInput
|
20
|
+
autoload :DatetimeSelectInput
|
21
|
+
autoload :EmailInput
|
22
|
+
autoload :FileInput
|
23
|
+
autoload :HiddenInput
|
24
|
+
autoload :NumberInput
|
25
|
+
autoload :NumericInput
|
26
|
+
autoload :PasswordInput
|
27
|
+
autoload :PhoneInput
|
28
|
+
autoload :RadioInput
|
29
|
+
autoload :RangeInput
|
30
|
+
autoload :SearchInput
|
31
|
+
autoload :SelectInput
|
32
|
+
autoload :StringInput
|
33
|
+
autoload :TextInput
|
34
|
+
autoload :TimeInput
|
35
|
+
autoload :TimePickerInput
|
36
|
+
autoload :TimeSelectInput
|
37
|
+
autoload :TimeZoneInput
|
38
|
+
autoload :UrlInput
|
39
|
+
end
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
@@ -84,11 +84,7 @@ module Formtastic
|
|
84
84
|
scope_conditions = conditions_from_reflection.empty? ? nil : {:conditions => conditions_from_reflection}
|
85
85
|
where_conditions = (scope_conditions && scope_conditions[:conditions]) || {}
|
86
86
|
|
87
|
-
|
88
|
-
reflection.klass.scoped(scope_conditions).where({}) # where is uneccessary, but keeps the stubbing simpler while we support rails3
|
89
|
-
else
|
90
|
-
reflection.klass.where(where_conditions)
|
91
|
-
end
|
87
|
+
reflection.klass.where(where_conditions)
|
92
88
|
end
|
93
89
|
end
|
94
90
|
|
@@ -9,21 +9,21 @@ module Formtastic
|
|
9
9
|
|
10
10
|
def error_sentence_html
|
11
11
|
error_class = builder.default_inline_error_class
|
12
|
-
template.content_tag(:p,
|
12
|
+
template.content_tag(:p, errors.to_sentence, :class => error_class)
|
13
13
|
end
|
14
14
|
|
15
15
|
def error_list_html
|
16
16
|
error_class = builder.default_error_list_class
|
17
17
|
list_elements = []
|
18
18
|
errors.each do |error|
|
19
|
-
list_elements << template.content_tag(:li,
|
19
|
+
list_elements << template.content_tag(:li, error.html_safe)
|
20
20
|
end
|
21
|
-
template.content_tag(:ul,
|
21
|
+
template.content_tag(:ul, list_elements.join("\n").html_safe, :class => error_class)
|
22
22
|
end
|
23
23
|
|
24
24
|
def error_first_html
|
25
25
|
error_class = builder.default_inline_error_class
|
26
|
-
template.content_tag(:p,
|
26
|
+
template.content_tag(:p, errors.first.untaint.html_safe, :class => error_class)
|
27
27
|
end
|
28
28
|
|
29
29
|
def error_none_html
|
@@ -85,6 +85,9 @@ module Formtastic
|
|
85
85
|
# <%= f.input :publish_at, :as => :time_select, :include_blank => true %>
|
86
86
|
# <%= f.input :publish_at, :as => :time_select, :include_blank => false %>
|
87
87
|
#
|
88
|
+
# @example Provide a value for the field via selected
|
89
|
+
# <%= f.input :publish_at, :as => :datetime_select, :selected => DateTime.new(2018, 10, 4, 12, 00)
|
90
|
+
#
|
88
91
|
# @todo Document i18n
|
89
92
|
# @todo Check what other Rails options are supported (`start_year`, `end_year`, `use_month_numbers`, `use_short_month`, `add_month_numbers`, `prompt`), write tests for them, and otherwise support them
|
90
93
|
# @todo Could we take the rendering from Rails' helpers and inject better HTML in and around it rather than re-inventing the whee?
|
@@ -157,6 +160,7 @@ module Formtastic
|
|
157
160
|
end
|
158
161
|
|
159
162
|
def value
|
163
|
+
return input_options[:selected] if options.key?(:selected)
|
160
164
|
object.send(method) if object && object.respond_to?(method)
|
161
165
|
end
|
162
166
|
|
@@ -238,4 +242,4 @@ module Formtastic
|
|
238
242
|
end
|
239
243
|
end
|
240
244
|
end
|
241
|
-
end
|
245
|
+
end
|
@@ -73,13 +73,11 @@ module Formtastic
|
|
73
73
|
raise IndeterminableMinimumAttributeError if validation.options[:greater_than] && column? && [:float, :decimal].include?(column.type)
|
74
74
|
|
75
75
|
if validation.options[:greater_than_or_equal_to]
|
76
|
-
return (validation.options[:greater_than_or_equal_to]
|
77
|
-
return (validation.options[:greater_than_or_equal_to])
|
76
|
+
return option_value(validation.options[:greater_than_or_equal_to], object)
|
78
77
|
end
|
79
78
|
|
80
79
|
if validation.options[:greater_than]
|
81
|
-
return (validation.options[:greater_than]
|
82
|
-
return (validation.options[:greater_than] + 1)
|
80
|
+
return option_value(validation.options[:greater_than], object) + 1
|
83
81
|
end
|
84
82
|
end
|
85
83
|
end
|
@@ -94,13 +92,11 @@ module Formtastic
|
|
94
92
|
raise IndeterminableMaximumAttributeError if validation.options[:less_than] && column? && [:float, :decimal].include?(column.type)
|
95
93
|
|
96
94
|
if validation.options[:less_than_or_equal_to]
|
97
|
-
return (validation.options[:less_than_or_equal_to]
|
98
|
-
return (validation.options[:less_than_or_equal_to])
|
95
|
+
return option_value(validation.options[:less_than_or_equal_to], object)
|
99
96
|
end
|
100
97
|
|
101
98
|
if validation.options[:less_than]
|
102
|
-
return (
|
103
|
-
return (validation.options[:less_than] - 1)
|
99
|
+
return option_value(validation.options[:less_than], object) - 1
|
104
100
|
end
|
105
101
|
end
|
106
102
|
end
|
@@ -208,8 +204,22 @@ module Formtastic
|
|
208
204
|
def readonly_from_options?
|
209
205
|
options[:input_html] && options[:input_html][:readonly]
|
210
206
|
end
|
207
|
+
|
208
|
+
private
|
209
|
+
|
210
|
+
# Loosely based on
|
211
|
+
# https://github.com/rails/rails/blob/5-2-stable/activemodel/lib/active_model/validations/numericality.rb#L54-L59
|
212
|
+
def option_value(option, object)
|
213
|
+
case option
|
214
|
+
when Symbol
|
215
|
+
object.send(option)
|
216
|
+
when Proc
|
217
|
+
option.call(object)
|
218
|
+
else
|
219
|
+
option
|
220
|
+
end
|
221
|
+
end
|
211
222
|
end
|
212
223
|
end
|
213
224
|
end
|
214
225
|
end
|
215
|
-
|
@@ -99,7 +99,7 @@ module Formtastic
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def hidden_field_for_all
|
102
|
-
if
|
102
|
+
if hidden_fields_for_every?
|
103
103
|
''
|
104
104
|
else
|
105
105
|
options = {}
|
@@ -109,7 +109,7 @@ module Formtastic
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
def
|
112
|
+
def hidden_fields_for_every?
|
113
113
|
options[:hidden_fields]
|
114
114
|
end
|
115
115
|
|
@@ -170,7 +170,7 @@ module Formtastic
|
|
170
170
|
protected
|
171
171
|
|
172
172
|
def checkbox_input(choice)
|
173
|
-
if
|
173
|
+
if hidden_fields_for_every?
|
174
174
|
check_box_with_hidden_input(choice)
|
175
175
|
else
|
176
176
|
check_box_without_hidden_input(choice)
|
@@ -31,7 +31,6 @@ module Formtastic
|
|
31
31
|
include Base::Placeholder
|
32
32
|
|
33
33
|
def to_html
|
34
|
-
raise "The :color input requires the color_field form helper, which is only available in Rails 4+" unless builder.respond_to?(:color_field)
|
35
34
|
input_wrapping do
|
36
35
|
label_html <<
|
37
36
|
builder.color_field(method, input_html_options)
|
@@ -196,7 +196,7 @@ module Formtastic
|
|
196
196
|
def extra_input_html_options
|
197
197
|
{
|
198
198
|
:multiple => multiple?,
|
199
|
-
:name =>
|
199
|
+
:name => multiple? ? input_html_options_name_multiple : input_html_options_name
|
200
200
|
}
|
201
201
|
|
202
202
|
|
data/lib/formtastic/localizer.rb
CHANGED
@@ -101,7 +101,7 @@ 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
|
@@ -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
|
data/lib/formtastic/version.rb
CHANGED
@@ -91,9 +91,8 @@
|
|
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/justinfrench/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,9 +100,8 @@ 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/justinfrench/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.
|
@@ -0,0 +1,71 @@
|
|
1
|
+
gem 'formtastic', path: '..'
|
2
|
+
gem 'bcrypt', '~> 3.1.7'
|
3
|
+
gem 'rails-dom-testing', group: :test
|
4
|
+
|
5
|
+
# to speed up travis install, reuse the bundle path
|
6
|
+
def bundle_path
|
7
|
+
File.expand_path ENV.fetch('BUNDLE_PATH', 'vendor/bundle'), ENV['TRAVIS_BUILD_DIR']
|
8
|
+
end
|
9
|
+
|
10
|
+
if Rails.version >= '6.1'
|
11
|
+
gsub_file 'Gemfile', /gem 'rails'.*/, "gem 'rails', '~> #{Rails.version}', github: 'rails/rails'"
|
12
|
+
elsif Rails.version >= '6.0'
|
13
|
+
gsub_file 'Gemfile', /gem 'rails'.*/, "gem 'rails', '~> #{Rails.version}', github: 'rails/rails', branch: '6-0-stable'"
|
14
|
+
elsif Rails.version >= '5.2'
|
15
|
+
gsub_file 'Gemfile', /gem 'rails'.*/, "gem 'rails', '~> #{Rails.version}', github: 'rails/rails', branch: '5-2-stable'"
|
16
|
+
end
|
17
|
+
|
18
|
+
### Ensure Dummy App's Ruby version matches the current environments Ruby Version
|
19
|
+
ruby_version = "ruby '#{RUBY_VERSION}'"
|
20
|
+
gsub_file 'Gemfile', /ruby '\d+.\d+.\d+'/, ruby_version
|
21
|
+
|
22
|
+
if File.directory?(bundle_path) && bundle_install?
|
23
|
+
def run_bundle
|
24
|
+
previous_bundle_path = bundle_path
|
25
|
+
|
26
|
+
require "bundler"
|
27
|
+
Bundler.with_clean_env do
|
28
|
+
system("bundle install --jobs=3 --retry=3 --path=#{previous_bundle_path}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
in_root do
|
34
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile')
|
35
|
+
end
|
36
|
+
|
37
|
+
formtastic = -> do
|
38
|
+
generate(:scaffold, 'user name:string password:digest')
|
39
|
+
generate('formtastic:install')
|
40
|
+
generate('formtastic:form', 'user name password:password --force')
|
41
|
+
|
42
|
+
rails_command('db:migrate')
|
43
|
+
|
44
|
+
in_root do
|
45
|
+
inject_into_class 'app/models/user.rb', 'User', " has_secure_password\n"
|
46
|
+
inject_into_file 'app/assets/stylesheets/application.css', " *= require formtastic\n", before: ' *= require_self'
|
47
|
+
inject_into_class 'test/controllers/users_controller_test.rb', 'UsersControllerTest', <<-RUBY
|
48
|
+
|
49
|
+
test "should show form" do
|
50
|
+
get edit_user_path(@user)
|
51
|
+
|
52
|
+
assert_select 'form' do
|
53
|
+
assert_select 'li.input.string' do
|
54
|
+
assert_select 'input#user_name[type=text]'
|
55
|
+
end
|
56
|
+
assert_select 'li.input.password' do
|
57
|
+
assert_select 'input#user_password[type=password]'
|
58
|
+
end
|
59
|
+
|
60
|
+
assert_select 'fieldset.actions' do
|
61
|
+
assert_select 'li.action.input_action' do
|
62
|
+
assert_select 'input[type=submit]'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end # test "should show form"
|
67
|
+
RUBY
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
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
|