alchemy_cms 3.3.0.rc1 → 3.3.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -2
  3. data/Gemfile +1 -0
  4. data/alchemy_cms.gemspec +6 -6
  5. data/app/assets/javascripts/alchemy/alchemy.base.js.coffee +0 -7
  6. data/app/assets/javascripts/alchemy/alchemy.dialog.js.coffee +4 -4
  7. data/app/assets/javascripts/alchemy/alchemy.element_editors.js.coffee +51 -5
  8. data/app/assets/javascripts/alchemy/alchemy.sitemap.js.coffee +0 -2
  9. data/app/assets/stylesheets/alchemy/elements.scss +2 -2
  10. data/app/controllers/alchemy/admin/elements_controller.rb +2 -0
  11. data/app/controllers/alchemy/admin/pages_controller.rb +11 -3
  12. data/app/controllers/alchemy/admin/pictures_controller.rb +1 -0
  13. data/app/models/alchemy/element.rb +3 -1
  14. data/app/models/alchemy/element/element_contents.rb +2 -7
  15. data/app/models/alchemy/element/presenters.rb +11 -4
  16. data/app/models/alchemy/page.rb +3 -1
  17. data/app/views/alchemy/admin/attachments/archive_overlay.js.erb +0 -1
  18. data/app/views/alchemy/admin/contents/create.js.erb +0 -1
  19. data/app/views/alchemy/admin/elements/_element_header.html.erb +3 -1
  20. data/app/views/alchemy/admin/elements/order.js.erb +25 -10
  21. data/app/views/alchemy/admin/elements/update.js.erb +1 -2
  22. data/app/views/alchemy/admin/essence_files/assign.js.erb +0 -1
  23. data/app/views/alchemy/admin/essence_pictures/assign.js.erb +0 -1
  24. data/app/views/alchemy/admin/legacy_page_urls/create.js.erb +0 -1
  25. data/app/views/alchemy/admin/pages/destroy.js.erb +0 -1
  26. data/app/views/alchemy/admin/pages/update.js.erb +6 -4
  27. data/app/views/alchemy/admin/pictures/_filter_and_size_bar.html.erb +2 -1
  28. data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +1 -7
  29. data/app/views/alchemy/admin/pictures/archive_overlay.js.erb +0 -1
  30. data/bin/alchemy +1 -1
  31. data/bin/rspec +3 -2
  32. data/bin/spring +6 -6
  33. data/config/alchemy/config.yml +6 -1
  34. data/lib/alchemy/seeder.rb +9 -3
  35. data/lib/alchemy/version.rb +1 -1
  36. metadata +6 -471
  37. data/spec/controllers/alchemy/admin/attachments_controller_spec.rb +0 -193
  38. data/spec/controllers/alchemy/admin/base_controller_spec.rb +0 -87
  39. data/spec/controllers/alchemy/admin/clipboard_controller_spec.rb +0 -60
  40. data/spec/controllers/alchemy/admin/contents_controller_spec.rb +0 -78
  41. data/spec/controllers/alchemy/admin/dashboard_controller_spec.rb +0 -144
  42. data/spec/controllers/alchemy/admin/elements_controller_spec.rb +0 -496
  43. data/spec/controllers/alchemy/admin/essence_files_controller_spec.rb +0 -76
  44. data/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb +0 -202
  45. data/spec/controllers/alchemy/admin/languages_controller_spec.rb +0 -73
  46. data/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb +0 -21
  47. data/spec/controllers/alchemy/admin/pages_controller_spec.rb +0 -639
  48. data/spec/controllers/alchemy/admin/pictures_controller_spec.rb +0 -383
  49. data/spec/controllers/alchemy/admin/resources_controller_spec.rb +0 -81
  50. data/spec/controllers/alchemy/admin/tags_controller_spec.rb +0 -63
  51. data/spec/controllers/alchemy/admin/trash_controller_spec.rb +0 -67
  52. data/spec/controllers/alchemy/api/contents_controller_spec.rb +0 -125
  53. data/spec/controllers/alchemy/api/elements_controller_spec.rb +0 -124
  54. data/spec/controllers/alchemy/api/pages_controller_spec.rb +0 -167
  55. data/spec/controllers/alchemy/attachments_controller_spec.rb +0 -64
  56. data/spec/controllers/alchemy/base_controller_spec.rb +0 -106
  57. data/spec/controllers/alchemy/elements_controller_spec.rb +0 -48
  58. data/spec/controllers/alchemy/messages_controller_spec.rb +0 -204
  59. data/spec/controllers/alchemy/on_page_layout_mixin_spec.rb +0 -330
  60. data/spec/controllers/alchemy/pages_controller_spec.rb +0 -343
  61. data/spec/controllers/alchemy/pictures_controller_spec.rb +0 -415
  62. data/spec/dummy/Rakefile +0 -6
  63. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  64. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  65. data/spec/dummy/app/controllers/admin/events_controller.rb +0 -3
  66. data/spec/dummy/app/controllers/application_controller.rb +0 -15
  67. data/spec/dummy/app/controllers/login_controller.rb +0 -5
  68. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  69. data/spec/dummy/app/mailers/.gitkeep +0 -0
  70. data/spec/dummy/app/models/ability.rb +0 -9
  71. data/spec/dummy/app/models/dummy_model.rb +0 -3
  72. data/spec/dummy/app/models/dummy_user.rb +0 -15
  73. data/spec/dummy/app/models/event.rb +0 -10
  74. data/spec/dummy/app/models/location.rb +0 -3
  75. data/spec/dummy/app/views/alchemy/elements/_all_you_can_eat_editor.html.erb +0 -11
  76. data/spec/dummy/app/views/alchemy/elements/_all_you_can_eat_view.html.erb +0 -31
  77. data/spec/dummy/app/views/alchemy/elements/_article_editor.html.erb +0 -6
  78. data/spec/dummy/app/views/alchemy/elements/_article_view.html.erb +0 -10
  79. data/spec/dummy/app/views/alchemy/elements/_bild_editor.html.erb +0 -3
  80. data/spec/dummy/app/views/alchemy/elements/_bild_view.html.erb +0 -5
  81. data/spec/dummy/app/views/alchemy/elements/_contactform_editor.html.erb +0 -6
  82. data/spec/dummy/app/views/alchemy/elements/_contactform_view.html.erb +0 -16
  83. data/spec/dummy/app/views/alchemy/elements/_download_editor.html.erb +0 -3
  84. data/spec/dummy/app/views/alchemy/elements/_download_view.html.erb +0 -5
  85. data/spec/dummy/app/views/alchemy/elements/_erb_element_editor.html.erb +0 -3
  86. data/spec/dummy/app/views/alchemy/elements/_erb_element_view.html.erb +0 -5
  87. data/spec/dummy/app/views/alchemy/elements/_header_editor.html.erb +0 -3
  88. data/spec/dummy/app/views/alchemy/elements/_header_view.html.erb +0 -5
  89. data/spec/dummy/app/views/alchemy/elements/_headline_editor.html.erb +0 -1
  90. data/spec/dummy/app/views/alchemy/elements/_headline_view.html.erb +0 -1
  91. data/spec/dummy/app/views/alchemy/elements/_news_editor.html.erb +0 -5
  92. data/spec/dummy/app/views/alchemy/elements/_news_view.html.erb +0 -11
  93. data/spec/dummy/app/views/alchemy/elements/_search_editor.html.erb +0 -1
  94. data/spec/dummy/app/views/alchemy/elements/_search_view.html.erb +0 -4
  95. data/spec/dummy/app/views/alchemy/elements/_slide_editor.html.erb +0 -3
  96. data/spec/dummy/app/views/alchemy/elements/_slide_view.html.erb +0 -5
  97. data/spec/dummy/app/views/alchemy/elements/_slider_editor.html.erb +0 -2
  98. data/spec/dummy/app/views/alchemy/elements/_slider_view.html.erb +0 -4
  99. data/spec/dummy/app/views/alchemy/elements/_text_editor.html.erb +0 -3
  100. data/spec/dummy/app/views/alchemy/elements/_text_view.html.erb +0 -5
  101. data/spec/dummy/app/views/alchemy/page_layouts/_standard.html.erb +0 -15
  102. data/spec/dummy/app/views/layouts/application.html.erb +0 -17
  103. data/spec/dummy/bin/bundle +0 -3
  104. data/spec/dummy/bin/rails +0 -4
  105. data/spec/dummy/bin/rake +0 -4
  106. data/spec/dummy/config.ru +0 -4
  107. data/spec/dummy/config/alchemy/cells.yml +0 -5
  108. data/spec/dummy/config/alchemy/elements.yml +0 -109
  109. data/spec/dummy/config/alchemy/page_layouts.yml +0 -32
  110. data/spec/dummy/config/application.rb +0 -32
  111. data/spec/dummy/config/boot.rb +0 -5
  112. data/spec/dummy/config/database.yml +0 -32
  113. data/spec/dummy/config/environment.rb +0 -5
  114. data/spec/dummy/config/environments/development.rb +0 -41
  115. data/spec/dummy/config/environments/production.rb +0 -77
  116. data/spec/dummy/config/environments/test.rb +0 -43
  117. data/spec/dummy/config/initializers/alchemy.rb +0 -3
  118. data/spec/dummy/config/initializers/assets.rb +0 -11
  119. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  120. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
  121. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  122. data/spec/dummy/config/initializers/inflections.rb +0 -16
  123. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  124. data/spec/dummy/config/initializers/secret_token.rb +0 -12
  125. data/spec/dummy/config/initializers/session_store.rb +0 -3
  126. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  127. data/spec/dummy/config/locales/kl.yml +0 -2
  128. data/spec/dummy/config/routes.rb +0 -12
  129. data/spec/dummy/config/secrets.yml +0 -22
  130. data/spec/dummy/db/migrate/20121026104128_create_events.rb +0 -20
  131. data/spec/dummy/db/migrate/20130328101418_create_locations.rb +0 -9
  132. data/spec/dummy/db/migrate/20130827094554_alchemy_two_point_six.rb +0 -1
  133. data/spec/dummy/db/migrate/20130828121054_remove_do_not_index_from_alchemy_essence_texts.rb +0 -1
  134. data/spec/dummy/db/migrate/20130828121120_remove_do_not_index_from_alchemy_essence_richtexts.rb +0 -1
  135. data/spec/dummy/db/migrate/20130918201742_add_published_at_to_alchemy_pages.rb +0 -1
  136. data/spec/dummy/db/migrate/20131209225243_create_dummy_users.rb +0 -9
  137. data/spec/dummy/db/migrate/20150122213511_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb +0 -31
  138. data/spec/dummy/db/migrate/20150122213512_add_missing_unique_indices.acts_as_taggable_on_engine.rb +0 -20
  139. data/spec/dummy/db/migrate/20150122213513_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +0 -15
  140. data/spec/dummy/db/migrate/20150122213514_add_missing_taggable_index.acts_as_taggable_on_engine.rb +0 -10
  141. data/spec/dummy/db/migrate/20150412103152_create_dummy_model.rb +0 -7
  142. data/spec/dummy/db/migrate/20150608204610_add_parent_element_id_to_alchemy_elements.rb +0 -1
  143. data/spec/dummy/db/migrate/20150729151825_add_link_text_to_alchemy_essence_files.rb +0 -1
  144. data/spec/dummy/db/migrate/20150906195818_add_locale_to_alchemy_languages.rb +0 -1
  145. data/spec/dummy/db/schema.rb +0 -326
  146. data/spec/dummy/db/seeds.rb +0 -1
  147. data/spec/dummy/lib/assets/.gitkeep +0 -0
  148. data/spec/dummy/public/404.html +0 -67
  149. data/spec/dummy/public/422.html +0 -67
  150. data/spec/dummy/public/500.html +0 -66
  151. data/spec/dummy/public/favicon.ico +0 -0
  152. data/spec/dummy/spec/javascripts +0 -1
  153. data/spec/factories.rb +0 -13
  154. data/spec/features/admin/admin_layout_spec.rb +0 -14
  155. data/spec/features/admin/dashboard_spec.rb +0 -81
  156. data/spec/features/admin/edit_elements_feature_spec.rb +0 -36
  157. data/spec/features/admin/language_tree_feature_spec.rb +0 -32
  158. data/spec/features/admin/languages_features_spec.rb +0 -65
  159. data/spec/features/admin/legacy_page_url_management_spec.rb +0 -62
  160. data/spec/features/admin/link_overlay_spec.rb +0 -53
  161. data/spec/features/admin/locale_select_feature_spec.rb +0 -25
  162. data/spec/features/admin/modules_integration_spec.rb +0 -23
  163. data/spec/features/admin/navigation_feature_spec.rb +0 -22
  164. data/spec/features/admin/page_creation_feature_spec.rb +0 -51
  165. data/spec/features/admin/page_editing_feature_spec.rb +0 -135
  166. data/spec/features/admin/picture_library_integration_spec.rb +0 -62
  167. data/spec/features/admin/resources_integration_spec.rb +0 -128
  168. data/spec/features/admin/site_select_feature_spec.rb +0 -31
  169. data/spec/features/admin/tinymce_feature_spec.rb +0 -33
  170. data/spec/features/navigation_spec.rb +0 -9
  171. data/spec/features/page_feature_spec.rb +0 -186
  172. data/spec/features/page_redirects_spec.rb +0 -358
  173. data/spec/features/picture_security_spec.rb +0 -29
  174. data/spec/features/security_spec.rb +0 -24
  175. data/spec/features/translation_integration_spec.rb +0 -51
  176. data/spec/fixtures/500x500.png +0 -0
  177. data/spec/fixtures/80x60.png +0 -0
  178. data/spec/fixtures/animated.gif +0 -0
  179. data/spec/fixtures/image with spaces.png +0 -0
  180. data/spec/fixtures/image.png +0 -0
  181. data/spec/fixtures/image2.PNG +0 -0
  182. data/spec/fixtures/image3.jpeg +0 -0
  183. data/spec/helpers/alchemy/admin/attachments_helper_spec.rb +0 -15
  184. data/spec/helpers/alchemy/admin/base_helper_spec.rb +0 -280
  185. data/spec/helpers/alchemy/admin/contents_helper_spec.rb +0 -46
  186. data/spec/helpers/alchemy/admin/elements_helper_spec.rb +0 -314
  187. data/spec/helpers/alchemy/admin/essences_helper_spec.rb +0 -201
  188. data/spec/helpers/alchemy/admin/navigation_helper_spec.rb +0 -294
  189. data/spec/helpers/alchemy/admin/pages_helper_spec.rb +0 -63
  190. data/spec/helpers/alchemy/admin/pictures_helper_spec.rb +0 -28
  191. data/spec/helpers/alchemy/admin/tags_helper_spec.rb +0 -111
  192. data/spec/helpers/alchemy/base_helper_spec.rb +0 -44
  193. data/spec/helpers/alchemy/elements_block_helper_spec.rb +0 -135
  194. data/spec/helpers/alchemy/elements_helper_spec.rb +0 -326
  195. data/spec/helpers/alchemy/essences_helper_spec.rb +0 -85
  196. data/spec/helpers/alchemy/pages_helper_spec.rb +0 -499
  197. data/spec/helpers/alchemy/picture_url_helpers_spec.rb +0 -78
  198. data/spec/helpers/alchemy/url_helper_spec.rb +0 -200
  199. data/spec/javascripts/alchemy/dialog_spec.coffee +0 -82
  200. data/spec/javascripts/alchemy/link_overlay_spec.coffee +0 -25
  201. data/spec/javascripts/alchemy_integration_spec.coffee +0 -3
  202. data/spec/javascripts/fixtures/select.html +0 -3
  203. data/spec/javascripts/helpers/mock-ajax.js +0 -199
  204. data/spec/javascripts/helpers/test_responses/test_responses.js +0 -1
  205. data/spec/javascripts/support/jasmine.yml +0 -29
  206. data/spec/libraries/auth_accessors_spec.rb +0 -40
  207. data/spec/libraries/config_spec.rb +0 -111
  208. data/spec/libraries/controller_actions_spec.rb +0 -133
  209. data/spec/libraries/i18n_spec.rb +0 -37
  210. data/spec/libraries/kaminari/scoped_pagination_url_helper_spec.rb +0 -30
  211. data/spec/libraries/modules_spec.rb +0 -67
  212. data/spec/libraries/mount_point_spec.rb +0 -77
  213. data/spec/libraries/page_layout_spec.rb +0 -150
  214. data/spec/libraries/paths_spec.rb +0 -15
  215. data/spec/libraries/permissions_spec.rb +0 -260
  216. data/spec/libraries/resource_spec.rb +0 -344
  217. data/spec/libraries/resources_helper_spec.rb +0 -193
  218. data/spec/libraries/shell_spec.rb +0 -121
  219. data/spec/libraries/template_tracker_spec.rb +0 -85
  220. data/spec/libraries/tinymce_spec.rb +0 -111
  221. data/spec/libraries/userstamp_spec.rb +0 -10
  222. data/spec/mailers/alchemy/messages_spec.rb +0 -21
  223. data/spec/models/alchemy/attachment_spec.rb +0 -250
  224. data/spec/models/alchemy/cell_spec.rb +0 -101
  225. data/spec/models/alchemy/content_spec.rb +0 -513
  226. data/spec/models/alchemy/element_spec.rb +0 -862
  227. data/spec/models/alchemy/element_to_page_spec.rb +0 -13
  228. data/spec/models/alchemy/essence_boolean_spec.rb +0 -10
  229. data/spec/models/alchemy/essence_date_spec.rb +0 -28
  230. data/spec/models/alchemy/essence_file_spec.rb +0 -40
  231. data/spec/models/alchemy/essence_html_spec.rb +0 -18
  232. data/spec/models/alchemy/essence_link_spec.rb +0 -10
  233. data/spec/models/alchemy/essence_picture_spec.rb +0 -255
  234. data/spec/models/alchemy/essence_richtext_spec.rb +0 -23
  235. data/spec/models/alchemy/essence_select_spec.rb +0 -10
  236. data/spec/models/alchemy/essence_text_spec.rb +0 -110
  237. data/spec/models/alchemy/language_spec.rb +0 -243
  238. data/spec/models/alchemy/legacy_page_url_spec.rb +0 -21
  239. data/spec/models/alchemy/message_spec.rb +0 -55
  240. data/spec/models/alchemy/page_spec.rb +0 -2108
  241. data/spec/models/alchemy/picture_spec.rb +0 -418
  242. data/spec/models/alchemy/site_spec.rb +0 -168
  243. data/spec/models/alchemy/tag_spec.rb +0 -29
  244. data/spec/models/dummy_model_spec.rb +0 -10
  245. data/spec/requests/alchemy/admin/resources_requests_spec.rb +0 -26
  246. data/spec/requests/alchemy/admin/site_requests_spec.rb +0 -19
  247. data/spec/requests/alchemy/site_requests_spec.rb +0 -18
  248. data/spec/requests/alchemy/sitemap_spec.rb +0 -56
  249. data/spec/routing/api_routing_spec.rb +0 -150
  250. data/spec/routing/routing_spec.rb +0 -340
  251. data/spec/spec_helper.rb +0 -90
  252. data/spec/support/ci/install_phantomjs +0 -7
  253. data/spec/support/hint_examples.rb +0 -28
  254. data/spec/support/test_tweaks.rb +0 -31
  255. data/spec/support/transformation_examples.rb +0 -179
  256. data/spec/tasks/helpers_spec.rb +0 -217
  257. data/spec/views/admin/pictures/show_spec.rb +0 -43
  258. data/spec/views/essences/essence_boolean_editor_spec.rb +0 -32
  259. data/spec/views/essences/essence_boolean_view_spec.rb +0 -23
  260. data/spec/views/essences/essence_date_view_spec.rb +0 -38
  261. data/spec/views/essences/essence_file_editor_spec.rb +0 -59
  262. data/spec/views/essences/essence_file_view_spec.rb +0 -77
  263. data/spec/views/essences/essence_html_view_spec.rb +0 -22
  264. data/spec/views/essences/essence_link_view_spec.rb +0 -41
  265. data/spec/views/essences/essence_picture_editor_spec.rb +0 -80
  266. data/spec/views/essences/essence_picture_view_spec.rb +0 -128
  267. data/spec/views/essences/essence_richtext_view_spec.rb +0 -32
  268. data/spec/views/essences/essence_select_view_spec.rb +0 -11
  269. data/spec/views/essences/essence_text_view_spec.rb +0 -51
