sinicum 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +7 -0
  2. data/.cane +19 -0
  3. data/.gitignore +14 -0
  4. data/.rubocop.yml +30 -0
  5. data/.travis.yml +14 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +24 -0
  8. data/README.md +327 -0
  9. data/Rakefile +37 -0
  10. data/app/assets/javascripts/sinicum/magnolia_client.js.coffee +233 -0
  11. data/app/controllers/sinicum/controller_base.rb +173 -0
  12. data/app/controllers/sinicum/controllers/cache_aware.rb +16 -0
  13. data/app/controllers/sinicum/controllers/global_state_cache.rb +83 -0
  14. data/app/helpers/sinicum/helper_utils.rb +152 -0
  15. data/app/helpers/sinicum/mgnl_helper.rb +145 -0
  16. data/app/helpers/sinicum/mgnl_helper5.rb +7 -0
  17. data/app/helpers/sinicum/mgnl_image_helper.rb +26 -0
  18. data/app/helpers/sinicum/taglib_helper5.rb +166 -0
  19. data/gemfiles/Gemfile-3.2 +6 -0
  20. data/gemfiles/Gemfile-4.0 +6 -0
  21. data/lib/generators/sinicum/install_generator.rb +162 -0
  22. data/lib/generators/sinicum/templates/VersionHandler.java +18 -0
  23. data/lib/generators/sinicum/templates/config/default/log4j-development.xml +203 -0
  24. data/lib/generators/sinicum/templates/config/default/log4j.xml +200 -0
  25. data/lib/generators/sinicum/templates/config/default/magnolia-author.properties +63 -0
  26. data/lib/generators/sinicum/templates/config/default/magnolia-public01.properties +63 -0
  27. data/lib/generators/sinicum/templates/config/default/magnolia.properties +63 -0
  28. data/lib/generators/sinicum/templates/config/repo-conf/jackrabbit-bundle-postgres-search-author.xml +73 -0
  29. data/lib/generators/sinicum/templates/config/repo-conf/jackrabbit-bundle-postgres-search-public01.xml +73 -0
  30. data/lib/generators/sinicum/templates/config/repo-conf/jackrabbit-bundle-postgres-search.xml +70 -0
  31. data/lib/generators/sinicum/templates/magnolia/config.modules.myproject.dialogs.xml +1625 -0
  32. data/lib/generators/sinicum/templates/magnolia/config.modules.myproject.templates.xml +247 -0
  33. data/lib/generators/sinicum/templates/module-config.xml +13 -0
  34. data/lib/generators/sinicum/templates/module-pom.xml +67 -0
  35. data/lib/generators/sinicum/templates/project-pom.xml +104 -0
  36. data/lib/generators/sinicum/templates/rails/_article.html.haml +15 -0
  37. data/lib/generators/sinicum/templates/rails/_content.html.haml +2 -0
  38. data/lib/generators/sinicum/templates/rails/_meta.html.haml +9 -0
  39. data/lib/generators/sinicum/templates/rails/application.html.haml +11 -0
  40. data/lib/generators/sinicum/templates/rails/content_controller.rb +5 -0
  41. data/lib/generators/sinicum/templates/rails/imaging.yml +8 -0
  42. data/lib/generators/sinicum/templates/rails/sinicum_server.yml +15 -0
  43. data/lib/sinicum.rb +53 -0
  44. data/lib/sinicum/content/aggregator.rb +173 -0
  45. data/lib/sinicum/content/website_content_resolver.rb +10 -0
  46. data/lib/sinicum/engine.rb +23 -0
  47. data/lib/sinicum/imaging.rb +29 -0
  48. data/lib/sinicum/imaging/config.rb +133 -0
  49. data/lib/sinicum/imaging/converter.rb +81 -0
  50. data/lib/sinicum/imaging/default_converter.rb +20 -0
  51. data/lib/sinicum/imaging/image_size_converter.rb +52 -0
  52. data/lib/sinicum/imaging/imaging.rb +171 -0
  53. data/lib/sinicum/imaging/imaging_file.rb +115 -0
  54. data/lib/sinicum/imaging/imaging_middleware.rb +56 -0
  55. data/lib/sinicum/imaging/max_size_converter.rb +39 -0
  56. data/lib/sinicum/imaging/resize_crop_converter.rb +35 -0
  57. data/lib/sinicum/jcr/api_client.rb +50 -0
  58. data/lib/sinicum/jcr/api_queries.rb +37 -0
  59. data/lib/sinicum/jcr/cache/global_cache.rb +26 -0
  60. data/lib/sinicum/jcr/dam/document.rb +57 -0
  61. data/lib/sinicum/jcr/dam/image.rb +40 -0
  62. data/lib/sinicum/jcr/jcr_configuration.rb +67 -0
  63. data/lib/sinicum/jcr/mgnl4_compatibility.rb +11 -0
  64. data/lib/sinicum/jcr/node.rb +268 -0
  65. data/lib/sinicum/jcr/node_initializer.rb +16 -0
  66. data/lib/sinicum/jcr/node_queries.rb +101 -0
  67. data/lib/sinicum/jcr/query_sanitizer.rb +24 -0
  68. data/lib/sinicum/jcr/type_translator.rb +38 -0
  69. data/lib/sinicum/jcr/type_translators/component_translator.rb +28 -0
  70. data/lib/sinicum/jcr/type_translators/dam_translator.rb +33 -0
  71. data/lib/sinicum/jcr/type_translators/data_translator.rb +31 -0
  72. data/lib/sinicum/jcr/type_translators/default_translator.rb +13 -0
  73. data/lib/sinicum/jcr/type_translators/translator_base.rb +40 -0
  74. data/lib/sinicum/logger.rb +28 -0
  75. data/lib/sinicum/navigation/default_navigation_element.rb +30 -0
  76. data/lib/sinicum/navigation/navigation_element.rb +39 -0
  77. data/lib/sinicum/navigation/navigation_element_list.rb +33 -0
  78. data/lib/sinicum/navigation/navigation_handler.rb +95 -0
  79. data/lib/sinicum/navigation/navigation_status.rb +27 -0
  80. data/lib/sinicum/templating/area_handler.rb +33 -0
  81. data/lib/sinicum/templating/dialog_resolver.rb +26 -0
  82. data/lib/sinicum/templating/templating_utils.rb +24 -0
  83. data/lib/sinicum/util.rb +12 -0
  84. data/lib/sinicum/version.rb +3 -0
  85. data/script/cibuild +31 -0
  86. data/sinicum.gemspec +29 -0
  87. data/spec/controllers/sinicum/controller_base_spec.rb +53 -0
  88. data/spec/controllers/sinicum/controllers/global_state_cache_spec.rb +35 -0
  89. data/spec/dummy/REVISION +1 -0
  90. data/spec/dummy/Rakefile +7 -0
  91. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  92. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  93. data/spec/dummy/app/views/application/index.html.erb +1 -0
  94. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  95. data/spec/dummy/app/views/layouts/layout_name.html.erb +0 -0
  96. data/spec/dummy/app/views/layouts/my-module/test.html.erb +0 -0
  97. data/spec/dummy/app/views/layouts/my_module/test.html.erb +0 -0
  98. data/spec/dummy/config.ru +4 -0
  99. data/spec/dummy/config/application.rb +45 -0
  100. data/spec/dummy/config/boot.rb +10 -0
  101. data/spec/dummy/config/database.yml +22 -0
  102. data/spec/dummy/config/environment.rb +5 -0
  103. data/spec/dummy/config/environments/development.rb +24 -0
  104. data/spec/dummy/config/environments/production.rb +51 -0
  105. data/spec/dummy/config/environments/test.rb +34 -0
  106. data/spec/dummy/config/imaging.yml +7 -0
  107. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  108. data/spec/dummy/config/initializers/inflections.rb +10 -0
  109. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  110. data/spec/dummy/config/initializers/secret_token.rb +11 -0
  111. data/spec/dummy/config/initializers/session_store.rb +8 -0
  112. data/spec/dummy/config/locales/en.yml +5 -0
  113. data/spec/dummy/config/routes.rb +59 -0
  114. data/spec/dummy/config/sinicum_server.yml +13 -0
  115. data/spec/dummy/public/404.html +26 -0
  116. data/spec/dummy/public/422.html +26 -0
  117. data/spec/dummy/public/500.html +26 -0
  118. data/spec/dummy/public/favicon.ico +0 -0
  119. data/spec/dummy/public/javascripts/application.js +2 -0
  120. data/spec/dummy/public/javascripts/controls.js +965 -0
  121. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  122. data/spec/dummy/public/javascripts/effects.js +1123 -0
  123. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  124. data/spec/dummy/public/javascripts/rails.js +191 -0
  125. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  126. data/spec/dummy/script/rails +6 -0
  127. data/spec/fixtures/api/cache_global.json +3 -0
  128. data/spec/fixtures/api/content_mgnl5.json +22 -0
  129. data/spec/fixtures/api/default_json.json.erb +47 -0
  130. data/spec/fixtures/api/default_json_mgnl5.json.erb +27 -0
  131. data/spec/fixtures/api/file.json +73 -0
  132. data/spec/fixtures/api/file_mgnl5.json +51 -0
  133. data/spec/fixtures/api/homepage.json +1497 -0
  134. data/spec/fixtures/api/homepage_parent.json +483 -0
  135. data/spec/fixtures/api/image.json +73 -0
  136. data/spec/fixtures/api/image_mgnl5.json +50 -0
  137. data/spec/fixtures/api/navigation_children.json +3107 -0
  138. data/spec/fixtures/api/navigation_parents.json +25 -0
  139. data/spec/fixtures/api/product.json +2084 -0
  140. data/spec/fixtures/api/query_result.json +61 -0
  141. data/spec/fixtures/mock_content.rb +6 -0
  142. data/spec/fixtures/mock_image.gif +0 -0
  143. data/spec/helpers/sinicum/helper_utils_spec.rb +55 -0
  144. data/spec/helpers/sinicum/mgnl_helper_spec.rb +315 -0
  145. data/spec/helpers/sinicum/mgnl_image_helper_spec.rb +103 -0
  146. data/spec/sinicum/content/aggregator_spec.rb +91 -0
  147. data/spec/sinicum/content/website_content_resolver_spec.rb +14 -0
  148. data/spec/sinicum/imaging/config_spec.rb +50 -0
  149. data/spec/sinicum/imaging/converter_spec.rb +41 -0
  150. data/spec/sinicum/imaging/image_size_converter_spec.rb +27 -0
  151. data/spec/sinicum/imaging/imaging.yml +15 -0
  152. data/spec/sinicum/imaging/imaging_file_spec.rb +125 -0
  153. data/spec/sinicum/imaging/imaging_middleware_spec.rb +79 -0
  154. data/spec/sinicum/imaging/max_size_converter_spec.rb +52 -0
  155. data/spec/sinicum/imaging/resize_crop_converter_spec.rb +18 -0
  156. data/spec/sinicum/imaging_spec.rb +13 -0
  157. data/spec/sinicum/jcr/api_client_spec.rb +69 -0
  158. data/spec/sinicum/jcr/cache/global_cache_spec.rb +29 -0
  159. data/spec/sinicum/jcr/dam/document_spec.rb +81 -0
  160. data/spec/sinicum/jcr/dam/image_spec.rb +46 -0
  161. data/spec/sinicum/jcr/jcr_configuration_spec.rb +57 -0
  162. data/spec/sinicum/jcr/mgnl4_compatibility_spec.rb +10 -0
  163. data/spec/sinicum/jcr/node_queries_spec.rb +113 -0
  164. data/spec/sinicum/jcr/node_spec.rb +261 -0
  165. data/spec/sinicum/jcr/query_sanitizer_spec.rb +26 -0
  166. data/spec/sinicum/jcr/type_translator_spec.rb +42 -0
  167. data/spec/sinicum/jcr/type_translators/component_translator_spec.rb +71 -0
  168. data/spec/sinicum/jcr/type_translators/data_translator_spec.rb +38 -0
  169. data/spec/sinicum/jcr/type_translators/default_translator_spec.rb +19 -0
  170. data/spec/sinicum/navigation/default_navigation_element_spec.rb +45 -0
  171. data/spec/sinicum/navigation/navigation_handler_spec.rb +71 -0
  172. data/spec/sinicum/templating/dialog_resolver_spec.rb +13 -0
  173. data/spec/sinicum/util_spec.rb +34 -0
  174. data/spec/spec_helper.rb +42 -0
  175. data/spec/support/default_node_reader.rb +40 -0
  176. metadata +434 -0
