diff --git a/.circleci/config.yml b/.circleci/config.yml index 4c0e85c8cf1..cfc2aeaf655 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -20,7 +20,7 @@ version: 2.1 .install_dependencies: &install_dependencies run: name: Install dependencies - command: bundle install --without development --path /home/circleci/project/vendor/bundle --retry 3 --jobs 3 + command: bundle install --path /home/circleci/project/vendor/bundle --retry 3 --jobs 3 .install_chromedriver: &install_chromedriver run: @@ -38,6 +38,28 @@ version: 2.1 name: Create test app command: PARALLEL_TEST_PROCESSORS=4 bundle exec rake setup +.restore_coverage: &restore_coverage + attach_workspace: + at: tmp + +.format_coverage: &format_coverage + run: + name: Format coverage + command: tmp/test-reporter format-coverage --input-type simplecov --output tmp/codeclimate.$CIRCLE_JOB.json + +.save_coverage: &save_coverage + persist_to_workspace: + root: tmp + paths: + - codeclimate.*.json + +.submit_coverage: &submit_coverage + run: + name: Upload coverage results to Code Climate + command: | + tmp/test-reporter sum-coverage tmp/codeclimate.*.json --parts 21 --output tmp/codeclimate.total.json + tmp/test-reporter upload-coverage --input tmp/codeclimate.total.json + .save_test_app_to_workspace: &save_test_app_to_workspace persist_to_workspace: root: spec/rails @@ -76,6 +98,11 @@ version: 2.1 name: Run lints command: bundle exec rake lint +.run_bug_report_template: &run_bug_report_template + run: + name: Run bug report template + command: ACTIVE_ADMIN_PATH=. ruby lib/bug_report_templates/active_admin_master.rb + .test_steps: &test_steps - checkout - *install_bundler @@ -86,7 +113,10 @@ version: 2.1 - *save_cache - *restore_test_app_from_workspace - *restore_test_times + - *restore_coverage - *run_tests + - *format_coverage + - *save_coverage - *save_test_times .test_app_steps: &test_app_steps @@ -100,6 +130,33 @@ version: 2.1 - *save_test_app_to_workspace jobs: + setup_coverage: + docker: + - image: circleci/ruby:2.5.3 + + steps: + - run: + name: Download Code Climate test-reporter + command: | + mkdir tmp + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-0.6.3-linux-amd64 > tmp/test-reporter + chmod +x tmp/test-reporter + + - persist_to_workspace: + root: tmp + paths: + - test-reporter + + upload_coverage: + docker: + - image: circleci/ruby:2.5.3 + environment: + CC_TEST_REPORTER_ID: 8d5fcf7abea6d56c625104a9d1a81140a588a7f546f4fa9de9bc6ffc8feaaf70 + + steps: + - *restore_coverage + - *submit_coverage + testapp42: docker: - image: circleci/ruby:2.5.3-node @@ -142,7 +199,7 @@ jobs: lint_and_docs: docker: - - image: circleci/ruby:2.5.3 + - image: circleci/ruby:2.5.3-node environment: BUNDLE_GEMFILE: Gemfile @@ -155,7 +212,11 @@ jobs: - *install_dependencies - *save_cache - *generate_docs + - *restore_coverage - *run_lints + - *run_bug_report_template + - *format_coverage + - *save_coverage ruby23rails42: docker: @@ -379,12 +440,27 @@ workflows: # build: jobs: - - lint_and_docs + - setup_coverage + + - lint_and_docs: + requires: + - setup_coverage + + - testapp42: + requires: + - setup_coverage + + - testapp50: + requires: + - setup_coverage + + - testapp51: + requires: + - setup_coverage - - testapp42 - - testapp50 - - testapp51 - - testapp52 + - testapp52: + requires: + - setup_coverage - ruby23rails42: requires: @@ -465,3 +541,32 @@ workflows: - jruby92rails52: requires: - testapp52 + + - upload_coverage: + requires: + - lint_and_docs + + - ruby23rails42 + - ruby23rails50 + - ruby23rails51 + - ruby23rails52 + + - ruby24rails42 + - ruby24rails50 + - ruby24rails51 + - ruby24rails52 + + - ruby25rails42 + - ruby25rails50 + - ruby25rails51 + - ruby25rails52 + + - jruby91rails42 + - jruby91rails50 + - jruby91rails51 + - jruby91rails52 + + - jruby92rails42 + - jruby92rails50 + - jruby92rails51 + - jruby92rails52 diff --git a/.gitignore b/.gitignore index 2c7a21bcebc..2797f655b43 100644 --- a/.gitignore +++ b/.gitignore @@ -1,46 +1,16 @@ -## Mac -.DS_Store - -## Windows -.Thumbs.db - -## TextMate -*.tm_project -*.tmproj -tmtags - -## Emacs -*~ -\#* -.\#* - -## Vim -*.swp -# IDEA / RUBYMINE -.idea - -## RVM -.rvmrc -.ruby-version -.ruby-gemset - ## Project (general) -tags tmp coverage -rdoc -doc .yardoc +.ruby-version pkg ## Project (specific) .bundle spec/rails -*.sqlite3-journal .test-rails-apps public .rspec_failures .rails-version .rbenv-version -.localeapp/* lib/bug_report_templates/tmp diff --git a/.rubocop.yml b/.rubocop.yml index 13babada370..f83c756882a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,8 @@ inherit_mode: merge: - Include +require: rubocop-rspec + AllCops: DisabledByDefault: true TargetRubyVersion: 2.3 @@ -48,6 +50,9 @@ Layout/EndOfLine: Layout/ExtraSpacing: Enabled: true +RSpec/HookArgument: + Enabled: true + Style/Encoding: Enabled: true diff --git a/.simplecov b/.simplecov index 1ccf149ce57..bd5cc3a2cc7 100644 --- a/.simplecov +++ b/.simplecov @@ -3,9 +3,7 @@ SimpleCov.start do end if ENV['CI'] == 'true' - require 'codecov' SimpleCov.formatters = [ - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::Codecov + SimpleCov::Formatter::HTMLFormatter ] end diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d5ea0819d8..06c8572ed0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,17 +2,24 @@ ## Unreleased +## 1.4.3 [☰](https://github.com/activeadmin/activeadmin/compare/v1.4.2...v1.4.3) + +### Bug Fixes + +* Fix `form` parameter to `batch_action` no longer accepting procs. [#5611] by [@buren] and [@deivid-rodriguez] +* Fix passing a proc to `scope_to`. [#5611] by [@deivid-rodriguez] + ## 1.4.2 [☰](https://github.com/activeadmin/activeadmin/compare/v1.4.1...v1.4.2) ### Bug Fixes -* Fix `input_html` filter option evaluated only once. [#5376][] by [@kjeldahl][] +* Fix `input_html` filter option evaluated only once. [#5376] by [@kjeldahl] ## 1.4.1 [☰](https://github.com/activeadmin/activeadmin/compare/v1.4.0...v1.4.1) ### Bug Fixes -* Fix menu item link with method delete. [#5583][] by [@tiagotex][] +* Fix menu item link with method delete. [#5583] by [@tiagotex] ## 1.4.0 [☰](https://github.com/activeadmin/activeadmin/compare/v1.3.1...v1.4.0) @@ -20,38 +27,38 @@ #### Minor -* Add missing I18n for comments. [#5458][], [#5461][] by [@mauriciopasquier][] -* Fix batch_actions.delete_confirmation translation in zh-CN.yml. [#5453][] by [@ShallmentMo][] -* Add some missing italian translations. [#5433][] by [@stefsava][] -* Enhance some chinese translations. [#5413][] by [@shouya][] -* Add missing filter predicate translations to nb. [#5357][] by [@rogerkk][] -* Add missing norwegian comment translations. [#5375][] by [@rogerkk][] -* Add missing dutch translations. [#5368][] by [@dennisvdvliet][] -* Add missing german translations. [#5341][] by [@eikes][] -* Add missing spanish translation. [#5336][] by [@mconiglio][] -* Add from and to predicates for russian language. [#5330][] by [@glebtv][] -* Fix typo in finnish translation. [#5320][] by [@JiiHu][] -* Add missing turkish translations. [#5295][] by [@kobeumut][] -* Add missing chinese translations. [#5266][] by [@jasl][] -* Allow proc label in datepicker input. [#5408][] by [@tiagotex][] -* Add `group` attribute to scopes in order to show them in grouped. [#5359][] by [@leio10][] -* Add missing polish translations and improve existing ones. [#5537][] by [@Wowu][] -* Add `priority` option to `action_item`. [#5334][] by [@andreslemik][] +* Add missing I18n for comments. [#5458], [#5461] by [@mauriciopasquier] +* Fix batch_actions.delete_confirmation translation in zh-CN.yml. [#5453] by [@ShallmentMo] +* Add some missing italian translations. [#5433] by [@stefsava] +* Enhance some chinese translations. [#5413] by [@shouya] +* Add missing filter predicate translations to nb. [#5357] by [@rogerkk] +* Add missing norwegian comment translations. [#5375] by [@rogerkk] +* Add missing dutch translations. [#5368] by [@dennisvdvliet] +* Add missing german translations. [#5341] by [@eikes] +* Add missing spanish translation. [#5336] by [@mconiglio] +* Add from and to predicates for russian language. [#5330] by [@glebtv] +* Fix typo in finnish translation. [#5320] by [@JiiHu] +* Add missing turkish translations. [#5295] by [@kobeumut] +* Add missing chinese translations. [#5266] by [@jasl] +* Allow proc label in datepicker input. [#5408] by [@tiagotex] +* Add `group` attribute to scopes in order to show them in grouped. [#5359] by [@leio10] +* Add missing polish translations and improve existing ones. [#5537] by [@Wowu] +* Add `priority` option to `action_item`. [#5334] by [@andreslemik] ### Bug Fixes -* Fixed the string representation of the resolved `sort_key` when no explicit `sortable` attribute is passed. [#5464][] by [@chumakoff][] -* Fixed docs on the column `sortable` attribute (which actually doesn't have to be explicitly specified when a block is passed to column). [#5464][] by [@chumakoff][] -* Fixed `if:` scope option when a lambda is passed. [#5501][] by [@deivid-rodriguez][] -* Comment validation adding redundant errors when resource is missing. [#5517][] by [@deivid-rodriguez][] -* Fixed resource filtering by association when the resource has custom primary key. [#5446][] by [@wasifhossain][] -* Fixed "create anoter" checkbox styling. [#5324][] by [@faucct][] +* Fixed the string representation of the resolved `sort_key` when no explicit `sortable` attribute is passed. [#5464] by [@chumakoff] +* Fixed docs on the column `sortable` attribute (which actually doesn't have to be explicitly specified when a block is passed to column). [#5464] by [@chumakoff] +* Fixed `if:` scope option when a lambda is passed. [#5501] by [@deivid-rodriguez] +* Comment validation adding redundant errors when resource is missing. [#5517] by [@deivid-rodriguez] +* Fixed resource filtering by association when the resource has custom primary key. [#5446] by [@wasifhossain] +* Fixed "create anoter" checkbox styling. [#5324] by [@faucct] ## 1.3.1 [☰](https://github.com/activeadmin/activeadmin/compare/v1.3.0...v1.3.1) ### Bug Fixes -* gemspec should have more permissive ransack dependency. [#5448][] by [@varyonic][] +* gemspec should have more permissive ransack dependency. [#5448] by [@varyonic] ## 1.3.0 [☰](https://github.com/activeadmin/activeadmin/compare/v1.2.1...v1.3.0) @@ -59,13 +66,13 @@ #### Major -* Rails 5.2 support [#5343][] by [@varyonic][], [#5399][], [#5401][] by [@zorab47][] +* Rails 5.2 support [#5343] by [@varyonic], [#5399], [#5401] by [@zorab47] ## 1.2.1 [☰](https://github.com/activeadmin/activeadmin/compare/v1.2.0...v1.2.1) ### Bug Fixes -* Resolve issue with [#5275][] preventing XSS in filters sidebar. [#5299][] by [@faucct][] +* Resolve issue with [#5275] preventing XSS in filters sidebar. [#5299] by [@faucct] ## 1.2.0 [☰](https://github.com/activeadmin/activeadmin/compare/v1.1.0...v1.2.0) @@ -73,41 +80,41 @@ #### Minor -* Do not display pagination info when there are no comments. [#5119][] by [@alex-bogomolov][] -* Revert generated config files to pluralized. [#5120][] by [@varyonic][], [#5137][] by [@deivid-rodriguez][] -* Warn when action definition overwrites controller method. [#5167][] by [@aarek][] -* Better performance of comments show view. [#5208][] by [@dhyegofernando][] -* Mitigate memory bloat [#4118][] with CSV exports. [#5251][] by [@f1sherman][] -* Fix issue applying custom decorations. [#5253][] by [@faucct][] -* Brazilian locale updated. [#5125][] by [@renotocn][] -* Japanese locale updated. [#5143][] by [@5t111111][], [#5157][] by [@innparusu95][] -* Italian locale updated. [#5180][] by [@blocknotes][] -* Swedish locale updated. [#5187][] by [@jawa][] -* Vietnamese locale updated. [#5194][] by [@Nguyenanh][] -* Esperanto locale added. [#5210][] by [@RobinvanderVliet][] +* Do not display pagination info when there are no comments. [#5119] by [@alex-bogomolov] +* Revert generated config files to pluralized. [#5120] by [@varyonic], [#5137] by [@deivid-rodriguez] +* Warn when action definition overwrites controller method. [#5167] by [@aarek] +* Better performance of comments show view. [#5208] by [@dhyegofernando] +* Mitigate memory bloat [#4118] with CSV exports. [#5251] by [@f1sherman] +* Fix issue applying custom decorations. [#5253] by [@faucct] +* Brazilian locale updated. [#5125] by [@renotocn] +* Japanese locale updated. [#5143] by [@5t111111], [#5157] by [@innparusu95] +* Italian locale updated. [#5180] by [@blocknotes] +* Swedish locale updated. [#5187] by [@jawa] +* Vietnamese locale updated. [#5194] by [@Nguyenanh] +* Esperanto locale added. [#5210] by [@RobinvanderVliet] ### Bug Fixes -* Fix a couple of issues rendering filter labels. [#5223][] by [@wspurgin][] -* Prevent NameError when filtering on a namespaced association. [#5240][] by [@DanielHeath][] -* Fix undefined method error in Ransack when building filters. [#5238][] by [@wspurgin][] -* Fixed [#5198][] Prevent XSS on sidebar's current filter rendering. [#5275][] by [@deivid-rodriguez][] -* Sanitize display_name. [#5284][] by [@markstory][] +* Fix a couple of issues rendering filter labels. [#5223] by [@wspurgin] +* Prevent NameError when filtering on a namespaced association. [#5240] by [@DanielHeath] +* Fix undefined method error in Ransack when building filters. [#5238] by [@wspurgin] +* Fixed [#5198] Prevent XSS on sidebar's current filter rendering. [#5275] by [@deivid-rodriguez] +* Sanitize display_name. [#5284] by [@markstory] ## 1.1.0 [☰](https://github.com/activeadmin/activeadmin/compare/v1.0.0...v1.1.0) ### Bug Fixes -* Fixed [#5093][] Handle table prefix & table suffix for `ActiveAdminComment` model -* Fixed [#4173][] by including the default Kaminari templates. [#5069][] by [@javierjulio][] -* Fixed [#5043][]. Do not crash in sidebar rendering when a default scope is not specified. [#5044][] by [@Fivell][] -* Fixed [#3894][]. Make tab's component work with non-ascii titles. [#5046][] by [@Fivell][] +* Fixed [#5093] Handle table prefix & table suffix for `ActiveAdminComment` model +* Fixed [#4173] by including the default Kaminari templates. [#5069] by [@javierjulio] +* Fixed [#5043]. Do not crash in sidebar rendering when a default scope is not specified. [#5044] by [@Fivell] +* Fixed [#3894]. Make tab's component work with non-ascii titles. [#5046] by [@Fivell] ### Removals -* Ruby 2.1 support has been dropped. [#5003][] by [@deivid-rodriguez][] -* Replaced `sass-rails` with `sass` dependency. [#5037][] by [@javierjulio][] -* Removed `jquery-ui-rails` as a dependency. [#5052][] by [@javierjulio][] +* Ruby 2.1 support has been dropped. [#5003] by [@deivid-rodriguez] +* Replaced `sass-rails` with `sass` dependency. [#5037] by [@javierjulio] +* Removed `jquery-ui-rails` as a dependency. [#5052] by [@javierjulio] The specific jQuery UI assets used are now within the vendor directory. This will be replaced by alternatives and dropped entirely in a major release. Please remove any direct inclusions of `//= require jquery-ui`. This allows us @@ -115,134 +122,134 @@ ### Deprecations -* Deprecated `config.register_stylesheet` and `config.register_javascript`. Import your CSS and JS files in `active_admin.scss` or `active_admin.js`. [#5060][] by [@javierjulio][] -* Deprecated `type` param from `status_tag` and related CSS classes [#4989][] by [@javierjulio][] - * The method signature has changed from: +* Deprecated `config.register_stylesheet` and `config.register_javascript`. Import your CSS and JS files in `active_admin.scss` or `active_admin.js`. [#5060] by [@javierjulio] +* Deprecated `type` param from `status_tag` and related CSS classes [#4989] by [@javierjulio] + The method signature has changed from: - ```ruby - status_tag(status, :ok, class: 'completed', label: 'on') - ``` + ```ruby + status_tag(status, :ok, class: 'completed', label: 'on') + ``` - to: + to: - ```ruby - status_tag(status, class: 'completed ok', label: 'on') - ``` + ```ruby + status_tag(status, class: 'completed ok', label: 'on') + ``` - * The following CSS classes have been deprecated and will be removed in the future: + The following CSS classes have been deprecated and will be removed in the future: - ```css - .status_tag { - &.ok, &.published, &.complete, &.completed, &.green { background: #8daa92; } - &.warn, &.warning, &.orange { background: #e29b20; } - &.error, &.errored, &.red { background: #d45f53; } - } - ``` + ```css + .status_tag { + &.ok, &.published, &.complete, &.completed, &.green { background: #8daa92; } + &.warn, &.warning, &.orange { background: #e29b20; } + &.error, &.errored, &.red { background: #d45f53; } + } + ``` ### Enhancements #### Minor -* Support proc as an input_html option value when declaring filters. [#5029][] by [@Fivell][] -* Base localization support, better associations handling for active filters sidebar. [#4951][] by [@Fivell][] -* Allow AA scopes to return paginated collections. [#4996][] by [@Fivell][] -* Added `scopes_show_count` configuration to setup show_count attribute for scopes globally. [#4950][] by [@Fivell][] -* Allow custom panel title given with `attributes_table`. [#4940][] by [@ajw725][] -* Allow passing a class to `action_item` block. [#4997][] by [@Fivell][] -* Add pagination to the comments section. [#5088][] by [@alex-bogomolov][] +* Support proc as an input_html option value when declaring filters. [#5029] by [@Fivell] +* Base localization support, better associations handling for active filters sidebar. [#4951] by [@Fivell] +* Allow AA scopes to return paginated collections. [#4996] by [@Fivell] +* Added `scopes_show_count` configuration to setup show_count attribute for scopes globally. [#4950] by [@Fivell] +* Allow custom panel title given with `attributes_table`. [#4940] by [@ajw725] +* Allow passing a class to `action_item` block. [#4997] by [@Fivell] +* Add pagination to the comments section. [#5088] by [@alex-bogomolov] -## 1.0.0 [☰](https://github.com/activeadmin/activeadmin/compare/v0.6.3...master) +## 1.0.0 [☰](https://github.com/activeadmin/activeadmin/compare/v0.6.3...v1.0.0) ### Breaking Changes -* Rename `allow_comments` to `comments` for more consistent naming. [#3695][] by [@pranas][] -* JavaScript `window.AA` has been removed, use `window.ActiveAdmin`. [#3606][] by [@timoschilling][] -* `f.form_buffers` has been removed. [#3486][] by [@varyonic][] -* Iconic has been removed. [#3553][] by [@timoschilling][] -* `config.show_comments_in_menu` has been removed, see `config.comments_menu`. [#4187][] by [@drn][] -* Rails 3.2 & Ruby 1.9.3 support has been dropped. [#4848][] by [@deivid-rodriguez][] -* Ruby 2.0.0 support has been dropped. [#4851][] by [@deivid-rodriguez][] -* Rails 4.0 & 4.1 support has been dropped. [#4870][] by [@deivid-rodriguez][] +* Rename `allow_comments` to `comments` for more consistent naming. [#3695] by [@pranas] +* JavaScript `window.AA` has been removed, use `window.ActiveAdmin`. [#3606] by [@timoschilling] +* `f.form_buffers` has been removed. [#3486] by [@varyonic] +* Iconic has been removed. [#3553] by [@timoschilling] +* `config.show_comments_in_menu` has been removed, see `config.comments_menu`. [#4187] by [@drn] +* Rails 3.2 & Ruby 1.9.3 support has been dropped. [#4848] by [@deivid-rodriguez] +* Ruby 2.0.0 support has been dropped. [#4851] by [@deivid-rodriguez] +* Rails 4.0 & 4.1 support has been dropped. [#4870] by [@deivid-rodriguez] ### Enhancements #### Major -* Migration from Metasearch to Ransack. [#1979][] by [@seanlinsley][] -* Rails 4 support. [#2326][] by many people :heart: -* Rails 4.2 support. [#3731][] by [@gonzedge][] and [@timoschilling][] -* Rails 5 support. [#4254][] by [@seanlinsley][] -* Rails 5.1 support. [#4882][] by [@varyonic][] +* Migration from Metasearch to Ransack. [#1979] by [@seanlinsley] +* Rails 4 support. [#2326] by many people :heart: +* Rails 4.2 support. [#3731] by [@gonzedge] and [@timoschilling] +* Rails 5 support. [#4254] by [@seanlinsley] +* Rails 5.1 support. [#4882] by [@varyonic] #### Minor -* "Create another" checkbox for the new resource page. [#4477][] by [@bolshakov][] -* Page supports belongs_to. [#4759][] by [@Fivell][] and [@zorab47][] -* Support for custom sorting strategies. [#4768][] by [@Fivell][] -* Stream CSV downloads as they're generated. [#3038][] by [@craigmcnamara][] - * Disable streaming in development for easier debugging. [#3535][] by [@seanlinsley][] -* Improved code reloading. [#3783][] by [@chancancode][] -* Do not auto link to inaccessible actions. [#3686][] by [@pranas][] -* Allow to enable comments on per-resource basis. [#3695][] by [@pranas][] -* Unify DSL for index `actions` and `actions dropdown: true`. [#3463][] by [@timoschilling][] -* Add DSL method `includes` for `ActiveRecord::Relation#includes`. [#3464][] by [@timoschilling][] -* BOM (byte order mark) configurable for CSV download. [#3519][] by [@timoschilling][] -* Column block on table index is now sortable by default. [#3075][] by [@dmitry][] -* Allow Arbre to be used inside ActiveAdmin forms. [#3486][] by [@varyonic][] -* Make AA ORM-agnostic. [#2545][] by [@johnnyshields][] -* Add multi-record support to `attributes_table_for`. [#2544][] by [@zorab47][] -* Table CSS classes are now prefixed to prevent clashes. [#2532][] by [@TimPetricola][] -* Allow Inherited Resources shorthand for redirection. [#2001][] by [@seanlinsley][] - -```ruby - controller do - # Redirects to index page instead of rendering updated resource - def update - update!{ collection_path } - end +* "Create another" checkbox for the new resource page. [#4477] by [@bolshakov] +* Page supports belongs_to. [#4759] by [@Fivell] and [@zorab47] +* Support for custom sorting strategies. [#4768] by [@Fivell] +* Stream CSV downloads as they're generated. [#3038] by [@craigmcnamara] + * Disable streaming in development for easier debugging. [#3535] by [@seanlinsley] +* Improved code reloading. [#3783] by [@chancancode] +* Do not auto link to inaccessible actions. [#3686] by [@pranas] +* Allow to enable comments on per-resource basis. [#3695] by [@pranas] +* Unify DSL for index `actions` and `actions dropdown: true`. [#3463] by [@timoschilling] +* Add DSL method `includes` for `ActiveRecord::Relation#includes`. [#3464] by [@timoschilling] +* BOM (byte order mark) configurable for CSV download. [#3519] by [@timoschilling] +* Column block on table index is now sortable by default. [#3075] by [@dmitry] +* Allow Arbre to be used inside ActiveAdmin forms. [#3486] by [@varyonic] +* Make AA ORM-agnostic. [#2545] by [@johnnyshields] +* Add multi-record support to `attributes_table_for`. [#2544] by [@zorab47] +* Table CSS classes are now prefixed to prevent clashes. [#2532] by [@TimPetricola] +* Allow Inherited Resources shorthand for redirection. [#2001] by [@seanlinsley] + + ```ruby + controller do + # Redirects to index page instead of rendering updated resource + def update + update!{ collection_path } end -``` + end + ``` -* Accept block for download links. [#2040][] by [@potatosalad][] +* Accept block for download links. [#2040] by [@potatosalad] -```ruby -index download_links: ->{ can?(:view_all_download_links) || [:pdf] } -``` + ```ruby + index download_links: ->{ can?(:view_all_download_links) || [:pdf] } + ``` -* Comments menu can be customized via configuration passed to `config.comments_menu`. [#4187][] by [@drn][] -* Added `config.route_options` to namespace to customize routes. [#4731][] by [@stereoscott[]] +* Comments menu can be customized via configuration passed to `config.comments_menu`. [#4187] by [@drn] +* Added `config.route_options` to namespace to customize routes. [#4731] by [@stereoscott] ### Security Fixes -* Prevents access to formats that the user not permitted to see. [#4867][] by [@Fivell][] and [@timoschilling][] -* Prevents potential DOS attack via Ruby symbols. [#1926][] by [@seanlinsley][] +* Prevents access to formats that the user not permitted to see. [#4867] by [@Fivell] and [@timoschilling] +* Prevents potential DOS attack via Ruby symbols. [#1926] by [@seanlinsley] * [this isn't an issue for those using Ruby >= 2.2](http://rubykaigi.org/2014/presentation/S-NarihiroNakamura) ### Bug Fixes -* Fixes filters for `has_many :through` relationships. [#2541][] by [@shekibobo][] -* "New" action item now only shows up on the index page. bf659bc by [@seanlinsley][] -* Fixes comment creation bug with aliased resources. 9a082486 by [@seanlinsley][] -* Fixes the deletion of `:if` and `:unless` from filters. [#2523][] by [@PChambino][] +* Fixes filters for `has_many :through` relationships. [#2541] by [@shekibobo] +* "New" action item now only shows up on the index page. bf659bc by [@seanlinsley] +* Fixes comment creation bug with aliased resources. 9a082486 by [@seanlinsley] +* Fixes the deletion of `:if` and `:unless` from filters. [#2523] by [@PChambino] ### Deprecations -* `ActiveAdmin::Event` (`ActiveAdmin::EventDispatcher`). [#3435][] by [@timoschilling][] +* `ActiveAdmin::Event` (`ActiveAdmin::EventDispatcher`). [#3435] by [@timoschilling] `ActiveAdmin::Event` will be removed in a future version, ActiveAdmin switched to use `ActiveSupport::Notifications` NOTE: The blog parameters has changed: -```ruby -ActiveSupport::Notifications.subscribe ActiveAdmin::Application::BeforeLoadEvent do |event, *args| - # some code -end + ```ruby + ActiveSupport::Notifications.subscribe ActiveAdmin::Application::BeforeLoadEvent do |event, *args| + # some code + end -ActiveSupport::Notifications.publish ActiveAdmin::Application::BeforeLoadEvent, "some data" -``` + ActiveSupport::Notifications.publish ActiveAdmin::Application::BeforeLoadEvent, "some data" + ``` ## Previous Changes -Please check [0-6-stable][] for previous changes. +Please check [0-6-stable] for previous changes. [0-6-stable]: https://github.com/activeadmin/activeadmin/blob/0-6-stable/CHANGELOG.md @@ -353,6 +360,7 @@ Please check [0-6-stable][] for previous changes. [#5517]: https://github.com/activeadmin/activeadmin/pull/5517 [#5537]: https://github.com/activeadmin/activeadmin/pull/5537 [#5583]: https://github.com/activeadmin/activeadmin/pull/5583 +[#5611]: https://github.com/activeadmin/activeadmin/pull/5611 [@5t111111]: https://github.com/5t111111 [@aarek]: https://github.com/aarek @@ -361,6 +369,7 @@ Please check [0-6-stable][] for previous changes. [@andreslemik]: https://github.com/andreslemik [@blocknotes]: https://github.com/blocknotes [@bolshakov]: https://github.com/bolshakov +[@buren]: https://github.com/buren [@chancancode]: https://github.com/chancancode [@chumakoff]: https://github.com/chumakoff [@craigmcnamara]: https://github.com/craigmcnamara @@ -400,6 +409,7 @@ Please check [0-6-stable][] for previous changes. [@shekibobo]: https://github.com/shekibobo [@shouya]: https://github.com/shouya [@stefsava]: https://github.com/stefsava +[@stereoscott]: https://github.com/stereoscott [@tiagotex]: https://github.com/tiagotex [@timoschilling]: https://github.com/timoschilling [@TimPetricola]: https://github.com/TimPetricola diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 18de30f2c25..7438c93086d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -184,7 +184,9 @@ Maintainers need to do the following to push out a release: * Make sure all pull requests are in and that changelog is current * Update `version.rb` file and changelog with new version number -* Create a stable branch for that release: +* If it's not a patch level release, create a stable branch for that release, + otherwise switch to the stable branch corresponding to the patch release you + want to ship: ```sh git checkout master @@ -195,8 +197,12 @@ Maintainers need to do the following to push out a release: git push activeadmin N-N-stable:N-N-stable ``` +* Make sure you have [chandler] properly configured. Chandler is used to + automatically submit github release notes from the changelog right after + pushing the gem to rubygems. * `bundle exec rake release` +[chandler]: https://github.com/mattbrictson/chandler#2-configure-credentials [chromedriver]: https://sites.google.com/a/chromium.org/chromedriver/getting-started [mailing list]: http://groups.google.com/group/activeadmin [Stack Overflow]: http://stackoverflow.com/questions/tagged/activeadmin diff --git a/Gemfile b/Gemfile index 406cc9253e8..dafbcb72da0 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,27 @@ source "https://rubygems.org" eval_gemfile(File.expand_path("Gemfile.common", __dir__)) -gem "rails", "~> 5.2.x" +group :release do + gem 'chandler', git: 'https://github.com/deivid-rodriguez/chandler', branch: 'submit_link_references' # Github releases from changelog +end + +group :lint do + # Code style + gem 'rubocop', '0.59.2' + gem 'rubocop-rspec', '~> 1.30' + gem 'mdl', '0.5.0' + + # Translations + gem 'i18n-tasks' + gem 'i18n-spec' +end + +group :docs do + gem 'yard' # Documentation generator + gem 'kramdown' # Markdown implementation (for yard) +end + +gem "rails", "~> 5.2.1" gem "devise", "~> 4.4" gem "draper", "~> 3.0" gem "activerecord-jdbcsqlite3-adapter", ">= 52.0", platforms: :jruby diff --git a/Gemfile.common b/Gemfile.common index b2b8450cfc1..9f5d7f90016 100644 --- a/Gemfile.common +++ b/Gemfile.common @@ -1,51 +1,24 @@ -# Optional dependencies -gem 'cancan' -gem 'pundit' -gem 'jruby-openssl', '~> 0.10.1', platforms: :jruby - # Utility gems used in both development & test environments gem 'rake' -gem 'parallel_tests', '~> 2.26' - -# Debugging gem 'pry' # Easily debug from your console with `binding.pry` -gem 'pry-byebug', platforms: :mri - -group :lint do - # Code style - gem 'rubocop', '0.59.2' - gem 'mdl', '0.4.0' - - # Translations - gem 'i18n-tasks' - gem 'i18n-spec' -end - -# Documentation -gem 'yard' # Documentation generator -gem 'redcarpet', platforms: :mri # Markdown implementation (for yard) -gem 'kramdown', platforms: :jruby # Markdown implementation (for yard) - -group :development do - # Debugging - gem 'better_errors' # Web UI to debug exceptions. Go to /__better_errors to access the latest one - - gem 'binding_of_caller', platforms: :mri # Retrieve the binding of a method's caller - - # Performance - gem 'rack-mini-profiler', '>= 0.10.1' # Inline app profiler. See ?pp=help for options. -end +gem 'pry-byebug', platforms: :mri # Step-by-step debugging group :test do gem 'capybara', '~> 3.10' + + # Optional dependencies + gem 'cancan' + gem 'pundit' + gem 'jruby-openssl', '~> 0.10.1', platforms: :jruby + gem 'simplecov', require: false # Test coverage generator. Go to /coverage/ after running tests - gem 'codecov', require: false # Test coverage website. Go to https://codecov.io gem 'cucumber-rails', '~> 1.5', require: false gem 'cucumber' gem 'database_cleaner' gem 'jasmine' gem 'jasmine-core', '2.9.1' # last release with Ruby 2.2 support. gem 'launchy' + gem 'parallel_tests', '~> 2.26' gem 'rails-i18n' # Provides default i18n for many languages gem 'rspec-rails' gem 'sqlite3', platforms: :mri diff --git a/Gemfile.lock b/Gemfile.lock index c98a415433e..ae3026e3abf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,16 @@ +GIT + remote: https://github.com/deivid-rodriguez/chandler + revision: 71ca85925b54a1b1e6ba785efa450a012364efe6 + branch: submit_link_references + specs: + chandler (0.7.0) + netrc + octokit (>= 2.2.0) + PATH remote: . specs: - activeadmin (1.4.2) + activeadmin (1.4.3) arbre (>= 1.1.1) coffee-rails formtastic (~> 3.1) @@ -17,52 +26,52 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (5.2.1) - actionpack (= 5.2.1) + actioncable (5.2.1.1) + actionpack (= 5.2.1.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.1) - actionpack (= 5.2.1) - actionview (= 5.2.1) - activejob (= 5.2.1) + actionmailer (5.2.1.1) + actionpack (= 5.2.1.1) + actionview (= 5.2.1.1) + activejob (= 5.2.1.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.1) - actionview (= 5.2.1) - activesupport (= 5.2.1) + actionpack (5.2.1.1) + actionview (= 5.2.1.1) + activesupport (= 5.2.1.1) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.1) - activesupport (= 5.2.1) + actionview (5.2.1.1) + activesupport (= 5.2.1.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.1) - activesupport (= 5.2.1) + activejob (5.2.1.1) + activesupport (= 5.2.1.1) globalid (>= 0.3.6) - activemodel (5.2.1) - activesupport (= 5.2.1) + activemodel (5.2.1.1) + activesupport (= 5.2.1.1) activemodel-serializers-xml (1.0.2) activemodel (> 5.x) activesupport (> 5.x) builder (~> 3.1) - activerecord (5.2.1) - activemodel (= 5.2.1) - activesupport (= 5.2.1) + activerecord (5.2.1.1) + activemodel (= 5.2.1.1) + activesupport (= 5.2.1.1) arel (>= 9.0) activerecord-jdbc-adapter (52.1-java) activerecord (~> 5.2.0) activerecord-jdbcsqlite3-adapter (52.1-java) activerecord-jdbc-adapter (= 52.1) jdbc-sqlite3 (~> 3.8, < 3.30) - activestorage (5.2.1) - actionpack (= 5.2.1) - activerecord (= 5.2.1) + activestorage (5.2.1.1) + actionpack (= 5.2.1.1) + activerecord (= 5.2.1.1) marcel (~> 0.3.1) - activesupport (5.2.1) + activesupport (5.2.1.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -76,16 +85,10 @@ GEM backports (3.11.4) bcrypt (3.1.12) bcrypt (3.1.12-java) - better_errors (2.5.0) - coderay (>= 1.0.0) - erubi (>= 1.0.0) - rack (>= 0.9.0) - binding_of_caller (0.8.0) - debug_inspector (>= 0.0.1) builder (3.2.3) byebug (10.0.2) cancan (1.6.10) - capybara (3.10.0) + capybara (3.12.0) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) @@ -95,10 +98,6 @@ GEM xpath (~> 3.2) childprocess (0.9.0) ffi (~> 1.0, >= 1.0.11) - codecov (0.1.13) - json - simplecov - url coderay (1.1.2) coffee-rails (4.2.2) coffee-script (>= 2.2.0) @@ -132,7 +131,6 @@ GEM cucumber-tag_expressions (1.1.1) cucumber-wire (0.0.1) database_cleaner (1.7.0) - debug_inspector (0.0.3) devise (4.5.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -149,6 +147,8 @@ GEM request_store (~> 1.0) erubi (1.7.1) execjs (2.7.0) + faraday (0.15.4) + multipart-post (>= 1.2, < 3) ffi (1.9.25) ffi (1.9.25-java) formtastic (3.1.5) @@ -222,11 +222,11 @@ GEM mini_mime (>= 0.1.1) marcel (0.3.3) mimemagic (~> 0.3.2) - mdl (0.4.0) + mdl (0.5.0) kramdown (~> 1.12, >= 1.12.0) mixlib-cli (~> 1.7, >= 1.7.0) mixlib-config (~> 2.2, >= 2.2.1) - method_source (0.9.0) + method_source (0.9.2) mime-types (3.2.2) mime-types-data (~> 3.2015) mime-types-data (3.2018.0812) @@ -239,11 +239,15 @@ GEM tomlrb multi_json (1.13.1) multi_test (0.1.2) + multipart-post (2.0.0) + netrc (0.11.0) nio4r (2.3.1) nio4r (2.3.1-java) nokogiri (1.8.5) mini_portile2 (~> 2.3.0) nokogiri (1.8.5-java) + octokit (4.13.0) + sawyer (~> 0.8.0, >= 0.5.3) orm_adapter (0.5.0) parallel (1.12.1) parallel_tests (2.26.0) @@ -265,23 +269,21 @@ GEM public_suffix (3.0.3) pundit (2.0.0) activesupport (>= 3.0.0) - rack (2.0.5) - rack-mini-profiler (1.0.0) - rack (>= 1.2.0) + rack (2.0.6) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.1) - actioncable (= 5.2.1) - actionmailer (= 5.2.1) - actionpack (= 5.2.1) - actionview (= 5.2.1) - activejob (= 5.2.1) - activemodel (= 5.2.1) - activerecord (= 5.2.1) - activestorage (= 5.2.1) - activesupport (= 5.2.1) + rails (5.2.1.1) + actioncable (= 5.2.1.1) + actionmailer (= 5.2.1.1) + actionpack (= 5.2.1.1) + actionview (= 5.2.1.1) + activejob (= 5.2.1.1) + activemodel (= 5.2.1.1) + activerecord (= 5.2.1.1) + activestorage (= 5.2.1.1) + activesupport (= 5.2.1.1) bundler (>= 1.3.0) - railties (= 5.2.1) + railties (= 5.2.1.1) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) @@ -291,9 +293,9 @@ GEM rails-i18n (5.1.1) i18n (>= 0.7, < 2) railties (>= 5.0, < 6) - railties (5.2.1) - actionpack (= 5.2.1) - activesupport (= 5.2.1) + railties (5.2.1.1) + actionpack (= 5.2.1.1) + activesupport (= 5.2.1.1) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) @@ -308,8 +310,7 @@ GEM rb-fsevent (0.10.3) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) - redcarpet (3.4.0) - regexp_parser (1.2.0) + regexp_parser (1.3.0) request_store (1.4.1) rack (>= 1.4) responders (2.4.0) @@ -340,6 +341,8 @@ GEM rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) + rubocop-rspec (1.30.0) + rubocop (>= 0.58.0) ruby-progressbar (1.10.0) rubyzip (1.2.2) sass (3.7.2) @@ -347,6 +350,9 @@ GEM sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) + sawyer (0.8.1) + addressable (>= 2.3.5, < 2.6) + faraday (~> 0.8, < 1.0) selenium-webdriver (3.141.0) childprocess (~> 0.5) rubyzip (~> 1.2, >= 1.2.2) @@ -367,14 +373,13 @@ GEM sqlite3 (1.3.13) terminal-table (1.8.0) unicode-display_width (~> 1.1, >= 1.1.1) - thor (0.20.0) + thor (0.20.3) thread_safe (0.3.6) thread_safe (0.3.6-java) tomlrb (1.2.7) tzinfo (1.2.5) thread_safe (~> 0.1) unicode-display_width (1.4.0) - url (0.3.2) warden (1.2.7) rack (>= 1.0) websocket-driver (0.7.0) @@ -393,11 +398,9 @@ PLATFORMS DEPENDENCIES activeadmin! activerecord-jdbcsqlite3-adapter (>= 52.0) - better_errors - binding_of_caller cancan capybara (~> 3.10) - codecov + chandler! cucumber cucumber-rails (~> 1.5) database_cleaner @@ -410,18 +413,17 @@ DEPENDENCIES jruby-openssl (~> 0.10.1) kramdown launchy - mdl (= 0.4.0) + mdl (= 0.5.0) parallel_tests (~> 2.26) pry pry-byebug pundit - rack-mini-profiler (>= 0.10.1) - rails (~> 5.2.x) + rails (~> 5.2.1) rails-i18n rake - redcarpet rspec-rails rubocop (= 0.59.2) + rubocop-rspec (~> 1.30) selenium-webdriver simplecov sqlite3 diff --git a/README.md b/README.md index 10656c5d343..c7e847ecf51 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ creating elegant backends for website administration. [![Version ][rubygems_badge]][rubygems] [![Circle CI ][circle_badge]][circle] -[![Coverage ][codecov_badge]][codecov] +[![Coverage ][coverage_badge]][coverage] [![Tidelift ][tidelift_badge]][tidelift] [![Inch CI ][inch_badge]][inch] @@ -67,8 +67,8 @@ Tool | Description [rubygems]: https://rubygems.org/gems/activeadmin [circle_badge]: https://circleci.com/gh/activeadmin/activeadmin/tree/master.svg [circle]: https://circleci.com/gh/activeadmin/activeadmin/tree/master -[codecov_badge]: https://codecov.io/gh/activeadmin/activeadmin/branch/master/graph/badge.svg -[codecov]: https://codecov.io/gh/activeadmin/activeadmin +[coverage_badge]: https://api.codeclimate.com/v1/badges/779e407d22bacff19733/test_coverage +[coverage]: https://codeclimate.com/github/activeadmin/activeadmin/test_coverage [inch_badge]: http://inch-ci.org/github/activeadmin/activeadmin.svg?branch=master [inch]: http://inch-ci.org/github/activeadmin/activeadmin [tidelift_badge]: https://tidelift.com/badges/github/activeadmin/activeadmin diff --git a/Rakefile b/Rakefile index 1c69f329e70..95280d2695a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,18 +1,19 @@ require 'bundler/gem_tasks' -# Import all our rake tasks -FileList['tasks/**/*.rake'].each { |task| import task } +import 'tasks/gemfiles.rake' +import 'tasks/local.rake' +import 'tasks/test.rake' + +if ENV['BUNDLE_GEMFILE'] == File.expand_path('Gemfile') + import 'tasks/docs.rake' + import 'tasks/lint.rake' + import 'tasks/release.rake' +end task default: :test -begin - require 'jasmine' - load 'jasmine/tasks/jasmine.rake' -rescue LoadError - task :jasmine do - abort 'Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine' - end -end +require 'jasmine' +load 'jasmine/tasks/jasmine.rake' task :console do require 'irb' diff --git a/codecov.yml b/codecov.yml deleted file mode 100644 index cd38ec20576..00000000000 --- a/codecov.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- - -codecov: - notify: - require_ci_to_pass: true - -comment: off - -coverage: - precision: 2 - - range: - - 70.0 - - 100.0 - - round: down - - status: - changes: false - - patch: true - - project: - default: - threshold: 1% diff --git a/features/index/batch_actions.feature b/features/index/batch_actions.feature index c5271d93ecc..573ba9af243 100644 --- a/features/index/batch_actions.feature +++ b/features/index/batch_actions.feature @@ -113,6 +113,34 @@ Feature: Batch Actions Given I submit the batch action form with "flag" Then I should see a flash with "Successfully flagged 10 posts" + Scenario: Using a custom batch action with form as Hash + Given 10 posts exist + And an index configuration of: + """ + ActiveAdmin.register Post do + batch_action(:flag, form: {type: ["a", "b"]}) do + redirect_to collection_path, notice: "Successfully flagged 10 posts" + end + end + """ + When I check the 1st record + Given I submit the batch action form with "flag" + Then I should see a flash with "Successfully flagged 10 posts" + + Scenario: Using a custom batch action with form as proc + Given 10 posts exist + And an index configuration of: + """ + ActiveAdmin.register Post do + batch_action(:flag, form: -> { {type: params[:type]} }) do + redirect_to collection_path, notice: "Successfully flagged 10 posts" + end + end + """ + When I check the 1st record + Given I submit the batch action form with "flag" + Then I should see a flash with "Successfully flagged 10 posts" + Scenario: Disabling batch actions for a resource Given 10 posts exist And an index configuration of: diff --git a/features/index/index_scope_to.feature b/features/index/index_scope_to.feature index 564f07a5e08..3a9c8e1a854 100644 --- a/features/index/index_scope_to.feature +++ b/features/index/index_scope_to.feature @@ -6,6 +6,8 @@ Feature: Index Scope To Given 10 posts exist And a post with the title "Hello World" written by "John Doe" exists And a published post with the title "Hello World" written by "John Doe" exists + + Scenario: Viewing the default scope counts Given an index configuration of: """ ActiveAdmin.register Post do @@ -21,8 +23,28 @@ Feature: Index Scope To end end """ + When I am on the index page for posts + Then I should see the scope "All" selected + And I should see the scope "All" with the count 2 + And I should see 2 posts in the table - Scenario: Viewing the default scope counts + When I follow "Published" + Then I should see 1 posts in the table + + Scenario: Viewing the default scope counts when using proc + Given an index configuration of: + """ + ActiveAdmin.register Post do + # Scope section to a specific author + scope_to ->{ User.find_by_first_name_and_last_name "John", "Doe" } + + # Set up some scopes + scope :all, default: true + scope :published do |posts| + posts.where "published_date IS NOT NULL" + end + end + """ When I am on the index page for posts Then I should see the scope "All" selected And I should see the scope "All" with the count 2 diff --git a/features/step_definitions/attribute_steps.rb b/features/step_definitions/attribute_steps.rb index f4d5ea7cad3..8041805c603 100644 --- a/features/step_definitions/attribute_steps.rb +++ b/features/step_definitions/attribute_steps.rb @@ -8,11 +8,6 @@ expect(text).to match /\w+ \d{1,2}, \d{4} \d{2}:\d{2}/ end -Then /^the attribute "([^"]*)" should be empty$/ do |title| - elems = all ".attributes_table th:contains('#{title}') ~ td > span.empty" - expect(elems.first).to_not eq(nil), 'attribute not empty' -end - Then /^I should not see the attribute "([^"]*)"$/ do |title| expect(page).to_not have_css '.attributes_table th', text: title end diff --git a/features/step_definitions/batch_action_steps.rb b/features/step_definitions/batch_action_steps.rb index 850df852e03..cb7a817f576 100644 --- a/features/step_definitions/batch_action_steps.rb +++ b/features/step_definitions/batch_action_steps.rb @@ -23,10 +23,6 @@ page.all("table.index_table input[type=checkbox]")[index.to_i].set true end -When /^I toggle the collection selection$/ do - page.find("#collection_selection_toggle_all").click -end - Then /^I should see that the batch action button is disabled$/ do expect(page).to have_css ".batch_actions_selector .dropdown_menu_button.disabled" end diff --git a/features/step_definitions/comment_steps.rb b/features/step_definitions/comment_steps.rb index d8d890e7f72..2fc162a51b4 100644 --- a/features/step_definitions/comment_steps.rb +++ b/features/step_definitions/comment_steps.rb @@ -7,10 +7,6 @@ step %{I press "Add Comment"} end -Given /^a tag with the name "([^"]*)" exists$/ do |tag_name| - Tag.create(name: tag_name) -end - Given /^(a|\d+) comments added by admin with an email "([^"]+)"?$/ do |number, email| number = number == 'a' ? 1 : number.to_i admin_user = ensure_user_created(email) diff --git a/features/step_definitions/configuration_steps.rb b/features/step_definitions/configuration_steps.rb index 75300ddbb2d..7e5df218f2b 100644 --- a/features/step_definitions/configuration_steps.rb +++ b/features/step_definitions/configuration_steps.rb @@ -64,7 +64,9 @@ def rollback_file(file, contents) when 'Category' step 'I am on the index page for categories' else + # :nocov: raise "#{resource} is not supported" + # :nocov: end when 'show' case resource = config_content.match(/ActiveAdmin\.register (\w+)/)[1] @@ -77,7 +79,9 @@ def rollback_file(file, contents) Tag.create! visit admin_tag_path Tag.last else + # :nocov: raise "#{resource} is not supported" + # :nocov: end end end diff --git a/features/step_definitions/dashboard_steps.rb b/features/step_definitions/dashboard_steps.rb index 2a60a07f01d..318ede56555 100644 --- a/features/step_definitions/dashboard_steps.rb +++ b/features/step_definitions/dashboard_steps.rb @@ -1,15 +1,3 @@ -Then /^I should see the default welcome message$/ do - step %{I should see "Welcome to Active Admin" within "#dashboard_default_message"} -end - Then /^I should not see the default welcome message$/ do step %{I should not see "Welcome to Active Admin"} end - -Then /^I should see a dashboard widget "([^"]*)"$/ do |name| - expect(page).to have_css '.dashboard .panel h3', text: name -end - -Then /^I should not see a dashboard widget "([^"]*)"$/ do |name| - expect(page).to_not have_css '.dashboard .panel h3', text: name -end diff --git a/features/step_definitions/footer_steps.rb b/features/step_definitions/footer_steps.rb index e3b40c5484a..bfd7ad6b535 100644 --- a/features/step_definitions/footer_steps.rb +++ b/features/step_definitions/footer_steps.rb @@ -15,7 +15,3 @@ Then /^I should see the footer "([^"]*)"$/ do |footer| expect(page).to have_css '#footer', text: footer end - -Then /^I should not see the footer "([^"]*)"$/ do |footer| - expect(page).to_not have_css '#footer', text: footer -end diff --git a/features/step_definitions/table_steps.rb b/features/step_definitions/table_steps.rb index e803dcb98e9..ef50b02a92e 100644 --- a/features/step_definitions/table_steps.rb +++ b/features/step_definitions/table_steps.rb @@ -35,25 +35,11 @@ def cell_to_string(td) def input_to_string(input) case input.attribute("type").value when "checkbox" - if input.attribute("disabled") - "_" - else - if input.attribute("checked") - "[X]" - else - "[ ]" - end - end - when "text" - if input.attribute("value").present? - "[#{input.attribute("value")}]" - else - "[ ]" - end - when "submit" - input.attribute("value") + "[ ]" else + # :nocov: raise "I don't know what to do with #{input}" + # :nocov: end end end @@ -77,12 +63,14 @@ def assert_tables_match(table, expected_table) begin assert_cells_match(cell, expected_cell) rescue + # :nocov: puts "Cell at line #{row_index} and column #{column_index}: #{cell.inspect} does not match #{expected_cell.inspect}" puts "Expecting:" table.each { |row| puts row.inspect } puts "to match:" expected_table.each { |row| puts row.inspect } raise $! + # :nocov: end end end diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index c6edf8dfea0..2b47a73364a 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -1,10 +1,5 @@ def ensure_user_created(email) - user = AdminUser.where(email: email).first_or_create(password: 'password', password_confirmation: 'password') - - unless user.persisted? - raise "Could not create user #{email}: #{user.errors.full_messages}" - end - user + AdminUser.create_with(password: 'password', password_confirmation: 'password').find_or_create_by!(email: email) end Given /^(?:I am logged|log) out$/ do diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index bc2d51108ed..c4065432aa6 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -9,49 +9,39 @@ def with_scope(locator) end World(WithinHelpers) -# Single-line step scoper -When /^(.*) within (.*[^:])$/ do |step_name, parent| +When /^(.*) within (.*)$/ do |step_name, parent| with_scope(parent) { step step_name } end -# Multi-line step scoper -When /^(.*) within (.*[^:]):$/ do |step_name, parent, table_or_string| - with_scope(parent) { step "#{step_name}:", table_or_string } -end - -Given /^(?:I )am on (.+)$/ do |page_name| +Given /^I am on (.+)$/ do |page_name| visit path_to(page_name) end -When /^(?:I )go to (.+)$/ do |page_name| +When /^I go to (.+)$/ do |page_name| visit path_to(page_name) end -When /^(?:I )press "([^"]*)"$/ do |button| +When /^I press "([^"]*)"$/ do |button| click_button(button) end -When /^(?:I )follow "([^"]*)"$/ do |link| +When /^I follow "([^"]*)"$/ do |link| first(:link, link).click end -When /^(?:I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value| +When /^I fill in "([^"]*)" with "([^"]*)"$/ do |field, value| fill_in(field, with: value) end -When /^(?:I )select "([^"]*)" from "([^"]*)"$/ do |value, field| +When /^I select "([^"]*)" from "([^"]*)"$/ do |value, field| select(value, from: field) end -When /^(?:I )(check|uncheck|choose) "([^"]*)"$/ do |action, field| +When /^I (check|uncheck) "([^"]*)"$/ do |action, field| send action, field end -When /^(?:I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field| - attach_file(field, File.expand_path(path)) -end - -Then /^(?:I )should( not)? see( the element)? "([^"]*)"$/ do |negate, is_css, text| +Then /^I should( not)? see( the element)? "([^"]*)"$/ do |negate, is_css, text| should = negate ? :not_to : :to have = is_css ? have_css(text) : have_content(text) expect(page).send should, have @@ -77,6 +67,6 @@ def with_scope(locator) end end -Then /^(?:|I )should be on (.+)$/ do |page_name| +Then /^I should be on (.+)$/ do |page_name| expect(URI.parse(current_url).path).to eq path_to page_name end diff --git a/features/support/env.rb b/features/support/env.rb index 525a635af1e..a679da84d64 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,9 +1,3 @@ -# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. -# It is recommended to regenerate this file in the future when you upgrade to a -# newer version of cucumber-rails. Consider adding your own code to a new file -# instead of editing this one. Cucumber will automatically load all features/**/*.rb -# files. - ENV['RAILS_ENV'] = 'test' require 'simplecov' if ENV["COVERAGE"] == "true" @@ -12,25 +6,14 @@ require f end -require 'rails' -ENV['RAILS_ROOT'] = File.expand_path("../../../spec/rails/rails-#{Rails.version}", __FILE__) - -require 'active_record' -require 'active_admin' -require 'devise' -ActiveAdmin.application.load_paths = [ENV['RAILS_ROOT'] + "/app/admin"] - -require ENV['RAILS_ROOT'] + '/config/environment' - -# Setup autoloading of ActiveAdmin -autoload :ActiveAdmin, 'active_admin' +require_relative "../../spec/rails/rails-#{Gem.loaded_specs["rails"].version}/config/environment" -require 'cucumber/rails' +require_relative 'rails' require 'rspec/mocks' World(RSpec::Mocks::ExampleMethods) -Around do |scenario, block| +Around '@mocks' do |scenario, block| RSpec::Mocks.setup block.call @@ -43,20 +26,37 @@ end After '@debug' do |scenario| + # :nocov: save_and_open_page if scenario.failed? + # :nocov: +end + +require 'capybara/dsl' + +World(Capybara::DSL) + +After do + Capybara.reset_sessions! +end + +Before do + Capybara.use_default_driver end -require 'capybara/rails' -require 'capybara/cucumber' -require 'capybara/session' -require 'selenium-webdriver' +Before '@javascript' do + Capybara.current_driver = Capybara.javascript_driver +end -# copied from https://about.gitlab.com/2017/12/19/moving-to-headless-chrome/ Capybara.register_driver :chrome do |app| - options = Selenium::WebDriver::Chrome::Options.new( - args: %w[headless disable-gpu no-sandbox] - ) - Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) + Capybara::Selenium::Driver.load_selenium + + options = Selenium::WebDriver::Chrome::Options.new + options.args << '--headless' + + http_client = Selenium::WebDriver::Remote::Http::Default.new + http_client.read_timeout = 180 + + Capybara::Selenium::Driver.new(app, browser: :chrome, options: options, http_client: http_client) end Capybara.javascript_driver = :chrome @@ -125,5 +125,5 @@ end Around '@locale_manipulation' do |scenario, block| - I18n.with_locale(:en) { block.call } + I18n.with_locale(:en, &block) end diff --git a/features/support/paths.rb b/features/support/paths.rb index 4a1254dcec8..908c8c48e89 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -8,8 +8,6 @@ module NavigationHelpers def path_to(page_name) case page_name - when /the home\s?page/ - '/' when /the dashboard/ "/admin" when /the new post page/ @@ -23,14 +21,9 @@ def path_to(page_name) when /the admin password reset form with token "([^"]*)"/ "/admin/password/edit?reset_password_token=#{$1}" - # the index page for posts in the root namespace # the index page for posts in the user_admin namespace when /^the index page for (.*) in the (.*) namespace$/ - if $2 != 'root' - send "#{$2}_#{$1}_path" - else - send "#{$1}_path" - end + send "#{$2}_#{$1}_path" # same as above, except defaults to admin namespace when /^the index page for (.*)$/ @@ -62,9 +55,11 @@ def path_to(page_name) page_name =~ /the (.*) page/ path_components = $1.split(/\s+/) self.send path_components.push('path').join('_') + # :nocov: rescue Object => e raise "Can't find mapping from \"#{page_name}\" to a path.\n" + "Now, go and add a mapping in #{__FILE__}" + # :nocov: end end end diff --git a/features/support/rails.rb b/features/support/rails.rb new file mode 100644 index 00000000000..7968a40c3df --- /dev/null +++ b/features/support/rails.rb @@ -0,0 +1,8 @@ +require 'cucumber/rails/application' +require 'cucumber/rails/action_controller' +require 'cucumber/rails/world' +require 'cucumber/rails/hooks' +require 'cucumber/rails/capybara' +require 'cucumber/rails/database' + +MultiTest.disable_autorun diff --git a/features/support/regular_env.rb b/features/support/regular_env.rb index dc2fce76492..0afe2885ed2 100644 --- a/features/support/regular_env.rb +++ b/features/support/regular_env.rb @@ -1,7 +1,7 @@ if ENV["COVERAGE"] == "true" require 'simplecov' - SimpleCov.command_name "regular features" + SimpleCov.command_name ["regular features", ENV['TEST_ENV_NUMBER']].compact.join(" ") end require_relative 'env' diff --git a/features/support/selectors.rb b/features/support/selectors.rb index 26526291079..fa0355e33b0 100644 --- a/features/support/selectors.rb +++ b/features/support/selectors.rb @@ -8,9 +8,6 @@ module HtmlSelectorsHelpers def selector_for(locator) case locator - when "the page" - "html > body" - # Add more mappings here. # Here is an example that pulls values out of the Regexp: # @@ -36,8 +33,10 @@ def selector_for(locator) $1 else + # :nocov: raise "Can't find mapping from \"#{locator}\" to a selector.\n" + "Now, go and add a mapping in #{__FILE__}" + # :nocov: end end end diff --git a/features/users/resetting_password.feature b/features/users/resetting_password.feature index f091295bafe..799b0d39b2f 100644 --- a/features/users/resetting_password.feature +++ b/features/users/resetting_password.feature @@ -13,6 +13,7 @@ Feature: User Resetting Password And I press "Reset My Password" Then I should see "You will receive an email with instructions on how to reset your password in a few minutes." + @mocks Scenario: Changing password after resetting When "admin@example.com" requests a password reset with token "foobarbaz" When I go to the admin password reset form with token "foobarbaz" @@ -21,6 +22,7 @@ Feature: User Resetting Password And I press "Change my password" Then I should see "success" + @mocks Scenario: Changing password after resetting with errors When "admin@example.com" requests a password reset with token "foobarbaz" but it expires When I go to the admin password reset form with token "foobarbaz" diff --git a/gemfiles/rails_42.gemfile b/gemfiles/rails_42.gemfile index 332ab20b3b5..6281727cfb7 100644 --- a/gemfiles/rails_42.gemfile +++ b/gemfiles/rails_42.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" eval_gemfile(File.expand_path(File.join("..", "Gemfile.common"), __dir__)) -gem "rails", "4.2.10" +gem "rails", "~> 4.2.10" gem "devise", "~> 4.4" # required for Ruby 2.5, see devise/issues/4736 gem "draper", "~> 2.1" gem "activerecord-jdbcsqlite3-adapter", "~> 1.3", platforms: :jruby diff --git a/gemfiles/rails_42.gemfile.lock b/gemfiles/rails_42.gemfile.lock index af5690d97d7..a2d8480a073 100644 --- a/gemfiles/rails_42.gemfile.lock +++ b/gemfiles/rails_42.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - activeadmin (1.4.2) + activeadmin (1.4.3) arbre (>= 1.1.1) coffee-rails formtastic (~> 3.1) @@ -17,41 +17,41 @@ PATH GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.10) - actionpack (= 4.2.10) - actionview (= 4.2.10) - activejob (= 4.2.10) + actionmailer (4.2.11) + actionpack (= 4.2.11) + actionview (= 4.2.11) + activejob (= 4.2.11) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.10) - actionview (= 4.2.10) - activesupport (= 4.2.10) + actionpack (4.2.11) + actionview (= 4.2.11) + activesupport (= 4.2.11) rack (~> 1.6) rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.10) - activesupport (= 4.2.10) + actionview (4.2.11) + activesupport (= 4.2.11) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (4.2.10) - activesupport (= 4.2.10) + activejob (4.2.11) + activesupport (= 4.2.11) globalid (>= 0.3.0) - activemodel (4.2.10) - activesupport (= 4.2.10) + activemodel (4.2.11) + activesupport (= 4.2.11) builder (~> 3.1) - activerecord (4.2.10) - activemodel (= 4.2.10) - activesupport (= 4.2.10) + activerecord (4.2.11) + activemodel (= 4.2.11) + activesupport (= 4.2.11) arel (~> 6.0) activerecord-jdbc-adapter (1.3.25) activerecord (>= 2.2, < 5.0) activerecord-jdbcsqlite3-adapter (1.3.25) activerecord-jdbc-adapter (~> 1.3.25) jdbc-sqlite3 (>= 3.7.2, < 3.9) - activesupport (4.2.10) + activesupport (4.2.11) i18n (~> 0.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) @@ -61,20 +61,13 @@ GEM arbre (1.1.1) activesupport (>= 3.0.0) arel (6.0.4) - ast (2.4.0) backports (3.11.4) bcrypt (3.1.12) bcrypt (3.1.12-java) - better_errors (2.5.0) - coderay (>= 1.0.0) - erubi (>= 1.0.0) - rack (>= 0.9.0) - binding_of_caller (0.8.0) - debug_inspector (>= 0.0.1) builder (3.2.3) byebug (10.0.2) cancan (1.6.10) - capybara (3.10.0) + capybara (3.12.0) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) @@ -84,10 +77,6 @@ GEM xpath (~> 3.2) childprocess (0.9.0) ffi (~> 1.0, >= 1.0.11) - codecov (0.1.13) - json - simplecov - url coderay (1.1.2) coffee-rails (4.2.2) coffee-script (>= 2.2.0) @@ -121,7 +110,6 @@ GEM cucumber-tag_expressions (1.1.1) cucumber-wire (0.0.1) database_cleaner (1.7.0) - debug_inspector (0.0.3) devise (4.5.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -135,7 +123,6 @@ GEM activemodel (>= 3.0) activesupport (>= 3.0) request_store (~> 1.0) - erubi (1.7.1) erubis (2.7.0) execjs (2.7.0) ffi (1.9.25) @@ -149,29 +136,13 @@ GEM has_scope (0.7.2) actionpack (>= 4.1) activesupport (>= 4.1) - highline (2.0.0) i18n (0.9.5) concurrent-ruby (~> 1.0) - i18n-spec (0.6.0) - iso - i18n-tasks (0.9.25) - activesupport (>= 4.0.2) - ast (>= 2.1.0) - erubi - highline (>= 2.0.0) - i18n - parser (>= 2.2.3.0) - rainbow (>= 2.2.2, < 4.0) - terminal-table (>= 1.5.1) inherited_resources (1.9.0) actionpack (>= 4.2, < 5.3) has_scope (~> 0.6) railties (>= 4.2, < 5.3) responders - iso (0.2.2) - i18n - jaro_winkler (1.5.1) - jaro_winkler (1.5.1-java) jasmine (2.9.0) jasmine-core (>= 2.9.0, < 3.0.0) phantomjs @@ -198,21 +169,16 @@ GEM activerecord kaminari-core (= 1.1.1) kaminari-core (1.1.1) - kramdown (1.17.0) launchy (2.4.3) addressable (~> 2.3) launchy (2.4.3-java) addressable (~> 2.3) spoon (~> 0.0.1) - loofah (2.2.2) + loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - mdl (0.4.0) - kramdown (~> 1.12, >= 1.12.0) - mixlib-cli (~> 1.7, >= 1.7.0) - mixlib-config (~> 2.2, >= 2.2.1) method_source (0.9.0) mime-types (3.2.2) mime-types-data (~> 3.2015) @@ -220,9 +186,6 @@ GEM mini_mime (1.0.1) mini_portile2 (2.3.0) minitest (5.11.3) - mixlib-cli (1.7.0) - mixlib-config (2.2.13) - tomlrb multi_json (1.13.1) multi_test (0.1.2) nokogiri (1.8.5) @@ -232,10 +195,7 @@ GEM parallel (1.12.1) parallel_tests (2.26.0) parallel - parser (2.5.1.2) - ast (~> 2.4.0) phantomjs (2.1.1.0) - powerpack (0.1.2) pry (0.11.3) coderay (~> 1.1.0) method_source (~> 0.9.0) @@ -249,21 +209,19 @@ GEM public_suffix (3.0.3) pundit (2.0.0) activesupport (>= 3.0.0) - rack (1.6.10) - rack-mini-profiler (1.0.0) - rack (>= 1.2.0) + rack (1.6.11) rack-test (0.6.3) rack (>= 1.0) - rails (4.2.10) - actionmailer (= 4.2.10) - actionpack (= 4.2.10) - actionview (= 4.2.10) - activejob (= 4.2.10) - activemodel (= 4.2.10) - activerecord (= 4.2.10) - activesupport (= 4.2.10) + rails (4.2.11) + actionmailer (= 4.2.11) + actionpack (= 4.2.11) + actionview (= 4.2.11) + activejob (= 4.2.11) + activemodel (= 4.2.11) + activerecord (= 4.2.11) + activesupport (= 4.2.11) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.10) + railties (= 4.2.11) sprockets-rails rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) @@ -276,13 +234,11 @@ GEM rails-i18n (4.0.9) i18n (~> 0.7) railties (~> 4.0) - railties (4.2.10) - actionpack (= 4.2.10) - activesupport (= 4.2.10) + railties (4.2.11) + actionpack (= 4.2.11) + activesupport (= 4.2.11) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rainbow (2.2.2) - rake rake (12.3.1) ransack (1.8.9) actionpack (>= 3.0, <= 5.1.1) @@ -292,8 +248,7 @@ GEM rb-fsevent (0.10.3) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) - redcarpet (3.4.0) - regexp_parser (1.2.0) + regexp_parser (1.3.0) request_store (1.4.1) rack (>= 1.4) responders (2.4.0) @@ -316,15 +271,6 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rubocop (0.59.2) - jaro_winkler (~> 1.5.1) - parallel (~> 1.10) - parser (>= 2.5, != 2.5.1.1) - powerpack (~> 0.1) - rainbow (>= 2.2.2, < 4.0) - ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.10.0) rubyzip (1.2.2) sass (3.7.2) sass-listen (~> 4.0.0) @@ -349,21 +295,15 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) - terminal-table (1.8.0) - unicode-display_width (~> 1.1, >= 1.1.1) - thor (0.20.0) + thor (0.20.3) thread_safe (0.3.6) thread_safe (0.3.6-java) - tomlrb (1.2.7) tzinfo (1.2.5) thread_safe (~> 0.1) - unicode-display_width (1.4.0) - url (0.3.2) warden (1.2.7) rack (>= 1.0) xpath (3.2.0) nokogiri (~> 1.8) - yard (0.9.16) PLATFORMS java @@ -372,39 +312,28 @@ PLATFORMS DEPENDENCIES activeadmin! activerecord-jdbcsqlite3-adapter (~> 1.3) - better_errors - binding_of_caller cancan capybara (~> 3.10) - codecov cucumber cucumber-rails (~> 1.5) database_cleaner devise (~> 4.4) draper (~> 2.1) - i18n-spec - i18n-tasks jasmine jasmine-core (= 2.9.1) jruby-openssl (~> 0.10.1) - kramdown launchy - mdl (= 0.4.0) parallel_tests (~> 2.26) pry pry-byebug pundit - rack-mini-profiler (>= 0.10.1) - rails (= 4.2.10) + rails (~> 4.2.10) rails-i18n rake - redcarpet rspec-rails - rubocop (= 0.59.2) selenium-webdriver simplecov sqlite3 - yard BUNDLED WITH 1.17.1 diff --git a/gemfiles/rails_50.gemfile b/gemfiles/rails_50.gemfile index fdccaf3a649..51fb6c49cdc 100644 --- a/gemfiles/rails_50.gemfile +++ b/gemfiles/rails_50.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" eval_gemfile(File.expand_path(File.join("..", "Gemfile.common"), __dir__)) -gem "rails", "5.0.7" +gem "rails", "~> 5.0.7" gem "devise", "~> 4.0" gem "draper", "~> 3.0" gem "activerecord-jdbcsqlite3-adapter", "~> 50.0", platforms: :jruby diff --git a/gemfiles/rails_50.gemfile.lock b/gemfiles/rails_50.gemfile.lock index 2b48752f479..cd575ed4461 100644 --- a/gemfiles/rails_50.gemfile.lock +++ b/gemfiles/rails_50.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - activeadmin (1.4.2) + activeadmin (1.4.3) arbre (>= 1.1.1) coffee-rails formtastic (~> 3.1) @@ -17,48 +17,48 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (5.0.7) - actionpack (= 5.0.7) + actioncable (5.0.7.1) + actionpack (= 5.0.7.1) nio4r (>= 1.2, < 3.0) websocket-driver (~> 0.6.1) - actionmailer (5.0.7) - actionpack (= 5.0.7) - actionview (= 5.0.7) - activejob (= 5.0.7) + actionmailer (5.0.7.1) + actionpack (= 5.0.7.1) + actionview (= 5.0.7.1) + activejob (= 5.0.7.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.7) - actionview (= 5.0.7) - activesupport (= 5.0.7) + actionpack (5.0.7.1) + actionview (= 5.0.7.1) + activesupport (= 5.0.7.1) rack (~> 2.0) rack-test (~> 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.7) - activesupport (= 5.0.7) + actionview (5.0.7.1) + activesupport (= 5.0.7.1) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.0.7) - activesupport (= 5.0.7) + activejob (5.0.7.1) + activesupport (= 5.0.7.1) globalid (>= 0.3.6) - activemodel (5.0.7) - activesupport (= 5.0.7) + activemodel (5.0.7.1) + activesupport (= 5.0.7.1) activemodel-serializers-xml (1.0.2) activemodel (> 5.x) activesupport (> 5.x) builder (~> 3.1) - activerecord (5.0.7) - activemodel (= 5.0.7) - activesupport (= 5.0.7) + activerecord (5.0.7.1) + activemodel (= 5.0.7.1) + activesupport (= 5.0.7.1) arel (~> 7.0) activerecord-jdbc-adapter (50.2-java) activerecord (~> 5.0.0, >= 5.0.3) activerecord-jdbcsqlite3-adapter (50.2-java) activerecord-jdbc-adapter (= 50.2) jdbc-sqlite3 (~> 3.8, < 3.30) - activesupport (5.0.7) + activesupport (5.0.7.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -68,20 +68,13 @@ GEM arbre (1.1.1) activesupport (>= 3.0.0) arel (7.1.4) - ast (2.4.0) backports (3.11.4) bcrypt (3.1.12) bcrypt (3.1.12-java) - better_errors (2.5.0) - coderay (>= 1.0.0) - erubi (>= 1.0.0) - rack (>= 0.9.0) - binding_of_caller (0.8.0) - debug_inspector (>= 0.0.1) builder (3.2.3) byebug (10.0.2) cancan (1.6.10) - capybara (3.10.0) + capybara (3.12.0) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) @@ -91,10 +84,6 @@ GEM xpath (~> 3.2) childprocess (0.9.0) ffi (~> 1.0, >= 1.0.11) - codecov (0.1.13) - json - simplecov - url coderay (1.1.2) coffee-rails (4.2.2) coffee-script (>= 2.2.0) @@ -128,7 +117,6 @@ GEM cucumber-tag_expressions (1.1.1) cucumber-wire (0.0.1) database_cleaner (1.7.0) - debug_inspector (0.0.3) devise (4.5.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -143,7 +131,6 @@ GEM activemodel-serializers-xml (~> 1.0) activesupport (~> 5.0) request_store (~> 1.0) - erubi (1.7.1) erubis (2.7.0) execjs (2.7.0) ffi (1.9.25) @@ -157,29 +144,13 @@ GEM has_scope (0.7.2) actionpack (>= 4.1) activesupport (>= 4.1) - highline (2.0.0) i18n (1.1.1) concurrent-ruby (~> 1.0) - i18n-spec (0.6.0) - iso - i18n-tasks (0.9.25) - activesupport (>= 4.0.2) - ast (>= 2.1.0) - erubi - highline (>= 2.0.0) - i18n - parser (>= 2.2.3.0) - rainbow (>= 2.2.2, < 4.0) - terminal-table (>= 1.5.1) inherited_resources (1.9.0) actionpack (>= 4.2, < 5.3) has_scope (~> 0.6) railties (>= 4.2, < 5.3) responders - iso (0.2.2) - i18n - jaro_winkler (1.5.1) - jaro_winkler (1.5.1-java) jasmine (2.9.0) jasmine-core (>= 2.9.0, < 3.0.0) phantomjs @@ -206,7 +177,6 @@ GEM activerecord kaminari-core (= 1.1.1) kaminari-core (1.1.1) - kramdown (1.17.0) launchy (2.4.3) addressable (~> 2.3) launchy (2.4.3-java) @@ -217,20 +187,13 @@ GEM nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - mdl (0.4.0) - kramdown (~> 1.12, >= 1.12.0) - mixlib-cli (~> 1.7, >= 1.7.0) - mixlib-config (~> 2.2, >= 2.2.1) - method_source (0.9.0) + method_source (0.9.2) mime-types (3.2.2) mime-types-data (~> 3.2015) mime-types-data (3.2018.0812) mini_mime (1.0.1) mini_portile2 (2.3.0) minitest (5.11.3) - mixlib-cli (1.7.0) - mixlib-config (2.2.13) - tomlrb multi_json (1.13.1) multi_test (0.1.2) nio4r (2.3.1) @@ -242,10 +205,7 @@ GEM parallel (1.12.1) parallel_tests (2.26.0) parallel - parser (2.5.1.2) - ast (~> 2.4.0) phantomjs (2.1.1.0) - powerpack (0.1.2) pry (0.11.3) coderay (~> 1.1.0) method_source (~> 0.9.0) @@ -259,22 +219,20 @@ GEM public_suffix (3.0.3) pundit (2.0.0) activesupport (>= 3.0.0) - rack (2.0.5) - rack-mini-profiler (1.0.0) - rack (>= 1.2.0) + rack (2.0.6) rack-test (0.6.3) rack (>= 1.0) - rails (5.0.7) - actioncable (= 5.0.7) - actionmailer (= 5.0.7) - actionpack (= 5.0.7) - actionview (= 5.0.7) - activejob (= 5.0.7) - activemodel (= 5.0.7) - activerecord (= 5.0.7) - activesupport (= 5.0.7) + rails (5.0.7.1) + actioncable (= 5.0.7.1) + actionmailer (= 5.0.7.1) + actionpack (= 5.0.7.1) + actionview (= 5.0.7.1) + activejob (= 5.0.7.1) + activemodel (= 5.0.7.1) + activerecord (= 5.0.7.1) + activesupport (= 5.0.7.1) bundler (>= 1.3.0) - railties (= 5.0.7) + railties (= 5.0.7.1) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) @@ -284,14 +242,12 @@ GEM rails-i18n (5.1.1) i18n (>= 0.7, < 2) railties (>= 5.0, < 6) - railties (5.0.7) - actionpack (= 5.0.7) - activesupport (= 5.0.7) + railties (5.0.7.1) + actionpack (= 5.0.7.1) + activesupport (= 5.0.7.1) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rainbow (2.2.2) - rake rake (12.3.1) ransack (2.1.0) actionpack (>= 5.0) @@ -301,8 +257,7 @@ GEM rb-fsevent (0.10.3) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) - redcarpet (3.4.0) - regexp_parser (1.2.0) + regexp_parser (1.3.0) request_store (1.4.1) rack (>= 1.4) responders (2.4.0) @@ -325,15 +280,6 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rubocop (0.59.2) - jaro_winkler (~> 1.5.1) - parallel (~> 1.10) - parser (>= 2.5, != 2.5.1.1) - powerpack (~> 0.1) - rainbow (>= 2.2.2, < 4.0) - ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.10.0) rubyzip (1.2.2) sass (3.7.2) sass-listen (~> 4.0.0) @@ -358,16 +304,11 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) - terminal-table (1.8.0) - unicode-display_width (~> 1.1, >= 1.1.1) - thor (0.20.0) + thor (0.20.3) thread_safe (0.3.6) thread_safe (0.3.6-java) - tomlrb (1.2.7) tzinfo (1.2.5) thread_safe (~> 0.1) - unicode-display_width (1.4.0) - url (0.3.2) warden (1.2.7) rack (>= 1.0) websocket-driver (0.6.5) @@ -377,7 +318,6 @@ GEM websocket-extensions (0.1.3) xpath (3.2.0) nokogiri (~> 1.8) - yard (0.9.16) PLATFORMS java @@ -386,39 +326,28 @@ PLATFORMS DEPENDENCIES activeadmin! activerecord-jdbcsqlite3-adapter (~> 50.0) - better_errors - binding_of_caller cancan capybara (~> 3.10) - codecov cucumber cucumber-rails (~> 1.5) database_cleaner devise (~> 4.0) draper (~> 3.0) - i18n-spec - i18n-tasks jasmine jasmine-core (= 2.9.1) jruby-openssl (~> 0.10.1) - kramdown launchy - mdl (= 0.4.0) parallel_tests (~> 2.26) pry pry-byebug pundit - rack-mini-profiler (>= 0.10.1) - rails (= 5.0.7) + rails (~> 5.0.7) rails-i18n rake - redcarpet rspec-rails - rubocop (= 0.59.2) selenium-webdriver simplecov sqlite3 - yard BUNDLED WITH 1.17.1 diff --git a/gemfiles/rails_51.gemfile b/gemfiles/rails_51.gemfile index 2a7de3a5dc0..fe4cd68a4d6 100644 --- a/gemfiles/rails_51.gemfile +++ b/gemfiles/rails_51.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" eval_gemfile(File.expand_path(File.join("..", "Gemfile.common"), __dir__)) -gem "rails", "5.1.6" +gem "rails", "~> 5.1.6" gem "devise", "~> 4.3" gem "draper", "~> 3.0" gem "activerecord-jdbcsqlite3-adapter", "~> 51.0", platforms: :jruby diff --git a/gemfiles/rails_51.gemfile.lock b/gemfiles/rails_51.gemfile.lock index 866fff63534..3c905c6217a 100644 --- a/gemfiles/rails_51.gemfile.lock +++ b/gemfiles/rails_51.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - activeadmin (1.4.2) + activeadmin (1.4.3) arbre (>= 1.1.1) coffee-rails formtastic (~> 3.1) @@ -17,48 +17,48 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (5.1.6) - actionpack (= 5.1.6) + actioncable (5.1.6.1) + actionpack (= 5.1.6.1) nio4r (~> 2.0) websocket-driver (~> 0.6.1) - actionmailer (5.1.6) - actionpack (= 5.1.6) - actionview (= 5.1.6) - activejob (= 5.1.6) + actionmailer (5.1.6.1) + actionpack (= 5.1.6.1) + actionview (= 5.1.6.1) + activejob (= 5.1.6.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.6) - actionview (= 5.1.6) - activesupport (= 5.1.6) + actionpack (5.1.6.1) + actionview (= 5.1.6.1) + activesupport (= 5.1.6.1) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.6) - activesupport (= 5.1.6) + actionview (5.1.6.1) + activesupport (= 5.1.6.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.1.6) - activesupport (= 5.1.6) + activejob (5.1.6.1) + activesupport (= 5.1.6.1) globalid (>= 0.3.6) - activemodel (5.1.6) - activesupport (= 5.1.6) + activemodel (5.1.6.1) + activesupport (= 5.1.6.1) activemodel-serializers-xml (1.0.2) activemodel (> 5.x) activesupport (> 5.x) builder (~> 3.1) - activerecord (5.1.6) - activemodel (= 5.1.6) - activesupport (= 5.1.6) + activerecord (5.1.6.1) + activemodel (= 5.1.6.1) + activesupport (= 5.1.6.1) arel (~> 8.0) activerecord-jdbc-adapter (51.2-java) activerecord (~> 5.1.0) activerecord-jdbcsqlite3-adapter (51.2-java) activerecord-jdbc-adapter (= 51.2) jdbc-sqlite3 (~> 3.8, < 3.30) - activesupport (5.1.6) + activesupport (5.1.6.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -68,20 +68,13 @@ GEM arbre (1.1.1) activesupport (>= 3.0.0) arel (8.0.0) - ast (2.4.0) backports (3.11.4) bcrypt (3.1.12) bcrypt (3.1.12-java) - better_errors (2.5.0) - coderay (>= 1.0.0) - erubi (>= 1.0.0) - rack (>= 0.9.0) - binding_of_caller (0.8.0) - debug_inspector (>= 0.0.1) builder (3.2.3) byebug (10.0.2) cancan (1.6.10) - capybara (3.10.0) + capybara (3.12.0) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) @@ -91,10 +84,6 @@ GEM xpath (~> 3.2) childprocess (0.9.0) ffi (~> 1.0, >= 1.0.11) - codecov (0.1.13) - json - simplecov - url coderay (1.1.2) coffee-rails (4.2.2) coffee-script (>= 2.2.0) @@ -128,7 +117,6 @@ GEM cucumber-tag_expressions (1.1.1) cucumber-wire (0.0.1) database_cleaner (1.7.0) - debug_inspector (0.0.3) devise (4.5.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -156,29 +144,13 @@ GEM has_scope (0.7.2) actionpack (>= 4.1) activesupport (>= 4.1) - highline (2.0.0) i18n (1.1.1) concurrent-ruby (~> 1.0) - i18n-spec (0.6.0) - iso - i18n-tasks (0.9.25) - activesupport (>= 4.0.2) - ast (>= 2.1.0) - erubi - highline (>= 2.0.0) - i18n - parser (>= 2.2.3.0) - rainbow (>= 2.2.2, < 4.0) - terminal-table (>= 1.5.1) inherited_resources (1.9.0) actionpack (>= 4.2, < 5.3) has_scope (~> 0.6) railties (>= 4.2, < 5.3) responders - iso (0.2.2) - i18n - jaro_winkler (1.5.1) - jaro_winkler (1.5.1-java) jasmine (2.9.0) jasmine-core (>= 2.9.0, < 3.0.0) phantomjs @@ -205,7 +177,6 @@ GEM activerecord kaminari-core (= 1.1.1) kaminari-core (1.1.1) - kramdown (1.17.0) launchy (2.4.3) addressable (~> 2.3) launchy (2.4.3-java) @@ -216,20 +187,13 @@ GEM nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - mdl (0.4.0) - kramdown (~> 1.12, >= 1.12.0) - mixlib-cli (~> 1.7, >= 1.7.0) - mixlib-config (~> 2.2, >= 2.2.1) - method_source (0.9.0) + method_source (0.9.2) mime-types (3.2.2) mime-types-data (~> 3.2015) mime-types-data (3.2018.0812) mini_mime (1.0.1) mini_portile2 (2.3.0) minitest (5.11.3) - mixlib-cli (1.7.0) - mixlib-config (2.2.13) - tomlrb multi_json (1.13.1) multi_test (0.1.2) nio4r (2.3.1) @@ -241,10 +205,7 @@ GEM parallel (1.12.1) parallel_tests (2.26.0) parallel - parser (2.5.1.2) - ast (~> 2.4.0) phantomjs (2.1.1.0) - powerpack (0.1.2) pry (0.11.3) coderay (~> 1.1.0) method_source (~> 0.9.0) @@ -258,22 +219,20 @@ GEM public_suffix (3.0.3) pundit (2.0.0) activesupport (>= 3.0.0) - rack (2.0.5) - rack-mini-profiler (1.0.0) - rack (>= 1.2.0) + rack (2.0.6) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.1.6) - actioncable (= 5.1.6) - actionmailer (= 5.1.6) - actionpack (= 5.1.6) - actionview (= 5.1.6) - activejob (= 5.1.6) - activemodel (= 5.1.6) - activerecord (= 5.1.6) - activesupport (= 5.1.6) + rails (5.1.6.1) + actioncable (= 5.1.6.1) + actionmailer (= 5.1.6.1) + actionpack (= 5.1.6.1) + actionview (= 5.1.6.1) + activejob (= 5.1.6.1) + activemodel (= 5.1.6.1) + activerecord (= 5.1.6.1) + activesupport (= 5.1.6.1) bundler (>= 1.3.0) - railties (= 5.1.6) + railties (= 5.1.6.1) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) @@ -283,14 +242,12 @@ GEM rails-i18n (5.1.1) i18n (>= 0.7, < 2) railties (>= 5.0, < 6) - railties (5.1.6) - actionpack (= 5.1.6) - activesupport (= 5.1.6) + railties (5.1.6.1) + actionpack (= 5.1.6.1) + activesupport (= 5.1.6.1) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rainbow (2.2.2) - rake rake (12.3.1) ransack (2.1.0) actionpack (>= 5.0) @@ -300,8 +257,7 @@ GEM rb-fsevent (0.10.3) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) - redcarpet (3.4.0) - regexp_parser (1.2.0) + regexp_parser (1.3.0) request_store (1.4.1) rack (>= 1.4) responders (2.4.0) @@ -324,15 +280,6 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rubocop (0.59.2) - jaro_winkler (~> 1.5.1) - parallel (~> 1.10) - parser (>= 2.5, != 2.5.1.1) - powerpack (~> 0.1) - rainbow (>= 2.2.2, < 4.0) - ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.10.0) rubyzip (1.2.2) sass (3.7.2) sass-listen (~> 4.0.0) @@ -357,16 +304,11 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) - terminal-table (1.8.0) - unicode-display_width (~> 1.1, >= 1.1.1) - thor (0.20.0) + thor (0.20.3) thread_safe (0.3.6) thread_safe (0.3.6-java) - tomlrb (1.2.7) tzinfo (1.2.5) thread_safe (~> 0.1) - unicode-display_width (1.4.0) - url (0.3.2) warden (1.2.7) rack (>= 1.0) websocket-driver (0.6.5) @@ -376,7 +318,6 @@ GEM websocket-extensions (0.1.3) xpath (3.2.0) nokogiri (~> 1.8) - yard (0.9.16) PLATFORMS java @@ -385,39 +326,28 @@ PLATFORMS DEPENDENCIES activeadmin! activerecord-jdbcsqlite3-adapter (~> 51.0) - better_errors - binding_of_caller cancan capybara (~> 3.10) - codecov cucumber cucumber-rails (~> 1.5) database_cleaner devise (~> 4.3) draper (~> 3.0) - i18n-spec - i18n-tasks jasmine jasmine-core (= 2.9.1) jruby-openssl (~> 0.10.1) - kramdown launchy - mdl (= 0.4.0) parallel_tests (~> 2.26) pry pry-byebug pundit - rack-mini-profiler (>= 0.10.1) - rails (= 5.1.6) + rails (~> 5.1.6) rails-i18n rake - redcarpet rspec-rails - rubocop (= 0.59.2) selenium-webdriver simplecov sqlite3 - yard BUNDLED WITH 1.17.1 diff --git a/lib/active_admin/batch_actions/controller.rb b/lib/active_admin/batch_actions/controller.rb index 16106947a9c..ff07104bddf 100644 --- a/lib/active_admin/batch_actions/controller.rb +++ b/lib/active_admin/batch_actions/controller.rb @@ -7,7 +7,7 @@ def batch_action if action_present? selection = params[:collection_selection] || [] inputs = JSON.parse params[:batch_action_inputs] || '{}' - valid_keys = StringSymbolOrProcSetting.new(current_batch_action.inputs).value(self).try(:keys) + valid_keys = MethodOrProcHelper.render_in_context(self, current_batch_action.inputs).try(:keys) inputs = inputs.with_indifferent_access.slice *valid_keys instance_exec selection, inputs, ¤t_batch_action.block else diff --git a/lib/active_admin/resource_controller/scoping.rb b/lib/active_admin/resource_controller/scoping.rb index 7f67193f48c..53e803357f1 100644 --- a/lib/active_admin/resource_controller/scoping.rb +++ b/lib/active_admin/resource_controller/scoping.rb @@ -15,7 +15,7 @@ module Scoping # Collection can be scoped conditionally with an :if or :unless proc. def begin_of_association_chain return nil unless active_admin_config.scope_to?(self) - StringSymbolOrProcSetting.new(active_admin_config.scope_to_method).value(self) + MethodOrProcHelper.render_in_context(self, active_admin_config.scope_to_method) end # Overriding from InheritedResources::BaseHelpers diff --git a/lib/active_admin/version.rb b/lib/active_admin/version.rb index e36e6d96567..bfab9e1867c 100644 --- a/lib/active_admin/version.rb +++ b/lib/active_admin/version.rb @@ -1,3 +1,3 @@ module ActiveAdmin - VERSION = '1.4.2' + VERSION = '1.4.3' end diff --git a/lib/active_admin/view_helpers/method_or_proc_helper.rb b/lib/active_admin/view_helpers/method_or_proc_helper.rb index ee79cf5e121..c520e37fd13 100644 --- a/lib/active_admin/view_helpers/method_or_proc_helper.rb +++ b/lib/active_admin/view_helpers/method_or_proc_helper.rb @@ -1,4 +1,5 @@ module MethodOrProcHelper + extend self # This method will either call the symbol on self or instance_exec the Proc # within self. Any args will be passed along to the method dispatch. diff --git a/spec/bug_report_templates_spec.rb b/spec/bug_report_templates_spec.rb deleted file mode 100644 index 349e616318e..00000000000 --- a/spec/bug_report_templates_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'open3' - -RSpec.describe 'bug_report_templates' do - subject do - Bundler.with_original_env do - Dir.chdir(chdir_path) do - Open3.capture2e( - {'ACTIVE_ADMIN_PATH' => active_admin_root}, - Gem.ruby, - template_path - )[1] - end - end - end - - let(:active_admin_root) { File.expand_path('../..', __FILE__) } - let(:chdir_path) { File.join(active_admin_root, 'lib', 'bug_report_templates') } - - context 'when runs active_admin_master.rb' do - let(:template_path) { 'active_admin_master.rb' } - - it 'passes' do - expect(subject).to be_truthy - end - end - -end diff --git a/spec/changelog_spec.lint.rb b/spec/changelog_spec.lint.rb index 1316a65989d..c03ef8c6f4f 100644 --- a/spec/changelog_spec.lint.rb +++ b/spec/changelog_spec.lint.rb @@ -1,4 +1,6 @@ -SimpleCov.command_name "lint" if ENV["COVERAGE"] == true +SimpleCov.command_name "lint" if ENV["COVERAGE"] == "true" + +require "kramdown" RSpec.describe "Changelog" do subject(:changelog) do @@ -6,10 +8,21 @@ File.read(path) end - it 'has definitions for all implicit links' do - implicit_link_names = changelog.scan(/\[([^\]]+)\]\[\]/).flatten.uniq + it 'uses the simplest style for implicit links' do + expect(changelog).not_to match(/\[([^\]]+)\]\[\]/) + end + + it 'has definitions for all issue/pr references' do + implicit_link_names = changelog.scan(/\[#([0-9]+)\] /).flatten.uniq + implicit_link_names.each do |name| + expect(changelog).to include("[##{name}]: https://github.com/activeadmin/activeadmin/pull/#{name}").or include("[##{name}]: https://github.com/activeadmin/activeadmin/issues/#{name}") + end + end + + it 'has definitions for users' do + implicit_link_names = changelog.scan(/ \[@([[:alnum:]]+)\]/).flatten.uniq implicit_link_names.each do |name| - expect(changelog).to include("[#{name}]: https") + expect(changelog).to include("[@#{name}]: https://github.com/#{name}") end end @@ -24,4 +37,10 @@ end end end + + describe 'warnings' do + subject(:document) { Kramdown::Document.new(changelog) } + + specify { expect(document.warnings).to be_empty } + end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 5e783c876c8..018f96f9b78 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -2,9 +2,7 @@ ENV['RAILS_ENV'] = 'test' -ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{Gem.loaded_specs["rails"].version}", __FILE__) - -require ENV['RAILS_ROOT'] + '/config/environment' +require_relative "rails/rails-#{Gem.loaded_specs["rails"].version}/config/environment" require 'rspec/rails' @@ -18,22 +16,11 @@ config.use_instantiated_fixtures = false config.render_views = false - devise = ActiveAdmin::Dependency.devise >= '4.2' ? Devise::Test::ControllerHelpers : Devise::TestHelpers - config.include devise, type: :controller + config.include Devise::Test::ControllerHelpers, type: :controller require 'support/active_admin_integration_spec_helper' config.include ActiveAdminIntegrationSpecHelper - - # Setup Some Admin stuff for us to play with - config.before(:suite) do - ActiveAdminIntegrationSpecHelper.load_defaults! - ActiveAdminIntegrationSpecHelper.reload_routes! - end end # Force deprecations to raise an exception. ActiveSupport::Deprecation.behavior = :raise - -# improve the performance of the specs suite by not logging anything -# see http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/ -Rails.logger.level = Logger::FATAL diff --git a/spec/requests/default_namespace_spec.rb b/spec/requests/default_namespace_spec.rb index c3c47717b0d..566799247c6 100644 --- a/spec/requests/default_namespace_spec.rb +++ b/spec/requests/default_namespace_spec.rb @@ -1,9 +1,6 @@ require 'rails_helper' RSpec.describe ActiveAdmin::Application, type: :request do - - include Rails.application.routes.url_helpers - let(:resource) { ActiveAdmin.register Category } [false, nil].each do |value| @@ -82,8 +79,8 @@ def with_custom_default_namespace(namespace) def with_temp_application(application) original_application = ActiveAdmin.application ActiveAdmin.application = application - load_defaults! - reload_routes! + + load_resources { ActiveAdmin.register(Category) } yield diff --git a/spec/requests/memory_spec.rb b/spec/requests/memory_spec.rb index 3170ff871c4..22e4156e143 100644 --- a/spec/requests/memory_spec.rb +++ b/spec/requests/memory_spec.rb @@ -1,8 +1,8 @@ require 'rails_helper' RSpec.describe "Memory Leak", type: :request, if: RUBY_ENGINE == 'ruby' do - before do - load_defaults! + around do |example| + with_resources_during(example) { ActiveAdmin.register(Category) } end def count_instances_of(klass) @@ -15,7 +15,7 @@ def count_instances_of(klass) GC.start count = count_instances_of(klass) - load_defaults! + load_resources { ActiveAdmin.register(Category) } GC.start GC.disable if previously_disabled diff --git a/spec/support/active_admin_integration_spec_helper.rb b/spec/support/active_admin_integration_spec_helper.rb index 3783cdc0beb..d6a268e5e05 100644 --- a/spec/support/active_admin_integration_spec_helper.rb +++ b/spec/support/active_admin_integration_spec_helper.rb @@ -1,13 +1,10 @@ module ActiveAdminIntegrationSpecHelper - extend self + def with_resources_during(example) + load_resources { yield } - def load_defaults! - ActiveAdmin.unload! - ActiveAdmin.load! - ActiveAdmin.register(Category) - ActiveAdmin.register(User) - ActiveAdmin.register(Post){ belongs_to :user, optional: true } - reload_menus! + example.run + + load_resources {} end def reload_menus! @@ -61,8 +58,6 @@ def with_translation(translation) # If no translations have been loaded, any later calls to `I18n.t` will # cause the full translation hash to be loaded, possibly overwritting what # we've loaded via `store_translations`. We use this hack to prevent that. - # TODO: Might not be necessary anymore once - # https://github.com/svenfuchs/i18n/pull/353 lands. I18n.backend.send(:init_translations) I18n.backend.store_translations I18n.locale, translation yield diff --git a/spec/unit/action_builder_spec.rb b/spec/unit/action_builder_spec.rb index 44edf0b6006..a02bfd2fe84 100644 --- a/spec/unit/action_builder_spec.rb +++ b/spec/unit/action_builder_spec.rb @@ -10,7 +10,7 @@ end describe 'creates a member action' do - after(:each) do + after do klass.clear_member_actions! end @@ -68,7 +68,7 @@ end describe 'creates a collection action' do - after(:each) do + after do klass.clear_collection_actions! end @@ -124,7 +124,7 @@ end context 'when method with given name is already defined' do - around :each do |example| + around do |example| original_stderr = $stderr $stderr = StringIO.new example.run diff --git a/spec/unit/namespace_spec.rb b/spec/unit/namespace_spec.rb index a3bc137a973..f12bc7e3e03 100644 --- a/spec/unit/namespace_spec.rb +++ b/spec/unit/namespace_spec.rb @@ -40,6 +40,10 @@ Admin.send(:remove_const, 'PostsController') end + after do + load_resources {} + end + it "should not crash" do expect { ActiveAdmin.unload! }.not_to raise_error end diff --git a/spec/unit/page_spec.rb b/spec/unit/page_spec.rb index 81a944b9179..48297e068d9 100644 --- a/spec/unit/page_spec.rb +++ b/spec/unit/page_spec.rb @@ -5,7 +5,6 @@ module ActiveAdmin RSpec.describe Page do it_should_behave_like "ActiveAdmin::Resource" - before { load_defaults! } let(:application){ ActiveAdmin::Application.new } let(:namespace){ Namespace.new(application, :admin) } diff --git a/spec/unit/pretty_format_spec.rb b/spec/unit/pretty_format_spec.rb index d2582cf65c3..685e5bb6f83 100644 --- a/spec/unit/pretty_format_spec.rb +++ b/spec/unit/pretty_format_spec.rb @@ -86,7 +86,7 @@ context "with non-English locale" do around do |example| - I18n.with_locale(:es) { example.call } + I18n.with_locale(:es, &example) end it "formats it with the default long format" do diff --git a/spec/unit/resource/menu_spec.rb b/spec/unit/resource/menu_spec.rb deleted file mode 100644 index 2ab8a2e570d..00000000000 --- a/spec/unit/resource/menu_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'rails_helper' - -module ActiveAdmin - RSpec.describe Resource, "Menu" do - - before { load_defaults! } - - let(:application){ ActiveAdmin::Application.new } - let(:namespace){ Namespace.new(application, :admin) } - - def config(options = {}) - @config ||= Resource.new(namespace, Category, options) - end - - # TODO... - - end -end diff --git a/spec/unit/resource/naming_spec.rb b/spec/unit/resource/naming_spec.rb index 985b490d671..90d9c041f6f 100644 --- a/spec/unit/resource/naming_spec.rb +++ b/spec/unit/resource/naming_spec.rb @@ -2,9 +2,6 @@ module ActiveAdmin RSpec.describe Resource, "Naming" do - - before { load_defaults! } - let(:application){ ActiveAdmin::Application.new } let(:namespace){ Namespace.new(application, :admin) } diff --git a/spec/unit/resource/pagination_spec.rb b/spec/unit/resource/pagination_spec.rb index 940c298bf0b..5375e4d1ef6 100644 --- a/spec/unit/resource/pagination_spec.rb +++ b/spec/unit/resource/pagination_spec.rb @@ -2,9 +2,6 @@ module ActiveAdmin RSpec.describe Resource, "Pagination" do - - before { load_defaults! } - let(:application){ ActiveAdmin::Application.new } let(:namespace){ Namespace.new(application, :admin) } diff --git a/spec/unit/resource/routes_spec.rb b/spec/unit/resource/routes_spec.rb index f9c8b926070..246c97a0443 100644 --- a/spec/unit/resource/routes_spec.rb +++ b/spec/unit/resource/routes_spec.rb @@ -1,20 +1,14 @@ require 'rails_helper' RSpec.describe ActiveAdmin::Resource::Routes do - - after do - load_defaults! - reload_routes! - end - let(:application) { ActiveAdmin.application } let(:namespace) { application.namespace(:admin) } context "when in the admin namespace" do let(:config) { namespace.resource_for('Category') } - before do - load_resources { ActiveAdmin.register Category } + around do |example| + with_resources_during(example) { ActiveAdmin.register Category } end let(:category) { Category.new { |c| c.id = 123 } } @@ -35,7 +29,11 @@ context "when in the root namespace" do let!(:config) { ActiveAdmin.register Category, namespace: false } - after(:each) do + around do |example| + with_resources_during(example) { config } + end + + after do application.namespace(:root).unload! application.namespaces.instance_variable_get(:@namespaces).delete(:root) end @@ -45,7 +43,6 @@ end it "should generate a correct route" do - reload_routes! expect(config.route_collection_path).to eq "/categories" end end @@ -53,7 +50,10 @@ context "when registering a plural resource" do class ::News; def self.has_many(*); end end let!(:config) { ActiveAdmin.register News } - before{ reload_routes! } + + around do |example| + with_resources_during(example) { config } + end it "should return the plural route with _index" do expect(config.route_collection_path).to eq "/admin/news" diff --git a/spec/unit/resource/scopes_spec.rb b/spec/unit/resource/scopes_spec.rb index 23aee9b20fd..ae3e39bf237 100644 --- a/spec/unit/resource/scopes_spec.rb +++ b/spec/unit/resource/scopes_spec.rb @@ -2,9 +2,6 @@ module ActiveAdmin RSpec.describe Resource, "Scopes" do - - before { load_defaults! } - let(:application){ ActiveAdmin::Application.new } let(:namespace){ Namespace.new(application, :admin) } diff --git a/spec/unit/resource_controller_spec.rb b/spec/unit/resource_controller_spec.rb index 6c09f9eb20f..c3aa8a3a2bd 100644 --- a/spec/unit/resource_controller_spec.rb +++ b/spec/unit/resource_controller_spec.rb @@ -218,7 +218,7 @@ def call_after_destroy(obj); end end describe "performing batch_action" do - let(:batch_action) { ActiveAdmin::BatchAction.new :flag, "Flag", &batch_action_block } + let(:batch_action) { ActiveAdmin::BatchAction.new *batch_action_args, &batch_action_block } let(:batch_action_block) { proc { self.instance_variable_set :@block_context, self.class } } let(:params) { ActionController::Parameters.new(http_params) } @@ -228,6 +228,7 @@ def call_after_destroy(obj); end end describe "when params batch_action matches existing BatchAction" do + let(:batch_action_args) { [:flag, "Flag"] } let(:http_params) do { batch_action: "flag", collection_selection: ["1"] } @@ -244,7 +245,22 @@ def call_after_destroy(obj); end end end + describe "when params batch_action matches existing BatchAction and form inputs defined" do + let(:batch_action_args) { [:flag, "Flag", { form: { type: ["a", "b"] } }] } + + let(:http_params) do + { batch_action: "flag", collection_selection: ["1"], batch_action_inputs: '{ "type": "a", "bogus": "param" }' } + end + + it "should filter permitted params" do + expect(controller).to receive(:instance_exec).with(["1"], { "type" => "a" }) + controller.batch_action + end + end + describe "when params batch_action doesn't match a BatchAction" do + let(:batch_action_args) { [:flag, "Flag"] } + let(:http_params) do { batch_action: "derp", collection_selection: ["1"] } end @@ -257,6 +273,8 @@ def call_after_destroy(obj); end end describe "when params batch_action is blank" do + let(:batch_action_args) { [:flag, "Flag"] } + let(:http_params) do { collection_selection: ["1"] } end diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 8f5a919ab52..8382f7d3f3c 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -5,7 +5,10 @@ module ActiveAdmin RSpec.describe Resource do it_should_behave_like "ActiveAdmin::Resource" - before { load_defaults! } + + around do |example| + with_resources_during(example) { namespace.register Category } + end let(:application){ ActiveAdmin::Application.new } let(:namespace){ Namespace.new(application, :admin) } @@ -38,6 +41,10 @@ def config(options = {}) expect(config.decorator_class).to eq nil end context 'when a decorator is defined' do + around do |example| + with_resources_during(example) { resource } + end + let(:resource) { namespace.register(Post) { decorate_with PostDecorator } } specify '#decorator_class_name should return PostDecorator' do expect(resource.decorator_class_name).to eq '::PostDecorator' @@ -62,9 +69,12 @@ def config(options = {}) end describe "#include_in_menu?" do - let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) } subject{ resource } + around do |example| + with_resources_during(example) { resource } + end + context "when regular resource" do let(:resource){ namespace.register(Post) } it { is_expected.to be_include_in_menu } @@ -238,38 +248,45 @@ class MockResource end describe '#find_resource' do - let(:resource) { namespace.register(Post) } let(:post) { double } - before do - allow(Post).to receive(:find_by).with("id" => "12345") { post } - allow(Post).to receive(:find_by).with("id" => "54321") { nil } + + around do |example| + with_resources_during(example) { resource } end - it 'can find the resource' do - expect(resource.find_resource('12345')).to eq post + context 'without a decorator' do + let(:resource) { namespace.register(Post) } + + it 'can find the resource' do + allow(Post).to receive(:find_by).with("id" => "12345") { post } + expect(resource.find_resource('12345')).to eq post + end end context 'with a decorator' do let(:resource) { namespace.register(Post) { decorate_with PostDecorator } } + it 'decorates the resource' do + allow(Post).to receive(:find_by).with("id" => "12345") { post } expect(resource.find_resource('12345')).to eq PostDecorator.new(post) end it 'does not decorate a not found resource' do + allow(Post).to receive(:find_by).with("id" => "54321") { nil } expect(resource.find_resource('54321')).to equal nil end end context 'when using a nonstandard primary key' do - let(:different_post) { double } + let(:resource) { namespace.register(Post) } + before do allow(Post).to receive(:primary_key).and_return 'something_else' - allow(Post).to receive(:find_by). - with("something_else" => "55555") { different_post } + allow(Post).to receive(:find_by).with("something_else" => "55555") { post } end it 'can find the post by the custom primary key' do - expect(resource.find_resource('55555')).to eq different_post + expect(resource.find_resource('55555')).to eq post end end @@ -282,6 +299,10 @@ class MockResource end end + after do + Admin.send(:remove_const, :"PostsController") + end + it 'can find the post by controller finder' do allow(Post).to receive(:find_by_title!).with('title-name').and_return(post) diff --git a/spec/unit/routing_spec.rb b/spec/unit/routing_spec.rb index 02bd099657e..059be4403e3 100644 --- a/spec/unit/routing_spec.rb +++ b/spec/unit/routing_spec.rb @@ -1,28 +1,27 @@ require 'rails_helper' RSpec.describe "Routing", type: :routing do - - before do - load_defaults! - reload_routes! - end - - after :all do - load_defaults! - reload_routes! - end - let(:namespaces) { ActiveAdmin.application.namespaces } it "should only have the namespaces necessary for route testing" do expect(namespaces.names).to eq [:admin] end - it "should route to the admin dashboard" do - expect(get('/admin')).to route_to 'admin/dashboard#index' + describe "admin dashboard" do + around do |example| + with_resources_during(example) {} + end + + it "should route to the admin dashboard" do + expect(get('/admin')).to route_to 'admin/dashboard#index' + end end describe "root path helper" do + around do |example| + with_resources_during(example) {} + end + context "when in admin namespace" do it "should be admin_root_path" do expect(admin_root_path).to eq "/admin" @@ -31,6 +30,10 @@ end describe "route_options" do + around do |example| + with_resources_during(example) { ActiveAdmin.register(Post) } + end + context "with a custom path set in route_options" do before do namespaces[:admin].route_options = { path: '/custom-path' } @@ -49,6 +52,10 @@ end describe "standard resources" do + around do |example| + with_resources_during(example) { ActiveAdmin.register(Post) } + end + context "when in admin namespace" do it "should route the index path" do expect(admin_posts_path).to eq "/admin/posts" @@ -68,11 +75,11 @@ end context "when in root namespace" do - before(:each) do - load_resources { ActiveAdmin.register(Post, namespace: false) } + around do |example| + with_resources_during(example) { ActiveAdmin.register(Post, namespace: false) } end - after(:each) do + after do namespaces.instance_variable_get(:@namespaces).delete(:root) end @@ -95,8 +102,8 @@ context "with member action" do context "without an http verb" do - before do - load_resources do + around do |example| + with_resources_during(example) do ActiveAdmin.register(Post){ member_action "do_something" } end end @@ -108,8 +115,8 @@ end context "with one http verb" do - before do - load_resources do + around do |example| + with_resources_during(example) do ActiveAdmin.register(Post){ member_action "do_something", method: :post } end end @@ -120,8 +127,8 @@ end context "with two http verbs" do - before do - load_resources do + around do |example| + with_resources_during(example) do ActiveAdmin.register(Post){ member_action "do_something", method: [:put, :delete] } end end @@ -138,6 +145,13 @@ end describe "belongs to resource" do + around do |example| + with_resources_during(example) do + ActiveAdmin.register(User) + ActiveAdmin.register(Post){ belongs_to :user, optional: true } + end + end + it "should route the nested index path" do expect(admin_user_posts_path(1)).to eq "/admin/users/1/posts" end @@ -155,8 +169,8 @@ end context "with collection action" do - before do - load_resources do + around do |example| + with_resources_during(example) do ActiveAdmin.register(Post) do belongs_to :user, optional: true end @@ -175,8 +189,8 @@ describe "page" do context "when default namespace" do - before(:each) do - load_resources { ActiveAdmin.register_page("Chocolate I lØve You!") } + around do |example| + with_resources_during(example) { ActiveAdmin.register_page("Chocolate I lØve You!") } end it "should route to the page under /admin" do @@ -185,11 +199,11 @@ end context "when in the root namespace" do - before(:each) do - load_resources { ActiveAdmin.register_page("Chocolate I lØve You!", namespace: false) } + around do |example| + with_resources_during(example) { ActiveAdmin.register_page("Chocolate I lØve You!", namespace: false) } end - after(:each) do + after do namespaces.instance_variable_get(:@namespaces).delete(:root) end @@ -199,8 +213,8 @@ end context "when singular page name" do - before(:each) do - load_resources { ActiveAdmin.register_page("Log") } + around do |example| + with_resources_during(example) { ActiveAdmin.register_page("Log") } end it "should not inject _index_ into the route name" do diff --git a/spec/unit/view_helpers/display_helper_spec.rb b/spec/unit/view_helpers/display_helper_spec.rb index 7b2a8f6f739..14e36a4d807 100644 --- a/spec/unit/view_helpers/display_helper_spec.rb +++ b/spec/unit/view_helpers/display_helper_spec.rb @@ -5,27 +5,29 @@ require 'active_admin/view_helpers/method_or_proc_helper' RSpec.describe ActiveAdmin::ViewHelpers::DisplayHelper do - include ActiveAdmin::ViewHelpers::ActiveAdminApplicationHelper - include ActiveAdmin::ViewHelpers::AutoLinkHelper - include ActiveAdmin::ViewHelpers::DisplayHelper - include MethodOrProcHelper - include ActionView::Helpers::UrlHelper - include ActionView::Helpers::TranslationHelper - include ActionView::Helpers::SanitizeHelper - - def active_admin_namespace - active_admin_application.namespaces[:admin] + let(:view_klass) do + Class.new(ActionView::Base) do + include ActiveAdmin::ViewHelpers::ActiveAdminApplicationHelper + include ActiveAdmin::ViewHelpers::AutoLinkHelper + include ActiveAdmin::ViewHelpers::DisplayHelper + include MethodOrProcHelper + include ActionView::Helpers::UrlHelper + include ActionView::Helpers::TranslationHelper + include ActionView::Helpers::SanitizeHelper + end end - def authorized?(*) - true - end + let(:active_admin_namespace){ view.active_admin_application.namespaces[:admin] } - def url_options - { locale: nil } - end + let(:view) { mock_action_view(view_klass) } + + let(:displayed_name) { view.display_name(resource) } before do + allow(view).to receive(:authorized?).and_return(true) + allow(view).to receive(:active_admin_namespace).and_return(active_admin_namespace) + allow(view).to receive(:url_options).and_return(locale: nil) + load_resources do ActiveAdmin.register(User) ActiveAdmin.register(Post){ belongs_to :user, optional: true } @@ -33,75 +35,106 @@ def url_options end describe '#display_name' do + let(:resource) { klass.new } + ActiveAdmin::Application.new.display_name_methods.map(&:to_s).each do |m| - it "should return #{m} when defined" do - klass = Class.new do - define_method(m) { m } + context "when it is the identity" do + let(:klass) do + Class.new do + define_method(m) { m } + end + end + + it "should return #{m}" do + expect(displayed_name).to eq m end - expect(display_name klass.new).to eq m end - it "should sanitize the result of #{m} when defined" do - klass = Class.new do - define_method(m) { '' } + context "when it includes js" do + let(:klass) do + Class.new do + define_method(m) { '' } + end + end + + it "should sanitize the result of #{m}" do + expect(displayed_name).to eq 'alert(1)' end - expect(display_name klass.new).to eq 'alert(1)' end end - it "should memoize the result for the class" do - subject = Class.new.new - expect(subject).to receive(:name).twice.and_return "My Name" + describe "memoization" do + let(:klass) { Class.new } - expect(display_name subject).to eq "My Name" + it "should memoize the result for the class" do + expect(resource).to receive(:name).and_return "My Name" + expect(displayed_name).to eq "My Name" - expect(ActiveAdmin.application).to_not receive(:display_name_methods) - expect(display_name subject).to eq "My Name" - end + expect(ActiveAdmin.application).to_not receive(:display_name_methods) + expect(displayed_name).to eq "My Name" + end - it "should not call a method if it's an association" do - klass = Class.new - subject = klass.new - allow(klass).to receive(:reflect_on_all_associations).and_return [ double(name: :login) ] - allow(subject).to receive :login - expect(subject).to_not receive :login - allow(subject).to receive(:email).and_return 'foo@bar.baz' + it "should not call a method if it's an association" do + allow(klass).to receive(:reflect_on_all_associations).and_return [ double(name: :login) ] + allow(resource).to receive :login + expect(resource).to_not receive :login + allow(resource).to receive(:email).and_return 'foo@bar.baz' - expect(display_name subject).to eq 'foo@bar.baz' + expect(displayed_name).to eq 'foo@bar.baz' + end end - it "should return `nil` when the passed object is `nil`" do - expect(display_name nil).to eq nil + context "when the passed object is `nil`" do + let(:resource) { nil } + + it "should return `nil` when the passed object is `nil`" do + expect(displayed_name).to eq nil + end end - it "should return 'false' when the passed object is `false`" do - expect(display_name false).to eq "false" + context "when the passed object is `false`" do + let(:resource) { false } + + it "should return 'false' when the passed object is `false`" do + expect(displayed_name).to eq "false" + end end - it "should default to `to_s`" do - subject = Class.new.new - expect(display_name subject).to eq sanitize(subject.to_s) + describe "default implementation" do + let(:klass) { Class.new } + + it "should default to `to_s`" do + result = resource.to_s + + expect(displayed_name).to eq view.sanitize(result) + end end context "when no display name method is defined" do - context "on a Rails model" do - it "should show the model name" do + context "when no ID" do + let(:resource) do class ThisModel extend ActiveModel::Naming end - subject = ThisModel.new - expect(display_name subject).to eq "This model" + + ThisModel.new end + it "should show the model name" do + expect(displayed_name).to eq "This model" + end + end + + context "when ID" do + let(:resource) { Tagging.create! } + it "should show the model name, plus the ID if in use" do - subject = Tagging.create! - expect(display_name subject).to eq "Tagging #1" + expect(displayed_name).to eq "Tagging #1" end it "should translate the model name" do with_translation activerecord: {models: {tagging: {one: "Different"}}} do - subject = Tagging.create! - expect(display_name subject).to eq "Different #1" + expect(displayed_name).to eq "Different #1" end end end @@ -110,26 +143,26 @@ class ThisModel describe '#format_attribute' do it 'calls the provided block to format the value' do - value = format_attribute double(foo: 2), ->r { r.foo + 1 } + value = view.format_attribute double(foo: 2), ->r { r.foo + 1 } expect(value).to eq '3' end it 'finds values as methods' do - value = format_attribute double(name: 'Joe'), :name + value = view.format_attribute double(name: 'Joe'), :name expect(value).to eq 'Joe' end it 'finds values from hashes' do - value = format_attribute({id: 100}, :id) + value = view.format_attribute({id: 100}, :id) expect(value).to eq '100' end [1, 1.2, :a_symbol].each do |val| it "calls to_s to format the value of type #{val.class}" do - value = format_attribute double(foo: val), :foo + value = view.format_attribute double(foo: val), :foo expect(value).to eq val.to_s end @@ -138,7 +171,7 @@ class ThisModel it 'localizes dates' do date = Date.parse '2016/02/28' - value = format_attribute double(date: date), :date + value = view.format_attribute double(date: date), :date expect(value).to eq 'February 28, 2016' end @@ -146,7 +179,7 @@ class ThisModel it 'localizes times' do time = Time.parse '2016/02/28 9:34 PM' - value = format_attribute double(time: time), :time + value = view.format_attribute double(time: time), :time expect(value).to eq 'February 28, 2016 21:34' end @@ -154,7 +187,7 @@ class ThisModel it 'uses a display_name method for arbitrary objects' do object = double to_s: :wrong, display_name: :right - value = format_attribute double(object: object), :object + value = view.format_attribute double(object: object), :object expect(value).to eq 'right' end @@ -162,7 +195,7 @@ class ThisModel it 'auto-links ActiveRecord records by association' do post = Post.create! author: User.new - value = format_attribute post, :author + value = view.format_attribute post, :author expect(value).to match / <\/a>/ end @@ -170,7 +203,7 @@ class ThisModel it 'auto-links ActiveRecord records & uses a display_name method' do post = Post.create! author: User.new(first_name: 'A', last_name: 'B') - value = format_attribute post, :author + value = view.format_attribute post, :author expect(value).to match /A B<\/a>/ end @@ -180,7 +213,7 @@ class ThisModel it 'calls status_tag for boolean values' do post = Post.new starred: true - value = format_attribute post, :starred + value = view.format_attribute post, :starred expect(value.to_s).to eq "Yes\n" end @@ -193,9 +226,9 @@ class ThisModel post.define_singleton_method(:false_method) do false end - true_value = format_attribute post, :true_method + true_value = view.format_attribute post, :true_method expect(true_value.to_s).to eq "Yes\n" - false_value = format_attribute post, :false_method + false_value = view.format_attribute post, :false_method expect(false_value.to_s).to eq "No\n" end diff --git a/spec/unit/views/components/paginated_collection_spec.rb b/spec/unit/views/components/paginated_collection_spec.rb index dd7c4b2e2c8..62bb8f8d88a 100644 --- a/spec/unit/views/components/paginated_collection_spec.rb +++ b/spec/unit/views/components/paginated_collection_spec.rb @@ -2,10 +2,8 @@ RSpec.describe ActiveAdmin::Views::PaginatedCollection do describe "creating with the dsl" do - - before :all do - load_defaults! - reload_routes! + around do |example| + with_resources_during(example) { ActiveAdmin.register Post } end let(:view) do diff --git a/tasks/application_generator.rb b/tasks/application_generator.rb index a44a367d6fa..e7fac549f28 100644 --- a/tasks/application_generator.rb +++ b/tasks/application_generator.rb @@ -1,3 +1,5 @@ +require 'fileutils' + module ActiveAdmin class ApplicationGenerator attr_reader :rails_env, :template @@ -11,7 +13,7 @@ def generate if File.exist? app_dir puts "test app #{app_dir} already exists; skipping test app generation" else - system "mkdir -p #{base_dir}" + FileUtils.mkdir_p base_dir args = %W( -m spec/support/#{template}.rb --skip-bootsnap @@ -26,7 +28,7 @@ def generate env = { 'BUNDLE_GEMFILE' => ENV['BUNDLE_GEMFILE'], 'RAILS_ENV' => rails_env } - Bundler.with_original_env { Kernel.system(env, command) } + Bundler.with_original_env { abort unless Kernel.system(env, command) } end app_dir diff --git a/tasks/gemfiles.rake b/tasks/gemfiles.rake index 3ad8773e997..6e61e0d4a2c 100644 --- a/tasks/gemfiles.rake +++ b/tasks/gemfiles.rake @@ -2,7 +2,7 @@ desc "Bundle all Gemfiles" task :bundle do |_t, opts| ["Gemfile", *Dir.glob("gemfiles/*.gemfile")].each do |gemfile| Bundler.with_original_env do - system({ "BUNDLE_GEMFILE" => gemfile }, "bundle", *opts) + sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle", *opts) end end end diff --git a/tasks/lint.rake b/tasks/lint.rake index 8daf92d2320..9be81b47195 100644 --- a/tasks/lint.rake +++ b/tasks/lint.rake @@ -78,7 +78,7 @@ namespace :lint do task :mdl do puts "Running mdl..." - abort unless system("mdl", "--git-recurse", ".") + sh("mdl", "--git-recurse", ".") end desc "Check for unnecessary trailing whitespace across all repo files" @@ -99,7 +99,7 @@ namespace :lint do task :rspec do puts "Linting project files..." - abort unless system( + sh( { "COVERAGE" => "true" }, "rspec", "spec/gemfiles_spec.lint.rb", diff --git a/tasks/release.rake b/tasks/release.rake new file mode 100644 index 00000000000..e98c7790826 --- /dev/null +++ b/tasks/release.rake @@ -0,0 +1,6 @@ +require "chandler/tasks" + +# +# Add chandler as a prerequisite for `rake release` +# +task "release:rubygem_push" => "chandler:push" diff --git a/tasks/test.rake b/tasks/test.rake index 4a32a369c6c..e916edffdb8 100644 --- a/tasks/test.rake +++ b/tasks/test.rake @@ -1,4 +1,3 @@ -require 'parallel' require_relative "application_generator" desc "Run the full suite using parallel_tests to run on multiple cores" @@ -11,7 +10,7 @@ end desc "Run the specs in parallel" task :spec do - system("parallel_rspec --serialize-stdout --verbose spec/") + sh("parallel_rspec --serialize-stdout --combine-stderr --verbose spec/") end namespace :spec do @@ -19,7 +18,7 @@ namespace :spec do %i(unit request).each do |type| desc "Run the #{type} specs in parallel" task type do - system("parallel_rspec --serialize-stdout --verbose spec/#{type}") + sh("parallel_rspec --serialize-stdout --combine-stderr --verbose spec/#{type}") end end @@ -32,12 +31,12 @@ namespace :cucumber do desc "Run the standard cucumber scenarios in parallel" task :regular do - system("parallel_cucumber --serialize-stdout --verbose features/") + sh("parallel_cucumber --serialize-stdout --combine-stderr --verbose features/") end desc "Run the cucumber scenarios that test reloading" task :reloading do - system("cucumber --profile class-reloading") + sh("cucumber --profile class-reloading") end end