Skip to content

Instantly share code, notes, and snippets.

@kaipr
Created January 13, 2011 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaipr/778369 to your computer and use it in GitHub Desktop.
Save kaipr/778369 to your computer and use it in GitHub Desktop.
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index b6f0511..5223ac5 100644
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -842,8 +842,8 @@ module ActiveRecord
def fixtures(*table_names)
if table_names.first == :all
- table_names = Dir["#{fixture_path}/**/*.{yml,csv}"]
- table_names.map! { |f| f[(fixture_path.size + 1)..-5] }
+ table_names = Dir[File.join(fixture_path, '**', '*.{yml,csv}']
+ table_names.map! { |f| f.match(/.{#{fixture_path.size}}\/?(.*)\.(yml|csv)/)[1] }
else
table_names = table_names.flatten.map { |n| n.to_s }
end
# This behaves as it should (as MRI does)
rbx-head :001 > Dir["testapp/test//fixtures/**/*.{yml,csv}"]
=> ["testapp/test//fixtures/bar.yml", "testapp/test//fixtures/foo.yml"]
# //** is a problem in current rubinius
rbx-head :002 > Dir["testapp/test/fixtures//**/*.{yml,csv}"]
=> ["testapp/test/fixtures/bar.yml", "testapp/test/fixtures/foo.yml"]
# Current implementation
table_names = Dir["#{fixture_path}/**/*.{yml,csv}"]
table_names.map! { |f| f[(fixture_path.size + 1)..-5] }
# First suggested implementation (needs a trailing slash on fixture_path)
table_names = Dir[File.join(fixture_path, '**', '*.{yml,csv}']
table_names.map! { |f| f[(fixture_path.size)..-5] }
# Second suggested implementation (kinda clumsy, but works)
table_names = Dir[File.join(fixture_path, '**', '*.{yml,csv}']
table_names.map! { |f| f.match(/.{#{fixture_path.size}}\/?(.*)\.(yml|csv)/)[1] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment