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,101 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Alchemy
4
- describe Cell do
5
- let(:cell) { build(:alchemy_cell) }
6
-
7
- # class methods
8
-
9
- describe '.definitions' do
10
- it "should return an Array" do
11
- expect(Cell.definitions).to be_a(Array)
12
- end
13
-
14
- it "should allow erb generated definitions" do
15
- expect(Cell.definitions.collect { |d| d['name'] }).to include('erb_cell')
16
- end
17
- end
18
-
19
- describe '.definition_for' do
20
- subject { Cell.definition_for('right_column') }
21
-
22
- it "returns a definition for given name" do
23
- eq({'name' => 'right_column', 'elements' => %w(search)})
24
- end
25
- end
26
-
27
- describe '.all_definitions_for' do
28
- subject { Cell.all_definitions_for(%(right_column)) }
29
-
30
- it "returns definitions for given names" do
31
- eq([{'name' => 'right_column', 'elements' => %w(search)}])
32
- end
33
- end
34
-
35
- describe ".definitions_for_element" do
36
- before do
37
- allow(Cell).to receive(:definitions).and_return([
38
- {'name' => 'cell_1', 'elements' => ['target', 'other']},
39
- {'name' => 'cell_2', 'elements' => ['other', 'other']},
40
- {'name' => 'cell_3', 'elements' => ['other', 'target']}
41
- ])
42
- end
43
-
44
- it "should return all cell definitions that includes the given element name" do
45
- expect(Cell.definitions_for_element('target')).to eq([
46
- {'name' => 'cell_1', 'elements' => ['target', 'other']},
47
- {'name' => 'cell_3', 'elements' => ['other', 'target']}
48
- ])
49
- end
50
- end
51
-
52
- describe '.translated_label_for' do
53
- subject { Cell.translated_label_for('right_column') }
54
-
55
- it "returns a translated label" do
56
- eq('Right column')
57
- end
58
- end
59
-
60
- # instance methods
61
-
62
- describe "#available_elements" do
63
- context "without assigned elements" do
64
- it "should return an empty Array" do
65
- allow(cell).to receive(:definition).and_return({})
66
- expect(cell.available_elements).to eq([])
67
- end
68
- end
69
-
70
- context "with assigned elements" do
71
- it "should return an Array of element names" do
72
- allow(cell).to receive(:definition).and_return({'elements' => ['test_element', 'test_element_2']})
73
- expect(cell.available_elements).to eq(['test_element', 'test_element_2'])
74
- end
75
- end
76
- end
77
-
78
- describe "#definition" do
79
- context "without a definition for the expected cellname" do
80
- it "should return an empty Hash" do
81
- allow(Cell).to receive(:definition_for).and_return({})
82
- expect(cell.definition).to eq({})
83
- end
84
- end
85
-
86
- context "with a definition for the expected cellname found" do
87
- it "should return its definition Hash" do
88
- allow(Cell).to receive(:definition_for).and_return({'name' => 'test_cell', 'elements' => ['test_element', 'test_element_2']})
89
- expect(cell.definition).to eq({'name' => 'test_cell', 'elements' => ['test_element', 'test_element_2']})
90
- end
91
- end
92
- end
93
-
94
- describe "#name_for_label" do
95
- it "should call translated_label_for" do
96
- expect(Cell).to receive(:translated_label_for).with(cell.name)
97
- cell.name_for_label
98
- end
99
- end
100
- end
101
- end
@@ -1,513 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Alchemy
4
- describe Content do
5
- let(:element) { create(:alchemy_element, name: 'headline', create_contents_after_create: true) }
6
- let(:content) { element.contents.find_by(essence_type: 'Alchemy::EssenceText') }
7
-
8
- it "should return the ingredient from its essence" do
9
- content.essence.update_attributes(body: "Hello")
10
- expect(content.ingredient).to eq("Hello")
11
- end
12
-
13
- describe '.normalize_essence_type' do
14
- context "passing namespaced essence type" do
15
- it "should not add alchemy namespace" do
16
- expect(Content.normalize_essence_type('Alchemy::EssenceText')).to eq("Alchemy::EssenceText")
17
- end
18
- end
19
-
20
- context "passing not namespaced essence type" do
21
- it "should add alchemy namespace" do
22
- expect(Content.normalize_essence_type('EssenceText')).to eq("Alchemy::EssenceText")
23
- end
24
- end
25
-
26
- context "passing non-namespaced essence type for an existing non-namespaced essence" do
27
- it "should not add alchemy namespace" do
28
- expect(Content.normalize_essence_type('DummyModel')).to eq("DummyModel")
29
- end
30
- end
31
- end
32
-
33
- describe '#normalized_essence_type' do
34
- context "without namespace in essence_type column" do
35
- it "should return the namespaced essence type" do
36
- expect(Content.new(essence_type: 'EssenceText').normalized_essence_type).to eq('Alchemy::EssenceText')
37
- end
38
- end
39
-
40
- context "with namespace in essence_type column" do
41
- it "should return the namespaced essence type" do
42
- expect(Content.new(essence_type: 'Alchemy::EssenceText').normalized_essence_type).to eq('Alchemy::EssenceText')
43
- end
44
- end
45
- end
46
-
47
- describe '#update_essence' do
48
- subject { content.update_essence(params) }
49
-
50
- let(:element) { create(:alchemy_element, name: 'text', create_contents_after_create: true) }
51
- let(:content) { element.contents.first }
52
- let(:params) { {} }
53
-
54
- context 'with params given' do
55
- let(:params) { {body: 'Mikes Petshop'} }
56
- let(:essence) { content.essence }
57
-
58
- before do
59
- expect(essence).to receive(:content).at_least(:once).and_return content
60
- end
61
-
62
- it "updates the attributes of related essence and return true" do
63
- is_expected.to be_truthy
64
- expect(content.ingredient).to eq("Mikes Petshop")
65
- end
66
-
67
- it "updates timestamp after updating related essence" do
68
- expect(content).to receive(:touch)
69
- subject
70
- end
71
- end
72
-
73
- context 'with validations and without params given' do
74
- let(:element) { create(:alchemy_element, name: 'contactform', create_contents_after_create: true) }
75
-
76
- it "should add error messages if save fails and return false" do
77
- is_expected.to be_falsey
78
- expect(content.errors[:essence].size).to eq(1)
79
- end
80
- end
81
-
82
- context 'if essence is missing' do
83
- before do
84
- expect(content).to receive(:essence).and_return nil
85
- end
86
-
87
- it "should raise error" do
88
- expect { subject }.to raise_error(EssenceMissingError)
89
- end
90
- end
91
- end
92
-
93
- describe '.copy' do
94
- before(:each) do
95
- @element = create(:alchemy_element, name: 'text', create_contents_after_create: true)
96
- @content = @element.contents.first
97
- end
98
-
99
- it "should create a new record with all attributes of source except given differences" do
100
- copy = Content.copy(@content, {name: 'foobar', element_id: @element.id + 1})
101
- expect(copy.name).to eq('foobar')
102
- end
103
-
104
- it "should make a new record for essence of source" do
105
- copy = Content.copy(@content, {element_id: @element.id + 1})
106
- expect(copy.essence_id).not_to eq(@content.essence_id)
107
- end
108
-
109
- it "should copy source essence attributes" do
110
- copy = Content.copy(@content, {element_id: @element.id + 1})
111
- copy.essence.body == @content.essence.body
112
- end
113
- end
114
-
115
- describe '.build' do
116
- let(:element) { build_stubbed(:alchemy_element) }
117
-
118
- it "builds a new instance from elements.yml definition" do
119
- expect(Content.build(element, {name: 'headline'})).to be_instance_of(Content)
120
- end
121
- end
122
-
123
- describe '.content_definition' do
124
- let(:element) { build_stubbed(:alchemy_element) }
125
-
126
- context "with blank name key" do
127
- it "returns a essence hash build from essence type" do
128
- expect(Content).to receive(:content_definition_from_essence_type).with(element, 'EssenceText')
129
- Content.content_definition(element, essence_type: 'EssenceText')
130
- end
131
- end
132
-
133
- context "with name key present" do
134
- it "returns a essence hash from element" do
135
- expect(element).to receive(:content_definition_for).with('headline')
136
- Content.content_definition(element, name: 'headline')
137
- end
138
- end
139
- end
140
-
141
- describe '.content_definition_from_essence_type' do
142
- let(:element) { build_stubbed(:alchemy_element) }
143
-
144
- it "returns the definition hash from element" do
145
- expect(Content).to receive(:content_name_from_element_and_essence_type).with(element, 'EssenceText').and_return('Foo')
146
- expect(Content.content_definition_from_essence_type(element, 'EssenceText')).to eq({
147
- 'type' => 'EssenceText',
148
- 'name' => 'Foo'
149
- })
150
- end
151
- end
152
-
153
- describe '.content_name_from_element_and_essence_type' do
154
- let(:element) { build_stubbed(:alchemy_element) }
155
-
156
- it "returns a name from essence type and count of essences in element" do
157
- expect(Content.content_name_from_element_and_essence_type(element, 'EssenceText')).to eq("essence_text_1")
158
- end
159
- end
160
-
161
- describe '.create_from_scratch' do
162
- let(:element) { create(:alchemy_element, name: 'article') }
163
-
164
- it "builds the content" do
165
- expect(Content.create_from_scratch(element, name: 'headline')).to be_instance_of(Alchemy::Content)
166
- end
167
-
168
- it "creates the essence from name" do
169
- expect(Content.create_from_scratch(element, name: 'headline').essence).to_not be_nil
170
- end
171
-
172
- it "creates the essence from essence_type" do
173
- expect(Content.create_from_scratch(element, essence_type: 'EssenceText').essence).to_not be_nil
174
- end
175
-
176
- context "with default value present" do
177
- it "should have the ingredient column filled with default value." do
178
- allow_any_instance_of(Element).to receive(:content_definition_for) do
179
- {'name' => 'headline', 'type' => 'EssenceText', 'default' => 'Welcome'}
180
- end
181
- content = Content.create_from_scratch(element, name: 'headline')
182
- expect(content.ingredient).to eq("Welcome")
183
- end
184
- end
185
- end
186
-
187
- describe '#ingredient=' do
188
- let(:element) { create(:alchemy_element, name: 'headline') }
189
-
190
- it "should set the given value to the ingredient column of essence" do
191
- c = Content.create_from_scratch(element, name: 'headline')
192
- c.ingredient = "Welcome"
193
- expect(c.ingredient).to eq("Welcome")
194
- end
195
-
196
- context "no essence associated" do
197
- let(:element) { create(:alchemy_element, name: 'headline') }
198
-
199
- it "should raise error" do
200
- content = Content.create(element_id: element.id, name: 'headline')
201
- expect { content.ingredient = "Welcome" }.to raise_error(EssenceMissingError)
202
- end
203
- end
204
- end
205
-
206
- describe "#definitions" do
207
- context "without any definitions in elements.yml file" do
208
- before { allow(Element).to receive(:definitions).and_return([]) }
209
-
210
- it "should return an empty array" do
211
- expect(Content.definitions).to eq([])
212
- end
213
- end
214
- end
215
-
216
- describe "#dom_id" do
217
- let(:content) { build_stubbed(:alchemy_content) }
218
-
219
- it "returns a dom id string" do
220
- expect(content.dom_id).to eq("essence_text_#{content.id}")
221
- end
222
-
223
- context "without an essence" do
224
- before { expect(content).to receive(:essence).and_return nil }
225
-
226
- it "returns empty string" do
227
- expect(content.dom_id).to eq('')
228
- end
229
- end
230
- end
231
-
232
- describe "#essence_partial_name" do
233
- let(:content) { build_stubbed(:alchemy_content) }
234
-
235
- it "returns the essence#partial_name" do
236
- expect(content.essence).to receive(:partial_name)
237
- content.essence_partial_name
238
- end
239
-
240
- context "without an essence" do
241
- before { expect(content).to receive(:essence).and_return nil }
242
-
243
- it "returns empty string" do
244
- expect(content.essence_partial_name).to eq('')
245
- end
246
- end
247
- end
248
-
249
- describe '#preview_content?' do
250
- let(:content) { build_stubbed(:alchemy_content) }
251
-
252
- context 'not defined as preview content' do
253
- it "returns false" do
254
- expect(content.preview_content?).to be false
255
- end
256
- end
257
-
258
- context 'defined as preview content via take_me_for_preview' do
259
- before do
260
- expect(content).to receive(:definition).at_least(:once).and_return({
261
- 'take_me_for_preview' => true
262
- })
263
- end
264
-
265
- it "returns true" do
266
- ActiveSupport::Deprecation.silence do
267
- expect(content.preview_content?).to be true
268
- end
269
- end
270
-
271
- it "display deprecation warning" do
272
- expect(ActiveSupport::Deprecation).to receive(:warn)
273
- content.preview_content?
274
- end
275
- end
276
-
277
- context 'defined as preview content via as_element_title' do
278
- before do
279
- expect(content).to receive(:definition).at_least(:once).and_return({
280
- 'as_element_title' => true
281
- })
282
- end
283
-
284
- it "returns true" do
285
- expect(content.preview_content?).to be true
286
- end
287
- end
288
- end
289
-
290
- describe '#preview_text' do
291
- let(:essence) { mock_model(EssenceText, preview_text: 'Lorem') }
292
- let(:content) { c = Content.new; c.essence = essence; c }
293
-
294
- it "should return the essences preview_text" do
295
- expect(essence).to receive(:preview_text).with(30)
296
- content.preview_text
297
- end
298
- end
299
-
300
- describe '#has_tinymce?' do
301
- let(:element) { build_stubbed(:alchemy_element, name: 'article') }
302
- let(:content) { build_stubbed(:alchemy_content, name: 'text', element: element) }
303
-
304
- subject { content.has_tinymce? }
305
-
306
- it { is_expected.to eq(false) }
307
-
308
- context 'having custom tinymce config hash' do
309
- before do
310
- expect(content).to receive(:settings) do
311
- {tinymce: {toolbar: []}}
312
- end
313
- end
314
-
315
- it { is_expected.to eq(true) }
316
- end
317
-
318
- context 'having essence that has_tinymce? eq true' do
319
- before do
320
- expect(content.essence).to receive(:has_tinymce?) { true }
321
- end
322
-
323
- it { is_expected.to eq(true) }
324
- end
325
- end
326
-
327
- describe '#has_custom_tinymce_config?' do
328
- let(:element) { build_stubbed(:alchemy_element, name: 'article') }
329
- let(:content) { build_stubbed(:alchemy_content, name: 'text', element: element) }
330
-
331
- subject { content.has_custom_tinymce_config? }
332
-
333
- it { is_expected.to eq(false) }
334
-
335
- context 'having custom tinymce config hash' do
336
- before do
337
- expect(content).to receive(:settings) do
338
- {tinymce: {toolbar: []}}
339
- end
340
- end
341
-
342
- it { is_expected.to eq(true) }
343
- end
344
- end
345
-
346
- describe '#tinymce_class_name' do
347
- let(:element) { build_stubbed(:alchemy_element, name: 'article') }
348
- let(:content) { build_stubbed(:alchemy_content, name: 'text', element: element) }
349
-
350
- subject { content.tinymce_class_name }
351
-
352
- it { is_expected.to eq('has_tinymce') }
353
-
354
- context 'having custom tinymce config' do
355
- before do
356
- expect(content).to receive(:has_custom_tinymce_config?).and_return(true)
357
- end
358
-
359
- it 'returns name including element name' do
360
- is_expected.to eq('has_tinymce article_text')
361
- end
362
- end
363
- end
364
-
365
- describe '#form_field_name' do
366
- let(:content) { Content.new(id: 1) }
367
-
368
- it "returns a name value for form fields with ingredient as default" do
369
- expect(content.form_field_name).to eq('contents[1][ingredient]')
370
- end
371
-
372
- context 'with a essence column given' do
373
- it "returns a name value for form fields for that column" do
374
- expect(content.form_field_name(:link_title)).to eq('contents[1][link_title]')
375
- end
376
- end
377
- end
378
-
379
- describe '#form_field_id' do
380
- let(:content) { Content.new(id: 1) }
381
-
382
- it "returns a id value for form fields with ingredient as default" do
383
- expect(content.form_field_id).to eq('contents_1_ingredient')
384
- end
385
-
386
- context 'with a essence column given' do
387
- it "returns a id value for form fields for that column" do
388
- expect(content.form_field_id(:link_title)).to eq('contents_1_link_title')
389
- end
390
- end
391
- end
392
-
393
- it_behaves_like "having a hint" do
394
- let(:subject) { Content.new }
395
- end
396
-
397
- describe '#settings' do
398
- let(:element) { build_stubbed(:alchemy_element, name: 'article') }
399
- let(:content) { build_stubbed(:alchemy_content, name: 'headline', element: element) }
400
-
401
- it "returns the settings hash from definition" do
402
- expect(content.settings).to eq({linkable: true})
403
- end
404
-
405
- context 'if settings are not defined' do
406
- let(:content) { build_stubbed(:alchemy_content, name: 'intro', element: element) }
407
-
408
- it "returns empty hash" do
409
- expect(content.settings).to eq({})
410
- end
411
- end
412
- end
413
-
414
- describe '#settings_value' do
415
- let(:key) { :key }
416
- let(:settings) { Hash.new }
417
-
418
- subject { content.settings_value(key, options) }
419
-
420
- before do
421
- allow(content).to receive(:settings) { settings }
422
- end
423
-
424
- context 'with content having settings' do
425
- let(:settings) { {key: 'settings_value'} }
426
-
427
- context 'and empty options' do
428
- let(:options) { {} }
429
-
430
- it "returns the value for key from content settings" do
431
- expect(subject).to eq('settings_value')
432
- end
433
- end
434
-
435
- context 'and nil options' do
436
- let(:options) { nil }
437
-
438
- it "returns the value for key from content settings" do
439
- expect(subject).to eq('settings_value')
440
- end
441
- end
442
-
443
- context 'but same key present in options' do
444
- let(:options) { {key: 'options_value'} }
445
-
446
- it "returns the value for key from options" do
447
- expect(subject).to eq('options_value')
448
- end
449
- end
450
- end
451
-
452
- context 'with content having no settings' do
453
- let(:settings) { {} }
454
-
455
- context 'and empty options' do
456
- let(:options) { {} }
457
-
458
- it { expect(subject).to eq(nil) }
459
- end
460
-
461
- context 'but key present in options' do
462
- let(:options) { {key: 'options_value'} }
463
-
464
- it "returns the value for key from options" do
465
- expect(subject).to eq('options_value')
466
- end
467
- end
468
- end
469
-
470
- context 'with content having settings with string as key' do
471
- let(:settings) { {'key' => 'value_from_string_key'} }
472
- let(:options) { {} }
473
-
474
- it "returns value" do
475
- expect(subject).to eq('value_from_string_key')
476
- end
477
- end
478
-
479
- context 'with key passed as string' do
480
- let(:settings) { {key: 'value_from_symbol_key'} }
481
- let(:key) { 'key' }
482
- let(:options) { {} }
483
-
484
- it "returns value" do
485
- expect(subject).to eq('value_from_symbol_key')
486
- end
487
- end
488
- end
489
-
490
- context 'delegations' do
491
- let(:page) { create(:alchemy_page, :restricted) }
492
-
493
- it "delegates restricted? to page" do
494
- element.update!(page: page)
495
- expect(page.restricted?).to be true
496
- expect(content.page).to eq page
497
- expect(content.restricted?).to be true
498
- end
499
-
500
- it "delegates trashed? to element" do
501
- element.update!(position: nil)
502
- expect(element.trashed?).to be true
503
- expect(content.trashed?).to be true
504
- end
505
-
506
- it "delegates public? to element" do
507
- element.update!(public: false)
508
- expect(element.public?).to be false
509
- expect(content.public?).to be false
510
- end
511
- end
512
- end
513
- end