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
@@ -1,96 +1,121 @@
1
1
  # encoding: UTF-8
2
2
  require 'spec_helper'
3
3
 
4
- describe Alchemy::Language do
4
+ module Alchemy
5
+ describe Language do
5
6
 
6
- before(:each) do
7
- @language = FactoryGirl.create(:language)
8
- end
7
+ let(:language) { FactoryGirl.create(:klingonian) }
8
+ let(:page) { FactoryGirl.create(:page, :language => language) }
9
9
 
10
- it "should return a label for code" do
11
- @language.label(:code).should == 'kl'
12
- end
10
+ it "should return a label for code" do
11
+ language.label(:code).should == 'kl'
12
+ end
13
13
 
14
- it "should return a label for name" do
15
- @language.label(:name).should == 'Klingonian'
16
- end
14
+ it "should return a label for name" do
15
+ language.label(:name).should == 'Klingonian'
16
+ end
17
+
18
+ context "with language_code and empty country_code" do
19
+
20
+ it "#code should return language locale only" do
21
+ language.country_code = ''
22
+ language.code.should == 'kl'
23
+ end
24
+
25
+ context "adding a value for country code" do
17
26
 
18
- context "with language_code and empty country_code" do
27
+ it "#code should return a joined locale" do
28
+ language.country_code = 'cr'
29
+ language.code.should == 'kl-cr'
30
+ end
31
+
32
+ it "should update all associated Pages with self.code as value for Page#language_code" do
33
+ page = FactoryGirl.create(:page, :language => language)
34
+ language.country_code = 'cr'
35
+ language.save
36
+ page.reload; page.language_code.should == 'kl-cr'
37
+ end
38
+ end
19
39
 
20
- it "#code should return language locale only" do
21
- @language.country_code = ''
22
- @language.code.should == 'kl'
23
40
  end
24
41
 
25
- context "adding a value for country code" do
42
+ context "with country_code and_language_code" do
43
+
44
+ context "removing the country_code" do
45
+
46
+ it "should update all associated Pages´s language_code with Language#code" do
47
+ language = FactoryGirl.create(:language, :country_code => 'kl')
48
+
49
+ language.country_code = ''
50
+ language.save
51
+ page.reload; page.language_code.should == "kl"
52
+ end
26
53
 
27
- it "#code should return a joined locale" do
28
- @language.country_code = 'cr'
29
- @language.code.should == 'kl-cr'
30
54
  end
31
55
 
32
- it "should update all associated Pages with self.code as value for Page#language_code" do
33
- @page = FactoryGirl.create(:page, :language => @language)
34
- @language.country_code = 'cr'
35
- @language.save
36
- @page.reload; @page.language_code.should == 'kl-cr'
56
+ end
57
+
58
+ it "should not be deletable if it is the default language" do
59
+ @default_language = Alchemy::Language.find_by_default(true)
60
+ if !@default_language
61
+ @default_language = FactoryGirl.create(:language, :name => "default", :code => "aa", :frontpage_name => "intro", :default => true)
37
62
  end
63
+ expect { @default_language.destroy }.to raise_error
38
64
  end
39
65
 
40
- end
66
+ describe "before save" do
41
67
 
42
- context "with country_code and_language_code" do
68
+ describe "#remove_old_default if default attribute has changed to true" do
69
+
70
+ it "should unset the default status of the old default-language" do
71
+ @default_language = Alchemy::Language.get_default
72
+ language.update_attributes(:default => true)
73
+ @default_language.reload
74
+ @default_language.default.should be(false)
75
+ end
43
76
 
44
- context "removing the country_code" do
45
- it "should update all associated Pages´s language_code with Language#code" do
46
- language = FactoryGirl.create(:language_with_country_code)
47
- @page = FactoryGirl.create(:page, :language => language)
48
- language.country_code = ''
49
- language.save
50
- @page.reload; @page.language_code.should == "kl"
51
77
  end
78
+
52
79
  end
53
80
 
54
- end
81
+ context "after_update" do
55
82
 
56
- it "should not be deletable if it is the default language" do
57
- @default_language = Alchemy::Language.find_by_default(true)
58
- if !@default_language
59
- @default_language = FactoryGirl.create(:language, :name => "default", :code => "aa", :frontpage_name => "intro", :default => true)
60
- end
61
- expect { @default_language.destroy }.to raise_error
62
- end
83
+ describe "#set_pages_language if language´s code has changed" do
84
+
85
+ it "should update all its pages with the new code" do
86
+ @other_page = FactoryGirl.create(:page, :language => language)
87
+ language.update_attributes(:code => "fo")
88
+ language.reload; page.reload; @other_page.reload
89
+ [page.language_code, @other_page.language_code].should == [language.code, language.code]
90
+ end
63
91
 
