formtastic 2.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +1 -0
  3. data/.github/workflows/test.yml +61 -0
  4. data/.gitignore +4 -2
  5. data/CHANGELOG.md +52 -0
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +105 -0
  8. data/MIT-LICENSE +1 -1
  9. data/{README.textile → README.md} +204 -219
  10. data/RELEASE_PROCESS +3 -1
  11. data/Rakefile +27 -29
  12. data/app/assets/stylesheets/formtastic.css +3 -2
  13. data/bin/appraisal +8 -0
  14. data/formtastic.gemspec +11 -14
  15. data/gemfiles/rails_5.2/Gemfile +5 -0
  16. data/gemfiles/rails_6.0/Gemfile +5 -0
  17. data/gemfiles/rails_6.1/Gemfile +5 -0
  18. data/gemfiles/rails_edge/Gemfile +13 -0
  19. data/lib/formtastic/action_class_finder.rb +18 -0
  20. data/lib/formtastic/actions/button_action.rb +55 -60
  21. data/lib/formtastic/actions/input_action.rb +59 -57
  22. data/lib/formtastic/actions/link_action.rb +68 -67
  23. data/lib/formtastic/actions.rb +6 -3
  24. data/lib/formtastic/deprecation.rb +5 -0
  25. data/lib/formtastic/engine.rb +3 -1
  26. data/lib/formtastic/form_builder.rb +35 -16
  27. data/lib/formtastic/helpers/action_helper.rb +34 -28
  28. data/lib/formtastic/helpers/enum.rb +13 -0
  29. data/lib/formtastic/helpers/errors_helper.rb +2 -2
  30. data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -12
  31. data/lib/formtastic/helpers/form_helper.rb +19 -16
  32. data/lib/formtastic/helpers/input_helper.rb +69 -97
  33. data/lib/formtastic/helpers/inputs_helper.rb +35 -25
  34. data/lib/formtastic/helpers/reflection.rb +4 -4
  35. data/lib/formtastic/helpers.rb +1 -2
  36. data/lib/formtastic/html_attributes.rb +12 -1
  37. data/lib/formtastic/i18n.rb +1 -1
  38. data/lib/formtastic/input_class_finder.rb +18 -0
  39. data/lib/formtastic/inputs/base/choices.rb +2 -2
  40. data/lib/formtastic/inputs/base/collections.rb +46 -14
  41. data/lib/formtastic/inputs/base/database.rb +7 -2
  42. data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
  43. data/lib/formtastic/inputs/base/errors.rb +7 -7
  44. data/lib/formtastic/inputs/base/hints.rb +2 -2
  45. data/lib/formtastic/inputs/base/html.rb +10 -9
  46. data/lib/formtastic/inputs/base/labelling.rb +5 -8
  47. data/lib/formtastic/inputs/base/naming.rb +4 -4
  48. data/lib/formtastic/inputs/base/numeric.rb +1 -1
  49. data/lib/formtastic/inputs/base/options.rb +3 -4
  50. data/lib/formtastic/inputs/base/stringish.rb +10 -2
  51. data/lib/formtastic/inputs/base/timeish.rb +34 -22
  52. data/lib/formtastic/inputs/base/validations.rb +41 -13
  53. data/lib/formtastic/inputs/base/wrapping.rb +29 -26
  54. data/lib/formtastic/inputs/base.rb +22 -15
  55. data/lib/formtastic/inputs/boolean_input.rb +26 -12
  56. data/lib/formtastic/inputs/check_boxes_input.rb +39 -31
  57. data/lib/formtastic/inputs/color_input.rb +41 -0
  58. data/lib/formtastic/inputs/country_input.rb +24 -5
  59. data/lib/formtastic/inputs/datalist_input.rb +41 -0
  60. data/lib/formtastic/inputs/date_picker_input.rb +93 -0
  61. data/lib/formtastic/inputs/{date_input.rb → date_select_input.rb} +1 -1
  62. data/lib/formtastic/inputs/datetime_picker_input.rb +103 -0
  63. data/lib/formtastic/inputs/{datetime_input.rb → datetime_select_input.rb} +1 -1
  64. data/lib/formtastic/inputs/file_input.rb +2 -2
  65. data/lib/formtastic/inputs/hidden_input.rb +2 -6
  66. data/lib/formtastic/inputs/radio_input.rb +28 -22
  67. data/lib/formtastic/inputs/select_input.rb +36 -39
  68. data/lib/formtastic/inputs/time_picker_input.rb +99 -0
  69. data/lib/formtastic/inputs/{time_input.rb → time_select_input.rb} +6 -2
  70. data/lib/formtastic/inputs/time_zone_input.rb +16 -6
  71. data/lib/formtastic/inputs.rb +32 -21
  72. data/lib/formtastic/localized_string.rb +1 -1
  73. data/lib/formtastic/localizer.rb +24 -24
  74. data/lib/formtastic/namespaced_class_finder.rb +99 -0
  75. data/lib/formtastic/version.rb +1 -1
  76. data/lib/formtastic.rb +20 -10
  77. data/lib/generators/formtastic/form/form_generator.rb +10 -4
  78. data/lib/generators/formtastic/input/input_generator.rb +46 -0
  79. data/lib/generators/formtastic/install/install_generator.rb +5 -19
  80. data/lib/generators/templates/_form.html.slim +2 -2
  81. data/lib/generators/templates/formtastic.rb +46 -25
  82. data/lib/generators/templates/input.rb +19 -0
  83. data/sample/basic_inputs.html +23 -3
  84. data/script/integration-template.rb +74 -0
  85. data/script/integration.sh +19 -0
  86. data/spec/action_class_finder_spec.rb +12 -0
  87. data/spec/actions/button_action_spec.rb +8 -8
  88. data/spec/actions/generic_action_spec.rb +92 -56
  89. data/spec/actions/input_action_spec.rb +7 -7
  90. data/spec/actions/link_action_spec.rb +10 -10
  91. data/spec/builder/custom_builder_spec.rb +36 -20
  92. data/spec/builder/error_proc_spec.rb +4 -4
  93. data/spec/builder/semantic_fields_for_spec.rb +28 -29
  94. data/spec/fast_spec_helper.rb +12 -0
  95. data/spec/generators/formtastic/form/form_generator_spec.rb +45 -32
  96. data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
  97. data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
  98. data/spec/helpers/action_helper_spec.rb +75 -103
  99. data/spec/helpers/actions_helper_spec.rb +17 -17
  100. data/spec/helpers/form_helper_spec.rb +84 -33
  101. data/spec/helpers/input_helper_spec.rb +333 -285
  102. data/spec/helpers/inputs_helper_spec.rb +167 -121
  103. data/spec/helpers/reflection_helper_spec.rb +3 -3
  104. data/spec/helpers/semantic_errors_helper_spec.rb +23 -23
  105. data/spec/i18n_spec.rb +26 -26
  106. data/spec/input_class_finder_spec.rb +10 -0
  107. data/spec/inputs/base/collections_spec.rb +76 -0
  108. data/spec/inputs/base/validations_spec.rb +480 -0
  109. data/spec/inputs/boolean_input_spec.rb +100 -65
  110. data/spec/inputs/check_boxes_input_spec.rb +200 -101
  111. data/spec/inputs/color_input_spec.rb +85 -0
  112. data/spec/inputs/country_input_spec.rb +20 -20
  113. data/spec/inputs/custom_input_spec.rb +3 -4
  114. data/spec/inputs/datalist_input_spec.rb +61 -0
  115. data/spec/inputs/date_picker_input_spec.rb +449 -0
  116. data/spec/inputs/date_select_input_spec.rb +249 -0
  117. data/spec/inputs/datetime_picker_input_spec.rb +490 -0
  118. data/spec/inputs/datetime_select_input_spec.rb +209 -0
  119. data/spec/inputs/email_input_spec.rb +5 -5
  120. data/spec/inputs/file_input_spec.rb +6 -6
  121. data/spec/inputs/hidden_input_spec.rb +22 -35
  122. data/spec/inputs/include_blank_spec.rb +11 -11
  123. data/spec/inputs/label_spec.rb +62 -25
  124. data/spec/inputs/number_input_spec.rb +112 -112
  125. data/spec/inputs/password_input_spec.rb +5 -5
  126. data/spec/inputs/phone_input_spec.rb +5 -5
  127. data/spec/inputs/placeholder_spec.rb +6 -6
  128. data/spec/inputs/radio_input_spec.rb +99 -55
  129. data/spec/inputs/range_input_spec.rb +66 -66
  130. data/spec/inputs/readonly_spec.rb +50 -0
  131. data/spec/inputs/search_input_spec.rb +5 -5
  132. data/spec/inputs/select_input_spec.rb +170 -170
  133. data/spec/inputs/string_input_spec.rb +68 -16
  134. data/spec/inputs/text_input_spec.rb +16 -16
  135. data/spec/inputs/time_picker_input_spec.rb +455 -0
  136. data/spec/inputs/time_select_input_spec.rb +261 -0
  137. data/spec/inputs/time_zone_input_spec.rb +54 -28
  138. data/spec/inputs/url_input_spec.rb +5 -5
  139. data/spec/inputs/with_options_spec.rb +7 -7
  140. data/spec/localizer_spec.rb +39 -17
  141. data/spec/namespaced_class_finder_spec.rb +79 -0
  142. data/spec/schema.rb +21 -0
  143. data/spec/spec_helper.rb +254 -221
  144. data/spec/support/custom_macros.rb +128 -95
  145. data/spec/support/shared_examples.rb +12 -0
  146. data/spec/support/specialized_class_finder_shared_example.rb +27 -0
  147. data/spec/support/test_environment.rb +26 -10
  148. metadata +177 -238
  149. data/.travis.yml +0 -8
  150. data/Appraisals +0 -11
  151. data/CHANGELOG +0 -371
  152. data/gemfiles/rails-3.0.gemfile +0 -7
  153. data/gemfiles/rails-3.1.gemfile +0 -7
  154. data/gemfiles/rails-3.2.gemfile +0 -7
  155. data/lib/formtastic/helpers/buttons_helper.rb +0 -310
  156. data/lib/formtastic/inputs/base/grouped_collections.rb +0 -77
  157. data/lib/formtastic/util.rb +0 -25
  158. data/lib/tasks/verify_rcov.rb +0 -44
  159. data/spec/helpers/buttons_helper_spec.rb +0 -166
  160. data/spec/helpers/commit_button_helper_spec.rb +0 -530
  161. data/spec/inputs/date_input_spec.rb +0 -227
  162. data/spec/inputs/datetime_input_spec.rb +0 -185
  163. data/spec/inputs/time_input_spec.rb +0 -267
  164. data/spec/support/deferred_garbage_collection.rb +0 -21
