mbrao 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/CHANGELOG.md +5 -0
  4. data/doc/ActionView/Template/Handlers/MbraoTemplate.html +87 -20
  5. data/doc/ActionView/Template/Handlers.html +1 -1
  6. data/doc/HTML/Pipeline/KramdownFilter.html +1 -1
  7. data/doc/HTML/Pipeline.html +1 -1
  8. data/doc/HTML.html +1 -1
  9. data/doc/Mbrao/Author.html +337 -67
  10. data/doc/Mbrao/Content.html +1268 -444
  11. data/doc/Mbrao/ContentPublicInterface.html +24 -20
  12. data/doc/Mbrao/Exceptions/InvalidDate.html +1 -1
  13. data/doc/Mbrao/Exceptions/InvalidMetadata.html +1 -1
  14. data/doc/Mbrao/Exceptions/Parsing.html +1 -1
  15. data/doc/Mbrao/Exceptions/Rendering.html +1 -1
  16. data/doc/Mbrao/Exceptions/UnavailableLocalization.html +1 -1
  17. data/doc/Mbrao/Exceptions/Unimplemented.html +1 -1
  18. data/doc/Mbrao/Exceptions/UnknownEngine.html +1 -1
  19. data/doc/Mbrao/Exceptions.html +1 -1
  20. data/doc/Mbrao/Parser.html +11 -11
  21. data/doc/Mbrao/ParsingEngines/Base.html +25 -24
  22. data/doc/Mbrao/ParsingEngines/PlainText.html +17 -16
  23. data/doc/Mbrao/ParsingEngines.html +1 -1
  24. data/doc/Mbrao/PublicInterface/ClassMethods.html +312 -19
  25. data/doc/Mbrao/PublicInterface.html +1 -1
  26. data/doc/Mbrao/RenderingEngines/Base.html +7 -7
  27. data/doc/Mbrao/RenderingEngines/HtmlPipeline.html +27 -15
  28. data/doc/Mbrao/RenderingEngines.html +1 -1
  29. data/doc/Mbrao/Validations/ClassMethods.html +21 -21
  30. data/doc/Mbrao/Validations.html +1 -1
  31. data/doc/Mbrao/Version.html +3 -3
  32. data/doc/Mbrao.html +1 -1
  33. data/doc/_index.html +1 -1
  34. data/doc/file.README.html +1 -1
  35. data/doc/index.html +1 -1
  36. data/doc/method_list.html +86 -62
  37. data/doc/top-level-namespace.html +1 -1
  38. data/lib/mbrao/author.rb +18 -4
  39. data/lib/mbrao/content.rb +93 -44
  40. data/lib/mbrao/integrations/rails.rb +12 -5
  41. data/lib/mbrao/parser.rb +23 -0
  42. data/lib/mbrao/parsing_engines/base.rb +12 -11
  43. data/lib/mbrao/parsing_engines/plain_text.rb +29 -23
  44. data/lib/mbrao/rendering_engines/base.rb +4 -4
  45. data/lib/mbrao/rendering_engines/html_pipeline.rb +7 -2
  46. data/lib/mbrao/version.rb +2 -2
  47. data/spec/mbrao/author_spec.rb +32 -16
  48. data/spec/mbrao/content_spec.rb +144 -85
  49. data/spec/mbrao/integrations/rails_spec.rb +14 -0
  50. data/spec/mbrao/parser_spec.rb +19 -19
  51. data/spec/mbrao/parsing_engines/base_spec.rb +12 -12
  52. data/spec/mbrao/parsing_engines/plain_text_spec.rb +21 -21
  53. data/spec/mbrao/rendering_engines/base_spec.rb +2 -2
  54. data/spec/mbrao/rendering_engines/html_pipeline_spec.rb +31 -31
  55. metadata +2 -2
@@ -7,39 +7,39 @@
7
7
  require "spec_helper"
8
8
 
9
9
  describe Mbrao::Content do
10
- let(:reference) { Mbrao::Content.new("UID") }
10
+ subject { Mbrao::Content.new("UID") }
11
11
 
12
12
  describe "#initialize" do
13
13
  it "store the uid" do
14
- reference = Mbrao::Content.new("SAMPLE")
15
- expect(reference.uid).to eq("SAMPLE")
14
+ subject = Mbrao::Content.new("SAMPLE")
15
+ expect(subject.uid).to eq("SAMPLE")
16
16
  end
17
17
  end
18
18
 
19
19
  describe "#locales=" do
20
20
  it "correctly assign a string, a symbol or an array" do
21
- reference.locales = :it
22
- expect(reference.locales).to eq(["it"])
23
- reference.locales = "en"
24
- expect(reference.locales).to eq(["en"])
25
- reference.locales = ["en", [:it, :es]]
26
- expect(reference.locales).to eq(["en", "it", "es"])
21
+ subject.locales = :it
22
+ expect(subject.locales).to eq(["it"])
23
+ subject.locales = "en"
24
+ expect(subject.locales).to eq(["en"])
25
+ subject.locales = ["en", [:it, :es]]
26
+ expect(subject.locales).to eq(["en", "it", "es"])
27
27
  end
28
28
  end
29
29
 
30
30
  shared_examples_for("localized setter") do |attribute|
