Commit Graph

32 Commits

Author SHA1 Message Date
Jared Beck 8f5a935c3a RSpec/ContextWording 2021-08-29 22:22:39 -04:00
Jared Beck 8d4a186d10 Use Time.current everywhere
Enforce with the Rails/TimeZone cop.
2021-03-17 23:33:46 -04:00
Jared Beck fbe05cf13f Tests: various updates for rails 6.1 2020-12-15 12:39:34 -05:00
Todd Lynam f7a94d0b63 Skip creating version for timestamp when changed attributed is ignored via Hash
- It was only ignoring attributes defined as symbols.
- It now ignores when attributes are either defined as symbols or Hashes.
- Consolidates calculation to be shared when determining if changed and not ignored.

Resolves #1240
2020-08-16 10:15:43 -10:00
Jared Beck 0726460a29 Testing the :skip option 2018-08-31 12:41:07 -04:00
Jared Beck 84368ea289 Extract `Events` module
Introduces event classes, like Events::Create, which wrap the
AR instance and have one public method, `#data`, which returns
the attributes of nascent `Version` records. See comments in
Events::Base.

This extraction greatly simplifies RecordTrail. Not only have
we moved a lot of code out of RecordTrail, but we've also
moved the `@in_after_callback` variable. In its new location, this
variable is much easier to understand, and we no longer need the
`ensure` blocks to reset it.

Preserving compatibility with PT-AT caused some minor difficulties,
and we should follow up with them to see if we can simplify the
API they are using. Specifically, we would like to delete the
`data_for_*` methods.
2018-07-22 01:32:30 -04:00
Jared Beck cfbf7a647c Lint: Style/FrozenStringLiteralComment 2017-12-10 23:05:39 -05:00
Jared Beck 515f0958a6 Lint: Fix RSpec/NamedSubject 2017-10-27 12:17:04 -04:00
Jared Beck df4f3bba4f Lint: Fix various offenses, mostly rspec
- Fix Lint/RescueWithoutErrorClass
  - And I use the term "fix" loosely
- Fix RSpec/PredicateMatcher
  - The failure message should actually be better this way too.
- RSpec/LetBeforeExamples
- RSpec/HookArgument
- Fix RSpec/ExpectInHook in widget_spec.rb
- Fix RSpec/MessageSpies
  - I like spies. I've never linted them before, but I like how they
    separate test setup from assertions.
2017-09-19 01:25:53 -04:00
Jared Beck 38fa23873c Merge rails_helper into spec_helper
The reason some projects have both is so that some spec files can be
run in isolation, without the rails stuff. In practice, I don't find
myself ever doing this. So, the complexity of two files is unnecessary.
2017-05-30 00:59:55 -04:00
Jared Beck c4148de9d0 Configure RSpec
Enable various standard configuration.
2017-05-21 02:04:28 -04:00
Jared Beck cf99fb3358 Lint: Finish fixing RSpec/NestedGroups 2017-04-01 20:13:08 -04:00
Jared Beck f3e38a2ec8 Lint: Improve RSpec/NestedGroups from infinity to 5 2017-04-01 02:28:55 -04:00
Jared Beck 0b016be756 Lint: Fix RSpec/NotToNot 2017-04-01 01:59:47 -04:00
Jared Beck af10cd4f00 Lint: Fix RSpec/ExampleWording 2017-04-01 01:50:13 -04:00
Jared Beck 3df7dc27d2 Lint: Fix Lint/AmbiguousBlockAssociation 2017-04-01 00:33:33 -04:00
Jared Beck fc071b2d13 rubocop 0.41.1 (was 0.40.0) 2016-06-27 03:02:33 -04:00
Jared Beck ad3806fcbb An idea to combat model pollution
Problem
-------

`has_paper_trail` adds too many methods to the ActiveRecord model.

> If I'm counting correctly, installing the paper_trail gem adds 36 instance
> methods and 10 class methods to all of your active record models. Of those
> 46, 13 have a prefix, either "pt_" or "paper_trail_". I don't know what the
> best way to deal with this is. Ideally, we'd add far fewer methods to
> people's models. If we were able to add fewer methods to models, then I
> wouldn't mind prefixing all of them.
> https://github.com/airblade/paper_trail/issues/703

Solution
--------

Add only two methods to the AR model.

1. An instance method `#paper_trail`
2. A class method `.paper_trail`

The instance method would return a `RecordTrail` and the class method would
return a `ClassTrail`. Those names are totally up for debate.

Advantages
----------

- Plain ruby, easy to understand
- Adding new methods to e.g. the `RecordTrail` does not add any methods to
  the AR model.
- Methods privacy is more strongly enforced.
- Enables isolated testing of e.g. `RecordTrail`; it can be constructed with a
  mock AR instance.

Disadvantages
-------------

- Two new classes, though they are simple.
2016-06-06 01:18:31 -04:00
Jared Beck 4200a6a8ca Fix Style/ParallelAssignment 2016-03-05 17:23:10 -05:00
Jared Beck c24d0b4780 Fix whitespace 2016-03-05 17:11:08 -05:00
Jared Beck 8980f08d0e Fix Style/StringLiterals: Use double quotes 2016-03-05 17:07:32 -05:00
Jared Beck 10941c8459 Fix Style/HashSyntax 2016-02-15 22:32:40 -05:00
Jared Beck d86e6ec64c Break long lines in `spec` dir 2016-02-15 18:27:57 -05:00
Owen Rodda b9d9fb2e7c Update PaperTrail and test suite for ActiveRecord 5 compatibility 2016-01-24 19:57:10 -05:00
Jared Beck d030ba2b02 Remove ruby 1.8 hacks
PaperTrail no longer supports ruby 1.8.
2015-12-13 01:14:59 -05:00
Jared Beck 40bf20beb5 Respect `:skip` re: timestamp-only updates
When attributes are ignored, either by `:ignore` or by `:skip`,
then during updates, timestamp attributes like `updated_at` should
not be considered notable changes.

[Fixes #569]
2015-07-15 22:29:19 -04:00
Ben Atkins 1b1e74dab5 Basic version comparisons for RUBY_VERSION can be done using Strings
As opposed to unnecessarily casting the RUBY_VERSION to a Float
2015-01-14 14:09:30 -05:00
Ben Atkins be5f192bd1 close #438; PaperTrail::Model::ClassMethods#paper_trail_enabled_for_model? should return false if has_paper_trail isn't declared on the class in question 2014-10-31 10:43:24 -04:00
Ben Atkins 716c3e0fb5 Use RSpec 3 for testing; Update syntax in spec suite for RSpec 3 2014-10-09 15:04:17 -04:00
Ben Atkins 8f256d7081 Add some additional testing and comments surrounding the PaperTrail::Model::InstanceMethods#changed_notably? private method changes 2014-10-08 00:09:40 -04:00
Ben Atkins 052f16495b Update Gadget spec with Ruby18 hash syntax 2014-10-07 23:16:36 -04:00
Ben Atkins 049a86f1ab Fix PaperTrail::Model::InstanceMethods#changed_notably? to return proper values when attrs are ignored 2014-10-07 23:16:36 -04:00