@@ -1,44 +1,44 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'Formtastic::FormBuilder#fields_for' do
4
+ RSpec.describe 'Formtastic::FormBuilder#fields_for' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- @new_post.stub!(:author).and_return(::Author.new)
11
+ allow(@new_post).to receive(:author).and_return(::Author.new)
12
12
  end
13
13
 
14
14
  context 'outside a form_for block' do
15
15
  it 'yields an instance of FormHelper.builder' do
16
16
  semantic_fields_for(@new_post) do |nested_builder|
17
- nested_builder.class.should == Formtastic::Helpers::FormHelper.builder
17
+ expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
18
18
  end
19
19
  semantic_fields_for(@new_post.author) do |nested_builder|
20
- nested_builder.class.should == Formtastic::Helpers::FormHelper.builder
20
+ expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
21
21
  end
22
22
  semantic_fields_for(:author, @new_post.author) do |nested_builder|
23
- nested_builder.class.should == Formtastic::Helpers::FormHelper.builder
23
+ expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
24
24
  end
25
25
  semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
26
- nested_builder.class.should == Formtastic::Helpers::FormHelper.builder
26
+ expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
27
27
  end
28
28
  end
29
29
 
30
30
  it 'should respond to input' do
31
31
  semantic_fields_for(@new_post) do |nested_builder|
