Update: Upgrade to Rails 5.1 to fix security vulnerabilities

Update: Added system tests
Update: More specific cookie names to avoid inter-app collisions
This commit is contained in:
Jonathan Abbett 2019-03-26 19:40:28 -04:00
parent 03f7d71c32
commit feb71e47a7
26 changed files with 336 additions and 144 deletions

2
.gitignore vendored
View File

@ -2,6 +2,7 @@
capybara-*.html capybara-*.html
.rspec .rspec
/log /log
/node_modules
/tmp /tmp
/test/dummy/log /test/dummy/log
/test/dummy/tmp /test/dummy/tmp
@ -15,6 +16,7 @@ capybara-*.html
**.orig **.orig
rerun.txt rerun.txt
pickle-email-*.html pickle-email-*.html
yarn-error.log
# TODO Comment out these rules if you are OK with secrets being uploaded to the repo # TODO Comment out these rules if you are OK with secrets being uploaded to the repo
config/initializers/secret_token.rb config/initializers/secret_token.rb

View File

@ -1 +1 @@
2.3.3 2.5.3

21
Gemfile
View File

@ -1,20 +1,11 @@
# frozen_string_literal: true # frozen_string_literal: true
source 'http://rubygems.org'
source "http://rubygems.org"
source "http://rails-assets.org"
# Declare your gem's dependencies in abraham.gemspec. # Declare your gem's dependencies in abraham.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and # Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group. # development dependencies will be added by default to the :development group.
gemspec 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 # 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 # your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing # Git. Remember to move these dependencies to your gemspec before releasing
@ -23,5 +14,11 @@ end
# To use a debugger # To use a debugger
# gem 'byebug', group: [:development, :test] # gem 'byebug', group: [:development, :test]
# Avoid the 'multiple sources' confusion group :test do
gem "rails-assets-tether", source: "http://rails-assets.org/" # 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

View File