64
- describe "before save" do
65
- describe "#remove_old_default if default attribute has changed to true" do
66
- it "should unset the default status of the old default-language" do
67
- @default_language = Alchemy::Language.get_default
68
- @language.update_attributes(:default => true)
69
- @default_language.reload
70
- @default_language.default.should be(false)
71
92
  end
72
- end
73
- end
74
93
 
75
- context "after_update" do
76
- describe "#set_pages_language if language´s code has changed" do
77
- it "should update all its pages with the new code" do
78
- @page = FactoryGirl.create(:page, :language => @language)
79
- @other_page = FactoryGirl.create(:page, :language => @language)
80
- @language.update_attributes(:code => "fo")
81
- @language.reload; @page.reload; @other_page.reload
82
- [@page.language_code, @other_page.language_code].should == [@language.code, @language.code]
94
+ describe "#unpublish_pages" do
95
+
96
+ it "should set all pages to unpublic if it gets set to unpublic" do
97
+ page = FactoryGirl.create(:page, :language => language)
98
+ @other_page = FactoryGirl.create(:page, :language => language)
99
+ language.update_attributes(:public => false)
100
+ language.reload; page.reload; @other_page.reload
101
+ [page.public?, @other_page.public?].should == [false, false]
102
+ end
103
+
83
104
  end
105
+
84
106
  end
85
- describe "#unpublish_pages" do
86
- it "should set all pages to unpublic if it gets set to unpublic" do
87
- @page = FactoryGirl.create(:page, :language => @language)
88
- @other_page = FactoryGirl.create(:page, :language => @language)
89
- @language.update_attributes(:public => false)
90
- @language.reload; @page.reload; @other_page.reload
91
- [@page.public?, @other_page.public?].should == [false, false]
107
+
108
+ describe '.find_by_code' do
109
+
110
+ context "with only the language code given" do
111
+
112
+ it "should find the language" do
113
+ Language.find_by_code(language.code).should == language
114
+ end
115
+
92
116
  end
117
+
93
118
  end
94
- end
95
119
 
120
+ end
96
121
  end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ module Alchemy
4
+ describe PageLayout do
5
+
6
+ context "method get_layouts" do
7
+
8
+ it "should generally return page_layouts, nothing else!" do
9
+ PageLayout.read_layouts_file.should be_instance_of(Array)
10
+ end
11
+
12
+ end
13
+
14
+ context "with custom page layouts" do
15
+
16
+ it "should return the users page_layouts if exists in the application" do
17
+ @config_path = Rails.root.join("config/alchemy")
18
+ FileUtils.mv(File.join(@config_path, 'page_layouts.yml'), File.join(@config_path, 'page_layouts.bak'))
19
+ layouts_file = File.join(@config_path, 'page_layouts.yml')
20
+ File.open(layouts_file, 'w') do |page_layouts|
21
+ page_layouts.puts "- name: testlayout\n elements:"
22
+ end
23
+ PageLayout.read_layouts_file.first.values.should include("testlayout")
24
+ end
25
+
26
+ after(:each) do
27
+ FileUtils.mv(File.join(@config_path, 'page_layouts.bak'), File.join(@config_path, 'page_layouts.yml'))
28
+ end
29
+
30
+ end
31
+
32
+ it "should not display hidden page layouts" do
33
+ PageLayout.selectable_layouts(Language.get_default).each { |e| e["hide"].should_not == true }
34
+ end
35
+
36
+ end
37
+ end
@@ -5,30 +5,30 @@ require 'spec_helper'
5
5
  module Alchemy
6
6
  describe Page do
7
7
 
8
- before(:each) do
9
- @rootpage = Page.root
10
- @rootpage.children.destroy_all
11
- @language = Language.get_default
12
- @language_root = FactoryGirl.create(:language_root_page, :name => 'Default Language Root', :language => @language)
13
- end
8
+ let(:rootpage) { Page.root }
9
+ let(:language) { Language.get_default }
10
+ let(:klingonian) { FactoryGirl.create(:klingonian) }
11
+ let(:language_root) { FactoryGirl.create(:language_root_page) }
12
+ let(:page) { mock(:page, :page_layout => 'foo') }
13
+ let(:public_page) { FactoryGirl.create(:public_page) }
14
+ let(:news_page) { FactoryGirl.create(:public_page, :page_layout => 'news', :do_not_autogenerate => false) }
14
15
 
15
16
  describe ".layout_description" do
16
17
 
17
18
  context "for a language root page" do
18
19
 
19
20
  it "should return the page layout description as hash" do
20
- @language_root.layout_description['name'].should == 'intro'
21
+ language_root.layout_description['name'].should == 'intro'
21
22
  end
22
23
 
23
24
  it "should return an empty hash for root page" do