32
- nested_builder.respond_to?(:input).should be_true
32
+ expect(nested_builder.respond_to?(:input)).to be_truthy
33
33
  end
34
34
  semantic_fields_for(@new_post.author) do |nested_builder|
35
- nested_builder.respond_to?(:input).should be_true
35
+ expect(nested_builder.respond_to?(:input)).to be_truthy
36
36
  end
37
37
  semantic_fields_for(:author, @new_post.author) do |nested_builder|
38
- nested_builder.respond_to?(:input).should be_true
38
+ expect(nested_builder.respond_to?(:input)).to be_truthy
39
39
  end
40
40
  semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
41
- nested_builder.respond_to?(:input).should be_true
41
+ expect(nested_builder.respond_to?(:input)).to be_truthy
42
42
  end
43
43
  end
44
44
  end
@@ -47,7 +47,7 @@ describe 'Formtastic::FormBuilder#fields_for' do
47
47
  it 'yields an instance of FormHelper.builder' do
48
48
  semantic_form_for(@new_post) do |builder|
49
49
  builder.semantic_fields_for(:author) do |nested_builder|
50
- nested_builder.class.should == Formtastic::Helpers::FormHelper.builder
50
+ expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
51
51
  end
52
52
  end
53
53
  end
@@ -55,7 +55,7 @@ describe 'Formtastic::FormBuilder#fields_for' do
55
55
  it 'yields an instance of FormHelper.builder with hash-like model' do
