comfortable_mexican_sofa 1.8.3 → 1.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. data/.gitignore +1 -1
  2. data/Gemfile +2 -2
  3. data/README.md +3 -3
  4. data/app/assets/stylesheets/comfortable_mexican_sofa/base.css.sass +11 -11
  5. data/app/assets/stylesheets/comfortable_mexican_sofa/bootstrap_overrides.css.sass +2 -2
  6. data/app/controllers/cms_admin/base_controller.rb +1 -1
  7. data/app/controllers/cms_content_controller.rb +1 -1
  8. data/app/models/cms/block.rb +1 -1
  9. data/app/models/cms/file.rb +4 -1
  10. data/config/database.yml +1 -1
  11. data/db/cms_fixtures/sample-site/categories/files.yml +1 -0
  12. data/db/cms_fixtures/sample-site/categories/pages.yml +1 -0
  13. data/db/cms_fixtures/sample-site/categories/snippets.yml +1 -0
  14. data/db/cms_fixtures/sample-site/files/_sample.jpg.yml +5 -0
  15. data/db/cms_fixtures/sample-site/files/sample.jpg +0 -0
  16. data/db/cms_fixtures/sample-site/layouts/default/{_default.yml → attributes.yml} +0 -0
  17. data/db/cms_fixtures/sample-site/layouts/default/{js.js → javascript.js} +0 -0
  18. data/db/cms_fixtures/sample-site/layouts/default/nested/{_nested.yml → attributes.yml} +0 -0
  19. data/db/cms_fixtures/sample-site/layouts/default/nested/{js.js → javascript.js} +0 -0
  20. data/db/cms_fixtures/sample-site/layouts/default/nested/{css.css → stylesheet.css} +0 -0
  21. data/db/cms_fixtures/sample-site/layouts/default/{css.css → stylesheet.css} +0 -0
  22. data/db/cms_fixtures/sample-site/pages/index/attributes.yml +6 -0
  23. data/db/cms_fixtures/sample-site/pages/index/child/{_child.yml → attributes.yml} +0 -0
  24. data/db/cms_fixtures/sample-site/snippets/default/attributes.yml +4 -0
  25. data/lib/comfortable_mexican_sofa.rb +25 -23
  26. data/lib/comfortable_mexican_sofa/fixture.rb +77 -0
  27. data/lib/comfortable_mexican_sofa/fixture/category.rb +35 -0
  28. data/lib/comfortable_mexican_sofa/fixture/file.rb +70 -0
  29. data/lib/comfortable_mexican_sofa/fixture/layout.rb +90 -0
  30. data/lib/comfortable_mexican_sofa/fixture/page.rb +122 -0
  31. data/lib/comfortable_mexican_sofa/fixture/snippet.rb +71 -0
  32. data/lib/comfortable_mexican_sofa/version.rb +1 -1
  33. data/lib/tasks/comfortable_mexican_sofa.rake +17 -20
  34. data/test/fixtures/cms/files.yml +2 -2
  35. data/test/functional/cms_admin/base_controller_test.rb +1 -1
  36. data/test/functional/cms_admin/categories_controller_test.rb +1 -1
  37. data/test/functional/cms_admin/files_controller_test.rb +1 -1
  38. data/test/functional/cms_admin/layouts_controller_test.rb +1 -1
  39. data/test/functional/cms_admin/pages_controller_test.rb +1 -1
  40. data/test/functional/cms_admin/revisions_controller_test.rb +1 -1
  41. data/test/functional/cms_admin/sites_controller_test.rb +1 -1
  42. data/test/functional/cms_admin/snippets_controller_test.rb +1 -1
  43. data/test/functional/cms_content_controller_test.rb +1 -1
  44. data/test/gemfiles/Gemfile.rails.3.1 +2 -1
  45. data/test/gemfiles/Gemfile.rails.3.2 +2 -1
  46. data/test/integration/authentication_test.rb +1 -1
  47. data/test/integration/fixtures_test.rb +5 -3
  48. data/test/integration/mirrors_test.rb +1 -1
  49. data/test/integration/render_cms_test.rb +1 -1
  50. data/test/integration/sites_test.rb +1 -1
  51. data/test/integration/view_hooks_test.rb +1 -1
  52. data/test/test_helper.rb +1 -0
  53. data/test/unit/configuration_test.rb +1 -1
  54. data/test/unit/fixtures/_sample.jpg.yml +0 -0
  55. data/test/unit/fixtures/categories_test.rb +35 -0
  56. data/test/unit/fixtures/files_test.rb +100 -0
  57. data/test/unit/fixtures/layouts_test.rb +135 -0
  58. data/test/unit/fixtures/pages_test.rb +152 -0
  59. data/test/unit/fixtures/snippets_test.rb +101 -0
  60. data/test/unit/fixtures_test.rb +11 -325
  61. data/test/unit/mirrors_test.rb +1 -1
  62. data/test/unit/models/block_test.rb +1 -1
  63. data/test/unit/models/categorization_test.rb +1 -1
  64. data/test/unit/models/category_test.rb +1 -1
  65. data/test/unit/models/file_test.rb +11 -6
  66. data/test/unit/models/layout_test.rb +1 -1
  67. data/test/unit/models/page_test.rb +2 -1
  68. data/test/unit/models/site_test.rb +1 -1
  69. data/test/unit/models/snippet_test.rb +1 -1
  70. data/test/unit/revisions_test.rb +1 -1
  71. data/test/unit/sitemap_test.rb +1 -1
  72. data/test/unit/tag_test.rb +1 -1
  73. data/test/unit/tags/asset_test.rb +1 -1
  74. data/test/unit/tags/collection_test.rb +1 -1
  75. data/test/unit/tags/field_datetime_test.rb +1 -1
  76. data/test/unit/tags/field_integer_test.rb +1 -1
  77. data/test/unit/tags/field_rich_text_test.rb +1 -1
  78. data/test/unit/tags/field_string_test.rb +1 -1
  79. data/test/unit/tags/field_text_test.rb +1 -1
  80. data/test/unit/tags/file_test.rb +1 -1
  81. data/test/unit/tags/helper_test.rb +1 -1
  82. data/test/unit/tags/page_datetime_test.rb +1 -1
  83. data/test/unit/tags/page_file_test.rb +1 -1
  84. data/test/unit/tags/page_files_test.rb +1 -1
  85. data/test/unit/tags/page_integer_test.rb +1 -1
  86. data/test/unit/tags/page_markdown_test.rb +1 -1
  87. data/test/unit/tags/page_rich_text_test.rb +1 -1
  88. data/test/unit/tags/page_string_test.rb +1 -1
  89. data/test/unit/tags/page_text_test.rb +1 -1
  90. data/test/unit/tags/partial_test.rb +1 -1
  91. data/test/unit/tags/snippet_test.rb +1 -1
  92. data/test/unit/view_methods_test.rb +1 -1
  93. metadata +28 -12
  94. data/db/cms_fixtures/sample-site/pages/index/_index.yml +0 -2
  95. data/db/cms_fixtures/sample-site/snippets/default/_default.yml +0 -1
  96. data/lib/comfortable_mexican_sofa/fixtures.rb +0 -289
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.expand_path('../test_helper', File.dirname(__FILE__))
3
+ require_relative '../test_helper'
4
4
 
