alchemy_cms 2.1.beta6 → 2.1.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. data/.gitignore +3 -1
  2. data/Gemfile +10 -2
  3. data/Guardfile +16 -0
  4. data/README.md +3 -3
  5. data/Rakefile +0 -5
  6. data/alchemy_cms.gemspec +1 -9
  7. data/app/assets/javascripts/alchemy/alchemy.base.js +5 -4
  8. data/app/assets/javascripts/alchemy/{alchemy.dragndrop.js.erb → alchemy.dragndrop.js} +0 -0
  9. data/app/assets/javascripts/alchemy/alchemy.elements_window.js +96 -0
  10. data/app/assets/javascripts/alchemy/alchemy.image_cropper.js +48 -50
  11. data/app/assets/javascripts/alchemy/alchemy.jquery_loader.js +41 -0
  12. data/app/assets/javascripts/alchemy/alchemy.js +2 -0
  13. data/app/assets/javascripts/alchemy/alchemy.menubar.js +55 -0
  14. data/app/assets/javascripts/alchemy/alchemy.preview.js +94 -139
  15. data/app/assets/javascripts/alchemy/alchemy.preview_window.js +98 -0
  16. data/app/assets/javascripts/alchemy/alchemy.windows.js +1 -174
  17. data/app/assets/javascripts/alchemy/menubar.js +2 -0
  18. data/app/assets/javascripts/alchemy/preview.js +2 -1
  19. data/app/assets/stylesheets/alchemy/_defaults.scss +7 -8
  20. data/app/assets/stylesheets/alchemy/base.css.scss +29 -33
  21. data/app/assets/stylesheets/alchemy/elements.css.scss +4 -4
  22. data/app/assets/stylesheets/alchemy/jquery-ui.alchemy.css.scss +1 -1
  23. data/app/assets/stylesheets/alchemy/jquery.Jcrop.css.scss +1 -1
  24. data/app/assets/stylesheets/alchemy/jquery.sb.css.scss +19 -4
  25. data/app/assets/stylesheets/alchemy/menubar.css.scss +85 -0
  26. data/app/assets/stylesheets/alchemy/standard_set.css +3 -5
  27. data/app/assets/stylesheets/alchemy/tinymce_content.css.scss +1 -1
  28. data/app/assets/stylesheets/alchemy/tinymce_dialog.css.scss +1 -1
  29. data/app/controllers/alchemy/admin/attachments_controller.rb +2 -18
  30. data/app/controllers/alchemy/admin/base_controller.rb +1 -1
  31. data/app/controllers/alchemy/admin/elements_controller.rb +2 -2
  32. data/app/controllers/alchemy/admin/essence_files_controller.rb +4 -2
  33. data/app/controllers/alchemy/admin/pictures_controller.rb +6 -20
  34. data/app/controllers/alchemy/admin/resources_controller.rb +7 -5
  35. data/app/controllers/alchemy/base_controller.rb +14 -4
  36. data/app/controllers/alchemy/messages_controller.rb +4 -4
  37. data/app/controllers/alchemy/pages_controller.rb +51 -32
  38. data/app/controllers/alchemy/pictures_controller.rb +0 -3
  39. data/app/controllers/alchemy/user_sessions_controller.rb +1 -1
  40. data/app/helpers/alchemy/admin/base_helper.rb +6 -4
  41. data/app/helpers/alchemy/base_helper.rb +26 -0
  42. data/app/helpers/alchemy/pages_helper.rb +42 -22
  43. data/app/models/alchemy/attachment.rb +10 -2
  44. data/app/models/alchemy/cell.rb +1 -0
  45. data/app/models/alchemy/content.rb +8 -6
  46. data/app/models/alchemy/element.rb +1 -1
  47. data/app/models/alchemy/essence_audio.rb +1 -8
  48. data/app/models/alchemy/essence_date.rb +2 -9
  49. data/app/models/alchemy/essence_file.rb +1 -8
  50. data/app/models/alchemy/essence_flash.rb +0 -7
  51. data/app/models/alchemy/essence_html.rb +1 -8
  52. data/app/models/alchemy/essence_picture.rb +0 -11
  53. data/app/models/alchemy/essence_richtext.rb +4 -12
  54. data/app/models/alchemy/essence_text.rb +1 -13
  55. data/app/models/alchemy/essence_video.rb +1 -8
  56. data/app/models/alchemy/page.rb +28 -22
  57. data/app/models/alchemy/picture.rb +19 -0
  58. data/app/sweepers/alchemy/pages_sweeper.rb +17 -6
  59. data/app/sweepers/alchemy/pictures_sweeper.rb +1 -3
  60. data/app/views/alchemy/admin/attachments/_archive_overlay.html.erb +2 -2
  61. data/app/views/alchemy/admin/attachments/_attachment.html.erb +1 -1
  62. data/app/views/alchemy/admin/attachments/_file_to_assign.html.erb +2 -2
  63. data/app/views/alchemy/admin/attachments/_files_list.html.erb +13 -11
  64. data/app/views/alchemy/admin/attachments/create.js.erb +1 -1
  65. data/app/views/alchemy/admin/attachments/edit.html.erb +2 -2
  66. data/app/views/alchemy/admin/elements/_new_element_form.html.erb +1 -2
  67. data/app/views/alchemy/admin/elements/new.html.erb +1 -1
  68. data/app/views/alchemy/admin/essence_files/edit.html.erb +32 -32
  69. data/app/views/alchemy/admin/essence_pictures/crop.html.erb +29 -29
  70. data/app/views/alchemy/admin/essence_pictures/update.js.erb +13 -12
  71. data/app/views/alchemy/admin/pages/_create_language_form.html.erb +4 -1
  72. data/app/views/alchemy/admin/pages/_new_page_form.html.erb +1 -1
  73. data/app/views/alchemy/admin/pages/edit.html.erb +8 -8
  74. data/app/views/alchemy/admin/pages/index.html.erb +1 -1
  75. data/app/views/alchemy/admin/pages/new.html.erb +1 -1
  76. data/app/views/alchemy/admin/pages/update.js.erb +19 -12
  77. data/app/views/alchemy/admin/pictures/_picture.html.erb +1 -1
  78. data/app/views/alchemy/admin/pictures/_pictures_list.html.erb +8 -6
  79. data/app/views/alchemy/admin/pictures/show_in_window.html.erb +6 -1
  80. data/app/views/alchemy/admin/resources/_table.html.erb +1 -1
  81. data/app/views/alchemy/admin/users/_table.html.erb +13 -13
  82. data/app/views/alchemy/admin/users/_user.html.erb +1 -1
  83. data/app/views/alchemy/admin/users/index.html.erb +2 -2
  84. data/app/views/alchemy/elements/_contactform_view.html.erb +78 -78
  85. data/app/views/alchemy/elements/_download_editor.html.erb +1 -0
  86. data/app/views/alchemy/elements/_download_view.html.erb +3 -0
  87. data/app/views/alchemy/essences/_essence_date_editor.html.erb +1 -1
  88. data/app/views/alchemy/essences/_essence_file_editor.html.erb +1 -0
  89. data/app/views/alchemy/essences/_essence_file_view.html.erb +6 -2
  90. data/app/views/alchemy/essences/_essence_picture_editor.html.erb +3 -2
  91. data/app/views/alchemy/essences/_essence_picture_view.html.erb +1 -1
  92. data/app/views/alchemy/navigation/_link.html.erb +1 -2
  93. data/app/views/alchemy/notifications/admin_user_created.text.erb +7 -7
  94. data/app/views/alchemy/notifications/registered_user_created.text.erb +5 -5
  95. data/app/views/alchemy/user_sessions/login.html.erb +34 -35
  96. data/app/views/layouts/alchemy/login.html.erb +3 -8
  97. data/app/views/layouts/alchemy/pages.html.erb +1 -0
  98. data/bin/alchemy +43 -75
  99. data/config/alchemy/config.yml +10 -0
  100. data/config/alchemy/elements.yml +5 -0
  101. data/config/alchemy/page_layouts.yml +1 -1
  102. data/config/locales/alchemy.de.yml +21 -8
  103. data/config/locales/alchemy.en.yml +20 -4
  104. data/config/routes.rb +25 -20
  105. data/db/migrate/{20111116125112_namespace_models.rb → 20111116125112_namespace_alchemy_models.rb} +1 -1
  106. data/lib/alchemy/capistrano.rb +4 -17
  107. data/lib/alchemy/engine.rb +2 -0
  108. data/lib/alchemy/essence.rb +29 -41
  109. data/lib/alchemy/i18n.rb +1 -1
  110. data/lib/alchemy/mount_point.rb +10 -0
  111. data/lib/alchemy/page_layout.rb +7 -7
  112. data/lib/alchemy/seeder.rb +85 -47
  113. data/lib/alchemy/upgrader.rb +115 -0
  114. data/lib/alchemy/version.rb +1 -1
  115. data/lib/alchemy_cms.rb +4 -3
  116. data/lib/rails/generators/alchemy/scaffold/scaffold_generator.rb +6 -2
  117. data/lib/tasks/ferret.rake +12 -0
  118. data/lib/tasks/install.rake +16 -105
  119. data/lib/tasks/routes.rake +29 -0
  120. data/lib/tasks/upgrade.rake +5 -67
  121. data/spec/controllers/admin/pages_controller_spec.rb +1 -1
  122. data/spec/controllers/pages_controller_spec.rb +31 -0
  123. data/spec/factories.rb +24 -15
  124. data/spec/helpers/admin/base_helper_spec.rb +0 -7
  125. data/spec/helpers/pages_helper_spec.rb +54 -29
  126. data/spec/helpers/url_helpers_spec.rb +40 -0
  127. data/spec/integration/admin/pages_controller_spec.rb +3 -3
  128. data/spec/integration/pages_controller_spec.rb +80 -6
  129. data/spec/integration/security_spec.rb +2 -2
  130. data/spec/models/content_spec.rb +24 -0
  131. data/spec/models/page_spec.rb +174 -47
  132. data/spec/models/picture_spec.rb +54 -0
  133. data/spec/page_layout_spec.rb +2 -2
  134. data/spec/routing_spec.rb +205 -1
  135. data/spec/spec_helper.rb +53 -32
  136. metadata +51 -46
  137. data/lib/alchemy/file_utilz.rb +0 -73
