require 'spec_helper' module ActionView describe Template do describe "#initialize" do describe "with no overrides defined" do before(:all) do @template = ActionView::Template.new("

test

", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html}) end it "should initialize new template object" do @template.is_a?(ActionView::Template).should == true end it "should return unmodified source" do @template.source.should == "

test

" end end describe "with a single remove override defined" do before(:all) do Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "p", :text => "

Argh!

") @template = ActionView::Template.new("

test

<%= raw(text) %>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html}) end it "should return modified source" do @template.source.should == "<%= raw(text) %>" end end describe "with a single replace override defined" do before(:all) do Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "p", :text => "

Argh!

") @template = ActionView::Template.new("

test

", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html}) end it "should return modified source" do @template.source.should == "

Argh!

" end end describe "with a single insert_after override defined" do before(:all) do Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "img.button", :text => "<% help %>") @template = ActionView::Template.new("
", "/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html}) end it "should return modified source" do @template.source.gsub("\n", "").should == "
<% help %>
" end end describe "with a single insert_before override defined" do before(:all) do Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "ul li:last", :text => "<%= help %>") @template = ActionView::Template.new("", "/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html}) end it "should return modified source" do @template.source.gsub("\n", "").should == "" end end describe "with a single insert_top override defined" do before(:all) do Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_top => "ul", :text => "
  • me first
  • ") @template = ActionView::Template.new("", "/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html}) end it "should return modified source" do @template.source.gsub("\n", "").should == "" end end describe "with a single insert_bottom override defined" do before(:all) do Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_bottom => "ul", :text => "
  • I'm always last
  • ") @template = ActionView::Template.new("", "/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html}) end it "should return modified source" do @template.source.gsub("\n", "").should == "" end end describe "with a single disabled override defined" do before(:all) do Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "p", :text => "

    Argh!

    ", :disabled => true) @template = ActionView::Template.new("

    test

    <%= raw(text) %>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html}) end it "should return unmodified source" do @template.source.should == "

    test

    <%= raw(text) %>" end end end end end