mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Add PaperTrail.gem_version
This commit is contained in:
parent
f7945086c5
commit
2246570dc3
5 changed files with 34 additions and 13 deletions
|
@ -18,7 +18,7 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
|
|||
|
||||
### Added
|
||||
|
||||
- None
|
||||
- `PaperTrail.gem_version` returns a `Gem::Version`, nice for comparisons.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -62,6 +62,13 @@ module PaperTrail
|
|||
!!paper_trail_store.fetch(:"enabled_for_#{model}", true)
|
||||
end
|
||||
|
||||
# Returns a `::Gem::Version`, convenient for comparisons. This is
|
||||
# recommended over `::PaperTrail::VERSION::STRING`.
|
||||
# @api public
|
||||
def gem_version
|
||||
::Gem::Version.new(VERSION::STRING)
|
||||
end
|
||||
|
||||
# Set the field which records when a version was created.
|
||||
# @api public
|
||||
def timestamp_field=(_field_name)
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
module PaperTrail
|
||||
# :nodoc:
|
||||
# The version number of the paper_trail gem. Not to be confused with
|
||||
# `PaperTrail::Version`. Ruby constants are case-sensitive, apparently,
|
||||
# and they are two different modules! It would be nice to remove `VERSION`,
|
||||
# because of this confusion, but it's not worth the breaking change.
|
||||
# People are encouraged to use `PaperTrail.gem_version` instead.
|
||||
module VERSION
|
||||
MAJOR = 6
|
||||
MINOR = 0
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
require "spec_helper"
|
||||
|
||||
RSpec.describe PaperTrail::VERSION do
|
||||
describe "STRING" do
|
||||
it "should join the numbers into a period separated string" do
|
||||
expect(described_class::STRING).to eq(
|
||||
[
|
||||
described_class::MAJOR,
|
||||
described_class::MINOR,
|
||||
described_class::TINY,
|
||||
described_class::PRE
|
||||
].compact.join(".")
|
||||
)
|
||||
module PaperTrail
|
||||
RSpec.describe VERSION do
|
||||
describe "STRING" do
|
||||
it "should join the numbers into a period separated string" do
|
||||
expect(described_class::STRING).to eq(
|
||||
[
|
||||
described_class::MAJOR,
|
||||
described_class::MINOR,
|
||||
described_class::TINY,
|
||||
described_class::PRE
|
||||
].compact.join(".")
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe PaperTrail do
|
||||
describe ".gem_version" do
|
||||
it "returns a Gem::Version" do
|
||||
v = described_class.gem_version
|
||||
expect(v).to be_a(::Gem::Version)
|
||||
expect(v.to_s).to eq(::PaperTrail::VERSION::STRING)
|
||||
end
|
||||
end
|
||||
|
||||
context "when enabled" do
|
||||
it "affects all threads" do
|
||||
Thread.new { described_class.enabled = false }.join
|
||||
|
|
Loading…
Reference in a new issue