Skip to content

Commit 0be4dbc

Browse files
committed
test: write a spec to prove we can post a JSON request to a Locomotive page
1 parent e6fb512 commit 0be4dbc

File tree

5 files changed

+51
-18
lines changed

5 files changed

+51
-18
lines changed

Gemfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ end
1111
group :development, :test do
1212
gem 'puma', '~> 6.4.0'
1313
gem 'rspec-rails', '~> 6.0.1'
14-
gem 'capybara', '~> 3.39.0'
14+
gem 'capybara', '~> 3.40'
15+
gem "rack", "3.1.8"
16+
1517
# gem 'custom_fields', path: '../custom_fields' # for Developers
1618
gem 'custom_fields', github: 'locomotivecms/custom_fields', ref: '87bf1b389d'
1719

1820
# gem 'locomotivecms_common', path: '../common', require: false
1921
# gem 'locomotivecms_common', github: 'locomotivecms/common', ref: '054505c', require: false
2022

2123
# gem 'locomotivecms_steam', path: '../steam', require: false
22-
gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: '4386db6', require: false
24+
gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: 'ba10b57', require: false
2325
end
2426

2527
group :test do

Gemfile.lock

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ GIT
1212

1313
GIT
1414
remote: https://github.com/locomotivecms/steam.git
15-
revision: 4386db65ad9982df326729682a2a11c6db8843c8
16-
ref: 4386db6
15+
revision: ba10b57b1aabbb434a9202d9296436355c988757
16+
ref: ba10b57
1717
specs:
1818
locomotivecms_steam (1.8.0.alpha2)
1919
RedCloth (~> 4.3.2)
@@ -22,7 +22,7 @@ GIT
2222
dragonfly (~> 1.4.0)
2323
duktape (~> 2.0.1.1)
2424
execjs (~> 2.9.1)
25-
httparty (~> 0.21.0)
25+
httparty (~> 0.22.0)
2626
kramdown (~> 2.3.0)
2727
liquid (~> 4.0.4)
2828
locomotivecms_common (~> 0.6.0.alpha1)
@@ -31,7 +31,8 @@ GIT
3131
moneta (~> 1.6.0)
3232
morphine (~> 0.1.1)
3333
multi_json (~> 1.15.0)
34-
nokogiri (~> 1.15.6)
34+
nokogiri (~> 1.16.7)
35+
parser (~> 3.3)
3536
pony (~> 1.12)
3637
rack-cache (>= 1.7, < 2)
3738
rack-rewrite (~> 1.5.1)
@@ -171,6 +172,7 @@ GEM
171172
adomain (0.2.4)
172173
addressable (~> 2.5)
173174
logger
175+
ast (2.4.2)
174176
attr_extras (7.1.0)
175177
autoprefixer-rails (10.4.15.0)
176178
execjs (~> 2)
@@ -187,11 +189,11 @@ GEM
187189
sassc (>= 2.0.0)
188190
bson (4.15.0)
189191
builder (3.2.4)
190-
capybara (3.39.2)
192+
capybara (3.40.0)
191193
addressable
192194
matrix
193195
mini_mime (>= 0.1.3)
194-
nokogiri (~> 1.8)
196+
nokogiri (~> 1.11)
195197
rack (>= 1.6.0)
196198
rack-test (>= 0.6.3)
197199
regexp_parser (>= 1.5, < 3.0)
@@ -217,6 +219,7 @@ GEM
217219
concurrent-ruby (1.2.2)
218220
connection_pool (2.4.1)
219221
crass (1.0.6)
222+
csv (3.3.0)
220223
database_cleaner-core (2.0.1)
221224
database_cleaner-mongoid (2.0.1)
222225
database_cleaner-core (~> 2.0.0)
@@ -286,7 +289,8 @@ GEM
286289
multi_json (>= 1.3.2)
287290
highline (2.1.0)
288291
htmlentities (4.3.4)
289-
httparty (0.21.0)
292+
httparty (0.22.0)
293+
csv
290294
mini_mime (>= 1.0.0)
291295
multi_xml (>= 0.5.2)
292296
i18n (1.14.1)
@@ -385,10 +389,13 @@ GEM
385389
net-smtp (0.4.0)
386390
net-protocol
387391
nio4r (2.6.0)
388-
nokogiri (1.15.6-x86_64-darwin)
392+
nokogiri (1.16.7-x86_64-darwin)
389393
racc (~> 1.4)
390394
origin (2.3.1)
391395
orm_adapter (0.5.0)
396+
parser (3.3.5.0)
397+
ast (~> 2.4.1)
398+
racc
392399
pony (1.13.1)
393400
mail (>= 2.0)
394401
psych (5.1.1.1)
@@ -399,7 +406,7 @@ GEM
399406
pundit (2.3.1)
400407
activesupport (>= 3.0.0)
401408
racc (1.7.3)
402-
rack (3.0.8)
409+
rack (3.1.8)
403410
rack-cache (1.14.0)
404411
rack (>= 0.4)
405412
rack-rewrite (1.5.1)
@@ -451,7 +458,7 @@ GEM
451458
rake (13.1.0)
452459
rdoc (6.6.0)
453460
psych (>= 4.0.0)
454-
regexp_parser (2.8.2)
461+
regexp_parser (2.9.2)
455462
reline (0.4.0)
456463
io-console (~> 0.5)
457464
responders (3.1.1)
@@ -557,7 +564,7 @@ PLATFORMS
557564
x86_64-darwin-22
558565