@@ -4,7 +4,7 @@ describe Alchemy::PagesController do
4
4
 
5
5
  before(:each) do
6
6
  @default_language = Alchemy::Language.get_default
7
- @default_language_root = Factory(:language_root_page, :language => @default_language, :name => 'Home', :public => true)
7
+ @default_language_root = Factory(:language_root_page, :language => @default_language, :name => 'Home')
8
8
  end
9
9
 
10
10
  describe "#show" do
@@ -28,7 +28,7 @@ describe Alchemy::PagesController do
28
28
 
29
29
  end
30
30
 
31
- context "fulltext search" do
31
+ describe "fulltext search" do
32
32
 
33
33
  before(:each) do
34
34
  @page = Factory(:public_page, :language => @default_language, :visible => true, :name => 'Page 1', :parent_id => @default_language_root.id)
@@ -55,16 +55,38 @@ describe Alchemy::PagesController do
55
55
  within('div#content .search_result') { page.should have_content('Petshop') }
56
56
  end
57
57
 
58
+ it "should not find contents placed on global-pages (layoutpage => true)" do
59
+ @page.update_attributes(:layoutpage => true)
60
+ @element.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true)
61
+ visit('/alchemy/suche?query=Petshop')
62
+ within('div#content') { page.should have_css('h2.no_search_results') }
63
+ end
64
+
65
+ it "should not find contents placed on unpublished pages (public => false)" do
66
+ @page.update_attributes(:public => false)
67
+ @element.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true)
68
+ visit('/alchemy/suche?query=Petshop')
69
+ within('div#content') { page.should have_css('h2.no_search_results') }
70
+ end
71
+
72
+ it "should not find contents placed on restricted pages (restricted => true)" do
73
+ @page.update_attributes(:restricted => true)
74
+ @element.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true)
75
+ visit('/alchemy/suche?query=Petshop')
76
+ within('div#content') { page.should have_css('h2.no_search_results') }
77
+ end
78
+
58
79
  end
