bootstrap_form_extensions 1.0.4 → 1.1.0

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.
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+
3
+ class DurationTest < ActionView::TestCase
4
+ include BootstrapFormExtensions::Duration
5
+
6
+ def setup
7
+ setup_test_fixture
8
+ end
9
+
10
+ test "duration" do
11
+ expected = '<div class="form-group duration-group" data-duration="true"><label class="control-label col-sm-2" for="thing_duration_in_seconds2">Duration in seconds2</label><div class="col-sm-10 form-inline"><input class="duration-seconds" data-formatted="1:37:23.476" type="hidden" value="5843.476" name="thing[duration_in_seconds2]" id="thing_duration_in_seconds2" /><input type="number" name="thing[hours]" id="thing_hours" value="1" class="form-control hours" min="0" />:<input type="number" name="thing[minutes]" id="thing_minutes" value="37" class="form-control minutes" min="0" max="59" />:<input type="number" name="thing[seconds]" id="thing_seconds" value="23" class="form-control seconds" min="0" max="59" />.<input type="number" name="thing[milliseconds]" id="thing_milliseconds" value="476" class="form-control milliseconds" min="0" max="999" /></div></div>'
12
+ assert_equal expected, @builder.duration(:duration_in_seconds2)
13
+ end
14
+
15
+ test "duration_without_bootstrap" do
16
+ expected = '<div class="duration-group" data-duration="true"><input class="duration-seconds" data-formatted="1:37:23.476" type="hidden" value="5843.476" name="thing[duration_in_seconds2]" id="thing_duration_in_seconds2" /><input type="number" name="thing[hours]" id="thing_hours" value="1" class="hours" min="0" />:<input type="number" name="thing[minutes]" id="thing_minutes" value="37" class="minutes" min="0" max="59" />:<input type="number" name="thing[seconds]" id="thing_seconds" value="23" class="seconds" min="0" max="59" />.<input type="number" name="thing[milliseconds]" id="thing_milliseconds" value="476" class="milliseconds" min="0" max="999" /></div>'
17
+ assert_equal expected, @builder.duration_without_bootstrap(:duration_in_seconds2)
18
+ end
19
+
20
+ test "duration_without_bootstrap accepts wrapper options, like a bootstrap form's form-group" do
21
+ @output_buffer = @builder.duration_without_bootstrap :duration_in_seconds2, wrapper: { data: { test: 'accepts' } }
22
+ assert_select 'div.duration-group[data-test="accepts"]'
23
+ end
24
+
25
+ test "duration_without_bootstrap accepts wrapper_class, like a bootstrap form's form-group" do
26
+ @output_buffer = @builder.duration_without_bootstrap :duration_in_seconds2, wrapper_class: 'test_class'
27
+ assert_select 'div.duration-group.test_class'
28
+ end
29
+
30
+ end
@@ -0,0 +1,91 @@
1
+ describe("Duration", function() {
2
+
3
+ describe("Plugin", function() {
4
+
5
+ it("should be defined on jQuery object", function() {
6
+ expect($(document.body).duration).not.toThrow()
7
+ })
8
+
9
+ })
10
+
11
+ describe("Run tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode", function() {
12
+
13
+ beforeEach(function() {
14
+ $.fn.bootstrapDuration = $.fn.duration.noConflict()
15
+ })
16
+
17
+ afterEach(function() {
18
+ $.fn.duration = $.fn.bootstrapDuration
19
+ delete $.fn.bootstrapDuration
20
+ })
21
+
22
+ describe("initialization", function() {
23
+
24
+ it("should provide no conflict - duration was set back to undefined (orig value)", function() {
25
+ expect($.fn.duration).toBeUndefined()
26
+ })
27
+
28
+ it("should return jquery collection containing the element", function() {
29
+ var $el = $('<div/>')
30
+ var $duration = $el.bootstrapDuration()
31
+ expect($duration).toEqual(jasmine.any($))
32
+ expect($duration[0]).toBe($el[0])
33
+ })
34
+
35
+ })
36
+
37
+ describe("behaviour", function() {
38
+
39
+ var $element
40
+ var fixture = function() {
41
+ return '<div class="duration-group" data-duration="true">'
42
+ + ' <input class="duration-seconds" id="thing_duration_in_seconds2" name="thing[duration_in_seconds2]" type="hidden" value="0">'
43
+ + ' <input class="hours" id="thing_hours" min="0" name="thing[hours]" type="number" value="0">:'
44
+ + ' <input class="minutes" id="thing_minutes" max="59" min="0" name="thing[minutes]" type="number" value="0">:'
45
+ + ' <input class="seconds" id="thing_seconds" max="59" min="0" name="thing[seconds]" type="number" value="0">.'
46
+ + ' <input class="milliseconds" id="thing_milliseconds" max="999" min="0" name="thing[milliseconds]" type="number" value="0">'
47
+ + '</div>'
48
+ }
49
+
50
+ beforeEach(function() {
51
+ $element = $(fixture())
52
+ $element.bootstrapDuration()
53
+ })
54
+
55
+ it("should update the value in seconds when the hours change", function() {
56
+ var $unit = $element.find('input.hours')
57
+ var $value = $element.find('input.duration-seconds')
58
+
59
+ $unit.val(1).trigger('change')
60
+ expect($value.val()).toBe('3600')
61
+ })
62
+
63
+ it("should update the value in seconds when the minutes change", function() {
64
+ var $unit = $element.find('input.minutes')
65
+ var $value = $element.find('input.duration-seconds')
66
+
67
+ $unit.val(1).trigger('change')
68
+ expect($value.val()).toBe('60')
69
+ })
70
+
71
+ it("should update the value in seconds when the seconds change", function() {
72
+ var $unit = $element.find('input.seconds')
73
+ var $value = $element.find('input.duration-seconds')
74
+
75
+ $unit.val(1).trigger('change')
76
+ expect($value.val()).toBe('1')
77
+ })
78
+
79
+ it("should update the value in seconds when the milliseconds change", function() {
80
+ var $unit = $element.find('input.milliseconds')
81
+ var $value = $element.find('input.duration-seconds')
82
+
83
+ $unit.val(1).trigger('change')
84
+ expect($value.val()).toBe('0.001')
85
+ })
86
+
87
+ })
88
+
89
+ })
90
+
91
+ })
@@ -9,7 +9,7 @@ class SubmitBarTest < ActionView::TestCase
9
9
 
