locomotivecms_coal 1.0.0.pre.alpha.1 → 1.0.0.pre.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.gitignore +1 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +23 -12
  6. data/README.md +167 -10
  7. data/lib/locomotive/coal/client.rb +70 -20
  8. data/lib/locomotive/coal/client_v2.rb +31 -0
  9. data/lib/locomotive/coal/error.rb +46 -5
  10. data/lib/locomotive/coal/resources/base.rb +57 -0
  11. data/lib/locomotive/coal/resources/concerns/request.rb +101 -0
  12. data/lib/locomotive/coal/resources/content_assets.rb +9 -0
  13. data/lib/locomotive/coal/resources/content_entries.rb +17 -11
  14. data/lib/locomotive/coal/resources/{contents.rb → content_types.rb} +4 -5
  15. data/lib/locomotive/coal/resources/engine_version.rb +15 -0
  16. data/lib/locomotive/coal/resources/my_account.rb +14 -2
  17. data/lib/locomotive/coal/resources/pages.rb +25 -0
  18. data/lib/locomotive/coal/resources/sites.rb +5 -17
  19. data/lib/locomotive/coal/resources/snippets.rb +9 -0
  20. data/lib/locomotive/coal/resources/theme_assets.rb +13 -0
  21. data/lib/locomotive/coal/resources/token.rb +2 -2
  22. data/lib/locomotive/coal/resources/translations.rb +9 -0
  23. data/lib/locomotive/coal/upload_io.rb +11 -0
  24. data/lib/locomotive/coal/version.rb +1 -1
  25. data/lib/locomotive/coal.rb +11 -3
  26. data/locomotivecms_coal.gemspec +4 -4
  27. data/spec/fixtures/assets/locomotive.png +0 -0
  28. data/spec/fixtures/assets/rails.png +0 -0
  29. data/spec/fixtures/coal_cassettes/client.yml +333 -69
  30. data/spec/fixtures/coal_cassettes/content_assets.yml +595 -0
  31. data/spec/fixtures/coal_cassettes/content_entries.yml +1134 -223
  32. data/spec/fixtures/coal_cassettes/content_types.yml +616 -0
  33. data/spec/fixtures/coal_cassettes/my_account.yml +167 -47
  34. data/spec/fixtures/coal_cassettes/pages.yml +281 -0
  35. data/spec/fixtures/coal_cassettes/sites.yml +93 -117
  36. data/spec/fixtures/coal_cassettes/snippets.yml +227 -0
  37. data/spec/fixtures/coal_cassettes/theme_assets.yml +406 -0
  38. data/spec/fixtures/coal_cassettes/token.yml +37 -55
  39. data/spec/fixtures/coal_cassettes/translations.yml +227 -0
  40. data/spec/fixtures/coal_cassettes/version.yml +89 -0
  41. data/spec/integration/client_spec.rb +37 -3
  42. data/spec/integration/resources/content_assets_spec.rb +42 -0
  43. data/spec/integration/resources/content_entries_spec.rb +45 -18
  44. data/spec/integration/resources/content_types_spec.rb +44 -0
  45. data/spec/integration/resources/engine_version_spec.rb +17 -0
  46. data/spec/integration/resources/my_account_spec.rb +22 -5
  47. data/spec/integration/resources/pages_spec.rb +43 -0
  48. data/spec/integration/resources/sites_spec.rb +9 -9
  49. data/spec/integration/resources/snippets_spec.rb +38 -0
  50. data/spec/integration/resources/theme_assets_spec.rb +43 -0
  51. data/spec/integration/resources/token_spec.rb +7 -7
  52. data/spec/integration/resources/translations_spec.rb +38 -0
  53. data/spec/spec_helper.rb +2 -13
  54. data/spec/support/api_settings.rb +7 -3
  55. data/spec/support/assets.rb +4 -0
  56. data/spec/support/vcr.rb +10 -0
  57. data/spec/unit/error_spec.rb +28 -0
  58. metadata +71 -13
  59. data/lib/locomotive/coal/request.rb +0 -63
  60. data/spec/fixtures/coal_cassettes/contents.yml +0 -120
  61. data/spec/integration/resources/contents_spec.rb +0 -22