59
80
 
60
81
  end
61
82
 
62
- context "redirecting" do
83
+ describe "redirecting" do
63
84
 
64
- context "in multi language mode" do
85
+ context "in multi language mode", :focus => true do
65
86
 
66
87
  before(:each) do
67
88
  @page = Factory(:public_page)
89
+ Alchemy::Config.stub!(:get) { |arg| arg == :url_nesting ? true : Alchemy::Config.parameter(arg) }
68
90
  end
69
91
 
70
92
  it "should redirect to url with nested language code" do
@@ -77,9 +99,10 @@ describe Alchemy::PagesController do
77
99
  before(:each) do
78
100
  @page.update_attributes(:public => false, :name => 'Not Public', :urlname => '')
79
101
  @child = Factory(:public_page, :name => 'Public Child', :parent_id => @page.id)
102
+ Alchemy::Config.stub!(:get) { |arg| arg == :url_nesting ? false : Alchemy::Config.parameter(arg) }
80
103
  end
81
104
 
82
- it ", if requested page is unpublished" do
105
+ it "if requested page is unpublished" do
83
106
  visit '/alchemy/kl/not-public'
84
107
  page.current_path.should == '/alchemy/kl/public-child'
85
108
  end
@@ -106,12 +129,63 @@ describe Alchemy::PagesController do
106
129
  page.current_url.should match(/\?query=Peter/)
