diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..33ac4dfe --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,60 @@ +name: CI RSpec Test + +on: [push, pull_request] + +jobs: + build: + name: >- + ${{ matrix.ruby }} + env: + CI: true + TESTOPTS: -v + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental }} + strategy: + fail-fast: true + matrix: + ruby: [2.5, 2.6, 2.7, 3.0, jruby] # truffleruby + mongoid: [7] + experimental: [false] + include: + - ruby: 2.3 + mongoid: 3 + experimental: true + - ruby: 2.4 + mongoid: 4 + experimental: true + - ruby: 2.5 + mongoid: 5 + experimental: true + - ruby: 2.6 + mongoid: 6 + experimental: true + - ruby: head + mongoid: 7 + experimental: true + - ruby: jruby-head + mongoid: 7 + experimental: true + # - ruby: truffleruby-head + # mongoid: 7 + # experimental: true + steps: + - name: repo checkout + uses: actions/checkout@v2 + - name: start mongodb + uses: supercharge/mongodb-github-action@1.6.0 + with: + mongodb-version: 4.4 + mongodb-replica-set: rs0 + - name: load ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler: 2 + - name: bundle install + run: bundle install --jobs 4 --retry 3 + - name: test + timeout-minutes: 10 + run: bundle exec rake spec + continue-on-error: ${{ matrix.experimental }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 33eec28a..00000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ - -sudo: false - -language: ruby - -cache: bundler - -services: mongodb - -env: - - MONGOID_VERSION=3 - - MONGOID_VERSION=4 - - MONGOID_VERSION=5 - - MONGOID_VERSION=6 - - MONGOID_VERSION=7 - - MONGOID_VERSION=HEAD - -rvm: - - 2.3 - -before_install: - - gem update bundler - -before_script: - - bundle exec danger - -addons: - apt: - sources: - - mongodb-3.2-precise - packages: - - mongodb-org-server - -matrix: - allow_failures: - - env: MONGOID_VERSION=HEAD diff --git a/CHANGELOG.md b/CHANGELOG.md index 80c58e22..2b56177a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### 0.8.4 (Next) +* [#250](https://github.com/mongoid/mongoid-history/pull/250): Migrate to Github actions - [@johnnyshields](https://github.com/johnnyshields). * [#249](https://github.com/mongoid/mongoid-history/pull/249): Don't update version on embedded documents if the document itself is being destroyed - [@getaroom](https://github.com/getaroom). * [#248](https://github.com/mongoid/mongoid-history/pull/248): Don't update version on embedded documents if an ancestor is being destroyed in the same operation - [@getaroom](https://github.com/getaroom). * Your contribution here. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 73955171..98f83cda 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,9 +1,8 @@ -Contributing to Mongoid-History -=============================== +# Contributing to Mongoid-History Mongoid-History is work of [many of contributors](https://github.com/mongoid/mongoid-history/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/mongoid/mongoid-history/pulls), [propose features, ask questions and discuss issues](https://github.com/mongoid/mongoid-history/issues). -#### Fork the Project +### Fork the Project Fork the [project on Github](https://github.com/mongoid/mongoid-history) and check out your copy. @@ -13,7 +12,7 @@ cd mongoid-history git remote add upstream https://github.com/mongoid/mongoid-history.git ``` -#### Create a Topic Branch +### Create a Topic Branch Make sure your fork is up-to-date and create a topic branch for your feature or bug fix. @@ -23,7 +22,7 @@ git pull upstream master git checkout -b my-feature-branch ``` -#### Bundle Install and Test +### Bundle Install and Test Ensure that you can build the project and run tests. @@ -32,13 +31,13 @@ bundle install bundle exec rake ``` -#### Write Tests +### Write Tests Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [spec/mongoid-history](spec/mongoid-history). We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix. -#### Write Code +### Write Code Implement your feature or bug fix. @@ -46,15 +45,15 @@ Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop), run ` Make sure that `bundle exec rake` completes without errors. -#### Write Documentation +### Write Documentation Document any external behavior in the [README](README.md). -#### Update Changelog +### Update Changelog Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Make it look like every other line, including your name and link to your Github account. -#### Commit Changes +### Commit Changes Make sure git knows your name and email address: @@ -70,17 +69,17 @@ git add ... git commit ``` -#### Push +### Push ``` git push origin my-feature-branch ``` -#### Make a Pull Request +### Make a Pull Request Go to https://github.com/contributor/mongoid-history and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days. -#### Rebase +### Rebase If you've been working on a change for a while, rebase with upstream/master. @@ -90,7 +89,7 @@ git rebase upstream/master git push origin my-feature-branch -f ``` -#### Update CHANGELOG Again +### Update CHANGELOG Again Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows. @@ -105,14 +104,14 @@ git commit --amend git push origin my-feature-branch -f ``` -#### Check on Your Pull Request +### Check on Your Pull Request Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above. -#### Be Patient +### Be Patient It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there! -#### Thank You +### Thank You Please do know that we really appreciate and value your time and work. We love you, really. diff --git a/Gemfile b/Gemfile index 8132c422..01f669f8 100644 --- a/Gemfile +++ b/Gemfile @@ -2,30 +2,31 @@ source 'https://rubygems.org' gemspec -case version = ENV['MONGOID_VERSION'] || '~> 7.0.0' +case version = ENV['MONGOID_VERSION'] || '~> 7.0' when 'HEAD' gem 'mongoid', github: 'mongodb/mongoid' when /\b7/ - gem 'mongoid', '~> 7.0.0' + gem 'mongoid', '~> 7.0' when /\b6/ - gem 'mongoid', '~> 6.0.0' + gem 'mongoid', '~> 6.0' when /\b5/ gem 'mongoid', '~> 5.0' - gem 'mongoid-observers', '~> 0.2.0' + gem 'mongoid-observers', '~> 0.2' when /\b4/ gem 'mongoid', '~> 4.0' - gem 'mongoid-observers', '~> 0.2.0' + gem 'mongoid-observers', '~> 0.2' when /\b3/ - gem 'mongoid', '~> 3.1.7' + gem 'mongoid', '~> 3.1' else gem 'mongoid', version end + gem 'mongoid-compatibility' group :development, :test do gem 'bundler' gem 'pry' - gem 'rake', '< 11.0' + gem 'rake' end group :test do diff --git a/README.md b/README.md index 9d6a6c14..387c6f5d 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,32 @@ -mongoid-history -=============== +# Mongoid History [![Gem Version](https://badge.fury.io/rb/mongoid-history.svg)](http://badge.fury.io/rb/mongoid-history) [![Build Status](https://secure.travis-ci.org/mongoid/mongoid-history.svg?branch=master)](http://travis-ci.org/mongoid/mongoid-history) [![Code Climate](https://codeclimate.com/github/mongoid/mongoid-history.svg)](https://codeclimate.com/github/mongoid/mongoid-history) -[![Coverage Status](https://coveralls.io/repos/mongoid/mongoid-history/badge.svg)](https://coveralls.io/r/mongoid/mongoid-history?branch=coveralls) -Mongoid-history tracks historical changes for any document, including embedded ones. It achieves this by storing all history tracks in a single collection that you define. Embedded documents are referenced by storing an association path, which is an array of `document_name` and `document_id` fields starting from the top most parent document and down to the embedded document that should track history. +Mongoid History tracks historical changes for any document, including embedded ones. It achieves this by storing all history tracks in a single collection that you define. Embedded documents are referenced by storing an association path, which is an array of `document_name` and `document_id` fields starting from the top most parent document and down to the embedded document that should track history. This gem also implements multi-user undo, which allows users to undo any history change in any order. Undoing a document also creates a new history track. This is great for auditing and preventing vandalism, but is probably not suitable for use cases such as a wiki (but we won't stop you either). -Install -------- +### Version Support -This gem supports Mongoid 3, 4, 5 on Ruby 1.9.3 or newer and Mongoid 6 and 7 on Ruby 2.2.2+. Add it to your `Gemfile` or run `gem install mongoid-history`. +Mongoid History supports the following dependency versions: + +* Ruby 2.3+ +* Mongoid 3.1+ +* Recent JRuby versions + +Earlier Ruby versions may work but are untested. + +## Install ```ruby gem 'mongoid-history' ``` -Usage ------ +## Usage -**Create a history tracker** +### Create a history tracker Create a new class to track histories. All histories are stored in this tracker. The name of the class can be anything you like. The only requirement is that it includes `Mongoid::History::Tracker` @@ -33,7 +37,7 @@ class HistoryTracker end ``` -**Set default tracker class name (Optional)** +### Set default tracker class name (optional) Mongoid::History will use the first loaded class to include Mongoid::History::Tracker as the default history tracker. If you are using multiple Tracker classes, you should set a global @@ -46,7 +50,7 @@ default in a Rails initializer: Mongoid::History.tracker_class_name = :history_tracker ``` -**Create trackable classes and objects** +### Create trackable classes and objects ```ruby class Post @@ -254,7 +258,7 @@ track.original # {} track.modified # { "title" => "Test", "body" => "Post", "comments" => [{ "_id" => "575fa9e667d827e5ed00000d", "title" => "test", "body" => "comment" }], ... } ``` -**Whitelist the tracked attributes of embedded relations** +### Whitelist the tracked attributes of embedded relations If you don't want to track all the attributes of embedded relations in parent audit history, you can whitelist the attributes as below: @@ -279,7 +283,7 @@ end It will now track only `_id` (Mandatory), `title` and `content` attributes for `pages` relation. -**Retrieving the list of tracked static and dynamic fields** +### Retrieving the list of tracked static and dynamic fields ```ruby class Book @@ -295,7 +299,7 @@ Book.tracked_field?(:title) #=> true Book.tracked_field?(:author) #=> false ``` -**Retrieving the list of tracked relations** +### Retrieving the list of tracked relations ```ruby class Book @@ -308,7 +312,7 @@ Book.tracked_embeds_many #=> ["pages"] Book.tracked_embeds_many?(:pages) #=> true ``` -**Skip soft-deleted embedded objects with nested tracking** +### Skip soft-deleted embedded objects with nested tracking Default paranoia field is `deleted_at`. You can use custom field for each class as below: @@ -331,7 +335,7 @@ end This will skip the `page` documents with `removed_at` set to a non-blank value from nested tracking -**Formatting fields** +### Formatting fields You can opt to use a proc or string interpolation to alter attributes being stored on a history record. @@ -366,7 +370,7 @@ class Page end ``` -**Displaying history trackers as an audit trail** +### Displaying history trackers as an audit trail In your Controller: @@ -409,7 +413,7 @@ In your View, you might do something like (example in HAML format): %li.remove Removed field #{k} (was previously #{v}) ``` -**Adding Userstamp on History Trackers** +### Adding Userstamp on History Trackers To track the User in the application who created the HistoryTracker, add the [Mongoid::Userstamp gem](https://github.com/tbpro/mongoid_userstamp) to your HistoryTracker class. @@ -422,7 +426,7 @@ class MyHistoryTracker end ``` -**Setting Modifier Class Name** +### Setting Modifier Class Name If your app will track history changes to a user, Mongoid History looks for these modifiers in the ``User`` class by default. If you have named your 'user' accounts differently, you will need to add that to your Mongoid History config: @@ -443,7 +447,7 @@ Or perhaps you are namespacing to a module: Mongoid::History.modifier_class_name = 'CMS::Author' ``` -**Conditional :if and :unless options** +### Conditional :if and :unless options The `track_history` method supports `:if` and `:unless` options which will skip generating the history tracker unless they are satisfied. These options can take either a method @@ -455,7 +459,7 @@ the history tracker unless they are satisfied. These options can take either a m unless: ->(obj){ obj.method_to_skip_history } ``` -**Using an alternate changes method** +### Using an alternate changes method Sometimes you may wish to provide an alternate method for determining which changes should be tracked. For example, if you are using embedded documents and nested attributes, you may wish to write your own changes method that includes changes from the embedded documents. @@ -535,7 +539,7 @@ end For more examples, check out [spec/integration/integration_spec.rb](spec/integration/integration_spec.rb). -**Multiple Trackers** +### Multiple Trackers You can have different trackers for different classes like so. @@ -575,8 +579,7 @@ If you are using multiple trackers and the `tracker_class_name` parameter is not specified, Mongoid::History will use the default tracker configured in the initializer file or whatever the first tracker was loaded. - -**Dependent Restrict Associations** +### Dependent Restrict Associations When `dependent: :restrict` is used on an association, a call to `destroy` on the model will raise `Mongoid::Errors::DeleteRestriction` when the dependency @@ -587,7 +590,7 @@ to all persistence calls: create, update and destroy. See [spec/integration/validation_failure_spec.rb](spec/integration/validation_failure_spec.rb) for examples. -**Thread Safety** +### Thread Safety Mongoid::History stores the tracking enable/disable flag in `Thread.current`. If the [RequestStore](https://github.com/steveklabnik/request_store) gem is installed, Mongoid::History @@ -595,13 +598,11 @@ will automatically store variables in the `RequestStore.store` instead. RequestS for threaded web servers like Thin or Puma. -Contributing to mongoid-history -------------------------------- +## Contributing -You're encouraged to contribute to this library. See [CONTRIBUTING](CONTRIBUTING.md) for details. +You're encouraged to contribute to Mongoid History. See [CONTRIBUTING.md](CONTRIBUTING.md) for details. -Copyright ---------- +## Copyright Copyright (c) 2011-2020 Aaron Qian and Contributors.