@ -2,73 +2,80 @@ PATH
remote: . remote: .
specs: specs:
abraham (1.3) abraham (1.3)
jquery-rails rails (~> 5.1)
rails (~> 5.0, >= 5.0.0.1)
rails-assets-js-cookie (~> 2.1)
rails-assets-shepherd.js (~> 1.8)
sass-rails (~> 5.0)
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
remote: http://rails-assets.org/
specs: specs:
actioncable (5.2.1) actioncable (5.2.2.1)
actionpack (= 5.2.1) actionpack (= 5.2.2.1)
nio4r (~> 2.0) nio4r (~> 2.0)
websocket-driver (>= 0.6.1) websocket-driver (>= 0.6.1)
actionmailer (5.2.1) actionmailer (5.2.2.1)
actionpack (= 5.2.1) actionpack (= 5.2.2.1)
actionview (= 5.2.1) actionview (= 5.2.2.1)
activejob (= 5.2.1) activejob (= 5.2.2.1)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
actionpack (5.2.1) actionpack (5.2.2.1)
actionview (= 5.2.1) actionview (= 5.2.2.1)
activesupport (= 5.2.1) activesupport (= 5.2.2.1)
rack (~> 2.0) rack (~> 2.0)
rack-test (>= 0.6.3) rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.1) actionview (5.2.2.1)
activesupport (= 5.2.1) activesupport (= 5.2.2.1)
builder (~> 3.1) builder (~> 3.1)
erubi (~> 1.4) erubi (~> 1.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3) rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.2.1) activejob (5.2.2.1)
activesupport (= 5.2.1) activesupport (= 5.2.2.1)
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (5.2.1) activemodel (5.2.2.1)
activesupport (= 5.2.1) activesupport (= 5.2.2.1)
activerecord (5.2.1) activerecord (5.2.2.1)
activemodel (= 5.2.1) activemodel (= 5.2.2.1)
activesupport (= 5.2.1) activesupport (= 5.2.2.1)
arel (>= 9.0) arel (>= 9.0)
activestorage (5.2.1) activestorage (5.2.2.1)
actionpack (= 5.2.1) actionpack (= 5.2.2.1)
activerecord (= 5.2.1) activerecord (= 5.2.2.1)
marcel (~> 0.3.1) marcel (~> 0.3.1)
activesupport (5.2.1) activesupport (5.2.2.1)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2) i18n (>= 0.7, < 2)
minitest (~> 5.1) minitest (~> 5.1)
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
arel (9.0.0) arel (9.0.0)
ast (2.4.0) ast (2.4.0)
builder (3.2.3) 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) crass (1.0.4)
erubi (1.7.1) erubi (1.8.0)
ffi (1.9.25) ffi (1.10.0)
globalid (0.4.1) globalid (0.4.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
i18n (1.1.1) i18n (1.6.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
jaro_winkler (1.5.1) jaro_winkler (1.5.1)
jquery-rails (4.3.3) listen (3.1.5)
rails-dom-testing (>= 1, < 3) rb-fsevent (~> 0.9, >= 0.9.4)
railties (>= 4.2.0) rb-inotify (~> 0.9, >= 0.9.7)
thor (>= 0.14, < 2.0) ruby_dep (~> 1.2)
loofah (2.2.3) loofah (2.2.3)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
@ -76,74 +83,79 @@ GEM
mini_mime (>= 0.1.1) mini_mime (>= 0.1.1)
marcel (0.3.3) marcel (0.3.3)
mimemagic (~> 0.3.2) mimemagic (~> 0.3.2)
method_source (0.9.1) metaclass (0.0.4)
mimemagic (0.3.2) method_source (0.9.2)
mimemagic (0.3.3)
mini_mime (1.0.1) mini_mime (1.0.1)
mini_portile2 (2.3.0) mini_portile2 (2.4.0)
minitest (5.11.3) minitest (5.11.3)
mocha (1.8.0)
metaclass (~> 0.0.1)
net_http_ssl_fix (0.0.10)
nio4r (2.3.1) nio4r (2.3.1)
nokogiri (1.8.5) nokogiri (1.10.2)
mini_portile2 (~> 2.3.0) mini_portile2 (~> 2.4.0)
parallel (1.12.1) parallel (1.12.1)
parser (2.5.3.0) parser (2.5.1.2)
ast (~> 2.4.0) ast (~> 2.4.0)
powerpack (0.1.2) powerpack (0.1.2)
public_suffix (3.0.3)
rack (2.0.6) rack (2.0.6)
rack-test (1.1.0) rack-test (1.1.0)
rack (>= 1.0, < 3) rack (>= 1.0, < 3)
rails (5.2.1) rails (5.2.2.1)
actioncable (= 5.2.1) actioncable (= 5.2.2.1)
actionmailer (= 5.2.1) actionmailer (= 5.2.2.1)
actionpack (= 5.2.1) actionpack (= 5.2.2.1)
actionview (= 5.2.1) actionview (= 5.2.2.1)
activejob (= 5.2.1) activejob (= 5.2.2.1)
activemodel (= 5.2.1) activemodel (= 5.2.2.1)
activerecord (= 5.2.1) activerecord (= 5.2.2.1)
activestorage (= 5.2.1) activestorage (= 5.2.2.1)
activesupport (= 5.2.1) activesupport (= 5.2.2.1)
bundler (>= 1.3.0) bundler (>= 1.3.0)
railties (= 5.2.1) railties (= 5.2.2.1)
sprockets-rails (>= 2.0.0) 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) rails-dom-testing (2.0.3)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
nokogiri (>= 1.6) nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4) rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2) loofah (~> 2.2, >= 2.2.2)
railties (5.2.1) railties (5.2.2.1)
actionpack (= 5.2.1) actionpack (= 5.2.2.1)
activesupport (= 5.2.1) activesupport (= 5.2.2.1)
method_source method_source
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0) thor (>= 0.19.0, < 2.0)
rainbow (3.0.0) rainbow (3.0.0)
rake (12.3.1) rake (12.3.2)
rb-fsevent (0.10.3) rb-fsevent (0.10.3)
rb-inotify (0.9.10) rb-inotify (0.10.0)
ffi (>= 0.5.0, < 2) ffi (~> 1.0)
rubocop (0.60.0) regexp_parser (1.3.0)
rubocop (0.59.2)
jaro_winkler (~> 1.5.1) jaro_winkler (~> 1.5.1)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1) parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1) powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0) rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.4.0) unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.10.0) ruby-progressbar (1.10.0)
sass (3.6.0) ruby_dep (1.5.0)
sass-listen (~> 4.0.0) rubyzip (1.2.2)
sass-listen (4.0.0) sassc (2.0.1)
rb-fsevent (~> 0.9, >= 0.9.4) ffi (~> 1.9)
rb-inotify (~> 0.9, >= 0.9.7) rake
sass-rails (5.0.7) sassc-rails (2.1.0)
railties (>= 4.0.0, < 6) railties (>= 4.0.0)
sass (~> 3.1) sassc (>= 2.0)
sprockets (>= 2.8, < 4.0) sprockets (> 3.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails
tilt (>= 1.1, < 3) tilt
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
sprockets (3.7.2) sprockets (3.7.2)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
@ -152,26 +164,36 @@ GEM
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
sqlite3 (1.3.13) sqlite3 (1.3.13)
thor (0.20.0) thor (0.20.3)
thread_safe (0.3.6) thread_safe (0.3.6)
tilt (2.0.8) tilt (2.0.9)
tzinfo (1.2.5) tzinfo (1.2.5)
thread_safe (~> 0.1) thread_safe (~> 0.1)
unicode-display_width (1.4.0) 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-driver (0.7.0)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3) websocket-extensions (0.1.3)
xpath (3.2.0)
nokogiri (~> 1.8)
PLATFORMS PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
abraham! abraham!
rails-assets-js-cookie (~> 2.1)! capybara (>= 2.15)
rails-assets-shepherd.js (~> 1.8)! listen
rails-assets-tether! mocha
rubocop rubocop
sassc-rails
selenium-webdriver
sqlite3 sqlite3
webdrivers
BUNDLED WITH BUNDLED WITH
1.17.1 1.17.3

