comfortable_mexican_sofa 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +12 -5
  3. data/app/models/comfy/cms/translation.rb +2 -0
  4. data/app/views/comfy/admin/cms/fragments/_form_fragments.html.haml +4 -2
  5. data/lib/comfortable_mexican_sofa/content/renderer.rb +11 -3
  6. data/lib/comfortable_mexican_sofa/content/tag.rb +6 -9
  7. data/lib/comfortable_mexican_sofa/content/tags/asset.rb +1 -1
  8. data/lib/comfortable_mexican_sofa/content/tags/file.rb +1 -1
  9. data/lib/comfortable_mexican_sofa/content/tags/file_link.rb +1 -1
  10. data/lib/comfortable_mexican_sofa/content/tags/files.rb +1 -1
  11. data/lib/comfortable_mexican_sofa/content/tags/fragment.rb +2 -2
  12. data/lib/comfortable_mexican_sofa/content/tags/helper.rb +1 -1
  13. data/lib/comfortable_mexican_sofa/content/tags/partial.rb +1 -1
  14. data/lib/comfortable_mexican_sofa/content/tags/snippet.rb +1 -1
  15. data/lib/comfortable_mexican_sofa/content/tags/template.rb +1 -1
  16. data/lib/comfortable_mexican_sofa/version.rb +1 -1
  17. data/test/controllers/comfy/admin/cms/pages_controller_test.rb +8 -5
  18. data/test/controllers/comfy/cms/content_controller_test.rb +16 -0
  19. data/test/lib/content/block_test.rb +1 -1
  20. data/test/lib/content/renderer_test.rb +39 -8
  21. data/test/lib/content/tag_test.rb +10 -4
  22. data/test/lib/content/tags/asset_test.rb +35 -11
  23. data/test/lib/content/tags/checkbox_test.rb +2 -2
  24. data/test/lib/content/tags/date_test.rb +2 -2
  25. data/test/lib/content/tags/datetime_test.rb +2 -2
  26. data/test/lib/content/tags/file_link_test.rb +25 -10
  27. data/test/lib/content/tags/file_test.rb +20 -7
  28. data/test/lib/content/tags/files_test.rb +12 -5
  29. data/test/lib/content/tags/fragment_test.rb +14 -10
  30. data/test/lib/content/tags/helper_test.rb +18 -9
  31. data/test/lib/content/tags/markdown_test.rb +7 -4
  32. data/test/lib/content/tags/number_test.rb +1 -1
  33. data/test/lib/content/tags/partial_test.rb +28 -7
  34. data/test/lib/content/tags/snippet_test.rb +5 -5
  35. data/test/lib/content/tags/template_test.rb +21 -6
  36. data/test/lib/content/tags/text_test.rb +1 -1
  37. data/test/lib/content/tags/textarea_test.rb +1 -1
  38. data/test/lib/content/tags/wysiwyg_test.rb +1 -1
  39. data/test/models/layout_test.rb +34 -14
  40. data/test/models/translation_test.rb +10 -4
  41. metadata +3 -3
@@ -7,7 +7,7 @@ class ContentTagsSnippetTest < ActiveSupport::TestCase
7
7
  end
8
8
 
9
9
  def test_init
10
- tag = ComfortableMexicanSofa::Content::Tag::Snippet.new(@page, "default")
10
+ tag = ComfortableMexicanSofa::Content::Tag::Snippet.new(context: @page, params: ["default"])
11
11
  assert_equal "default", tag.identifier
12
12
  assert_equal comfy_cms_snippets(:default), tag.snippet
13
13
  end
@@ -15,22 +15,22 @@ class ContentTagsSnippetTest < ActiveSupport::TestCase
15
15
  def test_init_without_identifier
16
16
  message = "Missing identifier for snippet tag"
17
17
  assert_exception_raised ComfortableMexicanSofa::Content::Tag::Error, message do
18
- ComfortableMexicanSofa::Content::Tag::Snippet.new(@page, "")
18
+ ComfortableMexicanSofa::Content::Tag::Snippet.new(context: @page)
19
19
  end
20
20
  end
21
21
 
22
22
  def test_snippet_new_record
23
- tag = ComfortableMexicanSofa::Content::Tag::Snippet.new(@page, "new")
23
+ tag = ComfortableMexicanSofa::Content::Tag::Snippet.new(context: @page, params: ["new"])
24
24
  assert tag.snippet.new_record?
25
25
  end
26
26
 
27
27
  def test_content
28
- tag = ComfortableMexicanSofa::Content::Tag::Snippet.new(@page, "default")
28
+ tag = ComfortableMexicanSofa::Content::Tag::Snippet.new(context: @page, params: ["default"])
29
29
  assert_equal "snippet content", tag.content
30
30
  end
31
31
 
32
32
  def test_content_new_record
