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,344 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class Party
4
- end
5
-
6
- module Namespace1
7
- module Namespace2
8
- class Party
9
- end
10
- end
11
- end
12
-
13
- module Namespace
14
- class Party
15
- end
16
- end
17
-
18
- module PartyEngine
19
- module Namespace
20
- class Party
21
- end
22
- end
23
- end
24
-
25
- module Alchemy
26
- describe Resource do
27
- # Alchemy's standard module definition. Only engine_name is relevant here
28
- let(:module_definition) do
29
- {
30
- "name" => "party_list",
31
- "engine_name" => "party_engine",
32
- "navigation" => {
33
- "name" => "modules.party_list",
34
- "controller" => "/admin/parties",
35
- "action" => "index",
36
- "image" => "/assets/party_list_module.png"
37
- }
38
- }
39
- end
40
-
41
- let(:columns) do
42
- [
43
- double(:column, {name: 'name', type: :string, array: false}),
44
- double(:column, {name: 'hidden_value', type: :string, array: false}),
45
- double(:column, {name: 'description', type: :string, array: false}),
46
- double(:column, {name: 'id', type: :integer, array: false}),
47
- double(:column, {name: 'starts_at', type: :datetime, array: false}),
48
- double(:column, {name: 'location_id', type: :integer, array: false}),
49
- double(:column, {name: 'organizer_id', type: :integer, array: false})
50
- ]
51
- end
52
-
53
- let(:resource) { Resource.new("admin/parties", module_definition) }
54
-
55
- before :each do
56
- # stubbing an ActiveRecord::ModelSchema...
57
- allow(Party).to receive(:columns).and_return columns
58
- end
59
-
60
- describe "#initialize" do
61
- it "sets an instance variable that holds the controller path" do
62
- resource = Resource.new("admin/parties")
63
- expect(resource.instance_variable_get(:@controller_path)).to eq("admin/parties")
64
- end
65
-
66
- context "when initialized with a module definition" do
67
- it "sets an instance variable that holds the module definition" do
68
- expect(resource.instance_variable_get(:@module_definition)).to eq(module_definition)
69
- end
70
- end
71
-
72
- context "when initialized with a custom model" do
73
- it "sets @model to custom model" do
74
- CustomParty = Class.new
75
- resource = Resource.new("admin/parties", nil, CustomParty)
76
- expect(resource.instance_variable_get(:@model)).to eq(CustomParty)
77
- end
78
- end
79
-
80
- context "when initialized without custom model" do
81
- it "guesses the model by the controller_path" do
82
- resource = Resource.new("admin/parties", nil, nil)
83
- expect(resource.instance_variable_get(:@model)).to eq(Party)
84
- end
85
- end
86
-
87
- context "when model has alchemy_resource_relations defined" do
88
- before do
89
- allow(Party).to receive(:alchemy_resource_relations) do
90
- {location: {attr_method: 'name', type: 'string'}}
91
- end
92
- end
93
-
94
- context ", but not an ActiveRecord association" do
95
- before do
96
- allow(Party).to receive(:respond_to?) do |arg|
97
- case arg
98
- when :reflect_on_all_associations
99
- then false
100
- when :alchemy_resource_relations
101
- then true
102
- end
103
- end
104
- end
105
-
106
- it "should raise error." do
107
- expect { Resource.new("admin/parties") }.to raise_error(MissingActiveRecordAssociation)
108
- end
109
- end
110
- end
111
- end
112
-
113
- describe "#resource_array" do
114
- it "splits the controller_path and returns it as array." do
115
- resource = Resource.new("namespace1/namespace2/parties")
116
- expect(resource.resource_array).to eql(%w(namespace1 namespace2 parties))
117
- end
118
-
119
- it "deletes 'admin' if found hence our model isn't in the admin-namespace by convention" do
120
- expect(resource.resource_array).to eql(%w(parties))
121
- end
122
- end
123
-
124
- describe "#model" do
125
- it "returns the @model instance variable" do
126
- expect(resource.model).to eq(resource.instance_variable_get(:@model))
127
- end
128
- end
129
-
130
- describe "#resources_name" do
131
- it "returns plural name (like parties for model Party)" do
132
- expect(resource.resources_name).to eq("parties")
133
- end
134
- end
135
-
136
- describe "#resource_name" do
137
- it "returns the resources name as singular" do
138
- expect(resource.resource_name).to eq("party")
139
- end
140
- end
141
-
142
- describe "#namespaced_resource_name" do
143
- it "returns resource_name with namespace (namespace_party for Namespace::Party), i.e. for use in forms" do
144
- namespaced_resource = Resource.new("admin/namespace/parties")
145
- expect(namespaced_resource.namespaced_resource_name).to eq('namespace_party')
146
- end
147
-
148
- it "equals resource_name if resource not namespaced" do
149
- namespaced_resource = Resource.new("admin/parties")
150
- expect(namespaced_resource.namespaced_resource_name).to eq('party')
151
- end
152
-
153
- it "doesn't include the engine's name" do
154
- namespaced_resource = Resource.new("admin/party_engine/namespace/parties", module_definition)
155
- expect(namespaced_resource.namespaced_resource_name).to eq('namespace_party')
156
- end
157
- end
158
-
159
- describe "#engine_name" do
160
- it "should return the engine name of the module" do
161
- resource = Resource.new("admin/party_engine/namespace/parties", module_definition)
162
- expect(resource.engine_name).to eq("party_engine")
163
- end
164
- end
165
-
166
- describe "#namespace_for_scope" do
167
- it "returns a scope for use in url_for based path helpers" do
168
- expect(resource.namespace_for_scope).to eq(%w(admin))
169
- end
170
- end
171
-
172
- describe "#attributes" do
173
- subject { resource.attributes }
174
-
175
- it "parses and returns the resource model's attributes from ActiveRecord::ModelSchema" do
176
- expect(subject).to eq([
177
- {name: "name", type: :string},
178
- {name: "hidden_value", type: :string},
179
- {name: "description", type: :string},
180
- {name: "starts_at", type: :datetime},
181
- {name: "location_id", type: :integer},
182
- {name: "organizer_id", type: :integer}
183
- ])
184
- end
185
-
186
- it "skips the standard database attributes (rails defaults)" do
187
- expect(subject.map { |el| el[:name] }).not_to include(%w(id updated_at created_at creator_id updater_id))
188
- end
189
-
190
- it "skips attributes returned by skipped_alchemy_resource_attributes" do
191
- allow(Party).to receive(:skipped_alchemy_resource_attributes) { %w(hidden_value) }
192
- expect(subject).to include({name: "id", type: :integer})
193
- expect(subject).not_to include({name: "hidden_value", type: :string})
194
- end
195
-
196
- context "when resource_relations are not defined" do
197
- it "includes the attribute" do
198
- expect(subject.detect { |a| a[:name] == "location_id" }).to eq({name: "location_id", type: :integer})
199
- end
200
- end
201
-
202
- context "with restricted attributes set" do
203
- before do
204
- allow(Party).to receive(:restricted_alchemy_resource_attributes) do
205
- [{name: "name", type: :string}]
206
- end
207
- end
208
-
209
- it "should include the restricted attributes" do
210
- expect(subject).to include(name: "name", type: :string)
211
- end
212
- end
213
- end
214
-
215
- context "when `skipped_alchemy_resource_attributes` is defined as class method in the model" do
216
- let(:custom_skipped_attributes) { %w(hidden_name) }
217
-
218
- before do
219
- allow(Party).to receive(:skipped_alchemy_resource_attributes) do
220
- custom_skipped_attributes
221
- end
222
- end
223
-
224
- describe '#attributes' do
225
- it "does not return the attributes returned by that method" do
226
- expect(resource.attributes.detect { |a| a[:name] == 'hidden_name' }).to be_nil
227
- expect(resource.attributes.detect { |a| a[:name] == 'name' }).not_to be_nil
228
- end
229
- end
230
- end
231
-
232
- describe "#searchable_attributes" do
233
- subject { resource.searchable_attributes }
234
-
235
- it "returns all attributes of type string" do
236
- is_expected.to eq([
237
- {name: "name", type: :string},
238
- {name: "hidden_value", type: :string},
239
- {name: "description", type: :string}
240
- ])
241
- end
242
-
243
- context "with an array attribute" do
244
- let(:columns) do
245
- [
246
- double(:column, {name: 'name', type: :string, array: false}),
247
- double(:column, {name: 'languages', type: :string, array: true})
248
- ]
249
- end
250
-
251
- it "does not include this column" do
252
- is_expected.to eq([{name: "name", type: :string}])
253
- end
254
- end
255
- end
256
-
257
- describe "#editable_attributes" do
258
- subject { resource.editable_attributes }
259
-
260
- let(:columns) do
261
- [
262
- double(:column, {name: 'name', type: :string}),
263
- double(:column, {name: 'title', type: :string}),
264
- double(:column, {name: 'synced_at', type: :datetime}),
265
- double(:column, {name: 'remote_record_id', type: :string})
266
- ]
267
- end
268
-
269
- before do
270
- allow(Party).to receive(:restricted_alchemy_resource_attributes) do
271
- [:synced_at, :remote_record_id]
272
- end
273
- end
274
-
275
- it "does not contain restricted attributes" do
276
- is_expected.to eq([{name: "name", type: :string}, {name: "title", type: :string}])
277
- end
278
- end
279
-
280
- context "when alchemy_resource_relations defined as class method in the model" do
281
- let(:resource) { Resource.new("admin/events") }
282
-
283
- before do
284
- allow(Event).to receive(:alchemy_resource_relations) do
285
- {
286
- location: {attr_method: "name", attr_type: :string}
287
- }
288
- end
289
- end
290
-
291
- describe '#resource_relations' do
292
- it "should contain model_association from ActiveRecord::Reflections" do
293
- relation = resource.resource_relations[:location_id]
294
- expect(relation.keys).to include(:model_association)
295
- expect(relation[:model_association].class).to be(ActiveRecord::Reflection::BelongsToReflection)
296
- end
297
-
298
- it "adds '_id' to relation key" do
299
- expect(resource.resource_relations[:location_id]).not_to be_nil
300
- end
301
-
302
- it "stores the relation name" do
303
- relation = resource.resource_relations[:location_id]
304
- expect(relation.keys).to include(:name)
305
- expect(relation[:name]).to eq('location')
306
- end
307
- end
308
-
309
- describe '#model_associations' do
310
- it "skip default alchemy model associations" do
311
- expect(resource.model_associations.collect(&:name)).not_to include(*resource.class.const_get(:DEFAULT_SKIPPED_ASSOCIATIONS).map(&:to_sym))
312
- end
313
- end
314
-
315
- describe '#model_association_names' do
316
- it 'returns an array of association names' do
317
- expect(resource.model_association_names).to eq [:location]
318
- end
319
- end
320
-
321
- describe '#attributes' do
322
- it "contains the attribute of the related model" do
323
- expect(resource.attributes.detect { |a| a[:name] == 'location_id' }.keys).to include(:relation)
324
- end
325
-
326
- it "contains the related model's column type as type" do
327
- expect(resource.attributes.detect { |a| a[:name] == "location_id" }[:type]).to eq(:string)
328
- end
329
- end
330
- end
331
-
332
- describe "#engine_name" do
333
- it "should return the engine name of the module" do
334
- expect(resource.engine_name).to eq("party_engine")
335
- end
336
- end
337
-
338
- describe "#in_engine?" do
339
- it "should return true if the module is shipped within an engine" do
340
- expect(resource.in_engine?).to eq(true)
341
- end
342
- end
343
- end
344
- end
@@ -1,193 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../lib/alchemy/resource"
2
- require File.dirname(__FILE__) + "/../../lib/alchemy/resources_helper"
3
-
4
- module Namespace
5
- class MyResource
6
- end
7
- end
8
-
9
- module EngineResource
10
- end
11
-
12
- class ResourcesController
13
- include Alchemy::ResourcesHelper
14
-
15
- def resource_handler
16
- @resource_handler ||= Alchemy::Resource.new('admin/namespace/my_resources')
17
- end
18
- end
19
-
20
- class ResourcesControllerForEngine
21
- include Alchemy::ResourcesHelper
22
-
23
- def resource_handler
24
- @resource_handler ||= Alchemy::Resource.new('admin/engine_resources', {'engine_name' => 'my_engine'})
25
- end
26
- end
27
-
28
- describe Alchemy::ResourcesHelper do
29
- let(:controller) { ResourcesController.new }
30
- let(:resource_item) { double('resource-item') }
31
-
32
- before {
33
- allow(controller).to receive(:main_app).and_return 'main_app_proxy'
34
- controller.instance_variable_set('@my_resource', resource_item)
35
- controller.instance_variable_set('@my_resources', [resource_item])
36
- }
37
-
38
- describe "path-helpers" do
39
- describe "#resource_url_proxy" do
40
- it "returns the current proxy for url-helper-methods" do
41
- expect(controller.resource_url_proxy).to eq('main_app_proxy')
42
- end
43
-
44
- context "when resource is in engine" do
45
- let(:controller_for_engine) { ResourcesControllerForEngine.new }
46
- before { allow(controller_for_engine).to receive('my_engine').and_return('my_engine_proxy') }
47
-
48
- it "returns the engine's proxy" do
49
- expect(controller_for_engine.resource_url_proxy).to eq('my_engine_proxy')
50
- end
51
- end
52
- end
53
-
54
- describe "#resource_scope" do
55
- it "returns an array containing a proxy and namespaces for url_for-based helper-methods" do
56
- expect(controller.resource_scope).to eq(%w[main_app_proxy admin])
57
- end
58
- end
59
-
60
- describe "#resource_path" do
61
- it "invokes polymorphic-path with correct scope and object" do
62
- my_resource_item = double
63
- expect(controller).to receive(:polymorphic_path).with(["main_app_proxy", "admin", my_resource_item], {})
64
- controller.resource_path(my_resource_item)
65
- end
66
-
67
- it "uses resource_name when no object is given" do
68
- expect(controller).to receive(:polymorphic_path).with(["main_app_proxy", "admin", "my_resource"], {})
69
- controller.resource_path
70
- end
71
- end
72
-
73
- describe "#resources_path" do
74
- it "invokes polymorphic-path with correct scope and resources_name" do
75
- expect(controller).to receive(:polymorphic_path).with(["main_app_proxy", "admin", "my_resources"], {})
76
- controller.resources_path
77
- end
78
- end
79
-
80
- describe "#new_resource_path" do
81
- it "invokes new_polymorphic_path with correct scope and resource_name" do
82
- expect(controller).to receive(:new_polymorphic_path).with(["main_app_proxy", "admin", "my_resource"], {})
83
- controller.new_resource_path
84
- end
85
- end
86
-
87
- describe "#edit_resource_path" do
88
- it "invokes edit_polymorphic_path with correct scope and resource_name" do
89
- my_resource_item = double
90
- expect(controller).to receive(:edit_polymorphic_path).with(["main_app_proxy", "admin", my_resource_item], {})
91
- controller.edit_resource_path(my_resource_item)
92
- end
93
- end
94
- end
95
-
96
- describe "#resource_instance_variable" do
97
- it "returns the resource_item" do
98
- expect(controller.resource_instance_variable).to eq(resource_item)
99
- end
100
- end
101
-
102
- describe "#resources_instance_variable" do
103
- it "returns a collection of resource_items" do
104
- expect(controller.resources_instance_variable).to eq([resource_item])
105
- end
106
- end
107
-
108
- describe "#resource_window_size" do
109
- it "returns overlay size string depending on resource attributes length" do
110
- allow(controller).to receive(:resource_handler).and_return double(attributes: double(length: 4))
111
- expect(controller.resource_window_size).to eq("420x260")
112
- end
113
- end
114
-
115
- describe "#render_attribute" do
116
- subject { controller.render_attribute(resource_item, attributes, options) }
117
-
118
- let(:options) { {} }
119
- let(:attributes) { {name: 'name'} }
120
-
121
- it "should return the value from resource attribute" do
122
- allow(resource_item).to receive(:name).and_return('my-name')
123
- is_expected.to eq('my-name')
124
- end
125
-
126
- context "resource having a relation" do
127
- let(:associated_object) { double("location", title: 'Title of related object') }
128
- let(:associated_klass) { double("klass", find: associated_object) }
129
- let(:relation) do
130
- {
131
- attr_method: 'title',
132
- model_association: OpenStruct.new(klass: associated_klass)
133
- }
134
- end
135
- let(:attributes) do
136
- {name: 'name', relation: relation}
137
- end
138
-
139
- it "should return the value from the related object attribute" do
140
- allow(resource_item).to receive(:name).and_return('my-name')
141
- is_expected.to eq('Title of related object')
142
- end
143
- end
144
-
145
- context 'with long values' do
146
- before do
147
- allow(resource_item).to receive(:name).and_return('*' * 51)
148
- end
149
-
150
- it 'truncates the values' do
151
- expect(subject.length).to eq(50)
152
- end
153
-
154
- context 'but with options[:truncate] set to 10' do
155
- let(:options) { {truncate: 10} }
156
-
157
- it 'does not truncate the values' do
158
- expect(subject.length).to eq(10)
159
- end
160
- end
161
-
162
- context 'but with options[:truncate] set to false' do
163
- let(:options) { {truncate: false} }
164
-
165
- it 'does not truncate the values' do
166
- expect(subject.length).to eq(51)
167
- end
168
- end
169
- end
170
- end
171
-
172
- describe "#resource_name" do
173
- it "returns resource_handler.resource_name" do
174
- expect(controller.resource_name).to eq("my_resource")
175
- end
176
- end
177
-
178
- describe '#current_location_params' do
179
- let(:params) { {q: "some_query", page: 6, action: "some_action"} }
180
-
181
- before do
182
- allow(controller).to receive(:params) { params }
183
- end
184
-
185
- it 'returns the current location params' do
186
- expect(controller.current_location_params).to eq({q: "some_query", page: 6})
187
- end
188
-
189
- it 'only includes the q and page parameters' do
190
- expect(controller.current_location_params).not_to have_key(:action)
191
- end
192
- end
193
- end