alchemy_cms 2.2.4 → 2.3.rc5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. data/.gitignore +1 -1
  2. data/.travis.yml +3 -4
  3. data/Gemfile +1 -0
  4. data/README.md +10 -6
  5. data/alchemy_cms.gemspec +5 -2
  6. data/app/assets/images/alchemy/icons.png +0 -0
  7. data/app/assets/images/sassy-ie-overlay.png +0 -0
  8. data/app/assets/javascripts/alchemy/alchemy.base.js +50 -59
  9. data/app/assets/javascripts/alchemy/alchemy.buttons.js +14 -4
  10. data/app/assets/javascripts/alchemy/alchemy.datepicker.js +8 -2
  11. data/app/assets/javascripts/alchemy/alchemy.elements_window.js +11 -3
  12. data/app/assets/javascripts/alchemy/alchemy.gui.js.coffee +1 -1
  13. data/app/assets/javascripts/alchemy/alchemy.link_overlay.js.coffee +14 -1
  14. data/app/assets/javascripts/alchemy/alchemy.preview.js +1 -1
  15. data/app/assets/javascripts/alchemy/alchemy.preview_window.js +12 -4
  16. data/app/assets/javascripts/alchemy/alchemy.uploader.js +4 -1
  17. data/app/assets/javascripts/alchemy/alchemy.windows.js +18 -8
  18. data/app/assets/stylesheets/alchemy/_defaults.scss +84 -120
  19. data/app/assets/stylesheets/alchemy/alchemy.css +2 -2
  20. data/app/assets/stylesheets/alchemy/archive.css.scss +288 -0
  21. data/app/assets/stylesheets/alchemy/base.css.scss +95 -390
  22. data/app/assets/stylesheets/alchemy/dashboard.css.scss +4 -4
  23. data/app/assets/stylesheets/alchemy/elements.css.scss +83 -118
  24. data/app/assets/stylesheets/alchemy/flash.css.scss +1 -1
  25. data/app/assets/stylesheets/alchemy/form_elements.css.scss +528 -0
  26. data/app/assets/stylesheets/alchemy/frame.css.scss +13 -39
  27. data/app/assets/stylesheets/alchemy/icons.css.scss +217 -228
  28. data/app/assets/stylesheets/alchemy/jquery-ui.alchemy.css.scss +48 -50
  29. data/app/assets/stylesheets/alchemy/jquery.Jcrop.css.scss +1 -1
  30. data/app/assets/stylesheets/alchemy/login.css.scss +1 -5
  31. data/app/assets/stylesheets/alchemy/menubar.css.scss +19 -29
  32. data/app/assets/stylesheets/alchemy/pagination.css.scss +3 -4
  33. data/app/assets/stylesheets/alchemy/sitemap.css.scss +81 -81
  34. data/app/assets/stylesheets/alchemy/tables.css.scss +63 -57
  35. data/app/assets/stylesheets/alchemy/tinymce_dialog.css.scss +57 -57
  36. data/app/assets/stylesheets/alchemy/upload.css.scss +6 -6
  37. data/app/assets/stylesheets/tiny_mce/plugins/inlinepopups/skins/alchemy/window.css.scss +6 -10
  38. data/app/controllers/alchemy/admin/attachments_controller.rb +5 -4
  39. data/app/controllers/alchemy/admin/base_controller.rb +1 -9
  40. data/app/controllers/alchemy/admin/contents_controller.rb +4 -6
  41. data/app/controllers/alchemy/admin/elements_controller.rb +2 -2
  42. data/app/controllers/alchemy/admin/pages_controller.rb +2 -2
  43. data/app/controllers/alchemy/admin/pictures_controller.rb +74 -15
  44. data/app/controllers/alchemy/attachments_controller.rb +8 -2
  45. data/app/controllers/alchemy/base_controller.rb +47 -5
  46. data/app/controllers/alchemy/elements_controller.rb +1 -1
  47. data/app/controllers/alchemy/messages_controller.rb +12 -12
  48. data/app/controllers/alchemy/pages_controller.rb +5 -1
  49. data/app/controllers/alchemy/pictures_controller.rb +9 -4
  50. data/app/controllers/alchemy/user_sessions_controller.rb +2 -4
  51. data/app/helpers/alchemy/admin/base_helper.rb +98 -19
  52. data/app/helpers/alchemy/admin/contents_helper.rb +2 -2
  53. data/app/helpers/alchemy/admin/elements_helper.rb +2 -3
  54. data/app/helpers/alchemy/base_helper.rb +6 -5
  55. data/app/helpers/alchemy/elements_helper.rb +2 -2
  56. data/app/helpers/alchemy/essences_helper.rb +4 -5
  57. data/app/helpers/alchemy/pages_helper.rb +15 -79
  58. data/app/helpers/alchemy/url_helper.rb +67 -0
  59. data/app/mailers/alchemy/messages.rb +1 -1
  60. data/app/mailers/alchemy/notifications.rb +1 -1
  61. data/app/models/alchemy/attachment.rb +11 -2
  62. data/app/models/alchemy/cell.rb +20 -10
  63. data/app/models/alchemy/content.rb +4 -3
  64. data/app/models/alchemy/element.rb +170 -178
  65. data/app/models/alchemy/language/code.rb +4 -1
  66. data/app/models/alchemy/message.rb +19 -3
  67. data/app/models/alchemy/page.rb +45 -40
  68. data/app/models/alchemy/picture.rb +24 -2
  69. data/app/models/alchemy/user.rb +2 -3
  70. data/app/views/alchemy/admin/attachments/_archive_overlay.html.erb +12 -12
  71. data/app/views/alchemy/admin/attachments/_attachment.html.erb +1 -1
  72. data/app/views/alchemy/admin/attachments/create.js.erb +1 -0
  73. data/app/views/alchemy/admin/attachments/edit.html.erb +9 -3
  74. data/app/views/alchemy/admin/attachments/index.html.erb +3 -2
  75. data/app/views/alchemy/admin/contents/_missing.html.erb +1 -1
  76. data/app/views/alchemy/admin/contents/create.js.erb +54 -0
  77. data/app/views/alchemy/admin/contents/new.html.erb +9 -4
  78. data/app/views/alchemy/admin/elements/{_add_content.html.erb → _add_picture.html.erb} +4 -4
  79. data/app/views/alchemy/admin/elements/_elements_select.html.erb +2 -1
  80. data/app/views/alchemy/admin/elements/_new_element_form.html.erb +1 -1
  81. data/app/views/alchemy/admin/elements/{_picture_editor.html.erb → _picture_gallery_editor.html.erb} +7 -11
  82. data/app/views/alchemy/admin/elements/fold.js.erb +46 -0
  83. data/app/views/alchemy/admin/elements/index.html.erb +24 -24
  84. data/app/views/alchemy/admin/elements/list.js.erb +11 -9
  85. data/app/views/alchemy/admin/essence_files/assign.js.erb +3 -1
  86. data/app/views/alchemy/admin/essence_pictures/destroy.js.erb +28 -0
  87. data/app/views/alchemy/admin/pages/_contactform_links.html.erb +8 -6
  88. data/app/views/alchemy/admin/pages/_external_link.html.erb +11 -9
  89. data/app/views/alchemy/admin/pages/_file_link.html.erb +10 -8
  90. data/app/views/alchemy/admin/pages/_internal_link.html.erb +14 -10
  91. data/app/views/alchemy/admin/pages/_new_page_form.html.erb +1 -1
  92. data/app/views/alchemy/admin/pages/_page.html.erb +1 -1
  93. data/app/views/alchemy/admin/pages/_page_for_links.html.erb +32 -21
  94. data/app/views/alchemy/admin/pages/configure.html.erb +2 -2
  95. data/app/views/alchemy/admin/pages/configure_external.html.erb +13 -13
  96. data/app/views/alchemy/admin/pages/edit.html.erb +2 -2
  97. data/app/views/alchemy/admin/pages/index.html.erb +26 -24
  98. data/app/views/alchemy/admin/pages/link.html.erb +2 -5
  99. data/app/views/alchemy/admin/partials/_upload_form.html.erb +28 -12
  100. data/app/views/alchemy/admin/pictures/_archive.html.erb +54 -0
  101. data/app/views/alchemy/admin/pictures/_archive_overlay.html.erb +10 -7
  102. data/app/views/alchemy/admin/pictures/_filter_and_size_bar.html.erb +21 -22
  103. data/app/views/alchemy/admin/pictures/_filter_bar.html.erb +31 -0
  104. data/app/views/alchemy/admin/pictures/_overlay_picture_list.html.erb +9 -0
  105. data/app/views/alchemy/admin/pictures/_picture.html.erb +36 -6
  106. data/app/views/alchemy/admin/pictures/_tag_list.html.erb +27 -0
  107. data/app/views/alchemy/admin/pictures/archive_overlay.js.erb +3 -1
  108. data/app/views/alchemy/admin/pictures/create.js.erb +4 -5
  109. data/app/views/alchemy/admin/pictures/edit.html.erb +26 -0
  110. data/app/views/alchemy/admin/pictures/edit_multiple.html.erb +39 -0
  111. data/app/views/alchemy/admin/pictures/index.html.erb +81 -70
  112. data/app/views/alchemy/admin/pictures/index.js.erb +3 -0
  113. data/app/views/alchemy/admin/pictures/new.html.erb +1 -0
  114. data/app/views/alchemy/admin/resources/index.html.erb +3 -1
  115. data/app/views/alchemy/admin/users/_table.html.erb +1 -1
  116. data/app/views/alchemy/admin/users/index.html.erb +27 -23
  117. data/app/views/alchemy/elements/_article_editor.html.erb +7 -2
  118. data/app/views/alchemy/elements/_bild_editor.html.erb +1 -1
  119. data/app/views/alchemy/elements/_bild_text_editor.html.erb +6 -1
  120. data/app/views/alchemy/elements/_bild_text_view.html.erb +3 -3
  121. data/app/views/alchemy/elements/_image_mosaic_editor.html.erb +1 -1
  122. data/app/views/alchemy/elements/_image_mosaic_view.html.erb +2 -2
  123. data/app/views/alchemy/elements/_intro_image_text_view.html.erb +4 -4
  124. data/app/views/alchemy/elements/_searchresult_editor.html.erb +4 -1
  125. data/app/views/alchemy/essences/_essence_boolean_editor.html.erb +1 -1
  126. data/app/views/alchemy/essences/_essence_picture_editor.html.erb +2 -3
  127. data/app/views/alchemy/essences/_essence_picture_tools.html.erb +1 -1
  128. data/app/views/alchemy/search/_form.html.erb +8 -0
  129. data/app/views/alchemy/search/_result.html.erb +3 -2
  130. data/app/views/alchemy/search/_results.html.erb +28 -0
  131. data/app/views/alchemy/user_sessions/leave.html.erb +4 -4
  132. data/app/views/alchemy/user_sessions/login.html.erb +1 -2
  133. data/app/views/layouts/alchemy/admin.html.erb +30 -10
  134. data/app/views/layouts/alchemy/login.html.erb +2 -39
  135. data/config/alchemy/elements.yml +1 -2
  136. data/config/alchemy/page_layouts.yml +8 -5
  137. data/config/authorization_rules.rb +27 -18
  138. data/config/initializers/localeapp.rb +9 -0
  139. data/config/locales/alchemy.de.yml +93 -56
  140. data/config/locales/alchemy.en.yml +73 -50
  141. data/config/routes.rb +3 -1
  142. data/db/migrate/20120704181529_add_upload_hash_to_alchemy_picture.rb +5 -0
  143. data/db/migrate/20120705214247_acts_as_taggable_on_migration.rb +28 -0
  144. data/db/migrate/20120728185830_add_cached_tag_list_to_alchemy_pictures.rb +5 -0
  145. data/db/migrate/20120831135441_set_alchemy_languages_country_code_default_to_empty_string.rb +9 -0
  146. data/lib/alchemy/capistrano.rb +2 -2
  147. data/lib/alchemy/essence.rb +14 -0
  148. data/lib/alchemy/page_layout.rb +0 -6
  149. data/lib/alchemy/resource.rb +9 -15
  150. data/lib/alchemy/upgrader.rb +18 -3
  151. data/lib/alchemy/version.rb +5 -1
  152. data/lib/alchemy_cms.rb +4 -1
  153. data/lib/rails/generators/alchemy/deploy_script/deploy_script_generator.rb +16 -6
  154. data/lib/rails/generators/alchemy/deploy_script/templates/deploy.rb.tt +17 -3
  155. data/lib/rails/generators/alchemy/elements/elements_generator.rb +6 -1
  156. data/lib/rails/generators/alchemy/elements/templates/editor.html.erb +10 -1
  157. data/lib/rails/generators/alchemy/elements/templates/view.html.erb +17 -18
  158. data/lib/rails/generators/alchemy/scaffold/files/pages.html.erb +4 -2
  159. data/lib/tasks/fleximage.rake +2 -2
  160. data/spec/controllers/admin/contents_controller_spec.rb +2 -2
  161. data/spec/controllers/admin/elements_controller_spec.rb +30 -1
  162. data/spec/controllers/admin/pages_controller_spec.rb +35 -18
  163. data/spec/controllers/admin/trash_controller_spec.rb +40 -16
  164. data/spec/controllers/attachments_controller_spec.rb +62 -0
  165. data/spec/controllers/base_controller_spec.rb +43 -42
  166. data/spec/controllers/elements_controller_spec.rb +30 -0
  167. data/spec/controllers/pages_controller_spec.rb +22 -5
  168. data/spec/controllers/pictures_controller_spec.rb +82 -0
  169. data/spec/dummy/app/models/event.rb +2 -1
  170. data/spec/dummy/config/database.yml +3 -2
  171. data/spec/dummy/db/schema.rb +51 -27
  172. data/spec/factories.rb +29 -8
  173. data/spec/helpers/admin/base_helper_spec.rb +134 -21
  174. data/spec/helpers/admin/contents_helper_spec.rb +2 -2
  175. data/spec/helpers/admin/elements_helper_spec.rb +17 -9
  176. data/spec/helpers/admin/essences_helper_spec.rb +7 -6
  177. data/spec/helpers/essences_helper_spec.rb +8 -7
  178. data/spec/helpers/pages_helper_spec.rb +208 -325
  179. data/spec/helpers/url_helper_spec.rb +171 -0
  180. data/spec/integration/admin/link_overlay_spec.rb +53 -0
  181. data/spec/integration/admin/modules_integration_spec.rb +22 -26
  182. data/spec/integration/admin/pages_controller_spec.rb +10 -19
  183. data/spec/integration/admin/picture_library_integration_spec.rb +52 -0
  184. data/spec/integration/admin/resources_integration_spec.rb +68 -75
  185. data/spec/integration/pages_controller_spec.rb +70 -61
  186. data/spec/integration/security_spec.rb +3 -5
  187. data/spec/integration/translation_integration_spec.rb +56 -0
  188. data/spec/libraries/essence_spec.rb +18 -0
  189. data/spec/libraries/resource_spec.rb +101 -79
  190. data/spec/libraries/resources_helper_spec.rb +3 -0
  191. data/spec/models/content_spec.rb +63 -60
  192. data/spec/models/element_spec.rb +203 -93
  193. data/spec/models/language_spec.rb +90 -65
  194. data/spec/models/page_layout_spec.rb +37 -0
  195. data/spec/models/page_spec.rb +181 -113
  196. data/spec/models/picture_spec.rb +73 -26
  197. data/spec/models/resource_spec.rb +52 -23
  198. data/spec/support/alchemy/specs_helpers.rb +2 -0
  199. data/spec/support/image.png +0 -0
  200. data/spec/{helpers/url_helpers_spec.rb → url_helpers_spec.rb} +0 -0
  201. data/vendor/assets/javascripts/jquery_plugins/jquery.selectBoxIt.js +1909 -0
  202. data/vendor/assets/javascripts/jquery_plugins/preloadCssImages.jQuery_v5.js +152 -0
  203. metadata +106 -33
  204. data/app/assets/stylesheets/alchemy/buttons.css.scss +0 -361
  205. data/app/assets/stylesheets/alchemy/jquery.sb.css.scss +0 -260
  206. data/app/views/alchemy/admin/contents/create.js.coffee +0 -49
  207. data/app/views/alchemy/admin/elements/fold.js.coffee +0 -37
  208. data/app/views/alchemy/admin/essence_pictures/destroy.js.coffee +0 -19
  209. data/app/views/alchemy/admin/pictures/_pictures_list.html.erb +0 -16
  210. data/app/views/alchemy/admin/pictures/update.js.erb +0 -3
  211. data/spec/dummy/config/locales/en.yml +0 -5
  212. data/spec/dummy/config/locales/fo.yml +0 -5
  213. data/spec/page_layout_spec.rb +0 -35
  214. data/vendor/assets/javascripts/jquery_plugins/jquery.in-place-edit.js +0 -172
  215. data/vendor/assets/javascripts/jquery_plugins/jquery.sb.min.js +0 -14