56
56
  semantic_form_for(:user) do |builder|
57
57
  builder.semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
58
- nested_builder.class.should == Formtastic::Helpers::FormHelper.builder
58
+ expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
59
59
  end
60
60
  end
61
61
  end
@@ -63,7 +63,7 @@ describe 'Formtastic::FormBuilder#fields_for' do
63
63
  it 'nests the object name' do
64
64
  semantic_form_for(@new_post) do |builder|
65
65
  builder.semantic_fields_for(@bob) do |nested_builder|
66
- nested_builder.object_name.should == 'post[author]'
66
+ expect(nested_builder.object_name).to eq('post[author]')
67
67
  end
68
68
  end
69
69
  end
@@ -71,45 +71,45 @@ describe 'Formtastic::FormBuilder#fields_for' do
71
71
  it 'supports passing collection as second parameter' do
72
72
  semantic_form_for(@new_post) do |builder|
73
73
  builder.semantic_fields_for(:author, [@fred,@bob]) do |nested_builder|
74
- nested_builder.object_name.should =~ /post\[author_attributes\]\[\d+\]/
74
+ expect(nested_builder.object_name).to match(/post\[author_attributes\]\[\d+\]/)
75
75
  end
76
76
  end
77
77
  end
78
78
 
79
79
  it 'should sanitize html id for li tag' do
80
- @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
80
+ allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
81
81
  concat(semantic_form_for(@new_post) do |builder|
82
82
  concat(builder.semantic_fields_for(@bob, :index => 1) do |nested_builder|
83
83
  concat(nested_builder.inputs(:login))
84
84
  end)
85
85
  end)
86
- output_buffer.should have_tag('form fieldset.inputs #post_author_1_login_input')
86
+ expect(output_buffer).to have_tag('form fieldset.inputs #post_author_1_login_input')
87
87
  # Not valid selector, so using good ol' regex
88
- output_buffer.should_not =~ /id="post\[author\]_1_login_input"/
88
+ expect(output_buffer).not_to match(/id="post\[author\]_1_login_input"/)
89
89
  # <=> output_buffer.should_not have_tag('form fieldset.inputs #post[author]_1_login_input')
90
90
  end
91
91
 
92
92
  it 'should use namespace provided in nested fields' do
93
- @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
93
+ allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
94
94
  concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
95
95
  concat(builder.semantic_fields_for(@bob, :index => 1) do |nested_builder|
96
96
  concat(nested_builder.inputs(:login))
97
97
  end)
98
98
  end)
99
- output_buffer.should have_tag('form fieldset.inputs #context2_post_author_1_login_input')
99
+ expect(output_buffer).to have_tag('form fieldset.inputs #context2_post_author_1_login_input')
100
100
  end
101
101
 
102
102
  it 'should render errors on the nested inputs' do
103
- @errors = mock('errors')
104
- @errors.stub!(:[]).with(:login).and_return(['oh noes'])
105
- @bob.stub!(:errors).and_return(@errors)
103
+ @errors = double('errors')
104
+ allow(@errors).to receive(:[]).with(errors_matcher(:login)).and_return(['oh noes'])
105
+ allow(@bob).to receive(:errors).and_return(@errors)
106
106
 
107
107
  concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
108
108
  concat(builder.semantic_fields_for(@bob) do |nested_builder|
109
109
  concat(nested_builder.inputs(:login))
110
110
  end)
