diff --git a/.gitignore b/.gitignore index ca20e21f3..8540dd815 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,5 @@ test/dummy/tmp/ *.gem .rbenv-gemsets *.swp -gemfiles/*.lock Gemfile.lock +.ruby-version diff --git a/.travis.yml b/.travis.yml index 42528216c..36d6d7d81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,28 +1,29 @@ -sudo: false language: ruby rvm: - - 1.9 - - 2.0 - - 2.1 - - 2.2 - - 2.3.1 + - 2.2.9 + - 2.3.6 + - 2.4.3 + - 2.5.0 gemfile: - - gemfiles/4.0.gemfile - - gemfiles/4.1.gemfile - - gemfiles/4.2.gemfile + - test/gemfiles/5.0.gemfile + - test/gemfiles/5.1.gemfile + - test/gemfiles/5.2.gemfile +before_install: + - gem update --system + - gem install bundler --no-document + matrix: include: - - rvm: 2.2.2 - gemfile: gemfiles/5.0.gemfile - - rvm: 2.3.1 - gemfile: gemfiles/5.0.gemfile - # Run Danger only once - script: bundle exec danger - - rvm: 2.2.2 - gemfile: gemfiles/5.1.gemfile - - rvm: 2.3.1 - gemfile: gemfiles/5.1.gemfile -before_install: - - gem install bundler --conservative --version '~> 1.10' -before_script: - - bundle exec rake -f test/dummy/Rakefile db:create db:migrate RAILS_ENV=test + # Bleeding edge + - rvm: ruby-head + gemfile: test/gemfiles/5.2.gemfile + + # Running one job to execute DANGER bot + - rvm: 2.5.0 + gemfile: test/gemfiles/5.2.gemfile + script: + - gem install danger + - danger + + allow_failures: + - rvm: ruby-head diff --git a/Appraisals b/Appraisals deleted file mode 100644 index 0af3c431b..000000000 --- a/Appraisals +++ /dev/null @@ -1,28 +0,0 @@ -appraise "4.0" do - gem "rails", "~> 4.0.0" - # nokogiri 1.7+ is not compatible with Ruby < 2.1, so pin at older version. - gem "nokogiri", "~> 1.6.8", platforms: [:ruby_19, :ruby_20] -end - -appraise "4.1" do - gem "rails", "~> 4.1.0" - # nokogiri 1.7+ is not compatible with Ruby < 2.1, so pin at older version. - gem "nokogiri", "~> 1.6.8", platforms: [:ruby_19, :ruby_20] -end - -appraise "4.2" do - gem "rails", "~> 4.2.0" - # nokogiri 1.7+ is not compatible with Ruby < 2.1, so pin at older version. - gem "nokogiri", "~> 1.6.8", platforms: [:ruby_19, :ruby_20] -end - -appraise "5.0" do - gem "rails", "~> 5.0.0" - gem "minitest", "< 5.10.2" - gem "danger" -end - -appraise "5.1" do - gem "rails", "~> 5.1.0" - gem "minitest", "< 5.10.2" -end diff --git a/CHANGELOG.md b/CHANGELOG.md index 923ceef97..fa41ccda6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Bugfixes: Features: - Your contribution here! + * [#344](https://github.com/bootstrap-ruby/rails-bootstrap-forms/pull/344): Allow HTML in help translations by using the '_html' suffix on the key - [@unikitty37](https://github.com/unikitty37) * [#325](https://github.com/bootstrap-ruby/rails-bootstrap-forms/pull/325): Support :prepend and :append for the `select` helper - [@donv](https://github.com/donv). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f8c9dd656..62a02439b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,53 +1,57 @@ # Contributing -The release of Bootstrap 4 and Rails 5.1 have implications -for the future direction of `bootstrap_form`. -Don't worry. -We plan to move this gem forward to Bootstrap 4 -and to support Rails 5.1 and beyond. -If you're thinking of contributing to `bootstrap_form`, -please read [issue #361](https://github.com/bootstrap-ruby/rails-bootstrap-forms/issues/361). +The release of Bootstrap 4 and Rails 5.1 have implications for the future +direction of `bootstrap_form`. Don't worry. We plan to move this gem forward to +Bootstrap 4 and to support Rails 5.1 and beyond. If you're thinking of +contributing to `bootstrap_form`, please read +[issue #361](https://github.com/bootstrap-ruby/rails-bootstrap-forms/issues/361). + Your comments are welcome. -Thanks so much for considering contributing to bootstrap_form! -We love pull requests! +Thanks so much for considering a contribution to bootstrap_form. We love pull requests! Here's a quick guide for contributing: -1. Make sure no one else is working on the same issue or feature. -Search the issues and pull requests for anything -that looks like the issue or feature you want to address. -If no one else is working on your issue or feature, -carry on with the following steps. +### 1. Check if issue or feature is available to work on + +Make sure no one else is working on the same issue or feature. Search the issues +and pull requests for anything that looks like the issue or feature you want to +address. If no one else is working on your issue or feature, carry on with the +following steps. + +### 2. Fork the repo + +For the project. Optionally, create a branch you want to work on -2. Fork the repo. +### 3. Get it running locally -2. Install the required dependencies. +- Install the required dependencies with `bundle install` +- Run tests via: `bundle exec rake` -``` -bundle install -bundle exec appraisal install -``` +### 4. Hack away -3. Run the existing test suite: +- Try to keep your changes small. Consider making several smaller pull requests. +- Don't forget to add necessary tests. +- Update the README if necessary. +- Add a line to the CHANGELOG for your bug fix or feature. -``` -$ bundle exec rake -f test/dummy/Rakefile db:create db:migrate RAILS_ENV=test -$ bundle exec appraisal rake test -``` +You may find using test/dummy application useful for development and debugging. -4. Add tests for your change. +- `cd test/dummy` +- `rake db:schema:load` +- `rails s` +- Navigate to http://localhost:3000 -5. Add your changes and make your test(s) pass. Following the conventions you -see used in the source will increase the chance that your pull request is -accepted right away. +### 5. Make a Pull Request -6. Update the README if necessary. +- If you never done it before read this: https://help.github.com/articles/about-pull-requests/ +- When PR is submitted check if TravisCI ran all tests successfully didn't raise any issues -7. Add a line to the CHANGELOG for your bug fix or feature. +### 6. Done! -8. Push to your fork and submit a pull request. +Somebody will shortly review your pull request and if everything is good will be +merged into master brach. Eventually gem will be published with your changes. -## Contributors +--- Thanks to all the great contributors over the years: https://github.com/bootstrap-ruby/rails-bootstrap-forms/graphs/contributors diff --git a/Gemfile b/Gemfile index a65ccd187..1112f4f7b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,17 +1,20 @@ source "http://rubygems.org" -# Declare your gem's dependencies in bootstrap_form.gemspec. -# Bundler will treat runtime dependencies like base dependencies, and -# development dependencies will be added by default to the :development group. gemspec -# jquery-rails is used by the dummy application -gem "jquery-rails" +# Uncomment and change rails version for testing purposes +# gem "rails", "~> 5.2.0.beta2" -# Declare any dependencies that are still in development here instead of in -# your gemspec. These might include edge Rails or gems from your path or -# Git. Remember to move these dependencies to your gemspec before releasing -# your gem to rubygems.org. +group :development do + gem "htmlbeautifier" +end -# To use debugger -# gem 'ruby-debug19', :require => 'ruby-debug' +group :test do + gem "diffy" + gem "equivalent-xml" + gem "mocha" + gem "sqlite3" + gem "timecop", "~> 0.7.1" +end + +gem "minitest", "~> 5.10.3" diff --git a/README.md b/README.md index 1ffd77618..a6102cc70 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,16 @@ en: password: "A good password should be at least six characters long" ``` +Help translations containing HTML should follow the convention of appending `_html` to the name: + +```yml +en: + activerecord: + help: + user: + password_html: "A good password should be at least six characters long" +``` + If your model name has multiple words (like `SuperUser`), the key on the translation file should be underscored (`super_user`). @@ -269,7 +279,7 @@ You still can use `wrapper_class` option to set only a css class. This is just a Our select helper accepts the same arguments as the [default Rails helper](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select). Here's an example of how you pass both options and html_options hashes: ```erb -<%= f.select :product, [["Apple", 1], ["Grape", 2]], { label: "Choose your favorite fruit:" }, { class: "selectpicker" } %> +<%= f.select :product, [["Apple", 1], ["Grape", 2]], { label: "Choose your favorite fruit:" }, { class: "selectpicker", wrapper: { class: 'has-warning', data: { foo: 'bar' } } } %> ``` ### Checkboxes and Radios diff --git a/Rakefile b/Rakefile index 8a5484318..708c7b858 100644 --- a/Rakefile +++ b/Rakefile @@ -1,37 +1,27 @@ -#!/usr/bin/env rake begin require 'bundler/setup' rescue LoadError puts 'You must `gem install bundler` and `bundle install` to run rake tasks' end -begin - require 'rdoc/task' -rescue LoadError - require 'rdoc/rdoc' - require 'rake/rdoctask' - RDoc::Task = Rake::RDocTask -end + +require 'rdoc/task' RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = 'BootstrapForm' rdoc.options << '--line-numbers' - rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('README.md') rdoc.rdoc_files.include('lib/**/*.rb') end - - -Bundler::GemHelper.install_tasks +require 'bundler/gem_tasks' require 'rake/testtask' Rake::TestTask.new(:test) do |t| - t.libs << 'lib' t.libs << 'test' t.pattern = 'test/**/*_test.rb' t.verbose = false end - -task :default => :test +task default: :test diff --git a/bootstrap_form.gemspec b/bootstrap_form.gemspec index 02eefe81e..5a0a9699a 100644 --- a/bootstrap_form.gemspec +++ b/bootstrap_form.gemspec @@ -1,8 +1,8 @@ -lib = File.expand_path("../lib", __FILE__) +lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + require "bootstrap_form/version" -# Describe your gem and declare its dependencies: Gem::Specification.new do |s| s.name = "bootstrap_form" s.version = BootstrapForm::VERSION @@ -16,17 +16,13 @@ Gem::Specification.new do |s| s.license = "MIT" s.files = `git ls-files -z`.split("\x0").reject do |f| - f.match(%r{^(test|spec|features)/}) + f.match(%r{^(test)/}) end - s.bindir = "exe" - s.add_development_dependency "appraisal" - s.add_development_dependency "diffy" - s.add_development_dependency "equivalent-xml" - s.add_development_dependency "mime-types", "~> 2.6.2" - s.add_development_dependency "mocha" - s.add_development_dependency "nokogiri" - s.add_development_dependency "rails", ">= 4.0" - s.add_development_dependency "sqlite3" - s.add_development_dependency "timecop", "~> 0.7.1" + s.bindir = "exe" + s.require_paths = ["lib"] + + s.required_ruby_version = ">= 2.2.2" + + s.add_dependency "rails", ">= 5.0" end diff --git a/gemfiles/4.0.gemfile b/gemfiles/4.0.gemfile deleted file mode 100644 index 976d756ea..000000000 --- a/gemfiles/4.0.gemfile +++ /dev/null @@ -1,9 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "jquery-rails" -gem "rails", "~> 4.0.0" -gem "nokogiri", "~> 1.6.8", platforms: [:ruby_19, :ruby_20] - -gemspec path: "../" diff --git a/gemfiles/4.1.gemfile b/gemfiles/4.1.gemfile deleted file mode 100644 index 5d937d0f7..000000000 --- a/gemfiles/4.1.gemfile +++ /dev/null @@ -1,9 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "jquery-rails" -gem "rails", "~> 4.1.0" -gem "nokogiri", "~> 1.6.8", platforms: [:ruby_19, :ruby_20] - -gemspec path: "../" diff --git a/gemfiles/4.2.gemfile b/gemfiles/4.2.gemfile deleted file mode 100644 index a5995131c..000000000 --- a/gemfiles/4.2.gemfile +++ /dev/null @@ -1,9 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "jquery-rails" -gem "rails", "~> 4.2.0" -gem "nokogiri", "~> 1.6.8", platforms: [:ruby_19, :ruby_20] - -gemspec path: "../" diff --git a/gemfiles/5.0.gemfile b/gemfiles/5.0.gemfile deleted file mode 100644 index b57e347dd..000000000 --- a/gemfiles/5.0.gemfile +++ /dev/null @@ -1,10 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "jquery-rails" -gem "rails", "~> 5.0.0" -gem "minitest", "< 5.10.2" -gem "danger" - -gemspec path: "../" diff --git a/gemfiles/5.1.gemfile b/gemfiles/5.1.gemfile deleted file mode 100644 index 0d55c51c1..000000000 --- a/gemfiles/5.1.gemfile +++ /dev/null @@ -1,9 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "jquery-rails" -gem "rails", "~> 5.1.0" -gem "minitest", "< 5.10.2" - -gemspec path: "../" diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index 423360e6e..74871db44 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -452,6 +452,11 @@ def get_help_text_by_i18n_key(name) warn "I18n key '#{downcased_scope}.#{name}' is deprecated, use '#{underscored_scope}.#{name}' instead" text end + help_text ||= I18n.t("#{name}_html", scope: underscored_scope, default: '').html_safe.presence + help_text ||= if text = I18n.t("#{name}_html", scope: downcased_scope, default: '').html_safe.presence + warn "I18n key '#{downcased_scope}.#{name}' is deprecated, use '#{underscored_scope}.#{name}' instead" + text + end help_text end end diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 7e0d69683..ff286ecc3 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -197,6 +197,19 @@ def setup assert_equivalent_xml expected, output end + test "help translations do not escape HTML when _html is appended to the name" do + I18n.backend.store_translations(:en, {activerecord: {help: {user: {email_html: "This is useful help"}}}}) + + output = bootstrap_form_for(@user) do |f| + f.text_field(:email) + end + + expected = %{
} + assert_equivalent_xml expected, output + + I18n.backend.store_translations(:en, {activerecord: {help: {user: {email_html: nil}}}}) + end + test "allows the form object to be nil" do builder = BootstrapForm::FormBuilder.new :other_model, nil, self, {} expected = %{} diff --git a/test/dummy/.gitignore b/test/dummy/.gitignore deleted file mode 100644 index 25a742dff..000000000 --- a/test/dummy/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -# See http://help.github.com/ignore-files/ for more about ignoring files. -# -# If you find yourself ignoring temporary files generated by your text editor -# or operating system, you probably want to add a global ignore instead: -# git config --global core.excludesfile '~/.gitignore_global' - -# Ignore bundler config. -/.bundle - -# Ignore the default SQLite database. -/db/*.sqlite3 -/db/*.sqlite3-journal - -# Ignore all logfiles and tempfiles. -/log/*.log -/tmp diff --git a/test/dummy/Gemfile b/test/dummy/Gemfile deleted file mode 100644 index 30d54d47a..000000000 --- a/test/dummy/Gemfile +++ /dev/null @@ -1,45 +0,0 @@ -source 'https://rubygems.org' - -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '4.0.0' - -# Use sqlite3 as the database for Active Record -gem 'sqlite3' - -# Use SCSS for stylesheets -gem 'sass-rails', '~> 4.0.0' - -# Use Uglifier as compressor for JavaScript assets -gem 'uglifier', '>= 1.3.0' - -# Use CoffeeScript for .js.coffee assets and views -gem 'coffee-rails', '~> 4.0.0' - -# See https://github.com/sstephenson/execjs#readme for more supported runtimes -# gem 'therubyracer', platforms: :ruby - -# Use jquery as the JavaScript library -gem 'jquery-rails' - -# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks -gem 'turbolinks' - -# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder', '~> 1.2' - -group :doc do - # bundle exec rake doc:rails generates the API under doc/api. - gem 'sdoc', require: false -end - -# Use ActiveModel has_secure_password -# gem 'bcrypt-ruby', '~> 3.0.0' - -# Use unicorn as the app server -# gem 'unicorn' - -# Use Capistrano for deployment -# gem 'capistrano', group: :development - -# Use debugger -# gem 'debugger', group: [:development, :test] diff --git a/test/dummy/Gemfile.lock b/test/dummy/Gemfile.lock deleted file mode 100644 index c362f1900..000000000 --- a/test/dummy/Gemfile.lock +++ /dev/null @@ -1,120 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - actionmailer (4.0.0) - actionpack (= 4.0.0) - mail (~> 2.5.3) - actionpack (4.0.0) - activesupport (= 4.0.0) - builder (~> 3.1.0) - erubis (~> 2.7.0) - rack (~> 1.5.2) - rack-test (~> 0.6.2) - activemodel (4.0.0) - activesupport (= 4.0.0) - builder (~> 3.1.0) - activerecord (4.0.0) - activemodel (= 4.0.0) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.0) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.3) - activesupport (4.0.0) - i18n (~> 0.6, >= 0.6.4) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - arel (4.0.0) - atomic (1.1.10) - builder (3.1.4) - coffee-rails (4.0.0) - coffee-script (>= 2.2.0) - railties (>= 4.0.0.beta, < 5.0) - coffee-script (2.2.0) - coffee-script-source - execjs - coffee-script-source (1.6.2) - erubis (2.7.0) - execjs (1.4.0) - multi_json (~> 1.0) - hike (1.2.3) - i18n (0.6.4) - jbuilder (1.4.2) - activesupport (>= 3.0.0) - multi_json (>= 1.2.0) - jquery-rails (3.0.1) - railties (>= 3.0, < 5.0) - thor (>= 0.14, < 2.0) - json (1.8.0) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mime-types (1.23) - minitest (4.7.5) - multi_json (1.7.7) - polyglot (0.3.3) - rack (1.5.2) - rack-test (0.6.2) - rack (>= 1.0) - rails (4.0.0) - actionmailer (= 4.0.0) - actionpack (= 4.0.0) - activerecord (= 4.0.0) - activesupport (= 4.0.0) - bundler (>= 1.3.0, < 2.0) - railties (= 4.0.0) - sprockets-rails (~> 2.0.0) - railties (4.0.0) - actionpack (= 4.0.0) - activesupport (= 4.0.0) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.1.0) - rdoc (3.12.2) - json (~> 1.4) - sass (3.2.9) - sass-rails (4.0.0) - railties (>= 4.0.0.beta, < 5.0) - sass (>= 3.1.10) - sprockets-rails (~> 2.0.0) - sdoc (0.3.20) - json (>= 1.1.3) - rdoc (~> 3.10) - sprockets (2.10.0) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.0.0) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (~> 2.8) - sqlite3 (1.3.7) - thor (0.18.1) - thread_safe (0.1.0) - atomic - tilt (1.4.1) - treetop (1.4.14) - polyglot - polyglot (>= 0.3.1) - turbolinks (1.2.0) - coffee-rails - tzinfo (0.3.37) - uglifier (2.1.1) - execjs (>= 0.3.0) - multi_json (~> 1.0, >= 1.0.2) - -PLATFORMS - ruby - -DEPENDENCIES - coffee-rails (~> 4.0.0) - jbuilder (~> 1.2) - jquery-rails - rails (= 4.0.0) - sass-rails (~> 4.0.0) - sdoc - sqlite3 - turbolinks - uglifier (>= 1.3.0) diff --git a/test/dummy/README.md b/test/dummy/README.md new file mode 100644 index 000000000..592c2fcc2 --- /dev/null +++ b/test/dummy/README.md @@ -0,0 +1,17 @@ +# TEST DUMMY APP (Rails 5.2) + +Following files were added or changed: + +- db/schema.rb +- config/application.rb +- config/routes.rb +- app/models/{address,user,super_user,faux_user}.rb +- app/controllers/bootstrap_controller.rb +- app/views/layouts/application.html.erb +- app/views/bootstrap/form.html.erb + +### Usage + +- `rake db:schema:load` +- `rails s` +- Navigate to http://localhost:3000 diff --git a/test/dummy/README.rdoc b/test/dummy/README.rdoc deleted file mode 100644 index dd4e97e22..000000000 --- a/test/dummy/README.rdoc +++ /dev/null @@ -1,28 +0,0 @@ -== README - -This README would normally document whatever steps are necessary to get the -application up and running. - -Things you may want to cover: - -* Ruby version - -* System dependencies - -* Configuration - -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... - - -Please feel free to use a different markup language if you do not plan to run -rake doc:app. diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile index 03926c32f..e85f91391 100644 --- a/test/dummy/Rakefile +++ b/test/dummy/Rakefile @@ -1,10 +1,6 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require File.expand_path('../config/application', __FILE__) +require_relative 'config/application' -Dummy::Application.load_tasks - -if Rake::Task.task_defined?(:'db:check_protected_environments') - Rake::Task[:'db:check_protected_environments'].clear -end +Rails.application.load_tasks diff --git a/test/dummy/app/assets/images/.keep b/test/dummy/app/assets/images/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/app/assets/javascripts/application.js b/test/dummy/app/assets/javascripts/application.js deleted file mode 100644 index d6925fa43..000000000 --- a/test/dummy/app/assets/javascripts/application.js +++ /dev/null @@ -1,16 +0,0 @@ -// This is a manifest file that'll be compiled into application.js, which will include all the files -// listed below. -// -// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, -// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. -// -// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the -// compiled file. -// -// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details -// about supported directives. -// -//= require jquery -//= require jquery_ujs -//= require turbolinks -//= require_tree . diff --git a/test/dummy/app/assets/stylesheets/application.css b/test/dummy/app/assets/stylesheets/application.css deleted file mode 100644 index 3192ec897..000000000 --- a/test/dummy/app/assets/stylesheets/application.css +++ /dev/null @@ -1,13 +0,0 @@ -/* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the top of the - * compiled file, but it's generally better to create a new file per style scope. - * - *= require_self - *= require_tree . - */ diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb index d83690e1b..09705d12a 100644 --- a/test/dummy/app/controllers/application_controller.rb +++ b/test/dummy/app/controllers/application_controller.rb @@ -1,5 +1,2 @@ class ApplicationController < ActionController::Base - # Prevent CSRF attacks by raising an exception. - # For APIs, you may want to use :null_session instead. - protect_from_forgery with: :exception end diff --git a/test/dummy/app/controllers/bootstrap_controller.rb b/test/dummy/app/controllers/bootstrap_controller.rb new file mode 100644 index 000000000..b726db3e7 --- /dev/null +++ b/test/dummy/app/controllers/bootstrap_controller.rb @@ -0,0 +1,14 @@ +class BootstrapController < ApplicationController + helper_method :codemirror_html + + def form + @user = User.new + end + +private + + def codemirror_html(html) + HtmlBeautifier.beautify(html.strip.gsub(">", ">\n").gsub("<", "\n<")) + end + +end \ No newline at end of file diff --git a/test/dummy/app/controllers/concerns/.keep b/test/dummy/app/controllers/concerns/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/app/helpers/application_helper.rb b/test/dummy/app/helpers/application_helper.rb deleted file mode 100644 index de6be7945..000000000 --- a/test/dummy/app/helpers/application_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ApplicationHelper -end diff --git a/test/dummy/app/mailers/.keep b/test/dummy/app/mailers/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/app/models/.keep b/test/dummy/app/models/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/app/models/application_record.rb b/test/dummy/app/models/application_record.rb new file mode 100644 index 000000000..10a4cba84 --- /dev/null +++ b/test/dummy/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/test/dummy/app/models/concerns/.keep b/test/dummy/app/models/concerns/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/app/views/bootstrap/form.html.erb b/test/dummy/app/views/bootstrap/form.html.erb new file mode 100644 index 000000000..f5a003177 --- /dev/null +++ b/test/dummy/app/views/bootstrap/form.html.erb @@ -0,0 +1,13 @@ +You may have mistyped the address or the page may have moved.
-If you are the application owner check the logs for more information.
- - diff --git a/test/dummy/public/422.html b/test/dummy/public/422.html deleted file mode 100644 index fbb4b84d7..000000000 --- a/test/dummy/public/422.html +++ /dev/null @@ -1,58 +0,0 @@ - - - -Maybe you tried to change something you didn't have access to.
-If you are the application owner check the logs for more information.
- - diff --git a/test/dummy/public/500.html b/test/dummy/public/500.html deleted file mode 100644 index e9052d35b..000000000 --- a/test/dummy/public/500.html +++ /dev/null @@ -1,57 +0,0 @@ - - - -If you are the application owner check the logs for more information.
- - diff --git a/test/dummy/public/robots.txt b/test/dummy/public/robots.txt deleted file mode 100644 index 1a3a5e4dd..000000000 --- a/test/dummy/public/robots.txt +++ /dev/null @@ -1,5 +0,0 @@ -# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file -# -# To ban all spiders from the entire site uncomment the next two lines: -# User-agent: * -# Disallow: / diff --git a/test/dummy/test/controllers/.keep b/test/dummy/test/controllers/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/test/fixtures/.keep b/test/dummy/test/fixtures/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/test/fixtures/addresses.yml b/test/dummy/test/fixtures/addresses.yml deleted file mode 100644 index ba3212270..000000000 --- a/test/dummy/test/fixtures/addresses.yml +++ /dev/null @@ -1,15 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - user_id: 1 - street: MyString - city: MyString - state: MyString - zip_code: MyString - -two: - user_id: 1 - street: MyString - city: MyString - state: MyString - zip_code: MyString diff --git a/test/dummy/test/fixtures/users.yml b/test/dummy/test/fixtures/users.yml deleted file mode 100644 index 719bdcb09..000000000 --- a/test/dummy/test/fixtures/users.yml +++ /dev/null @@ -1,15 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - email: MyString - password: MyString - comments: MyText - status: MyString - misc: MyString - -two: - email: MyString - password: MyString - comments: MyText - status: MyString - misc: MyString diff --git a/test/dummy/test/helpers/.keep b/test/dummy/test/helpers/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/test/integration/.keep b/test/dummy/test/integration/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/test/mailers/.keep b/test/dummy/test/mailers/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/test/models/.keep b/test/dummy/test/models/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/test/models/address_test.rb b/test/dummy/test/models/address_test.rb deleted file mode 100644 index 44f9f9b48..000000000 --- a/test/dummy/test/models/address_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class AddressTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/dummy/test/models/user_test.rb b/test/dummy/test/models/user_test.rb deleted file mode 100644 index 82f61e010..000000000 --- a/test/dummy/test/models/user_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class UserTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/dummy/test/test_helper.rb b/test/dummy/test/test_helper.rb deleted file mode 100644 index bc7e05d70..000000000 --- a/test/dummy/test/test_helper.rb +++ /dev/null @@ -1,15 +0,0 @@ -ENV["RAILS_ENV"] ||= "test" -require File.expand_path('../../config/environment', __FILE__) -require 'rails/test_help' - -class ActiveSupport::TestCase - ActiveRecord::Migration.check_pending! - - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - # - # Note: You'll currently still have to declare fixtures explicitly in integration tests - # -- they do not yet inherit this setting - fixtures :all - - # Add more helper methods to be used by all tests here... -end diff --git a/test/dummy/vendor/assets/javascripts/.keep b/test/dummy/vendor/assets/javascripts/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/vendor/assets/stylesheets/.keep b/test/dummy/vendor/assets/stylesheets/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/gemfiles/5.0.gemfile b/test/gemfiles/5.0.gemfile new file mode 100644 index 000000000..4408d2821 --- /dev/null +++ b/test/gemfiles/5.0.gemfile @@ -0,0 +1,14 @@ +source "http://rubygems.org" + +gemspec path: "../../" + +gem "rails", "~> 5.0.0" + +group :test do + gem "diffy" + gem "equivalent-xml" + gem "mocha" + gem "sqlite3" + gem "timecop", "~> 0.7.1" +end + diff --git a/test/gemfiles/5.1.gemfile b/test/gemfiles/5.1.gemfile new file mode 100644 index 000000000..d8f773078 --- /dev/null +++ b/test/gemfiles/5.1.gemfile @@ -0,0 +1,13 @@ +source "http://rubygems.org" + +gemspec path: "../../" + +gem "rails", "~> 5.1.0" + +group :test do + gem "diffy" + gem "equivalent-xml" + gem "mocha" + gem "sqlite3" + gem "timecop", "~> 0.7.1" +end diff --git a/test/gemfiles/5.2.gemfile b/test/gemfiles/5.2.gemfile new file mode 100644 index 000000000..c9b967421 --- /dev/null +++ b/test/gemfiles/5.2.gemfile @@ -0,0 +1,13 @@ +source "http://rubygems.org" + +gemspec path: "../../" + +gem "rails", "~> 5.2.0.beta2" + +group :test do + gem "diffy" + gem "equivalent-xml" + gem "mocha" + gem "sqlite3" + gem "timecop", "~> 0.7.1" +end diff --git a/test/test_helper.rb b/test/test_helper.rb index e38085c2c..f24b41149 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,55 +4,58 @@ require 'equivalent-xml' require 'mocha/mini_test' -# Configure Rails Environment ENV["RAILS_ENV"] = "test" -require File.expand_path("../dummy/config/environment.rb", __FILE__) +require_relative "./dummy/config/environment.rb" require "rails/test_help" Rails.backtrace_cleaner.remove_silencers! -# Load support files -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } +class ActionView::TestCase -def setup_test_fixture - @user = User.new(email: 'steve@example.com', password: 'secret', comments: 'my comment') - @builder = BootstrapForm::FormBuilder.new(:user, @user, self, {}) - @horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, { layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10" }) - I18n.backend.store_translations(:en, { - activerecord: { - attributes: { - user: { - email: "Email" - } - }, - help: { - user: { - password: "A good password should be at least six characters long" + def setup_test_fixture + @user = User.new(email: 'steve@example.com', password: 'secret', comments: 'my comment') + @builder = BootstrapForm::FormBuilder.new(:user, @user, self, {}) + @horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, { + layout: :horizontal, + label_col: "col-sm-2", + control_col: "col-sm-10" + }) + + I18n.backend.store_translations(:en, { + activerecord: { + attributes: { + user: { + email: "Email" + } + }, + help: { + user: { + password: "A good password should be at least six characters long" + } } } - } - }) -end + }) + end -def sort_attributes doc - doc.dup.traverse do |node| - if node.is_a?(Nokogiri::XML::Element) - attributes = node.attribute_nodes.sort_by(&:name) - attributes.each do |attribute| - node.delete(attribute.name) - node[attribute.name] = attribute.value + def sort_attributes doc + doc.dup.traverse do |node| + if node.is_a?(Nokogiri::XML::Element) + attributes = node.attribute_nodes.sort_by(&:name) + attributes.each do |attribute| + node.delete(attribute.name) + node[attribute.name] = attribute.value + end end + node end - node end -end -class ActionView::TestCase def assert_equivalent_xml(expected, actual) - expected_xml = Nokogiri::XML(expected) - actual_xml = Nokogiri::XML(actual) - ignored_attributes = %w(style data-disable-with) + expected_xml = Nokogiri::XML(expected) + actual_xml = Nokogiri::XML(actual) + ignored_attributes = %w(style data-disable-with) + equivalent = EquivalentXml.equivalent?(expected_xml, actual_xml, { ignore_attr_values: ignored_attributes }) do |a, b, result| @@ -75,6 +78,7 @@ def assert_equivalent_xml(expected, actual) end result end + assert equivalent, lambda { # using a lambda because diffing is expensive Diffy::Diff.new( @@ -83,4 +87,5 @@ def assert_equivalent_xml(expected, actual) ).to_s(:color) } end + end