locomotivecms_steam 1.2.0.rc2 → 1.2.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -5
- data/lib/locomotive/steam/adapters/mongodb.rb +5 -1
- data/lib/locomotive/steam/liquid/tags/action.rb +19 -1
- data/lib/locomotive/steam/liquid/tags/consume.rb +1 -1
- data/lib/locomotive/steam/repositories/content_entry_repository.rb +32 -13
- data/lib/locomotive/steam/services/content_entry_service.rb +16 -0
- data/lib/locomotive/steam/services/external_api_service.rb +1 -1
- data/lib/locomotive/steam/version.rb +1 -1
- data/spec/integration/repositories/content_entry_repository_spec.rb +15 -9
- data/spec/support/mongo.rb +2 -1
- data/spec/unit/liquid/tags/action_spec.rb +9 -0
- data/spec/unit/repositories/content_entry_repository_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eec023af794726f45fcdf70d6cb85b9874a8b56e
|
4
|
+
data.tar.gz: 67d5c5968b4597655ead417285dfa9163204d819
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6e0cab759ddd568f92f50dd88a4e1116b09f2ac959908dcf0067da5c4e2d90236fa75d3beabb7c8070fdaee9a8d7015d677b74d29aeb84c00beec500a7ff125
|
7
|
+
data.tar.gz: 86e838bd1b3db3ff5cd16465c1a0fb2d2ded0000368cbaca310409fc8fd93a93b90bb42e3252dd94313336f27fa7a3e5d3253dc6fd6af1499280ee652a89485e
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
locomotivecms_steam (1.2.0.
|
4
|
+
locomotivecms_steam (1.2.0.rc3)
|
5
5
|
RedCloth (~> 4.3.2)
|
6
6
|
autoprefixer-rails (~> 6.3.3.1)
|
7
7
|
chronic (~> 0.10.2)
|
@@ -112,20 +112,18 @@ GEM
|
|
112
112
|
mime-types (2.6.2)
|
113
113
|
mimetype-fu (0.1.2)
|
114
114
|
mini_portile2 (2.1.0)
|
115
|
-
minitest (5.9.
|
115
|
+
minitest (5.9.1)
|
116
116
|
moneta (0.8.0)
|
117
117
|
mongo (2.2.7)
|
118
118
|
bson (~> 4.0)
|
119
119
|
morphine (0.1.1)
|
120
120
|
multi_json (1.12.1)
|
121
121
|
multi_xml (0.5.5)
|
122
|
-
nokogiri (1.6.8)
|
122
|
+
nokogiri (1.6.8.1)
|
123
123
|
mini_portile2 (~> 2.1.0)
|
124
|
-
pkg-config (~> 1.1.7)
|
125
124
|
nokogumbo (1.4.9)
|
126
125
|
nokogiri
|
127
126
|
origin (2.2.0)
|
128
|
-
pkg-config (1.1.7)
|
129
127
|
pony (1.11)
|
130
128
|
mail (>= 2.0)
|
131
129
|
pry (0.10.4)
|
@@ -38,7 +38,7 @@ module Locomotive
|
|
38
38
|
|
39
39
|
def render(context)
|
40
40
|
Locomotive::Common::Logger.info "[action] executing #{@description}"
|
41
|
-
service(context).run(super, context
|
41
|
+
service(context).run(super, safe_params(context), context)
|
42
42
|
''
|
43
43
|
end
|
44
44
|
|
@@ -48,6 +48,24 @@ module Locomotive
|
|
48
48
|
context.registers[:services].action
|
49
49
|
end
|
50
50
|
|
51
|
+
def safe_params(context)
|
52
|
+
return {} if context['params'].blank?
|
53
|
+
|
54
|
+
context['params'].dup.tap do |params|
|
55
|
+
# Tempfile can't be converted in Duktape for obvious reasons
|
56
|
+
replace_tempfile(params)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def replace_tempfile(hash)
|
61
|
+
hash.each do |key, value|
|
62
|
+
case value
|
63
|
+
when Tempfile then hash[key] = value.path
|
64
|
+
when Hash then replace_tempfile(value)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
51
69
|
end
|
52
70
|
|
53
71
|
::Liquid::Template.register_tag('action'.freeze, Action)
|
@@ -72,7 +72,7 @@ module Locomotive
|
|
72
72
|
Locomotive::Common::Logger.info "[consume] #{@url.inspect} / #{@api_options.inspect}"
|
73
73
|
|
74
74
|
context.scopes.last[@name] = service(context).consume(@url, @api_options)
|
75
|
-
rescue Timeout::Error
|
75
|
+
rescue Timeout::Error, Errno::ETIMEDOUT
|
76
76
|
context.scopes.last[@name] = last_response(context)
|
77
77
|
end
|
78
78
|
|
@@ -22,8 +22,12 @@ module Locomotive
|
|
22
22
|
default_attribute :content_type, -> (repository) { repository.content_type }
|
23
23
|
end
|
24
24
|
|
25
|
-
# this is the starting point of all the next methods
|
25
|
+
# this is the starting point of all the next methods.
|
26
|
+
# type can be either an instance of the ContentTypeRepository class
|
27
|
+
# or the id of a content type.
|
26
28
|
def with(type)
|
29
|
+
type = self.content_type_repository.find(type) if type.is_a?(String)
|
30
|
+
|
27
31
|
self.content_type = type # used for creating the scope
|
28
32
|
self.scope.context[:content_type] = type
|
29
33
|
|
@@ -131,11 +135,15 @@ module Locomotive
|
|
131
135
|
end
|
132
136
|
|
133
137
|
def prepare_conditions(*conditions)
|
134
|
-
_conditions = Conditions.new(
|
138
|
+
_conditions = Conditions.new(conditions.first, self.content_type.fields, simple_clone).prepare
|
135
139
|
|
136
140
|
super({ _visible: true }, _conditions)
|
137
141
|
end
|
138
142
|
|
143
|
+
def simple_clone
|
144
|
+
self.class.new(self.adapter, self.site, self.locale, self.content_type_repository)
|
145
|
+
end
|
146
|
+
|
139
147
|
def add_localized_fields_to_mapper(mapper)
|
140
148
|
unless self.content_type.localized_names.blank?
|
141
149
|
mapper.localized_attributes(*self.content_type.localized_names)
|
@@ -185,10 +193,10 @@ module Locomotive
|
|
185
193
|
|
186
194
|
class Conditions
|
187
195
|
|
188
|
-
def initialize(
|
189
|
-
@adapter = adapter
|
196
|
+
def initialize(conditions = {}, fields, target_repository)
|
190
197
|
@conditions = conditions.try(:with_indifferent_access) || {}
|
191
198
|
@fields, @operators = fields, {}
|
199
|
+
@target_repository = target_repository
|
192
200
|
|
193
201
|
@conditions.each do |name, value|
|
194
202
|
_name, operator = name.to_s.split('.')
|
@@ -206,10 +214,10 @@ module Locomotive
|
|
206
214
|
_prepare(@fields.dates_and_date_times) { |field, value| value_to_date(value, field.type) }
|
207
215
|
|
208
216
|
# belongs_to
|
209
|
-
_prepare(@fields.belongs_to) { |field, value| value_to_id(value) }
|
217
|
+
_prepare(@fields.belongs_to) { |field, value| value_to_id(value, field.target_id) }
|
210
218
|
|
211
219
|
# many_to_many
|
212
|
-
_prepare(@fields.many_to_many) { |field, value| values_to_ids(value) }
|
220
|
+
_prepare(@fields.many_to_many) { |field, value| values_to_ids(value, field.target_id) }
|
213
221
|
|
214
222
|
@conditions
|
215
223
|
end
|
@@ -237,16 +245,31 @@ module Locomotive
|
|
237
245
|
end
|
238
246
|
end
|
239
247
|
|
240
|
-
def
|
248
|
+
def values_to_ids(value, target_id)
|
249
|
+
[*value].map { |_value| value_to_id(_value, target_id) }
|
250
|
+
end
|
251
|
+
|
252
|
+
def value_to_id(value, target_id)
|
241
253
|
_value = if value.is_a?(Hash)
|
242
254
|
value['_id'] || value[:_id]
|
243
255
|
elsif value.respond_to?(:each) # array
|
244
|
-
values_to_ids(value)
|
256
|
+
values_to_ids(value, target_id)
|
245
257
|
else
|
246
258
|
value.respond_to?(:_id) ? value._id : value
|
247
259
|
end
|
248
260
|
|
249
|
-
@adapter.make_id(_value)
|
261
|
+
if (id = @target_repository.adapter.make_id(_value)) == false
|
262
|
+
slug_to_id(value, target_id)
|
263
|
+
else
|
264
|
+
id
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def slug_to_id(slug, target_id)
|
269
|
+
if _repository = @target_repository.with(target_id)
|
270
|
+
_entry = _repository.first { where(_slug: slug).only(:_id) }
|
271
|
+
_entry.try(:_id)
|
272
|
+
end
|
250
273
|
end
|
251
274
|
|
252
275
|
def value_to_date(value, type)
|
@@ -259,10 +282,6 @@ module Locomotive
|
|
259
282
|
type == :date ? _value.to_date : _value.to_datetime
|
260
283
|
end
|
261
284
|
|
262
|
-
def values_to_ids(value)
|
263
|
-
[*value].map { |_value| value_to_id(_value) }
|
264
|
-
end
|
265
|
-
|
266
285
|
end
|
267
286
|
|
268
287
|
end
|
@@ -34,6 +34,8 @@ module Locomotive
|
|
34
34
|
_repository.create(entry)
|
35
35
|
end
|
36
36
|
|
37
|
+
logEntryOperation(type_slug, decorated_entry)
|
38
|
+
|
37
39
|
_json_decorate(decorated_entry, as_json)
|
38
40
|
end
|
39
41
|
end
|
@@ -48,6 +50,8 @@ module Locomotive
|
|
48
50
|
_repository.update(entry)
|
49
51
|
end
|
50
52
|
|
53
|
+
logEntryOperation(type_slug, decorated_entry)
|
54
|
+
|
51
55
|
_json_decorate(decorated_entry, as_json)
|
52
56
|
end
|
53
57
|
end
|
@@ -65,8 +69,20 @@ module Locomotive
|
|
65
69
|
content_type_repository.by_slug(slug)
|
66
70
|
end
|
67
71
|
|
72
|
+
def logger
|
73
|
+
Locomotive::Common::Logger
|
74
|
+
end
|
75
|
+
|
68
76
|
private
|
69
77
|
|
78
|
+
def logEntryOperation(type_slug, entry)
|
79
|
+
if (json = entry.as_json)['errors'].blank?
|
80
|
+
logger.info "[#{type_slug}] Entry persisted with success. #{json}"
|
81
|
+
else
|
82
|
+
logger.error "[#{type_slug}] Failed to persist entry. #{json}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
70
86
|
def with_repository(type_or_slug)
|
71
87
|
type = type_or_slug.respond_to?(:fields) ? type_or_slug : get_type(type_or_slug)
|
72
88
|
|
@@ -50,7 +50,7 @@ module Locomotive
|
|
50
50
|
parsed_response = response.parsed_response
|
51
51
|
|
52
52
|
if response.code == 200
|
53
|
-
HashConverter.to_underscore
|
53
|
+
HashConverter.to_underscore(parsed_response)
|
54
54
|
else
|
55
55
|
Locomotive::Common::Logger.error "[WebService] consumed #{path}, #{options.inspect}, response = #{response.inspect}"
|
56
56
|
nil
|
@@ -7,11 +7,13 @@ describe Locomotive::Steam::ContentEntryRepository do
|
|
7
7
|
|
8
8
|
shared_examples_for 'a repository' do
|
9
9
|
|
10
|
-
let(:site)
|
11
|
-
let(:locale)
|
12
|
-
let(:type_repository)
|
13
|
-
let(:repository)
|
14
|
-
let(:type)
|
10
|
+
let(:site) { Locomotive::Steam::Site.new(_id: site_id, locales: %w(en fr nb)) }
|
11
|
+
let(:locale) { :en }
|
12
|
+
let(:type_repository) { Locomotive::Steam::ContentTypeRepository.new(adapter, site, locale) }
|
13
|
+
let(:repository) { described_class.new(adapter, site, locale, type_repository).with(type) }
|
14
|
+
let(:type) { type_repository.by_slug('bands') }
|
15
|
+
let(:target_type) { type_repository.by_slug('songs') }
|
16
|
+
let(:target_repository) { described_class.new(adapter, site, locale, type_repository).with(target_type) }
|
15
17
|
|
16
18
|
describe '#all' do
|
17
19
|
subject { repository.all }
|
@@ -55,6 +57,11 @@ describe Locomotive::Steam::ContentEntryRepository do
|
|
55
57
|
it { expect(subject.map { |entry| entry[:name] }).to eq(['Alice in Chains', 'Pearl Jam']) }
|
56
58
|
end
|
57
59
|
|
60
|
+
describe 'filter by a belongs_to field' do
|
61
|
+
subject { target_repository.all(band: 'the-who') }
|
62
|
+
it { expect(subject.map { |entry| entry[:title] }).to eq(['Song #5', 'Song #6']) }
|
63
|
+
end
|
64
|
+
|
58
65
|
describe '#group_by_select_option' do
|
59
66
|
subject { repository.group_by_select_option(:kind) }
|
60
67
|
it { expect(subject.map { |h| h[:name] }).to eq(%w(grunge rock country)) }
|
@@ -73,9 +80,8 @@ describe Locomotive::Steam::ContentEntryRepository do
|
|
73
80
|
|
74
81
|
describe '#create' do
|
75
82
|
|
76
|
-
let(:
|
77
|
-
let(:
|
78
|
-
let(:entry) { repository.with(type).build(attributes) }
|
83
|
+
let(:attributes) { { title: 'Jeremy', band_id: 'pearl-jam', short_description: '"Jeremy" is a song by the American rock band Pearl Jam' } }
|
84
|
+
let(:entry) { repository.with(target_type).build(attributes) }
|
79
85
|
|
80
86
|
subject { repository.create(entry) }
|
81
87
|
|
@@ -89,7 +95,7 @@ describe Locomotive::Steam::ContentEntryRepository do
|
|
89
95
|
describe '#inc' do
|
90
96
|
|
91
97
|
let(:type) { type_repository.by_slug('songs') }
|
92
|
-
let(:attributes) { { title: 'Jeremy',
|
98
|
+
let(:attributes) { { title: 'Jeremy', band_id: 'pearl-jam', short_description: '"Jeremy" is a song by the American rock band Pearl Jam', views: 41 } }
|
93
99
|
let(:entry) { repository.with(type).build(attributes) }
|
94
100
|
|
95
101
|
before { repository.create(entry) }
|
data/spec/support/mongo.rb
CHANGED
@@ -18,6 +18,15 @@ describe Locomotive::Steam::Liquid::Tags::Action do
|
|
18
18
|
|
19
19
|
it { subject; expect(context['foo']).to eq 42.0 }
|
20
20
|
|
21
|
+
describe 'uploaded file' do
|
22
|
+
|
23
|
+
let(:assigns) { { 'params' => { 'my_file' => { 'tempfile' => Tempfile.new('my_file') } } } }
|
24
|
+
let(:source) { '{% action "uploaded file" %}setProp("path", params.my_file.tempfile);{% endaction %}' }
|
25
|
+
|
26
|
+
it { subject; expect(context['path']).to match /\/my_file/ }
|
27
|
+
|
28
|
+
end
|
29
|
+
|
21
30
|
end
|
22
31
|
|
23
32
|
end
|
@@ -407,7 +407,7 @@ describe Locomotive::Steam::ContentEntryRepository do
|
|
407
407
|
context 'belongs_to fields' do
|
408
408
|
|
409
409
|
let(:value) { 42 }
|
410
|
-
let(:field) { instance_double('BelongsToField', name: 'person', persisted_name: 'person_id') }
|
410
|
+
let(:field) { instance_double('BelongsToField', name: 'person', persisted_name: 'person_id', target_id: '42') }
|
411
411
|
let(:_fields) { instance_double('Fields', selects: [], belongs_to: [field], many_to_many: [], dates_and_date_times: []) }
|
412
412
|
let(:conditions) { { 'person' => value } }
|
413
413
|
|
@@ -450,7 +450,7 @@ describe Locomotive::Steam::ContentEntryRepository do
|
|
450
450
|
context 'many_to_many fields' do
|
451
451
|
|
452
452
|
let(:value) { 42 }
|
453
|
-
let(:field) { instance_double('ManyToManyField', name: 'tags', persisted_name: 'tag_ids') }
|
453
|
+
let(:field) { instance_double('ManyToManyField', name: 'tags', persisted_name: 'tag_ids', target_id: '42') }
|
454
454
|
let(:_fields) { instance_double('Fields', selects: [], belongs_to: [], many_to_many: [field], dates_and_date_times: []) }
|
455
455
|
let(:conditions) { { 'tags.in' => value } }
|
456
456
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locomotivecms_steam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0.
|
4
|
+
version: 1.2.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Didier Lafforgue
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-
|
14
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|