111
111
  end)
112
- output_buffer.should =~ /oh noes/
112
+ expect(output_buffer).to match(/oh noes/)
113
113
  end
114
114
 
115
115
  end
@@ -119,10 +119,9 @@ describe 'Formtastic::FormBuilder#fields_for' do
119
119
  before do
120
120
  output_buffer.replace ''
121
121
 
122
- @fred.posts.size.should == 1
123
- @fred.posts.first.stub!(:persisted?).and_return(true)
124
- @fred.stub!(:posts_attributes=)
125
-
122
+ expect(@fred.posts.size).to eq(1)
123
+ allow(@fred.posts.first).to receive(:persisted?).and_return(true)
124
+ allow(@fred).to receive(:posts_attributes=)
126
125
  concat(semantic_form_for(@fred) do |builder|
127
126
  concat(builder.semantic_fields_for(:posts) do |nested_builder|
128
127
  concat(nested_builder.input(:id, :as => :hidden))
@@ -132,11 +131,11 @@ describe 'Formtastic::FormBuilder#fields_for' do
132
131
  end
133
132
 
134
133
  it "should only render one hidden input (my one)" do
135
- output_buffer.should have_tag 'input#author_posts_attributes_0_id', :count => 1
134
+ expect(output_buffer).to have_tag 'input#author_posts_attributes_0_id', :count => 1
136
135
  end
137
136
 
138
137
  it "should render the hidden input inside an li.hidden" do
139
- output_buffer.should have_tag 'li.hidden input#author_posts_attributes_0_id'
138
+ expect(output_buffer).to have_tag 'li.hidden input#author_posts_attributes_0_id'
140
139
  end
141
140
  end
142
141
 
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ $LOAD_PATH << 'lib/formtastic'
3
+ require 'active_support/all'
4
+ require 'localized_string'
5
+ require 'inputs'
6
+ require 'helpers'
7
+
8
+ class MyInput
9
+ include Formtastic::Inputs::Base
10
+ end
11
+
12
+ I18n.enforce_available_locales = false if I18n.respond_to?(:enforce_available_locales)
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  # Generators are not automatically loaded by Rails
4
4
  require 'generators/formtastic/form/form_generator'
5
5
 
6
- describe Formtastic::FormGenerator do
6
+ RSpec.describe Formtastic::FormGenerator do
7
7
 
8
8
  include FormtasticSpecHelper
9
9
 
@@ -14,23 +14,27 @@ describe Formtastic::FormGenerator do
14
14
  @output_buffer = ''
15
15
  prepare_destination
16
16
  mock_everything
17
- ::Post.stub!(:reflect_on_all_associations).with(:belongs_to).and_return([
18
- mock('reflection', :name => :author, :options => {}, :klass => ::Author, :macro => :belongs_to),
19
- mock('reflection', :name => :reviewer, :options => {:class_name => 'Author'}, :klass => ::Author, :macro => :belongs_to),
20
- mock('reflection', :name => :main_post, :options => {}, :klass => ::Post, :macro => :belongs_to),
21
- mock('reflection', :name => :attachment, :options => {:polymorphic => true}, :macro => :belongs_to),
17
+ allow(::Post).to receive(:reflect_on_all_associations).with(:belongs_to).and_return([
18
+ double('reflection', :name => :author, :options => {}, :klass => ::Author, :macro => :belongs_to),
19
+ double('reflection', :name => :reviewer, :options => {:class_name => 'Author'}, :klass => ::Author, :macro => :belongs_to),
20
+ double('reflection', :name => :main_post, :options => {}, :klass => ::Post, :macro => :belongs_to),
21
+ double('reflection', :name => :attachment, :options => {:polymorphic => true}, :macro => :belongs_to),
22
22
  ])
23
23
  end
24
+
25
+ after do
26
+ FileUtils.rm_rf(File.expand_path("../../../../../tmp", __FILE__))
27
+ end
24
28
 
25
29
  describe 'without model' do
26
30
  it 'should raise Thor::RequiredArgumentMissingError' do
27
- lambda { run_generator }.should raise_error(Thor::RequiredArgumentMissingError)
31
+ expect { run_generator }.to raise_error(Thor::RequiredArgumentMissingError)
28
32
  end
29
33
  end
30
34
 
31
35
  describe 'with existing model' do
32
36
  it 'should not raise an exception' do
33
- lambda { run_generator %w(Post) }.should_not raise_error(Thor::RequiredArgumentMissingError)
37
+ expect { run_generator %w(Post) }.not_to raise_error
34
38
  end
35
39
  end
36
40
 
@@ -39,10 +43,10 @@ describe Formtastic::FormGenerator do
39
43
 
40
44
  describe 'render only the specified attributes' do
41
45
  subject { file('app/views/posts/_form.html.erb') }
42
- it { should exist }
43
- it { should contain "<%= f.input :title %>" }
44
- it { should contain "<%= f.input :author %>" }
45
- it { should_not contain "<%= f.input :main_post %>" }
46
+ it { is_expected.to exist }
47
+ it { is_expected.to contain "<%= f.input :title %>" }
48
+ it { is_expected.to contain "<%= f.input :author %>" }
49
+ it { is_expected.not_to contain "<%= f.input :main_post %>" }
46
50
  end
47
51
  end
48
52
 
@@ -52,17 +56,17 @@ describe Formtastic::FormGenerator do
52
56
  subject { file('app/views/posts/_form.html.erb') }
53
57
 
54
58
  describe 'content_columns' do
55
- it { should contain "<%= f.input :title %>" }
56
- it { should contain "<%= f.input :body %>" }
57
- it { should_not contain "<%= f.input :created_at %>" }
58
- it { should_not contain "<%= f.input :updated_at %>" }
59
+ it { is_expected.to contain "<%= f.input :title %>" }
60
+ it { is_expected.to contain "<%= f.input :body %>" }
61
+ it { is_expected.not_to contain "<%= f.input :created_at %>" }
62
+ it { is_expected.not_to contain "<%= f.input :updated_at %>" }
59
63
  end
60
64
 
61
65
  describe 'reflection_on_association' do
62
- it { should contain "<%= f.input :author %>" }
63
- it { should contain "<%= f.input :reviewer %>" }
64
- it { should contain "<%= f.input :main_post %>" }
65
- it { should_not contain "<%= f.input :attachment %>" }
66
+ it { is_expected.to contain "<%= f.input :author %>" }
67
+ it { is_expected.to contain "<%= f.input :reviewer %>" }
68
+ it { is_expected.to contain "<%= f.input :main_post %>" }
69
+ it { is_expected.not_to contain "<%= f.input :attachment %>" }
66
70
  end
67
71
  end
68
72
 
@@ -72,19 +76,28 @@ describe Formtastic::FormGenerator do
72
76
 
73
77
  describe 'app/views/posts/_form.html.erb' do
74
78
  subject { file('app/views/posts/_form.html.erb') }
75
- it { should exist }
76
- it { should contain "<%= semantic_form_for @post do |f| %>" }
79
+ it { is_expected.to exist }
80
+ it { is_expected.to contain "<%= semantic_form_for @post do |f| %>" }
77
81
  end
78
82
  end
79
83
 
80
84
  describe 'haml' do
81
- before { run_generator %w(Post --template-engine haml) }
82
-
85
+
83
86
  describe 'app/views/posts/_form.html.haml' do
87
+ before { run_generator %w(Post --template-engine haml) }
84
88
  subject { file('app/views/posts/_form.html.haml') }
85
- it { should exist }
86
- it { should contain "= semantic_form_for @post do |f|" }
89
+ it { is_expected.to exist }
90
+ it { is_expected.to contain "= semantic_form_for @post do |f|" }
91
+ end
92
+
93
+ context 'with copy option' do
94
+ describe 'app/views/posts/_form.html.haml' do
95
+ before { run_generator %w(Post --copy --template-engine haml) }
96
+ subject { file('app/views/posts/_form.html.haml') }
97
+ it { is_expected.not_to exist }
98
+ end
87
99
  end
100
+
88
101
  end
89
102
 
90
103
  describe 'slim' do
@@ -92,18 +105,18 @@ describe Formtastic::FormGenerator do
92
105
 
93
106
  describe 'app/views/posts/_form.html.slim' do
94
107
  subject { file('app/views/posts/_form.html.slim') }
95
- it { should exist }
96
- it { should contain "= semantic_form_for @post do |f|" }
108
+ it { is_expected.to exist }
109
+ it { is_expected.to contain "= semantic_form_for @post do |f|" }
97
110
  end
98
111
  end
99
112
  end
100
-
113
+
101
114
  describe 'with copy option' do
102
115
  before { run_generator %w(Post --copy) }
103
-
116
+
104
117
  describe 'app/views/posts/_form.html.erb' do
105
118
  subject { file('app/views/posts/_form.html.erb') }
106
- it { should_not exist }
119
+ it { is_expected.not_to exist }
107
120
  end
108
121
  end
109
122
 
@@ -112,7 +125,7 @@ describe Formtastic::FormGenerator do
112
125
 
113
126
  describe 'app/views/admin/posts/_form.html.erb' do
114
127
  subject { file('app/views/admin/posts/_form.html.erb') }
115
- it { should exist }
128
+ it { is_expected.to exist }
116
129
  end
117
130
  end
118
131
  end
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ require 'generators/formtastic/input/input_generator'
4
+
5
+ RSpec.describe Formtastic::InputGenerator do
6
+ include FormtasticSpecHelper
7
+
8
+ destination File.expand_path("../../../../../tmp", __FILE__)
9
+
10
+ before do
11
+ prepare_destination
12
+ end
13
+
14
+ after do
15
+ FileUtils.rm_rf(File.expand_path("../../../../../tmp", __FILE__))
16
+ end
17
+
18
+ describe 'without file name' do
19
+ it 'should raise Thor::RequiredArgumentMissingError' do
20
+ expect { run_generator }.to raise_error(Thor::RequiredArgumentMissingError)
21
+ end
22
+ end
23
+
24
+ describe "input generator with underscore definition" do
25
+ before { run_generator %w(hat_size)}
26
+
27
+ describe 'generate an input in its respective folder' do
28
+ subject{ file('app/inputs/hat_size_input.rb')}
29
+ it { is_expected.to exist}
30
+ it { is_expected.to contain "class HatSizeInput"}
31
+ it { is_expected.to contain "def to_html"}
32
+ it { is_expected.to contain "include Formtastic::Inputs::Base"}
33
+ it { is_expected.not_to contain "super"}
34
+ end
35
+ end
36
+
37
+ describe "input generator with camelcase definition" do
38
+ before { run_generator %w(HatSize)}
39
+
40
+ describe 'generate an input in its respective folder' do
41
+ subject{ file('app/inputs/hat_size_input.rb')}
42
+ it { is_expected.to exist}
43
+ it { is_expected.to contain "class HatSizeInput"}
44
+ end
45
+ end
46
+
47
+ describe "input generator with camelcase Input name sufixed" do
48
+ before { run_generator %w(HatSizeInput)}
49
+
50
+ describe 'generate an input in its respective folder' do
51
+ subject{ file('app/inputs/hat_size_input.rb')}
52
+ it { is_expected.to exist}
53
+ it { is_expected.to contain "class HatSizeInput"}
54
+ end
55
+ end
56
+
57
+ describe "input generator with underscore _input name sufixed" do
58
+ before { run_generator %w(hat_size_input)}
59
+
60
+ describe 'generate an input in its respective folder' do
61
+ subject{ file('app/inputs/hat_size_input.rb')}
62
+ it { is_expected.to exist}
63
+ it { is_expected.to contain "class HatSizeInput"}
64
+ end
65
+ end
66
+
67
+ describe "input generator with underscore input name sufixed" do
68
+ before { run_generator %w(hat_sizeinput)}
69
+
70
+ describe 'generate an input in its respective folder' do
71
+ subject{ file('app/inputs/hat_size_input.rb')}
72
+ it { is_expected.to exist}
73
+ it { is_expected.to contain "class HatSizeInput"}
74
+ end
75
+ end
76
+
77
+ describe "override an existing input using extend" do
78
+ before { run_generator %w(string --extend)}
79
+
80
+ describe 'app/inputs/string_input.rb' do
81
+ subject{ file('app/inputs/string_input.rb')}
82
+ it { is_expected.to exist }
83
+ it { is_expected.to contain "class StringInput < Formtastic::Inputs::StringInput" }
84
+ it { is_expected.to contain "def to_html" }
85
+ it { is_expected.not_to contain "include Formtastic::Inputs::Base" }
86
+ it { is_expected.to contain "super" }
87
+ it { is_expected.not_to contain "def input_html_options" }
88
+ end
89
+ end
90
+
91
+ describe "extend an existing input" do
92
+ before { run_generator %w(FlexibleText --extend string)}
93
+
94
+ describe 'app/inputs/flexible_text_input.rb' do
95
+ subject{ file('app/inputs/flexible_text_input.rb')}
96
+ it { is_expected.to contain "class FlexibleTextInput < Formtastic::Inputs::StringInput" }
97
+ it { is_expected.to contain "def input_html_options" }
98
+ it { is_expected.not_to contain "include Formtastic::Inputs::Base" }
99
+ it { is_expected.not_to contain "def to_html" }
100
+ end
101
+ end
102
+
103
+ describe "provide a slashed namespace" do
104
+ before { run_generator %w(stuff/foo)}
105
+
106
+ describe 'app/inputs/stuff/foo_input.rb' do
107
+ subject{ file('app/inputs/stuff/foo_input.rb')}
108
+ it {is_expected.to exist}
109
+ it { is_expected.to contain "class Stuff::FooInput" }
110
+ it { is_expected.to contain "include Formtastic::Inputs::Base" }
111
+ end
112
+ end
113
+
114
+ describe "provide a camelized namespace" do
115
+ before { run_generator %w(Stuff::Foo)}
116
+
117
+ describe 'app/inputs/stuff/foo_input.rb' do
118
+ subject{ file('app/inputs/stuff/foo_input.rb')}
119
+ it {is_expected.to exist}
120
+ it { is_expected.to contain "class Stuff::FooInput" }
121
+ it { is_expected.to contain "include Formtastic::Inputs::Base" }
122
+ end
123
+ end
124
+ end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  # Generators are not automatically loaded by Rails
4
4
  require 'generators/formtastic/install/install_generator'
5
5
 
6
- describe Formtastic::InstallGenerator do
6
+ RSpec.describe Formtastic::InstallGenerator do
7
7
  # Tell the generator where to put its output (what it thinks of as Rails.root)
8
8
  destination File.expand_path("../../../../../tmp", __FILE__)
9
9
 
@@ -14,14 +14,14 @@ describe Formtastic::InstallGenerator do
14
14
 
15
15
  describe 'config/initializers/formtastic.rb' do
16
16
  subject { file('config/initializers/formtastic.rb') }
17
- it { should exist }
18
- it { should contain "# Please note: If you're subclassing Formtastic::FormBuilder" }
17
+ it { is_expected.to exist }
18
+ it { is_expected.to contain "#" }
19
19
  end
20
20
 
21
21
  describe 'lib/templates/erb/scaffold/_form.html.erb' do
22
22
  subject { file('lib/templates/erb/scaffold/_form.html.erb') }
23
- it { should exist }
24
- it { should contain "<%%= semantic_form_for @<%= singular_name %> do |f| %>" }
23
+ it { is_expected.to exist }
24
+ it { is_expected.to contain "<%%= semantic_form_for @<%= singular_name %> do |f| %>" }
25
25
  end
26
26
  end
27
27
 
@@ -30,8 +30,8 @@ describe Formtastic::InstallGenerator do
30
30
 
31
31
  describe 'lib/templates/erb/scaffold/_form.html.haml' do
32
32
  subject { file('lib/templates/haml/scaffold/_form.html.haml') }
33
- it { should exist }
34
- it { should contain "= semantic_form_for @<%= singular_name %> do |f|" }
33
+ it { is_expected.to exist }
34
+ it { is_expected.to contain "= semantic_form_for @<%= singular_name %> do |f|" }
35
35
  end
36
36
  end
37
37
 
@@ -40,8 +40,8 @@ describe Formtastic::InstallGenerator do
40
40
 
41
41
  describe 'lib/templates/erb/scaffold/_form.html.slim' do
42
42
  subject { file('lib/templates/slim/scaffold/_form.html.slim') }
43
- it { should exist }
44
- it { should contain "= semantic_form_for @<%= singular_name %> do |f|" }
43
+ it { is_expected.to exist }
44
+ it { is_expected.to contain "= semantic_form_for @<%= singular_name %> do |f|" }
45
45
  end
46
46
  end
47
47
  end