formtastic 3.1.5 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +5 -5
  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.md +627 -629
  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 +9 -15
  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 +5 -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 +8 -24
  23. data/lib/formtastic/helpers/action_helper.rb +1 -48
  24. data/lib/formtastic/helpers/errors_helper.rb +2 -2
  25. data/lib/formtastic/helpers/fieldset_wrapper.rb +7 -3
  26. data/lib/formtastic/helpers/input_helper.rb +18 -76
  27. data/lib/formtastic/helpers/inputs_helper.rb +12 -3
  28. data/lib/formtastic/i18n.rb +1 -1
  29. data/lib/formtastic/inputs.rb +32 -29
  30. data/lib/formtastic/inputs/base/collections.rb +1 -5
  31. data/lib/formtastic/inputs/base/errors.rb +4 -4
  32. data/lib/formtastic/inputs/base/hints.rb +1 -1
  33. data/lib/formtastic/inputs/base/timeish.rb +5 -1
  34. data/lib/formtastic/inputs/base/validations.rb +19 -9
  35. data/lib/formtastic/inputs/check_boxes_input.rb +3 -3
  36. data/lib/formtastic/inputs/color_input.rb +0 -1
  37. data/lib/formtastic/inputs/select_input.rb +1 -1
  38. data/lib/formtastic/localizer.rb +5 -7
  39. data/lib/formtastic/version.rb +1 -1
  40. data/lib/generators/templates/formtastic.rb +4 -6
  41. data/sample/basic_inputs.html +1 -1
  42. data/script/integration-template.rb +74 -0
  43. data/script/integration.sh +19 -0
  44. data/spec/action_class_finder_spec.rb +1 -1
  45. data/spec/actions/button_action_spec.rb +8 -8
  46. data/spec/actions/generic_action_spec.rb +60 -60
  47. data/spec/actions/input_action_spec.rb +7 -7
  48. data/spec/actions/link_action_spec.rb +10 -10
  49. data/spec/builder/custom_builder_spec.rb +37 -21
  50. data/spec/builder/error_proc_spec.rb +4 -4
  51. data/spec/builder/semantic_fields_for_spec.rb +27 -27
  52. data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
  53. data/spec/generators/formtastic/input/input_generator_spec.rb +31 -31
  54. data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
  55. data/spec/helpers/action_helper_spec.rb +328 -10
  56. data/spec/helpers/actions_helper_spec.rb +17 -17
  57. data/spec/helpers/form_helper_spec.rb +33 -33
  58. data/spec/helpers/input_helper_spec.rb +975 -2
  59. data/spec/helpers/inputs_helper_spec.rb +120 -105
  60. data/spec/helpers/reflection_helper_spec.rb +3 -3
  61. data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
  62. data/spec/i18n_spec.rb +26 -26
  63. data/spec/input_class_finder_spec.rb +1 -1
  64. data/spec/inputs/base/collections_spec.rb +6 -6
  65. data/spec/inputs/base/validations_spec.rb +157 -19
  66. data/spec/inputs/boolean_input_spec.rb +55 -55
  67. data/spec/inputs/check_boxes_input_spec.rb +96 -95
  68. data/spec/inputs/color_input_spec.rb +51 -63
  69. data/spec/inputs/country_input_spec.rb +20 -20
  70. data/spec/inputs/custom_input_spec.rb +2 -6
  71. data/spec/inputs/datalist_input_spec.rb +1 -1
  72. data/spec/inputs/date_picker_input_spec.rb +42 -42
  73. data/spec/inputs/date_select_input_spec.rb +51 -37
  74. data/spec/inputs/datetime_picker_input_spec.rb +46 -46
  75. data/spec/inputs/datetime_select_input_spec.rb +53 -37
  76. data/spec/inputs/email_input_spec.rb +5 -5
  77. data/spec/inputs/file_input_spec.rb +6 -6
  78. data/spec/inputs/hidden_input_spec.rb +18 -18
  79. data/spec/inputs/include_blank_spec.rb +8 -8
  80. data/spec/inputs/label_spec.rb +20 -20
  81. data/spec/inputs/number_input_spec.rb +112 -112
  82. data/spec/inputs/password_input_spec.rb +5 -5
  83. data/spec/inputs/phone_input_spec.rb +5 -5
  84. data/spec/inputs/placeholder_spec.rb +5 -5
  85. data/spec/inputs/radio_input_spec.rb +63 -65
  86. data/spec/inputs/range_input_spec.rb +66 -66
  87. data/spec/inputs/readonly_spec.rb +4 -4
  88. data/spec/inputs/search_input_spec.rb +5 -5
  89. data/spec/inputs/select_input_spec.rb +92 -96
  90. data/spec/inputs/string_input_spec.rb +23 -23
  91. data/spec/inputs/text_input_spec.rb +16 -16
  92. data/spec/inputs/time_picker_input_spec.rb +43 -43
  93. data/spec/inputs/time_select_input_spec.rb +67 -54
  94. data/spec/inputs/time_zone_input_spec.rb +19 -19
  95. data/spec/inputs/url_input_spec.rb +5 -5
  96. data/spec/inputs/with_options_spec.rb +7 -7
  97. data/spec/localizer_spec.rb +17 -17
  98. data/spec/namespaced_class_finder_spec.rb +2 -2
  99. data/spec/schema.rb +21 -0
  100. data/spec/spec_helper.rb +163 -223
  101. data/spec/support/custom_macros.rb +72 -75
  102. data/spec/support/shared_examples.rb +0 -1301
  103. data/spec/support/test_environment.rb +23 -9
  104. metadata +36 -126
  105. data/.travis.yml +0 -46
  106. data/Appraisals +0 -43
  107. data/CHANGELOG +0 -54
  108. data/DEPRECATIONS +0 -52
  109. data/gemfiles/rails_3.2.gemfile +0 -9
  110. data/gemfiles/rails_4.0.4.gemfile +0 -8
  111. data/gemfiles/rails_4.1.gemfile +0 -8
  112. data/gemfiles/rails_4.2.gemfile +0 -8
  113. data/gemfiles/rails_4.gemfile +0 -8
  114. data/gemfiles/rails_5.0.gemfile +0 -8
  115. data/gemfiles/rails_edge.gemfile +0 -15
  116. data/lib/formtastic/util.rb +0 -57
  117. data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
  118. data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
  119. 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 do :name => 'Advanced options:' do %>
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 -= Formtastic::FormBuilder.skipped_columns
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{ |reflection| reflection.foreign_key.to_sym }
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
@@ -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, *(args << options))
26
+ ::I18n.translate(key, *args, **options)
27
27
  end