10
10
  test "SubmitBar with default values" do
11
11
  expected = <<-HTML
12
- <div class="form-group">
12
+ <div class="form-group col-sm-12">
13
13
  <div class='pull-left submitbar-left'>
14
14
  <div class="btn-group dropup submitbar-submit-group">
15
15
  <button type="submit" class="btn btn-primary submitbar-save">Save</button>
data/test/test_helper.rb CHANGED
@@ -30,7 +30,8 @@ def setup_test_fixture
30
30
  list: [ 'One', 'Two' ],
31
31
  variables: [ { name: 'var1', value: 1 }, { name: 'var2', value: 2 } ],
32
32
  schedule: [[false],[false],[false],[false],[false],[false],[false]],
33
- start_at: Time.new(1971, 10, 21, 11, 30, 0, '+04:00')
33
+ start_at: Time.new(1971, 10, 21, 11, 30, 0, '+04:00'),
34
+ duration_in_seconds2: 5843.476
34
35
  @builder = BootstrapForm::FormBuilder.new :thing, @thing, self, layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10"
35
36
  @template = @builder.instance_variable_get :@template
36
37
  @template.stubs(:controller_name).returns('things')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_form_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesús Dugarte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-17 00:00:00.000000000 Z
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bootstrap_form
@@ -104,6 +104,7 @@ files:
104
104
  - Rakefile
105
105
  - app/assets/javascripts/bootstrap_form_extensions/arrayed_field.js
106
106
  - app/assets/javascripts/bootstrap_form_extensions/bootstrap-timepicker.min.js
107
+ - app/assets/javascripts/bootstrap_form_extensions/duration.js
107
108
  - app/assets/javascripts/bootstrap_form_extensions/index.js
108
109
  - app/assets/javascripts/bootstrap_form_extensions/jquery.html5data.min.js
109
110
  - app/assets/javascripts/bootstrap_form_extensions/scheduler.js
@@ -112,6 +113,7 @@ files:
112
113
  - app/assets/javascripts/bootstrap_form_extensions/timespan.js
