formtastic 0.9.1 → 0.9.2
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 +21 -29
- data/Rakefile +2 -12
- data/generators/formtastic/templates/formtastic.rb +4 -0
- data/lib/formtastic.rb +114 -66
- data/spec/buttons_spec.rb +1 -1
- data/spec/commit_button_spec.rb +4 -4
- data/spec/custom_builder_spec.rb +1 -1
- data/spec/custom_macros.rb +461 -0
- data/spec/error_proc_spec.rb +1 -1
- data/spec/errors_spec.rb +8 -1
- data/spec/form_helper_spec.rb +1 -1
- data/spec/include_blank_spec.rb +1 -1
- data/spec/input_spec.rb +3 -1567
- data/spec/inputs/boolean_input_spec.rb +60 -0
- data/spec/inputs/check_boxes_input_spec.rb +106 -0
- data/spec/inputs/country_input_spec.rb +80 -0
- data/spec/inputs/date_input_spec.rb +43 -0
- data/spec/inputs/datetime_input_spec.rb +155 -0
- data/spec/inputs/file_input_spec.rb +33 -0
- data/spec/inputs/hidden_input_spec.rb +41 -0
- data/spec/inputs/numeric_input_spec.rb +44 -0
- data/spec/inputs/password_input_spec.rb +46 -0
- data/spec/inputs/radio_input_spec.rb +113 -0
- data/spec/inputs/select_input_spec.rb +263 -0
- data/spec/inputs/string_input_spec.rb +47 -0
- data/spec/inputs/text_input_spec.rb +33 -0
- data/spec/inputs/time_input_spec.rb +42 -0
- data/spec/inputs/time_zone_input_spec.rb +59 -0
- data/spec/inputs_spec.rb +1 -1
- data/spec/label_spec.rb +1 -1
- data/spec/semantic_fields_for_spec.rb +1 -1
- data/spec/spec.opts +2 -0
- data/spec/{test_helper.rb → spec_helper.rb} +36 -3
- metadata +38 -5
@@ -0,0 +1,47 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
describe 'string input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
|
12
|
+
semantic_form_for(@new_post) do |builder|
|
13
|
+
concat(builder.input(:title, :as => :string))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_have_input_wrapper_with_class(:string)
|
18
|
+
it_should_have_input_wrapper_with_id("post_title_input")
|
19
|
+
it_should_have_label_with_text(/Title/)
|
20
|
+
it_should_have_label_for("post_title")
|
21
|
+
it_should_have_input_with_id("post_title")
|
22
|
+
it_should_have_input_with_type(:text)
|
23
|
+
it_should_have_input_with_name("post[title]")
|
24
|
+
it_should_have_maxlength_matching_column_limit
|
25
|
+
it_should_use_default_text_field_size_for_columns_longer_than_default_text_field_size(:string)
|
26
|
+
it_should_use_column_size_for_columns_shorter_than_default_text_field_size(:string)
|
27
|
+
it_should_use_default_text_field_size_when_method_has_no_database_column(:string)
|
28
|
+
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
|
29
|
+
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
|
30
|
+
it_should_apply_error_logic_for_input_type(:string)
|
31
|
+
|
32
|
+
describe "when no object is provided" do
|
33
|
+
before do
|
34
|
+
semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
35
|
+
concat(builder.input(:title, :as => :string))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it_should_have_label_with_text(/Title/)
|
40
|
+
it_should_have_label_for("project_title")
|
41
|
+
it_should_have_input_with_id("project_title")
|
42
|
+
it_should_have_input_with_type(:text)
|
43
|
+
it_should_have_input_with_name("project[title]")
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
describe 'text input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
|
12
|
+
semantic_form_for(@new_post) do |builder|
|
13
|
+
concat(builder.input(:body, :as => :text))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_have_input_wrapper_with_class("text")
|
18
|
+
it_should_have_input_wrapper_with_id("post_body_input")
|
19
|
+
it_should_have_label_with_text(/Body/)
|
20
|
+
it_should_have_label_for("post_body")
|
21
|
+
it_should_have_textarea_with_id("post_body")
|
22
|
+
it_should_have_textarea_with_name("post[body]")
|
23
|
+
it_should_apply_error_logic_for_input_type(:numeric)
|
24
|
+
|
25
|
+
it 'should use input_html to style inputs' do
|
26
|
+
semantic_form_for(@new_post) do |builder|
|
27
|
+
concat(builder.input(:title, :as => :text, :input_html => { :class => 'myclass' }))
|
28
|
+
end
|
29
|
+
output_buffer.should have_tag("form li textarea.myclass")
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
describe 'time input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
|
12
|
+
semantic_form_for(@new_post) do |builder|
|
13
|
+
concat(builder.input(:publish_at, :as => :time))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_have_input_wrapper_with_class("time")
|
18
|
+
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
19
|
+
it_should_have_a_nested_fieldset
|
20
|
+
it_should_apply_error_logic_for_input_type(:time)
|
21
|
+
|
22
|
+
it 'should have a legend containing the label text inside the fieldset' do
|
23
|
+
output_buffer.should have_tag('form li.time fieldset legend', /Publish at/)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should have an ordered list of two items inside the fieldset' do
|
27
|
+
output_buffer.should have_tag('form li.time fieldset ol')
|
28
|
+
output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should have five labels for hour and minute' do
|
32
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', :count => 2)
|
33
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', /hour/i)
|
34
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', /minute/i)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should have two selects for hour and minute' do
|
38
|
+
output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
describe 'time_zone input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
|
12
|
+
semantic_form_for(@new_post) do |builder|
|
13
|
+
concat(builder.input(:time_zone))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_have_input_wrapper_with_class("time_zone")
|
18
|
+
it_should_have_input_wrapper_with_id("post_time_zone_input")
|
19
|
+
it_should_apply_error_logic_for_input_type(:time_zone)
|
20
|
+
|
21
|
+
it 'should generate a label for the input' do
|
22
|
+
output_buffer.should have_tag('form li label')
|
23
|
+
output_buffer.should have_tag('form li label[@for="post_time_zone"]')
|
24
|
+
output_buffer.should have_tag('form li label', /Time zone/)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should generate a select" do
|
28
|
+
output_buffer.should have_tag("form li select")
|
29
|
+
output_buffer.should have_tag("form li select#post_time_zone")
|
30
|
+
output_buffer.should have_tag("form li select[@name=\"post[time_zone]\"]")
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should use input_html to style inputs' do
|
34
|
+
semantic_form_for(@new_post) do |builder|
|
35
|
+
concat(builder.input(:time_zone, :input_html => { :class => 'myclass' }))
|
36
|
+
end
|
37
|
+
output_buffer.should have_tag("form li select.myclass")
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'when no object is given' do
|
41
|
+
before(:each) do
|
42
|
+
semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
43
|
+
concat(builder.input(:time_zone, :as => :time_zone))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should generate labels' do
|
48
|
+
output_buffer.should have_tag('form li label')
|
49
|
+
output_buffer.should have_tag('form li label[@for="project_time_zone"]')
|
50
|
+
output_buffer.should have_tag('form li label', /Time zone/)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should generate select inputs' do
|
54
|
+
output_buffer.should have_tag("form li select")
|
55
|
+
output_buffer.should have_tag("form li select#project_time_zone")
|
56
|
+
output_buffer.should have_tag("form li select[@name=\"project[time_zone]\"]")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/inputs_spec.rb
CHANGED
data/spec/label_spec.rb
CHANGED
data/spec/spec.opts
ADDED
@@ -20,8 +20,11 @@ smart_require 'active_support', 'activesupport', '>= 2.3.4'
|
|
20
20
|
smart_require 'action_controller', 'actionpack', '>= 2.3.4'
|
21
21
|
smart_require 'action_view', 'actionpack', '>= 2.3.4'
|
22
22
|
|
23
|
+
require 'custom_macros'
|
24
|
+
|
23
25
|
Spec::Runner.configure do |config|
|
24
26
|
config.include(RspecHpricotMatchers)
|
27
|
+
config.include(CustomMacros)
|
25
28
|
end
|
26
29
|
|
27
30
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
@@ -60,6 +63,10 @@ module FormtasticSpecHelper
|
|
60
63
|
end
|
61
64
|
end
|
62
65
|
class ::Author
|
66
|
+
def to_label
|
67
|
+
end
|
68
|
+
end
|
69
|
+
class ::Continent
|
63
70
|
end
|
64
71
|
|
65
72
|
def mock_everything
|
@@ -86,11 +93,23 @@ module FormtasticSpecHelper
|
|
86
93
|
@bob.stub!(:class).and_return(::Author)
|
87
94
|
@bob.stub!(:to_label).and_return('Bob Rock')
|
88
95
|
@bob.stub!(:login).and_return('bob')
|
96
|
+
@bob.stub!(:created_at)
|
89
97
|
@bob.stub!(:id).and_return(42)
|
90
98
|
@bob.stub!(:posts).and_return([])
|
91
99
|
@bob.stub!(:post_ids).and_return([])
|
92
100
|
@bob.stub!(:new_record?).and_return(false)
|
93
101
|
@bob.stub!(:errors).and_return(mock('errors', :[] => nil))
|
102
|
+
|
103
|
+
@james = mock('user')
|
104
|
+
@james.stub!(:class).and_return(::Author)
|
105
|
+
@james.stub!(:to_label).and_return('James Shock')
|
106
|
+
@james.stub!(:login).and_return('james')
|
107
|
+
@james.stub!(:id).and_return(75)
|
108
|
+
@james.stub!(:posts).and_return([])
|
109
|
+
@james.stub!(:post_ids).and_return([])
|
110
|
+
@james.stub!(:new_record?).and_return(false)
|
111
|
+
@james.stub!(:errors).and_return(mock('errors', :[] => nil))
|
112
|
+
|
94
113
|
|
95
114
|
::Author.stub!(:find).and_return([@fred, @bob])
|
96
115
|
::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
@@ -126,7 +145,9 @@ module FormtasticSpecHelper
|
|
126
145
|
::Post.stub!(:reflect_on_association).and_return do |column_name|
|
127
146
|
case column_name
|
128
147
|
when :author, :author_status
|
129
|
-
mock('reflection', :options => {}, :klass => ::Author, :macro => :belongs_to)
|
148
|
+
mock = mock('reflection', :options => {}, :klass => ::Author, :macro => :belongs_to)
|
149
|
+
mock.stub!(:[]).with(:class_name).and_return("Author")
|
150
|
+
mock
|
130
151
|
when :authors
|
131
152
|
mock('reflection', :options => {}, :klass => ::Author, :macro => :has_and_belongs_to_many)
|
132
153
|
end
|
@@ -136,10 +157,22 @@ module FormtasticSpecHelper
|
|
136
157
|
@new_post.stub!(:title)
|
137
158
|
@new_post.stub!(:body)
|
138
159
|
@new_post.stub!(:published)
|
160
|
+
@new_post.stub!(:publish_at)
|
161
|
+
@new_post.stub!(:secret)
|
162
|
+
@new_post.stub!(:time_zone)
|
163
|
+
@new_post.stub!(:category_name)
|
164
|
+
@new_post.stub!(:allow_comments)
|
139
165
|
@new_post.stub!(:column_for_attribute).with(:meta_description).and_return(mock('column', :type => :string, :limit => 255))
|
140
|
-
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit =>
|
166
|
+
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit => 50))
|
141
167
|
@new_post.stub!(:column_for_attribute).with(:body).and_return(mock('column', :type => :text))
|
142
168
|
@new_post.stub!(:column_for_attribute).with(:published).and_return(mock('column', :type => :boolean))
|
169
|
+
@new_post.stub!(:column_for_attribute).with(:publish_at).and_return(mock('column', :type => :date))
|
170
|
+
@new_post.stub!(:column_for_attribute).with(:time_zone).and_return(mock('column', :type => :string))
|
171
|
+
@new_post.stub!(:column_for_attribute).with(:allow_comments).and_return(mock('column', :type => :boolean))
|
172
|
+
|
173
|
+
@new_post.stub!(:author).and_return(@bob)
|
174
|
+
@new_post.stub!(:author_id).and_return(@bob.id)
|
175
|
+
|
143
176
|
end
|
144
177
|
|
145
178
|
def self.included(base)
|
@@ -156,4 +189,4 @@ module FormtasticSpecHelper
|
|
156
189
|
|
157
190
|
end
|
158
191
|
|
159
|
-
::ActiveSupport::Deprecation.silenced =
|
192
|
+
::ActiveSupport::Deprecation.silenced = false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formtastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin French
|
@@ -9,7 +9,7 @@ autorequire: formtastic
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-17 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -40,20 +40,37 @@ files:
|
|
40
40
|
- spec/buttons_spec.rb
|
41
41
|
- spec/commit_button_spec.rb
|
42
42
|
- spec/custom_builder_spec.rb
|
43
|
+
- spec/custom_macros.rb
|
43
44
|
- spec/error_proc_spec.rb
|
44
45
|
- spec/errors_spec.rb
|
45
46
|
- spec/form_helper_spec.rb
|
46
47
|
- spec/include_blank_spec.rb
|
47
48
|
- spec/input_spec.rb
|
49
|
+
- spec/inputs/boolean_input_spec.rb
|
50
|
+
- spec/inputs/check_boxes_input_spec.rb
|
51
|
+
- spec/inputs/country_input_spec.rb
|
52
|
+
- spec/inputs/date_input_spec.rb
|
53
|
+
- spec/inputs/datetime_input_spec.rb
|
54
|
+
- spec/inputs/file_input_spec.rb
|
55
|
+
- spec/inputs/hidden_input_spec.rb
|
56
|
+
- spec/inputs/numeric_input_spec.rb
|
57
|
+
- spec/inputs/password_input_spec.rb
|
58
|
+
- spec/inputs/radio_input_spec.rb
|
59
|
+
- spec/inputs/select_input_spec.rb
|
60
|
+
- spec/inputs/string_input_spec.rb
|
61
|
+
- spec/inputs/text_input_spec.rb
|
62
|
+
- spec/inputs/time_input_spec.rb
|
63
|
+
- spec/inputs/time_zone_input_spec.rb
|
48
64
|
- spec/inputs_spec.rb
|
49
65
|
- spec/label_spec.rb
|
50
66
|
- spec/semantic_fields_for_spec.rb
|
51
|
-
- spec/
|
67
|
+
- spec/spec.opts
|
68
|
+
- spec/spec_helper.rb
|
52
69
|
has_rdoc: true
|
53
70
|
homepage: http://github.com/justinfrench/formtastic/tree/master
|
54
71
|
licenses: []
|
55
72
|
|
56
|
-
post_install_message: "\n ========================================================================\n
|
73
|
+
post_install_message: "\n ========================================================================\n Thanks for installing Formtastic!\n ------------------------------------------------------------------------ \n You can now (optionally) run the generater to copy some stylesheets and\n a config initializer into your application:\n ./script/generate formtastic\n\n Find out more and get involved:\n http://github.com/justinfrench/formtastic\n http://groups.google.com.au/group/formtastic\n ========================================================================\n "
|
57
74
|
rdoc_options:
|
58
75
|
- --charset=UTF-8
|
59
76
|
require_paths:
|
@@ -81,12 +98,28 @@ test_files:
|
|
81
98
|
- spec/buttons_spec.rb
|
82
99
|
- spec/commit_button_spec.rb
|
83
100
|
- spec/custom_builder_spec.rb
|
101
|
+
- spec/custom_macros.rb
|
84
102
|
- spec/error_proc_spec.rb
|
85
103
|
- spec/errors_spec.rb
|
86
104
|
- spec/form_helper_spec.rb
|
87
105
|
- spec/include_blank_spec.rb
|
88
106
|
- spec/input_spec.rb
|
107
|
+
- spec/inputs/boolean_input_spec.rb
|
108
|
+
- spec/inputs/check_boxes_input_spec.rb
|
109
|
+
- spec/inputs/country_input_spec.rb
|
110
|
+
- spec/inputs/date_input_spec.rb
|
111
|
+
- spec/inputs/datetime_input_spec.rb
|
112
|
+
- spec/inputs/file_input_spec.rb
|
113
|
+
- spec/inputs/hidden_input_spec.rb
|
114
|
+
- spec/inputs/numeric_input_spec.rb
|
115
|
+
- spec/inputs/password_input_spec.rb
|
116
|
+
- spec/inputs/radio_input_spec.rb
|
117
|
+
- spec/inputs/select_input_spec.rb
|
118
|
+
- spec/inputs/string_input_spec.rb
|
119
|
+
- spec/inputs/text_input_spec.rb
|
120
|
+
- spec/inputs/time_input_spec.rb
|
121
|
+
- spec/inputs/time_zone_input_spec.rb
|
89
122
|
- spec/inputs_spec.rb
|
90
123
|
- spec/label_spec.rb
|
91
124
|
- spec/semantic_fields_for_spec.rb
|
92
|
-
- spec/
|
125
|
+
- spec/spec_helper.rb
|