deface 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +3 -2
- data/README.markdown +3 -11
- data/deface.gemspec +4 -4
- data/lib/deface/applicator.rb +1 -1
- data/lib/deface/dsl/loader.rb +42 -34
- data/lib/deface/railtie.rb +2 -2
- data/lib/deface/slim_converter.rb +15 -0
- data/lib/deface/sources/copy.rb +1 -1
- data/lib/deface/sources/slim.rb +2 -2
- data/lib/deface/template_helper.rb +1 -1
- data/spec/deface/action_view_template_spec.rb +12 -12
- data/spec/deface/actions/add_to_attributes_spec.rb +8 -8
- data/spec/deface/actions/insert_after_spec.rb +1 -1
- data/spec/deface/actions/insert_before_spec.rb +1 -1
- data/spec/deface/actions/insert_bottom_spec.rb +2 -2
- data/spec/deface/actions/insert_top_spec.rb +2 -2
- data/spec/deface/actions/remove_from_attributes_spec.rb +9 -9
- data/spec/deface/actions/remove_spec.rb +2 -2
- data/spec/deface/actions/replace_contents_spec.rb +2 -2
- data/spec/deface/actions/replace_spec.rb +10 -10
- data/spec/deface/actions/set_attributes_spec.rb +11 -11
- data/spec/deface/actions/surround_contents_spec.rb +5 -5
- data/spec/deface/actions/surround_spec.rb +5 -5
- data/spec/deface/applicator_spec.rb +6 -6
- data/spec/deface/dsl/context_spec.rb +7 -7
- data/spec/deface/dsl/loader_spec.rb +74 -77
- data/spec/deface/environment_spec.rb +38 -38
- data/spec/deface/haml_converter_spec.rb +24 -24
- data/spec/deface/override_spec.rb +90 -90
- data/spec/deface/parser_spec.rb +54 -54
- data/spec/deface/precompiler_spec.rb +7 -7
- data/spec/deface/search_spec.rb +7 -7
- data/spec/deface/slim_converter_spec.rb +32 -0
- data/spec/deface/template_helper_spec.rb +21 -22
- data/spec/deface/utils/failure_finder_spec.rb +11 -11
- data/spec/spec_helper.rb +25 -17
- metadata +33 -69
data/spec/deface/parser_spec.rb
CHANGED
@@ -7,15 +7,15 @@ module Deface
|
|
7
7
|
|
8
8
|
describe "#convert" do
|
9
9
|
it "should parse html fragment" do
|
10
|
-
Deface::Parser.convert("<h1>Hello</h1>").
|
11
|
-
Deface::Parser.convert("<h1>Hello</h1>").to_s.
|
12
|
-
Deface::Parser.convert("<title>Hello</title>").
|
13
|
-
Deface::Parser.convert("<title>Hello</title>").to_s.
|
10
|
+
expect(Deface::Parser.convert("<h1>Hello</h1>")).to be_an_instance_of(Nokogiri::HTML::DocumentFragment)
|
11
|
+
expect(Deface::Parser.convert("<h1>Hello</h1>").to_s).to eq("<h1>Hello</h1>")
|
12
|
+
expect(Deface::Parser.convert("<title>Hello</title>")).to be_an_instance_of(Nokogiri::HTML::DocumentFragment)
|
13
|
+
expect(Deface::Parser.convert("<title>Hello</title>").to_s).to eq("<title>Hello</title>")
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should parse html document" do
|
17
17
|
parsed = Deface::Parser.convert("<html><head><title>Hello</title></head><body>test</body>")
|
18
|
-
parsed.
|
18
|
+
expect(parsed).to be_an_instance_of(Nokogiri::HTML::Document)
|
19
19
|
parsed = parsed.to_s.split("\n")
|
20
20
|
|
21
21
|
unless RUBY_PLATFORM == 'java'
|
@@ -24,15 +24,15 @@ module Deface
|
|
24
24
|
|
25
25
|
#accounting for qwerks in Nokogir between ruby versions / platforms
|
26
26
|
if RUBY_PLATFORM == 'java'
|
27
|
-
parsed.
|
27
|
+
expect(parsed).to eq(["<html><head><title>Hello</title></head><body>test</body></html>"])
|
28
28
|
elsif RUBY_VERSION < "1.9"
|
29
|
-
parsed.
|
29
|
+
expect(parsed).to eq("<html>\n<head><title>Hello</title></head>\n<body>test</body>\n</html>".split("\n"))
|
30
30
|
else
|
31
|
-
parsed.
|
31
|
+
expect(parsed).to eq("<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>Hello</title>\n</head>\n<body>test</body>\n</html>".split("\n"))
|
32
32
|
end
|
33
33
|
|
34
34
|
parsed = Deface::Parser.convert("<html><title>test</title></html>")
|
35
|
-
parsed.
|
35
|
+
expect(parsed).to be_an_instance_of(Nokogiri::HTML::Document)
|
36
36
|
parsed = parsed.to_s.split("\n")
|
37
37
|
|
38
38
|
unless RUBY_PLATFORM == 'java'
|
@@ -41,88 +41,88 @@ module Deface
|
|
41
41
|
|
42
42
|
#accounting for qwerks in Nokogir between ruby versions / platforms
|
43
43
|
if RUBY_VERSION < "1.9" || RUBY_PLATFORM == 'java'
|
44
|
-
parsed.
|
44
|
+
expect(parsed).to eq(["<html><head><title>test</title></head></html>"])
|
45
45
|
else
|
46
|
-
parsed.
|
46
|
+
expect(parsed).to eq("<html><head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>test</title>\n</head></html>".split("\n"))
|
47
47
|
end
|
48
48
|
|
49
49
|
parsed = Deface::Parser.convert("<html><p>test</p></html>")
|
50
|
-
parsed.
|
50
|
+
expect(parsed).to be_an_instance_of(Nokogiri::HTML::Document)
|
51
51
|
parsed = parsed.to_s.split("\n")
|
52
52
|
|
53
53
|
if RUBY_PLATFORM == 'java'
|
54
|
-
parsed.
|
54
|
+
expect(parsed).to eq ["<html><head></head><body><p>test</p></body></html>"]
|
55
55
|
else
|
56
56
|
parsed = parsed[1..-1]
|
57
|
-
parsed.
|
57
|
+
expect(parsed).to eq ["<html><body><p>test</p></body></html>"]
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
# Regression test for #84, #100
|
62
62
|
it "should parse html document with erb in the head" do
|
63
63
|
parsed = Deface::Parser.convert("<html><head><%= method_name %></head><body></body></html>")
|
64
|
-
parsed.
|
64
|
+
expect(parsed).to be_an_instance_of(Nokogiri::HTML::Document)
|
65
65
|
parsed = parsed.to_s.split("\n")
|
66
66
|
|
67
67
|
if RUBY_PLATFORM == 'java'
|
68
|
-
parsed.
|
68
|
+
expect(parsed).to eq(["<html><head><erb loud=\"\"> method_name </erb></head><body></body></html>"])
|
69
69
|
else
|
70
70
|
parsed = parsed[1..-1]
|
71
|
-
parsed.
|
71
|
+
expect(parsed).to eq("<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<erb loud> method_name </erb>\n</head>\n<body></body>\n</html>".split("\n"))
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should parse body tag" do
|
76
76
|
tag = Deface::Parser.convert("<body id=\"body\" <%= something %>>test</body>")
|
77
|
-
tag.
|
78
|
-
tag.text.
|
79
|
-
tag.attributes['id'].value.
|
80
|
-
tag.attributes['data-erb-0'].value.
|
77
|
+
expect(tag).to be_an_instance_of(Nokogiri::XML::Element)
|
78
|
+
expect(tag.text).to eq 'test'
|
79
|
+
expect(tag.attributes['id'].value).to eq 'body'
|
80
|
+
expect(tag.attributes['data-erb-0'].value).to eq '<%= something %>'
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should convert <% ... %>" do
|
84
84
|
tag = Deface::Parser.convert("<% method_name %>")
|
85
85
|
tag = tag.css('erb').first
|
86
|
-
tag.attributes['silent'].value.
|
86
|
+
expect(tag.attributes['silent'].value).to eq ''
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should convert <%= ... %>" do
|
90
90
|
tag = Deface::Parser.convert("<%= method_name %>")
|
91
91
|
tag = tag.css('erb').first
|
92
|
-
tag.attributes['loud'].value.
|
92
|
+
expect(tag.attributes['loud'].value).to eq ''
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should convert first <% ... %> inside html tag" do
|
96
|
-
Deface::Parser.convert("<p <% method_name %>></p>").to_s.
|
96
|
+
expect(Deface::Parser.convert("<p <% method_name %>></p>").to_s).to eq("<p data-erb-0=\"<% method_name %>\"></p>")
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should convert second <% ... %> inside html tag" do
|
100
|
-
Deface::Parser.convert("<p <% method_name %> <% x = y %>></p>").to_s.
|
100
|
+
expect(Deface::Parser.convert("<p <% method_name %> <% x = y %>></p>").to_s).to eq("<p data-erb-0=\"<% method_name %>\" data-erb-1=\"<% x = y %>\"></p>")
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should convert <% ... %> inside double quoted attr value" do
|
104
|
-
Deface::Parser.convert("<p id=\"<% method_name %>\"></p>").to_s.
|
104
|
+
expect(Deface::Parser.convert("<p id=\"<% method_name %>\"></p>").to_s).to eq("<p data-erb-id=\"<% method_name %>\"></p>")
|
105
105
|
end
|
106
106
|
|
107
107
|
if RUBY_PLATFORM == 'java'
|
108
108
|
it "should convert <% ... %> contains double quoted value" do
|
109
|
-
Deface::Parser.convert("<p <% method_name \"test\" %>></p>").to_s.
|
109
|
+
expect(Deface::Parser.convert("<p <% method_name \"test\" %>></p>").to_s).to eq("<p data-erb-0=\"<% method_name %22test%22 %>\"></p>")
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should convert <% ... %> inside single quoted attr value" do
|
114
|
-
Deface::Parser.convert("<p id='<% method_name %>'></p>").to_s.
|
114
|
+
expect(Deface::Parser.convert("<p id='<% method_name %>'></p>").to_s).to eq("<p data-erb-id=\"<% method_name %>\"></p>")
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should convert <% ... %> inside non-quoted attr value" do
|
118
118
|
tag = Deface::Parser.convert("<p id=<% method_name %>></p>")
|
119
119
|
tag = tag.css('p').first
|
120
|
-
tag.attributes['data-erb-id'].value.
|
120
|
+
expect(tag.attributes['data-erb-id'].value).to eq '<% method_name %>'
|
121
121
|
|
122
122
|
tag = Deface::Parser.convert("<p id=<% method_name %> alt=\"test\"></p>")
|
123
123
|
tag = tag.css('p').first
|
124
|
-
tag.attributes['data-erb-id'].value.
|
125
|
-
tag.attributes['alt'].value.
|
124
|
+
expect(tag.attributes['data-erb-id'].value).to eq '<% method_name %>'
|
125
|
+
expect(tag.attributes['alt'].value).to eq 'test'
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should convert multiple <% ... %> inside html tag" do
|
@@ -130,88 +130,88 @@ module Deface
|
|
130
130
|
\"2\" %>" title='<% method_name %>' <%= other_method %></p>})
|
131
131
|
|
132
132
|
tag = tag.css('p').first
|
133
|
-
tag.attributes['data-erb-0'].value.
|
134
|
-
tag.attributes['data-erb-1'].value.
|
135
|
-
tag.attributes['data-erb-alt'].value.
|
136
|
-
tag.attributes['data-erb-title'].value.
|
133
|
+
expect(tag.attributes['data-erb-0'].value).to eq("<%= method_name %>")
|
134
|
+
expect(tag.attributes['data-erb-1'].value).to eq("<%= other_method %>")
|
135
|
+
expect(tag.attributes['data-erb-alt'].value).to eq("<% x = 'y' + \n \\\"2\\\" %>")
|
136
|
+
expect(tag.attributes['data-erb-title'].value).to eq("<% method_name %>")
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should convert <%= ... %> including href attribute" do
|
140
140
|
tag = Deface::Parser.convert(%(<a href="<%= x 'y' + "z" %>">A Link</a>))
|
141
141
|
tag = tag.css('a').first
|
142
|
-
tag.attributes['data-erb-href'].value.
|
143
|
-
tag.text.
|
142
|
+
expect(tag.attributes['data-erb-href'].value).to eq "<%= x 'y' + \"z\" %>"
|
143
|
+
expect(tag.text).to eq 'A Link'
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should escape contents erb tags" do
|
147
147
|
tag = Deface::Parser.convert("<% method_name :key => 'value' %>")
|
148
148
|
tag = tag.css('erb').first
|
149
|
-
tag.attributes.key?('silent').
|
150
|
-
tag.text.
|
149
|
+
expect(tag.attributes.key?('silent')).to be_truthy
|
150
|
+
expect(tag.text).to eq " method_name :key => 'value' "
|
151
151
|
end
|
152
152
|
|
153
153
|
it "should handle round brackets in erb tags" do
|
154
154
|
# commented out line below will fail as : adjacent to ( causes Nokogiri parser issue on jruby
|
155
155
|
tag = Deface::Parser.convert("<% method_name(:key => 'value') %>")
|
156
156
|
tag = tag.css('erb').first
|
157
|
-
tag.attributes.key?('silent').
|
158
|
-
tag.text.
|
157
|
+
expect(tag.attributes.key?('silent')).to be_truthy
|
158
|
+
expect(tag.text).to eq " method_name(:key => 'value') "
|
159
159
|
|
160
160
|
tag = Deface::Parser.convert("<% method_name( :key => 'value' ) %>")
|
161
161
|
tag = tag.css('erb').first
|
162
|
-
tag.attributes.key?('silent').
|
163
|
-
tag.text.
|
162
|
+
expect(tag.attributes.key?('silent')).to be_truthy
|
163
|
+
expect(tag.text).to eq " method_name( :key => 'value' ) "
|
164
164
|
end
|
165
165
|
|
166
166
|
it "should respect valid encoding tag" do
|
167
167
|
source = %q{<%# encoding: ISO-8859-1 %>Can you say ümlaut?}
|
168
168
|
Deface::Parser.convert(source)
|
169
|
-
source.encoding.name.
|
169
|
+
expect(source.encoding.name).to eq('ISO-8859-1')
|
170
170
|
end
|
171
171
|
|
172
172
|
it "should force default encoding" do
|
173
173
|
source = %q{Can you say ümlaut?}
|
174
174
|
source.force_encoding('ISO-8859-1')
|
175
175
|
Deface::Parser.convert(source)
|
176
|
-
source.encoding.
|
176
|
+
expect(source.encoding).to eq(Encoding.default_external)
|
177
177
|
end
|
178
178
|
|
179
179
|
it "should force default encoding" do
|
180
180
|
source = %q{<%# encoding: US-ASCII %>Can you say ümlaut?}
|
181
|
-
|
181
|
+
expect { Deface::Parser.convert(source) }.to raise_error(ActionView::WrongEncodingError)
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
185
185
|
describe "#undo_erb_markup" do
|
186
186
|
it "should revert <erb silent>" do
|
187
|
-
Deface::Parser.undo_erb_markup!("<erb silent> method_name </erb>").
|
187
|
+
expect(Deface::Parser.undo_erb_markup!("<erb silent> method_name </erb>")).to eq("<% method_name %>")
|
188
188
|
end
|
189
189
|
|
190
190
|
it "should revert <erb loud>" do
|
191
|
-
Deface::Parser.undo_erb_markup!("<erb loud> method_name </erb>").
|
191
|
+
expect(Deface::Parser.undo_erb_markup!("<erb loud> method_name </erb>")).to eq("<%= method_name %>")
|
192
192
|
end
|
193
193
|
|
194
194
|
it "should revert data-erb-x attrs inside html tag" do
|
195
|
-
Deface::Parser.undo_erb_markup!("<p data-erb-0=\"<% method_name %>\" data-erb-1=\"<% x = y %>\"></p>").
|
195
|
+
expect(Deface::Parser.undo_erb_markup!("<p data-erb-0=\"<% method_name %>\" data-erb-1=\"<% x = y %>\"></p>")).to eq("<p <% method_name %> <% x = y %>></p>")
|
196
196
|
end
|
197
197
|
|
198
198
|
it "should revert data-erb-id attr inside html tag" do
|
199
|
-
Deface::Parser.undo_erb_markup!("<p data-erb-id=\"<% method_name > 1 %>\"></p>").
|
199
|
+
expect(Deface::Parser.undo_erb_markup!("<p data-erb-id=\"<% method_name > 1 %>\"></p>")).to eq("<p id=\"<% method_name > 1 %>\"></p>")
|
200
200
|
end
|
201
201
|
|
202
202
|
it "should revert data-erb-href attr inside html tag" do
|
203
|
-
Deface::Parser.undo_erb_markup!("<a data-erb-href=\"<%= x 'y' + "z" %>\">A Link</a>").
|
203
|
+
expect(Deface::Parser.undo_erb_markup!("<a data-erb-href=\"<%= x 'y' + "z" %>\">A Link</a>")).to eq(%(<a href="<%= x 'y' + \"z\" %>">A Link</a>))
|
204
204
|
end
|
205
205
|
|
206
206
|
if RUBY_PLATFORM == 'java'
|
207
207
|
it "should revert data-erb-x containing double quoted value" do
|
208
|
-
Deface::Parser.undo_erb_markup!("<p data-erb-0=\"<% method_name %22test%22 %>\"></p>").
|
208
|
+
expect(Deface::Parser.undo_erb_markup!("<p data-erb-0=\"<% method_name %22test%22 %>\"></p>")).to eq(%(<p <% method_name \"test\" %>></p>))
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
212
212
|
it "should unescape contents of erb tags" do
|
213
|
-
Deface::Parser.undo_erb_markup!("<% method(:key => 'value' %>").
|
214
|
-
Deface::Parser.undo_erb_markup!("<% method(:key => 'value'\n %>").
|
213
|
+
expect(Deface::Parser.undo_erb_markup!("<% method(:key => 'value' %>")).to eq("<% method(:key => 'value' %>")
|
214
|
+
expect(Deface::Parser.undo_erb_markup!("<% method(:key => 'value'\n %>")).to eq("<% method(:key => 'value'\n %>")
|
215
215
|
end
|
216
216
|
|
217
217
|
end
|
@@ -10,14 +10,14 @@ module Deface
|
|
10
10
|
FileUtils.rm_rf('spec/dummy/app/compiled_views')
|
11
11
|
environment = Deface::Environment.new
|
12
12
|
overrides = Deface::Environment::Overrides.new
|
13
|
-
overrides.
|
14
|
-
overrides.
|
15
|
-
environment.
|
13
|
+
allow(overrides).to receive_messages(:all => {}) # need to do this before creating an override
|
14
|
+
allow(overrides).to receive_messages(:all => {"posts/precompileme".to_sym => {"precompileme".parameterize => Deface::Override.new(:virtual_path => "posts/precompileme", :name => "precompileme", :insert_bottom => 'li', :text => "Added to li!")}})
|
15
|
+
allow(environment).to receive_messages(:overrides => overrides)
|
16
16
|
|
17
|
-
Rails.application.config.
|
17
|
+
allow(Rails.application.config).to receive_messages :deface => environment
|
18
18
|
|
19
19
|
#stub view paths to be local spec/assets directory
|
20
|
-
ActionController::Base.
|
20
|
+
allow(ActionController::Base).to receive(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
|
21
21
|
|
22
22
|
Precompiler.precompile()
|
23
23
|
end
|
@@ -31,12 +31,12 @@ module Deface
|
|
31
31
|
|
32
32
|
filename = 'spec/dummy/app/compiled_views/posts/precompileme.html.erb'
|
33
33
|
|
34
|
-
File.exists?(filename).
|
34
|
+
expect(File.exists?(filename)).to be_truthy
|
35
35
|
|
36
36
|
file = File.open(filename, "rb")
|
37
37
|
contents = file.read
|
38
38
|
|
39
|
-
contents.
|
39
|
+
expect(contents).to match(/precompile/)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/spec/deface/search_spec.rb
CHANGED
@@ -11,14 +11,14 @@ module Deface
|
|
11
11
|
|
12
12
|
describe "#find" do
|
13
13
|
it "should find by virtual_path" do
|
14
|
-
Deface::Override.find({:virtual_path => "posts/index"}).size.
|
15
|
-
Deface::Override.find({:virtual_path => "/posts/index"}).size.
|
16
|
-
Deface::Override.find({:virtual_path => "/posts/index.html"}).size.
|
17
|
-
Deface::Override.find({:virtual_path => "posts/index.html"}).size.
|
14
|
+
expect(Deface::Override.find({:virtual_path => "posts/index"}).size).to eq(1)
|
15
|
+
expect(Deface::Override.find({:virtual_path => "/posts/index"}).size).to eq(1)
|
16
|
+
expect(Deface::Override.find({:virtual_path => "/posts/index.html"}).size).to eq(1)
|
17
|
+
expect(Deface::Override.find({:virtual_path => "posts/index.html"}).size).to eq(1)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should return empty array when no details hash passed" do
|
21
|
-
Deface::Override.find({}).
|
21
|
+
expect(Deface::Override.find({})).to eq([])
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -32,8 +32,8 @@ module Deface
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should find by virtual_path" do
|
35
|
-
Deface::Override.find_using("shared/post").size.
|
36
|
-
Deface::Override.find_using("shared/person").size.
|
35
|
+
expect(Deface::Override.find_using("shared/post").size).to eq(1)
|
36
|
+
expect(Deface::Override.find_using("shared/person").size).to eq(1)
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
describe SlimConverter do
|
5
|
+
include_context "mock Rails.application"
|
6
|
+
|
7
|
+
def slim_to_erb(src)
|
8
|
+
conv = Deface::SlimConverter.new(src)
|
9
|
+
conv.result.gsub("\n", "")
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "convert slim to erb" do
|
13
|
+
it "should hanlde simple tags" do
|
14
|
+
expect(slim_to_erb('div class="some" id="message"= "Hi, World!"')).to eq("<div class=\"some\" id=\"message\"><%= ::Temple::Utils.escape_html_safe((\"Hi, World!\")) %></div>")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should handle complex tags" do
|
18
|
+
expect(slim_to_erb(%q{nav#top-nav-bar
|
19
|
+
ul#nav-bar.inline data-hook=''
|
20
|
+
- if true
|
21
|
+
.nav-links.high_res
|
22
|
+
li.dropdown
|
23
|
+
.welcome Welcome #{Spree::User.first.email} ▾
|
24
|
+
ul.dropdown
|
25
|
+
li = link_to 'Account', account_path
|
26
|
+
li = link_to 'Log out', logout_path
|
27
|
+
})).to eq("<nav id=\"top-nav-bar\"><ul class=\"inline\" data-hook=\"\" id=\"nav-bar\"><% if true %><div class=\"nav-links high_res\"><li class=\"dropdown\"><div class=\"welcome\">Welcome <%= ::Temple::Utils.escape_html_safe((Spree::User.first.email)) %> ▾</div><ul class=\"dropdown\"><li><%= ::Temple::Utils.escape_html_safe((link_to 'Account', account_path)) %></li><li><%= ::Temple::Utils.escape_html_safe((link_to 'Log out', logout_path)) %></li></ul></li></div><% end %></ul></nav>")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -8,41 +8,40 @@ module Deface
|
|
8
8
|
describe "load_template_source" do
|
9
9
|
before do
|
10
10
|
#stub view paths to be local spec/assets directory
|
11
|
-
ActionController::Base.
|
11
|
+
allow(ActionController::Base).to receive(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "with no overrides defined" do
|
15
15
|
it "should return source for partial" do
|
16
|
-
load_template_source("shared/post", true).
|
16
|
+
expect(load_template_source("shared/post", true)).to eq "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should return converted source for partial containing haml" do
|
20
|
-
load_template_source("shared/hello", true).
|
20
|
+
expect(load_template_source("shared/hello", true)).to eq "<div class='<%= @some %>' id='message'><%= 'Hello, World!' %>\n</div>\n"
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should return converted source for partial containing slim" do
|
24
|
-
load_template_source("shared/hi", true).
|
24
|
+
expect(load_template_source("shared/hi", true)).to eq "<div class=\"some\" id=\"message\"><%= ::Temple::Utils.escape_html_safe((\"Hi, World!\")) %>\n</div>"
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should return source for template" do
|
28
|
-
load_template_source("shared/person", false).
|
28
|
+
expect(load_template_source("shared/person", false)).to eq "<p>I'm from shared/person template</p>\n<%= \"I've got ERB too\" %>\n"
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should return converted source for template containing haml" do
|
32
|
-
load_template_source("shared/pirate", false).gsub(/\s/, '').
|
32
|
+
expect(load_template_source("shared/pirate", false).gsub(/\s/, '')).to eq "<divid='content'><divclass='left'><p><%=print_information%></p></div><divclass='right'id='<%=@right%>'><%=render:partial=>\"sidebar\"%></div></div>"
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should return converted source for template containing slim" do
|
36
|
-
|
37
|
-
load_template_source("shared/public", false).gsub(/\s/, '').should == result
|
36
|
+
expect(load_template_source("shared/public", false).gsub(/\s/, '')).to include('print_information')
|
38
37
|
end
|
39
38
|
|
40
39
|
it "should return source for namespaced template" do
|
41
|
-
load_template_source("admin/posts/index", false).
|
40
|
+
expect(load_template_source("admin/posts/index", false)).to eq "<h1>Manage Posts</h1>\n"
|
42
41
|
end
|
43
42
|
|
44
43
|
it "should raise exception for non-existing file" do
|
45
|
-
|
44
|
+
expect { load_template_source("tester/post", true) }.to raise_error(ActionView::MissingTemplate)
|
46
45
|
end
|
47
46
|
|
48
47
|
end
|
@@ -55,40 +54,40 @@ module Deface
|
|
55
54
|
Deface::Override.new(:virtual_path => "shared/person", :name => "shared#person", :replace => "p", :text => "<h1>Argh!</h1>")
|
56
55
|
Deface::Override.new(:virtual_path => "shared/_hello", :name => "shared#hello", :replace_contents => "div#message", :text => "<%= 'Goodbye World!' %>")
|
57
56
|
Deface::Override.new(:virtual_path => "shared/pirate", :name => "shared#pirate", :replace => "p", :text => "<h1>Argh!</h1>")
|
57
|
+
Deface::Override.new(:virtual_path => "shared/public", :name => "shared#public", :replace => "p", :text => "<h1>Ahoy!</h1>")
|
58
58
|
Deface::Override.new(:virtual_path => "admin/posts/index", :name => "admin#posts#index", :replace => "h1", :text => "<h1>Argh!</h1>")
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should return overridden source for partial including overrides" do
|
62
|
-
load_template_source("shared/post", true).
|
62
|
+
expect(load_template_source("shared/post", true).strip).to eq "<%= \"And I've got ERB\" %>"
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should return converted and overridden source for partial containing haml" do
|
66
|
-
load_template_source("shared/hello", true).
|
66
|
+
expect(load_template_source("shared/hello", true).strip).to eq "<div class=\"<%= @some %>\" id=\"message\"><%= 'Goodbye World!' %></div>"
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should return converted and overridden source for partial containing slim" do
|
70
|
-
load_template_source("shared/hi", true).
|
70
|
+
expect(load_template_source("shared/hi", true)).to eq "<div class=\"some\" id=\"message\"><%= ::Temple::Utils.escape_html_safe((\"Hi, World!\")) %>\n</div>"
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should return overridden source for partial excluding overrides" do
|
74
|
-
load_template_source("shared/post", true, false).
|
74
|
+
expect(load_template_source("shared/post", true, false)).to eq "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should return overridden source for template including overrides" do
|
78
|
-
load_template_source("shared/person", false).
|
78
|
+
expect(load_template_source("shared/person", false).strip).to eq "<h1>Argh!</h1>\n<%= \"I've got ERB too\" %>"
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should return converted and overridden source for template containing haml" do
|
82
|
-
load_template_source("shared/pirate", false).gsub(/\s/, '').
|
82
|
+
expect(load_template_source("shared/pirate", false).gsub(/\s/, '')).to eq "<divid=\"content\"><divclass=\"left\"><h1>Argh!</h1></div><divclass=\"right\"id=\"<%=@right%>\"><%=render:partial=>\"sidebar\"%></div></div>"
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should return converted and overridden source for template containing slim" do
|
86
|
-
|
87
|
-
load_template_source("shared/public", false).gsub(/\s/, '').should == result
|
86
|
+
expect(load_template_source("shared/public", false).gsub(/\s/, '')).to include("<h1>Ahoy!</h1>")
|
88
87
|
end
|
89
88
|
|
90
89
|
it "should return source for namespaced template including overrides" do
|
91
|
-
load_template_source("admin/posts/index", false).
|
90
|
+
expect(load_template_source("admin/posts/index", false).strip).to eq "<h1>Argh!</h1>"
|
92
91
|
end
|
93
92
|
|
94
93
|
end
|
@@ -97,12 +96,12 @@ module Deface
|
|
97
96
|
|
98
97
|
describe "element_source" do
|
99
98
|
it "should return array of matches elements" do
|
100
|
-
element_source('<div><p class="pirate">Arrgh!</p><img src="/some/image.jpg"></div>', 'p.pirate').map(&:strip).
|
101
|
-
element_source('<div><p class="pirate">Arrgh!</p><p>No pirates here...</p></div>', 'p').map(&:strip).
|
99
|
+
expect(element_source('<div><p class="pirate">Arrgh!</p><img src="/some/image.jpg"></div>', 'p.pirate').map(&:strip)).to eq ["<p class=\"pirate\">Arrgh!</p>"]
|
100
|
+
expect(element_source('<div><p class="pirate">Arrgh!</p><p>No pirates here...</p></div>', 'p').map(&:strip)).to eq ["<p class=\"pirate\">Arrgh!</p>", "<p>No pirates here...</p>"]
|
102
101
|
end
|
103
102
|
|
104
103
|
it "should return empty array for no matches" do
|
105
|
-
element_source('<div><p class="pirate">Arrgh!</p><img src="/some/image.jpg"></div>', 'span').
|
104
|
+
expect(element_source('<div><p class="pirate">Arrgh!</p><img src="/some/image.jpg"></div>', 'span')).to eq []
|
106
105
|
end
|
107
106
|
end
|
108
107
|
end
|