require 'spec_helper' module Deface module Actions describe SurroundContents do include_context "mock Rails.application" before { Dummy.all.clear } describe "with a single html surround_contents override defined" do before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround_contents => "div", :text => "<%= render_original %>") } let(:source) { "

yay!

test

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

yay!

test

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

test

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

<% if 1==1 %>test<% end %>

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

Start

middle

child

This is the end.

" } it "should return modified source" do expect(Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '')).to eq("

Start

<% if 1==1 %>

middle

child

<% end %>

This is the end.

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

test

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

<% if 1==1 %>test<% else %>test<% end %>

") 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_contents => "h1", :closing_selector => "p", :text => "<% if 1==1 %><%= render_original %><% else %><%= render_original %><% end %>") } let(:source) { "

Start

middle

child

This is the end.

" } it "should return modified source" do expect(Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '')).to eq("

Start

<% if 1==1 %>

middle

child

<% else %>

middle

child

<% end %>

This is the end.

") end end end end end