@@ -0,0 +1,227 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:3000/locomotive/api/v3/tokens.json
6
+ body:
7
+ encoding: UTF-8
8
+ string: email=admin%40locomotivecms.com&password=locomotive
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 201
21
+ message: Created
22
+ headers:
23
+ Content-Type:
24
+ - application/json
25
+ Content-Length:
26
+ - '32'
27
+ Etag:
28
+ - W/"6ba0e226b40adfde2d656d9027a1335f"
29
+ Cache-Control:
30
+ - max-age=0, private, must-revalidate
31
+ X-Request-Id:
32
+ - 751faab6-a693-4324-b30e-6f3166e7c8c3
33
+ X-Runtime:
34
+ - '0.017173'
35
+ Connection:
36
+ - keep-alive
37
+ Server:
38
+ - thin
39
+ body:
40
+ encoding: UTF-8
41
+ string: '{"token":"Z9s7W_-BXyGQsDPFsorr"}'
42
+ http_version:
43
+ recorded_at: Mon, 04 May 2015 13:51:29 GMT
44
+ - request:
45
+ method: get
46
+ uri: http://localhost:3000/locomotive/sample/api/v3/translations.json
47
+ body:
48
+ encoding: UTF-8
49
+ string: auth_token=Z9s7W_-BXyGQsDPFsorr
50
+ headers:
51
+ Accept:
52
+ - application/json
53
+ X-Locomotive-Account-Email:
54
+ - admin@locomotivecms.com
55
+ X-Locomotive-Account-Token:
56
+ - Z9s7W_-BXyGQsDPFsorr
57
+ Content-Type:
58
+ - application/x-www-form-urlencoded
59
+ Accept-Encoding:
60
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
61
+ User-Agent:
62
+ - Ruby
63
+ response:
64
+ status:
65
+ code: 200
66
+ message: OK
67
+ headers:
68
+ Content-Type:
69
+ - application/json
70
+ Content-Length:
71
+ - '2'
72
+ Etag:
73
+ - W/"d751713988987e9331980363e24189ce"
74
+ Cache-Control:
75
+ - max-age=0, private, must-revalidate
76
+ X-Request-Id:
77
+ - ad679182-c1eb-4da7-b17d-b50d1311dd89
78
+ X-Runtime:
79
+ - '0.046291'
80
+ Connection:
81
+ - keep-alive
82
+ Server:
83
+ - thin
84
+ body:
85
+ encoding: UTF-8
86
+ string: "[]"
87
+ http_version:
88
+ recorded_at: Mon, 04 May 2015 13:51:29 GMT
89
+ - request:
90
+ method: post
91
+ uri: http://localhost:3000/locomotive/sample/api/v3/translations.json
92
+ body:
93
+ encoding: UTF-8
94
+ string: auth_token=Z9s7W_-BXyGQsDPFsorr&translation%5Bkey%5D=hello&translation%5Bvalues%5D%5Ben%5D=Hello+world&translation%5Bvalues%5D%5Bfr%5D=Bonjour+le+monde
95
+ headers:
96
+ Accept:
97
+ - application/json
98
+ X-Locomotive-Account-Email:
99
+ - admin@locomotivecms.com
100
+ X-Locomotive-Account-Token:
101
+ - Z9s7W_-BXyGQsDPFsorr
102
+ Content-Type:
103
+ - application/x-www-form-urlencoded
104
+ Accept-Encoding:
105
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
106
+ User-Agent:
107
+ - Ruby
108
+ response:
109
+ status:
110
+ code: 201
111
+ message: Created
112
+ headers:
113
+ Content-Type:
114
+ - application/json
115
+ Content-Length:
116
+ - '174'
117
+ Etag:
118
+ - W/"76f9bdf1fd5be82b02603ebc3502c37d"
119
+ Cache-Control:
120
+ - max-age=0, private, must-revalidate
121
+ X-Request-Id:
122
+ - ec8868b6-fc88-4124-9683-7cc4ac98f016
123
+ X-Runtime:
124
+ - '0.027800'
125
+ Connection:
126
+ - keep-alive
127
+ Server:
128
+ - thin
129
+ body:
130
+ encoding: UTF-8
131
+ string: '{"_id":"554779616469643251300300","created_at":"2015-05-04T13:51:29Z","updated_at":"2015-05-04T13:51:29Z","key":"hello","values":{"en":"Hello
132
+ world","fr":"Bonjour le monde"}}'
133
+ http_version:
134
+ recorded_at: Mon, 04 May 2015 13:51:29 GMT
135
+ - request:
136
+ method: put
137
+ uri: http://localhost:3000/locomotive/sample/api/v3/translations/554779616469643251300300.json
138
+ body:
139
+ encoding: UTF-8
140
+ string: auth_token=Z9s7W_-BXyGQsDPFsorr&translation%5Bvalues%5D%5Ben%5D=Hello+world%21&translation%5Bvalues%5D%5Bfr%5D=Bonjour+le+monde%21
141
+ headers:
142
+ Accept:
143
+ - application/json
144
+ X-Locomotive-Account-Email:
145
+ - admin@locomotivecms.com
146
+ X-Locomotive-Account-Token:
147
+ - Z9s7W_-BXyGQsDPFsorr
148
+ Content-Type:
149
+ - application/x-www-form-urlencoded
150
+ Accept-Encoding:
151
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
152
+ User-Agent:
153
+ - Ruby
154
+ response:
155
+ status:
156
+ code: 200
157
+ message: OK
158
+ headers:
159
+ Content-Type:
160
+ - application/json
161
+ Content-Length:
162
+ - '176'
163
+ Etag:
164
+ - W/"f19c11b58a3b1372154f14f944c36b79"
165
+ Cache-Control:
166
+ - max-age=0, private, must-revalidate
167
+ X-Request-Id:
168
+ - 9305074c-bb4d-4614-a0e2-966f933f3ebd
169
+ X-Runtime:
170
+ - '0.033007'
171
+ Connection:
172
+ - keep-alive
173
+ Server:
174
+ - thin
175
+ body:
176
+ encoding: UTF-8
177
+ string: '{"_id":"554779616469643251300300","created_at":"2015-05-04T13:51:29Z","updated_at":"2015-05-04T13:51:29Z","key":"hello","values":{"en":"Hello
178
+ world!","fr":"Bonjour le monde!"}}'
179
+ http_version:
180
+ recorded_at: Mon, 04 May 2015 13:51:29 GMT
181
+ - request:
182
+ method: delete
183
+ uri: http://localhost:3000/locomotive/sample/api/v3/translations/554779616469643251300300.json
184
+ body:
185
+ encoding: UTF-8
186
+ string: auth_token=Z9s7W_-BXyGQsDPFsorr
187
+ headers:
188
+ Accept:
189
+ - application/json
190
+ X-Locomotive-Account-Email:
191
+ - admin@locomotivecms.com
192
+ X-Locomotive-Account-Token:
193
+ - Z9s7W_-BXyGQsDPFsorr
194
+ Content-Type:
195
+ - application/x-www-form-urlencoded
196
+ Accept-Encoding:
197
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
198
+ User-Agent:
199
+ - Ruby
200
+ response:
201
+ status:
202
+ code: 200
203
+ message: OK
204
+ headers:
205
+ Content-Type:
206
+ - application/json
207
+ Content-Length:
208
+ - '176'
209
+ Etag:
210
+ - W/"f19c11b58a3b1372154f14f944c36b79"
211
+ Cache-Control:
212
+ - max-age=0, private, must-revalidate
213
+ X-Request-Id:
214
+ - ea91f6ca-641b-4b4c-b46a-db03331d8d4c
215
+ X-Runtime:
216
+ - '0.029273'
217
+ Connection:
218
+ - keep-alive
219
+ Server:
220
+ - thin
221
+ body:
222
+ encoding: UTF-8
223
+ string: '{"_id":"554779616469643251300300","created_at":"2015-05-04T13:51:29Z","updated_at":"2015-05-04T13:51:29Z","key":"hello","values":{"en":"Hello
224
+ world!","fr":"Bonjour le monde!"}}'
225
+ http_version:
226
+ recorded_at: Mon, 04 May 2015 13:51:29 GMT
227
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,89 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:3000/locomotive/api/v3/tokens.json
6
+ body:
7
+ encoding: UTF-8
8
+ string: email=admin%40locomotivecms.com&password=locomotive
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 201
21
+ message: Created
22
+ headers:
23
+ Content-Type:
24
+ - application/json
25
+ Content-Length:
26
+ - '32'
27
+ Etag:
28
+ - W/"0f853a81c9a270d46e518678936141a4"
29
+ Cache-Control:
30
+ - max-age=0, private, must-revalidate
31
+ X-Request-Id:
32
+ - 58c7202e-070a-4c41-b134-b7bb2cb3135a
33
+ X-Runtime:
34
+ - '0.013219'
35
+ Connection:
36
+ - keep-alive
37
+ Server:
38
+ - thin
39
+ body:
40
+ encoding: UTF-8
41
+ string: '{"token":"iHshzhpQSyX55mXWnAuj"}'
42
+ http_version:
43
+ recorded_at: Tue, 12 May 2015 13:15:27 GMT
44
+ - request:
45
+ method: get
46
+ uri: http://localhost:3000/locomotive/sample/api/v3/version.json
47
+ body:
48
+ encoding: UTF-8
49
+ string: auth_token=iHshzhpQSyX55mXWnAuj&email=admin%40locomotivecms.com&token=iHshzhpQSyX55mXWnAuj
50
+ headers:
51
+ Accept:
52
+ - application/json
53
+ X-Locomotive-Account-Email:
54
+ - admin@locomotivecms.com
55
+ X-Locomotive-Account-Token:
56
+ - iHshzhpQSyX55mXWnAuj
57
+ Content-Type:
58
+ - application/x-www-form-urlencoded
59
+ Accept-Encoding:
60
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
61
+ User-Agent:
62
+ - Ruby
63
+ response:
64
+ status:
65
+ code: 200
66
+ message: OK
67
+ headers:
68
+ Content-Type:
69
+ - application/json
70
+ Content-Length:
71
+ - '18'
72
+ Etag:
73
+ - W/"02b2733eaed04ddde340a02b57d9bc85"
74
+ Cache-Control:
75
+ - max-age=0, private, must-revalidate
76
+ X-Request-Id:
77
+ - ccaf5529-eb60-40a5-a4db-7264c82f4010
78
+ X-Runtime:
79
+ - '0.009330'
80
+ Connection:
81
+ - keep-alive
82
+ Server:
83
+ - thin
84
+ body:
85
+ encoding: UTF-8
86
+ string: '{"engine":"3.0.0"}'
87
+ http_version:
88
+ recorded_at: Tue, 12 May 2015 13:15:27 GMT
89
+ recorded_with: VCR 2.9.3
@@ -5,9 +5,10 @@ describe Locomotive::Coal::Client do
5
5
  before { VCR.insert_cassette 'client', record: :new_episodes }