24
- @rootpage.layout_description.should == {}
25
+ rootpage.layout_description.should == {}
25
26
  end
26
27
 
27
28
  end
28
29
 
29
30
  it "should raise Exception if the page_layout could not be found in the definition file" do
30
- @page = mock(:page, :page_layout => 'foo')
31
- expect { @page.layout_description }.to raise_error
31
+ expect { page.layout_description }.to raise_error
32
32
  end
33
33
 
34
34
  end
@@ -38,45 +38,42 @@ module Alchemy
38
38
  end
39
39
 
40
40
  it "should return all rss feed elements" do
41
- @page = FactoryGirl.create(:public_page, :page_layout => 'news', :parent_id => @language_root.id, :language => @language)
42
- @page.feed_elements.should == Element.find_all_by_name('news')
41
+ news_page.feed_elements.should_not be_empty
42
+ news_page.feed_elements.should == Element.find_all_by_name('news')
43
43
  end
44
44
 
45
45
  context "finding elements" do
46
46
 
47
- before(:each) do
48
- @page = FactoryGirl.create(:public_page)
49
- @non_public_elements = [
50
- FactoryGirl.create(:element, :public => false, :page => @page),
51
- FactoryGirl.create(:element, :public => false, :page => @page)
52
- ]
47
+ before do
48
+ FactoryGirl.create(:element, :public => false, :page => public_page)
49
+ FactoryGirl.create(:element, :public => false, :page => public_page)
53
50
  end
54
51
 
55
52
  it "should return the collection of elements if passed an array into options[:collection]" do
56
- options = {:collection => @page.elements}
57
- @page.find_elements(options).all.should == @page.elements.all
53
+ options = {:collection => public_page.elements}
54
+ public_page.find_elements(options).all.should == public_page.elements.all
58
55
  end
59
56
 
60
57
  context "with show_non_public argument TRUE" do
61
58
 
62
59
  it "should return all elements from empty options" do
63
- @page.find_elements({}, true).all.should == @page.elements.all
60
+ public_page.find_elements({}, true).all.should == public_page.elements.all
64
61
  end
65
62
 
66
63
  it "should only return the elements passed as options[:only]" do
67
- @page.find_elements({:only => ['article']}, true).all.should == @page.elements.named('article').all
64
+ public_page.find_elements({:only => ['article']}, true).all.should == public_page.elements.named('article').all
68
65
  end
69
66
 
70
67
  it "should not return the elements passed as options[:except]" do
71
- @page.find_elements({:except => ['article']}, true).all.should == @page.elements - @page.elements.named('article').all
68
+ public_page.find_elements({:except => ['article']}, true).all.should == public_page.elements - public_page.elements.named('article').all
72
69
  end
73
70
 
74
71
  it "should return elements offsetted" do
75
- @page.find_elements({:offset => 2}, true).all.should == @page.elements.offset(2)
72
+ public_page.find_elements({:offset => 2}, true).all.should == public_page.elements.offset(2)
76
73
  end
77
74
 
78
75
  it "should return elements limitted in count" do
79
- @page.find_elements({:count => 1}, true).all.should == @page.elements.limit(1)
76
+ public_page.find_elements({:count => 1}, true).all.should == public_page.elements.limit(1)
80
77
  end
81
78
 
82
79
  end
@@ -84,23 +81,23 @@ module Alchemy
84
81
  context "with show_non_public argument FALSE" do
85
82
 
86
83
  it "should return all elements from empty arguments" do
87
- @page.find_elements().all.should == @page.elements.published.all
84
+ public_page.find_elements().all.should == public_page.elements.published.all
88
85
  end
89
86
 
90
87
  it "should only return the public elements passed as options[:only]" do
91
- @page.find_elements(:only => ['article']).all.should == @page.elements.published.named('article').all
88
+ public_page.find_elements(:only => ['article']).all.should == public_page.elements.published.named('article').all
92
89
  end
93
90
 
94
91
  it "should return all public elements except the ones passed as options[:except]" do
95
- @page.find_elements(:except => ['article']).all.should == @page.elements.published.all - @page.elements.published.named('article').all
92
+ public_page.find_elements(:except => ['article']).all.should == public_page.elements.published.all - public_page.elements.published.named('article').all
96
93
  end
97
94
 
98
95
  it "should return elements offsetted" do
99
- @page.find_elements({:offset => 2}).all.should == @page.elements.published.offset(2)
96
+ public_page.find_elements({:offset => 2}).all.should == public_page.elements.published.offset(2)
100
97
  end
101
98
 
102
99
  it "should return elements limitted in count" do
103
- @page.find_elements({:count => 1}).all.should == @page.elements.published.limit(1)
100
+ public_page.find_elements({:count => 1}).all.should == public_page.elements.published.limit(1)
104
101
  end