33
- tag = ComfortableMexicanSofa::Content::Tag::Snippet.new(@page, "new")
33
+ tag = ComfortableMexicanSofa::Content::Tag::Snippet.new(context: @page, params: ["new"])
34
34
  assert_nil tag.content
35
35
  end
36
36
 
@@ -3,33 +3,48 @@ require_relative "../../../test_helper"
3
3
  class ContentTagsTemplateTest < ActiveSupport::TestCase
4
4
 
5
5
  def test_init
6
- tag = ComfortableMexicanSofa::Content::Tag::Template.new(@page, "path/to/template")
6
+ tag = ComfortableMexicanSofa::Content::Tag::Template.new(
7
+ context: @page,
8
+ params: ["path/to/template"]
9
+ )
7
10
  assert_equal "path/to/template", tag.path
8
11
  end
9
12
 
10
13
  def test_init_without_path
11
14
  message = "Missing template path for template tag"
12
15
  assert_exception_raised ComfortableMexicanSofa::Content::Tag::Error, message do
13
- ComfortableMexicanSofa::Content::Tag::Template.new(@page, "")
16
+ ComfortableMexicanSofa::Content::Tag::Template.new(context: @page)
14
17
  end
15
18
  end
16
19
 
17
20
  def test_content
18
- tag = ComfortableMexicanSofa::Content::Tag::Template.new(@page, "path/to/template")
21
+ tag = ComfortableMexicanSofa::Content::Tag::Template.new(
22
+ context: @page,
23
+ params: ["path/to/template"]
24
+ )
19
25
  assert_equal "<%= render template: \"path/to/template\" %>", tag.content
20
26
  end
21
27
 
22
28
  def test_render
23
- tag = ComfortableMexicanSofa::Content::Tag::Template.new(@page, "path/to/template")
29
+ tag = ComfortableMexicanSofa::Content::Tag::Template.new(
30
+ context: @page,
31
+ params: ["path/to/template"]
32
+ )
24
33
  assert_equal "<%= render template: \"path/to/template\" %>", tag.render
25
34
  end
26
35
 
27
36
  def test_render_with_whitelist
28
37
  ComfortableMexicanSofa.config.allowed_templates = ["allowed/path"]
29
- tag = ComfortableMexicanSofa::Content::Tag::Template.new(@page, "allowed/path")
38
+ tag = ComfortableMexicanSofa::Content::Tag::Template.new(
39
+ context: @page,
40
+ params: ["allowed/path"]
41
+ )
30
42
  assert_equal "<%= render template: \"allowed/path\" %>", tag.render
31
43
 
32
- tag = ComfortableMexicanSofa::Content::Tag::Template.new(@page, "not_allowed/path")
44
+ tag = ComfortableMexicanSofa::Content::Tag::Template.new(
45
+ context: @page,
46
+ params: ["not_allowed/path"]
47
+ )
33
48
  assert_equal "", tag.render
34
49
  end
35
50
 
@@ -7,7 +7,7 @@ class ContentTagsTextTest < ActiveSupport::TestCase
7
7
  end
8
8
 
9
9
  def test_init
10
- tag = ComfortableMexicanSofa::Content::Tag::Text.new(@page, "test")
10
+ tag = ComfortableMexicanSofa::Content::Tag::Text.new(context: @page, params: ["test"])
11
11
  assert_equal "test", tag.identifier
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ class ContentTagsTextAreaTest < ActiveSupport::TestCase
7
7
  end
8
8
 
9
9
  def test_init
10
- tag = ComfortableMexicanSofa::Content::Tag::TextArea.new(@page, "test")
10
+ tag = ComfortableMexicanSofa::Content::Tag::TextArea.new(context: @page, params: ["test"])
11
11
  assert_equal "test", tag.identifier
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ class ContentTagsWysiwygTest < ActiveSupport::TestCase
7
7
  end
8
8
 
9
9
  def test_init
10
- tag = ComfortableMexicanSofa::Content::Tag::Wysiwyg.new(@page, "test")
10
+ tag = ComfortableMexicanSofa::Content::Tag::Wysiwyg.new(context: @page, params: ["test"])
11
11
  assert_equal "test", tag.identifier
12
12
  end
13
13
 
@@ -22,44 +22,64 @@ class CmsLayoutTest < ActiveSupport::TestCase
22
22
 
23
23
  def test_content_tokens
24
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
25
+ expected = [
26
+ "a ",
27
+ { tag_class: "text", tag_params: "content", source: "{{cms:text content}}" },
28
+ " b"
29
+ ]
30
+ assert_equal expected, layout.content_tokens
27
31
  end
28
32
 
29
33
  def test_content_tokens_nested
30
34
  layout_a = Comfy::Cms::Layout.new(content: "a {{cms:text content}} {{cms:text footer}} b")
31
35
  layout_b = Comfy::Cms::Layout.new(content: "c {{cms:text content}} d")
32
36
  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
