simple_form-bootstrap 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  module SimpleForm; end
2
2
  module SimpleForm::Bootstrap
3
- VERSION = '1.1.2'
3
+ VERSION = '1.2.0'
4
4
  end
@@ -0,0 +1,40 @@
1
+ $:.push("#{__dir__}/lib")
2
+ require 'simple_form/bootstrap/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'simple_form-bootstrap'
6
+ s.version = SimpleForm::Bootstrap::VERSION
7
+ s.authors = ['Joel Low']
8
+ s.email = 'joel@joelsplace.sg'
9
+
10
+ s.homepage = 'https://github.com/lowjoel/simple_form-bootstrap'
11
+ s.rubygems_version = '2.2.2'
12
+ s.license = 'MIT'
13
+ s.description = 'Initialises Simple Form to automatically produce Bootstrap 3-friendly markup'
14
+ s.summary = <<SUMMARY
15
+ Initialises Simple Form to automatically produce Bootstrap 3-friendly markup. Also adds date and
16
+ time pickers.
17
+ SUMMARY
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.require_paths = ['lib']
22
+
23
+ s.add_dependency 'bootstrap-sass', '~> 3'
24
+ s.add_dependency 'simple_form', '>= 3.1.0'
25
+
26
+ s.add_dependency 'activemodel', '~> 4.0'
27
+ s.add_dependency 'actionpack', '~> 4.0'
28
+ s.add_dependency 'railties', '~> 4.0'
29
+
30
+ s.add_development_dependency 'rspec', '~> 3'
31
+ s.add_development_dependency 'rspec-rails', '~> 3'
32
+ s.add_development_dependency 'rspec-html-matchers'
33
+
34
+ s.add_development_dependency 'coveralls'
35
+ s.add_development_dependency 'codeclimate-test-reporter'
36
+
37
+ if s.respond_to? :required_rubygems_version=
38
+ s.required_rubygems_version = Gem::Requirement.new('>= 0')
39
+ end
40
+ end
@@ -0,0 +1,63 @@
1
+ require 'simplecov'
2
+
3
+ module CoverageHelper
4
+ class << self
5
+ # Helper to include Coveralls/Code Climate coverage, but not require developers to install the
6
+ # gem.
7
+ #
8
+ # @param name [String] The name of the module to require.
9
+ # @param initializer [Proc] The block to execute when the module is required successfully.
10
+ def load(name, &initializer)
11
+ old_formatter = SimpleCov.formatter
12
+ require name
13
+ initializer.call
14
+
15
+ merge_formatters(old_formatter, SimpleCov.formatter)
16
+ rescue LoadError => e
17
+ if e.path == name
18
+ puts format('Cannot find \'%s\', ignoring', name) if ENV['CI']
19
+ else
20
+ raise e
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ # Merge two SimpleCov formatters into a single MultiFormatter.
27
+ #
28
+ # This method is idempotent if the old and new formatters are the same.
29
+ def merge_formatters(old_formatter, new_formatter)
30
+ return if old_formatter == new_formatter
31
+
32
+ old_formatter = [*expand_formatter(old_formatter)]
33
+ new_formatter = [*expand_formatter(new_formatter)]
34
+ formatters = old_formatter + new_formatter
35
+
36
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[*formatters]
37
+ end
38
+
39
+ # Extracts the formatters from a MultiFormatter so we do not nest them.
40
+ def expand_formatter(formatter)
41
+ return formatter unless formatter.is_a?(SimpleCov::Formatter::MultiFormatter)
42
+ formatter.formatters
43
+ end
44
+ end
45
+ end
46
+
47
+ if ENV['CI']
48
+ # Coveralls
49
+ CoverageHelper.load('coveralls') do
50
+ Coveralls.wear!('rails')
51
+ end
52
+
53
+ # Code Climate
54
+ CoverageHelper.load('codeclimate-test-reporter') do
55
+ CodeClimate::TestReporter.start
56
+ end
57
+ end
58
+
59
+ # Code coverage exclusions
60
+ SimpleCov.start do
61
+ # Helpers for schema migrations. We don't test schema migrations, so these would never run.
62
+ add_filter '/lib/extensions/active_record/connection_adapters/table_definition.rb'
63
+ end
@@ -0,0 +1,45 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV['RAILS_ENV'] ||= 'test'
3
+ require 'spec_helper'
4
+ require 'rails'
5
+ require 'action_view'
6
+ require 'action_controller'
7
+ require 'active_model'
8
+ require 'rspec/rails'
9
+ # Add additional requires below this line. Rails is not loaded until this point!
10
+
11
+ require 'simple_form'
12
+ require 'simple_form/bootstrap'
13
+ SimpleForm.setup do; end
14
+
15
+ # Requires supporting ruby files with custom matchers and macros, etc, in
16
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
17
+ # run as spec files by default. This means that files in spec/support that end
18
+ # in _spec.rb will both be required and run as specs, causing the specs to be
19
+ # run twice. It is recommended that you do not name files matching this glob to
20
+ # end with _spec.rb. You can configure this pattern with the --pattern
21
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
22
+ #
23
+ # The following line is provided for convenience purposes. It has the downside
24
+ # of increasing the boot-up time by auto-requiring all files in the support
25
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
26
+ # require only the support files necessary.
27
+ #
28
+ Dir[__dir__ + '/support/**/*.rb'].each { |f| require f }
29
+
30
+ RSpec.configure do |config|
31
+ # RSpec Rails can automatically mix in different behaviours to your tests
32
+ # based on their file location, for example enabling you to call `get` and
33
+ # `post` in specs under `spec/controllers`.
34
+ #
35
+ # You can disable this behaviour by removing the line below, and instead
36
+ # explicitly tag your specs with their type, e.g.:
37
+ #
38
+ # RSpec.describe UsersController, :type => :controller do
39
+ # # ...
40
+ # end
41
+ #
42
+ # The different available types are documented in the features, such as in
43
+ # https://relishapp.com/rspec/rspec-rails/docs
44
+ config.infer_spec_type_from_file_location!
45
+ end
@@ -0,0 +1,85 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe 'button', type: :view do
4
+ class Button
5
+ extend ActiveModel::Naming
6
+ include ActiveModel::Conversion
7
+
8
+ def persisted?
9
+ true
10
+ end
11
+
12
+ def test
13
+ end
14
+ end
15
+
16
+ let(:button_type) { :button }
17
+ let(:button_text) { 'Button!' }
18
+ let(:button_options) { {} }
19
+ let(:button_block) { nil }
20
+ subject! do
21
+ object = Button.new
22
+ simple_form_for object, url: 'test' do |f|
23
+ f.button button_type, button_text, button_options, &button_block
24
+ end
25
+ render text: output_buffer
26
+ end
27
+
28
+ it 'displays the button' do
29
+ expect(rendered).to have_tag('button', text: button_text)
30
+ end
31
+
32
+ it 'includes the btn class' do
33
+ expect(rendered).to have_tag('button.btn', text: button_text)
34
+ end
35
+
36
+ context 'when no button class is specified' do
37
+ it 'includes the btn-default class' do
38
+ expect(rendered).to have_tag('button.btn.btn-default', text: button_text)
39
+ end
40
+ end
41
+
42
+ context 'when a button type is specified' do
43
+ let(:button_class) { ['btn-primary'] }
44
+ let(:button_options) { { class: button_class } }
45
+ it 'does not include the default button type' do
46
+ expect(rendered).not_to have_tag('button.btn.btn-default', text: button_text)
47
+ end
48
+
49
+ it 'includes the specified button type' do
50
+ expect(rendered).to have_tag('button.btn.btn-primary', text: button_text)
51
+ end
52
+ end
53
+
54
+ context 'when a button size is specified' do
55
+ let(:button_class) { ['btn-lg'] }
56
+ let(:button_options) { { class: button_class } }
57
+ it 'includes the btn-default class' do
58
+ expect(rendered).to have_tag('button.btn.btn-default.btn-lg', text: button_text)
59
+ end
60
+ end
61
+
62
+ context 'when creating a submit button' do
63
+ let(:button_type) { :submit }
64
+ context 'when no button class is specified' do
65
+ let(:button_class) { ['btn-primary'] }
66
+ let(:button_options) { { class: button_class } }
67
+ it 'includes the btn-primary class' do
68
+ expect(rendered).to have_tag('input.btn.btn-primary', with: { value: button_text })
69
+ end
70
+ end
71
+
72
+ context 'when a block is given' do
73
+ let(:proc_text) { 'I am in the proc!' }
74
+ let(:button_block) do
75
+ proc do
76
+ proc_text
77
+ end
78
+ end
79
+
80
+ it 'renders the block' do
81
+ expect(rendered).to have_tag('button', text: proc_text)
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,69 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe 'date_time', type: :view do
4
+ class DateTimeModel
5
+ extend ActiveModel::Naming
6
+ include ActiveModel::Conversion
7
+
8
+ def initialize(column_sql_type)
9
+ @column_sql_type = column_sql_type
10
+ end
11
+
12
+ def persisted?
13
+ true
14
+ end
15
+
16
+ def column_for_attribute(*)
17
+ Struct.new(:sql_type).new(@column_sql_type)
18
+ end
19
+
20
+ def has_attribute?(*)
21
+ true
22
+ end
23
+
24
+ def test
25
+ @test ||= DateTime.now
26
+ end
27
+ end
28
+
29
+ subject! do
30
+ simple_form_for object, url: 'test' do |f|
31
+ f.input :test
32
+ end
33
+ render text: output_buffer
34
+ end
35
+
36
+ context 'when the database column is a datetime' do
37
+ let(:object) { DateTimeModel.new('datetime') }
38
+ it 'displays the text field' do
39
+ expect(rendered).to have_tag('div.form-group.bootstrap_date_time') do
40
+ with_tag('input.bootstrap_date_time', with: { value: object.test })
41
+ end
42
+ end
43
+
44
+ it 'has a hidden datepicker control' do
45
+ selector = 'div.form-group.bootstrap_date_time div.input-group'
46
+ required_style = { style: 'display: none' }
47
+
48
+ expect(rendered).to have_tag(selector, with: required_style) do
49
+ with_tag('input.bootstrap_date_time', with: { type: 'hidden' })
50
+ end
51
+ end
52
+ end
53
+
54
+ context 'when the database column is a date' do
55
+ let(:object) { DateTimeModel.new('date') }
56
+ it 'displays the text field' do
57
+ expect(rendered).to have_tag('div.form-group.bootstrap_date') do
58
+ with_tag('input.bootstrap_date', with: { value: object.test })
59
+ end
60
+ end
61
+ end
62
+
63
+ context 'when the database column is not a datetime' do
64
+ let(:object) { DateTimeModel.new('string') }
65
+ it 'does not have a datepicker control' do
66
+ expect(rendered).not_to have_tag('div.form-group.bootstrap_date_time')
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe SimpleForm do
4
+ describe '.setup' do
5
+ it 'yields self' do
6
+ result = nil
7
+ subject.setup do |config|
8
+ result = config
9
+ end
10
+
11
+ expect(result).to equal(subject)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,90 @@
1
+ require 'rspec-html-matchers'
2
+ require 'coverage_helper'
3
+
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need
16
+ # it.
17
+ #
18
+ # The `.rspec` file also contains a few flags that are not defaults but that
19
+ # users commonly want.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+ RSpec.configure do |config|
23
+ # rspec-expectations config goes here. You can use an alternate
24
+ # assertion/expectation library such as wrong or the stdlib/minitest
25
+ # assertions if you prefer.
26
+ config.expect_with :rspec do |expectations|
27
+ # This option will default to `true` in RSpec 4. It makes the `description`
28
+ # and `failure_message` of custom matchers include text for helper methods
29
+ # defined using `chain`, e.g.:
30
+ # be_bigger_than(2).and_smaller_than(4).description
31
+ # # => "be bigger than 2 and smaller than 4"
32
+ # ...rather than:
33
+ # # => "be bigger than 2"
34
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
+ end
36
+
37
+ # rspec-mocks config goes here. You can use an alternate test double
38
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
39
+ config.mock_with :rspec do |mocks|
40
+ # Prevents you from mocking or stubbing a method that does not exist on
41
+ # a real object. This is generally recommended, and will default to
42
+ # `true` in RSpec 4.
43
+ mocks.verify_partial_doubles = true
44
+ end
45
+
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is
54
+ # recommended. For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.configure do
2
+ ActionView::RoutingUrlFor.class_eval do
3
+ include ActionDispatch::Routing::UrlFor
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ # Adapted from SimpleForm's mock controller
2
+ class MockController
3
+ attr_writer :action_name
4
+
5
+ def _routes
6
+ self
7
+ end
8
+
9
+ def action_name
10
+ defined?(@action_name) ? @action_name : "edit"
11
+ end
12
+
13
+ def named_routes
14
+ self
15
+ end
16
+ def route_defined?(selector)
17
+ false
18
+ end
19
+ def mounted_helpers
20
+ self
21
+ end
22
+ def method_defined?(selector)
23
+ false
24
+ end
25
+ end
26
+
27
+ module MockControllerAdditions
28
+ def self.included(module_)
29
+ module_.setup :set_controller
30
+ end
31
+
32
+ def set_controller
33
+ @controller = MockController.new
34
+ end
35
+ end
36
+
37
+ RSpec.configure do |config|
38
+ config.include MockControllerAdditions, type: :view
39
+ end