31
31
  it "should assign a single string" do
32
- reference.send("#{attribute}=", "ABC")
33
- expect(reference.send(attribute)).to eq("ABC")
34
- reference.send("#{attribute}=", 1)
35
- expect(reference.send(attribute)).to eq("1")
36
- reference.send("#{attribute}=", nil)
37
- expect(reference.send(attribute)).to eq("")
32
+ subject.send("#{attribute}=", "ABC")
33
+ expect(subject.send(attribute)).to eq("ABC")
34
+ subject.send("#{attribute}=", 1)
35
+ expect(subject.send(attribute)).to eq("1")
36
+ subject.send("#{attribute}=", nil)
37
+ expect(subject.send(attribute)).to eq("")
38
38
  end
39
39
 
40
40
  it "should assign a string with locales and sanitized entries" do
41
- reference.send("#{attribute}=", {en: nil, es: "ABC", it: 1})
42
- value = reference.send(attribute)
41
+ subject.send("#{attribute}=", {en: nil, es: "ABC", it: 1})
42
+ value = subject.send(attribute)
43
43
  expect(value).to be_a(::HashWithIndifferentAccess)
44
44
  expect(value["en"]).to eq("")
45
45
  expect(value[:es]).to eq("ABC")
@@ -49,80 +49,80 @@ describe Mbrao::Content do
49
49
 
50
50
  shared_examples_for("localized getter") do |attribute, v1, v2|
51
51
  it "should raise an exception if not available for that locale" do
52
- reference.locales = [:en, :it, :es]
53
- reference.send("#{attribute}=", v1)
54
- expect { reference.send("get_#{attribute}", [:de, :it]) }.not_to raise_error
55
- expect { reference.send("get_#{attribute}", [:de]) }.to raise_error(Mbrao::Exceptions::UnavailableLocalization)
52
+ subject.locales = [:en, :it, :es]
53
+ subject.send("#{attribute}=", v1)
54
+ expect { subject.send("get_#{attribute}", [:de, :it]) }.not_to raise_error
55
+ expect { subject.send("get_#{attribute}", [:de]) }.to raise_error(Mbrao::Exceptions::UnavailableLocalization)
56
56
  end
57
57
 
58
58
  it "should return the attribute itself if not localized" do
59
- reference.locales = [:en, :it, :es]
60
- reference.send("#{attribute}=", v1)
61
- expect(reference.send("get_#{attribute}", [:de, :it])).to eq(v1)
59
+ subject.locales = [:en, :it, :es]
60
+ subject.send("#{attribute}=", v1)
61
+ expect(subject.send("get_#{attribute}", [:de, :it])).to eq(v1)
62
62
  end
63
63
 
64
64
  it "should return the default locale if no locales are specified" do
65
65
  Mbrao::Parser.locale = :it
66
- reference.send("#{attribute}=", {en: v1, it: v2})
67
- expect(reference.send("get_#{attribute}")).to eq(v2)
66
+ subject.send("#{attribute}=", {en: v1, it: v2})
67
+ expect(subject.send("get_#{attribute}")).to eq(v2)
68
68
  end
69
69
 
70
70
  it "should return only the subset of valid and request locales" do
71
71
  Mbrao::Parser.locale = :it
72
- reference.send("#{attribute}=", {en: v1, it: v2, de: v1, es: v2})
72
+ subject.send("#{attribute}=", {en: v1, it: v2, de: v1, es: v2})
73
73
 
74
- value = reference.send("get_#{attribute}", [:de, :es])
74
+ value = subject.send("get_#{attribute}", [:de, :es])
75
75
  expect(value).to be_a(::HashWithIndifferentAccess)
76
76
  expect(value.keys).to eq(["de", "es"])
77
77
 
78
- value = reference.send("get_#{attribute}", [:it, :de, :pt, :fr])
78
+ value = subject.send("get_#{attribute}", [:it, :de, :pt, :fr])
79
79
  expect(value.keys.sort).to eq(["de", "it"])
80
80
 
81
- reference.locales = [:en, :it, :es]
82
- value = reference.send("get_#{attribute}", "*")
81
+ subject.locales = [:en, :it, :es]
82
+ value = subject.send("get_#{attribute}", "*")
83
83
  expect(value.keys.sort).to eq(["de", "en", "es", "it"])
84
84
 
85
- reference.send("#{attribute}=", {en: v1, "it,es" => v2, " de, fr " => v1})
86
- value = reference.send("get_#{attribute}", [:it, :fr])
85
+ subject.send("#{attribute}=", {en: v1, "it,es" => v2, " de, fr " => v1})
86
+ value = subject.send("get_#{attribute}", [:it, :fr])
87
87
  expect(value.keys.sort).to eq(["fr", "it"])
88
88
  end
89
89
  end
90
90
 
91
91
  shared_examples_for("date setter") do |attribute|
92
92
  it "should correctly parse a datetime classes" do
93
- reference.send("#{attribute}=", Date.civil(2012, 8, 8))
94
- value = reference.send(attribute)
93
+ subject.send("#{attribute}=", Date.civil(2012, 8, 8))
94
+ value = subject.send(attribute)
95
95
  expect(value).to be_a(DateTime)
