Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rename TestFixtures' public methods

In ActiveRecord::TestFixtures module, rename the following methods:

`fixture_path`        -> `fixture_directory_path
`fixture_table_names` -> `fixture_set_names
(`fixture_table_names` can be used in some future version for something else, for example to return a hash of the form `{ "fixture_set/name" => :fixture_table_name, ... }`
`fixture_class_names` -> `fixture_model_names`
`set_fixture_class`   -> `set_fixture_model`

`fixture_path`, `fixture_table_names`, `fixture_class_names` are deprecated.

`set_fixture_class` is aliased without deprecation.
  • Loading branch information...
commit 7c8c08e353045dbab1be835abed9ae2d3e60ea20 1 parent 1ccc132
@alexeymuranov authored
View
4 actionpack/lib/action_dispatch/testing/test_process.rb
@@ -35,8 +35,8 @@ def redirect_to_url
#
# post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png', :binary)
def fixture_file_upload(path, mime_type = nil, binary = false)
- if self.class.respond_to?(:fixture_path) && self.class.fixture_path
- path = File.join(self.class.fixture_path, path)
+ if self.class.respond_to?(:fixture_directory_path) && self.class.fixture_directory_path
+ path = File.join(self.class.fixture_directory_path, path)
end
Rack::Test::UploadedFile.new(path, mime_type, binary)
end
View
4 actionpack/test/controller/integration_test.rb
@@ -190,7 +190,7 @@ def test_xml_http_request_override_accept
class IntegrationTestTest < ActiveSupport::TestCase
def setup
@test = ::ActionDispatch::IntegrationTest.new(:app)
- @test.class.stubs(:fixture_table_names).returns([])
+ @test.class.stubs(:fixture_set_names).returns([])
@session = @test.open_session
end
@@ -225,7 +225,7 @@ def method_missing(name, *args)
# Tests that integration tests don't call Controller test methods for processing.
# Integration tests have their own setup and teardown.
class IntegrationTestUsesCorrectClass < ActionDispatch::IntegrationTest
- def self.fixture_table_names
+ def self.fixture_set_names
[]
end
View
2  actionpack/test/controller/test_case_test.rb
@@ -793,7 +793,7 @@ def test_test_uploaded_file
end
def test_fixture_path_is_accessed_from_self_instead_of_active_support_test_case
- TestCaseTest.stubs(:fixture_path).returns(FILES_DIR)
+ TestCaseTest.stubs(:fixture_directory_path).returns(FILES_DIR)
uploaded_file = fixture_file_upload('/mona_lisa.jpg', 'image/png')
assert_equal File.open("#{FILES_DIR}/mona_lisa.jpg", READ_PLAIN).read, uploaded_file.read
View
2  actionview/test/active_record_unit.rb
@@ -75,7 +75,7 @@ class ActiveRecordTestCase < ActionController::TestCase
# Set our fixture path
if ActiveRecordTestConnector.able_to_connect
- self.fixture_path = [FIXTURE_LOAD_PATH]
+ self.fixture_directory_path = [FIXTURE_LOAD_PATH]
self.use_transactional_fixtures = false
end
View
13 activerecord/CHANGELOG.md
@@ -1,3 +1,16 @@
+* Rename public class methods in the module `ActiveRecord::TestFixtures`:
+
+ `fixture_path` -> `fixture_directory_path`
+ `fixture_table_names` -> `fixture_set_names`
+ `fixture_class_names` -> `fixture_model_names`
+ `set_fixture_class` -> `set_fixture_model`
+
+ `fixture_table_names` can be used for something different in the future,
+ something better corresponding to its name (maybe some hash with
+ database table names as values?).
+
+ *Alexey Muranov*
+
* Don't allow `quote_value` to be called without a column.
Some adapters require column information to do their job properly.
View
72 activerecord/lib/active_record/fixtures.rb
@@ -12,7 +12,7 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError #:nodoc:
# \Fixtures are a way of organizing data that you want to test against; in short, sample data.
#
# They are stored in YAML files, one file per model, which are placed in the directory
- # appointed by <tt>ActiveSupport::TestCase.fixture_path=(path)</tt> (this is automatically
+ # appointed by <tt>ActiveSupport::TestCase.fixture_directory_path=(path)</tt> (this is automatically
# configured for Rails, so you can just put your files in <tt><your-rails-app>/test/fixtures/</tt>).
# The fixture file ends with the <tt>.yml</tt> file extension (Rails example:
# <tt><your-rails-app>/test/fixtures/web_sites.yml</tt>). The format of a fixture file looks
@@ -713,21 +713,51 @@ def after_teardown
end
included do
- class_attribute :fixture_path, :instance_writer => false
- class_attribute :fixture_table_names
- class_attribute :fixture_class_names
+ class_attribute :fixture_directory_path, :instance_writer => false
+ class_attribute :fixture_set_names
+ # class_attribute :fixture_table_names # TODO:decide how to use this
+ class_attribute :fixture_model_names
class_attribute :use_transactional_fixtures
class_attribute :use_instantiated_fixtures # true, false, or :no_instances
class_attribute :pre_loaded_fixtures
- self.fixture_table_names = []
+ self.fixture_set_names = []
+ # self.fixture_table_names = {} # TODO:decide how to use this, it is currently used as a deprecated alias of `fixture_set_names`
self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
self.pre_loaded_fixtures = false
- self.fixture_class_names = Hash.new do |h, fixture_set_name|
+ self.fixture_model_names = Hash.new do |h, fixture_set_name|
h[fixture_set_name] = ActiveRecord::FixtureSet.default_fixture_model_name(fixture_set_name)
end
+
+ #--
+ # NOTE: this is a deprecation of 3 class attributes
+ #++
+ { :fixture_table_names => :fixture_set_names,
+ :fixture_path => :fixture_directory_path,
+ :fixture_class_names => :fixture_model_names
+ }.each_pair do |old_name, new_name|
+
+ deprecation_message =
+ "`#{ old_name }` class attribute is deprecated and shall be removed from future releases, use `#{ new_name }` instead."
+
+ { old_name => new_name,
+ :"#{ old_name }=" => :"#{ new_name }=",
+ :"#{ old_name }?" => :"#{ new_name }?"
+ }.each_pair do |old_method_name, new_method_name|
+
+ define_singleton_method old_method_name do |*args|
+ ActiveSupport::Deprecation.warn(deprecation_message)
+ public_send new_method_name, *args
+ end
+
+ define_method old_method_name do |*args|
+ ActiveSupport::Deprecation.warn(deprecation_message)
+ public_send new_method_name, *args
+ end
+ end
+ end
end
module ClassMethods
@@ -735,30 +765,40 @@ module ClassMethods
#
# Examples:
#
- # set_fixture_class some_fixture: SomeModel,
+ # set_fixture_model :some_fixture => SomeModel,
# 'namespaced/fixture' => Another::Model
#
# The keys must be the fixture names, that coincide with the short paths to the fixture files.
#--
# It is also possible to pass the class name instead of the class:
- # set_fixture_class 'some_fixture' => 'SomeModel'
+ # set_fixture_model 'some_fixture' => 'SomeModel'
# I think this option is redundant, i propose to deprecate it.
# Isn't it easier to always pass the class itself?
# (2011-12-20 alexeymuranov)
#++
- def set_fixture_class(class_names = {})
- self.fixture_class_names = self.fixture_class_names.merge(class_names.stringify_keys)
+ def set_fixture_model(class_names = {})
+ self.fixture_model_names = self.fixture_model_names.merge(class_names.stringify_keys)
end
+ #--
+ # NOTE: `set_fixture_class` method is to be deprecated
+ #++
+ alias_method :set_fixture_class, :set_fixture_model
+ # def set_fixture_class(*args) # :nodoc:
+ # ActiveSupport::Deprecation.warn(
+ # "`set_fixture_class` class method may be deprecated in a future release, please consider using `set_fixture_model` instead.")
+ # set_fixture_model(*args)
+ # end
+
def fixtures(*fixture_set_names)
if fixture_set_names.first == :all
- fixture_set_names = Dir["#{fixture_path}/**/*.{yml}"]
- fixture_set_names.map! { |f| f[(fixture_path.to_s.size + 1)..-5] }
+ fixture_set_names = Dir["#{fixture_directory_path}/**/*.{yml}"]
+ fixture_set_names.map! { |f| f[(fixture_directory_path.to_s.size + 1)..-5] }
else
fixture_set_names = fixture_set_names.flatten.map { |n| n.to_s }
end
- self.fixture_table_names |= fixture_set_names
+ self.fixture_set_names |= fixture_set_names
require_fixture_classes(fixture_set_names)
setup_fixture_accessors(fixture_set_names)
end
@@ -778,7 +818,7 @@ def require_fixture_classes(fixture_set_names = nil)
if fixture_set_names
fixture_set_names = fixture_set_names.map { |n| n.to_s }
else
- fixture_set_names = fixture_table_names
+ fixture_set_names = self.fixture_set_names
end
fixture_set_names.each do |file_name|
@@ -788,7 +828,7 @@ def require_fixture_classes(fixture_set_names = nil)
end
def setup_fixture_accessors(fixture_set_names = nil)
- fixture_set_names = Array(fixture_set_names || fixture_table_names)
+ fixture_set_names = Array(fixture_set_names || self.fixture_set_names)
methods = Module.new do
fixture_set_names.each do |fs_name|
fs_name = fs_name.to_s
@@ -886,7 +926,7 @@ def enlist_fixture_connections
private
def load_fixtures
- fixtures = ActiveRecord::FixtureSet.create_fixtures(fixture_path, fixture_table_names, fixture_class_names)
+ fixtures = ActiveRecord::FixtureSet.create_fixtures(fixture_directory_path, fixture_set_names, fixture_model_names)
Hash[fixtures.map { |f| [f.name, f] }]
end
View
32 activerecord/test/cases/fixtures_test.rb
@@ -380,7 +380,7 @@ class MultipleFixturesTest < ActiveRecord::TestCase
fixtures :developers, :accounts
def test_fixture_table_names
- assert_equal %w(topics developers accounts), fixture_table_names
+ assert_equal %w(topics developers accounts), fixture_set_names
end
end
@@ -413,7 +413,7 @@ class OverlappingFixturesTest < ActiveRecord::TestCase
fixtures :developers, :accounts
def test_fixture_table_names
- assert_equal %w(topics developers accounts), fixture_table_names
+ assert_equal %w(topics developers accounts), fixture_set_names
end
end
@@ -449,10 +449,10 @@ def test_fixture_methods_can_be_overridden
end
class CheckSetTableNameFixturesTest < ActiveRecord::TestCase
- set_fixture_class :funny_jokes => 'Joke'
+ set_fixture_model :funny_jokes => 'Joke'
fixtures :funny_jokes
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
- # and thus takes into account our set_fixture_class
+ # and thus takes into account our set_fixture_model
self.use_transactional_fixtures = false
def test_table_method
@@ -461,10 +461,10 @@ def test_table_method
end
class FixtureNameIsNotTableNameFixturesTest < ActiveRecord::TestCase
- set_fixture_class :items => Book
+ set_fixture_model :items => Book
fixtures :items
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
- # and thus takes into account our set_fixture_class
+ # and thus takes into account our set_fixture_model
self.use_transactional_fixtures = false
def test_named_accessor
@@ -473,10 +473,10 @@ def test_named_accessor
end
class FixtureNameIsNotTableNameMultipleFixturesTest < ActiveRecord::TestCase
- set_fixture_class :items => Book, :funny_jokes => Joke
+ set_fixture_model :items => Book, :funny_jokes => Joke
fixtures :items, :funny_jokes
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
- # and thus takes into account our set_fixture_class
+ # and thus takes into account our set_fixture_model
self.use_transactional_fixtures = false
def test_named_accessor_of_differently_named_fixture
@@ -489,7 +489,7 @@ def test_named_accessor_of_same_named_fixture
end
class CustomConnectionFixturesTest < ActiveRecord::TestCase
- set_fixture_class :courses => Course
+ set_fixture_model :courses => Course
fixtures :courses
self.use_transactional_fixtures = false
@@ -504,7 +504,7 @@ def test_it_twice_in_whatever_order_to_check_for_fixture_leakage
end
class TransactionalFixturesOnCustomConnectionTest < ActiveRecord::TestCase
- set_fixture_class :courses => Course
+ set_fixture_model :courses => Course
fixtures :courses
self.use_transactional_fixtures = true
@@ -521,7 +521,7 @@ def test_it_twice_in_whatever_order_to_check_for_fixture_leakage
class InvalidTableNameFixturesTest < ActiveRecord::TestCase
fixtures :funny_jokes
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
- # and thus takes into account our lack of set_fixture_class
+ # and thus takes into account our lack of set_fixture_model
self.use_transactional_fixtures = false
def test_raises_error
@@ -532,10 +532,10 @@ def test_raises_error
end
class CheckEscapedYamlFixturesTest < ActiveRecord::TestCase
- set_fixture_class :funny_jokes => 'Joke'
+ set_fixture_model :funny_jokes => 'Joke'
fixtures :funny_jokes
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
- # and thus takes into account our set_fixture_class
+ # and thus takes into account our set_fixture_model
self.use_transactional_fixtures = false
def test_proper_escaped_fixture
@@ -580,11 +580,11 @@ def load_fixtures
end
class LoadAllFixturesTest < ActiveRecord::TestCase
- self.fixture_path = FIXTURES_ROOT + "/all"
+ self.fixture_directory_path = FIXTURES_ROOT + "/all"
fixtures :all
def test_all_there
- assert_equal %w(developers people tasks), fixture_table_names.sort
+ assert_equal %w(developers people tasks), fixture_set_names.sort
end
end
@@ -779,7 +779,7 @@ def test_does_not_logs_message_for_successful_dependency_load
class CustomNameForFixtureOrModelTest < ActiveRecord::TestCase
ActiveRecord::FixtureSet.reset_cache
- set_fixture_class :randomly_named_a9 =>
+ set_fixture_model :randomly_named_a9 =>
ClassNameThatDoesNotFollowCONVENTIONS,
:'admin/randomly_named_a9' =>
Admin::ClassNameThatDoesNotFollowCONVENTIONS,
View
4 activerecord/test/cases/helper.rb
@@ -74,12 +74,12 @@ class ActiveSupport::TestCase
include ActiveRecord::TestFixtures
include ActiveRecord::ValidationsRepairHelper
- self.fixture_path = FIXTURES_ROOT
+ self.fixture_directory_path = FIXTURES_ROOT
self.use_instantiated_fixtures = false
self.use_transactional_fixtures = true
def create_fixtures(*fixture_set_names, &block)
- ActiveRecord::FixtureSet.create_fixtures(ActiveSupport::TestCase.fixture_path, fixture_set_names, fixture_class_names, &block)
+ ActiveRecord::FixtureSet.create_fixtures(self.class.fixture_directory_path, fixture_set_names, fixture_model_names, &block)
end
end
View
6 guides/source/active_record_basics.md
@@ -175,13 +175,13 @@ class Product < ActiveRecord::Base
end
```
-If you do so, you will have to define manually the class name that is hosting
-the fixtures (class_name.yml) using the `set_fixture_class` method in your test
+If you do so, you will have to define manually the model name that is hosting
+the fixtures (model_name.yml) using the `set_fixture_model` method in your test
definition:
```ruby
class FunnyJoke < ActiveSupport::TestCase
- set_fixture_class funny_jokes: 'Joke'
+ set_fixture_model funny_jokes: 'Joke'
fixtures :funny_jokes
...
end
View
6 railties/lib/rails/test_help.rb
@@ -15,13 +15,13 @@
if defined?(ActiveRecord::Base)
class ActiveSupport::TestCase
include ActiveRecord::TestFixtures
- self.fixture_path = "#{Rails.root}/test/fixtures/"
+ self.fixture_directory_path = "#{Rails.root}/test/fixtures/"
end
- ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
+ ActionDispatch::IntegrationTest.fixture_directory_path = ActiveSupport::TestCase.fixture_directory_path
def create_fixtures(*fixture_set_names, &block)
- FixtureSet.create_fixtures(ActiveSupport::TestCase.fixture_path, fixture_set_names, {}, &block)
+ FixtureSet.create_fixtures(ActiveSupport::TestCase.fixture_directory_path, fixture_set_names, {}, &block)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.