formtastic 2.0.0.rc3 → 2.0.0.rc4

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.
Files changed (43) hide show
  1. data/.travis.yml +7 -0
  2. data/CHANGELOG +26 -0
  3. data/Gemfile +2 -0
  4. data/README.textile +0 -1
  5. data/RELEASE_PROCESS +0 -1
  6. data/Rakefile +1 -1
  7. data/app/assets/stylesheets/formtastic.css +3 -3
  8. data/app/assets/stylesheets/formtastic_ie6.css +7 -1
  9. data/app/assets/stylesheets/formtastic_ie7.css +7 -1
  10. data/formtastic.gemspec +0 -15
  11. data/lib/formtastic/form_builder.rb +2 -0
  12. data/lib/formtastic/helpers/errors_helper.rb +22 -0
  13. data/lib/formtastic/helpers/form_helper.rb +18 -16
  14. data/lib/formtastic/helpers/input_helper.rb +9 -7
  15. data/lib/formtastic/helpers/inputs_helper.rb +11 -3
  16. data/lib/formtastic/helpers/reflection.rb +5 -1
  17. data/lib/formtastic/inputs/base/collections.rb +7 -0
  18. data/lib/formtastic/inputs/base/html.rb +1 -1
  19. data/lib/formtastic/inputs/base/timeish.rb +7 -2
  20. data/lib/formtastic/inputs/base/validations.rb +39 -8
  21. data/lib/formtastic/inputs/check_boxes_input.rb +3 -3
  22. data/lib/formtastic/inputs/file_input.rb +4 -4
  23. data/lib/formtastic/inputs/number_input.rb +1 -1
  24. data/lib/formtastic/inputs/radio_input.rb +1 -1
  25. data/lib/formtastic/inputs/time_input.rb +25 -3
  26. data/lib/formtastic/version.rb +1 -1
  27. data/lib/generators/templates/formtastic.rb +10 -1
  28. data/spec/builder/errors_spec.rb +10 -0
  29. data/spec/builder/semantic_fields_for_spec.rb +77 -36
  30. data/spec/helpers/form_helper_spec.rb +32 -0
  31. data/spec/helpers/input_helper_spec.rb +196 -102
  32. data/spec/helpers/inputs_helper_spec.rb +85 -73
  33. data/spec/helpers/reflection_helper_spec.rb +32 -0
  34. data/spec/inputs/check_boxes_input_spec.rb +21 -6
  35. data/spec/inputs/date_input_spec.rb +20 -0
  36. data/spec/inputs/datetime_input_spec.rb +30 -11
  37. data/spec/inputs/label_spec.rb +8 -0
  38. data/spec/inputs/number_input_spec.rb +298 -2
  39. data/spec/inputs/radio_input_spec.rb +5 -6
  40. data/spec/inputs/string_input_spec.rb +22 -5
  41. data/spec/inputs/time_input_spec.rb +51 -7
  42. data/spec/spec_helper.rb +64 -12
  43. metadata +11 -9
@@ -50,6 +50,11 @@ describe 'radio input' do
50
50
  output_buffer.should_not have_tag('li.choice label.label')
51
51
  end
52
52
 
53
+ it 'should not add the required attribute to each input' do
54
+ output_buffer.should_not have_tag('li.choice input[@required]')
55
+ end
56
+
57
+
53
58
  it 'should contain a label for the radio input with a nested input and label text' do
54
59
  ::Author.all.each do |author|
55
60
  output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
@@ -63,12 +68,6 @@ describe 'radio input' do
63
68
  end
64
69
  end
65
70
 
66
- it "should add the required attribute to the input's html options" do
67
- ::Author.all.each do |post|
68
- output_buffer.should have_tag("form li fieldset ol li.author_#{post.id} input[@required]")
69
- end
70
- end
71
-
72
71
  it "should have a radio input" do
73
72
  ::Author.all.each do |author|
74
73
  output_buffer.should have_tag("form li fieldset ol li label input#post_author_id_#{author.id}")
@@ -151,12 +151,29 @@ describe 'string input' do
151
151
  end
152
152
 
153
153
  describe "when required" do
154
- it "should add the required attribute to the input's html options" do
155
- concat(semantic_form_for(@new_post) do |builder|
156
- concat(builder.input(:title, :as => :string, :required => true))
157
- end)
158
- output_buffer.should have_tag("input[@required]")
154
+
155
+ context "and configured to use HTML5 attribute" do
156
+ it "should add the required attribute to the input's html options" do
157
+ with_config :use_required_attribute, true do
158
+ concat(semantic_form_for(@new_post) do |builder|
159
+ concat(builder.input(:title, :as => :string, :required => true))
160
+ end)
161
+ output_buffer.should have_tag("input[@required]")
162
+ end
163
+ end
159
164
  end
