mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixtures: removed support for the ancient pre-YAML file format. Closes #10736.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8594 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
ce84cebc0e
commit
8f7fa55e8d
14 changed files with 12 additions and 75 deletions
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Fixtures: removed support for the ancient pre-YAML file format. #10736 [John Barnette]
|
||||||
|
|
||||||
* More thoroughly quote table names. #10698 [dimdenis, lotswholetime, Jeremy Kemper]
|
* More thoroughly quote table names. #10698 [dimdenis, lotswholetime, Jeremy Kemper]
|
||||||
|
|
||||||
* update_all ignores scoped :order and :limit, so post.comments.update_all doesn't try to include the comment order in the update statement. #10686 [Brendan Ribera]
|
* update_all ignores scoped :order and :limit, so post.comments.update_all doesn't try to include the comment order in the update statement. #10686 [Brendan Ribera]
|
||||||
|
@ -80,7 +82,7 @@ so newlines etc are escaped #10385 [Norbert Crombach]
|
||||||
|
|
||||||
* Dynamic finders on association collections respect association :order and :limit. #10211, #10227 [Patrick Joyce, Rick Olson, Jack Danger Canty]
|
* Dynamic finders on association collections respect association :order and :limit. #10211, #10227 [Patrick Joyce, Rick Olson, Jack Danger Canty]
|
||||||
|
|
||||||
* Add 'foxy' support for fixtures of polymorphic associations. #10183 [jbarnette, David Lowenfels]
|
* Add 'foxy' support for fixtures of polymorphic associations. #10183 [John Barnette, David Lowenfels]
|
||||||
|
|
||||||
* validates_inclusion_of and validates_exclusion_of allow formatted :message strings. #8132 [devrieda, Mike Naberezny]
|
* validates_inclusion_of and validates_exclusion_of allow formatted :message strings. #8132 [devrieda, Mike Naberezny]
|
||||||
|
|
||||||
|
@ -128,7 +130,7 @@ so newlines etc are escaped #10385 [Norbert Crombach]
|
||||||
- autofill timestamp columns
|
- autofill timestamp columns
|
||||||
- support YAML defaults
|
- support YAML defaults
|
||||||
- fixture label interpolation
|
- fixture label interpolation
|
||||||
Enabled for fixtures that correspond to a model class and don't specify a primary key value. #9981 [jbarnette]
|
Enabled for fixtures that correspond to a model class and don't specify a primary key value. #9981 [John Barnette]
|
||||||
|
|
||||||
* Add docs explaining how to protect all attributes using attr_accessible with no arguments. Closes #9631 [boone, rmm5t]
|
* Add docs explaining how to protect all attributes using attr_accessible with no arguments. Closes #9631 [boone, rmm5t]
|
||||||
|
|
||||||
|
|
|
@ -687,14 +687,6 @@ class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash)
|
||||||
read_yaml_fixture_files
|
read_yaml_fixture_files
|
||||||
elsif File.file?(csv_file_path)
|
elsif File.file?(csv_file_path)
|
||||||
read_csv_fixture_files
|
read_csv_fixture_files
|
||||||
else
|
|
||||||
# Standard fixtures
|
|
||||||
Dir.entries(@fixture_path).each do |file|
|
|
||||||
path = File.join(@fixture_path, file)
|
|
||||||
if File.file?(path) and file !~ @file_filter
|
|
||||||
self[file] = Fixture.new(path, model_class)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -773,15 +765,7 @@ class Fixture #:nodoc:
|
||||||
attr_reader :model_class
|
attr_reader :model_class
|
||||||
|
|
||||||
def initialize(fixture, model_class)
|
def initialize(fixture, model_class)
|
||||||
case fixture
|
|
||||||
when Hash, YAML::Omap
|
|
||||||
@fixture = fixture
|
@fixture = fixture
|
||||||
when String
|
|
||||||
@fixture = read_fixture_file(fixture)
|
|
||||||
else
|
|
||||||
raise ArgumentError, "Bad fixture argument #{fixture.inspect} during creation of #{class_name} fixture"
|
|
||||||
end
|
|
||||||
|
|
||||||
@model_class = model_class.is_a?(Class) ? model_class : model_class.constantize rescue nil
|
@model_class = model_class.is_a?(Class) ? model_class : model_class.constantize rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -821,25 +805,6 @@ class Fixture #:nodoc:
|
||||||
raise FixtureClassNotFound, "No class attached to find."
|
raise FixtureClassNotFound, "No class attached to find."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
def read_fixture_file(fixture_file_path)
|
|
||||||
IO.readlines(fixture_file_path).inject({}) do |fixture, line|
|
|
||||||
# Mercifully skip empty lines.
|
|
||||||
next if line =~ /^\s*$/
|
|
||||||
|
|
||||||
# Use the same regular expression for attributes as Active Record.
|
|
||||||
unless md = /^\s*([a-zA-Z][-_\w]*)\s*=>\s*(.+)\s*$/.match(line)
|
|
||||||
raise FormatError, "#{fixture_file_path}: fixture format error at '#{line}'. Expecting 'key => value'."
|
|
||||||
end
|
|
||||||
key, value = md.captures
|
|
||||||
|
|
||||||
# Disallow duplicate keys to catch typos.
|
|
||||||
raise FormatError, "#{fixture_file_path}: duplicate '#{key}' in fixture." if fixture[key]
|
|
||||||
fixture[key] = value.strip
|
|
||||||
fixture
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Test #:nodoc:
|
module Test #:nodoc:
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
1b => 1
|
|
|
@ -1 +0,0 @@
|
||||||
a b => 1
|
|
|
@ -1,3 +0,0 @@
|
||||||
a => 1
|
|
||||||
|
|
||||||
b => 2
|
|
|
@ -1,3 +0,0 @@
|
||||||
a => 1
|
|
||||||
b => 2
|
|
||||||
a => 3
|
|
|
@ -1 +0,0 @@
|
||||||
a =>
|
|
|
@ -1,3 +0,0 @@
|
||||||
developer_id => 1
|
|
||||||
project_id => 2
|
|
||||||
joined_on => 2004-10-10
|
|
|
@ -1,3 +0,0 @@
|
||||||
developer_id => 1
|
|
||||||
project_id => 1
|
|
||||||
joined_on => 2004-10-10
|
|
|
@ -1,2 +0,0 @@
|
||||||
developer_id => 2
|
|
||||||
project_id => 1
|
|
7
activerecord/test/fixtures/subscribers.yml
vendored
Normal file
7
activerecord/test/fixtures/subscribers.yml
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
first:
|
||||||
|
nick: alterself
|
||||||
|
name: Luke Holden
|
||||||
|
|
||||||
|
second:
|
||||||
|
nick: webster132
|
||||||
|
name: David Heinemeier Hansson
|
2
activerecord/test/fixtures/subscribers/first
vendored
2
activerecord/test/fixtures/subscribers/first
vendored
|
@ -1,2 +0,0 @@
|
||||||
nick => alterself
|
|
||||||
name => Luke Holden
|
|
|
@ -1,2 +0,0 @@
|
||||||
nick => webster132
|
|
||||||
name => David Heinemeier Hansson
|
|
|
@ -113,22 +113,6 @@ class FixturesTest < ActiveSupport::TestCase
|
||||||
assert first
|
assert first
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_bad_format
|
|
||||||
path = File.join(File.dirname(__FILE__), 'fixtures', 'bad_fixtures')
|
|
||||||
Dir.entries(path).each do |file|
|
|
||||||
next unless File.file?(file) and file !~ Fixtures::DEFAULT_FILTER_RE
|
|
||||||
assert_raise(Fixture::FormatError) {
|
|
||||||
Fixture.new(bad_fixtures_path, file)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_deprecated_yaml_extension
|
|
||||||
assert_raise(Fixture::FormatError) {
|
|
||||||
Fixtures.new(nil, 'bad_extension', 'BadExtension', File.join(File.dirname(__FILE__), 'fixtures'))
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_logger_level_invariant
|
def test_logger_level_invariant
|
||||||
level = ActiveRecord::Base.logger.level
|
level = ActiveRecord::Base.logger.level
|
||||||
create_fixtures('topics')
|
create_fixtures('topics')
|
||||||
|
|
Loading…
Reference in a new issue