From feb71e47a7b62040d5c3dadc179866dd82e190a1 Mon Sep 17 00:00:00 2001 From: Jonathan Abbett Date: Tue, 26 Mar 2019 19:40:28 -0400 Subject: [PATCH 1/2] Update: Upgrade to Rails 5.1 to fix security vulnerabilities Update: Added system tests Update: More specific cookie names to avoid inter-app collisions --- .gitignore | 2 + .ruby-version | 2 +- Gemfile | 21 +- Gemfile.lock | 188 ++++++++++-------- README.md | 15 +- abraham.gemspec | 12 +- app/assets/javascripts/abraham/index.js | 6 +- app/helpers/abraham_helper.rb | 8 + app/views/application/_abraham.html.erb | 5 +- lib/abraham/engine.rb | 3 - package.json | 9 + test/application_system_test_case.rb | 20 ++ .../app/assets/stylesheets/application.css | 2 +- test/dummy/config/application.rb | 2 + test/dummy/config/cable.yml | 3 +- test/dummy/config/environments/development.rb | 2 +- test/dummy/config/initializers/assets.rb | 3 + .../config/initializers/cookies_serializer.rb | 2 +- .../initializers/new_framework_defaults.rb | 3 - test/dummy/config/locales/en.yml | 10 + test/dummy/db/schema.rb | 16 +- .../controllers/dashboard_controller_test.rb | 19 ++ test/dummy/test/system/tours_test.rb | 66 ++++++ test/integration/navigation_test.rb | 9 - test/test_helper.rb | 7 +- yarn.lock | 45 +++++ 26 files changed, 336 insertions(+), 144 deletions(-) create mode 100644 package.json create mode 100644 test/application_system_test_case.rb create mode 100644 test/dummy/test/system/tours_test.rb delete mode 100644 test/integration/navigation_test.rb create mode 100644 yarn.lock diff --git a/.gitignore b/.gitignore index 5e2f246..b451ca2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ capybara-*.html .rspec /log +/node_modules /tmp /test/dummy/log /test/dummy/tmp @@ -15,6 +16,7 @@ capybara-*.html **.orig rerun.txt pickle-email-*.html +yarn-error.log # TODO Comment out these rules if you are OK with secrets being uploaded to the repo config/initializers/secret_token.rb diff --git a/.ruby-version b/.ruby-version index 0bee604..aedc15b 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.3.3 +2.5.3 diff --git a/Gemfile b/Gemfile index 35c4f0f..3cec611 100644 --- a/Gemfile +++ b/Gemfile @@ -1,20 +1,11 @@ # frozen_string_literal: true - -source "http://rubygems.org" -source "http://rails-assets.org" +source 'http://rubygems.org' # Declare your gem's dependencies in abraham.gemspec. # Bundler will treat runtime dependencies like base dependencies, and # development dependencies will be added by default to the :development group. gemspec -# These rails-assets dependencies need to be added to the developer's Gemfile -# since there's no way to specify a source in the gemspec. -source "http://rails-assets.org" do - gem "rails-assets-js-cookie", "~> 2.1" - gem "rails-assets-shepherd.js", "~> 1.8" -end - # 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 @@ -23,5 +14,11 @@ end # To use a debugger # gem 'byebug', group: [:development, :test] -# Avoid the 'multiple sources' confusion -gem "rails-assets-tether", source: "http://rails-assets.org/" +group :test do + # Adds support for Capybara system testing and selenium driver + gem 'capybara', '>= 2.15' + gem 'selenium-webdriver' + # Easy installation and use of web drivers to run system tests with browsers + gem 'webdrivers' + gem 'mocha' +end diff --git a/Gemfile.lock b/Gemfile.lock index c822bf0..1ea0ec5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,73 +2,80 @@ PATH remote: . specs: abraham (1.3) - jquery-rails - rails (~> 5.0, >= 5.0.0.1) - rails-assets-js-cookie (~> 2.1) - rails-assets-shepherd.js (~> 1.8) - sass-rails (~> 5.0) + rails (~> 5.1) GEM remote: http://rubygems.org/ - remote: http://rails-assets.org/ specs: - actioncable (5.2.1) - actionpack (= 5.2.1) + actioncable (5.2.2.1) + actionpack (= 5.2.2.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.1) - actionpack (= 5.2.1) - actionview (= 5.2.1) - activejob (= 5.2.1) + actionmailer (5.2.2.1) + actionpack (= 5.2.2.1) + actionview (= 5.2.2.1) + activejob (= 5.2.2.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.1) - actionview (= 5.2.1) - activesupport (= 5.2.1) + actionpack (5.2.2.1) + actionview (= 5.2.2.1) + activesupport (= 5.2.2.1) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.1) - activesupport (= 5.2.1) + actionview (5.2.2.1) + activesupport (= 5.2.2.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.1) - activesupport (= 5.2.1) + activejob (5.2.2.1) + activesupport (= 5.2.2.1) globalid (>= 0.3.6) - activemodel (5.2.1) - activesupport (= 5.2.1) - activerecord (5.2.1) - activemodel (= 5.2.1) - activesupport (= 5.2.1) + activemodel (5.2.2.1) + activesupport (= 5.2.2.1) + activerecord (5.2.2.1) + activemodel (= 5.2.2.1) + activesupport (= 5.2.2.1) arel (>= 9.0) - activestorage (5.2.1) - actionpack (= 5.2.1) - activerecord (= 5.2.1) + activestorage (5.2.2.1) + actionpack (= 5.2.2.1) + activerecord (= 5.2.2.1) marcel (~> 0.3.1) - activesupport (5.2.1) + activesupport (5.2.2.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + addressable (2.6.0) + public_suffix (>= 2.0.2, < 4.0) arel (9.0.0) ast (2.4.0) builder (3.2.3) - concurrent-ruby (1.1.2) + capybara (3.15.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.2) + xpath (~> 3.2) + childprocess (0.9.0) + ffi (~> 1.0, >= 1.0.11) + concurrent-ruby (1.1.5) crass (1.0.4) - erubi (1.7.1) - ffi (1.9.25) - globalid (0.4.1) + erubi (1.8.0) + ffi (1.10.0) + globalid (0.4.2) activesupport (>= 4.2.0) - i18n (1.1.1) + i18n (1.6.0) concurrent-ruby (~> 1.0) jaro_winkler (1.5.1) - jquery-rails (4.3.3) - rails-dom-testing (>= 1, < 3) - railties (>= 4.2.0) - thor (>= 0.14, < 2.0) + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -76,74 +83,79 @@ GEM mini_mime (>= 0.1.1) marcel (0.3.3) mimemagic (~> 0.3.2) - method_source (0.9.1) - mimemagic (0.3.2) + metaclass (0.0.4) + method_source (0.9.2) + mimemagic (0.3.3) mini_mime (1.0.1) - mini_portile2 (2.3.0) + mini_portile2 (2.4.0) minitest (5.11.3) + mocha (1.8.0) + metaclass (~> 0.0.1) + net_http_ssl_fix (0.0.10) nio4r (2.3.1) - nokogiri (1.8.5) - mini_portile2 (~> 2.3.0) + nokogiri (1.10.2) + mini_portile2 (~> 2.4.0) parallel (1.12.1) - parser (2.5.3.0) + parser (2.5.1.2) ast (~> 2.4.0) powerpack (0.1.2) + public_suffix (3.0.3) rack (2.0.6) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.1) - actioncable (= 5.2.1) - actionmailer (= 5.2.1) - actionpack (= 5.2.1) - actionview (= 5.2.1) - activejob (= 5.2.1) - activemodel (= 5.2.1) - activerecord (= 5.2.1) - activestorage (= 5.2.1) - activesupport (= 5.2.1) + rails (5.2.2.1) + actioncable (= 5.2.2.1) + actionmailer (= 5.2.2.1) + actionpack (= 5.2.2.1) + actionview (= 5.2.2.1) + activejob (= 5.2.2.1) + activemodel (= 5.2.2.1) + activerecord (= 5.2.2.1) + activestorage (= 5.2.2.1) + activesupport (= 5.2.2.1) bundler (>= 1.3.0) - railties (= 5.2.1) + railties (= 5.2.2.1) sprockets-rails (>= 2.0.0) - rails-assets-js-cookie (2.2.0) - rails-assets-shepherd.js (1.8.1) - rails-assets-tether (>= 1.0.1, < 2) - rails-assets-tether (1.4.3) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) - railties (5.2.1) - actionpack (= 5.2.1) - activesupport (= 5.2.1) + railties (5.2.2.1) + actionpack (= 5.2.2.1) + activesupport (= 5.2.2.1) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) rainbow (3.0.0) - rake (12.3.1) + rake (12.3.2) rb-fsevent (0.10.3) - rb-inotify (0.9.10) - ffi (>= 0.5.0, < 2) - rubocop (0.60.0) + rb-inotify (0.10.0) + ffi (~> 1.0) + regexp_parser (1.3.0) + rubocop (0.59.2) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.5, != 2.5.1.1) powerpack (~> 0.1) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.4.0) + unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.10.0) - sass (3.6.0) - sass-listen (~> 4.0.0) - sass-listen (4.0.0) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) + ruby_dep (1.5.0) + rubyzip (1.2.2) + sassc (2.0.1) + ffi (~> 1.9) + rake + sassc-rails (2.1.0) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + selenium-webdriver (3.141.0) + childprocess (~> 0.5) + rubyzip (~> 1.2, >= 1.2.2) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -152,26 +164,36 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) - thor (0.20.0) + thor (0.20.3) thread_safe (0.3.6) - tilt (2.0.8) + tilt (2.0.9) tzinfo (1.2.5) thread_safe (~> 0.1) unicode-display_width (1.4.0) + webdrivers (3.7.1) + net_http_ssl_fix + nokogiri (~> 1.6) + rubyzip (~> 1.0) + selenium-webdriver (~> 3.0) websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) + xpath (3.2.0) + nokogiri (~> 1.8) PLATFORMS ruby DEPENDENCIES abraham! - rails-assets-js-cookie (~> 2.1)! - rails-assets-shepherd.js (~> 1.8)! - rails-assets-tether! + capybara (>= 2.15) + listen + mocha rubocop + sassc-rails + selenium-webdriver sqlite3 + webdrivers BUNDLED WITH - 1.17.1 + 1.17.3 diff --git a/README.md b/README.md index 9f3fe3f..6159bd3 100644 --- a/README.md +++ b/README.md @@ -16,22 +16,25 @@ Abraham needs to know the current user to track tour views, e.g. `current_user` ## Installation -Add `abraham` and its JavaScript dependencies to your Gemfile: +Add `abraham` to your Gemfile: ``` gem 'abraham' -source 'https://rails-assets.org' do - gem 'rails-assets-shepherd.js', '~> 1.8' - gem 'rails-assets-js-cookie', '~> 2.1' -end ``` -Then run: +Install the gem and run the installer: ``` $ bundle install $ rails generate abraham:install +$ rails db:migrate +``` + +Install the JavaScript dependencies: + +``` +$ yarn add jquery js-cookie shepherd.js ``` Require `abraham` in `app/assets/javascripts/application.js` diff --git a/abraham.gemspec b/abraham.gemspec index d1c275b..5e66037 100644 --- a/abraham.gemspec +++ b/abraham.gemspec @@ -18,12 +18,10 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] - s.add_dependency "jquery-rails" - s.add_dependency "rails", "~> 5.0", ">= 5.0.0.1" - s.add_dependency "rails-assets-js-cookie", "~> 2.1" - s.add_dependency "rails-assets-shepherd.js", "~> 1.8" - s.add_dependency "sass-rails", "~> 5.0" + s.add_dependency 'rails', '~> 5.1' - s.add_development_dependency "rubocop" - s.add_development_dependency "sqlite3" + s.add_development_dependency 'sassc-rails' + s.add_development_dependency 'sqlite3' + s.add_development_dependency 'rubocop' + s.add_development_dependency 'listen' end diff --git a/app/assets/javascripts/abraham/index.js b/app/assets/javascripts/abraham/index.js index f16e3f7..8f6e410 100644 --- a/app/assets/javascripts/abraham/index.js +++ b/app/assets/javascripts/abraham/index.js @@ -1,8 +1,6 @@ //= require jquery -//= require jquery_ujs -//= require js-cookie -//= require tether -//= require shepherd.js.js +//= require js-cookie/src/js.cookie +//= require shepherd.js/dist/js/shepherd $(document).on('turbolinks:before-cache', function() { // Remove visible product tours diff --git a/app/helpers/abraham_helper.rb b/app/helpers/abraham_helper.rb index 4456e5b..06abb78 100644 --- a/app/helpers/abraham_helper.rb +++ b/app/helpers/abraham_helper.rb @@ -23,4 +23,12 @@ module AbrahamHelper end end end + + def abraham_cookie_prefix + "abraham-#{Rails.application.class.parent.to_s.underscore}-#{current_user.id}-#{controller_name}-#{action_name}" + end + + def abraham_domain + request.host + end end diff --git a/app/views/application/_abraham.html.erb b/app/views/application/_abraham.html.erb index dea6365..184299a 100644 --- a/app/views/application/_abraham.html.erb +++ b/app/views/application/_abraham.html.erb @@ -13,6 +13,7 @@ dataType: "json", contentType: "application/json", data: JSON.stringify({ + authenticity_token: '<%= form_authenticity_token %>', controller_name: '<%= controller_name %>', action_name: '<%= action_name %>', tour_name: '<%= tour_name %>' @@ -21,7 +22,7 @@ }); tour.on("cancel", function() { - Cookies.set('abraham-<%= controller_name %>-<%= action_name %>-<%= tour_name %>', 'later'); + Cookies.set('<%= abraham_cookie_prefix %>-<%= tour_name %>', 'later', { domain: '<%= abraham_domain %>' }); }); <% steps.each_with_index do |(key, step), index| %> @@ -54,7 +55,7 @@ <% end %> // Don't start the tour if the user dismissed it once this session - if (!Cookies.get('abraham-<%= controller_name %>-<%= action_name %>-<%= tour_name %>')) { + if (!Cookies.get('<%= abraham_cookie_prefix %>-<%= tour_name %>', { domain: '<%= abraham_domain %>' })) { tour.start(); } diff --git a/lib/abraham/engine.rb b/lib/abraham/engine.rb index 4daedda..9234726 100644 --- a/lib/abraham/engine.rb +++ b/lib/abraham/engine.rb @@ -4,8 +4,5 @@ require "rubygems" module Abraham class Engine < ::Rails::Engine - require "rails-assets-shepherd.js" - require "jquery-rails" - require "rails-assets-js-cookie" end end diff --git a/package.json b/package.json new file mode 100644 index 0000000..4dab5d2 --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "name": "abraham", + "private": true, + "dependencies": { + "jquery": "^3.3.1", + "js-cookie": "^2.2.0", + "shepherd.js": "^2.5.0" + } +} diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 0000000..b5c4659 --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,20 @@ +require "test_helper" +require "webdrivers" + +Capybara.server = :webrick + +Capybara.register_driver(:headless_chrome) do |app| + capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( + chromeOptions: { args: %w[headless disable-gpu] } + ) + + Capybara::Selenium::Driver.new( + app, + browser: :chrome, + desired_capabilities: capabilities + ) +end + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/test/dummy/app/assets/stylesheets/application.css b/test/dummy/app/assets/stylesheets/application.css index 24e6c64..dfb4f68 100644 --- a/test/dummy/app/assets/stylesheets/application.css +++ b/test/dummy/app/assets/stylesheets/application.css @@ -12,4 +12,4 @@ * *= require "shepherd.js/dist/css/shepherd-theme-default" *= require_tree . - */ + */ \ No newline at end of file diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 88c8809..57f3631 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -12,5 +12,7 @@ module Dummy # 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. + + config.active_record.sqlite3.represent_boolean_as_integer = true end end diff --git a/test/dummy/config/cable.yml b/test/dummy/config/cable.yml index 0bbde6f..acb18d9 100644 --- a/test/dummy/config/cable.yml +++ b/test/dummy/config/cable.yml @@ -6,4 +6,5 @@ test: production: adapter: redis - url: redis://localhost:6379/1 + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: dummy_production \ No newline at end of file diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index a296f8b..f5b7f3e 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -52,5 +52,5 @@ Rails.application.configure do # 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 + config.file_watcher = ActiveSupport::EventedFileUpdateChecker end diff --git a/test/dummy/config/initializers/assets.rb b/test/dummy/config/initializers/assets.rb index 1be14d3..9314fa9 100644 --- a/test/dummy/config/initializers/assets.rb +++ b/test/dummy/config/initializers/assets.rb @@ -8,6 +8,9 @@ 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 app/assets folder are already added. # Rails.application.config.assets.precompile += %w( search.js ) diff --git a/test/dummy/config/initializers/cookies_serializer.rb b/test/dummy/config/initializers/cookies_serializer.rb index ee8dff9..98a8373 100644 --- a/test/dummy/config/initializers/cookies_serializer.rb +++ b/test/dummy/config/initializers/cookies_serializer.rb @@ -4,4 +4,4 @@ # 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 +Rails.application.config.action_dispatch.cookies_serializer = :marshal \ No newline at end of file diff --git a/test/dummy/config/initializers/new_framework_defaults.rb b/test/dummy/config/initializers/new_framework_defaults.rb index 69b31ed..e1be9b2 100644 --- a/test/dummy/config/initializers/new_framework_defaults.rb +++ b/test/dummy/config/initializers/new_framework_defaults.rb @@ -19,8 +19,5 @@ ActiveSupport.to_time_preserves_timezone = true # Require `belongs_to` associations by default. Previous versions had false. Rails.application.config.active_record.belongs_to_required_by_default = true -# Do not halt callback chains when a callback returns false. Previous versions had true. -ActiveSupport.halt_callback_chains_on_return_false = false - # Configure SSL options to enable HSTS with subdomains. Previous versions had false. Rails.application.config.ssl_options = { hsts: { subdomains: true } } diff --git a/test/dummy/config/locales/en.yml b/test/dummy/config/locales/en.yml index 0653957..decc5a8 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/db/schema.rb b/test/dummy/db/schema.rb index c9d35d4..2be2300 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -12,16 +12,18 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20_161_118_143_752) do +ActiveRecord::Schema.define(version: 2016_11_18_143752) do + create_table "abraham_histories", force: :cascade do |t| - t.string "controller_name" - t.string "action_name" - t.string "tour_name" - t.integer "creator_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "controller_name" + t.string "action_name" + t.string "tour_name" + t.integer "creator_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.index ["created_at"], name: "index_abraham_histories_on_created_at" t.index ["creator_id"], name: "index_abraham_histories_on_creator_id" t.index ["updated_at"], name: "index_abraham_histories_on_updated_at" end + end diff --git a/test/dummy/test/controllers/dashboard_controller_test.rb b/test/dummy/test/controllers/dashboard_controller_test.rb index 9b28f69..9874ec4 100644 --- a/test/dummy/test/controllers/dashboard_controller_test.rb +++ b/test/dummy/test/controllers/dashboard_controller_test.rb @@ -3,6 +3,14 @@ require "test_helper" class DashboardControllerTest < ActionDispatch::IntegrationTest + setup do + I18n.locale = :en + end + + teardown do + I18n.locale = :en + end + test "uses configured shepherd theme" do # default get dashboard_home_url @@ -42,6 +50,17 @@ class DashboardControllerTest < ActionDispatch::IntegrationTest end end + test "should show tour for locale" do + I18n.locale = :es + get dashboard_home_url + assert_response :success + + assert_select 'body script' do |element| + # it's the spanish home tour + assert element.text.include? 'SPANISH This first HOME step is centered text-only' + end + end + test "other should have other tour code" do get dashboard_other_url assert_response :success diff --git a/test/dummy/test/system/tours_test.rb b/test/dummy/test/system/tours_test.rb new file mode 100644 index 0000000..d9b36cc --- /dev/null +++ b/test/dummy/test/system/tours_test.rb @@ -0,0 +1,66 @@ +require "application_system_test_case" + +class ToursTest < ApplicationSystemTestCase + setup do + @user_id = Random.rand(1..99999) + @cookie_name = "abraham-dummy-#{@user_id}-dashboard-home-intro" + ApplicationController.any_instance.stubs(:current_user).returns(OpenStruct.new(id: @user_id)) + end + + test "see and complete a tour" do + visit dashboard_home_url + + # Tour Step 1 + assert_selector ".shepherd-element", visible: true + assert_selector ".shepherd-text", text: "ENGLISH This first HOME step is centered text-only" + assert_selector ".shepherd-button", text: "LATER" + assert_selector ".shepherd-button", text: "CONTINUE" + find(".shepherd-button", text: "CONTINUE").click + + # Tour Step 2 + assert_selector ".shepherd-header", text: "ENGLISH This step has a title" + assert_selector ".shepherd-text", text: "ENGLISH This intermediate step has some text" + assert_selector ".shepherd-button", text: "EXIT" + assert_selector ".shepherd-button", text: "NEXT" + find(".shepherd-button", text: "NEXT").click + + # Tour Step 3 (should be skipped) + refute_selector ".shepherd-header", text: "ENGLISH A missing step" + + # Tour Step 4 + assert_selector ".shepherd-header", text: "ENGLISH The final step" + assert_selector ".shepherd-text", text: "ENGLISH Some text here too, and it's attached to the right" + assert_selector ".tippy-arrow", visible: true + assert_selector ".shepherd-button", text: "DONE" + find(".shepherd-button", text: "DONE").click + + # Tour should no longer be visible + refute_selector ".shepherd-element" + + # Tour should not reappear on reload + visit dashboard_home_url + refute_selector ".shepherd-element" + end + + test "mark a tour for later and it will not come back in this session" do + visit dashboard_home_url + assert_selector ".shepherd-element", visible: true + + # Dismiss tour + find(".shepherd-button", text: "LATER").click + + # Tour should no longer be visible + refute_selector ".shepherd-element" + + # Tour should not reappear on reload + visit dashboard_home_url + refute_selector ".shepherd-element" + + # Clear the cookie (simulate browser restart) + execute_script("Cookies.remove('#{@cookie_name}', { domain: '127.0.0.1' });") + + # Tour should reappear + visit dashboard_home_url + assert_selector ".shepherd-element", visible: true + end +end diff --git a/test/integration/navigation_test.rb b/test/integration/navigation_test.rb deleted file mode 100644 index 43df32a..0000000 --- a/test/integration/navigation_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class NavigationTest < ActionDispatch::IntegrationTest - # test "the truth" do - # assert true - # end -end diff --git a/test/test_helper.rb b/test/test_helper.rb index cf48e30..0be900c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,9 +3,10 @@ # Configure Rails Environment ENV["RAILS_ENV"] = "test" -require File.expand_path("../test/dummy/config/environment.rb", __dir__) -ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)] -require "rails/test_help" +require File.expand_path('../dummy/config/environment.rb', __FILE__) +ActiveRecord::Migrator.migrations_paths = [File.expand_path('../dummy/db/migrate', __FILE__)] +require 'rails/test_help' +require 'mocha/minitest' # Filter out Minitest backtrace while allowing backtrace from other libraries # to be shown. diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..f1e176e --- /dev/null +++ b/yarn.lock @@ -0,0 +1,45 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +element-matches@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/element-matches/-/element-matches-0.1.2.tgz#7345cb71e965bd2b12f725e524591c102198361a" + integrity sha512-yWh1otcs3OKUWDvu/IxyI36ZI3WNaRZlI0uG/DK6fu0pap0VYZ0J5pEGTk1zakme+hT0OKHwhlHc0N5TJhY6yQ== + +jquery@^3.3.1: + version "3.3.1" + resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.3.1.tgz#958ce29e81c9790f31be7792df5d4d95fc57fbca" + integrity sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg== + +js-cookie@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-2.2.0.tgz#1b2c279a6eece380a12168b92485265b35b1effb" + integrity sha1-Gywnmm7s44ChIWi5JIUmWzWx7/s= + +lodash-es@^4.17.11: + version "4.17.11" + resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.11.tgz#145ab4a7ac5c5e52a3531fb4f310255a152b4be0" + integrity sha512-DHb1ub+rMjjrxqlB3H56/6MXtm1lSksDp2rA2cNWjG8mlDUYFhUj3Di2Zn5IwSU87xLv8tNIQ7sSwE/YOX/D/Q== + +popper.js@^1.14.7: + version "1.14.7" + resolved "https://registry.yarnpkg.com/popper.js/-/popper.js-1.14.7.tgz#e31ec06cfac6a97a53280c3e55e4e0c860e7738e" + integrity sha512-4q1hNvoUre/8srWsH7hnoSJ5xVmIL4qgz+s4qf2TnJIMyZFUFMGH+9vE7mXynAlHSZ/NdTmmow86muD0myUkVQ== + +shepherd.js@^2.5.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/shepherd.js/-/shepherd.js-2.5.0.tgz#c8fdc1fbaff55f1e021c930178d0e2b1cea7a7e3" + integrity sha512-DesuIO0wqlCWP6tWU/g5Qt//OfapVEamnvLBWwCBUB/AbrPtWomngi7MJmmkulTJGQz8F6FGnc3TSXK6bM9cOA== + dependencies: + element-matches "^0.1.2" + lodash-es "^4.17.11" + popper.js "^1.14.7" + tippy.js "^4.0.1" + +tippy.js@^4.0.1: + version "4.2.0" + resolved "https://registry.yarnpkg.com/tippy.js/-/tippy.js-4.2.0.tgz#68387485cbc5d30ad5416bb01a20e63548898145" + integrity sha512-+WZRGtpIusZeJdZB2W5/rmOsT+6t3ASiQP0gln/OW1c+Goc6lx4vf+3i3KAJO875y7Vc1hGmFgyAMHor/eISBQ== + dependencies: + popper.js "^1.14.7" From 225b65f93e06c46127d3be7ad4cb9645afc3b7f8 Mon Sep 17 00:00:00 2001 From: Jonathan Abbett Date: Tue, 26 Mar 2019 19:49:41 -0400 Subject: [PATCH 2/2] Release 1.4 --- Gemfile.lock | 2 +- lib/abraham/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1ea0ec5..eedc33c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - abraham (1.3) + abraham (1.4) rails (~> 5.1) GEM diff --git a/lib/abraham/version.rb b/lib/abraham/version.rb index e52c405..47ab81b 100644 --- a/lib/abraham/version.rb +++ b/lib/abraham/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Abraham - VERSION = "1.3" + VERSION = "1.4" end