formtastic-rails3 0.9.7 → 0.9.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +23 -7
- data/Rakefile +27 -4
- data/generators/formtastic/templates/formtastic.css +9 -7
- data/generators/formtastic/templates/formtastic.rb +1 -1
- data/generators/formtastic/templates/formtastic_changes.css +4 -0
- data/lib/formtastic.rb +190 -142
- data/lib/formtastic/i18n.rb +8 -5
- data/lib/formtastic/railtie.rb +12 -0
- data/lib/formtastic/util.rb +35 -0
- data/lib/generators/formtastic/form/form_generator.rb +4 -3
- data/lib/generators/formtastic/install/install_generator.rb +2 -1
- data/rails/init.rb +5 -0
- data/spec/buttons_spec.rb +25 -8
- data/spec/commit_button_spec.rb +88 -64
- data/spec/custom_builder_spec.rb +1 -1
- data/spec/custom_macros.rb +67 -26
- data/spec/error_proc_spec.rb +1 -1
- data/spec/errors_spec.rb +21 -1
- data/spec/form_helper_spec.rb +47 -15
- data/spec/i18n_spec.rb +40 -19
- data/spec/include_blank_spec.rb +9 -5
- data/spec/input_spec.rb +224 -76
- data/spec/inputs/boolean_input_spec.rb +22 -11
- data/spec/inputs/check_boxes_input_spec.rb +103 -11
- data/spec/inputs/country_input_spec.rb +46 -8
- data/spec/inputs/date_input_spec.rb +80 -55
- data/spec/inputs/datetime_input_spec.rb +134 -83
- data/spec/inputs/file_input_spec.rb +4 -3
- data/spec/inputs/hidden_input_spec.rb +17 -3
- data/spec/inputs/numeric_input_spec.rb +3 -3
- data/spec/inputs/password_input_spec.rb +3 -3
- data/spec/inputs/radio_input_spec.rb +28 -11
- data/spec/inputs/select_input_spec.rb +122 -46
- data/spec/inputs/string_input_spec.rb +3 -3
- data/spec/inputs/text_input_spec.rb +4 -3
- data/spec/inputs/time_input_spec.rb +109 -53
- data/spec/inputs/time_zone_input_spec.rb +15 -7
- data/spec/inputs_spec.rb +85 -39
- data/spec/label_spec.rb +1 -1
- data/spec/layout_helper_spec.rb +5 -16
- data/spec/semantic_errors_spec.rb +7 -7
- data/spec/semantic_fields_for_spec.rb +5 -4
- data/spec/spec_helper.rb +102 -36
- metadata +11 -14
- data/lib/generators/formtastic/form/templates/_form.html.erb +0 -5
- data/lib/generators/formtastic/form/templates/_form.html.haml +0 -4
- data/lib/generators/formtastic/install/templates/formtastic.css +0 -144
- data/lib/generators/formtastic/install/templates/formtastic.rb +0 -58
- data/lib/generators/formtastic/install/templates/formtastic_changes.css +0 -10
- data/spec/inputs/currency_input_spec.rb +0 -80
data/lib/formtastic/i18n.rb
CHANGED
@@ -6,13 +6,16 @@ module Formtastic
|
|
6
6
|
:required => 'required',
|
7
7
|
:yes => 'Yes',
|
8
8
|
:no => 'No',
|
9
|
-
:create => 'Create {
|
10
|
-
:update => 'Update {
|
9
|
+
:create => 'Create %{model}',
|
10
|
+
:update => 'Update %{model}'
|
11
11
|
}.freeze
|
12
12
|
SCOPES = [
|
13
|
-
'{
|
14
|
-
'{
|
15
|
-
'{{attribute}
|
13
|
+
'%{model}.%{nested_model}.%{action}.%{attribute}',
|
14
|
+
'%{model}.%{action}.%{attribute}',
|
15
|
+
'%{model}.%{nested_model}.%{attribute}',
|
16
|
+
'%{model}.%{attribute}',
|
17
|
+
'%{nested_model}.%{attribute}',
|
18
|
+
'%{attribute}'
|
16
19
|
]
|
17
20
|
|
18
21
|
class << self
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'formtastic'
|
2
|
+
require 'formtastic/layout_helper'
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
module Formtastic
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
initializer :after_initialize do
|
8
|
+
ActionView::Base.send :include, Formtastic::SemanticFormHelper
|
9
|
+
ActionView::Base.send(:include, Formtastic::LayoutHelper)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Adapted from the rails3 compatibility shim in Haml 2.2
|
2
|
+
module Formtastic
|
3
|
+
module Util
|
4
|
+
extend self
|
5
|
+
## Rails XSS Safety
|
6
|
+
|
7
|
+
# Returns the given text, marked as being HTML-safe.
|
8
|
+
# With older versions of the Rails XSS-safety mechanism,
|
9
|
+
# this destructively modifies the HTML-safety of `text`.
|
10
|
+
#
|
11
|
+
# @param text [String]
|
12
|
+
# @return [String] `text`, marked as HTML-safe
|
13
|
+
def html_safe(text)
|
14
|
+
return text if text.nil?
|
15
|
+
return text.html_safe if defined?(ActiveSupport::SafeBuffer)
|
16
|
+
return text.html_safe!
|
17
|
+
end
|
18
|
+
|
19
|
+
def rails_safe_buffer_class
|
20
|
+
# It's important that we check ActiveSupport first,
|
21
|
+
# because in Rails 2.3.6 ActionView::SafeBuffer exists
|
22
|
+
# but is a deprecated proxy object.
|
23
|
+
return ActiveSupport::SafeBuffer if defined?(ActiveSupport::SafeBuffer)
|
24
|
+
return ActionView::SafeBuffer
|
25
|
+
end
|
26
|
+
|
27
|
+
def rails3?
|
28
|
+
version=
|
29
|
+
if defined?(ActionPack::VERSION::MAJOR)
|
30
|
+
ActionPack::VERSION::MAJOR
|
31
|
+
end
|
32
|
+
version >= 3
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -15,7 +15,8 @@ module Formtastic
|
|
15
15
|
:desc => 'Generate for custom controller/view path - in case model and controller namespace is different, i.e. "admin/posts"'
|
16
16
|
|
17
17
|
def self.source_root
|
18
|
-
|
18
|
+
# Set source directory for the templates to the rails2 generator template directory
|
19
|
+
@source_root ||= File.expand_path(File.join('..', '..', '..', '..', 'generators', 'form', 'templates'), File.dirname(__FILE__))
|
19
20
|
end
|
20
21
|
|
21
22
|
def self.banner
|
@@ -25,9 +26,9 @@ module Formtastic
|
|
25
26
|
def create_or_show
|
26
27
|
if options[:partial]
|
27
28
|
empty_directory "app/views/#{controller_path}"
|
28
|
-
template "
|
29
|
+
template "view__form.html.#{template_type}", "app/views/#{controller_path}/_form.html.#{template_type}"
|
29
30
|
else
|
30
|
-
template = File.read("#{self.class.source_root}/
|
31
|
+
template = File.read("#{self.class.source_root}/view__form.html.#{template_type}")
|
31
32
|
erb = ERB.new(template, nil, '-')
|
32
33
|
generated_code = erb.result(binding).strip rescue nil
|
33
34
|
|
@@ -4,7 +4,8 @@ module Formtastic
|
|
4
4
|
desc "Copies formtastic.css and formtastic_changes.css to public/stylesheets/ and a config initializer to config/initializers/formtastic_config.rb"
|
5
5
|
|
6
6
|
def self.source_root
|
7
|
-
|
7
|
+
# Set source directory for the templates to the rails2 generator template directory
|
8
|
+
@source_root ||= File.expand_path(File.join('..', '..', '..', '..', 'generators', 'formtastic', 'templates'), File.dirname(__FILE__))
|
8
9
|
end
|
9
10
|
|
10
11
|
def self.banner
|
data/rails/init.rb
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib formtastic])
|
3
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib formtastic layout_helper])
|
4
|
+
ActionView::Base.send :include, Formtastic::SemanticFormHelper
|
5
|
+
ActionView::Base.send :include, Formtastic::LayoutHelper
|
data/spec/buttons_spec.rb
CHANGED
@@ -6,33 +6,38 @@ describe 'SemanticFormBuilder#buttons' do
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
8
8
|
before do
|
9
|
-
@output_buffer =
|
9
|
+
@output_buffer = ''
|
10
10
|
mock_everything
|
11
11
|
end
|
12
12
|
|
13
13
|
describe 'with a block' do
|
14
14
|
describe 'when no options are provided' do
|
15
15
|
before do
|
16
|
-
semantic_form_for(@new_post) do |builder|
|
17
|
-
builder.buttons do
|
16
|
+
@form = semantic_form_for(@new_post) do |builder|
|
17
|
+
buttons = builder.buttons do
|
18
18
|
concat('hello')
|
19
19
|
end
|
20
|
+
concat(buttons)
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'should render a fieldset inside the form, with a class of "inputs"' do
|
25
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
24
26
|
output_buffer.should have_tag("form fieldset.buttons")
|
25
27
|
end
|
26
28
|
|
27
29
|
it 'should render an ol inside the fieldset' do
|
30
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
28
31
|
output_buffer.should have_tag("form fieldset.buttons ol")
|
29
32
|
end
|
30
33
|
|
31
34
|
it 'should render the contents of the block inside the ol' do
|
35
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
32
36
|
output_buffer.should have_tag("form fieldset.buttons ol", /hello/)
|
33
37
|
end
|
34
38
|
|
35
39
|
it 'should not render a legend inside the fieldset' do
|
40
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
36
41
|
output_buffer.should_not have_tag("form fieldset.buttons legend")
|
37
42
|
end
|
38
43
|
end
|
@@ -41,12 +46,13 @@ describe 'SemanticFormBuilder#buttons' do
|
|
41
46
|
before do
|
42
47
|
@legend_text = "Advanced options"
|
43
48
|
|
44
|
-
semantic_form_for(@new_post) do |builder|
|
49
|
+
@form = semantic_form_for(@new_post) do |builder|
|
45
50
|
builder.buttons :name => @legend_text do
|
46
51
|
end
|
47
52
|
end
|
48
53
|
end
|
49
54
|
it 'should render a fieldset inside the form' do
|
55
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
50
56
|
output_buffer.should have_tag("form fieldset legend", /#{@legend_text}/)
|
51
57
|
end
|
52
58
|
end
|
@@ -56,12 +62,13 @@ describe 'SemanticFormBuilder#buttons' do
|
|
56
62
|
@id_option = 'advanced'
|
57
63
|
@class_option = 'wide'
|
58
64
|
|
59
|
-
semantic_form_for(@new_post) do |builder|
|
65
|
+
@form = semantic_form_for(@new_post) do |builder|
|
60
66
|
builder.buttons :id => @id_option, :class => @class_option do
|
61
67
|
end
|
62
68
|
end
|
63
69
|
end
|
64
70
|
it 'should pass the options into the fieldset tag as attributes' do
|
71
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
65
72
|
output_buffer.should have_tag("form fieldset##{@id_option}")
|
66
73
|
output_buffer.should have_tag("form fieldset.#{@class_option}")
|
67
74
|
end
|
@@ -74,32 +81,38 @@ describe 'SemanticFormBuilder#buttons' do
|
|
74
81
|
describe 'with no args (default buttons)' do
|
75
82
|
|
76
83
|
before do
|
77
|
-
semantic_form_for(@new_post) do |builder|
|
84
|
+
@form = semantic_form_for(@new_post) do |builder|
|
78
85
|
concat(builder.buttons)
|
79
86
|
end
|
80
87
|
end
|
81
88
|
|
82
89
|
it 'should render a form' do
|
90
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
83
91
|
output_buffer.should have_tag('form')
|
84
92
|
end
|
85
93
|
|
86
94
|
it 'should render a buttons fieldset inside the form' do
|
95
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
87
96
|
output_buffer.should have_tag('form fieldset.buttons')
|
88
97
|
end
|
89
98
|
|
90
99
|
it 'should not render a legend in the fieldset' do
|
100
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
91
101
|
output_buffer.should_not have_tag('form fieldset.buttons legend')
|
92
102
|
end
|
93
103
|
|
94
104
|
it 'should render an ol in the fieldset' do
|
105
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
95
106
|
output_buffer.should have_tag('form fieldset.buttons ol')
|
96
107
|
end
|
97
108
|
|
98
109
|
it 'should render a list item in the ol for each default button' do
|
110
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
99
111
|
output_buffer.should have_tag('form fieldset.buttons ol li', :count => 1)
|
100
112
|
end
|
101
113
|
|
102
114
|
it 'should render a commit list item for the commit button' do
|
115
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
103
116
|
output_buffer.should have_tag('form fieldset.buttons ol li.commit')
|
104
117
|
end
|
105
118
|
|
@@ -108,12 +121,13 @@ describe 'SemanticFormBuilder#buttons' do
|
|
108
121
|
describe 'with button names as args' do
|
109
122
|
|
110
123
|
before do
|
111
|
-
semantic_form_for(@new_post) do |builder|
|
124
|
+
@form = semantic_form_for(@new_post) do |builder|
|
112
125
|
concat(builder.buttons(:commit))
|
113
126
|
end
|
114
127
|
end
|
115
128
|
|
116
129
|
it 'should render a form with a fieldset containing a list item for each button arg' do
|
130
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
117
131
|
output_buffer.should have_tag('form > fieldset.buttons > ol > li', :count => 1)
|
118
132
|
output_buffer.should have_tag('form > fieldset.buttons > ol > li.commit')
|
119
133
|
end
|
@@ -123,21 +137,24 @@ describe 'SemanticFormBuilder#buttons' do
|
|
123
137
|
describe 'with button names as args and an options hash' do
|
124
138
|
|
125
139
|
before do
|
126
|
-
semantic_form_for(@new_post) do |builder|
|
140
|
+
@form = semantic_form_for(@new_post) do |builder|
|
127
141
|
concat(builder.buttons(:commit, :name => "Now click a button", :id => "my-id"))
|
128
142
|
end
|
129
143
|
end
|
130
144
|
|
131
145
|
it 'should render a form with a fieldset containing a list item for each button arg' do
|
146
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
132
147
|
output_buffer.should have_tag('form > fieldset.buttons > ol > li', :count => 1)
|
133
148
|
output_buffer.should have_tag('form > fieldset.buttons > ol > li.commit', :count => 1)
|
134
149
|
end
|
135
150
|
|
136
151
|
it 'should pass the options down to the fieldset' do
|
152
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
137
153
|
output_buffer.should have_tag('form > fieldset#my-id.buttons')
|
138
154
|
end
|
139
155
|
|
140
156
|
it 'should use the special :name option as a text for the legend tag' do
|
157
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
141
158
|
output_buffer.should have_tag('form > fieldset#my-id.buttons > legend', /Now click a button/)
|
142
159
|
end
|
143
160
|
|
data/spec/commit_button_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
8
8
|
before do
|
9
|
-
@output_buffer =
|
9
|
+
@output_buffer = ''
|
10
10
|
mock_everything
|
11
11
|
end
|
12
12
|
|
@@ -14,29 +14,33 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
14
14
|
|
15
15
|
before do
|
16
16
|
@new_post.stub!(:new_record?).and_return(false)
|
17
|
-
semantic_form_for(@new_post) do |builder|
|
17
|
+
@form = semantic_form_for(@new_post) do |builder|
|
18
18
|
concat(builder.commit_button)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should render a commit li' do
|
23
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
23
24
|
output_buffer.should have_tag('li.commit')
|
24
25
|
end
|
25
26
|
|
26
27
|
it 'should render an input with a type attribute of "submit"' do
|
28
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
27
29
|
output_buffer.should have_tag('li.commit input[@type="submit"]')
|
28
30
|
end
|
29
31
|
|
30
32
|
it 'should render an input with a name attribute of "commit"' do
|
33
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
31
34
|
output_buffer.should have_tag('li.commit input[@name="commit"]')
|
32
35
|
end
|
33
36
|
|
34
37
|
it 'should pass options given in :button_html to the button' do
|
35
38
|
@new_post.stub!(:new_record?).and_return(false)
|
36
|
-
semantic_form_for(@new_post) do |builder|
|
39
|
+
form = semantic_form_for(@new_post) do |builder|
|
37
40
|
concat(builder.commit_button('text', :button_html => {:class => 'my_class', :id => 'my_id'}))
|
38
41
|
end
|
39
42
|
|
43
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
40
44
|
output_buffer.should have_tag('li.commit input#my_id')
|
41
45
|
output_buffer.should have_tag('li.commit input.my_class')
|
42
46
|
end
|
@@ -54,9 +58,10 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
54
58
|
it 'should use the default if set' do
|
55
59
|
with_config :default_commit_button_accesskey, 's' do
|
56
60
|
@new_post.stub!(:new_record?).and_return(false)
|
57
|
-
semantic_form_for(@new_post) do |builder|
|
61
|
+
form = semantic_form_for(@new_post) do |builder|
|
58
62
|
concat(builder.commit_button('text', :button_html => {}))
|
59
63
|
end
|
64
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
60
65
|
output_buffer.should have_tag('li.commit input[@accesskey="s"]')
|
61
66
|
end
|
62
67
|
end
|
@@ -64,9 +69,10 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
64
69
|
it 'should use the value set in options over the default' do
|
65
70
|
with_config :default_commit_button_accesskey, 's' do
|
66
71
|
@new_post.stub!(:new_record?).and_return(false)
|
67
|
-
semantic_form_for(@new_post) do |builder|
|
72
|
+
form = semantic_form_for(@new_post) do |builder|
|
68
73
|
concat(builder.commit_button('text', :accesskey => 'o'))
|
69
74
|
end
|
75
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
70
76
|
output_buffer.should_not have_tag('li.commit input[@accesskey="s"]')
|
71
77
|
output_buffer.should have_tag('li.commit input[@accesskey="o"]')
|
72
78
|
end
|
@@ -75,9 +81,10 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
75
81
|
it 'should use the value set in button_html over options' do
|
76
82
|
with_config :default_commit_button_accesskey, 's' do
|
77
83
|
@new_post.stub!(:new_record?).and_return(false)
|
78
|
-
semantic_form_for(@new_post) do |builder|
|
84
|
+
form = semantic_form_for(@new_post) do |builder|
|
79
85
|
concat(builder.commit_button('text', :accesskey => 'o', :button_html => {:accesskey => 't'}))
|
80
86
|
end
|
87
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
81
88
|
output_buffer.should_not have_tag('li.commit input[@accesskey="s"]')
|
82
89
|
output_buffer.should_not have_tag('li.commit input[@accesskey="o"]')
|
83
90
|
output_buffer.should have_tag('li.commit input[@accesskey="t"]')
|
@@ -90,16 +97,18 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
90
97
|
|
91
98
|
before do
|
92
99
|
@new_post.stub!(:new_record?).and_return(false)
|
93
|
-
semantic_form_for(@new_post) do |builder|
|
100
|
+
@form = semantic_form_for(@new_post) do |builder|
|
94
101
|
concat(builder.commit_button("a string", :button_html => { :class => "pretty"}))
|
95
102
|
end
|
96
103
|
end
|
97
104
|
|
98
105
|
it "should render the string as the value of the button" do
|
106
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
99
107
|
output_buffer.should have_tag('li input[@value="a string"]')
|
100
108
|
end
|
101
109
|
|
102
110
|
it "should deal with the options hash" do
|
111
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
103
112
|
output_buffer.should have_tag('li input.pretty')
|
104
113
|
end
|
105
114
|
|
@@ -109,12 +118,13 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
109
118
|
|
110
119
|
before do
|
111
120
|
@new_post.stub!(:new_record?).and_return(false)
|
112
|
-
semantic_form_for(@new_post) do |builder|
|
121
|
+
@form = semantic_form_for(@new_post) do |builder|
|
113
122
|
concat(builder.commit_button(:button_html => { :class => "pretty"}))
|
114
123
|
end
|
115
124
|
end
|
116
125
|
|
117
126
|
it "should deal with the options hash" do
|
127
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
118
128
|
output_buffer.should have_tag('li input.pretty')
|
119
129
|
end
|
120
130
|
|
@@ -126,9 +136,10 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
126
136
|
describe 'when used without object' do
|
127
137
|
describe 'when explicit label is provided' do
|
128
138
|
it 'should render an input with the explicitly specified label' do
|
129
|
-
semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
139
|
+
form = semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
130
140
|
concat(builder.commit_button("Click!"))
|
131
141
|
end
|
142
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
132
143
|
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="submit"]')
|
133
144
|
end
|
134
145
|
end
|
@@ -136,17 +147,18 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
136
147
|
describe 'when no explicit label is provided' do
|
137
148
|
describe 'when no I18n-localized label is provided' do
|
138
149
|
before do
|
139
|
-
::I18n.backend.store_translations :en, :formtastic => {:submit => 'Submit {
|
150
|
+
::I18n.backend.store_translations :en, :formtastic => {:submit => 'Submit %{model}'}
|
140
151
|
end
|
141
152
|
|
142
153
|
after do
|
143
|
-
::I18n.backend.
|
154
|
+
::I18n.backend.reload!
|
144
155
|
end
|
145
156
|
|
146
157
|
it 'should render an input with default I18n-localized label (fallback)' do
|
147
|
-
semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
158
|
+
form = semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
148
159
|
concat(builder.commit_button)
|
149
160
|
end
|
161
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
150
162
|
output_buffer.should have_tag('li.commit input[@value="Submit Post"][@class~="submit"]')
|
151
163
|
end
|
152
164
|
end
|
@@ -157,33 +169,36 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
157
169
|
:formtastic => {
|
158
170
|
:actions => {
|
159
171
|
:submit => 'Custom Submit',
|
160
|
-
:post => {
|
161
|
-
:submit => 'Custom Submit {{model}}'
|
162
|
-
}
|
163
172
|
}
|
164
173
|
}
|
165
174
|
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
|
166
175
|
end
|
167
176
|
|
168
|
-
|
169
|
-
|
170
|
-
concat(builder.commit_button)
|
171
|
-
end
|
172
|
-
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit Post"][@class~="submit"]})
|
177
|
+
after do
|
178
|
+
::I18n.backend.reload!
|
173
179
|
end
|
174
180
|
|
175
|
-
it 'should render an input with
|
181
|
+
it 'should render an input with localized label (I18n)' do
|
176
182
|
::I18n.backend.store_translations :en,
|
177
183
|
:formtastic => {
|
178
184
|
:actions => {
|
179
185
|
:post => {
|
180
|
-
:submit =>
|
186
|
+
:submit => 'Custom Submit %{model}'
|
181
187
|
}
|
182
188
|
}
|
183
189
|
}
|
184
|
-
semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
190
|
+
form = semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
191
|
+
concat(builder.commit_button)
|
192
|
+
end
|
193
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
194
|
+
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit Post"][@class~="submit"]})
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
198
|
+
form = semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
185
199
|
concat(builder.commit_button)
|
186
200
|
end
|
201
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
187
202
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit"][@class~="submit"]})
|
188
203
|
end
|
189
204
|
|
@@ -199,9 +214,10 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
199
214
|
|
200
215
|
describe 'when explicit label is provided' do
|
201
216
|
it 'should render an input with the explicitly specified label' do
|
202
|
-
semantic_form_for(@new_post) do |builder|
|
217
|
+
form = semantic_form_for(@new_post) do |builder|
|
203
218
|
concat(builder.commit_button("Click!"))
|
204
219
|
end
|
220
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
205
221
|
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="create"]')
|
206
222
|
end
|
207
223
|
end
|
@@ -209,17 +225,18 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
209
225
|
describe 'when no explicit label is provided' do
|
210
226
|
describe 'when no I18n-localized label is provided' do
|
211
227
|
before do
|
212
|
-
::I18n.backend.store_translations :en, :formtastic => {:create => 'Create {
|
228
|
+
::I18n.backend.store_translations :en, :formtastic => {:create => 'Create %{model}'}
|
213
229
|
end
|
214
230
|
|
215
231
|
after do
|
216
|
-
::I18n.backend.
|
232
|
+
::I18n.backend.reload!
|
217
233
|
end
|
218
234
|
|
219
235
|
it 'should render an input with default I18n-localized label (fallback)' do
|
220
|
-
semantic_form_for(@new_post) do |builder|
|
236
|
+
form = semantic_form_for(@new_post) do |builder|
|
221
237
|
concat(builder.commit_button)
|
222
238
|
end
|
239
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
223
240
|
output_buffer.should have_tag('li.commit input[@value="Create Post"][@class~="create"]')
|
224
241
|
end
|
225
242
|
end
|
@@ -230,40 +247,37 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
230
247
|
:formtastic => {
|
231
248
|
:actions => {
|
232
249
|
:create => 'Custom Create',
|
233
|
-
:post => {
|
234
|
-
:create => 'Custom Create {{model}}'
|
235
|
-
}
|
236
250
|
}
|
237
251
|
}
|
238
252
|
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
|
239
253
|
end
|
240
254
|
|
241
255
|
after do
|
242
|
-
::I18n.backend.
|
256
|
+
::I18n.backend.reload!
|
243
257
|
end
|
244
258
|
|
245
259
|
it 'should render an input with localized label (I18n)' do
|
246
|
-
semantic_form_for(@new_post) do |builder|
|
247
|
-
concat(builder.commit_button)
|
248
|
-
end
|
249
|
-
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create Post"][@class~="create"]})
|
250
|
-
end
|
251
|
-
|
252
|
-
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
253
260
|
::I18n.backend.store_translations :en,
|
254
261
|
:formtastic => {
|
255
262
|
:actions => {
|
256
263
|
:post => {
|
257
|
-
:create =>
|
264
|
+
:create => 'Custom Create %{model}'
|
258
265
|
}
|
259
266
|
}
|
260
267
|
}
|
261
|
-
semantic_form_for(@new_post) do |builder|
|
268
|
+
form = semantic_form_for(@new_post) do |builder|
|
262
269
|
concat(builder.commit_button)
|
263
270
|
end
|
271
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
272
|
+
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create Post"][@class~="create"]})
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
276
|
+
form = semantic_form_for(@new_post) do |builder|
|
277
|
+
concat(builder.commit_button)
|
278
|
+
end
|
279
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
264
280
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create"][@class~="create"]})
|
265
|
-
::I18n.backend.store_translations :en, :formtastic => nil
|
266
|
-
|
267
281
|
end
|
268
282
|
|
269
283
|
end
|
@@ -278,9 +292,10 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
278
292
|
|
279
293
|
describe 'when explicit label is provided' do
|
280
294
|
it 'should render an input with the explicitly specified label' do
|
281
|
-
semantic_form_for(@new_post) do |builder|
|
295
|
+
form = semantic_form_for(@new_post) do |builder|
|
282
296
|
concat(builder.commit_button("Click!"))
|
283
297
|
end
|
298
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
284
299
|
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="update"]')
|
285
300
|
end
|
286
301
|
end
|
@@ -288,54 +303,59 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
288
303
|
describe 'when no explicit label is provided' do
|
289
304
|
describe 'when no I18n-localized label is provided' do
|
290
305
|
before do
|
291
|
-
::I18n.backend.store_translations :en, :formtastic => {:update => 'Save {
|
306
|
+
::I18n.backend.store_translations :en, :formtastic => {:update => 'Save %{model}'}
|
292
307
|
end
|
293
308
|
|
294
309
|
after do
|
295
|
-
::I18n.backend.
|
310
|
+
::I18n.backend.reload!
|
296
311
|
end
|
297
312
|
|
298
313
|
it 'should render an input with default I18n-localized label (fallback)' do
|
299
|
-
semantic_form_for(@new_post) do |builder|
|
314
|
+
form = semantic_form_for(@new_post) do |builder|
|
300
315
|
concat(builder.commit_button)
|
301
316
|
end
|
317
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
302
318
|
output_buffer.should have_tag('li.commit input[@value="Save Post"][@class~="update"]')
|
303
319
|
end
|
304
320
|
end
|
305
321
|
|
306
322
|
describe 'when I18n-localized label is provided' do
|
307
323
|
before do
|
324
|
+
::I18n.backend.reload!
|
308
325
|
::I18n.backend.store_translations :en,
|
309
326
|
:formtastic => {
|
310
327
|
:actions => {
|
311
328
|
:update => 'Custom Save',
|
312
|
-
:post => {
|
313
|
-
:update => 'Custom Save {{model}}'
|
314
|
-
}
|
315
329
|
}
|
316
330
|
}
|
317
331
|
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
|
318
332
|
end
|
319
333
|
|
320
|
-
|
321
|
-
|
322
|
-
concat(builder.commit_button)
|
323
|
-
end
|
324
|
-
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save Post"][@class~="update"]})
|
334
|
+
after do
|
335
|
+
::I18n.backend.reload!
|
325
336
|
end
|
326
|
-
|
327
|
-
it 'should render an input with
|
337
|
+
|
338
|
+
it 'should render an input with localized label (I18n)' do
|
328
339
|
::I18n.backend.store_translations :en,
|
329
340
|
:formtastic => {
|
330
341
|
:actions => {
|
331
342
|
:post => {
|
332
|
-
:update =>
|
343
|
+
:update => 'Custom Save %{model}'
|
333
344
|
}
|
334
345
|
}
|
335
346
|
}
|
336
|
-
semantic_form_for(@new_post) do |builder|
|
347
|
+
form = semantic_form_for(@new_post) do |builder|
|
337
348
|
concat(builder.commit_button)
|
338
349
|
end
|
350
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
351
|
+
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save Post"][@class~="update"]})
|
352
|
+
end
|
353
|
+
|
354
|
+
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
355
|
+
form = semantic_form_for(@new_post) do |builder|
|
356
|
+
concat(builder.commit_button)
|
357
|
+
end
|
358
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
339
359
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save"][@class~="update"]})
|
340
360
|
::I18n.backend.store_translations :en, :formtastic => {}
|
341
361
|
end
|
@@ -348,27 +368,31 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
348
368
|
describe 'when the model is two words' do
|
349
369
|
before do
|
350
370
|
output_buffer = ''
|
351
|
-
|
352
371
|
class ::UserPost
|
353
|
-
extend ActiveModel::Naming
|
354
|
-
|
372
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
373
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
374
|
+
|
355
375
|
def id
|
356
376
|
end
|
357
377
|
|
378
|
+
def persisted?
|
379
|
+
end
|
380
|
+
|
381
|
+
# Rails does crappy human_name
|
358
382
|
def self.human_name
|
359
|
-
"
|
383
|
+
"User post"
|
360
384
|
end
|
361
385
|
end
|
362
|
-
|
363
386
|
@new_user_post = ::UserPost.new
|
364
387
|
|
365
388
|
@new_user_post.stub!(:new_record?).and_return(true)
|
366
|
-
semantic_form_for(@new_user_post, :url => '') do |builder|
|
389
|
+
@form = semantic_form_for(@new_user_post, :url => '') do |builder|
|
367
390
|
concat(builder.commit_button())
|
368
391
|
end
|
369
392
|
end
|
370
393
|
|
371
394
|
it "should render the string as the value of the button" do
|
395
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
372
396
|
output_buffer.should have_tag('li input[@value="Create User post"]')
|
373
397
|
end
|
374
398
|
|