Skip to content

Commit

Permalink
have Data1Authority rely on Earth.resources
Browse files Browse the repository at this point in the history
  • Loading branch information
seamusabshere committed Jul 7, 2011
1 parent f1c379f commit c6774a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/brighter_planet_metadata/data1_authority.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def authority?(method_id)
respond_to? method_id
end
def resources
::Dir[::File.expand_path(::File.join(::File.dirname($LOAD_PATH.grep(%r{earth}).sort_by { |path| path.length }.first), 'lib', 'earth', '**', '*.rb'))].select { |f| ::File.read(f) =~ /class [\:A-Za-z0-9]+ < ActiveRecord::Base/ }.map { |path| ::File.basename(path, '.rb').camelcase }.sort
::Earth.resources.sort
end
def datasets
::Dir[::File.expand_path(::File.join(::Rails.root, 'app', 'models', '**', '*.rb'))].select { |f| ::File.read(f) =~ /class [\:A-Za-z0-9]+ < Dataset/ }.map { |path| ::File.basename(path, '.rb').camelcase }.sort
Expand Down
32 changes: 19 additions & 13 deletions test/test_live_data1.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
require 'helper'
require 'earth'

class FakeEarth
def self.resources
[ 'LiveData1Resource' ]
end
end

class TestLiveData1 < Test::Unit::TestCase
def setup
super
# get the real gem path so we can fake it in fakefs (/usr/local/rvm/gems/ruby-1.8.7-head/gems/earth-0.3.11/lib/earth)
earth_gem_path = ::File.dirname($LOAD_PATH.grep(/earth/)[0])

FakeFS.activate!
FileUtils.mkdir_p earth_gem_path

# FAKING RESOURCES
# fake earth.rb so that Gem.required_path can find it
File.open(File.join(earth_gem_path, 'lib', 'earth.rb'), 'w') { |f| f.write "module Earth; end" }

# fake what looks like a resource
fake_resource_path = File.join earth_gem_path, 'lib', 'earth', 'live_data1_resource.rb'
File.open(fake_resource_path, 'w') { |f| f.write "class ::LiveData1Resource < ActiveRecord::Base; end"}
eval File.read(fake_resource_path) unless defined?(::LiveData1Resource)

# faking resources
eval %{
::OldEarth = ::Earth
::Earth = ::FakeEarth
}

# faking deploy
Rails.env = ActiveSupport::StringInquirer.new 'production'
Rails.root = '/var/www/data1/current'
Expand All @@ -32,6 +31,13 @@ def setup
File.open(fake_dataset_path, 'w') { |f| f.write "class ::LiveData1Dataset < Dataset; end"}
eval File.read(fake_dataset_path) unless defined?(::LiveData1Dataset)
end

def teardown
super
eval %{
::Earth = ::OldEarth
}
end

def test_self_awareness
assert ::Rails.env.production?
Expand Down

0 comments on commit c6774a9

Please sign in to comment.