require 'spec_helper' module Deface module Actions describe Surround do include_context "mock Rails.application" before { Dummy.all.clear } describe "with a single html surround override defined" do before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "p", :text => "

It's behind you!

<%= render_original %>
") } let(:source) { "

test

" } it "should return modified source" do Dummy.apply(source, {:virtual_path => "posts/index"}).should == "

It's behind you!

test

" end end describe "with a single erb surround override defined" do before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "p", :text => "<% some_method('test') do %><%= render_original %><% end %>") } let(:source) { "

test

" } it "should return modified source" do Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').should == "<% some_method('test') do %>

test

<% end %>
" end end describe "with a single surround override defined using :closing_selector" do before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "h1", :closing_selector => "p", :text => "<% some_method('test') do %><%= render_original %><% end %>") } let(:source) { "

Start

middle

This is the end.

" } it "should return modified source" do Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').should == "<% some_method('test') do %>

Start

middle

This is the end.

<% end %>
" end end describe "with multiple render_original calls defined" do before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "p", :text => "
<%= render_original %>

It's behind you!

<%= render_original %>
") } let(:source) { "

test

" } it "should return modified source" do Dummy.apply(source, {:virtual_path => "posts/index"}).should == "

test

It's behind you!

test

" end end describe "with multiple render_original calls defined using :closing_selector" do before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "h1", :closing_selector => "p", :text => "<% if true %><%= render_original %><% else %><%= render_original %><% end %>") } let(:source) { "

Start

middle

This is the end.

" } it "should return modified source" do Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').should == "<% if true %>

Start

middle

This is the end.

<% else %>

Start

middle

This is the end.

<% end %>
" end end end end end