formtastic 1.2.5 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.yardopts +1 -0
- data/CHANGELOG +279 -0
- data/Gemfile +3 -0
- data/README.textile +155 -172
- data/RELEASE_PROCESS +7 -0
- data/Rakefile +52 -0
- data/app/assets/stylesheets/formtastic.css +275 -0
- data/app/assets/stylesheets/formtastic_ie6.css +27 -0
- data/app/assets/stylesheets/formtastic_ie7.css +17 -0
- data/formtastic.gemspec +51 -0
- data/lib/formtastic.rb +21 -1960
- data/lib/formtastic/engine.rb +7 -0
- data/lib/formtastic/form_builder.rb +83 -0
- data/lib/formtastic/helpers.rb +16 -0
- data/lib/formtastic/helpers/buttons_helper.rb +277 -0
- data/lib/formtastic/helpers/errors_helper.rb +113 -0
- data/lib/formtastic/helpers/fieldset_wrapper.rb +75 -0
- data/lib/formtastic/helpers/file_column_detection.rb +16 -0
- data/lib/formtastic/helpers/form_helper.rb +198 -0
- data/lib/formtastic/helpers/input_helper.rb +366 -0
- data/lib/formtastic/helpers/inputs_helper.rb +392 -0
- data/lib/formtastic/helpers/reflection.rb +33 -0
- data/lib/formtastic/helpers/semantic_form_helper.rb +11 -0
- data/lib/formtastic/html_attributes.rb +21 -0
- data/lib/formtastic/i18n.rb +1 -0
- data/lib/formtastic/inputs.rb +31 -0
- data/lib/formtastic/inputs/base.rb +61 -0
- data/lib/formtastic/inputs/base/associations.rb +31 -0
- data/lib/formtastic/inputs/base/choices.rb +103 -0
- data/lib/formtastic/inputs/base/collections.rb +94 -0
- data/lib/formtastic/inputs/base/database.rb +17 -0
- data/lib/formtastic/inputs/base/errors.rb +58 -0
- data/lib/formtastic/inputs/base/fileish.rb +23 -0
- data/lib/formtastic/inputs/base/grouped_collections.rb +77 -0
- data/lib/formtastic/inputs/base/hints.rb +31 -0
- data/lib/formtastic/inputs/base/html.rb +52 -0
- data/lib/formtastic/inputs/base/labelling.rb +55 -0
- data/lib/formtastic/inputs/base/naming.rb +42 -0
- data/lib/formtastic/inputs/base/options.rb +18 -0
- data/lib/formtastic/inputs/base/stringish.rb +35 -0
- data/lib/formtastic/inputs/base/timeish.rb +128 -0
- data/lib/formtastic/inputs/base/validations.rb +166 -0
- data/lib/formtastic/inputs/base/wrapping.rb +40 -0
- data/lib/formtastic/inputs/boolean_input.rb +96 -0
- data/lib/formtastic/inputs/check_boxes_input.rb +179 -0
- data/lib/formtastic/inputs/country_input.rb +66 -0
- data/lib/formtastic/inputs/date_input.rb +14 -0
- data/lib/formtastic/inputs/datetime_input.rb +9 -0
- data/lib/formtastic/inputs/email_input.rb +40 -0
- data/lib/formtastic/inputs/file_input.rb +42 -0
- data/lib/formtastic/inputs/hidden_input.rb +66 -0
- data/lib/formtastic/inputs/number_input.rb +118 -0
- data/lib/formtastic/inputs/numeric_input.rb +21 -0
- data/lib/formtastic/inputs/password_input.rb +40 -0
- data/lib/formtastic/inputs/phone_input.rb +41 -0
- data/lib/formtastic/inputs/radio_input.rb +157 -0
- data/lib/formtastic/inputs/range_input.rb +119 -0
- data/lib/formtastic/inputs/search_input.rb +40 -0
- data/lib/formtastic/inputs/select_input.rb +210 -0
- data/lib/formtastic/inputs/string_input.rb +34 -0
- data/lib/formtastic/inputs/text_input.rb +47 -0
- data/lib/formtastic/inputs/time_input.rb +14 -0
- data/lib/formtastic/inputs/time_zone_input.rb +48 -0
- data/lib/formtastic/inputs/url_input.rb +40 -0
- data/lib/formtastic/localized_string.rb +105 -0
- data/lib/formtastic/railtie.rb +5 -7
- data/lib/formtastic/semantic_form_builder.rb +11 -0
- data/lib/formtastic/util.rb +6 -19
- data/lib/formtastic/version.rb +3 -0
- data/lib/generators/formtastic/install/install_generator.rb +28 -6
- data/lib/generators/templates/_form.html.erb +10 -4
- data/lib/generators/templates/_form.html.haml +8 -4
- data/lib/generators/templates/formtastic.rb +25 -32
- data/lib/locale/en.yml +1 -0
- data/lib/tasks/verify_rcov.rb +44 -0
- data/sample/basic_inputs.html +182 -0
- data/sample/config.ru +69 -0
- data/sample/index.html +14 -0
- data/spec/builder/custom_builder_spec.rb +109 -0
- data/spec/builder/error_proc_spec.rb +27 -0
- data/spec/builder/errors_spec.rb +193 -0
- data/spec/builder/semantic_fields_for_spec.rb +88 -0
- data/spec/helpers/buttons_helper_spec.rb +150 -0
- data/spec/helpers/commit_button_helper_spec.rb +470 -0
- data/spec/helpers/form_helper_spec.rb +135 -0
- data/spec/helpers/input_helper_spec.rb +837 -0
- data/spec/helpers/inputs_helper_spec.rb +562 -0
- data/spec/helpers/semantic_errors_helper_spec.rb +112 -0
- data/spec/i18n_spec.rb +199 -0
- data/spec/inputs/boolean_input_spec.rb +184 -0
- data/spec/inputs/check_boxes_input_spec.rb +375 -0
- data/spec/inputs/country_input_spec.rb +133 -0
- data/spec/inputs/custom_input_spec.rb +52 -0
- data/spec/inputs/date_input_spec.rb +110 -0
- data/spec/inputs/datetime_input_spec.rb +115 -0
- data/spec/inputs/email_input_spec.rb +55 -0
- data/spec/inputs/file_input_spec.rb +59 -0
- data/spec/inputs/hidden_input_spec.rb +120 -0
- data/spec/inputs/include_blank_spec.rb +70 -0
- data/spec/inputs/label_spec.rb +104 -0
- data/spec/inputs/number_input_spec.rb +487 -0
- data/spec/inputs/numeric_input_spec.rb +41 -0
- data/spec/inputs/password_input_spec.rb +69 -0
- data/spec/inputs/phone_input_spec.rb +55 -0
- data/spec/inputs/placeholder_spec.rb +71 -0
- data/spec/inputs/radio_input_spec.rb +234 -0
- data/spec/inputs/range_input_spec.rb +477 -0
- data/spec/inputs/search_input_spec.rb +55 -0
- data/spec/inputs/select_input_spec.rb +545 -0
- data/spec/inputs/string_input_spec.rb +163 -0
- data/spec/inputs/text_input_spec.rb +158 -0
- data/spec/inputs/time_input_spec.rb +155 -0
- data/spec/inputs/time_zone_input_spec.rb +87 -0
- data/spec/inputs/url_input_spec.rb +55 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +361 -0
- data/spec/support/custom_macros.rb +656 -0
- data/spec/support/deferred_garbage_collection.rb +21 -0
- data/spec/support/deprecation.rb +6 -0
- data/spec/support/test_environment.rb +30 -0
- metadata +306 -88
- 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/generators/formtastic/form/form_generator.rb +0 -84
- 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
data/lib/locale/en.yml
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'colored'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module RCov
|
5
|
+
|
6
|
+
class VerifyTask < Rake::TaskLib
|
7
|
+
|
8
|
+
attr_accessor :name
|
9
|
+
attr_accessor :index_html
|
10
|
+
attr_accessor :verbose
|
11
|
+
attr_accessor :threshold
|
12
|
+
attr_accessor :require_exact_threshold
|
13
|
+
|
14
|
+
def initialize(name=:verify_rcov)
|
15
|
+
@name = name
|
16
|
+
@index_html = 'coverage/index.html'
|
17
|
+
@verbose = true
|
18
|
+
@require_exact_threshold = true
|
19
|
+
yield self if block_given?
|
20
|
+
raise "Threshold must be set" if @threshold.nil?
|
21
|
+
define
|
22
|
+
end
|
23
|
+
|
24
|
+
def define
|
25
|
+
desc "Verify that rcov coverage is at least #{threshold}%"
|
26
|
+
task @name do
|
27
|
+
total_coverage = 0
|
28
|
+
File.open(index_html).each_line do |line|
|
29
|
+
if line =~ /<tt class='coverage_total'>\s*(\d+\.\d+)%\s*<\/tt>/
|
30
|
+
total_coverage = $1.to_f
|
31
|
+
break
|
32
|
+
end
|
33
|
+
end
|
34
|
+
output_coverage(total_coverage)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def output_coverage(total_coverage)
|
39
|
+
puts "Coverage: #{total_coverage}% (threshold: #{threshold}%)".green if verbose && total_coverage >= threshold
|
40
|
+
raise "Coverage must be at least #{threshold}% but was #{total_coverage}%".red if total_coverage < threshold
|
41
|
+
raise "Coverage has increased above the threshold of #{threshold}% to #{total_coverage}%. You should update your threshold value.".red if (total_coverage > threshold) and require_exact_threshold
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta content="noindex,nofollow" name="robots">
|
5
|
+
<meta charset="utf-8">
|
6
|
+
<title>Formtastic</title>
|
7
|
+
|
8
|
+
<link href="/formtastic.css" rel="stylesheet" type="text/css" />
|
9
|
+
<!--[if IE 6]><link href="/formtastic_ie6.css" rel="stylesheet" type="text/css" /><![endif]-->
|
10
|
+
<!--[if IE 7]><link href="/formtastic_ie7.css" rel="stylesheet" type="text/css" /><![endif]-->
|
11
|
+
|
12
|
+
<style>
|
13
|
+
body {
|
14
|
+
font-family: helvetica, arial;
|
15
|
+
font-size: 12px;
|
16
|
+
}
|
17
|
+
</style>
|
18
|
+
</head>
|
19
|
+
</html>
|
20
|
+
<body>
|
21
|
+
<h1>Formtastic</h1>
|
22
|
+
|
23
|
+
<form action="basic_inputs.html" class="formtastic gem" id="new_gem" method="get">
|
24
|
+
<fieldset class="inputs">
|
25
|
+
<ol>
|
26
|
+
<li class="input string stringish optional" id="gem_summary_input">
|
27
|
+
<label class="label" for="gem_summary">Summary</label>
|
28
|
+
<input id="gem_summary" name="gem[summary]" type="text" value="A Rails form builder plugin/gem with semantically rich and accessible markup" maxlength="255">
|
29
|
+
</li>
|
30
|
+
|
31
|
+
<li class="input text optional" id="gem_description_input">
|
32
|
+
<label class="label" for="gem_description">Description</label>
|
33
|
+
<textarea id="gem_description" rows="5">A Rails form builder plugin/gem with semantically rich and accessible markup</textarea>
|
34
|
+
</li>
|
35
|
+
|
36
|
+
<li class="input url stringish optional" id="gem_url_input">
|
37
|
+
<label class="label" for="gem_url">URL</label>
|
38
|
+
<input id="gem_url" name="gem[url]" type="url">
|
39
|
+
<p class="inline-hints">Example: https://github.com/justinfrench/formtastic</p>
|
40
|
+
</li>
|
41
|
+
|
42
|
+
<li class="input password stringish required" id="gem_password_input">
|
43
|
+
<label class="label" for="gem_password">Password<abbr title="required">*</abbr></label>
|
44
|
+
<input id="gem_password" name="gem[password]" type="password">
|
45
|
+
<p class="inline-errors">can't be blank</p>
|
46
|
+
</li>
|
47
|
+
|
48
|
+
<li class="input password stringish required" id="gem_password_input">
|
49
|
+
<label class="label" for="gem_password_confirmation">Password confirmation<abbr title="required">*</abbr></label>
|
50
|
+
<input id="gem_password_confirmation" name="gem[password_confirmation]" type="password">
|
51
|
+
<p class="inline-errors">can't be blank</p>
|
52
|
+
</li>
|
53
|
+
|
54
|
+
<li class="input numeric stringish optional" id="gem_downloads_input">
|
55
|
+
<label class="label" for="gem_downloads">Downloads</label>
|
56
|
+
<input id="gem_downloads" name="gem[downloads]" type="numeric" value="209,354">
|
57
|
+
</li>
|
58
|
+
|
59
|
+
<li class="input file optional" id="gem_file_input">
|
60
|
+
<label class="label" for="gem_file">File</label>
|
61
|
+
<input id="gem_file" name="gem[file]" type="file" value="value">
|
62
|
+
</li>
|
63
|
+
|
64
|
+
<li class="input email stringish optional" id="gem_email_input">
|
65
|
+
<label class="label" for="gem_email">Email</label>
|
66
|
+
<input id="gem_email" name="gem[email]" type="email">
|
67
|
+
</li>
|
68
|
+
|
69
|
+
<li class="input phone stringish optional" id="gem_phone_input">
|
70
|
+
<label class="label" for="gem_phone">Phone</label>
|
71
|
+
<input id="gem_phone" name="gem[phone]" type="phone">
|
72
|
+
</li>
|
73
|
+
|
74
|
+
<li class="input search stringish optional" id="gem_search_input">
|
75
|
+
<label class="label" for="gem_search">Search</label>
|
76
|
+
<input id="gem_search" name="gem[search]" type="search">
|
77
|
+
</li>
|
78
|
+
|
79
|
+
<li class="input date optional">
|
80
|
+
<fieldset class="fragments">
|
81
|
+
<legend class="label"><label>First release</label></legend>
|
82
|
+
<ol class="fragments-group">
|
83
|
+
<li class="fragment">
|
84
|
+
<label>Year</label>
|
85
|
+
<select id="gem_first_release_1i" name="gem[first_release][1i]">
|
86
|
+
<option>2009</option>
|
87
|
+
</select>
|
88
|
+
</li>
|
89
|
+
<li class="fragment">
|
90
|
+
<label>Month</label>
|
91
|
+
<select id="gem_first_release_2i" name="gem[first_release][2i]">
|
92
|
+
<option>October</option>
|
93
|
+
</select>
|
94
|
+
</li>
|
95
|
+
<li class="fragment">
|
96
|
+
<label>Day</label>
|
97
|
+
<select id="gem_first_release_3i" name="gem[first_release][3i]">
|
98
|
+
<option>15</option>
|
99
|
+
</select>
|
100
|
+
</li>
|
101
|
+
</ol>
|
102
|
+
</fieldset>
|
103
|
+
</li>
|
104
|
+
|
105
|
+
<li class="input string stringish optional autofocus" id="gem_autofocus_input">
|
106
|
+
<label class="label" for="gem_autofocus">Autofocus</label>
|
107
|
+
<input id="gem_autofocus" name="gem[autofocus]" type="text" value="The focus is set to this field" autofocus="autofocus">
|
108
|
+
</li>
|
109
|
+
|
110
|
+
<li class="input boolean optional" id="gem_terms_and_conditions_input">
|
111
|
+
<label for="gem_terms_and_conditions">
|
112
|
+
<input id="gem_terms_and_conditions" name="gem[terms_and_conditions]" type="checkbox" value="1" checked="checked">
|
113
|
+
I agree to your draconian terms of service even though I didn't read them
|
114
|
+
</label>
|
115
|
+
</li>
|
116
|
+
|
117
|
+
<li class="input select optional" id="gem_awesomeness_input">
|
118
|
+
<label class="label" for="gem_awesomeness">Select</label>
|
119
|
+
<select id="gem_awesomeness" name="gem[awesomeness]">
|
120
|
+
<option value="5">First choice</option>
|
121
|
+
<option value="4">Second choice</option>
|
122
|
+
</select>
|
123
|
+
</li>
|
124
|
+
|
125
|
+
<li class="input radio optional">
|
126
|
+
<fieldset class="choices">
|
127
|
+
<legend class="label"><label>Rate</label></legend>
|
128
|
+
<ol class="choices-group">
|
129
|
+
<li class="choice">
|
130
|
+
<label><input id="gem_rate_five" name="gem[rate]" type="radio" checked="checked"> Five</label></label>
|
131
|
+
</li>
|
132
|
+
<li class="choice">
|
133
|
+
<label><input id="gem_rate_four" name="gem[rate]" type="radio"> Four</label></label>
|
134
|
+
</li>
|
135
|
+
<li class="choice">
|
136
|
+
<label><input id="gem_rate_three" name="gem[rate]" type="radio"> Three</label></label>
|
137
|
+
</li>
|
138
|
+
<li class="choice">
|
139
|
+
<label><input id="gem_rate_two" name="gem[rate]" type="radio"> Two</label></label>
|
140
|
+
</li>
|
141
|
+
<li class="choice">
|
142
|
+
<label><input id="gem_rate_one" name="gem[rate]" type="radio"> One</label></label>
|
143
|
+
</li>
|
144
|
+
</ol>
|
145
|
+
</fieldset>
|
146
|
+
</li>
|
147
|
+
|
148
|
+
<li class="input check_boxes optional">
|
149
|
+
<fieldset class="choices">
|
150
|
+
<legend class="label"><label>Browsers</label></legend>
|
151
|
+
<ol class="choices-group">
|
152
|
+
<li class="choice">
|
153
|
+
<label><input id="gem_browser_google_chrome" name="gem[browser][]" type="checkbox"> Google Chrome</label></label>
|
154
|
+
</li>
|
155
|
+
<li class="choice">
|
156
|
+
<label><input id="gem_browser_apple_safari" name="gem[browser][]" type="checkbox"> Apple Safari</label></label>
|
157
|
+
</li>
|
158
|
+
<li class="choice">
|
159
|
+
<label><input id="gem_browser_mozilla_firefox" name="gem[browser][]" type="checkbox"> Mozilla Firefox</label></label>
|
160
|
+
</li>
|
161
|
+
<li class="choice">
|
162
|
+
<label><input id="gem_browser_opera" name="gem[browser][]" type="checkbox"> Opera</label></label>
|
163
|
+
</li>
|
164
|
+
<li class="choice">
|
165
|
+
<label><input id="gem_browser_internet_explorer" name="gem[browser][]" type="checkbox"> Internet Explorer (Although you really can't call it a browser can you? This is some long text to force wrapping.)</label></label>
|
166
|
+
</li>
|
167
|
+
</ol>
|
168
|
+
</fieldset>
|
169
|
+
</li>
|
170
|
+
</ol>
|
171
|
+
</fieldset>
|
172
|
+
|
173
|
+
<fieldset class="buttons">
|
174
|
+
<ol>
|
175
|
+
<li class="button commit">
|
176
|
+
<input class="create" id="gem_submit" type="submit">
|
177
|
+
</li>
|
178
|
+
</ol>
|
179
|
+
</fieldset>
|
180
|
+
</form>
|
181
|
+
</body>
|
182
|
+
</html>
|
data/sample/config.ru
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module Rack
|
2
|
+
module Formtastic
|
3
|
+
class Samples
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
@status, @headers, @body = @app.call(env)
|
10
|
+
@env = env
|
11
|
+
|
12
|
+
@body = '' if favicon?
|
13
|
+
@body = static_file if !favicon? && static_file?
|
14
|
+
@body = stylesheet if stylesheet?
|
15
|
+
@headers ||= {}
|
16
|
+
@headers['Content-Type'] = mime(extension)
|
17
|
+
[@status, @headers, @body]
|
18
|
+
end
|
19
|
+
|
20
|
+
def static_file?
|
21
|
+
!stylesheet?
|
22
|
+
end
|
23
|
+
|
24
|
+
def stylesheet?
|
25
|
+
@env["PATH_INFO"] =~ /\.(css)/
|
26
|
+
end
|
27
|
+
|
28
|
+
def favicon?
|
29
|
+
@env["PATH_INFO"] =~ /favicon.ico$/
|
30
|
+
end
|
31
|
+
|
32
|
+
def extension
|
33
|
+
@env["PATH_INFO"].split(".").last
|
34
|
+
end
|
35
|
+
|
36
|
+
def mime(extension)
|
37
|
+
mimes[extension] || mimes['html']
|
38
|
+
end
|
39
|
+
|
40
|
+
def mimes
|
41
|
+
{
|
42
|
+
'ico' => 'image/x-icon',
|
43
|
+
'html' => 'text/html',
|
44
|
+
'css' => 'text/css',
|
45
|
+
'js' => 'text/javascript'
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def static_file
|
50
|
+
::File.open(file_path)
|
51
|
+
end
|
52
|
+
|
53
|
+
def stylesheet
|
54
|
+
::File.open(::File.join("../app/assets/stylesheets", file_path))
|
55
|
+
end
|
56
|
+
|
57
|
+
def file_path
|
58
|
+
@env["PATH_INFO"].gsub(/^\//, '').gsub(/^$/, 'index.html')
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
use Rack::ContentLength
|
66
|
+
use Rack::Formtastic::Samples
|
67
|
+
|
68
|
+
app = lambda { |env| [200, @headers, @body] }
|
69
|
+
run app
|
data/sample/index.html
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Formtastic::Helpers::FormHelper.builder' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
class MyCustomFormBuilder < Formtastic::FormBuilder
|
9
|
+
end
|
10
|
+
|
11
|
+
# TODO should be a separate spec for custom inputs
|
12
|
+
class Formtastic::Inputs::AwesomeInput
|
13
|
+
include Formtastic::Inputs::Base
|
14
|
+
def to_html
|
15
|
+
"Awesome!"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
@output_buffer = ''
|
21
|
+
mock_everything
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'is the Formtastic::FormBuilder by default' do
|
25
|
+
Formtastic::Helpers::FormHelper.builder.should == Formtastic::FormBuilder
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'can be configured to use your own custom form builder' do
|
29
|
+
# Set it to a custom builder class
|
30
|
+
Formtastic::Helpers::FormHelper.builder = MyCustomFormBuilder
|
31
|
+
Formtastic::Helpers::FormHelper.builder.should == MyCustomFormBuilder
|
32
|
+
|
33
|
+
# Reset it to the default
|
34
|
+
Formtastic::Helpers::FormHelper.builder = Formtastic::FormBuilder
|
35
|
+
Formtastic::Helpers::FormHelper.builder.should == Formtastic::FormBuilder
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should allow custom settings per form builder subclass' do
|
39
|
+
with_config(:all_fields_required_by_default, true) do
|
40
|
+
MyCustomFormBuilder.all_fields_required_by_default = false
|
41
|
+
|
42
|
+
MyCustomFormBuilder.all_fields_required_by_default.should be_false
|
43
|
+
Formtastic::FormBuilder.all_fields_required_by_default.should be_true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "when using a custom builder" do
|
48
|
+
|
49
|
+
before do
|
50
|
+
@new_post.stub!(:title)
|
51
|
+
Formtastic::Helpers::FormHelper.builder = MyCustomFormBuilder
|
52
|
+
end
|
53
|
+
|
54
|
+
after do
|
55
|
+
Formtastic::Helpers::FormHelper.builder = Formtastic::FormBuilder
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "semantic_form_for" do
|
59
|
+
|
60
|
+
it "should yield an instance of the custom builder" do
|
61
|
+
semantic_form_for(@new_post) do |builder|
|
62
|
+
builder.class.should.kind_of?(MyCustomFormBuilder)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# TODO should be a separate spec for custom inputs
|
67
|
+
it "should allow me to call my custom input" do
|
68
|
+
semantic_form_for(@new_post) do |builder|
|
69
|
+
concat(builder.input(:title, :as => :awesome))
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "fields_for" do
|
76
|
+
|
77
|
+
it "should yield an instance of the parent form builder" do
|
78
|
+
@new_post.stub!(:comment).and_return([@fred])
|
79
|
+
@new_post.stub!(:comment_attributes=)
|
80
|
+
semantic_form_for(@new_post, :builder => MyCustomFormBuilder) do |builder|
|
81
|
+
builder.class.should.kind_of?(MyCustomFormBuilder)
|
82
|
+
|
83
|
+
builder.fields_for(:comment) do |nested_builder|
|
84
|
+
nested_builder.class.should.kind_of?(MyCustomFormBuilder)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "when using a builder passed to form options" do
|
94
|
+
|
95
|
+
describe "fields_for" do
|
96
|
+
|
97
|
+
it "should yield an instance of the parent form builder" do
|
98
|
+
@new_post.stub!(:author_attributes=)
|
99
|
+
semantic_form_for(@new_post, :builder => MyCustomFormBuilder) do |builder|
|
100
|
+
builder.fields_for(:author) do |nested_builder|
|
101
|
+
nested_builder.class.should.kind_of?(MyCustomFormBuilder)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Rails field_error_proc' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not be overridden globally for all form builders" do
|
14
|
+
current_field_error_proc = ::ActionView::Base.field_error_proc
|
15
|
+
|
16
|
+
semantic_form_for(@new_post) do |builder|
|
17
|
+
::ActionView::Base.field_error_proc.should_not == current_field_error_proc
|
18
|
+
end
|
19
|
+
|
20
|
+
::ActionView::Base.field_error_proc.should == current_field_error_proc
|
21
|
+
|
22
|
+
form_for(@new_post) do |builder|
|
23
|
+
::ActionView::Base.field_error_proc.should == current_field_error_proc
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|