6
6
  after { VCR.eject_cassette }
7
7
 
8
- let(:uri) { 'http://sample.lvh.me:4000/locomotive/api' }
9
- let(:credentials) { { email: 'john@doe.net', password: 'easyone' } }
10
- let(:client) { described_class.new(uri, credentials) }
8
+ let(:uri) { TEST_API_URI.dup }
9
+ let(:credentials) { TEST_API_CREDENTIALS.dup }
10
+ let(:options) { {} }
11
+ let(:client) { described_class.new(uri, credentials, options) }
11
12
 
12
13
  describe '#my_token' do
13
14
  subject { client.token }
@@ -19,15 +20,48 @@ describe Locomotive::Coal::Client do
19
20
  it { is_expected.not_to eq nil }
20
21
  end
21
22
 
23
+ describe '#engine_version' do
24
+ subject { client.engine_version }
25
+ it { is_expected.to match(/\A\d\..+/) }
26
+ end
27
+
28
+ describe '#version' do
29
+ subject { client.version }
30
+ it { is_expected.to match(/\A\d\..+/) }
31
+ end
32
+
22
33
  describe '#sites' do
23
34
  subject { client.sites.all.first }
24
35
  it { is_expected.not_to eq nil }
25
36
  end
26
37
 
38
+ context 'scoped by a site' do
39
+
40
+ let(:options) { { handle: 'sample' } }
41
+
42
+ describe '#snippets' do
43
+ subject { client.snippets.all }
44
+ it { is_expected.to eq [] }
45
+ end
46
+
47
+ describe '#translations' do
48
+ subject { client.translations.all }
49
+ it { is_expected.to eq [] }
50
+ end
51
+
52
+ describe '#theme_assets' do
53
+ subject { client.theme_assets.all }
54
+ it { is_expected.to eq [] }
55
+ end
56
+
57
+ end
58
+
27
59
  describe '#scope_by' do
