#306: added specs, updated regexp

This commit is contained in:
Vokhmin Alexey V 2013-09-19 16:07:49 +04:00
parent 32e3c1514f
commit a58b69c75a
2 changed files with 50 additions and 10 deletions

View File

@ -251,6 +251,33 @@ class Project < ActiveRecord::Base
@archive ||= create_archive treeish, format
end
# Finds release tag and increase its:
# 'Release: %mkrel 4mdk' => 'Release: 5mdk'
# 'Release: 4' => 'Release: 5'
# Finds release macros and increase it:
# '%define release %mkrel 4mdk' => '%define release 5mdk'
# '%define release 4' => '%define release 5'
def self.replace_release_tag(content)
build_new_release = Proc.new do |release, combine_release|
if combine_release.present?
r = combine_release.split('.').last.to_i
release << combine_release.gsub(/.[\d]+$/, '') << ".#{r + 1}"
else
release = release.to_i + 1
end
release
end
content.gsub(/^Release:(\s+)(%mkrel\s+)?(\d+)([.\d]+)?(mdk)?$/) do |line|
tab, mkrel, mdk = $1, $2, $5
"Release:#{tab}#{build_new_release.call($3, $4)}#{mdk}"
end.gsub(/^%define\s+release:?(\s+)(%mkrel\s+)?(\d+)([.\d]+)?(mdk)?$/) do |line|
tab, mkrel, mdk = $1, $2, $5
"%define release#{tab}#{build_new_release.call($3, $4)}#{mdk}"
end
end
protected
def increase_release_tag(project_version, user, message)
@ -258,16 +285,7 @@ class Project < ActiveRecord::Base
return unless blob
raw = Grit::GitRuby::Repository.new(repo.path).get_raw_object_by_sha1(blob.id)
content = raw.content.clone
# Finds release tag and increase its:
# 'Release: %mkrel 4mdk' => 'Release: 5mdk'
# 'Release: 4' => 'Release: 5'
content.gsub!(/^Release:(\s+)(%mkrel\s+)?(\d+)(mdk)?$/) { |line| "Release:#{$1}#{$3.to_i + 1}#{$4}" }
# Finds release macros and increase it:
# '%define release %mkrel 4mdk' => '%define release 5mdk'
# 'Release: 4' => 'Release: 5'
content.gsub!(/^%define\s+release:?(\s+)(%mkrel\s+)?(\d+)(mdk)?$/) { |line| "%define release #{$1}#{$3.to_i + 1}#{$4}" }
content = self.class.replace_release_tag raw.content
return if content == raw.content
update_file(blob.name, content.gsub("\r", ''),
@ -277,6 +295,7 @@ class Project < ActiveRecord::Base
)
end
def create_archive(treeish, format)
file_name = "#{name}-#{treeish}"
fullname = "#{file_name}.#{tag_file_format(format)}"

View File

@ -148,4 +148,25 @@ describe Project do
end
context '#replace_release_tag' do
[
['Release: %mkrel 4mdk', 'Release: 5mdk'],
['Release: 4', 'Release: 5'],
['Release: 4.1', 'Release: 4.2'],
['Release: 5.4.2', 'Release: 5.4.3'],
['Release: 5.4.2mdk', 'Release: 5.4.3mdk'],
['Release: %mkrel 5.4.31mdk', 'Release: 5.4.32mdk'],
['%define release %mkrel 4mdk', '%define release 5mdk'],
['%define release 4', '%define release 5'],
['%define release 4.1', '%define release 4.2'],
['%define release 5.4.2', '%define release 5.4.3'],
['%define release 5.4.31mdk', '%define release 5.4.32mdk']
].each do |items|
it "ensures that replace '#{items[0]}' => '#{items[1]}'" do
Project.replace_release_tag(items[0]).should == items[1]
end
end
end
end