sinicum 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.cane +19 -0
- data/.gitignore +14 -0
- data/.rubocop.yml +30 -0
- data/.travis.yml +14 -0
- data/Gemfile +4 -0
- data/LICENSE +24 -0
- data/README.md +327 -0
- data/Rakefile +37 -0
- data/app/assets/javascripts/sinicum/magnolia_client.js.coffee +233 -0
- data/app/controllers/sinicum/controller_base.rb +173 -0
- data/app/controllers/sinicum/controllers/cache_aware.rb +16 -0
- data/app/controllers/sinicum/controllers/global_state_cache.rb +83 -0
- data/app/helpers/sinicum/helper_utils.rb +152 -0
- data/app/helpers/sinicum/mgnl_helper.rb +145 -0
- data/app/helpers/sinicum/mgnl_helper5.rb +7 -0
- data/app/helpers/sinicum/mgnl_image_helper.rb +26 -0
- data/app/helpers/sinicum/taglib_helper5.rb +166 -0
- data/gemfiles/Gemfile-3.2 +6 -0
- data/gemfiles/Gemfile-4.0 +6 -0
- data/lib/generators/sinicum/install_generator.rb +162 -0
- data/lib/generators/sinicum/templates/VersionHandler.java +18 -0
- data/lib/generators/sinicum/templates/config/default/log4j-development.xml +203 -0
- data/lib/generators/sinicum/templates/config/default/log4j.xml +200 -0
- data/lib/generators/sinicum/templates/config/default/magnolia-author.properties +63 -0
- data/lib/generators/sinicum/templates/config/default/magnolia-public01.properties +63 -0
- data/lib/generators/sinicum/templates/config/default/magnolia.properties +63 -0
- data/lib/generators/sinicum/templates/config/repo-conf/jackrabbit-bundle-postgres-search-author.xml +73 -0
- data/lib/generators/sinicum/templates/config/repo-conf/jackrabbit-bundle-postgres-search-public01.xml +73 -0
- data/lib/generators/sinicum/templates/config/repo-conf/jackrabbit-bundle-postgres-search.xml +70 -0
- data/lib/generators/sinicum/templates/magnolia/config.modules.myproject.dialogs.xml +1625 -0
- data/lib/generators/sinicum/templates/magnolia/config.modules.myproject.templates.xml +247 -0
- data/lib/generators/sinicum/templates/module-config.xml +13 -0
- data/lib/generators/sinicum/templates/module-pom.xml +67 -0
- data/lib/generators/sinicum/templates/project-pom.xml +104 -0
- data/lib/generators/sinicum/templates/rails/_article.html.haml +15 -0
- data/lib/generators/sinicum/templates/rails/_content.html.haml +2 -0
- data/lib/generators/sinicum/templates/rails/_meta.html.haml +9 -0
- data/lib/generators/sinicum/templates/rails/application.html.haml +11 -0
- data/lib/generators/sinicum/templates/rails/content_controller.rb +5 -0
- data/lib/generators/sinicum/templates/rails/imaging.yml +8 -0
- data/lib/generators/sinicum/templates/rails/sinicum_server.yml +15 -0
- data/lib/sinicum.rb +53 -0
- data/lib/sinicum/content/aggregator.rb +173 -0
- data/lib/sinicum/content/website_content_resolver.rb +10 -0
- data/lib/sinicum/engine.rb +23 -0
- data/lib/sinicum/imaging.rb +29 -0
- data/lib/sinicum/imaging/config.rb +133 -0
- data/lib/sinicum/imaging/converter.rb +81 -0
- data/lib/sinicum/imaging/default_converter.rb +20 -0
- data/lib/sinicum/imaging/image_size_converter.rb +52 -0
- data/lib/sinicum/imaging/imaging.rb +171 -0
- data/lib/sinicum/imaging/imaging_file.rb +115 -0
- data/lib/sinicum/imaging/imaging_middleware.rb +56 -0
- data/lib/sinicum/imaging/max_size_converter.rb +39 -0
- data/lib/sinicum/imaging/resize_crop_converter.rb +35 -0
- data/lib/sinicum/jcr/api_client.rb +50 -0
- data/lib/sinicum/jcr/api_queries.rb +37 -0
- data/lib/sinicum/jcr/cache/global_cache.rb +26 -0
- data/lib/sinicum/jcr/dam/document.rb +57 -0
- data/lib/sinicum/jcr/dam/image.rb +40 -0
- data/lib/sinicum/jcr/jcr_configuration.rb +67 -0
- data/lib/sinicum/jcr/mgnl4_compatibility.rb +11 -0
- data/lib/sinicum/jcr/node.rb +268 -0
- data/lib/sinicum/jcr/node_initializer.rb +16 -0
- data/lib/sinicum/jcr/node_queries.rb +101 -0
- data/lib/sinicum/jcr/query_sanitizer.rb +24 -0
- data/lib/sinicum/jcr/type_translator.rb +38 -0
- data/lib/sinicum/jcr/type_translators/component_translator.rb +28 -0
- data/lib/sinicum/jcr/type_translators/dam_translator.rb +33 -0
- data/lib/sinicum/jcr/type_translators/data_translator.rb +31 -0
- data/lib/sinicum/jcr/type_translators/default_translator.rb +13 -0
- data/lib/sinicum/jcr/type_translators/translator_base.rb +40 -0
- data/lib/sinicum/logger.rb +28 -0
- data/lib/sinicum/navigation/default_navigation_element.rb +30 -0
- data/lib/sinicum/navigation/navigation_element.rb +39 -0
- data/lib/sinicum/navigation/navigation_element_list.rb +33 -0
- data/lib/sinicum/navigation/navigation_handler.rb +95 -0
- data/lib/sinicum/navigation/navigation_status.rb +27 -0
- data/lib/sinicum/templating/area_handler.rb +33 -0
- data/lib/sinicum/templating/dialog_resolver.rb +26 -0
- data/lib/sinicum/templating/templating_utils.rb +24 -0
- data/lib/sinicum/util.rb +12 -0
- data/lib/sinicum/version.rb +3 -0
- data/script/cibuild +31 -0
- data/sinicum.gemspec +29 -0
- data/spec/controllers/sinicum/controller_base_spec.rb +53 -0
- data/spec/controllers/sinicum/controllers/global_state_cache_spec.rb +35 -0
- data/spec/dummy/REVISION +1 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/application/index.html.erb +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/layout_name.html.erb +0 -0
- data/spec/dummy/app/views/layouts/my-module/test.html.erb +0 -0
- data/spec/dummy/app/views/layouts/my_module/test.html.erb +0 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +24 -0
- data/spec/dummy/config/environments/production.rb +51 -0
- data/spec/dummy/config/environments/test.rb +34 -0
- data/spec/dummy/config/imaging.yml +7 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +11 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +59 -0
- data/spec/dummy/config/sinicum_server.yml +13 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +191 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/fixtures/api/cache_global.json +3 -0
- data/spec/fixtures/api/content_mgnl5.json +22 -0
- data/spec/fixtures/api/default_json.json.erb +47 -0
- data/spec/fixtures/api/default_json_mgnl5.json.erb +27 -0
- data/spec/fixtures/api/file.json +73 -0
- data/spec/fixtures/api/file_mgnl5.json +51 -0
- data/spec/fixtures/api/homepage.json +1497 -0
- data/spec/fixtures/api/homepage_parent.json +483 -0
- data/spec/fixtures/api/image.json +73 -0
- data/spec/fixtures/api/image_mgnl5.json +50 -0
- data/spec/fixtures/api/navigation_children.json +3107 -0
- data/spec/fixtures/api/navigation_parents.json +25 -0
- data/spec/fixtures/api/product.json +2084 -0
- data/spec/fixtures/api/query_result.json +61 -0
- data/spec/fixtures/mock_content.rb +6 -0
- data/spec/fixtures/mock_image.gif +0 -0
- data/spec/helpers/sinicum/helper_utils_spec.rb +55 -0
- data/spec/helpers/sinicum/mgnl_helper_spec.rb +315 -0
- data/spec/helpers/sinicum/mgnl_image_helper_spec.rb +103 -0
- data/spec/sinicum/content/aggregator_spec.rb +91 -0
- data/spec/sinicum/content/website_content_resolver_spec.rb +14 -0
- data/spec/sinicum/imaging/config_spec.rb +50 -0
- data/spec/sinicum/imaging/converter_spec.rb +41 -0
- data/spec/sinicum/imaging/image_size_converter_spec.rb +27 -0
- data/spec/sinicum/imaging/imaging.yml +15 -0
- data/spec/sinicum/imaging/imaging_file_spec.rb +125 -0
- data/spec/sinicum/imaging/imaging_middleware_spec.rb +79 -0
- data/spec/sinicum/imaging/max_size_converter_spec.rb +52 -0
- data/spec/sinicum/imaging/resize_crop_converter_spec.rb +18 -0
- data/spec/sinicum/imaging_spec.rb +13 -0
- data/spec/sinicum/jcr/api_client_spec.rb +69 -0
- data/spec/sinicum/jcr/cache/global_cache_spec.rb +29 -0
- data/spec/sinicum/jcr/dam/document_spec.rb +81 -0
- data/spec/sinicum/jcr/dam/image_spec.rb +46 -0
- data/spec/sinicum/jcr/jcr_configuration_spec.rb +57 -0
- data/spec/sinicum/jcr/mgnl4_compatibility_spec.rb +10 -0
- data/spec/sinicum/jcr/node_queries_spec.rb +113 -0
- data/spec/sinicum/jcr/node_spec.rb +261 -0
- data/spec/sinicum/jcr/query_sanitizer_spec.rb +26 -0
- data/spec/sinicum/jcr/type_translator_spec.rb +42 -0
- data/spec/sinicum/jcr/type_translators/component_translator_spec.rb +71 -0
- data/spec/sinicum/jcr/type_translators/data_translator_spec.rb +38 -0
- data/spec/sinicum/jcr/type_translators/default_translator_spec.rb +19 -0
- data/spec/sinicum/navigation/default_navigation_element_spec.rb +45 -0
- data/spec/sinicum/navigation/navigation_handler_spec.rb +71 -0
- data/spec/sinicum/templating/dialog_resolver_spec.rb +13 -0
- data/spec/sinicum/util_spec.rb +34 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support/default_node_reader.rb +40 -0
- metadata +434 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
module Sinicum
|
|
5
|
+
module Jcr
|
|
6
|
+
describe Node do
|
|
7
|
+
context "should behave like an ActiveModel object" do
|
|
8
|
+
require 'test/unit/assertions'
|
|
9
|
+
require 'active_model/lint'
|
|
10
|
+
include Test::Unit::Assertions
|
|
11
|
+
include ActiveModel::Lint::Tests
|
|
12
|
+
|
|
13
|
+
before(:each) do
|
|
14
|
+
@model = Node.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
unless Rails.version =~ /^4\.1\./
|
|
18
|
+
ActiveModel::Lint::Tests.public_instance_methods.map { |m| m.to_s }.grep(/^test/)
|
|
19
|
+
.each do |m|
|
|
20
|
+
example m.gsub("_", " ") do
|
|
21
|
+
send(m)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should expose a singular and human name" do
|
|
26
|
+
@model.class.model_name.singular.should eq("sinicum_jcr_node")
|
|
27
|
+
@model.class.model_name.human.should eq("Node")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "should use i18n for model_name.human" do
|
|
32
|
+
begin
|
|
33
|
+
I18n.backend.store_translations(
|
|
34
|
+
I18n.locale,
|
|
35
|
+
activemodel: {
|
|
36
|
+
models: {
|
|
37
|
+
:'sinicum/jcr/node' => "A node name"
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
@model.class.model_name.human.should eq("A node name")
|
|
41
|
+
ensure
|
|
42
|
+
I18n.reload!
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe "basic properties after JSON initialization" do
|
|
48
|
+
let(:api_response) do
|
|
49
|
+
File.read(File.dirname(__FILE__) + "/../../fixtures/api/content_mgnl5.json")
|
|
50
|
+
end
|
|
51
|
+
let(:json_response) { MultiJson.load(api_response) }
|
|
52
|
+
let(:subject) { Node.new(json_response: json_response.first) }
|
|
53
|
+
|
|
54
|
+
its(:uuid) { should eq("684af75b-0504-467e-92ce-bea998cc8d8b") }
|
|
55
|
+
its(:jcr_path) { should eq("/home") }
|
|
56
|
+
its(:jcr_name) { should eq("home") }
|
|
57
|
+
its(:jcr_primary_type) { should eq("mgnl:page") }
|
|
58
|
+
its(:jcr_super_types) do should eq(
|
|
59
|
+
[
|
|
60
|
+
"mix:created", "mix:referenceable", "nt:base", "nt:hierarchyNode",
|
|
61
|
+
"mgnl:activatable", "mgnl:content", "mgnl:created", "mgnl:lastModified",
|
|
62
|
+
"mgnl:renderable", "mgnl:versionable"
|
|
63
|
+
])
|
|
64
|
+
end
|
|
65
|
+
its(:jcr_mixin_node_types) { should eq([]) }
|
|
66
|
+
its(:jcr_workspace) { should eq("website") }
|
|
67
|
+
its(:jcr_depth) { should eq(1) }
|
|
68
|
+
|
|
69
|
+
unless defined?(JRUBY_VERSION)
|
|
70
|
+
its(:created_at) { should eq(DateTime.new(2014, 3, 16, 14, 6, 17.666, "+01:00")) }
|
|
71
|
+
its(:updated_at) { should eq(DateTime.new(2014, 3, 18, 15, 57, 51.329, "+01:00")) }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
its(:mgnl_template) { should eq("themodule:pages/appplication") }
|
|
75
|
+
its(:mgnl_created_by) { should eq("superuser") }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe "handling of properties" do
|
|
79
|
+
let(:api_response) do
|
|
80
|
+
File.read(File.dirname(__FILE__) + "/../../fixtures/api/homepage.json")
|
|
81
|
+
end
|
|
82
|
+
let(:json_response) { MultiJson.load(api_response) }
|
|
83
|
+
let(:subject) { Node.new(json_response: json_response.first) }
|
|
84
|
+
|
|
85
|
+
it "should return the correct title" do
|
|
86
|
+
subject[:title].should eq("Shure: Mikrofone, Funkmikrofone, Ohrhörer")
|
|
87
|
+
subject[:boolean_true_test].should be true
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "should be possible to use symbol and string keys interchangeably" do
|
|
91
|
+
subject[:title].should eq("Shure: Mikrofone, Funkmikrofone, Ohrhörer")
|
|
92
|
+
subject["title"].should eq("Shure: Mikrofone, Funkmikrofone, Ohrhörer")
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
describe "handling of child nodes" do
|
|
97
|
+
let(:api_response) do
|
|
98
|
+
File.read(File.dirname(__FILE__) + "/../../fixtures/api/homepage.json")
|
|
99
|
+
end
|
|
100
|
+
let(:json_response) { MultiJson.load(api_response) }
|
|
101
|
+
let(:subject) { Node.new(json_response: json_response.first) }
|
|
102
|
+
|
|
103
|
+
it "should return a child node and resolve an array" do
|
|
104
|
+
children = subject[:orc_13]
|
|
105
|
+
children.should be_kind_of(Array)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should return the correct child node" do
|
|
109
|
+
children = subject[:orc_13]
|
|
110
|
+
children.first.jcr_path.should eq("/home/orc_13/0")
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "should return nodes in multiple steps" do
|
|
114
|
+
picture_teaser = subject[:orc_13].first[:picture_teaser_items].first
|
|
115
|
+
picture_teaser[:link_text].should eq("more")
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "should return non-array child nodes" do
|
|
119
|
+
picture_teaser = subject[:orc_13].first[:picture_teaser_items].first
|
|
120
|
+
text_files_node = picture_teaser[:text_files]
|
|
121
|
+
text_files_node.should be_kind_of(Node)
|
|
122
|
+
text_files_node.jcr_path.should eq("/home/orc_13/0/picture_teaser_items/0/text_files")
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "should be possible to call a node multiple times" do
|
|
126
|
+
children = subject[:orc_13]
|
|
127
|
+
children.should_not be_nil
|
|
128
|
+
subject[:orc_13].should eq(children)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
describe "parent handling" do
|
|
133
|
+
let(:api_response) do
|
|
134
|
+
File.read(File.dirname(__FILE__) + "/../../fixtures/api/homepage_parent.json")
|
|
135
|
+
end
|
|
136
|
+
let(:api_response2) do
|
|
137
|
+
File.read(File.dirname(__FILE__) + "/../../fixtures/api/homepage.json")
|
|
138
|
+
end
|
|
139
|
+
let(:json_response) { MultiJson.load(api_response) }
|
|
140
|
+
let(:subject) { Node.new(json_response: json_response) }
|
|
141
|
+
|
|
142
|
+
it "should return its parent node as an Array" do
|
|
143
|
+
body = { body: "should not be triggered because of cache" }
|
|
144
|
+
stub_request(:get, "http://content.dievision.de/sinicum-rest/website/home/orc_13")
|
|
145
|
+
.to_return(body: api_response, headers: { "Content-Type" => "application/json" })
|
|
146
|
+
.times(1).then.to_return(body)
|
|
147
|
+
stub_request(:get, "http://content.dievision.de/sinicum-rest/website/home")
|
|
148
|
+
.to_return(body: api_response2, headers: { "Content-Type" => "application/json" })
|
|
149
|
+
|
|
150
|
+
node = subject[0]
|
|
151
|
+
node.parent.uuid.should eq(subject.uuid)
|
|
152
|
+
node.parent.parent.uuid.should eq('21cbc762-bdcd-4520-9eff-1928986fb419')
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
describe "Type conversion" do
|
|
157
|
+
describe "date conversion" do
|
|
158
|
+
it "should properly convert a iso 8601 time string" do
|
|
159
|
+
time = subject.send(:jcr_time_string_to_datetime, "2010-04-13T09:35:01.322+02:00")
|
|
160
|
+
time.year.should eq(2010)
|
|
161
|
+
time.month.should eq(4)
|
|
162
|
+
time.day.should eq(13)
|
|
163
|
+
time.hour.should eq(9)
|
|
164
|
+
time.minute.should eq(35)
|
|
165
|
+
time.second.should eq(1)
|
|
166
|
+
time.zone.should eq("+02:00")
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "should return the original string if it is not an iso8601 format" do
|
|
170
|
+
time = subject.send(:jcr_time_string_to_datetime, "2010-04-13F09:35:01.322+02:00")
|
|
171
|
+
time.should eq("2010-04-13F09:35:01.322+02:00")
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "should handle null values" do
|
|
175
|
+
time = subject.send(:jcr_time_string_to_datetime, nil)
|
|
176
|
+
time.should be nil
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it "should convert Magnolia's Date notation: e.g. 2013-06-05T22:00:00.000Z"
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
describe "boolean conversion" do
|
|
183
|
+
it "should not touch strings" do
|
|
184
|
+
value = subject.send(:mgnl_boolean_string_to_boolean, "Some string")
|
|
185
|
+
value.should eq("Some string")
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it "should convert true values" do
|
|
189
|
+
value = subject.send(:mgnl_boolean_string_to_boolean, "true")
|
|
190
|
+
value.should be true
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it "should convert false values" do
|
|
194
|
+
value = subject.send(:mgnl_boolean_string_to_boolean, "false")
|
|
195
|
+
value.should be false
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
describe "persistence" do
|
|
201
|
+
it "should not be persisted as a new node" do
|
|
202
|
+
node = Node.new
|
|
203
|
+
node.should_not be_persisted
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
it "should be persisted if constructed from an api response" do
|
|
207
|
+
api_response = File.read(File.dirname(__FILE__) + "/../../fixtures/api/homepage.json")
|
|
208
|
+
node = Node.new(json_response: api_response)
|
|
209
|
+
node.should be_persisted
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
describe "initialize from hash" do
|
|
214
|
+
it "should set a property" do
|
|
215
|
+
node = Node.new(name: "A name")
|
|
216
|
+
node[:name].should eq("A name")
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
it "should not be possible to set 'forbidden' JCR properties" do
|
|
220
|
+
Node::PROHIBITED_JCR_PROPERTIES.each do |prop|
|
|
221
|
+
expect { Node.new(prop => "value") }.to raise_error
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
it "should not be possible to set 'forbidden' Manglia properties" do
|
|
226
|
+
Node::PROHIBITED_MGNL_PROPERTIES.each do |prop|
|
|
227
|
+
expect { Node.new(prop => "value") }.to raise_error
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
it "should directly set allowed JCR properties" do
|
|
232
|
+
Node::SETABLE_JCR_PROPERTIES.each do |prop|
|
|
233
|
+
node = Node.new(prop => "value")
|
|
234
|
+
node.send(prop).should eq("value")
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it "should should not set a hash-based value for a directly allowed JCR property" do
|
|
239
|
+
Node::SETABLE_JCR_PROPERTIES.each do |prop|
|
|
240
|
+
node = Node.new(prop => "value")
|
|
241
|
+
node[prop].should be_nil
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it "should directly set allowed Magnolia properties" do
|
|
246
|
+
Node::SETABLE_MGNL_PROPERTIES.each do |prop|
|
|
247
|
+
node = Node.new(prop => "value")
|
|
248
|
+
node.send(prop).should eq("value")
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
it "should should not set a hash-based value for a directly allowed Magnolia property" do
|
|
253
|
+
Node::SETABLE_MGNL_PROPERTIES.each do |prop|
|
|
254
|
+
node = Node.new(prop => "value")
|
|
255
|
+
node[prop].should be_nil
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Sinicum
|
|
4
|
+
module Jcr
|
|
5
|
+
describe QuerySanitizer do
|
|
6
|
+
let(:mock_class) { Class.new { include QuerySanitizer } }
|
|
7
|
+
subject { mock_class.new }
|
|
8
|
+
|
|
9
|
+
it "should not touch a query if no parameters are given" do
|
|
10
|
+
subject.send(:sanitize_query, "xpath", "query").should eq("query")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should not touch a query if empty parameters are given" do
|
|
14
|
+
subject.send(:sanitize_query, "xpath", "query", {}).should eq("query")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should sanitize a sql query" do
|
|
18
|
+
query = "select * from microphone where lower(url_path) = ':name' " \
|
|
19
|
+
"and jcr:path like '/products/microphones/en/%'"
|
|
20
|
+
result = subject.send(:sanitize_query, "xpath", query, name: "A name")
|
|
21
|
+
result.should eq("select * from microphone where lower(url_path) = 'A name' " \
|
|
22
|
+
"and jcr:path like '/products/microphones/en/%'")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Sinicum
|
|
4
|
+
module Jcr
|
|
5
|
+
describe TypeTranslator do
|
|
6
|
+
let(:first_translator) { Class.new }
|
|
7
|
+
let(:second_translator) { Class.new }
|
|
8
|
+
let(:third_translator) { Class.new }
|
|
9
|
+
let(:fourth_translator) { Class.new }
|
|
10
|
+
|
|
11
|
+
before(:each) { TypeTranslator.clear }
|
|
12
|
+
after(:each) { TypeTranslator.reset }
|
|
13
|
+
|
|
14
|
+
it "should add a new translator to the translator stack" do
|
|
15
|
+
TypeTranslator.use(first_translator)
|
|
16
|
+
TypeTranslator.use(second_translator)
|
|
17
|
+
TypeTranslator.list.should eq([second_translator, first_translator])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should reset the stack" do
|
|
21
|
+
TypeTranslator.clear
|
|
22
|
+
TypeTranslator.reset
|
|
23
|
+
TypeTranslator.list.should eq(TypeTranslator::DEFAULT_TRANSLATORS)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "swapping" do
|
|
27
|
+
let(:new_translator) { Class.new }
|
|
28
|
+
|
|
29
|
+
before(:each) do
|
|
30
|
+
[first_translator, second_translator, third_translator, fourth_translator].each do |t|
|
|
31
|
+
TypeTranslator.use(t)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should clear the stack" do
|
|
36
|
+
TypeTranslator.clear
|
|
37
|
+
TypeTranslator.list.should eq([])
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Sinicum
|
|
4
|
+
module Jcr
|
|
5
|
+
module TypeTranslators
|
|
6
|
+
describe ComponentTranslator do
|
|
7
|
+
let(:mock_class) do
|
|
8
|
+
Class.new do
|
|
9
|
+
def initialize(options)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
[:mgnl4, :mgnl5].each do |mgnl_version|
|
|
15
|
+
it "should return nothing for a default node in #{mgnl_version}" do
|
|
16
|
+
result = ComponentTranslator.initialize_node(
|
|
17
|
+
read_default_node_json("website", "mgnl:contentNode", nil, mgnl_version))
|
|
18
|
+
result.should be nil
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should return a page for a page instance in #{mgnl_version}" do
|
|
22
|
+
json = read_default_node_json(
|
|
23
|
+
"website",
|
|
24
|
+
"mgnl:page",
|
|
25
|
+
"myModule:pages/homepage",
|
|
26
|
+
mgnl_version)
|
|
27
|
+
stub_const("MyModule::Pages::Homepage", mock_class)
|
|
28
|
+
|
|
29
|
+
result = ComponentTranslator.initialize_node(json)
|
|
30
|
+
result.should be_kind_of(mock_class)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should handle module names with dashes in #{mgnl_version}" do
|
|
34
|
+
json = read_default_node_json(
|
|
35
|
+
"website",
|
|
36
|
+
"mgnl:page",
|
|
37
|
+
"myModule:pages/homepage",
|
|
38
|
+
mgnl_version)
|
|
39
|
+
stub_const("MyModule::Pages::Homepage", mock_class)
|
|
40
|
+
|
|
41
|
+
result = ComponentTranslator.initialize_node(json)
|
|
42
|
+
result.should be_kind_of(mock_class)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should return nothing if a page class is not defined in #{mgnl_version}" do
|
|
46
|
+
json = read_default_node_json(
|
|
47
|
+
"website",
|
|
48
|
+
"mgnl:page",
|
|
49
|
+
"myModule:pages/homepage",
|
|
50
|
+
mgnl_version)
|
|
51
|
+
|
|
52
|
+
result = ComponentTranslator.initialize_node(json)
|
|
53
|
+
result.should be nil
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should return a page for a component instance in #{mgnl_version}" do
|
|
57
|
+
json = read_default_node_json(
|
|
58
|
+
"website",
|
|
59
|
+
"mgnl:component",
|
|
60
|
+
"myModule:components/path/teaser",
|
|
61
|
+
mgnl_version)
|
|
62
|
+
stub_const("MyModule::Components::Path::Teaser", mock_class)
|
|
63
|
+
|
|
64
|
+
result = ComponentTranslator.initialize_node(json)
|
|
65
|
+
result.should be_kind_of(mock_class)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Sinicum
|
|
4
|
+
module Jcr
|
|
5
|
+
module TypeTranslators
|
|
6
|
+
describe ComponentTranslator do
|
|
7
|
+
let(:mock_class) do
|
|
8
|
+
Class.new do
|
|
9
|
+
def initialize(options)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
let(:api_response) do
|
|
14
|
+
File.read(File.dirname(__FILE__) +
|
|
15
|
+
"/../../../fixtures/api/product.json")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
let(:json) { MultiJson.load(api_response).first }
|
|
19
|
+
|
|
20
|
+
it "should return nothing for a default node" do
|
|
21
|
+
result = DataTranslator.initialize_node(read_default_node_json)
|
|
22
|
+
result.should be nil
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should return a default node when no matching class exists" do
|
|
26
|
+
result = DataTranslator.initialize_node(json)
|
|
27
|
+
result.should be nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should initialize a new class based on the node's primary type" do
|
|
31
|
+
stub_const("Microphone", mock_class)
|
|
32
|
+
result = DataTranslator.initialize_node(json)
|
|
33
|
+
result.should be_kind_of(mock_class)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Sinicum
|
|
4
|
+
module Jcr
|
|
5
|
+
module TypeTranslators
|
|
6
|
+
describe DefaultTranslator do
|
|
7
|
+
it "should return a Node instance" do
|
|
8
|
+
result = DefaultTranslator.initialize_node(read_default_node_json)
|
|
9
|
+
result.class.should eq(::Sinicum::Jcr::Node)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should return a properly initialized instance" do
|
|
13
|
+
result = DefaultTranslator.initialize_node(read_default_node_json)
|
|
14
|
+
result.uuid.should eq("21cbc762-bdcd-4520-9eff-1928986fb419")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|