105
102
 
106
103
  end
@@ -112,32 +109,32 @@ module Alchemy
112
109
  context "before/after filter" do
113
110
 
114
111
  it "should automatically set the title from its name" do
115
- page = FactoryGirl.create(:page, :name => 'My Testpage', :language => @language, :parent_id => @language_root.id)
112
+ page = FactoryGirl.create(:page, :name => 'My Testpage', :language => language, :parent_id => language_root.id)
116
113
  page.title.should == 'My Testpage'
117
114
  end
118
115
 
119
116
  it "should get a webfriendly urlname" do
120
- page = FactoryGirl.create(:page, :name => 'klingon$&stößel ', :language => @language, :parent_id => @language_root.id)
117
+ page = FactoryGirl.create(:page, :name => 'klingon$&stößel ', :language => language, :parent_id => language_root.id)
121
118
  page.urlname.should == 'klingon-stoessel'
122
119
  end
123
120
 
124
121
  it "should generate a three letter urlname from two letter name" do
125
- page = FactoryGirl.create(:page, :name => 'Au', :language => @language, :parent_id => @language_root.id)
122
+ page = FactoryGirl.create(:page, :name => 'Au', :language => language, :parent_id => language_root.id)
126
123
  page.urlname.should == '-au'
127
124
  end
128
125
 
129
126
  it "should generate a three letter urlname from two letter name with umlaut" do
130
- page = FactoryGirl.create(:page, :name => 'Aü', :language => @language, :parent_id => @language_root.id)
127
+ page = FactoryGirl.create(:page, :name => 'Aü', :language => language, :parent_id => language_root.id)
131
128
  page.urlname.should == 'aue'
132
129
  end
133
130
 
134
131
  it "should generate a three letter urlname from one letter name" do
135
- page = FactoryGirl.create(:page, :name => 'A', :language => @language, :parent_id => @language_root.id)
132
+ page = FactoryGirl.create(:page, :name => 'A', :language => language, :parent_id => language_root.id)
136
133
  page.urlname.should == '--a'
137
134
  end
138
135
 
139
136
  it "should add a user stamper" do
140
- page = FactoryGirl.create(:page, :name => 'A', :language => @language, :parent_id => @language_root.id)
137
+ page = FactoryGirl.create(:page, :name => 'A', :language => language, :parent_id => language_root.id)
141
138
  page.class.stamper_class.to_s.should == 'Alchemy::User'
142
139
  end
143
140
 
@@ -150,14 +147,14 @@ module Alchemy
150
147
  context "before/after filter" do
151
148
 
152
149
  it "should not set the title automatically if the name changed but title is not blank" do
153
- page = FactoryGirl.create(:page, :name => 'My Testpage', :language => @language, :parent_id => @language_root.id)
150
+ page = FactoryGirl.create(:page, :name => 'My Testpage', :language => language, :parent_id => language_root.id)
154
151
  page.name = "My Renaming Test"
155
152
  page.save; page.reload
156
153
  page.title.should == "My Testpage"
157
154
  end
158
155
 
159
156
  it "should not automatically set the title if it changed its value" do
160
- page = FactoryGirl.create(:page, :name => 'My Testpage', :language => @language, :parent_id => @language_root.id)
157
+ page = FactoryGirl.create(:page, :name => 'My Testpage', :language => language, :parent_id => language_root.id)
161
158
  page.title = "I like SEO"
162
159
  page.save; page.reload
163
160
  page.title.should == "I like SEO"
@@ -167,38 +164,34 @@ module Alchemy
167
164
 
168
165
  end
169
166
 
170
- context "with children" do
167
+ describe '#first_public_child' do
171
168
 
172
- before(:each) do
173
- @first_child = FactoryGirl.create(:page, :name => "First child", :language => @language, :public => false, :parent_id => @language_root.id)
174
- @first_child.move_to_child_of(@language_root)
169
+ before do
170
+ FactoryGirl.create(:page, :name => "First child", :language => language, :public => false, :parent_id => language_root.id)
171
+ end
175
172
 
176
- @first_public_child = FactoryGirl.create(:page, :name => "First public child", :language => @language, :parent_id => @language_root.id, :public => true)
177
- @first_public_child.move_to_child_of(@language_root)
173
+ it "should return first_public_child" do
174
+ first_public_child = FactoryGirl.create(:public_page, :name => "First public child", :language => language, :parent_id => language_root.id)
175
+ language_root.first_public_child.should == first_public_child
178
176
  end
179
177
 
180
- it "should return a page object (or nil if no public child exists) for first_public_child" do
181
- if @language_root.children.any?
182
- @language_root.first_public_child.should == @first_public_child
183
- else
184
- @language_root.first_public_child.should == nil
185
- end
178
+ it "should return nil if no public child exists" do
179
+ language_root.first_public_child.should == nil
186
180
  end
