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,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
module Actions
|
5
|
+
describe SetAttributes do
|
6
|
+
include_context "mock Rails.application"
|
7
|
+
before { Dummy.all.clear }
|
8
|
+
|
9
|
+
describe "with a single set_attributes override (containing only text) defined" do
|
10
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :set_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 == "pretty"
|
18
|
+
attrs["alt"].value.should == "something interesting"
|
19
|
+
attrs["src"].value.should == "path/to/button.png"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "with a single set_attributes override (containing erb) defined" do
|
24
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :set_attributes => 'img',
|
25
|
+
:attributes => {:class => 'pretty', 'data-erb-alt' => '<%= something_interesting %>'}) }
|
26
|
+
let(:source) { "<img class=\"button\" src=\"path/to/button.png\">" }
|
27
|
+
|
28
|
+
it "should return modified source" do
|
29
|
+
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
30
|
+
|
31
|
+
attrs["class"].value.should == "pretty"
|
32
|
+
attrs["alt"].value.should == "<%= something_interesting %>"
|
33
|
+
attrs["src"].value.should == "path/to/button.png"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "with a single set_attributes override (containing erb) defined targetting an existing pseudo attribute" do
|
38
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :set_attributes => 'img',
|
39
|
+
:attributes => {:class => '<%= get_some_other_class %>', :alt => 'something interesting'}) }
|
40
|
+
let(:source) { "<img class=\"<%= get_class %>\" src=\"path/to/button.png\">" }
|
41
|
+
|
42
|
+
it "should return modified source" do
|
43
|
+
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
44
|
+
|
45
|
+
attrs["class"].value.should == "<%= get_some_other_class %>"
|
46
|
+
attrs["alt"].value.should == "something interesting"
|
47
|
+
attrs["src"].value.should == "path/to/button.png"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "with a single set_attributes override (containing a pseudo attribute with erb) defined targetting an existing pseudo attribute" do
|
52
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :set_attributes => 'img',
|
53
|
+
:attributes => {'class' => '<%= hello_world %>'}) }
|
54
|
+
let(:source) { "<div><img class=\"<%= hello_moon %>\" src=\"path/to/button.png\"></div>" }
|
55
|
+
|
56
|
+
it "should return modified source" do
|
57
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "").should == "<div><img src=\"path/to/button.png\" class=\"<%= hello_world %>\"></div>"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
module Actions
|
5
|
+
describe SurroundContents do
|
6
|
+
include_context "mock Rails.application"
|
7
|
+
before { Dummy.all.clear }
|
8
|
+
|
9
|
+
describe "with a single html surround_contents override defined" do
|
10
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround_contents => "div", :text => "<span><%= render_original %></span>") }
|
11
|
+
let(:source) { "<h4>yay!</h4><div><p>test</p></div>" }
|
12
|
+
|
13
|
+
it "should return modified source" do
|
14
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<h4>yay!</h4><div><span><p>test</p></span></div>"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "with a single erb surround_contents override defined" do
|
19
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround_contents => "p", :text => "<% if 1==1 %><%= render_original %><% end %>") }
|
20
|
+
let(:source) { "<p>test</p>" }
|
21
|
+
|
22
|
+
it "should return modified source" do
|
23
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<p><% if 1==1 %>test<% end %></p>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "with a single erb surround_contents override defined using :closing_selector" do
|
28
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround_contents => "h1", :closing_selector => "p",
|
29
|
+
:text => "<% if 1==1 %><%= render_original %><% end %>") }
|
30
|
+
let(:source) { "<div><h1>Start</h1><h2>middle</h2><h3>child</h3><p><span>This is the</span> end.</p></div>" }
|
31
|
+
|
32
|
+
it "should return modified source" do
|
33
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').should == "<div><h1>Start</h1><% if 1==1 %><h2>middle</h2><h3>child</h3><% end %><p><span>This is the</span> end.</p></div>"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "with multiple render_original calls defined" do
|
38
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround_contents => "p", :text => "<% if 1==1 %><%= render_original %><% else %><%= render_original %><% end %>") }
|
39
|
+
let(:source) { "<p>test</p>" }
|
40
|
+
|
41
|
+
it "should return modified source" do
|
42
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<p><% if 1==1 %>test<% else %>test<% end %></p>"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "with multiple render_original calls defined using :closing_selector" do
|
47
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround_contents => "h1", :closing_selector => "p",
|
48
|
+
:text => "<% if 1==1 %><%= render_original %><% else %><%= render_original %><% end %>") }
|
49
|
+
let(:source) { "<div><h1>Start</h1><h2>middle</h2><h3>child</h3><p><span>This is the</span> end.</p></div>" }
|
50
|
+
|
51
|
+
it "should return modified source" do
|
52
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').should == "<div><h1>Start</h1><% if 1==1 %><h2>middle</h2><h3>child</h3><% else %><h2>middle</h2><h3>child</h3><% end %><p><span>This is the</span> end.</p></div>"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
module Actions
|
5
|
+
describe Surround do
|
6
|
+
include_context "mock Rails.application"
|
7
|
+
before { Dummy.all.clear }
|
8
|
+
|
9
|
+
describe "with a single html surround override defined" do
|
10
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "p", :text => "<h1>It's behind you!</h1><div><%= render_original %></div>") }
|
11
|
+
let(:source) { "<p>test</p>" }
|
12
|
+
|
13
|
+
it "should return modified source" do
|
14
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<h1>It's behind you!</h1><div><p>test</p></div>"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "with a single erb surround override defined" do
|
19
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "p", :text => "<% some_method('test') do %><%= render_original %><% end %>") }
|
20
|
+
let(:source) { "<span><p>test</p></span>" }
|
21
|
+
|
22
|
+
it "should return modified source" do
|
23
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').should == "<span><% some_method('test') do %><p>test</p><% end %></span>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "with a single surround override defined using :closing_selector" do
|
28
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "h1", :closing_selector => "p",
|
29
|
+
:text => "<% some_method('test') do %><%= render_original %><% end %>") }
|
30
|
+
let(:source) { "<span><h1>Start</h1><h2>middle</h2><p><span>This is the</span> end.</p></span>" }
|
31
|
+
|
32
|
+
it "should return modified source" do
|
33
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').should == "<span><% some_method('test') do %><h1>Start</h1><h2>middle</h2><p><span>This is the</span> end.</p><% end %></span>"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "with multiple render_original calls defined" do
|
38
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "p", :text => "<div><%= render_original %></div><h1>It's behind you!</h1><div><%= render_original %></div>") }
|
39
|
+
let(:source) { "<p>test</p>" }
|
40
|
+
|
41
|
+
it "should return modified source" do
|
42
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<div><p>test</p></div><h1>It's behind you!</h1><div><p>test</p></div>"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "with multiple render_original calls defined using :closing_selector" do
|
47
|
+
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "h1", :closing_selector => "p",
|
48
|
+
:text => "<% if true %><%= render_original %><% else %><%= render_original %><% end %>") }
|
49
|
+
let(:source) { "<span><h1>Start</h1><h2>middle</h2><p><span>This is the</span> end.</p></span>" }
|
50
|
+
|
51
|
+
it "should return modified source" do
|
52
|
+
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').should == "<span><% if true %><h1>Start</h1><h2>middle</h2><p><span>This is the</span> end.</p><% else %><h1>Start</h1><h2>middle</h2><p><span>This is the</span> end.</p><% end %></span>"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,17 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class Dummy
|
4
|
-
extend Deface::Applicator::ClassMethods
|
5
|
-
extend Deface::Search::ClassMethods
|
6
|
-
|
7
|
-
attr_reader :parsed_document
|
8
|
-
|
9
|
-
def self.all
|
10
|
-
Rails.application.config.deface.overrides.all
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
3
|
def attributes_to_sorted_array(src)
|
16
4
|
Nokogiri::HTML::DocumentFragment.parse(src).children.first.attributes
|
17
5
|
end
|
@@ -21,348 +9,6 @@ module Deface
|
|
21
9
|
include_context "mock Rails.application"
|
22
10
|
before { Dummy.all.clear }
|
23
11
|
|
24
|
-
describe "with a single remove override defined" do
|
25
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "p", :text => "<h1>Argh!</h1>") }
|
26
|
-
let(:source) { "<p>test</p><%= raw(text) %>" }
|
27
|
-
|
28
|
-
it "should return modified source" do
|
29
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<%= raw(text) %>"
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "with a single remove override with closing_selector defined" do
|
35
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "h1", :closing_selector => "h2") }
|
36
|
-
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>" }
|
37
|
-
|
38
|
-
it "should return modified source" do
|
39
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<h2>I should be safe</h2><span>Before!</span><span>After!</span>"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "with a single replace override defined" do
|
44
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "p", :text => "<h1>Argh!</h1>") }
|
45
|
-
let(:source) { "<p>test</p>" }
|
46
|
-
|
47
|
-
it "should return modified source" do
|
48
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<h1>Argh!</h1>"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "with a single replace override with closing_selector defined" do
|
53
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :closing_selector => "h2", :text => "<span>Argh!</span>") }
|
54
|
-
let(:source) { "<h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2>" }
|
55
|
-
|
56
|
-
it "should return modified source" do
|
57
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<span>Argh!</span>"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "with a single replace_contents override defined" do
|
62
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace_contents => "p", :text => "<h1>Argh!</h1>") }
|
63
|
-
let(:source) { "<p><span>Hello</span>I am not a <em>pirate</em></p>" }
|
64
|
-
|
65
|
-
it "should return modified source" do
|
66
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<p><h1>Argh!</h1></p>"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "with a single replace_contents override with closing_selector defined" do
|
71
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace_contents => "h1", :closing_selector => "h2", :text => "<span>Argh!</span>") }
|
72
|
-
let(:source) { "<h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2>" }
|
73
|
-
|
74
|
-
it "should return modified source" do
|
75
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<h1>start</h1><span>Argh!</span><h2>end</h2>"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "with a single insert_after override defined" do
|
80
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "img.button", :text => "<% help %>") }
|
81
|
-
let(:source) { "<div><img class=\"button\" src=\"path/to/button.png\"></div>" }
|
82
|
-
|
83
|
-
it "should return modified source" do
|
84
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "").should == "<div><img class=\"button\" src=\"path/to/button.png\"><% help %></div>"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "with a single insert_before override defined" do
|
89
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "ul li:last", :text => "<%= help %>") }
|
90
|
-
let(:source) { "<ul><li>first</li><li>second</li><li>third</li></ul>" }
|
91
|
-
|
92
|
-
it "should return modified source" do
|
93
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "").should == "<ul><li>first</li><li>second</li><li>third</li><%= help %></ul>"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "with a single insert_top override defined" do
|
98
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_top => "ul", :text => "<li>me first</li>") }
|
99
|
-
let(:source) { "<ul><li>first</li><li>second</li><li>third</li></ul>" }
|
100
|
-
|
101
|
-
it "should return modified source" do
|
102
|
-
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>"
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "with a single insert_top override defined when targetted elemenet has no children" do
|
107
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_top => "ul", :text => "<li>first</li><li>second</li><li>third</li>") }
|
108
|
-
let(:source) { "<ul></ul>" }
|
109
|
-
|
110
|
-
it "should return modified source" do
|
111
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "").should == "<ul><li>first</li><li>second</li><li>third</li></ul>"
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "with a single insert_bottom override defined" do
|
116
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_bottom => "ul", :text => "<li>I'm always last</li>") }
|
117
|
-
let(:source) { "<ul><li>first</li><li>second</li><li>third</li></ul>" }
|
118
|
-
|
119
|
-
it "should return modified source" do
|
120
|
-
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>"
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe "with a single insert_bottom override defined when targetted elemenet has no children" do
|
125
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_bottom => "ul", :text => "<li>I'm always last</li>") }
|
126
|
-
let(:source) { "<ul></ul>" }
|
127
|
-
|
128
|
-
it "should return modified source" do
|
129
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "").should == "<ul><li>I'm always last</li></ul>"
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "with a single set_attributes override (containing only text) defined" do
|
134
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :set_attributes => 'img',
|
135
|
-
:attributes => {:class => 'pretty', :alt => 'something interesting'}) }
|
136
|
-
let(:source) { "<img class=\"button\" src=\"path/to/button.png\">" }
|
137
|
-
|
138
|
-
it "should return modified source" do
|
139
|
-
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
140
|
-
|
141
|
-
attrs["class"].value.should == "pretty"
|
142
|
-
attrs["alt"].value.should == "something interesting"
|
143
|
-
attrs["src"].value.should == "path/to/button.png"
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "with a single set_attributes override (containing erb) defined" do
|
148
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :set_attributes => 'img',
|
149
|
-
:attributes => {:class => 'pretty', 'data-erb-alt' => '<%= something_interesting %>'}) }
|
150
|
-
let(:source) { "<img class=\"button\" src=\"path/to/button.png\">" }
|
151
|
-
|
152
|
-
it "should return modified source" do
|
153
|
-
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
154
|
-
|
155
|
-
attrs["class"].value.should == "pretty"
|
156
|
-
attrs["alt"].value.should == "<%= something_interesting %>"
|
157
|
-
attrs["src"].value.should == "path/to/button.png"
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
describe "with a single set_attributes override (containing erb) defined targetting an existing pseudo attribute" do
|
162
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :set_attributes => 'img',
|
163
|
-
:attributes => {:class => '<%= get_some_other_class %>', :alt => 'something interesting'}) }
|
164
|
-
let(:source) { "<img class=\"<%= get_class %>\" src=\"path/to/button.png\">" }
|
165
|
-
|
166
|
-
it "should return modified source" do
|
167
|
-
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
168
|
-
|
169
|
-
attrs["class"].value.should == "<%= get_some_other_class %>"
|
170
|
-
attrs["alt"].value.should == "something interesting"
|
171
|
-
attrs["src"].value.should == "path/to/button.png"
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
describe "with a single add_to_attributes override (containing only text) defined" do
|
176
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :add_to_attributes => 'img',
|
177
|
-
:attributes => {:class => 'pretty', :alt => 'something interesting'}) }
|
178
|
-
let(:source) { "<img class=\"button\" src=\"path/to/button.png\">" }
|
179
|
-
|
180
|
-
it "should return modified source" do
|
181
|
-
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
182
|
-
|
183
|
-
attrs["class"].value.should == "button pretty"
|
184
|
-
attrs["alt"].value.should == "something interesting"
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe "with a single add_to_attributes override (containing erb) defined" do
|
189
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :add_to_attributes => 'img',
|
190
|
-
:attributes => {:class => '<%= add_class %>'}) }
|
191
|
-
let(:source) { "<img class=\"button\" src=\"path/to/button.png\">" }
|
192
|
-
|
193
|
-
it "should return modified source" do
|
194
|
-
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
195
|
-
|
196
|
-
attrs["class"].value.should == "button <%= add_class %>"
|
197
|
-
attrs["src"].value.should == "path/to/button.png"
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
describe "with a single add_to_attributes override (containing erb) defined using pseudo attribute name" do
|
202
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :add_to_attributes => 'img',
|
203
|
-
:attributes => {'data-erb-class' => '<%= add_class %>'}) }
|
204
|
-
let(:source) { "<img class=\"button\" src=\"path/to/button.png\">" }
|
205
|
-
|
206
|
-
it "should return modified source" do
|
207
|
-
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
208
|
-
|
209
|
-
attrs["class"].value.should == "button <%= add_class %>"
|
210
|
-
attrs["src"].value.should == "path/to/button.png"
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
describe "with a single add_to_attributes override (containing erb) defined targetting an existing pseudo attribute" do
|
215
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :add_to_attributes => 'img',
|
216
|
-
:attributes => {:class => '<%= get_some_other_class %>'}) }
|
217
|
-
let(:source) { "<img class=\"<%= get_class %>\" src=\"path/to/button.png\">" }
|
218
|
-
|
219
|
-
it "should return modified source" do
|
220
|
-
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
221
|
-
|
222
|
-
attrs["class"].value.should == "<%= get_class %> <%= get_some_other_class %>"
|
223
|
-
attrs["src"].value.should == "path/to/button.png"
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
describe "with a single remove_from_attributes override (containing only text) defined" do
|
228
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove_from_attributes => 'img',
|
229
|
-
:attributes => {:class => 'pretty'}) }
|
230
|
-
let(:source) { "<img class=\"pretty button\" src=\"path/to/button.png\">" }
|
231
|
-
|
232
|
-
it "should return modified source" do
|
233
|
-
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
234
|
-
|
235
|
-
attrs["class"].value.should == "button"
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
describe "with a single remove_from_attributes override (containing erb) defined" do
|
240
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove_from_attributes => 'img',
|
241
|
-
:attributes => {:class => '<%= add_class %>'}) }
|
242
|
-
let(:source) { "<img class=\"button <%= add_class %>\" src=\"path/to/button.png\">" }
|
243
|
-
|
244
|
-
it "should return modified source" do
|
245
|
-
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
246
|
-
|
247
|
-
attrs["class"].value.should == "button"
|
248
|
-
attrs["src"].value.should == "path/to/button.png"
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
describe "with a single remove_from_attributes override (containing erb) defined using pseudo attribute name" do
|
253
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove_from_attributes => 'img',
|
254
|
-
:attributes => {'data-erb-class' => '<%= add_class %>'}) }
|
255
|
-
let(:source) { "<img class=\"button <%= add_class %>\" src=\"path/to/button.png\">" }
|
256
|
-
|
257
|
-
it "should return modified source" do
|
258
|
-
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
259
|
-
|
260
|
-
attrs["class"].value.should == "button"
|
261
|
-
attrs["src"].value.should == "path/to/button.png"
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
describe "with a single remove_from_attributes override (containing only text) defined where value is not present in attribute" do
|
266
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove_from_attributes => 'img',
|
267
|
-
:attributes => {:class => 'pretty'}) }
|
268
|
-
let(:source) { "<img class=\"button\" src=\"path/to/button.png\">" }
|
269
|
-
|
270
|
-
it "should return unmodified source" do
|
271
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<img class=\"button\" src=\"path/to/button.png\">"
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
describe "with a single remove_from_attributes override (containing only text) defined where value is not present in attribute" do
|
276
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove_from_attributes => 'img',
|
277
|
-
:attributes => {:class => 'pretty'}) }
|
278
|
-
let(:source) { "<img src=\"path/to/button.png\">" }
|
279
|
-
|
280
|
-
it "should return unmodified source" do
|
281
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<img src=\"path/to/button.png\">"
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
describe "with a single remove_from_attributes override (containing erb) defined targetting an existing pseudo attribute" do
|
286
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove_from_attributes => 'img',
|
287
|
-
:attributes => {:class => '<%= get_some_other_class %>'}) }
|
288
|
-
let(:source) { "<img class=\"<%= get_class %> <%= get_some_other_class %>\" src=\"path/to/button.png\">" }
|
289
|
-
|
290
|
-
it "should return modified source" do
|
291
|
-
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
292
|
-
|
293
|
-
attrs["class"].value.should == "<%= get_class %>"
|
294
|
-
attrs["src"].value.should == "path/to/button.png"
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
describe "with a single set_attributes override (containing a pseudo attribute with erb) defined targetting an existing pseudo attribute" do
|
299
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :set_attributes => 'img',
|
300
|
-
:attributes => {'class' => '<%= hello_world %>'}) }
|
301
|
-
let(:source) { "<div><img class=\"<%= hello_moon %>\" src=\"path/to/button.png\"></div>" }
|
302
|
-
|
303
|
-
it "should return modified source" do
|
304
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "").should == "<div><img src=\"path/to/button.png\" class=\"<%= hello_world %>\"></div>"
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
describe "with a single html surround override defined" do
|
309
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "p", :text => "<h1>It's behind you!</h1><div><%= render_original %></div>") }
|
310
|
-
let(:source) { "<p>test</p>" }
|
311
|
-
|
312
|
-
it "should return modified source" do
|
313
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<h1>It's behind you!</h1><div><p>test</p></div>"
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
describe "with a single erb surround override defined" do
|
318
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "p", :text => "<% some_method('test') do %><%= render_original %><% end %>") }
|
319
|
-
let(:source) { "<span><p>test</p></span>" }
|
320
|
-
|
321
|
-
it "should return modified source" do
|
322
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').should == "<span><% some_method('test') do %><p>test</p><% end %></span>"
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
describe "with a single surround override defined using :closing_selector" do
|
327
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "h1", :closing_selector => "p",
|
328
|
-
:text => "<% some_method('test') do %><%= render_original %><% end %>") }
|
329
|
-
let(:source) { "<span><h1>Start</h1><h2>middle</h2><p><span>This is the</span> end.</p></span>" }
|
330
|
-
|
331
|
-
it "should return modified source" do
|
332
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').should == "<span><% some_method('test') do %><h1>Start</h1><h2>middle</h2><p><span>This is the</span> end.</p><% end %></span>"
|
333
|
-
end
|
334
|
-
end
|
335
|
-
|
336
|
-
|
337
|
-
describe "with a single html surround_contents override defined" do
|
338
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround_contents => "div", :text => "<span><%= render_original %></span>") }
|
339
|
-
let(:source) { "<h4>yay!</h4><div><p>test</p></div>" }
|
340
|
-
|
341
|
-
it "should return modified source" do
|
342
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<h4>yay!</h4><div><span><p>test</p></span></div>"
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
describe "with a single erb surround_contents override defined" do
|
347
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround_contents => "p", :text => "<% if 1==1 %><%= render_original %><% end %>") }
|
348
|
-
let(:source) { "<p>test</p>" }
|
349
|
-
|
350
|
-
it "should return modified source" do
|
351
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).should == "<p><% if 1==1 %>test<% end %></p>"
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
describe "with a single erb surround_contents override defined using :closing_selector" do
|
356
|
-
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround_contents => "h1", :closing_selector => "p",
|
357
|
-
:text => "<% if 1==1 %><%= render_original %><% end %>") }
|
358
|
-
let(:source) { "<div><h1>Start</h1><h2>middle</h2><h3>child</h3><p><span>This is the</span> end.</p></div>" }
|
359
|
-
|
360
|
-
it "should return modified source" do
|
361
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').should == "<div><h1>Start</h1><% if 1==1 %><h2>middle</h2><h3>child</h3><% end %><p><span>This is the</span> end.</p></div>"
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
|
366
12
|
describe "with a single disabled override defined" do
|
367
13
|
before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "p", :text => "<h1>Argh!</h1>", :disabled => true) }
|
368
14
|
let(:source) { "<p>test</p><%= raw(text) %>" }
|