5
5
  class FixturesTest < ActionDispatch::IntegrationTest
6
6
 
@@ -29,13 +29,15 @@ class FixturesTest < ActionDispatch::IntegrationTest
29
29
  assert_difference 'Cms::Layout.count', 2 do
30
30
  assert_difference 'Cms::Snippet.count', 1 do
31
31
  get '/'
32
- assert_response :success
32
+ assert_response :redirect
33
+ assert_redirected_to 'http://test.host/child'
34
+ follow_redirect!
33
35
 
34
36
  assert_equal 'Home Fixture Page', Cms::Page.root.label
35
37
  assert_equal 'Default Fixture Layout', Cms::Layout.find_by_identifier('default').label
36
38
  assert_equal 'Default Fixture Snippet', Cms::Snippet.find_by_identifier('default').label
37
39
 
38
- assert_equal "<html>\n <body>\n Home Page Fixture Contént\nFixture Content for Default Snippet\n </body>\n</html>", response.body
40
+ assert_equal "<html>\n <body>\n <div class='left'> Child Page Left Fixture Content </div>\n<div class='right'> Child Page Right Fixture Content </div>\n </body>\n</html>", response.body
39
41
  end
40
42
  end
41
43
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
1
+ require_relative '../test_helper'
2
2
 
3
3
  class MirrorsTest < ActionDispatch::IntegrationTest
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
1
+ require_relative '../test_helper'
2
2
 