187
181
 
188
182
  end
189
183
 
190
184
  context ".contentpages" do
191
185
 
192
- before(:each) do
193
- @klingonian = FactoryGirl.create(:language)
194
- @layoutroot = Page.find_or_create_layout_root_for(@klingonian.id)
195
- @layoutpage = FactoryGirl.create(:public_page, :name => 'layoutpage', :layoutpage => true, :parent_id => @layoutroot.id, :language => @klingonian)
196
- @klingonian_lang_root = FactoryGirl.create(:language_root_page, :name => 'klingonian_lang_root', :layoutpage => nil, :language => @klingonian)
197
- @contentpage = FactoryGirl.create(:public_page, :name => 'contentpage', :parent_id => @language_root.id, :language => @language)
186
+ before do
187
+ layoutroot = Page.find_or_create_layout_root_for(klingonian.id)
188
+ @layoutpage = FactoryGirl.create(:public_page, :name => 'layoutpage', :layoutpage => true, :parent_id => layoutroot.id, :language => klingonian)
189
+ @klingonian_lang_root = FactoryGirl.create(:language_root_page, :name => 'klingonian_lang_root', :layoutpage => nil, :language => klingonian)
190
+ @contentpage = FactoryGirl.create(:public_page, :name => 'contentpage', :parent_id => language_root.id, :language => language)
198
191
  end
199
192
 
200
193
  it "should return a collection of contentpages" do
201
- Page.contentpages.to_a.should include(@language_root, @klingonian_lang_root, @contentpage)
194
+ Page.contentpages.to_a.should include(language_root, @klingonian_lang_root, @contentpage)
202
195
  end
203
196
 
204
197
  it "should not contain pages with attribute :layoutpage set to true" do
@@ -214,8 +207,8 @@ module Alchemy
214
207
  context ".public" do
215
208
 
216
209
  it "should return pages that are public" do
217
- FactoryGirl.create(:public_page, :name => 'First Public Child', :parent_id => @language_root.id, :language => @language)
218
- FactoryGirl.create(:public_page, :name => 'Second Public Child', :parent_id => @language_root.id, :language => @language)
210
+ FactoryGirl.create(:public_page, :name => 'First Public Child', :parent_id => language_root.id, :language => language)
211
+ FactoryGirl.create(:public_page, :name => 'Second Public Child', :parent_id => language_root.id, :language => language)
219
212
  Page.published.should have(3).pages
220
213
  end
221
214
 
@@ -224,22 +217,22 @@ module Alchemy
224
217
  context ".not_locked" do
225
218
 
226
219
  it "should return pages that are not blocked by a user at the moment" do
227
- FactoryGirl.create(:public_page, :locked => true, :name => 'First Public Child', :parent_id => @language_root.id, :language => @language)
228
- FactoryGirl.create(:public_page, :name => 'Second Public Child', :parent_id => @language_root.id, :language => @language)
220
+ FactoryGirl.create(:public_page, :locked => true, :name => 'First Public Child', :parent_id => language_root.id, :language => language)
221
+ FactoryGirl.create(:public_page, :name => 'Second Public Child', :parent_id => language_root.id, :language => language)
229
222
  Page.not_locked.should have(3).pages
230
223
  end
231
224
  end
232
225
 
233
226
  context ".all_locked" do
234
227
  it "should return 1 page that is blocked by a user at the moment" do
235
- FactoryGirl.create(:public_page, :locked => true, :name => 'First Public Child', :parent_id => @language_root.id, :language => @language)
228
+ FactoryGirl.create(:public_page, :locked => true, :name => 'First Public Child', :parent_id => language_root.id, :language => language)
236
229
  Page.all_locked.should have(1).pages
237
230
  end
238
231
  end
239
232
 
240
233
  context ".language_roots" do
241
234
  it "should return 1 language_root" do
242
- FactoryGirl.create(:public_page, :name => 'First Public Child', :parent_id => @language_root.id, :language => @language)
235
+ FactoryGirl.create(:public_page, :name => 'First Public Child', :parent_id => language_root.id, :language => language)
243
236
  Page.language_roots.should have(1).pages
244
237
  end
245
238
  end
@@ -247,43 +240,43 @@ module Alchemy
247
240
 
248
241
  context ".layoutpages" do
249
242
  it "should return 1 layoutpage" do
250
- FactoryGirl.create(:public_page, :layoutpage => true, :name => 'Layoutpage', :parent_id => @rootpage.id, :language => @language)
243
+ FactoryGirl.create(:public_page, :layoutpage => true, :name => 'Layoutpage', :parent_id => rootpage.id, :language => language)
251
244
  Page.layoutpages.should have(1).pages
