ghost_in_the_post 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +24 -0
- data/lib/ghost_in_the_post.rb +47 -0
- data/lib/ghost_in_the_post/automatic.rb +19 -0
- data/lib/ghost_in_the_post/ghost_on_command.rb +10 -0
- data/lib/ghost_in_the_post/ghost_on_delivery.rb +12 -0
- data/lib/ghost_in_the_post/mail_ghost.rb +30 -0
- data/lib/ghost_in_the_post/mailer.rb +18 -0
- data/lib/ghost_in_the_post/phantom/staticize.js +27 -0
- data/lib/ghost_in_the_post/phantom_transform.rb +91 -0
- data/lib/ghost_in_the_post/version.rb +3 -0
- data/spec/dummy/Gemfile +3 -0
- data/spec/dummy/Gemfile.lock +115 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/test.js +1 -0
- data/spec/dummy/app/mailers/auto_mailer.rb +13 -0
- data/spec/dummy/app/mailers/mailer.rb +13 -0
- data/spec/dummy/app/views/auto_mailer/normal_email.html.erb +13 -0
- data/spec/dummy/app/views/auto_mailer/normal_email.text +1 -0
- data/spec/dummy/app/views/mailer/normal_email.html.erb +12 -0
- data/spec/dummy/app/views/mailer/normal_email.text +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +13 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +11 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/ghost_in_the_post.rb +5 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/routes.rb +2 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/log/development.log +216 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/1hVihiFdBkDBsuCvA1I2vuFa9N6p-5zQ-qKvf4vz7jA.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/23mzeUAO-pIzGJ1n84Dbg25udWeSiBcd6e_QsDihWQc.cache +3 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6544SZAu2zCeDrdro4h3izdKNXVvHzstwz12UxeiJoA.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/BMI0IB92xLhvUPcr_K0JuSk8zczmrEEbJCd3qwHauhQ.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/GtqgDsC0JMsKfj0x5uQrbPcSS3QIPIzLKrq2fGJDBf0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/IFLV6zTaBXU1ccodbD3QJ4xUIOEix_Fbb7j8wsxrHw8.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Lc8lcXR-AibSZCIbx_imdfIOmD-zbZ_pwSNMs0o0Dos.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/O9gjtBITAGlfzUwc2DT5N0GW2bo2b2yQ64gnQljLogM.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/OQXwnC5z5STtd87Tr2dz1QBt4iZ8PoZTH8KBtBlUGnE.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/OZ04c215C4Euu3scfhmxmte0o_tZOVWTqrv61cpy7H4.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/_Bn81xMZj4dS_W5s9uSDhtEdpRZtsc21rcKEYAPCsZY.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/_Cw52w24AWZEbxLmduyWBMA6Y1OmJiEm1VNn7pY4rtk.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/_HO5Nyj_TzTxVwa4OOf_0UJfBCmjgkv7NsRU29AD5Oo.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/eN_ueL7m-D9xkEZpaLKwCxdrNzyz-MW9jcdJ5TdF9j8.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/efKfhZKxLC7ERXlMb5CQMqYwbvWS-A--pH-0fqzvRiQ.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/goEv0RKoifagsjFSdEHY-23E9ybQn_t1HHEZq7PlKQI.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/n6_6RjvPX2rCv5dytbSnnDrGwAj1ZcPfninuNUeP_iE.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/nXo-w2o4zQBM_uSUnniuP53t5erBbSZPecMED9YnzQI.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/oB1njyQ78MOMRf_5TvuYzHleeI8eke5-FDIIVl7qas0.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/qxbw0jMkxTNeM5T2QovOD9vTyvjHVjBN5tZdwBf519A.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/y98HqYF9nxOk8t_j3BKv9Nc4LuSAEzhER7rCCvOM6xI.cache +1 -0
- data/spec/lib/ghost_in_the_post/automatic_spec.rb +42 -0
- data/spec/lib/ghost_in_the_post/ghost_on_command_spec.rb +26 -0
- data/spec/lib/ghost_in_the_post/mail_ghost_spec.rb +73 -0
- data/spec/lib/ghost_in_the_post/mailer_spec.rb +38 -0
- data/spec/lib/ghost_in_the_post/phantom_transform_spec.rb +134 -0
- data/spec/lib/ghost_in_the_post_spec.rb +60 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/mailer_support.rb +23 -0
- data/spec/support/quiet_load.rb +6 -0
- metadata +238 -0
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/1hVihiFdBkDBsuCvA1I2vuFa9N6p-5zQ-qKvf4vz7jA.cache
ADDED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/23mzeUAO-pIzGJ1n84Dbg25udWeSiBcd6e_QsDihWQc.cache
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
[o:Set:
|
2
|
+
@hash{
|
3
|
+
I"environment-version:ETTI"environment-paths;TTI"Lprocessors:type=application/javascript&file_type=application/javascript;TTI"1file-digest://app/assets/javascripts/test.js;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TT
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/BMI0IB92xLhvUPcr_K0JuSk8zczmrEEbJCd3qwHauhQ.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"%�W\�yho9S���ƫ˥��)|�~���(���
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/GtqgDsC0JMsKfj0x5uQrbPcSS3QIPIzLKrq2fGJDBf0.cache
ADDED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/IFLV6zTaBXU1ccodbD3QJ4xUIOEix_Fbb7j8wsxrHw8.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�app/assets/javascripts/test.js?type=application/javascript&pipeline=self&id=b64c38812a66f3714232b5f6a440aa0d755642ad933e0bc59df8594afcc9d899:ET
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Lc8lcXR-AibSZCIbx_imdfIOmD-zbZ_pwSNMs0o0Dos.cache
ADDED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/O9gjtBITAGlfzUwc2DT5N0GW2bo2b2yQ64gnQljLogM.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�app/assets/javascripts/application.js?type=application/javascript&id=d60a1828a97cefde6fd8ada124f7d6b9e3754a5b8606cadb78146ea03d465ae7:ET
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/OQXwnC5z5STtd87Tr2dz1QBt4iZ8PoZTH8KBtBlUGnE.cache
ADDED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/OZ04c215C4Euu3scfhmxmte0o_tZOVWTqrv61cpy7H4.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�app/assets/javascripts/application.js?type=application/javascript&pipeline=self&id=0cb0379e0f5747f3fad310dacef102654555c5334351880dc80f112d7e2b86f0:ET
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/_Bn81xMZj4dS_W5s9uSDhtEdpRZtsc21rcKEYAPCsZY.cache
ADDED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/_HO5Nyj_TzTxVwa4OOf_0UJfBCmjgkv7NsRU29AD5Oo.cache
ADDED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/eN_ueL7m-D9xkEZpaLKwCxdrNzyz-MW9jcdJ5TdF9j8.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"%�
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/efKfhZKxLC7ERXlMb5CQMqYwbvWS-A--pH-0fqzvRiQ.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"~app/assets/javascripts/test.js?type=application/javascript&id=07c03e9c18a6664cd589766bf1c9c5fabfac303b890045debcb704e109e4fff7:ET
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/goEv0RKoifagsjFSdEHY-23E9ybQn_t1HHEZq7PlKQI.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�app/assets/javascripts/test.js?type=application/javascript&pipeline=self&id=963de54cc08f25dea0c490c740550aad17af6c3a62ca371ac3db8ebe89bc4fd2:ET
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache
ADDED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/n6_6RjvPX2rCv5dytbSnnDrGwAj1ZcPfninuNUeP_iE.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�app/assets/javascripts/application.js?type=application/javascript&pipeline=self&id=06950834cef83fe6dbc7a7c85bc9e4f615f55d9b8dbd85655e0c987022c23724:ET
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/nXo-w2o4zQBM_uSUnniuP53t5erBbSZPecMED9YnzQI.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"%yŜ�{���F�5��/_��XJ��QQ-� �
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/oB1njyQ78MOMRf_5TvuYzHleeI8eke5-FDIIVl7qas0.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"%6���%i���,}����Y� ���.��>m�
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache
ADDED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/qxbw0jMkxTNeM5T2QovOD9vTyvjHVjBN5tZdwBf519A.cache
ADDED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/y98HqYF9nxOk8t_j3BKv9Nc4LuSAEzhER7rCCvOM6xI.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�app/assets/javascripts/application.js?type=application/javascript&id=d5e992511ffbb70655162f9a39194f63a0c1fc96e34031c4d657819ef0485a81:ET
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require 'mail'
|
3
|
+
|
4
|
+
module GhostInThePost
|
5
|
+
describe Automatic do
|
6
|
+
class AutoMailer < BaseMailer
|
7
|
+
include Automatic
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:email) { Mail.new(to: "foo@example.com", from: "me@example.com") }
|
11
|
+
let(:instance) { AutoMailer.new(email) }
|
12
|
+
|
13
|
+
describe "#include_script" do
|
14
|
+
|
15
|
+
it "should add to include scripts" do
|
16
|
+
instance.include_script "test.js"
|
17
|
+
expect(instance.included_scripts).to eq(["test.js"])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#mail" do
|
22
|
+
it "should return an email" do
|
23
|
+
expect(instance.mail).to be_kind_of(Mail::Message)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return an email extended with GhostOnCommand and GhostOnDelivery" do
|
27
|
+
expect(email).to receive(:extend).with(GhostOnCommand).and_call_original
|
28
|
+
expect(email).to receive(:extend).with(GhostOnDelivery).and_call_original
|
29
|
+
mail = instance.mail
|
30
|
+
expect(mail).to be_kind_of(GhostOnCommand)
|
31
|
+
expect(mail).to be_kind_of(GhostOnDelivery)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have set the emails included scripts" do
|
35
|
+
email.extend GhostOnCommand
|
36
|
+
expect(email).to receive(:included_scripts=).with(nil).and_call_original
|
37
|
+
instance.mail
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require 'mail'
|
3
|
+
|
4
|
+
module GhostInThePost
|
5
|
+
describe GhostOnCommand do
|
6
|
+
let(:instance) { SomeMailer.new(Mail.new(to: "foo@example.com", from: "me@example.com")) }
|
7
|
+
let(:email) {instance.mail}
|
8
|
+
|
9
|
+
describe "#ghost" do
|
10
|
+
it "Should return a Message" do
|
11
|
+
expect(email.ghost).to be_a(Mail::Message)
|
12
|
+
end
|
13
|
+
it "should create a MailGhost" do
|
14
|
+
email.included_scripts = ["test"]
|
15
|
+
expect(MailGhost).to receive(:new).with(email, ["test"]).and_call_original
|
16
|
+
email.ghost
|
17
|
+
end
|
18
|
+
it "should apply included scripts to the mail ghost" do
|
19
|
+
expect(email).to receive(:included_scripts).and_call_original
|
20
|
+
email.ghost
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mail'
|
3
|
+
|
4
|
+
module GhostInThePost
|
5
|
+
describe MailGhost do
|
6
|
+
let(:email) { Mail.new }
|
7
|
+
let(:included_scripts) { ["application.js"] }
|
8
|
+
subject(:ghost) { MailGhost.new(email, included_scripts) }
|
9
|
+
|
10
|
+
it "takes an email and options" do
|
11
|
+
expect(ghost.email).to eq(email)
|
12
|
+
expect(ghost.included_scripts).to eq(included_scripts)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with an plaintext email" do
|
16
|
+
let(:email) do
|
17
|
+
Mail.new do
|
18
|
+
body "Hello world"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns the email without doing anything" do
|
23
|
+
expect(ghost.execute).to eq(email)
|
24
|
+
expect(email.html_part).to be_nil
|
25
|
+
expect(email.body.decoded).to eq("Hello world")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "works fine when given nil included_scripts" do
|
29
|
+
ghost = MailGhost.new(email, nil)
|
30
|
+
expect { ghost.execute }.to_not raise_error
|
31
|
+
expect(ghost.included_scripts).to eq([])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with an HTML email" do
|
36
|
+
let(:html) { "<h1>Hello world!</h1>" }
|
37
|
+
let(:email) do
|
38
|
+
html_string = html
|
39
|
+
Mail.new do
|
40
|
+
content_type 'text/html; charset=UTF-8'
|
41
|
+
body html_string
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "adjusts the html part using Roadie" do
|
46
|
+
document = double "A document", transform: "transformed HTML"
|
47
|
+
expect(PhantomTransform).to receive(:new).with(html, included_scripts).and_return document
|
48
|
+
ghost.execute
|
49
|
+
expect(email.body.decoded).to eq("transformed HTML")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with an multipart email" do
|
54
|
+
let(:html) { "<h1>Hello world!</h1>" }
|
55
|
+
let(:email) do
|
56
|
+
html_string = html
|
57
|
+
Mail.new do
|
58
|
+
text_part { body "Hello world" }
|
59
|
+
html_part { body html_string }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "adjusts the html part using Roadie" do
|
64
|
+
document = double "A document", transform: "transformed HTML"
|
65
|
+
expect(PhantomTransform).to receive(:new).with(html, included_scripts).and_return document
|
66
|
+
ghost.execute
|
67
|
+
expect(email.html_part.body.decoded).to eq("transformed HTML")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require 'mail'
|
3
|
+
|
4
|
+
module GhostInThePost
|
5
|
+
describe Mailer do
|
6
|
+
let(:email) { Mail.new(to: "foo@example.com", from: "me@example.com") }
|
7
|
+
let(:instance) { AutoMailer.new(email) }
|
8
|
+
|
9
|
+
describe "#include_script" do
|
10
|
+
|
11
|
+
it "should add to include scripts" do
|
12
|
+
instance.include_script "test.js"
|
13
|
+
expect(instance.included_scripts).to eq(["test.js"])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#mail" do
|
18
|
+
it "should return an email" do
|
19
|
+
expect(instance.mail).to be_kind_of(Mail::Message)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return an email extended with GhostOnCommand and GhostOnDelivery" do
|
23
|
+
expect(email).to receive(:extend).with(GhostOnCommand).and_call_original
|
24
|
+
expect(email).to receive(:extend).with(GhostOnDelivery).and_call_original
|
25
|
+
mail = instance.mail
|
26
|
+
expect(mail).to be_kind_of(GhostOnCommand)
|
27
|
+
expect(mail).to be_kind_of(GhostOnDelivery)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should have set the emails included scripts" do
|
31
|
+
email.extend GhostOnCommand
|
32
|
+
expect(email).to receive(:included_scripts=).with(nil).and_call_original
|
33
|
+
instance.mail
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module GhostInThePost
|
4
|
+
describe PhantomTransform do
|
5
|
+
let(:html){"<html><head><script></script></head><body><div id='test'></div></body></html>"}
|
6
|
+
let(:js){"(function(){document.getElementById('test').innerHTML='complete';})()"}
|
7
|
+
let(:included_scripts){["application.js"]}
|
8
|
+
subject {PhantomTransform.new(html, included_scripts)}
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
GhostInThePost.config = {phantomjs_path: "this/is/path"}
|
12
|
+
allow_message_expectations_on_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#initialize" do
|
16
|
+
it "should set html" do
|
17
|
+
pt = PhantomTransform.new(html, included_scripts)
|
18
|
+
expect(pt.instance_variable_get(:@html)).to eq(html)
|
19
|
+
end
|
20
|
+
it "should set included_scripts" do
|
21
|
+
pt = PhantomTransform.new(html, included_scripts)
|
22
|
+
expect(pt.instance_variable_get(:@included_scripts)).to eq(included_scripts)
|
23
|
+
end
|
24
|
+
it "should default included_scripts to an array" do
|
25
|
+
pt = PhantomTransform.new(html, nil)
|
26
|
+
expect(pt.instance_variable_get(:@included_scripts)).to eq([])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#transform" do
|
31
|
+
|
32
|
+
before :each do
|
33
|
+
allow(IO).to receive(:popen)
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with included_scripts" do
|
37
|
+
let(:path) {"/this/is/path"}
|
38
|
+
|
39
|
+
before :each do
|
40
|
+
allow(IO).to receive(:popen)
|
41
|
+
allow(Rails.application).to receive(:assets){
|
42
|
+
{
|
43
|
+
"application.js": "asset string"
|
44
|
+
}
|
45
|
+
}
|
46
|
+
allow_any_instance_of(Tempfile).to receive(:path){path}
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should call transform_with_injections" do
|
50
|
+
expect(subject).to receive(:transform_with_injections)
|
51
|
+
subject.transform
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should create a temp file, write to it and unlink it" do
|
55
|
+
file = Object.new
|
56
|
+
expect(subject).to receive(:injectable_scripts).twice{included_scripts}
|
57
|
+
expect(subject).to receive(:find_asset_in_pipeline).once.with(included_scripts.first){""}
|
58
|
+
expect(Tempfile).to receive(:new).with(['inject', '.js']){file}
|
59
|
+
allow(file).to receive(:path){path}
|
60
|
+
expect(file).to receive(:write)
|
61
|
+
expect(file).to receive(:close)
|
62
|
+
expect(file).to receive(:unlink)
|
63
|
+
subject.transform
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should call IO.popen with arguments" do
|
67
|
+
expect(IO).to receive(:popen).with([
|
68
|
+
GhostInThePost.phantomjs_path,
|
69
|
+
GhostInThePost::PhantomTransform::PHANTOMJS_SCRIPT,
|
70
|
+
html,
|
71
|
+
GhostInThePost.remove_js_tags,
|
72
|
+
path
|
73
|
+
])
|
74
|
+
subject.transform
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return the result of IO.popen with arguments" do
|
78
|
+
allow(IO).to receive(:popen) {"this is the end"}
|
79
|
+
expect(subject.transform).to eq("this is the end")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return the html if there was an error" do
|
83
|
+
file = Object.new
|
84
|
+
allow(Tempfile).to receive(:new).with(['inject', '.js']){file}
|
85
|
+
allow(file).to receive(:path){path}
|
86
|
+
allow(file).to receive(:write)
|
87
|
+
allow(file).to receive(:close)
|
88
|
+
allow(file).to receive(:unlink)
|
89
|
+
allow(IO).to receive(:popen) {raise ArgumentError}
|
90
|
+
expect(subject.transform).to eq(html)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should unlink file even if there was an error" do
|
94
|
+
file = Object.new
|
95
|
+
allow(Tempfile).to receive(:new).with(['inject', '.js']){file}
|
96
|
+
allow(file).to receive(:path){path}
|
97
|
+
allow(file).to receive(:write)
|
98
|
+
allow(file).to receive(:close)
|
99
|
+
allow(file).to receive(:unlink)
|
100
|
+
allow(IO).to receive(:popen) {raise ArgumentError}
|
101
|
+
subject.transform
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
context "without included_scripts" do
|
107
|
+
let(:pt){PhantomTransform.new(html)}
|
108
|
+
|
109
|
+
it "should call simple_transform" do
|
110
|
+
expect(pt).to receive(:simple_transform)
|
111
|
+
pt.transform
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should call IO.popen with arguments" do
|
115
|
+
expect(IO).to receive(:popen).with([
|
116
|
+
GhostInThePost.phantomjs_path,
|
117
|
+
GhostInThePost::PhantomTransform::PHANTOMJS_SCRIPT,
|
118
|
+
html,
|
119
|
+
GhostInThePost.remove_js_tags
|
120
|
+
])
|
121
|
+
pt.transform
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should return the result of IO.popen with arguments" do
|
125
|
+
allow(IO).to receive(:popen) {"this is the end"}
|
126
|
+
expect(pt.transform).to eq("this is the end")
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GhostInThePost do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
#reload so that variables are set to initials values
|
7
|
+
quiet_load 'ghost_in_the_post.rb'
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#create=" do
|
11
|
+
it "should complain if you add unknown keys" do
|
12
|
+
expect do
|
13
|
+
GhostInThePost.config = {bad_key: "blah"}
|
14
|
+
end.to raise_error(ArgumentError)
|
15
|
+
end
|
16
|
+
it "should set phantomjs_path" do
|
17
|
+
GhostInThePost.config = {phantomjs_path: "test_path"}
|
18
|
+
expect(GhostInThePost.phantomjs_path).to eq("test_path")
|
19
|
+
end
|
20
|
+
it "should raise ArgumentError if not path was set for phantom" do
|
21
|
+
expect do
|
22
|
+
GhostInThePost.config = {}
|
23
|
+
end.to raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
it "should set includes" do
|
26
|
+
GhostInThePost.config = {phantomjs_path: "test_path", includes: ["test"]}
|
27
|
+
expect(GhostInThePost.includes).to eq(["test"])
|
28
|
+
end
|
29
|
+
it "should force includes to an array" do
|
30
|
+
GhostInThePost.config = {phantomjs_path: "test_path", includes: "test"}
|
31
|
+
expect(GhostInThePost.includes).to eq(["test"])
|
32
|
+
end
|
33
|
+
it "should default includes to an empty array" do
|
34
|
+
GhostInThePost.config = {phantomjs_path: "test_path"}
|
35
|
+
expect(GhostInThePost.includes).to eq([])
|
36
|
+
end
|
37
|
+
it "should set remove_js_tags" do
|
38
|
+
GhostInThePost.config = {phantomjs_path: "test_path", remove_js_tags: false}
|
39
|
+
expect(GhostInThePost.remove_js_tags).to eq(false)
|
40
|
+
end
|
41
|
+
it "should default remove_js_tags to true" do
|
42
|
+
GhostInThePost.config = {phantomjs_path: "test_path"}
|
43
|
+
expect(GhostInThePost.remove_js_tags).to eq(true)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#phantomjs_path" do
|
48
|
+
it "should return phantomjs_path" do
|
49
|
+
GhostInThePost.config = {phantomjs_path: "test_path"}
|
50
|
+
expect(GhostInThePost.phantomjs_path).to eq("test_path")
|
51
|
+
end
|
52
|
+
it "should raise and ArgumentError if the path is not set" do
|
53
|
+
expect do
|
54
|
+
GhostInThePost.phantomjs_path
|
55
|
+
end.to raise_error(ArgumentError)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|