165
+
166
+ context "and configured to not use HTML5 attribute" do
167
+ it "should add the required attribute to the input's html options" do
168
+ with_config :use_required_attribute, false do
169
+ concat(semantic_form_for(@new_post) do |builder|
170
+ concat(builder.input(:title, :as => :string, :required => true))
171
+ end)
172
+ output_buffer.should_not have_tag("input[@required]")
173
+ end
174
+ end
175
+ end
176
+
160
177
  end
161
178
 
162
179
  end
@@ -16,22 +16,46 @@ describe 'time input' do
16
16
  output_buffer.replace ''
17
17
  end
18
18
 
19
- describe "with :ignore_date" do
19
+ describe "with :ignore_date => true" do
20
20
  before do
21
21
  concat(semantic_form_for(@new_post) do |builder|
22
22
  concat(builder.input(:publish_at, :as => :time, :ignore_date => true))
23
23
  end)
24
24
  end
25
25
 
26
- it 'should not have an input for day, month and year' do
27
- output_buffer.should_not have_tag('#post_publish_at_1i')
28
- output_buffer.should_not have_tag('#post_publish_at_2i')
29
- output_buffer.should_not have_tag('#post_publish_at_3i')
26
+ it 'should not have hidden inputs for day, month and year' do
27
+ output_buffer.should_not have_tag('input#post_publish_at_1i')
28
+ output_buffer.should_not have_tag('input#post_publish_at_2i')
29
+ output_buffer.should_not have_tag('input#post_publish_at_3i')
30
30
  end
31
31
 
32
32
  it 'should have an input for hour and minute' do
33
- output_buffer.should have_tag('#post_publish_at_4i')
34
- output_buffer.should have_tag('#post_publish_at_5i')
33
+ output_buffer.should have_tag('select#post_publish_at_4i')
34
+ output_buffer.should have_tag('select#post_publish_at_5i')
35
+ end
36
+
37
+ end
38
+
39
+ describe "with :ignore_date => false" do
40
+ before do
41
+ @new_post.stub(:publish_at).and_return(Time.parse('2010-11-07'))
42
+ concat(semantic_form_for(@new_post) do |builder|
43
+ concat(builder.input(:publish_at, :as => :time, :ignore_date => false))
44
+ end)
45
+ end
46
+
47
+ it 'should have a hidden input for day, month and year' do
48
+ output_buffer.should have_tag('input#post_publish_at_1i')
49
+ output_buffer.should have_tag('input#post_publish_at_2i')
50
+ output_buffer.should have_tag('input#post_publish_at_3i')
51
+ output_buffer.should have_tag('input#post_publish_at_1i[@value="2010"]')
52
+ output_buffer.should have_tag('input#post_publish_at_2i[@value="11"]')
53
+ output_buffer.should have_tag('input#post_publish_at_3i[@value="7"]')
54
+ end
55
+
56
+ it 'should have an select for hour and minute' do
57
+ output_buffer.should have_tag('select#post_publish_at_4i')
58
+ output_buffer.should have_tag('select#post_publish_at_5i')
35
59
  end
36
60
 
37
61
  end
@@ -126,6 +150,26 @@ describe 'time input' do
126
150
  output_buffer.should have_tag('form li.time fieldset ol li label', /#{f}/i) unless field == f
127
151
  end
128
152
  end
153
+
154
+ it "should not render the label when :labels[:#{field}] is false" do
155
+ output_buffer.replace ''
156
+ concat(semantic_form_for(@new_post) do |builder|
157
+ concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => false }))
158
+ end)
159
+ output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length-1)
160
+ fields.each do |f|
161
+ output_buffer.should have_tag('form li.time fieldset ol li label', /#{f}/i) unless field == f
162
+ end
163
+ end
164
+
165
+ it "should not render unsafe HTML when :labels[:#{field}] is false" do
166
+ output_buffer.replace ''
167
+ concat(semantic_form_for(@new_post) do |builder|
168
+ concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => false }))
169
+ end)
170
+ output_buffer.should_not include(">")
171
+ end
172
+
129
173
  end
130
174
  end
131
175
 
data/spec/spec_helper.rb CHANGED
@@ -72,6 +72,17 @@ module FormtasticSpecHelper
72
72
  active_model_validator(:numericality, attributes, options)
73
73
  end
74
74
 
75
+ class ::MongoPost
76
+ include MongoMapper::Document if defined?(MongoMapper::Document)
77
+
78
+ def id
79
+ end
80
+
81
+ def persisted?
82
+ end
83
+ end
84
+
85
+
75
86
  class ::Post