252
245
  end
253
246
  end
254
247
 
255
248
  context ".visible" do
256
249
  it "should return 1 visible page" do
257
- FactoryGirl.create(:public_page, :name => 'First Public Child', :visible => true, :parent_id => @language_root.id, :language => @language)
250
+ FactoryGirl.create(:public_page, :name => 'First Public Child', :visible => true, :parent_id => language_root.id, :language => language)
258
251
  Page.visible.should have(1).pages
259
252
  end
260
253
  end
261
254
 
262
255
  context ".accessible" do
263
256
  it "should return 2 accessible pages" do
264
- FactoryGirl.create(:public_page, :name => 'First Public Child', :restricted => true, :parent_id => @language_root.id, :language => @language)
257
+ FactoryGirl.create(:public_page, :name => 'First Public Child', :restricted => true, :parent_id => language_root.id, :language => language)
265
258
  Page.accessible.should have(2).pages
266
259
  end
267
260
  end
268
261
 
269
262
  context ".restricted" do
270
263
  it "should return 1 restricted page" do
271
- FactoryGirl.create(:public_page, :name => 'First Public Child', :restricted => true, :parent_id => @language_root.id, :language => @language)
264
+ FactoryGirl.create(:public_page, :name => 'First Public Child', :restricted => true, :parent_id => language_root.id, :language => language)
272
265
  Page.restricted.should have(1).pages
273
266
  end
274
267
  end
275
268
 
276
269
  context "#unlock" do
277
270
  it "should set the locked status to false" do
278
- @page = FactoryGirl.create(:public_page, :locked => true)
279
- @page.unlock
280
- @page.locked.should == false
271
+ page = FactoryGirl.create(:public_page, :locked => true)
272
+ page.unlock
273
+ page.locked.should == false
281
274
  end
282
275
  end
283
276
 
284
277
  describe "#cell_definitions" do
285
278
 
286
- before(:each) do
279
+ before do
287
280
  @page = FactoryGirl.build(:page, :page_layout => 'foo')
288
281
  @page.stub!(:layout_description).and_return({'name' => "foo", 'cells' => ["foo_cell"]})
289
282
  @cell_descriptions = [{'name' => "foo_cell", 'elements' => ["1", "2"]}]
@@ -303,24 +296,27 @@ module Alchemy
303
296
 
304
297
  describe "#elements_grouped_by_cells" do
305
298
 
306
- context "with no elements defined that are not defined in a cell" do
307
- it "should not have a cell for 'other elements'" do
308
- @page = FactoryGirl.build(:page, :page_layout => 'foo')
309
- @page.stub!(:layout_description).and_return({'name' => "foo", 'cells' => ["foo_cell"], 'elements' => ["1", "2"]})
310
- @cell_descriptions = [{'name' => "foo_cell", 'elements' => ["1", "2"]}]
311
- Cell.stub!(:definitions).and_return(@cell_descriptions)
312
- @page.elements_grouped_by_cells.keys.collect(&:name).should_not include('for_other_elements')
313
- end
299
+ before do
300
+ PageLayout.stub(:get).and_return({
301
+ 'name' => 'standard',
302
+ 'cells' => ['header'],
303
+ 'elements' => ['header', 'text'],
304
+ 'autogenerate' => ['header', 'text']
305
+ })
306
+ Cell.stub!(:definitions).and_return([{
307
+ 'name' => "header",
308
+ 'elements' => ["header"]
309
+ }])
310
+ @page = FactoryGirl.create(:public_page, :do_not_autogenerate => false)
314
311
  end
315
312
 
316
- context "with elements defined that are not defined in a cell" do
317
- it "should have a cell for 'other elements'" do
318
- @page = FactoryGirl.build(:page, :page_layout => 'foo')
319
- @page.stub!(:layout_description).and_return({'name' => "foo", 'cells' => ["foo_cell"], 'elements' => ["1", "2", "3"]})
320
- @cell_descriptions = [{'name' => "foo_cell", 'elements' => ["1", "2"]}]
321
- Cell.stub!(:definitions).and_return(@cell_descriptions)
322
- @page.elements_grouped_by_cells.keys.collect(&:name).should include('for_other_elements')
323
- end
313
+ it "should return elements grouped by cell" do
314
+ @page.elements_grouped_by_cells.keys.first.should be_instance_of(Cell)
315
+ @page.elements_grouped_by_cells.values.first.first.should be_instance_of(Element)
316
+ end
317
+
318
+ it "should only include elements beeing in a cell " do
319
+ @page.elements_grouped_by_cells.keys.should_not include(nil)
324
320
  end
325
321
 
326
322
  end
