alchemy_cms 2.2.rc8 → 2.2.rc11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/app/assets/javascripts/alchemy/alchemy.page_sorter.js +1 -1
- data/app/assets/stylesheets/alchemy/sitemap.css.scss +14 -13
- data/app/assets/stylesheets/alchemy/standard_set.css +9 -10
- data/app/controllers/alchemy/admin/pages_controller.rb +1 -0
- data/app/controllers/alchemy/base_controller.rb +2 -1
- data/app/helpers/alchemy/admin/essences_helper.rb +1 -0
- data/app/helpers/alchemy/elements_helper.rb +2 -10
- data/app/helpers/alchemy/essences_helper.rb +1 -0
- data/app/helpers/alchemy/pages_helper.rb +31 -13
- data/app/models/alchemy/attachment.rb +1 -1
- data/app/models/alchemy/content.rb +8 -8
- data/app/models/alchemy/element.rb +14 -10
- data/app/models/alchemy/essence_file.rb +1 -1
- data/app/models/alchemy/message.rb +9 -9
- data/app/models/alchemy/page.rb +4 -3
- data/app/models/alchemy/picture.rb +1 -1
- data/app/models/alchemy/user.rb +1 -1
- data/app/sweepers/alchemy/content_sweeper.rb +29 -6
- data/app/views/alchemy/admin/attachments/new.html.erb +1 -1
- data/app/views/alchemy/admin/pages/index.html.erb +7 -7
- data/app/views/alchemy/admin/pages/sort.js.erb +2 -1
- data/app/views/alchemy/admin/partials/_upload_form.html.erb +2 -2
- data/app/views/alchemy/admin/pictures/new.html.erb +1 -1
- data/app/views/alchemy/essences/_essence_picture_tools.html.erb +2 -2
- data/app/views/alchemy/essences/_essence_text_editor.html.erb +11 -11
- data/app/views/alchemy/navigation/_link.html.erb +20 -20
- data/app/views/alchemy/navigation/_renderer.html.erb +37 -23
- data/config/alchemy/config.yml +107 -65
- data/config/alchemy/elements.yml +12 -1
- data/config/locales/alchemy.de.yml +1 -0
- data/config/locales/alchemy.en.yml +1 -0
- data/lib/alchemy/essence.rb +1 -1
- data/lib/alchemy/page_layout.rb +3 -9
- data/lib/alchemy/resource.rb +5 -5
- data/lib/alchemy/version.rb +1 -1
- data/lib/rails/generators/alchemy/scaffold/scaffold_generator.rb +2 -2
- data/lib/rails/generators/alchemy/scaffold/{files/page_layouts.yml → templates/page_layouts.yml.tt} +4 -0
- data/spec/config_spec.rb +1 -1
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/helpers/admin/contents_helper_spec.rb +4 -3
- data/spec/helpers/admin/essences_helper_spec.rb +4 -8
- data/spec/helpers/essences_helper_spec.rb +0 -4
- data/spec/helpers/pages_helper_spec.rb +10 -1
- data/spec/integration/admin/modules_integration_spec.rb +25 -21
- data/spec/integration/admin/pages_controller_spec.rb +16 -19
- data/spec/integration/admin/resources_integration_spec.rb +58 -64
- data/spec/integration/pages_controller_spec.rb +24 -3
- data/spec/integration/security_spec.rb +12 -12
- data/spec/libraries/resource_spec.rb +16 -18
- data/spec/models/page_spec.rb +352 -326
- data/spec/page_layout_spec.rb +2 -2
- data/spec/support/alchemy/specs_helpers.rb +16 -1
- metadata +116 -38
- data/spec/support/integration_spec_helper.rb +0 -24
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Alchemy::PagesController do
|
5
5
|
|
6
|
-
before(:
|
6
|
+
before(:all) do
|
7
7
|
@default_language = Alchemy::Language.get_default
|
8
8
|
@default_language_root = FactoryGirl.create(:language_root_page, :language => @default_language, :name => 'Home')
|
9
9
|
end
|
@@ -31,7 +31,7 @@ describe Alchemy::PagesController do
|
|
31
31
|
|
32
32
|
describe "fulltext search" do
|
33
33
|
|
34
|
-
before(:
|
34
|
+
before(:all) do
|
35
35
|
@page = FactoryGirl.create(:public_page, :language => @default_language, :visible => true, :name => 'Page 1', :parent_id => @default_language_root.id)
|
36
36
|
@element = FactoryGirl.create(:element, :name => 'article', :page => @page)
|
37
37
|
FactoryGirl.create(:public_page, :language => @default_language, :name => 'Suche', :page_layout => 'search', :parent_id => @default_language_root.id)
|
@@ -145,7 +145,7 @@ describe Alchemy::PagesController do
|
|
145
145
|
|
146
146
|
context "with url nesting" do
|
147
147
|
|
148
|
-
before(:
|
148
|
+
before(:all) do
|
149
149
|
@level1 = FactoryGirl.create(:public_page, :parent_id => @default_language_root.id, :name => 'catalog', :language => @default_language)
|
150
150
|
@level2 = FactoryGirl.create(:public_page, :parent_id => @level1.id, :name => 'products', :language => @default_language)
|
151
151
|
@level3 = FactoryGirl.create(:public_page, :parent_id => @level2.id, :name => 'screwdriver', :language => @default_language)
|
@@ -256,6 +256,27 @@ describe Alchemy::PagesController do
|
|
256
256
|
|
257
257
|
describe "Handling of non-existing pages" do
|
258
258
|
|
259
|
+
context "when a language root page exists" do
|
260
|
+
|
261
|
+
before(:all) do
|
262
|
+
# We need an admin user, because otherwise we will be redirected to UserSessions controller to create a new user
|
263
|
+
FactoryGirl.create(:admin_user, :login => 'foo-boo', :email => 'foo@boo.org')
|
264
|
+
end
|
265
|
+
|
266
|
+
before(:each) do
|
267
|
+
visit "/alchemy/non-existing-page"
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should render the status code in the title tag" do
|
271
|
+
within("title") { page.should have_content("404") }
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should render the layout" do
|
275
|
+
page.should have_selector("#language_select")
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
279
|
+
|
259
280
|
context "404-Errors are handled by Rails now, so no need to test anymore.
|
260
281
|
However, it still serves as documentation how they can be handled, so we leave it here" do
|
261
282
|
|
@@ -2,13 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Security: " do
|
4
4
|
|
5
|
-
|
5
|
+
before(:all) do
|
6
|
+
Alchemy::Page.root.children.destroy_all
|
7
|
+
Alchemy::User.delete_all
|
8
|
+
# ensuring that we have the correct locale here
|
9
|
+
::I18n.locale = :en
|
10
|
+
end
|
6
11
|
|
7
|
-
|
8
|
-
Alchemy::User.delete_all
|
9
|
-
# ensuring that we have the correct locale here
|
10
|
-
::I18n.locale = :en
|
11
|
-
end
|
12
|
+
context "If no user is present" do
|
12
13
|
|
13
14
|
it "render the signup view" do
|
14
15
|
visit '/alchemy/'
|
@@ -19,7 +20,7 @@ describe "Security: " do
|
|
19
20
|
context "If user is present" do
|
20
21
|
|
21
22
|
before(:all) do
|
22
|
-
|
23
|
+
create_admin_user
|
23
24
|
end
|
24
25
|
|
25
26
|
it "a visitor should not be able to signup" do
|
@@ -35,17 +36,16 @@ describe "Security: " do
|
|
35
36
|
end
|
36
37
|
|
37
38
|
context "that is already logged in" do
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
fill_in('alchemy_user_session_password', :with => 's3cr3t')
|
42
|
-
click_on('Login')
|
39
|
+
|
40
|
+
before(:each) do
|
41
|
+
login_into_alchemy
|
43
42
|
end
|
44
43
|
|
45
44
|
it "should be redirected to dashboard" do
|
46
45
|
visit '/alchemy/admin/login'
|
47
46
|
current_path.should == '/alchemy/admin/dashboard'
|
48
47
|
end
|
48
|
+
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
@@ -29,36 +29,34 @@ describe Alchemy::Resource do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "instance methods" do
|
32
|
-
|
33
|
-
@resource = Alchemy::Resource.new("admin/events")
|
34
|
-
end
|
32
|
+
let(:resource) { Alchemy::Resource.new("admin/events") }
|
35
33
|
|
36
34
|
describe "model" do
|
37
35
|
it "returns resource's model-class" do
|
38
|
-
|
36
|
+
resource.model.should be(Event)
|
39
37
|
end
|
40
38
|
|
41
39
|
describe "resources_name" do
|
42
40
|
it "returns plural name (like events for model Event)" do
|
43
|
-
|
41
|
+
resource.resources_name.should == 'events'
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
45
|
describe "model_name" do
|
48
46
|
it "returns model_name (like event for model Event" do
|
49
|
-
|
47
|
+
resource.model_name.should == 'event'
|
50
48
|
end
|
51
49
|
end
|
52
50
|
|
53
51
|
describe "permission_scope" do
|
54
52
|
it "should return the permissions_scope usable in declarative authorization" do
|
55
|
-
|
53
|
+
resource.permission_scope.should == :admin_events
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
59
57
|
describe "namespace_for_scope" do
|
60
58
|
it "returns a scope for use in url_for-based path-helpers" do
|
61
|
-
|
59
|
+
resource.namespace_for_scope.should == ['admin']
|
62
60
|
end
|
63
61
|
end
|
64
62
|
|
@@ -76,24 +74,24 @@ describe Alchemy::Resource do
|
|
76
74
|
end
|
77
75
|
|
78
76
|
it "parses and returns the resource-model's attributes from ActiveRecord::ModelSchema" do
|
79
|
-
|
77
|
+
resource.attributes.should == [{:name => "name", :type => :string}, {:name => "hidden_value", :type => :string}, {:name => "description", :type => :string}, {:name => "starts_at", :type => :datetime}]
|
80
78
|
end
|
81
79
|
|
82
|
-
it "skips
|
83
|
-
|
84
|
-
|
80
|
+
it "skips a set of default attributes (DEFAULT_SKIPPED_ATTRIBUTES)" do
|
81
|
+
resource.attributes.should_not include({:name => "id", :type => :integer})
|
82
|
+
resource.attributes.should include({:name => "hidden_value", :type => :string})
|
85
83
|
end
|
86
84
|
|
87
|
-
it "should
|
88
|
-
|
89
|
-
|
90
|
-
|
85
|
+
it "should skip attributes set via skip_attributes" do
|
86
|
+
resource.skip_attributes = %W[hidden_value]
|
87
|
+
resource.attributes.should include({:name => "id", :type => :integer})
|
88
|
+
resource.attributes.should_not include({:name => "hidden_value", :type => :string})
|
91
89
|
end
|
92
90
|
|
93
91
|
describe "searchable_attributes" do
|
94
92
|
it "should return all attributes of type string" do
|
95
|
-
|
96
|
-
|
93
|
+
resource.skip_attributes = []
|
94
|
+
resource.searchable_attributes.should == [{:name => "name", :type => :string}, {:name => "hidden_value", :type => :string}, {:name => "description", :type => :string}]
|
97
95
|
end
|
98
96
|
end
|
99
97
|
end
|
data/spec/models/page_spec.rb
CHANGED
@@ -2,481 +2,506 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
|
5
|
+
module Alchemy
|
6
|
+
describe Page do
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
before(:all) 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
|
14
|
+
|
15
|
+
describe ".layout_description" do
|
12
16
|
|
13
|
-
|
17
|
+
context "for a language root page" do
|
14
18
|
|
15
|
-
|
19
|
+
it "should return the page layout description as hash" do
|
20
|
+
@language_root.layout_description['name'].should == 'intro'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return an empty hash for root page" do
|
24
|
+
@rootpage.layout_description.should == {}
|
25
|
+
end
|
16
26
|
|
17
|
-
it "should return the page layout description as hash" do
|
18
|
-
@language_root.layout_description['name'].should == 'intro'
|
19
27
|
end
|
20
28
|
|
21
|
-
it "should
|
22
|
-
@
|
29
|
+
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
|
23
32
|
end
|
24
33
|
|
25
34
|
end
|
26
35
|
|
27
|
-
it "should
|
28
|
-
|
29
|
-
expect { @page.layout_description }.to raise_error
|
36
|
+
it "should contain one rootpage" do
|
37
|
+
Page.rootpage.should be_instance_of(Page)
|
30
38
|
end
|
31
39
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
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')
|
43
|
+
end
|
37
44
|
|
38
|
-
|
39
|
-
@page = FactoryGirl.create(:public_page, :page_layout => 'news', :parent_id => @language_root.id, :language => @language)
|
40
|
-
@page.feed_elements.should == Alchemy::Element.find_all_by_name('news')
|
41
|
-
end
|
45
|
+
context "finding elements" do
|
42
46
|
|
43
|
-
|
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
|
+
]
|
53
|
+
end
|
44
54
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
FactoryGirl.create(:element, :public => false, :page => @page)
|
50
|
-
]
|
51
|
-
end
|
55
|
+
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
|
58
|
+
end
|
52
59
|
|
53
|
-
|
54
|
-
options = {:collection => @page.elements}
|
55
|
-
@page.find_elements(options).all.should == @page.elements.all
|
56
|
-
end
|
60
|
+
context "with show_non_public argument TRUE" do
|
57
61
|
|
58
|
-
|
62
|
+
it "should return all elements from empty options" do
|
63
|
+
@page.find_elements({}, true).all.should == @page.elements.all
|
64
|
+
end
|
59
65
|
|
60
|
-
|
61
|
-
|
62
|
-
|
66
|
+
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
|
68
|
+
end
|
63
69
|
|
64
|
-
|
65
|
-
|
66
|
-
|
70
|
+
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
|
72
|
+
end
|
67
73
|
|
68
|
-
|
69
|
-
|
70
|
-
|
74
|
+
it "should return elements offsetted" do
|
75
|
+
@page.find_elements({:offset => 2}, true).all.should == @page.elements.offset(2)
|
76
|
+
end
|
71
77
|
|
72
|
-
|
73
|
-
|
74
|
-
|
78
|
+
it "should return elements limitted in count" do
|
79
|
+
@page.find_elements({:count => 1}, true).all.should == @page.elements.limit(1)
|
80
|
+
end
|
75
81
|
|
76
|
-
it "should return elements limitted in count" do
|
77
|
-
@page.find_elements({:count => 1}, true).all.should == @page.elements.limit(1)
|
78
82
|
end
|
79
83
|
|
80
|
-
|
84
|
+
context "with show_non_public argument FALSE" do
|
81
85
|
|
82
|
-
|
86
|
+
it "should return all elements from empty arguments" do
|
87
|
+
@page.find_elements().all.should == @page.elements.published.all
|
88
|
+
end
|
83
89
|
|
84
|
-
|
85
|
-
|
86
|
-
|
90
|
+
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
|
92
|
+
end
|
87
93
|
|
88
|
-
|
89
|
-
|
90
|
-
|
94
|
+
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
|
96
|
+
end
|
91
97
|
|
92
|
-
|
93
|
-
|
94
|
-
|
98
|
+
it "should return elements offsetted" do
|
99
|
+
@page.find_elements({:offset => 2}).all.should == @page.elements.published.offset(2)
|
100
|
+
end
|
95
101
|
|
96
|
-
|
97
|
-
|
98
|
-
|
102
|
+
it "should return elements limitted in count" do
|
103
|
+
@page.find_elements({:count => 1}).all.should == @page.elements.published.limit(1)
|
104
|
+
end
|
99
105
|
|
100
|
-
it "should return elements limitted in count" do
|
101
|
-
@page.find_elements({:count => 1}).all.should == @page.elements.published.limit(1)
|
102
106
|
end
|
103
107
|
|
104
108
|
end
|
105
109
|
|
106
|
-
|
110
|
+
describe '#create' do
|
107
111
|
|
108
|
-
|
112
|
+
context "before/after filter" do
|
109
113
|
|
110
|
-
|
114
|
+
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)
|
116
|
+
page.title.should == 'My Testpage'
|
117
|
+
end
|
111
118
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
119
|
+
it "should get a webfriendly urlname" do
|
120
|
+
page = FactoryGirl.create(:page, :name => 'klingon$&stößel ', :language => @language, :parent_id => @language_root.id)
|
121
|
+
page.urlname.should == 'klingon-stoessel'
|
122
|
+
end
|
116
123
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
124
|
+
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)
|
126
|
+
page.urlname.should == '-au'
|
127
|
+
end
|
121
128
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
129
|
+
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)
|
131
|
+
page.urlname.should == 'aue'
|
132
|
+
end
|
126
133
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
134
|
+
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)
|
136
|
+
page.urlname.should == '--a'
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should add a user stamper" do
|
140
|
+
page = FactoryGirl.create(:page, :name => 'A', :language => @language, :parent_id => @language_root.id)
|
141
|
+
page.class.stamper_class.to_s.should == 'Alchemy::User'
|
142
|
+
end
|
131
143
|
|
132
|
-
it "should generate a three letter urlname from one letter name" do
|
133
|
-
page = FactoryGirl.create(:page, :name => 'A', :language => @language, :parent_id => @language_root.id)
|
134
|
-
page.urlname.should == '--a'
|
135
144
|
end
|
136
145
|
|
137
146
|
end
|
138
147
|
|
139
|
-
|
148
|
+
describe '#update' do
|
140
149
|
|
141
|
-
|
150
|
+
context "before/after filter" do
|
142
151
|
|
143
|
-
|
152
|
+
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)
|
154
|
+
page.name = "My Renaming Test"
|
155
|
+
page.save; page.reload
|
156
|
+
page.title.should == "My Testpage"
|
157
|
+
end
|
144
158
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
159
|
+
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)
|
161
|
+
page.title = "I like SEO"
|
162
|
+
page.save; page.reload
|
163
|
+
page.title.should == "I like SEO"
|
164
|
+
end
|
151
165
|
|
152
|
-
it "should not automatically set the title if it changed its value" do
|
153
|
-
page = FactoryGirl.create(:page, :name => 'My Testpage', :language => @language, :parent_id => @language_root.id)
|
154
|
-
page.title = "I like SEO"
|
155
|
-
page.save; page.reload
|
156
|
-
page.title.should == "I like SEO"
|
157
166
|
end
|
158
167
|
|
159
168
|
end
|
160
169
|
|
161
|
-
|
162
|
-
|
163
|
-
context "with children" do
|
170
|
+
context "with children" do
|
164
171
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
@first_public_child = FactoryGirl.create(:page, :name => "First public child", :language => @language, :parent_id => @language_root.id, :public => true)
|
170
|
-
@first_public_child.move_to_child_of(@language_root)
|
171
|
-
end
|
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)
|
172
175
|
|
173
|
-
|
174
|
-
|
175
|
-
@language_root.first_public_child.should == @first_public_child
|
176
|
-
else
|
177
|
-
@language_root.first_public_child.should == nil
|
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)
|
178
178
|
end
|
179
|
-
end
|
180
|
-
|
181
|
-
end
|
182
179
|
|
183
|
-
|
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
|
186
|
+
end
|
184
187
|
|
185
|
-
before(:each) do
|
186
|
-
@klingonian = FactoryGirl.create(:language)
|
187
|
-
@layoutroot = Alchemy::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)
|
191
188
|
end
|
192
189
|
|
193
|
-
|
194
|
-
Alchemy::Page.contentpages.to_a.should include(@language_root, @klingonian_lang_root, @contentpage)
|
195
|
-
end
|
190
|
+
context ".contentpages" do
|
196
191
|
|
197
|
-
|
198
|
-
|
199
|
-
|
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)
|
198
|
+
end
|
200
199
|
|
201
|
-
|
202
|
-
|
203
|
-
|
200
|
+
it "should return a collection of contentpages" do
|
201
|
+
Page.contentpages.to_a.should include(@language_root, @klingonian_lang_root, @contentpage)
|
202
|
+
end
|
204
203
|
|
205
|
-
|
204
|
+
it "should not contain pages with attribute :layoutpage set to true" do
|
205
|
+
Page.contentpages.to_a.select { |p| p.layoutpage == true }.should be_empty
|
206
|
+
end
|
206
207
|
|
207
|
-
|
208
|
+
it "should contain pages with attribute :layoutpage set to nil" do
|
209
|
+
Page.contentpages.to_a.select { |p| p.layoutpage == nil }.should include(@klingonian_lang_root)
|
210
|
+
end
|
208
211
|
|
209
|
-
it "should return pages that are public" do
|
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)
|
212
|
-
Alchemy::Page.published.should have(3).pages
|
213
212
|
end
|
214
213
|
|
215
|
-
|
214
|
+
context ".public" do
|
216
215
|
|
217
|
-
|
216
|
+
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)
|
219
|
+
Page.published.should have(3).pages
|
220
|
+
end
|
218
221
|
|
219
|
-
it "should return pages that are not blocked by a user at the moment" do
|
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)
|
222
|
-
Alchemy::Page.not_locked.should have(3).pages
|
223
222
|
end
|
224
|
-
end
|
225
223
|
|
226
|
-
|
227
|
-
it "should return 1 page that is blocked by a user at the moment" do
|
228
|
-
FactoryGirl.create(:public_page, :locked => true, :name => 'First Public Child', :parent_id => @language_root.id, :language => @language)
|
229
|
-
Alchemy::Page.all_locked.should have(1).pages
|
230
|
-
end
|
231
|
-
end
|
224
|
+
context ".not_locked" do
|
232
225
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
226
|
+
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)
|
229
|
+
Page.not_locked.should have(3).pages
|
230
|
+
end
|
237
231
|
end
|
238
|
-
end
|
239
232
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
233
|
+
context ".all_locked" do
|
234
|
+
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)
|
236
|
+
Page.all_locked.should have(1).pages
|
237
|
+
end
|
245
238
|
end
|
246
|
-
end
|
247
239
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
240
|
+
context ".language_roots" do
|
241
|
+
it "should return 1 language_root" do
|
242
|
+
FactoryGirl.create(:public_page, :name => 'First Public Child', :parent_id => @language_root.id, :language => @language)
|
243
|
+
Page.language_roots.should have(1).pages
|
244
|
+
end
|
252
245
|
end
|
253
|
-
end
|
254
246
|
|
255
|
-
context ".accessable" do
|
256
|
-
it "should return 2 accessable pages" do
|
257
|
-
FactoryGirl.create(:public_page, :name => 'First Public Child', :restricted => true, :parent_id => @language_root.id, :language => @language)
|
258
|
-
Alchemy::Page.accessable.should have(2).pages
|
259
|
-
end
|
260
|
-
end
|
261
247
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
248
|
+
context ".layoutpages" do
|
249
|
+
it "should return 1 layoutpage" do
|
250
|
+
FactoryGirl.create(:public_page, :layoutpage => true, :name => 'Layoutpage', :parent_id => @rootpage.id, :language => @language)
|
251
|
+
Page.layoutpages.should have(1).pages
|
252
|
+
end
|
266
253
|
end
|
267
|
-
end
|
268
254
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
255
|
+
context ".visible" do
|
256
|
+
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)
|
258
|
+
Page.visible.should have(1).pages
|
259
|
+
end
|
274
260
|
end
|
275
|
-
end
|
276
|
-
|
277
|
-
describe "#cell_definitions" do
|
278
261
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
262
|
+
context ".accessible" do
|
263
|
+
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)
|
265
|
+
Page.accessible.should have(2).pages
|
266
|
+
end
|
284
267
|
end
|
285
268
|
|
286
|
-
|
287
|
-
|
269
|
+
context ".restricted" do
|
270
|
+
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)
|
272
|
+
Page.restricted.should have(1).pages
|
273
|
+
end
|
288
274
|
end
|
289
275
|
|
290
|
-
|
291
|
-
|
292
|
-
|
276
|
+
context "#unlock" do
|
277
|
+
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
|
281
|
+
end
|
293
282
|
end
|
294
283
|
|
295
|
-
|
284
|
+
describe "#cell_definitions" do
|
296
285
|
|
297
|
-
|
298
|
-
|
299
|
-
context "with no elements defined that are not defined in a cell" do
|
300
|
-
it "should not have a cell for 'other elements'" do
|
286
|
+
before(:each) do
|
301
287
|
@page = FactoryGirl.build(:page, :page_layout => 'foo')
|
302
|
-
@page.stub!(:layout_description).and_return({'name' => "foo", 'cells' => ["foo_cell"]
|
288
|
+
@page.stub!(:layout_description).and_return({'name' => "foo", 'cells' => ["foo_cell"]})
|
303
289
|
@cell_descriptions = [{'name' => "foo_cell", 'elements' => ["1", "2"]}]
|
304
|
-
|
305
|
-
@page.elements_grouped_by_cells.keys.collect(&:name).should_not include('for_other_elements')
|
290
|
+
Cell.stub!(:definitions).and_return(@cell_descriptions)
|
306
291
|
end
|
307
|
-
end
|
308
292
|
|
309
|
-
|
310
|
-
|
311
|
-
@page = FactoryGirl.build(:page, :page_layout => 'foo')
|
312
|
-
@page.stub!(:layout_description).and_return({'name' => "foo", 'cells' => ["foo_cell"], 'elements' => ["1", "2", "3"]})
|
313
|
-
@cell_descriptions = [{'name' => "foo_cell", 'elements' => ["1", "2"]}]
|
314
|
-
Alchemy::Cell.stub!(:definitions).and_return(@cell_descriptions)
|
315
|
-
@page.elements_grouped_by_cells.keys.collect(&:name).should include('for_other_elements')
|
293
|
+
it "should return all cell definitions for its page_layout" do
|
294
|
+
@page.cell_definitions.should == @cell_descriptions
|
316
295
|
end
|
317
|
-
end
|
318
|
-
|
319
|
-
end
|
320
|
-
|
321
|
-
describe '.all_from_clipboard_for_select' do
|
322
|
-
|
323
|
-
context "with clipboard holding pages having non unique page layout" do
|
324
296
|
|
325
|
-
it "should return
|
326
|
-
|
327
|
-
|
328
|
-
clipboard = [
|
329
|
-
{:id => page_1.id, :action => "copy"},
|
330
|
-
{:id => page_2.id, :action => "copy"}
|
331
|
-
]
|
332
|
-
Alchemy::Page.all_from_clipboard_for_select(clipboard, @language.id).should == [page_1, page_2]
|
297
|
+
it "should return empty array if no cells defined in page layout" do
|
298
|
+
@page.stub!(:layout_description).and_return({'name' => "foo"})
|
299
|
+
@page.cell_definitions.should == []
|
333
300
|
end
|
334
301
|
|
335
302
|
end
|
336
303
|
|
337
|
-
|
304
|
+
describe "#elements_grouped_by_cells" do
|
338
305
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
{
|
343
|
-
|
344
|
-
|
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
|
345
314
|
end
|
346
315
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
{:id => page_1.id, :action => "copy"},
|
356
|
-
{:id => page_2.id, :action => "copy"}
|
357
|
-
]
|
358
|
-
Alchemy::Page.all_from_clipboard_for_select(clipboard, @language.id).should == [page_1]
|
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
|
359
324
|
end
|
360
325
|
|
361
326
|
end
|
362
327
|
|
363
|
-
|
328
|
+
describe '.all_from_clipboard_for_select' do
|
329
|
+
|
330
|
+
context "with clipboard holding pages having non unique page layout" do
|
364
331
|
|
365
|
-
|
332
|
+
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')
|
335
|
+
clipboard = [
|
336
|
+
{:id => page_1.id, :action => "copy"},
|
337
|
+
{:id => page_2.id, :action => "copy"}
|
338
|
+
]
|
339
|
+
Page.all_from_clipboard_for_select(clipboard, @language.id).should include(page_1, page_2)
|
340
|
+
end
|
366
341
|
|
367
|
-
context "saving a normal content page" do
|
368
|
-
it "should be possible to save when its urlname already exists in the scope of global pages" do
|
369
|
-
@contentpage = FactoryGirl.create(:page, :urlname => "existing_twice")
|
370
|
-
@global_with_same_urlname = FactoryGirl.create(:page, :urlname => "existing_twice", :layoutpage => true)
|
371
|
-
@contentpage.title = "new Title"
|
372
|
-
@contentpage.save.should == true
|
373
342
|
end
|
374
|
-
end
|
375
343
|
|
376
|
-
|
344
|
+
context "with clipboard holding a page having unique page layout" do
|
377
345
|
|
378
|
-
|
379
|
-
|
380
|
-
|
346
|
+
it "should not return any pages" do
|
347
|
+
page_1 = FactoryGirl.create(:page, :language => @language, :page_layout => 'contact')
|
348
|
+
clipboard = [
|
349
|
+
{:id => page_1.id, :action => "copy"}
|
350
|
+
]
|
351
|
+
Page.all_from_clipboard_for_select(clipboard, @language.id).should == []
|
352
|
+
end
|
381
353
|
|
382
|
-
it "should validate the page_layout" do
|
383
|
-
@contentpage.save
|
384
|
-
@contentpage.should have(1).error_on(:page_layout)
|
385
354
|
end
|
386
355
|
|
387
|
-
|
388
|
-
|
389
|
-
|
356
|
+
context "with clipboard holding two pages. One having a unique page layout." do
|
357
|
+
|
358
|
+
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')
|
361
|
+
clipboard = [
|
362
|
+
{:id => page_1.id, :action => "copy"},
|
363
|
+
{:id => page_2.id, :action => "copy"}
|
364
|
+
]
|
365
|
+
Page.all_from_clipboard_for_select(clipboard, @language.id).should == [page_1]
|
366
|
+
end
|
367
|
+
|
390
368
|
end
|
391
369
|
|
392
370
|
end
|
393
371
|
|
394
|
-
|
372
|
+
describe "validations" do
|
395
373
|
|
396
|
-
|
397
|
-
|
398
|
-
|
374
|
+
context "saving a normal content page" do
|
375
|
+
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
|
380
|
+
end
|
399
381
|
end
|
400
382
|
|
401
|
-
|
402
|
-
@rootpage.save
|
403
|
-
@rootpage.should be_valid
|
404
|
-
end
|
383
|
+
context "creating a normal content page" do
|
405
384
|
|
406
|
-
|
385
|
+
before(:each) do
|
386
|
+
@contentpage = FactoryGirl.build(:page, :parent_id => nil, :page_layout => nil)
|
387
|
+
end
|
407
388
|
|
408
|
-
|
389
|
+
it "should validate the page_layout" do
|
390
|
+
@contentpage.save
|
391
|
+
@contentpage.should have(1).error_on(:page_layout)
|
392
|
+
end
|
409
393
|
|
410
|
-
|
411
|
-
|
412
|
-
|
394
|
+
it "should validate the parent_id" do
|
395
|
+
@contentpage.save
|
396
|
+
@contentpage.should have(1).error_on(:parent_id)
|
397
|
+
end
|
413
398
|
|
414
|
-
it "should not validate the page_layout" do
|
415
|
-
@systempage.save
|
416
|
-
@systempage.should be_valid
|
417
399
|
end
|
418
400
|
|
419
|
-
|
401
|
+
context "creating the rootpage without parent_id and page_layout" do
|
420
402
|
|
421
|
-
|
422
|
-
|
423
|
-
|
403
|
+
before(:each) do
|
404
|
+
Page.delete_all
|
405
|
+
@rootpage = FactoryGirl.build(:page, :parent_id => nil, :page_layout => nil, :name => 'Rootpage')
|
406
|
+
end
|
424
407
|
|
425
|
-
|
408
|
+
it "should be valid" do
|
409
|
+
@rootpage.save
|
410
|
+
@rootpage.should be_valid
|
411
|
+
end
|
426
412
|
|
427
|
-
before(:each) do
|
428
|
-
@page = FactoryGirl.build(:page, :language_code => nil, :language => FactoryGirl.create(:language))
|
429
413
|
end
|
430
414
|
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
415
|
+
context "saving a systempage" do
|
416
|
+
|
417
|
+
before(:each) do
|
418
|
+
@systempage = FactoryGirl.build(:systempage)
|
419
|
+
end
|
420
|
+
|
421
|
+
it "should not validate the page_layout" do
|
422
|
+
@systempage.save
|
423
|
+
@systempage.should be_valid
|
424
|
+
end
|
435
425
|
|
436
|
-
it "should autogenerate the elements" do
|
437
|
-
@page.save
|
438
|
-
@page.elements.should_not be_empty
|
439
426
|
end
|
440
427
|
|
441
|
-
|
428
|
+
end
|
429
|
+
|
430
|
+
describe 'before and after filters' do
|
431
|
+
|
432
|
+
context "a normal page" do
|
442
433
|
|
443
434
|
before(:each) do
|
435
|
+
@page = FactoryGirl.build(:page, :language_code => nil, :language => FactoryGirl.create(:language))
|
436
|
+
end
|
437
|
+
|
438
|
+
it "should get the language code for language" do
|
444
439
|
@page.save
|
445
|
-
@
|
446
|
-
|
447
|
-
|
440
|
+
@page.language_code.should == "kl"
|
441
|
+
end
|
442
|
+
|
443
|
+
it "should autogenerate the elements" do
|
448
444
|
@page.save
|
445
|
+
@page.elements.should_not be_empty
|
449
446
|
end
|
450
447
|
|
451
|
-
|
452
|
-
|
453
|
-
|
448
|
+
context "with children getting restricted set to true" do
|
449
|
+
|
450
|
+
before(:each) do
|
451
|
+
@page.save
|
452
|
+
@child1 = FactoryGirl.create(:page, :name => 'Child 1', :parent_id => @page.id)
|
453
|
+
@page.reload
|
454
|
+
@page.restricted = true
|
455
|
+
@page.save
|
456
|
+
end
|
457
|
+
|
458
|
+
it "should restrict all its children" do
|
459
|
+
@child1.reload
|
460
|
+
@child1.restricted?.should be_true
|
461
|
+
end
|
462
|
+
|
454
463
|
end
|
455
464
|
|
456
|
-
|
465
|
+
context "with restricted parent gets created" do
|
457
466
|
|
458
|
-
|
467
|
+
before(:each) do
|
468
|
+
@page.save
|
469
|
+
@page.parent.update_attributes(:restricted => true)
|
470
|
+
@new_page = FactoryGirl.create(:page, :name => 'New Page', :parent_id => @page.id)
|
471
|
+
end
|
472
|
+
|
473
|
+
it "should also be restricted" do
|
474
|
+
@new_page.restricted?.should be_true
|
475
|
+
end
|
459
476
|
|
460
|
-
before(:each) do
|
461
|
-
@page.save
|
462
|
-
@page.parent.update_attributes(:restricted => true)
|
463
|
-
@new_page = FactoryGirl.create(:page, :name => 'New Page', :parent_id => @page.id)
|
464
477
|
end
|
465
478
|
|
466
|
-
|
467
|
-
|
479
|
+
context "with do_not_autogenerate set to true" do
|
480
|
+
|
481
|
+
before(:each) do
|
482
|
+
@page.do_not_autogenerate = true
|
483
|
+
end
|
484
|
+
|
485
|
+
it "should not autogenerate the elements" do
|
486
|
+
@page.save
|
487
|
+
@page.elements.should be_empty
|
488
|
+
end
|
489
|
+
|
468
490
|
end
|
469
491
|
|
470
492
|
end
|
471
493
|
|
472
|
-
context "
|
494
|
+
context "a systempage" do
|
473
495
|
|
474
496
|
before(:each) do
|
475
|
-
@page
|
497
|
+
@page = FactoryGirl.create(:systempage)
|
498
|
+
end
|
499
|
+
|
500
|
+
it "should not get the language code for language" do
|
501
|
+
@page.language_code.should be_nil
|
476
502
|
end
|
477
503
|
|
478
504
|
it "should not autogenerate the elements" do
|
479
|
-
@page.save
|
480
505
|
@page.elements.should be_empty
|
481
506
|
end
|
482
507
|
|
@@ -484,22 +509,23 @@ describe Alchemy::Page do
|
|
484
509
|
|
485
510
|
end
|
486
511
|
|
487
|
-
|
512
|
+
describe '#fold' do
|
488
513
|
|
489
514
|
before(:each) do
|
490
|
-
@page = FactoryGirl.create(:
|
515
|
+
@page = FactoryGirl.create(:public_page)
|
516
|
+
@user = FactoryGirl.create(:admin_user, :email => 'faz@baz.com', :login => 'foo_baz')
|
491
517
|
end
|
492
518
|
|
493
|
-
|
494
|
-
|
495
|
-
|
519
|
+
context "with folded status set to true" do
|
520
|
+
|
521
|
+
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
|
524
|
+
end
|
496
525
|
|
497
|
-
it "should not autogenerate the elements" do
|
498
|
-
@page.elements.should be_empty
|
499
526
|
end
|
500
527
|
|
501
528
|
end
|
502
529
|
|
503
530
|
end
|
504
|
-
|
505
531
|
end
|