60
+ let(:uri) { 'http://www.example.com:3000/locomotive/api/v3' }
28
61
  let(:site) { client.sites.all.first }
29
62
  subject { client.scope_by(site) }
30
63
  it { is_expected.to eq client }
64
+ it { expect(subject.options[:handle]).to eq 'www' }
31
65
  end
32
66
 
33
67
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Coal::Resources::ContentAssets, order: :defined do
4
+
5
+ before { VCR.insert_cassette 'content_assets', record: :new_episodes }
6
+ after { VCR.eject_cassette }
7
+
8
+ let(:uri) { TEST_SITE_API_V3_URI }
9
+ let(:credentials) { { email: TEST_API_EMAIL, token: api_token } }
10
+ let(:content_assets) { described_class.new(uri, credentials) }
11
+
12
+ describe '#all' do
13
+ subject { content_assets.all }
14
+ it { expect(subject).not_to eq nil }
15
+ end
16
+
17
+ describe '#create' do
18
+ subject { create_content_asset }
19
+ it { expect(subject._id).not_to eq nil }
20
+ end
21
+
22
+ describe '#update' do
23
+ let(:content_asset) { single_content_asset || create_content_asset }
24
+ subject { content_assets.update(content_asset._id, source: asset_io('locomotive.png')) }
25
+ it { expect(subject.url).to match /locomotive.png$/ }
26
+ end
27
+
28
+ describe '#destroy' do
29
+ let(:content_asset) { single_content_asset || create_content_asset }
30
+ subject { content_assets.destroy(content_asset._id) }
31
+ it { expect(subject._id).not_to eq nil }
32
+ end
33
+
34
+ def create_content_asset
35
+ content_assets.create(source: asset_io('rails.png'))
36
+ end
37
+
38
+ def single_content_asset
39
+ content_assets.all.detect { |a| a.url =~ /rails.png$/ }
40
+ end
41
+
42
+ end
@@ -1,14 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Locomotive::Coal::Resources::ContentEntries do
3
+ describe Locomotive::Coal::Resources::ContentEntries, order: :defined do
4
4
 