@@ -330,13 +326,13 @@ module Alchemy
330
326
  context "with clipboard holding pages having non unique page layout" do
331
327
 
332
328
  it "should return the pages" do
333
- page_1 = FactoryGirl.create(:page, :language => @language)
334
- page_2 = FactoryGirl.create(:page, :language => @language, :name => 'Another page')
329
+ page_1 = FactoryGirl.create(:page, :language => language)
330
+ page_2 = FactoryGirl.create(:page, :language => language, :name => 'Another page')
335
331
  clipboard = [
336
332
  {:id => page_1.id, :action => "copy"},
337
333
  {:id => page_2.id, :action => "copy"}
338
334
  ]
339
- Page.all_from_clipboard_for_select(clipboard, @language.id).should include(page_1, page_2)
335
+ Page.all_from_clipboard_for_select(clipboard, language.id).should include(page_1, page_2)
340
336
  end
341
337
 
342
338
  end
@@ -344,11 +340,11 @@ module Alchemy
344
340
  context "with clipboard holding a page having unique page layout" do
345
341
 
346
342
  it "should not return any pages" do
347
- page_1 = FactoryGirl.create(:page, :language => @language, :page_layout => 'contact')
343
+ page_1 = FactoryGirl.create(:page, :language => language, :page_layout => 'contact')
348
344
  clipboard = [
349
345
  {:id => page_1.id, :action => "copy"}
350
346
  ]
351
- Page.all_from_clipboard_for_select(clipboard, @language.id).should == []
347
+ Page.all_from_clipboard_for_select(clipboard, language.id).should == []
352
348
  end
353
349
 
354
350
  end
@@ -356,13 +352,13 @@ module Alchemy
356
352
  context "with clipboard holding two pages. One having a unique page layout." do
357
353
 
358
354
  it "should return one page" do
359
- page_1 = FactoryGirl.create(:page, :language => @language, :page_layout => 'standard')
360
- page_2 = FactoryGirl.create(:page, :name => 'Another page', :language => @language, :page_layout => 'contact')
355
+ page_1 = FactoryGirl.create(:page, :language => language, :page_layout => 'standard')
356
+ page_2 = FactoryGirl.create(:page, :name => 'Another page', :language => language, :page_layout => 'contact')
361
357
  clipboard = [
362
358
  {:id => page_1.id, :action => "copy"},
363
359
  {:id => page_2.id, :action => "copy"}
364
360
  ]
365
- Page.all_from_clipboard_for_select(clipboard, @language.id).should == [page_1]
361
+ Page.all_from_clipboard_for_select(clipboard, language.id).should == [page_1]
366
362
  end
367
363
 
368
364
  end
@@ -372,26 +368,30 @@ module Alchemy
372
368
  describe "validations" do
373
369
 
374
370
  context "saving a normal content page" do
371
+
375
372
  it "should be possible to save when its urlname already exists in the scope of global pages" do
376
- @contentpage = FactoryGirl.create(:page, :urlname => "existing_twice")
377
- @global_with_same_urlname = FactoryGirl.create(:page, :urlname => "existing_twice", :layoutpage => true)
378
- @contentpage.title = "new Title"
379
- @contentpage.save.should == true
373
+ contentpage = FactoryGirl.create(:page, :urlname => "existing_twice")
374
+ global_with_same_urlname = FactoryGirl.create(:page, :urlname => "existing_twice", :layoutpage => true)
375
+ contentpage.title = "new Title"
376
+ contentpage.save.should == true
380
377
  end
378
+
381
379
  end
382
380
 
383
381
  context "creating a normal content page" do
384
382
 
385
- before(:each) do
386
- @contentpage = FactoryGirl.build(:page, :parent_id => nil, :page_layout => nil)
383
+ before do
384
+ @contentpage = FactoryGirl.build(:page)
387
385
  end
388
386
 
389
387
  it "should validate the page_layout" do
388
+ @contentpage.page_layout = nil
390
389
  @contentpage.save
391
390
  @contentpage.should have(1).error_on(:page_layout)
392
391
  end
393
392
 
394
393
  it "should validate the parent_id" do
394
+ @contentpage.parent_id = nil
395
395
  @contentpage.save
396
396
  @contentpage.should have(1).error_on(:parent_id)
397
397
  end
@@ -400,7 +400,7 @@ module Alchemy
400
400
 
401
401
  context "creating the rootpage without parent_id and page_layout" do
402
402
 
403
- before(:each) do
403
+ before do
404
404
  Page.delete_all
405
405
  @rootpage = FactoryGirl.build(:page, :parent_id => nil, :page_layout => nil, :name => 'Rootpage')
406
406
  end
@@ -414,7 +414,7 @@ module Alchemy
414
414
 
415
415
  context "saving a systempage" do
416
416
 
