formtastic 3.1.3 → 3.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.travis.yml +12 -10
  2. data/Appraisals +11 -7
  3. data/CHANGELOG +12 -0
  4. data/DEPRECATIONS +3 -0
  5. data/{README.textile → README.md} +629 -616
  6. data/formtastic.gemspec +3 -3
  7. data/gemfiles/rails_3.2.gemfile +1 -0
  8. data/gemfiles/rails_edge.gemfile +5 -0
  9. data/lib/formtastic.rb +4 -0
  10. data/lib/formtastic/form_builder.rb +3 -0
  11. data/lib/formtastic/helpers.rb +1 -1
  12. data/lib/formtastic/helpers/enum.rb +13 -0
  13. data/lib/formtastic/helpers/fieldset_wrapper.rb +6 -6
  14. data/lib/formtastic/helpers/form_helper.rb +1 -1
  15. data/lib/formtastic/helpers/input_helper.rb +5 -1
  16. data/lib/formtastic/helpers/inputs_helper.rb +16 -20
  17. data/lib/formtastic/inputs/base/choices.rb +1 -1
  18. data/lib/formtastic/inputs/base/collections.rb +41 -4
  19. data/lib/formtastic/inputs/base/html.rb +7 -6
  20. data/lib/formtastic/inputs/base/naming.rb +4 -4
  21. data/lib/formtastic/inputs/base/options.rb +2 -3
  22. data/lib/formtastic/inputs/base/validations.rb +19 -3
  23. data/lib/formtastic/inputs/check_boxes_input.rb +10 -2
  24. data/lib/formtastic/inputs/country_input.rb +3 -1
  25. data/lib/formtastic/inputs/radio_input.rb +20 -0
  26. data/lib/formtastic/inputs/select_input.rb +28 -0
  27. data/lib/formtastic/inputs/time_zone_input.rb +16 -6
  28. data/lib/formtastic/localizer.rb +15 -15
  29. data/lib/formtastic/namespaced_class_finder.rb +1 -1
  30. data/lib/formtastic/version.rb +1 -1
  31. data/lib/generators/formtastic/form/form_generator.rb +1 -1
  32. data/lib/generators/formtastic/input/input_generator.rb +46 -0
  33. data/lib/generators/templates/formtastic.rb +10 -7
  34. data/lib/generators/templates/input.rb +19 -0
  35. data/spec/fast_spec_helper.rb +12 -0
  36. data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
  37. data/spec/helpers/form_helper_spec.rb +4 -4
  38. data/spec/inputs/base/collections_spec.rb +76 -0
  39. data/spec/inputs/base/validations_spec.rb +342 -0
  40. data/spec/inputs/check_boxes_input_spec.rb +66 -20
  41. data/spec/inputs/country_input_spec.rb +4 -4
  42. data/spec/inputs/radio_input_spec.rb +28 -0
  43. data/spec/inputs/readonly_spec.rb +50 -0
  44. data/spec/inputs/select_input_spec.rb +71 -11
  45. data/spec/inputs/time_zone_input_spec.rb +35 -9
  46. data/spec/spec_helper.rb +2 -30
  47. data/spec/support/shared_examples.rb +69 -0
  48. metadata +23 -12
  49. data/spec/support/deferred_garbage_collection.rb +0 -21
@@ -492,29 +492,8 @@ module FormtasticSpecHelper
492
492
  Formtastic::FormBuilder.send(:"#{config_method_name}=", old_value)
493
493
  end
494
494
 
495
- class ToSMatcher
496
- def initialize(str)
497
- @str=str.to_s
498
- end
499
-
500
- def matches?(value)
501
- value.to_s==@str
502
- end
503
-
504
- def failure_message_for_should
505
- "Expected argument that converted to #{@str}"
506
- end
507
- end
508
-
509
- def errors_matcher(method)
510
- # In edge rails (Rails 4) tags store method_name as a string and index the errors object using a string
511
- # therefore allow stubs to match on either string or symbol. The errors object calls to_sym on all index
512
- # accesses so @object.errors[:abc] is equivalent to @object.errors["abc"]
513
- if Rails::VERSION::MAJOR == 4
514
- ToSMatcher.new(method)
515
- else
516
- method
517
- end
495
+ RSpec::Matchers.define :errors_matcher do |expected|
496
+ match { |actual| actual.to_s == expected.to_s }
518
497
  end
519
498
  end
520
499
 