@@ -6,6 +6,9 @@ module Namespace
6
6
  end
7
7
  end
8
8
 
9
+ module EngineResource
10
+ end
11
+
9
12
  class ResourcesController
10
13
  def resource_handler
11
14
  @resource_handler = Alchemy::Resource.new('admin/namespace/my_resources')
@@ -1,100 +1,103 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Alchemy::Content do
3
+ module Alchemy
4
+ describe Content do
4
5
 
5
- it "should return the ingredient from its essence" do
6
- @element = FactoryGirl.create(:element, :name => 'headline')
7
- @content = @element.contents.find_by_essence_type('Alchemy::EssenceText')
8
- @content.essence.update_attributes(:body => "Hello")
9
- @content.ingredient.should == "Hello"
10
- end
6
+ let(:element) { FactoryGirl.create(:element, :name => 'headline', :create_contents_after_create => true) }
7
+ let(:content) { element.contents.find_by_essence_type('Alchemy::EssenceText') }
8
+
9
+ it "should return the ingredient from its essence" do
10
+ content.essence.update_attributes(:body => "Hello")
11
+ content.ingredient.should == "Hello"
12
+ end
11
13
 
12
- describe '.normalize_essence_type' do
14
+ describe '.normalize_essence_type' do
13
15
 
14
- context "passing namespaced essence type" do
16
+ context "passing namespaced essence type" do
17
+
18
+ it "should not add alchemy namespace" do
19
+ Content.normalize_essence_type('Alchemy::EssenceText').should == "Alchemy::EssenceText"
20
+ end
15
21
 
