alchemy_cms 2.6.3 → 2.7.0
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.
- checksums.yaml +4 -4
- data/.simplecov +14 -0
- data/.travis.yml +1 -1
- data/Gemfile +7 -6
- data/README.md +15 -5
- data/alchemy_cms.gemspec +3 -2
- data/app/assets/javascripts/alchemy/alchemy.base.js.coffee +9 -17
- data/app/assets/javascripts/alchemy/alchemy.dirty.js.coffee +70 -0
- data/app/assets/javascripts/alchemy/alchemy.dragndrop.js.coffee +80 -0
- data/app/assets/javascripts/alchemy/alchemy.element_editors.js.coffee +43 -19
- data/app/assets/javascripts/alchemy/alchemy.gui.js.coffee +3 -1
- data/app/assets/javascripts/alchemy/alchemy.js +4 -2
- data/app/assets/javascripts/alchemy/alchemy.onload.js.coffee +1 -1
- data/app/assets/javascripts/alchemy/alchemy.spinner.js.coffee +14 -0
- data/app/assets/javascripts/alchemy/alchemy.tinymce.js.coffee.erb +96 -0
- data/app/assets/javascripts/alchemy/alchemy.translations.js.coffee +22 -0
- data/app/assets/javascripts/alchemy/alchemy.windows.js.coffee +28 -17
- data/app/assets/stylesheets/alchemy/base.scss +6 -0
- data/app/assets/stylesheets/alchemy/elements.scss +2 -28
- data/app/assets/stylesheets/alchemy/errors.scss +1 -1
- data/app/assets/stylesheets/alchemy/menubar.css.scss +2 -0
- data/app/assets/stylesheets/alchemy/sitemap.scss +21 -34
- data/app/assets/stylesheets/alchemy/tables.scss +13 -3
- data/app/controllers/alchemy/admin/attachments_controller.rb +10 -5
- data/app/controllers/alchemy/admin/base_controller.rb +19 -0
- data/app/controllers/alchemy/admin/contents_controller.rb +1 -4
- data/app/controllers/alchemy/admin/dashboard_controller.rb +2 -1
- data/app/controllers/alchemy/admin/elements_controller.rb +1 -1
- data/app/controllers/alchemy/admin/essence_files_controller.rb +1 -1
- data/app/controllers/alchemy/admin/essence_pictures_controller.rb +70 -56
- data/app/controllers/alchemy/admin/pages_controller.rb +37 -114
- data/app/controllers/alchemy/admin/pictures_controller.rb +5 -12
- data/app/controllers/alchemy/admin/resources_controller.rb +3 -1
- data/app/controllers/alchemy/admin/trash_controller.rb +1 -1
- data/app/controllers/alchemy/attachments_controller.rb +1 -1
- data/app/controllers/alchemy/base_controller.rb +3 -15
- data/app/controllers/alchemy/messages_controller.rb +4 -10
- data/app/controllers/alchemy/pages_controller.rb +6 -6
- data/app/controllers/alchemy/passwords_controller.rb +1 -1
- data/app/controllers/alchemy/user_sessions_controller.rb +1 -1
- data/app/helpers/alchemy/admin/base_helper.rb +49 -230
- data/app/helpers/alchemy/admin/contents_helper.rb +5 -1
- data/app/helpers/alchemy/admin/elements_helper.rb +19 -47
- data/app/helpers/alchemy/admin/essences_helper.rb +59 -17
- data/app/helpers/alchemy/admin/navigation_helper.rb +204 -0
- data/app/helpers/alchemy/admin/pages_helper.rb +22 -79
- data/app/helpers/alchemy/admin/pictures_helper.rb +1 -1
- data/app/helpers/alchemy/admin/tags_helper.rb +42 -0
- data/app/helpers/alchemy/base_helper.rb +0 -11
- data/app/helpers/alchemy/elements_helper.rb +48 -25
- data/app/helpers/alchemy/essences_helper.rb +0 -20
- data/app/helpers/alchemy/pages_helper.rb +18 -14
- data/app/helpers/alchemy/url_helper.rb +1 -0
- data/app/mailers/alchemy/messages.rb +4 -6
- data/app/models/alchemy/attachment.rb +3 -0
- data/app/models/alchemy/cell.rb +33 -35
- data/app/models/alchemy/content.rb +20 -111
- data/app/models/alchemy/content/factory.rb +188 -0
- data/app/models/alchemy/element.rb +51 -200
- data/app/models/alchemy/element/definitions.rb +52 -0
- data/app/models/alchemy/element/presenters.rb +87 -0
- data/app/models/alchemy/essence_date.rb +1 -1
- data/app/models/alchemy/essence_file.rb +6 -7
- data/app/models/alchemy/essence_picture.rb +19 -4
- data/app/models/alchemy/message.rb +18 -14
- data/app/models/alchemy/page.rb +120 -214
- data/app/models/alchemy/page/elements.rb +145 -36
- data/app/models/alchemy/page/natures.rb +90 -0
- data/app/models/alchemy/page/scopes.rb +93 -0
- data/app/models/alchemy/page/users.rb +25 -0
- data/app/models/alchemy/picture.rb +15 -0
- data/app/models/alchemy/site.rb +15 -1
- data/app/models/alchemy/site/layout.rb +38 -0
- data/app/models/alchemy/user.rb +13 -3
- data/app/views/alchemy/admin/attachments/_archive_overlay.html.erb +7 -7
- data/app/views/alchemy/admin/attachments/_file_to_assign.html.erb +8 -8
- data/app/views/alchemy/admin/attachments/_tag_list.html.erb +1 -16
- data/app/views/alchemy/admin/attachments/destroy.js.erb +1 -4
- data/app/views/alchemy/admin/contents/create.js.erb +1 -1
- data/app/views/alchemy/admin/dashboard/index.html.erb +14 -13
- data/app/views/alchemy/admin/elements/_element_head.html.erb +7 -7
- data/app/views/alchemy/admin/elements/_refresh_editor.js.erb +10 -0
- data/app/views/alchemy/admin/elements/create.js.erb +44 -44
- data/app/views/alchemy/admin/elements/fold.js.erb +22 -26
- data/app/views/alchemy/admin/elements/trash.js.erb +1 -1
- data/app/views/alchemy/admin/elements/update.js.erb +22 -25
- data/app/views/alchemy/admin/essence_files/assign.js.erb +8 -3
- data/app/views/alchemy/admin/essence_pictures/crop.html.erb +14 -12
- data/app/views/alchemy/admin/essence_pictures/edit.html.erb +22 -39
- data/app/views/alchemy/admin/pages/_page.html.erb +73 -80
- data/app/views/alchemy/admin/pages/destroy.js.erb +2 -2
- data/app/views/alchemy/admin/pages/edit.html.erb +21 -18
- data/app/views/alchemy/admin/pages/fold.js.erb +1 -0
- data/app/views/alchemy/admin/pages/info.html.erb +32 -0
- data/app/views/alchemy/admin/partials/_main_navigation_entry.html.erb +11 -13
- data/app/views/alchemy/admin/partials/_remote_search_form.html.erb +20 -20
- data/app/views/alchemy/admin/partials/_sub_navigation.html.erb +8 -0
- data/app/views/alchemy/admin/partials/_toolbar_button.html.erb +25 -0
- data/app/views/alchemy/admin/partials/_upload_form.html.erb +15 -15
- data/app/views/alchemy/admin/pictures/_filter_and_size_bar.html.erb +39 -39
- data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +10 -10
- data/app/views/alchemy/admin/pictures/_tag_list.html.erb +1 -16
- data/app/views/alchemy/admin/resources/destroy.js.erb +1 -1
- data/app/views/alchemy/base/500.html.erb +1 -1
- data/app/views/alchemy/base/permission_denied.js.erb +1 -1
- data/app/views/alchemy/base/redirect.js.erb +1 -1
- data/app/views/alchemy/essences/_essence_link_editor.html.erb +1 -1
- data/app/views/alchemy/essences/_essence_picture_editor.html.erb +1 -1
- data/app/views/alchemy/essences/_essence_richtext_editor.html.erb +1 -1
- data/app/views/alchemy/essences/_essence_text_editor.html.erb +1 -1
- data/app/views/alchemy/essences/{_essence_picture_tools.html.erb → shared/_essence_picture_tools.html.erb} +5 -5
- data/app/views/alchemy/essences/{_linkable_essence_tools.html.erb → shared/_linkable_essence_tools.html.erb} +0 -0
- data/app/views/alchemy/messages/contact_form_mail.de.text.erb +12 -0
- data/app/views/alchemy/messages/contact_form_mail.en.text.erb +12 -0
- data/app/views/alchemy/notifications/reset_password_instructions.de.text.erb +1 -1
- data/app/views/alchemy/notifications/reset_password_instructions.en.text.erb +2 -2
- data/app/views/alchemy/pages/sitemap.xml.erb +3 -5
- data/app/views/alchemy/user_sessions/leave.html.erb +1 -1
- data/app/views/layouts/alchemy/admin.html.erb +4 -2
- data/app/views/layouts/alchemy/sitemap.xml.erb +1 -1
- data/bin/alchemy +7 -13
- data/config/alchemy/config.yml +1 -0
- data/config/authorization_rules.rb +2 -3
- data/config/initializers/dragonfly.rb +2 -0
- data/config/locales/alchemy.de.yml +8 -9
- data/config/locales/alchemy.en.yml +7 -4
- data/config/routes.rb +3 -0
- data/db/migrate/{20130214233001_alchemy_two_point_five.rb → 20130827094554_alchemy_two_point_six.rb} +29 -6
- data/lib/alchemy/auth/engine.rb +9 -0
- data/lib/alchemy/capistrano.rb +37 -12
- data/lib/alchemy/config.rb +48 -35
- data/lib/alchemy/engine.rb +35 -6
- data/lib/alchemy/essence.rb +25 -29
- data/lib/alchemy/ferret/search.rb +86 -0
- data/lib/alchemy/{scoped_pagination_url_helper.rb → kaminari/scoped_pagination_url_helper.rb} +0 -0
- data/lib/alchemy/logger.rb +3 -4
- data/lib/alchemy/page_layout.rb +124 -55
- data/lib/alchemy/resource.rb +0 -10
- data/lib/alchemy/resources_helper.rb +0 -5
- data/lib/alchemy/seeder.rb +1 -32
- data/lib/alchemy/shell.rb +6 -1
- data/lib/alchemy/tinymce.rb +41 -32
- data/lib/alchemy/upgrader.rb +3 -1
- data/lib/alchemy/upgrader/two_point_five.rb +15 -8
- data/lib/alchemy/upgrader/two_point_one.rb +10 -10
- data/lib/alchemy/upgrader/two_point_two.rb +96 -51
- data/lib/alchemy/version.rb +1 -1
- data/lib/alchemy_cms.rb +5 -46
- data/lib/rails/generators/alchemy/deploy_script/templates/deploy.rb.tt +1 -1
- data/lib/rails/generators/alchemy/devise/devise_generator.rb +9 -4
- data/lib/rails/generators/alchemy/essence/essence_generator.rb +7 -6
- data/lib/rails/generators/alchemy/essence/templates/editor.html.erb +1 -1
- data/lib/rails/generators/alchemy/scaffold/files/_standard.html.erb +1 -0
- data/lib/rails/generators/alchemy/scaffold/scaffold_generator.rb +1 -0
- data/lib/rails/generators/alchemy/site_layouts/site_layouts_generator.rb +23 -0
- data/lib/rails/generators/alchemy/site_layouts/templates/layout.html.erb +1 -0
- data/lib/rails/generators/alchemy/site_layouts/templates/layout.html.haml +1 -0
- data/lib/rails/generators/alchemy/site_layouts/templates/layout.html.slim +1 -0
- data/lib/rails/templates/alchemy.rb +2 -2
- data/lib/tasks/alchemy/db.rake +3 -1
- data/lib/tasks/alchemy/tidy.rake +82 -0
- data/lib/tasks/alchemy/upgrade.rake +2 -1
- data/spec/controllers/admin/attachments_controller_spec.rb +124 -0
- data/spec/controllers/admin/base_controller_spec.rb +35 -0
- data/spec/controllers/admin/clipboard_controller_spec.rb +1 -1
- data/spec/controllers/admin/contents_controller_spec.rb +17 -26
- data/spec/controllers/admin/dashboard_controller_spec.rb +121 -0
- data/spec/controllers/admin/elements_controller_spec.rb +1 -1
- data/spec/controllers/admin/essence_files_controller_spec.rb +67 -0
- data/spec/controllers/admin/essence_pictures_controller_spec.rb +161 -0
- data/spec/controllers/admin/languages_controller_spec.rb +1 -1
- data/spec/controllers/admin/layoutpages_controller_spec.rb +28 -0
- data/spec/controllers/admin/pages_controller_spec.rb +164 -118
- data/spec/controllers/admin/pictures_controller_spec.rb +89 -0
- data/spec/controllers/admin/trash_controller_spec.rb +21 -31
- data/spec/controllers/admin/users_controller_spec.rb +114 -85
- data/spec/controllers/attachments_controller_spec.rb +6 -2
- data/spec/controllers/base_controller_spec.rb +22 -0
- data/spec/controllers/elements_controller_spec.rb +1 -1
- data/spec/controllers/messages_controller_spec.rb +200 -0
- data/spec/controllers/pictures_controller_spec.rb +1 -1
- data/spec/controllers/user_sessions_controller_spec.rb +7 -6
- data/spec/controllers/users_controller_spec.rb +2 -2
- data/spec/dummy/config/alchemy/cells.yml +2 -0
- data/spec/dummy/config/application.rb +19 -8
- data/spec/dummy/db/migrate/{20130214233001_alchemy_two_point_five.rb → 20130827094554_alchemy_two_point_six.rb} +29 -6
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/fast_specs.rb +15 -0
- data/spec/helpers/admin/base_helper_spec.rb +53 -34
- data/spec/helpers/admin/contents_helper_spec.rb +15 -7
- data/spec/helpers/admin/elements_helper_spec.rb +79 -34
- data/spec/helpers/admin/essences_helper_spec.rb +45 -31
- data/spec/helpers/admin/navigation_helper_spec.rb +204 -0
- data/spec/helpers/admin/pages_helper_spec.rb +25 -15
- data/spec/helpers/admin/tags_helper_spec.rb +62 -2
- data/spec/helpers/elements_helper_spec.rb +202 -138
- data/spec/helpers/pages_helper_spec.rb +48 -0
- data/spec/helpers/url_helper_spec.rb +7 -0
- data/spec/libraries/config_spec.rb +110 -3
- data/spec/libraries/essence_spec.rb +29 -9
- data/spec/libraries/page_layout_spec.rb +134 -0
- data/spec/libraries/resource_spec.rb +3 -16
- data/spec/libraries/resources_helper_spec.rb +4 -8
- data/spec/libraries/shell_spec.rb +1 -0
- data/spec/libraries/tinymce_spec.rb +61 -0
- data/spec/mailers/messages_spec.rb +23 -0
- data/spec/models/attachment_spec.rb +45 -0
- data/spec/models/cell_spec.rb +62 -9
- data/spec/models/content_spec.rb +110 -28
- data/spec/models/element_spec.rb +275 -253
- data/spec/models/essence_date_spec.rb +25 -0
- data/spec/models/essence_file_spec.rb +23 -0
- data/spec/models/essence_html_spec.rb +13 -0
- data/spec/models/essence_picture_spec.rb +16 -0
- data/spec/models/essence_text_spec.rb +29 -0
- data/spec/models/language_spec.rb +34 -0
- data/spec/models/message_spec.rb +43 -0
- data/spec/models/page_spec.rb +726 -567
- data/spec/models/picture_spec.rb +98 -0
- data/spec/models/site_spec.rb +60 -2
- data/spec/models/tag_spec.rb +31 -0
- data/spec/models/user_spec.rb +4 -4
- data/spec/spec_helper.rb +49 -58
- data/spec/support/alchemy/controller_helpers.rb +35 -0
- data/spec/support/alchemy/{specs_helpers.rb → integration_helpers.rb} +4 -8
- data/spec/{factories.rb → support/factories.rb} +11 -1
- data/vendor/assets/javascripts/jquery_plugins/jquery.ui.nestedSortable.js +2 -8
- metadata +166 -106
- data/Guardfile +0 -16
- data/app/assets/javascripts/alchemy/alchemy.dirty.js +0 -93
- data/app/assets/javascripts/alchemy/alchemy.dragndrop.js +0 -122
- data/app/models/alchemy/tree_node.rb +0 -4
- data/app/views/alchemy/admin/pages/_page_infos.html.erb +0 -3
- data/app/views/alchemy/admin/partials/_sub_navigation_tab.html.erb +0 -8
- data/app/views/alchemy/messages/contact_form_mail.text.erb +0 -12
- data/config/initializers/kaminari_config.rb +0 -9
- data/db/migrate/20130221200514_migrate_attachments_to_dragonfly.rb +0 -21
- data/db/migrate/20130312205327_change_alchemy_users_role_to_roles.rb +0 -11
- data/lib/alchemy/auth_engine.rb +0 -7
- data/lib/alchemy/authentication_helpers.rb +0 -9
- data/lib/alchemy/ferret_search.rb +0 -84
- data/lib/extensions/array.rb +0 -25
- data/lib/extensions/hash.rb +0 -34
- data/spec/dummy/db/migrate/20130221200514_migrate_attachments_to_dragonfly.rb +0 -21
- data/spec/dummy/db/migrate/20130312205327_change_alchemy_users_role_to_roles.rb +0 -11
- data/spec/models/page_layout_spec.rb +0 -60
|
@@ -1,57 +1,71 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Alchemy::Admin::EssencesHelper do
|
|
4
|
+
include Alchemy::Admin::ElementsHelper
|
|
4
5
|
|
|
5
6
|
let(:element) { FactoryGirl.create(:element, :name => 'article', :create_contents_after_create => true) }
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
describe 'essence rendering' do
|
|
9
|
+
before do
|
|
10
|
+
element.content_by_name('intro').essence.update_attributes(:body => 'hello!')
|
|
11
|
+
end
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
it "should render an essence editor" do
|
|
14
|
+
content = element.content_by_name('intro')
|
|
15
|
+
helper.render_essence_editor(content).should match(/input.+type="text".+value="hello!/)
|
|
16
|
+
end
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
it "should render an essence editor by name" do
|
|
19
|
+
helper.render_essence_editor_by_name(element, 'intro').should match(/input.+type="text".+value="hello!/)
|
|
20
|
+
end
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
it "should render an essence editor by type" do
|
|
23
|
+
helper.render_essence_editor_by_type(element, 'EssenceText').should match(/input.+type="text".+value="hello!/)
|
|
24
|
+
end
|
|
22
25
|
end
|
|
23
26
|
|
|
24
|
-
describe '#
|
|
25
|
-
|
|
26
|
-
let(:
|
|
27
|
-
let(:
|
|
28
|
-
let(:
|
|
29
|
-
let(:page_b) { FactoryGirl.create(:public_page, :name => 'Page B') }
|
|
30
|
-
let(:page_c) { FactoryGirl.create(:public_page, :name => 'Page C') }
|
|
27
|
+
describe '#pages_for_select' do
|
|
28
|
+
let(:contact_form) { FactoryGirl.create(:element, :name => 'contactform', :create_contents_after_create => true) }
|
|
29
|
+
let(:page_a) { FactoryGirl.create(:public_page, :name => 'Page A') }
|
|
30
|
+
let(:page_b) { FactoryGirl.create(:public_page, :name => 'Page B') }
|
|
31
|
+
let(:page_c) { FactoryGirl.create(:public_page, :name => 'Page C', :parent_id => page_b.id) }
|
|
31
32
|
|
|
32
33
|
before do
|
|
33
|
-
|
|
34
|
-
contact_page
|
|
34
|
+
# to be shure the ordering is alphabetic
|
|
35
35
|
page_b
|
|
36
|
-
page_c
|
|
37
36
|
page_a
|
|
37
|
+
helper.session[:language_id] = 1
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
context "with
|
|
40
|
+
context "with no arguments given" do
|
|
41
|
+
it "should return options for select with all pages ordered by lft" do
|
|
42
|
+
helper.pages_for_select.should match(/option.*Page B.*Page A/m)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should return options for select with nested page names" do
|
|
46
|
+
page_c
|
|
47
|
+
output = helper.pages_for_select
|
|
48
|
+
output.should match(/option.*Startseite.*> Page B.*> Page C.*> Page A/m)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
41
51
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
context "with pages passed in" do
|
|
53
|
+
before do
|
|
54
|
+
@pages = []
|
|
55
|
+
3.times { @pages << FactoryGirl.create(:public_page) }
|
|
46
56
|
end
|
|
47
57
|
|
|
48
|
-
it "should
|
|
49
|
-
output = helper.
|
|
50
|
-
output.should match(
|
|
58
|
+
it "should return options for select with only these pages" do
|
|
59
|
+
output = helper.pages_for_select(@pages)
|
|
60
|
+
output.should match(/#{@pages.collect(&:name).join('.*')}/m)
|
|
61
|
+
output.should_not match(/Page A/m)
|
|
51
62
|
end
|
|
52
63
|
|
|
64
|
+
it "should not nest the page names" do
|
|
65
|
+
output = helper.pages_for_select(@pages)
|
|
66
|
+
output.should_not match(/option.* /m)
|
|
67
|
+
end
|
|
53
68
|
end
|
|
54
|
-
|
|
55
69
|
end
|
|
56
70
|
|
|
57
71
|
end
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Alchemy::Admin::NavigationHelper do
|
|
4
|
+
let(:alchemy_module) { {
|
|
5
|
+
'name' => 'dashboard',
|
|
6
|
+
'engine_name' => 'alchemy',
|
|
7
|
+
'navigation' => {
|
|
8
|
+
'name' => 'modules.dashboard',
|
|
9
|
+
'controller' => 'alchemy/admin/dashboard',
|
|
10
|
+
'action' => 'index',
|
|
11
|
+
'icon' => 'dashboard',
|
|
12
|
+
'sub_navigation' => [{
|
|
13
|
+
'controller' => 'alchemy/admin/layoutpages',
|
|
14
|
+
'action' => 'index'
|
|
15
|
+
}]
|
|
16
|
+
}
|
|
17
|
+
} }
|
|
18
|
+
|
|
19
|
+
let(:event_module) { {
|
|
20
|
+
'navigation' => {
|
|
21
|
+
'controller' => 'admin/events',
|
|
22
|
+
'action' => 'index',
|
|
23
|
+
'sub_navigation' => [{
|
|
24
|
+
'controller' => 'admin/events',
|
|
25
|
+
'action' => 'index'
|
|
26
|
+
}]
|
|
27
|
+
}
|
|
28
|
+
} }
|
|
29
|
+
|
|
30
|
+
let(:navigation) { alchemy_module['navigation'] }
|
|
31
|
+
|
|
32
|
+
describe '#alchemy_main_navigation_entry' do
|
|
33
|
+
before {
|
|
34
|
+
helper.stub(:url_for_module).and_return('')
|
|
35
|
+
helper.stub(:_t).and_return(alchemy_module['name'])
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
context "with permission" do
|
|
39
|
+
before {
|
|
40
|
+
helper.stub(:permitted_to?).and_return(true)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
it "renders the main navigation entry partial" do
|
|
44
|
+
helper.alchemy_main_navigation_entry(alchemy_module).should match /<a.+class="main_navi_entry/
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context "without permission" do
|
|
49
|
+
before {
|
|
50
|
+
helper.stub(:permitted_to?).and_return(false)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
it "returns empty string" do
|
|
54
|
+
helper.alchemy_main_navigation_entry(alchemy_module).should be_empty
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe '#admin_subnavigation' do
|
|
60
|
+
before {
|
|
61
|
+
helper.stub(:current_alchemy_module).and_return(alchemy_module)
|
|
62
|
+
helper.stub(:url_for_module_sub_navigation).and_return('')
|
|
63
|
+
helper.stub(:_t).and_return(alchemy_module['name'])
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
context "with permission" do
|
|
67
|
+
before {
|
|
68
|
+
helper.stub(:permitted_to?).and_return(true)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
it "renders the sub navigation for current module" do
|
|
72
|
+
helper.admin_subnavigation.should match /<div.+class="subnavi_tab/
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context "without permission" do
|
|
77
|
+
before {
|
|
78
|
+
helper.stub(:permitted_to?).and_return(false)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
it "renders the sub navigation for current module" do
|
|
82
|
+
helper.admin_subnavigation.should be_empty
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context "without a module present" do
|
|
87
|
+
before {
|
|
88
|
+
helper.stub(:current_alchemy_module).and_return(nil)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
it "returns nil" do
|
|
92
|
+
helper.admin_subnavigation.should be_nil
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe '#navigate_module' do
|
|
98
|
+
it "returns array with symbolized controller and action name" do
|
|
99
|
+
helper.navigate_module(navigation).should == [:index, :alchemy_admin_dashboard]
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
describe '#main_navigation_css_classes' do
|
|
104
|
+
it "returns string with css classes for main navigation entry" do
|
|
105
|
+
helper.main_navigation_css_classes(navigation).should == "main_navi_entry"
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context "with active entry" do
|
|
109
|
+
before {
|
|
110
|
+
helper.stub(:params).and_return({controller: 'alchemy/admin/dashboard', action: 'index'})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
it "includes active class" do
|
|
114
|
+
helper.main_navigation_css_classes(navigation).should == "main_navi_entry active"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe '#entry_active?' do
|
|
120
|
+
let(:entry) {
|
|
121
|
+
{'controller' => 'alchemy/admin/dashboard', 'action' => 'index'}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
context "with active entry" do
|
|
125
|
+
before {
|
|
126
|
+
helper.stub(:params).and_return({controller: 'alchemy/admin/dashboard', action: 'index'})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
it "returns true" do
|
|
130
|
+
helper.entry_active?(entry).should be_true
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context "and with leading slash in controller name" do
|
|
134
|
+
before { entry['controller'] = '/alchemy/admin/dashboard' }
|
|
135
|
+
|
|
136
|
+
it "returns true" do
|
|
137
|
+
helper.entry_active?(entry).should be_true
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
context "but with action listed in nested_actions key" do
|
|
142
|
+
before {
|
|
143
|
+
entry['action'] = nil
|
|
144
|
+
entry['nested_actions'] = %w(index)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
it "returns true" do
|
|
148
|
+
helper.entry_active?(entry).should be_true
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
context "with inactive entry" do
|
|
154
|
+
before {
|
|
155
|
+
helper.stub(:params).and_return({controller: 'alchemy/admin/users', action: 'index'})
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
it "returns false" do
|
|
159
|
+
helper.entry_active?(entry).should be_false
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
describe '#url_for_module' do
|
|
165
|
+
context "with module within an engine" do
|
|
166
|
+
it "returns correct url string" do
|
|
167
|
+
helper.url_for_module(alchemy_module).should == '/admin/dashboard'
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
context "with module within host app" do
|
|
172
|
+
it "returns correct url string" do
|
|
173
|
+
helper.url_for_module(event_module).should == '/admin/events'
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
describe '#url_for_module_sub_navigation' do
|
|
179
|
+
context "with module within an engine" do
|
|
180
|
+
let(:navigation) { alchemy_module['navigation']['sub_navigation'].first }
|
|
181
|
+
|
|
182
|
+
before {
|
|
183
|
+
helper.stub(:module_definition_for).and_return(alchemy_module)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
it "returns correct url string" do
|
|
187
|
+
helper.url_for_module_sub_navigation(navigation).should == '/admin/layoutpages'
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
context "with module within host app" do
|
|
192
|
+
let(:navigation) { event_module['navigation']['sub_navigation'].first }
|
|
193
|
+
|
|
194
|
+
before {
|
|
195
|
+
helper.stub(:module_definition_for).and_return(event_module)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
it "returns correct url string" do
|
|
199
|
+
helper.url_for_module_sub_navigation(navigation).should == '/admin/events'
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
end
|
|
@@ -2,15 +2,33 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Alchemy::Admin::PagesHelper do
|
|
4
4
|
|
|
5
|
-
describe '#
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
describe '#sitemap_folder_link' do
|
|
6
|
+
let(:user) { FactoryGirl.build_stubbed(:admin_user) }
|
|
7
|
+
before { helper.stub(:current_user).and_return(user) }
|
|
8
|
+
subject { helper.sitemap_folder_link(page) }
|
|
9
|
+
|
|
10
|
+
context "with folded page" do
|
|
11
|
+
let(:page) { mock_model(Alchemy::Page, folded?: true) }
|
|
12
|
+
|
|
13
|
+
it "renders a link with folded class" do
|
|
14
|
+
should match /class="page_folder folded spinner"/
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "renders a link with hide title" do
|
|
18
|
+
should match /title="Show childpages"/
|
|
19
|
+
end
|
|
8
20
|
end
|
|
9
|
-
end
|
|
10
21
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
context "with collapsed page" do
|
|
23
|
+
let(:page) { mock_model(Alchemy::Page, folded?: false) }
|
|
24
|
+
|
|
25
|
+
it "renders a link with collapsed class" do
|
|
26
|
+
should match /class="page_folder collapsed spinner"/
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "renders a link with hide title" do
|
|
30
|
+
should match /title="Hide childpages"/
|
|
31
|
+
end
|
|
14
32
|
end
|
|
15
33
|
end
|
|
16
34
|
|
|
@@ -20,12 +38,4 @@ describe Alchemy::Admin::PagesHelper do
|
|
|
20
38
|
end
|
|
21
39
|
end
|
|
22
40
|
|
|
23
|
-
describe '#combined_page_status' do
|
|
24
|
-
let(:page) { FactoryGirl.build(:page, public: true, visible: true, restricted: false, locked: false)}
|
|
25
|
-
|
|
26
|
-
it "returns the translated page status" do
|
|
27
|
-
helper.combined_page_status(page).should == 'Page is visible in navigation.<br>Page is published.<br>Page is not restricted.'
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
41
|
end
|
|
@@ -3,8 +3,68 @@ require 'spec_helper'
|
|
|
3
3
|
module Alchemy
|
|
4
4
|
describe Admin::TagsHelper do
|
|
5
5
|
|
|
6
|
-
let(:tag)
|
|
7
|
-
|
|
6
|
+
let(:tag) { mock_model(ActsAsTaggableOn::Tag, name: 'foo', count: 1) }
|
|
7
|
+
let(:tag2) { mock_model(ActsAsTaggableOn::Tag, name: 'abc', count: 1) }
|
|
8
|
+
let(:params) { {controller: 'admin/attachments', action: 'index', use_route: 'alchemy', tagged_with: 'foo'} }
|
|
9
|
+
|
|
10
|
+
describe '#render_tag_list' do
|
|
11
|
+
context "with tagged objects" do
|
|
12
|
+
before { Attachment.stub!(:tag_counts).and_return([tag, tag2]) }
|
|
13
|
+
|
|
14
|
+
it "returns a tag list as <li> tags" do
|
|
15
|
+
helper.render_tag_list('Alchemy::Attachment', params).should match(/li/)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "has the tags name in the li's name attribute" do
|
|
19
|
+
helper.render_tag_list('Alchemy::Attachment', params).should match(/li.+name="#{tag.name}"/)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "has active class if tag is present in params" do
|
|
23
|
+
helper.render_tag_list('Alchemy::Attachment', params).should match(/li.+class="active"/)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "tags are sorted alphabetically" do
|
|
27
|
+
helper.render_tag_list('Alchemy::Attachment', params).should match(/li.+name="#{tag2.name}.+li.+name="#{tag.name}/)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "with lowercase and uppercase tag names mixed" do
|
|
31
|
+
let(:tag) { mock_model(ActsAsTaggableOn::Tag, name: 'Foo', count: 1) }
|
|
32
|
+
|
|
33
|
+
it "tags are sorted alphabetically correctly" do
|
|
34
|
+
helper.render_tag_list('Alchemy::Attachment', params).should match(/li.+name="#{tag2.name}.+li.+name="#{tag.name}/)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "output is html_safe" do
|
|
39
|
+
helper.render_tag_list('Alchemy::Attachment', params).html_safe?.should be_true
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context "without any tagged objects" do
|
|
44
|
+
it "returns empty string" do
|
|
45
|
+
render_tag_list('Alchemy::Attachment', params).should be_empty
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "with nil given as class_name parameter" do
|
|
50
|
+
it "raises argument error" do
|
|
51
|
+
expect { render_tag_list(nil, params) }.to raise_error(ArgumentError)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe '#tag_list_tag_active?' do
|
|
57
|
+
context "the tag is in params" do
|
|
58
|
+
it "returns true" do
|
|
59
|
+
tag_list_tag_active?(tag, params).should be_true
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context "params[:tagged_with] is not present" do
|
|
64
|
+
it "returns false" do
|
|
65
|
+
tag_list_tag_active?(tag, {}).should be_false
|
|
66
|
+
end
|
|
67
|
+
end
|
|
8
68
|
end
|
|
9
69
|
|
|
10
70
|
describe "#filtered_by_tag?" do
|
|
@@ -2,210 +2,274 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
include Alchemy::BaseHelper
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
before(:each) do
|
|
8
|
-
@page = FactoryGirl.create(:public_page)
|
|
9
|
-
@element = FactoryGirl.create(:element, :page => @page)
|
|
10
|
-
session[:language_id] = @page.language_id
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "should render an element view partial" do
|
|
14
|
-
helper.render_element(@element).should match(/id="#{@element.name}_#{@element.id}"/)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "should render a unique dom id for element" do
|
|
18
|
-
helper.element_dom_id(@element).should == "#{@element.name}_#{@element.id}"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "#render_elements" do
|
|
5
|
+
module Alchemy
|
|
6
|
+
describe ElementsHelper do
|
|
22
7
|
|
|
23
8
|
before(:each) do
|
|
24
|
-
|
|
9
|
+
@page = FactoryGirl.create(:public_page)
|
|
10
|
+
@element = FactoryGirl.create(:element, :page => @page)
|
|
11
|
+
session[:language_id] = @page.language_id
|
|
25
12
|
end
|
|
26
13
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# m for regex means line breaks are like every character
|
|
31
|
-
helper.render_elements.should match(/id="#{@element.name}_#{@element.id.to_s}.*id="#{@another_element.name}_#{@another_element.id.to_s}"/m)
|
|
32
|
-
end
|
|
14
|
+
it "should render an element view partial" do
|
|
15
|
+
helper.render_element(@element).should match(/id="#{@element.name}_#{@element.id}"/)
|
|
16
|
+
end
|
|
33
17
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
@another_element = FactoryGirl.create(:element, :page => @page, :cell_id => cell.id)
|
|
37
|
-
helper.render_elements.should_not match(/id="#{@another_element.name}_#{@another_element.id}"/)
|
|
38
|
-
end
|
|
18
|
+
it "should render a unique dom id for element" do
|
|
19
|
+
helper.element_dom_id(@element).should == "#{@element.name}_#{@element.id}"
|
|
39
20
|
end
|
|
40
21
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
helper.
|
|
22
|
+
describe "#render_elements" do
|
|
23
|
+
|
|
24
|
+
before(:each) do
|
|
25
|
+
helper.stub!(:configuration).and_return(true)
|
|
45
26
|
end
|
|
46
|
-
end
|
|
47
27
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
28
|
+
context "with no certain option given" do
|
|
29
|
+
it "should render all elements from @page" do
|
|
30
|
+
@another_element = FactoryGirl.create(:element, :page => @page)
|
|
31
|
+
# m for regex means line breaks are like every character
|
|
32
|
+
helper.render_elements.should match(/id="#{@element.name}_#{@element.id.to_s}.*id="#{@another_element.name}_#{@another_element.id.to_s}"/m)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should not render elements that are in a cell" do
|
|
36
|
+
cell = FactoryGirl.create(:cell)
|
|
37
|
+
@another_element = FactoryGirl.create(:element, :page => @page, :cell_id => cell.id)
|
|
38
|
+
helper.render_elements.should_not match(/id="#{@another_element.name}_#{@another_element.id}"/)
|
|
39
|
+
end
|
|
52
40
|
end
|
|
53
|
-
end
|
|
54
41
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
context "with except option" do
|
|
43
|
+
it "should render all elements except a certain one" do
|
|
44
|
+
@another_element = FactoryGirl.create(:element, :page => @page)
|
|
45
|
+
helper.render_elements(:except => @another_element.name).should_not match(/id="#{@another_element.name}_\d*"/)
|
|
46
|
+
end
|
|
60
47
|
end
|
|
61
48
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
helper.render_elements(:from_page => @another_page).should_not match(/id="#{@element_in_cell.name}_#{@element_in_cell.id}*"/)
|
|
49
|
+
context "with only option" do
|
|
50
|
+
it "should render one certain element" do
|
|
51
|
+
@another_element = FactoryGirl.create(:element, :name => 'headline', :page => @page)
|
|
52
|
+
helper.render_elements(:only => @element.name).should_not match(/id="#{@another_element.name}_\d*"/)
|
|
53
|
+
end
|
|
68
54
|
end
|
|
69
55
|
|
|
70
|
-
context "
|
|
71
|
-
it "should render all elements from
|
|
56
|
+
context "with from_page option" do
|
|
57
|
+
it "should render all elements from a certain page" do
|
|
58
|
+
@another_page = FactoryGirl.create(:public_page)
|
|
59
|
+
@element_on_other_page = FactoryGirl.create(:element, :name => 'headline', :page => @another_page)
|
|
60
|
+
helper.render_elements(:from_page => @another_page).should match(/id="#{@element_on_other_page.name}_\d*"/)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should not render any elements in a cell from the given page" do
|
|
72
64
|
@another_page = FactoryGirl.create(:public_page)
|
|
73
65
|
@cell = FactoryGirl.create(:cell, :name => "Celltest", :page => @another_page)
|
|
74
66
|
@element_not_in_cell = FactoryGirl.create(:element, :name => 'headline', :page => @another_page)
|
|
75
67
|
@element_in_cell = FactoryGirl.create(:element, :name => 'article', :cell => @cell, :page => @another_page)
|
|
76
|
-
helper.render_elements(:from_page => @another_page
|
|
68
|
+
helper.render_elements(:from_page => @another_page).should_not match(/id="#{@element_in_cell.name}_#{@element_in_cell.id}*"/)
|
|
77
69
|
end
|
|
78
|
-
end
|
|
79
70
|
|
|
80
|
-
|
|
71
|
+
context "and from_cell option" do
|
|
72
|
+
it "should render all elements from the page's cell" do
|
|
73
|
+
@another_page = FactoryGirl.create(:public_page)
|
|
74
|
+
@cell = FactoryGirl.create(:cell, :name => "Celltest", :page => @another_page)
|
|
75
|
+
@element_not_in_cell = FactoryGirl.create(:element, :name => 'headline', :page => @another_page)
|
|
76
|
+
@element_in_cell = FactoryGirl.create(:element, :name => 'article', :cell => @cell, :page => @another_page)
|
|
77
|
+
helper.render_elements(:from_page => @another_page, :from_cell => "Celltest").should match(/id="#{@element_in_cell.name}_#{@element_in_cell.id}*"/)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
81
80
|
|
|
82
|
-
context "with from_cell option" do
|
|
83
|
-
it "should render all elements from a certain cell" do
|
|
84
|
-
cell = FactoryGirl.create(:cell)
|
|
85
|
-
@another_element = FactoryGirl.create(:element, :page => @page, :cell_id => cell.id)
|
|
86
|
-
helper.render_elements(:from_cell => cell).should match(/id="#{@another_element.name}_#{@another_element.id}"/)
|
|
87
81
|
end
|
|
88
82
|
|
|
89
|
-
context "with from_cell
|
|
90
|
-
it "should render
|
|
83
|
+
context "with from_cell option" do
|
|
84
|
+
it "should render all elements from a certain cell" do
|
|
91
85
|
cell = FactoryGirl.create(:cell)
|
|
92
86
|
@another_element = FactoryGirl.create(:element, :page => @page, :cell_id => cell.id)
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
helper.render_elements(:from_cell => cell).should match(/id="#{@another_element.name}_#{@another_element.id}"/)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
context "with from_cell and only option" do
|
|
91
|
+
it "should render certain elements from a certain cell" do
|
|
92
|
+
cell = FactoryGirl.create(:cell)
|
|
93
|
+
@another_element = FactoryGirl.create(:element, :page => @page, :cell_id => cell.id)
|
|
94
|
+
@another_element2 = FactoryGirl.create(:element, :page => @page)
|
|
95
|
+
helper.render_elements(:from_cell => cell, :only => @another_element.name).should_not match(/id="#{@another_element2.name}_#{@another_element2.id}"/)
|
|
96
|
+
end
|
|
95
97
|
end
|
|
98
|
+
|
|
99
|
+
context "with from_cell and except option" do
|
|
100
|
+
it "should render all elements except certain ones from a certain cell" do
|
|
101
|
+
cell = FactoryGirl.create(:cell)
|
|
102
|
+
@another_element = FactoryGirl.create(:element, :page => @page, :cell_id => cell.id)
|
|
103
|
+
@another_element2 = FactoryGirl.create(:element, :page => @page, :cell_id => cell.id)
|
|
104
|
+
helper.render_elements(:from_cell => cell, :except => @another_element.name).should_not match(/id="#{@another_element.name}_#{@another_element.id}"/)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
96
108
|
end
|
|
97
109
|
|
|
98
|
-
context "with
|
|
99
|
-
it "should render
|
|
100
|
-
|
|
101
|
-
@
|
|
102
|
-
@
|
|
103
|
-
|
|
110
|
+
context "with count option" do
|
|
111
|
+
it "should render just one element because of the count option" do
|
|
112
|
+
@page.elements.delete_all
|
|
113
|
+
@another_element_1 = FactoryGirl.create(:element, :page => @page)
|
|
114
|
+
@another_element_2 = FactoryGirl.create(:element, :page => @page)
|
|
115
|
+
@another_element_3 = FactoryGirl.create(:element, :page => @page)
|
|
116
|
+
helper.render_elements(:count => 1).should match(/id="#{@another_element_1.name}_#{@another_element_1.id}"/)
|
|
104
117
|
end
|
|
105
118
|
end
|
|
106
119
|
|
|
107
|
-
|
|
120
|
+
context "with offset option" do
|
|
121
|
+
it "should render all elements beginning with the second." do
|
|
122
|
+
@page.elements.delete_all
|
|
123
|
+
@another_page = FactoryGirl.create(:public_page)
|
|
124
|
+
@another_element_1 = FactoryGirl.create(:element, :page => @page)
|
|
125
|
+
@another_element_2 = FactoryGirl.create(:element, :page => @page)
|
|
126
|
+
@another_element_3 = FactoryGirl.create(:element, :page => @page)
|
|
127
|
+
helper.render_elements(:offset => 1).should_not match(/id="#{@another_element_1.name}_#{@another_element_1.id}"/)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
108
130
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
131
|
+
context "with option fallback" do
|
|
132
|
+
before do
|
|
133
|
+
@another_page = FactoryGirl.create(:public_page, :name => 'Another Page', :page_layout => 'news')
|
|
134
|
+
@another_element_1 = FactoryGirl.create(:element, :page => @another_page, :name => 'news')
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it "should render the fallback element, when no element with the given name is found" do
|
|
138
|
+
helper.render_elements(
|
|
139
|
+
:fallback => {:for => 'higgs', :with => 'news', :from => 'news'}
|
|
140
|
+
).should match(/id="news_#{@another_element_1.id}"/)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "should also take a page object as fallback from" do
|
|
144
|
+
helper.render_elements(
|
|
145
|
+
:fallback => {:for => 'higgs', :with => 'news', :from => @another_page}
|
|
146
|
+
).should match(/id="news_#{@another_element_1.id}"/)
|
|
147
|
+
end
|
|
116
148
|
end
|
|
149
|
+
|
|
117
150
|
end
|
|
118
151
|
|
|
119
|
-
|
|
120
|
-
it "should render
|
|
121
|
-
|
|
122
|
-
@
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
@another_element_3 = FactoryGirl.create(:element, :page => @page)
|
|
126
|
-
helper.render_elements(:offset => 1).should_not match(/id="#{@another_element_1.name}_#{@another_element_1.id}"/)
|
|
152
|
+
describe "#render_cell_elements" do
|
|
153
|
+
it "should render elements for a cell" do
|
|
154
|
+
cell = FactoryGirl.create(:cell)
|
|
155
|
+
@element_in_cell = FactoryGirl.create(:element, :cell_id => cell.id)
|
|
156
|
+
helper.stub(:configuration).and_return(true)
|
|
157
|
+
helper.render_cell_elements(cell).should match(/id="#{@element_in_cell.name}_#{@element_in_cell.id}"/)
|
|
127
158
|
end
|
|
128
159
|
end
|
|
129
160
|
|
|
130
|
-
context "
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
161
|
+
context "in preview mode" do
|
|
162
|
+
describe '#element_preview_code_attributes' do
|
|
163
|
+
it "should return the data-alchemy-element HTML attribute for element" do
|
|
164
|
+
@preview_mode = true
|
|
165
|
+
helper.element_preview_code_attributes(@element).should == {:'data-alchemy-element' => @element.id}
|
|
166
|
+
end
|
|
135
167
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
).should match(/id="news_#{@another_element_1.id}"/)
|
|
168
|
+
it "should return an empty hash if not in preview_mode" do
|
|
169
|
+
helper.element_preview_code_attributes(@element).should == {}
|
|
170
|
+
end
|
|
140
171
|
end
|
|
141
172
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
:
|
|
145
|
-
|
|
173
|
+
describe '#element_preview_code' do
|
|
174
|
+
it "should return the data-alchemy-element HTML attribute for element" do
|
|
175
|
+
assign(:preview_mode, true)
|
|
176
|
+
helper.element_preview_code(@element).should == " data-alchemy-element=\"#{@element.id}\""
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it "should not return the data-alchemy-element HTML attribute if not in preview_mode" do
|
|
180
|
+
helper.element_preview_code(@element).should_not == " data-alchemy-element=\"#{@element.id}\""
|
|
181
|
+
end
|
|
146
182
|
end
|
|
147
183
|
end
|
|
148
184
|
|
|
149
|
-
|
|
185
|
+
describe '#element_tags' do
|
|
150
186
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
187
|
+
context "element having tags" do
|
|
188
|
+
before { @element.tag_list = "peter, lustig"; @element.save! }
|
|
189
|
+
|
|
190
|
+
context "with no formatter lambda given" do
|
|
191
|
+
it "should return tag list as HTML data attribute" do
|
|
192
|
+
helper.element_tags(@element).should == " data-element-tags=\"peter lustig\""
|
|
193
|
+
end
|
|
194
|
+
end
|
|
159
195
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
196
|
+
context "with a formatter lambda given" do
|
|
197
|
+
it "should return a properly formatted HTML data attribute" do
|
|
198
|
+
helper.element_tags(@element, :formatter => lambda { |tags| tags.join ", " }).
|
|
199
|
+
should == " data-element-tags=\"peter, lustig\""
|
|
200
|
+
end
|
|
201
|
+
end
|
|
165
202
|
end
|
|
166
203
|
|
|
167
|
-
|
|
168
|
-
|
|
204
|
+
context "element not having tags" do
|
|
205
|
+
it "should return empty string" do
|
|
206
|
+
helper.element_tags(@element).should be_blank
|
|
207
|
+
end
|
|
169
208
|
end
|
|
209
|
+
|
|
170
210
|
end
|
|
171
211
|
|
|
172
|
-
describe '#
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
212
|
+
describe '#all_elements_by_name' do
|
|
213
|
+
let(:page) { mock_model('Page') }
|
|
214
|
+
let(:element) { mock_model('Element') }
|
|
215
|
+
|
|
216
|
+
it "should return all public elements found by name" do
|
|
217
|
+
Element.stub_chain(:published, :where, :limit).and_return([element])
|
|
218
|
+
expect(helper.all_elements_by_name('el_name')).to eq([element])
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
it "should return an empty collection if element not found" do
|
|
222
|
+
expect(helper.all_elements_by_name('not_existing_name')).to eq([])
|
|
176
223
|
end
|
|
177
224
|
|
|
178
|
-
|
|
179
|
-
|
|
225
|
+
context "options[:from_page] is passed" do
|
|
226
|
+
before do
|
|
227
|
+
Page.stub_chain(:with_language, :find_by_page_layout).and_return(page)
|
|
228
|
+
page.stub_chain(:elements, :published, :where, :limit).and_return([element])
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
context "as a String" do
|
|
232
|
+
it "should return all elements associated with the page found by the given layout name" do
|
|
233
|
+
expect(helper.all_elements_by_name('el_name', from_page: 'layout_name')).to eq([element])
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
context "as a Page object" do
|
|
238
|
+
it "should return all elements associated with this given page" do
|
|
239
|
+
expect(helper.all_elements_by_name('el_name', from_page: page)).to eq([element])
|
|
240
|
+
end
|
|
241
|
+
end
|
|
180
242
|
end
|
|
181
243
|
end
|
|
182
|
-
end
|
|
183
244
|
|
|
184
|
-
|
|
245
|
+
describe '#element_from_page' do
|
|
246
|
+
let(:page) { mock_model('Page', urlname: 'page-1') }
|
|
247
|
+
let(:element) { mock_model('Element', name: 'el_name') }
|
|
185
248
|
|
|
186
|
-
|
|
187
|
-
|
|
249
|
+
before do
|
|
250
|
+
page.stub_chain(:elements, :published, :find_by_name).and_return(element)
|
|
251
|
+
end
|
|
188
252
|
|
|
189
|
-
context "
|
|
190
|
-
|
|
191
|
-
|
|
253
|
+
context "options[:page_urlname] and options[:element_name] is passed" do
|
|
254
|
+
before do
|
|
255
|
+
Page.stub_chain(:published, :find_by_urlname).and_return(page)
|
|
192
256
|
end
|
|
193
|
-
end
|
|
194
257
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
helper.element_tags(@element, :formatter => lambda { |tags| tags.join ", " }).
|
|
198
|
-
should == " data-element-tags=\"peter, lustig\""
|
|
258
|
+
it "should return the element with the given name" do
|
|
259
|
+
expect(helper.element_from_page(element_name: element.name, page_urlname: page.urlname)).to eq(element)
|
|
199
260
|
end
|
|
200
261
|
end
|
|
201
|
-
end
|
|
202
262
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
263
|
+
context "options[:page_id] and options[:element_name] is passed" do
|
|
264
|
+
before do
|
|
265
|
+
Page.stub_chain(:published, :find_by_id).and_return(page)
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
it "should return the element with the given name" do
|
|
269
|
+
expect(helper.element_from_page(element_name: element.name, page_id: page.id)).to eq(element)
|
|
270
|
+
end
|
|
206
271
|
end
|
|
207
272
|
end
|
|
208
273
|
|
|
209
274
|
end
|
|
210
|
-
|
|
211
275
|
end
|