5
- before { VCR.insert_cassette 'content_entries', record: :new_episodes }
6
- after { VCR.eject_cassette }
5
+ before(:all) do
6
+ VCR.insert_cassette 'content_entries', record: :new_episodes, match_requests_on: [:method, :query, :body]
7
+ @content_type = build_content_types.create(name: 'Article', slug: 'articles', fields: [{ label: 'Title', name: 'title', type: 'string', localized: true }])
8
+ end
9
+
10
+ after(:all) do
11
+ build_content_types.destroy(@content_type._id)
12
+ VCR.eject_cassette
13
+ end
7
14
 
8
- let(:uri) { TEST_API_URI }
9
- let(:token) { api_token }
10
- let(:content_type) { Locomotive::Coal::Resources::Contents.new(uri, token).by_slug(:bands) }
11
- let(:entries) { described_class.new(uri, token, content_type) }
15
+ let(:uri) { TEST_SITE_API_V3_URI }
16
+ let(:credentials) { { email: TEST_API_EMAIL, token: api_token } }
17
+ let(:content_type) { @content_type }
18
+ let(:entries) { described_class.new(uri, credentials, content_type) }
12
19
 
13
20
  describe '#all' do
14
21
 
@@ -17,36 +24,56 @@ describe Locomotive::Coal::Resources::ContentEntries do
17
24
 
18
25
  subject { entries.all(query, options) }
19
26
 