16
- it "should not add alchemy namespace" do
17
- Alchemy::Content.normalize_essence_type('Alchemy::EssenceText').should == "Alchemy::EssenceText"
18
22
  end
19
23
 
20
- end
24
+ context "passing not namespaced essence type" do
21
25
 
22
- context "passing not namespaced essence type" do
26
+ it "should add alchemy namespace" do
27
+ Content.normalize_essence_type('EssenceText').should == "Alchemy::EssenceText"
28
+ end
23
29
 
24
- it "should add alchemy namespace" do
25
- Alchemy::Content.normalize_essence_type('EssenceText').should == "Alchemy::EssenceText"
26
30
  end
27
31
 
28
32
  end
29
33
 
30
- end
34
+ describe '#normalized_essence_type' do
31
35
 
32
- describe '#normalized_essence_type' do
36
+ context "without namespace in essence_type column" do
33
37
 
34
- context "without namespace in essence_type column" do
38
+ it "should return the namespaced essence type" do
39
+ Content.new(:essence_type => 'EssenceText').normalized_essence_type.should == 'Alchemy::EssenceText'
40
+ end
35
41
 
36
- it "should return the namespaced essence type" do
37
- Alchemy::Content.new(:essence_type => 'EssenceText').normalized_essence_type.should == 'Alchemy::EssenceText'
38
42
  end