76
87
  extend ActiveModel::Naming if defined?(ActiveModel::Naming)
77
88
  include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
@@ -82,6 +93,7 @@ module FormtasticSpecHelper
82
93
  def persisted?
83
94
  end
84
95
  end
96
+
85
97
  module ::Namespaced
86
98
  class Post
87
99
  extend ActiveModel::Naming if defined?(ActiveModel::Naming)
@@ -94,6 +106,7 @@ module FormtasticSpecHelper
94
106
  end
95
107
  end
96
108
  end
109
+
97
110
  class ::Author
98
111
  extend ActiveModel::Naming if defined?(ActiveModel::Naming)
99
112
  include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
@@ -104,10 +117,21 @@ module FormtasticSpecHelper
104
117
  def persisted?
105
118
  end
106
119
  end
120
+
121
+ class ::HashBackedAuthor < Hash
122
+ extend ActiveModel::Naming if defined?(ActiveModel::Naming)
123
+ include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
124
+ def persisted?; false; end
125
+ def name
126
+ 'hash backed author'
127
+ end
128
+ end
129
+
107
130
  class ::Continent
108
131
  extend ActiveModel::Naming if defined?(ActiveModel::Naming)
109
132
  include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
110
133
  end
134
+
111
135
  class ::PostModel
112
136
  extend ActiveModel::Naming if defined?(ActiveModel::Naming)
113
137
  include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
@@ -138,15 +162,15 @@ module FormtasticSpecHelper
138
162
 
139
163
  # Resource-oriented styles like form_for(@post) will expect a path method for the object,
140
164
  # so we're defining some here.
141
- def post_models_path; "/postmodels/1"; end
165
+ def post_models_path(*args); "/postmodels/1"; end
142
166
 
143
- def post_path(o); "/posts/1"; end
144
- def posts_path; "/posts"; end
145
- def new_post_path; "/posts/new"; end
167
+ def post_path(*args); "/posts/1"; end
168
+ def posts_path(*args); "/posts"; end
169
+ def new_post_path(*args); "/posts/new"; end
146
170
 
147
- def author_path(o); "/authors/1"; end
148
- def authors_path; "/authors"; end
149
- def new_author_path; "/authors/new"; end
171
+ def author_path(*args); "/authors/1"; end
172
+ def authors_path(*args); "/authors"; end
173
+ def new_author_path(*args); "/authors/new"; end
150
174
 
151
175
  @fred = ::Author.new
152
176
  @fred.stub!(:class).and_return(::Author)
@@ -198,6 +222,8 @@ module FormtasticSpecHelper
198
222
  ::Author.stub!(:to_key).and_return(nil)
199
223
  ::Author.stub!(:persisted?).and_return(nil)
200
224
 
225
+ @hash_backed_author = HashBackedAuthor.new
226
+
201
227
  # Sometimes we need a mock @post object and some Authors for belongs_to
202
228
  @new_post = mock('post')
203
229
  @new_post.stub!(:class).and_return(::Post)
@@ -256,7 +282,6 @@ module FormtasticSpecHelper
256
282
  when :mongoid_reviewer
257
283
  mock('reflection', :options => nil, :klass => ::Author, :macro => :referenced_in, :foreign_key => "reviewer_id") # custom id
258
284
  end
259
-
260
285
  end
261
286
  ::Post.stub!(:find).and_return([@freds_post])
262
287
  ::Post.stub!(:all).and_return([@freds_post])
@@ -266,6 +291,34 @@ module FormtasticSpecHelper
266
291
  ::Post.stub!(:persisted?).and_return(nil)
267
292
  ::Post.stub!(:to_ary)
268
293
 
