locomotivecms_coal 1.7.0 → 1.8.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/locomotive/coal/resources/concerns/request.rb +1 -1
- data/lib/locomotive/coal/version.rb +1 -1
- metadata +20 -123
- data/.gitignore +0 -4
- data/.rspec +0 -2
- data/.travis.yml +0 -7
- data/Gemfile +0 -20
- data/Gemfile.lock +0 -122
- data/Rakefile +0 -21
- data/locomotivecms_coal.gemspec +0 -27
- data/spec/fixtures/assets/locomotive.png +0 -0
- data/spec/fixtures/assets/rails.png +0 -0
- data/spec/fixtures/coal_cassettes/accounts.yml +0 -214
- data/spec/fixtures/coal_cassettes/client.yml +0 -479
- data/spec/fixtures/coal_cassettes/content_assets.yml +0 -270
- data/spec/fixtures/coal_cassettes/content_entries.yml +0 -2189
- data/spec/fixtures/coal_cassettes/content_types.yml +0 -726
- data/spec/fixtures/coal_cassettes/current_site.yml +0 -166
- data/spec/fixtures/coal_cassettes/memberships.yml +0 -270
- data/spec/fixtures/coal_cassettes/my_account.yml +0 -260
- data/spec/fixtures/coal_cassettes/pages.yml +0 -333
- data/spec/fixtures/coal_cassettes/sections.yml +0 -267
- data/spec/fixtures/coal_cassettes/sites.yml +0 -212
- data/spec/fixtures/coal_cassettes/snippets.yml +0 -269
- data/spec/fixtures/coal_cassettes/theme_assets.yml +0 -270
- data/spec/fixtures/coal_cassettes/token.yml +0 -103
- data/spec/fixtures/coal_cassettes/translations.yml +0 -267
- data/spec/fixtures/coal_cassettes/version.yml +0 -103
- data/spec/integration/client_spec.rb +0 -67
- data/spec/integration/resources/accounts_spec.rb +0 -38
- data/spec/integration/resources/content_assets_spec.rb +0 -42
- data/spec/integration/resources/content_entries_spec.rb +0 -97
- data/spec/integration/resources/content_types_spec.rb +0 -44
- data/spec/integration/resources/current_site_spec.rb +0 -22
- data/spec/integration/resources/engine_version_spec.rb +0 -17
- data/spec/integration/resources/memberships_spec.rb +0 -39
- data/spec/integration/resources/my_account_spec.rb +0 -34
- data/spec/integration/resources/pages_spec.rb +0 -43
- data/spec/integration/resources/sections_spec.rb +0 -46
- data/spec/integration/resources/sites_spec.rb +0 -43
- data/spec/integration/resources/snippets_spec.rb +0 -38
- data/spec/integration/resources/theme_assets_spec.rb +0 -43
- data/spec/integration/resources/token_spec.rb +0 -38
- data/spec/integration/resources/translations_spec.rb +0 -38
- data/spec/spec_helper.rb +0 -28
- data/spec/support/api_settings.rb +0 -10
- data/spec/support/assets.rb +0 -4
- data/spec/support/default_resources.rb +0 -7
- data/spec/support/pry.rb +0 -4
- data/spec/support/vcr.rb +0 -10
- data/spec/unit/client_spec.rb +0 -52
- data/spec/unit/client_v2_spec.rb +0 -22
- data/spec/unit/error_spec.rb +0 -36
- data/spec/unit/paginated_resources_spec.rb +0 -50
- data/spec/unit/resource_spec.rb +0 -29
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Locomotive::Coal::Resources::ThemeAssets, order: :defined do
|
4
|
-
|
5
|
-
before { VCR.insert_cassette 'theme_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(:theme_assets) { described_class.new(uri, credentials) }
|
11
|
-
|
12
|
-
describe '#all' do
|
13
|
-
subject { theme_assets.all }
|
14
|
-
it { expect(subject).not_to eq nil }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#create' do
|
18
|
-
subject { create_theme_asset }
|
19
|
-
it { expect(subject._id).not_to eq nil }
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#update' do
|
23
|
-
let(:theme_asset) { single_theme_asset || create_theme_asset }
|
24
|
-
subject { theme_assets.update(theme_asset._id, folder: 'header') }
|
25
|
-
it { expect(subject.url).to match /theme\/images\/header\/rails.png$/ }
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#destroy' do
|
29
|
-
let(:theme_asset) { single_theme_asset || create_theme_asset }
|
30
|
-
subject { theme_assets.destroy(theme_asset._id) }
|
31
|
-
it { expect(subject._id).not_to eq nil }
|
32
|
-
end
|
33
|
-
|
34
|
-
def create_theme_asset
|
35
|
-
file = Locomotive::Coal::UploadIO.new(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'assets', 'rails.png'))
|
36
|
-
theme_assets.create(source: file, folder: 'footer' )
|
37
|
-
end
|
38
|
-
|
39
|
-
def single_theme_asset
|
40
|
-
theme_assets.all.detect { |a| a.url =~ /theme\/images\/footer\/rails.png$/ }
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Locomotive::Coal::Resources::Token do
|
4
|
-
|
5
|
-
before { VCR.insert_cassette 'token', record: :new_episodes }
|
6
|
-
after { VCR.eject_cassette }
|
7
|
-
|
8
|
-
let(:uri) { nil }
|
9
|
-
let(:credentials) { nil }
|
10
|
-
let(:token) { described_class.new(uri, credentials) }
|
11
|
-
|
12
|
-
describe '#get' do
|
13
|
-
|
14
|
-
subject { token.get }
|
15
|
-
|
16
|
-
context 'uri not pointing to a Locomotive engine' do
|
17
|
-
let(:uri) { URI('http://acme.example.local:3000') }
|
18
|
-
let(:credentials) { TEST_API_CREDENTIALS }
|
19
|
-
it { expect { subject }.to raise_error Locomotive::Coal::UnknownResourceError }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'valid uri' do
|
23
|
-
let(:uri) { TEST_API_V3_URI }
|
24
|
-
|
25
|
-
context 'email + password as credentials' do
|
26
|
-
let(:credentials) { TEST_API_CREDENTIALS }
|
27
|
-
it { is_expected.to match(/^[a-zA-Z0-9_-]{,20}$/) }
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'api key as credentials' do
|
31
|
-
let(:credentials) { TEST_API_CREDENTIALS_WITH_KEY }
|
32
|
-
it { is_expected.to match(/^[a-zA-Z0-9_-]{,20}$/) }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Locomotive::Coal::Resources::Translations, order: :defined do
|
4
|
-
|
5
|
-
before { VCR.insert_cassette 'translations', 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(:translations) { described_class.new(uri, credentials) }
|
11
|
-
|
12
|
-
describe '#all' do
|
13
|
-
subject { translations.all }
|
14
|
-
it { expect(subject).not_to eq nil }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#create' do
|
18
|
-
subject { create_translation }
|
19
|
-
it { expect(subject._id).not_to eq nil }
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#update' do
|
23
|
-
let(:translation) { translations.all.detect { |s| s.key == 'hello' } || create_translation }
|
24
|
-
subject { translations.update(translation._id, values: { 'en' => 'Hello world!', 'fr' => 'Bonjour le monde!' }) }
|
25
|
-
it { expect(subject.values).to eq('en' => 'Hello world!', 'fr' => 'Bonjour le monde!') }
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#destroy' do
|
29
|
-
let(:translation) { translations.all.detect { |s| s.key == 'hello' } || create_translation }
|
30
|
-
subject { translations.destroy(translation._id) }
|
31
|
-
it { expect(subject._id).not_to eq nil }
|
32
|
-
end
|
33
|
-
|
34
|
-
def create_translation
|
35
|
-
translations.create(key: 'hello', values: { 'en' => 'Hello world', 'fr' => 'Bonjour le monde' })
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
require 'coveralls'
|
3
|
-
|
4
|
-
SimpleCov.start do
|
5
|
-
add_filter 'spec/'
|
6
|
-
add_filter 'lib/locomotive/coal/version.rb'
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'rubygems'
|
10
|
-
require 'bundler/setup'
|
11
|
-
|
12
|
-
Dir["#{File.expand_path('../support', __FILE__)}/*.rb"].each do |file|
|
13
|
-
require file
|
14
|
-
end
|
15
|
-
|
16
|
-
require_relative '../lib/locomotive/coal'
|
17
|
-
|
18
|
-
RSpec.configure do |config|
|
19
|
-
# config.include Spec::Helpers
|
20
|
-
|
21
|
-
# config.filter_run focused: true
|
22
|
-
# config.run_all_when_everything_filtered = true
|
23
|
-
|
24
|
-
# config.before { reset! }
|
25
|
-
# config.after { reset! }
|
26
|
-
|
27
|
-
config.order = :random
|
28
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
TEST_API_URI = URI('http://localhost:3000').freeze
|
2
|
-
TEST_API_V3_URI = URI('http://localhost:3000/locomotive/api/v3').freeze
|
3
|
-
TEST_SITE_API_V3_URI = URI('http://localhost:3000/locomotive/sample/api/v3').freeze
|
4
|
-
TEST_API_EMAIL = 'admin@locomotivecms.com'
|
5
|
-
TEST_API_CREDENTIALS = { email: TEST_API_EMAIL, password: 'locomotive' }.freeze
|
6
|
-
TEST_API_CREDENTIALS_WITH_KEY = { email: TEST_API_EMAIL, api_key: 'd49cd50f6f0d2b163f48fc73cb249f0244c37074' }.freeze
|
7
|
-
|
8
|
-
def api_token(uri = nil, credentials = nil)
|
9
|
-
Locomotive::Coal::Resources::Token.new(uri || TEST_API_V3_URI, credentials || TEST_API_CREDENTIALS.dup).get
|
10
|
-
end
|
data/spec/support/assets.rb
DELETED
data/spec/support/pry.rb
DELETED
data/spec/support/vcr.rb
DELETED
data/spec/unit/client_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Locomotive::Coal::Client do
|
4
|
-
|
5
|
-
let(:uri) { 'http://sample.lvh.me:4000/locomotive/api' }
|
6
|
-
let(:credentials) { { email: 'fake' } }
|
7
|
-
subject { described_class.new(uri, credentials) }
|
8
|
-
|
9
|
-
describe '#initialize' do
|
10
|
-
|
11
|
-
context 'no uri' do
|
12
|
-
let(:uri) { nil }
|
13
|
-
it { expect { subject }.to raise_error Locomotive::Coal::MissingURIOrCredentialsError }
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'no credentials' do
|
17
|
-
let(:credentials) { nil }
|
18
|
-
it { expect { subject }.to raise_error Locomotive::Coal::MissingURIOrCredentialsError }
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'resources' do
|
24
|
-
describe '#current_site' do
|
25
|
-
subject { super().current_site }
|
26
|
-
it { is_expected.to be_a Locomotive::Coal::Resources::CurrentSite }
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#pages' do
|
30
|
-
subject { super().pages }
|
31
|
-
it { is_expected.to be_a Locomotive::Coal::Resources::Pages }
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#content_types' do
|
35
|
-
subject { super().content_types }
|
36
|
-
it { is_expected.to be_a Locomotive::Coal::Resources::ContentTypes }
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#content_entries' do
|
40
|
-
subject { super().content_entries(content_type) }
|
41
|
-
let(:content_type) { double(:content_type, slug: 'abc') }
|
42
|
-
it { is_expected.to be_a Locomotive::Coal::Resources::ContentEntries }
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#content_assets' do
|
46
|
-
subject { super().content_assets }
|
47
|
-
it { is_expected.to be_a Locomotive::Coal::Resources::ContentAssets }
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
data/spec/unit/client_v2_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
describe Locomotive::Coal::ClientV2 do
|
2
|
-
let(:site) { double(:site, domains: [domain]) }
|
3
|
-
|
4
|
-
let(:client) { described_class.new('abc.com', { foo: :bar }) }
|
5
|
-
|
6
|
-
describe '#scope_by' do
|
7
|
-
subject { client.scope_by(site) }
|
8
|
-
|
9
|
-
context 'domains include current site' do
|
10
|
-
let(:domain) { 'abc.com' }
|
11
|
-
it { is_expected.to eq client }
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'domains do not include current site' do
|
15
|
-
let(:domain) { 'xyz.com' }
|
16
|
-
it { is_expected.to_not eq client }
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
end
|
data/spec/unit/error_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Locomotive::Coal::Error do
|
4
|
-
|
5
|
-
let(:status) { nil }
|
6
|
-
let(:body) { {} }
|
7
|
-
let(:response) { instance_double('Response', status: status, body: body) }
|
8
|
-
let(:error) { described_class.from_response(response) }
|
9
|
-
|
10
|
-
describe '#message' do
|
11
|
-
|
12
|
-
subject { error.message }
|
13
|
-
|
14
|
-
context 'error caused by a wrong answer from the server' do
|
15
|
-
|
16
|
-
context 'invalid resource (422)' do
|
17
|
-
let(:status) { 422 }
|
18
|
-
let(:body) { { 'error' => 'Resource invalid', 'attributes' => { 'name' => ["can't be blank"] } } }
|
19
|
-
|
20
|
-
it { is_expected.to eq "Resource invalid: name can't be blank" }
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'Request Entity Too Large (413)' do
|
25
|
-
|
26
|
-
let(:status) { 413 }
|
27
|
-
|
28
|
-
it { is_expected.to eq "File too big for the server" }
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Locomotive::Coal::PaginatedResources do
|
4
|
-
|
5
|
-
let(:list) { ['a', 42, :foo] }
|
6
|
-
let(:page) { 1 }
|
7
|
-
let(:total_pages) { 1 }
|
8
|
-
let(:total_entries) { 3 }
|
9
|
-
let(:paginate) { described_class.new(list, page, total_pages, total_entries) }
|
10
|
-
|
11
|
-
describe '#find' do
|
12
|
-
subject { paginate.find { |el| el == 42 } }
|
13
|
-
it { is_expected.to eq 42 }
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#each' do
|
17
|
-
it { expect(paginate.respond_to?(:each)).to eq true }
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#_next_page' do
|
21
|
-
subject { paginate._next_page }
|
22
|
-
it { is_expected.to eq nil }
|
23
|
-
|
24
|
-
context '3 pages of entries' do
|
25
|
-
let(:total_pages) { 3 }
|
26
|
-
it { is_expected.to eq 2 }
|
27
|
-
|
28
|
-
context 'current page is the last one' do
|
29
|
-
let(:page) { 3 }
|
30
|
-
it { is_expected.to eq nil }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#_page' do
|
36
|
-
subject { paginate._page }
|
37
|
-
it { is_expected.to eq 1 }
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#_total_pages' do
|
41
|
-
subject { paginate._total_pages }
|
42
|
-
it { is_expected.to eq 1 }
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#_total_entries' do
|
46
|
-
subject { paginate._total_entries }
|
47
|
-
it { is_expected.to eq 3 }
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
data/spec/unit/resource_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Locomotive::Coal::Resource do
|
4
|
-
|
5
|
-
let(:attributes) { { 'title' => 'Hello world' } }
|
6
|
-
let(:resource) { described_class.new(attributes) }
|
7
|
-
|
8
|
-
describe 'unknown attribute' do
|
9
|
-
subject { resource.name }
|
10
|
-
it { expect { subject }.to raise_error(NoMethodError, /undefined method `name'/) }
|
11
|
-
end
|
12
|
-
|
13
|
-
describe 'existing attribute' do
|
14
|
-
subject { resource.title }
|
15
|
-
it { is_expected.to eq 'Hello world' }
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#respond_to?' do
|
19
|
-
let(:name) { :title }
|
20
|
-
subject { resource.respond_to?(name) }
|
21
|
-
it { is_expected.to eq true }
|
22
|
-
|
23
|
-
context 'unknown attribute' do
|
24
|
-
let(:name) { :body }
|
25
|
-
it { is_expected.to eq false }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|