107
130
  end
108
131
 
132
+ context "url nesting" do
133
+
134
+ before(:each) do
135
+ @level1 = Factory(:public_page, :parent_id => @default_language_root.id, :name => 'catalog', :language => @default_language)
136
+ @level2 = Factory(:public_page, :parent_id => @level1.id, :name => 'products', :language => @default_language)
137
+ @level3 = Factory(:public_page, :parent_id => @level2.id, :name => 'screwdriver', :language => @default_language)
138
+ end
139
+
140
+ context "enabled" do
141
+
142
+ before(:each) do
143
+ Alchemy::Config.stub!(:get) { |arg| arg == :url_nesting ? true : Alchemy::Config.parameter(arg) }
144
+ end
145
+
146
+ context "requesting a non nested url" do
147
+
148
+ it "should redirect to nested url" do
149
+ visit "/alchemy/de/screwdriver"
150
+ page.current_path.should == '/alchemy/de/catalog/products/screwdriver'
151
+ end
152
+
153
+ it "should only redirect to nested url if page is nested" do
154
+ visit "/alchemy/de/catalog"
155
+ page.status_code.should == 200
156
+ page.current_path.should == "/alchemy/de/catalog"
157
+ end
158
+
159
+ end
160
+
161
+ end
162
+
163
+ context "disabled" do
164
+
165
+ before(:each) do
166
+ Alchemy::Config.stub!(:get) { |arg| arg == :url_nesting ? false : Alchemy::Config.parameter(arg) }
167
+ end
168
+
169
+ context "requesting a nested url" do
170
+
171
+ it "should redirect to not nested url" do
172
+ visit "/alchemy/de/catalog/products/screwdriver"
173
+ page.current_path.should == "/alchemy/de/screwdriver"
174
+ end
175
+
176
+ end
177
+
178
+ end
179
+
180
+ end
181
+
109
182
  end
110
183
 
111
184
  context "not in multi language mode" do
112
185
 
113
186
  before(:each) do
114
187
  @page = Factory(:public_page, :language => @default_language, :parent_id => @default_language_root.id)