39
43
 
40
- end
44
+ context "with namespace in essence_type column" do
41
45
 
42
- context "with namespace in essence_type column" do
46
+ it "should return the namespaced essence type" do
47
+ Content.new(:essence_type => 'Alchemy::EssenceText').normalized_essence_type.should == 'Alchemy::EssenceText'
48
+ end
43
49
 
44
- it "should return the namespaced essence type" do
45
- Alchemy::Content.new(:essence_type => 'Alchemy::EssenceText').normalized_essence_type.should == 'Alchemy::EssenceText'
46
50
  end
47
51
 
48
52
  end
49
53
 
50
- end
54
+ describe '#update_essence' do
51
55
 
52
- describe '#update_essence' do
56
+ it "should update the attributes of related essence and return true" do
57
+ @element = FactoryGirl.create(:element, :name => 'text', :create_contents_after_create => true)
58
+ @content = @element.contents.first
59
+ @content.update_essence(:body => 'Mikes Petshop')
60
+ @content.ingredient.should == "Mikes Petshop"
61
+ end
53
62
 
54
- it "should update the attributes of related essence and return true" do
55
- @element = FactoryGirl.create(:element, :name => 'text')
56
- @content = @element.contents.first
57
- @content.update_essence(:body => 'Mikes Petshop')
58
- @content.ingredient.should == "Mikes Petshop"
59
- end
63
+ it "should add error messages if save fails and return false" do
64
+ @element = FactoryGirl.create(:element, :name => 'contactform', :create_contents_after_create => true)
65
+ @content = @element.contents.first
66
+ @content.update_essence
67
+ @content.errors[:essence].should have(1).item
68
+ end
60
69
 
