formtastic 1.1.0 → 1.2.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +1 -1
- data/README.textile +80 -66
- data/generators/form/form_generator.rb +37 -46
- data/generators/formtastic/formtastic_generator.rb +10 -8
- data/lib/formtastic.rb +318 -227
- data/lib/formtastic/i18n.rb +8 -6
- data/lib/formtastic/layout_helper.rb +6 -4
- data/lib/formtastic/railtie.rb +3 -1
- data/lib/formtastic/util.rb +2 -0
- data/lib/generators/formtastic/form/form_generator.rb +5 -7
- data/lib/generators/formtastic/install/install_generator.rb +2 -9
- data/lib/generators/templates/_form.html.erb +5 -0
- data/lib/generators/templates/_form.html.haml +4 -0
- data/{generators/formtastic → lib/generators}/templates/formtastic.css +25 -11
- data/{generators/formtastic → lib/generators}/templates/formtastic.rb +19 -2
- data/{generators/formtastic → lib/generators}/templates/formtastic_changes.css +0 -0
- metadata +58 -98
- data/Rakefile +0 -127
- data/generators/form/templates/view__form.html.erb +0 -5
- data/generators/form/templates/view__form.html.haml +0 -4
- data/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +0 -16
- data/init.rb +0 -5
- data/rails/init.rb +0 -2
- data/spec/buttons_spec.rb +0 -166
- data/spec/commit_button_spec.rb +0 -401
- data/spec/custom_builder_spec.rb +0 -98
- data/spec/defaults_spec.rb +0 -20
- data/spec/error_proc_spec.rb +0 -27
- data/spec/errors_spec.rb +0 -105
- data/spec/form_helper_spec.rb +0 -142
- data/spec/helpers/layout_helper_spec.rb +0 -21
- data/spec/i18n_spec.rb +0 -152
- data/spec/include_blank_spec.rb +0 -74
- data/spec/input_spec.rb +0 -786
- data/spec/inputs/boolean_input_spec.rb +0 -104
- data/spec/inputs/check_boxes_input_spec.rb +0 -426
- data/spec/inputs/country_input_spec.rb +0 -118
- data/spec/inputs/date_input_spec.rb +0 -168
- data/spec/inputs/datetime_input_spec.rb +0 -310
- data/spec/inputs/file_input_spec.rb +0 -34
- data/spec/inputs/hidden_input_spec.rb +0 -78
- data/spec/inputs/numeric_input_spec.rb +0 -44
- data/spec/inputs/password_input_spec.rb +0 -46
- data/spec/inputs/radio_input_spec.rb +0 -243
- data/spec/inputs/select_input_spec.rb +0 -546
- data/spec/inputs/string_input_spec.rb +0 -64
- data/spec/inputs/text_input_spec.rb +0 -34
- data/spec/inputs/time_input_spec.rb +0 -206
- data/spec/inputs/time_zone_input_spec.rb +0 -110
- data/spec/inputs_spec.rb +0 -476
- data/spec/label_spec.rb +0 -89
- data/spec/semantic_errors_spec.rb +0 -98
- data/spec/semantic_fields_for_spec.rb +0 -45
- data/spec/spec.opts +0 -2
- data/spec/spec_helper.rb +0 -289
- data/spec/support/custom_macros.rb +0 -494
- data/spec/support/output_buffer.rb +0 -4
- data/spec/support/test_environment.rb +0 -45
data/Rakefile
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'rubygems'
|
3
|
-
require 'rake'
|
4
|
-
require 'rake/rdoctask'
|
5
|
-
|
6
|
-
begin
|
7
|
-
gem 'rspec', '>= 1.2.6'
|
8
|
-
gem 'rspec-rails', '>= 1.2.6'
|
9
|
-
require 'spec'
|
10
|
-
require 'spec/rake/spectask'
|
11
|
-
rescue LoadError
|
12
|
-
begin
|
13
|
-
require 'rspec/core/rake_task.rb'
|
14
|
-
require 'rspec/core/version'
|
15
|
-
rescue LoadError
|
16
|
-
puts "[formtastic:] RSpec - or one of it's dependencies - is not available. Install it with: sudo gem install rspec-rails"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
begin
|
21
|
-
GEM = "formtastic"
|
22
|
-
AUTHOR = "Justin French"
|
23
|
-
EMAIL = "justin@indent.com.au"
|
24
|
-
SUMMARY = "A Rails form builder plugin/gem with semantically rich and accessible markup"
|
25
|
-
HOMEPAGE = "http://github.com/justinfrench/formtastic/tree/master"
|
26
|
-
INSTALL_MESSAGE = %q{
|
27
|
-
========================================================================
|
28
|
-
Thanks for installing Formtastic!
|
29
|
-
------------------------------------------------------------------------
|
30
|
-
You can now (optionally) run the generator to copy some stylesheets and
|
31
|
-
a config initializer into your application:
|
32
|
-
rails generator formastic:install # Rails 3
|
33
|
-
./script/generate formtastic # Rails 2
|
34
|
-
|
35
|
-
To generate some semantic form markup for your existing models, just run:
|
36
|
-
rails generate formtastic:form MODEL_NAME # Rails 3
|
37
|
-
./script/generate form MODEL_NAME # Rails 2
|
38
|
-
|
39
|
-
Find out more and get involved:
|
40
|
-
http://github.com/justinfrench/formtastic
|
41
|
-
http://groups.google.com.au/group/formtastic
|
42
|
-
========================================================================
|
43
|
-
}
|
44
|
-
|
45
|
-
gem 'jeweler', '>= 1.0.0'
|
46
|
-
require 'jeweler'
|
47
|
-
|
48
|
-
Jeweler::Tasks.new do |s|
|
49
|
-
s.name = GEM
|
50
|
-
s.summary = SUMMARY
|
51
|
-
s.email = EMAIL
|
52
|
-
s.homepage = HOMEPAGE
|
53
|
-
s.description = SUMMARY
|
54
|
-
s.author = AUTHOR
|
55
|
-
s.post_install_message = INSTALL_MESSAGE
|
56
|
-
|
57
|
-
s.require_path = 'lib'
|
58
|
-
s.files = %w(MIT-LICENSE README.textile Rakefile init.rb) + Dir.glob("{rails,lib,generators,spec}/**/*")
|
59
|
-
|
60
|
-
# Runtime dependencies: When installing Formtastic these will be checked if they are installed.
|
61
|
-
# Will be offered to install these if they are not already installed.
|
62
|
-
s.add_dependency 'activesupport', '>= 2.3.0'
|
63
|
-
s.add_dependency 'actionpack', '>= 2.3.0'
|
64
|
-
s.add_dependency 'i18n', '>= 0.4.0'
|
65
|
-
|
66
|
-
# Development dependencies. Not installed by default.
|
67
|
-
# Install with: sudo gem install formtastic --development
|
68
|
-
s.add_development_dependency 'rspec-rails', '>= 1.2.6'
|
69
|
-
s.add_development_dependency 'rspec_tag_matchers', '>= 1.0.0'
|
70
|
-
end
|
71
|
-
|
72
|
-
Jeweler::GemcutterTasks.new
|
73
|
-
rescue LoadError
|
74
|
-
puts "[formtastic:] Jeweler - or one of its dependencies - is not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
|
75
|
-
end
|
76
|
-
|
77
|
-
desc 'Default: run unit specs.'
|
78
|
-
task :default => :spec
|
79
|
-
|
80
|
-
desc 'Generate documentation for the formtastic plugin.'
|
81
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
82
|
-
rdoc.rdoc_dir = 'rdoc'
|
83
|
-
rdoc.title = 'Formtastic'
|
84
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
85
|
-
rdoc.rdoc_files.include('README.textile')
|
86
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
87
|
-
end
|
88
|
-
|
89
|
-
if defined?(Spec)
|
90
|
-
desc 'Test the formtastic plugin.'
|
91
|
-
Spec::Rake::SpecTask.new('spec') do |t|
|
92
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
93
|
-
t.spec_opts = ["-c"]
|
94
|
-
end
|
95
|
-
|
96
|
-
desc 'Test the formtastic plugin with specdoc formatting and colors'
|
97
|
-
Spec::Rake::SpecTask.new('specdoc') do |t|
|
98
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
99
|
-
t.spec_opts = ["--format specdoc", "-c"]
|
100
|
-
end
|
101
|
-
|
102
|
-
desc "Run all examples with RCov"
|
103
|
-
Spec::Rake::SpecTask.new('examples_with_rcov') do |t|
|
104
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
105
|
-
t.rcov = true
|
106
|
-
t.rcov_opts = ['--exclude', 'spec,Library']
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
if defined?(RSpec)
|
111
|
-
desc 'Test the formtastic plugin.'
|
112
|
-
RSpec::Core::RakeTask.new('spec') do |t|
|
113
|
-
t.pattern = FileList['spec/**/*_spec.rb']
|
114
|
-
end
|
115
|
-
|
116
|
-
desc 'Test the formtastic plugin with specdoc formatting and colors'
|
117
|
-
RSpec::Core::RakeTask.new('specdoc') do |t|
|
118
|
-
t.pattern = FileList['spec/**/*_spec.rb']
|
119
|
-
end
|
120
|
-
|
121
|
-
desc "Run all examples with RCov"
|
122
|
-
RSpec::Core::RakeTask.new('examples_with_rcov') do |t|
|
123
|
-
t.pattern = FileList['spec/**/*_spec.rb']
|
124
|
-
t.rcov = true
|
125
|
-
t.rcov_opts = ['--exclude', 'spec,Library']
|
126
|
-
end
|
127
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class FormtasticStylesheetsGenerator < Rails::Generator::Base
|
2
|
-
|
3
|
-
def initialize(*runtime_args)
|
4
|
-
puts %q{
|
5
|
-
===================================================
|
6
|
-
Please run `./script/generate formtastic` instead.
|
7
|
-
===================================================
|
8
|
-
}
|
9
|
-
end
|
10
|
-
|
11
|
-
def manifest
|
12
|
-
record do |m|
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
data/init.rb
DELETED
data/rails/init.rb
DELETED
data/spec/buttons_spec.rb
DELETED
@@ -1,166 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe 'SemanticFormBuilder#buttons' 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
|
-
@form = semantic_form_for(@new_post) do |builder|
|
17
|
-
buttons = builder.buttons do
|
18
|
-
concat('hello')
|
19
|
-
end
|
20
|
-
concat(buttons)
|
21
|
-
end
|
22
|
-
end
|
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?
|
26
|
-
output_buffer.should have_tag("form fieldset.buttons")
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should render an ol inside the fieldset' do
|
30
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
31
|
-
output_buffer.should have_tag("form fieldset.buttons ol")
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should render the contents of the block inside the ol' do
|
35
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
36
|
-
output_buffer.should have_tag("form fieldset.buttons ol", /hello/)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should not render a legend inside the fieldset' do
|
40
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
41
|
-
output_buffer.should_not have_tag("form fieldset.buttons legend")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe 'when a :name option is provided' do
|
46
|
-
before do
|
47
|
-
@legend_text = "Advanced options"
|
48
|
-
|
49
|
-
@form = semantic_form_for(@new_post) do |builder|
|
50
|
-
builder.buttons :name => @legend_text do
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
it 'should render a fieldset inside the form' do
|
55
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
56
|
-
output_buffer.should have_tag("form fieldset legend", /#{@legend_text}/)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe 'when other options are provided' do
|
61
|
-
before do
|
62
|
-
@id_option = 'advanced'
|
63
|
-
@class_option = 'wide'
|
64
|
-
|
65
|
-
@form = semantic_form_for(@new_post) do |builder|
|
66
|
-
builder.buttons :id => @id_option, :class => @class_option do
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
it 'should pass the options into the fieldset tag as attributes' do
|
71
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
72
|
-
output_buffer.should have_tag("form fieldset##{@id_option}")
|
73
|
-
output_buffer.should have_tag("form fieldset.#{@class_option}")
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
describe 'without a block' do
|
80
|
-
|
81
|
-
describe 'with no args (default buttons)' do
|
82
|
-
|
83
|
-
before do
|
84
|
-
@form = semantic_form_for(@new_post) do |builder|
|
85
|
-
concat(builder.buttons)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should render a form' do
|
90
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
91
|
-
output_buffer.should have_tag('form')
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should render a buttons fieldset inside the form' do
|
95
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
96
|
-
output_buffer.should have_tag('form fieldset.buttons')
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'should not render a legend in the fieldset' do
|
100
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
101
|
-
output_buffer.should_not have_tag('form fieldset.buttons legend')
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'should render an ol in the fieldset' do
|
105
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
106
|
-
output_buffer.should have_tag('form fieldset.buttons ol')
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should render a list item in the ol for each default button' do
|
110
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
111
|
-
output_buffer.should have_tag('form fieldset.buttons ol li', :count => 1)
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'should render a commit list item for the commit button' do
|
115
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
116
|
-
output_buffer.should have_tag('form fieldset.buttons ol li.commit')
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
describe 'with button names as args' do
|
122
|
-
|
123
|
-
before do
|
124
|
-
@form = semantic_form_for(@new_post) do |builder|
|
125
|
-
concat(builder.buttons(:commit))
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
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?
|
131
|
-
output_buffer.should have_tag('form > fieldset.buttons > ol > li', :count => 1)
|
132
|
-
output_buffer.should have_tag('form > fieldset.buttons > ol > li.commit')
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
|
-
describe 'with button names as args and an options hash' do
|
138
|
-
|
139
|
-
before do
|
140
|
-
@form = semantic_form_for(@new_post) do |builder|
|
141
|
-
concat(builder.buttons(:commit, :name => "Now click a button", :id => "my-id"))
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
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?
|
147
|
-
output_buffer.should have_tag('form > fieldset.buttons > ol > li', :count => 1)
|
148
|
-
output_buffer.should have_tag('form > fieldset.buttons > ol > li.commit', :count => 1)
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'should pass the options down to the fieldset' do
|
152
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
153
|
-
output_buffer.should have_tag('form > fieldset#my-id.buttons')
|
154
|
-
end
|
155
|
-
|
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?
|
158
|
-
output_buffer.should have_tag('form > fieldset#my-id.buttons > legend', /Now click a button/)
|
159
|
-
end
|
160
|
-
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
166
|
-
|
data/spec/commit_button_spec.rb
DELETED
@@ -1,401 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe 'SemanticFormBuilder#commit_button' do
|
5
|
-
|
6
|
-
include FormtasticSpecHelper
|
7
|
-
|
8
|
-
before do
|
9
|
-
@output_buffer = ''
|
10
|
-
mock_everything
|
11
|
-
end
|
12
|
-
|
13
|
-
describe 'when used on any record' do
|
14
|
-
|
15
|
-
before do
|
16
|
-
@new_post.stub!(:new_record?).and_return(false)
|
17
|
-
@form = semantic_form_for(@new_post) do |builder|
|
18
|
-
concat(builder.commit_button)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should render a commit li' do
|
23
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
24
|
-
output_buffer.should have_tag('li.commit')
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should render an input with a type attribute of "submit"' do
|
28
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
29
|
-
output_buffer.should have_tag('li.commit input[@type="submit"]')
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should render an input with a name attribute of "commit"' do
|
33
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
34
|
-
output_buffer.should have_tag('li.commit input[@name="commit"]')
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should pass options given in :button_html to the button' do
|
38
|
-
@new_post.stub!(:new_record?).and_return(false)
|
39
|
-
form = semantic_form_for(@new_post) do |builder|
|
40
|
-
concat(builder.commit_button('text', :button_html => {:class => 'my_class', :id => 'my_id'}))
|
41
|
-
end
|
42
|
-
|
43
|
-
output_buffer.concat(form) if Formtastic::Util.rails3?
|
44
|
-
output_buffer.should have_tag('li.commit input#my_id')
|
45
|
-
output_buffer.should have_tag('li.commit input.my_class')
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "its accesskey" do
|
51
|
-
|
52
|
-
it 'should allow nil default' do
|
53
|
-
with_config :default_commit_button_accesskey, nil do
|
54
|
-
output_buffer.should_not have_tag('li.commit input[@accesskey]')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should use the default if set' do
|
59
|
-
with_config :default_commit_button_accesskey, 's' do
|
60
|
-
@new_post.stub!(:new_record?).and_return(false)
|
61
|
-
form = semantic_form_for(@new_post) do |builder|
|
62
|
-
concat(builder.commit_button('text', :button_html => {}))
|
63
|
-
end
|
64
|
-
output_buffer.concat(form) if Formtastic::Util.rails3?
|
65
|
-
output_buffer.should have_tag('li.commit input[@accesskey="s"]')
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'should use the value set in options over the default' do
|
70
|
-
with_config :default_commit_button_accesskey, 's' do
|
71
|
-
@new_post.stub!(:new_record?).and_return(false)
|
72
|
-
form = semantic_form_for(@new_post) do |builder|
|
73
|
-
concat(builder.commit_button('text', :accesskey => 'o'))
|
74
|
-
end
|
75
|
-
output_buffer.concat(form) if Formtastic::Util.rails3?
|
76
|
-
output_buffer.should_not have_tag('li.commit input[@accesskey="s"]')
|
77
|
-
output_buffer.should have_tag('li.commit input[@accesskey="o"]')
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'should use the value set in button_html over options' do
|
82
|
-
with_config :default_commit_button_accesskey, 's' do
|
83
|
-
@new_post.stub!(:new_record?).and_return(false)
|
84
|
-
form = semantic_form_for(@new_post) do |builder|
|
85
|
-
concat(builder.commit_button('text', :accesskey => 'o', :button_html => {:accesskey => 't'}))
|
86
|
-
end
|
87
|
-
output_buffer.concat(form) if Formtastic::Util.rails3?
|
88
|
-
output_buffer.should_not have_tag('li.commit input[@accesskey="s"]')
|
89
|
-
output_buffer.should_not have_tag('li.commit input[@accesskey="o"]')
|
90
|
-
output_buffer.should have_tag('li.commit input[@accesskey="t"]')
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
describe 'when the first option is a string and the second is a hash' do
|
97
|
-
|
98
|
-
before do
|
99
|
-
@new_post.stub!(:new_record?).and_return(false)
|
100
|
-
@form = semantic_form_for(@new_post) do |builder|
|
101
|
-
concat(builder.commit_button("a string", :button_html => { :class => "pretty"}))
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should render the string as the value of the button" do
|
106
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
107
|
-
output_buffer.should have_tag('li input[@value="a string"]')
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should deal with the options hash" do
|
111
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
112
|
-
output_buffer.should have_tag('li input.pretty')
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
describe 'when the first option is a hash' do
|
118
|
-
|
119
|
-
before do
|
120
|
-
@new_post.stub!(:new_record?).and_return(false)
|
121
|
-
@form = semantic_form_for(@new_post) do |builder|
|
122
|
-
concat(builder.commit_button(:button_html => { :class => "pretty"}))
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should deal with the options hash" do
|
127
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
128
|
-
output_buffer.should have_tag('li input.pretty')
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
describe 'label' do
|
134
|
-
|
135
|
-
# No object
|
136
|
-
describe 'when used without object' do
|
137
|
-
describe 'when explicit label is provided' do
|
138
|
-
it 'should render an input with the explicitly specified label' do
|
139
|
-
form = semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
140
|
-
concat(builder.commit_button("Click!"))
|
141
|
-
end
|
142
|
-
output_buffer.concat(form) if Formtastic::Util.rails3?
|
143
|
-
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="submit"]')
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe 'when no explicit label is provided' do
|
148
|
-
describe 'when no I18n-localized label is provided' do
|
149
|
-
before do
|
150
|
-
::I18n.backend.store_translations :en, :formtastic => {:submit => 'Submit %{model}'}
|
151
|
-
end
|
152
|
-
|
153
|
-
after do
|
154
|
-
::I18n.backend.reload!
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'should render an input with default I18n-localized label (fallback)' do
|
158
|
-
form = semantic_form_for(:post, :url => 'http://example.com') do |builder|
|
159
|
-
concat(builder.commit_button)
|
160
|
-
end
|
161
|
-
output_buffer.concat(form) if Formtastic::Util.rails3?
|
162
|
-
output_buffer.should have_tag('li.commit input[@value="Submit Post"][@class~="submit"]')
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
describe 'when I18n-localized label is provided' do
|
167
|
-
before do
|
168
|
-
::I18n.backend.store_translations :en,
|
169
|
-
:formtastic => {
|
170
|
-
:actions => {
|
171
|
-
:submit => 'Custom Submit',
|
172
|
-
}
|
173
|
-
}
|
174
|
-
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
|
175
|
-
end
|
176
|
-
|
177
|
-
after do
|
178
|
-
::I18n.backend.reload!
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'should render an input with localized label (I18n)' do
|
182
|
-
::I18n.backend.store_translations :en,
|
183
|
-
:formtastic => {
|
184
|
-
:actions => {
|
185
|
-
:post => {
|
186
|
-
:submit => 'Custom Submit %{model}'
|
187
|
-
}
|
188
|
-
}
|
189
|
-
}
|
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|
|
199
|
-
concat(builder.commit_button)
|
200
|
-
end
|
201
|
-
output_buffer.concat(form) if Formtastic::Util.rails3?
|
202
|
-
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit"][@class~="submit"]})
|
203
|
-
end
|
204
|
-
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
# New record
|
210
|
-
describe 'when used on a new record' do
|
211
|
-
before do
|
212
|
-
@new_post.stub!(:new_record?).and_return(true)
|
213
|
-
end
|
214
|
-
|
215
|
-
describe 'when explicit label is provided' do
|
216
|
-
it 'should render an input with the explicitly specified label' do
|
217
|
-
form = semantic_form_for(@new_post) do |builder|
|
218
|
-
concat(builder.commit_button("Click!"))
|
219
|
-
end
|
220
|
-
output_buffer.concat(form) if Formtastic::Util.rails3?
|
221
|
-
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="create"]')
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
describe 'when no explicit label is provided' do
|
226
|
-
describe 'when no I18n-localized label is provided' do
|
227
|
-
before do
|
228
|
-
::I18n.backend.store_translations :en, :formtastic => {:create => 'Create %{model}'}
|
229
|
-
end
|
230
|
-
|
231
|
-
after do
|
232
|
-
::I18n.backend.reload!
|
233
|
-
end
|
234
|
-
|
235
|
-
it 'should render an input with default I18n-localized label (fallback)' do
|
236
|
-
form = semantic_form_for(@new_post) do |builder|
|
237
|
-
concat(builder.commit_button)
|
238
|
-
end
|
239
|
-
output_buffer.concat(form) if Formtastic::Util.rails3?
|
240
|
-
output_buffer.should have_tag('li.commit input[@value="Create Post"][@class~="create"]')
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
describe 'when I18n-localized label is provided' do
|
245
|
-
before do
|
246
|
-
::I18n.backend.store_translations :en,
|
247
|
-
:formtastic => {
|
248
|
-
:actions => {
|
249
|
-
:create => 'Custom Create',
|
250
|
-
}
|
251
|
-
}
|
252
|
-
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
|
253
|
-
end
|
254
|
-
|
255
|
-
after do
|
256
|
-
::I18n.backend.reload!
|
257
|
-
end
|
258
|
-
|
259
|
-
it 'should render an input with localized label (I18n)' do
|
260
|
-
::I18n.backend.store_translations :en,
|
261
|
-
:formtastic => {
|
262
|
-
:actions => {
|
263
|
-
:post => {
|
264
|
-
:create => 'Custom Create %{model}'
|
265
|
-
}
|
266
|
-
}
|
267
|
-
}
|
268
|
-
form = semantic_form_for(@new_post) do |builder|
|
269
|
-
concat(builder.commit_button)
|
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?
|
280
|
-
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create"][@class~="create"]})
|
281
|
-
end
|
282
|
-
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
# Existing record
|
288
|
-
describe 'when used on an existing record' do
|
289
|
-
before do
|
290
|
-
@new_post.stub!(:new_record?).and_return(false)
|
291
|
-
end
|
292
|
-
|
293
|
-
describe 'when explicit label is provided' do
|
294
|
-
it 'should render an input with the explicitly specified label' do
|
295
|
-
form = semantic_form_for(@new_post) do |builder|
|
296
|
-
concat(builder.commit_button("Click!"))
|
297
|
-
end
|
298
|
-
output_buffer.concat(form) if Formtastic::Util.rails3?
|
299
|
-
output_buffer.should have_tag('li.commit input[@value="Click!"][@class~="update"]')
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
describe 'when no explicit label is provided' do
|
304
|
-
describe 'when no I18n-localized label is provided' do
|
305
|
-
before do
|
306
|
-
::I18n.backend.store_translations :en, :formtastic => {:update => 'Save %{model}'}
|
307
|
-
end
|
308
|
-
|
309
|
-
after do
|
310
|
-
::I18n.backend.reload!
|
311
|
-
end
|
312
|
-
|
313
|
-
it 'should render an input with default I18n-localized label (fallback)' do
|
314
|
-
form = semantic_form_for(@new_post) do |builder|
|
315
|
-
concat(builder.commit_button)
|
316
|
-
end
|
317
|
-
output_buffer.concat(form) if Formtastic::Util.rails3?
|
318
|
-
output_buffer.should have_tag('li.commit input[@value="Save Post"][@class~="update"]')
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
describe 'when I18n-localized label is provided' do
|
323
|
-
before do
|
324
|
-
::I18n.backend.reload!
|
325
|
-
::I18n.backend.store_translations :en,
|
326
|
-
:formtastic => {
|
327
|
-
:actions => {
|
328
|
-
:update => 'Custom Save',
|
329
|
-
}
|
330
|
-
}
|
331
|
-
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
|
332
|
-
end
|
333
|
-
|
334
|
-
after do
|
335
|
-
::I18n.backend.reload!
|
336
|
-
end
|
337
|
-
|
338
|
-
it 'should render an input with localized label (I18n)' do
|
339
|
-
::I18n.backend.store_translations :en,
|
340
|
-
:formtastic => {
|
341
|
-
:actions => {
|
342
|
-
:post => {
|
343
|
-
:update => 'Custom Save %{model}'
|
344
|
-
}
|
345
|
-
}
|
346
|
-
}
|
347
|
-
form = semantic_form_for(@new_post) do |builder|
|
348
|
-
concat(builder.commit_button)
|
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?
|
359
|
-
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save"][@class~="update"]})
|
360
|
-
::I18n.backend.store_translations :en, :formtastic => {}
|
361
|
-
end
|
362
|
-
|
363
|
-
end
|
364
|
-
end
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
describe 'when the model is two words' do
|
369
|
-
before do
|
370
|
-
output_buffer = ''
|
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
|
386
|
-
@new_user_post = ::UserPost.new
|
387
|
-
|
388
|
-
@new_user_post.stub!(:new_record?).and_return(true)
|
389
|
-
@form = semantic_form_for(@new_user_post, :url => '') do |builder|
|
390
|
-
concat(builder.commit_button())
|
391
|
-
end
|
392
|
-
end
|
393
|
-
|
394
|
-
it "should render the string as the value of the button" do
|
395
|
-
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
396
|
-
output_buffer.should have_tag('li input[@value="Create User post"]')
|
397
|
-
end
|
398
|
-
|
399
|
-
end
|
400
|
-
|
401
|
-
end
|