559566
DEPENDENCIES
560-
capybara (~> 3.39.0)
567+
capybara (~> 3.40)
561568
custom_fields!
562569
database_cleaner-mongoid (~> 2.0.1)
563570
debug (~> 1.9.2)
@@ -568,6 +575,7 @@ DEPENDENCIES
568575
locomotivecms!
569576
locomotivecms_steam!
570577
puma (~> 6.4.0)
578+
rack (= 3.1.8)
571579
rails-controller-testing
572580
rspec-rails (~> 6.0.1)
573581
selenium-webdriver (= 4.10)

spec/api/locomotive/api/resources/content_entry_resource_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
it 'returns a successful response' do
3030
expect(last_response).to be_successful
3131
expect(parsed_response.size).to eq 1
32-
expect(last_response.header['X-Per-Page'].to_i).to eq 1
33-
expect(last_response.header['X-Total-Entries'].to_i).to eq 2
34-
expect(last_response.header['X-Total-Pages'].to_i).to eq 2
32+
expect(last_response.headers['X-Per-Page'].to_i).to eq 1
33+
expect(last_response.headers['X-Total-Entries'].to_i).to eq 2
34+
expect(last_response.headers['X-Total-Pages'].to_i).to eq 2
3535
end
3636

3737
end

spec/requests/json_page_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe 'Locomotive JSON page', type: :request do
4+
5+
let(:site) { create('existing site', domains: ['www.example.com']) }
6+
7+
before do
8+
page = site.pages.create(
9+
parent: site.pages.root.first,
10+
title: 'Post form',
11+
slug: 'post-form',
12+
response_type: 'application/json',
13+
published: true,
14+
raw_template: %({ "email":"{{ params.email }}" })
15+
)
16+
end
17+
18+
it 'returns a response' do
19+
headers = { 'ACCEPT' => 'application/json', 'Content-Type' => 'application/json' }
20+
post "/post-form.json", params: { email: '[email protected]' }, headers: headers, as: :json
21+
expect(response).to have_http_status(200)
22+
expect(response.body).to eq(%({ "email":"[email protected]" }))
23+
end
24+
25+
end

spec/system/public_form_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,5 @@
2626
expect(page).to have_content('num errors: 1')
2727
expect(page).to have_content("-name can't be blank-")
2828
end
29-
3029
end
31-
3230
end

0 commit comments

Comments
 (0)