locomotivecms_steam 1.0.0.pre.alpha.3 → 1.0.0.pre.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -6
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb +2 -2
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/site.rb +1 -1
- data/lib/locomotive/steam/adapters/filesystem.rb +5 -0
- data/lib/locomotive/steam/adapters/mongodb/command.rb +31 -0
- data/lib/locomotive/steam/adapters/mongodb.rb +17 -0
- data/lib/locomotive/steam/entities/content_entry.rb +4 -0
- data/lib/locomotive/steam/entities/content_type.rb +3 -2
- data/lib/locomotive/steam/middlewares/site.rb +1 -1
- data/lib/locomotive/steam/models/associations/belongs_to.rb +12 -3
- data/lib/locomotive/steam/models/associations/embedded.rb +4 -0
- data/lib/locomotive/steam/models/associations/many_to_many.rb +12 -2
- data/lib/locomotive/steam/models/associations/referenced.rb +8 -0
- data/lib/locomotive/steam/models/entity.rb +7 -1
- data/lib/locomotive/steam/models/i18n_field.rb +4 -0
- data/lib/locomotive/steam/models/mapper.rb +25 -7
- data/lib/locomotive/steam/models/repository.rb +4 -0
- data/lib/locomotive/steam/models/scope.rb +4 -0
- data/lib/locomotive/steam/repositories/content_entry_repository.rb +1 -1
- data/lib/locomotive/steam/services/translator_service.rb +4 -1
- data/lib/locomotive/steam/services.rb +20 -2
- data/lib/locomotive/steam/version.rb +1 -1
- data/locomotivecms_steam.gemspec +1 -1
- data/spec/integration/repositories/content_entry_repository_spec.rb +15 -0
- data/spec/support/helpers.rb +13 -0
- data/spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb +3 -3
- data/spec/unit/models/mapper_spec.rb +70 -1
- data/spec/unit/repositories/content_entry_repository_spec.rb +4 -4
- data/spec/unit/services/translator_service_spec.rb +22 -14
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8dd492e17a42930ea27866b0ea918ad91b126e3
|
4
|
+
data.tar.gz: 22c9afe5347bcca41f42e56d63b118dc049b0678
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 106e73a7703b15425b7cd38fe16d7b4dd517e674a7ea1efcf9d1de93ea5f6ffb63e22d138219f78b1782168f63c92df4e432fa86740c39d1955607ee49e346b9
|
7
|
+
data.tar.gz: 6196fa5aafdfebffe83886d172d57650b1cb4368d05c525dd74e93b9f3f0e0aa8bedde39962cf74bac5e75c7d708a55a91c18f0e99888b9549b23827cb665c09
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
locomotivecms_steam (1.0.0.pre.
|
4
|
+
locomotivecms_steam (1.0.0.pre.beta.1)
|
5
5
|
RedCloth (~> 4.2.9)
|
6
6
|
chronic (~> 0.10.2)
|
7
7
|
coffee-script (~> 2.4.1)
|
@@ -9,7 +9,7 @@ PATH
|
|
9
9
|
dragonfly (~> 1.0.10)
|
10
10
|
haml (~> 4.0.6)
|
11
11
|
httparty (~> 0.13.5)
|
12
|
-
kramdown (~> 1.
|
12
|
+
kramdown (~> 1.8.0)
|
13
13
|
locomotivecms-solid (~> 4.0.0.alpha2)
|
14
14
|
locomotivecms_common (~> 0.0.4)
|
15
15
|
mime-types (~> 2.6.1)
|
@@ -81,7 +81,7 @@ GEM
|
|
81
81
|
rack (>= 1.3.0)
|
82
82
|
eventmachine (1.0.7)
|
83
83
|
execjs (2.5.2)
|
84
|
-
ffi (1.9.
|
84
|
+
ffi (1.9.10)
|
85
85
|
haml (4.0.6)
|
86
86
|
tilt
|
87
87
|
hike (1.2.3)
|
@@ -99,7 +99,7 @@ GEM
|
|
99
99
|
json_spec (1.1.4)
|
100
100
|
multi_json (~> 1.0)
|
101
101
|
rspec (>= 2.0, < 4.0)
|
102
|
-
kramdown (1.
|
102
|
+
kramdown (1.8.0)
|
103
103
|
less (2.6.0)
|
104
104
|
commonjs (~> 0.2.7)
|
105
105
|
locomotivecms-liquid (4.0.0.alpha2)
|
@@ -169,14 +169,14 @@ GEM
|
|
169
169
|
crass (~> 1.0.2)
|
170
170
|
nokogiri (>= 1.4.4)
|
171
171
|
nokogumbo (= 1.4.1)
|
172
|
-
sass (3.4.
|
172
|
+
sass (3.4.16)
|
173
173
|
simplecov (0.10.0)
|
174
174
|
docile (~> 1.1.0)
|
175
175
|
json (~> 1.8)
|
176
176
|
simplecov-html (~> 0.10.0)
|
177
177
|
simplecov-html (0.10.0)
|
178
178
|
slop (3.6.0)
|
179
|
-
sprockets (2.12.
|
179
|
+
sprockets (2.12.4)
|
180
180
|
hike (~> 1.2)
|
181
181
|
multi_json (~> 1.0)
|
182
182
|
rack (~> 1.0)
|
@@ -29,13 +29,13 @@ module Locomotive
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def modify_for_selects(attributes)
|
32
|
-
content_type.
|
32
|
+
content_type.select_fields.each do |field|
|
33
33
|
attributes[:"#{field.name}_id"] = attributes.delete(field.name.to_sym)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
def modify_for_associations(attributes)
|
38
|
-
content_type.
|
38
|
+
content_type.association_fields.each do |field|
|
39
39
|
case field.type
|
40
40
|
when :belongs_to
|
41
41
|
modify_belongs_to_association(field, attributes)
|
@@ -11,7 +11,7 @@ module Locomotive
|
|
11
11
|
def load(scope)
|
12
12
|
attributes = _load(File.join(site_path, 'config', 'site.yml'))
|
13
13
|
|
14
|
-
(attributes[:domains] ||= [])
|
14
|
+
(attributes[:domains] ||= []).concat(%w(0.0.0.0 localhost))
|
15
15
|
|
16
16
|
attributes[:picture] = File.expand_path(File.join(site_path, 'icon.png'))
|
17
17
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Locomotive::Steam
|
2
|
+
module Adapters
|
3
|
+
module MongoDB
|
4
|
+
|
5
|
+
class Command
|
6
|
+
|
7
|
+
def initialize(collection, mapper)
|
8
|
+
@collection = collection
|
9
|
+
@mapper = mapper
|
10
|
+
end
|
11
|
+
|
12
|
+
def insert(entity)
|
13
|
+
# make sure the entity gets a valid id
|
14
|
+
entity[:_id] ||= BSON::ObjectId.new
|
15
|
+
|
16
|
+
serialized_entity = @mapper.serialize(entity)
|
17
|
+
|
18
|
+
@collection.insert(serialized_entity)
|
19
|
+
|
20
|
+
entity
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(entity)
|
24
|
+
@collection.find(_id: entity._id).remove if entity._id
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -4,6 +4,7 @@ require 'origin'
|
|
4
4
|
require_relative 'mongodb/origin'
|
5
5
|
require_relative 'mongodb/query'
|
6
6
|
require_relative 'mongodb/dataset'
|
7
|
+
require_relative 'mongodb/command'
|
7
8
|
|
8
9
|
module Locomotive::Steam
|
9
10
|
|
@@ -27,6 +28,14 @@ module Locomotive::Steam
|
|
27
28
|
query(mapper, scope) { where(_id: BSON::ObjectId.from_string(id)) }.first
|
28
29
|
end
|
29
30
|
|
31
|
+
def create(mapper, scope, entity)
|
32
|
+
command(mapper).insert(entity)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete(mapper, scope, entity)
|
36
|
+
command(mapper).delete(entity)
|
37
|
+
end
|
38
|
+
|
30
39
|
def key(name, operator)
|
31
40
|
name.to_sym.__send__(operator.to_sym)
|
32
41
|
end
|
@@ -50,6 +59,10 @@ module Locomotive::Steam
|
|
50
59
|
Locomotive::Steam::Adapters::MongoDB::Query
|
51
60
|
end
|
52
61
|
|
62
|
+
def command_klass
|
63
|
+
Locomotive::Steam::Adapters::MongoDB::Command
|
64
|
+
end
|
65
|
+
|
53
66
|
def dataset(mapper, query)
|
54
67
|
Locomotive::Steam::Adapters::MongoDB::Dataset.new do
|
55
68
|
query.against(collection(mapper)).map do |attributes|
|
@@ -58,6 +71,10 @@ module Locomotive::Steam
|
|
58
71
|
end
|
59
72
|
end
|
60
73
|
|
74
|
+
def command(mapper)
|
75
|
+
command_klass.new(collection(mapper), mapper)
|
76
|
+
end
|
77
|
+
|
61
78
|
def collection(mapper)
|
62
79
|
session["locomotive_#{mapper.name}"]
|
63
80
|
end
|
@@ -5,7 +5,8 @@ module Locomotive::Steam
|
|
5
5
|
include Locomotive::Steam::Models::Entity
|
6
6
|
extend Forwardable
|
7
7
|
|
8
|
-
|
8
|
+
def_delegator :fields, :associations, :association_fields
|
9
|
+
def_delegator :fields, :selects, :select_fields
|
9
10
|
|
10
11
|
def initialize(attributes = {})
|
11
12
|
super({
|
@@ -27,7 +28,7 @@ module Locomotive::Steam
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def localized_names
|
30
|
-
fields.localized_names +
|
31
|
+
fields.localized_names + select_fields.map(&:name)
|
31
32
|
end
|
32
33
|
|
33
34
|
def label_field_name
|
@@ -4,12 +4,21 @@ module Locomotive::Steam
|
|
4
4
|
class BelongsToAssociation < ReferencedAssociation
|
5
5
|
|
6
6
|
def __load__
|
7
|
-
|
8
|
-
target_id = @entity[:"#{name}_id"]
|
7
|
+
target_id = @entity[__target_key__]
|
9
8
|
target = @repository.find(target_id)
|
10
9
|
|
11
10
|
# replace the proxy class by the real target entity
|
12
|
-
@entity[
|
11
|
+
@entity[__name__] = target
|
12
|
+
end
|
13
|
+
|
14
|
+
def __serialize__(attributes)
|
15
|
+
attributes[__target_key__] = attributes[__name__].try(:_id)
|
16
|
+
|
17
|
+
attributes.delete(__name__)
|
18
|
+
end
|
19
|
+
|
20
|
+
def __target_key__
|
21
|
+
:"#{__name__}_id"
|
13
22
|
end
|
14
23
|
|
15
24
|
end
|
@@ -4,10 +4,9 @@ module Locomotive::Steam
|
|
4
4
|
class ManyToManyAssociation < ReferencedAssociation
|
5
5
|
|
6
6
|
def __load__
|
7
|
-
source_key = :"#{@options[:association_name].to_s.singularize}_ids"
|
8
7
|
key = @repository.k(:_id, :in)
|
9
8
|
|
10
|
-
@repository.local_conditions[key] = @entity[
|
9
|
+
@repository.local_conditions[key] = @entity[__target_key__]
|
11
10
|
|
12
11
|
# use order_by from options as the default one for further queries
|
13
12
|
@repository.local_conditions[:order_by] = @options[:order_by] unless @options[:order_by].blank?
|
@@ -16,6 +15,17 @@ module Locomotive::Steam
|
|
16
15
|
@repository
|
17
16
|
end
|
18
17
|
|
18
|
+
def __serialize__(attributes)
|
19
|
+
attributes[__target_key__] = attributes[__name__].try(:map, &:_id)
|
20
|
+
|
21
|
+
attributes.delete(__name__)
|
22
|
+
end
|
23
|
+
|
24
|
+
def __target_key__
|
25
|
+
:"#{__name__.to_s.singularize}_ids"
|
26
|
+
end
|
27
|
+
|
28
|
+
|
19
29
|
end
|
20
30
|
|
21
31
|
end
|
@@ -19,6 +19,10 @@ module Locomotive::Steam
|
|
19
19
|
@options = options
|
20
20
|
end
|
21
21
|
|
22
|
+
def __name__
|
23
|
+
@options[:association_name]
|
24
|
+
end
|
25
|
+
|
22
26
|
def __attach__(entity)
|
23
27
|
@entity = entity
|
24
28
|
end
|
@@ -27,6 +31,10 @@ module Locomotive::Steam
|
|
27
31
|
# needs implementation
|
28
32
|
end
|
29
33
|
|
34
|
+
def __serialize__(entity)
|
35
|
+
# needs implementation
|
36
|
+
end
|
37
|
+
|
30
38
|
def __call_block_once__
|
31
39
|
# setup the repository if custom configuration from the
|
32
40
|
# repository for instance.
|
@@ -5,7 +5,7 @@ module Locomotive::Steam
|
|
5
5
|
|
6
6
|
include Locomotive::Steam::Models::Concerns::Validation
|
7
7
|
|
8
|
-
attr_accessor :attributes, :localized_attributes, :base_url
|
8
|
+
attr_accessor :attributes, :associations, :localized_attributes, :base_url
|
9
9
|
|
10
10
|
def initialize(attributes)
|
11
11
|
@attributes = attributes.with_indifferent_access
|
@@ -14,6 +14,8 @@ module Locomotive::Steam
|
|
14
14
|
def method_missing(name, *args, &block)
|
15
15
|
if attributes.include?(name)
|
16
16
|
self[name]
|
17
|
+
elsif name.to_s.end_with?('=') && attributes.include?(name.to_s.chop)
|
18
|
+
self[name.to_s.chop] = args.first
|
17
19
|
else
|
18
20
|
super
|
19
21
|
end
|
@@ -35,6 +37,10 @@ module Locomotive::Steam
|
|
35
37
|
attributes[name.to_sym]
|
36
38
|
end
|
37
39
|
|
40
|
+
def serialize
|
41
|
+
attributes.dup
|
42
|
+
end
|
43
|
+
|
38
44
|
end
|
39
45
|
end
|
40
46
|
end
|
@@ -48,11 +48,12 @@ module Locomotive::Steam
|
|
48
48
|
|
49
49
|
def to_entity(attributes)
|
50
50
|
entity_klass.new(deserialize(attributes)).tap do |entity|
|
51
|
-
attach_entity_to_associations(entity)
|
52
|
-
|
53
51
|
set_default_attributes(entity)
|
54
52
|
|
55
53
|
entity.localized_attributes = @localized_attributes_hash || {}
|
54
|
+
entity.associations = {}
|
55
|
+
|
56
|
+
attach_entity_to_associations(entity)
|
56
57
|
|
57
58
|
entity.base_url = @repository.base_url(entity)
|
58
59
|
end
|
@@ -64,6 +65,23 @@ module Locomotive::Steam
|
|
64
65
|
attributes
|
65
66
|
end
|
66
67
|
|
68
|
+
def serialize(entity)
|
69
|
+
entity.serialize.tap do |attributes|
|
70
|
+
# scope
|
71
|
+
@repository.scope.apply(attributes)
|
72
|
+
|
73
|
+
# localized fields
|
74
|
+
@localized_attributes.each do |name|
|
75
|
+
entity.send(name).serialize(attributes)
|
76
|
+
end
|
77
|
+
|
78
|
+
# association name -> id (belongs_to) or ids (many_to_many)
|
79
|
+
(entity.associations || {}).each do |name, association|
|
80
|
+
association.__serialize__(attributes)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
67
85
|
def entity_klass
|
68
86
|
options[:entity]
|
69
87
|
end
|
@@ -88,10 +106,7 @@ module Locomotive::Steam
|
|
88
106
|
@associations.each do |(type, name, repository_klass, options, block)|
|
89
107
|
klass = ASSOCIATION_CLASSES[type]
|
90
108
|
|
91
|
-
_options = options.merge(
|
92
|
-
association_name: name,
|
93
|
-
mapper_name: self.name
|
94
|
-
})
|
109
|
+
_options = options.merge(association_name: name, mapper_name: self.name)
|
95
110
|
|
96
111
|
attributes[name] = (if type == :embedded
|
97
112
|
klass.new(repository_klass, attributes[name], @repository.scope, _options)
|
@@ -103,7 +118,10 @@ module Locomotive::Steam
|
|
103
118
|
|
104
119
|
def attach_entity_to_associations(entity)
|
105
120
|
@associations.each do |(type, name, _)|
|
106
|
-
entity[name]
|
121
|
+
association = entity[name]
|
122
|
+
association.__attach__(entity)
|
123
|
+
|
124
|
+
entity.associations[name] = association
|
107
125
|
end
|
108
126
|
end
|
109
127
|
|
@@ -140,7 +140,7 @@ module Locomotive
|
|
140
140
|
end
|
141
141
|
|
142
142
|
def add_associations_to_mapper(mapper)
|
143
|
-
self.content_type.
|
143
|
+
self.content_type.association_fields.each do |field|
|
144
144
|
mapper.association(field.type, field.name, self.class, field.association_options, &method(:prepare_repository_for_association))
|
145
145
|
end
|
146
146
|
end
|
@@ -17,10 +17,13 @@ module Locomotive
|
|
17
17
|
if scope.blank?
|
18
18
|
values = repository.by_key(input).try(:values) || {}
|
19
19
|
|
20
|
-
if
|
20
|
+
# FIXME: important to check if the returned value is nil (instead of nil + false)
|
21
|
+
# false being reserved for an existing key but without provided translation)
|
22
|
+
if (translation = values[locale.to_s]).present?
|
21
23
|
translation
|
22
24
|
else
|
23
25
|
Locomotive::Common::Logger.warn "Missing translation '#{input}' for the '#{locale}' locale".yellow
|
26
|
+
ActiveSupport::Notifications.instrument('steam.missing_translation', input: input, locale: locale)
|
24
27
|
input
|
25
28
|
end
|
26
29
|
else
|
@@ -15,12 +15,30 @@ module Locomotive
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
class SiteProxy < SimpleDelegator
|
19
|
+
|
20
|
+
def initialize(&block)
|
21
|
+
@site = nil
|
22
|
+
@default = block
|
23
|
+
super(@site)
|
24
|
+
end
|
25
|
+
|
26
|
+
def __getobj__
|
27
|
+
super || @default.call
|
28
|
+
end
|
29
|
+
|
30
|
+
def nil?
|
31
|
+
__getobj__.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
18
36
|
class Instance < Struct.new(:request)
|
19
37
|
|
20
38
|
include Morphine
|
21
39
|
|
22
40
|
register :current_site do
|
23
|
-
repositories.current_site = site_finder.find
|
41
|
+
repositories.current_site = SiteProxy.new { site_finder.find }
|
24
42
|
end
|
25
43
|
|
26
44
|
register :repositories do
|
@@ -113,7 +131,7 @@ module Locomotive
|
|
113
131
|
end
|
114
132
|
|
115
133
|
def set_site(site)
|
116
|
-
self.current_site
|
134
|
+
self.current_site.__setobj__(site)
|
117
135
|
end
|
118
136
|
|
119
137
|
end
|
data/locomotivecms_steam.gemspec
CHANGED
@@ -38,7 +38,7 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_dependency 'coffee-script', '~> 2.4.1'
|
39
39
|
spec.add_dependency 'compass', '~> 1.0.3'
|
40
40
|
|
41
|
-
spec.add_dependency 'kramdown', '~> 1.
|
41
|
+
spec.add_dependency 'kramdown', '~> 1.8.0'
|
42
42
|
spec.add_dependency 'RedCloth', '~> 4.2.9'
|
43
43
|
spec.add_dependency 'haml', '~> 4.0.6'
|
44
44
|
spec.add_dependency 'mimetype-fu', '~> 0.1.2'
|
@@ -56,6 +56,21 @@ describe Locomotive::Steam::ContentEntryRepository do
|
|
56
56
|
it { expect(subject.map { |h| h[:entries].size }).to eq([2, 1, 0]) }
|
57
57
|
end
|
58
58
|
|
59
|
+
describe '#create' do
|
60
|
+
|
61
|
+
let(:type) { type_repository.by_slug('songs') }
|
62
|
+
let(:attributes) { { title: 'Jeremy', band: 'pearl-jam', short_description: '"Jeremy" is a song by the American rock band Pearl Jam' } }
|
63
|
+
let(:entry) { repository.with(type).build(attributes) }
|
64
|
+
|
65
|
+
subject { repository.create(entry) }
|
66
|
+
|
67
|
+
it { expect { subject }.to change { repository.all.size } }
|
68
|
+
it { expect(subject._id).not_to eq nil }
|
69
|
+
|
70
|
+
after { repository.delete(entry) }
|
71
|
+
|
72
|
+
end
|
73
|
+
|
59
74
|
end
|
60
75
|
|
61
76
|
context 'MongoDB' do
|
data/spec/support/helpers.rb
CHANGED
@@ -43,5 +43,18 @@ module Spec
|
|
43
43
|
Rack::MockRequest.env_for(url, opts)
|
44
44
|
end
|
45
45
|
|
46
|
+
def notification_payload_for(notification)
|
47
|
+
payload = nil
|
48
|
+
subscription = ActiveSupport::Notifications.subscribe(notification) do |name, start, finish, id, _payload|
|
49
|
+
payload = _payload
|
50
|
+
end
|
51
|
+
|
52
|
+
yield
|
53
|
+
|
54
|
+
ActiveSupport::Notifications.unsubscribe(subscription)
|
55
|
+
|
56
|
+
return payload
|
57
|
+
end
|
58
|
+
|
46
59
|
end
|
47
60
|
end
|
@@ -6,7 +6,7 @@ require_relative '../../../../../lib/locomotive/steam/adapters/filesystem/yaml_l
|
|
6
6
|
describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentEntry do
|
7
7
|
|
8
8
|
let(:site_path) { default_fixture_site_path }
|
9
|
-
let(:content_type) { instance_double('Bands', _id: 42, slug: 'bands',
|
9
|
+
let(:content_type) { instance_double('Bands', _id: 42, slug: 'bands', association_fields: [], select_fields: []) }
|
10
10
|
let(:scope) { instance_double('Scope', locale: :en, context: { content_type: content_type }) }
|
11
11
|
let(:loader) { described_class.new(site_path) }
|
12
12
|
|
@@ -23,7 +23,7 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentEntry do
|
|
23
23
|
context 'a content type with a belongs_to field' do
|
24
24
|
|
25
25
|
let(:field) { instance_double('Field', name: 'band', type: :belongs_to) }
|
26
|
-
let(:content_type) { instance_double('Songs', slug: 'songs',
|
26
|
+
let(:content_type) { instance_double('Songs', slug: 'songs', association_fields: [field], select_fields: []) }
|
27
27
|
|
28
28
|
it 'adds a new attribute for the foreign key' do
|
29
29
|
expect(subject.first[:band_id]).to eq 'pearl-jam'
|
@@ -36,7 +36,7 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentEntry do
|
|
36
36
|
context 'a content type with a select field' do
|
37
37
|
|
38
38
|
let(:field) { instance_double('Field', name: 'kind', type: :select) }
|
39
|
-
let(:content_type) { instance_double('Bands', slug: 'bands',
|
39
|
+
let(:content_type) { instance_double('Bands', slug: 'bands', select_fields: [field], association_fields: []) }
|
40
40
|
|
41
41
|
it 'adds a new attribute for the foreign key' do
|
42
42
|
expect(subject.first[:kind_id]).to eq 'grunge'
|
@@ -2,7 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Locomotive::Steam::Models::Mapper do
|
4
4
|
|
5
|
-
let(:
|
5
|
+
let(:adapter) { instance_double('Adapter') }
|
6
|
+
let(:scope) { instance_double('SimpleScope', apply: true) }
|
7
|
+
let(:repository) { instance_double('Repository', scope: scope, base_url: '') }
|
6
8
|
let(:name) { 'pages' }
|
7
9
|
let(:options) { { entity: MyPage } }
|
8
10
|
let(:block) { nil }
|
@@ -17,6 +19,68 @@ describe Locomotive::Steam::Models::Mapper do
|
|
17
19
|
|
18
20
|
end
|
19
21
|
|
22
|
+
describe '#serialize' do
|
23
|
+
|
24
|
+
let(:options) { { entity: MyArticle } }
|
25
|
+
let(:attributes) { { title: 'Hello world', body: 'Lorem ipsum', published_at: DateTime.parse('2007/06/29 00:00:00') } }
|
26
|
+
let(:entity) { mapper.to_entity(attributes) }
|
27
|
+
|
28
|
+
subject { mapper.serialize(entity) }
|
29
|
+
|
30
|
+
it { expect(subject).to eq('title' => 'Hello world', 'body' => 'Lorem ipsum', 'published_at' => DateTime.parse('2007/06/29 00:00:00')) }
|
31
|
+
|
32
|
+
describe 'association' do
|
33
|
+
|
34
|
+
let(:repository) { instance_double('AuthorRepository', scope: scope, adapter: adapter, base_url: '') }
|
35
|
+
|
36
|
+
describe 'belongs_to' do
|
37
|
+
|
38
|
+
let(:block) { ->(_) { belongs_to_association(:author, BlankRepository) } }
|
39
|
+
|
40
|
+
context 'no object' do
|
41
|
+
|
42
|
+
let(:attributes) { { author_id: nil } }
|
43
|
+
|
44
|
+
it { expect(subject).to eq('author_id' => nil) }
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'existing object' do
|
49
|
+
|
50
|
+
before { entity.author = instance_double('Author', _id: 1) }
|
51
|
+
|
52
|
+
it { expect(subject).to eq('title' => 'Hello world', 'author_id' => 1, 'body' => 'Lorem ipsum', 'published_at' => DateTime.parse('2007/06/29 00:00:00')) }
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'many_to_many' do
|
59
|
+
|
60
|
+
let(:block) { ->(_) { many_to_many_association(:authors, BlankRepository) } }
|
61
|
+
|
62
|
+
context 'no object' do
|
63
|
+
|
64
|
+
let(:attributes) { { author_ids: nil } }
|
65
|
+
|
66
|
+
it { expect(subject).to eq('author_ids' => nil) }
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'existing object' do
|
71
|
+
|
72
|
+
before { entity.authors = [instance_double('Author', _id: 1), instance_double('Author', _id: 2)] }
|
73
|
+
|
74
|
+
it { expect(subject).to eq('title' => 'Hello world', 'author_ids' => [1, 2], 'body' => 'Lorem ipsum', 'published_at' => DateTime.parse('2007/06/29 00:00:00')) }
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
20
84
|
describe '#to_entity' do
|
21
85
|
|
22
86
|
subject { mapper.to_entity(attributes) }
|
@@ -68,6 +132,11 @@ describe Locomotive::Steam::Models::Mapper do
|
|
68
132
|
attr_accessor :site
|
69
133
|
end
|
70
134
|
|
135
|
+
class MyArticle
|
136
|
+
include Locomotive::Steam::Models::Entity
|
137
|
+
attr_accessor :site
|
138
|
+
end
|
139
|
+
|
71
140
|
class BlankRepository < Struct.new(:adapter)
|
72
141
|
attr_accessor :page, :scope
|
73
142
|
end
|
@@ -242,7 +242,7 @@ describe Locomotive::Steam::ContentEntryRepository do
|
|
242
242
|
describe 'belongs_to' do
|
243
243
|
|
244
244
|
let(:field) { instance_double('Field', name: :author, type: :belongs_to, association_options: { target_id: 2 }) }
|
245
|
-
let(:type) { build_content_type('Articles', label_field_name: :title,
|
245
|
+
let(:type) { build_content_type('Articles', label_field_name: :title, association_fields: [field]) }
|
246
246
|
let(:entries) { [{ content_type_id: 1, title: 'Hello world', author_id: 'john-doe' }] }
|
247
247
|
let(:other_type) { build_content_type('Authors', _id: 2, label_field_name: :name, fields_by_name: { name: instance_double('Field', name: :name, type: :string) }) }
|
248
248
|
let(:other_entries) { [{ content_type_id: 2, _id: 'john-doe', name: 'John Doe' }] }
|
@@ -269,7 +269,7 @@ describe Locomotive::Steam::ContentEntryRepository do
|
|
269
269
|
describe 'has_many' do
|
270
270
|
|
271
271
|
let(:field) { instance_double('Field', name: :articles, type: :has_many, association_options: { target_id: 2, inverse_of: :author, order_by: 'position_in_author' }) }
|
272
|
-
let(:type) { build_content_type('Authors', label_field_name: :name,
|
272
|
+
let(:type) { build_content_type('Authors', label_field_name: :name, association_fields: [field]) }
|
273
273
|
let(:entries) { [{ content_type_id: 1, _id: 'john-doe', name: 'John Doe' }] }
|
274
274
|
let(:other_type) { build_content_type('Articles', _id: 2, label_field_name: :title, fields_by_name: { name: instance_double('Field', name: :title, type: :string) }) }
|
275
275
|
let(:other_entries) {
|
@@ -302,7 +302,7 @@ describe Locomotive::Steam::ContentEntryRepository do
|
|
302
302
|
describe 'many_to_many' do
|
303
303
|
|
304
304
|
let(:field) { instance_double('Field', name: :articles, type: :many_to_many, association_options: { target_id: 2, inverse_of: :authors }) }
|
305
|
-
let(:type) { build_content_type('Authors', label_field_name: :name,
|
305
|
+
let(:type) { build_content_type('Authors', label_field_name: :name, association_fields: [field]) }
|
306
306
|
let(:entries) { [{ content_type_id: 1, _id: 1, name: 'John Doe', article_ids: ['hello-world', 'lorem-ipsum'] }] }
|
307
307
|
let(:other_type) { build_content_type('Articles', _id: 2, label_field_name: :title, fields_by_name: { name: instance_double('Field', name: :title, type: :string) }) }
|
308
308
|
let(:other_entries) {
|
@@ -339,7 +339,7 @@ describe Locomotive::Steam::ContentEntryRepository do
|
|
339
339
|
slug: name.to_s.downcase,
|
340
340
|
order_by: nil,
|
341
341
|
localized_names: [],
|
342
|
-
|
342
|
+
association_fields: [],
|
343
343
|
fields_by_name: {}
|
344
344
|
}.merge(attributes))
|
345
345
|
end
|
@@ -12,25 +12,18 @@ describe Locomotive::Steam::TranslatorService do
|
|
12
12
|
let(:locale) { nil }
|
13
13
|
let(:scope) { nil }
|
14
14
|
|
15
|
+
before do
|
16
|
+
allow(repository).to receive(:by_key).with('example_test').and_return(translation)
|
17
|
+
end
|
18
|
+
|
15
19
|
subject { service.translate(input, locale, scope) }
|
16
20
|
|
17
21
|
describe 'existing translation' do
|
18
22
|
|
19
23
|
let(:translation) { instance_double('Translation', values: { 'en' => 'Example text', 'es' => 'Texto de ejemplo' }) }
|
20
24
|
|
21
|
-
before do
|
22
|
-
allow(repository).to receive(:by_key).with('example_test').and_return(translation)
|
23
|
-
end
|
24
|
-
|
25
25
|
it { is_expected.to eq 'Example text' }
|
26
26
|
|
27
|
-
context 'no translation found' do
|
28
|
-
|
29
|
-
let(:translation) { nil }
|
30
|
-
it { is_expected.to eq 'example_test' }
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
27
|
context 'specifying a locale' do
|
35
28
|
|
36
29
|
let(:locale) { 'es' }
|
@@ -40,15 +33,15 @@ describe Locomotive::Steam::TranslatorService do
|
|
40
33
|
|
41
34
|
context "specifying a locale that doesn't exist" do
|
42
35
|
|
43
|
-
let(:locale) { 'nl' }
|
36
|
+
let(:locale) { puts 'NL'; 'nl' }
|
44
37
|
|
45
38
|
it 'reverts to default locale' do
|
46
|
-
is_expected.to eq
|
39
|
+
is_expected.to eq 'example_test'
|
47
40
|
end
|
48
41
|
|
49
42
|
end
|
50
43
|
|
51
|
-
context
|
44
|
+
context 'specifying a scope' do
|
52
45
|
|
53
46
|
let(:input) { 'fr' }
|
54
47
|
let(:locale) { 'en' }
|
@@ -60,6 +53,21 @@ describe Locomotive::Steam::TranslatorService do
|
|
60
53
|
|
61
54
|
end
|
62
55
|
|
56
|
+
describe 'missing translation' do
|
57
|
+
|
58
|
+
let(:locale) { 'fr' }
|
59
|
+
let(:translation) { nil }
|
60
|
+
|
61
|
+
it { is_expected.to eq 'example_test' }
|
62
|
+
|
63
|
+
it 'sends a notification' do
|
64
|
+
payload = notification_payload_for('steam.missing_translation') { subject }
|
65
|
+
expect(payload[:input]).to eq 'example_test'
|
66
|
+
expect(payload[:locale]).to eq 'fr'
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
63
71
|
end
|
64
72
|
|
65
73
|
end
|
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.0.0.pre.
|
4
|
+
version: 1.0.0.pre.beta.1
|
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: 2015-
|
14
|
+
date: 2015-07-30 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -271,14 +271,14 @@ dependencies:
|
|
271
271
|
requirements:
|
272
272
|
- - "~>"
|
273
273
|
- !ruby/object:Gem::Version
|
274
|
-
version: 1.
|
274
|
+
version: 1.8.0
|
275
275
|
type: :runtime
|
276
276
|
prerelease: false
|
277
277
|
version_requirements: !ruby/object:Gem::Requirement
|
278
278
|
requirements:
|
279
279
|
- - "~>"
|
280
280
|
- !ruby/object:Gem::Version
|
281
|
-
version: 1.
|
281
|
+
version: 1.8.0
|
282
282
|
- !ruby/object:Gem::Dependency
|
283
283
|
name: RedCloth
|
284
284
|
requirement: !ruby/object:Gem::Requirement
|
@@ -419,6 +419,7 @@ files:
|
|
419
419
|
- lib/locomotive/steam/adapters/memory/order.rb
|
420
420
|
- lib/locomotive/steam/adapters/memory/query.rb
|
421
421
|
- lib/locomotive/steam/adapters/mongodb.rb
|
422
|
+
- lib/locomotive/steam/adapters/mongodb/command.rb
|
422
423
|
- lib/locomotive/steam/adapters/mongodb/dataset.rb
|
423
424
|
- lib/locomotive/steam/adapters/mongodb/origin.rb
|
424
425
|
- lib/locomotive/steam/adapters/mongodb/query.rb
|