alchemy_cms 3.3.0.rc1 → 3.3.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -2
- data/Gemfile +1 -0
- data/alchemy_cms.gemspec +6 -6
- data/app/assets/javascripts/alchemy/alchemy.base.js.coffee +0 -7
- data/app/assets/javascripts/alchemy/alchemy.dialog.js.coffee +4 -4
- data/app/assets/javascripts/alchemy/alchemy.element_editors.js.coffee +51 -5
- data/app/assets/javascripts/alchemy/alchemy.sitemap.js.coffee +0 -2
- data/app/assets/stylesheets/alchemy/elements.scss +2 -2
- data/app/controllers/alchemy/admin/elements_controller.rb +2 -0
- data/app/controllers/alchemy/admin/pages_controller.rb +11 -3
- data/app/controllers/alchemy/admin/pictures_controller.rb +1 -0
- data/app/models/alchemy/element.rb +3 -1
- data/app/models/alchemy/element/element_contents.rb +2 -7
- data/app/models/alchemy/element/presenters.rb +11 -4
- data/app/models/alchemy/page.rb +3 -1
- data/app/views/alchemy/admin/attachments/archive_overlay.js.erb +0 -1
- data/app/views/alchemy/admin/contents/create.js.erb +0 -1
- data/app/views/alchemy/admin/elements/_element_header.html.erb +3 -1
- data/app/views/alchemy/admin/elements/order.js.erb +25 -10
- data/app/views/alchemy/admin/elements/update.js.erb +1 -2
- data/app/views/alchemy/admin/essence_files/assign.js.erb +0 -1
- data/app/views/alchemy/admin/essence_pictures/assign.js.erb +0 -1
- data/app/views/alchemy/admin/legacy_page_urls/create.js.erb +0 -1
- data/app/views/alchemy/admin/pages/destroy.js.erb +0 -1
- data/app/views/alchemy/admin/pages/update.js.erb +6 -4
- data/app/views/alchemy/admin/pictures/_filter_and_size_bar.html.erb +2 -1
- data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +1 -7
- data/app/views/alchemy/admin/pictures/archive_overlay.js.erb +0 -1
- data/bin/alchemy +1 -1
- data/bin/rspec +3 -2
- data/bin/spring +6 -6
- data/config/alchemy/config.yml +6 -1
- data/lib/alchemy/seeder.rb +9 -3
- data/lib/alchemy/version.rb +1 -1
- metadata +6 -471
- data/spec/controllers/alchemy/admin/attachments_controller_spec.rb +0 -193
- data/spec/controllers/alchemy/admin/base_controller_spec.rb +0 -87
- data/spec/controllers/alchemy/admin/clipboard_controller_spec.rb +0 -60
- data/spec/controllers/alchemy/admin/contents_controller_spec.rb +0 -78
- data/spec/controllers/alchemy/admin/dashboard_controller_spec.rb +0 -144
- data/spec/controllers/alchemy/admin/elements_controller_spec.rb +0 -496
- data/spec/controllers/alchemy/admin/essence_files_controller_spec.rb +0 -76
- data/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb +0 -202
- data/spec/controllers/alchemy/admin/languages_controller_spec.rb +0 -73
- data/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb +0 -21
- data/spec/controllers/alchemy/admin/pages_controller_spec.rb +0 -639
- data/spec/controllers/alchemy/admin/pictures_controller_spec.rb +0 -383
- data/spec/controllers/alchemy/admin/resources_controller_spec.rb +0 -81
- data/spec/controllers/alchemy/admin/tags_controller_spec.rb +0 -63
- data/spec/controllers/alchemy/admin/trash_controller_spec.rb +0 -67
- data/spec/controllers/alchemy/api/contents_controller_spec.rb +0 -125
- data/spec/controllers/alchemy/api/elements_controller_spec.rb +0 -124
- data/spec/controllers/alchemy/api/pages_controller_spec.rb +0 -167
- data/spec/controllers/alchemy/attachments_controller_spec.rb +0 -64
- data/spec/controllers/alchemy/base_controller_spec.rb +0 -106
- data/spec/controllers/alchemy/elements_controller_spec.rb +0 -48
- data/spec/controllers/alchemy/messages_controller_spec.rb +0 -204
- data/spec/controllers/alchemy/on_page_layout_mixin_spec.rb +0 -330
- data/spec/controllers/alchemy/pages_controller_spec.rb +0 -343
- data/spec/controllers/alchemy/pictures_controller_spec.rb +0 -415
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/admin/events_controller.rb +0 -3
- data/spec/dummy/app/controllers/application_controller.rb +0 -15
- data/spec/dummy/app/controllers/login_controller.rb +0 -5
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/ability.rb +0 -9
- data/spec/dummy/app/models/dummy_model.rb +0 -3
- data/spec/dummy/app/models/dummy_user.rb +0 -15
- data/spec/dummy/app/models/event.rb +0 -10
- data/spec/dummy/app/models/location.rb +0 -3
- data/spec/dummy/app/views/alchemy/elements/_all_you_can_eat_editor.html.erb +0 -11
- data/spec/dummy/app/views/alchemy/elements/_all_you_can_eat_view.html.erb +0 -31
- data/spec/dummy/app/views/alchemy/elements/_article_editor.html.erb +0 -6
- data/spec/dummy/app/views/alchemy/elements/_article_view.html.erb +0 -10
- data/spec/dummy/app/views/alchemy/elements/_bild_editor.html.erb +0 -3
- data/spec/dummy/app/views/alchemy/elements/_bild_view.html.erb +0 -5
- data/spec/dummy/app/views/alchemy/elements/_contactform_editor.html.erb +0 -6
- data/spec/dummy/app/views/alchemy/elements/_contactform_view.html.erb +0 -16
- data/spec/dummy/app/views/alchemy/elements/_download_editor.html.erb +0 -3
- data/spec/dummy/app/views/alchemy/elements/_download_view.html.erb +0 -5
- data/spec/dummy/app/views/alchemy/elements/_erb_element_editor.html.erb +0 -3
- data/spec/dummy/app/views/alchemy/elements/_erb_element_view.html.erb +0 -5
- data/spec/dummy/app/views/alchemy/elements/_header_editor.html.erb +0 -3
- data/spec/dummy/app/views/alchemy/elements/_header_view.html.erb +0 -5
- data/spec/dummy/app/views/alchemy/elements/_headline_editor.html.erb +0 -1
- data/spec/dummy/app/views/alchemy/elements/_headline_view.html.erb +0 -1
- data/spec/dummy/app/views/alchemy/elements/_news_editor.html.erb +0 -5
- data/spec/dummy/app/views/alchemy/elements/_news_view.html.erb +0 -11
- data/spec/dummy/app/views/alchemy/elements/_search_editor.html.erb +0 -1
- data/spec/dummy/app/views/alchemy/elements/_search_view.html.erb +0 -4
- data/spec/dummy/app/views/alchemy/elements/_slide_editor.html.erb +0 -3
- data/spec/dummy/app/views/alchemy/elements/_slide_view.html.erb +0 -5
- data/spec/dummy/app/views/alchemy/elements/_slider_editor.html.erb +0 -2
- data/spec/dummy/app/views/alchemy/elements/_slider_view.html.erb +0 -4
- data/spec/dummy/app/views/alchemy/elements/_text_editor.html.erb +0 -3
- data/spec/dummy/app/views/alchemy/elements/_text_view.html.erb +0 -5
- data/spec/dummy/app/views/alchemy/page_layouts/_standard.html.erb +0 -15
- data/spec/dummy/app/views/layouts/application.html.erb +0 -17
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/alchemy/cells.yml +0 -5
- data/spec/dummy/config/alchemy/elements.yml +0 -109
- data/spec/dummy/config/alchemy/page_layouts.yml +0 -32
- data/spec/dummy/config/application.rb +0 -32
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -32
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -41
- data/spec/dummy/config/environments/production.rb +0 -77
- data/spec/dummy/config/environments/test.rb +0 -43
- data/spec/dummy/config/initializers/alchemy.rb +0 -3
- data/spec/dummy/config/initializers/assets.rb +0 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/secret_token.rb +0 -12
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/kl.yml +0 -2
- data/spec/dummy/config/routes.rb +0 -12
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/db/migrate/20121026104128_create_events.rb +0 -20
- data/spec/dummy/db/migrate/20130328101418_create_locations.rb +0 -9
- data/spec/dummy/db/migrate/20130827094554_alchemy_two_point_six.rb +0 -1
- data/spec/dummy/db/migrate/20130828121054_remove_do_not_index_from_alchemy_essence_texts.rb +0 -1
- data/spec/dummy/db/migrate/20130828121120_remove_do_not_index_from_alchemy_essence_richtexts.rb +0 -1
- data/spec/dummy/db/migrate/20130918201742_add_published_at_to_alchemy_pages.rb +0 -1
- data/spec/dummy/db/migrate/20131209225243_create_dummy_users.rb +0 -9
- data/spec/dummy/db/migrate/20150122213511_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb +0 -31
- data/spec/dummy/db/migrate/20150122213512_add_missing_unique_indices.acts_as_taggable_on_engine.rb +0 -20
- data/spec/dummy/db/migrate/20150122213513_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +0 -15
- data/spec/dummy/db/migrate/20150122213514_add_missing_taggable_index.acts_as_taggable_on_engine.rb +0 -10
- data/spec/dummy/db/migrate/20150412103152_create_dummy_model.rb +0 -7
- data/spec/dummy/db/migrate/20150608204610_add_parent_element_id_to_alchemy_elements.rb +0 -1
- data/spec/dummy/db/migrate/20150729151825_add_link_text_to_alchemy_essence_files.rb +0 -1
- data/spec/dummy/db/migrate/20150906195818_add_locale_to_alchemy_languages.rb +0 -1
- data/spec/dummy/db/schema.rb +0 -326
- data/spec/dummy/db/seeds.rb +0 -1
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/javascripts +0 -1
- data/spec/factories.rb +0 -13
- data/spec/features/admin/admin_layout_spec.rb +0 -14
- data/spec/features/admin/dashboard_spec.rb +0 -81
- data/spec/features/admin/edit_elements_feature_spec.rb +0 -36
- data/spec/features/admin/language_tree_feature_spec.rb +0 -32
- data/spec/features/admin/languages_features_spec.rb +0 -65
- data/spec/features/admin/legacy_page_url_management_spec.rb +0 -62
- data/spec/features/admin/link_overlay_spec.rb +0 -53
- data/spec/features/admin/locale_select_feature_spec.rb +0 -25
- data/spec/features/admin/modules_integration_spec.rb +0 -23
- data/spec/features/admin/navigation_feature_spec.rb +0 -22
- data/spec/features/admin/page_creation_feature_spec.rb +0 -51
- data/spec/features/admin/page_editing_feature_spec.rb +0 -135
- data/spec/features/admin/picture_library_integration_spec.rb +0 -62
- data/spec/features/admin/resources_integration_spec.rb +0 -128
- data/spec/features/admin/site_select_feature_spec.rb +0 -31
- data/spec/features/admin/tinymce_feature_spec.rb +0 -33
- data/spec/features/navigation_spec.rb +0 -9
- data/spec/features/page_feature_spec.rb +0 -186
- data/spec/features/page_redirects_spec.rb +0 -358
- data/spec/features/picture_security_spec.rb +0 -29
- data/spec/features/security_spec.rb +0 -24
- data/spec/features/translation_integration_spec.rb +0 -51
- data/spec/fixtures/500x500.png +0 -0
- data/spec/fixtures/80x60.png +0 -0
- data/spec/fixtures/animated.gif +0 -0
- data/spec/fixtures/image with spaces.png +0 -0
- data/spec/fixtures/image.png +0 -0
- data/spec/fixtures/image2.PNG +0 -0
- data/spec/fixtures/image3.jpeg +0 -0
- data/spec/helpers/alchemy/admin/attachments_helper_spec.rb +0 -15
- data/spec/helpers/alchemy/admin/base_helper_spec.rb +0 -280
- data/spec/helpers/alchemy/admin/contents_helper_spec.rb +0 -46
- data/spec/helpers/alchemy/admin/elements_helper_spec.rb +0 -314
- data/spec/helpers/alchemy/admin/essences_helper_spec.rb +0 -201
- data/spec/helpers/alchemy/admin/navigation_helper_spec.rb +0 -294
- data/spec/helpers/alchemy/admin/pages_helper_spec.rb +0 -63
- data/spec/helpers/alchemy/admin/pictures_helper_spec.rb +0 -28
- data/spec/helpers/alchemy/admin/tags_helper_spec.rb +0 -111
- data/spec/helpers/alchemy/base_helper_spec.rb +0 -44
- data/spec/helpers/alchemy/elements_block_helper_spec.rb +0 -135
- data/spec/helpers/alchemy/elements_helper_spec.rb +0 -326
- data/spec/helpers/alchemy/essences_helper_spec.rb +0 -85
- data/spec/helpers/alchemy/pages_helper_spec.rb +0 -499
- data/spec/helpers/alchemy/picture_url_helpers_spec.rb +0 -78
- data/spec/helpers/alchemy/url_helper_spec.rb +0 -200
- data/spec/javascripts/alchemy/dialog_spec.coffee +0 -82
- data/spec/javascripts/alchemy/link_overlay_spec.coffee +0 -25
- data/spec/javascripts/alchemy_integration_spec.coffee +0 -3
- data/spec/javascripts/fixtures/select.html +0 -3
- data/spec/javascripts/helpers/mock-ajax.js +0 -199
- data/spec/javascripts/helpers/test_responses/test_responses.js +0 -1
- data/spec/javascripts/support/jasmine.yml +0 -29
- data/spec/libraries/auth_accessors_spec.rb +0 -40
- data/spec/libraries/config_spec.rb +0 -111
- data/spec/libraries/controller_actions_spec.rb +0 -133
- data/spec/libraries/i18n_spec.rb +0 -37
- data/spec/libraries/kaminari/scoped_pagination_url_helper_spec.rb +0 -30
- data/spec/libraries/modules_spec.rb +0 -67
- data/spec/libraries/mount_point_spec.rb +0 -77
- data/spec/libraries/page_layout_spec.rb +0 -150
- data/spec/libraries/paths_spec.rb +0 -15
- data/spec/libraries/permissions_spec.rb +0 -260
- data/spec/libraries/resource_spec.rb +0 -344
- data/spec/libraries/resources_helper_spec.rb +0 -193
- data/spec/libraries/shell_spec.rb +0 -121
- data/spec/libraries/template_tracker_spec.rb +0 -85
- data/spec/libraries/tinymce_spec.rb +0 -111
- data/spec/libraries/userstamp_spec.rb +0 -10
- data/spec/mailers/alchemy/messages_spec.rb +0 -21
- data/spec/models/alchemy/attachment_spec.rb +0 -250
- data/spec/models/alchemy/cell_spec.rb +0 -101
- data/spec/models/alchemy/content_spec.rb +0 -513
- data/spec/models/alchemy/element_spec.rb +0 -862
- data/spec/models/alchemy/element_to_page_spec.rb +0 -13
- data/spec/models/alchemy/essence_boolean_spec.rb +0 -10
- data/spec/models/alchemy/essence_date_spec.rb +0 -28
- data/spec/models/alchemy/essence_file_spec.rb +0 -40
- data/spec/models/alchemy/essence_html_spec.rb +0 -18
- data/spec/models/alchemy/essence_link_spec.rb +0 -10
- data/spec/models/alchemy/essence_picture_spec.rb +0 -255
- data/spec/models/alchemy/essence_richtext_spec.rb +0 -23
- data/spec/models/alchemy/essence_select_spec.rb +0 -10
- data/spec/models/alchemy/essence_text_spec.rb +0 -110
- data/spec/models/alchemy/language_spec.rb +0 -243
- data/spec/models/alchemy/legacy_page_url_spec.rb +0 -21
- data/spec/models/alchemy/message_spec.rb +0 -55
- data/spec/models/alchemy/page_spec.rb +0 -2108
- data/spec/models/alchemy/picture_spec.rb +0 -418
- data/spec/models/alchemy/site_spec.rb +0 -168
- data/spec/models/alchemy/tag_spec.rb +0 -29
- data/spec/models/dummy_model_spec.rb +0 -10
- data/spec/requests/alchemy/admin/resources_requests_spec.rb +0 -26
- data/spec/requests/alchemy/admin/site_requests_spec.rb +0 -19
- data/spec/requests/alchemy/site_requests_spec.rb +0 -18
- data/spec/requests/alchemy/sitemap_spec.rb +0 -56
- data/spec/routing/api_routing_spec.rb +0 -150
- data/spec/routing/routing_spec.rb +0 -340
- data/spec/spec_helper.rb +0 -90
- data/spec/support/ci/install_phantomjs +0 -7
- data/spec/support/hint_examples.rb +0 -28
- data/spec/support/test_tweaks.rb +0 -31
- data/spec/support/transformation_examples.rb +0 -179
- data/spec/tasks/helpers_spec.rb +0 -217
- data/spec/views/admin/pictures/show_spec.rb +0 -43
- data/spec/views/essences/essence_boolean_editor_spec.rb +0 -32
- data/spec/views/essences/essence_boolean_view_spec.rb +0 -23
- data/spec/views/essences/essence_date_view_spec.rb +0 -38
- data/spec/views/essences/essence_file_editor_spec.rb +0 -59
- data/spec/views/essences/essence_file_view_spec.rb +0 -77
- data/spec/views/essences/essence_html_view_spec.rb +0 -22
- data/spec/views/essences/essence_link_view_spec.rb +0 -41
- data/spec/views/essences/essence_picture_editor_spec.rb +0 -80
- data/spec/views/essences/essence_picture_view_spec.rb +0 -128
- data/spec/views/essences/essence_richtext_view_spec.rb +0 -32
- data/spec/views/essences/essence_select_view_spec.rb +0 -11
- data/spec/views/essences/essence_text_view_spec.rb +0 -51
@@ -1,243 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
module Alchemy
|
5
|
-
describe Language do
|
6
|
-
let(:default_language) { Alchemy::Language.default }
|
7
|
-
let(:language) { create(:alchemy_language, :klingon) }
|
8
|
-
let(:page) { create(:alchemy_page, language: language) }
|
9
|
-
|
10
|
-
it 'is valid with uppercase country code' do
|
11
|
-
language = Alchemy::Language.new(
|
12
|
-
country_code: 'AT',
|
13
|
-
language_code: 'de',
|
14
|
-
name: 'Österreich',
|
15
|
-
frontpage_name: 'Start',
|
16
|
-
page_layout: 'index'
|
17
|
-
)
|
18
|
-
expect(language).to be_valid
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should return a label for code" do
|
22
|
-
expect(language.label(:code)).to eq('kl')
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should return a label for name" do
|
26
|
-
expect(language.label(:name)).to eq('Klingon')
|
27
|
-
end
|
28
|
-
|
29
|
-
context "with language_code and empty country_code" do
|
30
|
-
it "#code should return language locale only" do
|
31
|
-
language.country_code = ''
|
32
|
-
expect(language.code).to eq('kl')
|
33
|
-
end
|
34
|
-
|
35
|
-
context "adding a value for country code" do
|
36
|
-
it "#code should return a joined locale" do
|
37
|
-
language.country_code = 'cr'
|
38
|
-
expect(language.code).to eq('kl-cr')
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should update all associated Pages with self.code as value for Page#language_code" do
|
42
|
-
page = create(:alchemy_page, language: language)
|
43
|
-
language.country_code = 'cr'
|
44
|
-
language.save
|
45
|
-
page.reload; expect(page.language_code).to eq('kl-cr')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "with country_code and_language_code" do
|
51
|
-
context "removing the country_code" do
|
52
|
-
it "should update all associated Pages´s language_code with Language#code" do
|
53
|
-
language = create(:alchemy_language, country_code: 'kl')
|
54
|
-
language.country_code = ''
|
55
|
-
language.save
|
56
|
-
page.reload; expect(page.language_code).to eq("kl")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should not be deletable if it is the default language" do
|
62
|
-
expect {
|
63
|
-
default_language.destroy
|
64
|
-
}.to raise_error(DefaultLanguageNotDeletable)
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "before save" do
|
68
|
-
describe "#remove_old_default if default attribute has changed to true" do
|
69
|
-
it "should unset the default status of the old default language" do
|
70
|
-
default_language
|
71
|
-
language.update_attributes(default: true)
|
72
|
-
default_language.reload
|
73
|
-
expect(default_language.default).to be_falsey
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context "after_update" do
|
79
|
-
describe "#set_pages_language if language´s code has changed" do
|
80
|
-
it "should update all its pages with the new code" do
|
81
|
-
@other_page = create(:alchemy_page, language: language)
|
82
|
-
language.update_attributes(code: "fo")
|
83
|
-
language.reload; page.reload; @other_page.reload
|
84
|
-
expect([page.language_code, @other_page.language_code]).to eq([language.code, language.code])
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "#unpublish_pages" do
|
89
|
-
it "should set all pages to unpublic if it gets set to unpublic" do
|
90
|
-
page = create(:alchemy_page, language: language)
|
91
|
-
@other_page = create(:alchemy_page, language: language)
|
92
|
-
language.update_attributes(public: false)
|
93
|
-
language.reload; page.reload; @other_page.reload
|
94
|
-
expect([page.public?, @other_page.public?]).to eq([false, false])
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe '.find_by_code' do
|
100
|
-
context "with only the language code given" do
|
101
|
-
it "should find the language" do
|
102
|
-
expect(Language.find_by_code(language.code)).to eq(language)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe 'validations' do
|
108
|
-
let(:language) { Language.new(default: true, public: false) }
|
109
|
-
|
110
|
-
describe 'publicity_of_default_language' do
|
111
|
-
context 'if language is not published' do
|
112
|
-
it "should add an error to the object" do
|
113
|
-
expect(language.valid?).to eq(false)
|
114
|
-
expect(language.errors.messages).to have_key(:public)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
describe 'presence_of_default_language' do
|
120
|
-
context 'if no default language would exist anymore' do
|
121
|
-
before do
|
122
|
-
allow(Language).to receive(:default).and_return(language)
|
123
|
-
allow(language).to receive(:default_changed?).and_return(true)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should add an error to the object" do
|
127
|
-
expect(language.valid?).to eq(false)
|
128
|
-
expect(language.errors.messages).to have_key(:default)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe 'before' do
|
134
|
-
subject do
|
135
|
-
language.valid?
|
136
|
-
language.locale
|
137
|
-
end
|
138
|
-
|
139
|
-
before do
|
140
|
-
allow(::I18n).to receive(:available_locales) do
|
141
|
-
[:de, :'de-at', :en, :'en-uk']
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'when locale is already set' do
|
146
|
-
let(:language) do
|
147
|
-
build(:alchemy_language, language_code: 'de', locale: 'de')
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'does not set the locale again' do
|
151
|
-
expect(language).to_not receive(:set_locale)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context 'when code is an available locale' do
|
156
|
-
let(:language) do
|
157
|
-
build(:alchemy_language, language_code: 'de', country_code: 'at')
|
158
|
-
end
|
159
|
-
|
160
|
-
it 'sets the locale to code' do
|
161
|
-
is_expected.to eq('de-at')
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
context 'when code is not is an available locale, but language_code is' do
|
166
|
-
let(:language) do
|
167
|
-
build(:alchemy_language, language_code: 'de', country_code: 'ch')
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'sets the locale to language code' do
|
171
|
-
is_expected.to eq('de')
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
context "when language_code is an available locale" do
|
176
|
-
let(:language) do
|
177
|
-
build(:alchemy_language, language_code: 'en')
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'sets the locale to language_code' do
|
181
|
-
is_expected.to eq('en')
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
context "when neither language_code nor code is an available locale" do
|
186
|
-
it { is_expected.to be_nil }
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
describe 'presence_of_locale_file' do
|
191
|
-
context "when locale file is missing for selected language code" do
|
192
|
-
let(:language) do
|
193
|
-
build(:alchemy_language, language_code: 'jp')
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'adds errors to locale attribute' do
|
197
|
-
expect(language).to_not be_valid
|
198
|
-
expect(language.errors).to have_key(:locale)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
context "when locale file is present for selected language code" do
|
203
|
-
let(:language) do
|
204
|
-
build(:alchemy_language, :klingon)
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'adds no errors to locale attribute' do
|
208
|
-
expect(language).to be_valid
|
209
|
-
expect(language.errors).to_not have_key(:locale)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe '#matching_locales' do
|
216
|
-
let(:language) do
|
217
|
-
build(:alchemy_language, language_code: 'de')
|
218
|
-
end
|
219
|
-
|
220
|
-
subject do
|
221
|
-
language.matching_locales
|
222
|
-
end
|
223
|
-
|
224
|
-
before do
|
225
|
-
expect(::I18n).to receive(:available_locales) do
|
226
|
-
[:de, :'de-at', :'en-uk']
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
it 'returns locales matching the language code' do
|
231
|
-
is_expected.to eq [:de, :'de-at']
|
232
|
-
end
|
233
|
-
|
234
|
-
context 'when language code is not is an available locale' do
|
235
|
-
let(:language) do
|
236
|
-
build(:alchemy_language, language_code: 'jp')
|
237
|
-
end
|
238
|
-
|
239
|
-
it { is_expected.to eq [] }
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Alchemy::LegacyPageUrl do
|
4
|
-
let(:page) { build_stubbed(:alchemy_page) }
|
5
|
-
|
6
|
-
let(:page_url_with_parameters) do
|
7
|
-
Alchemy::LegacyPageUrl.new(urlname: 'index.php?id=2', page: page)
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:valid_page_url) do
|
11
|
-
Alchemy::LegacyPageUrl.new(urlname: 'my/0-work+is-nice_stuff', page: page)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'is only valid with correct urlname format' do
|
15
|
-
expect(valid_page_url).to be_valid
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'is also valid with get parameters in urlname' do
|
19
|
-
expect(page_url_with_parameters).to be_valid
|
20
|
-
end
|
21
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Alchemy
|
4
|
-
Config.get(:mailer)['fields'].push('email_of_my_boss')
|
5
|
-
Config.get(:mailer)['validate_fields'].push('email_of_my_boss')
|
6
|
-
|
7
|
-
describe Message do
|
8
|
-
let(:message) { Message.new }
|
9
|
-
|
10
|
-
describe '.config' do
|
11
|
-
it "should return the mailer config" do
|
12
|
-
expect(Config).to receive(:get).with(:mailer)
|
13
|
-
Message.config
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it "has attributes writers and getters for all fields defined in mailer config" do
|
18
|
-
Config.get(:mailer)['fields'].each do |field|
|
19
|
-
expect(message).to respond_to(field)
|
20
|
-
expect(message).to respond_to("#{field}=")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "validation of" do
|
25
|
-
context "all fields defined in mailer config" do
|
26
|
-
it "adds errors on that fields" do
|
27
|
-
Config.get(:mailer)['validate_fields'].each do |field|
|
28
|
-
expect(message).to_not be_valid
|
29
|
-
expect(message.errors[field].size).to eq(1)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'field containing email in its name' do
|
35
|
-
context "when field has a value" do
|
36
|
-
before { message.email_of_my_boss = 'wrong email format' }
|
37
|
-
|
38
|
-
it "adds error notice (is invalid) to the field" do
|
39
|
-
expect(message).to_not be_valid
|
40
|
-
expect(message.errors[:email_of_my_boss]).to include("is invalid")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "when field is blank" do
|
45
|
-
before { message.email_of_my_boss = '' }
|
46
|
-
|
47
|
-
it "adds error notice (can't be blank) to the field" do
|
48
|
-
expect(message).to_not be_valid
|
49
|
-
expect(message.errors[:email_of_my_boss]).to include("can't be blank")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,2108 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Alchemy
|
6
|
-
describe Page do
|
7
|
-
let(:rootpage) { Page.root }
|
8
|
-
let(:language) { Language.default }
|
9
|
-
let(:klingon) { create(:alchemy_language, :klingon) }
|
10
|
-
let(:language_root) { create(:alchemy_page, :language_root) }
|
11
|
-
let(:page) { mock_model(Page, page_layout: 'foo') }
|
12
|
-
let(:public_page) { create(:alchemy_page, :public) }
|
13
|
-
let(:news_page) { create(:alchemy_page, :public, page_layout: 'news', do_not_autogenerate: false) }
|
14
|
-
|
15
|
-
# Validations
|
16
|
-
|
17
|
-
context 'validations' do
|
18
|
-
context "Creating a normal content page" do
|
19
|
-
let(:contentpage) { build(:alchemy_page) }
|
20
|
-
let(:with_same_urlname) { create(:alchemy_page, urlname: "existing_twice") }
|
21
|
-
let(:global_with_same_urlname) { create(:alchemy_page, urlname: "existing_twice", layoutpage: true) }
|
22
|
-
|
23
|
-
context "when its urlname exists as global page" do
|
24
|
-
before { global_with_same_urlname }
|
25
|
-
|
26
|
-
it "it should be possible to save." do
|
27
|
-
contentpage.urlname = "existing_twice"
|
28
|
-
expect(contentpage).to be_valid
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should validate the page_layout" do
|
33
|
-
contentpage.page_layout = nil
|
34
|
-
expect(contentpage).not_to be_valid
|
35
|
-
contentpage.valid?
|
36
|
-
expect(contentpage.errors[:page_layout].size).to eq(1)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should validate the parent_id" do
|
40
|
-
contentpage.parent_id = nil
|
41
|
-
expect(contentpage).not_to be_valid
|
42
|
-
contentpage.valid?
|
43
|
-
expect(contentpage.errors[:parent_id].size).to eq(1)
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'with page having same urlname' do
|
47
|
-
before { with_same_urlname }
|
48
|
-
|
49
|
-
it "should not be valid" do
|
50
|
-
contentpage.urlname = 'existing_twice'
|
51
|
-
expect(contentpage).not_to be_valid
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "with url_nesting set to true" do
|
56
|
-
let(:other_parent) { create(:alchemy_page, parent_id: Page.root.id, visible: true) }
|
57
|
-
|
58
|
-
before do
|
59
|
-
allow(Config).to receive(:get).and_return(true)
|
60
|
-
with_same_urlname
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should only validate urlname dependent of parent" do
|
64
|
-
contentpage.urlname = 'existing_twice'
|
65
|
-
contentpage.parent_id = other_parent.id
|
66
|
-
expect(contentpage).to be_valid
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should validate urlname dependent of parent" do
|
70
|
-
contentpage.urlname = 'existing_twice'
|
71
|
-
expect(contentpage).not_to be_valid
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "creating the rootpage without parent_id and page_layout" do
|
77
|
-
let(:rootpage) { build(:alchemy_page, parent_id: nil, page_layout: nil, name: 'Rootpage') }
|
78
|
-
|
79
|
-
before do
|
80
|
-
Page.delete_all
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should be valid" do
|
84
|
-
expect(rootpage).to be_valid
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context "saving a systempage" do
|
89
|
-
let(:systempage) { build(:alchemy_page, :system) }
|
90
|
-
|
91
|
-
it "should not validate the page_layout" do
|
92
|
-
expect(systempage).to be_valid
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context 'saving an external page' do
|
97
|
-
let(:external_page) { build(:alchemy_page, page_layout: 'external') }
|
98
|
-
|
99
|
-
it "does not pass with invalid url given" do
|
100
|
-
external_page.urlname = 'not, a valid page url'
|
101
|
-
expect(external_page).to_not be_valid
|
102
|
-
end
|
103
|
-
|
104
|
-
it "only be valid with correct url given" do
|
105
|
-
external_page.urlname = 'www.google.com&utf_src=alchemy;page_id=%20'
|
106
|
-
expect(external_page).to be_valid
|
107
|
-
end
|
108
|
-
|
109
|
-
context 'on create' do
|
110
|
-
it "is valid without urlname given" do
|
111
|
-
external_page.urlname = ''
|
112
|
-
expect(external_page).to be_valid
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context 'on update' do
|
117
|
-
before { external_page.save! }
|
118
|
-
|
119
|
-
it "is not valid without urlname given" do
|
120
|
-
external_page.urlname = ''
|
121
|
-
expect(external_page).to_not be_valid
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
# Callbacks
|
128
|
-
|
129
|
-
context 'callbacks' do
|
130
|
-
let(:page) do
|
131
|
-
create(:alchemy_page, name: 'My Testpage', language: language, parent_id: language_root.id)
|
132
|
-
end
|
133
|
-
|
134
|
-
context 'before_save' do
|
135
|
-
it "should not set the title automatically if the name changed but title is not blank" do
|
136
|
-
page.name = "My Renaming Test"
|
137
|
-
page.save; page.reload
|
138
|
-
expect(page.title).to eq("My Testpage")
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should not automatically set the title if it changed its value" do
|
142
|
-
page.title = "I like SEO"
|
143
|
-
page.save; page.reload
|
144
|
-
expect(page.title).to eq("I like SEO")
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
context 'after_update' do
|
149
|
-
context "urlname has changed" do
|
150
|
-
it "should store legacy url if page is not redirect to external page" do
|
151
|
-
page.urlname = 'new-urlname'
|
152
|
-
page.save!
|
153
|
-
expect(page.legacy_urls).not_to be_empty
|
154
|
-
expect(page.legacy_urls.first.urlname).to eq('my-testpage')
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should not store legacy url if page is redirect to external page" do
|
158
|
-
page.urlname = 'new-urlname'
|
159
|
-
page.page_layout = "external"
|
160
|
-
page.save!
|
161
|
-
expect(page.legacy_urls).to be_empty
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should not store legacy url twice for same urlname" do
|
165
|
-
page.urlname = 'new-urlname'
|
166
|
-
page.save!
|
167
|
-
page.urlname = 'my-testpage'
|
168
|
-
page.save!
|
169
|
-
page.urlname = 'another-urlname'
|
170
|
-
page.save!
|
171
|
-
expect(page.legacy_urls.select { |u| u.urlname == 'my-testpage' }.size).to eq(1)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
context "urlname has not changed" do
|
176
|
-
it "should not store a legacy url" do
|
177
|
-
page.urlname = 'my-testpage'
|
178
|
-
page.save!
|
179
|
-
expect(page.legacy_urls).to be_empty
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
context "public has changed" do
|
184
|
-
it "should update published_at" do
|
185
|
-
expect {
|
186
|
-
page.update_attributes!(public: true)
|
187
|
-
}.to change { page.read_attribute(:published_at) }
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should not update already set published_at" do
|
191
|
-
page.update_attributes!(published_at: 2.weeks.ago)
|
192
|
-
expect {
|
193
|
-
page.update_attributes!(public: true)
|
194
|
-
}.to_not change { page.read_attribute(:published_at) }
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
context "public has not changed" do
|
199
|
-
it "should not update published_at" do
|
200
|
-
page.update_attributes!(name: 'New Name')
|
201
|
-
expect(page.read_attribute(:published_at)).to be_nil
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
context 'after_move' do
|
207
|
-
let(:parent_1) { create(:alchemy_page, name: 'Parent 1', visible: true) }
|
208
|
-
let(:parent_2) { create(:alchemy_page, name: 'Parent 2', visible: true) }
|
209
|
-
let(:page) { create(:alchemy_page, parent_id: parent_1.id, name: 'Page', visible: true) }
|
210
|
-
|
211
|
-
it "updates the urlname" do
|
212
|
-
expect(page.urlname).to eq('parent-1/page')
|
213
|
-
page.move_to_child_of parent_2
|
214
|
-
expect(page.urlname).to eq('parent-2/page')
|
215
|
-
end
|
216
|
-
|
217
|
-
context 'of an external page' do
|
218
|
-
let(:external) { create(:alchemy_page, parent_id: parent_1.id, name: 'external', page_layout: 'external', urlname: 'http://google.com') }
|
219
|
-
|
220
|
-
it "the urlname does not get updated" do
|
221
|
-
external.move_to_child_of parent_2
|
222
|
-
expect(external.urlname).to eq('http://google.com')
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
context "Saving a normal page" do
|
228
|
-
let(:page) do
|
229
|
-
build(:alchemy_page, language_code: nil, language: klingon, do_not_autogenerate: false)
|
230
|
-
end
|
231
|
-
|
232
|
-
it "sets the language code" do
|
233
|
-
page.save!
|
234
|
-
expect(page.language_code).to eq("kl")
|
235
|
-
end
|
236
|
-
|
237
|
-
it "autogenerates the elements" do
|
238
|
-
page.save!
|
239
|
-
expect(page.elements).not_to be_empty
|
240
|
-
end
|
241
|
-
|
242
|
-
context 'with elements already on the page' do
|
243
|
-
before do
|
244
|
-
page.elements << create(:alchemy_element, name: 'header')
|
245
|
-
end
|
246
|
-
|
247
|
-
it "does not autogenerate" do
|
248
|
-
page.save!
|
249
|
-
expect(page.elements.select { |e| e.name == 'header' }.length).to eq(1)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
context "with cells" do
|
254
|
-
before do
|
255
|
-
allow(page).to receive(:definition) do
|
256
|
-
{
|
257
|
-
'cells' => %w(header main),
|
258
|
-
'autogenerate' => %w(article)
|
259
|
-
}
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
context 'with elements defined in cells' do
|
264
|
-
before do
|
265
|
-
allow(page).to receive(:cell_definitions) do
|
266
|
-
[{'name' => 'header', 'elements' => %w(article)}]
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
it "has the generated elements in their cells" do
|
271
|
-
page.save!
|
272
|
-
expect(page.cells.where(name: 'header').first.elements).not_to be_empty
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
context "and no elements in cell definitions" do
|
277
|
-
before do
|
278
|
-
allow(page).to receive(:cell_definitions) do
|
279
|
-
[{'name' => 'header', 'elements' => []}]
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
it "should have the elements in the nil cell" do
|
284
|
-
page.save!
|
285
|
-
expect(page.cells.collect(&:elements).flatten).to be_empty
|
286
|
-
end
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
context "with children getting restricted set to true" do
|
291
|
-
before do
|
292
|
-
page.save
|
293
|
-
@child1 = create(:alchemy_page, name: 'Child 1', parent_id: page.id)
|
294
|
-
page.reload
|
295
|
-
page.restricted = true
|
296
|
-
page.save
|
297
|
-
end
|
298
|
-
|
299
|
-
it "restricts all its children" do
|
300
|
-
@child1.reload
|
301
|
-
expect(@child1.restricted?).to be_truthy
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
context "with restricted parent gets created" do
|
306
|
-
before do
|
307
|
-
page.save
|
308
|
-
page.parent.update!(restricted: true)
|
309
|
-
@new_page = create(:alchemy_page, name: 'New Page', parent_id: page.id)
|
310
|
-
end
|
311
|
-
|
312
|
-
it "is also be restricted" do
|
313
|
-
expect(@new_page.restricted?).to be_truthy
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
context "with do_not_autogenerate set to true" do
|
318
|
-
before do
|
319
|
-
page.do_not_autogenerate = true
|
320
|
-
end
|
321
|
-
|
322
|
-
it "should not autogenerate the elements" do
|
323
|
-
page.save
|
324
|
-
expect(page.elements).to be_empty
|
325
|
-
end
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
context "Creating a systempage" do
|
330
|
-
let!(:page) { create(:alchemy_page, :system) }
|
331
|
-
|
332
|
-
it "does not get the language code from language" do
|
333
|
-
expect(page.language_code).to be_nil
|
334
|
-
end
|
335
|
-
|
336
|
-
it "does not autogenerate the elements" do
|
337
|
-
expect(page.elements).to be_empty
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
context "after changing the page layout" do
|
342
|
-
let(:news_element) { news_page.elements.find_by(name: 'news') }
|
343
|
-
|
344
|
-
it "all elements not allowed on this page should be trashed" do
|
345
|
-
expect(news_page.trashed_elements).to be_empty
|
346
|
-
news_page.update_attributes(page_layout: 'standard')
|
347
|
-
trashed = news_page.trashed_elements.pluck(:name)
|
348
|
-
expect(trashed).to eq(['news'])
|
349
|
-
expect(trashed).to_not include('article', 'header')
|
350
|
-
end
|
351
|
-
|
352
|
-
it "should autogenerate elements" do
|
353
|
-
news_page.update_attributes(page_layout: 'contact')
|
354
|
-
expect(news_page.elements.pluck(:name)).to include('contactform')
|
355
|
-
end
|
356
|
-
end
|
357
|
-
end
|
358
|
-
|
359
|
-
# ClassMethods (a-z)
|
360
|
-
|
361
|
-
describe '.all_from_clipboard_for_select' do
|
362
|
-
context "with clipboard holding pages having non unique page layout" do
|
363
|
-
it "should return the pages" do
|
364
|
-
page_1 = create(:alchemy_page, language: language)
|
365
|
-
page_2 = create(:alchemy_page, language: language, name: 'Another page')
|
366
|
-
clipboard = [
|
367
|
-
{'id' => page_1.id.to_s, 'action' => 'copy'},
|
368
|
-
{'id' => page_2.id.to_s, 'action' => 'copy'}
|
369
|
-
]
|
370
|
-
expect(Page.all_from_clipboard_for_select(clipboard, language.id)).to include(page_1, page_2)
|
371
|
-
end
|
372
|
-
end
|
373
|
-
|
374
|
-
context "with clipboard holding a page having unique page layout" do
|
375
|
-
it "should not return any pages" do
|
376
|
-
page_1 = create(:alchemy_page, language: language, page_layout: 'contact')
|
377
|
-
clipboard = [
|
378
|
-
{'id' => page_1.id.to_s, 'action' => 'copy'}
|
379
|
-
]
|
380
|
-
expect(Page.all_from_clipboard_for_select(clipboard, language.id)).to eq([])
|
381
|
-
end
|
382
|
-
end
|
383
|
-
|
384
|
-
context "with clipboard holding two pages. One having a unique page layout." do
|
385
|
-
it "should return one page" do
|
386
|
-
page_1 = create(:alchemy_page, language: language, page_layout: 'standard')
|
387
|
-
page_2 = create(:alchemy_page, name: 'Another page', language: language, page_layout: 'contact')
|
388
|
-
clipboard = [
|
389
|
-
{'id' => page_1.id.to_s, 'action' => 'copy'},
|
390
|
-
{'id' => page_2.id.to_s, 'action' => 'copy'}
|
391
|
-
]
|
392
|
-
expect(Page.all_from_clipboard_for_select(clipboard, language.id)).to eq([page_1])
|
393
|
-
end
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
|
-
describe '.locked' do
|
398
|
-
it "should return 1 page that is blocked by a user at the moment" do
|
399
|
-
create(:alchemy_page, :public, locked: true, name: 'First Public Child', parent_id: language_root.id, language: language)
|
400
|
-
expect(Page.locked.size).to eq(1)
|
401
|
-
end
|
402
|
-
end
|
403
|
-
|
404
|
-
describe '.locked_by' do
|
405
|
-
let(:user) { double(:user, id: 1, class: DummyUser) }
|
406
|
-
|
407
|
-
before do
|
408
|
-
create(:alchemy_page, :public, locked: true, locked_by: 53) # This page must not be part of the collection
|
409
|
-
allow(user.class)
|
410
|
-
.to receive(:primary_key)
|
411
|
-
.and_return('id')
|
412
|
-
end
|
413
|
-
|
414
|
-
it "should return the correct page collection blocked by a certain user" do
|
415
|
-
page = create(:alchemy_page, :public, locked: true, locked_by: 1)
|
416
|
-
expect(Page.locked_by(user).pluck(:id)).to eq([page.id])
|
417
|
-
end
|
418
|
-
|
419
|
-
context 'with user class having a different primary key' do
|
420
|
-
let(:user) { double(:user, user_id: 123, class: DummyUser) }
|
421
|
-
|
422
|
-
before do
|
423
|
-
allow(user.class)
|
424
|
-
.to receive(:primary_key)
|
425
|
-
.and_return('user_id')
|
426
|
-
end
|
427
|
-
|
428
|
-
it "should return the correct page collection blocked by a certain user" do
|
429
|
-
page = create(:alchemy_page, :public, locked: true, locked_by: 123)
|
430
|
-
expect(Page.locked_by(user).pluck(:id)).to eq([page.id])
|
431
|
-
end
|
432
|
-
end
|
433
|
-
end
|
434
|
-
|
435
|
-
describe '.ancestors_for' do
|
436
|
-
let(:lang_root) { Page.language_root_for(Language.default.id) }
|
437
|
-
let(:parent) { create(:alchemy_page, :public) }
|
438
|
-
let(:page) { create(:alchemy_page, :public, parent_id: parent.id) }
|
439
|
-
|
440
|
-
it "returns an array of all parents including self" do
|
441
|
-
expect(Page.ancestors_for(page)).to eq([lang_root, parent, page])
|
442
|
-
end
|
443
|
-
|
444
|
-
it "does not include the root page" do
|
445
|
-
expect(Page.ancestors_for(page)).not_to include(Page.root)
|
446
|
-
end
|
447
|
-
|
448
|
-
context "with current page nil" do
|
449
|
-
it "should return an empty array" do
|
450
|
-
expect(Page.ancestors_for(nil)).to eq([])
|
451
|
-
end
|
452
|
-
end
|
453
|
-
end
|
454
|
-
|
455
|
-
describe '.contentpages' do
|
456
|
-
let!(:layoutroot) do
|
457
|
-
Page.find_or_create_layout_root_for(klingon.id)
|
458
|
-
end
|
459
|
-
|
460
|
-
let!(:layoutpage) do
|
461
|
-
create :alchemy_page, :public, {
|
462
|
-
name: 'layoutpage',
|
463
|
-
layoutpage: true,
|
464
|
-
parent_id: layoutroot.id,
|
465
|
-
language: klingon
|
466
|
-
}
|
467
|
-
end
|
468
|
-
|
469
|
-
let!(:klingon_lang_root) do
|
470
|
-
create :alchemy_page, :language_root, {
|
471
|
-
name: 'klingon_lang_root',
|
472
|
-
layoutpage: nil,
|
473
|
-
language: klingon
|
474
|
-
}
|
475
|
-
end
|
476
|
-
|
477
|
-
let!(:contentpage) do
|
478
|
-
create :alchemy_page, :public, {
|
479
|
-
name: 'contentpage',
|
480
|
-
parent_id: language_root.id,
|
481
|
-
language: language
|
482
|
-
}
|
483
|
-
end
|
484
|
-
|
485
|
-
it "returns a collection of contentpages" do
|
486
|
-
expect(Page.contentpages.to_a).to include(
|
487
|
-
language_root,
|
488
|
-
klingon_lang_root,
|
489
|
-
contentpage
|
490
|
-
)
|
491
|
-
end
|
492
|
-
|
493
|
-
it "does not contain pages with attribute :layoutpage set to true" do
|
494
|
-
expect(Page.contentpages.to_a.select { |p| p.layoutpage == true }).to be_empty
|
495
|
-
end
|
496
|
-
|
497
|
-
it "contains pages with attribute :layoutpage set to nil" do
|
498
|
-
expect(Page.contentpages.to_a.select do |page|
|
499
|
-
page.layoutpage.nil?
|
500
|
-
end).to include(klingon_lang_root)
|
501
|
-
end
|
502
|
-
end
|
503
|
-
|
504
|
-
describe '.copy' do
|
505
|
-
let(:page) { create(:alchemy_page, name: 'Source') }
|
506
|
-
subject { Page.copy(page) }
|
507
|
-
|
508
|
-
it "the copy should have added (copy) to name" do
|
509
|
-
expect(subject.name).to eq("#{page.name} (Copy)")
|
510
|
-
end
|
511
|
-
|
512
|
-
context "page with tags" do
|
513
|
-
before { page.tag_list = 'red, yellow'; page.save }
|
514
|
-
|
515
|
-
it "the copy should have source tag_list" do
|
516
|
-
# The order of tags varies between postgresql and sqlite/mysql
|
517
|
-
# This is related to acts-as-taggable-on v.2.4.1
|
518
|
-
# To fix the spec we sort the tags until the issue is solved (https://github.com/mbleigh/acts-as-taggable-on/issues/363)
|
519
|
-
expect(subject.tag_list).not_to be_empty
|
520
|
-
expect(subject.tag_list.sort).to eq(page.tag_list.sort)
|
521
|
-
end
|
522
|
-
end
|
523
|
-
|
524
|
-
context "page with elements" do
|
525
|
-
before { page.elements << create(:alchemy_element) }
|
526
|
-
|
527
|
-
it "the copy should have source elements" do
|
528
|
-
expect(subject.elements).not_to be_empty
|
529
|
-
expect(subject.elements.count).to eq(page.elements.count)
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
context "page with trashed elements" do
|
534
|
-
before do
|
535
|
-
page.elements << create(:alchemy_element)
|
536
|
-
page.elements.first.trash!
|
537
|
-
end
|
538
|
-
|
539
|
-
it "the copy should not hold a copy of the trashed elements" do
|
540
|
-
expect(subject.elements).to be_empty
|
541
|
-
end
|
542
|
-
end
|
543
|
-
|
544
|
-
context "page with cells" do
|
545
|
-
before { page.cells << create(:alchemy_cell) }
|
546
|
-
|
547
|
-
it "the copy should have source cells" do
|
548
|
-
expect(subject.cells).not_to be_empty
|
549
|
-
expect(subject.cells.count).to eq(page.cells.length) # It must be length, because!
|
550
|
-
end
|
551
|
-
end
|
552
|
-
|
553
|
-
context "page with autogenerate elements" do
|
554
|
-
before do
|
555
|
-
page = create(:alchemy_page)
|
556
|
-
allow(page).to receive(:definition).and_return({'name' => 'standard', 'elements' => ['headline'], 'autogenerate' => ['headline']})
|
557
|
-
end
|
558
|
-
|
559
|
-
it "the copy should not autogenerate elements" do
|
560
|
-
expect(subject.elements).to be_empty
|
561
|
-
end
|
562
|
-
end
|
563
|
-
|
564
|
-
context "with different page name given" do
|
565
|
-
subject { Page.copy(page, {name: 'Different name'}) }
|
566
|
-
|
567
|
-
it "should take this name" do
|
568
|
-
expect(subject.name).to eq('Different name')
|
569
|
-
end
|
570
|
-
end
|
571
|
-
end
|
572
|
-
|
573
|
-
describe '.create' do
|
574
|
-
context "before/after filter" do
|
575
|
-
it "should automatically set the title from its name" do
|
576
|
-
page = create(:alchemy_page, name: 'My Testpage', language: language, parent_id: language_root.id)
|
577
|
-
expect(page.title).to eq('My Testpage')
|
578
|
-
end
|
579
|
-
|
580
|
-
it "should get a webfriendly urlname" do
|
581
|
-
page = create(:alchemy_page, name: 'klingon$&stößel ', language: language, parent_id: language_root.id)
|
582
|
-
expect(page.urlname).to eq('klingon-stoessel')
|
583
|
-
end
|
584
|
-
|
585
|
-
context "with no name set" do
|
586
|
-
it "should not set a urlname" do
|
587
|
-
page = Page.create(name: '', language: language, parent_id: language_root.id)
|
588
|
-
expect(page.urlname).to be_blank
|
589
|
-
end
|
590
|
-
end
|
591
|
-
|
592
|
-
it "should generate a three letter urlname from two letter name" do
|
593
|
-
page = create(:alchemy_page, name: 'Au', language: language, parent_id: language_root.id)
|
594
|
-
expect(page.urlname).to eq('-au')
|
595
|
-
end
|
596
|
-
|
597
|
-
it "should generate a three letter urlname from two letter name with umlaut" do
|
598
|
-
page = create(:alchemy_page, name: 'Aü', language: language, parent_id: language_root.id)
|
599
|
-
expect(page.urlname).to eq('aue')
|
600
|
-
end
|
601
|
-
|
602
|
-
it "should generate a three letter urlname from one letter name" do
|
603
|
-
page = create(:alchemy_page, name: 'A', language: language, parent_id: language_root.id)
|
604
|
-
expect(page.urlname).to eq('--a')
|
605
|
-
end
|
606
|
-
|
607
|
-
it "should add a user stamper" do
|
608
|
-
page = create(:alchemy_page, name: 'A', language: language, parent_id: language_root.id)
|
609
|
-
expect(page.class.stamper_class.to_s).to eq('DummyUser')
|
610
|
-
end
|
611
|
-
|
612
|
-
context "with language given" do
|
613
|
-
it "does not set the language from parent" do
|
614
|
-
expect_any_instance_of(Page).not_to receive(:set_language_from_parent_or_default)
|
615
|
-
Page.create!(name: 'A', parent_id: language_root.id, page_layout: 'standard', language: language)
|
616
|
-
end
|
617
|
-
end
|
618
|
-
|
619
|
-
context "with no language given" do
|
620
|
-
it "sets the language from parent" do
|
621
|
-
expect_any_instance_of(Page).to receive(:set_language_from_parent_or_default)
|
622
|
-
Page.create!(name: 'A', parent_id: language_root.id, page_layout: 'standard')
|
623
|
-
end
|
624
|
-
end
|
625
|
-
end
|
626
|
-
end
|
627
|
-
|
628
|
-
describe '.find_or_create_layout_root_for' do
|
629
|
-
subject { Page.find_or_create_layout_root_for(language_id) }
|
630
|
-
|
631
|
-
let(:language) { mock_model('Language', name: 'English') }
|
632
|
-
let(:language_id) { language.id }
|
633
|
-
|
634
|
-
before { allow(Language).to receive(:find).and_return(language) }
|
635
|
-
|
636
|
-
context 'if no layout root page for given language id could be found' do
|
637
|
-
before do
|
638
|
-
expect(Page).to receive(:create!).and_return(page)
|
639
|
-
end
|
640
|
-
|
641
|
-
it "creates one" do
|
642
|
-
is_expected.to eq(page)
|
643
|
-
end
|
644
|
-
end
|
645
|
-
|
646
|
-
context 'if layout root page for given language id could be found' do
|
647
|
-
let(:page) { mock_model('Page') }
|
648
|
-
|
649
|
-
before do
|
650
|
-
expect(Page).to receive(:layout_root_for).and_return(page)
|
651
|
-
end
|
652
|
-
|
653
|
-
it "returns layout root page" do
|
654
|
-
is_expected.to eq(page)
|
655
|
-
end
|
656
|
-
end
|
657
|
-
end
|
658
|
-
|
659
|
-
describe '.language_roots' do
|
660
|
-
it "should return 1 language_root" do
|
661
|
-
create(:alchemy_page, :public, name: 'First Public Child', parent_id: language_root.id, language: language)
|
662
|
-
expect(Page.language_roots.size).to eq(1)
|
663
|
-
end
|
664
|
-
end
|
665
|
-
|
666
|
-
describe '.layoutpages' do
|
667
|
-
it "should return 1 layoutpage" do
|
668
|
-
create(:alchemy_page, :public, layoutpage: true, name: 'Layoutpage', parent_id: rootpage.id, language: language)
|
669
|
-
expect(Page.layoutpages.size).to eq(1)
|
670
|
-
end
|
671
|
-
end
|
672
|
-
|
673
|
-
describe '.not_locked' do
|
674
|
-
it "should return pages that are not blocked by a user at the moment" do
|
675
|
-
create(:alchemy_page, :public, locked: true, name: 'First Public Child', parent_id: language_root.id, language: language)
|
676
|
-
create(:alchemy_page, :public, name: 'Second Public Child', parent_id: language_root.id, language: language)
|
677
|
-
expect(Page.not_locked.size).to eq(3)
|
678
|
-
end
|
679
|
-
end
|
680
|
-
|
681
|
-
describe '.not_restricted' do
|
682
|
-
it "should return 2 accessible pages" do
|
683
|
-
create(:alchemy_page, :public, name: 'First Public Child', restricted: true, parent_id: language_root.id, language: language)
|
684
|
-
expect(Page.not_restricted.size).to eq(2)
|
685
|
-
end
|
686
|
-
end
|
687
|
-
|
688
|
-
describe '.public' do
|
689
|
-
it "should return pages that are public" do
|
690
|
-
create(:alchemy_page, :public, name: 'First Public Child', parent_id: language_root.id, language: language)
|
691
|
-
create(:alchemy_page, :public, name: 'Second Public Child', parent_id: language_root.id, language: language)
|
692
|
-
expect(Page.published.size).to eq(3)
|
693
|
-
end
|
694
|
-
end
|
695
|
-
|
696
|
-
describe '.public_language_roots' do
|
697
|
-
it "should return pages that public language roots" do
|
698
|
-
create(:alchemy_page, :public, name: 'First Public Child', parent_id: language_root.id, language: language)
|
699
|
-
expect(Page.public_language_roots.size).to eq(1)
|
700
|
-
end
|
701
|
-
end
|
702
|
-
|
703
|
-
describe '.restricted' do
|
704
|
-
it "should return 1 restricted page" do
|
705
|
-
create(:alchemy_page, :public, name: 'First Public Child', restricted: true, parent_id: language_root.id, language: language)
|
706
|
-
expect(Page.restricted.size).to eq(1)
|
707
|
-
end
|
708
|
-
end
|
709
|
-
|
710
|
-
describe '.rootpage' do
|
711
|
-
it "should contain one rootpage" do
|
712
|
-
expect(Page.rootpage).to be_instance_of(Page)
|
713
|
-
end
|
714
|
-
end
|
715
|
-
|
716
|
-
describe '.visible' do
|
717
|
-
it "should return 1 visible page" do
|
718
|
-
create(:alchemy_page, :public, name: 'First Public Child', visible: true, parent_id: language_root.id, language: language)
|
719
|
-
expect(Page.visible.size).to eq(1)
|
720
|
-
end
|
721
|
-
end
|
722
|
-
|
723
|
-
# InstanceMethods (a-z)
|
724
|
-
|
725
|
-
describe '#available_element_definitions' do
|
726
|
-
let(:page) { build_stubbed(:alchemy_page, :public) }
|
727
|
-
|
728
|
-
it "returns all element definitions of available elements" do
|
729
|
-
expect(page.available_element_definitions).to be_an(Array)
|
730
|
-
expect(page.available_element_definitions.collect { |e| e['name'] }).to include('header')
|
731
|
-
end
|
732
|
-
|
733
|
-
context "with unique elements already on page" do
|
734
|
-
let(:element) { build_stubbed(:alchemy_element, :unique) }
|
735
|
-
|
736
|
-
before do
|
737
|
-
allow(page)
|
738
|
-
.to receive(:elements)
|
739
|
-
.and_return double(not_trashed: double(pluck: [element.name]))
|
740
|
-
end
|
741
|
-
|
742
|
-
it "does not return unique element definitions" do
|
743
|
-
expect(page.available_element_definitions.collect { |e| e['name'] }).to include('article')
|
744
|
-
expect(page.available_element_definitions.collect { |e| e['name'] }).not_to include('header')
|
745
|
-
end
|
746
|
-
end
|
747
|
-
|
748
|
-
context 'limited amount' do
|
749
|
-
let(:page) { build_stubbed(:alchemy_page, page_layout: 'columns') }
|
750
|
-
let(:unique_element) do
|
751
|
-
build_stubbed(:alchemy_element, :unique, name: 'unique_headline')
|
752
|
-
end
|
753
|
-
let(:element_1) { build_stubbed(:alchemy_element, name: 'column_headline') }
|
754
|
-
let(:element_2) { build_stubbed(:alchemy_element, name: 'column_headline') }
|
755
|
-
let(:element_3) { build_stubbed(:alchemy_element, name: 'column_headline') }
|
756
|
-
|
757
|
-
before {
|
758
|
-
allow(Element).to receive(:definitions).and_return([
|
759
|
-
{
|
760
|
-
'name' => 'column_headline',
|
761
|
-
'amount' => 3,
|
762
|
-
'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}]
|
763
|
-
},
|
764
|
-
{
|
765
|
-
'name' => 'unique_headline',
|
766
|
-
'unique' => true,
|
767
|
-
'amount' => 3,
|
768
|
-
'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}]
|
769
|
-
}
|
770
|
-
])
|
771
|
-
allow(PageLayout).to receive(:get).and_return({
|
772
|
-
'name' => 'columns',
|
773
|
-
'elements' => ['column_headline', 'unique_headline'],
|
774
|
-
'autogenerate' => ['unique_headline', 'column_headline', 'column_headline', 'column_headline']
|
775
|
-
})
|
776
|
-
allow(page).to receive(:elements).and_return double(
|
777
|
-
not_trashed: double(pluck: [
|
778
|
-
unique_element.name,
|
779
|
-
element_1.name,
|
780
|
-
element_2.name,
|
781
|
-
element_3.name
|
782
|
-
])
|
783
|
-
)
|
784
|
-
}
|
785
|
-
|
786
|
-
it "should be readable" do
|
787
|
-
element = page.element_definitions_by_name('column_headline').first
|
788
|
-
expect(element['amount']).to be 3
|
789
|
-
end
|
790
|
-
|
791
|
-
it "should limit elements" do
|
792
|
-
expect(page.available_element_definitions.collect { |e| e['name'] }).not_to include('column_headline')
|
793
|
-
end
|
794
|
-
|
795
|
-
it "should be ignored if unique" do
|
796
|
-
expect(page.available_element_definitions.collect { |e| e['name'] }).not_to include('unique_headline')
|
797
|
-
end
|
798
|
-
end
|
799
|
-
end
|
800
|
-
|
801
|
-
describe '#available_element_names' do
|
802
|
-
let(:page) { build_stubbed(:alchemy_page) }
|
803
|
-
|
804
|
-
it "returns all names of elements that could be placed on current page" do
|
805
|
-
page.available_element_names == %w(header article)
|
806
|
-
end
|
807
|
-
end
|
808
|
-
|
809
|
-
describe '#cache_key' do
|
810
|
-
let(:page) do
|
811
|
-
stub_model(Page, updated_at: Time.current, published_at: Time.current - 1.week)
|
812
|
-
end
|
813
|
-
|
814
|
-
subject { page.cache_key }
|
815
|
-
|
816
|
-
before do
|
817
|
-
expect(Page).to receive(:current_preview).and_return(preview)
|
818
|
-
end
|
819
|
-
|
820
|
-
context "when current page rendered in preview mode" do
|
821
|
-
let(:preview) { page }
|
822
|
-
|
823
|
-
it { is_expected.to eq("alchemy/pages/#{page.id}-#{page.updated_at}") }
|
824
|
-
end
|
825
|
-
|
826
|
-
context "when current page not in preview mode" do
|
827
|
-
let(:preview) { nil }
|
828
|
-
|
829
|
-
it { is_expected.to eq("alchemy/pages/#{page.id}-#{page.published_at}") }
|
830
|
-
end
|
831
|
-
end
|
832
|
-
|
833
|
-
describe '#cell_definitions' do
|
834
|
-
before do
|
835
|
-
@page = build(:alchemy_page, page_layout: 'foo')
|
836
|
-
allow(@page).to receive(:definition).and_return({'name' => "foo", 'cells' => ["foo_cell"]})
|
837
|
-
@cell_definitions = [{'name' => "foo_cell", 'elements' => ["1", "2"]}]
|
838
|
-
allow(Cell).to receive(:definitions).and_return(@cell_definitions)
|
839
|
-
end
|
840
|
-
|
841
|
-
it "should return all cell definitions for its page_layout" do
|
842
|
-
expect(@page.cell_definitions).to eq(@cell_definitions)
|
843
|
-
end
|
844
|
-
|
845
|
-
it "should return empty array if no cells defined in page layout" do
|
846
|
-
allow(@page).to receive(:definition).and_return({'name' => "foo"})
|
847
|
-
expect(@page.cell_definitions).to eq([])
|
848
|
-
end
|
849
|
-
end
|
850
|
-
|
851
|
-
describe '#destroy' do
|
852
|
-
context "with trashed but still assigned elements" do
|
853
|
-
before { news_page.elements.map(&:trash!) }
|
854
|
-
|
855
|
-
it "should not delete the trashed elements" do
|
856
|
-
news_page.destroy
|
857
|
-
expect(Element.trashed).not_to be_empty
|
858
|
-
end
|
859
|
-
end
|
860
|
-
end
|
861
|
-
|
862
|
-
describe "#elements" do
|
863
|
-
let(:page) { create(:alchemy_page) }
|
864
|
-
let!(:element_1) { create(:alchemy_element, page: page) }
|
865
|
-
let!(:element_2) { create(:alchemy_element, page: page) }
|
866
|
-
let!(:element_3) { create(:alchemy_element, page: page) }
|
867
|
-
|
868
|
-
before do
|
869
|
-
element_3.move_to_top
|
870
|
-
end
|
871
|
-
|
872
|
-
it 'returns a ordered active record collection of elements on that page' do
|
873
|
-
expect(page.elements).to eq([element_3, element_1, element_2])
|
874
|
-
end
|
875
|
-
|
876
|
-
context 'with nestable elements' do
|
877
|
-
let(:nestable_element) { create(:alchemy_element, :with_nestable_elements) }
|
878
|
-
|
879
|
-
before do
|
880
|
-
nestable_element.nested_elements << create(:alchemy_element, name: 'slide')
|
881
|
-
page.elements << nestable_element
|
882
|
-
end
|
883
|
-
|
884
|
-
it 'does not contain nested elements of an element' do
|
885
|
-
expect(nestable_element.nested_elements).to_not be_empty
|
886
|
-
expect(page.elements).to_not include(nestable_element.nested_elements.first)
|
887
|
-
end
|
888
|
-
end
|
889
|
-
end
|
890
|
-
|
891
|
-
describe "#descendent_elements" do
|
892
|
-
let!(:page) do
|
893
|
-
create(:alchemy_page)
|
894
|
-
end
|
895
|
-
|
896
|
-
let!(:element_1) do
|
897
|
-
create(:alchemy_element, page_id: page.id)
|
898
|
-
end
|
899
|
-
|
900
|
-
let!(:element_2) do
|
901
|
-
create(:alchemy_element, :with_nestable_elements, page_id: page.id, parent_element_id: element_1.id)
|
902
|
-
end
|
903
|
-
|
904
|
-
let!(:element_3) do
|
905
|
-
create(:alchemy_element, page_id: page.id)
|
906
|
-
end
|
907
|
-
|
908
|
-
it 'returns an active record collection of all elements including nested elements on that page' do
|
909
|
-
expect(page.descendent_elements.count).to eq(3)
|
910
|
-
end
|
911
|
-
end
|
912
|
-
|
913
|
-
describe "#descendent_contents" do
|
914
|
-
let!(:page) do
|
915
|
-
create(:alchemy_page)
|
916
|
-
end
|
917
|
-
|
918
|
-
let!(:element_1) do
|
919
|
-
create(:alchemy_element, :with_nestable_elements, :with_contents, name: 'slider', page_id: page.id)
|
920
|
-
end
|
921
|
-
|
922
|
-
let!(:element_2) do
|
923
|
-
create :alchemy_element,
|
924
|
-
:with_contents, {
|
925
|
-
name: 'slide',
|
926
|
-
page_id: page.id,
|
927
|
-
parent_element_id: element_1.id
|
928
|
-
}
|
929
|
-
end
|
930
|
-
|
931
|
-
let!(:element_3) do
|
932
|
-
create(:alchemy_element, :with_contents, name: 'slide', page_id: page.id)
|
933
|
-
end
|
934
|
-
|
935
|
-
it 'returns an active record collection of all content including nested elements on that page' do
|
936
|
-
expect(page.descendent_contents.count).to eq(2)
|
937
|
-
end
|
938
|
-
end
|
939
|
-
|
940
|
-
describe '#element_definitions' do
|
941
|
-
let(:page) { build_stubbed(:alchemy_page) }
|
942
|
-
subject { page.element_definitions }
|
943
|
-
before { expect(Element).to receive(:definitions).and_return([{'name' => 'article'}, {'name' => 'header'}]) }
|
944
|
-
|
945
|
-
it "returns all element definitions that could be placed on current page" do
|
946
|
-
is_expected.to include({'name' => 'article'})
|
947
|
-
is_expected.to include({'name' => 'header'})
|
948
|
-
end
|
949
|
-
end
|
950
|
-
|
951
|
-
describe '#element_definitions_by_name' do
|
952
|
-
let(:page) { build_stubbed(:alchemy_page, :public) }
|
953
|
-
|
954
|
-
context "with no name given" do
|
955
|
-
it "returns empty array" do
|
956
|
-
expect(page.element_definitions_by_name(nil)).to eq([])
|
957
|
-
end
|
958
|
-
end
|
959
|
-
|
960
|
-
context "with 'all' passed as name" do
|
961
|
-
it "returns all element definitions" do
|
962
|
-
expect(Element).to receive(:definitions)
|
963
|
-
page.element_definitions_by_name('all')
|
964
|
-
end
|
965
|
-
end
|
966
|
-
|
967
|
-
context "with :all passed as name" do
|
968
|
-
it "returns all element definitions" do
|
969
|
-
expect(Element).to receive(:definitions)
|
970
|
-
page.element_definitions_by_name(:all)
|
971
|
-
end
|
972
|
-
end
|
973
|
-
end
|
974
|
-
|
975
|
-
describe '#element_definition_names' do
|
976
|
-
let(:page) { build_stubbed(:alchemy_page, :public) }
|
977
|
-
|
978
|
-
subject { page.element_definition_names }
|
979
|
-
|
980
|
-
before do
|
981
|
-
allow(page).to receive(:definition) { page_definition }
|
982
|
-
allow(page).to receive(:cell_definitions) { cell_definitions }
|
983
|
-
end
|
984
|
-
|
985
|
-
context "with elements only assigned in page definition" do
|
986
|
-
let(:page_definition) do
|
987
|
-
{'elements' => %w(article)}
|
988
|
-
end
|
989
|
-
|
990
|
-
let(:cell_definitions) { [] }
|
991
|
-
|
992
|
-
it "returns an array of the page's element names" do
|
993
|
-
is_expected.to eq %w(article)
|
994
|
-
end
|
995
|
-
end
|
996
|
-
|
997
|
-
context "with elements assigned only in cell definition" do
|
998
|
-
before do
|
999
|
-
allow(page).to receive(:definition).and_return({})
|
1000
|
-
allow(page).to receive(:cell_definitions) do
|
1001
|
-
[{'elements' => ['search']}]
|
1002
|
-
end
|
1003
|
-
end
|
1004
|
-
|
1005
|
-
it "returns an array of the cell's element names" do
|
1006
|
-
is_expected.to eq(['search'])
|
1007
|
-
end
|
1008
|
-
end
|
1009
|
-
|
1010
|
-
context "with elements assigned in page and cell definition" do
|
1011
|
-
let(:page_definition) do
|
1012
|
-
{'elements' => %w(header article)}
|
1013
|
-
end
|
1014
|
-
|
1015
|
-
let(:cell_definitions) do
|
1016
|
-
[{'elements' => %w(search)}]
|
1017
|
-
end
|
1018
|
-
|
1019
|
-
it "returns the combined element names" do
|
1020
|
-
is_expected.to eq %w(header article search)
|
1021
|
-
end
|
1022
|
-
|
1023
|
-
context "and cell definition contains same element name as page definition" do
|
1024
|
-
let(:page_definition) do
|
1025
|
-
{'elements' => %w(header article)}
|
1026
|
-
end
|
1027
|
-
|
1028
|
-
let(:cell_definitions) do
|
1029
|
-
[{'elements' => %w(header search)}]
|
1030
|
-
end
|
1031
|
-
|
1032
|
-
it "includes no duplicates" do
|
1033
|
-
is_expected.to eq %w(header article search)
|
1034
|
-
end
|
1035
|
-
end
|
1036
|
-
end
|
1037
|
-
|
1038
|
-
context "without elements assigned in page definition or cell definition" do
|
1039
|
-
let(:page_definition) { {} }
|
1040
|
-
let(:cell_definitions) { [] }
|
1041
|
-
|
1042
|
-
it { is_expected.to eq([]) }
|
1043
|
-
end
|
1044
|
-
end
|
1045
|
-
|
1046
|
-
describe '#elements_grouped_by_cells' do
|
1047
|
-
let(:page) { create(:alchemy_page, :public, do_not_autogenerate: false) }
|
1048
|
-
|
1049
|
-
before do
|
1050
|
-
allow(PageLayout).to receive(:get).and_return({
|
1051
|
-
'name' => 'standard',
|
1052
|
-
'cells' => ['header'],
|
1053
|
-
'elements' => ['header', 'text'],
|
1054
|
-
'autogenerate' => ['header', 'text']
|
1055
|
-
})
|
1056
|
-
allow(Cell).to receive(:definitions).and_return([{
|
1057
|
-
'name' => "header",
|
1058
|
-
'elements' => ["header"]
|
1059
|
-
}])
|
1060
|
-
end
|
1061
|
-
|
1062
|
-
it "should return elements grouped by cell" do
|
1063
|
-
elements = page.elements_grouped_by_cells
|
1064
|
-
expect(elements.keys.first).to be_instance_of(Cell)
|
1065
|
-
expect(elements.values.first.first).to be_instance_of(Element)
|
1066
|
-
end
|
1067
|
-
|
1068
|
-
it "should only include elements beeing in a cell " do
|
1069
|
-
expect(page.elements_grouped_by_cells.keys).not_to include(nil)
|
1070
|
-
end
|
1071
|
-
end
|
1072
|
-
|
1073
|
-
describe '#feed_elements' do
|
1074
|
-
let(:news_element) { create(:alchemy_element, name: 'news', public: false, page: news_page) }
|
1075
|
-
|
1076
|
-
it "should return all published rss feed elements" do
|
1077
|
-
expect(news_page.feed_elements).not_to be_empty
|
1078
|
-
expect(news_page.feed_elements).to eq(Element.where(name: 'news').available.to_a)
|
1079
|
-
end
|
1080
|
-
|
1081
|
-
it "should not return unpublished rss feed elements" do
|
1082
|
-
expect(news_page.feed_elements).not_to include(news_element)
|
1083
|
-
end
|
1084
|
-
|
1085
|
-
it "should not return trashed rss feed elements" do
|
1086
|
-
news_element.update(public: true)
|
1087
|
-
news_element.trash!
|
1088
|
-
expect(news_page.feed_elements).not_to include(news_element)
|
1089
|
-
end
|
1090
|
-
end
|
1091
|
-
|
1092
|
-
describe '#find_elements' do
|
1093
|
-
before do
|
1094
|
-
create(:alchemy_element, public: false, page: public_page)
|
1095
|
-
create(:alchemy_element, public: false, page: public_page)
|
1096
|
-
end
|
1097
|
-
|
1098
|
-
context "with show_non_public argument TRUE" do
|
1099
|
-
it "should return all elements from empty options" do
|
1100
|
-
expect(public_page.find_elements({}, true).to_a).to eq(public_page.elements.to_a)
|
1101
|
-
end
|
1102
|
-
|
1103
|
-
it "should only return the elements passed as options[:only]" do
|
1104
|
-
expect(public_page.find_elements({only: ['article']}, true).to_a).to eq(public_page.elements.named('article').to_a)
|
1105
|
-
end
|
1106
|
-
|
1107
|
-
it "should not return the elements passed as options[:except]" do
|
1108
|
-
expect(public_page.find_elements({except: ['article']}, true).to_a).to eq(public_page.elements - public_page.elements.named('article').to_a)
|
1109
|
-
end
|
1110
|
-
|
1111
|
-
it "should return elements offsetted" do
|
1112
|
-
expect(public_page.find_elements({offset: 2}, true).to_a).to eq(public_page.elements.offset(2))
|
1113
|
-
end
|
1114
|
-
|
1115
|
-
it "should return elements limitted in count" do
|
1116
|
-
expect(public_page.find_elements({count: 1}, true).to_a).to eq(public_page.elements.limit(1))
|
1117
|
-
end
|
1118
|
-
end
|
1119
|
-
|
1120
|
-
context "with options[:from_cell]" do
|
1121
|
-
let(:element) { build_stubbed(:alchemy_element) }
|
1122
|
-
|
1123
|
-
context "given as String" do
|
1124
|
-
context 'with elements present' do
|
1125
|
-
before do
|
1126
|
-
expect(public_page.cells)
|
1127
|
-
.to receive(:find_by_name)
|
1128
|
-
.and_return double(elements: double(offset: double(limit: double(published: [element]))))
|
1129
|
-
end
|
1130
|
-
|
1131
|
-
it "returns only the elements from given cell" do
|
1132
|
-
expect(public_page.find_elements(from_cell: 'A Cell').to_a).to eq([element])
|
1133
|
-
end
|
1134
|
-
end
|
1135
|
-
|
1136
|
-
context "that can not be found" do
|
1137
|
-
let(:elements) { [] }
|
1138
|
-
|
1139
|
-
before do
|
1140
|
-
allow(elements)
|
1141
|
-
.to receive(:offset)
|
1142
|
-
.and_return double(limit: double(published: elements))
|
1143
|
-
end
|
1144
|
-
|
1145
|
-
it "returns empty set" do
|
1146
|
-
expect(Element).to receive(:none).and_return(elements)
|
1147
|
-
expect(public_page.find_elements(from_cell: 'Lolo').to_a).to eq([])
|
1148
|
-
end
|
1149
|
-
|
1150
|
-
it "loggs a warning" do
|
1151
|
-
expect(Rails.logger).to receive(:debug)
|
1152
|
-
public_page.find_elements(from_cell: 'Lolo')
|
1153
|
-
end
|
1154
|
-
end
|
1155
|
-
end
|
1156
|
-
|
1157
|
-
context "given as cell object" do
|
1158
|
-
let(:cell) { build_stubbed(:alchemy_cell, page: public_page) }
|
1159
|
-
|
1160
|
-
it "returns only the elements from given cell" do
|
1161
|
-
expect(cell)
|
1162
|
-
.to receive(:elements)
|
1163
|
-
.and_return double(offset: double(limit: double(published: [element])))
|
1164
|
-
|
1165
|
-
expect(public_page.find_elements(from_cell: cell).to_a).to eq([element])
|
1166
|
-
end
|
1167
|
-
end
|
1168
|
-
end
|
1169
|
-
|
1170
|
-
context "with show_non_public argument FALSE" do
|
1171
|
-
it "should return all elements from empty arguments" do
|
1172
|
-
expect(public_page.find_elements.to_a).to eq(public_page.elements.published.to_a)
|
1173
|
-
end
|
1174
|
-
|
1175
|
-
it "should only return the public elements passed as options[:only]" do
|
1176
|
-
expect(public_page.find_elements(only: ['article']).to_a).to eq(public_page.elements.published.named('article').to_a)
|
1177
|
-
end
|
1178
|
-
|
1179
|
-
it "should return all public elements except the ones passed as options[:except]" do
|
1180
|
-
expect(public_page.find_elements(except: ['article']).to_a).to eq(public_page.elements.published.to_a - public_page.elements.published.named('article').to_a)
|
1181
|
-
end
|
1182
|
-
|
1183
|
-
it "should return elements offsetted" do
|
1184
|
-
expect(public_page.find_elements({offset: 2}).to_a).to eq(public_page.elements.published.offset(2))
|
1185
|
-
end
|
1186
|
-
|
1187
|
-
it "should return elements limitted in count" do
|
1188
|
-
expect(public_page.find_elements({count: 1}).to_a).to eq(public_page.elements.published.limit(1))
|
1189
|
-
end
|
1190
|
-
end
|
1191
|
-
end
|
1192
|
-
|
1193
|
-
describe '#first_public_child' do
|
1194
|
-
before do
|
1195
|
-
create(:alchemy_page, name: "First child", language: language, public: false, parent_id: language_root.id)
|
1196
|
-
end
|
1197
|
-
|
1198
|
-
it "should return first_public_child" do
|
1199
|
-
first_public_child = create(:alchemy_page, :public, name: "First public child", language: language, parent_id: language_root.id)
|
1200
|
-
expect(language_root.first_public_child).to eq(first_public_child)
|
1201
|
-
end
|
1202
|
-
|
1203
|
-
it "should return nil if no public child exists" do
|
1204
|
-
expect(language_root.first_public_child).to eq(nil)
|
1205
|
-
end
|
1206
|
-
end
|
1207
|
-
|
1208
|
-
context 'folding' do
|
1209
|
-
let(:user) { mock_model('DummyUser') }
|
1210
|
-
|
1211
|
-
describe '#fold!' do
|
1212
|
-
context "with folded status set to true" do
|
1213
|
-
it "should create a folded page for user" do
|
1214
|
-
public_page.fold!(user.id, true)
|
1215
|
-
expect(public_page.folded_pages.first.user_id).to eq(user.id)
|
1216
|
-
end
|
1217
|
-
end
|
1218
|
-
end
|
1219
|
-
|
1220
|
-
describe '#folded?' do
|
1221
|
-
let(:page) { Page.new }
|
1222
|
-
|
1223
|
-
context 'with user is a active record model' do
|
1224
|
-
before do
|
1225
|
-
expect(Alchemy.user_class).to receive(:'<').and_return(true)
|
1226
|
-
end
|
1227
|
-
|
1228
|
-
context 'if page is folded' do
|
1229
|
-
before do
|
1230
|
-
expect(page)
|
1231
|
-
.to receive(:folded_pages)
|
1232
|
-
.and_return double(where: double(any?: true))
|
1233
|
-
end
|
1234
|
-
|
1235
|
-
it "should return true" do
|
1236
|
-
expect(page.folded?(user.id)).to eq(true)
|
1237
|
-
end
|
1238
|
-
end
|
1239
|
-
|
1240
|
-
context 'if page is not folded' do
|
1241
|
-
it "should return false" do
|
1242
|
-
expect(page.folded?(101_093)).to eq(false)
|
1243
|
-
end
|
1244
|
-
end
|
1245
|
-
end
|
1246
|
-
end
|
1247
|
-
end
|
1248
|
-
|
1249
|
-
describe '#get_language_root' do
|
1250
|
-
before { language_root }
|
1251
|
-
subject { public_page.get_language_root }
|
1252
|
-
|
1253
|
-
it "returns the language root page" do
|
1254
|
-
is_expected.to eq language_root
|
1255
|
-
end
|
1256
|
-
end
|
1257
|
-
|
1258
|
-
describe '#definition' do
|
1259
|
-
context 'if the page layout could not be found in the definition file' do
|
1260
|
-
let(:page) { build_stubbed(:alchemy_page, page_layout: 'notexisting') }
|
1261
|
-
|
1262
|
-
it "it loggs a warning." do
|
1263
|
-
expect(Alchemy::Logger).to receive(:warn)
|
1264
|
-
page.definition
|
1265
|
-
end
|
1266
|
-
|
1267
|
-
it "it returns empty hash." do
|
1268
|
-
expect(page.definition).to eq({})
|
1269
|
-
end
|
1270
|
-
end
|
1271
|
-
|
1272
|
-
context "for a language root page" do
|
1273
|
-
it "it returns the page layout definition as hash." do
|
1274
|
-
expect(language_root.definition['name']).to eq('index')
|
1275
|
-
end
|
1276
|
-
|
1277
|
-
it "it returns an empty hash for root page." do
|
1278
|
-
expect(rootpage.definition).to eq({})
|
1279
|
-
end
|
1280
|
-
end
|
1281
|
-
end
|
1282
|
-
|
1283
|
-
describe '#lock_to!' do
|
1284
|
-
let(:page) { create(:alchemy_page) }
|
1285
|
-
let(:user) { mock_model('DummyUser') }
|
1286
|
-
|
1287
|
-
it "should set locked to true" do
|
1288
|
-
page.lock_to!(user)
|
1289
|
-
page.reload
|
1290
|
-
expect(page.locked).to eq(true)
|
1291
|
-
end
|
1292
|
-
|
1293
|
-
it "should not update the timestamps " do
|
1294
|
-
expect { page.lock!(user) }.to_not change(page, :updated_at)
|
1295
|
-
end
|
1296
|
-
|
1297
|
-
it "should set locked_by to the users id" do
|
1298
|
-
page.lock_to!(user)
|
1299
|
-
page.reload
|
1300
|
-
expect(page.locked_by).to eq(user.id)
|
1301
|
-
end
|
1302
|
-
end
|
1303
|
-
|
1304
|
-
describe '#copy_and_paste' do
|
1305
|
-
let(:source) { build_stubbed(:alchemy_page) }
|
1306
|
-
let(:new_parent) { build_stubbed(:alchemy_page) }
|
1307
|
-
let(:page_name) { "Pagename (pasted)" }
|
1308
|
-
let(:copied_page) { mock_model('Page') }
|
1309
|
-
|
1310
|
-
subject { Page.copy_and_paste(source, new_parent, page_name) }
|
1311
|
-
|
1312
|
-
it "should copy the source page with the given name to the new parent" do
|
1313
|
-
expect(Page).to receive(:copy).with(source, {
|
1314
|
-
parent_id: new_parent.id,
|
1315
|
-
language: new_parent.language,
|
1316
|
-
name: page_name,
|
1317
|
-
title: page_name
|
1318
|
-
})
|
1319
|
-
subject
|
1320
|
-
end
|
1321
|
-
|
1322
|
-
it "should return the copied page" do
|
1323
|
-
allow(Page).to receive(:copy).and_return(copied_page)
|
1324
|
-
expect(subject).to be_a(copied_page.class)
|
1325
|
-
end
|
1326
|
-
|
1327
|
-
context "if source page has children" do
|
1328
|
-
it "should also copy and paste the children" do
|
1329
|
-
allow(Page).to receive(:copy).and_return(copied_page)
|
1330
|
-
allow(source).to receive(:children).and_return([mock_model('Page')])
|
1331
|
-
expect(source).to receive(:copy_children_to).with(copied_page)
|
1332
|
-
subject
|
1333
|
-
end
|
1334
|
-
end
|
1335
|
-
end
|
1336
|
-
|
1337
|
-
context 'previous and next.' do
|
1338
|
-
let(:center_page) { create(:alchemy_page, :public, name: 'Center Page') }
|
1339
|
-
let(:next_page) { create(:alchemy_page, :public, name: 'Next Page') }
|
1340
|
-
let(:non_public_page) { create(:alchemy_page, name: 'Not public Page') }
|
1341
|
-
let(:restricted_page) { create(:alchemy_page, :restricted, public: true) }
|
1342
|
-
|
1343
|
-
before do
|
1344
|
-
public_page
|
1345
|
-
restricted_page
|
1346
|
-
non_public_page
|
1347
|
-
center_page
|
1348
|
-
next_page
|
1349
|
-
end
|
1350
|
-
|
1351
|
-
describe '#previous' do
|
1352
|
-
it "should return the previous page on the same level" do
|
1353
|
-
expect(center_page.previous).to eq(public_page)
|
1354
|
-
expect(next_page.previous).to eq(center_page)
|
1355
|
-
end
|
1356
|
-
|
1357
|
-
context "no previous page on same level present" do
|
1358
|
-
it "should return nil" do
|
1359
|
-
expect(public_page.previous).to be_nil
|
1360
|
-
end
|
1361
|
-
end
|
1362
|
-
|
1363
|
-
context "with options restricted" do
|
1364
|
-
context "set to true" do
|
1365
|
-
it "returns previous restricted page" do
|
1366
|
-
expect(center_page.previous(restricted: true)).to eq(restricted_page)
|
1367
|
-
end
|
1368
|
-
end
|
1369
|
-
|
1370
|
-
context "set to false" do
|
1371
|
-
it "skips restricted page" do
|
1372
|
-
expect(center_page.previous(restricted: false)).to eq(public_page)
|
1373
|
-
end
|
1374
|
-
end
|
1375
|
-
end
|
1376
|
-
|
1377
|
-
context "with options public" do
|
1378
|
-
context "set to true" do
|
1379
|
-
it "returns previous public page" do
|
1380
|
-
expect(center_page.previous(public: true)).to eq(public_page)
|
1381
|
-
end
|
1382
|
-
end
|
1383
|
-
|
1384
|
-
context "set to false" do
|
1385
|
-
it "skips public page" do
|
1386
|
-
expect(center_page.previous(public: false)).to eq(non_public_page)
|
1387
|
-
end
|
1388
|
-
end
|
1389
|
-
end
|
1390
|
-
end
|
1391
|
-
|
1392
|
-
describe '#next' do
|
1393
|
-
it "should return the next page on the same level" do
|
1394
|
-
expect(center_page.next).to eq(next_page)
|
1395
|
-
end
|
1396
|
-
|
1397
|
-
context "no next page on same level present" do
|
1398
|
-
it "should return nil" do
|
1399
|
-
expect(next_page.next).to be_nil
|
1400
|
-
end
|
1401
|
-
end
|
1402
|
-
end
|
1403
|
-
end
|
1404
|
-
|
1405
|
-
describe '#publish!' do
|
1406
|
-
let(:page) { build_stubbed(:alchemy_page, public: false) }
|
1407
|
-
let(:current_time) { Time.current }
|
1408
|
-
|
1409
|
-
before do
|
1410
|
-
current_time
|
1411
|
-
allow(Time).to receive(:now).and_return(current_time)
|
1412
|
-
page.publish!
|
1413
|
-
end
|
1414
|
-
|
1415
|
-
it "sets public attribute to true" do
|
1416
|
-
expect(page.public).to eq(true)
|
1417
|
-
end
|
1418
|
-
|
1419
|
-
it "sets published_at attribute to current time" do
|
1420
|
-
expect(page.published_at).to eq(current_time)
|
1421
|
-
end
|
1422
|
-
end
|
1423
|
-
|
1424
|
-
describe '#set_language_from_parent_or_default' do
|
1425
|
-
let(:default_language) { mock_model('Language', code: 'es') }
|
1426
|
-
let(:page) { Page.new }
|
1427
|
-
|
1428
|
-
before { allow(page).to receive(:parent).and_return(parent) }
|
1429
|
-
|
1430
|
-
subject { page }
|
1431
|
-
|
1432
|
-
context "parent has a language" do
|
1433
|
-
let(:parent) { mock_model('Page', language: default_language, language_id: default_language.id, language_code: default_language.code) }
|
1434
|
-
|
1435
|
-
before do
|
1436
|
-
page.send(:set_language_from_parent_or_default)
|
1437
|
-
end
|
1438
|
-
|
1439
|
-
describe '#language_id' do
|
1440
|
-
subject { super().language_id }
|
1441
|
-
it { is_expected.to eq(parent.language_id) }
|
1442
|
-
end
|
1443
|
-
end
|
1444
|
-
|
1445
|
-
context "parent has no language" do
|
1446
|
-
let(:parent) { mock_model('Page', language: nil, language_id: nil, language_code: nil) }
|
1447
|
-
|
1448
|
-
before do
|
1449
|
-
allow(Language).to receive(:default).and_return(default_language)
|
1450
|
-
page.send(:set_language_from_parent_or_default)
|
1451
|
-
end
|
1452
|
-
|
1453
|
-
describe '#language_id' do
|
1454
|
-
subject { super().language_id }
|
1455
|
-
it { is_expected.to eq(default_language.id) }
|
1456
|
-
end
|
1457
|
-
end
|
1458
|
-
end
|
1459
|
-
|
1460
|
-
describe '#taggable?' do
|
1461
|
-
context "definition has 'taggable' key with true value" do
|
1462
|
-
it "should return true" do
|
1463
|
-
page = build(:alchemy_page)
|
1464
|
-
allow(page).to receive(:definition).and_return({'name' => 'standard', 'taggable' => true})
|
1465
|
-
expect(page.taggable?).to be_truthy
|
1466
|
-
end
|
1467
|
-
end
|
1468
|
-
|
1469
|
-
context "definition has 'taggable' key with foo value" do
|
1470
|
-
it "should return false" do
|
1471
|
-
page = build(:alchemy_page)
|
1472
|
-
allow(page).to receive(:definition).and_return({'name' => 'standard', 'taggable' => 'foo'})
|
1473
|
-
expect(page.taggable?).to be_falsey
|
1474
|
-
end
|
1475
|
-
end
|
1476
|
-
|
1477
|
-
context "definition has no 'taggable' key" do
|
1478
|
-
it "should return false" do
|
1479
|
-
page = build(:alchemy_page)
|
1480
|
-
allow(page).to receive(:definition).and_return({'name' => 'standard'})
|
1481
|
-
expect(page.taggable?).to be_falsey
|
1482
|
-
end
|
1483
|
-
end
|
1484
|
-
end
|
1485
|
-
|
1486
|
-
describe '#unlock!' do
|
1487
|
-
let(:page) { create(:alchemy_page, locked: true, locked_by: 1) }
|
1488
|
-
|
1489
|
-
before do
|
1490
|
-
allow(page).to receive(:save).and_return(true)
|
1491
|
-
end
|
1492
|
-
|
1493
|
-
it "should set the locked status to false" do
|
1494
|
-
page.unlock!
|
1495
|
-
page.reload
|
1496
|
-
expect(page.locked).to eq(false)
|
1497
|
-
end
|
1498
|
-
|
1499
|
-
it "should not update the timestamps " do
|
1500
|
-
expect { page.unlock! }.to_not change(page, :updated_at)
|
1501
|
-
end
|
1502
|
-
|
1503
|
-
it "should set locked_by to nil" do
|
1504
|
-
page.unlock!
|
1505
|
-
page.reload
|
1506
|
-
expect(page.locked_by).to eq(nil)
|
1507
|
-
end
|
1508
|
-
|
1509
|
-
it "sets current preview to nil" do
|
1510
|
-
Page.current_preview = page
|
1511
|
-
page.unlock!
|
1512
|
-
expect(Page.current_preview).to be_nil
|
1513
|
-
end
|
1514
|
-
end
|
1515
|
-
|
1516
|
-
context 'urlname updating' do
|
1517
|
-
let(:parentparent) { create(:alchemy_page, name: 'parentparent', visible: true) }
|
1518
|
-
let(:parent) { create(:alchemy_page, parent_id: parentparent.id, name: 'parent', visible: true) }
|
1519
|
-
let(:page) { create(:alchemy_page, parent_id: parent.id, name: 'page', visible: true) }
|
1520
|
-
let(:invisible) { create(:alchemy_page, parent_id: page.id, name: 'invisible', visible: false) }
|
1521
|
-
let(:contact) { create(:alchemy_page, parent_id: invisible.id, name: 'contact', visible: true) }
|
1522
|
-
let(:external) { create(:alchemy_page, parent_id: parent.id, name: 'external', page_layout: 'external', urlname: 'http://google.com') }
|
1523
|
-
let(:language_root) { parentparent.parent }
|
1524
|
-
|
1525
|
-
context "with activated url_nesting" do
|
1526
|
-
before { allow(Config).to receive(:get).and_return(true) }
|
1527
|
-
|
1528
|
-
it "should store all parents urlnames delimited by slash" do
|
1529
|
-
expect(page.urlname).to eq('parentparent/parent/page')
|
1530
|
-
end
|
1531
|
-
|
1532
|
-
it "should not include the root page" do
|
1533
|
-
Page.root.update_column(:urlname, 'root')
|
1534
|
-
language_root.update(urlname: 'new-urlname')
|
1535
|
-
expect(language_root.urlname).not_to match(/root/)
|
1536
|
-
end
|
1537
|
-
|
1538
|
-
it "should not include the language root page" do
|
1539
|
-
expect(page.urlname).not_to match(/startseite/)
|
1540
|
-
end
|
1541
|
-
|
1542
|
-
it "should not include invisible pages" do
|
1543
|
-
expect(contact.urlname).not_to match(/invisible/)
|
1544
|
-
end
|
1545
|
-
|
1546
|
-
context "with an invisible parent" do
|
1547
|
-
before { parent.update_attribute(:visible, false) }
|
1548
|
-
|
1549
|
-
it "does not change if set_urlname is called" do
|
1550
|
-
expect { page.send(:set_urlname) }.not_to change { page.urlname }
|
1551
|
-
end
|
1552
|
-
|
1553
|
-
it "does not change if update_urlname! is called" do
|
1554
|
-
expect { page.update_urlname! }.not_to change { page.urlname }
|
1555
|
-
end
|
1556
|
-
end
|
1557
|
-
|
1558
|
-
context "after changing page's urlname" do
|
1559
|
-
it "updates urlnames of descendants" do
|
1560
|
-
page
|
1561
|
-
parentparent.urlname = 'new-urlname'
|
1562
|
-
parentparent.save!
|
1563
|
-
page.reload
|
1564
|
-
expect(page.urlname).to eq('new-urlname/parent/page')
|
1565
|
-
end
|
1566
|
-
|
1567
|
-
context 'with descendants that are redirecting to external' do
|
1568
|
-
it "it skips this page" do
|
1569
|
-
external
|
1570
|
-
parent.urlname = 'new-urlname'
|
1571
|
-
parent.save!
|
1572
|
-
external.reload
|
1573
|
-
expect(external.urlname).to eq('http://google.com')
|
1574
|
-
end
|
1575
|
-
end
|
1576
|
-
|
1577
|
-
it "should create a legacy url" do
|
1578
|
-
allow(page).to receive(:slug).and_return('foo')
|
1579
|
-
page.update_urlname!
|
1580
|
-
expect(page.legacy_urls).not_to be_empty
|
1581
|
-
expect(page.legacy_urls.pluck(:urlname)).to include('parentparent/parent/page')
|
1582
|
-
end
|
1583
|
-
end
|
1584
|
-
|
1585
|
-
context "after updating my visibility" do
|
1586
|
-
it "should update urlnames of descendants" do
|
1587
|
-
page
|
1588
|
-
parentparent.visible = false
|
1589
|
-
parentparent.save!
|
1590
|
-
page.reload
|
1591
|
-
expect(page.urlname).to eq('parent/page')
|
1592
|
-
end
|
1593
|
-
end
|
1594
|
-
end
|
1595
|
-
|
1596
|
-
context "with disabled url_nesting" do
|
1597
|
-
before { allow(Config).to receive(:get).and_return(false) }
|
1598
|
-
|
1599
|
-
it "should only store my urlname" do
|
1600
|
-
expect(page.urlname).to eq('page')
|
1601
|
-
end
|
1602
|
-
end
|
1603
|
-
end
|
1604
|
-
|
1605
|
-
describe "#update_node!" do
|
1606
|
-
let(:original_url) { "sample-url" }
|
1607
|
-
let(:page) { create(:alchemy_page, language: language, parent_id: language_root.id, urlname: original_url, restricted: false) }
|
1608
|
-
let(:node) { TreeNode.new(10, 11, 12, 13, "another-url", true) }
|
1609
|
-
|
1610
|
-
context "when nesting is enabled" do
|
1611
|
-
before { allow(Alchemy::Config).to receive(:get).with(:url_nesting) { true } }
|
1612
|
-
|
1613
|
-
context "when page is not external" do
|
1614
|
-
before do
|
1615
|
-
expect(page).to receive(:redirects_to_external?).and_return(false)
|
1616
|
-
end
|
1617
|
-
|
1618
|
-
it "should update all attributes" do
|
1619
|
-
page.update_node!(node)
|
1620
|
-
page.reload
|
1621
|
-
expect(page.lft).to eq(node.left)
|
1622
|
-
expect(page.rgt).to eq(node.right)
|
1623
|
-
expect(page.parent_id).to eq(node.parent)
|
1624
|
-
expect(page.depth).to eq(node.depth)
|
1625
|
-
expect(page.urlname).to eq(node.url)
|
1626
|
-
expect(page.restricted).to eq(node.restricted)
|
1627
|
-
end
|
1628
|
-
|
1629
|
-
context "when url is the same" do
|
1630
|
-
let(:node) { TreeNode.new(10, 11, 12, 13, original_url, true) }
|
1631
|
-
|
1632
|
-
it "should not create a legacy url" do
|
1633
|
-
page.update_node!(node)
|
1634
|
-
page.reload
|
1635
|
-
expect(page.legacy_urls.size).to eq(0)
|
1636
|
-
end
|
1637
|
-
end
|
1638
|
-
|
1639
|
-
context "when url is not the same" do
|
1640
|
-
it "should create a legacy url" do
|
1641
|
-
page.update_node!(node)
|
1642
|
-
page.reload
|
1643
|
-
expect(page.legacy_urls.size).to eq(1)
|
1644
|
-
end
|
1645
|
-
end
|
1646
|
-
end
|
1647
|
-
|
1648
|
-
context "when page is external" do
|
1649
|
-
before do
|
1650
|
-
expect(page)
|
1651
|
-
.to receive(:redirects_to_external?)
|
1652
|
-
.and_return(true)
|
1653
|
-
end
|
1654
|
-
|
1655
|
-
it "should update all attributes except url" do
|
1656
|
-
page.update_node!(node)
|
1657
|
-
page.reload
|
1658
|
-
expect(page.lft).to eq(node.left)
|
1659
|
-
expect(page.rgt).to eq(node.right)
|
1660
|
-
expect(page.parent_id).to eq(node.parent)
|
1661
|
-
expect(page.depth).to eq(node.depth)
|
1662
|
-
expect(page.urlname).to eq(original_url)
|
1663
|
-
expect(page.restricted).to eq(node.restricted)
|
1664
|
-
end
|
1665
|
-
|
1666
|
-
it "should not create a legacy url" do
|
1667
|
-
page.update_node!(node)
|
1668
|
-
page.reload
|
1669
|
-
expect(page.legacy_urls.size).to eq(0)
|
1670
|
-
end
|
1671
|
-
end
|
1672
|
-
end
|
1673
|
-
|
1674
|
-
context "when nesting is disabled" do
|
1675
|
-
before do
|
1676
|
-
allow(Alchemy::Config).to receive(:get).with(:url_nesting) { false }
|
1677
|
-
end
|
1678
|
-
|
1679
|
-
context "when page is not external" do
|
1680
|
-
before do
|
1681
|
-
allow(page).to receive(:redirects_to_external?).and_return(false)
|
1682
|
-
end
|
1683
|
-
|
1684
|
-
it "should update all attributes except url" do
|
1685
|
-
page.update_node!(node)
|
1686
|
-
page.reload
|
1687
|
-
expect(page.lft).to eq(node.left)
|
1688
|
-
expect(page.rgt).to eq(node.right)
|
1689
|
-
expect(page.parent_id).to eq(node.parent)
|
1690
|
-
expect(page.depth).to eq(node.depth)
|
1691
|
-
expect(page.urlname).to eq(original_url)
|
1692
|
-
expect(page.restricted).to eq(node.restricted)
|
1693
|
-
end
|
1694
|
-
|
1695
|
-
it "should not create a legacy url" do
|
1696
|
-
page.update_node!(node)
|
1697
|
-
page.reload
|
1698
|
-
expect(page.legacy_urls.size).to eq(0)
|
1699
|
-
end
|
1700
|
-
end
|
1701
|
-
|
1702
|
-
context "when page is external" do
|
1703
|
-
before do
|
1704
|
-
expect(Alchemy::Config).to receive(:get).and_return(true)
|
1705
|
-
allow(page).to receive(:redirects_to_external?).and_return(true)
|
1706
|
-
end
|
1707
|
-
|
1708
|
-
it "should update all attributes except url" do
|
1709
|
-
page.update_node!(node)
|
1710
|
-
page.reload
|
1711
|
-
expect(page.lft).to eq(node.left)
|
1712
|
-
expect(page.rgt).to eq(node.right)
|
1713
|
-
expect(page.parent_id).to eq(node.parent)
|
1714
|
-
expect(page.depth).to eq(node.depth)
|
1715
|
-
expect(page.urlname).to eq(original_url)
|
1716
|
-
expect(page.restricted).to eq(node.restricted)
|
1717
|
-
end
|
1718
|
-
|
1719
|
-
it "should not create a legacy url" do
|
1720
|
-
page.update_node!(node)
|
1721
|
-
page.reload
|
1722
|
-
expect(page.legacy_urls.size).to eq(0)
|
1723
|
-
end
|
1724
|
-
end
|
1725
|
-
end
|
1726
|
-
end
|
1727
|
-
|
1728
|
-
describe '#cache_page?' do
|
1729
|
-
let(:page) { Page.new(page_layout: "news") }
|
1730
|
-
subject { page.cache_page? }
|
1731
|
-
|
1732
|
-
before { Rails.application.config.action_controller.perform_caching = true }
|
1733
|
-
after { Rails.application.config.action_controller.perform_caching = false }
|
1734
|
-
|
1735
|
-
it 'returns true when everthing is alright' do
|
1736
|
-
expect(subject).to be true
|
1737
|
-
end
|
1738
|
-
|
1739
|
-
it 'returns false when the Rails app does not perform caching' do
|
1740
|
-
Rails.application.config.action_controller.perform_caching = false
|
1741
|
-
expect(subject).to be false
|
1742
|
-
end
|
1743
|
-
|
1744
|
-
it 'returns false when caching is deactivated in the Alchemy config' do
|
1745
|
-
allow(Alchemy::Config).to receive(:get).with(:cache_pages).and_return(false)
|
1746
|
-
expect(subject).to be false
|
1747
|
-
end
|
1748
|
-
|
1749
|
-
it 'returns false when the page layout is set to cache = false' do
|
1750
|
-
page_layout = PageLayout.get('news')
|
1751
|
-
page_layout['cache'] = false
|
1752
|
-
allow(PageLayout).to receive(:get).with('news').and_return(page_layout)
|
1753
|
-
expect(subject).to be false
|
1754
|
-
end
|
1755
|
-
|
1756
|
-
it 'returns false when the page layout is set to searchresults = true' do
|
1757
|
-
page_layout = PageLayout.get('news')
|
1758
|
-
page_layout['searchresults'] = true
|
1759
|
-
allow(PageLayout).to receive(:get).with('news').and_return(page_layout)
|
1760
|
-
expect(subject).to be false
|
1761
|
-
end
|
1762
|
-
end
|
1763
|
-
|
1764
|
-
describe '#slug' do
|
1765
|
-
context "with parents path saved in urlname" do
|
1766
|
-
let(:page) { build(:alchemy_page, urlname: 'root/parent/my-name') }
|
1767
|
-
|
1768
|
-
it "should return the last part of the urlname" do
|
1769
|
-
expect(page.slug).to eq('my-name')
|
1770
|
-
end
|
1771
|
-
end
|
1772
|
-
|
1773
|
-
context "with single urlname" do
|
1774
|
-
let(:page) { build(:alchemy_page, urlname: 'my-name') }
|
1775
|
-
|
1776
|
-
it "should return the last part of the urlname" do
|
1777
|
-
expect(page.slug).to eq('my-name')
|
1778
|
-
end
|
1779
|
-
end
|
1780
|
-
|
1781
|
-
context "with nil as urlname" do
|
1782
|
-
let(:page) { build(:alchemy_page, urlname: nil) }
|
1783
|
-
|
1784
|
-
it "should return nil" do
|
1785
|
-
expect(page.slug).to be_nil
|
1786
|
-
end
|
1787
|
-
end
|
1788
|
-
end
|
1789
|
-
|
1790
|
-
describe '#external_urlname' do
|
1791
|
-
let(:external_page) { build(:alchemy_page, page_layout: 'external') }
|
1792
|
-
|
1793
|
-
context 'with missing protocol' do
|
1794
|
-
before { external_page.urlname = 'google.com' }
|
1795
|
-
|
1796
|
-
it "returns an urlname prefixed with http://" do
|
1797
|
-
expect(external_page.external_urlname).to eq 'http://google.com'
|
1798
|
-
end
|
1799
|
-
end
|
1800
|
-
|
1801
|
-
context 'with protocol present' do
|
1802
|
-
before { external_page.urlname = 'ftp://google.com' }
|
1803
|
-
|
1804
|
-
it "returns the urlname" do
|
1805
|
-
expect(external_page.external_urlname).to eq 'ftp://google.com'
|
1806
|
-
end
|
1807
|
-
end
|
1808
|
-
|
1809
|
-
context 'beginngin with a slash' do
|
1810
|
-
before { external_page.urlname = '/internal-url' }
|
1811
|
-
|
1812
|
-
it "returns the urlname" do
|
1813
|
-
expect(external_page.external_urlname).to eq '/internal-url'
|
1814
|
-
end
|
1815
|
-
end
|
1816
|
-
end
|
1817
|
-
|
1818
|
-
context 'page status methods' do
|
1819
|
-
let(:page) { build(:alchemy_page, public: true, visible: true, restricted: false, locked: false) }
|
1820
|
-
|
1821
|
-
describe '#status' do
|
1822
|
-
it "returns a combined status hash" do
|
1823
|
-
expect(page.status).to eq({public: true, visible: true, restricted: false, locked: false})
|
1824
|
-
end
|
1825
|
-
end
|
1826
|
-
|
1827
|
-
describe '#status_title' do
|
1828
|
-
it "returns a translated status string for public status" do
|
1829
|
-
expect(page.status_title(:public)).to eq('Page is published.')
|
1830
|
-
end
|
1831
|
-
|
1832
|
-
it "returns a translated status string for visible status" do
|
1833
|
-
expect(page.status_title(:visible)).to eq('Page is visible in navigation.')
|
1834
|
-
end
|
1835
|
-
|
1836
|
-
it "returns a translated status string for locked status" do
|
1837
|
-
expect(page.status_title(:locked)).to eq('')
|
1838
|
-
end
|
1839
|
-
|
1840
|
-
it "returns a translated status string for restricted status" do
|
1841
|
-
expect(page.status_title(:restricted)).to eq('Page is not restricted.')
|
1842
|
-
end
|
1843
|
-
end
|
1844
|
-
end
|
1845
|
-
|
1846
|
-
context 'indicate page editors' do
|
1847
|
-
let(:page) { Page.new }
|
1848
|
-
let(:user) { create(:alchemy_dummy_user, :as_editor) }
|
1849
|
-
|
1850
|
-
describe '#creator' do
|
1851
|
-
before { page.update(creator_id: user.id) }
|
1852
|
-
|
1853
|
-
it "returns the user that created the page" do
|
1854
|
-
expect(page.creator).to eq(user)
|
1855
|
-
end
|
1856
|
-
|
1857
|
-
context 'with user class having a different primary key' do
|
1858
|
-
before do
|
1859
|
-
allow(Alchemy.user_class)
|
1860
|
-
.to receive(:primary_key)
|
1861
|
-
.and_return('user_id')
|
1862
|
-
|
1863
|
-
allow(page)
|
1864
|
-
.to receive(:creator_id)
|
1865
|
-
.and_return(1)
|
1866
|
-
end
|
1867
|
-
|
1868
|
-
it "returns the user that created the page" do
|
1869
|
-
expect(Alchemy.user_class)
|
1870
|
-
.to receive(:find_by)
|
1871
|
-
.with({'user_id' => 1})
|
1872
|
-
|
1873
|
-
page.creator
|
1874
|
-
end
|
1875
|
-
end
|
1876
|
-
end
|
1877
|
-
|
1878
|
-
describe '#updater' do
|
1879
|
-
before { page.update(updater_id: user.id) }
|
1880
|
-
|
1881
|
-
it "returns the user that updated the page" do
|
1882
|
-
expect(page.updater).to eq(user)
|
1883
|
-
end
|
1884
|
-
|
1885
|
-
context 'with user class having a different primary key' do
|
1886
|
-
before do
|
1887
|
-
allow(Alchemy.user_class)
|
1888
|
-
.to receive(:primary_key)
|
1889
|
-
.and_return('user_id')
|
1890
|
-
|
1891
|
-
allow(page)
|
1892
|
-
.to receive(:updater_id)
|
1893
|
-
.and_return(1)
|
1894
|
-
end
|
1895
|
-
|
1896
|
-
it "returns the user that updated the page" do
|
1897
|
-
expect(Alchemy.user_class)
|
1898
|
-
.to receive(:find_by)
|
1899
|
-
.with({'user_id' => 1})
|
1900
|
-
|
1901
|
-
page.updater
|
1902
|
-
end
|
1903
|
-
end
|
1904
|
-
end
|
1905
|
-
|
1906
|
-
describe '#locker' do
|
1907
|
-
before { page.update(locked_by: user.id) }
|
1908
|
-
|
1909
|
-
it "returns the user that locked the page" do
|
1910
|
-
expect(page.locker).to eq(user)
|
1911
|
-
end
|
1912
|
-
|
1913
|
-
context 'with user class having a different primary key' do
|
1914
|
-
before do
|
1915
|
-
allow(Alchemy.user_class)
|
1916
|
-
.to receive(:primary_key)
|
1917
|
-
.and_return('user_id')
|
1918
|
-
|
1919
|
-
allow(page)
|
1920
|
-
.to receive(:locked_by)
|
1921
|
-
.and_return(1)
|
1922
|
-
end
|
1923
|
-
|
1924
|
-
it "returns the user that locked the page" do
|
1925
|
-
expect(Alchemy.user_class)
|
1926
|
-
.to receive(:find_by)
|
1927
|
-
.with({'user_id' => 1})
|
1928
|
-
|
1929
|
-
page.locker
|
1930
|
-
end
|
1931
|
-
end
|
1932
|
-
end
|
1933
|
-
|
1934
|
-
context 'with user that can not be found' do
|
1935
|
-
it 'does not raise not found error' do
|
1936
|
-
%w(creator updater locker).each do |user_type|
|
1937
|
-
expect {
|
1938
|
-
page.send(user_type)
|
1939
|
-
}.to_not raise_error
|
1940
|
-
end
|
1941
|
-
end
|
1942
|
-
end
|
1943
|
-
|
1944
|
-
context 'with user class having a name accessor' do
|
1945
|
-
let(:user) { double(name: 'Paul Page') }
|
1946
|
-
|
1947
|
-
describe '#creator_name' do
|
1948
|
-
before { allow(page).to receive(:creator).and_return(user) }
|
1949
|
-
|
1950
|
-
it "returns the name of the creator" do
|
1951
|
-
expect(page.creator_name).to eq('Paul Page')
|
1952
|
-
end
|
1953
|
-
end
|
1954
|
-
|
1955
|
-
describe '#updater_name' do
|
1956
|
-
before { allow(page).to receive(:updater).and_return(user) }
|
1957
|
-
|
1958
|
-
it "returns the name of the updater" do
|
1959
|
-
expect(page.updater_name).to eq('Paul Page')
|
1960
|
-
end
|
1961
|
-
end
|
1962
|
-
|
1963
|
-
describe '#locker_name' do
|
1964
|
-
before { allow(page).to receive(:locker).and_return(user) }
|
1965
|
-
|
1966
|
-
it "returns the name of the current page editor" do
|
1967
|
-
expect(page.locker_name).to eq('Paul Page')
|
1968
|
-
end
|
1969
|
-
end
|
1970
|
-
end
|
1971
|
-
|
1972
|
-
context 'with user class not having a name accessor' do
|
1973
|
-
let(:user) { Alchemy.user_class.new }
|
1974
|
-
|
1975
|
-
describe '#creator_name' do
|
1976
|
-
before { allow(page).to receive(:creator).and_return(user) }
|
1977
|
-
|
1978
|
-
it "returns unknown" do
|
1979
|
-
expect(page.creator_name).to eq('unknown')
|
1980
|
-
end
|
1981
|
-
end
|
1982
|
-
|
1983
|
-
describe '#updater_name' do
|
1984
|
-
before { allow(page).to receive(:updater).and_return(user) }
|
1985
|
-
|
1986
|
-
it "returns unknown" do
|
1987
|
-
expect(page.updater_name).to eq('unknown')
|
1988
|
-
end
|
1989
|
-
end
|
1990
|
-
|
1991
|
-
describe '#locker_name' do
|
1992
|
-
before { allow(page).to receive(:locker).and_return(user) }
|
1993
|
-
|
1994
|
-
it "returns unknown" do
|
1995
|
-
expect(page.locker_name).to eq('unknown')
|
1996
|
-
end
|
1997
|
-
end
|
1998
|
-
end
|
1999
|
-
end
|
2000
|
-
|
2001
|
-
describe '#controller_and_action' do
|
2002
|
-
let(:page) { Page.new }
|
2003
|
-
|
2004
|
-
context 'if the page has a custom controller defined in its definition' do
|
2005
|
-
before do
|
2006
|
-
allow(page).to receive(:has_controller?).and_return(true)
|
2007
|
-
allow(page).to receive(:definition).and_return({'controller' => 'comments', 'action' => 'index'})
|
2008
|
-
end
|
2009
|
-
it "should return a Hash with controller and action key-value pairs" do
|
2010
|
-
expect(page.controller_and_action).to eq({controller: '/comments', action: 'index'})
|
2011
|
-
end
|
2012
|
-
end
|
2013
|
-
end
|
2014
|
-
|
2015
|
-
it_behaves_like "having a hint" do
|
2016
|
-
let(:subject) { Page.new }
|
2017
|
-
end
|
2018
|
-
|
2019
|
-
describe '#layout_partial_name' do
|
2020
|
-
let(:page) { Page.new(page_layout: 'Standard Page') }
|
2021
|
-
|
2022
|
-
it "returns a partial renderer compatible name" do
|
2023
|
-
expect(page.layout_partial_name).to eq('standard_page')
|
2024
|
-
end
|
2025
|
-
end
|
2026
|
-
|
2027
|
-
describe '#published_at' do
|
2028
|
-
context 'with published_at date set' do
|
2029
|
-
let(:published_at) { Time.current }
|
2030
|
-
let(:page) { build_stubbed(:alchemy_page, published_at: published_at) }
|
2031
|
-
|
2032
|
-
it "returns the published_at value from database" do
|
2033
|
-
expect(page.published_at).to eq(published_at)
|
2034
|
-
end
|
2035
|
-
end
|
2036
|
-
|
2037
|
-
context 'with published_at is nil' do
|
2038
|
-
let(:updated_at) { Time.current }
|
2039
|
-
let(:page) { build_stubbed(:alchemy_page, published_at: nil, updated_at: updated_at) }
|
2040
|
-
|
2041
|
-
it "returns the updated_at value" do
|
2042
|
-
expect(page.published_at).to eq(updated_at)
|
2043
|
-
end
|
2044
|
-
end
|
2045
|
-
end
|
2046
|
-
|
2047
|
-
describe "#richtext_contents_ids" do
|
2048
|
-
let!(:page) { create(:alchemy_page) }
|
2049
|
-
|
2050
|
-
let!(:expanded_element) do
|
2051
|
-
create :alchemy_element,
|
2052
|
-
name: 'article',
|
2053
|
-
page: page,
|
2054
|
-
folded: false,
|
2055
|
-
create_contents_after_create: true
|
2056
|
-
end
|
2057
|
-
|
2058
|
-
let!(:folded_element) do
|
2059
|
-
create :alchemy_element,
|
2060
|
-
name: 'article',
|
2061
|
-
page: page,
|
2062
|
-
folded: true,
|
2063
|
-
create_contents_after_create: true
|
2064
|
-
end
|
2065
|
-
|
2066
|
-
subject(:richtext_contents_ids) { page.richtext_contents_ids }
|
2067
|
-
|
2068
|
-
it 'returns content ids for all expanded elements that have tinymce enabled' do
|
2069
|
-
expanded_rtf_contents = expanded_element.contents.essence_richtexts
|
2070
|
-
expect(richtext_contents_ids).to eq(expanded_rtf_contents.pluck(:id))
|
2071
|
-
folded_rtf_content = folded_element.contents.essence_richtexts.first
|
2072
|
-
expect(richtext_contents_ids).to_not include(folded_rtf_content.id)
|
2073
|
-
end
|
2074
|
-
|
2075
|
-
context 'with nested elements' do
|
2076
|
-
let!(:nested_expanded_element) do
|
2077
|
-
create :alchemy_element,
|
2078
|
-
name: 'article',
|
2079
|
-
page: page,
|
2080
|
-
parent_element: expanded_element,
|
2081
|
-
folded: false,
|
2082
|
-
create_contents_after_create: true
|
2083
|
-
end
|
2084
|
-
|
2085
|
-
let!(:nested_folded_element) do
|
2086
|
-
create :alchemy_element,
|
2087
|
-
name: 'article',
|
2088
|
-
page: page,
|
2089
|
-
parent_element: folded_element,
|
2090
|
-
folded: true,
|
2091
|
-
create_contents_after_create: true
|
2092
|
-
end
|
2093
|
-
|
2094
|
-
it 'returns content ids for all expanded nested elements that have tinymce enabled' do
|
2095
|
-
expanded_rtf_contents = expanded_element.contents.essence_richtexts
|
2096
|
-
nested_expanded_rtf_contents = nested_expanded_element.contents.essence_richtexts
|
2097
|
-
rtf_content_ids = expanded_rtf_contents.pluck(:id) +
|
2098
|
-
nested_expanded_rtf_contents.pluck(:id)
|
2099
|
-
expect(richtext_contents_ids.sort).to eq(rtf_content_ids)
|
2100
|
-
|
2101
|
-
nested_folded_rtf_content = nested_folded_element.contents.essence_richtexts.first
|
2102
|
-
|
2103
|
-
expect(richtext_contents_ids).to_not include(nested_folded_rtf_content.id)
|
2104
|
-
end
|
2105
|
-
end
|
2106
|
-
end
|
2107
|
-
end
|
2108
|
-
end
|