61
- it "should add error messages if save fails and return false" do
62
- @element = FactoryGirl.create(:element, :name => 'contactform')
63
- @content = @element.contents.first
64
- @content.update_essence
65
- @content.errors[:essence].should have(1).item
66
- end
70
+ it "should raise error if essence is missing" do
71
+ @element = FactoryGirl.create(:element, :name => 'text', :create_contents_after_create => true)
72
+ @content = @element.contents.first
73
+ @content.update_essence
74
+ end
67
75
 
68
- it "should raise error if essence is missing" do
69
- @element = FactoryGirl.create(:element, :name => 'text')
70
- @content = @element.contents.first
71
- @content.update_essence
72
76
  end
73
77
 
74
- end
78
+ describe '#copy' do
75
79
 
76
- describe '#copy' do
80
+ before(:each) do
81
+ @element = FactoryGirl.create(:element, :name => 'text', :create_contents_after_create => true)
82
+ @content = @element.contents.first
83
+ end
77
84
 
78
- before(:each) do
79
- @element = FactoryGirl.create(:element, :name => 'text')
80
- @content = @element.contents.first
81
- end
85
+ it "should create a new record with all attributes of source except given differences" do
86
+ copy = Content.copy(@content, {:name => 'foobar', :element_id => @element.id + 1})
87
+ copy.name.should == 'foobar'
88
+ end
82
89
 
83
- it "should create a new record with all attributes of source except given differences" do
84
- copy = Alchemy::Content.copy(@content, {:name => 'foobar', :element_id => @element.id + 1})
85
- copy.name.should == 'foobar'
86
- end
90
+ it "should make a new record for essence of source" do
91
+ copy = Content.copy(@content, {:element_id => @element.id + 1})
92
+ copy.essence_id.should_not == @content.essence_id
93
+ end
87
94
 
88
- it "should make a new record for essence of source" do
89
- copy = Alchemy::Content.copy(@content, {:element_id => @element.id + 1})
90
- copy.essence_id.should_not == @content.essence_id
91
- end
95
+ it "should copy source essence attributes" do
96
+ copy = Content.copy(@content, {:element_id => @element.id + 1})
97
+ copy.essence.body == @content.essence.body
98
+ end
92
99
 
93
- it "should copy source essence attributes" do
94
- copy = Alchemy::Content.copy(@content, {:element_id => @element.id + 1})
95
- copy.essence.body == @content.essence.body
96
100
  end
97
101
 
98
102
  end
99
-
100
103
  end