28
28
  alias :t :translate
29
29
 
@@ -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
- autoload :UrlInput
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
- if Util.rails3?
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, Formtastic::Util.html_safe(errors.to_sentence.html_safe), :class => error_class)
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, Formtastic::Util.html_safe(error.html_safe))
19
+ list_elements << template.content_tag(:li, error.html_safe)
20
20
  end
21
- template.content_tag(:ul, Formtastic::Util.html_safe(list_elements.join("\n")), :class => error_class)
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, Formtastic::Util.html_safe(errors.first.untaint), :class => error_class)
26
+ template.content_tag(:p, errors.first.untaint.html_safe, :class => error_class)
27
27
  end
28
28
 
29
29
  def error_none_html
@@ -7,7 +7,7 @@ module Formtastic
7
7
  if hint?
8
8
  template.content_tag(
9
9
  :p,
10
- Formtastic::Util.html_safe(hint_text),
10
+ hint_text.html_safe,
11
11
  :class => builder.default_hint_class
12
12
  )
13
13
  end
@@ -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].call(object)) if validation.options[:greater_than_or_equal_to].kind_of?(Proc)
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].call(object) + 1) if validation.options[:greater_than].kind_of?(Proc)
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].call(object)) if validation.options[:less_than_or_equal_to].kind_of?(Proc)
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 ((validation.options[:less_than].call(object)) - 1) if validation.options[:less_than].kind_of?(Proc)
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 hidden_fields?
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 hidden_fields?
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 hidden_fields?
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 => (multiple? && Rails::VERSION::MAJOR >= 3) ? input_html_options_name_multiple : input_html_options_name
199
+ :name => multiple? ? input_html_options_name_multiple : input_html_options_name
200
200
  }
201
201
 
202
202
 
@@ -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 !name =~ /\[/ && builder.respond_to?(:parent_builder) && builder.parent_builder.object_name
119
- # Rails 3.1 nested builder case
120
- [builder.parent_builder.object_name.to_s, name]
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
@@ -1,3 +1,3 @@
1
1
  module Formtastic
2
- VERSION = "3.1.5"
2
+ VERSION = "4.0.0"
3
3
  end
@@ -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 # TODO: add link # for more information
95
- # NOTE: this behavior will be default from Formtastic 4.0
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,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 # TODO: add link # for more information
105
- # NOTE: this behavior will be default from Formtastic 4.0
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.
@@ -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/justinfrench/formtastic</p>
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