formtastic 1.0.1 → 1.1.0.beta
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.
- data/README.textile +2 -2
- data/Rakefile +33 -8
- data/generators/formtastic/templates/formtastic.css +3 -18
- data/init.rb +5 -0
- data/lib/formtastic.rb +180 -82
- data/lib/formtastic/i18n.rb +8 -9
- data/lib/formtastic/layout_helper.rb +0 -1
- data/lib/formtastic/railtie.rb +12 -0
- data/lib/formtastic/util.rb +7 -0
- data/lib/generators/formtastic/form/form_generator.rb +86 -0
- data/lib/generators/formtastic/install/install_generator.rb +24 -0
- data/rails/init.rb +1 -6
- data/spec/buttons_spec.rb +25 -8
- data/spec/commit_button_spec.rb +67 -29
- data/spec/custom_builder_spec.rb +40 -4
- data/spec/defaults_spec.rb +1 -1
- data/spec/error_proc_spec.rb +1 -1
- data/spec/errors_spec.rb +3 -2
- data/spec/form_helper_spec.rb +33 -17
- data/spec/helpers/layout_helper_spec.rb +21 -0
- data/spec/i18n_spec.rb +13 -9
- data/spec/include_blank_spec.rb +9 -5
- data/spec/input_spec.rb +188 -48
- data/spec/inputs/boolean_input_spec.rb +14 -7
- data/spec/inputs/check_boxes_input_spec.rb +150 -20
- data/spec/inputs/country_input_spec.rb +9 -5
- data/spec/inputs/date_input_spec.rb +21 -9
- data/spec/inputs/datetime_input_spec.rb +33 -14
- data/spec/inputs/file_input_spec.rb +4 -3
- data/spec/inputs/hidden_input_spec.rb +11 -4
- 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 +29 -10
- data/spec/inputs/select_input_spec.rb +66 -26
- data/spec/inputs/string_input_spec.rb +5 -4
- data/spec/inputs/text_input_spec.rb +4 -3
- data/spec/inputs/time_input_spec.rb +26 -10
- data/spec/inputs/time_zone_input_spec.rb +11 -5
- data/spec/inputs_spec.rb +103 -39
- data/spec/label_spec.rb +5 -3
- data/spec/semantic_errors_spec.rb +7 -7
- data/spec/semantic_fields_for_spec.rb +5 -4
- data/spec/spec_helper.rb +86 -38
- data/spec/{custom_macros.rb → support/custom_macros.rb} +69 -35
- data/spec/support/output_buffer.rb +4 -0
- data/spec/support/test_environment.rb +45 -0
- metadata +26 -28
- data/spec/layout_helper_spec.rb +0 -29
data/lib/formtastic/i18n.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
module Formtastic
|
3
2
|
module I18n
|
4
3
|
|
@@ -7,16 +6,16 @@ module Formtastic
|
|
7
6
|
:required => 'required',
|
8
7
|
:yes => 'Yes',
|
9
8
|
:no => 'No',
|
10
|
-
:create => 'Create {
|
11
|
-
:update => 'Update {
|
9
|
+
:create => 'Create %{model}',
|
10
|
+
:update => 'Update %{model}'
|
12
11
|
}.freeze
|
13
12
|
SCOPES = [
|
14
|
-
'{
|
15
|
-
'{
|
16
|
-
'{
|
17
|
-
'{
|
18
|
-
'{
|
19
|
-
'{
|
13
|
+
'%{model}.%{nested_model}.%{action}.%{attribute}',
|
14
|
+
'%{model}.%{action}.%{attribute}',
|
15
|
+
'%{model}.%{nested_model}.%{attribute}',
|
16
|
+
'%{model}.%{attribute}',
|
17
|
+
'%{nested_model}.%{attribute}',
|
18
|
+
'%{attribute}'
|
20
19
|
]
|
21
20
|
|
22
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 'formtastic.initialize', :after => :after_initialize do
|
8
|
+
ActionView::Base.send :include, Formtastic::SemanticFormHelper
|
9
|
+
ActionView::Base.send(:include, Formtastic::LayoutHelper)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/formtastic/util.rb
CHANGED
@@ -0,0 +1,86 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Formtastic
|
3
|
+
class FormGenerator < Rails::Generators::NamedBase
|
4
|
+
desc "Generates formtastic form code based on an existing model. By default the " <<
|
5
|
+
"generated code will be printed out directly in the terminal, and also copied " <<
|
6
|
+
"to clipboard. Can optionally be saved into partial directly."
|
7
|
+
|
8
|
+
argument :name, :type => :string, :required => true, :banner => 'ExistingModelName'
|
9
|
+
argument :attributes, :type => :array, :default => [], :banner => 'field:type field:type'
|
10
|
+
|
11
|
+
class_option :haml, :type => :boolean, :default => false, :group => :formtastic,
|
12
|
+
:desc => "Generate HAML instead of ERB"
|
13
|
+
|
14
|
+
class_option :partial, :type => :boolean, :default => false, :group => :formtastic,
|
15
|
+
:desc => 'Generate a form partial in the model views path, i.e. "_form.html.erb" or "_form.html.haml"'
|
16
|
+
|
17
|
+
class_option :controller, :type => :string, :default => false, :group => :formtastic,
|
18
|
+
:desc => 'Generate for custom controller/view path - in case model and controller namespace is different, i.e. "admin/posts"'
|
19
|
+
|
20
|
+
def self.source_root
|
21
|
+
# Set source directory for the templates to the rails2 generator template directory
|
22
|
+
@source_root ||= File.expand_path(File.join('..', '..', '..', '..', 'generators', 'form', 'templates'), File.dirname(__FILE__))
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_or_show
|
26
|
+
@attributes = self.columns if @attributes.empty?
|
27
|
+
if options[:partial]
|
28
|
+
empty_directory "app/views/#{controller_path}"
|
29
|
+
template "view__form.html.#{template_type}", "app/views/#{controller_path}/_form.html.#{template_type}"
|
30
|
+
else
|
31
|
+
template = File.read("#{self.class.source_root}/view__form.html.#{template_type}")
|
32
|
+
erb = ERB.new(template, nil, '-')
|
33
|
+
generated_code = erb.result(binding).strip rescue nil
|
34
|
+
|
35
|
+
puts "# ---------------------------------------------------------"
|
36
|
+
puts "# GENERATED FORMTASTIC CODE"
|
37
|
+
puts "# ---------------------------------------------------------"
|
38
|
+
puts
|
39
|
+
puts generated_code || "Nothing could be generated - model exists?"
|
40
|
+
puts
|
41
|
+
puts "# ---------------------------------------------------------"
|
42
|
+
puts "Copied to clipboard - just paste it!" if save_to_clipboard(generated_code)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
IGNORED_COLUMNS = [:updated_at, :created_at].freeze
|
49
|
+
|
50
|
+
def template_type
|
51
|
+
@template_type ||= options[:haml] ? :haml : :erb
|
52
|
+
end
|
53
|
+
|
54
|
+
def controller_path
|
55
|
+
@controller_path ||= if options[:controller]
|
56
|
+
options[:controller].underscore
|
57
|
+
else
|
58
|
+
name.underscore.pluralize
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def columns
|
63
|
+
@columns ||= self.name.camelize.constantize.content_columns.reject { |column| IGNORED_COLUMNS.include?(column.name.to_sym) }
|
64
|
+
end
|
65
|
+
|
66
|
+
def save_to_clipboard(data)
|
67
|
+
return unless data
|
68
|
+
|
69
|
+
begin
|
70
|
+
case RUBY_PLATFORM
|
71
|
+
when /win32/
|
72
|
+
require 'win32/clipboard'
|
73
|
+
::Win32::Clipboard.data = data
|
74
|
+
when /darwin/ # mac
|
75
|
+
`echo "#{data}" | pbcopy`
|
76
|
+
else # linux/unix
|
77
|
+
`echo "#{data}" | xsel --clipboard` || `echo "#{data}" | xclip`
|
78
|
+
end
|
79
|
+
rescue LoadError
|
80
|
+
false
|
81
|
+
else
|
82
|
+
true
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Formtastic
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
desc "Copies formtastic.css and formtastic_changes.css to public/stylesheets/ and a config initializer to config/initializers/formtastic_config.rb"
|
5
|
+
|
6
|
+
def self.source_root
|
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__))
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.banner
|
12
|
+
"rails generate formtastic:install [options]"
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy_files
|
16
|
+
empty_directory 'config/initializers'
|
17
|
+
template 'formtastic.rb', 'config/initializers/formtastic.rb'
|
18
|
+
|
19
|
+
empty_directory 'public/stylesheets'
|
20
|
+
template 'formtastic.css', 'public/stylesheets/formtastic.css'
|
21
|
+
template 'formtastic_changes.css', 'public/stylesheets/formtastic_changes.css'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/rails/init.rb
CHANGED
@@ -1,7 +1,2 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require
|
3
|
-
require 'formtastic/layout_helper'
|
4
|
-
|
5
|
-
ActionView::Base.send :include, Formtastic::SemanticFormHelper
|
6
|
-
ActionView::Base.send :include, Formtastic::LayoutHelper
|
7
|
-
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "init"))
|
data/spec/buttons_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe 'SemanticFormBuilder#buttons' do
|
5
5
|
|
@@ -13,26 +13,31 @@ describe 'SemanticFormBuilder#buttons' do
|
|
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
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe 'SemanticFormBuilder#commit_button' do
|
5
5
|
|
@@ -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,7 +147,7 @@ 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
|
@@ -144,9 +155,10 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
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
|
@@ -171,20 +183,22 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
171
183
|
:formtastic => {
|
172
184
|
:actions => {
|
173
185
|
:post => {
|
174
|
-
:submit => 'Custom Submit {
|
186
|
+
:submit => 'Custom Submit %{model}'
|
175
187
|
}
|
176
188
|
}
|
177
189
|
}
|
178
|
-
semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
190
|
+
form = semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
179
191
|
concat(builder.commit_button)
|
180
192
|
end
|
193
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
181
194
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit Post"][@class~="submit"]})
|
182
195
|
end
|
183
196
|
|
184
197
|
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
185
|
-
semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
198
|
+
form = semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
186
199
|
concat(builder.commit_button)
|
187
200
|
end
|
201
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
188
202
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit"][@class~="submit"]})
|
189
203
|
end
|
190
204
|
|
@@ -200,9 +214,10 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
200
214
|
|
201
215
|
describe 'when explicit label is provided' do
|
202
216
|
it 'should render an input with the explicitly specified label' do
|
203
|
-
semantic_form_for(@new_post) do |builder|
|
217
|
+
form = semantic_form_for(@new_post) do |builder|
|
204
218
|
concat(builder.commit_button("Click!"))
|
205
219
|
end
|
220
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
206
221
|
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="create"]')
|
207
222
|
end
|
208
223
|
end
|
@@ -210,7 +225,7 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
210
225
|
describe 'when no explicit label is provided' do
|
211
226
|
describe 'when no I18n-localized label is provided' do
|
212
227
|
before do
|
213
|
-
::I18n.backend.store_translations :en, :formtastic => {:create => 'Create {
|
228
|
+
::I18n.backend.store_translations :en, :formtastic => {:create => 'Create %{model}'}
|
214
229
|
end
|
215
230
|
|
216
231
|
after do
|
@@ -218,9 +233,10 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
218
233
|
end
|
219
234
|
|
220
235
|
it 'should render an input with default I18n-localized label (fallback)' do
|
221
|
-
semantic_form_for(@new_post) do |builder|
|
236
|
+
form = semantic_form_for(@new_post) do |builder|
|
222
237
|
concat(builder.commit_button)
|
223
238
|
end
|
239
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
224
240
|
output_buffer.should have_tag('li.commit input[@value="Create Post"][@class~="create"]')
|
225
241
|
end
|
226
242
|
end
|
@@ -245,21 +261,23 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
245
261
|
:formtastic => {
|
246
262
|
:actions => {
|
247
263
|
:post => {
|
248
|
-
:create => 'Custom Create {
|
264
|
+
:create => 'Custom Create %{model}'
|
249
265
|
}
|
250
266
|
}
|
251
267
|
}
|
252
|
-
semantic_form_for(@new_post) do |builder|
|
268
|
+
form = semantic_form_for(@new_post) do |builder|
|
253
269
|
concat(builder.commit_button)
|
254
270
|
end
|
271
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
255
272
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create Post"][@class~="create"]})
|
256
273
|
end
|
257
274
|
|
258
275
|
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
259
|
-
semantic_form_for(@new_post) do |builder|
|
276
|
+
form = semantic_form_for(@new_post) do |builder|
|
260
277
|
concat(builder.commit_button)
|
261
278
|
end
|
262
|
-
output_buffer.
|
279
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
280
|
+
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create"][@class~="create"]})
|
263
281
|
end
|
264
282
|
|
265
283
|
end
|
@@ -274,9 +292,10 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
274
292
|
|
275
293
|
describe 'when explicit label is provided' do
|
276
294
|
it 'should render an input with the explicitly specified label' do
|
277
|
-
semantic_form_for(@new_post) do |builder|
|
295
|
+
form = semantic_form_for(@new_post) do |builder|
|
278
296
|
concat(builder.commit_button("Click!"))
|
279
297
|
end
|
298
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
280
299
|
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="update"]')
|
281
300
|
end
|
282
301
|
end
|
@@ -284,7 +303,7 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
284
303
|
describe 'when no explicit label is provided' do
|
285
304
|
describe 'when no I18n-localized label is provided' do
|
286
305
|
before do
|
287
|
-
::I18n.backend.store_translations :en, :formtastic => {:update => 'Save {
|
306
|
+
::I18n.backend.store_translations :en, :formtastic => {:update => 'Save %{model}'}
|
288
307
|
end
|
289
308
|
|
290
309
|
after do
|
@@ -292,15 +311,17 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
292
311
|
end
|
293
312
|
|
294
313
|
it 'should render an input with default I18n-localized label (fallback)' do
|
295
|
-
semantic_form_for(@new_post) do |builder|
|
314
|
+
form = semantic_form_for(@new_post) do |builder|
|
296
315
|
concat(builder.commit_button)
|
297
316
|
end
|
317
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
298
318
|
output_buffer.should have_tag('li.commit input[@value="Save Post"][@class~="update"]')
|
299
319
|
end
|
300
320
|
end
|
301
321
|
|
302
322
|
describe 'when I18n-localized label is provided' do
|
303
323
|
before do
|
324
|
+
::I18n.backend.reload!
|
304
325
|
::I18n.backend.store_translations :en,
|
305
326
|
:formtastic => {
|
306
327
|
:actions => {
|
@@ -319,20 +340,22 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
319
340
|
:formtastic => {
|
320
341
|
:actions => {
|
321
342
|
:post => {
|
322
|
-
:update => 'Custom Save {
|
343
|
+
:update => 'Custom Save %{model}'
|
323
344
|
}
|
324
345
|
}
|
325
346
|
}
|
326
|
-
semantic_form_for(@new_post) do |builder|
|
347
|
+
form = semantic_form_for(@new_post) do |builder|
|
327
348
|
concat(builder.commit_button)
|
328
349
|
end
|
350
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
329
351
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save Post"][@class~="update"]})
|
330
352
|
end
|
331
353
|
|
332
354
|
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
|
333
|
-
semantic_form_for(@new_post) do |builder|
|
355
|
+
form = semantic_form_for(@new_post) do |builder|
|
334
356
|
concat(builder.commit_button)
|
335
357
|
end
|
358
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
336
359
|
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save"][@class~="update"]})
|
337
360
|
::I18n.backend.store_translations :en, :formtastic => {}
|
338
361
|
end
|
@@ -345,16 +368,31 @@ describe 'SemanticFormBuilder#commit_button' do
|
|
345
368
|
describe 'when the model is two words' do
|
346
369
|
before do
|
347
370
|
output_buffer = ''
|
348
|
-
class ::UserPost
|
371
|
+
class ::UserPost
|
372
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
373
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
374
|
+
|
375
|
+
def id
|
376
|
+
end
|
377
|
+
|
378
|
+
def persisted?
|
379
|
+
end
|
380
|
+
|
381
|
+
# Rails does crappy human_name
|
382
|
+
def self.human_name
|
383
|
+
"User post"
|
384
|
+
end
|
385
|
+
end
|
349
386
|
@new_user_post = ::UserPost.new
|
350
387
|
|
351
388
|
@new_user_post.stub!(:new_record?).and_return(true)
|
352
|
-
semantic_form_for(@new_user_post, :url => '') do |builder|
|
389
|
+
@form = semantic_form_for(@new_user_post, :url => '') do |builder|
|
353
390
|
concat(builder.commit_button())
|
354
391
|
end
|
355
392
|
end
|
356
393
|
|
357
394
|
it "should render the string as the value of the button" do
|
395
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
358
396
|
output_buffer.should have_tag('li input[@value="Create User post"]')
|
359
397
|
end
|
360
398
|
|