188
+ Alchemy::Config.stub!(:get) { |arg| arg == :url_nesting ? false : Alchemy::Config.parameter(arg) }
115
189
  end
116
190
 
117
191
  it "should redirect from nested language code url to normal url" do
@@ -140,7 +214,7 @@ describe Alchemy::PagesController do
140
214
  @child = Factory(:public_page, :name => 'Public Child', :parent_id => @page.id, :language => @default_language)
141
215
  end
142
216
 
143
- it ", if requested page is unpublished" do
217
+ it "if requested page is unpublished" do
144
218
  visit '/alchemy/not-public'
145
219
  page.current_path.should == '/alchemy/public-child'
146
220
  end
@@ -12,7 +12,7 @@ describe "Security: " do
12
12
 
13
13
  it "render the signup view" do
14
14
  visit '/alchemy/'
15
- within('#alchemy_greeting') { page.should have_content('signup') }
15
+ within('#alchemy_greeting') { page.should have_content('Signup') }
16
16
  end
17
17
  end
18
18
 
@@ -39,7 +39,7 @@ describe "Security: " do
39
39
  visit '/alchemy/admin/login'
40
40
  fill_in('alchemy_user_session_login', :with => 'jdoe')
41
41
  fill_in('alchemy_user_session_password', :with => 's3cr3t')
42
- click_on('Login')
42
+ click_on('login')
43
43
  end
44
44
 
45
45
  it "should be redirected to dashboard" do
@@ -48,4 +48,28 @@ describe Alchemy::Content do
48
48
 
49
49
  end
50
50
 
51
+ describe '#update_essence' do
52
+
53
+ it "should update the attributes of related essence and return true" do
54
+ @element = Factory(:element, :name => 'text')
55
+ @content = @element.contents.first
56
+ @content.update_essence(:body => 'Mikes Petshop')
57
+ @content.ingredient.should == "Mikes Petshop"
58
+ end
59
+
60
+ it "should add error messages if save fails and return false" do
61
+ @element = Factory(:element, :name => 'contactform')
62
+ @content = @element.contents.first
63
+ @content.update_essence
64
+ @content.errors[:essence].should have(1).item
65
+ end
66
+
67
+ it "should raise error if essence is missing" do
68
+ @element = Factory(:element, :name => 'text')
69
+ @content = @element.contents.first
70
+ @content.update_essence
71
+ end
72
+
73
+ end
74
+
51
75
  end
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  describe Alchemy::Page do
6
6
 
7
7
  before(:each) do
8
- @rootpage = Alchemy::Page.rootpage
8
+ @rootpage = Alchemy::Page.root
9
9
  @language = Alchemy::Language.get_default
10
- @language_root = Factory(:page, :parent_id => @rootpage.id, :language => @language, :language_root => true, :page_layout => 'intro')
10
+ @language_root = Factory(:language_root_page, :name => 'Default Language Root', :language => @language)
11
11
  end
12
12
 
13
13
  describe ".layout_description" do
@@ -104,46 +104,37 @@ describe Alchemy::Page do
104
104
  end
105
105
 
106
106
  end
107
-
108
- context "create" do
109
- it "the rootpage with page_layout rootpage does not need a parent_id" do
110
- @rootpage.rootpage?.should be_true
111
- end
112
-
113
- it "all pages except the rootpage must have a parent_id" do
114
- page = Factory.build(:page, :page_layout => "anypage", :parent_id => nil, :language => @language)
115
- page.valid?
116
- page.should have(1).error_on(:parent_id)
117
- end
118
-
119
- it "must not be created if the page_layout is set to 'rootpage' and a page already exists with this page_layout and parent_id = nil" do
120
- page = Factory.build(:page, :name => "anypage", :page_layout => "rootpage", :parent_id => @language_root.id, :language => @language)
121
- page.valid?
122
- page.should have(1).error_on(:page_layout)
123
- end
124
-
125
- it "should get a webfriendly urlname on create" do
126
- page = Factory(:page, :name => 'klingon$&stößel ', :language => @language, :parent_id => @language_root.id)
127
- page.urlname.should == 'klingon-stoessel'
128
- end
129
107
 