20
- it { expect(subject.size).not_to eq 0 }
21
- it { expect(subject._total_pages).not_to eq 0 }
22
- it { expect(subject._total_entries).not_to eq 0 }
27
+ before { entries.create(title: 'Hello world'); entries.create(title: 'Lorem ipsum') }
28
+ after { ['hello-world', 'lorem-ipsum'].each { |slug| entries.destroy(slug) } }
29
+
30
+ it 'returns a paginated list of entries' do
31
+ expect(subject.size).to be >= 2
32
+ expect(subject._total_pages).to eq 1
33
+ expect(subject._total_entries).to be >= 2
34
+ end
23
35
 
24
36
  describe 'pagination' do
25
37
 
26
- let(:options) { { page: 2, per_page: 2 } }
38
+ let(:options) { { page: 2, per_page: 1 } }
27
39
 
28
- it { expect(subject.size).not_to eq 0 }
29
- it { expect(subject._total_pages).to be > 1 }
30
- it { expect(subject._total_entries).to be > 1 }
40
+ it 'returns the second page of entries' do
41
+ expect(subject.size).to eq 1
42
+ expect(subject._total_pages).to be >= 2
43
+ expect(subject._total_entries).to be >= 2
44
+ end
31
45
 
32
46
  end
33
47
 
34
48
  describe 'filter' do
35
49
 
36
- let(:query) { { _visible: true, name: 'Pearl Jam' } }
50
+ let(:query) { { _visible: true, title: 'Hello world' } }
37
51
 
38
52
  it { expect(subject.size).to eq 1 }
39
53
 
40
54
  end
55
+
41
56
  end
42
57
 
43
58
  describe '#update' do
44
59
 
45
- let(:entry) { entries.all.first }
46
- subject { entries.update(entry._id, { name: 'Pearl Jam' }) }
60
+ let(:entry) { entries.create(title: 'Random title') }
61
+ subject { entries.update(entry._slug, { title: 'Random title!' }) }
62
+
63
+ it { expect(subject.title).to eq 'Random title!' }
47
64
 
48
- it { expect(subject._id).to eq entry._id }
65
+ describe 'with a localized content entry' do
66
+
67
+ subject { entries.update(entry._id, { title: 'Titre au hasard' }, :fr) }
68
+
69
+ it { expect(subject.title).to eq 'Titre au hasard' }
70
+
71
+ end
72
+
73
+ end
49
74
 
75
+ def build_content_types
76
+ Locomotive::Coal::Resources::ContentTypes.new(TEST_SITE_API_V3_URI, { email: TEST_API_EMAIL, token: api_token })
50
77
  end
51
78
 
52
79
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Coal::Resources::ContentTypes, order: :defined do
4
+
5
+ before(:all) { VCR.insert_cassette 'content_types', record: :new_episodes, match_requests_on: [:method, :query, :body] }
6
+ after(:all) { VCR.eject_cassette }
7
+
8
+ let(:uri) { TEST_SITE_API_V3_URI }
9
+ let(:credentials) { { email: TEST_API_EMAIL, token: api_token } }
10
+ let(:content_types) { described_class.new(uri, credentials) }
11
+
12
+ describe '#all' do
13
+ subject { content_types.all }
14
+ it { expect(subject).not_to eq nil }
15
+ end
16
+
17
+ describe '#create' do
18
+ subject { create_content_type }
19
+ it { expect(subject._id).not_to eq nil }
20
+ end
21
+
22
+ describe '#update' do
23
+ let(:content_type) { content_types.all.detect { |s| s.slug == 'projects' } || create_content_type }
24
+ subject { content_types.update(content_type._id, name: 'Our projects') }
25
+ it { expect(subject.name).to eq 'Our projects' }
26
+ end
27
+
28
+ describe '#destroy' do
29
+ let(:content_type) { content_types.all.detect { |s| s.slug == 'projects' } || create_content_type }
30
+ subject { content_types.destroy(content_type._id) }
31
+ it { expect(subject._id).not_to eq nil }
32
+ end
33
+
34
+ describe '#by_slug' do
35
+ before { content_types.all.detect { |s| s.slug == 'projects' } || create_content_type }
36
+ subject { content_types.by_slug(:projects) }
37
+ it { expect(subject).not_to eq nil }
38
+ end
39
+
40
+ def create_content_type
41
+ content_types.create(name: 'Projects', slug: 'projects', fields: [{ label: 'Name', name: 'name', type: 'string' }])
42
+ end
43
+
44
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Coal::Resources::EngineVersion do
4
+
5
+ before { VCR.insert_cassette 'version' }
6
+ after { VCR.eject_cassette }
7
+
8
+ let(:uri) { TEST_SITE_API_V3_URI }
9
+ let(:credentials) { { email: TEST_API_EMAIL, token: api_token } }
10
+ let(:engine_version) { described_class.new(uri, credentials) }
11
+
12
+ describe '#version' do
13
+ subject { engine_version.version }
14
+ it { is_expected.to match(/\A\d\..+/) }
15
+ end
16
+
17
+ end
@@ -2,16 +2,33 @@ require 'spec_helper'
2
2
 