@@ -1,418 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- module Alchemy
5
- describe Picture do
6
- it_behaves_like "has image transformations" do
7
- let(:picture) { build_stubbed(:alchemy_picture) }
8
- end
9
-
10
- let :image_file do
11
- File.new(File.expand_path('../../../fixtures/image.png', __FILE__))
12
- end
13
-
14
- let(:picture) { Picture.new }
15
-
16
- it "is valid with valid attributes" do
17
- picture = Picture.new(image_file: image_file)
18
- expect(picture).to be_valid
19
- end
20
-
21
- it "is not valid without image file" do
22
- picture = Picture.new
23
- expect(picture).not_to be_valid
24
- end
25
-
26
- it "is valid with capitalized image file extension" do
27
- image_file = File.new(File.expand_path('../../../fixtures/image2.PNG', __FILE__))
28
- picture = Picture.new(image_file: image_file)
29
- expect(picture).to be_valid
30
- end
31
-
32
- it "is valid with jpeg image file extension" do
33
- image_file = File.new(File.expand_path('../../../fixtures/image3.jpeg', __FILE__))
34
- picture = Picture.new(image_file: image_file)
35
- expect(picture).to be_valid
36
- end
37
-
38
- context 'with enabled preprocess_image_resize config option' do
39
- let(:image_file) do
40
- File.new(File.expand_path('../../../fixtures/80x60.png', __FILE__))
41
- end
42
-
43
- context 'with > geometry string' do
44
- before do
45
- allow(Config).to receive(:get) do |arg|
46
- if arg == :preprocess_image_resize
47
- '10x10>'
48
- end
49
- end
50
- end
51
-
52
- it "it resizes the image after upload" do
53
- picture = Picture.new(image_file: image_file)
54
- expect(picture.image_file.data[0x10..0x18].unpack('NN')).to eq([10, 8])
55
- end
56
- end
57
-
58
- context 'without > geometry string' do
59
- before do
60
- allow(Config).to receive(:get) do |arg|
61
- if arg == :preprocess_image_resize
62
- '10x10'
63
- end
64
- end
65
- end
66
-
67
- it "it resizes the image after upload" do
68
- picture = Picture.new(image_file: image_file)
69
- expect(picture.image_file.data[0x10..0x18].unpack('NN')).to eq([10, 8])
70
- end
71
- end
72
- end
73
-
74
- describe '#suffix' do
75
- it "should return the suffix of original filename" do
76
- pic = stub_model(Picture, image_file_name: 'kitten.JPG')
77
- allow(pic).to receive(:image_file).and_return(OpenStruct.new({ext: 'jpg'}))
78
- expect(pic.suffix).to eq("jpg")
79
- end
80
-
81
- context "image has no suffix" do
82
- it "should return empty string" do
83
- pic = stub_model(Picture, image_file_name: 'kitten')
84
- allow(pic).to receive(:image_file).and_return(OpenStruct.new({ext: ''}))
85
- expect(pic.suffix).to eq("")
86
- end
87
- end
88
- end
89
-
90
- describe '#humanized_name' do
91
- it "should return a humanized version of original filename" do
92
- pic = stub_model(Picture, image_file_name: 'cute_kitten.JPG')
93
- allow(pic).to receive(:image_file).and_return(OpenStruct.new({ext: 'jpg'}))
94
- expect(pic.humanized_name).to eq("cute kitten")
95
- end
96
-
97
- it "should not remove incidents of suffix from filename" do
98
- pic = stub_model(Picture, image_file_name: 'cute_kitten_mo.jpgi.JPG')
99
- allow(pic).to receive(:image_file).and_return(OpenStruct.new({ext: 'jpg'}))
100
- expect(pic.humanized_name).to eq("cute kitten mo.jpgi")
101
- expect(pic.humanized_name).not_to eq("cute kitten moi")
102
- end
103
-
104
- context "image has no suffix" do
105
- it "should return humanized name" do
106
- pic = stub_model(Picture, image_file_name: 'cute_kitten')
107
- allow(pic).to receive(:suffix).and_return("")
108
- expect(pic.humanized_name).to eq("cute kitten")
109
- end
110
- end
111
- end
112
-
113
- describe '#security_token' do
114
- before { @pic = stub_model(Picture, id: 1) }
115
-
116
- it "should return a sha1 hash" do
117
- expect(@pic.security_token).to match(/\b([a-f0-9]{16})\b/)
118
- end
119
-
120
- it "should return a 16 chars long hash" do
121
- @pic.security_token.length == 16
122
- end
123
-
124
- it "should convert crop true value into string" do
125
- digest = PictureAttributes.secure({id: @pic.id, crop: 'crop'})
126
- expect(@pic.security_token(crop: true)).to eq(digest)
127
- end
128
-
129
- it "should always include picture id" do
130
- digest = PictureAttributes.secure({id: @pic.id})
131
- expect(@pic.security_token).to eq(digest)
132
- end
133
-
134
- it "should remove all not suitable options" do
135
- digest = PictureAttributes.secure({id: @pic.id})
136
- expect(@pic.security_token({foo: 'baz'})).to eq(digest)
137
- end
138
-
139
- it "should remove all option values that have nil values" do
140
- digest = PictureAttributes.secure({id: @pic.id})
141
- expect(@pic.security_token({crop: nil})).to eq(digest)
142
- end
143
- end
144
-
145
- describe ".search_by" do
146
- subject(:search_by) { Picture.search_by(params, query, per_page) }
147
-
148
- let(:pictures) { Picture.all }
149
- let(:params) { ActionController::Parameters.new }
150
- let(:query) { double(result: pictures) }
151
- let(:per_page) { nil }
152
-
153
- it 'orders the result by name' do
154
- expect(pictures).to receive(:order).with(:name)
155
- search_by
156
- end
157
-
158
- context "with per_page given" do
159
- let(:per_page) { 10 }
160
-
161
- context "without page parameter given" do
162
- it "paginates the records" do
163
- expect(pictures).to receive(:page).with(1).and_call_original
164
- search_by
165
- end
166
- end
167
-
168
- context "with page parameter given" do
169
- let(:params) do
170
- ActionController::Parameters.new(page: 2)
171
- end
172
-
173
- it "paginates the records" do
174
- expect(pictures).to receive(:page).with(2).and_call_original
175
- search_by
176
- end
177
- end
178
- end
179
-
180
- context "when params[:filter] is set" do
181
- let(:params) do
182
- ActionController::Parameters.new(filter: 'recent')
183
- end
184
-
185
- it "filters the pictures collection by the given filter string" do
186
- expect(pictures).to \
187
- receive(:filtered_by).with(params['filter']).and_call_original
188
- search_by
189
- end
190
- end
191
-
192
- context "when params[:tagged_with] is set" do
193
- let(:params) do
194
- ActionController::Parameters.new(tagged_with: 'kitten')
195
- end
196
-
197
- it "filters the records by tags" do
198
- expect(pictures).to \
199
- receive(:tagged_with).with(params['tagged_with']).and_call_original
200
- search_by
201
- end
202
- end
203
- end
204
-
205
- describe '.filtered_by' do
206
- let(:picture) { build_stubbed(:alchemy_picture) }
207
-
208
- context "with 'recent' as argument" do
209
- it 'should call the .recent scope' do
210
- expect(Picture).to receive(:recent).and_return(picture)
211
- expect(Picture.filtered_by('recent')).to eq(picture)
212
- end
213
- end
214
-
215
- context "with 'last_upload' as argument" do
216
- it 'should call the .last_upload scope' do
217
- expect(Picture).to receive(:last_upload).and_return(picture)
218
- expect(Picture.filtered_by('last_upload')).to eq(picture)
219
- end
220
- end
221
-
222
- context "with 'without_tag' as argument" do
223
- it 'should call the .without_tag scope' do
224
- expect(Picture).to receive(:without_tag).and_return(picture)
225
- expect(Picture.filtered_by('without_tag')).to eq(picture)
226
- end
227
- end
228
-
229
- context "with no argument" do
230
- it 'should return the scoped collection' do
231
- expect(Picture).to receive(:all).and_return(picture)
232
- expect(Picture.filtered_by('')).to eq(picture)
233
- end
234
- end
235
- end
236
-
237
- describe '.last_upload' do
238
- it "should return all pictures that have the same upload-hash as the most recent picture" do
239
- other_upload = Picture.create!(image_file: image_file, upload_hash: '456')
240
- same_upload = Picture.create!(image_file: image_file, upload_hash: '123')
241
- most_recent = Picture.create!(image_file: image_file, upload_hash: '123')
242
-
243
- expect(Picture.last_upload).to include(most_recent)
244
- expect(Picture.last_upload).to include(same_upload)
245
- expect(Picture.last_upload).not_to include(other_upload)
246
-
247
- [other_upload, same_upload, most_recent].each(&:destroy)
248
- end
249
- end
250
-
251
- describe '.recent' do
252
- before do
253
- now = Time.current
254
- @recent = Picture.create!(image_file: image_file)
255
- @old_picture = Picture.create!(image_file: image_file)
256
- @recent.update_column(:created_at, now - 23.hours)
257
- @old_picture.update_column(:created_at, now - 10.days)
258
- end
259
-
260
- it "should return all pictures that have been created in the last 24 hours" do
261
- expect(Picture.recent).to include(@recent)
262
- end
263
-
264
- it "should not return old pictures" do
265
- expect(Picture.recent).not_to include(@old_picture)
266
- end
267
- end
268
-
269
- describe '#destroy' do
270
- context "a picture that is assigned in an essence" do
271
- let(:essence_picture) { EssencePicture.create }
272
- let(:picture) { create :alchemy_picture }
273
-
274
- before do
275
- essence_picture.update_attributes(picture_id: picture.id)
276
- end
277
-
278
- it "should raise error message" do
279
- expect { picture.destroy }.to raise_error PictureInUseError
280
- end
281
- end
282
- end
283
-
284
- describe "#image_file_dimensions" do
285
- it "should return the width and height in the format of '1024x768'" do
286
- picture.image_file = image_file
287
- expect(picture.image_file_dimensions).to eq('1x1')
288
- end
289
- end
290
-
291
- describe '#update_name_and_tag_list!' do
292
- let(:picture) { Picture.new(image_file: image_file) }
293
-
294
- before { allow(picture).to receive(:save!).and_return(true) }
295
-
296
- it "updates tag_list" do
297
- expect(picture).to receive(:tag_list=).with('Foo')
298
- picture.update_name_and_tag_list!({pictures_tag_list: 'Foo'})
299
- end
300
-
301
- context 'name is present' do
302
- it "updates name" do
303
- expect(picture).to receive(:name=).with('Foo')
304
- picture.update_name_and_tag_list!({pictures_name: 'Foo'})
305
- end
306
- end
307
-
308
- context 'name is not present' do
309
- it "does not update name" do
310
- expect(picture).not_to receive(:name=).with('Foo')
311
- picture.update_name_and_tag_list!({pictures_name: ''})
312
- end
313
- end
314
- end
315
-
316
- describe '#urlname' do
317
- subject { picture.urlname }
318
-
319
- let(:picture) { build_stubbed(:alchemy_picture, name: 'Cute kittens.jpg') }
320
-
321
- it "returns a uri escaped name" do
322
- is_expected.to eq('Cute+kittens')
323
- end
324
-
325
- context 'with blank name' do
326
- let(:picture) { build_stubbed(:alchemy_picture, name: '') }
327
-
328
- it "returns generic name" do
329
- is_expected.to eq("image_#{picture.id}")
330
- end
331
- end
332
- end
333
-
334
- describe '#to_jq_upload' do
335
- subject { picture.to_jq_upload }
336
-
337
- let(:picture) { build_stubbed(:alchemy_picture, image_file_name: 'cute-kittens.jpg', image_file_size: 1024) }
338
-
339
- it "returns a hash containing data for jquery fileuploader" do
340
- is_expected.to be_an_instance_of(Hash)
341
- is_expected.to include(name: picture.image_file_name)
342
- is_expected.to include(size: picture.image_file_size)
343
- end
344
-
345
- context 'with error' do
346
- let(:picture) { build_stubbed(:alchemy_picture) }
347
-
348
- before do
349
- expect(picture).to receive(:errors).and_return({image_file: %w(stupid_cats)})
350
- end
351
-
352
- it "returns hash with error message" do
353
- is_expected.to be_an_instance_of(Hash)
354
- is_expected.to include(error: 'stupid_cats')
355
- end
356
- end
357
- end
358
-
359
- describe '#restricted?' do
360
- subject { picture.restricted? }
361
-
362
- let(:picture) { build_stubbed(:alchemy_picture) }
363
-
364
- context 'is assigned on pages' do
365
- context 'that are all restricted' do
366
- before do
367
- expect(picture).to receive(:pages).at_least(:once).and_return double(
368
- not_restricted: double(blank?: true),
369
- any?: true
370
- )
371
- end
372
-
373
- it { is_expected.to be_truthy }
374
- end
375
-
376
- context 'that are not all restricted' do
377
- before do
378
- expect(picture).to receive(:pages).at_least(:once).and_return double(
379
- not_restricted: double(blank?: false),
380
- any?: true
381
- )
382
- end
383
-
384
- it { is_expected.to be_falsey }
385
- end
386
- end
387
-
388
- context 'is not assigned on any page' do
389
- before do
390
- expect(picture).to receive(:pages).and_return double(any?: false)
391
- end
392
-
393
- it { is_expected.to be_falsey }
394
- end
395
- end
396
-
397
- context 'navigating records' do
398
- let!(:picture1) { create(:alchemy_picture, name: 'abc') }
399
- let!(:picture2) { create(:alchemy_picture, name: 'def') }
400
-
401
- describe "#previous" do
402
- subject { picture2.previous }
403
-
404
- it "returns the previous record by name" do
405
- is_expected.to eq(picture1)
406
- end
407
- end
408
-
409
- describe "#next" do
410
- subject { picture1.next }
411
-
412
- it "returns the next record by name" do
413
- is_expected.to eq(picture2)
414
- end
415
- end
416
- end
417
- end
418
- end
@@ -1,168 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Alchemy
4
- describe Site do
5
- let(:site) { create(:alchemy_site) }
6
- let(:another_site) { create(:alchemy_site, name: 'Another Site', host: 'another.com') }
7
-
8
- describe 'new instances' do
9
- subject { build(:alchemy_site, host: 'bla.com') }
10
-
11
- before { Site.current = subject }
12
-
13
- it 'should start out with no languages' do
14
- expect(subject.languages).to be_empty
15
- end
16
-
17
- context 'when being saved' do
18
- context 'when it has no languages yet' do
19
- it 'should automatically create a default language' do
20
- subject.save!
21
- expect(subject.languages.count).to eq(1)
22
- expect(subject.languages.first).to be_default
23
- end
24
- end
25
-
26
- context 'when it already has a language' do
27
- let(:language) { build(:alchemy_language, site: nil) }
28
- before { subject.languages << language }
29
-
30
- it 'should not create any additional languages' do
31
- expect(subject.languages).to eq([language])
32
-
33
- expect { subject.save! }.
34
- to_not change(subject, "languages")
35
- end
36
- end
37
- end
38
- end
39
-
40
- describe '.find_for_host' do
41
- # No need to create a default site, as it has already been added through the seeds.
42
- # But let's add some more:
43
- #
44
- let(:default_site) { Site.default }
45
- let!(:magiclabs_site) { create(:alchemy_site, host: 'www.magiclabs.de', aliases: 'magiclabs.de magiclabs.com www.magiclabs.com') }
46
-
47
- subject { Site.find_for_host(host) }
48
-
49
- context "when the request doesn't match anything" do
50
- let(:host) { 'oogabooga.com' }
51
- it { is_expected.to eq(default_site) }
52
- end
53
-
54
- context "when the request matches a site's host field" do
55
- let(:host) { 'www.magiclabs.de' }
56
- it { is_expected.to eq(magiclabs_site) }
57
- end
58
-
59
- context "when the request matches one of the site's aliases" do
60
- let(:host) { 'magiclabs.com' }
61
- it { is_expected.to eq(magiclabs_site) }
62
- end
63
-
64
- context "when the request matches the site's first alias" do
65
- let(:host) { 'magiclabs.de' }
66
- it { is_expected.to eq(magiclabs_site) }
67
- end
68
-
69
- context "when the request matches the site's last alias" do
70
- let(:host) { 'www.magiclabs.com' }
71
- it { is_expected.to eq(magiclabs_site) }
72
- end
73
-
74
- context "when the request host matches only part of a site's aliases" do
75
- let(:host) { 'labs.com' }
76
- it { is_expected.to eq(default_site) }
77
- end
78
- end
79
-
80
- describe '.current' do
81
- context 'when set to a site' do
82
- before { Site.current = site }
83
- specify "Language should be scoped to that site" do
84
- expect(Language.all.to_sql).to match(/alchemy_languages.+site_id.+#{site.id}/)
85
- end
86
- end
87
-
88
- context 'when set to nil' do
89
- before { Site.current = nil }
90
- specify "Language should not be scoped to a site" do
91
- expect(Language.all.to_sql).not_to match(/alchemy_languages.+site_id.+#{site.id}/)
92
- end
93
-
94
- it "should return default site" do
95
- expect(Site.current).not_to be_nil
96
- expect(Site.current).to eq(Site.default)
97
- end
98
- end
99
- end
100
-
101
- describe '.definitions' do
102
- # To prevent memoization across specs
103
- before { Site.instance_variable_set("@definitions", nil) }
104
-
105
- subject { Site.definitions }
106
-
107
- context "with file present" do
108
- let(:definitions) { [{'name' => 'lala'}] }
109
- before { expect(YAML).to receive(:load_file).and_return(definitions) }
110
- it { is_expected.to eq(definitions) }
111
- end
112
-
113
- context "with empty file" do
114
- before { expect(YAML).to receive(:load_file).and_return(false) }
115
- it { is_expected.to eq([]) }
116
- end
117
-
118
- context "with no file present" do
119
- it { is_expected.to eq([]) }
120
- end
121
- end
122
-
123
- describe '#current?' do
124
- subject { site.current? }
125
-
126
- context 'when Site.current is set to the same site' do
127
- before { Site.current = site }
128
- it { is_expected.to be_truthy }
129
- end
130
-
131
- context 'when Site.current is set to nil' do
132
- before { Site.current = nil }
133
- it { is_expected.to be_falsey }
134
- end
135
-
136
- context 'when Site.current is set to a different site' do
137
- before { Site.current = another_site }
138
- it { is_expected.to be_falsey }
139
- end
140
- end
141
-
142
- describe '#to_partial_path' do
143
- let(:site) { Site.new(name: 'My custom site') }
144
-
145
- it "returns the path to partial" do
146
- expect(site.to_partial_path).to eq("alchemy/site_layouts/my_custom_site")
147
- end
148
- end
149
-
150
- describe '#partial_name' do
151
- let(:site) { Site.new(name: 'My custom site') }
152
-
153
- it "returns the name for layout partial" do
154
- expect(site.partial_name).to eq("my_custom_site")
155
- end
156
- end
157
-
158
- describe '#definition' do
159
- let(:site) { Site.new(name: 'My custom site') }
160
- let(:definitions) { [{'name' => 'my_custom_site', 'page_layouts' => %w(standard)}] }
161
-
162
- it "returns layout definition from site_layouts.yml file" do
163
- allow(Site).to receive(:definitions).and_return(definitions)
164
- expect(site.definition).to eq(definitions.first)
165
- end
166
- end
167
- end
168
- end