@@ -3,48 +3,101 @@ require 'spec_helper'
3
3
  module Alchemy
4
4
  describe Element do
5
5
 
6
- context "scoped" do
6
+ describe '#new_from_scratch' do
7
7
 
8
- before(:each) do
9
- Element.delete_all
8
+ it "should initialize an element by name from scratch" do
9
+ el = Element.new_from_scratch({'name' => 'article'})
10
+ el.should be_valid
11
+ end
12
+
13
+ it "should raise an error if the given name is not defined in the elements.yml" do
14
+ expect { Element.new_from_scratch({'name' => 'foobar'}) }.to raise_error
10
15
  end
11
16
 
17
+ it "should take the first part of an given name containing a hash (#)" do
18
+ el = Element.new_from_scratch({'name' => 'article#header'})
19
+ el.name.should == "article"
20
+ end
21
+
22
+ it "should merge given attributes into defined ones" do
23
+ el = Element.new_from_scratch({'name' => 'article', 'page_id' => 1})
24
+ el.page_id.should == 1
25
+ end
26
+
27
+ it "should not have forbidden attributes from definition" do
28
+ el = Element.new_from_scratch({'name' => 'article'})
29
+ el.contents.should == []
30
+ end
31
+
32
+ end
33
+
34
+ context "scoped" do
35
+
12
36
  it "should return all public elements" do
13
- elements = [FactoryGirl.create(:element, :public => true), FactoryGirl.create(:element, :public => true)]
14
- Element.published.all.should == elements
37
+ element_1 = FactoryGirl.create(:element, :public => true)
38
+ element_2 = FactoryGirl.create(:element, :public => true)
39
+ elements = Element.published.all
40
+ elements.should include(element_1)
41
+ elements.should include(element_2)
15
42
  end
16
43
 
17
44
  it "should return all elements by name" do
18
- elements = [FactoryGirl.create(:element, :name => 'article'), FactoryGirl.create(:element, :name => 'article')]
19
- Element.named(['article']).all.should == elements
45
+ element_1 = FactoryGirl.create(:element, :name => 'article')
46
+ element_2 = FactoryGirl.create(:element, :name => 'article')
47
+ elements = Element.named(['article']).all
48
+ elements.should include(element_1)
49
+ elements.should include(element_2)
20
50
  end
21
51
 
22
52
  it "should return all elements but excluded ones" do
23
53
  FactoryGirl.create(:element, :name => 'article')
24
54
  FactoryGirl.create(:element, :name => 'article')
25
- excluded = [FactoryGirl.create(:element, :name => 'claim')]
26
- Element.excluded(['article']).all.should == excluded
55
+ excluded = FactoryGirl.create(:element, :name => 'claim')
56
+ Element.excluded(['claim']).all.should_not include(excluded)
27
57
  end
28
58
 
29
59
  context "not_in_cell" do
60
+
30
61
  it "should return all elements that are not in a cell" do
62
+ Element.delete_all
31
63
  FactoryGirl.create(:element, :cell_id => 6)
32
64
  FactoryGirl.create(:element, :cell_id => nil)
33
65
  Element.not_in_cell.should have(1).element
34
66
  end
67
+
35
68
  end
36
69
 
37
70
  end
38
71
 
39
- it "should return a list of element definitions for a list of element names" do
40
- element_names = ["article"]
41
- definitions = Element.all_definitions_for(element_names)
42
- definitions.first.fetch("name").should == 'article'
43
- end
72
+ describe '.all_definitions_for' do
73
+
74
+ it "should return a list of element definitions for a list of element names" do
75
+ element_names = ["article"]
76
+ definitions = Element.all_definitions_for(element_names)
77
+ definitions.first.fetch("name").should == 'article'
78
+ end
79
+
80
+ context "given 'all' as element name" do
81
+
82
+ before do
83
+ @element_definition = [
84
+ {'name' => 'article'},
85
+ {'name' => 'headline'}
86
+ ]
87
+ Element.stub!(:definitions).and_return @element_definition
88
+ end
89
+
90
+ it "should return all element definitions" do
91
+ Element.all_definitions_for('all').should == @element_definition
92
+ end
93
+
94
+ end
95
+
96
+ it "should always return an array" do
97
+ definitions = Element.all_definitions_for(nil)
98
+ definitions.should == []
99
+ end
44
100
 
45
- it "should always return an array calling all_definitions_for()" do
46
- definitions = Element.all_definitions_for(nil)
47
- definitions.should == []
48
101
  end
49
102
 
50
103
  context "no description files are found" do
@@ -65,56 +118,47 @@ module Alchemy
65
118
 
66
119
  context "retrieving contents, essences and ingredients" do
67
120
 
68
- before(:each) do
69
- @element = FactoryGirl.create(:element, :name => 'news')
70
- end
121
+ let(:element) { FactoryGirl.create(:element, :name => 'news', :create_contents_after_create => true) }
71
122
 
