Skip to content

Commit

Permalink
Rails Edge info returns the latest git commit hash [#36 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
fesplugas authored and josh committed Apr 22, 2008
1 parent a4fc93c commit bf1b1e0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 43 deletions.
2 changes: 2 additions & 0 deletions railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN* *SVN*


* Rails Edge info returns the latest git commit hash [Francesc Esplugas]

* Added Rails.public_path to control where HTML and assets are expected to be loaded from (defaults to Rails.root + "/public") #11581 [nicksieger] * Added Rails.public_path to control where HTML and assets are expected to be loaded from (defaults to Rails.root + "/public") #11581 [nicksieger]


* rake time:zones:local finds correct base utc offset for zones in the Southern Hemisphere [Geoff Buesing] * rake time:zones:local finds correct base utc offset for zones in the Southern Hemisphere [Geoff Buesing]
Expand Down
10 changes: 5 additions & 5 deletions railties/builtin/rails_info/rails/info.rb
Expand Up @@ -29,8 +29,8 @@ def component_version(component)
"#{component.classify}::VERSION::STRING".constantize "#{component.classify}::VERSION::STRING".constantize
end end


def edge_rails_revision(info = svn_info) def edge_rails_revision(info = git_info)
info[/^Revision: (\d+)/, 1] || freeze_edge_version info[/commit ([a-z0-9-]+)/, 1] || freeze_edge_version
end end


def freeze_edge_version def freeze_edge_version
Expand Down Expand Up @@ -67,10 +67,10 @@ def rails_vendor_root
@rails_vendor_root ||= "#{RAILS_ROOT}/vendor/rails" @rails_vendor_root ||= "#{RAILS_ROOT}/vendor/rails"
end end


def svn_info def git_info
env_lang, ENV['LC_ALL'] = ENV['LC_ALL'], 'C' env_lang, ENV['LC_ALL'] = ENV['LC_ALL'], 'C'
Dir.chdir(rails_vendor_root) do Dir.chdir(rails_vendor_root) do
silence_stderr { `svn info` } silence_stderr { `git log -n 1` }
end end
ensure ensure
ENV['LC_ALL'] = env_lang ENV['LC_ALL'] = env_lang
Expand Down Expand Up @@ -98,7 +98,7 @@ def svn_info
end end
end end


# The Rails SVN revision, if it's checked out into vendor/rails. # The Rails Git revision, if it's checked out into vendor/rails.
property 'Edge Rails revision' do property 'Edge Rails revision' do
edge_rails_revision edge_rails_revision
end end
Expand Down
70 changes: 32 additions & 38 deletions railties/test/rails_info_test.rb
Expand Up @@ -23,27 +23,21 @@ def test_edge_rails_revision_not_set_when_svn_info_is_empty
end end
assert !property_defined?('Test that this will not be defined') assert !property_defined?('Test that this will not be defined')
end end

def test_edge_rails_revision_extracted_from_svn_info def test_edge_rails_revision_extracted_from_svn_info
Rails::Info.property 'Test Edge Rails revision' do Rails::Info.property 'Test Edge Rails revision' do
Rails::Info.edge_rails_revision <<-EOS Rails::Info.edge_rails_revision <<-EOS
Path: . commit 420c4b3d8878156d04f45e47050ddc62ae00c68c
URL: http://www.rubyonrails.com/svn/rails/trunk Author: David Heinemeier Hansson <david@loudthinking.com>
Repository UUID: 5ecf4fe2-1ee6-0310-87b1-e25e094e27de Date: Sun Apr 13 17:33:27 2008 -0500
Revision: 2881
Node Kind: directory
Schedule: normal
Last Changed Author: sam
Last Changed Rev: 2881
Last Changed Date: 2005-11-04 21:04:41 -0600 (Fri, 04 Nov 2005)
Properties Last Updated: 2005-10-28 19:30:00 -0500 (Fri, 28 Oct 2005)
Added Rails.public_path to control where HTML and assets are expected to be loaded from
EOS EOS
end end

assert_property 'Test Edge Rails revision', '2881' assert_property 'Test Edge Rails revision', '420c4b3d8878156d04f45e47050ddc62ae00c68c'
end end

def test_property_with_block_swallows_exceptions_and_ignores_property def test_property_with_block_swallows_exceptions_and_ignores_property
assert_nothing_raised do assert_nothing_raised do
Rails::Info.module_eval do Rails::Info.module_eval do
Expand All @@ -52,54 +46,54 @@ def test_property_with_block_swallows_exceptions_and_ignores_property
end end
assert !property_defined?('Bogus') assert !property_defined?('Bogus')
end end

def test_property_with_string def test_property_with_string
Rails::Info.module_eval do Rails::Info.module_eval do
property 'Hello', 'World' property 'Hello', 'World'
end end
assert_property 'Hello', 'World' assert_property 'Hello', 'World'
end end

def test_property_with_block def test_property_with_block
Rails::Info.module_eval do Rails::Info.module_eval do
property('Goodbye') {'World'} property('Goodbye') {'World'}
end end
assert_property 'Goodbye', 'World' assert_property 'Goodbye', 'World'
end end

def test_component_version def test_component_version
assert_property 'Active Support version', ActiveSupport::VERSION::STRING assert_property 'Active Support version', ActiveSupport::VERSION::STRING
end end

def test_components_exist def test_components_exist
Rails::Info.components.each do |component| Rails::Info.components.each do |component|
dir = File.dirname(__FILE__) + "/../../" + component.gsub('_', '') dir = File.dirname(__FILE__) + "/../../" + component.gsub('_', '')
assert File.directory?(dir), "#{component.classify} does not exist" assert File.directory?(dir), "#{component.classify} does not exist"
end end
end end


protected protected
def svn_info=(info) def svn_info=(info)
Rails::Info.module_eval do Rails::Info.module_eval do
class << self class << self
def svn_info def svn_info
info info
end
end end
end end
end end
end

def properties
Rails::Info.properties
end


def property_defined?(property_name) def properties
properties.names.include? property_name Rails::Info.properties
end end


def assert_property(property_name, value) def property_defined?(property_name)
raise "Property #{property_name.inspect} not defined" unless properties.names.include? property_name
property_defined? property_name end
assert_equal value, properties.value_for(property_name)
end def assert_property(property_name, value)
raise "Property #{property_name.inspect} not defined" unless
property_defined? property_name
assert_equal value, properties.value_for(property_name)
end
end end

0 comments on commit bf1b1e0

Please sign in to comment.