294
+
295
+ ::MongoPost.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
296
+ ::MongoPost.stub!(:human_name).and_return('MongoPost')
297
+ ::MongoPost.stub!(:associations).and_return do |column_name|
298
+ case column_name
299
+ when :sub_posts
300
+ mock('reflection', :options => {:polymorphic => true}, :klass => ::MongoPost, :macro => :has_many)
301
+ end
302
+ end
303
+ ::MongoPost.stub!(:find).and_return([@freds_post])
304
+ ::MongoPost.stub!(:all).and_return([@freds_post])
305
+ ::MongoPost.stub!(:where).and_return([@freds_post])
306
+ ::MongoPost.stub!(:to_key).and_return(nil)
307
+ ::MongoPost.stub!(:persisted?).and_return(nil)
308
+ ::MongoPost.stub!(:to_ary)
309
+ ::MongoPost.stub!(:model_name).and_return( mock(:model_name_mock, :singular => "post", :plural => "posts", :param_key => "post", :route_key => "posts") )
310
+
311
+ @new_mm_post = mock('mm_post')
312
+ @new_mm_post.stub!(:class).and_return(::MongoPost)
313
+ @new_mm_post.stub!(:id).and_return(nil)
314
+ @new_mm_post.stub!(:new_record?).and_return(true)
315
+ @new_mm_post.stub!(:errors).and_return(mock('errors', :[] => nil))
316
+ @new_mm_post.stub!(:title).and_return("Hello World")
317
+ @new_mm_post.stub!(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
318
+ @new_mm_post.stub!(:to_key).and_return(nil)
319
+ @new_mm_post.stub!(:to_model).and_return(@new_mm_post)
320
+ @new_mm_post.stub!(:persisted?).and_return(nil)
321
+
269
322
  @mock_file = mock('file')
270
323
  Formtastic::FormBuilder.file_methods.each do |method|
271
324
  @mock_file.stub!(method).and_return(true)
@@ -350,12 +403,11 @@ end
350
403
 
351
404
  ::ActiveSupport::Deprecation.silenced = false
352
405
 
353
-
354
- Rspec.configure do |config|
406
+ RSpec.configure do |config|
355
407
  config.before(:all) do
356
- DeferredGarbageCollection.start
408
+ DeferredGarbageCollection.start unless ENV["DEFER_GC"] == "false"
357
409
  end
358
410
  config.after(:all) do
359
- DeferredGarbageCollection.reconsider
411
+ DeferredGarbageCollection.reconsider unless ENV["DEFER_GC"] == "false"
360
412
  end
361
413
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formtastic
3
3
  version: !ruby/object:Gem::Version
4
- hash: 977940588
5
- prerelease: true
4
+ hash: 15424093
5
+ prerelease: 6
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
9
  - 0
10
- - rc3
11
- version: 2.0.0.rc3
10
+ - rc
11
+ - 4
12
+ version: 2.0.0.rc4
12
13
  platform: ruby
13
14
  authors:
14
15
  - Justin French
@@ -16,8 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2011-06-19 00:00:00 +10:00
20
- default_executable:
20
+ date: 2011-08-16 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -152,6 +152,7 @@ extra_rdoc_files:
152
152
  files:
153
153
  - .gitignore
154
154
  - .rspec
155
+ - .travis.yml
155
156
  - .yardopts
156
157
  - CHANGELOG
157
158
  - Gemfile
@@ -240,6 +241,7 @@ files:
240
241
  - spec/helpers/form_helper_spec.rb
241
242
  - spec/helpers/input_helper_spec.rb
242
243
  - spec/helpers/inputs_helper_spec.rb
244
+ - spec/helpers/reflection_helper_spec.rb
243
245
  - spec/helpers/semantic_errors_helper_spec.rb
244
246
  - spec/i18n_spec.rb
245
247
  - spec/inputs/boolean_input_spec.rb
@@ -273,11 +275,10 @@ files:
273
275
  - spec/support/deferred_garbage_collection.rb
274
276
  - spec/support/deprecation.rb
275
277
  - spec/support/test_environment.rb
276
- has_rdoc: true
277
278
  homepage: http://github.com/justinfrench/formtastic
278
279
  licenses: []
279
280
 
280
- post_install_message: "\n ========================================================================\n Thanks for installing Formtastic!\n ------------------------------------------------------------------------\n You can now (optionally) run the generator to copy a config initializer \n (and some stylesheets, in Rails 3.0.x) into your application:\n rails generate formtastic:install\n\n Find out more and get involved:\n http://github.com/justinfrench/formtastic\n http://rdoc.info/github/justinfrench/formtastic/master/frames\n http://groups.google.com.au/group/formtastic\n http://twitter.com/formtastic\n ========================================================================\n "
281
+ post_install_message:
281
282
  rdoc_options:
282
283
  - --charset=UTF-8
283
284
  require_paths:
@@ -303,7 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
303
304
  requirements: []
304
305
 
305
306
  rubyforge_project:
306
- rubygems_version: 1.3.7
307
+ rubygems_version: 1.8.7
307
308
  signing_key:
308
309
  specification_version: 3
309
310
  summary: A Rails form builder plugin/gem with semantically rich and accessible markup
@@ -317,6 +318,7 @@ test_files:
317
318
  - spec/helpers/form_helper_spec.rb
318
319
  - spec/helpers/input_helper_spec.rb
319
320
  - spec/helpers/inputs_helper_spec.rb
321
+ - spec/helpers/reflection_helper_spec.rb
320
322
  - spec/helpers/semantic_errors_helper_spec.rb
321
323
  - spec/i18n_spec.rb
322
324
  - spec/inputs/boolean_input_spec.rb