bootstrap_form_extensions 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/bootstrap_form_extensions/arrayed_field.js +70 -0
- data/app/assets/javascripts/bootstrap_form_extensions/bootstrap-timepicker.min.js +5 -0
- data/app/assets/javascripts/bootstrap_form_extensions/index.js +2 -0
- data/app/assets/javascripts/bootstrap_form_extensions/jquery.html5data.min.js +7 -0
- data/app/assets/javascripts/bootstrap_form_extensions/scheduler.js +226 -0
- data/app/assets/javascripts/bootstrap_form_extensions/select_or_new.js +76 -0
- data/app/assets/javascripts/bootstrap_form_extensions/time_picker.js +61 -0
- data/app/assets/javascripts/bootstrap_form_extensions/timespan.js +60 -0
- data/app/assets/stylesheets/bootstrap_form_extensions/bootstrap-timepicker.min.css +10 -0
- data/app/assets/stylesheets/bootstrap_form_extensions/common.css +11 -0
- data/app/assets/stylesheets/bootstrap_form_extensions/index.css +4 -0
- data/app/assets/stylesheets/bootstrap_form_extensions/scheduler.css +31 -0
- data/app/assets/stylesheets/bootstrap_form_extensions/submit_bar.css +4 -0
- data/app/views/bootstrap_form_extensions/_submit_bar.html.erb +36 -0
- data/lib/bootstrap_form_extensions.rb +22 -0
- data/lib/bootstrap_form_extensions/arrayed_field.rb +107 -0
- data/lib/bootstrap_form_extensions/date_time_pickers.rb +71 -0
- data/lib/bootstrap_form_extensions/helpers.rb +18 -0
- data/lib/bootstrap_form_extensions/scheduler.rb +72 -0
- data/lib/bootstrap_form_extensions/select_or_new.rb +36 -0
- data/lib/bootstrap_form_extensions/submit_bar.rb +65 -0
- data/lib/bootstrap_form_extensions/timespan.rb +55 -0
- data/lib/bootstrap_form_extensions/version.rb +3 -0
- data/lib/tasks/rails_bootstrap_form_extensions_tasks.rake +4 -0
- data/test/arrayed_field_test.rb +63 -0
- data/test/bootstrap_form_extensions_test.rb +7 -0
- data/test/date_time_pickers_test.rb +50 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/category.rb +7 -0
- data/test/dummy/app/models/thing.rb +46 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/migrate/20150918185031_create_things.rb +9 -0
- data/test/dummy/db/migrate/20150924203053_add_timespan.rb +7 -0
- data/test/dummy/db/migrate/20150929213249_add_arrayed_field.rb +7 -0
- data/test/dummy/db/migrate/20151006171627_add_another_arrayed_field.rb +7 -0
- data/test/dummy/db/migrate/20151006181943_add_json_field.rb +7 -0
- data/test/dummy/db/migrate/20151007213131_add_scheduler_field.rb +7 -0
- data/test/dummy/db/migrate/20151030194330_add_date_time.rb +7 -0
- data/test/dummy/db/migrate/20151106165522_add_category.rb +10 -0
- data/test/dummy/db/schema.rb +31 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/log/test.log +1997 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/fixtures/things.yml +8 -0
- data/test/javascripts/arrayed_field_spec.js +101 -0
- data/test/javascripts/helpers/function_bind_polyfill_for_phantomjs.js +32 -0
- data/test/javascripts/helpers/jasmine-jquery.js +838 -0
- data/test/javascripts/scheduler_spec.js +354 -0
- data/test/javascripts/select_or_new_spec.js +113 -0
- data/test/javascripts/support/jasmine.yml +127 -0
- data/test/javascripts/support/jasmine_helper.rb +19 -0
- data/test/javascripts/time_picker_spec.js +42 -0
- data/test/javascripts/timespan_spec.js +81 -0
- data/test/javascripts/vendor/bootstrap.min.js +7 -0
- data/test/javascripts/vendor/jquery-2.1.4.min.js +4 -0
- data/test/scheduler_serializer_test.rb +200 -0
- data/test/scheduler_test.rb +15 -0
- data/test/select_or_new_test.rb +37 -0
- data/test/submit_bar_test.rb +112 -0
- data/test/test_helper.rb +37 -0
- data/test/timespan_test.rb +47 -0
- metadata +291 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SchedulerTest < ActionView::TestCase
|
4
|
+
include BootstrapFormExtensions::Scheduler
|
5
|
+
|
6
|
+
def setup
|
7
|
+
setup_test_fixture
|
8
|
+
end
|
9
|
+
|
10
|
+
test "scheduler" do
|
11
|
+
expected = '<div class="form-group" data-scheduler="true"><label class="control-label col-sm-2" for="thing_schedule">Schedule</label><div class="col-sm-10"><input value="[[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true],[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true],[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true],[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true],[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true],[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true],[false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true]]" class="scheduler-hidden-field" type="hidden" name="thing[schedule]" id="thing_schedule" /><table class="scheduler-badge"><tbody><tr><td class="off" data-day="0" data-hour="0"> </td><td class="on" data-day="0" data-hour="1"> </td><td class="on" data-day="0" data-hour="2"> </td><td class="on" data-day="0" data-hour="3"> </td><td class="on" data-day="0" data-hour="4"> </td><td class="on" data-day="0" data-hour="5"> </td><td class="on" data-day="0" data-hour="6"> </td><td class="on" data-day="0" data-hour="7"> </td><td class="on" data-day="0" data-hour="8"> </td><td class="on" data-day="0" data-hour="9"> </td><td class="on" data-day="0" data-hour="10"> </td><td class="on" data-day="0" data-hour="11"> </td><td class="on" data-day="0" data-hour="12"> </td><td class="on" data-day="0" data-hour="13"> </td><td class="on" data-day="0" data-hour="14"> </td><td class="on" data-day="0" data-hour="15"> </td><td class="on" data-day="0" data-hour="16"> </td><td class="on" data-day="0" data-hour="17"> </td><td class="on" data-day="0" data-hour="18"> </td><td class="on" data-day="0" data-hour="19"> </td><td class="on" data-day="0" data-hour="20"> </td><td class="on" data-day="0" data-hour="21"> </td><td class="on" data-day="0" data-hour="22"> </td><td class="on" data-day="0" data-hour="23"> </td></tr><tr><td class="off" data-day="1" data-hour="0"> </td><td class="on" data-day="1" data-hour="1"> </td><td class="on" data-day="1" data-hour="2"> </td><td class="on" data-day="1" data-hour="3"> </td><td class="on" data-day="1" data-hour="4"> </td><td class="on" data-day="1" data-hour="5"> </td><td class="on" data-day="1" data-hour="6"> </td><td class="on" data-day="1" data-hour="7"> </td><td class="on" data-day="1" data-hour="8"> </td><td class="on" data-day="1" data-hour="9"> </td><td class="on" data-day="1" data-hour="10"> </td><td class="on" data-day="1" data-hour="11"> </td><td class="on" data-day="1" data-hour="12"> </td><td class="on" data-day="1" data-hour="13"> </td><td class="on" data-day="1" data-hour="14"> </td><td class="on" data-day="1" data-hour="15"> </td><td class="on" data-day="1" data-hour="16"> </td><td class="on" data-day="1" data-hour="17"> </td><td class="on" data-day="1" data-hour="18"> </td><td class="on" data-day="1" data-hour="19"> </td><td class="on" data-day="1" data-hour="20"> </td><td class="on" data-day="1" data-hour="21"> </td><td class="on" data-day="1" data-hour="22"> </td><td class="on" data-day="1" data-hour="23"> </td></tr><tr><td class="off" data-day="2" data-hour="0"> </td><td class="on" data-day="2" data-hour="1"> </td><td class="on" data-day="2" data-hour="2"> </td><td class="on" data-day="2" data-hour="3"> </td><td class="on" data-day="2" data-hour="4"> </td><td class="on" data-day="2" data-hour="5"> </td><td class="on" data-day="2" data-hour="6"> </td><td class="on" data-day="2" data-hour="7"> </td><td class="on" data-day="2" data-hour="8"> </td><td class="on" data-day="2" data-hour="9"> </td><td class="on" data-day="2" data-hour="10"> </td><td class="on" data-day="2" data-hour="11"> </td><td class="on" data-day="2" data-hour="12"> </td><td class="on" data-day="2" data-hour="13"> </td><td class="on" data-day="2" data-hour="14"> </td><td class="on" data-day="2" data-hour="15"> </td><td class="on" data-day="2" data-hour="16"> </td><td class="on" data-day="2" data-hour="17"> </td><td class="on" data-day="2" data-hour="18"> </td><td class="on" data-day="2" data-hour="19"> </td><td class="on" data-day="2" data-hour="20"> </td><td class="on" data-day="2" data-hour="21"> </td><td class="on" data-day="2" data-hour="22"> </td><td class="on" data-day="2" data-hour="23"> </td></tr><tr><td class="off" data-day="3" data-hour="0"> </td><td class="on" data-day="3" data-hour="1"> </td><td class="on" data-day="3" data-hour="2"> </td><td class="on" data-day="3" data-hour="3"> </td><td class="on" data-day="3" data-hour="4"> </td><td class="on" data-day="3" data-hour="5"> </td><td class="on" data-day="3" data-hour="6"> </td><td class="on" data-day="3" data-hour="7"> </td><td class="on" data-day="3" data-hour="8"> </td><td class="on" data-day="3" data-hour="9"> </td><td class="on" data-day="3" data-hour="10"> </td><td class="on" data-day="3" data-hour="11"> </td><td class="on" data-day="3" data-hour="12"> </td><td class="on" data-day="3" data-hour="13"> </td><td class="on" data-day="3" data-hour="14"> </td><td class="on" data-day="3" data-hour="15"> </td><td class="on" data-day="3" data-hour="16"> </td><td class="on" data-day="3" data-hour="17"> </td><td class="on" data-day="3" data-hour="18"> </td><td class="on" data-day="3" data-hour="19"> </td><td class="on" data-day="3" data-hour="20"> </td><td class="on" data-day="3" data-hour="21"> </td><td class="on" data-day="3" data-hour="22"> </td><td class="on" data-day="3" data-hour="23"> </td></tr><tr><td class="off" data-day="4" data-hour="0"> </td><td class="on" data-day="4" data-hour="1"> </td><td class="on" data-day="4" data-hour="2"> </td><td class="on" data-day="4" data-hour="3"> </td><td class="on" data-day="4" data-hour="4"> </td><td class="on" data-day="4" data-hour="5"> </td><td class="on" data-day="4" data-hour="6"> </td><td class="on" data-day="4" data-hour="7"> </td><td class="on" data-day="4" data-hour="8"> </td><td class="on" data-day="4" data-hour="9"> </td><td class="on" data-day="4" data-hour="10"> </td><td class="on" data-day="4" data-hour="11"> </td><td class="on" data-day="4" data-hour="12"> </td><td class="on" data-day="4" data-hour="13"> </td><td class="on" data-day="4" data-hour="14"> </td><td class="on" data-day="4" data-hour="15"> </td><td class="on" data-day="4" data-hour="16"> </td><td class="on" data-day="4" data-hour="17"> </td><td class="on" data-day="4" data-hour="18"> </td><td class="on" data-day="4" data-hour="19"> </td><td class="on" data-day="4" data-hour="20"> </td><td class="on" data-day="4" data-hour="21"> </td><td class="on" data-day="4" data-hour="22"> </td><td class="on" data-day="4" data-hour="23"> </td></tr><tr><td class="off" data-day="5" data-hour="0"> </td><td class="on" data-day="5" data-hour="1"> </td><td class="on" data-day="5" data-hour="2"> </td><td class="on" data-day="5" data-hour="3"> </td><td class="on" data-day="5" data-hour="4"> </td><td class="on" data-day="5" data-hour="5"> </td><td class="on" data-day="5" data-hour="6"> </td><td class="on" data-day="5" data-hour="7"> </td><td class="on" data-day="5" data-hour="8"> </td><td class="on" data-day="5" data-hour="9"> </td><td class="on" data-day="5" data-hour="10"> </td><td class="on" data-day="5" data-hour="11"> </td><td class="on" data-day="5" data-hour="12"> </td><td class="on" data-day="5" data-hour="13"> </td><td class="on" data-day="5" data-hour="14"> </td><td class="on" data-day="5" data-hour="15"> </td><td class="on" data-day="5" data-hour="16"> </td><td class="on" data-day="5" data-hour="17"> </td><td class="on" data-day="5" data-hour="18"> </td><td class="on" data-day="5" data-hour="19"> </td><td class="on" data-day="5" data-hour="20"> </td><td class="on" data-day="5" data-hour="21"> </td><td class="on" data-day="5" data-hour="22"> </td><td class="on" data-day="5" data-hour="23"> </td></tr><tr><td class="off" data-day="6" data-hour="0"> </td><td class="on" data-day="6" data-hour="1"> </td><td class="on" data-day="6" data-hour="2"> </td><td class="on" data-day="6" data-hour="3"> </td><td class="on" data-day="6" data-hour="4"> </td><td class="on" data-day="6" data-hour="5"> </td><td class="on" data-day="6" data-hour="6"> </td><td class="on" data-day="6" data-hour="7"> </td><td class="on" data-day="6" data-hour="8"> </td><td class="on" data-day="6" data-hour="9"> </td><td class="on" data-day="6" data-hour="10"> </td><td class="on" data-day="6" data-hour="11"> </td><td class="on" data-day="6" data-hour="12"> </td><td class="on" data-day="6" data-hour="13"> </td><td class="on" data-day="6" data-hour="14"> </td><td class="on" data-day="6" data-hour="15"> </td><td class="on" data-day="6" data-hour="16"> </td><td class="on" data-day="6" data-hour="17"> </td><td class="on" data-day="6" data-hour="18"> </td><td class="on" data-day="6" data-hour="19"> </td><td class="on" data-day="6" data-hour="20"> </td><td class="on" data-day="6" data-hour="21"> </td><td class="on" data-day="6" data-hour="22"> </td><td class="on" data-day="6" data-hour="23"> </td></tr></tbody></table></div></div>'
|
12
|
+
assert_equal expected, @builder.scheduler(:schedule)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SelectOrNewTest < ActionView::TestCase
|
4
|
+
include BootstrapFormExtensions::SelectOrNew
|
5
|
+
|
6
|
+
def setup
|
7
|
+
setup_test_fixture
|
8
|
+
end
|
9
|
+
|
10
|
+
test "select_or_new" do
|
11
|
+
expected = <<-HTML.chomp
|
12
|
+
<div class="form-group" data-select-or-new="true"><label class="control-label col-sm-2" for="thing_category">Category</label><div class="col-sm-10"><select class="form-control" name="thing[category]" id="thing_category"><option value="">Please select</option>
|
13
|
+
<option value="1">One</option>
|
14
|
+
<option value="2">Two</option>
|
15
|
+
<option value="0">New...</option></select><div class="input-group" style="display: none;"><input type="text" name="thing[new_category]" id="thing_new_category" class="form-control" placeholder="New..." /><div class="input-group-addon select-or-new-cancel"><i class="text-danger glyphicon glyphicon-remove"></i></div></div></div></div>
|
16
|
+
HTML
|
17
|
+
assert_equal expected, @builder.select_or_new(:category, [ [ 'One', 1 ], [ 'Two', 2 ] ])
|
18
|
+
end
|
19
|
+
|
20
|
+
test "display new, if option is selected" do
|
21
|
+
expected = <<-HTML.chomp
|
22
|
+
<div class="form-group" data-select-or-new="true"><label class="control-label col-sm-2" for="thing_category">Category</label><div class="col-sm-10"><select class="form-control" name="thing[category]" id="thing_category"><option value="">Please select</option>
|
23
|
+
<option value="1">One</option>
|
24
|
+
<option value="2">Two</option>
|
25
|
+
<option value="0">New...</option></select><div class="input-group" style="display: none;"><input type="text" name="thing[new_category]" id="thing_new_category" value="New Category" class="form-control" placeholder="New..." /><div class="input-group-addon select-or-new-cancel"><i class="text-danger glyphicon glyphicon-remove"></i></div></div></div></div>
|
26
|
+
HTML
|
27
|
+
@thing.category_id = 0
|
28
|
+
@thing.new_category = "New Category"
|
29
|
+
assert_equal expected, @builder.select_or_new(:category, [ [ 'One', 1 ], [ 'Two', 2 ] ])
|
30
|
+
end
|
31
|
+
|
32
|
+
test "add a css class to the select" do
|
33
|
+
@output_buffer = @builder.select_or_new :category, [ [ 'One', 1 ], [ 'Two', 2 ] ], {}, { class: 'category_select_css' }
|
34
|
+
assert_select 'select.category_select_css'
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SubmitBarTest < ActionView::TestCase
|
4
|
+
include BootstrapFormExtensions::SubmitBar
|
5
|
+
|
6
|
+
def setup
|
7
|
+
setup_test_fixture
|
8
|
+
end
|
9
|
+
|
10
|
+
test "SubmitBar with default values" do
|
11
|
+
expected = <<-HTML
|
12
|
+
<div class="form-group">
|
13
|
+
<div class='pull-left submitbar-left'>
|
14
|
+
<div class="btn-group dropup submitbar-submit-group">
|
15
|
+
<button type="submit" class="btn btn-primary submitbar-save">Save</button>
|
16
|
+
<button type="button" class="btn btn-primary dropdown-toggle submitbar-next-action-toggle" data-toggle="dropdown">
|
17
|
+
<span class="caret"></span>
|
18
|
+
<span class="sr-only">Toggle Dropdown</span>
|
19
|
+
</button>
|
20
|
+
<ul class="dropdown-menu submitbar-next-action-menu" role="menu">
|
21
|
+
<li><button type="submit" name="next_action" class="btn-link submitbar-duplicate" value="duplicate">Save and duplicate</button></li>
|
22
|
+
<li><button type="submit" name="next_action" class="btn-link submitbar-new" value="new">Save and new</button></li>
|
23
|
+
</ul>
|
24
|
+
</div>
|
25
|
+
<a class="btn btn-default submitbar-cancel" rel="nofollow" href="/things">Cancel</a>
|
26
|
+
</div>
|
27
|
+
</div>
|
28
|
+
HTML
|
29
|
+
assert_equal expected, @builder.submit_bar
|
30
|
+
end
|
31
|
+
|
32
|
+
test "don't show the submit button" do
|
33
|
+
@output_buffer = @builder.submit_bar show_submit_button: false
|
34
|
+
assert_select 'button.submitbar-save', count: 0
|
35
|
+
assert_select 'div.submitbar-submit-group', count: 0
|
36
|
+
end
|
37
|
+
|
38
|
+
test "change the submit button text" do
|
39
|
+
@output_buffer = @builder.submit_bar submit_button_text: 'Register'
|
40
|
+
assert_select 'button.submitbar-save', text: 'Register'
|
41
|
+
assert_select 'button.submitbar-duplicate', text: /^Register/
|
42
|
+
assert_select 'button.submitbar-new', text: /^Register/
|
43
|
+
end
|
44
|
+
|
45
|
+
test "don't show the submit menu" do
|
46
|
+
@output_buffer = @builder.submit_bar show_submit_menu: false
|
47
|
+
assert_select 'button.submitbar-next-action-toggle', count: 0
|
48
|
+
assert_select 'ul.submitbar-next-action-menu', count: 0
|
49
|
+
assert_select 'button[name=next_action]', count: 0
|
50
|
+
end
|
51
|
+
|
52
|
+
test "don't show the submit and duplicate button" do
|
53
|
+
@output_buffer = @builder.submit_bar show_submit_and_dup_button: false
|
54
|
+
assert_select 'button.submitbar-next-action-toggle', count: 1
|
55
|
+
assert_select 'ul.submitbar-next-action-menu', count: 1
|
56
|
+
assert_select 'button.submitbar-duplicate', count: 0
|
57
|
+
end
|
58
|
+
|
59
|
+
test "don't show the submit and new button" do
|
60
|
+
@output_buffer = @builder.submit_bar show_submit_and_new_button: false
|
61
|
+
assert_select 'button.submitbar-next-action-toggle', count: 1
|
62
|
+
assert_select 'ul.submitbar-next-action-menu', count: 1
|
63
|
+
assert_select 'button.submitbar-new', count: 0
|
64
|
+
end
|
65
|
+
|
66
|
+
test "don't show the cancel button" do
|
67
|
+
@output_buffer = @builder.submit_bar show_cancel_button: false
|
68
|
+
assert_select 'submitbar-cancel', count: 0
|
69
|
+
end
|
70
|
+
|
71
|
+
test "change the cancel button text" do
|
72
|
+
@output_buffer = @builder.submit_bar cancel_button_text: 'Abort'
|
73
|
+
assert_select 'a.submitbar-cancel', text: 'Abort'
|
74
|
+
end
|
75
|
+
|
76
|
+
test "change the cancel button url" do
|
77
|
+
@output_buffer = @builder.submit_bar cancel_button_url: '/'
|
78
|
+
assert_select 'a.submitbar-cancel', href: '/'
|
79
|
+
end
|
80
|
+
|
81
|
+
test "cancel button points to the create url when the object is new" do
|
82
|
+
@output_buffer = @builder.submit_bar
|
83
|
+
assert_select 'a.submitbar-cancel[href=?]', things_path
|
84
|
+
end
|
85
|
+
|
86
|
+
test "cancel button points to the index url when the object is persisted" do
|
87
|
+
@thing.save
|
88
|
+
@output_buffer = @builder.submit_bar
|
89
|
+
assert_select 'a.submitbar-cancel[href=?]', thing_path(@thing)
|
90
|
+
end
|
91
|
+
|
92
|
+
test "cancel button text changes if there is no submit button" do
|
93
|
+
@output_buffer = @builder.submit_bar show_submit_button:false
|
94
|
+
assert_select 'a.submitbar-cancel', text: 'Back'
|
95
|
+
end
|
96
|
+
|
97
|
+
test "add extra buttons" do
|
98
|
+
@output_buffer = @builder.submit_bar extra_buttons: [ { text: 'Option', url: '/option', class: 'option_css' } ]
|
99
|
+
assert_select 'a.submitbar-extra-button', count: 1, text: 'Option'
|
100
|
+
assert_select 'a.submitbar-extra-button[href=?]', '/option'
|
101
|
+
assert_select 'a.submitbar-extra-button.option_css', count: 1
|
102
|
+
end
|
103
|
+
|
104
|
+
test "add extra buttons on the right" do
|
105
|
+
@output_buffer = @builder.submit_bar right_buttons: [ { text: 'Option', url: '/option', class: 'option_css' } ]
|
106
|
+
assert_select 'div.submitbar-right', count: 1
|
107
|
+
assert_select 'a.submitbar-right-button', count: 1, text: 'Option'
|
108
|
+
assert_select 'a.submitbar-right-button[href=?]', '/option'
|
109
|
+
assert_select 'a.submitbar-right-button.option_css', count: 1
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'mocha/mini_test'
|
2
|
+
|
3
|
+
# Configure Rails Environment
|
4
|
+
ENV["RAILS_ENV"] = "test"
|
5
|
+
|
6
|
+
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
|
7
|
+
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
|
8
|
+
require "rails/test_help"
|
9
|
+
|
10
|
+
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
11
|
+
# to be shown.
|
12
|
+
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
13
|
+
|
14
|
+
# Load support files
|
15
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
16
|
+
|
17
|
+
# Load fixtures from the engine
|
18
|
+
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
|
19
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
20
|
+
ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
|
21
|
+
ActiveSupport::TestCase.fixtures :all
|
22
|
+
end
|
23
|
+
|
24
|
+
ActionController::Base.prepend_view_path File.dirname(__FILE__) + "/../app/views"
|
25
|
+
|
26
|
+
def setup_test_fixture
|
27
|
+
@thing = Thing.new name: 'Something',
|
28
|
+
duration_in_seconds: 3600,
|
29
|
+
urls: [ 'www.example1.com', 'www.example2.com' ],
|
30
|
+
list: [ 'One', 'Two' ],
|
31
|
+
variables: [ { name: 'var1', value: 1 }, { name: 'var2', value: 2 } ],
|
32
|
+
schedule: [[false],[false],[false],[false],[false],[false],[false]],
|
33
|
+
start_at: Time.new(1971, 10, 21, 11, 30, 0, '+04:00')
|
34
|
+
@builder = BootstrapForm::FormBuilder.new :thing, @thing, self, layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10"
|
35
|
+
@template = @builder.instance_variable_get :@template
|
36
|
+
@template.stubs(:controller_name).returns('things')
|
37
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TimespanTest < ActionView::TestCase
|
4
|
+
include BootstrapFormExtensions::Timespan
|
5
|
+
|
6
|
+
def setup
|
7
|
+
setup_test_fixture
|
8
|
+
end
|
9
|
+
|
10
|
+
test "Timespan with default values" do
|
11
|
+
expected = <<-HTML.chomp
|
12
|
+
<span data-timespan="true"><input class="timespan-seconds" type="hidden" value="3600" name="thing[duration_in_seconds]" id="thing_duration_in_seconds" /><div class="form-group"><input type="text" name="duration_quantity" id="duration_quantity" value="1" size="5" class="form-control timespan-quantity" /></div> <div class="form-group"><select name="duration_unit" id="duration_unit" class="form-control timespan-unit"><option value="1">seconds</option>
|
13
|
+
<option value="60">minutes</option>
|
14
|
+
<option selected="selected" value="3600">hours</option>
|
15
|
+
<option value="86400">days</option>
|
16
|
+
<option value="604800">weeks</option>
|
17
|
+
<option value="18144000">months</option></select></div></span>
|
18
|
+
HTML
|
19
|
+
assert_equal expected, @builder.timespan(:duration_in_seconds)
|
20
|
+
end
|
21
|
+
|
22
|
+
test "specifying units" do
|
23
|
+
expected = <<-HTML.chomp
|
24
|
+
<span data-timespan="true"><input class="timespan-seconds" type="hidden" value="3600" name="thing[duration_in_seconds]" id="thing_duration_in_seconds" /><div class="form-group"><input type="text" name="duration_quantity" id="duration_quantity" value="1" size="5" class="form-control timespan-quantity" /></div> <div class="form-group"><select name="duration_unit" id="duration_unit" class="form-control timespan-unit"><option selected="selected" value="3600">hours</option>
|
25
|
+
<option value="86400">days</option></select></div></span>
|
26
|
+
HTML
|
27
|
+
assert_equal expected, @builder.timespan(:duration_in_seconds, units: %i[ hours days ])
|
28
|
+
end
|
29
|
+
|
30
|
+
test "specifying quantity html options" do
|
31
|
+
@output_buffer = @builder.timespan(:duration_in_seconds, quantity_options: { class: 'quantity-css' })
|
32
|
+
assert_select 'input.timespan-quantity.quantity-css'
|
33
|
+
end
|
34
|
+
|
35
|
+
test "specifying unit html options" do
|
36
|
+
@output_buffer = @builder.timespan(:duration_in_seconds, unit_options: { class: 'unit-css' })
|
37
|
+
assert_select 'select.timespan-unit.unit-css'
|
38
|
+
end
|
39
|
+
|
40
|
+
test "field has errors" do
|
41
|
+
@thing.errors.add :duration_in_seconds, 'has some errors'
|
42
|
+
@output_buffer = @builder.timespan(:duration_in_seconds)
|
43
|
+
assert_select 'div.has-error > input.timespan-quantity'
|
44
|
+
assert_select 'span.help-block', text: 'has some errors'
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,291 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bootstrap_form_extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jesús Dugarte
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bootstrap_form
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bootstrap-datepicker-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: jasmine
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: ''
|
98
|
+
email: jdugarte@gmail.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- MIT-LICENSE
|
104
|
+
- Rakefile
|
105
|
+
- app/assets/javascripts/bootstrap_form_extensions/arrayed_field.js
|
106
|
+
- app/assets/javascripts/bootstrap_form_extensions/bootstrap-timepicker.min.js
|
107
|
+
- app/assets/javascripts/bootstrap_form_extensions/index.js
|
108
|
+
- app/assets/javascripts/bootstrap_form_extensions/jquery.html5data.min.js
|
109
|
+
- app/assets/javascripts/bootstrap_form_extensions/scheduler.js
|
110
|
+
- app/assets/javascripts/bootstrap_form_extensions/select_or_new.js
|
111
|
+
- app/assets/javascripts/bootstrap_form_extensions/time_picker.js
|
112
|
+
- app/assets/javascripts/bootstrap_form_extensions/timespan.js
|
113
|
+
- app/assets/stylesheets/bootstrap_form_extensions/bootstrap-timepicker.min.css
|
114
|
+
- app/assets/stylesheets/bootstrap_form_extensions/common.css
|
115
|
+
- app/assets/stylesheets/bootstrap_form_extensions/index.css
|
116
|
+
- app/assets/stylesheets/bootstrap_form_extensions/scheduler.css
|
117
|
+
- app/assets/stylesheets/bootstrap_form_extensions/submit_bar.css
|
118
|
+
- app/views/bootstrap_form_extensions/_submit_bar.html.erb
|
119
|
+
- lib/bootstrap_form_extensions.rb
|
120
|
+
- lib/bootstrap_form_extensions/arrayed_field.rb
|
121
|
+
- lib/bootstrap_form_extensions/date_time_pickers.rb
|
122
|
+
- lib/bootstrap_form_extensions/helpers.rb
|
123
|
+
- lib/bootstrap_form_extensions/scheduler.rb
|
124
|
+
- lib/bootstrap_form_extensions/select_or_new.rb
|
125
|
+
- lib/bootstrap_form_extensions/submit_bar.rb
|
126
|
+
- lib/bootstrap_form_extensions/timespan.rb
|
127
|
+
- lib/bootstrap_form_extensions/version.rb
|
128
|
+
- lib/tasks/rails_bootstrap_form_extensions_tasks.rake
|
129
|
+
- test/arrayed_field_test.rb
|
130
|
+
- test/bootstrap_form_extensions_test.rb
|
131
|
+
- test/date_time_pickers_test.rb
|
132
|
+
- test/dummy/README.rdoc
|
133
|
+
- test/dummy/Rakefile
|
134
|
+
- test/dummy/app/assets/javascripts/application.js
|
135
|
+
- test/dummy/app/assets/stylesheets/application.css
|
136
|
+
- test/dummy/app/controllers/application_controller.rb
|
137
|
+
- test/dummy/app/helpers/application_helper.rb
|
138
|
+
- test/dummy/app/models/category.rb
|
139
|
+
- test/dummy/app/models/thing.rb
|
140
|
+
- test/dummy/app/views/layouts/application.html.erb
|
141
|
+
- test/dummy/bin/bundle
|
142
|
+
- test/dummy/bin/rails
|
143
|
+
- test/dummy/bin/rake
|
144
|
+
- test/dummy/bin/setup
|
145
|
+
- test/dummy/config.ru
|
146
|
+
- test/dummy/config/application.rb
|
147
|
+
- test/dummy/config/boot.rb
|
148
|
+
- test/dummy/config/database.yml
|
149
|
+
- test/dummy/config/environment.rb
|
150
|
+
- test/dummy/config/environments/development.rb
|
151
|
+
- test/dummy/config/environments/production.rb
|
152
|
+
- test/dummy/config/environments/test.rb
|
153
|
+
- test/dummy/config/initializers/assets.rb
|
154
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
155
|
+
- test/dummy/config/initializers/cookies_serializer.rb
|
156
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
157
|
+
- test/dummy/config/initializers/inflections.rb
|
158
|
+
- test/dummy/config/initializers/mime_types.rb
|
159
|
+
- test/dummy/config/initializers/session_store.rb
|
160
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
161
|
+
- test/dummy/config/locales/en.yml
|
162
|
+
- test/dummy/config/routes.rb
|
163
|
+
- test/dummy/config/secrets.yml
|
164
|
+
- test/dummy/db/migrate/20150918185031_create_things.rb
|
165
|
+
- test/dummy/db/migrate/20150924203053_add_timespan.rb
|
166
|
+
- test/dummy/db/migrate/20150929213249_add_arrayed_field.rb
|
167
|
+
- test/dummy/db/migrate/20151006171627_add_another_arrayed_field.rb
|
168
|
+
- test/dummy/db/migrate/20151006181943_add_json_field.rb
|
169
|
+
- test/dummy/db/migrate/20151007213131_add_scheduler_field.rb
|
170
|
+
- test/dummy/db/migrate/20151030194330_add_date_time.rb
|
171
|
+
- test/dummy/db/migrate/20151106165522_add_category.rb
|
172
|
+
- test/dummy/db/schema.rb
|
173
|
+
- test/dummy/db/test.sqlite3
|
174
|
+
- test/dummy/log/development.log
|
175
|
+
- test/dummy/log/test.log
|
176
|
+
- test/dummy/public/404.html
|
177
|
+
- test/dummy/public/422.html
|
178
|
+
- test/dummy/public/500.html
|
179
|
+
- test/dummy/public/favicon.ico
|
180
|
+
- test/dummy/test/fixtures/things.yml
|
181
|
+
- test/javascripts/arrayed_field_spec.js
|
182
|
+
- test/javascripts/helpers/function_bind_polyfill_for_phantomjs.js
|
183
|
+
- test/javascripts/helpers/jasmine-jquery.js
|
184
|
+
- test/javascripts/scheduler_spec.js
|
185
|
+
- test/javascripts/select_or_new_spec.js
|
186
|
+
- test/javascripts/support/jasmine.yml
|
187
|
+
- test/javascripts/support/jasmine_helper.rb
|
188
|
+
- test/javascripts/time_picker_spec.js
|
189
|
+
- test/javascripts/timespan_spec.js
|
190
|
+
- test/javascripts/vendor/bootstrap.min.js
|
191
|
+
- test/javascripts/vendor/jquery-2.1.4.min.js
|
192
|
+
- test/scheduler_serializer_test.rb
|
193
|
+
- test/scheduler_test.rb
|
194
|
+
- test/select_or_new_test.rb
|
195
|
+
- test/submit_bar_test.rb
|
196
|
+
- test/test_helper.rb
|
197
|
+
- test/timespan_test.rb
|
198
|
+
homepage: http://github.com/jdugarte/rails-bootstrap-form-extensions/
|
199
|
+
licenses:
|
200
|
+
- MIT
|
201
|
+
metadata: {}
|
202
|
+
post_install_message:
|
203
|
+
rdoc_options: []
|
204
|
+
require_paths:
|
205
|
+
- lib
|
206
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
207
|
+
requirements:
|
208
|
+
- - ">="
|
209
|
+
- !ruby/object:Gem::Version
|
210
|
+
version: '0'
|
211
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
requirements: []
|
217
|
+
rubyforge_project:
|
218
|
+
rubygems_version: 2.2.3
|
219
|
+
signing_key:
|
220
|
+
specification_version: 4
|
221
|
+
summary: Specialized controls added to the bootstrap_form gem
|
222
|
+
test_files:
|
223
|
+
- test/arrayed_field_test.rb
|
224
|
+
- test/bootstrap_form_extensions_test.rb
|
225
|
+
- test/date_time_pickers_test.rb
|
226
|
+
- test/dummy/app/assets/javascripts/application.js
|
227
|
+
- test/dummy/app/assets/stylesheets/application.css
|
228
|
+
- test/dummy/app/controllers/application_controller.rb
|
229
|
+
- test/dummy/app/helpers/application_helper.rb
|
230
|
+
- test/dummy/app/models/category.rb
|
231
|
+
- test/dummy/app/models/thing.rb
|
232
|
+
- test/dummy/app/views/layouts/application.html.erb
|
233
|
+
- test/dummy/bin/bundle
|
234
|
+
- test/dummy/bin/rails
|
235
|
+
- test/dummy/bin/rake
|
236
|
+
- test/dummy/bin/setup
|
237
|
+
- test/dummy/config/application.rb
|
238
|
+
- test/dummy/config/boot.rb
|
239
|
+
- test/dummy/config/database.yml
|
240
|
+
- test/dummy/config/environment.rb
|
241
|
+
- test/dummy/config/environments/development.rb
|
242
|
+
- test/dummy/config/environments/production.rb
|
243
|
+
- test/dummy/config/environments/test.rb
|
244
|
+
- test/dummy/config/initializers/assets.rb
|
245
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
246
|
+
- test/dummy/config/initializers/cookies_serializer.rb
|
247
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
248
|
+
- test/dummy/config/initializers/inflections.rb
|
249
|
+
- test/dummy/config/initializers/mime_types.rb
|
250
|
+
- test/dummy/config/initializers/session_store.rb
|
251
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
252
|
+
- test/dummy/config/locales/en.yml
|
253
|
+
- test/dummy/config/routes.rb
|
254
|
+
- test/dummy/config/secrets.yml
|
255
|
+
- test/dummy/config.ru
|
256
|
+
- test/dummy/db/migrate/20150918185031_create_things.rb
|
257
|
+
- test/dummy/db/migrate/20150924203053_add_timespan.rb
|
258
|
+
- test/dummy/db/migrate/20150929213249_add_arrayed_field.rb
|
259
|
+
- test/dummy/db/migrate/20151006171627_add_another_arrayed_field.rb
|
260
|
+
- test/dummy/db/migrate/20151006181943_add_json_field.rb
|
261
|
+
- test/dummy/db/migrate/20151007213131_add_scheduler_field.rb
|
262
|
+
- test/dummy/db/migrate/20151030194330_add_date_time.rb
|
263
|
+
- test/dummy/db/migrate/20151106165522_add_category.rb
|
264
|
+
- test/dummy/db/schema.rb
|
265
|
+
- test/dummy/db/test.sqlite3
|
266
|
+
- test/dummy/log/development.log
|
267
|
+
- test/dummy/log/test.log
|
268
|
+
- test/dummy/public/404.html
|
269
|
+
- test/dummy/public/422.html
|
270
|
+
- test/dummy/public/500.html
|
271
|
+
- test/dummy/public/favicon.ico
|
272
|
+
- test/dummy/Rakefile
|
273
|
+
- test/dummy/README.rdoc
|
274
|
+
- test/dummy/test/fixtures/things.yml
|
275
|
+
- test/javascripts/arrayed_field_spec.js
|
276
|
+
- test/javascripts/helpers/function_bind_polyfill_for_phantomjs.js
|
277
|
+
- test/javascripts/helpers/jasmine-jquery.js
|
278
|
+
- test/javascripts/scheduler_spec.js
|
279
|
+
- test/javascripts/select_or_new_spec.js
|
280
|
+
- test/javascripts/support/jasmine.yml
|
281
|
+
- test/javascripts/support/jasmine_helper.rb
|
282
|
+
- test/javascripts/time_picker_spec.js
|
283
|
+
- test/javascripts/timespan_spec.js
|
284
|
+
- test/javascripts/vendor/bootstrap.min.js
|
285
|
+
- test/javascripts/vendor/jquery-2.1.4.min.js
|
286
|
+
- test/scheduler_serializer_test.rb
|
287
|
+
- test/scheduler_test.rb
|
288
|
+
- test/select_or_new_test.rb
|
289
|
+
- test/submit_bar_test.rb
|
290
|
+
- test/test_helper.rb
|
291
|
+
- test/timespan_test.rb
|