113
114
  - app/assets/stylesheets/bootstrap_form_extensions/bootstrap-timepicker.min.css
114
115
  - app/assets/stylesheets/bootstrap_form_extensions/common.css
116
+ - app/assets/stylesheets/bootstrap_form_extensions/duration.css
115
117
  - app/assets/stylesheets/bootstrap_form_extensions/index.css
116
118
  - app/assets/stylesheets/bootstrap_form_extensions/scheduler.css
117
119
  - app/assets/stylesheets/bootstrap_form_extensions/select_or_new.css
@@ -120,6 +122,7 @@ files:
120
122
  - lib/bootstrap_form_extensions.rb
121
123
  - lib/bootstrap_form_extensions/arrayed_field.rb
122
124
  - lib/bootstrap_form_extensions/date_time_pickers.rb
125
+ - lib/bootstrap_form_extensions/duration.rb
123
126
  - lib/bootstrap_form_extensions/helpers.rb
124
127
  - lib/bootstrap_form_extensions/scheduler.rb
125
128
  - lib/bootstrap_form_extensions/select_or_new.rb
@@ -162,6 +165,7 @@ files:
162
165
  - test/dummy/config/locales/en.yml
163
166
  - test/dummy/config/routes.rb
164
167
  - test/dummy/config/secrets.yml
168
+ - test/dummy/db/development.sqlite3
165
169
  - test/dummy/db/migrate/20150918185031_create_things.rb
166
170
  - test/dummy/db/migrate/20150924203053_add_timespan.rb
167
171
  - test/dummy/db/migrate/20150929213249_add_arrayed_field.rb
@@ -170,6 +174,7 @@ files:
170
174
  - test/dummy/db/migrate/20151007213131_add_scheduler_field.rb
171
175
  - test/dummy/db/migrate/20151030194330_add_date_time.rb
172
176
  - test/dummy/db/migrate/20151106165522_add_category.rb
177
+ - test/dummy/db/migrate/20151119160842_add_duration.rb
173
178
  - test/dummy/db/schema.rb
174
179
  - test/dummy/db/test.sqlite3
175
180
  - test/dummy/log/development.log
@@ -179,7 +184,9 @@ files:
179
184
  - test/dummy/public/500.html
180
185
  - test/dummy/public/favicon.ico
181
186
  - test/dummy/test/fixtures/things.yml
187
+ - test/duration_test.rb
182
188
  - test/javascripts/arrayed_field_spec.js
189
+ - test/javascripts/duration_spec.js
183
190
  - test/javascripts/helpers/function_bind_polyfill_for_phantomjs.js
184
191
  - test/javascripts/helpers/jasmine-jquery.js
185
192
  - test/javascripts/scheduler_spec.js
@@ -254,6 +261,7 @@ test_files:
254
261
  - test/dummy/config/routes.rb
255
262
  - test/dummy/config/secrets.yml
256
263
  - test/dummy/config.ru
264
+ - test/dummy/db/development.sqlite3
257
265
  - test/dummy/db/migrate/20150918185031_create_things.rb
258
266
  - test/dummy/db/migrate/20150924203053_add_timespan.rb
259
267
  - test/dummy/db/migrate/20150929213249_add_arrayed_field.rb
@@ -262,6 +270,7 @@ test_files:
262
270
  - test/dummy/db/migrate/20151007213131_add_scheduler_field.rb
263
271
  - test/dummy/db/migrate/20151030194330_add_date_time.rb
264
272
  - test/dummy/db/migrate/20151106165522_add_category.rb
273
+ - test/dummy/db/migrate/20151119160842_add_duration.rb
265
274
  - test/dummy/db/schema.rb
266
275
  - test/dummy/db/test.sqlite3
267
276
  - test/dummy/log/development.log
@@ -273,7 +282,9 @@ test_files:
273
282
  - test/dummy/Rakefile
274
283
  - test/dummy/README.rdoc
275
284
  - test/dummy/test/fixtures/things.yml
285
+ - test/duration_test.rb
276
286
  - test/javascripts/arrayed_field_spec.js
287
+ - test/javascripts/duration_spec.js
277
288
  - test/javascripts/helpers/function_bind_polyfill_for_phantomjs.js
278
289
  - test/javascripts/helpers/jasmine-jquery.js
279
290
  - test/javascripts/scheduler_spec.js