Sha256: 1f65a3a46db4b4abbe306db09eb3929614cb558fd6e8d0645774934a02032ced

Contents?: true

Size: 1.86 KB

Versions: 4

Compression:

Stored size: 1.86 KB

Contents

require File.expand_path("#{File.dirname(__FILE__)}/rails_spec_helper")

describe Erector::Rails::WidgetExtensions do
  include Erector::Mixin

  before(:each) do
    @view = ActionView::Base.new
  end

  def test_render(&block)
    Erector::Rails.render(Erector.inline(&block), @view)
  end

  it "should be set up with the same output buffer as rails" do
    test_render { output.buffer.should === parent.output_buffer }
  end

  it "should get a new output buffer every time" do
    one = test_render { text "foo" }
    two = test_render { text "foo" }
    one.should == "foo"
    two.should == "foo"
  end

  describe "#capture" do
    it "captures parent output" do
      captured = nil
      test_render do
        captured = capture do
          parent.concat "capture me!"
        end
      end.should == ""
      captured.should == "capture me!"
    end

    it "captures with an erector block" do
      captured = nil
      test_render do
        captured = capture do
          text 'capture me!'
        end
      end.should == ""
      captured.should == "capture me!"
    end

    it "captures erector output when called via parent" do
      test_render do
        text "A"
        c = parent.capture do
          text "C"
        end
        text "B"
        text c
      end.should == "ABC"
    end

    it "returns a safe string" do
      captured = nil
      test_render do
        captured = capture {}
      end.should == ""
      captured.should be_html_safe
    end
  end

  describe "escaping" do
    it "escapes non-safe strings" do
      erector { text "<>&" }.should == "&lt;&gt;&amp;"
    end

    it "does not escape safe strings" do
      erector { text "<>&".html_safe }.should == "<>&"
    end

    it "returns safe strings from capture" do
      captured = nil
      erector do
        captured = capture {}
      end
      captured.should be_html_safe
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
erector-0.10.0 spec/rails2/rails_app/spec/rails_widget_spec.rb
erector-0.9.0 spec/rails2/rails_app/spec/rails_widget_spec.rb
erector-0.9.0.pre1 spec/rails2/rails_app/spec/rails_widget_spec.rb
erector-0.8.3 spec/rails2/rails_app/spec/rails_widget_spec.rb