deface 0.9.1 → 1.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/.travis.yml +1 -0
- data/README.markdown +139 -59
- data/deface.gemspec +4 -2
- data/gemfiles/haml3_2.gemfile +5 -0
- data/lib/deface.rb +28 -1
- data/lib/deface/action_view_extensions.rb +7 -1
- data/lib/deface/actions/action.rb +19 -0
- data/lib/deface/actions/add_to_attributes.rb +15 -0
- data/lib/deface/actions/attribute_action.rb +33 -0
- data/lib/deface/actions/element_action.rb +13 -0
- data/lib/deface/actions/insert_after.rb +9 -0
- data/lib/deface/actions/insert_before.rb +9 -0
- data/lib/deface/actions/insert_bottom.rb +14 -0
- data/lib/deface/actions/insert_top.rb +14 -0
- data/lib/deface/actions/remove.rb +13 -0
- data/lib/deface/actions/remove_from_attributes.rb +13 -0
- data/lib/deface/actions/replace.rb +14 -0
- data/lib/deface/actions/replace_contents.rb +19 -0
- data/lib/deface/actions/set_attributes.rb +12 -0
- data/lib/deface/actions/surround.rb +24 -0
- data/lib/deface/actions/surround_action.rb +15 -0
- data/lib/deface/actions/surround_contents.rb +33 -0
- data/lib/deface/applicator.rb +35 -191
- data/lib/deface/dsl/context.rb +7 -3
- data/lib/deface/dsl/loader.rb +5 -2
- data/lib/deface/environment.rb +31 -1
- data/lib/deface/haml_converter.rb +33 -5
- data/lib/deface/matchers/element.rb +13 -0
- data/lib/deface/matchers/range.rb +52 -0
- data/lib/deface/override.rb +28 -57
- data/lib/deface/sources/copy.rb +15 -0
- data/lib/deface/sources/cut.rb +25 -0
- data/lib/deface/sources/erb.rb +9 -0
- data/lib/deface/sources/haml.rb +14 -0
- data/lib/deface/sources/partial.rb +13 -0
- data/lib/deface/sources/source.rb +11 -0
- data/lib/deface/sources/template.rb +13 -0
- data/lib/deface/sources/text.rb +9 -0
- data/lib/deface/utils/failure_finder.rb +41 -0
- data/spec/deface/action_view_template_spec.rb +28 -2
- data/spec/deface/actions/add_to_attributes_spec.rb +62 -0
- data/spec/deface/actions/insert_after_spec.rb +19 -0
- data/spec/deface/actions/insert_before_spec.rb +19 -0
- data/spec/deface/actions/insert_bottom_spec.rb +28 -0
- data/spec/deface/actions/insert_top_spec.rb +28 -0
- data/spec/deface/actions/remove_from_attributes_spec.rb +81 -0
- data/spec/deface/actions/remove_spec.rb +30 -0
- data/spec/deface/actions/replace_contents_spec.rb +29 -0
- data/spec/deface/actions/replace_spec.rb +52 -0
- data/spec/deface/actions/set_attributes_spec.rb +62 -0
- data/spec/deface/actions/surround_contents_spec.rb +57 -0
- data/spec/deface/actions/surround_spec.rb +57 -0
- data/spec/deface/applicator_spec.rb +0 -354
- data/spec/deface/dsl/context_spec.rb +14 -7
- data/spec/deface/dsl/loader_spec.rb +12 -4
- data/spec/deface/override_spec.rb +26 -3
- data/spec/deface/template_helper_spec.rb +11 -0
- data/spec/deface/utils/failure_finder_spec.rb +76 -0
- data/spec/spec_helper.rb +21 -2
- data/tasks/utils.rake +24 -0
- metadata +91 -14
@@ -0,0 +1,41 @@
|
|
1
|
+
module Deface
|
2
|
+
module Utils
|
3
|
+
module FailureFinder
|
4
|
+
def overrides_by_virtual_path(virtual_path)
|
5
|
+
begin
|
6
|
+
load_template_source(virtual_path, false, true).dup
|
7
|
+
rescue Exception => e
|
8
|
+
puts "Error processing overrides for :virtual_path => '#{virtual_path}'"
|
9
|
+
puts " #{e.message}"
|
10
|
+
return nil
|
11
|
+
end
|
12
|
+
Deface::Override.find(:virtual_path => virtual_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def output_results_by_virtual_path(virtual_path)
|
16
|
+
has_failz = 0
|
17
|
+
|
18
|
+
fails = overrides_by_virtual_path(virtual_path)
|
19
|
+
return(has_failz += 1) if fails.nil?
|
20
|
+
|
21
|
+
count = fails.group_by{ |o| !o.failure.nil? }
|
22
|
+
if count.key?(true)
|
23
|
+
has_failz += count[true].count
|
24
|
+
puts "#{count[true].count} of #{fails.count} override(s) failed for :virtual_path => '#{virtual_path}'"
|
25
|
+
else
|
26
|
+
puts "0 of #{fails.count} override(s) failed for :virtual_path => '#{virtual_path}'"
|
27
|
+
end
|
28
|
+
|
29
|
+
fails.each do |override|
|
30
|
+
if override.failure.nil?
|
31
|
+
puts " '#{override.name}' reported no failures".green
|
32
|
+
else
|
33
|
+
puts " '#{override.name}' #{override.failure}".red
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
has_failz
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -62,7 +62,33 @@ module ActionView
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
describe "non erb or haml template" do
|
66
|
+
before(:each) do
|
67
|
+
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "p")
|
68
|
+
@template = ActionView::Template.new("xml.post => :blah", "/some/path/to/file.erb", ActionView::Template::Handlers::Builder, {:virtual_path=>"posts/index", :format=>:xml, :updated_at => (Time.now - 100)})
|
69
|
+
end
|
67
70
|
|
71
|
+
it "should return unmodified source" do
|
72
|
+
#if processed, source would include "=>"
|
73
|
+
@template.source.should == "xml.post => :blah"
|
74
|
+
end
|
75
|
+
end
|
68
76
|
|
77
|
+
describe "#should_be_defaced?(handler) method" do
|
78
|
+
#not so BDD, but it keeps us from making mistakes in the future
|
79
|
+
#for instance, we test ActionView::Template here with a handler == ....::Handlers::ERB,
|
80
|
+
#while in rails it seems it's an instance of ...::Handlers::ERB
|
81
|
+
it "should be truthy only for haml/erb handlers and their instances" do
|
82
|
+
expectations = { Haml::Plugin => true,
|
83
|
+
ActionView::Template::Handlers::ERB => true,
|
84
|
+
ActionView::Template::Handlers::ERB.new => true,
|
85
|
+
ActionView::Template::Handlers::Builder => false }
|
86
|
+
expectations.each do |handler, expected|
|
87
|
+
@template = ActionView::Template.new("xml.post => :blah", "/some/path/to/file.erb", handler, {:virtual_path=>"posts/index", :format=>:xml, :updated_at => (Time.now - 100)})
|
88
|
+
@template.is_a?(ActionView::Template).should == true
|
89
|
+
@template.send(:should_be_defaced?, handler).should eq(expected), "unexpected result for handler "+handler.to_s
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
module Actions
|
5
|
+
describe AddToAttributes do
|
6
|
+
include_context "mock Rails.application"
|
7
|
+
before { Dummy.all.clear }
|
8
|
+
|
9
|
+
describe "with a single add_to_attributes override (containing only text) defined" do
|
10
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :add_to_attributes => 'img',
|
11
|
+
:attributes => {:class => 'pretty', :alt => 'something interesting'}) }
|
12
|
+
let(:source) { "<img class=\"button\" src=\"path/to/button.png\">" }
|
13
|
+
|
14
|
+
it "should return modified source" do
|
15
|
+
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
16
|
+
|
17
|
+
attrs["class"].value.should == "button pretty"
|
18
|
+
attrs["alt"].value.should == "something interesting"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "with a single add_to_attributes override (containing erb) defined" do
|
23
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :add_to_attributes => 'img',
|
24
|
+
:attributes => {:class => '<%= add_class %>'}) }
|
25
|
+
let(:source) { "<img class=\"button\" src=\"path/to/button.png\">" }
|
26
|
+
|
27
|
+
it "should return modified source" do
|
28
|
+
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
29
|
+
|
30
|
+
attrs["class"].value.should == "button <%= add_class %>"
|
31
|
+
attrs["src"].value.should == "path/to/button.png"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "with a single add_to_attributes override (containing erb) defined using pseudo attribute name" do
|
36
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :add_to_attributes => 'img',
|
37
|
+
:attributes => {'data-erb-class' => '<%= add_class %>'}) }
|
38
|
+
let(:source) { "<img class=\"button\" src=\"path/to/button.png\">" }
|
39
|
+
|
40
|
+
it "should return modified source" do
|
41
|
+
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
42
|
+
|
43
|
+
attrs["class"].value.should == "button <%= add_class %>"
|
44
|
+
attrs["src"].value.should == "path/to/button.png"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "with a single add_to_attributes override (containing erb) defined targetting an existing pseudo attribute" do
|
49
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :add_to_attributes => 'img',
|
50
|
+
:attributes => {:class => '<%= get_some_other_class %>'}) }
|
51
|
+
let(:source) { "<img class=\"<%= get_class %>\" src=\"path/to/button.png\">" }
|
52
|
+
|
53
|
+
it "should return modified source" do
|
54
|
+
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
55
|
+
|
56
|
+
attrs["class"].value.should == "<%= get_class %> <%= get_some_other_class %>"
|
57
|
+
attrs["src"].value.should == "path/to/button.png"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
module Actions
|
5
|
+
describe ReplaceContents do
|
6
|
+
include_context "mock Rails.application"
|
7
|
+
before { Dummy.all.clear }
|
8
|
+
|
9
|
+
describe "with a single insert_after override defined" do
|
10
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "img.button", :text => "<% help %>") }
|
11
|
+
let(:source) { "<div><img class=\"button\" src=\"path/to/button.png\"></div>" }
|
12
|
+
|
13
|
+
it "should return modified source" do
|
14
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "").should == "<div><img class=\"button\" src=\"path/to/button.png\"><% help %></div>"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
module Actions
|
5
|
+
describe InsertBefore do
|
6
|
+
include_context "mock Rails.application"
|
7
|
+
before { Dummy.all.clear }
|
8
|
+
|
9
|
+
describe "with a single insert_before override defined" do
|
10
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "ul li:last", :text => "<%= help %>") }
|
11
|
+
let(:source) { "<ul><li>first</li><li>second</li><li>third</li></ul>" }
|
12
|
+
|
13
|
+
it "should return modified source" do
|
14
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "").should == "<ul><li>first</li><li>second</li><li>third</li><%= help %></ul>"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
module Actions
|
5
|
+
describe InsertBottom do
|
6
|
+
include_context "mock Rails.application"
|
7
|
+
before { Dummy.all.clear }
|
8
|
+
|
9
|
+
describe "with a single insert_bottom override defined" do
|
10
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_bottom => "ul", :text => "<li>I'm always last</li>") }
|
11
|
+
let(:source) { "<ul><li>first</li><li>second</li><li>third</li></ul>" }
|
12
|
+
|
13
|
+
it "should return modified source" do
|
14
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "").should == "<ul><li>first</li><li>second</li><li>third</li><li>I'm always last</li></ul>"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "with a single insert_bottom override defined when targetted elemenet has no children" do
|
19
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_bottom => "ul", :text => "<li>I'm always last</li>") }
|
20
|
+
let(:source) { "<ul></ul>" }
|
21
|
+
|
22
|
+
it "should return modified source" do
|
23
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "").should == "<ul><li>I'm always last</li></ul>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
module Actions
|
5
|
+
describe InsertTop do
|
6
|
+
include_context "mock Rails.application"
|
7
|
+
before { Dummy.all.clear }
|
8
|
+
|
9
|
+
describe "with a single insert_top override defined" do
|
10
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_top => "ul", :text => "<li>me first</li>") }
|
11
|
+
let(:source) { "<ul><li>first</li><li>second</li><li>third</li></ul>" }
|
12
|
+
|
13
|
+
it "should return modified source" do
|
14
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "").should == "<ul><li>me first</li><li>first</li><li>second</li><li>third</li></ul>"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "with a single insert_top override defined when targetted elemenet has no children" do
|
19
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_top => "ul", :text => "<li>first</li><li>second</li><li>third</li>") }
|
20
|
+
let(:source) { "<ul></ul>" }
|
21
|
+
|
22
|
+
it "should return modified source" do
|
23
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "").should == "<ul><li>first</li><li>second</li><li>third</li></ul>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
module Actions
|
5
|
+
describe RemoveFromAttributes do
|
6
|
+
include_context "mock Rails.application"
|
7
|
+
before { Dummy.all.clear }
|
8
|
+
|
9
|
+
describe "with a single remove_from_attributes override (containing only text) defined" do
|
10
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove_from_attributes => 'img',
|
11
|
+
:attributes => {:class => 'pretty'}) }
|
12
|
+
let(:source) { "<img class=\"pretty button\" src=\"path/to/button.png\">" }
|
13
|
+
|
14
|
+
it "should return modified source" do
|
15
|
+
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
16
|
+
|
17
|
+
attrs["class"].value.should == "button"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "with a single remove_from_attributes override (containing erb) defined" do
|
22
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove_from_attributes => 'img',
|
23
|
+
:attributes => {:class => '<%= add_class %>'}) }
|
24
|
+
let(:source) { "<img class=\"button <%= add_class %>\" src=\"path/to/button.png\">" }
|
25
|
+
|
26
|
+
it "should return modified source" do
|
27
|
+
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
28
|
+
|
29
|
+
attrs["class"].value.should == "button"
|
30
|
+
attrs["src"].value.should == "path/to/button.png"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "with a single remove_from_attributes override (containing erb) defined using pseudo attribute name" do
|
35
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove_from_attributes => 'img',
|
36
|
+
:attributes => {'data-erb-class' => '<%= add_class %>'}) }
|
37
|
+
let(:source) { "<img class=\"button <%= add_class %>\" src=\"path/to/button.png\">" }
|
38
|
+
|
39
|
+
it "should return modified source" do
|
40
|
+
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
41
|
+
|
42
|
+
attrs["class"].value.should == "button"
|
43
|
+
attrs["src"].value.should == "path/to/button.png"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "with a single remove_from_attributes override (containing only text) defined where value is not present in attribute" do
|
48
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove_from_attributes => 'img',
|
49
|
+
:attributes => {:class => 'pretty'}) }
|
50
|
+
let(:source) { "<img class=\"button\" src=\"path/to/button.png\">" }
|
51
|
+
|
52
|
+
it "should return unmodified source" do
|
53
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<img class=\"button\" src=\"path/to/button.png\">"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "with a single remove_from_attributes override (containing only text) defined where value is not present in attribute" do
|
58
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove_from_attributes => 'img',
|
59
|
+
:attributes => {:class => 'pretty'}) }
|
60
|
+
let(:source) { "<img src=\"path/to/button.png\">" }
|
61
|
+
|
62
|
+
it "should return unmodified source" do
|
63
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<img src=\"path/to/button.png\">"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "with a single remove_from_attributes override (containing erb) defined targetting an existing pseudo attribute" do
|
68
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove_from_attributes => 'img',
|
69
|
+
:attributes => {:class => '<%= get_some_other_class %>'}) }
|
70
|
+
let(:source) { "<img class=\"<%= get_class %> <%= get_some_other_class %>\" src=\"path/to/button.png\">" }
|
71
|
+
|
72
|
+
it "should return modified source" do
|
73
|
+
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
74
|
+
|
75
|
+
attrs["class"].value.should == "<%= get_class %>"
|
76
|
+
attrs["src"].value.should == "path/to/button.png"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
module Actions
|
5
|
+
describe Remove do
|
6
|
+
include_context "mock Rails.application"
|
7
|
+
before { Dummy.all.clear }
|
8
|
+
|
9
|
+
describe "with a single remove override defined" do
|
10
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "p", :text => "<h1>Argh!</h1>") }
|
11
|
+
let(:source) { "<p>test</p><%= raw(text) %>" }
|
12
|
+
|
13
|
+
it "should return modified source" do
|
14
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<%= raw(text) %>"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "with a single remove override with closing_selector defined" do
|
20
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "h1", :closing_selector => "h2") }
|
21
|
+
let(:source) { "<h2>I should be safe</h2><span>Before!</span><h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2><span>After!</span>" }
|
22
|
+
|
23
|
+
it "should return modified source" do
|
24
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<h2>I should be safe</h2><span>Before!</span><span>After!</span>"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
module Actions
|
5
|
+
describe ReplaceContents do
|
6
|
+
include_context "mock Rails.application"
|
7
|
+
before { Dummy.all.clear }
|
8
|
+
|
9
|
+
describe "with a single replace_contents override defined" do
|
10
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace_contents => "p", :text => "<h1>Argh!</h1>") }
|
11
|
+
let(:source) { "<p><span>Hello</span>I am not a <em>pirate</em></p>" }
|
12
|
+
|
13
|
+
it "should return modified source" do
|
14
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<p><h1>Argh!</h1></p>"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "with a single replace_contents override with closing_selector defined" do
|
19
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace_contents => "h1", :closing_selector => "h2", :text => "<span>Argh!</span>") }
|
20
|
+
let(:source) { "<h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2>" }
|
21
|
+
|
22
|
+
it "should return modified source" do
|
23
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<h1>start</h1><span>Argh!</span><h2>end</h2>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
module Actions
|
5
|
+
describe Replace do
|
6
|
+
include_context "mock Rails.application"
|
7
|
+
before { Dummy.all.clear }
|
8
|
+
|
9
|
+
describe "with a single replace override defined" do
|
10
|
+
before { @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "p", :text => "<h1>Argh!</h1>") }
|
11
|
+
let(:source) { "<p>test</p>" }
|
12
|
+
|
13
|
+
it "should return modified source" do
|
14
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<h1>Argh!</h1>"
|
15
|
+
@override.failure.should be_false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "with a single replace override with closing_selector defined" do
|
20
|
+
before { @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :closing_selector => "h2", :text => "<span>Argh!</span>") }
|
21
|
+
let(:source) { "<h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2>" }
|
22
|
+
|
23
|
+
it "should return modified source" do
|
24
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<span>Argh!</span>"
|
25
|
+
@override.failure.should be_false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "with a single replace override with bad closing_selector defined" do
|
30
|
+
before { @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :closing_selector => "h3", :text => "<span>Argh!</span>") }
|
31
|
+
let(:source) { "<h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2>" }
|
32
|
+
|
33
|
+
it "should log error and return unmodified source" do
|
34
|
+
Rails.logger.should_receive(:info).with(/failed to match with end selector/)
|
35
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == source
|
36
|
+
@override.failure.should be_true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "with a single replace override with bad selector defined" do
|
41
|
+
before { @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h3", :closing_selector => "h2", :text => "<span>Argh!</span>") }
|
42
|
+
let(:source) { "<h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2>" }
|
43
|
+
|
44
|
+
it "should log error and return unmodified source" do
|
45
|
+
Rails.logger.should_receive(:info).with(/failed to match with starting selector/)
|
46
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == source
|
47
|
+
@override.failure.should be_true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|