1
0
Fork 0
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:
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 ### Added
- None - `PaperTrail.gem_version` returns a `Gem::Version`, nice for comparisons.
### Fixed ### Fixed

View file

@ -62,6 +62,13 @@ module PaperTrail
!!paper_trail_store.fetch(:"enabled_for_#{model}", true) !!paper_trail_store.fetch(:"enabled_for_#{model}", true)
end 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. # Set the field which records when a version was created.
# @api public # @api public
def timestamp_field=(_field_name) def timestamp_field=(_field_name)

View file

@ -1,5 +1,9 @@
module PaperTrail 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 module VERSION
MAJOR = 6 MAJOR = 6
MINOR = 0 MINOR = 0

View file

@ -1,6 +1,7 @@
require "spec_helper" require "spec_helper"
RSpec.describe PaperTrail::VERSION do module PaperTrail
RSpec.describe VERSION do
describe "STRING" do describe "STRING" do
it "should join the numbers into a period separated string" do it "should join the numbers into a period separated string" do
expect(described_class::STRING).to eq( expect(described_class::STRING).to eq(
@ -13,4 +14,5 @@ RSpec.describe PaperTrail::VERSION do
) )
end end
end end
end
end end

View file

@ -1,6 +1,14 @@
require "rails_helper" require "rails_helper"
RSpec.describe PaperTrail do 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 context "when enabled" do
it "affects all threads" do it "affects all threads" do
Thread.new { described_class.enabled = false }.join Thread.new { described_class.enabled = false }.join