alchemy_cms 2.2.2 → 2.2.3.1

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.
@@ -19,7 +19,7 @@ describe "Security: " do
19
19
 
20
20
  context "If user is present" do
21
21
 
22
- before(:all) do
22
+ before(:each) do
23
23
  create_admin_user
24
24
  end
25
25
 
@@ -1,272 +1,294 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Alchemy::Element do
3
+ module Alchemy
4
+ describe Element do
4
5
 
5
- context "scoped" do
6
+ context "scoped" do
6
7
 
7
- before(:each) do
8
- Alchemy::Element.delete_all
9
- end
8
+ before(:each) do
9
+ Element.delete_all
10
+ end
10
11
 
11
- it "should return all public elements" do
12
- elements = [FactoryGirl.create(:element, :public => true), FactoryGirl.create(:element, :public => true)]
13
- Alchemy::Element.published.all.should == elements
14
- end
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
- it "should return all elements by name" do
17
- elements = [FactoryGirl.create(:element, :name => 'article'), FactoryGirl.create(:element, :name => 'article')]
18
- Alchemy::Element.named(['article']).all.should == elements
19
- end
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
- it "should return all elements but excluded ones" do
22
- FactoryGirl.create(:element, :name => 'article')
23
- FactoryGirl.create(:element, :name => 'article')
24
- excluded = [FactoryGirl.create(:element, :name => 'claim')]
25
- Alchemy::Element.excluded(['article']).all.should == excluded
26
- end
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
- context "not_in_cell" do
29
- it "should return all elements that are not in a cell" do
30
- FactoryGirl.create(:element, :cell_id => 6)
31
- FactoryGirl.create(:element, :cell_id => nil)
32
- Alchemy::Element.not_in_cell.should have(1).element
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
- end
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
- it "should return a list of element definitions for a list of element names" do
39
- element_names = ["article"]
40
- definitions = Alchemy::Element.all_definitions_for(element_names)
41
- definitions.first.fetch("name").should == 'article'
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
- it "should always return an array calling all_definitions_for()" do
45
- definitions = Alchemy::Element.all_definitions_for(nil)
46
- definitions.should == []
47
- end
50
+ context "no description files are found" do
48
51
 
49
- context "no description files are found" do
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
- before(:each) do
52
- FileUtils.mv(File.join(File.dirname(__FILE__), '..', '..', 'config', 'alchemy', 'elements.yml'), File.join(File.dirname(__FILE__), '..', '..', 'config', 'alchemy', 'elements.yml.bak'))
53
- end
56
+ it "should raise an error" do
57
+ expect { Element.descriptions }.to raise_error(LoadError)
58
+ end
54
59
 
55
- it "should raise an error" do
56
- expect { Alchemy::Element.descriptions }.should raise_error(LoadError)
57
- end
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
- end
66
+ context "retrieving contents, essences and ingredients" do
64
67
 
65
- context "retrieving contents, essences and ingredients" do
68
+ before(:each) do
69
+ @element = FactoryGirl.create(:element, :name => 'news')
70
+ end
66
71
 
67
- before(:each) do
68
- @element = FactoryGirl.create(:element, :name => 'news')
69
- end
72
+ it "should return an ingredient by name" do
73
+ @element.ingredient('news_headline').should == EssenceText.first.ingredient
74
+ end
70
75
 
71
- it "should return an ingredient by name" do
72
- @element.ingredient('news_headline').should == Alchemy::EssenceText.first.ingredient
73
- end
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
- it "should return the content for rss title" do
76
- @element.content_for_rss_title.should == @element.contents.find_by_name('news_headline')
77
- end
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
- end
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
- it "should return a collection of trashed elements" do
86
- @element = FactoryGirl.create(:element)
87
- @element.trash
88
- Alchemy::Element.trashed.should include(@element)
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
- it "should return a collection of not trashed elements" do
92
- @element = FactoryGirl.create(:element, :page_id => 1)
93
- Alchemy::Element.not_trashed.should include(@element)
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
- context "limited amount" do
97
- before(:each) do
98
- descriptions = Alchemy::Element.descriptions
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
- it "should limit elements" do
125
- Alchemy::Element.all_for_page(@page).each { |e| e['name'].should_not == 'column_headline' }
126
- end
135
+ context "trashed" do
127
136
 
