From 51de9966499e9cf67647837411f188f3bdae21c5 Mon Sep 17 00:00:00 2001 From: Ben Atkins Date: Wed, 11 Jun 2014 14:55:04 -0400 Subject: [PATCH] Expand VERSION (number) into it's own module to give the version number tracking more modularity --- CHANGELOG.md | 1 + lib/paper_trail/version_number.rb | 17 ++++++++++- paper_trail.gemspec | 2 +- spec/modules/version_number_spec.rb | 44 +++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 spec/modules/version_number_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index d8b08d66..e8968b0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - [#372](https://github.com/airblade/paper_trail/pull/372) - Use [Arel](https://github.com/rails/arel) for SQL construction. - [#347](https://github.com/airblade/paper_trail/pull/347) - Autoload `ActiveRecord` models in via a `Rails::Engine` when the gem is used with `Rails`. + - Expand `PaperTrail::VERSION` into a module, mimicking the form used by Rails to give it some additional modularity & versatility. - Fixed `VersionConcern#index` instance method so that it conforms to using the primary key for ordering when possible. ## 3.0.2 diff --git a/lib/paper_trail/version_number.rb b/lib/paper_trail/version_number.rb index 8acac776..99b737f0 100644 --- a/lib/paper_trail/version_number.rb +++ b/lib/paper_trail/version_number.rb @@ -1,3 +1,18 @@ module PaperTrail - VERSION = '3.0.2' + module VERSION + MAJOR = 3 + MINOR = 0 + TINY = 3 + PRE = 'alpha' + + STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') + + def self.to_s + STRING + end + end + + def self.version + VERSION::STRING + end end diff --git a/paper_trail.gemspec b/paper_trail.gemspec index bdcbd747..0730052e 100644 --- a/paper_trail.gemspec +++ b/paper_trail.gemspec @@ -3,7 +3,7 @@ require 'paper_trail/version_number' Gem::Specification.new do |s| s.name = 'paper_trail' - s.version = PaperTrail::VERSION + s.version = PaperTrail.version s.platform = Gem::Platform::RUBY s.summary = "Track changes to your models' data. Good for auditing or versioning." s.description = s.summary diff --git a/spec/modules/version_number_spec.rb b/spec/modules/version_number_spec.rb new file mode 100644 index 00000000..aaa38629 --- /dev/null +++ b/spec/modules/version_number_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper' + +describe 'PaperTrail::VERSION' do + + describe "Constants" do + subject { PaperTrail::VERSION } + + describe :MAJOR do + it { should be_const_defined(:MAJOR) } + it { subject::MAJOR.should be_a(Integer) } + end + describe :MINOR do + it { should be_const_defined(:MINOR) } + it { subject::MINOR.should be_a(Integer) } + end + describe :TINY do + it { should be_const_defined(:TINY) } + it { subject::TINY.should be_a(Integer) } + end + describe :PRE do + it { should be_const_defined(:PRE) } + if PaperTrail::VERSION::PRE + it { subject::PRE.should be_instance_of(String) } + end + end + describe :STRING do + it { should be_const_defined(:STRING) } + it { subject::STRING.should be_instance_of(String) } + + it "should join the numbers into a period separated string" do + subject::STRING.should == + [subject::MAJOR, subject::MINOR, subject::TINY, subject::PRE].compact.join('.') + end + end + end + +end + +describe PaperTrail do + describe :version do + it { should respond_to(:version) } + its(:version) { should == PaperTrail::VERSION::STRING } + end +end