app_version 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +97 -0
- data/Rakefile +22 -0
- data/lib/app_version.rb +5 -0
- data/lib/app_version/app_version.rb +149 -0
- data/lib/app_version/railtie.rb +12 -0
- data/lib/app_version/templates/version.yml +21 -0
- data/lib/app_version/templates/version.yml.erb +20 -0
- data/lib/install.rb +14 -0
- data/lib/tasks/app_version_tasks.rake +26 -0
- data/lib/uninstall.rb +11 -0
- data/test/app_version_test.rb +275 -0
- data/test/version.yml +9 -0
- metadata +77 -0
data/README.rdoc
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
= App Version
|
2
|
+
|
3
|
+
This is a simple plugin that makes it easy to manage the version number of your
|
4
|
+
Rails application. The version numbers supported by this plugin look like
|
5
|
+
'2.0.1 M4 (600) of branch by coder on 2008-10-27'.
|
6
|
+
|
7
|
+
The components of the version number are:
|
8
|
+
|
9
|
+
2 => major
|
10
|
+
0 => minor
|
11
|
+
1 => patch
|
12
|
+
M4 => milestone
|
13
|
+
(600) => build number (usually Subversion revision)
|
14
|
+
branch => the name of the branch this version is from.
|
15
|
+
coder => the name of the user that made the release
|
16
|
+
2008-10-27 => the date of the release
|
17
|
+
|
18
|
+
Only the major and minor numbers are required. The rest can be omitted and the
|
19
|
+
plugin will attempt to do the right thing.
|
20
|
+
|
21
|
+
== Install
|
22
|
+
|
23
|
+
To install this plugin from gitHub run the following command:
|
24
|
+
|
25
|
+
./script/plugin install git://github.com/toland/app_version.git
|
26
|
+
|
27
|
+
== Usage
|
28
|
+
|
29
|
+
To use, simply place a file in RAILS_ROOT/config called version.yml with the
|
30
|
+
following format:
|
31
|
+
|
32
|
+
major: 2
|
33
|
+
minor: 0
|
34
|
+
patch: 1
|
35
|
+
milestone: 4
|
36
|
+
build: git-revcount
|
37
|
+
branch: master
|
38
|
+
committer: coder
|
39
|
+
build_date: 2008-10-27
|
40
|
+
|
41
|
+
If the milestone or patch fields are less than 0 then they will not show up
|
42
|
+
in the version string. The build field can be a build number or one of the
|
43
|
+
following strings: svn, git-hash or git-revcount. If it is a number then that
|
44
|
+
number will be used as the build number, if it is one of the special strings
|
45
|
+
then the plugin will attempt to query the source control system for the build
|
46
|
+
number. The build date field can be a date or the following string: git-revdate.
|
47
|
+
If you use the special string it will query the source control system and output
|
48
|
+
in YYYY-MM-DD format the commit date of the last revision.
|
49
|
+
|
50
|
+
Using 'svn' for the build number will cause the plugin to query Subversion for
|
51
|
+
the current revision number. Since Git doesn't have a numbered revision we have
|
52
|
+
to fake it. 'git-revcount' will count the number of commits to the repository
|
53
|
+
and use that as the build number whereas 'git-hash' will use the first 6 digits
|
54
|
+
of the current HEAD's hash.
|
55
|
+
|
56
|
+
The plugin creates a constant APP_VERSION that contains the version number of
|
57
|
+
the application. Calling the +to_s+ method on APP_VERSION will result in a
|
58
|
+
properly formatted version number. APP_VERSION also has +major+, +minor+,
|
59
|
+
+patch+, +milestone+, +build+, +branch+, +committer+, and +build_date+
|
60
|
+
methods to retrieve the individual components of the version number.
|
61
|
+
|
62
|
+
== Capistrano Usage
|
63
|
+
|
64
|
+
When the app_version plugin is installed, it copies a templated edition of the
|
65
|
+
version.yml file into /lib/templates/version.yml.erb, the initial file shows a
|
66
|
+
tag for retrieving the revision count with git. It also shows displaying the
|
67
|
+
branch as specified with "set :branch" in your capistrano deploy.rb, see the
|
68
|
+
comments in the erb file for more nifty tricks.
|
69
|
+
|
70
|
+
When you do a cap deploy, there is a capistrano recipe built-in to the app_version
|
71
|
+
plugin, which will render the templated version.yml into the standard location as
|
72
|
+
mentioned above. This happens automatically after the deploy is done.
|
73
|
+
|
74
|
+
Both the standard and extended capistrano usage can co-exist in the same project
|
75
|
+
the dynamic rendering of the version.yml only happens when using capistrano to
|
76
|
+
deploy your app.
|
77
|
+
|
78
|
+
== Rake tasks
|
79
|
+
|
80
|
+
This plugin includes 4 new rake tasks:
|
81
|
+
|
82
|
+
rake app:install - will copy the version.yml and version.yml.erb into more user
|
83
|
+
accessible locations (/config, and /lib/templates)
|
84
|
+
|
85
|
+
rake app:uninstall - will remove the files copied in the install task
|
86
|
+
|
87
|
+
rake app:render - will render the erb template into /config/version.yml
|
88
|
+
in case you want to have dynamic values updated via a rake task.
|
89
|
+
Note: certain examples expect the app to be in a git working directory.
|
90
|
+
|
91
|
+
rake app:version - will output the version number of the current rails
|
92
|
+
application.
|
93
|
+
|
94
|
+
= License
|
95
|
+
|
96
|
+
This plugin is released under the terms of the Ruby license. See
|
97
|
+
http://www.ruby-lang.org/en/LICENSE.txt.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rdoc/task'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the app_version plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the app_version plugin.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'App-version'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
data/lib/app_version.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'active_support/core_ext/object'
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module App
|
6
|
+
class Version
|
7
|
+
include Comparable
|
8
|
+
|
9
|
+
attr_accessor :major, :minor, :patch, :milestone, :build, :branch, :committer, :build_date, :format
|
10
|
+
|
11
|
+
[:major, :minor, :patch, :milestone, :build, :branch, :committer, :format].each do |attr|
|
12
|
+
define_method "#{attr}=".to_sym do |value|
|
13
|
+
instance_variable_set("@#{attr}".to_sym, value.blank? ? nil : value.to_s)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Creates a new instance of the Version class using information in the passed
|
18
|
+
# Hash to construct the version number.
|
19
|
+
#
|
20
|
+
# Version.new(:major => 1, :minor => 0) #=> "1.0"
|
21
|
+
def initialize(args = nil)
|
22
|
+
if args && args.is_a?(Hash)
|
23
|
+
args.keys.reject {|key| key.is_a?(Symbol) }.each {|key| args[key.to_sym] = args.delete(key) }
|
24
|
+
|
25
|
+
[:major, :minor].each do |param|
|
26
|
+
raise ArgumentError.new("The #{param.to_s} parameter is required") if args[param].blank?
|
27
|
+
end
|
28
|
+
|
29
|
+
@major = args[:major].to_s
|
30
|
+
@minor = args[:minor].to_s
|
31
|
+
@patch = args[:patch].to_s unless args[:patch].blank?
|
32
|
+
@milestone = args[:milestone].to_s unless args[:milestone].blank?
|
33
|
+
@build = args[:build].to_s unless args[:build].blank?
|
34
|
+
@branch = args[:branch].to_s unless args[:branch].blank?
|
35
|
+
@committer = args[:committer].to_s unless args[:committer].blank?
|
36
|
+
@format = args[:format].to_s unless args[:format].blank?
|
37
|
+
|
38
|
+
unless args[:build_date].blank?
|
39
|
+
b_date = case args[:build_date]
|
40
|
+
when 'git-revdate'
|
41
|
+
get_revdate_from_git
|
42
|
+
else
|
43
|
+
args[:build_date].to_s
|
44
|
+
end
|
45
|
+
@build_date = Date.parse(b_date)
|
46
|
+
end
|
47
|
+
|
48
|
+
@build = case args[:build]
|
49
|
+
when 'svn'
|
50
|
+
get_build_from_subversion
|
51
|
+
when 'git-revcount'
|
52
|
+
get_revcount_from_git
|
53
|
+
when 'git-hash'
|
54
|
+
get_hash_from_git
|
55
|
+
when nil, ''
|
56
|
+
nil
|
57
|
+
else
|
58
|
+
args[:build].to_s
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Parses a version string to create an instance of the Version class.
|
64
|
+
def self.parse(version)
|
65
|
+
m = version.match(/(\d+)\.(\d+)(?:\.(\d+))?(?:\sM(\d+))?(?:\s\((\d+)\))?(?:\sof\s(\w+))?(?:\sby\s(\w+))?(?:\son\s(\S+))?/)
|
66
|
+
|
67
|
+
raise ArgumentError.new("The version '#{version}' is unparsable") if m.nil?
|
68
|
+
|
69
|
+
version = App::Version.new :major => m[1],
|
70
|
+
:minor => m[2],
|
71
|
+
:patch => m[3],
|
72
|
+
:milestone => m[4],
|
73
|
+
:build => m[5],
|
74
|
+
:branch => m[6],
|
75
|
+
:committer => m[7]
|
76
|
+
|
77
|
+
if (m[8] && m[8] != '')
|
78
|
+
date = Date.parse(m[8])
|
79
|
+
version.build_date = date
|
80
|
+
end
|
81
|
+
|
82
|
+
return version
|
83
|
+
end
|
84
|
+
|
85
|
+
# Loads the version information from a YAML file.
|
86
|
+
def self.load(path)
|
87
|
+
App::Version.new YAML::load(File.open(path))
|
88
|
+
end
|
89
|
+
|
90
|
+
def <=>(other)
|
91
|
+
# if !self.build.nil? && !other.build.nil?
|
92
|
+
# return self.build <=> other.build
|
93
|
+
# end
|
94
|
+
|
95
|
+
%w(build major minor patch milestone branch committer build_date).each do |meth|
|
96
|
+
rhs = self.send(meth) || -1
|
97
|
+
lhs = other.send(meth) || -1
|
98
|
+
|
99
|
+
ret = lhs <=> rhs
|
100
|
+
return ret unless ret == 0
|
101
|
+
end
|
102
|
+
|
103
|
+
return 0
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_s
|
107
|
+
if @format
|
108
|
+
str = eval(@format.to_s.inspect)
|
109
|
+
else
|
110
|
+
str = "#{major}.#{minor}"
|
111
|
+
str << ".#{patch}" unless patch.blank?
|
112
|
+
str << " M#{milestone}" unless milestone.blank?
|
113
|
+
str << " (#{build})" unless build.blank?
|
114
|
+
str << " of #{branch}" unless branch.blank?
|
115
|
+
str << " by #{committer}" unless committer.blank?
|
116
|
+
str << " on #{build_date}" unless build_date.blank?
|
117
|
+
end
|
118
|
+
str
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
def get_build_from_subversion
|
124
|
+
if File.exists?(".svn")
|
125
|
+
#YAML.parse(`svn info`)['Revision'].value
|
126
|
+
match = /(?:\d+:)?(\d+)M?S?/.match(`svnversion . -c`)
|
127
|
+
match && match[1]
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def get_revcount_from_git
|
132
|
+
if File.exists?(".git")
|
133
|
+
`git rev-list --count HEAD`.strip
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def get_revdate_from_git
|
138
|
+
if File.exists?(".git")
|
139
|
+
`git show --date=short --pretty=format:%cd|head -n1`.strip
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def get_hash_from_git
|
144
|
+
if File.exists?(".git")
|
145
|
+
`git show --pretty=format:%H|head -n1|cut -c 1-6`.strip
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This is your version information.
|
2
|
+
#
|
3
|
+
# This is a simple plugin that makes it easy to manage the version number of your
|
4
|
+
# Rails application. The version numbers supported by this plugin look like
|
5
|
+
# '2.0.1 M4 (600) of branch by coder on 2008-10-27'.
|
6
|
+
#
|
7
|
+
# The components that produced the example about would be:
|
8
|
+
#
|
9
|
+
# major: 2
|
10
|
+
# minor: 0
|
11
|
+
# patch: 1
|
12
|
+
# milestone: M4
|
13
|
+
# build: 600
|
14
|
+
# branch: branch
|
15
|
+
# committer: coder
|
16
|
+
# build_date: 2008-10-27
|
17
|
+
#
|
18
|
+
# major and minor are required. All others are optional - See readme in the app_version plugin
|
19
|
+
|
20
|
+
major: 1
|
21
|
+
minor: 0
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# this version.yml was generated by app_version plugin
|
2
|
+
# during a capistrano deployment.
|
3
|
+
# please do not edit this file if it is in the config directory.
|
4
|
+
# instead edit the file application/lib/templates/version.yml.erb
|
5
|
+
|
6
|
+
major: 1
|
7
|
+
minor: 0
|
8
|
+
# patch: 1
|
9
|
+
# milestone: 4
|
10
|
+
build: <%= `git rev-list HEAD|wc -l`.strip %>
|
11
|
+
<%#branch: <%# branch %>
|
12
|
+
committer: <%= `git show -s --pretty=format:"%an"` %>
|
13
|
+
build_date: <%= Date.today.to_s %>
|
14
|
+
|
15
|
+
<%# nifty tricks (note these examples are commented out in erb syntax, to use them replace the # with =) -%>
|
16
|
+
<%# `git rev-list HEAD|wc -l`.strip => will insert the count of commits to the repository (git) -%>
|
17
|
+
<%# `git show -s --pretty=format:"%an"` => will insert the name of the author of the last commit (git) -%>
|
18
|
+
<%# many more options are available - see git show. -%>
|
19
|
+
<%# Date.today.to_s => will insert today's date - formatted yyyy-mm-dd -%>
|
20
|
+
<%# branch => will insert the branch variable used in capistrano -%>
|
data/lib/install.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# copy the version.yml.erb to some user editable location for example, in lib
|
2
|
+
|
3
|
+
targetTemplateDir = File.join(Rails.root.to_s, 'lib/templates')
|
4
|
+
sourceTemplateFile = File.join(File.dirname(__FILE__), 'lib/templates/version.yml.erb')
|
5
|
+
|
6
|
+
sourceSampleFile = File.join(File.dirname(__FILE__), 'lib/templates/version.yml')
|
7
|
+
targetSampleDir = File.join(Rails.root.to_s, '/config')
|
8
|
+
|
9
|
+
FileUtils.mkdir( targetTemplateDir, :verbose => true) unless File.exists?(targetTemplateDir)
|
10
|
+
FileUtils.cp( sourceTemplateFile, targetTemplateDir,:verbose => true)
|
11
|
+
FileUtils.cp( sourceSampleFile, targetSampleDir, :verbose => true )
|
12
|
+
|
13
|
+
# Show the README text file
|
14
|
+
# puts IO.read(File.join(File.dirname(__FILE__), 'README'))
|
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :app do
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
desc 'Report the application version.'
|
5
|
+
task :version do
|
6
|
+
require File.join(File.dirname(__FILE__), "../app_version.rb")
|
7
|
+
puts "Application version: " << App::Version.load("#{Rails.root.to_s}/config/version.yml").to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Configure for initial install.'
|
11
|
+
task :install do
|
12
|
+
require File.join(File.dirname(__FILE__), "../../install.rb")
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Clean up prior to removal.'
|
16
|
+
task :uninstall do
|
17
|
+
require File.join(File.dirname(__FILE__), "../../uninstall.rb")
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Render the version.yml from its template.'
|
21
|
+
task :render do
|
22
|
+
template = File.read(Rails.root.to_s+ "/lib/templates/version.yml.erb")
|
23
|
+
result = ERB.new(template).result(binding)
|
24
|
+
File.open(Rails.root.to_s+ "/config/version.yml", 'w') { |f| f.write(result)}
|
25
|
+
end
|
26
|
+
end
|
data/lib/uninstall.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
targetTemplateDir = File.join(RAILS_ROOT, 'lib/templates')
|
2
|
+
|
3
|
+
targetTemplateFile = File.join(RAILS_ROOT, 'lib/templates/version.yml.erb')
|
4
|
+
targetConfigSampleFile = File.join(RAILS_ROOT, '/config/version.yml')
|
5
|
+
targetTemplateSampleFile = File.join(RAILS_ROOT, 'lib/templates/version.yml')
|
6
|
+
|
7
|
+
if File.exist?(targetTemplateFile) then FileUtils.rm( targetTemplateFile, :verbose => true) end
|
8
|
+
if File.exist?(targetConfigSampleFile) then FileUtils.rm( targetConfigSampleFile, :verbose => true) end
|
9
|
+
if File.exist?(targetTemplateSampleFile) then FileUtils.rm( targetTemplateSampleFile, :verbose => true) end
|
10
|
+
|
11
|
+
if Dir.entries( targetTemplateDir ).entries.length == 2 then FileUtils.rmdir( targetTemplateDir, :verbose => true ) end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'active_support'
|
3
|
+
require 'app_version'
|
4
|
+
|
5
|
+
class AppVersionTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@version = App::Version.new
|
9
|
+
@version.major = '1'
|
10
|
+
@version.minor = '2'
|
11
|
+
@version.patch = '3'
|
12
|
+
@version.milestone = '4'
|
13
|
+
@version.build = '500'
|
14
|
+
@version.branch = 'master'
|
15
|
+
@version.committer = 'coder'
|
16
|
+
@version.build_date = Date.civil(2008, 10, 27)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_load_from_file
|
20
|
+
version = App::Version.load 'test/version.yml'
|
21
|
+
assert_equal @version, version
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_create_from_string
|
25
|
+
version = App::Version.parse '1.2.3 M4 (500) of master by coder on 2008-10-27'
|
26
|
+
assert_equal @version, version
|
27
|
+
|
28
|
+
version = App::Version.parse '1.2.3 M4 (500)'
|
29
|
+
@version.branch = nil
|
30
|
+
@version.committer = nil
|
31
|
+
@version.build_date = nil
|
32
|
+
assert_equal @version, version
|
33
|
+
|
34
|
+
version = App::Version.parse '1.2.3 (500)'
|
35
|
+
@version.milestone = nil
|
36
|
+
@version.branch = nil
|
37
|
+
@version.committer = nil
|
38
|
+
@version.build_date = nil
|
39
|
+
assert_equal @version, version
|
40
|
+
|
41
|
+
version = App::Version.parse '1.2 (500)'
|
42
|
+
@version.patch = nil
|
43
|
+
@version.branch = nil
|
44
|
+
@version.committer = nil
|
45
|
+
@version.build_date = nil
|
46
|
+
assert_equal @version, version
|
47
|
+
|
48
|
+
version = App::Version.parse '1.2'
|
49
|
+
@version.milestone = nil
|
50
|
+
@version.build = nil
|
51
|
+
@version.branch = nil
|
52
|
+
@version.committer = nil
|
53
|
+
@version.build_date = nil
|
54
|
+
assert_equal @version, version
|
55
|
+
|
56
|
+
version = App::Version.parse '1.2.1'
|
57
|
+
@version.patch = 1
|
58
|
+
@version.branch = nil
|
59
|
+
@version.committer = nil
|
60
|
+
@version.build_date = nil
|
61
|
+
assert_equal @version, version
|
62
|
+
|
63
|
+
version = App::Version.parse '2007.200.10 M9 (6) of branch by coder on 2008-10-27'
|
64
|
+
@version.major = 2007
|
65
|
+
@version.minor = 200
|
66
|
+
@version.patch = 10
|
67
|
+
@version.milestone = 9
|
68
|
+
@version.build = 6
|
69
|
+
@version.branch = 'branch'
|
70
|
+
@version.committer = 'coder'
|
71
|
+
@version.build_date = Date.civil(2008, 10, 31)
|
72
|
+
assert_raises(ArgumentError) { App::Version.parse 'This is not a valid version' }
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_create_from_int_hash_with_symbol_keys
|
76
|
+
version = App::Version.new :major => 1,
|
77
|
+
:minor => 2,
|
78
|
+
:patch => 3,
|
79
|
+
:milestone => 4,
|
80
|
+
:build => 500,
|
81
|
+
:branch => 'master',
|
82
|
+
:committer => 'coder',
|
83
|
+
:build_date => Date.civil(2008, 10, 27)
|
84
|
+
assert_equal @version, version
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_create_from_int_hash_with_string_keys
|
88
|
+
version = App::Version.new 'major' => 1,
|
89
|
+
'minor' => 2,
|
90
|
+
'patch' => 3,
|
91
|
+
'milestone' => 4,
|
92
|
+
'build' => 500,
|
93
|
+
'branch' => 'master',
|
94
|
+
'committer' => 'coder',
|
95
|
+
'build_date' => '2008-10-27'
|
96
|
+
assert_equal @version, version
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_create_from_string_hash_with_symbol_keys
|
100
|
+
version = App::Version.new :major => '1',
|
101
|
+
:minor => '2',
|
102
|
+
:patch => '3',
|
103
|
+
:milestone => '4',
|
104
|
+
:build => '500',
|
105
|
+
:branch => 'master',
|
106
|
+
:committer => 'coder',
|
107
|
+
:build_date => '2008-10-27'
|
108
|
+
assert_equal @version, version
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_create_from_string_hash_with_string_keys
|
112
|
+
version = App::Version.new 'major' => '1',
|
113
|
+
'minor' => '2',
|
114
|
+
'patch' => '3',
|
115
|
+
'milestone' => '4',
|
116
|
+
'build' => '500',
|
117
|
+
'branch' => 'master',
|
118
|
+
'committer' => 'coder',
|
119
|
+
'build_date' => '2008-10-27'
|
120
|
+
assert_equal @version, version
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_create_from_hash_with_invalid_date
|
124
|
+
# note - Date.parse will make heroic efforts to understand the date text.
|
125
|
+
version = App::Version.new :major => '1',
|
126
|
+
:minor => '2',
|
127
|
+
:patch => '3',
|
128
|
+
:milestone => '4',
|
129
|
+
:build => '500',
|
130
|
+
:branch => 'master',
|
131
|
+
:committer => 'coder',
|
132
|
+
:build_date => '12wtf34'
|
133
|
+
assert_not_equal @version, version
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_should_raise_when_major_is_missing
|
137
|
+
assert_raises(ArgumentError) {
|
138
|
+
App::Version.new :minor => 2, :milestone => 3, :build => 400
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_should_raise_when_minor_is_missing
|
143
|
+
assert_raises(ArgumentError) {
|
144
|
+
App::Version.new :major => 1, :milestone => 3, :build => 400
|
145
|
+
}
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_create_without_optional_parameters
|
149
|
+
version = App::Version.new :major => 1, :minor => 2
|
150
|
+
|
151
|
+
@version.patch = nil
|
152
|
+
@version.milestone = nil
|
153
|
+
@version.build = nil
|
154
|
+
@version.branch = nil
|
155
|
+
@version.committer = nil
|
156
|
+
@version.build_date = nil
|
157
|
+
assert_equal @version, version
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_create_with_0
|
161
|
+
version = App::Version.new :major => 1,
|
162
|
+
:minor => 2,
|
163
|
+
:patch => 0,
|
164
|
+
:milestone => 0,
|
165
|
+
:build => 100
|
166
|
+
|
167
|
+
assert_equal '0', version.patch
|
168
|
+
assert_equal '0', version.milestone
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_create_with_nil
|
172
|
+
version = App::Version.new :major => 1,
|
173
|
+
:minor => 2,
|
174
|
+
:patch => nil,
|
175
|
+
:milestone => nil,
|
176
|
+
:build => 100,
|
177
|
+
:branch => nil,
|
178
|
+
:committer => nil,
|
179
|
+
:build_date => nil
|
180
|
+
|
181
|
+
assert_equal nil, version.patch
|
182
|
+
assert_equal nil, version.milestone
|
183
|
+
assert_equal nil, version.branch
|
184
|
+
assert_equal nil, version.committer
|
185
|
+
assert_equal nil, version.build_date
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_create_with_empty_string
|
189
|
+
version = App::Version.new :major => 1,
|
190
|
+
:minor => 2,
|
191
|
+
:patch => '',
|
192
|
+
:milestone => '',
|
193
|
+
:build => 100,
|
194
|
+
:branch => '',
|
195
|
+
:committer => '',
|
196
|
+
:build_date => ''
|
197
|
+
|
198
|
+
assert_equal nil, version.patch
|
199
|
+
assert_equal nil, version.milestone
|
200
|
+
assert_equal nil, version.branch
|
201
|
+
assert_equal nil, version.committer
|
202
|
+
assert_equal nil, version.build_date
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_to_s
|
206
|
+
assert_equal '1.2.3 M4 (500) of master by coder on 2008-10-27', @version.to_s
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_to_s_with_no_milestone
|
210
|
+
@version.milestone = nil
|
211
|
+
assert_equal '1.2.3 (500) of master by coder on 2008-10-27', @version.to_s
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_to_s_with_no_build
|
215
|
+
@version.build = nil
|
216
|
+
assert_equal '1.2.3 M4 of master by coder on 2008-10-27', @version.to_s
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_to_s_with_no_patch
|
220
|
+
@version.patch = nil
|
221
|
+
assert_equal '1.2 M4 (500) of master by coder on 2008-10-27', @version.to_s
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_to_s_with_no_build_or_milestone
|
225
|
+
@version.milestone = nil
|
226
|
+
@version.build = nil
|
227
|
+
assert_equal '1.2.3 of master by coder on 2008-10-27', @version.to_s
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_to_s_with_no_branch
|
231
|
+
@version.branch = nil
|
232
|
+
assert_equal '1.2.3 M4 (500) by coder on 2008-10-27', @version.to_s
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_to_s_with_no_committer
|
236
|
+
@version.committer = nil
|
237
|
+
assert_equal '1.2.3 M4 (500) of master on 2008-10-27', @version.to_s
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_to_s_with_no_build_date
|
241
|
+
@version.build_date = nil
|
242
|
+
assert_equal '1.2.3 M4 (500) of master by coder', @version.to_s
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_to_s_with_no_branch_or_committer
|
246
|
+
@version.branch = nil
|
247
|
+
@version.committer = nil
|
248
|
+
assert_equal '1.2.3 M4 (500) on 2008-10-27', @version.to_s
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_to_s_with_no_committer_or_build_date
|
252
|
+
@version.committer = nil
|
253
|
+
@version.build_date = nil
|
254
|
+
assert_equal '1.2.3 M4 (500) of master', @version.to_s
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_to_s_with_no_build_date_or_committer_or_build_date
|
258
|
+
@version.branch = nil
|
259
|
+
@version.committer = nil
|
260
|
+
@version.build_date = nil
|
261
|
+
assert_equal '1.2.3 M4 (500)', @version.to_s
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_version_with_leading_zeros
|
265
|
+
version = App::Version.new :major => '2010', :minor => '04'
|
266
|
+
assert_equal '04', version.minor
|
267
|
+
assert_equal '2010.04', version.to_s
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_version_with_alpha_characters
|
271
|
+
version = App::Version.new :major => '2010', :minor => '4a'
|
272
|
+
assert_equal '4a', version.minor
|
273
|
+
assert_equal '2010.4a', version.to_s
|
274
|
+
end
|
275
|
+
end
|
data/test/version.yml
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: app_version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Stephen Kapp
|
9
|
+
- Phillip Toland
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-06-22 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.2.8
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 3.2.8
|
31
|
+
description: App Version Gem originally App Version Rails Plugin from https://github.com/toland/app_version
|
32
|
+
email:
|
33
|
+
- mort666@virus.org
|
34
|
+
- phil.toland@gmail.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- lib/app_version/app_version.rb
|
40
|
+
- lib/app_version/railtie.rb
|
41
|
+
- lib/app_version/templates/version.yml
|
42
|
+
- lib/app_version/templates/version.yml.erb
|
43
|
+
- lib/app_version.rb
|
44
|
+
- lib/install.rb
|
45
|
+
- lib/tasks/app_version_tasks.rake
|
46
|
+
- lib/uninstall.rb
|
47
|
+
- Rakefile
|
48
|
+
- README.rdoc
|
49
|
+
- test/app_version_test.rb
|
50
|
+
- test/version.yml
|
51
|
+
homepage: ''
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.25
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: APP Version Gem
|
75
|
+
test_files:
|
76
|
+
- test/app_version_test.rb
|
77
|
+
- test/version.yml
|