@@ -0,0 +1,91 @@
1
+ require "spec_helper"
2
+
3
+ module Sinicum
4
+ module Content
5
+ describe "Content Thread local functionality" do
6
+ it "should return the original content as content data" do
7
+ Aggregator.original_content = "content"
8
+ Aggregator.content_data.should == "content"
9
+ end
10
+
11
+ it "should implicitly reset all stacks if original content is called" do
12
+ Aggregator.should_receive(:clean)
13
+ Aggregator.original_content = "original_content"
14
+ end
15
+
16
+ it "should return an empty hash if no content node with the respective name exists" do
17
+ Aggregator.original_content = {}
18
+ Aggregator.push_content_node(:no_valid_name) do
19
+ Aggregator.content_data.should == {}
20
+ end
21
+ Aggregator.clean
22
+ end
23
+
24
+ it "should clean the stack" do
25
+ Aggregator.original_content = "content"
26
+ Thread.current[:__cms_stack] = "other content"
27
+ Aggregator.clean
28
+ Aggregator.original_content.should.nil?
29
+ Thread.current[:__cms_stack].should.nil?
30
+ end
31
+
32
+ it "should push a paragraph name" do
33
+ Aggregator.push_content_node("some_name") do
34
+ Aggregator.content_node.should eq("some_name")
35
+ end
36
+ end
37
+
38
+ describe "current content" do
39
+ it "should push current content" do
40
+ Aggregator.original_content = "original"
41
+ in_block = false
42
+ Aggregator.push_current_content("local") do
43
+ Aggregator.content_data.should eq("local")
44
+ in_block = true
45
+ end
46
+ Aggregator.content_data.should eq("original")
47
+ in_block.should be_true
48
+ end
49
+ end
50
+
51
+ describe "current page" do
52
+ before(:each) do
53
+ Aggregator.clean
54
+ @original_page = Sinicum::Jcr::Node.new
55
+ @new_page = Sinicum::Jcr::Node.new
56
+ Aggregator.original_content = @original_page
57
+ end
58
+
59
+ it "should return the original page if no active page has been set explicitly" do
60
+ Aggregator.active_page.should == @original_page
61
+ end
62
+
63
+ it "should push the new content on top of the active page stack" do
64
+ Aggregator.push_active_page(@new_page) do
65
+ Aggregator.active_page.should == @new_page
66
+ end
67
+ end
68
+
69
+ it "should restore the active page after the push" do
70
+ Aggregator.push_active_page(@new_page) do
71
+ # nothing
72
+ end
73
+ Aggregator.active_page.should == @original_page
74
+ end
75
+
76
+ it "should make the new active page the current content_data object" do
77
+ Aggregator.push_active_page(@new_page) do
78
+ Aggregator.content_data.should == @new_page
79
+ end
80
+ end
81
+
82
+ it "should restore the content data object after the push" do
83
+ Aggregator.push_active_page(@new_page) do
84
+ # nothing
85
+ end
86
+ Aggregator.content_data.should == @original_page
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ module Sinicum
4
+ module Content
5
+ describe WebsiteContentResolver do
6
+ it "should fetch the content matching the path" do
7
+ node = double(:node)
8
+ Sinicum::Jcr::Node.should_receive(:find_by_path).with(:website, "/home").and_return(node)
9
+ result = WebsiteContentResolver.find_for_path("/home")
10
+ result.should eq(node)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ module Sinicum
4
+ module Imaging
5
+ describe Config do
6
+ test_config = File.join(File.dirname(__FILE__), "imaging.yml")
7
+
8
+ before(:each) do
9
+ @tmpdir = File.join("/", "tmp", "imaging")
10
+ FileUtils.mkdir(@tmpdir) unless File.exist?(@tmpdir)
11
+ end
12
+
13
+ after(:each) do
14
+ FileUtils.rm_r(@tmpdir) if File.exist?(@tmpdir)
15
+ end
16
+
17
+ it "should not initialize if not yet configured" do
18
+ expect { Config.instance }.to raise_error(RuntimeError, /config/)
19
+ end
20
+
21
+ it "should use the correct configuration file" do
22
+ config = Config.configure(test_config)
23
+ config.send(:config_file).should == test_config
24
+ end
25
+
26
+ it "should set the right root directory" do
27
+ config = Config.configure(test_config)
28
+ config.root_dir.should == @tmpdir.to_s
29
+ end
30
+
31
+ it "should store all files under the root dir" do
32
+ config = Config.configure(test_config)
33
+ config.file_dir.should =~ /#{config.root_dir}\/.+/
34
+ config.tmp_dir.should =~ /#{config.root_dir}\/.+/
35
+ config.version_file.should =~ /#{config.root_dir}\/.+/
36
+ end
37
+
38
+ it "should return the default converter if no valid renderer is given" do
39
+ config = Config.configure(test_config)
40
+ config.converter(:inexistent).should be_a DefaultConverter
41
+ end
42
+
43
+ it "should return the right converter" do
44
+ config = Config.configure(test_config)
45
+ config.converter(:slideshow_thumbs).should be_a ResizeCropConverter
46
+ config.converter(:margin_column).should be_a MaxSizeConverter
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ module Sinicum
4
+ module Imaging
5
+ describe Converter do
6
+ let(:conv) do
7
+ clazz = Class.new do
8
+ include Converter
9
+
10
+ def initialize(configuration)
11
+ super(configuration)
12
+ end
13
+ end
14
+ clazz
15
+ end
16
+
17
+ describe "#device_pixel_size" do
18
+ it "should work without a hires_factor" do
19
+ converter = conv.new("x" => 57)
20
+ converter.send(:device_pixel_size, 57).should eq(57)
21
+ end
22
+
23
+ it "should consider a hires_factor if given" do
24
+ converter = conv.new("x" => 57, "hires_factor" => 2)
25
+ converter.send(:device_pixel_size, 57).should eq(114)
26
+ end
27
+
28
+ it "should consider round a result and always return an integer" do
29
+ converter = conv.new("x" => 57, "hires_factor" => 1.4)
30
+ converter.send(:device_pixel_size, 57).should eq(80)
31
+ converter.send(:device_pixel_size, 57).should be_kind_of(Integer)
32
+ end
33
+
34
+ it "should work with an empty string" do
35
+ converter = conv.new("x" => 57, "hires_factor" => 2)
36
+ converter.send(:device_pixel_size, '').should eq('')
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module Sinicum
4
+ module Imaging
5
+ describe ImageSizeConverter do
6
+ let(:image) do
7
+ document = double("document")
8
+ document.stub(:[]).and_return(nil)
9
+ document.stub(:[]).with(:width).and_return(100)
10
+ document.stub(:[]).with(:height).and_return(50)
11
+ image = Sinicum::Jcr::Dam::Image.new
12
+ image.stub(:[]).and_return(nil)
13
+ image.stub(:[]).with(:document).and_return(document)
14
+ end
15
+
16
+ it "should convert the width" do
17
+ conv = ImageSizeConverter.new(image, "teaser")
18
+ conv.width.should eq(960)
19
+ end
20
+
21
+ it "should convert the height" do
22
+ conv = ImageSizeConverter.new(image, "teaser")
23
+ conv.height.should eq(444)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ root_dir: /tmp/imaging
2
+
3
+ renderer:
4
+
5
+ slideshow_thumbs:
6
+ render_type: resize_crop
7
+ format: jpeg
8
+ x: 64
9
+ y: 50
10
+
11
+ margin_column:
12
+ render_type: resize_max
13
+ format: jpeg
14
+ x: 300
15
+ y: 500
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ module Sinicum
4
+ module Imaging
5
+ describe ImagingFile do
6
+ context "dam" do
7
+ it "should normalize the path" do
8
+ file = ImagingFile.new("/dam/pa.th/to.jpg")
9
+ file.normalized_request_path.should eq("/damfiles/default/pa.th/to")
10
+ file.extension.should eq("jpg")
11
+ file.fingerprint.should be nil
12
+ end
13
+
14
+ it "should normalize not touch a regular imaging path" do
15
+ file = ImagingFile.new("/damfiles/default/path/to")
16
+ file.normalized_request_path.should eq("/damfiles/default/path/to")
17
+ file.extension.should be nil
18
+ file.fingerprint.should be nil
19
+ end
20
+
21
+ it "should extract the cache key with a suffix" do
22
+ file = ImagingFile.new(
23
+ "/damfiles/default/path/to/file-de89466a9267dccc7712379f44e6cd85.jpg")
24
+ file.normalized_request_path.should eq("/damfiles/default/path/to/file")
25
+ file.extension.should eq("jpg")
26
+ file.fingerprint.should eq("de89466a9267dccc7712379f44e6cd85")
27
+ end
28
+
29
+ it "should ignore a possible document repetition if the last two path parts do not match" do
30
+ file = ImagingFile.new("/dam/pa.th/to/tu.jpg")
31
+ file.normalized_request_path.should eq("/damfiles/default/pa.th/to/tu")
32
+ file.extension.should eq("jpg")
33
+ file.fingerprint.should be nil
34
+ end
35
+
36
+ it "should extract the cache key with a suffix" do
37
+ file = ImagingFile.new("/damfiles/default/path/to/" \
38
+ "file-de89466a9267dccc7712379f44e6cd85.jpg")
39
+ file.normalized_request_path.should eq("/damfiles/default/path/to/file")
40
+ file.extension.should eq("jpg")
41
+ file.fingerprint.should eq("de89466a9267dccc7712379f44e6cd85")
42
+ end
43
+
44
+ it "should extract the cache key without a suffix" do
45
+ file = ImagingFile.new(
46
+ "/damfiles/default/path/to/file-de89466a9267dccc7712379f44e6cd85")
47
+ file.normalized_request_path.should eq("/damfiles/default/path/to/file")
48
+ file.extension.should be nil
49
+ file.fingerprint.should eq("de89466a9267dccc7712379f44e6cd85")
50
+ end
51
+
52
+ describe "#cache_time" do
53
+ it "should have a cache time of one day for regular requests" do
54
+ file = ImagingFile.new("/damfiles/default/path/to")
55
+ file.cache_time.should eq(24 * 60 * 60)
56
+ end
57
+
58
+ it "should have a cache time of a week day for requests with a fingerprint" do
59
+ file = ImagingFile.new("/damfiles/default/path/to-de89466a9267dccc7712379f44e6cd85")
60
+ file.cache_time.should eq(7 * 24 * 60 * 60)
61
+ end
62
+ end
63
+ end
64
+
65
+ context "dms" do
66
+ it "should normalize the path" do
67
+ file = ImagingFile.new("/dms/pa.th/to.jpg")
68
+ file.normalized_request_path.should eq("/dmsfiles/default/pa.th/to")
69
+ file.extension.should eq("jpg")
70
+ file.fingerprint.should be nil
71
+ end
72
+
73
+ it "should normalize not touch a regular imaging path" do
74
+ file = ImagingFile.new("/dmsfiles/default/path/to")
75
+ file.normalized_request_path.should eq("/dmsfiles/default/path/to")
76
+ file.extension.should be nil
77
+ file.fingerprint.should be nil
78
+ end
79
+
80
+ it "should extract the cache key with a suffix" do
81
+ file = ImagingFile.new(
82
+ "/dmsfiles/default/path/to/file-de89466a9267dccc7712379f44e6cd85.jpg")
83
+ file.normalized_request_path.should eq("/dmsfiles/default/path/to/file")
84
+ file.extension.should eq("jpg")
85
+ file.fingerprint.should eq("de89466a9267dccc7712379f44e6cd85")
86
+ end
87
+
88
+ it "should ignore a possible document repetition if the last two path parts do not match" do
89
+ file = ImagingFile.new("/dms/pa.th/to/tu.jpg")
90
+ file.normalized_request_path.should eq("/dmsfiles/default/pa.th/to/tu")
91
+ file.extension.should eq("jpg")
92
+ file.fingerprint.should be nil
93
+ end
94
+
95
+ it "should extract the cache key with a suffix" do
96
+ file = ImagingFile.new("/dmsfiles/default/path/to/" \
97
+ "file-de89466a9267dccc7712379f44e6cd85.jpg")
98
+ file.normalized_request_path.should eq("/dmsfiles/default/path/to/file")
99
+ file.extension.should eq("jpg")
100
+ file.fingerprint.should eq("de89466a9267dccc7712379f44e6cd85")
101
+ end
102
+
103
+ it "should extract the cache key without a suffix" do
104
+ file = ImagingFile.new(
105
+ "/dmsfiles/default/path/to/file-de89466a9267dccc7712379f44e6cd85")
106
+ file.normalized_request_path.should eq("/dmsfiles/default/path/to/file")
107
+ file.extension.should be nil
108
+ file.fingerprint.should eq("de89466a9267dccc7712379f44e6cd85")
109
+ end
110
+
111
+ describe "#cache_time" do
112
+ it "should have a cache time of one day for regular requests" do
113
+ file = ImagingFile.new("/dmsfiles/default/path/to")
114
+ file.cache_time.should eq(24 * 60 * 60)
115
+ end
116
+
117
+ it "should have a cache time of a week day for requests with a fingerprint" do
118
+ file = ImagingFile.new("/dmsfiles/default/path/to-de89466a9267dccc7712379f44e6cd85")
119
+ file.cache_time.should eq(7 * 24 * 60 * 60)
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ module Sinicum
4
+ module Imaging
5
+ describe ImagingMiddleware do
6
+ include Rack::Test::Methods
7
+
8
+ let(:inner_app) do
9
+ ->(env) { [200, { "Content-Type" => "text/plain" }, "Downstream Response"] }
10
+ end
11
+ let(:app) { ImagingMiddleware.new(inner_app) }
12
+
13
+ let(:mock_file) { File.absolute_path("../../../fixtures/mock_image.gif", __FILE__) }
14
+
15
+ it "should be ok" do
16
+ get "/"
17
+ last_response.should =~ /Downstream Response/
18
+ end
19
+
20
+ it "should return 404 if the file requested does not exist" do
21
+ ::Sinicum::Imaging::Imaging.stub(:rendered_resource).and_return(nil)
22
+ get "/damfiles/default/path/to/file"
23
+ last_response.status.should eq(404)
24
+ end
25
+
26
+ describe "request to an existing file" do
27
+ before(:each) do
28
+ mock_resource = double("resource")
29
+ mock_resource.stub(:path) { mock_file }
30
+ mock_resource.stub(:filename) { "mock_image.gif" }
31
+ mock_resource.stub(:fingerprint) { "de89466a9267dccc7712379f44e6cd85" }
32
+ ::Sinicum::Imaging::Imaging.stub(:rendered_resource).and_return(mock_resource)
33
+ end
34
+
35
+ it "should be successful" do
36
+ get "/damfiles/default/path/to/file-de89466a9267dccc7712379f44e6cd85"
37
+ last_response.status.should eq(200)
38
+ get "/dmsfiles/default/path/to/file-de89466a9267dccc7712379f44e6cd85"
39
+ last_response.status.should eq(200)
40
+ end
41
+
42
+ it "should set the filename header" do
43
+ get "/damfiles/default/path/to/file-de89466a9267dccc7712379f44e6cd85"
44
+ cd_header = last_response.headers["Content-Disposition"]
45
+ cd_header.should =~ /inline; filename="mock_image.gif"/
46
+ get "/dmsfiles/default/path/to/file-de89466a9267dccc7712379f44e6cd85"
47
+ cd_header = last_response.headers["Content-Disposition"]
48
+ cd_header.should =~ /inline; filename="mock_image.gif"/
49
+ end
50
+
51
+ it "should set the cache header to one week" do
52
+ Rails.configuration.action_controller.perform_caching = true
53
+ get "/damfiles/default/path/to/file-de89466a9267dccc7712379f44e6cd85"
54
+ cd_header = last_response.headers["Cache-Control"]
55
+ cd_header.should =~ /max-age=604800, public/
56
+ Rails.configuration.action_controller.perform_caching = false
57
+ end
58
+
59
+ it "should set the cache header to one week (dms)" do
60
+ Rails.configuration.action_controller.perform_caching = true
61
+ get "/dmsfiles/default/path/to/file-de89466a9267dccc7712379f44e6cd85"
62
+ cd_header = last_response.headers["Cache-Control"]
63
+ cd_header.should =~ /max-age=604800, public/
64
+ Rails.configuration.action_controller.perform_caching = false
65
+ end
66
+ end
67
+
68
+ describe "request images whith the original prefix" do
69
+ it "should be successful" do
70
+ ::Sinicum::Imaging::Imaging.stub(:rendered_resource).and_return(nil)
71
+ get "/dam/path/to/file"
72
+ last_response.body.should_not =~ /Downstream Response/
73
+ get "/dms/path/to/file"
74
+ last_response.body.should_not =~ /Downstream Response/
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end