@@ -543,11 +522,4 @@ RSpec.configure do |config|
543
522
  allow(Formtastic.deprecation).to receive(:deprecation_warning).with(method, instance_of(String), instance_of(Array))
544
523
  end
545
524
  end
546
-
547
- config.before(:all) do
548
- DeferredGarbageCollection.start unless ENV["DEFER_GC"] == "false"
549
- end
550
- config.after(:all) do
551
- DeferredGarbageCollection.reconsider unless ENV["DEFER_GC"] == "false"
552
- end
553
525
  end
@@ -490,6 +490,19 @@ RSpec.shared_examples 'Input Helper' do
490
490
  end
491
491
  end
492
492
 
493
+ it 'should be required when there is :create option in validation contexts array on create' do
494
+ with_config :required_string, " required yo!" do
495
+ @new_post.class.should_receive(:validators_on).with(:title).at_least(:once).and_return([
496
+ active_model_presence_validator([:title], {:on => [:create]})
497
+ ])
498
+ concat(semantic_form_for(@new_post) do |builder|
499
+ concat(builder.input(:title))
500
+ end)
501
+ output_buffer.should have_tag('form li.required')
502
+ output_buffer.should_not have_tag('form li.optional')
503
+ end
504
+ end
505
+
493
506
  it 'should be required when there is :on => :save option on create' do
494
507
  with_config :required_string, " required yo!" do
