diff options
-rw-r--r-- | actionmailer/test/base_test.rb | 1 | ||||
-rw-r--r-- | actionpack/CHANGELOG.md | 16 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/conditional_get.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/instrumentation.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_view/digestor.rb | 8 | ||||
-rw-r--r-- | actionpack/test/fixtures/digestor/messages/_form.html.erb | 0 | ||||
-rw-r--r-- | actionpack/test/fixtures/digestor/messages/edit.html.erb | 5 | ||||
-rw-r--r-- | actionpack/test/template/digestor_test.rb | 35 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/has_one_association.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 18 |
10 files changed, 79 insertions, 20 deletions
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index fcf5be56f7..c7b8f47d89 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -2,6 +2,7 @@ require 'abstract_unit' require 'set' +require 'action_dispatch' require 'active_support/time' require 'mailers/base_mailer' diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 9469e5b488..1232370439 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -2,15 +2,15 @@ * Added controller-level etag additions that will be part of the action etag computation *Jeremy Kemper/DHH* - class InvoicesController < ApplicationController - etag { current_user.try :id } - - def show - # Etag will differ even for the same invoice when it's viewed by a different current_user - @invoice = Invoice.find(params[:id]) - fresh_when(@invoice) + class InvoicesController < ApplicationController + etag { current_user.try :id } + + def show + # Etag will differ even for the same invoice when it's viewed by a different current_user + @invoice = Invoice.find(params[:id]) + fresh_when(@invoice) + end end - end * Add automatic template digests to all CacheHelper#cache calls (originally spiked in the cache_digests plugin) *DHH* diff --git a/actionpack/lib/action_controller/metal/conditional_get.rb b/actionpack/lib/action_controller/metal/conditional_get.rb index 1445b3e383..7521deaaca 100644 --- a/actionpack/lib/action_controller/metal/conditional_get.rb +++ b/actionpack/lib/action_controller/metal/conditional_get.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/class/attribute' + module ActionController module ConditionalGet extend ActiveSupport::Concern @@ -5,7 +7,10 @@ module ActionController include RackDelegation include Head - included { cattr_accessor(:etaggers) { Array.new } } + included do + class_attribute :etaggers + self.etaggers = [] + end module ClassMethods # Allows you to consider additional controller-wide information when generating an etag. @@ -161,7 +166,7 @@ module ActionController private def combine_etags(etag) - [ etag, *etaggers.map { |etagger| instance_exec &etagger }.compact ] + [ etag, *etaggers.map { |etagger| instance_exec(&etagger) }.compact ] end end end diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb index 640ebf5f00..ca4ae532ca 100644 --- a/actionpack/lib/action_controller/metal/instrumentation.rb +++ b/actionpack/lib/action_controller/metal/instrumentation.rb @@ -11,6 +11,7 @@ module ActionController extend ActiveSupport::Concern include AbstractController::Logger + include ActionController::RackDelegation attr_internal :view_runtime diff --git a/actionpack/lib/action_view/digestor.rb b/actionpack/lib/action_view/digestor.rb index cfa864cdd4..899100d06c 100644 --- a/actionpack/lib/action_view/digestor.rb +++ b/actionpack/lib/action_view/digestor.rb @@ -15,10 +15,10 @@ module ActionView # render(topics) => render("topics/topic") # render(message.topics) => render("topics/topic") RENDER_DEPENDENCY = / - render\s? # render, followed by an optional space - \(? # start a optional parenthesis for the render call - (partial:)?\s? # naming the partial, used with collection -- 1st capture - ([@a-z"'][@a-z_\/\."']+) # the template name itself -- 2nd capture + render\s* # render, followed by optional whitespace + \(? # start an optional parenthesis for the render call + (partial:|:partial\s+=>)?\s* # naming the partial, used with collection -- 1st capture + ([@a-z"'][@a-z_\/\."']+) # the template name itself -- 2nd capture /x cattr_accessor(:cache) { Hash.new } diff --git a/actionpack/test/fixtures/digestor/messages/_form.html.erb b/actionpack/test/fixtures/digestor/messages/_form.html.erb new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/actionpack/test/fixtures/digestor/messages/_form.html.erb diff --git a/actionpack/test/fixtures/digestor/messages/edit.html.erb b/actionpack/test/fixtures/digestor/messages/edit.html.erb new file mode 100644 index 0000000000..a9e0a88e32 --- /dev/null +++ b/actionpack/test/fixtures/digestor/messages/edit.html.erb @@ -0,0 +1,5 @@ +<%= render "header" %> +<%= render partial: "form" %> +<%= render @message %> +<%= render ( @message.events ) %> +<%= render :partial => "comments/comment", :collection => @message.comments %> diff --git a/actionpack/test/template/digestor_test.rb b/actionpack/test/template/digestor_test.rb index 067ab500f5..9c84f3107f 100644 --- a/actionpack/test/template/digestor_test.rb +++ b/actionpack/test/template/digestor_test.rb @@ -16,7 +16,7 @@ class FixtureFinder TMP_DIR = "#{File.dirname(__FILE__)}/../tmp" def find(logical_name, keys, partial, options) - FixtureTemplate.new("#{TMP_DIR}/#{partial ? logical_name.gsub(%r|/([^/]+)$|, '/_\1') : logical_name}.#{options[:formats].first}.erb") + FixtureTemplate.new("#{TMP_DIR}/digestor/#{partial ? logical_name.gsub(%r|/([^/]+)$|, '/_\1') : logical_name}.#{options[:formats].first}.erb") end end @@ -26,7 +26,7 @@ class TemplateDigestorTest < ActionView::TestCase end def teardown - FileUtils.rm_r FixtureFinder::TMP_DIR + FileUtils.rm_r File.join(FixtureFinder::TMP_DIR, "digestor") ActionView::Digestor.cache.clear end @@ -92,6 +92,35 @@ class TemplateDigestorTest < ActionView::TestCase end end + def test_extra_whitespace_in_render_partial + assert_digest_difference("messages/edit") do + change_template("messages/_form") + end + end + + def test_extra_whitespace_in_render_named_partial + assert_digest_difference("messages/edit") do + change_template("messages/_header") + end + end + + def test_extra_whitespace_in_render_record + assert_digest_difference("messages/edit") do + change_template("messages/_message") + end + end + + def test_extra_whitespace_in_render_with_parenthesis + assert_digest_difference("messages/edit") do + change_template("events/_event") + end + end + + def test_old_style_hash_in_render_invocation + assert_digest_difference("messages/edit") do + change_template("comments/_comment") + end + end private def assert_logged(message) @@ -121,7 +150,7 @@ class TemplateDigestorTest < ActionView::TestCase end def change_template(template_name) - File.open("#{FixtureFinder::TMP_DIR}/#{template_name}.html.erb", "w") do |f| + File.open("#{FixtureFinder::TMP_DIR}/digestor/#{template_name}.html.erb", "w") do |f| f.write "\nTHIS WAS CHANGED!" end end diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb index dd7da59a86..06bead41de 100644 --- a/activerecord/lib/active_record/associations/has_one_association.rb +++ b/activerecord/lib/active_record/associations/has_one_association.rb @@ -30,11 +30,11 @@ module ActiveRecord if (target || record) && target != record reflection.klass.transaction do remove_target!(options[:dependent]) if target && !target.destroyed? - + if record set_owner_attributes(record) set_inverse_instance(record) - + if owner.persisted? && save && !record.save nullify_owner_attributes(record) set_owner_attributes(target) if target @@ -82,7 +82,7 @@ module ActiveRecord if target.persisted? && owner.persisted? && !target.save set_owner_attributes(target) raise RecordNotSaved, "Failed to remove the existing associated #{reflection.name}. " + - "The record failed to save when after its foreign key was set to nil." + "The record failed to save after its foreign key was set to nil." end end end diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index 8acbc08e09..09318879d5 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -208,6 +208,21 @@ module ActiveRecord connection.transaction(options, &block) end + # This callback is called after a record has been created, updated, or destroyed. + # + # You can specify that the callback should only be fired by a certain action with + # the +:on+ option: + # + # after_commit :do_foo, :on => :create + # after_commit :do_bar, :on => :update + # after_commit :do_baz, :on => :destroy + # + # Also, to have the callback fired on create and update, but not on destroy: + # + # after_commit :do_zoo, :if => :persisted? + # + # Note that transactional fixtures do not play well with this feature. Please + # use the +test_after_commit+ gem to have these hooks fired in tests. def after_commit(*args, &block) options = args.last if options.is_a?(Hash) && options[:on] @@ -217,6 +232,9 @@ module ActiveRecord set_callback(:commit, :after, *args, &block) end + # This callback is called after a create, update, or destroy are rolled back. + # + # Please check the documentation of +after_commit+ for options. def after_rollback(*args, &block) options = args.last if options.is_a?(Hash) && options[:on] |