locomotivecms_steam 1.5.0.beta3 → 1.5.0.rc0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -4
- data/Gemfile.lock +3 -6
- data/README.md +33 -0
- data/Rakefile +8 -3
- data/docker-compose.yml +15 -0
- data/lib/locomotive/steam/entities/content_type.rb +7 -2
- data/lib/locomotive/steam/liquid/drops/section_content_proxy.rb +4 -0
- data/lib/locomotive/steam/liquid/filters/translate.rb +2 -0
- data/lib/locomotive/steam/liquid/tags/link_to.rb +8 -1
- data/lib/locomotive/steam/liquid/tags/model_form.rb +7 -1
- data/lib/locomotive/steam/middlewares/auth.rb +10 -17
- data/lib/locomotive/steam/middlewares/concerns/auth_helpers.rb +30 -0
- data/lib/locomotive/steam/middlewares/concerns/helpers.rb +13 -3
- data/lib/locomotive/steam/middlewares/concerns/liquid_context.rb +1 -1
- data/lib/locomotive/steam/middlewares/concerns/recaptcha.rb +30 -0
- data/lib/locomotive/steam/middlewares/default_env.rb +5 -3
- data/lib/locomotive/steam/middlewares/entry_submission.rb +4 -1
- data/lib/locomotive/steam/middlewares/impersonated_entry.rb +73 -0
- data/lib/locomotive/steam/middlewares/locale.rb +14 -9
- data/lib/locomotive/steam/models/associations/belongs_to.rb +6 -0
- data/lib/locomotive/steam/server.rb +1 -0
- data/lib/locomotive/steam/services.rb +9 -1
- data/lib/locomotive/steam/services/action_service.rb +3 -3
- data/lib/locomotive/steam/services/auth_service.rb +1 -1
- data/lib/locomotive/steam/services/content_entry_service.rb +11 -1
- data/lib/locomotive/steam/services/cookie_service.rb +25 -0
- data/lib/locomotive/steam/services/page_finder_service.rb +12 -0
- data/lib/locomotive/steam/services/recaptcha_service.rb +33 -0
- data/lib/locomotive/steam/services/translator_service.rb +12 -13
- data/lib/locomotive/steam/version.rb +1 -1
- data/spec/integration/liquid/filters/translate_spec.rb +7 -0
- data/spec/integration/repositories/content_entry_repository_spec.rb +4 -0
- data/spec/integration/server/auth_spec.rb +8 -1
- data/spec/integration/services/content_entry_service_spec.rb +11 -0
- data/spec/support/helpers.rb +1 -1
- data/spec/unit/liquid/drops/section_content_proxy_spec.rb +8 -0
- data/spec/unit/liquid/tags/action_spec.rb +2 -1
- data/spec/unit/liquid/tags/global_section_spec.rb +2 -1
- data/spec/unit/liquid/tags/link_to_spec.rb +7 -0
- data/spec/unit/liquid/tags/model_form_spec.rb +7 -0
- data/spec/unit/liquid/tags/section_spec.rb +2 -1
- data/spec/unit/liquid/tags/snippet_spec.rb +2 -1
- data/spec/unit/middlewares/auth_spec.rb +1 -0
- data/spec/unit/middlewares/entry_submission_spec.rb +64 -20
- data/spec/unit/middlewares/helpers_spec.rb +5 -1
- data/spec/unit/middlewares/impersonated_entry_spec.rb +80 -0
- data/spec/unit/middlewares/locale_spec.rb +57 -36
- data/spec/unit/middlewares/section_spec.rb +6 -5
- data/spec/unit/middlewares/site_spec.rb +13 -0
- data/spec/unit/services/action_service_spec.rb +17 -11
- data/spec/unit/services/auth_service_spec.rb +7 -1
- data/spec/unit/services/content_entry_service_spec.rb +25 -4
- data/spec/unit/services/cookie_service_spec.rb +38 -0
- data/spec/unit/services/page_finder_service_spec.rb +69 -0
- data/spec/unit/services/recaptcha_service_spec.rb +71 -0
- data/spec/unit/services/translator_service_spec.rb +11 -1
- metadata +16 -2
@@ -2,7 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Locomotive::Steam::Liquid::Tags::Section do
|
4
4
|
|
5
|
-
let(:
|
5
|
+
let(:request) { instance_double('Request', env: {}) }
|
6
|
+
let(:services) { Locomotive::Steam::Services.build_instance(request) }
|
6
7
|
let(:finder) { services.section_finder }
|
7
8
|
let(:source) { 'Locomotive {% section header %}' }
|
8
9
|
let(:live_editing) { true }
|
@@ -2,7 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Locomotive::Steam::Liquid::Tags::Snippet do
|
4
4
|
|
5
|
-
let(:
|
5
|
+
let(:request) { instance_double('Request', env: {}) }
|
6
|
+
let(:services) { Locomotive::Steam::Services.build_instance(request) }
|
6
7
|
let(:finder) { services.snippet_finder }
|
7
8
|
let(:snippet) { instance_double('Snippet', template: nil, :template= => nil, liquid_source: 'built by NoCoffee') }
|
8
9
|
let(:source) { 'Locomotive {% include footer %}' }
|
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require_relative '../../../lib/locomotive/steam/middlewares/thread_safe'
|
4
4
|
require_relative '../../../lib/locomotive/steam/middlewares/concerns/helpers'
|
5
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/recaptcha'
|
5
6
|
require_relative '../../../lib/locomotive/steam/middlewares/auth'
|
6
7
|
|
7
8
|
describe Locomotive::Steam::Middlewares::Auth::AuthOptions do
|
@@ -2,38 +2,51 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require_relative '../../../lib/locomotive/steam/middlewares/thread_safe'
|
4
4
|
require_relative '../../../lib/locomotive/steam/middlewares/concerns/helpers'
|
5
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/recaptcha'
|
5
6
|
require_relative '../../../lib/locomotive/steam/middlewares/entry_submission'
|
6
7
|
|
7
8
|
describe Locomotive::Steam::Middlewares::EntrySubmission do
|
8
9
|
|
9
|
-
let(:app)
|
10
|
-
let(:site)
|
11
|
-
let(:middleware)
|
12
|
-
let(:
|
13
|
-
let(:
|
14
|
-
let(:
|
15
|
-
let(:
|
10
|
+
let(:app) { ->(env) { [200, env, ['app']] } }
|
11
|
+
let(:site) { instance_double('Site', default_locale: 'en', locales: ['en']) }
|
12
|
+
let(:middleware) { described_class.new(app) }
|
13
|
+
let(:recaptcha_enabled) { false }
|
14
|
+
let(:recaptcha_valid) { false }
|
15
|
+
let(:content_type) { instance_double('ContentType', :recaptcha_required? => recaptcha_enabled) }
|
16
|
+
let(:service) { instance_double('EntrySubmissionService') }
|
17
|
+
let(:entry_service) { instance_double('EntryService', get_type: content_type) }
|
18
|
+
let(:recaptcha_service) { instance_double('RecaptchaService', verify: recaptcha_valid) }
|
19
|
+
let(:services) { instance_double('Services', entry_submission: service, content_entry: entry_service, recaptcha: recaptcha_service, :locale= => 'en') }
|
20
|
+
let(:session) { {} }
|
21
|
+
let(:method) { 'POST' }
|
22
|
+
let(:errors) { instance_double('Error', empty?: false) }
|
23
|
+
let(:entry) { instance_double('Entry', errors: errors, content_type_slug: 'contacts') }
|
24
|
+
let(:form) { { content_type_slug: 'contacts', :'g-recaptcha-response' => 'myrecaptchacode', content: { email: 'john@doe.net' } } }
|
25
|
+
let(:rack_env) { build_env }
|
16
26
|
|
17
27
|
before do
|
18
28
|
allow_any_instance_of(described_class).to receive(:csrf_field).and_return('csrf_field')
|
29
|
+
allow(service).to receive(:submit).with('contacts', { email: 'john@doe.net' }).and_return(entry)
|
30
|
+
allow(entry_service).to receive(:build).with('contacts', { email: 'john@doe.net' }).and_return(entry)
|
19
31
|
end
|
20
32
|
|
21
|
-
|
33
|
+
subject do
|
34
|
+
code, env = middleware.call(rack_env)
|
35
|
+
[code, env['steam.liquid_assigns']['contact']]
|
36
|
+
end
|
22
37
|
|
23
|
-
|
38
|
+
context 'recaptcha has not been enabled' do
|
24
39
|
|
25
|
-
|
26
|
-
expect(
|
40
|
+
it 'creates a new entry' do
|
41
|
+
expect(subject.first).to eq 200
|
42
|
+
expect(subject.last).to eq entry
|
27
43
|
end
|
28
44
|
|
29
|
-
|
30
|
-
|
31
|
-
context 'the creation of a content entry returns nil' do
|
45
|
+
context 'the form has not been set up for public submission' do
|
32
46
|
|
33
|
-
let(:form) { { content_type_slug: 'contacts', content: { email: 'john@doe.net' } } }
|
34
47
|
let(:entry) { nil }
|
35
48
|
|
36
|
-
it 'raises an exception' do
|
49
|
+
it 'raises an exception with an explicit error message' do
|
37
50
|
expect { subject }.to raise_exception('Unknown content type "contacts" or public_submission_enabled property not true')
|
38
51
|
end
|
39
52
|
|
@@ -41,12 +54,43 @@ describe Locomotive::Steam::Middlewares::EntrySubmission do
|
|
41
54
|
|
42
55
|
end
|
43
56
|
|
57
|
+
context 'recaptcha has been enabled' do
|
58
|
+
|
59
|
+
let(:recaptcha_enabled) { true }
|
60
|
+
|
61
|
+
context 'the recaptcha response is valid' do
|
62
|
+
|
63
|
+
let(:recaptcha_valid) { true }
|
64
|
+
|
65
|
+
it 'creates a new entry' do
|
66
|
+
expect(recaptcha_service).to receive(:verify).with('myrecaptchacode').and_return(true)
|
67
|
+
expect(subject.first).to eq 200
|
68
|
+
expect(subject.last).to eq entry
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'the recaptcha response is invalid' do
|
74
|
+
|
75
|
+
let(:recaptcha_valid) { false }
|
76
|
+
|
77
|
+
it 'returns a 200 code with the invalid entry' do
|
78
|
+
expect(errors).to receive(:add).with(:recaptcha_invalid, true)
|
79
|
+
expect(subject.first).to eq 200
|
80
|
+
expect(subject.last).to eq entry
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
44
87
|
def build_env
|
45
88
|
env_for('http://example.com/contact-us', params: form, method: method).tap do |env|
|
46
|
-
env['steam.request']
|
47
|
-
env['steam.site']
|
48
|
-
env['steam.services']
|
49
|
-
env['rack.session']
|
89
|
+
env['steam.request'] = Rack::Request.new(env)
|
90
|
+
env['steam.site'] = site
|
91
|
+
env['steam.services'] = services
|
92
|
+
env['rack.session'] = session
|
93
|
+
env['steam.liquid_assigns'] = {}
|
50
94
|
end
|
51
95
|
end
|
52
96
|
|
@@ -42,7 +42,11 @@ describe Locomotive::Steam::Middlewares::Concerns::Helpers do
|
|
42
42
|
|
43
43
|
context 'mounted_on is not blank' do
|
44
44
|
|
45
|
-
before
|
45
|
+
before do
|
46
|
+
allow(instance).to receive(:mounted_on).and_return('/my_app')
|
47
|
+
allow(instance).to receive(:inject_cookies).and_return(nil)
|
48
|
+
end
|
49
|
+
|
46
50
|
|
47
51
|
let(:location) { '/foo/bar' }
|
48
52
|
it { is_expected.to eq '/my_app/foo/bar' }
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/helpers'
|
4
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/auth_helpers'
|
5
|
+
require_relative '../../../lib/locomotive/steam/middlewares/thread_safe'
|
6
|
+
require_relative '../../../lib/locomotive/steam/middlewares/impersonated_entry'
|
7
|
+
|
8
|
+
describe Locomotive::Steam::Middlewares::ImpersonatedEntry do
|
9
|
+
|
10
|
+
let(:site) { instance_double('Site', _id: 42) }
|
11
|
+
let(:url) { 'http://models.example.com' }
|
12
|
+
let(:app) { ->(env) { [200, env, ['<html><body></body></html>']] } }
|
13
|
+
let(:entry) { nil }
|
14
|
+
let(:session) { {} }
|
15
|
+
let(:params) { {} }
|
16
|
+
let(:middleware) { described_class.new(app) }
|
17
|
+
|
18
|
+
subject do
|
19
|
+
code, env, body = call
|
20
|
+
[env['steam.impersonating_authenticated_entry'], body.first]
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'no impersonation' do
|
24
|
+
|
25
|
+
it { is_expected.to eq [nil, '<html><body></body></html>'] }
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'impersonating is on' do
|
30
|
+
|
31
|
+
let(:session) { { authenticated_impersonation: '1', authenticated_entry_type: 'accounts' } }
|
32
|
+
|
33
|
+
context 'the account is not logged in' do
|
34
|
+
|
35
|
+
it { is_expected.to eq [nil, '<html><body></body></html>'] }
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'the account is logged in' do
|
40
|
+
|
41
|
+
let(:entry) { instance_double('Account', _label: 'John') }
|
42
|
+
|
43
|
+
it { expect(subject.first).to eq true }
|
44
|
+
it { expect(subject.last.gsub(/\s*\n\s+/, ' ')).to include('<body><div class="locomotive-impersonating-banner" ') }
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'the administrator wants to leave the impersonating mode' do
|
49
|
+
|
50
|
+
let(:entry) { instance_double('Account', _label: 'John') }
|
51
|
+
let(:params) { { impersonating: 'stop' } }
|
52
|
+
|
53
|
+
subject do
|
54
|
+
code, env, body = call
|
55
|
+
[code, env['steam.impersonating_authenticated_entry'], env['Location']]
|
56
|
+
end
|
57
|
+
|
58
|
+
it { is_expected.to eq [302, nil, '/'] }
|
59
|
+
|
60
|
+
it "resets the session variable used to tell if we're in the impersonating mode" do
|
61
|
+
subject
|
62
|
+
expect(session[:authenticated_impersonation]).to eq '0'
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def call
|
70
|
+
env = env_for(url, params: params)
|
71
|
+
env['rack.session'] = session
|
72
|
+
env['steam.site'] = site
|
73
|
+
env['steam.path'] = '/'
|
74
|
+
env['steam.request'] = Rack::Request.new(env)
|
75
|
+
env['steam.liquid_assigns'] = {}
|
76
|
+
env['steam.authenticated_entry'] = entry
|
77
|
+
middleware.call(env)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -9,94 +9,115 @@ describe Locomotive::Steam::Middlewares::Locale do
|
|
9
9
|
let(:site) { instance_double('Site', default_locale: :de, locales: [:de, :fr, :en]) }
|
10
10
|
let(:url) { 'http://models.example.com' }
|
11
11
|
let(:app) { ->(env) { [200, env, 'app'] } }
|
12
|
-
let(:
|
12
|
+
let(:cookie_lang) { nil }
|
13
|
+
let(:cookie_service) { instance_double('Cookie Service', :get => cookie_lang) }
|
14
|
+
let(:services) { instance_double('Services', :locale= => 'en', :cookie => cookie_service) }
|
13
15
|
let(:middleware) { Locomotive::Steam::Middlewares::Locale.new(app) }
|
14
|
-
let(:session) { {} }
|
15
16
|
let(:accept_language) { '' }
|
16
17
|
|
17
18
|
subject do
|
18
19
|
env = env_for(
|
19
20
|
url,
|
20
21
|
'steam.site' => site,
|
21
|
-
'rack.session' => session,
|
22
22
|
'HTTP_ACCEPT_LANGUAGE' => accept_language)
|
23
23
|
env['steam.request'] = Rack::Request.new(env)
|
24
24
|
env['steam.services'] = services
|
25
|
+
env['steam.locale']
|
25
26
|
code, env = middleware.call(env)
|
26
|
-
[env['steam.locale'],
|
27
|
+
[env['steam.locale'], env['steam.path']]
|
27
28
|
end
|
28
29
|
|
29
|
-
describe '
|
30
|
+
describe 'whatever url' do
|
30
31
|
|
31
|
-
let(:url) { 'http://models.example.com/
|
32
|
+
let(:url) { 'http://models.example.com/whatever' }
|
32
33
|
|
33
|
-
it
|
34
|
+
it 'should set the cookies' do
|
35
|
+
expect(cookie_service).to receive(:set).with('steam-locale', {
|
36
|
+
value: :de,
|
37
|
+
path: '/',
|
38
|
+
max_age: 1.year
|
39
|
+
}).and_return(nil)
|
40
|
+
is_expected.to eq [:de, '/whatever']
|
41
|
+
end
|
34
42
|
|
35
43
|
end
|
36
44
|
|
37
|
-
describe '
|
45
|
+
describe 'browse site with' do
|
38
46
|
|
39
|
-
|
47
|
+
before { allow(cookie_service).to receive(:set).and_return(nil) }
|
40
48
|
|
41
|
-
|
49
|
+
describe 'locale defined in the path' do
|
42
50
|
|
43
|
-
|
51
|
+
let(:url) { 'http://models.example.com/de/hello-de/foo' }
|
44
52
|
|
45
|
-
|
53
|
+
it { is_expected.to eq [:de, '/hello-de/foo'] }
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'no locale defined in the path' do
|
58
|
+
|
59
|
+
describe 'first connexion' do
|
60
|
+
|
61
|
+
context 'without accept-language header' do
|
62
|
+
|
63
|
+
it { is_expected.to eq [:de, '/'] }
|
64
|
+
|
65
|
+
end
|
46
66
|
|
47
|
-
|
67
|
+
context 'with accept-language header' do
|
48
68
|
|
49
|
-
|
69
|
+
let(:accept_language) { 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7' }
|
50
70
|
|
51
|
-
|
71
|
+
it { is_expected.to eq [:fr, '/'] }
|
52
72
|
|
53
|
-
|
73
|
+
context 'with url path' do
|
54
74
|
|
55
|
-
|
75
|
+
let(:url) { 'http://models.example.com/werkzeug' }
|
56
76
|
|
57
|
-
|
77
|
+
it { is_expected.to eq [:de, '/werkzeug'] }
|
78
|
+
|
79
|
+
end
|
58
80
|
|
59
81
|
end
|
60
82
|
|
61
83
|
end
|
62
84
|
|
63
|
-
|
85
|
+
context 'user with cookie, use it' do
|
64
86
|
|
65
|
-
|
87
|
+
let(:cookie_lang) { 'en' }
|
66
88
|
|
67
|
-
|
89
|
+
it { is_expected.to eq [:en, '/'] }
|
68
90
|
|
69
|
-
|
91
|
+
end
|
70
92
|
|
71
93
|
end
|
72
94
|
|
73
|
-
|
95
|
+
describe 'locale asked in the request params' do
|
74
96
|
|
75
|
-
|
97
|
+
context 'the locale is blank' do
|
76
98
|
|
77
|
-
|
99
|
+
let(:url) { 'http://models.example.com?locale=' }
|
78
100
|
|
79
|
-
|
101
|
+
it { is_expected.to eq [:de, '/'] }
|
80
102
|
|
81
|
-
|
103
|
+
end
|
82
104
|
|
83
|
-
|
105
|
+
context 'the locale exists' do
|
84
106
|
|
85
|
-
|
107
|
+
let(:url) { 'http://models.example.com?locale=en' }
|
86
108
|
|
87
|
-
|
109
|
+
it { is_expected.to eq [:en, '/'] }
|
88
110
|
|
89
|
-
|
111
|
+
end
|
90
112
|
|
91
|
-
|
113
|
+
context 'the locale is unknown' do
|
92
114
|
|
93
|
-
|
115
|
+
let(:url) { 'http://models.example.com?locale=onload' }
|
94
116
|
|
95
|
-
|
117
|
+
it { is_expected.to eq [:de, '/'] }
|
96
118
|
|
97
|
-
|
119
|
+
end
|
98
120
|
|
99
121
|
end
|
100
|
-
|
101
122
|
end
|
102
123
|
end
|
@@ -27,11 +27,12 @@ describe Locomotive::Steam::Middlewares::Section do
|
|
27
27
|
}
|
28
28
|
|
29
29
|
before do
|
30
|
-
env['steam.page']
|
31
|
-
env['steam.services']
|
32
|
-
env['steam.locale']
|
33
|
-
env['steam.
|
34
|
-
env['steam.
|
30
|
+
env['steam.page'] = page
|
31
|
+
env['steam.services'] = services
|
32
|
+
env['steam.locale'] = :en
|
33
|
+
env['steam.liquid_registers'] = {}
|
34
|
+
env['steam.liquid_assigns'] = {}
|
35
|
+
env['steam.request'] = Rack::Request.new(env)
|
35
36
|
env['steam.request'].add_header('HTTP_LOCOMOTIVE_SECTION_TYPE', 'header')
|
36
37
|
allow(section_finder).to receive(:find).with('header').and_return(section)
|
37
38
|
end
|
@@ -10,6 +10,7 @@ describe Locomotive::Steam::Middlewares::Site do
|
|
10
10
|
let(:configuration) { instance_double('SimpleConfiguration', render_404_if_no_site: render_404) }
|
11
11
|
let(:services) { instance_double('SimpleServices', configuration: configuration) }
|
12
12
|
let(:url) { 'http://models.example.com' }
|
13
|
+
let(:engine_site) { nil }
|
13
14
|
let(:app) { ->(env) { [200, env, 'app'] } }
|
14
15
|
let(:middleware) { Locomotive::Steam::Middlewares::Site.new(app) }
|
15
16
|
let(:is_default_host) { nil }
|
@@ -17,6 +18,7 @@ describe Locomotive::Steam::Middlewares::Site do
|
|
17
18
|
subject do
|
18
19
|
env = env_for(url, 'steam.services' => services)
|
19
20
|
env['steam.request'] = Rack::Request.new(env)
|
21
|
+
env['steam.site'] = engine_site
|
20
22
|
env['steam.is_default_host'] = is_default_host
|
21
23
|
code, env = middleware.call(env)
|
22
24
|
[code, env['Location']]
|
@@ -42,6 +44,17 @@ describe Locomotive::Steam::Middlewares::Site do
|
|
42
44
|
|
43
45
|
end
|
44
46
|
|
47
|
+
describe 'the site has been set from the Engine' do
|
48
|
+
|
49
|
+
let(:engine_site) { instance_double('SiteWithDomains', name: 'Acme', domains: ['www.acme.com'], redirect_to_first_domain: false, redirect_to_https: false) }
|
50
|
+
|
51
|
+
it 'sets the site for all the services' do
|
52
|
+
expect(services).to receive(:set_site).with(engine_site).and_return(engine_site)
|
53
|
+
is_expected.to eq [200, nil]
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
45
58
|
describe 'redirection' do
|
46
59
|
|
47
60
|
let(:redirect_to_first_domain) { false }
|
@@ -2,13 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Locomotive::Steam::ActionService do
|
4
4
|
|
5
|
-
let(:site_hash)
|
6
|
-
let(:site)
|
7
|
-
let(:email_service)
|
8
|
-
let(:entry_service)
|
9
|
-
let(:api_service)
|
5
|
+
let(:site_hash) { { 'name' => 'Acme Corp' } }
|
6
|
+
let(:site) { instance_double('Site', as_json: site_hash ) }
|
7
|
+
let(:email_service) { instance_double('EmailService') }
|
8
|
+
let(:entry_service) { instance_double('ContentService') }
|
9
|
+
let(:api_service) { instance_double('ExternalAPIService') }
|
10
10
|
let(:redirection_service) { instance_double('PageRedirectionService') }
|
11
|
-
let(:
|
11
|
+
let(:cookie_service) { instance_double('CookieService') }
|
12
|
+
let(:service) { described_class.new(site, email_service, content_entry: entry_service, api: api_service, redirection: redirection_service, cookie: cookie_service) }
|
12
13
|
|
13
14
|
describe '#run' do
|
14
15
|
|
@@ -115,18 +116,23 @@ describe Locomotive::Steam::ActionService do
|
|
115
116
|
|
116
117
|
describe 'getCookiesProp' do
|
117
118
|
|
118
|
-
let(:cookies) { { 'name' => 'John' } }
|
119
119
|
let(:script) { "return getCookiesProp('name');" }
|
120
120
|
|
121
|
-
it
|
121
|
+
it 'should read in the cookie name and return John' do
|
122
|
+
expect(cookie_service).to receive(:get).with('name').and_return('John')
|
123
|
+
is_expected.to eq('John')
|
124
|
+
end
|
122
125
|
|
123
126
|
end
|
124
127
|
|
125
|
-
describe '
|
128
|
+
describe 'setCookiesProp' do
|
126
129
|
|
127
|
-
let(:script) { "return setCookiesProp('done', true);" }
|
130
|
+
let(:script) { "return setCookiesProp('done', {'value': true});" }
|
128
131
|
|
129
|
-
it
|
132
|
+
it 'should set the cookie done with the value true' do
|
133
|
+
expect(cookie_service).to receive(:set).with('done', {'value' => true})
|
134
|
+
is_expected.to eq(nil)
|
135
|
+
end
|
130
136
|
|
131
137
|
end
|
132
138
|
|