+ expected = [
38
+ "a ",
39
+ "c ",
40
+ { tag_class: "text", tag_params: "content", source: "{{cms:text content}}" },
41
+ " d",
42
+ " ",
43
+ { tag_class: "text", tag_params: "footer", source: "{{cms:text footer}}" },
44
+ " b"
45
+ ]
46
+ assert_equal expected, layout_b.content_tokens
37
47
  end
38
48
 
39
49
  def test_content_tokens_nested_with_fragment_subclass_tag
40
50
  layout_a = Comfy::Cms::Layout.new(content: "a {{cms:markdown content}} b")
41
51
  layout_b = Comfy::Cms::Layout.new(content: "c {{cms:text content}} d")
42
52
  layout_b.parent = layout_a
43
- assert_equal [
44
- "a ", "c ", { tag_class: "text", tag_params: "content" }, " d", " b"
45
- ], layout_b.content_tokens
53
+ expected = [
54
+ "a ",
55
+ "c ",
56
+ { tag_class: "text", tag_params: "content", source: "{{cms:text content}}" },
57
+ " d",
58
+ " b"
59
+ ]
60
+ assert_equal expected, layout_b.content_tokens
46
61
  end
47
62
 
48
63
  def test_content_tokens_nested_with_non_fragment_subclass_tag
49
64
  layout_a = Comfy::Cms::Layout.new(content: "a {{cms:snippet content}} b")
50
65
  layout_b = Comfy::Cms::Layout.new(content: "c {{cms:text content}} d")
51
66
  layout_b.parent = layout_a
52
- assert_equal [
53
- "c ", { tag_class: "text", tag_params: "content" }, " d"
54
- ], layout_b.content_tokens
67
+ expected = [
68
+ "c ",
69
+ { tag_class: "text", tag_params: "content", source: "{{cms:text content}}" },
70
+ " d"
71
+ ]
72
+ assert_equal expected, layout_b.content_tokens
55
73
  end
56
74
 
57
75
  def test_content_tokens_nested_without_content_tag
58
76
  layout_a = Comfy::Cms::Layout.new(content: "a {{cms:text footer}} b")
59
77
  layout_b = Comfy::Cms::Layout.new(content: "c {{cms:text content}} d")
60
78
  layout_b.parent = layout_a
61
- assert_equal ["c ", { tag_class: "text", tag_params: "content" }, " d"],
62
- layout_b.content_tokens
79
+ expected = [
80
+ "c ", { tag_class: "text", tag_params: "content", source: "{{cms:text content}}" }, " d"
81
+ ]
82
+ assert_equal expected, layout_b.content_tokens
63
83
  end
64
84
 
65
85
  def test_label_assignment
@@ -3,7 +3,9 @@ require_relative "../test_helper"
3
3
  class CmsPageTest < ActiveSupport::TestCase
4
4
 
5
5
  setup do
6
- @page = comfy_cms_pages(:default)
6
+ @site = comfy_cms_sites(:default)
7
+ @page = comfy_cms_pages(:default)
8
+ @translation = comfy_cms_translations(:default)
7
9
  end
8
10
 
9
11
  def test_fixtures_validity
@@ -22,7 +24,7 @@ class CmsPageTest < ActiveSupport::TestCase
22
24
  def test_validation_on_locale_uniqueness
23
25
  translation = @page.translations.new(
24
26
  label: "Test",
25
- locale: comfy_cms_translations(:default).locale
27
+ locale: @translation.locale
26
28
  )
27
29
  assert translation.invalid?
28
30
  assert_has_errors_on translation, :locale
@@ -31,7 +33,7 @@ class CmsPageTest < ActiveSupport::TestCase
31
33
  def test_validation_on_locale_uniqueness_against_site
32
34
  translation = @page.translations.new(
33
35
  label: "Test",
34
- locale: comfy_cms_sites(:default).locale
36
+ locale: @site.locale
35
37
  )
36
38
  assert translation.invalid?
37
39
  assert_has_errors_on translation, :locale
@@ -54,8 +56,12 @@ class CmsPageTest < ActiveSupport::TestCase
54
56
 
55
57
  def test_scope_published
56
58
  assert_equal 1, Comfy::Cms::Translation.published.count
57
- comfy_cms_translations(:default).update_columns(is_published: false)
59
+ @translation.update_columns(is_published: false)
58
60
  assert_equal 0, Comfy::Cms::Translation.published.count
59
61
  end
60
62
 
63
+ def test_site_delegation
64
+ assert_equal @site, @translation.site
65
+ end
66
+
61
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comfortable_mexican_sofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Khabarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-10 00:00:00.000000000 Z
11
+ date: 2018-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_link_to
@@ -746,7 +746,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
746
746
  version: '0'
747
747
  requirements: []
748
748
  rubyforge_project:
749
- rubygems_version: 2.6.11
749
+ rubygems_version: 2.7.4
750
750
  signing_key:
751
751
  specification_version: 4
752
752
  summary: Rails 5.2+ CMS Engine