alchemy_cms 2.2.2 → 2.2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/alchemy_cms.gemspec +0 -1
- data/app/helpers/alchemy/admin/base_helper.rb +3 -3
- data/app/models/alchemy/content.rb +8 -1
- data/app/models/alchemy/element.rb +15 -16
- data/app/models/alchemy/page.rb +1 -0
- data/lib/alchemy/essence.rb +7 -4
- data/lib/alchemy/version.rb +1 -1
- data/spec/controllers/admin/elements_controller_spec.rb +28 -0
- data/spec/controllers/admin/trash_controller_spec.rb +45 -12
- data/spec/dummy/config/locales/fo.yml +5 -0
- data/spec/integration/admin/pages_controller_spec.rb +1 -8
- data/spec/integration/admin/resources_integration_spec.rb +2 -2
- data/spec/integration/pages_controller_spec.rb +189 -191
- data/spec/integration/security_spec.rb +1 -1
- data/spec/models/element_spec.rb +204 -182
- data/spec/models/essence_boolean_spec.rb +1 -1
- data/spec/models/essence_select_spec.rb +1 -1
- data/spec/models/language_spec.rb +1 -1
- data/spec/models/page_spec.rb +1 -1
- data/spec/spec_helper.rb +14 -13
- data/spec/support/alchemy/specs_helpers.rb +27 -8
- data/spec/support/alchemy/test_tweaks.rb +35 -0
- metadata +7 -19
data/spec/models/element_spec.rb
CHANGED
@@ -1,272 +1,294 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
module Alchemy
|
4
|
+
describe Element do
|
4
5
|
|
5
|
-
|
6
|
+
context "scoped" do
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
before(:each) do
|
9
|
+
Element.delete_all
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
it "should return all public elements" do
|
13
|
+
elements = [FactoryGirl.create(:element, :public => true), FactoryGirl.create(:element, :public => true)]
|
14
|
+
Element.published.all.should == elements
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
it "should return all elements by name" do
|
18
|
+
elements = [FactoryGirl.create(:element, :name => 'article'), FactoryGirl.create(:element, :name => 'article')]
|
19
|
+
Element.named(['article']).all.should == elements
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
it "should return all elements but excluded ones" do
|
23
|
+
FactoryGirl.create(:element, :name => 'article')
|
24
|
+
FactoryGirl.create(:element, :name => 'article')
|
25
|
+
excluded = [FactoryGirl.create(:element, :name => 'claim')]
|
26
|
+
Element.excluded(['article']).all.should == excluded
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
context "not_in_cell" do
|
30
|
+
it "should return all elements that are not in a cell" do
|
31
|
+
FactoryGirl.create(:element, :cell_id => 6)
|
32
|
+
FactoryGirl.create(:element, :cell_id => nil)
|
33
|
+
Element.not_in_cell.should have(1).element
|
34
|
+
end
|
33
35
|
end
|
36
|
+
|
34
37
|
end
|
35
38
|
|
36
|
-
|
39
|
+
it "should return a list of element definitions for a list of element names" do
|
40
|
+
element_names = ["article"]
|
41
|
+
definitions = Element.all_definitions_for(element_names)
|
42
|
+
definitions.first.fetch("name").should == 'article'
|
43
|
+
end
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
45
|
+
it "should always return an array calling all_definitions_for()" do
|
46
|
+
definitions = Element.all_definitions_for(nil)
|
47
|
+
definitions.should == []
|
48
|
+
end
|
43
49
|
|
44
|
-
|
45
|
-
definitions = Alchemy::Element.all_definitions_for(nil)
|
46
|
-
definitions.should == []
|
47
|
-
end
|
50
|
+
context "no description files are found" do
|
48
51
|
|
49
|
-
|
52
|
+
before(:each) do
|
53
|
+
FileUtils.mv(File.join(File.dirname(__FILE__), '..', '..', 'config', 'alchemy', 'elements.yml'), File.join(File.dirname(__FILE__), '..', '..', 'config', 'alchemy', 'elements.yml.bak'))
|
54
|
+
end
|
50
55
|
|
51
|
-
|
52
|
-
|
53
|
-
|
56
|
+
it "should raise an error" do
|
57
|
+
expect { Element.descriptions }.to raise_error(LoadError)
|
58
|
+
end
|
54
59
|
|
55
|
-
|
56
|
-
|
57
|
-
|
60
|
+
after(:each) do
|
61
|
+
FileUtils.mv(File.join(File.dirname(__FILE__), '..', '..', 'config', 'alchemy', 'elements.yml.bak'), File.join(File.dirname(__FILE__), '..', '..', 'config', 'alchemy', 'elements.yml'))
|
62
|
+
end
|
58
63
|
|
59
|
-
after(:each) do
|
60
|
-
FileUtils.mv(File.join(File.dirname(__FILE__), '..', '..', 'config', 'alchemy', 'elements.yml.bak'), File.join(File.dirname(__FILE__), '..', '..', 'config', 'alchemy', 'elements.yml'))
|
61
64
|
end
|
62
65
|
|
63
|
-
|
66
|
+
context "retrieving contents, essences and ingredients" do
|
64
67
|
|
65
|
-
|
68
|
+
before(:each) do
|
69
|
+
@element = FactoryGirl.create(:element, :name => 'news')
|
70
|
+
end
|
66
71
|
|
67
|
-
|
68
|
-
|
69
|
-
|
72
|
+
it "should return an ingredient by name" do
|
73
|
+
@element.ingredient('news_headline').should == EssenceText.first.ingredient
|
74
|
+
end
|
70
75
|
|
71
|
-
|
72
|
-
|
73
|
-
|
76
|
+
it "should return the content for rss title" do
|
77
|
+
@element.content_for_rss_title.should == @element.contents.find_by_name('news_headline')
|
78
|
+
end
|
74
79
|
|
75
|
-
|
76
|
-
|
77
|
-
|
80
|
+
it "should return the content for rss description" do
|
81
|
+
@element.content_for_rss_description.should == @element.contents.find_by_name('body')
|
82
|
+
end
|
78
83
|
|
79
|
-
it "should return the content for rss description" do
|
80
|
-
@element.content_for_rss_description.should == @element.contents.find_by_name('body')
|
81
84
|
end
|
82
85
|
|
83
|
-
|
86
|
+
it "should return a collection of trashed elements" do
|
87
|
+
@element = FactoryGirl.create(:element)
|
88
|
+
@element.trash
|
89
|
+
Element.trashed.should include(@element)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return a collection of not trashed elements" do
|
93
|
+
@element = FactoryGirl.create(:element, :page_id => 1)
|
94
|
+
Element.not_trashed.should include(@element)
|
95
|
+
end
|
96
|
+
|
97
|
+
context "limited amount" do
|
98
|
+
before(:each) do
|
99
|
+
descriptions = Element.descriptions
|
100
|
+
descriptions << {
|
101
|
+
'name' => 'column_headline',
|
102
|
+
'amount' => 3,
|
103
|
+
'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}]
|
104
|
+
}
|
105
|
+
descriptions << {
|
106
|
+
'name' => 'unique_headline',
|
107
|
+
'unique' => true,
|
108
|
+
'amount' => 3,
|
109
|
+
'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}]
|
110
|
+
}
|
111
|
+
Element.stub!(:descriptions).and_return(descriptions)
|
112
|
+
PageLayout.add(
|
113
|
+
'name' => 'columns',
|
114
|
+
'elements' => ['column_headline', 'unique_headline'],
|
115
|
+
'autogenerate' => ['unique_headline', 'column_headline', 'column_headline', 'column_headline']
|
116
|
+
)
|
117
|
+
@page = FactoryGirl.create(:page, :page_layout => 'columns')
|
118
|
+
end
|
84
119
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
120
|
+
it "should be readable" do
|
121
|
+
element = Element.all_definitions_for(['column_headline']).first
|
122
|
+
element['amount'].should be 3
|
123
|
+
end
|
90
124
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
125
|
+
it "should limit elements" do
|
126
|
+
Element.all_for_page(@page).each { |e| e['name'].should_not == 'column_headline' }
|
127
|
+
end
|
95
128
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
descriptions << {
|
100
|
-
'name' => 'column_headline',
|
101
|
-
'amount' => 3,
|
102
|
-
'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}]
|
103
|
-
}
|
104
|
-
descriptions << {
|
105
|
-
'name' => 'unique_headline',
|
106
|
-
'unique' => true,
|
107
|
-
'amount' => 3,
|
108
|
-
'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}]
|
109
|
-
}
|
110
|
-
Alchemy::Element.stub!(:descriptions).and_return(descriptions)
|
111
|
-
Alchemy::PageLayout.add(
|
112
|
-
'name' => 'columns',
|
113
|
-
'elements' => ['column_headline', 'unique_headline'],
|
114
|
-
'autogenerate' => ['unique_headline', 'column_headline', 'column_headline', 'column_headline']
|
115
|
-
)
|
116
|
-
@page = FactoryGirl.create(:page, :page_layout => 'columns')
|
117
|
-
end
|
129
|
+
it "should be ignored if unique" do
|
130
|
+
Element.all_for_page(@page).each { |e| e['name'].should_not == 'unique_headline' }
|
131
|
+
end
|
118
132
|
|
119
|
-
it "should be readable" do
|
120
|
-
element = Alchemy::Element.all_definitions_for(['column_headline']).first
|
121
|
-
element['amount'].should be 3
|
122
133
|
end
|
123
134
|
|
124
|
-
|
125
|
-
Alchemy::Element.all_for_page(@page).each { |e| e['name'].should_not == 'column_headline' }
|
126
|
-
end
|
135
|
+
context "trashed" do
|
127
136
|
|
128
|
-
|
129
|
-
|
130
|
-
|
137
|
+
before(:each) do
|
138
|
+
@element = FactoryGirl.create(:element)
|
139
|
+
@element.trash
|
140
|
+
end
|
131
141
|
|
132
|
-
|
142
|
+
it "should be not public" do
|
143
|
+
@element.public.should be_false
|
144
|
+
end
|
133
145
|
|
134
|
-
|
146
|
+
it "should have no page" do
|
147
|
+
@element.page.should == nil
|
148
|
+
end
|
135
149
|
|
136
|
-
|
137
|
-
@element = FactoryGirl.create(:element)
|
138
|
-
@element.trash
|
139
|
-
end
|
150
|
+
context "collections" do
|
140
151
|
|
141
|
-
|
142
|
-
@element.public.should be_false
|
143
|
-
end
|
152
|
+
context "for trashed elements" do
|
144
153
|
|
145
|
-
|
146
|
-
|
147
|
-
|
154
|
+
let(:element) do
|
155
|
+
FactoryGirl.create(:element, :page_id => 1)
|
156
|
+
end
|
148
157
|
|
149
|
-
|
150
|
-
|
151
|
-
|
158
|
+
it "should return a collection of trashed elements" do
|
159
|
+
not_trashed_element = FactoryGirl.create(:element)
|
160
|
+
element.trash
|
161
|
+
Element.trashed.should include(element)
|
162
|
+
end
|
152
163
|
|
153
|
-
|
164
|
+
it "should return a collection of not trashed elements" do
|
165
|
+
Element.not_trashed.should include(element)
|
166
|
+
end
|
154
167
|
|
155
|
-
|
156
|
-
expect { Alchemy::Element.all_for_page(nil) }.should raise_error(TypeError)
|
157
|
-
end
|
168
|
+
end
|
158
169
|
|
159
|
-
|
170
|
+
end
|
160
171
|
|
161
|
-
before(:each) do
|
162
|
-
@element = FactoryGirl.create(:element, :name => 'headline')
|
163
|
-
@content = @element.contents.first
|
164
172
|
end
|
165
173
|
|
166
|
-
|
174
|
+
describe "#trash" do
|
167
175
|
|
168
|
-
|
169
|
-
@element.
|
176
|
+
before(:each) do
|
177
|
+
@element = FactoryGirl.create(:element, :page_id => 1, :cell_id => 1)
|
178
|
+
@element.trash
|
170
179
|
end
|
171
180
|
|
172
|
-
|
173
|
-
|
174
|
-
|
181
|
+
it "should remove the elements position" do
|
182
|
+
@element.position.should == nil
|
183
|
+
end
|
175
184
|
|
176
|
-
it "should
|
177
|
-
@element.
|
185
|
+
it "should set the public state to false" do
|
186
|
+
@element.public?.should == false
|
178
187
|
end
|
179
188
|
|
180
|
-
|
189
|
+
it "should not remove the page_id" do
|
190
|
+
@element.page_id.should == 1
|
191
|
+
end
|
181
192
|
|
182
|
-
|
193
|
+
it "should not remove the cell_id" do
|
194
|
+
@element.cell_id.should == 1
|
195
|
+
end
|
183
196
|
|
184
|
-
|
197
|
+
it "it should be possible to trash more than one element from the same page" do
|
198
|
+
trashed_element_2 = FactoryGirl.create(:element, :page_id => 1)
|
199
|
+
trashed_element_2.trash
|
200
|
+
Element.trashed.should include(@element, trashed_element_2)
|
201
|
+
end
|
185
202
|
|
186
|
-
before(:each) do
|
187
|
-
@element = FactoryGirl.create(:element)
|
188
|
-
@contents = @element.contents.select { |c| c.essence_type == 'Alchemy::EssenceText' }
|
189
203
|
end
|
190
204
|
|
191
|
-
|
205
|
+
describe "#all_contents_by_type" do
|
192
206
|
|
193
|
-
|
194
|
-
@element.
|
207
|
+
before(:each) do
|
208
|
+
@element = FactoryGirl.create(:element)
|
209
|
+
@contents = @element.contents.select { |c| c.essence_type == 'Alchemy::EssenceText' }
|
195
210
|
end
|
196
211
|
|
197
|
-
|
212
|
+
context "with namespaced essence type" do
|
198
213
|
|
199
|
-
|
214
|
+
it "should return content by passing a essence type" do
|
215
|
+
@element.all_contents_by_type('Alchemy::EssenceText').should == @contents
|
216
|
+
end
|
200
217
|
|
201
|
-
it "should return content by passing a essence type" do
|
202
|
-
@element.all_contents_by_type('EssenceText').should == @contents
|
203
218
|
end
|
204
219
|
|
205
|
-
|
220
|
+
context "without namespaced essence type" do
|
206
221
|
|
207
|
-
|
222
|
+
it "should return content by passing a essence type" do
|
223
|
+
@element.all_contents_by_type('EssenceText').should == @contents
|
224
|
+
end
|
208
225
|
|
209
|
-
|
226
|
+
end
|
210
227
|
|
211
|
-
before(:each) do
|
212
|
-
@element = FactoryGirl.create(:element)
|
213
228
|
end
|
214
229
|
|
215
|
-
|
216
|
-
copy = Alchemy::Element.copy(@element)
|
217
|
-
copy.contents.count.should == @element.contents.count
|
218
|
-
end
|
230
|
+
describe '#copy' do
|
219
231
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
end
|
232
|
+
before(:each) do
|
233
|
+
@element = FactoryGirl.create(:element)
|
234
|
+
end
|
224
235
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
236
|
+
it "should not create contents from scratch" do
|
237
|
+
copy = Element.copy(@element)
|
238
|
+
copy.contents.count.should == @element.contents.count
|
239
|
+
end
|
229
240
|
|
230
|
-
|
241
|
+
it "should create a new record with all attributes of source except given differences" do
|
242
|
+
copy = Element.copy(@element, {:name => 'foobar'})
|
243
|
+
copy.name.should == 'foobar'
|
244
|
+
end
|
231
245
|
|
232
|
-
|
246
|
+
it "should make copies of all contents of source" do
|
247
|
+
copy = Element.copy(@element)
|
248
|
+
copy.contents.collect(&:id).should_not == @element.contents.collect(&:id)
|
249
|
+
end
|
233
250
|
|
234
|
-
before(:each) do
|
235
|
-
@page = FactoryGirl.create(:language_root_page)
|
236
|
-
@page.elements.delete_all
|
237
|
-
@element1 = FactoryGirl.create(:element, :page => @page, :name => 'headline')
|
238
|
-
@element2 = FactoryGirl.create(:element, :page => @page)
|
239
|
-
@element3 = FactoryGirl.create(:element, :page => @page, :name => 'text')
|
240
251
|
end
|
241
252
|
|
242
|
-
describe
|
253
|
+
describe "Finding previous or next element." do
|
243
254
|
|
244
|
-
|
245
|
-
@
|
255
|
+
before(:each) do
|
256
|
+
@page = FactoryGirl.create(:language_root_page)
|
257
|
+
@page.elements.delete_all
|
258
|
+
@element1 = FactoryGirl.create(:element, :page => @page, :name => 'headline')
|
259
|
+
@element2 = FactoryGirl.create(:element, :page => @page)
|
260
|
+
@element3 = FactoryGirl.create(:element, :page => @page, :name => 'text')
|
246
261
|
end
|
247
262
|
|
248
|
-
|
249
|
-
it "should return previous of this kind" do
|
250
|
-
@element3.prev('headline').should == @element1
|
251
|
-
end
|
252
|
-
end
|
263
|
+
describe '#prev' do
|
253
264
|
|
254
|
-
|
265
|
+
it "should return previous element on same page" do
|
266
|
+
@element2.prev.should == @element1
|
267
|
+
end
|
255
268
|
|
256
|
-
|
269
|
+
context "with name as parameter" do
|
270
|
+
it "should return previous of this kind" do
|
271
|
+
@element3.prev('headline').should == @element1
|
272
|
+
end
|
273
|
+
end
|
257
274
|
|
258
|
-
it "should return next element on same page" do
|
259
|
-
@element1.next.should == @element2
|
260
275
|
end
|
261
276
|
|
262
|
-
|
263
|
-
|
264
|
-
|
277
|
+
describe '#next' do
|
278
|
+
|
279
|
+
it "should return next element on same page" do
|
280
|
+
@element1.next.should == @element2
|
281
|
+
end
|
282
|
+
|
283
|
+
context "with name as parameter" do
|
284
|
+
it "should return next of this kind" do
|
285
|
+
@element1.next('text').should == @element3
|
286
|
+
end
|
265
287
|
end
|
288
|
+
|
266
289
|
end
|
267
290
|
|
268
291
|
end
|
269
292
|
|
270
293
|
end
|
271
|
-
|
272
294
|
end
|