comfortable_mexican_sofa 1.12.11 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +4 -0
- data/.gitattributes +2 -0
- data/.github/issue_template.md +22 -0
- data/.github/pull_request_template.md +6 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +974 -0
- data/.travis.yml +2 -10
- data/Gemfile +5 -7
- data/README.md +40 -39
- data/Rakefile +1 -31
- data/app/assets/javascripts/comfy/admin/cms/application.js.coffee +7 -4
- data/app/assets/javascripts/comfy/admin/cms/base.js.coffee +23 -33
- data/app/assets/javascripts/comfy/admin/cms/lib/diff/pretty_text_diff.js +76 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr.min.js +2 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/ar.js +52 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/bg.js +65 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/bn.js +65 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/cat.js +83 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/cs.js +70 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/cy.js +92 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/da.js +71 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/de.js +70 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/default.js +80 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/eo.js +73 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/es.js +69 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/et.js +73 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/fa.js +68 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/fi.js +69 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/fr.js +75 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/gr.js +74 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/he.js +57 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/hi.js +65 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/hr.js +66 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/hu.js +72 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/id.js +61 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/it.js +70 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/ja.js +57 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/ko.js +60 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/lt.js +72 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/lv.js +67 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/mk.js +69 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/mn.js +67 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/ms.js +68 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/my.js +69 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/nl.js +75 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/no.js +73 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/pa.js +65 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/pl.js +68 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/pt-BR.js +66 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/pt.js +66 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/ro.js +69 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/ru.js +66 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/si.js +65 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/sk.js +70 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/sl.js +70 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/sq.js +65 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/sr.js +69 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/sv.js +70 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/th.js +72 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/tr.js +66 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/uk.js +66 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/vn.js +66 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/zh-CN.js +61 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/flatpickr/i18n/zh-TW.js +61 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/redactor.js +9 -3
- data/app/assets/javascripts/comfy/admin/cms/uploader.js.coffee +9 -10
- data/app/assets/stylesheets/comfy/admin/cms/application.sass +4 -4
- data/app/assets/stylesheets/comfy/admin/cms/base.sass +215 -338
- data/app/assets/stylesheets/comfy/admin/cms/lib/flatpickr.min.css +13 -0
- data/app/assets/stylesheets/comfy/admin/cms/redactor_overrides.sass +2 -2
- data/app/controllers/comfy/admin/base_controller.rb +20 -0
- data/app/controllers/comfy/admin/cms/base_controller.rb +9 -22
- data/app/controllers/comfy/admin/cms/categories_controller.rb +2 -3
- data/app/controllers/comfy/admin/cms/files_controller.rb +50 -31
- data/app/controllers/comfy/admin/cms/layouts_controller.rb +12 -13
- data/app/controllers/comfy/admin/cms/pages_controller.rb +28 -28
- data/app/controllers/comfy/admin/cms/revisions_controller.rb +23 -14
- data/app/controllers/comfy/admin/cms/sites_controller.rb +9 -10
- data/app/controllers/comfy/admin/cms/snippets_controller.rb +11 -11
- data/app/controllers/comfy/admin/cms/translations_controller.rb +98 -0
- data/app/controllers/comfy/cms/assets_controller.rb +9 -10
- data/app/controllers/comfy/cms/base_controller.rb +0 -2
- data/app/controllers/comfy/cms/content_controller.rb +50 -31
- data/app/controllers/concerns/comfy/paginate.rb +2 -2
- data/app/helpers/comfy/admin/cms_helper.rb +29 -0
- data/app/helpers/comfy/cms_helper.rb +40 -60
- data/app/models/comfy/cms/categorization.rb +8 -11
- data/app/models/comfy/cms/category.rb +10 -14
- data/app/models/comfy/cms/file.rb +31 -47
- data/app/models/comfy/cms/fragment.rb +55 -0
- data/app/models/comfy/cms/layout.rb +45 -40
- data/app/models/comfy/cms/page.rb +47 -36
- data/app/models/comfy/cms/revision.rb +5 -8
- data/app/models/comfy/cms/site.rb +26 -51
- data/app/models/comfy/cms/snippet.rb +20 -24
- data/app/models/comfy/cms/translation.rb +37 -0
- data/app/models/concerns/comfy/cms/with_categories.rb +38 -0
- data/app/models/concerns/comfy/cms/with_fragments.rb +121 -0
- data/app/views/comfy/admin/cms/categories/_categories.html.haml +2 -1
- data/app/views/comfy/admin/cms/categories/_edit.html.haml +7 -6
- data/app/views/comfy/admin/cms/categories/_form.html.haml +8 -5
- data/app/views/comfy/admin/cms/categories/_index.html.haml +24 -20
- data/app/views/comfy/admin/cms/categories/_show.html.haml +10 -9
- data/app/views/comfy/admin/cms/categories/create.js.erb +2 -2
- data/app/views/comfy/admin/cms/categories/edit.js.erb +1 -1
- data/app/views/comfy/admin/cms/categories/update.js.erb +2 -2
- data/app/views/comfy/admin/cms/files/_file.html.haml +31 -25
- data/app/views/comfy/admin/cms/files/_form.html.haml +16 -12
- data/app/views/comfy/admin/cms/files/edit.html.haml +1 -1
- data/app/views/comfy/admin/cms/files/index.html.haml +17 -19
- data/app/views/comfy/admin/cms/files/new.html.haml +1 -1
- data/app/views/comfy/admin/cms/layouts/_form.html.haml +10 -10
- data/app/views/comfy/admin/cms/layouts/_index_branch.html.haml +21 -19
- data/app/views/comfy/admin/cms/layouts/edit.html.haml +5 -5
- data/app/views/comfy/admin/cms/layouts/index.html.haml +4 -7
- data/app/views/comfy/admin/cms/pages/_form.html.haml +15 -21
- data/app/views/comfy/admin/cms/pages/_form_fragments.html.haml +40 -0
- data/app/views/comfy/admin/cms/pages/_fragment_attachments.html.haml +10 -0
- data/app/views/comfy/admin/cms/pages/_index_branch.html.haml +34 -26
- data/app/views/comfy/admin/cms/pages/edit.html.haml +19 -5
- data/app/views/comfy/admin/cms/pages/form_fragments.js.erb +1 -0
- data/app/views/comfy/admin/cms/pages/index.html.haml +5 -8
- data/app/views/comfy/admin/cms/pages/new.html.haml +1 -1
- data/app/views/comfy/admin/cms/revisions/show.html.haml +29 -27
- data/app/views/comfy/admin/cms/sites/_form.html.haml +6 -8
- data/app/views/comfy/admin/cms/sites/edit.html.haml +1 -1
- data/app/views/comfy/admin/cms/sites/index.html.haml +23 -22
- data/app/views/comfy/admin/cms/sites/new.html.haml +1 -1
- data/app/views/comfy/admin/cms/snippets/_form.html.haml +9 -9
- data/app/views/comfy/admin/cms/snippets/edit.html.haml +6 -5
- data/app/views/comfy/admin/cms/snippets/index.html.haml +25 -25
- data/app/views/comfy/admin/cms/snippets/new.html.haml +1 -1
- data/app/views/comfy/admin/cms/translations/_form.html.haml +21 -0
- data/app/views/comfy/admin/cms/translations/edit.html.haml +9 -0
- data/app/views/comfy/admin/cms/translations/form_fragments.js.erb +1 -0
- data/app/views/comfy/admin/cms/translations/new.html.haml +5 -0
- data/app/views/kaminari/comfy/_first_page.html.haml +3 -2
- data/app/views/kaminari/comfy/_gap.html.haml +2 -2
- data/app/views/kaminari/comfy/_last_page.html.haml +3 -2
- data/app/views/kaminari/comfy/_next_page.html.haml +2 -2
- data/app/views/kaminari/comfy/_page.html.haml +2 -2
- data/app/views/kaminari/comfy/_prev_page.html.haml +1 -1
- data/app/views/layouts/comfy/admin/cms/_body.html.haml +13 -15
- data/app/views/layouts/comfy/admin/cms/_footer_js.html.haml +10 -3
- data/app/views/layouts/comfy/admin/cms/_head.html.haml +7 -10
- data/app/views/layouts/comfy/admin/cms/_left.html.haml +33 -15
- data/app/views/layouts/comfy/admin/cms/_right.html.haml +2 -2
- data/comfortable_mexican_sofa.gemspec +19 -19
- data/config/application.rb +14 -8
- data/config/boot.rb +2 -2
- data/config/cms_routes.rb +3 -3
- data/config/environments/development.rb +37 -4
- data/config/environments/test.rb +12 -14
- data/config/initializers/comfortable_mexican_sofa.rb +5 -12
- data/config/locales/cs.yml +33 -7
- data/config/locales/da.yml +33 -7
- data/config/locales/de.yml +32 -6
- data/config/locales/en.yml +33 -7
- data/config/locales/es.yml +33 -7
- data/config/locales/fr.yml +33 -7
- data/config/locales/it.yml +33 -7
- data/config/locales/ja.yml +33 -7
- data/config/locales/nb.yml +33 -7
- data/config/locales/nl.yml +33 -7
- data/config/locales/pl.yml +33 -7
- data/config/locales/pt-BR.yml +33 -7
- data/config/locales/ru.yml +33 -7
- data/config/locales/sk.yml +33 -7
- data/config/locales/sv.yml +33 -7
- data/config/locales/tr.yml +33 -7
- data/config/locales/uk.yml +33 -7
- data/config/locales/zh-CN.yml +33 -7
- data/config/locales/zh-TW.yml +33 -7
- data/config/storage.yml +35 -0
- data/db/cms_seeds/sample-site/files/_default.jpg.yml +5 -0
- data/db/{cms_fixtures/sample-site/files/sample.jpg → cms_seeds/sample-site/files/default.jpg} +0 -0
- data/db/cms_seeds/sample-site/layouts/default/content.html +16 -0
- data/db/cms_seeds/sample-site/layouts/default/nested/content.html +14 -0
- data/db/cms_seeds/sample-site/pages/index/child_a/content.html +7 -0
- data/db/cms_seeds/sample-site/pages/index/child_b/content.html +6 -0
- data/db/cms_seeds/sample-site/pages/index/content.es.html +6 -0
- data/db/cms_seeds/sample-site/pages/index/content.fr.html +6 -0
- data/db/cms_seeds/sample-site/pages/index/content.html +24 -0
- data/db/{cms_fixtures/sample-site/pages/index/child/thumbnail.png → cms_seeds/sample-site/pages/index/footer.png} +0 -0
- data/db/cms_seeds/sample-site/pages/index/header.png +0 -0
- data/db/cms_seeds/sample-site/snippets/default.html +8 -0
- data/db/migrate/00_create_active_storage_tables.active_storage.rb +26 -0
- data/db/migrate/01_create_cms.rb +113 -104
- data/doc/preview.jpg +0 -0
- data/lib/comfortable_mexican_sofa.rb +10 -14
- data/lib/comfortable_mexican_sofa/configuration.rb +9 -13
- data/lib/comfortable_mexican_sofa/content.rb +28 -0
- data/lib/comfortable_mexican_sofa/content/block.rb +11 -0
- data/lib/comfortable_mexican_sofa/content/params_parser.rb +80 -0
- data/lib/comfortable_mexican_sofa/content/renderer.rb +125 -0
- data/lib/comfortable_mexican_sofa/content/tag.rb +37 -0
- data/lib/comfortable_mexican_sofa/content/tags/asset.rb +56 -0
- data/lib/comfortable_mexican_sofa/content/tags/checkbox.rb +21 -0
- data/lib/comfortable_mexican_sofa/content/tags/date.rb +22 -0
- data/lib/comfortable_mexican_sofa/content/tags/datetime.rb +22 -0
- data/lib/comfortable_mexican_sofa/content/tags/file.rb +77 -0
- data/lib/comfortable_mexican_sofa/content/tags/file_link.rb +66 -0
- data/lib/comfortable_mexican_sofa/content/tags/files.rb +39 -0
- data/lib/comfortable_mexican_sofa/content/tags/fragment.rb +54 -0
- data/lib/comfortable_mexican_sofa/content/tags/helper.rb +52 -0
- data/lib/comfortable_mexican_sofa/content/tags/markdown.rb +21 -0
- data/lib/comfortable_mexican_sofa/content/tags/number.rb +17 -0
- data/lib/comfortable_mexican_sofa/content/tags/partial.rb +42 -0
- data/lib/comfortable_mexican_sofa/content/tags/snippet.rb +31 -0
- data/lib/comfortable_mexican_sofa/content/tags/template.rb +41 -0
- data/lib/comfortable_mexican_sofa/content/tags/text.rb +17 -0
- data/lib/comfortable_mexican_sofa/content/tags/textarea.rb +17 -0
- data/lib/comfortable_mexican_sofa/content/tags/wysiwyg.rb +18 -0
- data/lib/comfortable_mexican_sofa/engine.rb +3 -2
- data/lib/comfortable_mexican_sofa/extensions/acts_as_tree.rb +33 -30
- data/lib/comfortable_mexican_sofa/extensions/has_revisions.rb +27 -23
- data/lib/comfortable_mexican_sofa/form_builder.rb +32 -104
- data/lib/comfortable_mexican_sofa/render_methods.rb +24 -21
- data/lib/comfortable_mexican_sofa/routes/cms.rb +6 -14
- data/lib/comfortable_mexican_sofa/routes/cms_admin.rb +39 -29
- data/lib/comfortable_mexican_sofa/routing.rb +1 -1
- data/lib/comfortable_mexican_sofa/seeds.rb +102 -0
- data/lib/comfortable_mexican_sofa/seeds/file/exporter.rb +40 -0
- data/lib/comfortable_mexican_sofa/seeds/file/importer.rb +61 -0
- data/lib/comfortable_mexican_sofa/seeds/layout/exporter.rb +37 -0
- data/lib/comfortable_mexican_sofa/seeds/layout/importer.rb +59 -0
- data/lib/comfortable_mexican_sofa/seeds/page/exporter.rb +88 -0
- data/lib/comfortable_mexican_sofa/seeds/page/importer.rb +213 -0
- data/lib/comfortable_mexican_sofa/seeds/snippet/exporter.rb +31 -0
- data/lib/comfortable_mexican_sofa/seeds/snippet/importer.rb +48 -0
- data/lib/comfortable_mexican_sofa/version.rb +1 -1
- data/lib/comfortable_mexican_sofa/view_hooks.rb +0 -1
- data/lib/generators/comfy/cms/assets_generator.rb +0 -1
- data/lib/generators/comfy/cms/cms_generator.rb +15 -5
- data/lib/generators/comfy/scaffold/scaffold_generator.rb +26 -20
- data/lib/generators/comfy/scaffold/templates/{controller.rb → controller.rb.tt} +10 -10
- data/lib/generators/comfy/scaffold/templates/{migration.rb → migration.rb.tt} +2 -3
- data/lib/generators/comfy/scaffold/templates/{model.rb → model.rb.tt} +7 -7
- data/lib/generators/comfy/scaffold/templates/tests/{controller.rb → controller.rb.tt} +37 -24
- data/lib/generators/comfy/scaffold/templates/tests/{fixture.yml → fixture.yml.tt} +0 -0
- data/lib/generators/comfy/scaffold/templates/tests/{model.rb → model.rb.tt} +3 -4
- data/lib/generators/comfy/scaffold/templates/views/_form.haml.tt +7 -0
- data/lib/generators/comfy/scaffold/templates/views/{edit.haml → edit.haml.tt} +1 -1
- data/lib/generators/comfy/scaffold/templates/views/index.haml.tt +21 -0
- data/lib/generators/comfy/scaffold/templates/views/{new.haml → new.haml.tt} +1 -1
- data/lib/generators/comfy/scaffold/templates/views/{show.haml → show.haml.tt} +2 -2
- data/lib/tasks/cms_seeds.rake +37 -0
- data/test/controllers/comfy/admin/cms/base_controller_test.rb +5 -6
- data/test/controllers/comfy/admin/cms/categories_controller_test.rb +27 -24
- data/test/controllers/comfy/admin/cms/files_controller_test.rb +97 -97
- data/test/controllers/comfy/admin/cms/layouts_controller_test.rb +32 -31
- data/test/controllers/comfy/admin/cms/pages_controller_test.rb +317 -263
- data/test/controllers/comfy/admin/cms/revisions_controller_test.rb +175 -65
- data/test/controllers/comfy/admin/cms/sites_controller_test.rb +27 -29
- data/test/controllers/comfy/admin/cms/snippets_controller_test.rb +54 -51
- data/test/controllers/comfy/admin/cms/translations_controller_test.rb +181 -0
- data/test/controllers/comfy/cms/assets_controller_test.rb +24 -22
- data/test/controllers/comfy/cms/content_controller_test.rb +126 -140
- data/test/fixtures/active_storage/attachments.yml +9 -0
- data/test/fixtures/active_storage/blobs.yml +13 -0
- data/test/fixtures/comfy/cms/files.yml +2 -6
- data/test/fixtures/comfy/cms/fragments.yml +25 -0
- data/test/fixtures/comfy/cms/layouts.yml +7 -13
- data/test/fixtures/comfy/cms/pages.yml +2 -17
- data/test/fixtures/comfy/cms/revisions.yml +16 -8
- data/test/fixtures/comfy/cms/sites.yml +0 -1
- data/test/fixtures/comfy/cms/snippets.yml +1 -1
- data/test/fixtures/comfy/cms/translations.yml +7 -0
- data/test/fixtures/generators/cms/application.rb +7 -0
- data/test/fixtures/generators/cms/routes.rb +4 -7
- data/test/fixtures/generators/scaffold/controller.rb +10 -10
- data/test/fixtures/generators/scaffold/migration.rb +2 -3
- data/test/fixtures/generators/scaffold/model.rb +7 -7
- data/test/fixtures/generators/scaffold/routes.rb +1 -2
- data/test/fixtures/generators/scaffold/tests/controller.rb +37 -24
- data/test/fixtures/generators/scaffold/tests/model.rb +3 -4
- data/test/fixtures/generators/scaffold/views/_form.haml +3 -2
- data/test/fixtures/generators/scaffold/views/edit.haml +1 -1
- data/test/fixtures/generators/scaffold/views/index.haml +15 -13
- data/test/fixtures/generators/scaffold/views/new.haml +1 -1
- data/test/fixtures/generators/scaffold/views/show.haml +2 -2
- data/test/gemfiles/Gemfile.rails.5.2 +32 -0
- data/test/generators/cms_assets_generator_test.rb +1 -2
- data/test/generators/cms_generator_test.rb +3 -1
- data/test/generators/cms_views_generator_test.rb +1 -1
- data/test/generators/scaffold_generator_test.rb +2 -2
- data/test/helpers/cms_helper_test.rb +52 -73
- data/test/integration/access_control_test.rb +35 -28
- data/test/integration/js_variables_test.rb +1 -2
- data/test/integration/render_cms_test.rb +37 -37
- data/test/integration/routing_test.rb +4 -5
- data/test/integration/seeds_test.rb +76 -0
- data/test/integration/sites_test.rb +35 -49
- data/test/integration/view_hooks_test.rb +12 -13
- data/test/lib/configuration_test.rb +3 -4
- data/test/lib/content/block_test.rb +26 -0
- data/test/lib/content/params_parser_test.rb +125 -0
- data/test/lib/content/renderer_test.rb +240 -0
- data/test/lib/content/tag_test.rb +48 -0
- data/test/lib/content/tags/asset_test.rb +79 -0
- data/test/lib/content/tags/checkbox_test.rb +20 -0
- data/test/lib/content/tags/date_test.rb +20 -0
- data/test/lib/content/tags/datetime_test.rb +20 -0
- data/test/lib/content/tags/file_link_test.rb +78 -0
- data/test/lib/content/tags/file_test.rb +60 -0
- data/test/lib/content/tags/files_test.rb +49 -0
- data/test/lib/content/tags/fragment_test.rb +63 -0
- data/test/lib/content/tags/helper_test.rb +52 -0
- data/test/lib/content/tags/markdown_test.rb +33 -0
- data/test/lib/content/tags/number_test.rb +13 -0
- data/test/lib/content/tags/partial_test.rb +43 -0
- data/test/lib/content/tags/snippet_test.rb +36 -0
- data/test/lib/content/tags/template_test.rb +35 -0
- data/test/lib/content/tags/text_test.rb +13 -0
- data/test/lib/content/tags/textarea_test.rb +13 -0
- data/test/lib/content/tags/wysiwyg_test.rb +13 -0
- data/test/lib/revisions_test.rb +146 -111
- data/test/lib/seeds/files_test.rb +96 -0
- data/test/lib/seeds/layouts_test.rb +155 -0
- data/test/lib/seeds/pages_test.rb +227 -0
- data/test/lib/seeds/snippets_test.rb +98 -0
- data/test/lib/seeds_test.rb +50 -0
- data/test/models/categorization_test.rb +37 -38
- data/test/models/category_test.rb +14 -14
- data/test/models/file_test.rb +23 -96
- data/test/models/fragment_test.rb +131 -0
- data/test/models/layout_test.rb +105 -74
- data/test/models/page_test.rb +352 -97
- data/test/models/site_test.rb +101 -90
- data/test/models/snippet_test.rb +29 -23
- data/test/models/translation_test.rb +60 -0
- data/test/tasks/cms_seeds_test.rb +33 -0
- data/test/test_helper.rb +49 -32
- metadata +235 -210
- data/_config.yml +0 -1
- data/app/assets/images/comfy/admin/cms/arrow_bottom.gif +0 -0
- data/app/assets/images/comfy/admin/cms/arrow_right.gif +0 -0
- data/app/assets/images/comfy/admin/cms/checkerboard.gif +0 -0
- data/app/assets/images/comfy/admin/cms/icon_draft.gif +0 -0
- data/app/assets/images/comfy/admin/cms/icon_file.gif +0 -0
- data/app/assets/images/comfy/admin/cms/icon_layout.gif +0 -0
- data/app/assets/images/comfy/admin/cms/icon_move.gif +0 -0
- data/app/assets/images/comfy/admin/cms/icon_page.gif +0 -0
- data/app/assets/images/comfy/admin/cms/icon_site.gif +0 -0
- data/app/assets/images/comfy/admin/cms/icon_snippet.gif +0 -0
- data/app/assets/javascripts/comfy/admin/cms/lib/bootstrap-datetimepicker.js +0 -29
- data/app/assets/javascripts/comfy/admin/cms/lib/diff.js.coffee +0 -9
- data/app/assets/javascripts/comfy/admin/cms/lib/diff/pretty_text_diff.min.js +0 -5
- data/app/assets/stylesheets/comfy/admin/cms/bootstrap_overrides.sass +0 -32
- data/app/assets/stylesheets/comfy/admin/cms/lib/bootstrap-datetimepicker.css +0 -9
- data/app/models/comfy/cms/block.rb +0 -63
- data/app/views/comfy/admin/cms/files/_page_form.html.haml +0 -10
- data/app/views/comfy/admin/cms/pages/_form_blocks.html.haml +0 -32
- data/app/views/comfy/admin/cms/pages/form_blocks.js.erb +0 -1
- data/app/views/comfy/admin/cms/partials/_body_before.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_file_form_after.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_file_form_before.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_files_after.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_files_before.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_html_footer.html.haml +0 -2
- data/app/views/comfy/admin/cms/partials/_html_head.html.haml +0 -2
- data/app/views/comfy/admin/cms/partials/_layout_form_after.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_layout_form_before.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_layouts_after.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_layouts_before.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_navigation_after.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_navigation_before.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_navigation_inner.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_page_form_after.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_page_form_before.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_page_form_inner.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_pages_after.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_pages_before.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_right_column_after.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_right_column_before.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_site_form_after.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_site_form_before.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_sites_after.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_sites_before.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_snippet_form_after.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_snippet_form_before.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_snippets_after.html.haml +0 -3
- data/app/views/comfy/admin/cms/partials/_snippets_before.html.haml +0 -3
- data/app/views/comfy/admin/cms/sites/_mirrors.html.haml +0 -18
- data/app/views/comfy/cms/content/render_sitemap.xml.builder +0 -14
- data/app/views/layouts/comfy/admin/cms/_footer.html.haml +0 -3
- data/config/initializers/paperclip.rb +0 -3
- data/config/initializers/secret_token.rb +0 -15
- data/db/cms_fixtures/sample-site/categories/files.yml +0 -1
- data/db/cms_fixtures/sample-site/categories/pages.yml +0 -1
- data/db/cms_fixtures/sample-site/categories/snippets.yml +0 -1
- data/db/cms_fixtures/sample-site/files/_sample.jpg.yml +0 -5
- data/db/cms_fixtures/sample-site/layouts/default/attributes.yml +0 -1
- data/db/cms_fixtures/sample-site/layouts/default/content.html +0 -5
- data/db/cms_fixtures/sample-site/layouts/default/javascript.js +0 -1
- data/db/cms_fixtures/sample-site/layouts/default/nested/attributes.yml +0 -2
- data/db/cms_fixtures/sample-site/layouts/default/nested/content.haml +0 -3
- data/db/cms_fixtures/sample-site/layouts/default/nested/javascript.js +0 -1
- data/db/cms_fixtures/sample-site/layouts/default/nested/stylesheet.css +0 -1
- data/db/cms_fixtures/sample-site/layouts/default/stylesheet.css +0 -1
- data/db/cms_fixtures/sample-site/pages/index/attributes.yml +0 -6
- data/db/cms_fixtures/sample-site/pages/index/child/attributes.yml +0 -3
- data/db/cms_fixtures/sample-site/pages/index/child/left.haml +0 -1
- data/db/cms_fixtures/sample-site/pages/index/child/right.html +0 -1
- data/db/cms_fixtures/sample-site/pages/index/content.html +0 -2
- data/db/cms_fixtures/sample-site/snippets/default/attributes.yml +0 -4
- data/db/cms_fixtures/sample-site/snippets/default/content.html +0 -1
- data/db/seeds.rb +0 -7
- data/db/upgrade_migrations/02_upgrade_to_1_1_0.rb +0 -19
- data/db/upgrade_migrations/03_upgrade_to_1_2_0.rb +0 -15
- data/db/upgrade_migrations/04_upgrade_to_1_3_0.rb +0 -23
- data/db/upgrade_migrations/05_upgrade_to_1_4_0.rb +0 -33
- data/db/upgrade_migrations/06_upgrade_to_1_5_0.rb +0 -21
- data/db/upgrade_migrations/07_upgrade_to_1_6_0.rb +0 -25
- data/db/upgrade_migrations/08_upgrade_to_1_12_0.rb +0 -83
- data/doc/preview.png +0 -0
- data/lib/comfortable_mexican_sofa/extensions/cms_manageable.rb +0 -106
- data/lib/comfortable_mexican_sofa/extensions/is_categorized.rb +0 -49
- data/lib/comfortable_mexican_sofa/extensions/is_mirrored.rb +0 -86
- data/lib/comfortable_mexican_sofa/extensions/rails.rb +0 -17
- data/lib/comfortable_mexican_sofa/fixture.rb +0 -82
- data/lib/comfortable_mexican_sofa/fixture/category.rb +0 -42
- data/lib/comfortable_mexican_sofa/fixture/file.rb +0 -85
- data/lib/comfortable_mexican_sofa/fixture/layout.rb +0 -95
- data/lib/comfortable_mexican_sofa/fixture/page.rb +0 -129
- data/lib/comfortable_mexican_sofa/fixture/snippet.rb +0 -75
- data/lib/comfortable_mexican_sofa/tag.rb +0 -154
- data/lib/comfortable_mexican_sofa/tags/asset.rb +0 -30
- data/lib/comfortable_mexican_sofa/tags/collection.rb +0 -64
- data/lib/comfortable_mexican_sofa/tags/field_boolean.rb +0 -17
- data/lib/comfortable_mexican_sofa/tags/field_datetime.rb +0 -17
- data/lib/comfortable_mexican_sofa/tags/field_integer.rb +0 -17
- data/lib/comfortable_mexican_sofa/tags/field_rich_text.rb +0 -17
- data/lib/comfortable_mexican_sofa/tags/field_string.rb +0 -17
- data/lib/comfortable_mexican_sofa/tags/field_text.rb +0 -17
- data/lib/comfortable_mexican_sofa/tags/file.rb +0 -29
- data/lib/comfortable_mexican_sofa/tags/helper.rb +0 -24
- data/lib/comfortable_mexican_sofa/tags/page_datetime.rb +0 -13
- data/lib/comfortable_mexican_sofa/tags/page_file.rb +0 -62
- data/lib/comfortable_mexican_sofa/tags/page_files.rb +0 -51
- data/lib/comfortable_mexican_sofa/tags/page_integer.rb +0 -13
- data/lib/comfortable_mexican_sofa/tags/page_markdown.rb +0 -16
- data/lib/comfortable_mexican_sofa/tags/page_rich_text.rb +0 -13
- data/lib/comfortable_mexican_sofa/tags/page_string.rb +0 -13
- data/lib/comfortable_mexican_sofa/tags/page_text.rb +0 -13
- data/lib/comfortable_mexican_sofa/tags/partial.rb +0 -23
- data/lib/comfortable_mexican_sofa/tags/snippet.rb +0 -19
- data/lib/comfortable_mexican_sofa/tags/template.rb +0 -22
- data/lib/generators/comfy/scaffold/templates/views/_form.haml +0 -6
- data/lib/generators/comfy/scaffold/templates/views/index.haml +0 -23
- data/lib/tasks/comfortable_mexican_sofa.rake +0 -37
- data/test/fixtures/comfy/cms/blocks.yml +0 -12
- data/test/gemfiles/Gemfile.rails.4.1 +0 -22
- data/test/gemfiles/Gemfile.rails.4.2 +0 -22
- data/test/gemfiles/Gemfile.rails.5.0 +0 -23
- data/test/gemfiles/Gemfile.rails.master +0 -23
- data/test/integration/fixtures_test.rb +0 -65
- data/test/integration/mirrors_test.rb +0 -72
- data/test/lib/fixtures/categories_test.rb +0 -36
- data/test/lib/fixtures/files_test.rb +0 -109
- data/test/lib/fixtures/layouts_test.rb +0 -135
- data/test/lib/fixtures/pages_test.rb +0 -168
- data/test/lib/fixtures/snippets_test.rb +0 -106
- data/test/lib/fixtures_test.rb +0 -43
- data/test/lib/mirrors_test.rb +0 -254
- data/test/lib/tag_test.rb +0 -309
- data/test/lib/tags/asset_test.rb +0 -95
- data/test/lib/tags/collection_test.rb +0 -117
- data/test/lib/tags/field_boolean_test.rb +0 -49
- data/test/lib/tags/field_datetime_test.rb +0 -50
- data/test/lib/tags/field_integer_test.rb +0 -49
- data/test/lib/tags/field_rich_text_test.rb +0 -49
- data/test/lib/tags/field_string_test.rb +0 -52
- data/test/lib/tags/field_text_test.rb +0 -48
- data/test/lib/tags/file_test.rb +0 -67
- data/test/lib/tags/helper_test.rb +0 -86
- data/test/lib/tags/page_datetime_test.rb +0 -50
- data/test/lib/tags/page_file_test.rb +0 -119
- data/test/lib/tags/page_files_test.rb +0 -117
- data/test/lib/tags/page_integer_test.rb +0 -49
- data/test/lib/tags/page_markdown_test.rb +0 -48
- data/test/lib/tags/page_rich_text_test.rb +0 -49
- data/test/lib/tags/page_string_test.rb +0 -49
- data/test/lib/tags/page_text_test.rb +0 -52
- data/test/lib/tags/partial_test.rb +0 -76
- data/test/lib/tags/snippet_test.rb +0 -45
- data/test/lib/tags/template_test.rb +0 -56
- data/test/models/block_test.rb +0 -233
@@ -0,0 +1,131 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class CmsFragmentTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@site = comfy_cms_sites(:default)
|
7
|
+
@layout = comfy_cms_layouts(:default)
|
8
|
+
@page = comfy_cms_pages(:default)
|
9
|
+
|
10
|
+
@upload_doc = fixture_file_upload("files/document.pdf", "application/pdf")
|
11
|
+
@upload_img = fixture_file_upload("files/image.jpg", "image/jpeg")
|
12
|
+
end
|
13
|
+
|
14
|
+
def page_params(frag_params = [])
|
15
|
+
{
|
16
|
+
layout: @layout,
|
17
|
+
label: 'test page',
|
18
|
+
slug: 'test_page',
|
19
|
+
parent_id: @page.id,
|
20
|
+
fragments_attributes: frag_params
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
# -- Tests -------------------------------------------------------------------
|
25
|
+
|
26
|
+
def test_initialization
|
27
|
+
frag = Comfy::Cms::Fragment.new
|
28
|
+
assert_equal "text", frag.tag
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_fixtures_validity
|
32
|
+
Comfy::Cms::Fragment.all.each do |frag|
|
33
|
+
assert frag.valid?, frag.errors.full_messages.to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_validation
|
38
|
+
frag = Comfy::Cms::Fragment.new
|
39
|
+
refute frag.valid?
|
40
|
+
assert_has_errors_on frag, :identifier, :record
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_content_serialization
|
44
|
+
fragment = Comfy::Cms::Fragment.new
|
45
|
+
|
46
|
+
fragment.content = 'test'
|
47
|
+
assert_equal 'test', fragment.content
|
48
|
+
|
49
|
+
fragment.content = 12345
|
50
|
+
assert_equal 12345, fragment.content
|
51
|
+
|
52
|
+
fragment.content = [1, 2, 3]
|
53
|
+
assert_equal [1, 2, 3], fragment.content
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_creation
|
57
|
+
assert_difference "Comfy::Cms::Fragment.count" do
|
58
|
+
@page.fragments.create!(
|
59
|
+
identifier: "test",
|
60
|
+
content: "test content"
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_creation_with_files
|
66
|
+
assert_count_difference [Comfy::Cms::Fragment] do
|
67
|
+
assert_count_difference [ActiveStorage::Attachment], 2 do
|
68
|
+
frag = @page.fragments.create!(
|
69
|
+
identifier: "test",
|
70
|
+
tag: "files",
|
71
|
+
files: [@upload_doc, @upload_img]
|
72
|
+
)
|
73
|
+
assert_equal 2, frag.attachments.count
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_creation_with_file
|
79
|
+
assert_count_difference [Comfy::Cms::Fragment, ActiveStorage::Attachment] do
|
80
|
+
frag = @page.fragments.create!(
|
81
|
+
identifier: "test",
|
82
|
+
tag: "file",
|
83
|
+
files: [@upload_doc, @upload_img]
|
84
|
+
)
|
85
|
+
assert_equal 1, frag.attachments.count
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_update_with_files
|
90
|
+
frag = comfy_cms_fragments(:file)
|
91
|
+
assert_equal 1, frag.attachments.count
|
92
|
+
assert_equal "fragment.jpg", frag.attachments.first.filename.to_s
|
93
|
+
assert_difference -> {frag.attachments.count} do
|
94
|
+
frag.update_attributes(
|
95
|
+
tag: "files",
|
96
|
+
files: [@upload_doc]
|
97
|
+
)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_update_with_file
|
102
|
+
frag = comfy_cms_fragments(:file)
|
103
|
+
assert_equal 1, frag.attachments.count
|
104
|
+
assert_equal "fragment.jpg", frag.attachments.first.filename.to_s
|
105
|
+
assert_no_difference -> {frag.attachments.count} do
|
106
|
+
frag.update_attributes(
|
107
|
+
tag: "file",
|
108
|
+
files: [@upload_doc]
|
109
|
+
)
|
110
|
+
end
|
111
|
+
frag.reload
|
112
|
+
assert_equal "document.pdf", frag.attachments.first.filename.to_s
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_update_with_file_removal
|
116
|
+
frag = comfy_cms_fragments(:file)
|
117
|
+
assert_difference -> {frag.attachments.count}, -1 do
|
118
|
+
frag.update_attributes(
|
119
|
+
file_ids_destroy: frag.attachments.pluck(:id)
|
120
|
+
)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_touch
|
125
|
+
timestamp = 2.days.ago
|
126
|
+
@page.update_column(:updated_at, timestamp)
|
127
|
+
comfy_cms_fragments(:default).update_attributes(content: "updated")
|
128
|
+
@page.reload
|
129
|
+
refute_equal timestamp, @page.updated_at
|
130
|
+
end
|
131
|
+
end
|
data/test/models/layout_test.rb
CHANGED
@@ -1,62 +1,112 @@
|
|
1
1
|
require_relative '../test_helper'
|
2
2
|
|
3
3
|
class CmsLayoutTest < ActiveSupport::TestCase
|
4
|
-
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@site = comfy_cms_sites(:default)
|
7
|
+
@layout = comfy_cms_layouts(:default)
|
8
|
+
@page = comfy_cms_pages(:default)
|
9
|
+
end
|
10
|
+
|
5
11
|
def test_fixtures_validity
|
6
12
|
Comfy::Cms::Layout.all.each do |layout|
|
7
13
|
assert layout.valid?, layout.errors.full_messages.to_s
|
8
14
|
end
|
9
15
|
end
|
10
|
-
|
16
|
+
|
11
17
|
def test_validations
|
12
|
-
layout =
|
18
|
+
layout = @site.layouts.create
|
13
19
|
assert layout.errors.present?
|
14
20
|
assert_has_errors_on layout, [:label, :identifier]
|
15
21
|
end
|
16
|
-
|
22
|
+
|
23
|
+
def test_content_tokens
|
24
|
+
layout = Comfy::Cms::Layout.new(content: "a {{cms:text content}} b")
|
25
|
+
assert_equal ["a ", {tag_class: "text", tag_params: "content"}, " b"],
|
26
|
+
layout.content_tokens
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_content_tokens_nested
|
30
|
+
layout_a = Comfy::Cms::Layout.new(content: "a {{cms:text content}} {{cms:text footer}} b")
|
31
|
+
layout_b = Comfy::Cms::Layout.new(content: "c {{cms:text content}} d")
|
32
|
+
layout_b.parent = layout_a
|
33
|
+
assert_equal [
|
34
|
+
"a ", "c ", {tag_class: "text", tag_params: "content"}, " d", " ",
|
35
|
+
{tag_class: "text", tag_params: "footer"}, " b"
|
36
|
+
], layout_b.content_tokens
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_content_tokens_nested_with_fragment_subclass_tag
|
40
|
+
layout_a = Comfy::Cms::Layout.new(content: "a {{cms:markdown content}} b")
|
41
|
+
layout_b = Comfy::Cms::Layout.new(content: "c {{cms:text content}} d")
|
42
|
+
layout_b.parent = layout_a
|
43
|
+
assert_equal [
|
44
|
+
"a ", "c ", {tag_class: "text", tag_params: "content"}, " d", " b"
|
45
|
+
], layout_b.content_tokens
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_content_tokens_nested_with_non_fragment_subclass_tag
|
49
|
+
layout_a = Comfy::Cms::Layout.new(content: "a {{cms:snippet content}} b")
|
50
|
+
layout_b = Comfy::Cms::Layout.new(content: "c {{cms:text content}} d")
|
51
|
+
layout_b.parent = layout_a
|
52
|
+
assert_equal [
|
53
|
+
"c ", {tag_class: "text", tag_params: "content"}, " d"
|
54
|
+
], layout_b.content_tokens
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_content_tokens_nested_without_content_tag
|
58
|
+
layout_a = Comfy::Cms::Layout.new(content: "a {{cms:text footer}} b")
|
59
|
+
layout_b = Comfy::Cms::Layout.new(content: "c {{cms:text content}} d")
|
60
|
+
layout_b.parent = layout_a
|
61
|
+
assert_equal ["c ", {tag_class: "text", tag_params: "content"}, " d"],
|
62
|
+
layout_b.content_tokens
|
63
|
+
end
|
64
|
+
|
17
65
|
def test_label_assignment
|
18
|
-
layout =
|
19
|
-
:
|
20
|
-
:
|
66
|
+
layout = @site.layouts.new(
|
67
|
+
identifier: 'test',
|
68
|
+
content: 'content'
|
21
69
|
)
|
22
70
|
assert layout.valid?
|
23
71
|
assert_equal 'Test', layout.label
|
24
72
|
end
|
25
|
-
|
73
|
+
|
26
74
|
def test_creation
|
27
75
|
assert_difference 'Comfy::Cms::Layout.count' do
|
28
|
-
layout =
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
76
|
+
layout = @site.layouts.create(
|
77
|
+
label: 'New Layout',
|
78
|
+
identifier: 'new-layout',
|
79
|
+
content: '{{cms:text default}}',
|
80
|
+
css: 'css',
|
81
|
+
js: 'js'
|
34
82
|
)
|
35
|
-
assert_equal 'New Layout',
|
36
|
-
assert_equal 'new-layout',
|
37
|
-
assert_equal '{{cms:
|
38
|
-
assert_equal 'css',
|
39
|
-
assert_equal 'js',
|
40
|
-
assert_equal 1,
|
83
|
+
assert_equal 'New Layout', layout.label
|
84
|
+
assert_equal 'new-layout', layout.identifier
|
85
|
+
assert_equal '{{cms:text default}}', layout.content
|
86
|
+
assert_equal 'css', layout.css
|
87
|
+
assert_equal 'js', layout.js
|
88
|
+
assert_equal 1, layout.position
|
41
89
|
end
|
42
90
|
end
|
43
|
-
|
91
|
+
|
44
92
|
def test_options_for_select
|
45
93
|
assert_equal ['Default Layout', 'Nested Layout', '. . Child Layout'],
|
46
|
-
Comfy::Cms::Layout.options_for_select(
|
94
|
+
Comfy::Cms::Layout.options_for_select(@site).collect{|t| t.first}
|
47
95
|
assert_equal ['Default Layout', 'Nested Layout'],
|
48
|
-
Comfy::Cms::Layout.options_for_select(
|
96
|
+
Comfy::Cms::Layout.options_for_select(@site, comfy_cms_layouts(:child)).collect{|t| t.first}
|
49
97
|
assert_equal ['Default Layout'],
|
50
|
-
Comfy::Cms::Layout.options_for_select(
|
98
|
+
Comfy::Cms::Layout.options_for_select(@site, comfy_cms_layouts(:nested)).collect{|t| t.first}
|
51
99
|
end
|
52
|
-
|
100
|
+
|
53
101
|
def test_app_layouts_for_select
|
54
102
|
FileUtils.touch(File.expand_path('app/views/layouts/comfy/admin/cms/nested.html.erb', Rails.root))
|
55
103
|
FileUtils.touch(File.expand_path('app/views/layouts/comfy/_partial.html.erb', Rails.root))
|
56
104
|
FileUtils.touch(File.expand_path('app/views/layouts/comfy/not_a_layout.erb', Rails.root))
|
57
105
|
|
58
106
|
view_paths = [File.expand_path('app/views/', Rails.root)]
|
59
|
-
assert_equal ['comfy/admin/cms', 'comfy/admin/cms/nested'],
|
107
|
+
assert_equal ['comfy/admin/cms', 'comfy/admin/cms/nested'],
|
108
|
+
Comfy::Cms::Layout.app_layouts_for_select(view_paths)
|
109
|
+
|
60
110
|
ensure
|
61
111
|
FileUtils.rm(File.expand_path('app/views/layouts/comfy/admin/cms/nested.html.erb', Rails.root))
|
62
112
|
FileUtils.rm(File.expand_path('app/views/layouts/comfy/_partial.html.erb', Rails.root))
|
@@ -72,71 +122,52 @@ class CmsLayoutTest < ActiveSupport::TestCase
|
|
72
122
|
ensure
|
73
123
|
FileUtils.rm_r(File.expand_path('app/additional_views', Rails.root))
|
74
124
|
end
|
75
|
-
|
76
|
-
def test_merged_content_with_same_child_content
|
77
|
-
parent_layout = comfy_cms_layouts(:nested)
|
78
|
-
assert_equal "{{cms:page:header}}\n{{cms:page:content}}", parent_layout.content
|
79
|
-
assert_equal "{{cms:page:header}}\n{{cms:page:content}}", parent_layout.merged_content
|
80
|
-
|
81
|
-
child_layout = comfy_cms_layouts(:child)
|
82
|
-
assert_equal parent_layout, child_layout.parent
|
83
|
-
assert_equal "{{cms:page:left_column}}\n{{cms:page:right_column}}", child_layout.content
|
84
|
-
assert_equal "{{cms:page:header}}\n{{cms:page:left_column}}\n{{cms:page:right_column}}", child_layout.merged_content
|
85
|
-
|
86
|
-
child_layout.update_columns(:content => '{{cms:page:content}}')
|
87
|
-
assert_equal "{{cms:page:header}}\n{{cms:page:content}}", child_layout.merged_content
|
88
|
-
|
89
|
-
parent_layout.update_columns(:content => '{{cms:page:whatever}}')
|
90
|
-
child_layout.reload
|
91
|
-
assert_equal '{{cms:page:content}}', child_layout.merged_content
|
92
|
-
end
|
93
|
-
|
125
|
+
|
94
126
|
def test_update_forces_page_content_reload
|
95
127
|
layout_1 = comfy_cms_layouts(:nested)
|
96
128
|
layout_2 = comfy_cms_layouts(:child)
|
97
|
-
page_1 =
|
98
|
-
:
|
99
|
-
:
|
100
|
-
:
|
101
|
-
:
|
102
|
-
:
|
103
|
-
:
|
104
|
-
{ :
|
105
|
-
:
|
106
|
-
{ :
|
107
|
-
:
|
129
|
+
page_1 = @site.pages.create!(
|
130
|
+
label: 'page_1',
|
131
|
+
slug: 'page-1',
|
132
|
+
parent_id: @page.id,
|
133
|
+
layout_id: layout_1.id,
|
134
|
+
is_published: '1',
|
135
|
+
fragments_attributes: [
|
136
|
+
{ identifier: 'header',
|
137
|
+
content: 'header_content' },
|
138
|
+
{ identifier: 'content',
|
139
|
+
content: 'content_content' }
|
108
140
|
]
|
109
141
|
)
|
110
|
-
page_2 =
|
111
|
-
:
|
112
|
-
:
|
113
|
-
:
|
114
|
-
:
|
115
|
-
:
|
116
|
-
:
|
117
|
-
{ :
|
118
|
-
:
|
119
|
-
{ :
|
120
|
-
:
|
121
|
-
{ :
|
122
|
-
:
|
142
|
+
page_2 = @site.pages.create!(
|
143
|
+
label: 'page_2',
|
144
|
+
slug: 'page-2',
|
145
|
+
parent_id: @page.id,
|
146
|
+
layout_id: layout_2.id,
|
147
|
+
is_published: '1',
|
148
|
+
fragments_attributes: [
|
149
|
+
{ identifier: 'header',
|
150
|
+
content: 'header_content' },
|
151
|
+
{ identifier: 'left_column',
|
152
|
+
content: 'left_column_content' },
|
153
|
+
{ identifier: 'right_column',
|
154
|
+
content: 'left_column_content' }
|
123
155
|
]
|
124
156
|
)
|
125
157
|
assert_equal "header_content\ncontent_content", page_1.content_cache
|
126
158
|
assert_equal "header_content\nleft_column_content\nleft_column_content", page_2.content_cache
|
127
|
-
|
128
|
-
layout_1.update_attributes(:
|
159
|
+
|
160
|
+
layout_1.update_attributes(content: "Updated {{cms:text content}}")
|
129
161
|
page_1.reload
|
130
162
|
page_2.reload
|
131
|
-
|
163
|
+
|
132
164
|
assert_equal "Updated content_content", page_1.content_cache
|
133
165
|
assert_equal "Updated left_column_content\nleft_column_content", page_2.content_cache
|
134
166
|
end
|
135
167
|
|
136
168
|
def test_cache_buster
|
137
169
|
timestamp = Time.current
|
138
|
-
layout =
|
139
|
-
|
170
|
+
layout = @site.layouts.create(updated_at: timestamp)
|
140
171
|
assert_equal timestamp.to_i, layout.cache_buster
|
141
172
|
end
|
142
173
|
end
|
data/test/models/page_test.rb
CHANGED
@@ -1,9 +1,22 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require_relative '../test_helper'
|
4
2
|
|
5
3
|
class CmsPageTest < ActiveSupport::TestCase
|
6
4
|
|
5
|
+
setup do
|
6
|
+
@site = comfy_cms_sites(:default)
|
7
|
+
@layout = comfy_cms_layouts(:default)
|
8
|
+
@page = comfy_cms_pages(:default)
|
9
|
+
end
|
10
|
+
|
11
|
+
def new_params(options = {})
|
12
|
+
{ label: "Test Page",
|
13
|
+
slug: "test-page",
|
14
|
+
layout: @layout
|
15
|
+
}.merge(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
# -- Tests -------------------------------------------------------------------
|
19
|
+
|
7
20
|
def test_fixtures_validity
|
8
21
|
Comfy::Cms::Page.all.each do |page|
|
9
22
|
assert page.valid?, page.errors.full_messages.to_s
|
@@ -15,32 +28,32 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
15
28
|
page = Comfy::Cms::Page.new
|
16
29
|
page.save
|
17
30
|
assert page.invalid?
|
18
|
-
assert_has_errors_on page, :
|
31
|
+
assert_has_errors_on page, :site, :layout, :slug, :label
|
19
32
|
end
|
20
33
|
|
21
34
|
def test_validation_of_parent_presence
|
22
|
-
page =
|
35
|
+
page = @site.pages.new(new_params)
|
23
36
|
assert !page.parent
|
24
37
|
assert page.valid?, page.errors.full_messages.to_s
|
25
|
-
assert_equal
|
38
|
+
assert_equal @page, page.parent
|
26
39
|
end
|
27
40
|
|
28
41
|
def test_validation_of_parent_relationship
|
29
|
-
page
|
30
|
-
|
31
|
-
page.
|
32
|
-
|
33
|
-
|
34
|
-
page.parent = comfy_cms_pages(:child)
|
35
|
-
assert page.invalid?
|
36
|
-
assert_has_errors_on page, :parent_id
|
42
|
+
assert !@page.parent
|
43
|
+
@page.parent = @page
|
44
|
+
assert @page.invalid?
|
45
|
+
assert_has_errors_on @page, :parent_id
|
46
|
+
|
47
|
+
@page.parent = comfy_cms_pages(:child)
|
48
|
+
assert @page.invalid?
|
49
|
+
assert_has_errors_on @page, :parent_id
|
37
50
|
end
|
38
51
|
|
39
52
|
def test_validation_of_target_page
|
40
53
|
page = comfy_cms_pages(:child)
|
41
|
-
page.target_page =
|
54
|
+
page.target_page = @page
|
42
55
|
page.save!
|
43
|
-
assert_equal
|
56
|
+
assert_equal @page, page.target_page
|
44
57
|
page.target_page = page
|
45
58
|
assert page.invalid?
|
46
59
|
assert_has_errors_on page, :target_page_id
|
@@ -60,73 +73,225 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
60
73
|
|
61
74
|
def test_validation_of_slug_allows_unicode_accent_characters
|
62
75
|
page = comfy_cms_pages(:child)
|
63
|
-
thai_character_ko_kai
|
64
|
-
thai_character_mai_tho
|
76
|
+
thai_character_ko_kai = "\u0e01"
|
77
|
+
thai_character_mai_tho = "\u0E49"
|
65
78
|
page.slug = thai_character_ko_kai + thai_character_mai_tho
|
66
79
|
assert page.valid?
|
67
80
|
end
|
68
81
|
|
69
82
|
def test_label_assignment
|
70
|
-
page =
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:layout
|
83
|
+
page = @site.pages.new(
|
84
|
+
slug: 'test',
|
85
|
+
parent: @page,
|
86
|
+
layout: @layout
|
74
87
|
)
|
75
88
|
assert page.valid?
|
76
89
|
assert_equal 'Test', page.label
|
77
90
|
end
|
78
91
|
|
79
|
-
def
|
80
|
-
|
81
|
-
page =
|
82
|
-
:
|
83
|
-
:
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
{ :identifier => 'default_page_text',
|
88
|
-
:content => 'test' }
|
92
|
+
def test_create
|
93
|
+
assert_count_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
94
|
+
page = @site.pages.create!(new_params(
|
95
|
+
parent: @page,
|
96
|
+
fragments_attributes: [
|
97
|
+
{ identifier: "content",
|
98
|
+
tag: "text",
|
99
|
+
content: "test" }
|
89
100
|
]
|
90
|
-
)
|
101
|
+
))
|
91
102
|
assert page.is_published?
|
92
103
|
assert_equal 1, page.position
|
93
104
|
end
|
94
105
|
end
|
95
106
|
|
107
|
+
def test_create_with_file
|
108
|
+
assert_count_difference [Comfy::Cms::Page, Comfy::Cms::Fragment, ActiveStorage::Attachment] do
|
109
|
+
page = @site.pages.create!(new_params(
|
110
|
+
parent: @page,
|
111
|
+
fragments_attributes: [{
|
112
|
+
identifier: "test",
|
113
|
+
tag: "file",
|
114
|
+
files: [fixture_file_upload("files/image.jpg", "image/jpeg")]
|
115
|
+
}]
|
116
|
+
))
|
117
|
+
assert_equal 1, page.fragments.count
|
118
|
+
assert page.fragments.first.attachments.attached?
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_create_with_files
|
123
|
+
assert_count_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
124
|
+
assert_count_difference [ActiveStorage::Attachment], 2 do
|
125
|
+
page = @site.pages.create!(new_params(
|
126
|
+
parent: @page,
|
127
|
+
fragments_attributes: [{
|
128
|
+
identifier: "test",
|
129
|
+
tag: "files",
|
130
|
+
files: [
|
131
|
+
fixture_file_upload("files/image.jpg", "image/jpeg"),
|
132
|
+
fixture_file_upload("files/document.pdf", "application/pdf")
|
133
|
+
]
|
134
|
+
}]
|
135
|
+
))
|
136
|
+
assert_equal 1, page.fragments.count
|
137
|
+
assert page.fragments.first.attachments.attached?
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_create_with_date
|
143
|
+
string = "1981-10-04 12:34:56"
|
144
|
+
datetime = DateTime.parse(string)
|
145
|
+
assert_count_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
146
|
+
page = @site.pages.create!(new_params(
|
147
|
+
parent: @page,
|
148
|
+
fragments_attributes: [{
|
149
|
+
identifier: "test",
|
150
|
+
tag: "date_time",
|
151
|
+
datetime: string
|
152
|
+
}]
|
153
|
+
))
|
154
|
+
frag = page.fragments.first
|
155
|
+
assert_equal datetime, frag.datetime
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_create_with_boolean
|
160
|
+
assert_count_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
161
|
+
page = @site.pages.create!(new_params(
|
162
|
+
parent: @page,
|
163
|
+
fragments_attributes: [{
|
164
|
+
identifier: "test",
|
165
|
+
tag: "checkbox",
|
166
|
+
boolean: "1"
|
167
|
+
}]
|
168
|
+
))
|
169
|
+
frag = page.fragments.first
|
170
|
+
assert frag.boolean
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_update
|
175
|
+
frag = comfy_cms_fragments(:default)
|
176
|
+
assert_count_no_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
177
|
+
@page.update_attributes!(fragments_attributes: [{
|
178
|
+
identifier: frag.identifier,
|
179
|
+
content: "updated content"
|
180
|
+
}])
|
181
|
+
end
|
182
|
+
frag.reload
|
183
|
+
assert_equal "updated content", frag.content
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_update_with_file
|
187
|
+
assert_count_no_difference [ActiveStorage::Attachment] do
|
188
|
+
@page.update_attributes!(
|
189
|
+
fragments_attributes: [{
|
190
|
+
identifier: "file",
|
191
|
+
tag: "file",
|
192
|
+
files: fixture_file_upload("files/document.pdf", "application/pdf")
|
193
|
+
}]
|
194
|
+
)
|
195
|
+
assert_equal "document.pdf", comfy_cms_fragments(:file).attachments.first.filename.to_s
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_update_with_file_removal
|
200
|
+
id = comfy_cms_fragments(:file).attachments.first.id
|
201
|
+
assert_count_difference [ActiveStorage::Attachment], -1 do
|
202
|
+
@page.update_attributes!(
|
203
|
+
fragments_attributes: [{
|
204
|
+
identifier: "file",
|
205
|
+
file_ids_destroy: [id]
|
206
|
+
}]
|
207
|
+
)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_update_with_date
|
212
|
+
frag = comfy_cms_fragments(:datetime)
|
213
|
+
string = "2020-01-01"
|
214
|
+
date = DateTime.parse(string)
|
215
|
+
assert_count_no_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
216
|
+
@page.update_attributes!(fragments_attributes: [{
|
217
|
+
identifier: frag.identifier,
|
218
|
+
datetime: string
|
219
|
+
}])
|
220
|
+
end
|
221
|
+
frag.reload
|
222
|
+
assert_equal date, frag.datetime
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_update_with_boolean
|
226
|
+
frag = comfy_cms_fragments(:boolean)
|
227
|
+
assert frag.boolean
|
228
|
+
assert_count_no_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
229
|
+
@page.update_attributes!(fragments_attributes: [{
|
230
|
+
identifier: frag.identifier,
|
231
|
+
boolean: "0"
|
232
|
+
}])
|
233
|
+
end
|
234
|
+
frag.reload
|
235
|
+
refute frag.boolean
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_update_with_parent_id_change
|
239
|
+
page_a = @page
|
240
|
+
page_b = comfy_cms_pages(:child)
|
241
|
+
page_c = @site.pages.create!(
|
242
|
+
label: 'Test Page',
|
243
|
+
slug: 'test-page',
|
244
|
+
layout: @layout,
|
245
|
+
parent: page_a
|
246
|
+
)
|
247
|
+
|
248
|
+
assert_equal 2, page_a.children_count
|
249
|
+
assert_equal 0, page_b.children_count
|
250
|
+
assert_equal 0, page_c.children_count
|
251
|
+
|
252
|
+
page_c.update_attributes!(parent_id: page_b)
|
253
|
+
|
254
|
+
page_a.reload; page_b.reload; page_c.reload
|
255
|
+
assert_equal 1, page_a.children_count
|
256
|
+
assert_equal 1, page_b.children_count
|
257
|
+
assert_equal 0, page_c.children_count
|
258
|
+
end
|
259
|
+
|
96
260
|
def test_initialization_of_full_path
|
97
261
|
page = Comfy::Cms::Page.new
|
98
262
|
assert_equal '/', page.full_path
|
99
263
|
|
100
264
|
page = Comfy::Cms::Page.new(new_params)
|
101
265
|
assert page.invalid?
|
102
|
-
assert_has_errors_on page, :
|
266
|
+
assert_has_errors_on page, :site
|
103
267
|
|
104
|
-
page =
|
268
|
+
page = @site.pages.new(new_params(parent: @page))
|
105
269
|
assert page.valid?
|
106
270
|
assert_equal '/test-page', page.full_path
|
107
271
|
|
108
|
-
page =
|
272
|
+
page = @site.pages.new(new_params(parent: comfy_cms_pages(:child)))
|
109
273
|
assert page.valid?
|
110
274
|
assert_equal '/child-page/test-page', page.full_path
|
111
275
|
|
112
276
|
Comfy::Cms::Page.destroy_all
|
113
|
-
page =
|
277
|
+
page = @site.pages.new(new_params)
|
114
278
|
assert page.valid?
|
115
279
|
assert_equal '/', page.full_path
|
116
280
|
end
|
117
281
|
|
118
282
|
def test_sync_child_pages
|
119
283
|
page = comfy_cms_pages(:child)
|
120
|
-
page_1 =
|
121
|
-
page_2 =
|
122
|
-
page_3 =
|
123
|
-
page_4 =
|
284
|
+
page_1 = @site.pages.create!(new_params(parent: page, slug: 'test-page-1'))
|
285
|
+
page_2 = @site.pages.create!(new_params(parent: page, slug: 'test-page-2'))
|
286
|
+
page_3 = @site.pages.create!(new_params(parent: page_2, slug: 'test-page-3'))
|
287
|
+
page_4 = @site.pages.create!(new_params(parent: page_1, slug: 'test-page-4'))
|
288
|
+
|
124
289
|
assert_equal '/child-page/test-page-1', page_1.full_path
|
125
290
|
assert_equal '/child-page/test-page-2', page_2.full_path
|
126
291
|
assert_equal '/child-page/test-page-2/test-page-3', page_3.full_path
|
127
292
|
assert_equal '/child-page/test-page-1/test-page-4', page_4.full_path
|
128
293
|
|
129
|
-
page.update_attributes!(:
|
294
|
+
page.update_attributes!(slug: 'updated-page')
|
130
295
|
assert_equal '/updated-page', page.full_path
|
131
296
|
page_1.reload; page_2.reload; page_3.reload; page_4.reload
|
132
297
|
assert_equal '/updated-page/test-page-1', page_1.full_path
|
@@ -134,7 +299,7 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
134
299
|
assert_equal '/updated-page/test-page-2/test-page-3', page_3.full_path
|
135
300
|
assert_equal '/updated-page/test-page-1/test-page-4', page_4.full_path
|
136
301
|
|
137
|
-
page_2.update_attributes!(:
|
302
|
+
page_2.update_attributes!(parent: page_1)
|
138
303
|
page_1.reload; page_2.reload; page_3.reload; page_4.reload
|
139
304
|
assert_equal '/updated-page/test-page-1', page_1.full_path
|
140
305
|
assert_equal '/updated-page/test-page-1/test-page-2', page_2.full_path
|
@@ -143,12 +308,12 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
143
308
|
end
|
144
309
|
|
145
310
|
def test_children_count_updating
|
146
|
-
page_1 =
|
311
|
+
page_1 = @page
|
147
312
|
page_2 = comfy_cms_pages(:child)
|
148
313
|
assert_equal 1, page_1.children_count
|
149
314
|
assert_equal 0, page_2.children_count
|
150
315
|
|
151
|
-
page_3 =
|
316
|
+
page_3 = @site.pages.create!(new_params(parent: page_2))
|
152
317
|
page_1.reload; page_2.reload
|
153
318
|
assert_equal 1, page_1.children_count
|
154
319
|
assert_equal 1, page_2.children_count
|
@@ -166,120 +331,195 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
166
331
|
end
|
167
332
|
|
168
333
|
def test_cascading_destroy
|
169
|
-
|
170
|
-
|
171
|
-
|
334
|
+
assert_count_difference [Comfy::Cms::Page], -2 do
|
335
|
+
assert_count_difference [Comfy::Cms::Fragment], -4 do
|
336
|
+
assert_count_difference [Comfy::Cms::Translation], -1 do
|
337
|
+
@page.destroy
|
338
|
+
end
|
172
339
|
end
|
173
340
|
end
|
174
341
|
end
|
175
342
|
|
176
343
|
def test_options_for_select
|
177
344
|
assert_equal ['Default Page', '. . Child Page'],
|
178
|
-
Comfy::Cms::Page.options_for_select(
|
345
|
+
Comfy::Cms::Page.options_for_select(@site).collect{|t| t.first }
|
179
346
|
assert_equal ['Default Page'],
|
180
|
-
Comfy::Cms::Page.options_for_select(
|
347
|
+
Comfy::Cms::Page.options_for_select(@site, comfy_cms_pages(:child)).collect{|t| t.first }
|
181
348
|
assert_equal [],
|
182
|
-
Comfy::Cms::Page.options_for_select(
|
349
|
+
Comfy::Cms::Page.options_for_select(@site, @page)
|
183
350
|
|
184
|
-
page = Comfy::Cms::Page.new(new_params(:
|
351
|
+
page = Comfy::Cms::Page.new(new_params(parent: @page))
|
185
352
|
assert_equal ['Default Page', '. . Child Page'],
|
186
|
-
Comfy::Cms::Page.options_for_select(
|
353
|
+
Comfy::Cms::Page.options_for_select(@site, page).collect{|t| t.first }
|
354
|
+
end
|
355
|
+
|
356
|
+
def test_fragments_attributes
|
357
|
+
assert_equal @page.fragments.count, @page.fragments_attributes.size
|
358
|
+
|
359
|
+
@page.fragments_attributes = [
|
360
|
+
{ identifier: "content",
|
361
|
+
content: "updated content"
|
362
|
+
}
|
363
|
+
]
|
364
|
+
|
365
|
+
assert_equal [
|
366
|
+
{ identifier: "boolean",
|
367
|
+
tag: "checkbox",
|
368
|
+
content: nil,
|
369
|
+
datetime: nil,
|
370
|
+
boolean: true },
|
371
|
+
{ identifier: "file",
|
372
|
+
tag: "file",
|
373
|
+
content: nil,
|
374
|
+
datetime: nil,
|
375
|
+
boolean: false },
|
376
|
+
{ identifier: "datetime",
|
377
|
+
tag: "datetime",
|
378
|
+
content: nil,
|
379
|
+
datetime: comfy_cms_fragments(:datetime).datetime,
|
380
|
+
boolean: false },
|
381
|
+
{ identifier: "content",
|
382
|
+
tag: "text",
|
383
|
+
content: "updated content",
|
384
|
+
datetime: nil,
|
385
|
+
boolean: false }
|
386
|
+
], @page.fragments_attributes
|
387
|
+
|
388
|
+
assert_equal [
|
389
|
+
{ identifier: "boolean",
|
390
|
+
tag: "checkbox",
|
391
|
+
content: nil,
|
392
|
+
datetime: nil,
|
393
|
+
boolean: true },
|
394
|
+
{ identifier: "file",
|
395
|
+
tag: "file",
|
396
|
+
content: nil,
|
397
|
+
datetime: nil,
|
398
|
+
boolean: false },
|
399
|
+
{ identifier: "datetime",
|
400
|
+
tag: "datetime",
|
401
|
+
content: nil,
|
402
|
+
datetime: comfy_cms_fragments(:datetime).datetime,
|
403
|
+
boolean: false },
|
404
|
+
{ identifier: "content",
|
405
|
+
tag: "text",
|
406
|
+
content: "content",
|
407
|
+
datetime: nil,
|
408
|
+
boolean: false }
|
409
|
+
], @page.fragments_attributes_was
|
187
410
|
end
|
188
411
|
|
189
|
-
def
|
190
|
-
|
191
|
-
assert_equal
|
192
|
-
|
193
|
-
|
412
|
+
def test_render
|
413
|
+
expected = @page.render
|
414
|
+
assert_equal "content", expected
|
415
|
+
end
|
416
|
+
|
417
|
+
def test_fragment_nodes
|
418
|
+
content = "a {{cms:text a}} b {{cms:snippet b}} c {{cms:text c}}"
|
419
|
+
@page.layout.update_column(:content, content)
|
420
|
+
nodes = @page.fragment_nodes
|
421
|
+
assert_equal 2, nodes.count
|
422
|
+
assert_equal "a", nodes[0].identifier
|
423
|
+
assert_equal "c", nodes[1].identifier
|
424
|
+
end
|
425
|
+
|
426
|
+
def test_fragment_nodes_with_duplicates
|
427
|
+
content = "{{cms:wysiwyg test}} {{cms:markdown test}}"
|
428
|
+
@page.layout.update_column(:content, content)
|
429
|
+
nodes = @page.fragment_nodes
|
430
|
+
assert_equal 1, nodes.count
|
431
|
+
assert_equal ComfortableMexicanSofa::Content::Tag::Wysiwyg, nodes[0].class
|
432
|
+
assert_equal "test", nodes[0].identifier
|
433
|
+
end
|
434
|
+
|
435
|
+
def test_fragment_nodes_with_no_layout
|
436
|
+
@page.update_column(:layout_id, nil)
|
437
|
+
assert_equal [], @page.fragment_nodes
|
194
438
|
end
|
195
439
|
|
196
440
|
def test_content_caching
|
197
|
-
page
|
198
|
-
assert_equal page.content_cache, page.render
|
441
|
+
assert_equal @page.content_cache, @page.render
|
199
442
|
|
200
|
-
page.update_columns(:
|
201
|
-
refute_equal page.content_cache, page.render
|
443
|
+
@page.update_columns(content_cache: 'Old Content')
|
444
|
+
refute_equal @page.content_cache, @page.render
|
202
445
|
|
203
|
-
page.clear_content_cache!
|
204
|
-
assert_equal page.content_cache, page.render
|
446
|
+
@page.clear_content_cache!
|
447
|
+
assert_equal @page.content_cache, @page.render
|
205
448
|
end
|
206
449
|
|
207
450
|
def test_content_cache_clear_on_save
|
208
|
-
page = comfy_cms_pages(:default)
|
209
451
|
old_content = 'Old Content'
|
210
|
-
page.update_columns(:
|
452
|
+
@page.update_columns(content_cache: old_content)
|
211
453
|
|
212
|
-
page.save!
|
213
|
-
refute_equal old_content, page.content_cache
|
454
|
+
@page.save!
|
455
|
+
refute_equal old_content, @page.content_cache
|
214
456
|
end
|
215
457
|
|
216
458
|
def test_scope_published
|
217
459
|
assert_equal 2, Comfy::Cms::Page.published.count
|
218
|
-
comfy_cms_pages(:child).update_columns(:
|
460
|
+
comfy_cms_pages(:child).update_columns(is_published: false)
|
219
461
|
assert_equal 1, Comfy::Cms::Page.published.count
|
220
462
|
end
|
221
463
|
|
222
464
|
def test_root?
|
223
|
-
assert
|
224
|
-
|
465
|
+
assert @page.root?
|
466
|
+
refute comfy_cms_pages(:child).root?
|
225
467
|
end
|
226
468
|
|
227
469
|
def test_url
|
228
|
-
|
229
|
-
|
230
|
-
assert_equal '//test.host/', comfy_cms_pages(:default).url
|
470
|
+
assert_equal '//test.host/', @page.url
|
231
471
|
assert_equal '//test.host/child-page', comfy_cms_pages(:child).url
|
232
472
|
|
233
|
-
assert_equal '/',
|
234
|
-
assert_equal '/child-page', comfy_cms_pages(:child).url(:
|
473
|
+
assert_equal '/', @page.url(relative: true)
|
474
|
+
assert_equal '/child-page', comfy_cms_pages(:child).url(relative: true)
|
235
475
|
|
236
|
-
site.update_columns(:
|
237
|
-
|
476
|
+
@site.update_columns(path: '/en/site')
|
477
|
+
@page.reload
|
238
478
|
comfy_cms_pages(:child).reload
|
239
479
|
|
240
|
-
assert_equal '//test.host/en/site/',
|
480
|
+
assert_equal '//test.host/en/site/', @page.url
|
241
481
|
assert_equal '//test.host/en/site/child-page', comfy_cms_pages(:child).url
|
242
482
|
|
243
|
-
assert_equal '/en/site/',
|
244
|
-
assert_equal '/en/site/child-page', comfy_cms_pages(:child).url(:
|
483
|
+
assert_equal '/en/site/', @page.url(relative: true)
|
484
|
+
assert_equal '/en/site/child-page', comfy_cms_pages(:child).url(relative: true)
|
245
485
|
end
|
246
486
|
|
247
487
|
def test_url_with_public_cms_path
|
248
488
|
ComfortableMexicanSofa.config.public_cms_path = '/custom'
|
249
|
-
assert_equal '//test.host/custom/',
|
489
|
+
assert_equal '//test.host/custom/', @page.url
|
250
490
|
assert_equal '//test.host/custom/child-page', comfy_cms_pages(:child).url
|
251
491
|
|
252
|
-
assert_equal '/custom/',
|
253
|
-
assert_equal '/custom/child-page', comfy_cms_pages(:child).url(:
|
492
|
+
assert_equal '/custom/', @page.url(relative: true)
|
493
|
+
assert_equal '/custom/child-page', comfy_cms_pages(:child).url(relative: true)
|
254
494
|
end
|
255
495
|
|
256
496
|
def test_unicode_slug_escaping
|
257
497
|
page = comfy_cms_pages(:child)
|
258
|
-
page_1 =
|
498
|
+
page_1 = @site.pages.create!(new_params(parent: page, slug: 'tést-ünicode-slug'))
|
259
499
|
assert_equal CGI::escape('tést-ünicode-slug'), page_1.slug
|
260
500
|
assert_equal CGI::escape('/child-page/tést-ünicode-slug').gsub('%2F', '/'), page_1.full_path
|
261
501
|
end
|
262
502
|
|
263
503
|
def test_unicode_slug_unescaping
|
264
504
|
page = comfy_cms_pages(:child)
|
265
|
-
page_1 =
|
266
|
-
found_page =
|
505
|
+
page_1 = @site.pages.create!(new_params(parent: page, slug: 'tést-ünicode-slug'))
|
506
|
+
found_page = @site.pages.where(slug: CGI::escape('tést-ünicode-slug')).first
|
267
507
|
assert_equal 'tést-ünicode-slug', found_page.slug
|
268
508
|
assert_equal '/child-page/tést-ünicode-slug', found_page.full_path
|
269
509
|
end
|
270
510
|
|
271
511
|
def test_identifier
|
272
|
-
assert_equal 'index',
|
512
|
+
assert_equal 'index', @page.identifier
|
273
513
|
assert_equal 'child-page', comfy_cms_pages(:child).identifier
|
274
514
|
|
275
|
-
|
515
|
+
@page.update_column(:slug, 'index')
|
276
516
|
assert_equal 'index', comfy_cms_pages(:default).identifier
|
277
517
|
end
|
278
518
|
|
279
519
|
def test_children_count_updating_on_move
|
280
|
-
page_1 =
|
520
|
+
page_1 = @page
|
281
521
|
page_2 = comfy_cms_pages(:child)
|
282
|
-
page_3 =
|
522
|
+
page_3 = @site.pages.create!(new_params(parent: page_2))
|
283
523
|
|
284
524
|
page_2.reload
|
285
525
|
|
@@ -297,13 +537,28 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
297
537
|
assert_equal 0, page_3.children_count
|
298
538
|
end
|
299
539
|
|
300
|
-
|
540
|
+
def test_translate
|
541
|
+
translation = comfy_cms_translations(:default)
|
542
|
+
translation.update_columns(layout_id: comfy_cms_layouts(:nested).id)
|
301
543
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
544
|
+
@page.translate!(:fr)
|
545
|
+
assert @page.readonly?
|
546
|
+
|
547
|
+
assert_equal comfy_cms_layouts(:nested), @page.layout
|
548
|
+
assert_equal 'Default Translation', @page.label
|
549
|
+
assert_equal 'Translation Content', @page.content_cache
|
550
|
+
end
|
551
|
+
|
552
|
+
def test_translate_with_unpublished
|
553
|
+
comfy_cms_translations(:default).update_column(:is_published, false)
|
554
|
+
assert_exception_raised ActiveRecord::RecordNotFound do
|
555
|
+
@page.translate!(:fr)
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
559
|
+
def test_translate_with_invalid_locale
|
560
|
+
assert_exception_raised ActiveRecord::RecordNotFound do
|
561
|
+
@page.translate!(:es)
|
562
|
+
end
|
308
563
|
end
|
309
564
|
end
|