aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/upgrading_ruby_on_rails.md
diff options
context:
space:
mode:
authorVictor Costan <costan@gmail.com>2013-11-24 12:52:53 -0500
committerVictor Costan <costan@gmail.com>2013-12-03 02:52:26 -0500
commitddf27acbc285a892842866cde04951cdad52c5c9 (patch)
tree9497d0ae23ce1217adb5d21143587c54825dc564 /guides/source/upgrading_ruby_on_rails.md
parentabc1e5831cae724cfcdf524f62abb71be02d7e86 (diff)
downloadrails-ddf27acbc285a892842866cde04951cdad52c5c9.tar.gz
rails-ddf27acbc285a892842866cde04951cdad52c5c9.tar.bz2
rails-ddf27acbc285a892842866cde04951cdad52c5c9.zip
Introduce a context for rendering fixtures ERB.
Fixture files are passed through an ERB renderer before being read as YAML. The rendering is currently done in the context of the main object, so method definitons leak into other fixtures, and there is no clean place to define fixture helpers. After this commit, the ERB renderer will use a new subclass of ActiveRecord::FixtureSet.context_class each time a fixture is rendered.
Diffstat (limited to 'guides/source/upgrading_ruby_on_rails.md')
-rw-r--r--guides/source/upgrading_ruby_on_rails.md17
1 files changed, 17 insertions, 0 deletions
diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md
index ef5f6ac024..3fbc913d8b 100644
--- a/guides/source/upgrading_ruby_on_rails.md
+++ b/guides/source/upgrading_ruby_on_rails.md
@@ -27,6 +27,23 @@ Upgrading from Rails 4.0 to Rails 4.1
NOTE: This section is a work in progress.
+### Methods defined in Active Record fixtures
+
+Rails 4.1 evaluates each fixture's ERB in a separate context, so helper methods
+defined in a fixture will not be available in other fixtures.
+
+Helper methods that are used in multiple fixtures should be defined on modules
+included in the newly introduced `ActiveRecord::FixtureSet.context_class`, in
+`test_helper.rb`.
+
+```ruby
+class FixtureFileHelpers
+ def file_sha(path)
+ Digest::SHA2.hexdigest(File.read(Rails.root.join('test/fixtures', path)))
+ end
+end
+ActiveRecord::FixtureSet.context_class.send :include, FixtureFileHelpers
+```
Upgrading from Rails 3.2 to Rails 4.0
-------------------------------------