comfortable_mexican_sofa 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +95 -4
- data/.travis.yml +2 -1
- data/CONTRIBUTING.md +8 -5
- data/Gemfile +9 -9
- data/Rakefile +1 -1
- data/app/assets/javascripts/comfy/admin/cms/base.js.coffee +1 -0
- data/app/assets/stylesheets/comfy/admin/cms/base.sass +14 -4
- data/app/controllers/application_controller.rb +2 -2
- data/app/controllers/comfy/admin/base_controller.rb +1 -1
- data/app/controllers/comfy/admin/cms/base_controller.rb +7 -6
- data/app/controllers/comfy/admin/cms/categories_controller.rb +2 -1
- data/app/controllers/comfy/admin/cms/files_controller.rb +32 -29
- data/app/controllers/comfy/admin/cms/layouts_controller.rb +10 -9
- data/app/controllers/comfy/admin/cms/pages_controller.rb +31 -27
- data/app/controllers/comfy/admin/cms/revisions/base_controller.rb +5 -4
- data/app/controllers/comfy/admin/cms/revisions/layout_controller.rb +2 -1
- data/app/controllers/comfy/admin/cms/revisions/page_controller.rb +9 -3
- data/app/controllers/comfy/admin/cms/revisions/snippet_controller.rb +2 -1
- data/app/controllers/comfy/admin/cms/revisions/translation_controller.rb +9 -3
- data/app/controllers/comfy/admin/cms/sites_controller.rb +10 -9
- data/app/controllers/comfy/admin/cms/snippets_controller.rb +10 -9
- data/app/controllers/comfy/admin/cms/translations_controller.rb +15 -14
- data/app/controllers/comfy/cms/assets_controller.rb +4 -3
- data/app/controllers/comfy/cms/base_controller.rb +12 -11
- data/app/controllers/comfy/cms/content_controller.rb +8 -7
- data/app/controllers/concerns/comfy/paginate.rb +2 -1
- data/app/helpers/comfy/cms_helper.rb +6 -3
- data/app/models/comfy/cms/categorization.rb +2 -1
- data/app/models/comfy/cms/category.rb +3 -2
- data/app/models/comfy/cms/file.rb +9 -7
- data/app/models/comfy/cms/fragment.rb +8 -6
- data/app/models/comfy/cms/layout.rb +24 -24
- data/app/models/comfy/cms/page.rb +51 -32
- data/app/models/comfy/cms/revision.rb +2 -1
- data/app/models/comfy/cms/site.rb +27 -26
- data/app/models/comfy/cms/snippet.rb +7 -5
- data/app/models/comfy/cms/translation.rb +6 -4
- data/app/models/concerns/comfy/cms/with_categories.rb +9 -7
- data/app/models/concerns/comfy/cms/with_fragments.rb +15 -13
- data/app/views/comfy/admin/cms/categories/_categories.html.haml +1 -1
- data/app/views/comfy/admin/cms/files/_file.html.haml +3 -3
- data/app/views/comfy/admin/cms/files/_modal.html.haml +2 -2
- data/app/views/comfy/admin/cms/{pages/_fragment_attachments.html.haml → fragments/_form_fragment_attachments.html.haml} +0 -0
- data/app/views/comfy/admin/cms/{pages → fragments}/_form_fragments.html.haml +0 -0
- data/app/views/comfy/admin/cms/layouts/_index_branch.html.haml +2 -2
- data/app/views/comfy/admin/cms/pages/_form.html.haml +7 -7
- data/app/views/comfy/admin/cms/pages/_index_branch.html.haml +16 -15
- data/app/views/comfy/admin/cms/pages/form_fragments.js.erb +1 -1
- data/app/views/comfy/admin/cms/pages/toggle_branch.js.erb +1 -1
- data/app/views/comfy/admin/cms/snippets/index.html.haml +3 -3
- data/app/views/comfy/admin/cms/translations/_form.html.haml +1 -1
- data/app/views/comfy/admin/cms/translations/form_fragments.js.erb +1 -1
- data/app/views/layouts/comfy/admin/cms/_body.html.haml +1 -4
- data/app/views/layouts/comfy/admin/cms.html.haml +1 -1
- data/bin/bundle +3 -0
- data/bin/rails +4 -0
- data/bin/rake +4 -0
- data/bin/setup +36 -0
- data/bin/update +31 -0
- data/bin/yarn +11 -0
- data/comfortable_mexican_sofa.gemspec +14 -14
- data/config/application.rb +4 -3
- data/config/boot.rb +3 -3
- data/config/cms_routes.rb +1 -1
- data/config/environment.rb +1 -1
- data/config/environments/development.rb +2 -2
- data/config/environments/test.rb +1 -1
- data/config/initializers/comfortable_mexican_sofa.rb +2 -5
- data/config/locales/cs.yml +2 -1
- data/config/locales/da.yml +2 -1
- data/config/locales/de.yml +2 -1
- data/config/locales/en.yml +2 -1
- data/config/locales/es.yml +2 -1
- data/config/locales/fr.yml +2 -1
- data/config/locales/it.yml +2 -1
- data/config/locales/ja.yml +2 -1
- data/config/locales/nb.yml +2 -1
- data/config/locales/nl.yml +2 -1
- data/config/locales/pl.yml +2 -1
- data/config/locales/pt-BR.yml +2 -1
- data/config/locales/ru.yml +2 -1
- data/config/locales/sk.yml +2 -1
- data/config/locales/sv.yml +2 -1
- data/config/locales/tr.yml +2 -1
- data/config/locales/uk.yml +2 -1
- data/config/locales/zh-CN.yml +2 -1
- data/config/locales/zh-TW.yml +2 -1
- data/config.ru +1 -1
- data/lib/comfortable_mexican_sofa/access_control/admin_authentication.rb +2 -1
- data/lib/comfortable_mexican_sofa/access_control/admin_authorization.rb +2 -0
- data/lib/comfortable_mexican_sofa/access_control/public_authentication.rb +3 -1
- data/lib/comfortable_mexican_sofa/access_control/public_authorization.rb +2 -0
- data/lib/comfortable_mexican_sofa/configuration.rb +27 -29
- data/lib/comfortable_mexican_sofa/content/block.rb +2 -1
- data/lib/comfortable_mexican_sofa/content/params_parser.rb +22 -21
- data/lib/comfortable_mexican_sofa/content/renderer.rb +10 -8
- data/lib/comfortable_mexican_sofa/content/tag.rb +1 -0
- data/lib/comfortable_mexican_sofa/content/tags/asset.rb +4 -3
- data/lib/comfortable_mexican_sofa/content/tags/checkbox.rb +3 -2
- data/lib/comfortable_mexican_sofa/content/tags/date.rb +4 -3
- data/lib/comfortable_mexican_sofa/content/tags/datetime.rb +4 -3
- data/lib/comfortable_mexican_sofa/content/tags/file.rb +15 -13
- data/lib/comfortable_mexican_sofa/content/tags/file_link.rb +8 -7
- data/lib/comfortable_mexican_sofa/content/tags/files.rb +15 -13
- data/lib/comfortable_mexican_sofa/content/tags/fragment.rb +7 -6
- data/lib/comfortable_mexican_sofa/content/tags/helper.rb +2 -1
- data/lib/comfortable_mexican_sofa/content/tags/markdown.rb +5 -4
- data/lib/comfortable_mexican_sofa/content/tags/number.rb +4 -3
- data/lib/comfortable_mexican_sofa/content/tags/partial.rb +1 -0
- data/lib/comfortable_mexican_sofa/content/tags/snippet.rb +3 -2
- data/lib/comfortable_mexican_sofa/content/tags/template.rb +1 -0
- data/lib/comfortable_mexican_sofa/content/tags/text.rb +4 -3
- data/lib/comfortable_mexican_sofa/content/tags/textarea.rb +4 -3
- data/lib/comfortable_mexican_sofa/content/tags/wysiwyg.rb +4 -3
- data/lib/comfortable_mexican_sofa/content.rb +21 -21
- data/lib/comfortable_mexican_sofa/engine.rb +17 -15
- data/lib/comfortable_mexican_sofa/error.rb +12 -6
- data/lib/comfortable_mexican_sofa/extensions/acts_as_tree.rb +17 -11
- data/lib/comfortable_mexican_sofa/extensions/has_revisions.rb +14 -13
- data/lib/comfortable_mexican_sofa/form_builder.rb +2 -2
- data/lib/comfortable_mexican_sofa/render_methods.rb +74 -76
- data/lib/comfortable_mexican_sofa/routes/cms.rb +4 -4
- data/lib/comfortable_mexican_sofa/routes/cms_admin.rb +2 -1
- data/lib/comfortable_mexican_sofa/routing.rb +4 -2
- data/lib/comfortable_mexican_sofa/seeds/file/exporter.rb +7 -6
- data/lib/comfortable_mexican_sofa/seeds/file/importer.rb +9 -9
- data/lib/comfortable_mexican_sofa/seeds/layout/exporter.rb +8 -7
- data/lib/comfortable_mexican_sofa/seeds/layout/importer.rb +11 -10
- data/lib/comfortable_mexican_sofa/seeds/page/exporter.rb +25 -23
- data/lib/comfortable_mexican_sofa/seeds/page/importer.rb +47 -43
- data/lib/comfortable_mexican_sofa/seeds/snippet/exporter.rb +7 -6
- data/lib/comfortable_mexican_sofa/seeds/snippet/importer.rb +7 -6
- data/lib/comfortable_mexican_sofa/seeds.rb +16 -9
- data/lib/comfortable_mexican_sofa/version.rb +4 -2
- data/lib/comfortable_mexican_sofa/view_hooks.rb +10 -9
- data/lib/comfortable_mexican_sofa.rb +30 -30
- data/lib/generators/comfy/cms/assets_generator.rb +6 -4
- data/lib/generators/comfy/cms/cms_generator.rb +14 -14
- data/lib/generators/comfy/cms/controllers_generator.rb +5 -3
- data/lib/generators/comfy/cms/models_generator.rb +5 -3
- data/lib/generators/comfy/cms/views_generator.rb +5 -3
- data/lib/generators/comfy/scaffold/scaffold_generator.rb +19 -18
- data/lib/tasks/cms_seeds.rake +4 -5
- data/test/controllers/comfy/admin/cms/base_controller_test.rb +4 -3
- data/test/controllers/comfy/admin/cms/categories_controller_test.rb +19 -18
- data/test/controllers/comfy/admin/cms/files_controller_test.rb +19 -19
- data/test/controllers/comfy/admin/cms/layouts_controller_test.rb +33 -32
- data/test/controllers/comfy/admin/cms/pages_controller_test.rb +99 -98
- data/test/controllers/comfy/admin/cms/revisions/layout_controller_test.rb +9 -9
- data/test/controllers/comfy/admin/cms/revisions/page_controller_test.rb +6 -6
- data/test/controllers/comfy/admin/cms/revisions/snippet_controller_test.rb +9 -8
- data/test/controllers/comfy/admin/cms/revisions/translation_controller_test.rb +6 -7
- data/test/controllers/comfy/admin/cms/sites_controller_test.rb +31 -30
- data/test/controllers/comfy/admin/cms/snippets_controller_test.rb +38 -37
- data/test/controllers/comfy/admin/cms/translations_controller_test.rb +21 -20
- data/test/controllers/comfy/cms/assets_controller_test.rb +14 -13
- data/test/controllers/comfy/cms/content_controller_test.rb +58 -57
- data/test/gemfiles/Gemfile.rails.5.2 +5 -4
- data/test/generators/cms_assets_generator_test.rb +6 -4
- data/test/generators/cms_controllers_generator_test.rb +7 -5
- data/test/generators/cms_generator_test.rb +12 -10
- data/test/generators/cms_models_generator_test.rb +7 -5
- data/test/generators/cms_views_generator_test.rb +6 -4
- data/test/generators/scaffold_generator_test.rb +18 -16
- data/test/helpers/cms_helper_test.rb +5 -2
- data/test/integration/access_control_test.rb +29 -20
- data/test/integration/i18n_test.rb +8 -7
- data/test/integration/js_variables_test.rb +2 -1
- data/test/integration/render_cms_test.rb +93 -88
- data/test/integration/routing_test.rb +4 -3
- data/test/integration/seeds_test.rb +21 -22
- data/test/integration/sites_test.rb +26 -25
- data/test/integration/view_hooks_test.rb +15 -14
- data/test/lib/configuration_test.rb +13 -15
- data/test/lib/content/block_test.rb +1 -1
- data/test/lib/content/params_parser_test.rb +11 -10
- data/test/lib/content/renderer_test.rb +16 -11
- data/test/lib/content/tag_test.rb +7 -3
- data/test/lib/content/tags/asset_test.rb +4 -3
- data/test/lib/content/tags/checkbox_test.rb +2 -1
- data/test/lib/content/tags/date_test.rb +2 -1
- data/test/lib/content/tags/datetime_test.rb +2 -1
- data/test/lib/content/tags/file_link_test.rb +3 -2
- data/test/lib/content/tags/file_test.rb +3 -2
- data/test/lib/content/tags/files_test.rb +4 -3
- data/test/lib/content/tags/fragment_test.rb +2 -1
- data/test/lib/content/tags/helper_test.rb +4 -3
- data/test/lib/content/tags/markdown_test.rb +2 -1
- data/test/lib/content/tags/number_test.rb +2 -1
- data/test/lib/content/tags/partial_test.rb +4 -3
- data/test/lib/content/tags/snippet_test.rb +2 -1
- data/test/lib/content/tags/template_test.rb +2 -1
- data/test/lib/content/tags/text_test.rb +2 -1
- data/test/lib/content/tags/textarea_test.rb +2 -1
- data/test/lib/content/tags/wysiwyg_test.rb +2 -1
- data/test/lib/revisions_test.rb +44 -42
- data/test/lib/seeds/files_test.rb +30 -29
- data/test/lib/seeds/layouts_test.rb +13 -12
- data/test/lib/seeds/pages_test.rb +32 -29
- data/test/lib/seeds/snippets_test.rb +21 -20
- data/test/lib/seeds_test.rb +9 -8
- data/test/models/categorization_test.rb +10 -9
- data/test/models/category_test.rb +1 -1
- data/test/models/file_test.rb +1 -1
- data/test/models/fragment_test.rb +11 -10
- data/test/models/layout_test.rb +71 -70
- data/test/models/page_test.rb +170 -159
- data/test/models/site_test.rb +17 -16
- data/test/models/snippet_test.rb +1 -0
- data/test/models/translation_test.rb +2 -1
- data/test/tasks/cms_seeds_test.rb +3 -2
- data/test/test_helper.rb +42 -40
- metadata +55 -51
- data/.rubocop_todo.yml +0 -974
- data/script/rails +0 -6
data/test/models/page_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "../test_helper"
|
2
2
|
|
3
3
|
class CmsPageTest < ActiveSupport::TestCase
|
4
4
|
|
@@ -61,13 +61,13 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
61
61
|
|
62
62
|
def test_validation_of_slug
|
63
63
|
page = comfy_cms_pages(:child)
|
64
|
-
page.slug =
|
64
|
+
page.slug = "slug.with.d0ts-and_things"
|
65
65
|
assert page.valid?
|
66
66
|
|
67
|
-
page.slug =
|
67
|
+
page.slug = "inva lid"
|
68
68
|
assert page.invalid?
|
69
69
|
|
70
|
-
page.slug =
|
70
|
+
page.slug = "acción"
|
71
71
|
assert page.valid?
|
72
72
|
end
|
73
73
|
|
@@ -81,24 +81,26 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
81
81
|
|
82
82
|
def test_label_assignment
|
83
83
|
page = @site.pages.new(
|
84
|
-
slug:
|
84
|
+
slug: "test",
|
85
85
|
parent: @page,
|
86
86
|
layout: @layout
|
87
87
|
)
|
88
88
|
assert page.valid?
|
89
|
-
assert_equal
|
89
|
+
assert_equal "Test", page.label
|
90
90
|
end
|
91
91
|
|
92
92
|
def test_create
|
93
93
|
assert_count_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
94
|
-
page = @site.pages.create!(
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
94
|
+
page = @site.pages.create!(
|
95
|
+
new_params(
|
96
|
+
parent: @page,
|
97
|
+
fragments_attributes: [
|
98
|
+
{ identifier: "content",
|
99
|
+
tag: "text",
|
100
|
+
content: "test" }
|
101
|
+
]
|
102
|
+
)
|
103
|
+
)
|
102
104
|
assert page.is_published?
|
103
105
|
assert_equal 1, page.position
|
104
106
|
end
|
@@ -106,14 +108,16 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
106
108
|
|
107
109
|
def test_create_with_file
|
108
110
|
assert_count_difference [Comfy::Cms::Page, Comfy::Cms::Fragment, ActiveStorage::Attachment] do
|
109
|
-
page = @site.pages.create!(
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
111
|
+
page = @site.pages.create!(
|
112
|
+
new_params(
|
113
|
+
parent: @page,
|
114
|
+
fragments_attributes: [{
|
115
|
+
identifier: "test",
|
116
|
+
tag: "file",
|
117
|
+
files: [fixture_file_upload("files/image.jpg", "image/jpeg")]
|
118
|
+
}]
|
119
|
+
)
|
120
|
+
)
|
117
121
|
assert_equal 1, page.fragments.count
|
118
122
|
assert page.fragments.first.attachments.attached?
|
119
123
|
end
|
@@ -122,17 +126,19 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
122
126
|
def test_create_with_files
|
123
127
|
assert_count_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
124
128
|
assert_count_difference [ActiveStorage::Attachment], 2 do
|
125
|
-
page = @site.pages.create!(
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
129
|
+
page = @site.pages.create!(
|
130
|
+
new_params(
|
131
|
+
parent: @page,
|
132
|
+
fragments_attributes: [{
|
133
|
+
identifier: "test",
|
134
|
+
tag: "files",
|
135
|
+
files: [
|
136
|
+
fixture_file_upload("files/image.jpg", "image/jpeg"),
|
137
|
+
fixture_file_upload("files/document.pdf", "application/pdf")
|
138
|
+
]
|
139
|
+
}]
|
140
|
+
)
|
141
|
+
)
|
136
142
|
assert_equal 1, page.fragments.count
|
137
143
|
assert page.fragments.first.attachments.attached?
|
138
144
|
end
|
@@ -143,14 +149,16 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
143
149
|
string = "1981-10-04 12:34:56"
|
144
150
|
datetime = DateTime.parse(string)
|
145
151
|
assert_count_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
146
|
-
page = @site.pages.create!(
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
152
|
+
page = @site.pages.create!(
|
153
|
+
new_params(
|
154
|
+
parent: @page,
|
155
|
+
fragments_attributes: [{
|
156
|
+
identifier: "test",
|
157
|
+
tag: "date_time",
|
158
|
+
datetime: string
|
159
|
+
}]
|
160
|
+
)
|
161
|
+
)
|
154
162
|
frag = page.fragments.first
|
155
163
|
assert_equal datetime, frag.datetime
|
156
164
|
end
|
@@ -158,14 +166,16 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
158
166
|
|
159
167
|
def test_create_with_boolean
|
160
168
|
assert_count_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
161
|
-
page = @site.pages.create!(
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
+
page = @site.pages.create!(
|
170
|
+
new_params(
|
171
|
+
parent: @page,
|
172
|
+
fragments_attributes: [{
|
173
|
+
identifier: "test",
|
174
|
+
tag: "checkbox",
|
175
|
+
boolean: "1"
|
176
|
+
}]
|
177
|
+
)
|
178
|
+
)
|
169
179
|
frag = page.fragments.first
|
170
180
|
assert frag.boolean
|
171
181
|
end
|
@@ -174,10 +184,10 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
174
184
|
def test_update
|
175
185
|
frag = comfy_cms_fragments(:default)
|
176
186
|
assert_count_no_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
177
|
-
@page.update_attributes!(fragments_attributes: [
|
178
|
-
identifier: frag.identifier,
|
179
|
-
|
180
|
-
|
187
|
+
@page.update_attributes!(fragments_attributes: [
|
188
|
+
{ identifier: frag.identifier,
|
189
|
+
content: "updated content" }
|
190
|
+
])
|
181
191
|
end
|
182
192
|
frag.reload
|
183
193
|
assert_equal "updated content", frag.content
|
@@ -211,12 +221,12 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
211
221
|
def test_update_with_date
|
212
222
|
frag = comfy_cms_fragments(:datetime)
|
213
223
|
string = "2020-01-01"
|
214
|
-
date
|
224
|
+
date = DateTime.parse(string)
|
215
225
|
assert_count_no_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
216
|
-
@page.update_attributes!(fragments_attributes: [
|
217
|
-
identifier: frag.identifier,
|
218
|
-
|
219
|
-
|
226
|
+
@page.update_attributes!(fragments_attributes: [
|
227
|
+
{ identifier: frag.identifier,
|
228
|
+
datetime: string }
|
229
|
+
])
|
220
230
|
end
|
221
231
|
frag.reload
|
222
232
|
assert_equal date, frag.datetime
|
@@ -226,10 +236,10 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
226
236
|
frag = comfy_cms_fragments(:boolean)
|
227
237
|
assert frag.boolean
|
228
238
|
assert_count_no_difference [Comfy::Cms::Page, Comfy::Cms::Fragment] do
|
229
|
-
@page.update_attributes!(fragments_attributes: [
|
230
|
-
identifier: frag.identifier,
|
231
|
-
|
232
|
-
|
239
|
+
@page.update_attributes!(fragments_attributes: [
|
240
|
+
{ identifier: frag.identifier,
|
241
|
+
boolean: "0" }
|
242
|
+
])
|
233
243
|
end
|
234
244
|
frag.reload
|
235
245
|
refute frag.boolean
|
@@ -239,8 +249,8 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
239
249
|
page_a = @page
|
240
250
|
page_b = comfy_cms_pages(:child)
|
241
251
|
page_c = @site.pages.create!(
|
242
|
-
label:
|
243
|
-
slug:
|
252
|
+
label: "Test Page",
|
253
|
+
slug: "test-page",
|
244
254
|
layout: @layout,
|
245
255
|
parent: page_a
|
246
256
|
)
|
@@ -251,7 +261,7 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
251
261
|
|
252
262
|
page_c.update_attributes!(parent_id: page_b)
|
253
263
|
|
254
|
-
page_a
|
264
|
+
[page_a, page_b, page_c].each(&:reload)
|
255
265
|
assert_equal 1, page_a.children_count
|
256
266
|
assert_equal 1, page_b.children_count
|
257
267
|
assert_equal 0, page_c.children_count
|
@@ -259,7 +269,7 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
259
269
|
|
260
270
|
def test_initialization_of_full_path
|
261
271
|
page = Comfy::Cms::Page.new
|
262
|
-
assert_equal
|
272
|
+
assert_equal "/", page.full_path
|
263
273
|
|
264
274
|
page = Comfy::Cms::Page.new(new_params)
|
265
275
|
assert page.invalid?
|
@@ -267,67 +277,67 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
267
277
|
|
268
278
|
page = @site.pages.new(new_params(parent: @page))
|
269
279
|
assert page.valid?
|
270
|
-
assert_equal
|
280
|
+
assert_equal "/test-page", page.full_path
|
271
281
|
|
272
282
|
page = @site.pages.new(new_params(parent: comfy_cms_pages(:child)))
|
273
283
|
assert page.valid?
|
274
|
-
assert_equal
|
284
|
+
assert_equal "/child-page/test-page", page.full_path
|
275
285
|
|
276
286
|
Comfy::Cms::Page.destroy_all
|
277
287
|
page = @site.pages.new(new_params)
|
278
288
|
assert page.valid?
|
279
|
-
assert_equal
|
289
|
+
assert_equal "/", page.full_path
|
280
290
|
end
|
281
291
|
|
282
292
|
def test_sync_child_pages
|
283
293
|
page = comfy_cms_pages(:child)
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
assert_equal
|
290
|
-
assert_equal
|
291
|
-
assert_equal
|
292
|
-
assert_equal
|
293
|
-
|
294
|
-
page.update_attributes!(slug:
|
295
|
-
assert_equal
|
296
|
-
|
297
|
-
assert_equal
|
298
|
-
assert_equal
|
299
|
-
assert_equal
|
300
|
-
assert_equal
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
assert_equal
|
305
|
-
assert_equal
|
306
|
-
assert_equal
|
307
|
-
assert_equal
|
294
|
+
page_a = @site.pages.create!(new_params(parent: page, slug: "test-page-1"))
|
295
|
+
page_b = @site.pages.create!(new_params(parent: page, slug: "test-page-2"))
|
296
|
+
page_c = @site.pages.create!(new_params(parent: page_b, slug: "test-page-3"))
|
297
|
+
page_d = @site.pages.create!(new_params(parent: page_a, slug: "test-page-4"))
|
298
|
+
|
299
|
+
assert_equal "/child-page/test-page-1", page_a.full_path
|
300
|
+
assert_equal "/child-page/test-page-2", page_b.full_path
|
301
|
+
assert_equal "/child-page/test-page-2/test-page-3", page_c.full_path
|
302
|
+
assert_equal "/child-page/test-page-1/test-page-4", page_d.full_path
|
303
|
+
|
304
|
+
page.update_attributes!(slug: "updated-page")
|
305
|
+
assert_equal "/updated-page", page.full_path
|
306
|
+
[page_a, page_b, page_c, page_d].each(&:reload)
|
307
|
+
assert_equal "/updated-page/test-page-1", page_a.full_path
|
308
|
+
assert_equal "/updated-page/test-page-2", page_b.full_path
|
309
|
+
assert_equal "/updated-page/test-page-2/test-page-3", page_c.full_path
|
310
|
+
assert_equal "/updated-page/test-page-1/test-page-4", page_d.full_path
|
311
|
+
|
312
|
+
page_b.update_attributes!(parent: page_a)
|
313
|
+
[page_a, page_b, page_c, page_d].each(&:reload)
|
314
|
+
assert_equal "/updated-page/test-page-1", page_a.full_path
|
315
|
+
assert_equal "/updated-page/test-page-1/test-page-2", page_b.full_path
|
316
|
+
assert_equal "/updated-page/test-page-1/test-page-2/test-page-3", page_c.full_path
|
317
|
+
assert_equal "/updated-page/test-page-1/test-page-4", page_d.full_path
|
308
318
|
end
|
309
319
|
|
310
320
|
def test_children_count_updating
|
311
|
-
|
312
|
-
|
313
|
-
assert_equal 1,
|
314
|
-
assert_equal 0,
|
321
|
+
page_a = @page
|
322
|
+
page_b = comfy_cms_pages(:child)
|
323
|
+
assert_equal 1, page_a.children_count
|
324
|
+
assert_equal 0, page_b.children_count
|
315
325
|
|
316
|
-
|
317
|
-
|
318
|
-
assert_equal 1,
|
319
|
-
assert_equal 1,
|
320
|
-
assert_equal 0,
|
326
|
+
page_c = @site.pages.create!(new_params(parent: page_b))
|
327
|
+
[page_a, page_b].each(&:reload)
|
328
|
+
assert_equal 1, page_a.children_count
|
329
|
+
assert_equal 1, page_b.children_count
|
330
|
+
assert_equal 0, page_c.children_count
|
321
331
|
|
322
|
-
|
323
|
-
|
324
|
-
assert_equal 2,
|
325
|
-
assert_equal 0,
|
332
|
+
page_c.update_attributes!(parent: page_a)
|
333
|
+
[page_a, page_b].each(&:reload)
|
334
|
+
assert_equal 2, page_a.children_count
|
335
|
+
assert_equal 0, page_b.children_count
|
326
336
|
|
327
|
-
|
328
|
-
|
329
|
-
assert_equal 1,
|
330
|
-
assert_equal 0,
|
337
|
+
page_c.destroy
|
338
|
+
[page_a, page_b].each(&:reload)
|
339
|
+
assert_equal 1, page_a.children_count
|
340
|
+
assert_equal 0, page_b.children_count
|
331
341
|
end
|
332
342
|
|
333
343
|
def test_cascading_destroy
|
@@ -341,16 +351,16 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
341
351
|
end
|
342
352
|
|
343
353
|
def test_options_for_select
|
344
|
-
assert_equal [
|
345
|
-
Comfy::Cms::Page.options_for_select(@site).collect
|
346
|
-
assert_equal [
|
347
|
-
Comfy::Cms::Page.options_for_select(@site, comfy_cms_pages(:child)).collect
|
354
|
+
assert_equal ["Default Page", ". . Child Page"],
|
355
|
+
Comfy::Cms::Page.options_for_select(site: @site).collect(&:first)
|
356
|
+
assert_equal ["Default Page"],
|
357
|
+
Comfy::Cms::Page.options_for_select(site: @site, page: comfy_cms_pages(:child)).collect(&:first)
|
348
358
|
assert_equal [],
|
349
|
-
Comfy::Cms::Page.options_for_select(@site, @page)
|
359
|
+
Comfy::Cms::Page.options_for_select(site: @site, page: @page)
|
350
360
|
|
351
361
|
page = Comfy::Cms::Page.new(new_params(parent: @page))
|
352
|
-
assert_equal [
|
353
|
-
Comfy::Cms::Page.options_for_select(@site, page).collect
|
362
|
+
assert_equal ["Default Page", ". . Child Page"],
|
363
|
+
Comfy::Cms::Page.options_for_select(site: @site, page: page).collect(&:first)
|
354
364
|
end
|
355
365
|
|
356
366
|
def test_fragments_attributes
|
@@ -440,7 +450,7 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
440
450
|
def test_content_caching
|
441
451
|
assert_equal @page.content_cache, @page.render
|
442
452
|
|
443
|
-
@page.update_columns(content_cache:
|
453
|
+
@page.update_columns(content_cache: "Old Content")
|
444
454
|
refute_equal @page.content_cache, @page.render
|
445
455
|
|
446
456
|
@page.clear_content_cache!
|
@@ -448,7 +458,7 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
448
458
|
end
|
449
459
|
|
450
460
|
def test_content_cache_clear_on_save
|
451
|
-
old_content =
|
461
|
+
old_content = "Old Content"
|
452
462
|
@page.update_columns(content_cache: old_content)
|
453
463
|
|
454
464
|
@page.save!
|
@@ -467,74 +477,74 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
467
477
|
end
|
468
478
|
|
469
479
|
def test_url
|
470
|
-
assert_equal
|
471
|
-
assert_equal
|
480
|
+
assert_equal "//test.host/", @page.url
|
481
|
+
assert_equal "//test.host/child-page", comfy_cms_pages(:child).url
|
472
482
|
|
473
|
-
assert_equal
|
474
|
-
assert_equal
|
483
|
+
assert_equal "/", @page.url(relative: true)
|
484
|
+
assert_equal "/child-page", comfy_cms_pages(:child).url(relative: true)
|
475
485
|
|
476
|
-
@site.update_columns(path:
|
486
|
+
@site.update_columns(path: "/en/site")
|
477
487
|
@page.reload
|
478
488
|
comfy_cms_pages(:child).reload
|
479
489
|
|
480
|
-
assert_equal
|
481
|
-
assert_equal
|
490
|
+
assert_equal "//test.host/en/site/", @page.url
|
491
|
+
assert_equal "//test.host/en/site/child-page", comfy_cms_pages(:child).url
|
482
492
|
|
483
|
-
assert_equal
|
484
|
-
assert_equal
|
493
|
+
assert_equal "/en/site/", @page.url(relative: true)
|
494
|
+
assert_equal "/en/site/child-page", comfy_cms_pages(:child).url(relative: true)
|
485
495
|
end
|
486
496
|
|
487
497
|
def test_url_with_public_cms_path
|
488
|
-
ComfortableMexicanSofa.config.public_cms_path =
|
489
|
-
assert_equal
|
490
|
-
assert_equal
|
498
|
+
ComfortableMexicanSofa.config.public_cms_path = "/custom"
|
499
|
+
assert_equal "//test.host/custom/", @page.url
|
500
|
+
assert_equal "//test.host/custom/child-page", comfy_cms_pages(:child).url
|
491
501
|
|
492
|
-
assert_equal
|
493
|
-
assert_equal
|
502
|
+
assert_equal "/custom/", @page.url(relative: true)
|
503
|
+
assert_equal "/custom/child-page", comfy_cms_pages(:child).url(relative: true)
|
494
504
|
end
|
495
505
|
|
496
506
|
def test_unicode_slug_escaping
|
497
507
|
page = comfy_cms_pages(:child)
|
498
|
-
|
499
|
-
assert_equal CGI
|
500
|
-
assert_equal CGI
|
508
|
+
page_a = @site.pages.create!(new_params(parent: page, slug: "tést-ünicode-slug"))
|
509
|
+
assert_equal CGI.escape("tést-ünicode-slug"), page_a.slug
|
510
|
+
assert_equal CGI.escape("/child-page/tést-ünicode-slug").gsub("%2F", "/"), page_a.full_path
|
501
511
|
end
|
502
512
|
|
503
513
|
def test_unicode_slug_unescaping
|
504
514
|
page = comfy_cms_pages(:child)
|
505
|
-
|
506
|
-
found_page = @site.pages.where(slug: CGI
|
507
|
-
assert_equal
|
508
|
-
assert_equal
|
515
|
+
@site.pages.create!(new_params(parent: page, slug: "tést-ünicode-slug"))
|
516
|
+
found_page = @site.pages.where(slug: CGI.escape("tést-ünicode-slug")).first
|
517
|
+
assert_equal "tést-ünicode-slug", found_page.slug
|
518
|
+
assert_equal "/child-page/tést-ünicode-slug", found_page.full_path
|
509
519
|
end
|
510
520
|
|
511
521
|
def test_identifier
|
512
|
-
assert_equal
|
513
|
-
assert_equal
|
522
|
+
assert_equal "index", @page.identifier
|
523
|
+
assert_equal "child-page", comfy_cms_pages(:child).identifier
|
514
524
|
|
515
|
-
@page.update_column(:slug,
|
516
|
-
assert_equal
|
525
|
+
@page.update_column(:slug, "index")
|
526
|
+
assert_equal "index", comfy_cms_pages(:default).identifier
|
517
527
|
end
|
518
528
|
|
519
529
|
def test_children_count_updating_on_move
|
520
|
-
|
521
|
-
|
522
|
-
|
530
|
+
page_a = @page
|
531
|
+
page_b = comfy_cms_pages(:child)
|
532
|
+
page_c = @site.pages.create!(new_params(parent: page_b))
|
523
533
|
|
524
|
-
|
534
|
+
page_b.reload
|
525
535
|
|
526
|
-
assert_equal 1,
|
527
|
-
assert_equal 1,
|
528
|
-
assert_equal 0,
|
536
|
+
assert_equal 1, page_a.children_count
|
537
|
+
assert_equal 1, page_b.children_count
|
538
|
+
assert_equal 0, page_c.children_count
|
529
539
|
|
530
|
-
|
531
|
-
|
540
|
+
page_c.parent_id = page_a.id
|
541
|
+
page_c.save!
|
532
542
|
|
533
|
-
|
543
|
+
[page_a, page_b, page_c].each(&:reload)
|
534
544
|
|
535
|
-
assert_equal 2,
|
536
|
-
assert_equal 0,
|
537
|
-
assert_equal 0,
|
545
|
+
assert_equal 2, page_a.children_count
|
546
|
+
assert_equal 0, page_b.children_count
|
547
|
+
assert_equal 0, page_c.children_count
|
538
548
|
end
|
539
549
|
|
540
550
|
def test_translate
|
@@ -545,8 +555,8 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
545
555
|
assert @page.readonly?
|
546
556
|
|
547
557
|
assert_equal comfy_cms_layouts(:nested), @page.layout
|
548
|
-
assert_equal
|
549
|
-
assert_equal
|
558
|
+
assert_equal "Default Translation", @page.label
|
559
|
+
assert_equal "Translation Content", @page.content_cache
|
550
560
|
end
|
551
561
|
|
552
562
|
def test_translate_with_unpublished
|
@@ -561,4 +571,5 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
561
571
|
@page.translate!(:es)
|
562
572
|
end
|
563
573
|
end
|
574
|
+
|
564
575
|
end
|
data/test/models/site_test.rb
CHANGED
@@ -15,7 +15,7 @@ class CmsSiteTest < ActiveSupport::TestCase
|
|
15
15
|
def test_validation
|
16
16
|
site = Comfy::Cms::Site.new
|
17
17
|
assert site.invalid?
|
18
|
-
assert_has_errors_on site,
|
18
|
+
assert_has_errors_on site, :identifier, :label, :hostname
|
19
19
|
|
20
20
|
site = Comfy::Cms::Site.new(identifier: "test", hostname: "http://site.host")
|
21
21
|
assert site.invalid?
|
@@ -140,24 +140,24 @@ class CmsSiteTest < ActiveSupport::TestCase
|
|
140
140
|
end
|
141
141
|
|
142
142
|
def test_find_site_with_public_cms_path
|
143
|
-
ComfortableMexicanSofa.config.public_cms_path =
|
144
|
-
assert_equal
|
143
|
+
ComfortableMexicanSofa.config.public_cms_path = "/custom"
|
144
|
+
assert_equal "//test.host/custom", comfy_cms_sites(:default).url
|
145
145
|
|
146
|
-
site_a = Comfy::Cms::Site.create!(identifier:
|
147
|
-
site_b = Comfy::Cms::Site.create!(identifier:
|
146
|
+
site_a = Comfy::Cms::Site.create!(identifier: "test_a", hostname: "test2.host", path: "en")
|
147
|
+
site_b = Comfy::Cms::Site.create!(identifier: "test_b", hostname: "test2.host", path: "fr")
|
148
148
|
|
149
|
-
assert_nil Comfy::Cms::Site.find_site(
|
150
|
-
assert_nil Comfy::Cms::Site.find_site(
|
151
|
-
assert_equal site_a, Comfy::Cms::Site.find_site(
|
152
|
-
assert_equal site_a, Comfy::Cms::Site.find_site(
|
153
|
-
assert_equal site_a, Comfy::Cms::Site.find_site(
|
149
|
+
assert_nil Comfy::Cms::Site.find_site("test2.host")
|
150
|
+
assert_nil Comfy::Cms::Site.find_site("test2.host", "/custom/some/path")
|
151
|
+
assert_equal site_a, Comfy::Cms::Site.find_site("test2.host", "/custom/en")
|
152
|
+
assert_equal site_a, Comfy::Cms::Site.find_site("test2.host", "/custom/en?a=b")
|
153
|
+
assert_equal site_a, Comfy::Cms::Site.find_site("test2.host", "/custom/en/some/path?a=b")
|
154
154
|
|
155
|
-
assert_nil Comfy::Cms::Site.find_site(
|
155
|
+
assert_nil Comfy::Cms::Site.find_site("test2.host", "/custom/english/some/path")
|
156
156
|
|
157
|
-
assert_equal site_b, Comfy::Cms::Site.find_site(
|
158
|
-
assert_equal site_b, Comfy::Cms::Site.find_site(
|
159
|
-
assert_equal site_b, Comfy::Cms::Site.find_site(
|
160
|
-
assert_equal site_b, Comfy::Cms::Site.find_site(
|
157
|
+
assert_equal site_b, Comfy::Cms::Site.find_site("test2.host", "/custom/fr")
|
158
|
+
assert_equal site_b, Comfy::Cms::Site.find_site("test2.host", "/custom/fr?a=b")
|
159
|
+
assert_equal site_b, Comfy::Cms::Site.find_site("test2.host", "/custom/fr/some/path")
|
160
|
+
assert_equal site_b, Comfy::Cms::Site.find_site("test2.host", "/custom/fr/some/path?a=b")
|
161
161
|
end
|
162
162
|
|
163
163
|
def test_find_site_with_site_alias
|
@@ -166,7 +166,7 @@ class CmsSiteTest < ActiveSupport::TestCase
|
|
166
166
|
|
167
167
|
ComfortableMexicanSofa.config.hostname_aliases = {
|
168
168
|
"test.host" => "alias_a.host",
|
169
|
-
"test2.host" => %w
|
169
|
+
"test2.host" => %w[alias_b.host alias_c.host]
|
170
170
|
}
|
171
171
|
|
172
172
|
assert_equal site_a, Comfy::Cms::Site.find_site("alias_a.host")
|
@@ -186,4 +186,5 @@ class CmsSiteTest < ActiveSupport::TestCase
|
|
186
186
|
|
187
187
|
assert_equal "/cms/site-path", @site.url(relative: true)
|
188
188
|
end
|
189
|
+
|
189
190
|
end
|
data/test/models/snippet_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "../test_helper"
|
2
2
|
|
3
3
|
class CmsPageTest < ActiveSupport::TestCase
|
4
4
|
|
@@ -57,4 +57,5 @@ class CmsPageTest < ActiveSupport::TestCase
|
|
57
57
|
comfy_cms_translations(:default).update_columns(is_published: false)
|
58
58
|
assert_equal 0, Comfy::Cms::Translation.published.count
|
59
59
|
end
|
60
|
+
|
60
61
|
end
|
@@ -12,7 +12,7 @@ class CmsSeedsTaskTest < ActiveSupport::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_import
|
15
|
-
importer = mock
|
15
|
+
importer = mock
|
16
16
|
ComfortableMexicanSofa::Seeds::Importer.expects(:new).with("from_folder", "to_site").returns(importer)
|
17
17
|
importer.expects(:import!)
|
18
18
|
|
@@ -22,7 +22,7 @@ class CmsSeedsTaskTest < ActiveSupport::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_export
|
25
|
-
exporter = mock
|
25
|
+
exporter = mock
|
26
26
|
ComfortableMexicanSofa::Seeds::Exporter.expects(:new).with("from_site", "to_folder").returns(exporter)
|
27
27
|
exporter.expects(:export!)
|
28
28
|
|
@@ -30,4 +30,5 @@ class CmsSeedsTaskTest < ActiveSupport::TestCase
|
|
30
30
|
@rake["comfy:cms_seeds:export"].invoke("from_site", "to_folder")
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
33
34
|
end
|