130
- it "should generate a three letter urlname from two letter name" do
131
- page = Factory(:page, :name => 'Au', :language => @language, :parent_id => @language_root.id)
132
- page.urlname.should == '-au'
133
- end
108
+ describe '#create' do
134
109
 
135
- it "should generate a three letter urlname from two letter name with umlaut" do
136
- page = Factory(:page, :name => 'Aü', :language => @language, :parent_id => @language_root.id)
137
- page.urlname.should == 'aue'
138
- end
110
+ context "generate urlnames" do
111
+
112
+ it "should get a webfriendly urlname" do
113
+ page = Factory(:page, :name => 'klingon$&stößel ', :language => @language, :parent_id => @language_root.id)
114
+ page.urlname.should == 'klingon-stoessel'
115
+ end
116
+
117
+ it "should generate a three letter urlname from two letter name" do
118
+ page = Factory(:page, :name => 'Au', :language => @language, :parent_id => @language_root.id)
119
+ page.urlname.should == '-au'
120
+ end
121
+
122
+ it "should generate a three letter urlname from two letter name with umlaut" do
123
+ page = Factory(:page, :name => 'Aü', :language => @language, :parent_id => @language_root.id)
124
+ page.urlname.should == 'aue'
125
+ end
126
+
127
+ it "should generate a three letter urlname from one letter name" do
128
+ page = Factory(:page, :name => 'A', :language => @language, :parent_id => @language_root.id)
129
+ page.urlname.should == '--a'
130
+ end
131
+
132
+ end
139
133
 
140
- it "should generate a three letter urlname from one letter name" do
141
- page = Factory(:page, :name => 'A', :language => @language, :parent_id => @language_root.id)
142
- page.urlname.should == '--a'
143
- end
144
134
  end
145
-
135
+
146
136
  context "with children" do
137
+
147
138
  before(:each) do
148
139
  @first_child = Factory(:page, :name => "First child", :language => @language, :public => false, :parent_id => @language_root.id)
149
140
  @first_child.move_to_child_of(@language_root)
@@ -151,7 +142,7 @@ describe Alchemy::Page do
151
142
  @first_public_child = Factory(:page, :name => "First public child", :language => @language, :parent_id => @language_root.id, :public => true)
152
143
  @first_public_child.move_to_child_of(@language_root)
153
144
  end
154
-
145
+
155
146
  it "should return a page object (or nil if no public child exists) for first_public_child" do
156
147
  if @language_root.children.any?
157
148
  @language_root.first_public_child.should == @first_public_child
@@ -159,23 +150,28 @@ describe Alchemy::Page do
159
150
  @language_root.first_public_child.should == nil
160
151
  end
161
152
  end
153
+
162
154
  end
163
-
155
+
164
156
  context ".public" do
165
- it "should return 2 pages that are public" do
157
+
158
+ it "should return pages that are public" do
166
159
  Factory(:public_page, :name => 'First Public Child', :parent_id => @language_root.id, :language => @language)
167
160
  Factory(:public_page, :name => 'Second Public Child', :parent_id => @language_root.id, :language => @language)
168
- Alchemy::Page.published.should have(2).pages
169
- end
161
+ Alchemy::Page.published.should have(3).pages
162
+ end
163
+
170
164
  end
171
-
165
+
172
166
  context ".not_locked" do
173
- it "should return 3 pages that are not blocked by a user at the moment" do
174
- Factory(:public_page, :locked => true, :name => 'First Public Child', :parent_id => @language_root.id, :language => @language)
167
+
168
+ it "should return pages that are not blocked by a user at the moment" do
169
+ Factory(:public_page, :locked => true, :name => 'First Public Child', :parent_id => @language_root.id, :language => @language)
175
170
  Factory(:public_page, :name => 'Second Public Child', :parent_id => @language_root.id, :language => @language)
176
- Alchemy::Page.not_locked.should have(3).pages
177
- end
171
+ Alchemy::Page.not_locked.should have(3).pages
172
+ end
178
173
  end
