formtastic 1.2.4 → 3.1.5
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/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +46 -0
- data/.yardopts +1 -0
- data/Appraisals +43 -0
- data/CHANGELOG +54 -0
- data/DEPRECATIONS +52 -0
- data/Gemfile +3 -0
- data/README.md +629 -0
- data/RELEASE_PROCESS +6 -0
- data/Rakefile +35 -0
- data/app/assets/stylesheets/formtastic.css +289 -0
- data/app/assets/stylesheets/formtastic_ie6.css +33 -0
- data/app/assets/stylesheets/formtastic_ie7.css +23 -0
- data/formtastic.gemspec +42 -0
- data/gemfiles/rails_3.2.gemfile +9 -0
- data/gemfiles/rails_4.0.4.gemfile +8 -0
- data/gemfiles/rails_4.1.gemfile +8 -0
- data/gemfiles/rails_4.2.gemfile +8 -0
- data/gemfiles/rails_4.gemfile +8 -0
- data/gemfiles/rails_5.0.gemfile +8 -0
- data/gemfiles/rails_edge.gemfile +15 -0
- data/lib/formtastic.rb +40 -1945
- data/lib/formtastic/action_class_finder.rb +18 -0
- data/lib/formtastic/actions.rb +11 -0
- data/lib/formtastic/actions/base.rb +156 -0
- data/lib/formtastic/actions/button_action.rb +67 -0
- data/lib/formtastic/actions/buttonish.rb +17 -0
- data/lib/formtastic/actions/input_action.rb +70 -0
- data/lib/formtastic/actions/link_action.rb +88 -0
- data/lib/formtastic/deprecation.rb +42 -0
- data/lib/formtastic/engine.rb +11 -0
- data/lib/formtastic/form_builder.rb +124 -0
- data/lib/formtastic/helpers.rb +16 -0
- data/lib/formtastic/helpers/action_helper.rb +162 -0
- data/lib/formtastic/helpers/actions_helper.rb +168 -0
- data/lib/formtastic/helpers/enum.rb +13 -0
- data/lib/formtastic/helpers/errors_helper.rb +81 -0
- data/lib/formtastic/helpers/fieldset_wrapper.rb +80 -0
- data/lib/formtastic/helpers/file_column_detection.rb +16 -0
- data/lib/formtastic/helpers/form_helper.rb +203 -0
- data/lib/formtastic/helpers/input_helper.rb +407 -0
- data/lib/formtastic/helpers/inputs_helper.rb +411 -0
- data/lib/formtastic/helpers/reflection.rb +37 -0
- data/lib/formtastic/html_attributes.rb +32 -0
- data/lib/formtastic/i18n.rb +4 -2
- data/lib/formtastic/input_class_finder.rb +18 -0
- data/lib/formtastic/inputs.rb +39 -0
- data/lib/formtastic/inputs/base.rb +76 -0
- data/lib/formtastic/inputs/base/associations.rb +31 -0
- data/lib/formtastic/inputs/base/choices.rb +108 -0
- data/lib/formtastic/inputs/base/collections.rb +159 -0
- data/lib/formtastic/inputs/base/database.rb +22 -0
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
- data/lib/formtastic/inputs/base/errors.rb +58 -0
- data/lib/formtastic/inputs/base/fileish.rb +23 -0
- data/lib/formtastic/inputs/base/hints.rb +31 -0
- data/lib/formtastic/inputs/base/html.rb +53 -0
- data/lib/formtastic/inputs/base/labelling.rb +52 -0
- data/lib/formtastic/inputs/base/naming.rb +42 -0
- data/lib/formtastic/inputs/base/numeric.rb +50 -0
- data/lib/formtastic/inputs/base/options.rb +17 -0
- data/lib/formtastic/inputs/base/placeholder.rb +17 -0
- data/lib/formtastic/inputs/base/stringish.rb +38 -0
- data/lib/formtastic/inputs/base/timeish.rb +241 -0
- data/lib/formtastic/inputs/base/validations.rb +215 -0
- data/lib/formtastic/inputs/base/wrapping.rb +50 -0
- data/lib/formtastic/inputs/boolean_input.rb +118 -0
- data/lib/formtastic/inputs/check_boxes_input.rb +197 -0
- data/lib/formtastic/inputs/color_input.rb +42 -0
- data/lib/formtastic/inputs/country_input.rb +86 -0
- data/lib/formtastic/inputs/datalist_input.rb +41 -0
- data/lib/formtastic/inputs/date_picker_input.rb +93 -0
- data/lib/formtastic/inputs/date_select_input.rb +34 -0
- data/lib/formtastic/inputs/datetime_picker_input.rb +103 -0
- data/lib/formtastic/inputs/datetime_select_input.rb +12 -0
- data/lib/formtastic/inputs/email_input.rb +41 -0
- data/lib/formtastic/inputs/file_input.rb +42 -0
- data/lib/formtastic/inputs/hidden_input.rb +62 -0
- data/lib/formtastic/inputs/number_input.rb +88 -0
- data/lib/formtastic/inputs/password_input.rb +41 -0
- data/lib/formtastic/inputs/phone_input.rb +42 -0
- data/lib/formtastic/inputs/radio_input.rb +163 -0
- data/lib/formtastic/inputs/range_input.rb +95 -0
- data/lib/formtastic/inputs/search_input.rb +41 -0
- data/lib/formtastic/inputs/select_input.rb +235 -0
- data/lib/formtastic/inputs/string_input.rb +36 -0
- data/lib/formtastic/inputs/text_input.rb +48 -0
- data/lib/formtastic/inputs/time_picker_input.rb +99 -0
- data/lib/formtastic/inputs/time_select_input.rb +38 -0
- data/lib/formtastic/inputs/time_zone_input.rb +58 -0
- data/lib/formtastic/inputs/url_input.rb +41 -0
- data/lib/formtastic/localized_string.rb +17 -0
- data/lib/formtastic/localizer.rb +152 -0
- data/lib/formtastic/namespaced_class_finder.rb +99 -0
- data/lib/formtastic/util.rb +35 -16
- data/lib/formtastic/version.rb +3 -0
- data/lib/generators/formtastic/form/form_generator.rb +64 -37
- data/lib/generators/formtastic/input/input_generator.rb +46 -0
- data/lib/generators/formtastic/install/install_generator.rb +13 -5
- data/lib/generators/templates/_form.html.erb +10 -4
- data/lib/generators/templates/_form.html.haml +8 -4
- data/lib/generators/templates/_form.html.slim +8 -0
- data/lib/generators/templates/formtastic.rb +77 -44
- data/lib/generators/templates/input.rb +19 -0
- data/lib/locale/en.yml +3 -0
- data/sample/basic_inputs.html +224 -0
- data/sample/config.ru +69 -0
- data/sample/index.html +14 -0
- data/spec/action_class_finder_spec.rb +12 -0
- data/spec/actions/button_action_spec.rb +63 -0
- data/spec/actions/generic_action_spec.rb +521 -0
- data/spec/actions/input_action_spec.rb +59 -0
- data/spec/actions/link_action_spec.rb +92 -0
- data/spec/builder/custom_builder_spec.rb +116 -0
- data/spec/builder/error_proc_spec.rb +27 -0
- data/spec/builder/semantic_fields_for_spec.rb +142 -0
- data/spec/fast_spec_helper.rb +12 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +131 -0
- data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +47 -0
- data/spec/helpers/action_helper_spec.rb +19 -0
- data/spec/helpers/actions_helper_spec.rb +143 -0
- data/spec/helpers/form_helper_spec.rb +218 -0
- data/spec/helpers/input_helper_spec.rb +6 -0
- data/spec/helpers/inputs_helper_spec.rb +655 -0
- data/spec/helpers/namespaced_action_helper_spec.rb +43 -0
- data/spec/helpers/namespaced_input_helper_spec.rb +36 -0
- data/spec/helpers/reflection_helper_spec.rb +32 -0
- data/spec/helpers/semantic_errors_helper_spec.rb +112 -0
- data/spec/i18n_spec.rb +210 -0
- data/spec/input_class_finder_spec.rb +10 -0
- data/spec/inputs/base/collections_spec.rb +76 -0
- data/spec/inputs/base/validations_spec.rb +342 -0
- data/spec/inputs/boolean_input_spec.rb +254 -0
- data/spec/inputs/check_boxes_input_spec.rb +546 -0
- data/spec/inputs/color_input_spec.rb +97 -0
- data/spec/inputs/country_input_spec.rb +133 -0
- data/spec/inputs/custom_input_spec.rb +55 -0
- data/spec/inputs/datalist_input_spec.rb +61 -0
- data/spec/inputs/date_picker_input_spec.rb +449 -0
- data/spec/inputs/date_select_input_spec.rb +235 -0
- data/spec/inputs/datetime_picker_input_spec.rb +490 -0
- data/spec/inputs/datetime_select_input_spec.rb +193 -0
- data/spec/inputs/email_input_spec.rb +85 -0
- data/spec/inputs/file_input_spec.rb +89 -0
- data/spec/inputs/hidden_input_spec.rb +135 -0
- data/spec/inputs/include_blank_spec.rb +78 -0
- data/spec/inputs/label_spec.rb +149 -0
- data/spec/inputs/number_input_spec.rb +815 -0
- data/spec/inputs/password_input_spec.rb +99 -0
- data/spec/inputs/phone_input_spec.rb +85 -0
- data/spec/inputs/placeholder_spec.rb +71 -0
- data/spec/inputs/radio_input_spec.rb +328 -0
- data/spec/inputs/range_input_spec.rb +505 -0
- data/spec/inputs/readonly_spec.rb +50 -0
- data/spec/inputs/search_input_spec.rb +84 -0
- data/spec/inputs/select_input_spec.rb +615 -0
- data/spec/inputs/string_input_spec.rb +260 -0
- data/spec/inputs/text_input_spec.rb +187 -0
- data/spec/inputs/time_picker_input_spec.rb +455 -0
- data/spec/inputs/time_select_input_spec.rb +248 -0
- data/spec/inputs/time_zone_input_spec.rb +143 -0
- data/spec/inputs/url_input_spec.rb +85 -0
- data/spec/inputs/with_options_spec.rb +43 -0
- data/spec/localizer_spec.rb +130 -0
- data/spec/namespaced_class_finder_spec.rb +79 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +525 -0
- data/spec/support/custom_macros.rb +564 -0
- data/spec/support/deprecation.rb +6 -0
- data/spec/support/shared_examples.rb +1313 -0
- data/spec/support/specialized_class_finder_shared_example.rb +27 -0
- data/spec/support/test_environment.rb +31 -0
- data/spec/util_spec.rb +66 -0
- metadata +434 -161
- data/README.textile +0 -682
- data/generators/form/USAGE +0 -16
- data/generators/form/form_generator.rb +0 -111
- data/generators/formtastic/formtastic_generator.rb +0 -26
- data/init.rb +0 -5
- data/lib/formtastic/layout_helper.rb +0 -12
- data/lib/formtastic/railtie.rb +0 -14
- data/lib/generators/templates/formtastic.css +0 -145
- data/lib/generators/templates/formtastic_changes.css +0 -14
- data/lib/generators/templates/rails2/_form.html.erb +0 -5
- data/lib/generators/templates/rails2/_form.html.haml +0 -4
- data/rails/init.rb +0 -2
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
# Generators are not automatically loaded by Rails
|
|
4
|
+
require 'generators/formtastic/form/form_generator'
|
|
5
|
+
|
|
6
|
+
describe Formtastic::FormGenerator do
|
|
7
|
+
|
|
8
|
+
include FormtasticSpecHelper
|
|
9
|
+
|
|
10
|
+
# Tell the generator where to put its output (what it thinks of as Rails.root)
|
|
11
|
+
destination File.expand_path("../../../../../tmp", __FILE__)
|
|
12
|
+
|
|
13
|
+
before do
|
|
14
|
+
@output_buffer = ''
|
|
15
|
+
prepare_destination
|
|
16
|
+
mock_everything
|
|
17
|
+
::Post.stub(: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
|
+
])
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
after do
|
|
26
|
+
FileUtils.rm_rf(File.expand_path("../../../../../tmp", __FILE__))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe 'without model' do
|
|
30
|
+
it 'should raise Thor::RequiredArgumentMissingError' do
|
|
31
|
+
lambda { run_generator }.should raise_error(Thor::RequiredArgumentMissingError)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe 'with existing model' do
|
|
36
|
+
it 'should not raise an exception' do
|
|
37
|
+
lambda { run_generator %w(Post) }.should_not raise_error
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe 'with attributes' do
|
|
42
|
+
before { run_generator %w(Post title:string author:references) }
|
|
43
|
+
|
|
44
|
+
describe 'render only the specified attributes' do
|
|
45
|
+
subject { file('app/views/posts/_form.html.erb') }
|
|
46
|
+
it { should exist }
|
|
47
|
+
it { should contain "<%= f.input :title %>" }
|
|
48
|
+
it { should contain "<%= f.input :author %>" }
|
|
49
|
+
it { should_not contain "<%= f.input :main_post %>" }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe 'without attributes' do
|
|
54
|
+
before { run_generator %w(Post) }
|
|
55
|
+
|
|
56
|
+
subject { file('app/views/posts/_form.html.erb') }
|
|
57
|
+
|
|
58
|
+
describe 'content_columns' do
|
|
59
|
+
it { should contain "<%= f.input :title %>" }
|
|
60
|
+
it { should contain "<%= f.input :body %>" }
|
|
61
|
+
it { should_not contain "<%= f.input :created_at %>" }
|
|
62
|
+
it { should_not contain "<%= f.input :updated_at %>" }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe 'reflection_on_association' do
|
|
66
|
+
it { should contain "<%= f.input :author %>" }
|
|
67
|
+
it { should contain "<%= f.input :reviewer %>" }
|
|
68
|
+
it { should contain "<%= f.input :main_post %>" }
|
|
69
|
+
it { should_not contain "<%= f.input :attachment %>" }
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
describe 'with template engine option' do
|
|
74
|
+
describe 'erb' do
|
|
75
|
+
before { run_generator %w(Post --template-engine erb) }
|
|
76
|
+
|
|
77
|
+
describe 'app/views/posts/_form.html.erb' do
|
|
78
|
+
subject { file('app/views/posts/_form.html.erb') }
|
|
79
|
+
it { should exist }
|
|
80
|
+
it { should contain "<%= semantic_form_for @post do |f| %>" }
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe 'haml' do
|
|
85
|
+
|
|
86
|
+
describe 'app/views/posts/_form.html.haml' do
|
|
87
|
+
before { run_generator %w(Post --template-engine haml) }
|
|
88
|
+
subject { file('app/views/posts/_form.html.haml') }
|
|
89
|
+
it { should exist }
|
|
90
|
+
it { should 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 { should_not exist }
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
describe 'slim' do
|
|
104
|
+
before { run_generator %w(Post --template-engine slim) }
|
|
105
|
+
|
|
106
|
+
describe 'app/views/posts/_form.html.slim' do
|
|
107
|
+
subject { file('app/views/posts/_form.html.slim') }
|
|
108
|
+
it { should exist }
|
|
109
|
+
it { should contain "= semantic_form_for @post do |f|" }
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
describe 'with copy option' do
|
|
115
|
+
before { run_generator %w(Post --copy) }
|
|
116
|
+
|
|
117
|
+
describe 'app/views/posts/_form.html.erb' do
|
|
118
|
+
subject { file('app/views/posts/_form.html.erb') }
|
|
119
|
+
it { should_not exist }
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
describe 'with controller option' do
|
|
124
|
+
before { run_generator %w(Post --controller admin/posts) }
|
|
125
|
+
|
|
126
|
+
describe 'app/views/admin/posts/_form.html.erb' do
|
|
127
|
+
subject { file('app/views/admin/posts/_form.html.erb') }
|
|
128
|
+
it { should exist }
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'generators/formtastic/input/input_generator'
|
|
4
|
+
|
|
5
|
+
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
|
+
lambda { run_generator }.should 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 { should exist}
|
|
30
|
+
it { should contain "class HatSizeInput"}
|
|
31
|
+
it { should contain "def to_html"}
|
|
32
|
+
it { should contain "include Formtastic::Inputs::Base"}
|
|
33
|
+
it { should_not 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 { should exist}
|
|
43
|
+
it { should 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 { should exist}
|
|
53
|
+
it { should 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 { should exist}
|
|
63
|
+
it { should 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 { should exist}
|
|
73
|
+
it { should 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 { should exist }
|
|
83
|
+
it { should contain "class StringInput < Formtastic::Inputs::StringInput" }
|
|
84
|
+
it { should contain "def to_html" }
|
|
85
|
+
it { should_not contain "include Formtastic::Inputs::Base" }
|
|
86
|
+
it { should contain "super" }
|
|
87
|
+
it { should_not 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 { should contain "class FlexibleTextInput < Formtastic::Inputs::StringInput" }
|
|
97
|
+
it { should contain "def input_html_options" }
|
|
98
|
+
it { should_not contain "include Formtastic::Inputs::Base" }
|
|
99
|
+
it { should_not 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 {should exist}
|
|
109
|
+
it { should contain "class Stuff::FooInput" }
|
|
110
|
+
it { should 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 {should exist}
|
|
120
|
+
it { should contain "class Stuff::FooInput" }
|
|
121
|
+
it { should contain "include Formtastic::Inputs::Base" }
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
# Generators are not automatically loaded by Rails
|
|
4
|
+
require 'generators/formtastic/install/install_generator'
|
|
5
|
+
|
|
6
|
+
describe Formtastic::InstallGenerator do
|
|
7
|
+
# Tell the generator where to put its output (what it thinks of as Rails.root)
|
|
8
|
+
destination File.expand_path("../../../../../tmp", __FILE__)
|
|
9
|
+
|
|
10
|
+
before { prepare_destination }
|
|
11
|
+
|
|
12
|
+
describe 'no arguments' do
|
|
13
|
+
before { run_generator }
|
|
14
|
+
|
|
15
|
+
describe 'config/initializers/formtastic.rb' do
|
|
16
|
+
subject { file('config/initializers/formtastic.rb') }
|
|
17
|
+
it { should exist }
|
|
18
|
+
it { should contain "#" }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe 'lib/templates/erb/scaffold/_form.html.erb' do
|
|
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| %>" }
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe 'haml' do
|
|
29
|
+
before { run_generator %w(--template-engine haml) }
|
|
30
|
+
|
|
31
|
+
describe 'lib/templates/erb/scaffold/_form.html.haml' do
|
|
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|" }
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe 'slim' do
|
|
39
|
+
before { run_generator %w(--template-engine slim) }
|
|
40
|
+
|
|
41
|
+
describe 'lib/templates/erb/scaffold/_form.html.slim' do
|
|
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|" }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe 'Formtastic::FormBuilder#action' do
|
|
5
|
+
include_context 'Action Helper' # from spec/support/shared_examples.rb
|
|
6
|
+
|
|
7
|
+
# TODO: remove this in Formtastic 4.0
|
|
8
|
+
describe 'instantiating an action class' do
|
|
9
|
+
context 'of unknown action' do
|
|
10
|
+
it "should try to load class named as the action" do
|
|
11
|
+
expect {
|
|
12
|
+
semantic_form_for(@new_post) do |builder|
|
|
13
|
+
builder.action(:destroy)
|
|
14
|
+
end
|
|
15
|
+
}.to raise_error(Formtastic::UnknownActionError, 'Unable to find action destroy')
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe 'Formtastic::FormBuilder#actions' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ''
|
|
10
|
+
mock_everything
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe 'with a block' do
|
|
14
|
+
describe 'when no options are provided' do
|
|
15
|
+
before do
|
|
16
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
17
|
+
concat(builder.actions do
|
|
18
|
+
concat('hello')
|
|
19
|
+
end)
|
|
20
|
+
end)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'should render a fieldset inside the form, with a class of "actions"' do
|
|
24
|
+
output_buffer.should have_tag("form fieldset.actions")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'should render an ol inside the fieldset' do
|
|
28
|
+
output_buffer.should have_tag("form fieldset.actions ol")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'should render the contents of the block inside the ol' do
|
|
32
|
+
output_buffer.should have_tag("form fieldset.actions ol", /hello/)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'should not render a legend inside the fieldset' do
|
|
36
|
+
output_buffer.should_not have_tag("form fieldset.actions legend")
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe 'when a :name option is provided' do
|
|
41
|
+
before do
|
|
42
|
+
@legend_text = "Advanced options"
|
|
43
|
+
|
|
44
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
45
|
+
builder.actions :name => @legend_text do
|
|
46
|
+
end
|
|
47
|
+
end)
|
|
48
|
+
end
|
|
49
|
+
it 'should render a fieldset inside the form' do
|
|
50
|
+
output_buffer.should have_tag("form fieldset.actions legend", /#{@legend_text}/)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe 'when other options are provided' do
|
|
55
|
+
before do
|
|
56
|
+
@id_option = 'advanced'
|
|
57
|
+
@class_option = 'wide'
|
|
58
|
+
|
|
59
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
60
|
+
builder.actions :id => @id_option, :class => @class_option do
|
|
61
|
+
end
|
|
62
|
+
end)
|
|
63
|
+
end
|
|
64
|
+
it 'should pass the options into the fieldset tag as attributes' do
|
|
65
|
+
output_buffer.should have_tag("form fieldset##{@id_option}")
|
|
66
|
+
output_buffer.should have_tag("form fieldset.#{@class_option}")
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe 'without a block' do
|
|
73
|
+
|
|
74
|
+
describe 'with no args (default buttons)' do
|
|
75
|
+
|
|
76
|
+
before do
|
|
77
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
78
|
+
concat(builder.actions)
|
|
79
|
+
end)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'should render a form' do
|
|
83
|
+
output_buffer.should have_tag('form')
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'should render an actions fieldset inside the form' do
|
|
87
|
+
output_buffer.should have_tag('form fieldset.actions')
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'should not render a legend in the fieldset' do
|
|
91
|
+
output_buffer.should_not have_tag('form fieldset.actions legend')
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'should render an ol in the fieldset' do
|
|
95
|
+
output_buffer.should have_tag('form fieldset.actions ol')
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'should render a list item in the ol for each default action' do
|
|
99
|
+
output_buffer.should have_tag('form fieldset.actions ol li.action.input_action', :count => 1)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe 'with button names as args' do
|
|
105
|
+
|
|
106
|
+
before do
|
|
107
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
108
|
+
concat(builder.actions(:submit, :cancel, :reset))
|
|
109
|
+
end)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'should render a form with a fieldset containing a list item for each button arg' do
|
|
113
|
+
output_buffer.should have_tag('form > fieldset.actions > ol > li.action', :count => 3)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe 'with button names as args and an options hash' do
|
|
119
|
+
|
|
120
|
+
before do
|
|
121
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
122
|
+
concat(builder.actions(:submit, :cancel, :reset, :name => "Now click a button", :id => "my-id"))
|
|
123
|
+
end)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'should render a form with a fieldset containing a list item for each button arg' do
|
|
127
|
+
output_buffer.should have_tag('form > fieldset.actions > ol > li.action', :count => 3)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it 'should pass the options down to the fieldset' do
|
|
131
|
+
output_buffer.should have_tag('form > fieldset#my-id.actions')
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'should use the special :name option as a text for the legend tag' do
|
|
135
|
+
output_buffer.should have_tag('form > fieldset#my-id.actions > legend', /Now click a button/)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
|