View File

@ -16,22 +16,25 @@ Abraham needs to know the current user to track tour views, e.g. `current_user`
## Installation ## Installation
Add `abraham` and its JavaScript dependencies to your Gemfile: Add `abraham` to your Gemfile:
``` ```
gem 'abraham' 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 $ bundle install
$ rails generate abraham: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` Require `abraham` in `app/assets/javascripts/application.js`

View File

@ -18,12 +18,10 @@ Gem::Specification.new do |s|
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
s.add_dependency "jquery-rails" s.add_dependency 'rails', '~> 5.1'
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_development_dependency "rubocop" s.add_development_dependency 'sassc-rails'
s.add_development_dependency "sqlite3" s.add_development_dependency 'sqlite3'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'listen'
end end

View File

@ -1,8 +1,6 @@
//= require jquery //= require jquery
//= require jquery_ujs //= require js-cookie/src/js.cookie
//= require js-cookie //= require shepherd.js/dist/js/shepherd
//= require tether
//= require shepherd.js.js
$(document).on('turbolinks:before-cache', function() { $(document).on('turbolinks:before-cache', function() {
// Remove visible product tours // Remove visible product tours

View File

@ -23,4 +23,12 @@ module AbrahamHelper
end end
end 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 end

View File

@ -13,6 +13,7 @@
dataType: "json", dataType: "json",
contentType: "application/json", contentType: "application/json",
data: JSON.stringify({ data: JSON.stringify({
authenticity_token: '<%= form_authenticity_token %>',
controller_name: '<%= controller_name %>', controller_name: '<%= controller_name %>',
action_name: '<%= action_name %>', action_name: '<%= action_name %>',
tour_name: '<%= tour_name %>' tour_name: '<%= tour_name %>'
@ -21,7 +22,7 @@
}); });
tour.on("cancel", function() { 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| %> <% steps.each_with_index do |(key, step), index| %>
@ -54,7 +55,7 @@
<% end %> <% end %>
// Don't start the tour if the user dismissed it once this session // 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(); tour.start();
} }
</script> </script>

View File

@ -4,8 +4,5 @@ require "rubygems"
module Abraham module Abraham
class Engine < ::Rails::Engine class Engine < ::Rails::Engine
require "rails-assets-shepherd.js"
require "jquery-rails"
require "rails-assets-js-cookie"
end end
end end

9
package.json Normal file
View File

@ -0,0 +1,9 @@
{
"name": "abraham",
"private": true,
"dependencies": {
"jquery": "^3.3.1",
"js-cookie": "^2.2.0",
"shepherd.js": "^2.5.0"
}
}

View File

@ -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

View File

@ -12,4 +12,4 @@
* *
*= require "shepherd.js/dist/css/shepherd-theme-default" *= require "shepherd.js/dist/css/shepherd-theme-default"
*= require_tree . *= require_tree .
*/ */

View File

@ -12,5 +12,7 @@ module Dummy
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded. # -- all .rb files in that directory are automatically loaded.
config.active_record.sqlite3.represent_boolean_as_integer = true
end end
end end

View File

@ -6,4 +6,5 @@ test:
production: production:
adapter: redis adapter: redis
url: redis://localhost:6379/1 url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: dummy_production

View File

@ -52,5 +52,5 @@ Rails.application.configure do
# Use an evented file watcher to asynchronously detect changes in source code, # Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem. # routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end end

View File

@ -8,6 +8,9 @@ Rails.application.config.assets.version = "1.0"
# Add additional assets to the asset load path # Add additional assets to the asset load path
# Rails.application.config.assets.paths << Emoji.images_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. # Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js ) # Rails.application.config.assets.precompile += %w( search.js )

View File

@ -4,4 +4,4 @@
# Specify a serializer for the signed and encrypted cookie jars. # Specify a serializer for the signed and encrypted cookie jars.
# Valid options are :json, :marshal, and :hybrid. # Valid options are :json, :marshal, and :hybrid.
Rails.application.config.action_dispatch.cookies_serializer = :json Rails.application.config.action_dispatch.cookies_serializer = :marshal

View File

@ -19,8 +19,5 @@ ActiveSupport.to_time_preserves_timezone = true
# Require `belongs_to` associations by default. Previous versions had false. # Require `belongs_to` associations by default. Previous versions had false.
Rails.application.config.active_record.belongs_to_required_by_default = true 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. # Configure SSL options to enable HSTS with subdomains. Previous versions had false.
Rails.application.config.ssl_options = { hsts: { subdomains: true } } Rails.application.config.ssl_options = { hsts: { subdomains: true } }

View File

@ -16,6 +16,16 @@
# #
# This would use the information in config/locales/es.yml. # 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 # To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html. # available at http://guides.rubyonrails.org/i18n.html.

View File

@ -12,16 +12,18 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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| create_table "abraham_histories", force: :cascade do |t|
t.string "controller_name" t.string "controller_name"
t.string "action_name" t.string "action_name"
t.string "tour_name" t.string "tour_name"
t.integer "creator_id", null: false t.integer "creator_id", null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["created_at"], name: "index_abraham_histories_on_created_at" t.index ["created_at"], name: "index_abraham_histories_on_created_at"
t.index ["creator_id"], name: "index_abraham_histories_on_creator_id" t.index ["creator_id"], name: "index_abraham_histories_on_creator_id"
t.index ["updated_at"], name: "index_abraham_histories_on_updated_at" t.index ["updated_at"], name: "index_abraham_histories_on_updated_at"
end end
end end

View File

@ -3,6 +3,14 @@
require "test_helper" require "test_helper"
class DashboardControllerTest < ActionDispatch::IntegrationTest class DashboardControllerTest < ActionDispatch::IntegrationTest
setup do
I18n.locale = :en
end
teardown do
I18n.locale = :en
end
test "uses configured shepherd theme" do test "uses configured shepherd theme" do
# default # default
get dashboard_home_url get dashboard_home_url
@ -42,6 +50,17 @@ class DashboardControllerTest < ActionDispatch::IntegrationTest
end end
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 test "other should have other tour code" do
get dashboard_other_url get dashboard_other_url
assert_response :success assert_response :success

View File

@ -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

View File

@ -1,9 +0,0 @@
# frozen_string_literal: true
require "test_helper"
class NavigationTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

View File

@ -3,9 +3,10 @@
# Configure Rails Environment # Configure Rails Environment
ENV["RAILS_ENV"] = "test" ENV["RAILS_ENV"] = "test"
require File.expand_path("../test/dummy/config/environment.rb", __dir__) require File.expand_path('../dummy/config/environment.rb', __FILE__)
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)] ActiveRecord::Migrator.migrations_paths = [File.expand_path('../dummy/db/migrate', __FILE__)]
require "rails/test_help" require 'rails/test_help'
require 'mocha/minitest'
# Filter out Minitest backtrace while allowing backtrace from other libraries # Filter out Minitest backtrace while allowing backtrace from other libraries
# to be shown. # to be shown.

45
yarn.lock Normal file
View File

@ -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"