3
3
  describe Locomotive::Coal::Resources::MyAccount do
4
4
 
5
- before { VCR.insert_cassette 'my_account', record: :new_episodes }
5
+ before { VCR.insert_cassette 'my_account', record: :new_episodes, match_requests_on: [:method, :query, :body] }
6
6
  after { VCR.eject_cassette }
7
7
 
8
- let(:uri) { TEST_API_URI }
9
- let(:token) { api_token }
10
- let(:my_account) { described_class.new(uri, token) }
8
+ let(:uri) { TEST_API_V3_URI }
9
+ let(:credentials) { { email: TEST_API_EMAIL, token: api_token } }
10
+ let(:resource) { described_class.new(uri, credentials) }
11
11
 
12
12
  describe '#get' do
13
- subject { my_account.get }
13
+ subject { resource.get }
14
14
  it { expect(subject.name).not_to eq nil }
15
15
  end
16
16
 
17
+ describe '#create' do
18
+ let(:credentials) { nil }
19
+ let(:attributes) { { name: 'Jack Doe', email: 'jack@doe.net', password: 'easyone', password_confirmation: 'easyone' } }
20
+ subject { resource.create(attributes) }
21
+ it { expect(subject._id).not_to eq nil }
22
+
23
+ describe 'missing attributes' do
24
+ let(:attributes) { { name: 'Wrong account' } }
25
+ it { expect { subject }.to raise_error(Locomotive::Coal::InvalidResourceError, 'Resource invalid: email is missing, password is missing') }
26
+ end
27
+ end
28
+
29
+ describe '#update' do
30
+ subject { resource.update(name: 'John Doe') }
31
+ it { expect(subject._id).not_to eq nil }
32
+ end
33
+
17
34
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Coal::Resources::Pages, order: :defined do
4
+
5
+ before { VCR.insert_cassette 'pages', record: :new_episodes }
6
+ after { VCR.eject_cassette }
7
+
8
+ let(:uri) { TEST_SITE_API_V3_URI }
9
+ let(:credentials) { { email: TEST_API_EMAIL, token: api_token } }
10
+ let(:pages) { described_class.new(uri, credentials) }
11
+
12
+ describe '#all' do
13
+ subject { pages.all(:en) }
14
+ it { expect(subject).not_to eq nil }
15
+ end
16
+
17
+ describe '#fullpaths' do
18
+ subject { pages.fullpaths(:en) }
19
+ it { expect(subject).not_to eq nil }
20
+ end
21
+
22
+ describe '#create' do
23
+ subject { create_page }
24
+ it { expect(subject._id).not_to eq nil }
25
+ end
26
+
27
+ describe '#update' do
28
+ let(:page) { pages.all(:en).detect { |s| s.fullpath == 'about-us' } || create_page }
29
+ subject { pages.update(page._id, { template: 'Locomotive rocks. period' }, :en) }
30
+ it { expect(subject.template).to eq 'Locomotive rocks. period' }
31
+ end
32
+
33
+ describe '#destroy' do
34
+ let(:page) { pages.all(:en).detect { |s| s.fullpath == 'about-us' } || create_page }
35
+ subject { pages.destroy(page._id) }
36
+ it { expect(subject._id).not_to eq nil }
37
+ end
38
+
39
+ def create_page
40
+ pages.create(title: 'About us', slug: 'about-us', parent: 'index', template: 'Locomotive rocks!')
41
+ end
42
+
43
+ end