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 = %{
This is useful help
} + 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 @@ +

Simple

+
+ <% example = capture do %> + <%= bootstrap_form_for @user, url: "/" do |form| %> + <%= form.email_field :email, placeholder: "Enter Email", label: "Email address", help: "We'll never share your email with anyone else" %> + <%= form.password_field :password, placeholder: "Password" %> + <%= form.check_box :terms, label: "Check me out" %> + <%= form.submit %> + <% end %> + <% end %> + <%= example %> + +
diff --git a/test/dummy/app/views/layouts/application.html.erb b/test/dummy/app/views/layouts/application.html.erb index 670d1875b..2f017f557 100644 --- a/test/dummy/app/views/layouts/application.html.erb +++ b/test/dummy/app/views/layouts/application.html.erb @@ -1,14 +1,54 @@ - - - - Dummy - <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> - <%= javascript_include_tag "application", "data-turbolinks-track" => true %> - <%= csrf_meta_tags %> - - - -<%= yield %> - - - + + + + + + + + + + + + + + Hello, world! + <%= csrf_meta_tags %> + + + +
+ <%= yield %> +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/test/dummy/bin/bundle b/test/dummy/bin/bundle index 66e9889e8..f19acf5b5 100755 --- a/test/dummy/bin/bundle +++ b/test/dummy/bin/bundle @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/test/dummy/bin/rails b/test/dummy/bin/rails index 728cd85aa..073966023 100755 --- a/test/dummy/bin/rails +++ b/test/dummy/bin/rails @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path('../../config/application', __FILE__) +APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/test/dummy/bin/setup b/test/dummy/bin/setup new file mode 100755 index 000000000..94fd4d797 --- /dev/null +++ b/test/dummy/bin/setup @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/test/dummy/bin/update b/test/dummy/bin/update new file mode 100755 index 000000000..58bfaed51 --- /dev/null +++ b/test/dummy/bin/update @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/test/dummy/bin/yarn b/test/dummy/bin/yarn new file mode 100755 index 000000000..ec3db7b27 --- /dev/null +++ b/test/dummy/bin/yarn @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +APP_ROOT = File.expand_path('..', __dir__) +Dir.chdir(APP_ROOT) do + begin + exec "yarnpkg #{ARGV.join(' ')}" + rescue Errno::ENOENT + $stderr.puts "Yarn executable was not detected in the system." + $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end +end diff --git a/test/dummy/config.ru b/test/dummy/config.ru index 5bc2a619e..f7ba0b527 100644 --- a/test/dummy/config.ru +++ b/test/dummy/config.ru @@ -1,4 +1,5 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require_relative 'config/environment' + run Rails.application diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 4cd6683f8..adc98cac0 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -1,23 +1,24 @@ -require File.expand_path('../boot', __FILE__) +require_relative 'boot' require 'rails/all' -# Require the gems listed in Gemfile, including any gems -# you've limited to :test, :development, or :production. -Bundler.require(:default, Rails.env) +Bundler.require(*Rails.groups) +require "bootstrap_form" module Dummy class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + + if config.respond_to?(:load_defaults) + config.load_defaults [Rails::VERSION::MAJOR, Rails::VERSION::MINOR].join(".") + end + + if config.respond_to?(:secret_key_base) + config.secret_key_base = "ignore" + end + # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de end end diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb index 5e5f0c1fa..c9aef85d4 100644 --- a/test/dummy/config/boot.rb +++ b/test/dummy/config/boot.rb @@ -1,4 +1,5 @@ # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__) diff --git a/test/dummy/config/database.yml b/test/dummy/config/database.yml index 51a4dd459..0d02f2498 100644 --- a/test/dummy/config/database.yml +++ b/test/dummy/config/database.yml @@ -3,23 +3,23 @@ # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' -development: +# +default: &default adapter: sqlite3 - database: db/development.sqlite3 - pool: 5 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> timeout: 5000 +development: + <<: *default + database: db/development.sqlite3 + # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: - adapter: sqlite3 + <<: *default database: db/test.sqlite3 - pool: 5 - timeout: 5000 production: - adapter: sqlite3 + <<: *default database: db/production.sqlite3 - pool: 5 - timeout: 5000 diff --git a/test/dummy/config/environment.rb b/test/dummy/config/environment.rb index 10e0cadcf..426333bb4 100644 --- a/test/dummy/config/environment.rb +++ b/test/dummy/config/environment.rb @@ -1,5 +1,5 @@ # Load the Rails application. -require File.expand_path('../application', __FILE__) +require_relative 'application' # Initialize the Rails application. -Dummy::Application.initialize! +Rails.application.initialize! diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index 9d26e1250..8a9751305 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -1,4 +1,4 @@ -Dummy::Application.configure do +Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on @@ -9,21 +9,52 @@ # Do not eager load code on boot. config.eager_load = false - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options) + if config.respond_to?(:active_storage) + config.active_storage.service = :local + end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + config.action_mailer.perform_caching = false + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log - # Raise an error on page load if there are pending migrations + # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. config.assets.debug = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + # config.file_watcher = ActiveSupport::EventedFileUpdateChecker end diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb deleted file mode 100644 index b690b1cf6..000000000 --- a/test/dummy/config/environments/production.rb +++ /dev/null @@ -1,80 +0,0 @@ -Dummy::Application.configure do - # Settings specified here will take precedence over those in config/application.rb. - - # Code is not reloaded between requests. - config.cache_classes = true - - # Eager load code on boot. This eager loads most of Rails and - # your application in memory, allowing both thread web servers - # and those relying on copy on write to perform better. - # Rake tasks automatically ignore this option for performance. - config.eager_load = true - - # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false - config.action_controller.perform_caching = true - - # Enable Rack::Cache to put a simple HTTP cache in front of your application - # Add `rack-cache` to your Gemfile before enabling this. - # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. - # config.action_dispatch.rack_cache = true - - # Disable Rails's static asset server (Apache or nginx will already do this). - config.serve_static_assets = false - - # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier - # config.assets.css_compressor = :sass - - # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = false - - # Generate digests for assets URLs. - config.assets.digest = true - - # Version of your assets, change this if you want to expire all your assets. - config.assets.version = '1.0' - - # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx - - # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true - - # Set to :debug to see everything in the log. - config.log_level = :info - - # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid ] - - # Use a different logger for distributed setups. - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) - - # Use a different cache store in production. - # config.cache_store = :mem_cache_store - - # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = "http://assets.example.com" - - # Precompile additional assets. - # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. - # config.assets.precompile += %w( search.js ) - - # Ignore bad email addresses and do not raise email delivery errors. - # Set this to true and configure the email server for immediate delivery to raise delivery errors. - # config.action_mailer.raise_delivery_errors = false - - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation can not be found). - config.i18n.fallbacks = true - - # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify - - # Disable automatic flushing of the log to improve performance. - # config.autoflush_log = false - - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new -end diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index aeb6b5550..41c1cacc3 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -1,4 +1,4 @@ -Dummy::Application.configure do +Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's @@ -12,23 +12,11 @@ # preloads Rails for running tests, you may have to set it to true. config.eager_load = false - version = Rails.version.to_f - - # Configure static asset server for tests with Cache-Control for performance. - if version < 4.2 - config.serve_static_assets = true - elsif version < 5 - config.serve_static_files = true - end - - if version < 5 - config.static_cache_control = "public, max-age=3600" - else - config.public_file_server.enabled = true - config.public_file_server.headers = { - "Cache-Control" => "public, max-age=3600" - } - end + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + } # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -40,6 +28,13 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false + # Store uploaded files on the local file system in a temporary directory + if config.respond_to?(:active_storage) + config.active_storage.service = :test + end + + config.action_mailer.perform_caching = false + # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. @@ -48,6 +43,6 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # In Rails 5, the default value of this option will change from `:sorted` to `:random`. - config.active_support.test_order = :sorted + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true end diff --git a/test/dummy/config/initializers/application_controller_renderer.rb b/test/dummy/config/initializers/application_controller_renderer.rb new file mode 100644 index 000000000..89d2efab2 --- /dev/null +++ b/test/dummy/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/test/dummy/config/initializers/assets.rb b/test/dummy/config/initializers/assets.rb new file mode 100644 index 000000000..4b828e80c --- /dev/null +++ b/test/dummy/config/initializers/assets.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path +# Add Yarn node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join('node_modules') + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/test/dummy/config/initializers/cookies_serializer.rb b/test/dummy/config/initializers/cookies_serializer.rb new file mode 100644 index 000000000..5a6a32d37 --- /dev/null +++ b/test/dummy/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/test/dummy/config/initializers/generic_migration.rb b/test/dummy/config/initializers/generic_migration.rb deleted file mode 100644 index 6634663f7..000000000 --- a/test/dummy/config/initializers/generic_migration.rb +++ /dev/null @@ -1,6 +0,0 @@ -version = Rails.version.to_f -if version < 5.0 - class GenericMigration < ActiveRecord::Migration; end -else - class GenericMigration < ActiveRecord::Migration[5.0]; end -end diff --git a/test/dummy/config/initializers/mime_types.rb b/test/dummy/config/initializers/mime_types.rb index 72aca7e44..dc1899682 100644 --- a/test/dummy/config/initializers/mime_types.rb +++ b/test/dummy/config/initializers/mime_types.rb @@ -2,4 +2,3 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf -# Mime::Type.register_alias "text/html", :iphone diff --git a/test/dummy/config/initializers/secret_token.rb b/test/dummy/config/initializers/secret_token.rb deleted file mode 100644 index 6681ab352..000000000 --- a/test/dummy/config/initializers/secret_token.rb +++ /dev/null @@ -1,12 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key is used for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! - -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -# You can use `rake secret` to generate a secure secret key. - -# Make sure your secret_key_base is kept private -# if you're sharing your code publicly. -Dummy::Application.config.secret_key_base = 'bec72f1ad1c7af22ffaa254b55db3012b074c780aebcb898a763397a82e1ab4514361d1bccd30addb962d142c20e37d0502a9bd0526a76e36135dfd957b50f7d' diff --git a/test/dummy/config/initializers/session_store.rb b/test/dummy/config/initializers/session_store.rb deleted file mode 100644 index 155f7b028..000000000 --- a/test/dummy/config/initializers/session_store.rb +++ /dev/null @@ -1,3 +0,0 @@ -# Be sure to restart your server when you modify this file. - -Dummy::Application.config.session_store :cookie_store, key: '_dummy_session' diff --git a/test/dummy/config/initializers/wrap_parameters.rb b/test/dummy/config/initializers/wrap_parameters.rb index 33725e95f..bbfc3961b 100644 --- a/test/dummy/config/initializers/wrap_parameters.rb +++ b/test/dummy/config/initializers/wrap_parameters.rb @@ -5,10 +5,10 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] if respond_to?(:wrap_parameters) + wrap_parameters format: [:json] end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true +# self.include_root_in_json = true # end diff --git a/test/dummy/config/locales/en.yml b/test/dummy/config/locales/en.yml index 065395716..decc5a857 100644 --- a/test/dummy/config/locales/en.yml +++ b/test/dummy/config/locales/en.yml @@ -16,6 +16,16 @@ # # This would use the information in config/locales/es.yml. # +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# # To learn more, please read the Rails Internationalization guide # available at http://guides.rubyonrails.org/i18n.html. diff --git a/test/dummy/config/puma.rb b/test/dummy/config/puma.rb new file mode 100644 index 000000000..1e19380dc --- /dev/null +++ b/test/dummy/config/puma.rb @@ -0,0 +1,56 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. If you use this option +# you need to make sure to reconnect any threads in the `on_worker_boot` +# block. +# +# preload_app! + +# If you are preloading your application and using Active Record, it's +# recommended that you close any connections to the database before workers +# are forked to prevent connection leakage. +# +# before_fork do +# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord) +# end + +# The code in the `on_worker_boot` will be called if you are using +# clustered mode by specifying a number of `workers`. After each worker +# process is booted, this block will be run. If you are using the `preload_app!` +# option, you will want to use this block to reconnect to any threads +# or connections that may have been created at application boot, as Ruby +# cannot share connections between processes. +# +# on_worker_boot do +# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) +# end +# + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index 4867764b3..7f9ec0db9 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -1,3 +1,5 @@ Dummy::Application.routes.draw do resources :users + + root to: "bootstrap#form" end diff --git a/test/dummy/config/spring.rb b/test/dummy/config/spring.rb new file mode 100644 index 000000000..9fa7863f9 --- /dev/null +++ b/test/dummy/config/spring.rb @@ -0,0 +1,6 @@ +%w[ + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +].each { |path| Spring.watch(path) } diff --git a/test/dummy/config/storage.yml b/test/dummy/config/storage.yml new file mode 100644 index 000000000..388b6e475 --- /dev/null +++ b/test/dummy/config/storage.yml @@ -0,0 +1,35 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# keyfile: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# path: your_azure_storage_path +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/test/dummy/db/migrate/20130703191909_create_users.rb b/test/dummy/db/migrate/20130703191909_create_users.rb deleted file mode 100644 index 94f264ea1..000000000 --- a/test/dummy/db/migrate/20130703191909_create_users.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateUsers < GenericMigration - def change - create_table :users do |t| - t.string :email - t.string :password - t.text :comments - t.string :status - t.string :misc - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20130703191937_create_addresses.rb b/test/dummy/db/migrate/20130703191937_create_addresses.rb deleted file mode 100644 index 9613a6e37..000000000 --- a/test/dummy/db/migrate/20130703191937_create_addresses.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateAddresses < GenericMigration - def change - create_table :addresses do |t| - t.integer :user_id - t.string :street - t.string :city - t.string :state - t.string :zip_code - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20130912171202_add_preferences_to_user.rb b/test/dummy/db/migrate/20130912171202_add_preferences_to_user.rb deleted file mode 100644 index 8d354faa3..000000000 --- a/test/dummy/db/migrate/20130912171202_add_preferences_to_user.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddPreferencesToUser < GenericMigration - def change - add_column :users, :preferences, :text - end -end diff --git a/test/dummy/db/migrate/20140327190145_add_terms_to_user.rb b/test/dummy/db/migrate/20140327190145_add_terms_to_user.rb deleted file mode 100644 index 2aa04a3ea..000000000 --- a/test/dummy/db/migrate/20140327190145_add_terms_to_user.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddTermsToUser < GenericMigration - def change - add_column :users, :terms, :boolean, default: false - end -end diff --git a/test/dummy/db/migrate/20140922133133_add_type_to_users.rb b/test/dummy/db/migrate/20140922133133_add_type_to_users.rb deleted file mode 100644 index fc2239cd8..000000000 --- a/test/dummy/db/migrate/20140922133133_add_type_to_users.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddTypeToUsers < GenericMigration - def change - add_column :users, :type, :string - end -end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index a072ddbdb..4020137a6 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -1,38 +1,24 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). -# -# It's strongly recommended that you check this file into your version control system. +ActiveRecord::Schema.define(version: 1) do -ActiveRecord::Schema.define(version: 20140922133133) do - - create_table "addresses", force: :cascade do |t| - t.integer "user_id" - t.string "street" - t.string "city" - t.string "state" - t.string "zip_code" - t.datetime "created_at" - t.datetime "updated_at" + create_table :addresses, force: :cascade do |t| + t.integer :user_id + t.string :street + t.string :city + t.string :state + t.string :zip_code + t.timestamps end - create_table "users", force: :cascade do |t| - t.string "email" - t.string "password" - t.text "comments" - t.string "status" - t.string "misc" - t.datetime "created_at" - t.datetime "updated_at" - t.text "preferences" - t.boolean "terms", default: false - t.string "type" + create_table :users, force: :cascade do |t| + t.string :email + t.string :password + t.text :comments + t.string :status + t.string :misc + t.text :preferences + t.boolean :terms, default: false + t.string :type + t.timestamps end end diff --git a/test/dummy/db/seeds.rb b/test/dummy/db/seeds.rb deleted file mode 100644 index 4edb1e857..000000000 --- a/test/dummy/db/seeds.rb +++ /dev/null @@ -1,7 +0,0 @@ -# This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). -# -# Examples: -# -# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) -# Mayor.create(name: 'Emanuel', city: cities.first) diff --git a/test/dummy/lib/assets/.keep b/test/dummy/lib/assets/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/lib/tasks/.keep b/test/dummy/lib/tasks/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/dummy/package.json b/test/dummy/package.json new file mode 100644 index 000000000..caa2d7bb3 --- /dev/null +++ b/test/dummy/package.json @@ -0,0 +1,5 @@ +{ + "name": "dummy", + "private": true, + "dependencies": {} +} diff --git a/test/dummy/public/404.html b/test/dummy/public/404.html deleted file mode 100644 index a0daa0c15..000000000 --- a/test/dummy/public/404.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - The page you were looking for doesn't exist (404) - - - - - -
-

The page you were looking for doesn't exist.

-

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 @@ - - - - The change you wanted was rejected (422) - - - - - -
-

The change you wanted was rejected.

-

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 @@ - - - - We're sorry, but something went wrong (500) - - - - - -
-

We're sorry, but something went wrong.

-
-

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