96
96
  expect(value.strftime("%Y%m%dT%H%M%S%z")).to eq("20120808T000000+0000")
97
97
 
98
- reference.send("#{attribute}=", DateTime.civil(2012, 8, 8, 11, 30, 45))
99
- value = reference.send(attribute)
98
+ subject.send("#{attribute}=", DateTime.civil(2012, 8, 8, 11, 30, 45))
99
+ value = subject.send(attribute)
100
100
  expect(value).to be_a(DateTime)
101
101
  expect(value.strftime("%Y%m%dT%H%M%S%z")).to eq("20120808T113045+0000")
102
102
 
103
103
  Time.zone = 'Europe/Rome'
104
104
  date = Time.at(1344421800)
105
- reference.send("#{attribute}=", date)
106
- value = reference.send(attribute)
105
+ subject.send("#{attribute}=", date)
106
+ value = subject.send(attribute)
107
107
  expect(value).to be_a(DateTime)
108
108
  expect(value.strftime("%Y%m%dT%H%M%S%z")).to eq("20120808T103000+0000")
109
109
  end
110
110
 
111
111
  it "should correctly parse a timestamp" do
112
- reference.send("#{attribute}=", 1344421800)
113
- value = reference.send(attribute)
112
+ subject.send("#{attribute}=", 1344421800)
113
+ value = subject.send(attribute)
114
114
  expect(value).to be_a(DateTime)
115
115
  expect(value.strftime("%Y%m%dT%H%M%S%z")).to eq("20120808T103000+0000")
116
116
  end
117
117
 
118
118
  it "should try to parse everything else as a ISO8601 format" do
119
- reference.send("#{attribute}=", "20120808T083000-0200")
120
- value = reference.send(attribute)
119
+ subject.send("#{attribute}=", "20120808T083000-0200")
120
+ value = subject.send(attribute)
121
121
  expect(value).to be_a(DateTime)
122
122
  expect(value.strftime("%Y%m%dT%H%M%S%z")).to eq("20120808T103000+0000")
123
123
 
124
- expect { reference.send("#{attribute}=", "ABC") }.to raise_error(Mbrao::Exceptions::InvalidDate)
125
- expect { reference.send("#{attribute}=", []) }.to raise_error(Mbrao::Exceptions::InvalidDate)
124
+ expect { subject.send("#{attribute}=", "ABC") }.to raise_error(Mbrao::Exceptions::InvalidDate)
125
+ expect { subject.send("#{attribute}=", []) }.to raise_error(Mbrao::Exceptions::InvalidDate)
126
126
  end
127
127
  end
128
128
 
@@ -132,31 +132,38 @@ describe Mbrao::Content do
132
132
 
133
133
  describe "#body=" do
134
134
  it "should set the content as string" do
135
- reference.body = "A"
136
- expect(reference.body).to eq("A")
137
- reference.body = 1
138
- expect(reference.body).to eq("1")
139
- reference.body = nil
140
- expect(reference.body).to eq("")
135
+ subject.body = "A"
136
+ expect(subject.body).to eq("A")
137
+ subject.body = 1
138
+ expect(subject.body).to eq("1")
139
+ subject.body = nil
140
+ expect(subject.body).to eq("")
141
141
  end
142
142
  end
143
143
 
144
144
  describe "#tags=" do
145
145
  it "should assign a single value" do
146
- reference.tags = "ABC"
147
- expect(reference.tags).to eq(["ABC"])
148
- reference.tags = ["ABC", [1, nil]]
149
- expect(reference.tags).to eq(["ABC", "1"])
146
+ subject.tags = "ABC"
147
+ expect(subject.tags).to eq(["ABC"])
148
+ subject.tags = ["ABC", [1, nil]]
149
+ expect(subject.tags).to eq(["ABC", "1"])
150
150
  end
151
151
 
152
152
  it "should assign values with locales and sanitized entries" do
153
- reference.tags = {en: nil, es: "ABC", it: [1, [2, 3]]}
154
- value = reference.tags
153
+ subject.tags = {en: nil, es: "ABC", it: [1, [2, 3]]}
154
+ value = subject.tags
155
155
  expect(value).to be_a(::HashWithIndifferentAccess)
156
156
  expect(value["en"]).to eq([])
157
157
  expect(value[:es]).to eq(["ABC"])
158
158
  expect(value["it"]).to eq(["1", "2", "3"])
159
159
  end
160
+
161
+ it "should split, flatten and uniquize tags" do
162
+ subject.tags = ["1", ["2", "3"], "3, 4,5"]
163
+ expect(subject.tags).to eq(["1","2","3","4","5"])
164
+ subject.tags = "1,2,3,4,5"
165
+ expect(subject.tags).to eq(["1","2","3","4","5"])
166
+ end
160
167
  end
161
168
 
162
169
  describe "#more=" do
@@ -166,26 +173,26 @@ describe Mbrao::Content do
166
173
  describe "#author=" do
167
174
  it "should assign an existing author" do
168
175
  author = ::Mbrao::Author.new("NAME")
169
- reference.author = author
170
- expect(reference.author).to be(author)
176
+ subject.author = author
177
+ expect(subject.author).to be(author)
171
178
  end
172
179
 
173
180
  it "should only assign a name" do
