├── .github └── workflows │ └── rubyonrails.yml ├── .gitignore ├── .ruby-version ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Gemfile ├── MIT-LICENSE ├── README.md ├── activeadmin_reorderable.gemspec ├── app └── assets │ ├── javascripts │ └── activeadmin_reorderable.js │ └── stylesheets │ └── activeadmin_reorderable.scss ├── config └── importmap.rb ├── lib ├── active_admin │ ├── reorderable │ │ ├── dsl.rb │ │ └── table_methods.rb │ └── views │ │ ├── index_as_reorderable_table.rb │ │ └── reorderable_table_for.rb ├── activeadmin_reorderable.rb └── activeadmin_reorderable │ ├── engine.rb │ └── version.rb ├── package.json └── spec ├── dummy ├── .ruby-version ├── README.md ├── Rakefile ├── app │ ├── admin │ │ ├── dashboard.rb │ │ ├── item.rb │ │ └── item_queue.rb │ ├── assets │ │ ├── config │ │ │ └── manifest.js │ │ ├── images │ │ │ └── .keep │ │ ├── javascripts │ │ │ └── active_admin.js │ │ └── stylesheets │ │ │ ├── active_admin.scss │ │ │ └── application.css │ ├── controllers │ │ ├── application_controller.rb │ │ └── concerns │ │ │ └── .keep │ ├── helpers │ │ └── application_helper.rb │ ├── javascript │ │ └── packs │ │ │ └── application.js │ ├── jobs │ │ └── application_job.rb │ ├── mailers │ │ └── application_mailer.rb │ ├── models │ │ ├── application_record.rb │ │ ├── concerns │ │ │ └── .keep │ │ ├── item.rb │ │ └── item_queue.rb │ └── views │ │ └── layouts │ │ ├── application.html.erb │ │ ├── mailer.html.erb │ │ └── mailer.text.erb ├── bin │ ├── bundle │ ├── rails │ ├── rake │ ├── setup │ └── yarn ├── config.ru ├── config │ ├── application.rb │ ├── boot.rb │ ├── credentials.yml.enc │ ├── database.yml │ ├── environment.rb │ ├── environments │ │ ├── development.rb │ │ ├── production.rb │ │ └── test.rb │ ├── initializers │ │ ├── active_admin.rb │ │ ├── application_controller_renderer.rb │ │ ├── assets.rb │ │ ├── backtrace_silencers.rb │ │ ├── content_security_policy.rb │ │ ├── cookies_serializer.rb │ │ ├── filter_parameter_logging.rb │ │ ├── inflections.rb │ │ ├── mime_types.rb │ │ ├── permissions_policy.rb │ │ └── wrap_parameters.rb │ ├── locales │ │ └── en.yml │ ├── master.key │ ├── puma.rb │ └── routes.rb ├── db │ ├── migrate │ │ ├── 20240711020903_create_active_admin_comments.rb │ │ ├── 20240711183453_create_items.rb │ │ ├── 20240711183524_create_item_queues.rb │ │ ├── 20240711185338_add_item_queue_id_to_item.rb │ │ ├── 20240715153551_add_position_to_item_queue.rb │ │ └── 20240715154734_add_title_to_item_queue.rb │ ├── schema.rb │ └── seeds.rb ├── lib │ ├── assets │ │ └── .keep │ └── tasks │ │ └── .keep ├── log │ └── .keep ├── package.json ├── public │ ├── 404.html │ ├── 422.html │ ├── 500.html │ ├── apple-touch-icon-precomposed.png │ ├── apple-touch-icon.png │ ├── favicon.ico │ └── robots.txt ├── spec │ └── factories │ │ ├── item_queues.rb │ │ └── items.rb └── vendor │ └── .keep ├── features └── reorderable_spec.rb ├── rails_helper.rb ├── spec_helper.rb └── support ├── active_admin_helpers.rb ├── appear_before.rb ├── drag_by.rb └── have_js_errors.rb /.github/workflows/rubyonrails.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. They are 2 | # provided by a third-party and are governed by separate terms of service, 3 | # privacy policy, and support documentation. 4 | # 5 | # This workflow will install a prebuilt Ruby version, install dependencies, and 6 | # run tests and linters. 7 | name: "Ruby on Rails CI" 8 | on: 9 | push: 10 | branches: [ "master" ] 11 | pull_request: 12 | branches: [ "master" ] 13 | jobs: 14 | test: 15 | runs-on: ubuntu-latest 16 | env: 17 | RAILS_ENV: test 18 | steps: 19 | - name: Checkout code 20 | uses: actions/checkout@v4 21 | # Add or replace dependency steps here 22 | - name: Install Ruby and gems 23 | uses: ruby/setup-ruby@v1 24 | with: 25 | bundler-cache: true 26 | # Add or replace database setup steps here 27 | - name: Set up database schema 28 | run: cd spec/dummy && bundle exec rails db:schema:load 29 | # Add or replace test runners here 30 | - name: Run tests 31 | run: bundle exec rspec 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | builds/* 2 | Gemfile.lock 3 | node_modules 4 | *.gem 5 | spec/dummy/db/*.sqlite3 6 | spec/dummy/db/*.sqlite3-journal 7 | spec/dummy/log/*.log 8 | spec/dummy/tmp/ 9 | spec/dummy/.sass-cache 10 | spec/dummy/public/system 11 | spec/dummy/public/packs-test 12 | spec/dummy/public/packs 13 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 3.1.4 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.3.4 4 | 5 | - Update sass to use @use instead of @import, to resolve deprecation warnings in dartsass 6 | 7 | ## 0.3.3 8 | 9 | - Update included files in gemspec 10 | 11 | ## 0.3.2 12 | 13 | - Change backend update from dragover to dragend 14 | 15 | ## 0.3.1 16 | 17 | - Fix some JS errors reported in #28 - Thanks @dramalho 18 | 19 | ## 0.3.0 20 | 21 | - Add tests, using dummy Rails app 22 | - Rewrite JS using vanilla JS 23 | - Remove jQuery dependency 24 | 25 | ## 0.2.1 26 | 27 | - Update to be compatible with webpacker / npm 28 | - Use AA methods for building urls 29 | 30 | ## 0.1.0 31 | 32 | - Replace deprecated `render :nothing` with `head :ok` (thanks @zharikovpro) 33 | 34 | ## 0.0.3 35 | 36 | - Removed a console.log within the reordering JavaScript. 37 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thank you for considering a contribution to this project! 4 | 5 | ## Create an issue 6 | 7 | If you find an issue, or you'd like to request a new feature, [open a github issue](https://github.com/dkniffin/activeadmin_reorderable/issues/new). 8 | 9 | ## Submit a pull request 10 | 11 | If you know how to make the change, please submit a pull request (PR). This makes it much easier to 12 | accept the change 13 | 14 | 1. Fork it ( https://github.com/[my-github-username]/activeadmin_reorderable/fork ) 15 | 2. Create your feature branch (`git checkout -b my-new-feature`) 16 | 3. Commit your changes (`git commit -am "Add some feature"`) 17 | 4. Push to the branch (`git push origin my-new-feature`) 18 | 5. Create a new Pull Request 19 | 20 | In order for the PR to be merged, the test suite must pass, there must be no conflicts on the 21 | merge, and it must be merged by a maintainer. 22 | 23 | ## Issue and PR reviews 24 | 25 | Another way you can help is by reviewing issues, trying to reproduce bugs, and providing feedback on PRs. 26 | 27 | ## Pushing a new version 28 | 29 | First, you must be authorized on both rubygems.org and npmjs.com. Then: 30 | 31 | 1. Update the ruby gem: 32 | - Update the version in `lib/activeadmin_reorderable/version.rb` 33 | - `gem build activeadmin_reorderable.gemspec` 34 | - `gem push activeadmin_reorderable-X.Y.Z.gem` 35 | 36 | 2. Update the npm package: 37 | - Update the version in `package.json` 38 | - `npm publish` 39 | 40 | 3. Update the changelog. 41 | 42 | 4. Commit and push changes 43 | 44 | 5. Tag the version in git: 45 | - `git tag -a X.Y.Z` 46 | - Add the same text as the changelog to the tag description 47 | - `git push origin X.Y.Z` 48 | 49 | 6. Create a new release in Github: https://github.com/dkniffin/activeadmin_reorderable/releases 50 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2022 Derek Kniffin 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ActiveAdmin Reorderable 2 | 3 | Drag and drop to reorder your ActiveAdmin tables. 4 | 5 | ![Drag and drop reordering](https://s3.amazonaws.com/kurtzkloud.com/p/activeadmin_reorderable/screenshot.gif) 6 | 7 | ## Requirements 8 | Your resource classes must respond to `insert_at` ala the [`acts_as_list`](https://github.com/swanandp/acts_as_list) API. You don't need to use `acts_as_list`, but if you don't, make sure to define `insert_at`. 9 | 10 | ## Installation 11 | ### Importmap 12 | 13 | - Add `gem 'activeadmin_reorderable'` to `Gemfile` and run `bundle install` 14 | - Add `import "activeadmin_reorderable"` to JS entrypoint (a JS file that is included for activeadmin) 15 | - Add `@import "activeadmin_reorderable";` in your CSS style file 16 | 17 | NOTE: no need to pin the import in your application. That's handled internally by the gem. 18 | 19 | ### Sprockets 20 | - Add `gem 'activeadmin_reorderable'` to `Gemfile` and run `bundle install` 21 | - Add `#= require activeadmin_reorderable` to `app/assets/javascripts/active_admin.js.coffee` 22 | - Add `@import "activeadmin_reorderable";` as the last `@import` statement in `app/assets/stylesheets/active_admin.css.scss` 23 | 24 | ### Webpacker / npm 25 | - `npm install --save activeadmin_reorderable` or `yarn add activeadmin_reorderable` 26 | - Add `import "activeadmin_reorderable"` to your JS pack file 27 | - Add `@import "activeadmin_reorderable/app/assets/styleseehts/activeadmin_reorderable.scss";` to your CSS style file 28 | 29 | ## Use 30 | `parts.rb` 31 | ```ruby 32 | ActiveAdmin.register Part do 33 | reorderable # Necessary to support reordering in a subtable within Widget below 34 | end 35 | ``` 36 | 37 | `widgets.rb` 38 | ```ruby 39 | ActiveAdmin.register Widget do 40 | config.sort_order = 'position_asc' # assuming Widget.insert_at modifies the `position` attribute 41 | config.paginate = false 42 | 43 | reorderable 44 | 45 | actions :index, :show 46 | 47 | # Reorderable Index Table 48 | index as: :reorderable_table do 49 | column :id 50 | column :name 51 | end 52 | 53 | show do |widget| 54 | attributes_table do 55 | row :id 56 | row :name 57 | end 58 | 59 | # Reorderable Subtable 60 | # Note: you must include `reorderable` in the ActiveAdmin configuration for the resource 61 | # being sorted. See the `Part` example above this code block. 62 | reorderable_table_for widget.parts do 63 | column :name 64 | column :cost 65 | end 66 | end 67 | end 68 | ``` 69 | 70 | ## Contributing 71 | 72 | See [CONTRIBUTING.md](./CONTRIBUTING.md) 73 | -------------------------------------------------------------------------------- /activeadmin_reorderable.gemspec: -------------------------------------------------------------------------------- 1 | $:.push File.expand_path("../lib", __FILE__) 2 | 3 | require "activeadmin_reorderable/version" 4 | 5 | Gem::Specification.new do |s| 6 | s.name = "activeadmin_reorderable" 7 | s.version = ActiveadminReorderable::VERSION 8 | s.authors = ["Derek Kniffin", "Chris Jones", "Lawson Kurtz"] 9 | s.email = ["derek.kniffin@gmail.com"] 10 | s.homepage = "http://www.github.com/dkniffin/activeadmin_reorderable" 11 | s.summary = "Drag and drop reordering for ActiveAdmin tables" 12 | s.description = "Add drag and drop reordering to ActiveAdmin tables." 13 | s.license = "MIT" 14 | 15 | s.files = Dir["{app,lib,config}/**/*", "MIT-LICENSE", "package.json", "README.md"] 16 | 17 | s.add_development_dependency "activeadmin", "~> 3.0" 18 | s.add_development_dependency "acts_as_list" 19 | s.add_development_dependency "capybara" 20 | s.add_development_dependency "database_cleaner" 21 | s.add_development_dependency "factory_bot_rails" 22 | s.add_development_dependency "pry" 23 | s.add_development_dependency "puma" 24 | s.add_development_dependency "rails", "~> 6.1", ">= 6.1.4.4" 25 | s.add_development_dependency "rspec-rails" 26 | s.add_development_dependency "selenium-webdriver", '~> 4.10' 27 | s.add_development_dependency "sqlite3", "~> 1.4" 28 | s.add_development_dependency "sassc-rails" 29 | s.add_development_dependency "concurrent-ruby", "1.3.4" 30 | end 31 | -------------------------------------------------------------------------------- /app/assets/javascripts/activeadmin_reorderable.js: -------------------------------------------------------------------------------- 1 | const setupReorderable = ({ table, onDragover, onDragEnd }) => { 2 | const rows = table.getElementsByTagName('tbody')[0].rows 3 | 4 | let dragSrc = null 5 | let srcIndex = null 6 | 7 | for (var i = 0; i < rows.length; i++) { 8 | const row = rows[i] 9 | const handle = row.querySelector(".reorder-handle") 10 | 11 | // Add draggable only when the handle is clicked, to prevent dragging from the rest of the row 12 | handle.addEventListener("mousedown", () => row.setAttribute("draggable", "true")) 13 | handle.addEventListener("mouseup", () => row.setAttribute("draggable", "false")) 14 | 15 | row.addEventListener("dragstart", (e) => { 16 | e.dataTransfer.effectAllowed = "move" 17 | 18 | dragSrc = row 19 | srcIndex = row.rowIndex 20 | 21 | // Apply styling a millisecond later, so the dragging image shows up correctly 22 | setTimeout(() => { row.classList.add("dragged-row") }, 1) 23 | }) 24 | 25 | row.addEventListener("dragover", (e) => { 26 | e.preventDefault() 27 | e.dataTransfer.dropEffect = "move" 28 | 29 | // If dragged to a new location, move the dragged row 30 | if (dragSrc != row) { 31 | const sourceIndex = dragSrc.rowIndex 32 | const targetIndex = row.rowIndex 33 | 34 | if (sourceIndex < targetIndex) { 35 | table.tBodies[0].insertBefore(dragSrc, row.nextSibling) 36 | } else { 37 | table.tBodies[0].insertBefore(dragSrc, row) 38 | } 39 | onDragover(dragSrc) 40 | } 41 | }) 42 | 43 | row.addEventListener("dragend", () => { 44 | // Disable dragging, so only the handle can start the dragging again 45 | row.setAttribute("draggable", "false") 46 | row.classList.remove("dragged-row") 47 | 48 | if (srcIndex != row.rowIndex) { 49 | onDragEnd(dragSrc) 50 | } 51 | 52 | dragSrc = null 53 | srcIndex = null 54 | }) 55 | } 56 | } 57 | 58 | const updateEvenOddClasses = (row, index) => { 59 | row.classList.remove("odd") 60 | row.classList.remove("even") 61 | 62 | if ((index + 1) % 2 == 0) { 63 | row.classList.add("even") 64 | } else { 65 | row.classList.add("odd") 66 | } 67 | } 68 | 69 | const updatePositionText = (row, index) => { 70 | const position = row.querySelector(".position") 71 | if (position) { 72 | position.textContent = index 73 | } 74 | } 75 | 76 | const updateBackend = (url, rowIndex) => { 77 | let headers = { } 78 | 79 | const csrfElement = document.querySelector("meta[name=csrf-token]") 80 | if (csrfElement) { 81 | headers["X-CSRF-Token"] = csrfElement.getAttribute("content") 82 | } else { 83 | console.warn("Rails CSRF element not present. AJAX requests may fail due to CORS issues.") 84 | } 85 | 86 | const formData = new FormData() 87 | formData.append("position", rowIndex) 88 | 89 | fetch(url, { method: "POST", headers, body: formData }) 90 | } 91 | 92 | document.addEventListener("DOMContentLoaded", () => { 93 | document.querySelectorAll("table.aa-reorderable").forEach((table) => { 94 | setupReorderable({ 95 | table, 96 | onDragover: (_row) => { 97 | const allRows = table.getElementsByTagName('tbody')[0].rows 98 | 99 | for (var i = 0; i < allRows.length; i++) { 100 | const loopRow = allRows[i] 101 | const index = i + 1 102 | updateEvenOddClasses(loopRow, index) 103 | updatePositionText(loopRow, index) 104 | } 105 | }, 106 | onDragEnd: (row) => { 107 | const handle = row.querySelector(".reorder-handle") 108 | const url = handle.dataset["reorderUrl"] 109 | const allRows = table.getElementsByTagName('tbody')[0].rows 110 | const rowIndex = Array.prototype.indexOf.call(allRows, row) 111 | 112 | updateBackend(url, rowIndex + 1) 113 | } 114 | }) 115 | }) 116 | }) 117 | -------------------------------------------------------------------------------- /app/assets/stylesheets/activeadmin_reorderable.scss: -------------------------------------------------------------------------------- 1 | @use "@activeadmin/activeadmin/src/scss/mixins/all" as *; 2 | 3 | .aa-reorderable { 4 | .reorder-handle { 5 | cursor: move; 6 | 7 | @include light-button; 8 | } 9 | 10 | .dragged-row { 11 | opacity: 0; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /config/importmap.rb: -------------------------------------------------------------------------------- 1 | pin "activeadmin_reorderable", to: "activeadmin_reorderable.js" 2 | -------------------------------------------------------------------------------- /lib/active_admin/reorderable/dsl.rb: -------------------------------------------------------------------------------- 1 | module ActiveAdmin 2 | module Reorderable 3 | module DSL 4 | private 5 | 6 | def reorderable(&block) 7 | body = proc do 8 | resource.insert_at(params[:position].to_i) 9 | head :ok 10 | end 11 | 12 | member_action(:reorder, :method => :post, &block || body) 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/active_admin/reorderable/table_methods.rb: -------------------------------------------------------------------------------- 1 | module ActiveAdmin 2 | module Reorderable 3 | module TableMethods 4 | 5 | def reorder_column 6 | column '', :class => 'reorder-handle-col' do |resource| 7 | reorder_handle_for(resource) 8 | end 9 | end 10 | 11 | private 12 | 13 | def reorder_handle_for(resource) 14 | aa_resource = active_admin_namespace.resource_for(resource.class) 15 | url = aa_resource.route_member_action_path(:reorder, resource) 16 | 17 | span(reorder_handle_content, :class => 'reorder-handle', 'data-reorder-url' => url) 18 | end 19 | 20 | def reorder_handle_content 21 | '≡≡'.html_safe 22 | end 23 | 24 | end 25 | 26 | ::ActiveAdmin::Views::TableFor.send(:include, TableMethods) 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/active_admin/views/index_as_reorderable_table.rb: -------------------------------------------------------------------------------- 1 | module ActiveAdmin 2 | module Views 3 | class IndexAsReorderableTable < IndexAsTable 4 | 5 | def self.index_name 6 | 'reorderable_table' 7 | end 8 | 9 | def build(page_presenter, collection) 10 | add_class 'aa-reorderable' 11 | super(page_presenter, collection) 12 | end 13 | 14 | def table_for(*args, &block) 15 | insert_tag ReorderableTableFor, *args, &block 16 | end 17 | 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/active_admin/views/reorderable_table_for.rb: -------------------------------------------------------------------------------- 1 | module ActiveAdmin 2 | module Views 3 | class ReorderableTableFor < IndexAsTable::IndexTableFor 4 | builder_method :reorderable_table_for 5 | 6 | def build(collection, options = {}, &block) 7 | options[:class] = [options[:class], 'aa-reorderable'].compact.join(' ') 8 | 9 | super(collection, options) do 10 | reorder_column 11 | block.call if block.present? 12 | end 13 | end 14 | 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /lib/activeadmin_reorderable.rb: -------------------------------------------------------------------------------- 1 | require 'activeadmin' 2 | 3 | Dir[File.dirname(__FILE__) + '/activeadmin_reorderable/*.rb'].each {|file| require file } 4 | Dir[File.dirname(__FILE__) + '/active_admin/**/*.rb'].each {|file| require file } 5 | 6 | ::ActiveAdmin::ResourceDSL.send(:include, ActiveAdmin::Reorderable::DSL) 7 | -------------------------------------------------------------------------------- /lib/activeadmin_reorderable/engine.rb: -------------------------------------------------------------------------------- 1 | require 'rails/engine' 2 | 3 | module ActiveadminReorderable 4 | class Engine < Rails::Engine 5 | initializer "activeadmin_reorderable.importmap", before: "importmap" do |app| 6 | # Skip if importmap-rails is not installed 7 | next unless app.config.respond_to?(:importmap) 8 | 9 | app.config.importmap.paths << Engine.root.join("config/importmap.rb") 10 | app.config.importmap.cache_sweepers << Engine.root.join("app/assets/javascripts") 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/activeadmin_reorderable/version.rb: -------------------------------------------------------------------------------- 1 | module ActiveadminReorderable 2 | VERSION = "0.3.4" 3 | end 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "activeadmin_reorderable", 3 | "version": "0.3.4", 4 | "description": "Drag and drop to reorder your ActiveAdmin tables.", 5 | "main": "app/assets/javascripts/activeadmin_reorderable.js", 6 | "files": [ 7 | "app/**/*" 8 | ], 9 | "repository": "https://github.com/dkniffin/activeadmin_reorderable", 10 | "author": "Derek Kniffin ", 11 | "license": "MIT", 12 | "scripts": { }, 13 | "devDependencies": { }, 14 | "dependencies": { 15 | "@activeadmin/activeadmin": "^3.2.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spec/dummy/.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-3.1.4 2 | -------------------------------------------------------------------------------- /spec/dummy/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | -------------------------------------------------------------------------------- /spec/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative "config/application" 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /spec/dummy/app/admin/dashboard.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | ActiveAdmin.register_page "Dashboard" do 3 | menu priority: 1, label: proc { I18n.t("active_admin.dashboard") } 4 | 5 | content title: proc { I18n.t("active_admin.dashboard") } do 6 | div class: "blank_slate_container", id: "dashboard_default_message" do 7 | span class: "blank_slate" do 8 | span I18n.t("active_admin.dashboard_welcome.welcome") 9 | small I18n.t("active_admin.dashboard_welcome.call_to_action") 10 | end 11 | end 12 | 13 | # Here is an example of a simple dashboard with columns and panels. 14 | # 15 | # columns do 16 | # column do 17 | # panel "Recent Posts" do 18 | # ul do 19 | # Post.recent(5).map do |post| 20 | # li link_to(post.title, admin_post_path(post)) 21 | # end 22 | # end 23 | # end 24 | # end 25 | 26 | # column do 27 | # panel "Info" do 28 | # para "Welcome to ActiveAdmin." 29 | # end 30 | # end 31 | # end 32 | end # content 33 | end 34 | -------------------------------------------------------------------------------- /spec/dummy/app/admin/item.rb: -------------------------------------------------------------------------------- 1 | ActiveAdmin.register Item do 2 | permit_params :id, :name, :description, :position, :item_queue_id 3 | 4 | reorderable 5 | end 6 | -------------------------------------------------------------------------------- /spec/dummy/app/admin/item_queue.rb: -------------------------------------------------------------------------------- 1 | ActiveAdmin.register ItemQueue do 2 | config.sort_order = 'position_asc' 3 | 4 | permit_params :id, :position 5 | 6 | reorderable 7 | 8 | index as: :reorderable_table do 9 | column :id 10 | column :title 11 | column :position, class: "position" 12 | end 13 | 14 | show do |item_queue| 15 | attributes_table do 16 | row :id 17 | row :created_at 18 | row :updated_at 19 | end 20 | 21 | reorderable_table_for item_queue.items do 22 | column :name 23 | column :description 24 | column :position, class: "position" 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link_tree ../images 2 | //= link_directory ../stylesheets .css 3 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkniffin/activeadmin_reorderable/18c3846650f45735891b313d48ded2b9bbd598ab/spec/dummy/app/assets/images/.keep -------------------------------------------------------------------------------- /spec/dummy/app/assets/javascripts/active_admin.js: -------------------------------------------------------------------------------- 1 | //= require active_admin/base 2 | //= require activeadmin_reorderable 3 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/stylesheets/active_admin.scss: -------------------------------------------------------------------------------- 1 | // Sass variable overrides must be declared before loading up Active Admin's styles. 2 | // 3 | // To view the variables that Active Admin provides, take a look at 4 | // `app/assets/stylesheets/active_admin/mixins/_variables.scss` in the 5 | // Active Admin source. 6 | // 7 | // For example, to change the sidebar width: 8 | // $sidebar-width: 242px; 9 | 10 | // Active Admin's got SASS! 11 | @import "active_admin/mixins"; 12 | @import "active_admin/base"; 13 | 14 | // Overriding any non-variable Sass must be done after the fact. 15 | // For example, to change the default status-tag color: 16 | // 17 | // .status_tag { background: #6090DB; } 18 | 19 | @import "activeadmin_reorderable"; 20 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's 6 | * vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 10 | * files in this directory. Styles in this file should be added after the last require_* statement. 11 | * It is generally better to create a new file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /spec/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | end 3 | -------------------------------------------------------------------------------- /spec/dummy/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkniffin/activeadmin_reorderable/18c3846650f45735891b313d48ded2b9bbd598ab/spec/dummy/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /spec/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /spec/dummy/app/javascript/packs/application.js: -------------------------------------------------------------------------------- 1 | // This file is automatically compiled by Webpack, along with any other files 2 | // present in this directory. You're encouraged to place your actual application logic in 3 | // a relevant structure within app/javascript and only use these pack files to reference 4 | // that code so it'll be compiled. 5 | 6 | import Rails from "@rails/ujs" 7 | 8 | Rails.start() 9 | -------------------------------------------------------------------------------- /spec/dummy/app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | # Automatically retry jobs that encountered a deadlock 3 | # retry_on ActiveRecord::Deadlocked 4 | 5 | # Most jobs are safe to ignore if the underlying records are no longer available 6 | # discard_on ActiveJob::DeserializationError 7 | end 8 | -------------------------------------------------------------------------------- /spec/dummy/app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: 'from@example.com' 3 | layout 'mailer' 4 | end 5 | -------------------------------------------------------------------------------- /spec/dummy/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /spec/dummy/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkniffin/activeadmin_reorderable/18c3846650f45735891b313d48ded2b9bbd598ab/spec/dummy/app/models/concerns/.keep -------------------------------------------------------------------------------- /spec/dummy/app/models/item.rb: -------------------------------------------------------------------------------- 1 | require "acts_as_list" 2 | 3 | class Item < ApplicationRecord 4 | belongs_to :item_queue 5 | acts_as_list scope: :item_queue 6 | 7 | def self.ransackable_attributes(auth_object = nil) 8 | ["created_at", "description", "id", "name", "position", "updated_at"] 9 | end 10 | 11 | def self.ransackable_associations(auth_object = nil) 12 | ["item_queue"] 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /spec/dummy/app/models/item_queue.rb: -------------------------------------------------------------------------------- 1 | class ItemQueue < ApplicationRecord 2 | has_many :items, -> { order(position: :asc) } 3 | 4 | acts_as_list 5 | 6 | def self.ransackable_attributes(auth_object = nil) 7 | ["created_at", "id", "updated_at", "position", "title"] 8 | end 9 | 10 | def self.ransackable_associations(auth_object = nil) 11 | ["items"] 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | 6 | <%= csrf_meta_tags %> 7 | <%= csp_meta_tag %> 8 | 9 | <%= stylesheet_link_tag 'application', media: 'all' %> 10 | <%= javascript_pack_tag 'application' %> 11 | 12 | 13 | 14 | <%= yield %> 15 | 16 | 17 | -------------------------------------------------------------------------------- /spec/dummy/app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /spec/dummy/app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /spec/dummy/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'bundle' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "rubygems" 12 | 13 | m = Module.new do 14 | module_function 15 | 16 | def invoked_as_script? 17 | File.expand_path($0) == File.expand_path(__FILE__) 18 | end 19 | 20 | def env_var_version 21 | ENV["BUNDLER_VERSION"] 22 | end 23 | 24 | def cli_arg_version 25 | return unless invoked_as_script? # don't want to hijack other binstubs 26 | return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` 27 | bundler_version = nil 28 | update_index = nil 29 | ARGV.each_with_index do |a, i| 30 | if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN 31 | bundler_version = a 32 | end 33 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ 34 | bundler_version = $1 35 | update_index = i 36 | end 37 | bundler_version 38 | end 39 | 40 | def gemfile 41 | gemfile = ENV["BUNDLE_GEMFILE"] 42 | return gemfile if gemfile && !gemfile.empty? 43 | 44 | File.expand_path("../../Gemfile", __FILE__) 45 | end 46 | 47 | def lockfile 48 | lockfile = 49 | case File.basename(gemfile) 50 | when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) 51 | else "#{gemfile}.lock" 52 | end 53 | File.expand_path(lockfile) 54 | end 55 | 56 | def lockfile_version 57 | return unless File.file?(lockfile) 58 | lockfile_contents = File.read(lockfile) 59 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ 60 | Regexp.last_match(1) 61 | end 62 | 63 | def bundler_version 64 | @bundler_version ||= 65 | env_var_version || cli_arg_version || 66 | lockfile_version 67 | end 68 | 69 | def bundler_requirement 70 | return "#{Gem::Requirement.default}.a" unless bundler_version 71 | 72 | bundler_gem_version = Gem::Version.new(bundler_version) 73 | 74 | requirement = bundler_gem_version.approximate_recommendation 75 | 76 | return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") 77 | 78 | requirement += ".a" if bundler_gem_version.prerelease? 79 | 80 | requirement 81 | end 82 | 83 | def load_bundler! 84 | ENV["BUNDLE_GEMFILE"] ||= gemfile 85 | 86 | activate_bundler 87 | end 88 | 89 | def activate_bundler 90 | gem_error = activation_error_handling do 91 | gem "bundler", bundler_requirement 92 | end 93 | return if gem_error.nil? 94 | require_error = activation_error_handling do 95 | require "bundler/version" 96 | end 97 | return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) 98 | warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" 99 | exit 42 100 | end 101 | 102 | def activation_error_handling 103 | yield 104 | nil 105 | rescue StandardError, LoadError => e 106 | e 107 | end 108 | end 109 | 110 | m.load_bundler! 111 | 112 | if m.invoked_as_script? 113 | load Gem.bin_path("bundler", "bundle") 114 | end 115 | -------------------------------------------------------------------------------- /spec/dummy/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../config/application', __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /spec/dummy/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /spec/dummy/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path('..', __dir__) 6 | 7 | def system!(*args) 8 | system(*args) || abort("\n== Command #{args} failed ==") 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This script is a way to set up or update your development environment automatically. 13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 14 | # Add necessary setup steps to this file. 15 | 16 | puts '== Installing dependencies ==' 17 | system! 'gem install bundler --conservative' 18 | system('bundle check') || system!('bundle install') 19 | 20 | # Install JavaScript dependencies 21 | system! 'bin/yarn' 22 | 23 | # puts "\n== Copying sample files ==" 24 | # unless File.exist?('config/database.yml') 25 | # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' 26 | # end 27 | 28 | puts "\n== Preparing database ==" 29 | system! 'bin/rails db:prepare' 30 | 31 | puts "\n== Removing old logs and tempfiles ==" 32 | system! 'bin/rails log:clear tmp:clear' 33 | 34 | puts "\n== Restarting application server ==" 35 | system! 'bin/rails restart' 36 | end 37 | -------------------------------------------------------------------------------- /spec/dummy/bin/yarn: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_ROOT = File.expand_path('..', __dir__) 3 | Dir.chdir(APP_ROOT) do 4 | yarn = ENV["PATH"].split(File::PATH_SEPARATOR). 5 | select { |dir| File.expand_path(dir) != __dir__ }. 6 | product(["yarn", "yarn.cmd", "yarn.ps1"]). 7 | map { |dir, file| File.expand_path(file, dir) }. 8 | find { |file| File.executable?(file) } 9 | 10 | if yarn 11 | exec yarn, *ARGV 12 | else 13 | $stderr.puts "Yarn executable was not detected in the system." 14 | $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" 15 | exit 1 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative "config/environment" 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /spec/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative "boot" 2 | 3 | require "rails" 4 | # Pick the frameworks you want: 5 | require "active_model/railtie" 6 | require "active_job/railtie" 7 | require "active_record/railtie" 8 | # require "active_storage/engine" 9 | require "action_controller/railtie" 10 | require "action_mailer/railtie" 11 | # require "action_mailbox/engine" 12 | # require "action_text/engine" 13 | require "action_view/railtie" 14 | # require "action_cable/engine" 15 | require "sprockets/railtie" 16 | # require "rails/test_unit/railtie" 17 | 18 | # Require the gems listed in Gemfile, including any gems 19 | # you've limited to :test, :development, or :production. 20 | Bundler.require(*Rails.groups) 21 | 22 | module Dummy 23 | class Application < Rails::Application 24 | # Initialize configuration defaults for originally generated Rails version. 25 | config.load_defaults 6.1 26 | 27 | # Configuration for the application, engines, and railties goes here. 28 | # 29 | # These settings can be overridden in specific environments using the files 30 | # in config/environments, which are processed later. 31 | # 32 | # config.time_zone = "Central Time (US & Canada)" 33 | # config.eager_load_paths << Rails.root.join("extras") 34 | 35 | # Don't generate system test files. 36 | config.generators.system_tests = nil 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /spec/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 2 | 3 | require "bundler/setup" # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /spec/dummy/config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | nq8vlttLJOzAGY1DrWUGMNZ0z0rf0wdlB1GyhdPWfU+EDO2hAxl9BDLzOearu0FzQJUvjes6MgDsg5dvfmeLlqsuT6eHjnmhPCjw512t+l+TUqd0J5pJpYB++FdU4iJYzoKHDGbrnZ8bAkg9eaQiX1UfShrXb0akrGNGyYefXLU+tk6X4bO81RE4tpjpC0aG1+htBZBGnSOLxKKiNQ6m+WkAvqQoDWgZrOSV6ni20gqeq0GKAqHruadaiFb4apyNGYOxRPgHYEpHoxM/HxbE2NHQ2v7z6iSWejdNzzWE73yW4I46Zpk3n8B2gIsNzupZR3U0JkcvkHb/TzxOsejR29dOwS0ioyvqQSUQ1HnC3mFG58t24iAjqw9RN6WXIoqJFmw+ZTj99lsIA86V1Qsr7KxdYx6QEi+/tcqP--JRD5CY/08aW2JK3U--64QiDogmm0O06vCCD41ArA== -------------------------------------------------------------------------------- /spec/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite. Versions 3.8.0 and up are supported. 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: db/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: db/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: db/production.sqlite3 26 | -------------------------------------------------------------------------------- /spec/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # In the development environment your application's code is reloaded any time 7 | # it changes. This slows down response time but is perfect for development 8 | # since you don't have to restart the web server when you make code changes. 9 | config.cache_classes = false 10 | 11 | # Do not eager load code on boot. 12 | config.eager_load = false 13 | 14 | # Show full error reports. 15 | config.consider_all_requests_local = true 16 | 17 | # Enable/disable caching. By default caching is disabled. 18 | # Run rails dev:cache to toggle caching. 19 | if Rails.root.join('tmp', 'caching-dev.txt').exist? 20 | config.action_controller.perform_caching = true 21 | config.action_controller.enable_fragment_cache_logging = true 22 | 23 | config.cache_store = :memory_store 24 | config.public_file_server.headers = { 25 | 'Cache-Control' => "public, max-age=#{2.days.to_i}" 26 | } 27 | else 28 | config.action_controller.perform_caching = false 29 | 30 | config.cache_store = :null_store 31 | end 32 | 33 | # Don't care if the mailer can't send. 34 | config.action_mailer.raise_delivery_errors = false 35 | 36 | config.action_mailer.perform_caching = false 37 | 38 | # Print deprecation notices to the Rails logger. 39 | config.active_support.deprecation = :log 40 | 41 | # Raise exceptions for disallowed deprecations. 42 | config.active_support.disallowed_deprecation = :raise 43 | 44 | # Tell Active Support which deprecation messages to disallow. 45 | config.active_support.disallowed_deprecation_warnings = [] 46 | 47 | # Raise an error on page load if there are pending migrations. 48 | config.active_record.migration_error = :page_load 49 | 50 | # Highlight code that triggered database queries in logs. 51 | config.active_record.verbose_query_logs = true 52 | 53 | # Debug mode disables concatenation and preprocessing of assets. 54 | # This option may cause significant delays in view rendering with a large 55 | # number of complex assets. 56 | config.assets.debug = true 57 | 58 | # Suppress logger output for asset requests. 59 | config.assets.quiet = true 60 | 61 | # Raises error for missing translations. 62 | # config.i18n.raise_on_missing_translations = true 63 | 64 | # Annotate rendered view with file names. 65 | # config.action_view.annotate_rendered_view_with_filenames = true 66 | 67 | # Use an evented file watcher to asynchronously detect changes in source code, 68 | # routes, locales, etc. This feature depends on the listen gem. 69 | # config.file_watcher = ActiveSupport::EventedFileUpdateChecker 70 | 71 | # Uncomment if you wish to allow Action Cable access from any origin. 72 | # config.action_cable.disable_request_forgery_protection = true 73 | end 74 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # Code is not reloaded between requests. 7 | config.cache_classes = true 8 | 9 | # Eager load code on boot. This eager loads most of Rails and 10 | # your application in memory, allowing both threaded web servers 11 | # and those relying on copy on write to perform better. 12 | # Rake tasks automatically ignore this option for performance. 13 | config.eager_load = true 14 | 15 | # Full error reports are disabled and caching is turned on. 16 | config.consider_all_requests_local = false 17 | config.action_controller.perform_caching = true 18 | 19 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 20 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 21 | # config.require_master_key = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 26 | 27 | # Compress CSS using a preprocessor. 28 | # config.assets.css_compressor = :sass 29 | 30 | # Do not fallback to assets pipeline if a precompiled asset is missed. 31 | config.assets.compile = false 32 | 33 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 34 | # config.asset_host = 'http://assets.example.com' 35 | 36 | # Specifies the header that your server uses for sending files. 37 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 38 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 39 | 40 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 41 | # config.force_ssl = true 42 | 43 | # Include generic and useful information about system operation, but avoid logging too much 44 | # information to avoid inadvertent exposure of personally identifiable information (PII). 45 | config.log_level = :info 46 | 47 | # Prepend all log lines with the following tags. 48 | config.log_tags = [ :request_id ] 49 | 50 | # Use a different cache store in production. 51 | # config.cache_store = :mem_cache_store 52 | 53 | # Use a real queuing backend for Active Job (and separate queues per environment). 54 | # config.active_job.queue_adapter = :resque 55 | # config.active_job.queue_name_prefix = "dummy_production" 56 | 57 | config.action_mailer.perform_caching = false 58 | 59 | # Ignore bad email addresses and do not raise email delivery errors. 60 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 61 | # config.action_mailer.raise_delivery_errors = false 62 | 63 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 64 | # the I18n.default_locale when a translation cannot be found). 65 | config.i18n.fallbacks = true 66 | 67 | # Send deprecation notices to registered listeners. 68 | config.active_support.deprecation = :notify 69 | 70 | # Log disallowed deprecations. 71 | config.active_support.disallowed_deprecation = :log 72 | 73 | # Tell Active Support which deprecation messages to disallow. 74 | config.active_support.disallowed_deprecation_warnings = [] 75 | 76 | # Use default logging formatter so that PID and timestamp are not suppressed. 77 | config.log_formatter = ::Logger::Formatter.new 78 | 79 | # Use a different logger for distributed setups. 80 | # require "syslog/logger" 81 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 82 | 83 | if ENV["RAILS_LOG_TO_STDOUT"].present? 84 | logger = ActiveSupport::Logger.new(STDOUT) 85 | logger.formatter = config.log_formatter 86 | config.logger = ActiveSupport::TaggedLogging.new(logger) 87 | end 88 | 89 | # Do not dump schema after migrations. 90 | config.active_record.dump_schema_after_migration = false 91 | 92 | # Inserts middleware to perform automatic connection switching. 93 | # The `database_selector` hash is used to pass options to the DatabaseSelector 94 | # middleware. The `delay` is used to determine how long to wait after a write 95 | # to send a subsequent read to the primary. 96 | # 97 | # The `database_resolver` class is used by the middleware to determine which 98 | # database is appropriate to use based on the time delay. 99 | # 100 | # The `database_resolver_context` class is used by the middleware to set 101 | # timestamps for the last write to the primary. The resolver uses the context 102 | # class timestamps to determine how long to wait before reading from the 103 | # replica. 104 | # 105 | # By default Rails will store a last write timestamp in the session. The 106 | # DatabaseSelector middleware is designed as such you can define your own 107 | # strategy for connection switching and pass that into the middleware through 108 | # these configuration options. 109 | # config.active_record.database_selector = { delay: 2.seconds } 110 | # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver 111 | # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session 112 | end 113 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | # The test environment is used exclusively to run your application's 4 | # test suite. You never need to work with it otherwise. Remember that 5 | # your test database is "scratch space" for the test suite and is wiped 6 | # and recreated between test runs. Don't rely on the data there! 7 | 8 | Rails.application.configure do 9 | # Settings specified here will take precedence over those in config/application.rb. 10 | 11 | config.cache_classes = true 12 | 13 | # Do not eager load code on boot. This avoids loading your whole application 14 | # just for the purpose of running a single test. If you are using a tool that 15 | # preloads Rails for running tests, you may have to set it to true. 16 | config.eager_load = false 17 | 18 | # Configure public file server for tests with Cache-Control for performance. 19 | config.public_file_server.enabled = true 20 | config.public_file_server.headers = { 21 | 'Cache-Control' => "public, max-age=#{1.hour.to_i}" 22 | } 23 | 24 | # Show full error reports and disable caching. 25 | config.consider_all_requests_local = true 26 | config.action_controller.perform_caching = false 27 | config.cache_store = :null_store 28 | 29 | # Raise exceptions instead of rendering exception templates. 30 | config.action_dispatch.show_exceptions = false 31 | 32 | # Disable request forgery protection in test environment. 33 | config.action_controller.allow_forgery_protection = false 34 | 35 | config.action_mailer.perform_caching = false 36 | 37 | # Tell Action Mailer not to deliver emails to the real world. 38 | # The :test delivery method accumulates sent emails in the 39 | # ActionMailer::Base.deliveries array. 40 | config.action_mailer.delivery_method = :test 41 | 42 | # Print deprecation notices to the stderr. 43 | config.active_support.deprecation = :stderr 44 | 45 | # Raise exceptions for disallowed deprecations. 46 | config.active_support.disallowed_deprecation = :raise 47 | 48 | # Tell Active Support which deprecation messages to disallow. 49 | config.active_support.disallowed_deprecation_warnings = [] 50 | 51 | # Raises error for missing translations. 52 | # config.i18n.raise_on_missing_translations = true 53 | 54 | # Annotate rendered view with file names. 55 | # config.action_view.annotate_rendered_view_with_filenames = true 56 | end 57 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/active_admin.rb: -------------------------------------------------------------------------------- 1 | ActiveAdmin.setup do |config| 2 | # == Site Title 3 | # 4 | # Set the title that is displayed on the main layout 5 | # for each of the active admin pages. 6 | # 7 | config.site_title = "Dummy" 8 | 9 | # Set the link url for the title. For example, to take 10 | # users to your main site. Defaults to no link. 11 | # 12 | # config.site_title_link = "/" 13 | 14 | # Set an optional image to be displayed for the header 15 | # instead of a string (overrides :site_title) 16 | # 17 | # Note: Aim for an image that's 21px high so it fits in the header. 18 | # 19 | # config.site_title_image = "logo.png" 20 | 21 | # == Load Paths 22 | # 23 | # By default Active Admin files go inside app/admin/. 24 | # You can change this directory. 25 | # 26 | # eg: 27 | # config.load_paths = [File.join(Rails.root, 'app', 'ui')] 28 | # 29 | # Or, you can also load more directories. 30 | # Useful when setting namespaces with users that are not your main AdminUser entity. 31 | # 32 | # eg: 33 | # config.load_paths = [ 34 | # File.join(Rails.root, 'app', 'admin'), 35 | # File.join(Rails.root, 'app', 'cashier') 36 | # ] 37 | 38 | # == Default Namespace 39 | # 40 | # Set the default namespace each administration resource 41 | # will be added to. 42 | # 43 | # eg: 44 | # config.default_namespace = :hello_world 45 | # 46 | # This will create resources in the HelloWorld module and 47 | # will namespace routes to /hello_world/* 48 | # 49 | # To set no namespace by default, use: 50 | # config.default_namespace = false 51 | # 52 | # Default: 53 | # config.default_namespace = :admin 54 | # 55 | # You can customize the settings for each namespace by using 56 | # a namespace block. For example, to change the site title 57 | # within a namespace: 58 | # 59 | # config.namespace :admin do |admin| 60 | # admin.site_title = "Custom Admin Title" 61 | # end 62 | # 63 | # This will ONLY change the title for the admin section. Other 64 | # namespaces will continue to use the main "site_title" configuration. 65 | 66 | # == User Authentication 67 | # 68 | # Active Admin will automatically call an authentication 69 | # method in a before filter of all controller actions to 70 | # ensure that there is a currently logged in admin user. 71 | # 72 | # This setting changes the method which Active Admin calls 73 | # within the application controller. 74 | # config.authentication_method = :authenticate_admin_user! 75 | 76 | # == User Authorization 77 | # 78 | # Active Admin will automatically call an authorization 79 | # method in a before filter of all controller actions to 80 | # ensure that there is a user with proper rights. You can use 81 | # CanCanAdapter or make your own. Please refer to documentation. 82 | # config.authorization_adapter = ActiveAdmin::CanCanAdapter 83 | 84 | # In case you prefer Pundit over other solutions you can here pass 85 | # the name of default policy class. This policy will be used in every 86 | # case when Pundit is unable to find suitable policy. 87 | # config.pundit_default_policy = "MyDefaultPunditPolicy" 88 | 89 | # If you wish to maintain a separate set of Pundit policies for admin 90 | # resources, you may set a namespace here that Pundit will search 91 | # within when looking for a resource's policy. 92 | # config.pundit_policy_namespace = :admin 93 | 94 | # You can customize your CanCan Ability class name here. 95 | # config.cancan_ability_class = "Ability" 96 | 97 | # You can specify a method to be called on unauthorized access. 98 | # This is necessary in order to prevent a redirect loop which happens 99 | # because, by default, user gets redirected to Dashboard. If user 100 | # doesn't have access to Dashboard, he'll end up in a redirect loop. 101 | # Method provided here should be defined in application_controller.rb. 102 | # config.on_unauthorized_access = :access_denied 103 | 104 | # == Current User 105 | # 106 | # Active Admin will associate actions with the current 107 | # user performing them. 108 | # 109 | # This setting changes the method which Active Admin calls 110 | # (within the application controller) to return the currently logged in user. 111 | # config.current_user_method = :current_admin_user 112 | 113 | # == Logging Out 114 | # 115 | # Active Admin displays a logout link on each screen. These 116 | # settings configure the location and method used for the link. 117 | # 118 | # This setting changes the path where the link points to. If it's 119 | # a string, the strings is used as the path. If it's a Symbol, we 120 | # will call the method to return the path. 121 | # 122 | # Default: 123 | config.logout_link_path = :destroy_admin_user_session_path 124 | 125 | # This setting changes the http method used when rendering the 126 | # link. For example :get, :delete, :put, etc.. 127 | # 128 | # Default: 129 | # config.logout_link_method = :get 130 | 131 | # == Root 132 | # 133 | # Set the action to call for the root path. You can set different 134 | # roots for each namespace. 135 | # 136 | # Default: 137 | # config.root_to = 'dashboard#index' 138 | 139 | # == Admin Comments 140 | # 141 | # This allows your users to comment on any resource registered with Active Admin. 142 | # 143 | # You can completely disable comments: 144 | # config.comments = false 145 | # 146 | # You can change the name under which comments are registered: 147 | # config.comments_registration_name = 'AdminComment' 148 | # 149 | # You can change the order for the comments and you can change the column 150 | # to be used for ordering: 151 | # config.comments_order = 'created_at ASC' 152 | # 153 | # You can disable the menu item for the comments index page: 154 | # config.comments_menu = false 155 | # 156 | # You can customize the comment menu: 157 | # config.comments_menu = { parent: 'Admin', priority: 1 } 158 | 159 | # == Batch Actions 160 | # 161 | # Enable and disable Batch Actions 162 | # 163 | config.batch_actions = true 164 | 165 | # == Controller Filters 166 | # 167 | # You can add before, after and around filters to all of your 168 | # Active Admin resources and pages from here. 169 | # 170 | # config.before_action :do_something_awesome 171 | 172 | # == Attribute Filters 173 | # 174 | # You can exclude possibly sensitive model attributes from being displayed, 175 | # added to forms, or exported by default by ActiveAdmin 176 | # 177 | config.filter_attributes = [:encrypted_password, :password, :password_confirmation] 178 | 179 | # == Localize Date/Time Format 180 | # 181 | # Set the localize format to display dates and times. 182 | # To understand how to localize your app with I18n, read more at 183 | # https://guides.rubyonrails.org/i18n.html 184 | # 185 | # You can run `bin/rails runner 'puts I18n.t("date.formats")'` to see the 186 | # available formats in your application. 187 | # 188 | config.localize_format = :long 189 | 190 | # == Setting a Favicon 191 | # 192 | # config.favicon = 'favicon.ico' 193 | 194 | # == Meta Tags 195 | # 196 | # Add additional meta tags to the head element of active admin pages. 197 | # 198 | # Add tags to all pages logged in users see: 199 | # config.meta_tags = { author: 'My Company' } 200 | 201 | # By default, sign up/sign in/recover password pages are excluded 202 | # from showing up in search engine results by adding a robots meta 203 | # tag. You can reset the hash of meta tags included in logged out 204 | # pages: 205 | # config.meta_tags_for_logged_out_pages = {} 206 | 207 | # == Removing Breadcrumbs 208 | # 209 | # Breadcrumbs are enabled by default. You can customize them for individual 210 | # resources or you can disable them globally from here. 211 | # 212 | # config.breadcrumb = false 213 | 214 | # == Create Another Checkbox 215 | # 216 | # Create another checkbox is disabled by default. You can customize it for individual 217 | # resources or you can enable them globally from here. 218 | # 219 | # config.create_another = true 220 | 221 | # == Register Stylesheets & Javascripts 222 | # 223 | # We recommend using the built in Active Admin layout and loading 224 | # up your own stylesheets / javascripts to customize the look 225 | # and feel. 226 | # 227 | # To load a stylesheet: 228 | # config.register_stylesheet 'my_stylesheet.css' 229 | # 230 | # You can provide an options hash for more control, which is passed along to stylesheet_link_tag(): 231 | # config.register_stylesheet 'my_print_stylesheet.css', media: :print 232 | # 233 | # To load a javascript file: 234 | # config.register_javascript 'my_javascript.js' 235 | 236 | # == CSV options 237 | # 238 | # Set the CSV builder separator 239 | # config.csv_options = { col_sep: ';' } 240 | # 241 | # Force the use of quotes 242 | # config.csv_options = { force_quotes: true } 243 | 244 | # == Menu System 245 | # 246 | # You can add a navigation menu to be used in your application, or configure a provided menu 247 | # 248 | # To change the default utility navigation to show a link to your website & a logout btn 249 | # 250 | # config.namespace :admin do |admin| 251 | # admin.build_menu :utility_navigation do |menu| 252 | # menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank } 253 | # admin.add_logout_button_to_menu menu 254 | # end 255 | # end 256 | # 257 | # If you wanted to add a static menu item to the default menu provided: 258 | # 259 | # config.namespace :admin do |admin| 260 | # admin.build_menu :default do |menu| 261 | # menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: "_blank" } 262 | # end 263 | # end 264 | 265 | # == Download Links 266 | # 267 | # You can disable download links on resource listing pages, 268 | # or customize the formats shown per namespace/globally 269 | # 270 | # To disable/customize for the :admin namespace: 271 | # 272 | # config.namespace :admin do |admin| 273 | # 274 | # # Disable the links entirely 275 | # admin.download_links = false 276 | # 277 | # # Only show XML & PDF options 278 | # admin.download_links = [:xml, :pdf] 279 | # 280 | # # Enable/disable the links based on block 281 | # # (for example, with cancan) 282 | # admin.download_links = proc { can?(:view_download_links) } 283 | # 284 | # end 285 | 286 | # == Pagination 287 | # 288 | # Pagination is enabled by default for all resources. 289 | # You can control the default per page count for all resources here. 290 | # 291 | # config.default_per_page = 30 292 | # 293 | # You can control the max per page count too. 294 | # 295 | # config.max_per_page = 10_000 296 | 297 | # == Filters 298 | # 299 | # By default the index screen includes a "Filters" sidebar on the right 300 | # hand side with a filter for each attribute of the registered model. 301 | # You can enable or disable them for all resources here. 302 | # 303 | # config.filters = true 304 | # 305 | # By default the filters include associations in a select, which means 306 | # that every record will be loaded for each association (up 307 | # to the value of config.maximum_association_filter_arity). 308 | # You can enabled or disable the inclusion 309 | # of those filters by default here. 310 | # 311 | # config.include_default_association_filters = true 312 | 313 | # config.maximum_association_filter_arity = 256 # default value of :unlimited will change to 256 in a future version 314 | # config.filter_columns_for_large_association = [ 315 | # :display_name, 316 | # :full_name, 317 | # :name, 318 | # :username, 319 | # :login, 320 | # :title, 321 | # :email, 322 | # ] 323 | # config.filter_method_for_large_association = '_start' 324 | 325 | # == Head 326 | # 327 | # You can add your own content to the site head like analytics. Make sure 328 | # you only pass content you trust. 329 | # 330 | # config.head = ''.html_safe 331 | 332 | # == Footer 333 | # 334 | # By default, the footer shows the current Active Admin version. You can 335 | # override the content of the footer here. 336 | # 337 | # config.footer = 'my custom footer text' 338 | 339 | # == Sorting 340 | # 341 | # By default ActiveAdmin::OrderClause is used for sorting logic 342 | # You can inherit it with own class and inject it for all resources 343 | # 344 | # config.order_clause = MyOrderClause 345 | 346 | # == Webpacker 347 | # 348 | # By default, Active Admin uses Sprocket's asset pipeline. 349 | # You can switch to using Webpacker here. 350 | # 351 | # config.use_webpacker = true 352 | end 353 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ActiveSupport::Reloader.to_prepare do 4 | # ApplicationController.renderer.defaults.merge!( 5 | # http_host: 'example.org', 6 | # https: false 7 | # ) 8 | # end 9 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = '1.0' 5 | 6 | # Add additional assets to the asset load path. 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | # Add Yarn node_modules folder to the asset load path. 9 | Rails.application.config.assets.paths << Rails.root.join('node_modules') 10 | 11 | # Precompile additional assets. 12 | # application.js, application.css, and all non-JS/CSS in the app/assets 13 | # folder are already added. 14 | # Rails.application.config.assets.precompile += %w( admin.js admin.css ) 15 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code 7 | # by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". 8 | Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"] 9 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Define an application-wide content security policy 4 | # For further information see the following documentation 5 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy 6 | 7 | # Rails.application.config.content_security_policy do |policy| 8 | # policy.default_src :self, :https 9 | # policy.font_src :self, :https, :data 10 | # policy.img_src :self, :https, :data 11 | # policy.object_src :none 12 | # policy.script_src :self, :https 13 | # policy.style_src :self, :https 14 | # # If you are using webpack-dev-server then specify webpack-dev-server host 15 | # policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development? 16 | 17 | # # Specify URI for violation reports 18 | # # policy.report_uri "/csp-violation-report-endpoint" 19 | # end 20 | 21 | # If you are using UJS then enable automatic nonce generation 22 | # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } 23 | 24 | # Set the nonce only to specific directives 25 | # Rails.application.config.content_security_policy_nonce_directives = %w(script-src) 26 | 27 | # Report CSP violations to a specified URI 28 | # For further information see the following documentation: 29 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only 30 | # Rails.application.config.content_security_policy_report_only = true 31 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Specify a serializer for the signed and encrypted cookie jars. 4 | # Valid options are :json, :marshal, and :hybrid. 5 | Rails.application.config.action_dispatch.cookies_serializer = :json 6 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [ 5 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 6 | ] 7 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/permissions_policy.rb: -------------------------------------------------------------------------------- 1 | # Define an application-wide HTTP permissions policy. For further 2 | # information see https://developers.google.com/web/updates/2018/06/feature-policy 3 | # 4 | # Rails.application.config.permissions_policy do |f| 5 | # f.camera :none 6 | # f.gyroscope :none 7 | # f.microphone :none 8 | # f.usb :none 9 | # f.fullscreen :self 10 | # f.payment :self, "https://secure.example.com" 11 | # end 12 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /spec/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # 'true': 'foo' 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at https://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /spec/dummy/config/master.key: -------------------------------------------------------------------------------- 1 | 860a16cc63ea3454c40b61aa9f7ac21b -------------------------------------------------------------------------------- /spec/dummy/config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers: a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum; this matches the default thread size of Active Record. 6 | # 7 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 8 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 9 | threads min_threads_count, max_threads_count 10 | 11 | # Specifies the `worker_timeout` threshold that Puma will use to wait before 12 | # terminating a worker in development environments. 13 | # 14 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" 15 | 16 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 17 | # 18 | port ENV.fetch("PORT") { 3000 } 19 | 20 | # Specifies the `environment` that Puma will run in. 21 | # 22 | environment ENV.fetch("RAILS_ENV") { "development" } 23 | 24 | # Specifies the `pidfile` that Puma will use. 25 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 26 | 27 | # Specifies the number of `workers` to boot in clustered mode. 28 | # Workers are forked web server processes. If using threads and workers together 29 | # the concurrency of the application would be max `threads` * `workers`. 30 | # Workers do not work on JRuby or Windows (both of which do not support 31 | # processes). 32 | # 33 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 34 | 35 | # Use the `preload_app!` method when specifying a `workers` number. 36 | # This directive tells Puma to first boot the application and load code 37 | # before forking the application. This takes advantage of Copy On Write 38 | # process behavior so workers use less memory. 39 | # 40 | # preload_app! 41 | 42 | # Allow puma to be restarted by `rails restart` command. 43 | plugin :tmp_restart 44 | -------------------------------------------------------------------------------- /spec/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | ActiveAdmin.routes(self) 3 | # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html 4 | end 5 | -------------------------------------------------------------------------------- /spec/dummy/db/migrate/20240711020903_create_active_admin_comments.rb: -------------------------------------------------------------------------------- 1 | class CreateActiveAdminComments < ActiveRecord::Migration[6.1] 2 | def self.up 3 | create_table :active_admin_comments do |t| 4 | t.string :namespace 5 | t.text :body 6 | t.references :resource, polymorphic: true 7 | t.references :author, polymorphic: true 8 | t.timestamps 9 | end 10 | add_index :active_admin_comments, [:namespace] 11 | end 12 | 13 | def self.down 14 | drop_table :active_admin_comments 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /spec/dummy/db/migrate/20240711183453_create_items.rb: -------------------------------------------------------------------------------- 1 | class CreateItems < ActiveRecord::Migration[6.1] 2 | def change 3 | create_table :items do |t| 4 | t.string :name 5 | t.string :description 6 | t.integer :position 7 | 8 | t.timestamps 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/dummy/db/migrate/20240711183524_create_item_queues.rb: -------------------------------------------------------------------------------- 1 | class CreateItemQueues < ActiveRecord::Migration[6.1] 2 | def change 3 | create_table :item_queues do |t| 4 | 5 | t.timestamps 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /spec/dummy/db/migrate/20240711185338_add_item_queue_id_to_item.rb: -------------------------------------------------------------------------------- 1 | class AddItemQueueIdToItem < ActiveRecord::Migration[6.1] 2 | def change 3 | add_column :items, :item_queue_id, :integer 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /spec/dummy/db/migrate/20240715153551_add_position_to_item_queue.rb: -------------------------------------------------------------------------------- 1 | class AddPositionToItemQueue < ActiveRecord::Migration[6.1] 2 | def change 3 | add_column :item_queues, :position, :integer 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /spec/dummy/db/migrate/20240715154734_add_title_to_item_queue.rb: -------------------------------------------------------------------------------- 1 | class AddTitleToItemQueue < ActiveRecord::Migration[6.1] 2 | def change 3 | add_column :item_queues, :title, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /spec/dummy/db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # This file is the source Rails uses to define your schema when running `bin/rails 6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to 7 | # be faster and is potentially less error prone than running all of your 8 | # migrations from scratch. Old migrations may fail to apply correctly if those 9 | # migrations use external dependencies or application code. 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 2024_07_15_154734) do 14 | 15 | create_table "active_admin_comments", force: :cascade do |t| 16 | t.string "namespace" 17 | t.text "body" 18 | t.string "resource_type" 19 | t.integer "resource_id" 20 | t.string "author_type" 21 | t.integer "author_id" 22 | t.datetime "created_at", precision: 6, null: false 23 | t.datetime "updated_at", precision: 6, null: false 24 | t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author" 25 | t.index ["namespace"], name: "index_active_admin_comments_on_namespace" 26 | t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource" 27 | end 28 | 29 | create_table "item_queues", force: :cascade do |t| 30 | t.datetime "created_at", precision: 6, null: false 31 | t.datetime "updated_at", precision: 6, null: false 32 | t.integer "position" 33 | t.string "title" 34 | end 35 | 36 | create_table "items", force: :cascade do |t| 37 | t.string "name" 38 | t.string "description" 39 | t.integer "position" 40 | t.datetime "created_at", precision: 6, null: false 41 | t.datetime "updated_at", precision: 6, null: false 42 | t.integer "item_queue_id" 43 | end 44 | 45 | end 46 | -------------------------------------------------------------------------------- /spec/dummy/db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) 7 | # Character.create(name: 'Luke', movie: movies.first) 8 | -------------------------------------------------------------------------------- /spec/dummy/lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkniffin/activeadmin_reorderable/18c3846650f45735891b313d48ded2b9bbd598ab/spec/dummy/lib/assets/.keep -------------------------------------------------------------------------------- /spec/dummy/lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkniffin/activeadmin_reorderable/18c3846650f45735891b313d48ded2b9bbd598ab/spec/dummy/lib/tasks/.keep -------------------------------------------------------------------------------- /spec/dummy/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkniffin/activeadmin_reorderable/18c3846650f45735891b313d48ded2b9bbd598ab/spec/dummy/log/.keep -------------------------------------------------------------------------------- /spec/dummy/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dummy", 3 | "private": true, 4 | "dependencies": { 5 | "@rails/ujs": "^6.0.0" 6 | }, 7 | "version": "0.1.0" 8 | } 9 | -------------------------------------------------------------------------------- /spec/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /spec/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /spec/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /spec/dummy/public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkniffin/activeadmin_reorderable/18c3846650f45735891b313d48ded2b9bbd598ab/spec/dummy/public/apple-touch-icon-precomposed.png -------------------------------------------------------------------------------- /spec/dummy/public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkniffin/activeadmin_reorderable/18c3846650f45735891b313d48ded2b9bbd598ab/spec/dummy/public/apple-touch-icon.png -------------------------------------------------------------------------------- /spec/dummy/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkniffin/activeadmin_reorderable/18c3846650f45735891b313d48ded2b9bbd598ab/spec/dummy/public/favicon.ico -------------------------------------------------------------------------------- /spec/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /spec/dummy/spec/factories/item_queues.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :item_queue do 3 | title { "Foobar" } 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /spec/dummy/spec/factories/items.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :item do 3 | name { "MyString" } 4 | description { "MyString" } 5 | position { 1 } 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dummy/vendor/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkniffin/activeadmin_reorderable/18c3846650f45735891b313d48ded2b9bbd598ab/spec/dummy/vendor/.keep -------------------------------------------------------------------------------- /spec/features/reorderable_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | describe "Reorderable", type: :feature do 4 | let!(:queue) { ItemQueue.create(title: "Queue A") } 5 | let!(:item1) { Item.create(name: "Item 1", description: "Description 1", item_queue: queue, position: 1) } 6 | let!(:item2) { Item.create(name: "Item 2", description: "Description 2", item_queue: queue, position: 2) } 7 | let!(:queue2) { ItemQueue.create(title: "Queue B") } 8 | 9 | it "item index page shows items" do 10 | visit admin_items_path 11 | expect(page).to have_content item1.name 12 | expect(page).to have_content item1.description 13 | expect(page).to have_content item2.name 14 | expect(page).to have_content item2.description 15 | end 16 | 17 | it "item queue show page allows reordering", js: true do 18 | visit admin_item_queue_path(queue) 19 | 20 | # Sanity checks 21 | expect(page).to have_css("table.aa-reorderable") 22 | 23 | row1 = find(".aa-reorderable tbody tr:nth-child(1)") 24 | expect(row1).to have_content(item1.name) 25 | 26 | row2 = find(".aa-reorderable tbody tr:nth-child(2)") 27 | expect(row2).to have_content(item2.name) 28 | 29 | # Test initial state 30 | expect(item1.name).to appear_before(item2.name) 31 | expect(item1.reload.position).to eq(1) 32 | expect(item2.reload.position).to eq(2) 33 | 34 | row1.find(".reorder-handle").drag_by(0, 50) # Drag down 50, far enough to put it in the next row 35 | 36 | expect(item2.name).to appear_before(item1.name) 37 | 38 | # Check that the position column updated immediately 39 | expect(row1.find(".position")).to have_content("2") 40 | expect(row2.find(".position")).to have_content("1") 41 | 42 | sleep 1 # Give some time for the DB to update 43 | 44 | expect(item1.reload.position).to eq(2) 45 | expect(item2.reload.position).to eq(1) 46 | 47 | expect(page).to_not have_js_errors 48 | end 49 | 50 | it "item queue index allows reordering", js: true do 51 | visit admin_item_queues_path 52 | 53 | expect(page).to have_css("table.aa-reorderable") 54 | 55 | row1 = find(".aa-reorderable tbody tr:nth-child(1)") 56 | expect(row1).to have_content(queue.title) 57 | 58 | row2 = find(".aa-reorderable tbody tr:nth-child(2)") 59 | expect(row2).to have_content(queue2.title) 60 | 61 | 62 | # Test initial state 63 | expect(queue.title).to appear_before(queue2.title) 64 | expect(queue.reload.position).to eq(1) 65 | expect(queue2.reload.position).to eq(2) 66 | 67 | row1.find(".reorder-handle").drag_by(0, 50) # Drag down 50, far enough to put it in the next row 68 | 69 | expect(queue2.title).to appear_before(queue.title) 70 | 71 | # Check that the position column updated immediately 72 | expect(row1.find(".position")).to have_content("2") 73 | expect(row2.find(".position")).to have_content("1") 74 | 75 | sleep 1 # Give some time for the DB to update 76 | 77 | expect(queue.reload.position).to eq(2) 78 | expect(queue2.reload.position).to eq(1) 79 | 80 | expect(page).to_not have_js_errors 81 | end 82 | end 83 | -------------------------------------------------------------------------------- /spec/rails_helper.rb: -------------------------------------------------------------------------------- 1 | ENV["RAILS_ENV"] ||= 'test' 2 | 3 | require 'spec_helper' 4 | require File.expand_path('dummy/config/environment', __dir__) 5 | require 'rspec/rails' 6 | require 'pry' 7 | require 'factory_bot_rails' 8 | require 'capybara/rspec' 9 | require 'capybara/rails' 10 | require 'selenium-webdriver' 11 | require 'database_cleaner' 12 | 13 | ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../') 14 | Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each { |f| require f } 15 | 16 | RSpec.configure do |config| 17 | config.use_instantiated_fixtures = false 18 | config.filter_run focus: true 19 | config.filter_run_excluding skip: true 20 | config.run_all_when_everything_filtered = true 21 | config.use_transactional_fixtures = false 22 | 23 | config.before(:suite) do 24 | DatabaseCleaner.clean_with(:truncation) 25 | end 26 | 27 | config.before do |example| 28 | DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction 29 | DatabaseCleaner.start 30 | end 31 | 32 | config.after do 33 | DatabaseCleaner.clean 34 | end 35 | 36 | Capybara.register_driver :chrome do |app| 37 | Capybara::Selenium::Driver.new(app, browser: :chrome) 38 | end 39 | 40 | Capybara.register_driver :headless_chrome do |app| 41 | args = ['no-sandbox', 'headless', 'disable-gpu', 'remote-debugging-port=9222'] 42 | options = Selenium::WebDriver::Chrome::Options.new(args: args) 43 | Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) 44 | end 45 | 46 | Capybara.javascript_driver = ENV.fetch('JS_DRIVER', :headless_chrome).to_sym 47 | 48 | config.include ActiveAdminHelpers 49 | end 50 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | RSpec.configure do |config| 2 | end 3 | -------------------------------------------------------------------------------- /spec/support/active_admin_helpers.rb: -------------------------------------------------------------------------------- 1 | # Copied from https://github.com/platanus/activeadmin_addons/blob/cf71013d7423d4ba7a5f721acf35731fbcd37f37/spec/support/active_admin_helpers.rb 2 | module ActiveAdminHelpers 3 | extend self 4 | 5 | def reload_menus! 6 | ActiveAdmin.application.namespaces.each(&:reset_menu!) 7 | end 8 | 9 | def register_page(klass, reset_app = true, &block) 10 | load_resources(reset_app) do 11 | ActiveAdmin.register(klass) do 12 | instance_eval(&block) 13 | end 14 | end 15 | end 16 | 17 | def register_index(klass, reset_app = true, &block) 18 | load_resources(reset_app) do 19 | ActiveAdmin.register(klass) do 20 | index do 21 | instance_eval(&block) 22 | end 23 | end 24 | end 25 | end 26 | 27 | def register_show(klass, reset_app = true, &block) 28 | load_resources(reset_app) do 29 | ActiveAdmin.register(klass) do 30 | show do 31 | attributes_table do 32 | instance_eval(&block) 33 | end 34 | end 35 | end 36 | end 37 | end 38 | 39 | def register_form(klass, reset_app = true, &block) 40 | load_resources(reset_app) do 41 | ActiveAdmin.register(klass) do 42 | form do |f| 43 | f.inputs "Details" do 44 | instance_exec(f, &block) 45 | end 46 | end 47 | end 48 | end 49 | end 50 | 51 | # Sometimes we need to reload the routes within 52 | # the application to test them out 53 | def reload_routes!(_show_routes = false) 54 | Rails.application.reload_routes! 55 | return unless _show_routes 56 | 57 | Rails.application.routes.routes.each do |route| 58 | puts route.path.spec 59 | end 60 | end 61 | 62 | # Helper method to load resources and ensure that Active Admin is 63 | # setup with the new configurations. 64 | # 65 | # Eg: 66 | # load_resources(reset_app) do 67 | # ActiveAdmin.regiser(Post) 68 | # end 69 | # 70 | def load_resources(reset_app = true) 71 | if !!reset_app 72 | ActiveAdmin.application = nil 73 | ActiveAdmin.setup {} 74 | # Disabling authentication in specs so that we don't have to worry about 75 | # it allover the place 76 | ActiveAdmin.application.authentication_method = false 77 | ActiveAdmin.application.current_user_method = false 78 | ActiveAdmin.application.use_webpacker = true 79 | end 80 | 81 | yield 82 | 83 | reload_menus! 84 | reload_routes! 85 | end 86 | end 87 | -------------------------------------------------------------------------------- /spec/support/appear_before.rb: -------------------------------------------------------------------------------- 1 | # https://stackoverflow.com/a/65686916/1202488 2 | RSpec::Matchers.define :appear_before do |later_content| 3 | match do |earlier_content| 4 | page.body.index(earlier_content) < page.body.index(later_content) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /spec/support/drag_by.rb: -------------------------------------------------------------------------------- 1 | # https://stackoverflow.com/a/16091480/1202488 2 | 3 | module CapybaraExtension 4 | def drag_by(right_by, down_by) 5 | base.drag_by(right_by, down_by) 6 | end 7 | end 8 | 9 | module CapybaraSeleniumExtension 10 | def drag_by(right_by, down_by) 11 | driver.browser.action.drag_and_drop_by(native, right_by, down_by).perform 12 | end 13 | end 14 | 15 | ::Capybara::Selenium::Node.send :include, CapybaraSeleniumExtension 16 | ::Capybara::Node::Element.send :include, CapybaraExtension 17 | -------------------------------------------------------------------------------- /spec/support/have_js_errors.rb: -------------------------------------------------------------------------------- 1 | RSpec::Matchers.define :have_js_errors do 2 | failure_message_when_negated do 3 | %(Found JS errors:\n #{@errors.join("\n ")}) 4 | end 5 | 6 | match do 7 | logs = page.driver.browser.logs.get(:browser) 8 | @errors = logs.select { |log| log.level == "SEVERE" } 9 | @errors.count > 0 10 | end 11 | end 12 | --------------------------------------------------------------------------------