128
- it "should be ignored if unique" do
129
- Alchemy::Element.all_for_page(@page).each { |e| e['name'].should_not == 'unique_headline' }
130
- end
137
+ before(:each) do
138
+ @element = FactoryGirl.create(:element)
139
+ @element.trash
140
+ end
131
141
 
132
- end
142
+ it "should be not public" do
143
+ @element.public.should be_false
144
+ end
133
145
 
134
- context "trashed" do
146
+ it "should have no page" do
147
+ @element.page.should == nil
148
+ end
135
149
 
136
- before(:each) do
137
- @element = FactoryGirl.create(:element)
138
- @element.trash
139
- end
150
+ context "collections" do
140
151
 
141
- it "should be not public" do
142
- @element.public.should be_false
143
- end
152
+ context "for trashed elements" do
144
153
 
145
- it "should have no page" do
146
- @element.page.should == nil
147
- end
154
+ let(:element) do
155
+ FactoryGirl.create(:element, :page_id => 1)
156
+ end
148
157
 
149
- it "should be folded" do
150
- @element.folded.should == true
151
- end
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
- end
164
+ it "should return a collection of not trashed elements" do
165
+ Element.not_trashed.should include(element)
166
+ end
154
167
 
155
- it "should raise error if all_for_page method has no page" do
156
- expect { Alchemy::Element.all_for_page(nil) }.should raise_error(TypeError)
157
- end
168
+ end
158
169
 
159
- describe "#content_by_type" do
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
- context "with namespaced essence type" do
174
+ describe "#trash" do
167
175
 
168
- it "should return content by passing a essence type" do
169
- @element.content_by_type('Alchemy::EssenceText').should == @content
176
+ before(:each) do
177
+ @element = FactoryGirl.create(:element, :page_id => 1, :cell_id => 1)
178
+ @element.trash
170
179
  end
171
180
 
172
- end
173
-
174
- context "without namespaced essence type" do
181
+ it "should remove the elements position" do
182
+ @element.position.should == nil
183
+ end
175
184
 
176
- it "should return content by passing a essence type" do
177
- @element.content_by_type('EssenceText').should == @content
185
+ it "should set the public state to false" do
186
+ @element.public?.should == false
178
187
  end
179
188
 
180
- end
189
+ it "should not remove the page_id" do
190
+ @element.page_id.should == 1
191
+ end
181
192
 
182
- end
193
+ it "should not remove the cell_id" do
194
+ @element.cell_id.should == 1
195
+ end
183
196
 
184
- describe "#all_contents_by_type" do
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
- context "with namespaced essence type" do
205
+ describe "#all_contents_by_type" do
192
206
 
193
- it "should return content by passing a essence type" do
194
- @element.all_contents_by_type('Alchemy::EssenceText').should == @contents
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
- end
212
+ context "with namespaced essence type" do
198
213
 
199
- context "without namespaced essence type" do
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
- end
220
+ context "without namespaced essence type" do
206
221
 
207
- end
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
- describe '#copy' do
226
+ end
210
227
 
211
- before(:each) do
212
- @element = FactoryGirl.create(:element)
213
228
  end
214
229
 
215
- it "should not create contents from scratch" do
216
- copy = Alchemy::Element.copy(@element)
217
- copy.contents.count.should == @element.contents.count
218
- end
230
+ describe '#copy' do
219
231
 
220
- it "should create a new record with all attributes of source except given differences" do
221
- copy = Alchemy::Element.copy(@element, {:name => 'foobar'})
222
- copy.name.should == 'foobar'
223
- end
232
+ before(:each) do
233
+ @element = FactoryGirl.create(:element)
234
+ end
224
235
 
225
- it "should make copies of all contents of source" do
226
- copy = Alchemy::Element.copy(@element)
227
- copy.contents.collect(&:id).should_not == @element.contents.collect(&:id)
228
- end
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
- end
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
- describe "Finding previous or next element." do
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 '#prev' do
253
+ describe "Finding previous or next element." do
243
254
 
244
- it "should return previous element on same page" do
245
- @element2.prev.should == @element1
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
- context "with name as parameter" do
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
- end
265
+ it "should return previous element on same page" do
266
+ @element2.prev.should == @element1
267
+ end
255
268
 
256
- describe '#next' do
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
- context "with name as parameter" do
263
- it "should return next of this kind" do
264
- @element1.next('text').should == @element3
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