72
123
  it "should return an ingredient by name" do
73
- @element.ingredient('news_headline').should == EssenceText.first.ingredient
124
+ element.ingredient('news_headline').should == EssenceText.first.ingredient
74
125
  end
75
126
 
76
127
  it "should return the content for rss title" do
77
- @element.content_for_rss_title.should == @element.contents.find_by_name('news_headline')
128
+ element.content_for_rss_title.should == element.contents.find_by_name('news_headline')
78
129
  end
79
130
 
80
131
  it "should return the content for rss description" do
81
- @element.content_for_rss_description.should == @element.contents.find_by_name('body')
132
+ element.content_for_rss_description.should == element.contents.find_by_name('body')
82
133
  end
83
134
 
84
135
  end
85
136
 
86
- it "should return a collection of trashed elements" do
87
- @element = FactoryGirl.create(:element)
88
- @element.trash
89
- Element.trashed.should include(@element)
90
- end
91
-
92
- it "should return a collection of not trashed elements" do
93
- @element = FactoryGirl.create(:element, :page_id => 1)
94
- Element.not_trashed.should include(@element)
95
- end
96
-
97
137
  context "limited amount" do
98
- before(:each) do
99
- descriptions = Element.descriptions
100
- descriptions << {
101
- 'name' => 'column_headline',
102
- 'amount' => 3,
103
- 'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}]
104
- }
105
- descriptions << {
106
- 'name' => 'unique_headline',
107
- 'unique' => true,
108
- 'amount' => 3,
109
- 'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}]
110
- }
111
- Element.stub!(:descriptions).and_return(descriptions)
112
- PageLayout.add(
138
+
139
+ before do
140
+ defs = [
141
+ {
142
+ 'name' => 'column_headline',
143
+ 'amount' => 3,
144
+ 'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}]
145
+ },
146
+ {
147
+ 'name' => 'unique_headline',
148
+ 'unique' => true,
149
+ 'amount' => 3,
150
+ 'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}]
151
+ }
152
+ ]
153
+ # F&%#ing alias methods
154
+ Element.stub!(:definitions).and_return(defs)
155
+ Element.stub!(:descriptions).and_return(defs)
156
+ PageLayout.stub!(:get).and_return({
113
157
  'name' => 'columns',
114
158
  'elements' => ['column_headline', 'unique_headline'],
115
159
  'autogenerate' => ['unique_headline', 'column_headline', 'column_headline', 'column_headline']
116
- )
117
- @page = FactoryGirl.create(:page, :page_layout => 'columns')
160
+ })
161
+ @page = FactoryGirl.create(:page, :page_layout => 'columns', :do_not_autogenerate => false)
118
162
  end
119
163
 
120
164
  it "should be readable" do
@@ -132,39 +176,22 @@ module Alchemy
132
176
 
133
177
  end
134
178
 
135
- context "trashed" do
179
+ context "collections" do
136
180
 
137
- before(:each) do
138
- @element = FactoryGirl.create(:element)
139
- @element.trash
140
- end
141
-
142
- it "should be not public" do
143
- @element.public.should be_false
144
- end
145
-
146
- it "should have no page" do
147
- @element.page.should == nil
148
- end
149
-
150
- context "collections" do
181
+ context "for trashed elements" do
151
182
 
152
- context "for trashed elements" do
153
-
154
- let(:element) do
155
- FactoryGirl.create(:element, :page_id => 1)
156
- end
157
-
158
- it "should return a collection of trashed elements" do
159
- not_trashed_element = FactoryGirl.create(:element)
160
- element.trash
161
- Element.trashed.should include(element)
162
- end
183
+ let(:element) do
184
+ FactoryGirl.create(:element, :page_id => 1)
185
+ end
163
186
 
164
- it "should return a collection of not trashed elements" do
165
- Element.not_trashed.should include(element)
166
- end
187
+ it "should return a collection of trashed elements" do
188
+ not_trashed_element = FactoryGirl.create(:element)
189
+ element.trash
190
+ Element.trashed.should include(element)
191
+ end
167
192
 
193
+ it "should return a collection of not trashed elements" do
194
+ Element.not_trashed.should include(element)
168
195
  end
169
196
 
170
197
  end
@@ -202,6 +229,35 @@ module Alchemy
202
229
 
203
230
  end
204
231
 
232
+ it "should raise error if all_for_page method has no page" do
233
+ expect { Element.all_for_page(nil) }.to raise_error(TypeError)
234
+ end
235
+
236
+ describe "#content_by_type" do
237
+
238
+ before(:each) do
239
+ @element = FactoryGirl.create(:element, :name => 'headline')
240
+ @content = @element.contents.first
241
+ end
242
+
243
+ context "with namespaced essence type" do
244
+
245
+ it "should return content by passing a essence type" do
246
+ @element.content_by_type('Alchemy::EssenceText').should == @content
247
+ end
248
+
249
+ end
250
+
251
+ context "without namespaced essence type" do
252
+
253
+ it "should return content by passing a essence type" do
254
+ @element.content_by_type('EssenceText').should == @content
255
+ end
256
+
257
+ end
258
+
259
+ end
260
+
205
261
  describe "#all_contents_by_type" do
