Add PaperTrail.gem_version

This commit is contained in:
Jared Beck 2017-04-01 01:19:54 -04:00
parent f7945086c5
commit 2246570dc3
5 changed files with 34 additions and 13 deletions

View File

@ -18,7 +18,7 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
### Added
- None
- `PaperTrail.gem_version` returns a `Gem::Version`, nice for comparisons.
### Fixed

View File

@ -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)

View File

@ -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

View File

@ -1,6 +1,7 @@
require "spec_helper"
RSpec.describe PaperTrail::VERSION do
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(
@ -13,4 +14,5 @@ RSpec.describe PaperTrail::VERSION do
)
end
end
end
end

View File

@ -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