alchemy_cms 2.2.4 → 2.3.rc5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/.travis.yml +3 -4
- data/Gemfile +1 -0
- data/README.md +10 -6
- data/alchemy_cms.gemspec +5 -2
- data/app/assets/images/alchemy/icons.png +0 -0
- data/app/assets/images/sassy-ie-overlay.png +0 -0
- data/app/assets/javascripts/alchemy/alchemy.base.js +50 -59
- data/app/assets/javascripts/alchemy/alchemy.buttons.js +14 -4
- data/app/assets/javascripts/alchemy/alchemy.datepicker.js +8 -2
- data/app/assets/javascripts/alchemy/alchemy.elements_window.js +11 -3
- data/app/assets/javascripts/alchemy/alchemy.gui.js.coffee +1 -1
- data/app/assets/javascripts/alchemy/alchemy.link_overlay.js.coffee +14 -1
- data/app/assets/javascripts/alchemy/alchemy.preview.js +1 -1
- data/app/assets/javascripts/alchemy/alchemy.preview_window.js +12 -4
- data/app/assets/javascripts/alchemy/alchemy.uploader.js +4 -1
- data/app/assets/javascripts/alchemy/alchemy.windows.js +18 -8
- data/app/assets/stylesheets/alchemy/_defaults.scss +84 -120
- data/app/assets/stylesheets/alchemy/alchemy.css +2 -2
- data/app/assets/stylesheets/alchemy/archive.css.scss +288 -0
- data/app/assets/stylesheets/alchemy/base.css.scss +95 -390
- data/app/assets/stylesheets/alchemy/dashboard.css.scss +4 -4
- data/app/assets/stylesheets/alchemy/elements.css.scss +83 -118
- data/app/assets/stylesheets/alchemy/flash.css.scss +1 -1
- data/app/assets/stylesheets/alchemy/form_elements.css.scss +528 -0
- data/app/assets/stylesheets/alchemy/frame.css.scss +13 -39
- data/app/assets/stylesheets/alchemy/icons.css.scss +217 -228
- data/app/assets/stylesheets/alchemy/jquery-ui.alchemy.css.scss +48 -50
- data/app/assets/stylesheets/alchemy/jquery.Jcrop.css.scss +1 -1
- data/app/assets/stylesheets/alchemy/login.css.scss +1 -5
- data/app/assets/stylesheets/alchemy/menubar.css.scss +19 -29
- data/app/assets/stylesheets/alchemy/pagination.css.scss +3 -4
- data/app/assets/stylesheets/alchemy/sitemap.css.scss +81 -81
- data/app/assets/stylesheets/alchemy/tables.css.scss +63 -57
- data/app/assets/stylesheets/alchemy/tinymce_dialog.css.scss +57 -57
- data/app/assets/stylesheets/alchemy/upload.css.scss +6 -6
- data/app/assets/stylesheets/tiny_mce/plugins/inlinepopups/skins/alchemy/window.css.scss +6 -10
- data/app/controllers/alchemy/admin/attachments_controller.rb +5 -4
- data/app/controllers/alchemy/admin/base_controller.rb +1 -9
- data/app/controllers/alchemy/admin/contents_controller.rb +4 -6
- data/app/controllers/alchemy/admin/elements_controller.rb +2 -2
- data/app/controllers/alchemy/admin/pages_controller.rb +2 -2
- data/app/controllers/alchemy/admin/pictures_controller.rb +74 -15
- data/app/controllers/alchemy/attachments_controller.rb +8 -2
- data/app/controllers/alchemy/base_controller.rb +47 -5
- data/app/controllers/alchemy/elements_controller.rb +1 -1
- data/app/controllers/alchemy/messages_controller.rb +12 -12
- data/app/controllers/alchemy/pages_controller.rb +5 -1
- data/app/controllers/alchemy/pictures_controller.rb +9 -4
- data/app/controllers/alchemy/user_sessions_controller.rb +2 -4
- data/app/helpers/alchemy/admin/base_helper.rb +98 -19
- data/app/helpers/alchemy/admin/contents_helper.rb +2 -2
- data/app/helpers/alchemy/admin/elements_helper.rb +2 -3
- data/app/helpers/alchemy/base_helper.rb +6 -5
- data/app/helpers/alchemy/elements_helper.rb +2 -2
- data/app/helpers/alchemy/essences_helper.rb +4 -5
- data/app/helpers/alchemy/pages_helper.rb +15 -79
- data/app/helpers/alchemy/url_helper.rb +67 -0
- data/app/mailers/alchemy/messages.rb +1 -1
- data/app/mailers/alchemy/notifications.rb +1 -1
- data/app/models/alchemy/attachment.rb +11 -2
- data/app/models/alchemy/cell.rb +20 -10
- data/app/models/alchemy/content.rb +4 -3
- data/app/models/alchemy/element.rb +170 -178
- data/app/models/alchemy/language/code.rb +4 -1
- data/app/models/alchemy/message.rb +19 -3
- data/app/models/alchemy/page.rb +45 -40
- data/app/models/alchemy/picture.rb +24 -2
- data/app/models/alchemy/user.rb +2 -3
- data/app/views/alchemy/admin/attachments/_archive_overlay.html.erb +12 -12
- data/app/views/alchemy/admin/attachments/_attachment.html.erb +1 -1
- data/app/views/alchemy/admin/attachments/create.js.erb +1 -0
- data/app/views/alchemy/admin/attachments/edit.html.erb +9 -3
- data/app/views/alchemy/admin/attachments/index.html.erb +3 -2
- data/app/views/alchemy/admin/contents/_missing.html.erb +1 -1
- data/app/views/alchemy/admin/contents/create.js.erb +54 -0
- data/app/views/alchemy/admin/contents/new.html.erb +9 -4
- data/app/views/alchemy/admin/elements/{_add_content.html.erb → _add_picture.html.erb} +4 -4
- data/app/views/alchemy/admin/elements/_elements_select.html.erb +2 -1
- data/app/views/alchemy/admin/elements/_new_element_form.html.erb +1 -1
- data/app/views/alchemy/admin/elements/{_picture_editor.html.erb → _picture_gallery_editor.html.erb} +7 -11
- data/app/views/alchemy/admin/elements/fold.js.erb +46 -0
- data/app/views/alchemy/admin/elements/index.html.erb +24 -24
- data/app/views/alchemy/admin/elements/list.js.erb +11 -9
- data/app/views/alchemy/admin/essence_files/assign.js.erb +3 -1
- data/app/views/alchemy/admin/essence_pictures/destroy.js.erb +28 -0
- data/app/views/alchemy/admin/pages/_contactform_links.html.erb +8 -6
- data/app/views/alchemy/admin/pages/_external_link.html.erb +11 -9
- data/app/views/alchemy/admin/pages/_file_link.html.erb +10 -8
- data/app/views/alchemy/admin/pages/_internal_link.html.erb +14 -10
- data/app/views/alchemy/admin/pages/_new_page_form.html.erb +1 -1
- data/app/views/alchemy/admin/pages/_page.html.erb +1 -1
- data/app/views/alchemy/admin/pages/_page_for_links.html.erb +32 -21
- data/app/views/alchemy/admin/pages/configure.html.erb +2 -2
- data/app/views/alchemy/admin/pages/configure_external.html.erb +13 -13
- data/app/views/alchemy/admin/pages/edit.html.erb +2 -2
- data/app/views/alchemy/admin/pages/index.html.erb +26 -24
- data/app/views/alchemy/admin/pages/link.html.erb +2 -5
- data/app/views/alchemy/admin/partials/_upload_form.html.erb +28 -12
- data/app/views/alchemy/admin/pictures/_archive.html.erb +54 -0
- data/app/views/alchemy/admin/pictures/_archive_overlay.html.erb +10 -7
- data/app/views/alchemy/admin/pictures/_filter_and_size_bar.html.erb +21 -22
- data/app/views/alchemy/admin/pictures/_filter_bar.html.erb +31 -0
- data/app/views/alchemy/admin/pictures/_overlay_picture_list.html.erb +9 -0
- data/app/views/alchemy/admin/pictures/_picture.html.erb +36 -6
- data/app/views/alchemy/admin/pictures/_tag_list.html.erb +27 -0
- data/app/views/alchemy/admin/pictures/archive_overlay.js.erb +3 -1
- data/app/views/alchemy/admin/pictures/create.js.erb +4 -5
- data/app/views/alchemy/admin/pictures/edit.html.erb +26 -0
- data/app/views/alchemy/admin/pictures/edit_multiple.html.erb +39 -0
- data/app/views/alchemy/admin/pictures/index.html.erb +81 -70
- data/app/views/alchemy/admin/pictures/index.js.erb +3 -0
- data/app/views/alchemy/admin/pictures/new.html.erb +1 -0
- data/app/views/alchemy/admin/resources/index.html.erb +3 -1
- data/app/views/alchemy/admin/users/_table.html.erb +1 -1
- data/app/views/alchemy/admin/users/index.html.erb +27 -23
- data/app/views/alchemy/elements/_article_editor.html.erb +7 -2
- data/app/views/alchemy/elements/_bild_editor.html.erb +1 -1
- data/app/views/alchemy/elements/_bild_text_editor.html.erb +6 -1
- data/app/views/alchemy/elements/_bild_text_view.html.erb +3 -3
- data/app/views/alchemy/elements/_image_mosaic_editor.html.erb +1 -1
- data/app/views/alchemy/elements/_image_mosaic_view.html.erb +2 -2
- data/app/views/alchemy/elements/_intro_image_text_view.html.erb +4 -4
- data/app/views/alchemy/elements/_searchresult_editor.html.erb +4 -1
- data/app/views/alchemy/essences/_essence_boolean_editor.html.erb +1 -1
- data/app/views/alchemy/essences/_essence_picture_editor.html.erb +2 -3
- data/app/views/alchemy/essences/_essence_picture_tools.html.erb +1 -1
- data/app/views/alchemy/search/_form.html.erb +8 -0
- data/app/views/alchemy/search/_result.html.erb +3 -2
- data/app/views/alchemy/search/_results.html.erb +28 -0
- data/app/views/alchemy/user_sessions/leave.html.erb +4 -4
- data/app/views/alchemy/user_sessions/login.html.erb +1 -2
- data/app/views/layouts/alchemy/admin.html.erb +30 -10
- data/app/views/layouts/alchemy/login.html.erb +2 -39
- data/config/alchemy/elements.yml +1 -2
- data/config/alchemy/page_layouts.yml +8 -5
- data/config/authorization_rules.rb +27 -18
- data/config/initializers/localeapp.rb +9 -0
- data/config/locales/alchemy.de.yml +93 -56
- data/config/locales/alchemy.en.yml +73 -50
- data/config/routes.rb +3 -1
- data/db/migrate/20120704181529_add_upload_hash_to_alchemy_picture.rb +5 -0
- data/db/migrate/20120705214247_acts_as_taggable_on_migration.rb +28 -0
- data/db/migrate/20120728185830_add_cached_tag_list_to_alchemy_pictures.rb +5 -0
- data/db/migrate/20120831135441_set_alchemy_languages_country_code_default_to_empty_string.rb +9 -0
- data/lib/alchemy/capistrano.rb +2 -2
- data/lib/alchemy/essence.rb +14 -0
- data/lib/alchemy/page_layout.rb +0 -6
- data/lib/alchemy/resource.rb +9 -15
- data/lib/alchemy/upgrader.rb +18 -3
- data/lib/alchemy/version.rb +5 -1
- data/lib/alchemy_cms.rb +4 -1
- data/lib/rails/generators/alchemy/deploy_script/deploy_script_generator.rb +16 -6
- data/lib/rails/generators/alchemy/deploy_script/templates/deploy.rb.tt +17 -3
- data/lib/rails/generators/alchemy/elements/elements_generator.rb +6 -1
- data/lib/rails/generators/alchemy/elements/templates/editor.html.erb +10 -1
- data/lib/rails/generators/alchemy/elements/templates/view.html.erb +17 -18
- data/lib/rails/generators/alchemy/scaffold/files/pages.html.erb +4 -2
- data/lib/tasks/fleximage.rake +2 -2
- data/spec/controllers/admin/contents_controller_spec.rb +2 -2
- data/spec/controllers/admin/elements_controller_spec.rb +30 -1
- data/spec/controllers/admin/pages_controller_spec.rb +35 -18
- data/spec/controllers/admin/trash_controller_spec.rb +40 -16
- data/spec/controllers/attachments_controller_spec.rb +62 -0
- data/spec/controllers/base_controller_spec.rb +43 -42
- data/spec/controllers/elements_controller_spec.rb +30 -0
- data/spec/controllers/pages_controller_spec.rb +22 -5
- data/spec/controllers/pictures_controller_spec.rb +82 -0
- data/spec/dummy/app/models/event.rb +2 -1
- data/spec/dummy/config/database.yml +3 -2
- data/spec/dummy/db/schema.rb +51 -27
- data/spec/factories.rb +29 -8
- data/spec/helpers/admin/base_helper_spec.rb +134 -21
- data/spec/helpers/admin/contents_helper_spec.rb +2 -2
- data/spec/helpers/admin/elements_helper_spec.rb +17 -9
- data/spec/helpers/admin/essences_helper_spec.rb +7 -6
- data/spec/helpers/essences_helper_spec.rb +8 -7
- data/spec/helpers/pages_helper_spec.rb +208 -325
- data/spec/helpers/url_helper_spec.rb +171 -0
- data/spec/integration/admin/link_overlay_spec.rb +53 -0
- data/spec/integration/admin/modules_integration_spec.rb +22 -26
- data/spec/integration/admin/pages_controller_spec.rb +10 -19
- data/spec/integration/admin/picture_library_integration_spec.rb +52 -0
- data/spec/integration/admin/resources_integration_spec.rb +68 -75
- data/spec/integration/pages_controller_spec.rb +70 -61
- data/spec/integration/security_spec.rb +3 -5
- data/spec/integration/translation_integration_spec.rb +56 -0
- data/spec/libraries/essence_spec.rb +18 -0
- data/spec/libraries/resource_spec.rb +101 -79
- data/spec/libraries/resources_helper_spec.rb +3 -0
- data/spec/models/content_spec.rb +63 -60
- data/spec/models/element_spec.rb +203 -93
- data/spec/models/language_spec.rb +90 -65
- data/spec/models/page_layout_spec.rb +37 -0
- data/spec/models/page_spec.rb +181 -113
- data/spec/models/picture_spec.rb +73 -26
- data/spec/models/resource_spec.rb +52 -23
- data/spec/support/alchemy/specs_helpers.rb +2 -0
- data/spec/support/image.png +0 -0
- data/spec/{helpers/url_helpers_spec.rb → url_helpers_spec.rb} +0 -0
- data/vendor/assets/javascripts/jquery_plugins/jquery.selectBoxIt.js +1909 -0
- data/vendor/assets/javascripts/jquery_plugins/preloadCssImages.jQuery_v5.js +152 -0
- metadata +106 -33
- data/app/assets/stylesheets/alchemy/buttons.css.scss +0 -361
- data/app/assets/stylesheets/alchemy/jquery.sb.css.scss +0 -260
- data/app/views/alchemy/admin/contents/create.js.coffee +0 -49
- data/app/views/alchemy/admin/elements/fold.js.coffee +0 -37
- data/app/views/alchemy/admin/essence_pictures/destroy.js.coffee +0 -19
- data/app/views/alchemy/admin/pictures/_pictures_list.html.erb +0 -16
- data/app/views/alchemy/admin/pictures/update.js.erb +0 -3
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/locales/fo.yml +0 -5
- data/spec/page_layout_spec.rb +0 -35
- data/vendor/assets/javascripts/jquery_plugins/jquery.in-place-edit.js +0 -172
- data/vendor/assets/javascripts/jquery_plugins/jquery.sb.min.js +0 -14
data/spec/models/content_spec.rb
CHANGED
@@ -1,100 +1,103 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
module Alchemy
|
4
|
+
describe Content do
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
let(:element) { FactoryGirl.create(:element, :name => 'headline', :create_contents_after_create => true) }
|
7
|
+
let(:content) { element.contents.find_by_essence_type('Alchemy::EssenceText') }
|
8
|
+
|
9
|
+
it "should return the ingredient from its essence" do
|
10
|
+
content.essence.update_attributes(:body => "Hello")
|
11
|
+
content.ingredient.should == "Hello"
|
12
|
+
end
|
11
13
|
|
12
|
-
|
14
|
+
describe '.normalize_essence_type' do
|
13
15
|
|
14
|
-
|
16
|
+
context "passing namespaced essence type" do
|
17
|
+
|
18
|
+
it "should not add alchemy namespace" do
|
19
|
+
Content.normalize_essence_type('Alchemy::EssenceText').should == "Alchemy::EssenceText"
|
20
|
+
end
|
15
21
|
|
16
|
-
it "should not add alchemy namespace" do
|
17
|
-
Alchemy::Content.normalize_essence_type('Alchemy::EssenceText').should == "Alchemy::EssenceText"
|
18
22
|
end
|
19
23
|
|
20
|
-
|
24
|
+
context "passing not namespaced essence type" do
|
21
25
|
|
22
|
-
|
26
|
+
it "should add alchemy namespace" do
|
27
|
+
Content.normalize_essence_type('EssenceText').should == "Alchemy::EssenceText"
|
28
|
+
end
|
23
29
|
|
24
|
-
it "should add alchemy namespace" do
|
25
|
-
Alchemy::Content.normalize_essence_type('EssenceText').should == "Alchemy::EssenceText"
|
26
30
|
end
|
27
31
|
|
28
32
|
end
|
29
33
|
|
30
|
-
|
34
|
+
describe '#normalized_essence_type' do
|
31
35
|
|
32
|
-
|
36
|
+
context "without namespace in essence_type column" do
|
33
37
|
|
34
|
-
|
38
|
+
it "should return the namespaced essence type" do
|
39
|
+
Content.new(:essence_type => 'EssenceText').normalized_essence_type.should == 'Alchemy::EssenceText'
|
40
|
+
end
|
35
41
|
|
36
|
-
it "should return the namespaced essence type" do
|
37
|
-
Alchemy::Content.new(:essence_type => 'EssenceText').normalized_essence_type.should == 'Alchemy::EssenceText'
|
38
42
|
end
|
39
43
|
|
40
|
-
|
44
|
+
context "with namespace in essence_type column" do
|
41
45
|
|
42
|
-
|
46
|
+
it "should return the namespaced essence type" do
|
47
|
+
Content.new(:essence_type => 'Alchemy::EssenceText').normalized_essence_type.should == 'Alchemy::EssenceText'
|
48
|
+
end
|
43
49
|
|
44
|
-
it "should return the namespaced essence type" do
|
45
|
-
Alchemy::Content.new(:essence_type => 'Alchemy::EssenceText').normalized_essence_type.should == 'Alchemy::EssenceText'
|
46
50
|
end
|
47
51
|
|
48
52
|
end
|
49
53
|
|
50
|
-
|
54
|
+
describe '#update_essence' do
|
51
55
|
|
52
|
-
|
56
|
+
it "should update the attributes of related essence and return true" do
|
57
|
+
@element = FactoryGirl.create(:element, :name => 'text', :create_contents_after_create => true)
|
58
|
+
@content = @element.contents.first
|
59
|
+
@content.update_essence(:body => 'Mikes Petshop')
|
60
|
+
@content.ingredient.should == "Mikes Petshop"
|
61
|
+
end
|
53
62
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
63
|
+
it "should add error messages if save fails and return false" do
|
64
|
+
@element = FactoryGirl.create(:element, :name => 'contactform', :create_contents_after_create => true)
|
65
|
+
@content = @element.contents.first
|
66
|
+
@content.update_essence
|
67
|
+
@content.errors[:essence].should have(1).item
|
68
|
+
end
|
60
69
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
70
|
+
it "should raise error if essence is missing" do
|
71
|
+
@element = FactoryGirl.create(:element, :name => 'text', :create_contents_after_create => true)
|
72
|
+
@content = @element.contents.first
|
73
|
+
@content.update_essence
|
74
|
+
end
|
67
75
|
|
68
|
-
it "should raise error if essence is missing" do
|
69
|
-
@element = FactoryGirl.create(:element, :name => 'text')
|
70
|
-
@content = @element.contents.first
|
71
|
-
@content.update_essence
|
72
76
|
end
|
73
77
|
|
74
|
-
|
78
|
+
describe '#copy' do
|
75
79
|
|
76
|
-
|
80
|
+
before(:each) do
|
81
|
+
@element = FactoryGirl.create(:element, :name => 'text', :create_contents_after_create => true)
|
82
|
+
@content = @element.contents.first
|
83
|
+
end
|
77
84
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
85
|
+
it "should create a new record with all attributes of source except given differences" do
|
86
|
+
copy = Content.copy(@content, {:name => 'foobar', :element_id => @element.id + 1})
|
87
|
+
copy.name.should == 'foobar'
|
88
|
+
end
|
82
89
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
90
|
+
it "should make a new record for essence of source" do
|
91
|
+
copy = Content.copy(@content, {:element_id => @element.id + 1})
|
92
|
+
copy.essence_id.should_not == @content.essence_id
|
93
|
+
end
|
87
94
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
95
|
+
it "should copy source essence attributes" do
|
96
|
+
copy = Content.copy(@content, {:element_id => @element.id + 1})
|
97
|
+
copy.essence.body == @content.essence.body
|
98
|
+
end
|
92
99
|
|
93
|
-
it "should copy source essence attributes" do
|
94
|
-
copy = Alchemy::Content.copy(@content, {:element_id => @element.id + 1})
|
95
|
-
copy.essence.body == @content.essence.body
|
96
100
|
end
|
97
101
|
|
98
102
|
end
|
99
|
-
|
100
103
|
end
|
data/spec/models/element_spec.rb
CHANGED
@@ -3,48 +3,101 @@ require 'spec_helper'
|
|
3
3
|
module Alchemy
|
4
4
|
describe Element do
|
5
5
|
|
6
|
-
|
6
|
+
describe '#new_from_scratch' do
|
7
7
|
|
8
|
-
|
9
|
-
Element.
|
8
|
+
it "should initialize an element by name from scratch" do
|
9
|
+
el = Element.new_from_scratch({'name' => 'article'})
|
10
|
+
el.should be_valid
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should raise an error if the given name is not defined in the elements.yml" do
|
14
|
+
expect { Element.new_from_scratch({'name' => 'foobar'}) }.to raise_error
|
10
15
|
end
|
11
16
|
|
17
|
+
it "should take the first part of an given name containing a hash (#)" do
|
18
|
+
el = Element.new_from_scratch({'name' => 'article#header'})
|
19
|
+
el.name.should == "article"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should merge given attributes into defined ones" do
|
23
|
+
el = Element.new_from_scratch({'name' => 'article', 'page_id' => 1})
|
24
|
+
el.page_id.should == 1
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not have forbidden attributes from definition" do
|
28
|
+
el = Element.new_from_scratch({'name' => 'article'})
|
29
|
+
el.contents.should == []
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context "scoped" do
|
35
|
+
|
12
36
|
it "should return all public elements" do
|
13
|
-
|
14
|
-
|
37
|
+
element_1 = FactoryGirl.create(:element, :public => true)
|
38
|
+
element_2 = FactoryGirl.create(:element, :public => true)
|
39
|
+
elements = Element.published.all
|
40
|
+
elements.should include(element_1)
|
41
|
+
elements.should include(element_2)
|
15
42
|
end
|
16
43
|
|
17
44
|
it "should return all elements by name" do
|
18
|
-
|
19
|
-
|
45
|
+
element_1 = FactoryGirl.create(:element, :name => 'article')
|
46
|
+
element_2 = FactoryGirl.create(:element, :name => 'article')
|
47
|
+
elements = Element.named(['article']).all
|
48
|
+
elements.should include(element_1)
|
49
|
+
elements.should include(element_2)
|
20
50
|
end
|
21
51
|
|
22
52
|
it "should return all elements but excluded ones" do
|
23
53
|
FactoryGirl.create(:element, :name => 'article')
|
24
54
|
FactoryGirl.create(:element, :name => 'article')
|
25
|
-
excluded =
|
26
|
-
Element.excluded(['
|
55
|
+
excluded = FactoryGirl.create(:element, :name => 'claim')
|
56
|
+
Element.excluded(['claim']).all.should_not include(excluded)
|
27
57
|
end
|
28
58
|
|
29
59
|
context "not_in_cell" do
|
60
|
+
|
30
61
|
it "should return all elements that are not in a cell" do
|
62
|
+
Element.delete_all
|
31
63
|
FactoryGirl.create(:element, :cell_id => 6)
|
32
64
|
FactoryGirl.create(:element, :cell_id => nil)
|
33
65
|
Element.not_in_cell.should have(1).element
|
34
66
|
end
|
67
|
+
|
35
68
|
end
|
36
69
|
|
37
70
|
end
|
38
71
|
|
39
|
-
|
40
|
-
|
41
|
-
definitions
|
42
|
-
|
43
|
-
|
72
|
+
describe '.all_definitions_for' do
|
73
|
+
|
74
|
+
it "should return a list of element definitions for a list of element names" do
|
75
|
+
element_names = ["article"]
|
76
|
+
definitions = Element.all_definitions_for(element_names)
|
77
|
+
definitions.first.fetch("name").should == 'article'
|
78
|
+
end
|
79
|
+
|
80
|
+
context "given 'all' as element name" do
|
81
|
+
|
82
|
+
before do
|
83
|
+
@element_definition = [
|
84
|
+
{'name' => 'article'},
|
85
|
+
{'name' => 'headline'}
|
86
|
+
]
|
87
|
+
Element.stub!(:definitions).and_return @element_definition
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should return all element definitions" do
|
91
|
+
Element.all_definitions_for('all').should == @element_definition
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should always return an array" do
|
97
|
+
definitions = Element.all_definitions_for(nil)
|
98
|
+
definitions.should == []
|
99
|
+
end
|
44
100
|
|
45
|
-
it "should always return an array calling all_definitions_for()" do
|
46
|
-
definitions = Element.all_definitions_for(nil)
|
47
|
-
definitions.should == []
|
48
101
|
end
|
49
102
|
|
50
103
|
context "no description files are found" do
|
@@ -65,56 +118,47 @@ module Alchemy
|
|
65
118
|
|
66
119
|
context "retrieving contents, essences and ingredients" do
|
67
120
|
|
68
|
-
|
69
|
-
@element = FactoryGirl.create(:element, :name => 'news')
|
70
|
-
end
|
121
|
+
let(:element) { FactoryGirl.create(:element, :name => 'news', :create_contents_after_create => true) }
|
71
122
|
|
72
123
|
it "should return an ingredient by name" do
|
73
|
-
|
124
|
+
element.ingredient('news_headline').should == EssenceText.first.ingredient
|
74
125
|
end
|
75
126
|
|
76
127
|
it "should return the content for rss title" do
|
77
|
-
|
128
|
+
element.content_for_rss_title.should == element.contents.find_by_name('news_headline')
|
78
129
|
end
|
79
130
|
|
80
131
|
it "should return the content for rss description" do
|
81
|
-
|
132
|
+
element.content_for_rss_description.should == element.contents.find_by_name('body')
|
82
133
|
end
|
83
134
|
|
84
135
|
end
|
85
136
|
|
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
137
|
context "limited amount" do
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
138
|
+
|
139
|
+
before do
|
140
|
+
defs = [
|
141
|
+
{
|
142
|
+
'name' => 'column_headline',
|
143
|
+
'amount' => 3,
|
144
|
+
'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}]
|
145
|
+
},
|
146
|
+
{
|
147
|
+
'name' => 'unique_headline',
|
148
|
+
'unique' => true,
|
149
|
+
'amount' => 3,
|
150
|
+
'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}]
|
151
|
+
}
|
152
|
+
]
|
153
|
+
# F&%#ing alias methods
|
154
|
+
Element.stub!(:definitions).and_return(defs)
|
155
|
+
Element.stub!(:descriptions).and_return(defs)
|
156
|
+
PageLayout.stub!(:get).and_return({
|
113
157
|
'name' => 'columns',
|
114
158
|
'elements' => ['column_headline', 'unique_headline'],
|
115
159
|
'autogenerate' => ['unique_headline', 'column_headline', 'column_headline', 'column_headline']
|
116
|
-
)
|
117
|
-
@page = FactoryGirl.create(:page, :page_layout => 'columns')
|
160
|
+
})
|
161
|
+
@page = FactoryGirl.create(:page, :page_layout => 'columns', :do_not_autogenerate => false)
|
118
162
|
end
|
119
163
|
|
120
164
|
it "should be readable" do
|
@@ -132,39 +176,22 @@ module Alchemy
|
|
132
176
|
|
133
177
|
end
|
134
178
|
|
135
|
-
context "
|
179
|
+
context "collections" do
|
136
180
|
|
137
|
-
|
138
|
-
@element = FactoryGirl.create(:element)
|
139
|
-
@element.trash
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should be not public" do
|
143
|
-
@element.public.should be_false
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should have no page" do
|
147
|
-
@element.page.should == nil
|
148
|
-
end
|
149
|
-
|
150
|
-
context "collections" do
|
181
|
+
context "for trashed elements" do
|
151
182
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
FactoryGirl.create(:element, :page_id => 1)
|
156
|
-
end
|
157
|
-
|
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
|
183
|
+
let(:element) do
|
184
|
+
FactoryGirl.create(:element, :page_id => 1)
|
185
|
+
end
|
163
186
|
|
164
|
-
|
165
|
-
|
166
|
-
|
187
|
+
it "should return a collection of trashed elements" do
|
188
|
+
not_trashed_element = FactoryGirl.create(:element)
|
189
|
+
element.trash
|
190
|
+
Element.trashed.should include(element)
|
191
|
+
end
|
167
192
|
|
193
|
+
it "should return a collection of not trashed elements" do
|
194
|
+
Element.not_trashed.should include(element)
|
168
195
|
end
|
169
196
|
|
170
197
|
end
|
@@ -202,6 +229,35 @@ module Alchemy
|
|
202
229
|
|
203
230
|
end
|
204
231
|
|
232
|
+
it "should raise error if all_for_page method has no page" do
|
233
|
+
expect { Element.all_for_page(nil) }.to raise_error(TypeError)
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "#content_by_type" do
|
237
|
+
|
238
|
+
before(:each) do
|
239
|
+
@element = FactoryGirl.create(:element, :name => 'headline')
|
240
|
+
@content = @element.contents.first
|
241
|
+
end
|
242
|
+
|
243
|
+
context "with namespaced essence type" do
|
244
|
+
|
245
|
+
it "should return content by passing a essence type" do
|
246
|
+
@element.content_by_type('Alchemy::EssenceText').should == @content
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
context "without namespaced essence type" do
|
252
|
+
|
253
|
+
it "should return content by passing a essence type" do
|
254
|
+
@element.content_by_type('EssenceText').should == @content
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|
258
|
+
|
259
|
+
end
|
260
|
+
|
205
261
|
describe "#all_contents_by_type" do
|
206
262
|
|
207
263
|
before(:each) do
|
@@ -229,35 +285,33 @@ module Alchemy
|
|
229
285
|
|
230
286
|
describe '#copy' do
|
231
287
|
|
232
|
-
|
233
|
-
@element = FactoryGirl.create(:element)
|
234
|
-
end
|
288
|
+
let(:element) { FactoryGirl.create(:element, :create_contents_after_create => true) }
|
235
289
|
|
236
290
|
it "should not create contents from scratch" do
|
237
|
-
copy = Element.copy(
|
238
|
-
copy.contents.count.should ==
|
291
|
+
copy = Element.copy(element)
|
292
|
+
copy.contents.count.should == element.contents.count
|
239
293
|
end
|
240
294
|
|
241
295
|
it "should create a new record with all attributes of source except given differences" do
|
242
|
-
copy = Element.copy(
|
296
|
+
copy = Element.copy(element, {:name => 'foobar'})
|
243
297
|
copy.name.should == 'foobar'
|
244
298
|
end
|
245
299
|
|
246
300
|
it "should make copies of all contents of source" do
|
247
|
-
copy = Element.copy(
|
248
|
-
copy.contents.collect(&:id).should_not ==
|
301
|
+
copy = Element.copy(element)
|
302
|
+
copy.contents.collect(&:id).should_not == element.contents.collect(&:id)
|
249
303
|
end
|
250
304
|
|
251
305
|
end
|
252
306
|
|
253
307
|
describe "Finding previous or next element." do
|
254
308
|
|
309
|
+
let(:page) { FactoryGirl.create(:language_root_page) }
|
310
|
+
|
255
311
|
before(:each) do
|
256
|
-
@
|
257
|
-
@page
|
258
|
-
@
|
259
|
-
@element2 = FactoryGirl.create(:element, :page => @page)
|
260
|
-
@element3 = FactoryGirl.create(:element, :page => @page, :name => 'text')
|
312
|
+
@element1 = FactoryGirl.create(:element, :page => page, :name => 'headline')
|
313
|
+
@element2 = FactoryGirl.create(:element, :page => page)
|
314
|
+
@element3 = FactoryGirl.create(:element, :page => page, :name => 'text')
|
261
315
|
end
|
262
316
|
|
263
317
|
describe '#prev' do
|
@@ -290,5 +344,61 @@ module Alchemy
|
|
290
344
|
|
291
345
|
end
|
292
346
|
|
347
|
+
describe '#belonging_cellnames' do
|
348
|
+
|
349
|
+
before do
|
350
|
+
@page = FactoryGirl.create(:public_page)
|
351
|
+
@element = FactoryGirl.create(:element, :page => @page)
|
352
|
+
end
|
353
|
+
|
354
|
+
context "with page having cells defining the correct elements" do
|
355
|
+
|
356
|
+
before do
|
357
|
+
Cell.stub!(:definitions).and_return([
|
358
|
+
{'name' => 'header', 'elements' => ['article', 'headline']},
|
359
|
+
{'name' => 'footer', 'elements' => ['article', 'text']},
|
360
|
+
{'name' => 'sidebar', 'elements' => ['teaser']}
|
361
|
+
])
|
362
|
+
end
|
363
|
+
|
364
|
+
it "should return a list of all cells from given page this element could be placed in" do
|
365
|
+
@header_cell = FactoryGirl.create(:cell, :name => 'header', :page => @page)
|
366
|
+
@footer_cell = FactoryGirl.create(:cell, :name => 'footer', :page => @page)
|
367
|
+
@sidebar_cell = FactoryGirl.create(:cell, :name => 'sidebar', :page => @page)
|
368
|
+
@element.belonging_cellnames(@page).should include('header')
|
369
|
+
@element.belonging_cellnames(@page).should include('footer')
|
370
|
+
end
|
371
|
+
|
372
|
+
context "but without any cells" do
|
373
|
+
|
374
|
+
it "should return the 'nil cell'" do
|
375
|
+
@element.belonging_cellnames(@page).should == ['for_other_elements']
|
376
|
+
end
|
377
|
+
|
378
|
+
end
|
379
|
+
|
380
|
+
end
|
381
|
+
|
382
|
+
context "with page having cells defining the wrong elements" do
|
383
|
+
|
384
|
+
before do
|
385
|
+
Cell.stub!(:definitions).and_return([
|
386
|
+
{'name' => 'header', 'elements' => ['download', 'headline']},
|
387
|
+
{'name' => 'footer', 'elements' => ['contactform', 'text']},
|
388
|
+
{'name' => 'sidebar', 'elements' => ['teaser']}
|
389
|
+
])
|
390
|
+
end
|
391
|
+
|
392
|
+
it "should return the 'nil cell'" do
|
393
|
+
@header_cell = FactoryGirl.create(:cell, :name => 'header', :page => @page)
|
394
|
+
@footer_cell = FactoryGirl.create(:cell, :name => 'footer', :page => @page)
|
395
|
+
@sidebar_cell = FactoryGirl.create(:cell, :name => 'sidebar', :page => @page)
|
396
|
+
@element.belonging_cellnames(@page).should == ['for_other_elements']
|
397
|
+
end
|
398
|
+
|
399
|
+
end
|
400
|
+
|
401
|
+
end
|
402
|
+
|
293
403
|
end
|
294
404
|
end
|