174
- reference.author = "NAME"
175
- expect(reference.author).to be_a(::Mbrao::Author)
176
- expect(reference.author.name).to eq("NAME")
181
+ subject.author = "NAME"
182
+ expect(subject.author).to be_a(::Mbrao::Author)
183
+ expect(subject.author.name).to eq("NAME")
177
184
  end
178
185
 
179
186
  it "should assign by an hash" do
180
- reference.author = {name: "NAME", email: "EMAIL@email.com", "website" => "http://WEBSITE.TLD", "image" => "http://IMAGE.TLD", metadata: {a: "b"}, uid: "UID"}
181
- expect(reference.author).to be_a(::Mbrao::Author)
182
- expect(reference.author.name).to eq("NAME")
183
- expect(reference.author.email).to eq("EMAIL@email.com")
184
- expect(reference.author.website).to eq("http://WEBSITE.TLD")
185
- expect(reference.author.image).to eq("http://IMAGE.TLD")
186
- expect(reference.author.metadata).to be_a(::HashWithIndifferentAccess)
187
- expect(reference.author.metadata["a"]).to eq("b")
188
- expect(reference.author.uid).to eq("UID")
187
+ subject.author = {name: "NAME", email: "EMAIL@email.com", "website" => "http://WEBSITE.TLD", "image" => "http://IMAGE.TLD", metadata: {a: "b"}, uid: "UID"}
188
+ expect(subject.author).to be_a(::Mbrao::Author)
189
+ expect(subject.author.name).to eq("NAME")
190
+ expect(subject.author.email).to eq("EMAIL@email.com")
191
+ expect(subject.author.website).to eq("http://WEBSITE.TLD")
192
+ expect(subject.author.image).to eq("http://IMAGE.TLD")
193
+ expect(subject.author.metadata).to be_a(::HashWithIndifferentAccess)
194
+ expect(subject.author.metadata["a"]).to eq("b")
195
+ expect(subject.author.uid).to eq("UID")
189
196
  end
190
197
  end
191
198
 
@@ -199,25 +206,25 @@ describe Mbrao::Content do
199
206
 
200
207
  describe "#metadata=" do
201
208
  it "correctly set a non hash value" do
202
- reference.metadata = "RAW"
203
- expect(reference.metadata).to be_a(::HashWithIndifferentAccess)
204
- expect(reference.metadata["raw"]).to eq("RAW")
209
+ subject.metadata = "RAW"
210
+ expect(subject.metadata).to be_a(::HashWithIndifferentAccess)
211
+ expect(subject.metadata["raw"]).to eq("RAW")
205
212
  end
206
213
 
207
214
  it "correctly set a hash value" do
208
- reference.metadata = {en: nil, es: "ABC", it: [1, [2, 3]]}
209
- expect(reference.metadata).to be_a(::HashWithIndifferentAccess)
210
- expect(reference.metadata["es"]).to eq("ABC")
215
+ subject.metadata = {en: nil, es: "ABC", it: [1, [2, 3]]}
216
+ expect(subject.metadata).to be_a(::HashWithIndifferentAccess)
217
+ expect(subject.metadata["es"]).to eq("ABC")
211
218
  end
212
219
  end
213
220
 
214
221
  describe "#enabled_for_locales?" do
215
222
  it "correctly check availability for certain locales" do
216
- reference.locales = [:en, :it]
217
- expect(reference.enabled_for_locales?).to be_true
218
- expect(reference.enabled_for_locales?(:en)).to be_true
219
- expect(reference.enabled_for_locales?(:it, :es)).to be_true
220
- expect(reference.enabled_for_locales?(:es, :de)).to be_false
223
+ subject.locales = [:en, :it]
224
+ expect(subject.enabled_for_locales?).to be_true
225
+ expect(subject.enabled_for_locales?(:en)).to be_true
226
+ expect(subject.enabled_for_locales?(:it, :es)).to be_true
227
+ expect(subject.enabled_for_locales?(:es, :de)).to be_false
221
228
  end
222
229
  end
223
230
 
@@ -227,11 +234,11 @@ describe Mbrao::Content do
227
234
 
228
235
  describe "#get_body" do
229
236
  it "should create a parsing engine and use it for filtering" do
230
- reference.body = "BODY"
237
+ subject.body = "BODY"
231
238
  engine = ::Mbrao::ParsingEngines::Base.new
232
- expect(engine).to receive(:filter_content).with(reference, ["it", "en"])
239
+ expect(engine).to receive(:filter_content).with(subject, ["it", "en"])
233
240
  expect(::Mbrao::Parser).to receive(:create_engine).with("ENGINE").and_return(engine)
234
- reference.get_body(["it", "en"], "ENGINE")
241
+ subject.get_body(["it", "en"], "ENGINE")
235
242
  end
236
243
  end
237
244
 
@@ -243,6 +250,58 @@ describe Mbrao::Content do
243
250
  it_should_behave_like "localized getter", :more, "ABC", "123"
244
251
  end
245
252
 