206
262
 
207
263
  before(:each) do
@@ -229,35 +285,33 @@ module Alchemy
229
285
 
230
286
  describe '#copy' do
231
287
 
232
- before(:each) do
233
- @element = FactoryGirl.create(:element)
234
- end
288
+ let(:element) { FactoryGirl.create(:element, :create_contents_after_create => true) }
235
289
 
236
290
  it "should not create contents from scratch" do
237
- copy = Element.copy(@element)
238
- copy.contents.count.should == @element.contents.count
291
+ copy = Element.copy(element)
292
+ copy.contents.count.should == element.contents.count
239
293
  end
240
294
 
241
295
  it "should create a new record with all attributes of source except given differences" do
242
- copy = Element.copy(@element, {:name => 'foobar'})
296
+ copy = Element.copy(element, {:name => 'foobar'})
243
297
  copy.name.should == 'foobar'
244
298
  end
245
299
 
246
300
  it "should make copies of all contents of source" do
247
- copy = Element.copy(@element)
248
- copy.contents.collect(&:id).should_not == @element.contents.collect(&:id)
301
+ copy = Element.copy(element)
302
+ copy.contents.collect(&:id).should_not == element.contents.collect(&:id)
249
303
  end
250
304
 
251
305
  end
252
306
 
253
307
  describe "Finding previous or next element." do
254
308
 
309
+ let(:page) { FactoryGirl.create(:language_root_page) }
310
+
255
311
  before(:each) do
256
- @page = FactoryGirl.create(:language_root_page)
257
- @page.elements.delete_all
258
- @element1 = FactoryGirl.create(:element, :page => @page, :name => 'headline')
259
- @element2 = FactoryGirl.create(:element, :page => @page)
260
- @element3 = FactoryGirl.create(:element, :page => @page, :name => 'text')
312
+ @element1 = FactoryGirl.create(:element, :page => page, :name => 'headline')
313
+ @element2 = FactoryGirl.create(:element, :page => page)
314
+ @element3 = FactoryGirl.create(:element, :page => page, :name => 'text')
261
315
  end
262
316
 
263
317
  describe '#prev' do
@@ -290,5 +344,61 @@ module Alchemy
290
344
 
291
345
  end
292
346
 
347
+ describe '#belonging_cellnames' do
348
+
349
+ before do
350
+ @page = FactoryGirl.create(:public_page)
351
+ @element = FactoryGirl.create(:element, :page => @page)
352
+ end
353
+
354
+ context "with page having cells defining the correct elements" do
355
+
356
+ before do
357
+ Cell.stub!(:definitions).and_return([
358
+ {'name' => 'header', 'elements' => ['article', 'headline']},
359
+ {'name' => 'footer', 'elements' => ['article', 'text']},
360
+ {'name' => 'sidebar', 'elements' => ['teaser']}
361
+ ])
362
+ end
363
+
364
+ it "should return a list of all cells from given page this element could be placed in" do
365
+ @header_cell = FactoryGirl.create(:cell, :name => 'header', :page => @page)
366
+ @footer_cell = FactoryGirl.create(:cell, :name => 'footer', :page => @page)
367
+ @sidebar_cell = FactoryGirl.create(:cell, :name => 'sidebar', :page => @page)
368
+ @element.belonging_cellnames(@page).should include('header')
369
+ @element.belonging_cellnames(@page).should include('footer')
370
+ end
371
+
372
+ context "but without any cells" do
373
+
374
+ it "should return the 'nil cell'" do
375
+ @element.belonging_cellnames(@page).should == ['for_other_elements']
376
+ end
377
+
378
+ end
379
+
380
+ end
381
+
382
+ context "with page having cells defining the wrong elements" do
383
+
384
+ before do
385
+ Cell.stub!(:definitions).and_return([
386
+ {'name' => 'header', 'elements' => ['download', 'headline']},
387
+ {'name' => 'footer', 'elements' => ['contactform', 'text']},
388
+ {'name' => 'sidebar', 'elements' => ['teaser']}
389
+ ])
390
+ end
391
+
392
+ it "should return the 'nil cell'" do
393
+ @header_cell = FactoryGirl.create(:cell, :name => 'header', :page => @page)
394
+ @footer_cell = FactoryGirl.create(:cell, :name => 'footer', :page => @page)
395
+ @sidebar_cell = FactoryGirl.create(:cell, :name => 'sidebar', :page => @page)
396
+ @element.belonging_cellnames(@page).should == ['for_other_elements']
397
+ end
398
+
399
+ end
400
+
401
+ end
402
+
293
403
  end
294
404
  end