417
- before(:each) do
417
+ before do
418
418
  @systempage = FactoryGirl.build(:systempage)
419
419
  end
420
420
 
@@ -431,8 +431,8 @@ module Alchemy
431
431
 
432
432
  context "a normal page" do
433
433
 
434
- before(:each) do
435
- @page = FactoryGirl.build(:page, :language_code => nil, :language => FactoryGirl.create(:language))
434
+ before do
435
+ @page = FactoryGirl.build(:page, :language_code => nil, :language => klingonian, :do_not_autogenerate => false)
436
436
  end
437
437
 
438
438
  it "should get the language code for language" do
@@ -445,9 +445,33 @@ module Alchemy
445
445
  @page.elements.should_not be_empty
446
446
  end
447
447
 
448
+ context "with cells" do
449
+
450
+ before do
451
+ @page.stub!(:definition).and_return({'name' => 'with_cells', 'cells' => ['header', 'main']})
452
+ end
453
+
454
+ it "should have the generated elements in their cells" do
455
+ @page.stub!(:cell_definitions).and_return([{'name' => 'header', 'elements' => ['article']}])
456
+ @page.save
457
+ @page.cells.where(:name => 'header').first.elements.should_not be_empty
458
+ end
459
+
460
+ context "and no elements in cell definitions" do
461
+
462
+ it "should have the elements in the nil cell" do
463
+ @page.stub!(:cell_definitions).and_return([{'name' => 'header', 'elements' => []}])
464
+ @page.save
465
+ @page.cells.collect(&:elements).flatten.should be_empty
466
+ end
467
+
468
+ end
469
+
470
+ end
471
+
448
472
  context "with children getting restricted set to true" do
449
473
 
450
- before(:each) do
474
+ before do
451
475
  @page.save
452
476
  @child1 = FactoryGirl.create(:page, :name => 'Child 1', :parent_id => @page.id)
453
477
  @page.reload
@@ -464,7 +488,7 @@ module Alchemy
464
488
 
465
489
  context "with restricted parent gets created" do
466
490
 
467
- before(:each) do
491
+ before do
468
492
  @page.save
469
493
  @page.parent.update_attributes(:restricted => true)
470
494
  @new_page = FactoryGirl.create(:page, :name => 'New Page', :parent_id => @page.id)
@@ -478,7 +502,7 @@ module Alchemy
478
502
 
479
503
  context "with do_not_autogenerate set to true" do
480
504
 
481
- before(:each) do
505
+ before do
482
506
  @page.do_not_autogenerate = true
483
507
  end
484
508
 
@@ -493,7 +517,7 @@ module Alchemy
493
517
 
494
518
  context "a systempage" do
495
519
 
496
- before(:each) do
520
+ before do
497
521
  @page = FactoryGirl.create(:systempage)
498
522
  end
499
523
 
@@ -511,16 +535,60 @@ module Alchemy
511
535
 
512
536
  describe '#fold' do
513
537
 
514
- before(:each) do
515
- @page = FactoryGirl.create(:public_page)
538
+ before do
516
539
  @user = FactoryGirl.create(:admin_user, :email => 'faz@baz.com', :login => 'foo_baz')
517
540
  end
518
541
 
519
542
  context "with folded status set to true" do
520
543
 
521
544
  it "should create a folded page for user" do
522
- @page.fold(@user.id, true)
523
- FoldedPage.find_or_create_by_user_id_and_page_id(@user.id, @page.id).should_not be_nil
545
+ public_page.fold(@user.id, true)
546
+ FoldedPage.find_or_create_by_user_id_and_page_id(@user.id, public_page.id).should_not be_nil
547
+ end
548
+
549
+ end
550
+
551
+ end
552
+
553
+ describe 'previous and next. ' do
554
+
555
+ let(:center_page) { FactoryGirl.create(:public_page, :name => 'Center Page') }
556
+ let(:next_page) { FactoryGirl.create(:public_page, :name => 'Next Page') }
557
+
558
+ before do
559
+ public_page
560
+ center_page
561
+ next_page
562
+ end
563
+
564
+ describe '#previous' do
565
+
566
+ it "should return the previous page on the same level" do
567
+ center_page.previous.should == public_page
568
+ end
569
+
570
+ context "no previous page on same level present" do
571
+
572
+ it "should return nil" do
573
+ public_page.previous.should be_nil
574
+ end
575
+
576
+ end
577
+
578
+ end
579
+
580
+ describe '#next' do
581
+
582
+ it "should return the next page on the same level" do
583
+ center_page.next.should == next_page
584
+ end
585
+
586
+ context "no next page on same level present" do
587
+
588
+ it "should return nil" do
589
+ next_page.next.should be_nil
590
+ end
591
+
524
592
  end
525
593
 
526
594
  end