253
+ describe "#as_json" do
254
+ subject {
255
+ @created_at = DateTime.civil(1984, 7, 7, 11, 30, 0)
256
+ metadata = {"uid" => "UID", "title" => {it: "IT", en: "EN"}, "author" => "AUTHOR", "tags" => {it: "IT", en: "EN"}, "more" => "MORE", created_at: @created_at, locales: ["it", ["en"]], other: ["OTHER"]}
257
+ ::Mbrao::Content.create(metadata, "BODY")
258
+ }
259
+
260
+ it "should return the content as a JSON hash" do
261
+ expect(subject.as_json).to eq({
262
+ "author" => {"uid" => nil, "name" => "AUTHOR", "email" => nil, "website" => nil, "image" => nil, "metadata" => {}},
263
+ "body" => "BODY",
264
+ "created_at" => @created_at,
265
+ "locales" => ["it", "en"],
266
+ "metadata" => {"other" => ["OTHER"]},
267
+ "more" => "MORE",
268
+ "tags" => {"it" => ["IT"], "en"=>["EN"]},
269
+ "title" => {"it" => "IT", "en" => "EN"},
270
+ "uid" => "UID",
271
+ "updated_at" => @created_at
272
+ })
273
+ end
274
+
275
+ it "should filter out keys if asked to" do
276
+ expect(subject.as_json(exclude: [:author, :uid])).to eq({
277
+ "body" => "BODY",
278
+ "created_at" => @created_at,
279
+ "locales" => ["it", "en"],
280
+ "metadata" => {"other" => ["OTHER"]},
281
+ "more" => "MORE",
282
+ "tags" => {"it" => ["IT"], "en"=>["EN"]},
283
+ "title" => {"it" => "IT", "en" => "EN"},
284
+ "updated_at" => @created_at
285
+ })
286
+ end
287
+
288
+ it "should filter out empty values if asked to" do
289
+ subject.author = nil
290
+ subject.uid = nil
291
+
292
+ expect(subject.as_json(exclude_empty: true)).to eq({
293
+ "body" => "BODY",
294
+ "created_at" => @created_at,
295
+ "locales" => ["it", "en"],
296
+ "metadata" => {"other" => ["OTHER"]},
297
+ "more" => "MORE",
298
+ "tags" => {"it" => ["IT"], "en"=>["EN"]},
299
+ "title" => {"it" => "IT", "en" => "EN"},
300
+ "updated_at" => @created_at
301
+ })
302
+ end
303
+ end
304
+
246
305
  describe ".create" do
247
306
  it "should return a Content object" do
248
307
  expect(::Mbrao::Content.create(nil, "BODY")).to be_a(::Mbrao::Content)
@@ -8,7 +8,14 @@ require "spec_helper"
8
8
  require "action_view"
9
9
  require "mbrao/integrations/rails"
10
10
 
11
+
11
12
  describe ActionView::Template::Handlers::MbraoTemplate do
13
+ class Rails
14
+ def self.version
15
+ "3"
16
+ end
17
+ end
18
+
12
19
  class DummyTemplate
13
20
  def initialize(content)
14
21
  @content = content
@@ -34,6 +41,13 @@ describe ActionView::Template::Handlers::MbraoTemplate do
34
41
  end
35
42
  end
36
43
 
44
+ describe ".register" do
45
+ it "should register template" do
46
+ expect(ActionView::Template).to receive(:register_template_handler).with("emt", an_instance_of(ActionView::Template::Handlers::MbraoTemplate))
47
+ ActionView::Template::Handlers::MbraoTemplate.register
48
+ end
49
+ end
50
+
37
51
  describe ".instance" do
38
52
  it "should create a new instance" do
39
53
  expect(ActionView::Template::Handlers::MbraoTemplate.instance).to be_a(ActionView::Template::Handlers::MbraoTemplate)
@@ -59,14 +59,14 @@ describe Mbrao::Parser do
59
59
 
60
60
  describe ".create_engine" do
61
61
  it "should create an engine via Lazier.find_class" do
62
- reference = ::Mbrao::ParsingEngines::ScopedParser.new
62
+ subject = ::Mbrao::ParsingEngines::ScopedParser.new
63
63
  cls = ::Mbrao::ParsingEngines::ScopedParser
64
- expect(cls).to receive(:new).exactly(2).and_return(reference)
64
+ expect(cls).to receive(:new).exactly(2).and_return(subject)
65
65
 
66
66
  expect(::Lazier).to receive(:find_class).with(:scoped_parser, "::Mbrao::ParsingEngines::%CLASS%").and_return(cls)
67
- expect(::Mbrao::Parser.create_engine(:scoped_parser)).to eq(reference)
67
+ expect(::Mbrao::Parser.create_engine(:scoped_parser)).to eq(subject)
68
68
  expect(::Lazier).to receive(:find_class).with(:scoped_parser, "::Mbrao::RenderingEngines::%CLASS%").and_return(cls)
69
- expect(::Mbrao::Parser.create_engine(:scoped_parser, :rendering)).to eq(reference)
69
+ expect(::Mbrao::Parser.create_engine(:scoped_parser, :rendering)).to eq(subject)
70
70
  end
71
71
 
72
72
  it "should raise an exception if the engine class is not found" do
@@ -122,12 +122,12 @@ describe Mbrao::Parser do
122
122
 
123
123
  describe "#parse" do
124
124
  it "should sanitize options" do
