Skip to content
Browse files

Merge pull request #10907 from senny/fixtures_and_database_url

fixture setup does not rely on `AR::Base.configurations`.
  • Loading branch information...
2 parents be4fac3 + 6d10d64 commit 00519985f3a8091c41f9038db72bb7129e5bb37d @senny senny committed Jun 15, 2013
View
5 activerecord/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Fixture setup does no longer depend on `ActiveRecord::Base.configurations`.
+ This is relevant when `ENV["DATABASE_URL"]` is used in place of a `database.yml`.
+
+ *Yves Senn*
+
* Fix mysql2 adapter raises the correct exception when executing a query on a
closed connection.
View
4 activerecord/lib/active_record/fixtures.rb
@@ -841,8 +841,6 @@ def run_in_transaction?
end
def setup_fixtures
- return if ActiveRecord::Base.configurations.blank?
-
if pre_loaded_fixtures && !use_transactional_fixtures
raise RuntimeError, 'pre_loaded_fixtures requires use_transactional_fixtures'
end
@@ -875,8 +873,6 @@ def setup_fixtures
end
def teardown_fixtures
- return if ActiveRecord::Base.configurations.blank?
-
# Rollback changes if a transaction is active.
if run_in_transaction?
@fixture_connections.each do |connection|
View
16 activerecord/test/cases/fixtures_test.rb
@@ -245,6 +245,22 @@ def test_binary_in_fixtures
def test_serialized_fixtures
assert_equal ["Green", "Red", "Orange"], traffic_lights(:uk).state
end
+
+ def test_fixtures_are_set_up_with_database_env_variable
+ ENV.stubs(:[]).with("DATABASE_URL").returns("sqlite3:///:memory:")
+ ActiveRecord::Base.stubs(:configurations).returns({})
+ test_case = Class.new(ActiveRecord::TestCase) do
+ fixtures :accounts
+
+ def test_fixtures
+ assert accounts(:signals37)
+ end
+ end
+
+ result = test_case.new(:test_fixtures).run
+
+ assert result.passed?, "Expected #{result.name} to pass:\n#{result}"
+ end
end
if Account.connection.respond_to?(:reset_pk_sequence!)

0 comments on commit 0051998

Please sign in to comment.
Something went wrong with that request. Please try again.