495
508
  @new_post.class.should_receive(:validators_on).with(:title).at_least(:once).and_return([
@@ -503,6 +516,19 @@ RSpec.shared_examples 'Input Helper' do
503
516
  end
504
517
  end
505
518
 
519
+ it 'should be required when there is :save option in validation contexts array on create' do
520
+ with_config :required_string, " required yo!" do
521
+ @new_post.class.should_receive(:validators_on).with(:title).at_least(:once).and_return([
522
+ active_model_presence_validator([:title], {:on => [:save]})
523
+ ])
524
+ concat(semantic_form_for(@new_post) do |builder|
525
+ concat(builder.input(:title))
526
+ end)
527
+ output_buffer.should have_tag('form li.required')
528
+ output_buffer.should_not have_tag('form li.optional')
529
+ end
530
+ end
531
+
506
532
  it 'should be required when there is :on => :save option on update' do
507
533
  with_config :required_string, " required yo!" do
508
534
  @fred.class.should_receive(:validators_on).with(:login).at_least(:once).and_return([
@@ -516,6 +542,19 @@ RSpec.shared_examples 'Input Helper' do
516
542
  end
517
543
  end
518
544
 
545
+ it 'should be required when there is :save option in validation contexts array on update' do
546
+ with_config :required_string, " required yo!" do
547
+ @fred.class.should_receive(:validators_on).with(:login).at_least(:once).and_return([
548
+ active_model_presence_validator([:login], {:on => [:save]})
549
+ ])
550
+ concat(semantic_form_for(@fred) do |builder|
551
+ concat(builder.input(:login))
552
+ end)
553
+ output_buffer.should have_tag('form li.required')
554
+ output_buffer.should_not have_tag('form li.optional')
555
+ end
556
+ end
557
+
519
558
  it 'should not be required when there is :on => :create option on update' do
520
559
  @fred.class.should_receive(:validators_on).with(:login).at_least(:once).and_return([
521
560
  active_model_presence_validator([:login], {:on => :create})
@@ -527,6 +566,17 @@ RSpec.shared_examples 'Input Helper' do
527
566
  output_buffer.should have_tag('form li.optional')
528
567
  end
529
568
 
569
+ it 'should not be required when there is :create option in validation contexts array on update' do
570
+ @fred.class.should_receive(:validators_on).with(:login).at_least(:once).and_return([
571
+ active_model_presence_validator([:login], {:on => [:create]})
572
+ ])
573
+ concat(semantic_form_for(@fred) do |builder|
574
+ concat(builder.input(:login))
575
+ end)
576
+ output_buffer.should_not have_tag('form li.required')
577
+ output_buffer.should have_tag('form li.optional')
578
+ end
579
+
530
580
  it 'should not be required when there is :on => :update option on create' do
531
581
  @new_post.class.should_receive(:validators_on).with(:title).at_least(:once).and_return([
532
582
  active_model_presence_validator([:title], {:on => :update})
@@ -538,6 +588,17 @@ RSpec.shared_examples 'Input Helper' do
538
588
  output_buffer.should have_tag('form li.optional')
539
589
  end
540
590
 
591
+ it 'should not be required when there is :update option in validation contexts array on create' do
592
+ @new_post.class.should_receive(:validators_on).with(:title).at_least(:once).and_return([
593
+ active_model_presence_validator([:title], {:on => [:update]})
594
+ ])
595
+ concat(semantic_form_for(@new_post) do |builder|
596
+ concat(builder.input(:title))
597
+ end)
598
+ output_buffer.should_not have_tag('form li.required')
599
+ output_buffer.should have_tag('form li.optional')
600
+ end
601
+
541
602
  it 'should be not be required if the optional :if condition is not satisifed' do
542
603
  presence_should_be_required(:required => false, :tag => :body, :options => { :if => false })
543
604
  end
@@ -747,6 +808,14 @@ RSpec.shared_examples 'Input Helper' do
747
808
  default_input_type(:integer, :section_id).should == :select
748
809
  end
749
810
 
811
+ it 'should default to :select for enum' do
812
+ statuses = ActiveSupport::HashWithIndifferentAccess.new("active"=>0, "inactive"=>1)
813
+ @new_post.class.stub(:statuses) { statuses }
814
+ @new_post.stub(:defined_enums) { {"status" => statuses } }
815
+
816
+ default_input_type(:integer, :status).should == :select
817
+ end
818
+
750
819
  it 'should default to :password for :string column types with "password" in the method name' do
751
820
  default_input_type(:string, :password).should == :password
752
821
  default_input_type(:string, :hashed_password).should == :password
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: 3.1.3
4
+ version: 3.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-09 00:00:00.000000000 Z
12
+ date: 2016-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '2.14'
53
+ version: 3.3.2
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '2.14'
61
+ version: 3.3.2
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rspec_tag_matchers
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -160,17 +160,17 @@ dependencies:
160
160
  requirement: !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
163
- - - '='
163
+ - - ~>
164
164
  - !ruby/object:Gem::Version
165
- version: 1.1.1
165
+ version: 1.1.3
166
166
  type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  none: false
170
170
  requirements:
171
- - - '='
171
+ - - ~>
172
172
  - !ruby/object:Gem::Version
173
- version: 1.1.1
173
+ version: 1.1.3
174
174
  - !ruby/object:Gem::Dependency
175
175
  name: appraisal
176
176
  requirement: !ruby/object:Gem::Requirement
@@ -226,7 +226,7 @@ email:
226
226
  executables: []
227
227
  extensions: []
228
228
  extra_rdoc_files:
229
- - README.textile
229
+ - README.md
230
230
  files:
231
231
  - .gitignore
232
232
  - .rspec
@@ -237,7 +237,7 @@ files:
237
237
  - DEPRECATIONS
238
238
  - Gemfile
239
239
  - MIT-LICENSE
240
- - README.textile
240
+ - README.md
241
241
  - RELEASE_PROCESS
242
242
  - Rakefile
243
243
  - app/assets/stylesheets/formtastic.css
@@ -264,6 +264,7 @@ files:
264
264
  - lib/formtastic/helpers.rb
265
265
  - lib/formtastic/helpers/action_helper.rb
266
266
  - lib/formtastic/helpers/actions_helper.rb
267
+ - lib/formtastic/helpers/enum.rb
267
268
  - lib/formtastic/helpers/errors_helper.rb
268
269
  - lib/formtastic/helpers/fieldset_wrapper.rb
269
270
  - lib/formtastic/helpers/file_column_detection.rb
@@ -325,11 +326,13 @@ files:
325
326
  - lib/formtastic/util.rb
326
327
  - lib/formtastic/version.rb
327
328
  - lib/generators/formtastic/form/form_generator.rb
329
+ - lib/generators/formtastic/input/input_generator.rb
328
330
  - lib/generators/formtastic/install/install_generator.rb
329
331
  - lib/generators/templates/_form.html.erb
330
332
  - lib/generators/templates/_form.html.haml
331
333
  - lib/generators/templates/_form.html.slim
332
334
  - lib/generators/templates/formtastic.rb
335
+ - lib/generators/templates/input.rb
333
336
  - lib/locale/en.yml
334
337
  - sample/basic_inputs.html
335
338
  - sample/config.ru
@@ -342,7 +345,9 @@ files:
342
345
  - spec/builder/custom_builder_spec.rb
343
346
  - spec/builder/error_proc_spec.rb
344
347
  - spec/builder/semantic_fields_for_spec.rb
348
+ - spec/fast_spec_helper.rb
345
349
  - spec/generators/formtastic/form/form_generator_spec.rb
350
+ - spec/generators/formtastic/input/input_generator_spec.rb
346
351
  - spec/generators/formtastic/install/install_generator_spec.rb
347
352
  - spec/helpers/action_helper_spec.rb
348
353
  - spec/helpers/actions_helper_spec.rb
@@ -355,6 +360,8 @@ files:
355
360
  - spec/helpers/semantic_errors_helper_spec.rb
356
361
  - spec/i18n_spec.rb
357
362
  - spec/input_class_finder_spec.rb
363
+ - spec/inputs/base/collections_spec.rb
364
+ - spec/inputs/base/validations_spec.rb
358
365
  - spec/inputs/boolean_input_spec.rb
359
366
  - spec/inputs/check_boxes_input_spec.rb
360
367
  - spec/inputs/color_input_spec.rb
@@ -376,6 +383,7 @@ files:
376
383
  - spec/inputs/placeholder_spec.rb
377
384
  - spec/inputs/radio_input_spec.rb
378
385
  - spec/inputs/range_input_spec.rb
386
+ - spec/inputs/readonly_spec.rb
379
387
  - spec/inputs/search_input_spec.rb
380
388
  - spec/inputs/select_input_spec.rb
381
389
  - spec/inputs/string_input_spec.rb
@@ -390,7 +398,6 @@ files:
390
398
  - spec/spec.opts
391
399
  - spec/spec_helper.rb
392
400
  - spec/support/custom_macros.rb
393
- - spec/support/deferred_garbage_collection.rb
394
401
  - spec/support/deprecation.rb
395
402
  - spec/support/shared_examples.rb
396
403
  - spec/support/specialized_class_finder_shared_example.rb
@@ -431,7 +438,9 @@ test_files:
431
438
  - spec/builder/custom_builder_spec.rb
432
439
  - spec/builder/error_proc_spec.rb
433
440
  - spec/builder/semantic_fields_for_spec.rb
441
+ - spec/fast_spec_helper.rb
434
442
  - spec/generators/formtastic/form/form_generator_spec.rb
443
+ - spec/generators/formtastic/input/input_generator_spec.rb
435
444
  - spec/generators/formtastic/install/install_generator_spec.rb
436
445
  - spec/helpers/action_helper_spec.rb
437
446
  - spec/helpers/actions_helper_spec.rb
@@ -444,6 +453,8 @@ test_files:
444
453
  - spec/helpers/semantic_errors_helper_spec.rb
445
454
  - spec/i18n_spec.rb
446
455
  - spec/input_class_finder_spec.rb
456
+ - spec/inputs/base/collections_spec.rb
457
+ - spec/inputs/base/validations_spec.rb
447
458
  - spec/inputs/boolean_input_spec.rb
448
459
  - spec/inputs/check_boxes_input_spec.rb
449
460
  - spec/inputs/color_input_spec.rb
@@ -465,6 +476,7 @@ test_files:
465
476
  - spec/inputs/placeholder_spec.rb
466
477
  - spec/inputs/radio_input_spec.rb
467
478
  - spec/inputs/range_input_spec.rb
479
+ - spec/inputs/readonly_spec.rb
468
480
  - spec/inputs/search_input_spec.rb
469
481
  - spec/inputs/select_input_spec.rb
470
482
  - spec/inputs/string_input_spec.rb
@@ -479,7 +491,6 @@ test_files:
479
491
  - spec/spec.opts
480
492
  - spec/spec_helper.rb
481
493
  - spec/support/custom_macros.rb
482
- - spec/support/deferred_garbage_collection.rb
483
494
  - spec/support/deprecation.rb
484
495
  - spec/support/shared_examples.rb
485
496
  - spec/support/specialized_class_finder_shared_example.rb
@@ -1,21 +0,0 @@
1
- # Taken from http://makandra.com/notes/950-speed-up-rspec-by-deferring-garbage-collection
2
- class DeferredGarbageCollection
3
-
4
- DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 10.0).to_f
5
-
6
- @@last_gc_run = Time.now
7
-
8
- def self.start
9
- GC.disable if DEFERRED_GC_THRESHOLD > 0
10
- end
11
-
12
- def self.reconsider
13
- if DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD
14
- GC.enable
15
- GC.start
16
- GC.disable
17
- @@last_gc_run = Time.now
18
- end
19
- end
20
-
21
- end