125
- reference = BlankParser.new
126
- expect(::Mbrao::Parser).to receive(:create_engine).exactly(3).and_return(reference)
125
+ subject = BlankParser.new
126
+ expect(::Mbrao::Parser).to receive(:create_engine).exactly(3).and_return(subject)
127
127
 
128
- expect(reference).to receive(:parse).with("CONTENT", {"metadata" => true, "content" => true, "engine" => :blank_parser})
129
- expect(reference).to receive(:parse).with("CONTENT", {"metadata" => true, "content" => false, "engine" => :blank_parser})
130
- expect(reference).to receive(:parse).with("CONTENT", {"metadata" => false, "content" => false, "engine" => :blank_parser})
128
+ expect(subject).to receive(:parse).with("CONTENT", {"metadata" => true, "content" => true, "engine" => :blank_parser})
129
+ expect(subject).to receive(:parse).with("CONTENT", {"metadata" => true, "content" => false, "engine" => :blank_parser})
130
+ expect(subject).to receive(:parse).with("CONTENT", {"metadata" => false, "content" => false, "engine" => :blank_parser})
131
131
 
132
132
  ::Mbrao::Parser.new.parse("CONTENT", {engine: :blank_parser})
133
133
  ::Mbrao::Parser.new.parse("CONTENT", {engine: :blank_parser, content: 2})
@@ -135,31 +135,31 @@ describe Mbrao::Parser do
135
135
  end
136
136
 
137
137
  it "should call .create_engine call its #parse method" do
138
- reference = BlankParser.new
139
- expect(::Mbrao::Parser).to receive(:create_engine).and_return(reference)
138
+ subject = BlankParser.new
139
+ expect(::Mbrao::Parser).to receive(:create_engine).and_return(subject)
140
140
 
141
- expect(reference).to receive(:parse).with("CONTENT", {"metadata" => true, "content" => true, "engine" => :blank_parser, "other" => "OK"})
141
+ expect(subject).to receive(:parse).with("CONTENT", {"metadata" => true, "content" => true, "engine" => :blank_parser, "other" => "OK"})
142
142
  ::Mbrao::Parser.new.parse("CONTENT", {engine: :blank_parser, other: "OK"})
143
143
  end
144
144
  end
145
145
 
146
146
  describe "#render" do
147
147
  it "should sanitize options" do
148
- reference = Object.new
149
- expect(::Mbrao::Parser).to receive(:create_engine).exactly(2).and_return(reference)
148
+ subject = Object.new
149
+ expect(::Mbrao::Parser).to receive(:create_engine).exactly(2).and_return(subject)
150
150
 
151
- expect(reference).to receive(:render).with("CONTENT", {"engine" => :blank_rendered}, {content: "OK"})
152
- expect(reference).to receive(:render).with("CONTENT", {"engine" => :html_pipeline}, {content: "OK"})
151
+ expect(subject).to receive(:render).with("CONTENT", {"engine" => :blank_rendered}, {content: "OK"})
152
+ expect(subject).to receive(:render).with("CONTENT", {"engine" => :html_pipeline}, {content: "OK"})
153
153
 
154
154
  ::Mbrao::Parser.new.render("CONTENT", {engine: :blank_rendered}, {content: "OK"})
155
155
  ::Mbrao::Parser.new.render("CONTENT", {engine: :html_pipeline}, {content: "OK"})
156
156
  end
157
157
 
158
158
  it "should call .create_engine call its #parse method" do
159
- reference = Object.new
160
- expect(::Mbrao::Parser).to receive(:create_engine).with(:blank_rendered, :rendering).and_return(reference)
159
+ subject = Object.new
160
+ expect(::Mbrao::Parser).to receive(:create_engine).with(:blank_rendered, :rendering).and_return(subject)
161
161
 
162
- expect(reference).to receive(:render).with("CONTENT", {"engine" => :blank_rendered}, {content: "OK"})
162
+ expect(subject).to receive(:render).with("CONTENT", {"engine" => :blank_rendered}, {content: "OK"})
163
163
  ::Mbrao::Parser.new.render("CONTENT", {engine: :blank_rendered}, {content: "OK"})
164
164
  end
165
165
  end
@@ -7,11 +7,11 @@
7
7
  require "spec_helper"
8
8
 
9
9
  describe Mbrao::ParsingEngines::Base do
10
- let(:reference) { Mbrao::ParsingEngines::Base.new }
10
+ subject{ Mbrao::ParsingEngines::Base.new }
11
11
 
12
12
  shared_examples_for("unimplemented") do |method|
13
13
  it "should raise an exception" do
14
- expect { reference.send(method, "CONTENT", {}) }.to raise_error(Mbrao::Exceptions::Unimplemented)
14
+ expect { subject.send(method, "CONTENT", {}) }.to raise_error(Mbrao::Exceptions::Unimplemented)
15
15
  end
16
16
  end
17
17
 
@@ -28,25 +28,25 @@ describe Mbrao::ParsingEngines::Base do
28
28
  end
29
29
 
30
30
  describe "#parse" do
31
- let(:reference) { ::Mbrao::ParsingEngines::Base.new }
31
+ subject{ ::Mbrao::ParsingEngines::Base.new }
32
32
 
33
33
  it "should forward to ::Mbrao::Content.create" do
