This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
pages_spec.rb
93 lines (74 loc) · 1.98 KB
/
pages_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# frozen_string_literal: true
require 'rails_helper'
describe 'api/pages' do
def json
JSON.parse(response.body)
end
let(:expected) do
%w(
id
title
slug
content
created_at
updated_at
publish_status
campaign_action_count
action_count
language
featured
image
url
)
end
describe 'GET index' do
before do
create(:page, :published, title: 'Foo', content: 'Bar')
end
subject { JSON.parse(response.body) }
before { get('/api/pages.json') }
it 'returns list of pages' do
expect(subject.size).to eq(1)
expect(subject.first.keys).to match_array(expected)
expect(subject.first.symbolize_keys).to include(title: 'Foo',
content: 'Bar')
end
end
describe 'GET featured' do
before do
create(:page, :published, featured: true, title: 'Foo', content: 'Bar')
create(:page, featured: false)
end
subject { JSON.parse(response.body) }
before { get(featured_api_pages_path(format: :json)) }
it 'returns list of pages' do
expect(subject.size).to eq(1)
expect(subject.first.keys).to match_array(expected)
expect(subject.first.symbolize_keys).to include(title: 'Foo',
content: 'Bar')
end
end
describe 'GET show' do
let(:page) { create(:page, title: 'Foo', content: 'Bar') }
subject { JSON.parse(response.body) }
before { get(api_page_path(page, format: :json)) }
it 'returns page' do
expected = %w(
id
title
slug
content
created_at
updated_at
publish_status
featured
action_count
language
campaign_action_count
)
expect(subject.keys).to match_array(expected)
expect(subject.symbolize_keys).to include(title: 'Foo',
id: page.id)
end
end
end