174
+
179
175
  context ".all_locked" do
180
176
  it "should return 1 page that is blocked by a user at the moment" do
181
177
  Factory(:public_page, :locked => true, :name => 'First Public Child', :parent_id => @language_root.id, :language => @language)
@@ -307,4 +303,135 @@ describe Alchemy::Page do
307
303
 
308
304
  end
309
305
 
306
+ describe "validations" do
307
+
308
+ context "creating a normal content page" do
309
+
310
+ before(:each) do
311
+ @contentpage = Factory.build(:page, :parent_id => nil, :page_layout => nil)
312
+ end
313
+
314
+ it "should validate the page_layout" do
315
+ @contentpage.save
316
+ @contentpage.should have(1).error_on(:page_layout)
317
+ end
318
+
319
+ it "should validate the parent_id" do
320
+ @contentpage.save
321
+ @contentpage.should have(1).error_on(:parent_id)
322
+ end
323
+
324
+ end
325
+
326
+ context "creating the rootpage without parent_id and page_layout" do
327
+
328
+ before(:each) do
329
+ Alchemy::Page.delete_all
330
+ @rootpage = Factory.build(:page, :parent_id => nil, :page_layout => nil, :name => 'Rootpage')
331
+ end
332
+
333
+ it "should be valid" do
334
+ @rootpage.save
335
+ @rootpage.should be_valid
336
+ end
337
+
338
+ end
339
+
340
+ context "saving a systempage" do
341
+
342
+ before(:each) do
343
+ @systempage = Factory.build(:systempage)
344
+ end
345
+
346
+ it "should not validate the page_layout" do
347
+ @systempage.save
348
+ @systempage.should be_valid
349
+ end
350
+
351
+ end
352
+
353
+ end
354
+
355
+ describe 'before and after filters' do
356
+
357
+ context "a normal page" do
358
+
359
+ before(:each) do
360
+ @page = Factory.build(:page, :language_code => nil, :language => Factory(:language))
361
+ end
362
+
363
+ it "should get the language code for language" do
364
+ @page.save
365
+ @page.language_code.should == "kl"
366
+ end
367
+
368
+ it "should autogenerate the elements" do
369
+ @page.save
370
+ @page.elements.should_not be_empty
371
+ end
372
+
373
+ context "with children getting restricted set to true" do
374
+
375
+ before(:each) do
376
+ @page.save
377
+ @child1 = Factory(:page, :name => 'Child 1', :parent_id => @page.id)
378
+ @page.reload
379
+ @page.restricted = true
380
+ @page.save
381
+ end
382
+
383
+ it "should restrict all its children" do
384
+ @child1.reload
385
+ @child1.restricted?.should be_true
386
+ end
387
+
388
+ end
389
+
390
+ context "with restricted parent gets created" do
391
+
392
+ before(:each) do
393
+ @page.save
394
+ @page.parent.update_attributes(:restricted => true)
395
+ @new_page = Factory(:page, :name => 'New Page', :parent_id => @page.id)
396
+ end
397
+
398
+ it "should also be restricted" do
399
+ @new_page.restricted?.should be_true
400
+ end
401
+
402
+ end
403
+
404
+ context "with do_not_autogenerate set to true" do
405
+
406
+ before(:each) do
407
+ @page.do_not_autogenerate = true
408
+ end
409
+
410
+ it "should not autogenerate the elements" do
411
+ @page.save
412
+ @page.elements.should be_empty
413
+ end
414
+
415
+ end
416
+
417
+ end
418
+
419
+ context "a systempage" do
420
+
421
+ before(:each) do
422
+ @page = Factory(:systempage)
423
+ end
424
+
425
+ it "should not get the language code for language" do
426
+ @page.language_code.should be_nil
427
+ end
428
+
429
+ it "should not autogenerate the elements" do
430
+ @page.elements.should be_empty
431
+ end
432
+
433
+ end
434
+
435
+ end
436
+
310
437
  end