34
- expect(reference).to receive(:separate_components).with("CONTENT", {a: "b"}).and_return([{a: "b"}, "BODY"])
35
- allow(reference).to receive(:parse_metadata).and_return({a: "b"})
34
+ expect(subject).to receive(:separate_components).with("CONTENT", {a: "b"}).and_return([{a: "b"}, "BODY"])
35
+ allow(subject).to receive(:parse_metadata).and_return({a: "b"})
36
36
  expect(::Mbrao::Content).to receive(:create).with({a: "b"}, "BODY")
37
- reference.parse("CONTENT", {a: "b"})
37
+ subject.parse("CONTENT", {a: "b"})
38
38
  end
39
39
 
40
40
  it "should return a Content object" do
41
- allow(reference).to receive(:separate_components).with("CONTENT", {a: "b"}).and_return([])
42
- allow(reference).to receive(:parse_metadata).and_return({})
43
- expect(reference.parse("CONTENT", {a: "b"})).to be_a(::Mbrao::Content)
41
+ allow(subject).to receive(:separate_components).with("CONTENT", {a: "b"}).and_return([])
42
+ allow(subject).to receive(:parse_metadata).and_return({})
43
+ expect(subject.parse("CONTENT", {a: "b"})).to be_a(::Mbrao::Content)
44
44
  end
45
45
 
46
46
  it "should separate_components" do
47
- expect(reference).to receive(:separate_components).with("CONTENT", {a: "b"})
48
- allow(reference).to receive(:parse_metadata).and_return({})
49
- reference.parse("CONTENT", {a: "b"})
47
+ expect(subject).to receive(:separate_components).with("CONTENT", {a: "b"})
48
+ allow(subject).to receive(:parse_metadata).and_return({})
49
+ subject.parse("CONTENT", {a: "b"})
50
50
  end
51
51
  end
52
52
  end
@@ -7,7 +7,7 @@
7
7
  require "spec_helper"
8
8
 
9
9
  describe Mbrao::ParsingEngines::PlainText do
10
- let(:reference) { Mbrao::ParsingEngines::PlainText.new }
10
+ subject{ Mbrao::ParsingEngines::PlainText.new }
11
11
 
12
12
  let(:sample_metadata) {
13
13
  <<EOM
@@ -76,30 +76,30 @@ EOS4
76
76
 
77
77
  describe "#separate_components" do
78
78
  it "should return correct metadata and contents" do
79
- expect(reference.separate_components(sample_valid)).to eq([sample_metadata.strip, sample_content.strip])
79
+ expect(subject.separate_components(sample_valid)).to eq([sample_metadata.strip, sample_content.strip])
80
80
  end
81
81
 
82
82
  it "should return the whole content if metadata are either incorrectly tagged or not present" do
83
- expect(reference.separate_components(sample_invalid)).to eq(["", sample_invalid.strip])
84
- expect(reference.separate_components(sample_no_metadata)).to eq(["", sample_no_metadata.strip])
83
+ expect(subject.separate_components(sample_invalid)).to eq(["", sample_invalid.strip])
84
+ expect(subject.separate_components(sample_no_metadata)).to eq(["", sample_no_metadata.strip])
85
85
  end
86
86
 
87
87
  it "should use different tags" do
88
- expect(reference.separate_components("[meta]{{metadata}}OK\n[/meta] REST", {meta_tags: ["[meta]", "[/meta]"]})).to eq(["{{metadata}}OK", "REST"])
88
+ expect(subject.separate_components("[meta]{{metadata}}OK\n[/meta] REST", {meta_tags: ["[meta]", "[/meta]"]})).to eq(["{{metadata}}OK", "REST"])
89
89
  end
90
90
  end
91
91
 
92
92
  describe "#parse_metadata" do
93
93
  it "should correctly parse YAML formatted metadata" do
94
- expect(reference.parse_metadata("---\nyaml:\n :a: 'b'")).to eq({"yaml" => {a: "b"}})
94
+ expect(subject.parse_metadata("---\nyaml:\n :a: 'b'")).to eq({"yaml" => {a: "b"}})
95
95
  end
96
96
 
97
97
  it "should return a default value if parsing failed" do
98
- expect(reference.parse_metadata("---\n\"yaml:", {default: "DEFAULT"})).to eq("DEFAULT")
98
+ expect(subject.parse_metadata("---\n\"yaml:", {default: "DEFAULT"})).to eq("DEFAULT")
99
99
  end
100
100
 
101
101
  it "should raise an exception if parsing failed and no default is available" do
102
- expect { reference.parse_metadata("---\n\"yaml:") }.to raise_error(::Mbrao::Exceptions::InvalidMetadata)
102
+ expect { subject.parse_metadata("---\n\"yaml:") }.to raise_error(::Mbrao::Exceptions::InvalidMetadata)
103
103
  end
104
104
  end
105
105
 
@@ -109,33 +109,33 @@ EOS4
109
109
  end
110
110
 
111
111
  it "should return the original content if locales contains *" do
112
- expect(parse_content(reference.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "*"))).to eq(["START", "IT, EN", "MIDDLE", "!IT and !ES", "EN in !IT", "!IT", "END"])
112
+ expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "*"))).to eq(["START", "IT, EN", "MIDDLE", "!IT and !ES", "EN in !IT", "!IT", "END"])
113
113
  end
