Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revert file position in Footnotes::Filter#initialize

Resolved merge conflicts

Conflicts:

	lib/rails-footnotes/footnotes.rb
  • Loading branch information...
commit c3dca85f0d6aa66acebeaf1c17fc6e2f1fa7b52f 1 parent 54aa382
labocho labocho authored romanvbabenko committed
Showing with 31 additions and 1 deletion.
  1. +11 −1 lib/rails-footnotes/filter.rb
  2. +20 −0 spec/footnotes_spec.rb
12 lib/rails-footnotes/filter.rb
View
@@ -52,8 +52,11 @@ def prefix(*args)
def initialize(controller)
@controller = controller
@template = controller.instance_variable_get(:@template)
- @body = controller.response.body
@notes = []
+
+ revert_pos(controller.response_body) do
+ @body = controller.response.body
+ end
end
def add_footnotes!
@@ -91,6 +94,13 @@ def initialize_notes!
end
end
+ def revert_pos(file)
+ return yield unless file.respond_to?(:pos) && file.respond_to?(:pos=)
+ original = file.pos
+ yield
+ file.pos = original
+ end
+
def performed_render?
@controller.instance_variable_get(:@performed_render) || # rails 2.x
(@controller.respond_to?(:performed?) && @controller.performed?) # rails3, will break on redirect??
20 spec/footnotes_spec.rb
View
@@ -1,6 +1,7 @@
require "spec_helper"
require 'action_controller'
require 'action_controller/test_case'
+require "tempfile"
class FootnotesController < ActionController::Base
attr_accessor :template, :performed_render
@@ -36,6 +37,25 @@ class NoteZNote < TestNote; end
index.should eql 334
end
+ context "response_body is file" do
+ before do
+ @file = Tempfile.new("test")
+ @file.write "foobarbaz"
+ @file.rewind
+ end
+
+ after do
+ @file.close!
+ end
+
+ it "should not change file position" do
+ @controller.response_body = @file
+ expect {
+ @footnotes = Footnotes::Filter.new(@controller)
+ }.not_to change{ @controller.response_body.pos }
+ end
+ end
+
#TODO doe's not pased with 1.8.7
if RUBY_VERSION >= '1.9.0'
it "foonotes_included" do
Please sign in to comment.
Something went wrong with that request. Please try again.