3
3
  class RenderCmsTest < ActionDispatch::IntegrationTest
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
1
+ require_relative '../test_helper'
2
2
 
3
3
  class SitesTest < ActionDispatch::IntegrationTest
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
1
+ require_relative '../test_helper'
2
2
 
3
3
  class ViewHooksTest < ActionDispatch::IntegrationTest
4
4
 
@@ -6,6 +6,7 @@ Coveralls.wear!('rails')
6
6
  ENV['RAILS_ENV'] = 'test'
7
7
  require File.expand_path('../../config/environment', __FILE__)
8
8
  require 'rails/test_help'
9
+ require 'mocha/setup'
9
10
 
10
11
  # No need to add cache-busters in test environment
11
12
  Paperclip::Attachment.default_options[:use_timestamp] = false
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.expand_path('../test_helper', File.dirname(__FILE__))
3
+ require_relative '../test_helper'
4
4
 
5
5
  class ConfigurationTest < ActiveSupport::TestCase
6
6
 
File without changes
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../test_helper'
4
+
5
+ class FixtureCategoriesTest < ActiveSupport::TestCase
6
+
7
+ def test_creation
8
+ assert_difference 'Cms::Category.count', 3 do
9
+ ComfortableMexicanSofa::Fixture::Category::Importer.new('sample-site', 'default-site').import!
10
+ assert Cms::Category.where(:label => 'File Category', :categorized_type => 'Cms::File').present?
11
+ assert Cms::Category.where(:label => 'Page Category', :categorized_type => 'Cms::Page').present?
12
+ assert Cms::Category.where(:label => 'Snippet Category', :categorized_type => 'Cms::Snippet').present?
13
+ end
14
+ end
15
+
16
+ def test_export
17
+ Cms::Category.delete_all
18
+ cms_sites(:default).categories.create!(:label => 'File', :categorized_type => 'Cms::File')
19
+ cms_sites(:default).categories.create!(:label => 'Page', :categorized_type => 'Cms::Page')
20
+ cms_sites(:default).categories.create!(:label => 'Snippet', :categorized_type => 'Cms::Snippet')
21
+
22
+ host_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'test-site')
23
+ ComfortableMexicanSofa::Fixture::Category::Exporter.new('default-site', 'test-site').export!
24
+ files_path = File.join(host_path, 'categories/files.yml')
25
+ pages_path = File.join(host_path, 'categories/pages.yml')
26
+ snippets_path = File.join(host_path, 'categories/snippets.yml')
27
+
28
+ assert_equal ['File'], YAML.load_file(files_path)
29
+ assert_equal ['Page'], YAML.load_file(pages_path)
30
+ assert_equal ['Snippet'], YAML.load_file(snippets_path)
31
+
32
+ FileUtils.rm_rf(host_path)
33
+ end
34
+
35
+ end
@@ -0,0 +1,100 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../test_helper'
4
+
5
+ class FixtureFilesTest < ActiveSupport::TestCase
6
+
7
+ def test_creation
8
+ Cms::File.delete_all
9
+
10
+ assert_difference 'Cms::File.count' do
11
+ ComfortableMexicanSofa::Fixture::File::Importer.new('sample-site', 'default-site').import!
12
+ assert file = Cms::File.last
13
+
14
+ assert_equal 'Fixture File', file.label
15
+ assert_equal 'sample.jpg', file.file_file_name
16
+ assert_equal 'Fixture Description', file.description
17
+
18
+ assert_equal 2, file.categories.count
19
+ assert_equal ['category_a', 'category_b'], file.categories.map{|c| c.label}
20
+ end
21
+ end
22
+
23
+ def test_update
24
+ file = cms_files(:default)
25
+ file.update_column(:updated_at, 10.years.ago)
26
+ assert_equal 'sample.jpg', file.file_file_name
27
+ assert_equal 'Default File', file.label
28
+ assert_equal 'Default Description', file.description
29
+
30
+ assert_no_difference 'Cms::Snippet.count' do
31
+ ComfortableMexicanSofa::Fixture::File::Importer.new('sample-site', 'default-site').import!
32
+ file.reload
33
+ assert_equal 'sample.jpg', file.file_file_name
34
+ assert_equal 'Fixture File', file.label
35
+ assert_equal 'Fixture Description', file.description
36
+ end
37
+ end
38
+
39
+ def test_update_ignore
40
+ file = cms_files(:default)
41
+ file_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'sample-site', 'files', 'sample.jpg')
42
+ attr_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'sample-site', 'files', '_sample.jpg.yml')
43
+
44
+ assert file.updated_at >= File.mtime(file_path)
45
+ assert file.updated_at >= File.mtime(attr_path)
46
+
47
+ ComfortableMexicanSofa::Fixture::File::Importer.new('sample-site', 'default-site').import!
48
+ file.reload
49
+ assert_equal 'sample.jpg', file.file_file_name
50
+ assert_equal 'Default File', file.label
51
+ assert_equal 'Default Description', file.description
52
+ end
53
+
54
+ def test_update_force
55
+ file = cms_files(:default)
56
+ ComfortableMexicanSofa::Fixture::File::Importer.new('sample-site', 'default-site').import!
57
+ file.reload
58
+ assert_equal 'Default File', file.label
59
+
60
+ ComfortableMexicanSofa::Fixture::File::Importer.new('sample-site', 'default-site', :forced).import!
61
+ file.reload
62
+ assert_equal 'Fixture File', file.label
63
+ end
64
+
65
+ def test_delete
66
+ old_file = cms_files(:default)
67
+ old_file.update_column(:file_file_name, 'old')
68
+
69
+ assert_no_difference 'Cms::File.count' do
70
+ ComfortableMexicanSofa::Fixture::File::Importer.new('sample-site', 'default-site').import!
71
+ assert file = Cms::File.last
72
+ assert_equal 'sample.jpg', file.file_file_name
73
+ assert_equal 'Fixture File', file.label
74
+ assert_equal 'Fixture Description', file.description
75
+
76
+ assert Cms::File.where(:id => old_file.id).blank?
77
+ end
78
+ end
79
+
80
+ def test_export
81
+ host_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'test-site')
82
+ attr_path = File.join(host_path, 'files/_sample.jpg.yml')
83
+ file_path = File.join(host_path, 'files/sample.jpg')
84
+
85
+ Paperclip::Attachment.any_instance.stubs(:path).
86
+ returns(File.join(Rails.root, 'db/cms_fixtures/sample-site/files/sample.jpg'))
87
+ ComfortableMexicanSofa::Fixture::File::Exporter.new('default-site', 'test-site').export!
88
+
89
+ assert File.exists?(attr_path)
90
+ assert File.exists?(file_path)
91
+ assert_equal ({
92
+ 'label' => 'Default File',
93
+ 'description' => 'Default Description',
94
+ 'categories' => ['Default']
95
+ }), YAML.load_file(attr_path)
96
+
97
+ FileUtils.rm_rf(host_path)
98
+ end
99
+
100
+ end
@@ -0,0 +1,135 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../test_helper'
4
+
5
+ class FixtureLayoutsTest < ActiveSupport::TestCase
6
+
7
+ def test_creation
8
+ Cms::Layout.delete_all
9
+
10
+ assert_difference 'Cms::Layout.count', 2 do
11
+ ComfortableMexicanSofa::Fixture::Layout::Importer.new('sample-site', 'default-site').import!
12
+
13
+ assert layout = Cms::Layout.where(:identifier => 'default').first
14
+ assert_equal 'Default Fixture Layout', layout.label
15
+ assert_equal "<html>\n <body>\n {{ cms:page:content }}\n </body>\n</html>", layout.content
16
+ assert_equal 'body{color: red}', layout.css
17
+ assert_equal '// default js', layout.js
18
+
19
+ assert nested_layout = Cms::Layout.where(:identifier => 'nested').first
20
+ assert_equal layout, nested_layout.parent
21
+ assert_equal 'Default Fixture Nested Layout', nested_layout.label
22
+ assert_equal "<div class='left'> {{ cms:page:left }} </div>\n<div class='right'> {{ cms:page:right }} </div>", nested_layout.content
23
+ assert_equal 'div{float:left}', nested_layout.css
24
+ assert_equal '// nested js', nested_layout.js
25
+ end
26
+ end
27
+
28
+ def test_update
29
+ layout = cms_layouts(:default)
30
+ nested_layout = cms_layouts(:nested)
31
+ child_layout = cms_layouts(:child)
32
+ layout.update_column(:updated_at, 10.years.ago)
33
+ nested_layout.update_column(:updated_at, 10.years.ago)
34
+ child_layout.update_column(:updated_at, 10.years.ago)
35
+
36
+ assert_difference 'Cms::Layout.count', -1 do
37
+ ComfortableMexicanSofa::Fixture::Layout::Importer.new('sample-site', 'default-site').import!
38
+
39
+ layout.reload
40
+ assert_equal 'Default Fixture Layout', layout.label
41
+ assert_equal "<html>\n <body>\n {{ cms:page:content }}\n </body>\n</html>", layout.content
42
+ assert_equal 'body{color: red}', layout.css
43
+ assert_equal '// default js', layout.js
44
+ assert_equal 0, layout.position
45
+
46
+ nested_layout.reload
47
+ assert_equal layout, nested_layout.parent
48
+ assert_equal 'Default Fixture Nested Layout', nested_layout.label
49
+ assert_equal "<div class='left'> {{ cms:page:left }} </div>\n<div class='right'> {{ cms:page:right }} </div>", nested_layout.content
50
+ assert_equal 'div{float:left}', nested_layout.css
51
+ assert_equal '// nested js', nested_layout.js
52
+ assert_equal 42, nested_layout.position
53
+
54
+ assert_nil Cms::Layout.where(:identifier => 'child').first
55
+ end
56
+ end
57
+
58
+ def test_update_ignore
59
+ layout = cms_layouts(:default)
60
+ layout_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'sample-site', 'layouts', 'default')
61
+ attr_file_path = File.join(layout_path, 'attributes.yml')
62
+ content_file_path = File.join(layout_path, 'content.html')
63
+ css_file_path = File.join(layout_path, 'stylesheet.css')
64
+ js_file_path = File.join(layout_path, 'javascript.js')
65
+
66
+ assert layout.updated_at >= File.mtime(attr_file_path)
67
+ assert layout.updated_at >= File.mtime(content_file_path)
68
+ assert layout.updated_at >= File.mtime(css_file_path)
69
+ assert layout.updated_at >= File.mtime(js_file_path)
70
+
71
+ ComfortableMexicanSofa::Fixture::Layout::Importer.new('sample-site', 'default-site').import!
72
+ layout.reload
73
+ assert_equal 'default', layout.identifier
74
+ assert_equal 'Default Layout', layout.label
75
+ assert_equal "{{cms:field:default_field_text:text}}\nlayout_content_a\n{{cms:page:default_page_text:text}}\nlayout_content_b\n{{cms:snippet:default}}\nlayout_content_c", layout.content
76
+ assert_equal 'default_css', layout.css
77
+ assert_equal 'default_js', layout.js
78
+ end
79
+
80
+ def test_update_force
81
+ layout = cms_layouts(:default)
82
+ ComfortableMexicanSofa::Fixture::Layout::Importer.new('sample-site', 'default-site').import!
83
+ layout.reload
84
+ assert_equal 'Default Layout', layout.label
85
+
86
+ ComfortableMexicanSofa::Fixture::Layout::Importer.new('sample-site', 'default-site', :forced).import!
87
+ layout.reload
88
+ assert_equal 'Default Fixture Layout', layout.label
89
+ end
90
+
91
+ def test_export
92
+ host_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'test-site')
93
+ layout_1_attr_path = File.join(host_path, 'layouts/nested/attributes.yml')
94
+ layout_1_content_path = File.join(host_path, 'layouts/nested/content.html')
95
+ layout_1_css_path = File.join(host_path, 'layouts/nested/stylesheet.css')
96
+ layout_1_js_path = File.join(host_path, 'layouts/nested/javascript.js')
97
+ layout_2_attr_path = File.join(host_path, 'layouts/nested/child/attributes.yml')
98
+ layout_2_content_path = File.join(host_path, 'layouts/nested/child/content.html')
99
+ layout_2_css_path = File.join(host_path, 'layouts/nested/child/stylesheet.css')
100
+ layout_2_js_path = File.join(host_path, 'layouts/nested/child/javascript.js')
101
+
102
+ ComfortableMexicanSofa::Fixture::Layout::Exporter.new('default-site', 'test-site').export!
103
+
104
+ assert File.exists?(layout_1_attr_path)
105
+ assert File.exists?(layout_1_content_path)
106
+ assert File.exists?(layout_1_css_path)
107
+ assert File.exists?(layout_1_js_path)
108
+
109
+ assert File.exists?(layout_2_attr_path)
110
+ assert File.exists?(layout_2_content_path)
111
+ assert File.exists?(layout_2_css_path)
112
+ assert File.exists?(layout_2_js_path)
113
+
114
+ assert_equal ({
115
+ 'label' => 'Nested Layout',
116
+ 'app_layout' => nil,
117
+ 'position' => 0
118
+ }), YAML.load_file(layout_1_attr_path)
119
+ assert_equal cms_layouts(:nested).content, IO.read(layout_1_content_path)
120
+ assert_equal cms_layouts(:nested).css, IO.read(layout_1_css_path)
121
+ assert_equal cms_layouts(:nested).js, IO.read(layout_1_js_path)
122
+
123
+ assert_equal ({
124
+ 'label' => 'Child Layout',
125
+ 'app_layout' => nil,
126
+ 'position' => 0
127
+ }), YAML.load_file(layout_2_attr_path)
128
+ assert_equal cms_layouts(:child).content, IO.read(layout_2_content_path)
129
+ assert_equal cms_layouts(:child).css, IO.read(layout_2_css_path)
130
+ assert_equal cms_layouts(:child).js, IO.read(layout_2_js_path)
131
+
132
+ FileUtils.rm_rf(host_path)
133
+ end
134
+
135
+ end
@@ -0,0 +1,152 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../test_helper'
4
+
5
+ class FixturePagesTest < ActiveSupport::TestCase
6
+
7
+ def test_creation
8
+ Cms::Page.delete_all
9
+
10
+ layout = cms_layouts(:default)
11
+ layout.update_column(:content, '<html>{{cms:page:content}}</html>')
12
+
13
+ nested = cms_layouts(:nested)
14
+ nested.update_column(:content, '<html>{{cms:page:left}}<br/>{{cms:page:right}}</html>')
15
+
16
+ assert_difference 'Cms::Page.count', 2 do
17
+ ComfortableMexicanSofa::Fixture::Page::Importer.new('sample-site', 'default-site').import!
18
+
19
+ assert page = Cms::Page.where(:full_path => '/').first
20
+ assert_equal layout, page.layout
21
+ assert_equal 'index', page.slug
22
+ assert_equal "<html>Home Page Fixture Contént\ndefault_snippet_content</html>", page.content
23
+ assert_equal 0, page.position
24
+ assert page.is_published?
25
+ assert_equal 2, page.categories.count
26
+ assert_equal ['category_a', 'category_b'], page.categories.map{|c| c.label}
27
+
28
+ assert child_page = Cms::Page.where(:full_path => '/child').first
29
+ assert_equal page, child_page.parent
30
+ assert_equal nested, child_page.layout
31
+ assert_equal 'child', child_page.slug
32
+ assert_equal '<html>Child Page Left Fixture Content<br/>Child Page Right Fixture Content</html>', child_page.content
33
+ assert_equal 42, child_page.position
34
+
35
+ assert_equal child_page, page.target_page
36
+ end
37
+ end
38
+
39
+ def test_update
40
+ page = cms_pages(:default)
41
+ page.update_column(:updated_at, 10.years.ago)
42
+ assert_equal 'Default Page', page.label
43
+
44
+ child = cms_pages(:child)
45
+ child.update_column(:slug, 'old')
46
+
47
+ assert_no_difference 'Cms::Page.count' do
48
+ ComfortableMexicanSofa::Fixture::Page::Importer.new('sample-site', 'default-site').import!
49
+
50
+ page.reload
51
+ assert_equal 'Home Fixture Page', page.label
52
+
53
+ assert_nil Cms::Page.where(:slug => 'old').first
54
+ end
55
+ end
56
+
57
+ def test_update_ignore
58
+ Cms::Page.destroy_all
59
+
60
+ page = cms_sites(:default).pages.create!(
61
+ :label => 'Test',
62
+ :layout => cms_layouts(:default),
63
+ :blocks_attributes => [ { :identifier => 'content', :content => 'test content' } ]
64
+ )
65
+
66
+ page_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'sample-site', 'pages', 'index')
67
+ attr_file_path = File.join(page_path, 'attributes.yml')
68
+ content_file_path = File.join(page_path, 'content.html')
69
+
70
+ assert page.updated_at >= File.mtime(attr_file_path)
71
+ assert page.updated_at >= File.mtime(content_file_path)
72
+
73
+ ComfortableMexicanSofa::Fixture::Page::Importer.new('sample-site', 'default-site').import!
74
+ page.reload
75
+
76
+ assert_equal nil, page.slug
77
+ assert_equal 'Test', page.label
78
+ block = page.blocks.where(:identifier => 'content').first
79
+ assert_equal 'test content', block.content
80
+ end
81
+
82
+ def test_update_force
83
+ page = cms_pages(:default)
84
+ ComfortableMexicanSofa::Fixture::Page::Importer.new('sample-site', 'default-site').import!
85
+ page.reload
86
+ assert_equal 'Default Page', page.label
87
+
88
+ ComfortableMexicanSofa::Fixture::Page::Importer.new('sample-site', 'default-site', :forced).import!
89
+ page.reload
90
+ assert_equal 'Home Fixture Page', page.label
91
+ end
92
+
93
+ def test_update_removing_deleted_blocks
94
+ Cms::Page.destroy_all
95
+
96
+ page = cms_sites(:default).pages.create!(
97
+ :label => 'Test',
98
+ :layout => cms_layouts(:default),
99
+ :blocks_attributes => [ { :identifier => 'to_delete', :content => 'test content' } ]
100
+ )
101
+ page.update_column(:updated_at, 10.years.ago)
102
+
103
+ ComfortableMexicanSofa::Fixture::Page::Importer.new('sample-site', 'default-site').import!
104
+ page.reload
105
+
106
+ block = page.blocks.where(:identifier => 'content').first
107
+ assert_equal "Home Page Fixture Contént\n{{ cms:snippet:default }}", block.content
108
+
109
+ block = page.blocks.where(:identifier => 'to_delete').first
110
+ assert_equal nil, block.content
111
+ end
112
+
113
+ def test_export
114
+ cms_pages(:default).update_attribute(:target_page, cms_pages(:child))
115
+ cms_categories(:default).categorizations.create!(
116
+ :categorized => cms_pages(:default)
117
+ )
118
+
119
+ host_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'test-site')
120
+ page_1_attr_path = File.join(host_path, 'pages/index/attributes.yml')
121
+ page_1_block_a_path = File.join(host_path, 'pages/index/default_field_text.html')
122
+ page_1_block_b_path = File.join(host_path, 'pages/index/default_page_text.html')
123
+ page_2_attr_path = File.join(host_path, 'pages/index/child-page/attributes.yml')
124
+
125
+ ComfortableMexicanSofa::Fixture::Page::Exporter.new('default-site', 'test-site').export!
126
+
127
+ assert_equal ({
128
+ 'label' => 'Default Page',
129
+ 'layout' => 'default',
130
+ 'parent' => nil,
131
+ 'target_page' => '/child-page',
132
+ 'categories' => ['Default'],
133
+ 'is_published' => true,
134
+ 'position' => 0
135
+ }), YAML.load_file(page_1_attr_path)
136
+ assert_equal cms_blocks(:default_field_text).content, IO.read(page_1_block_a_path)
137
+ assert_equal cms_blocks(:default_page_text).content, IO.read(page_1_block_b_path)
138
+
139
+ assert_equal ({
140
+ 'label' => 'Child Page',
141
+ 'layout' => 'default',
142
+ 'parent' => 'index',
143
+ 'target_page' => nil,
144
+ 'categories' => [],
145
+ 'is_published' => true,
146
+ 'position' => 0
147
+ }), YAML.load_file(page_2_attr_path)
148
+
149
+ FileUtils.rm_rf(host_path)
150
+ end
151
+
152
+ end