114
114
 
115
115
  it "should use default locale if nothing is specified" do
116
116
  ::Mbrao::Parser.locale = :it
117
- expect(parse_content(reference.filter_content(::Mbrao::Content.create(nil, sample_nested_content)))).to eq(["START", "IT, EN", "MIDDLE", "END"])
117
+ expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content)))).to eq(["START", "IT, EN", "MIDDLE", "END"])
118
118
  end
119
119
 
120
120
  it "should ignore unclosed tag, trying to close the leftmost start tag" do
121
- expect(parse_content(reference.filter_content(::Mbrao::Content.create(nil, "{{content: it}}\n{{content: en}}NO{{/content}}")))).to eq(["{{content: en}}NO"])
121
+ expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, "{{content: it}}\n{{content: en}}NO{{/content}}")))).to eq(["{{content: en}}NO"])
122
122
  end
123
123
 
124
124
  it "should correctly filter by tag" do
125
- expect(parse_content(reference.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "en"))).to eq(["START", "IT, EN", "MIDDLE", "!IT and !ES", "EN in !IT", "!IT", "END"])
126
- expect(parse_content(reference.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "it"))).to eq(["START", "IT, EN", "MIDDLE", "END"])
127
- expect(parse_content(reference.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "es"))).to eq(["START", "MIDDLE", "!IT", "END"])
128
- expect(parse_content(reference.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "fr"))).to eq(["START", "MIDDLE", "!IT and !ES", "!IT", "END"])
129
- expect(parse_content(reference.filter_content(::Mbrao::Content.create(nil, sample_nested_content), ["it", "en"]))).to eq(["START", "IT, EN", "MIDDLE", "END"])
130
- expect(parse_content(reference.filter_content(::Mbrao::Content.create(nil, sample_nested_content), ["es", "en"]))).to eq(["START", "IT, EN", "MIDDLE", "EN in !IT", "!IT", "END"])
131
- expect(parse_content(reference.filter_content(::Mbrao::Content.create(nil, sample_nested_content), ["fr", "en"]))).to eq(["START", "IT, EN", "MIDDLE", "!IT and !ES", "EN in !IT", "!IT", "END"])
132
- expect(parse_content(reference.filter_content(::Mbrao::Content.create(nil, sample_nested_content), ["fr", "es", "en"]))).to eq(["START", "IT, EN", "MIDDLE", "EN in !IT", "!IT", "END"])
125
+ expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "en"))).to eq(["START", "IT, EN", "MIDDLE", "!IT and !ES", "EN in !IT", "!IT", "END"])
126
+ expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "it"))).to eq(["START", "IT, EN", "MIDDLE", "END"])
127
+ expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "es"))).to eq(["START", "MIDDLE", "!IT", "END"])
128
+ expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "fr"))).to eq(["START", "MIDDLE", "!IT and !ES", "!IT", "END"])
129
+ expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), ["it", "en"]))).to eq(["START", "IT, EN", "MIDDLE", "END"])
130
+ expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), ["es", "en"]))).to eq(["START", "IT, EN", "MIDDLE", "EN in !IT", "!IT", "END"])
131
+ expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), ["fr", "en"]))).to eq(["START", "IT, EN", "MIDDLE", "!IT and !ES", "EN in !IT", "!IT", "END"])
132
+ expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), ["fr", "es", "en"]))).to eq(["START", "IT, EN", "MIDDLE", "EN in !IT", "!IT", "END"])
133
133
  end
134
134
 
135
135
  it "should use different tags" do
136
136
  sample = "[content-it]{{content: !it}}IT[/content]\nOK"
137
- expect(parse_content(reference.filter_content(::Mbrao::Content.create(nil, sample), "it", {content_tags: ["[content-%ARGS%]", "[/content]"]}))).to eq(["{{content: !it}}IT", "OK"])
138
- expect(parse_content(reference.filter_content(::Mbrao::Content.create(nil, sample), "en", {content_tags: ["[content-%ARGS%]", "[/content]"]}))).to eq(["OK"])
137
+ expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample), "it", {content_tags: ["[content-%ARGS%]", "[/content]"]}))).to eq(["{{content: !it}}IT", "OK"])
138
+ expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample), "en", {content_tags: ["[content-%ARGS%]", "[/content]"]}))).to eq(["OK"])
139
139
  end
140
140
  end
141
141
  end
@@ -7,11 +7,11 @@
7
7
  require "spec_helper"
8
8
 
9
9
  describe Mbrao::RenderingEngines::Base do
10
- let(:reference) { Mbrao::RenderingEngines::Base.new }
10
+ subject{ Mbrao::RenderingEngines::Base.new }
11
11
 
12
12
  describe "#render" do
13
13
  it "should raise an exception" do
14
- expect { reference.render("CONTENT", {}, {}) }.to raise_error(Mbrao::Exceptions::Unimplemented)
14
+ expect { subject.render("CONTENT", {}, {}) }.to raise_error(Mbrao::Exceptions::Unimplemented)
15
15
  end
16
16
  end
17
17
  end