comfortable_mexican_sofa 1.0.51 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. data/README.md +8 -18
  2. data/Rakefile +1 -4
  3. data/VERSION +1 -1
  4. data/app/controllers/cms_admin/base_controller.rb +8 -9
  5. data/app/controllers/cms_admin/layouts_controller.rb +5 -5
  6. data/app/controllers/cms_admin/pages_controller.rb +14 -14
  7. data/app/controllers/cms_admin/sites_controller.rb +4 -4
  8. data/app/controllers/cms_admin/snippets_controller.rb +4 -4
  9. data/app/controllers/cms_admin/uploads_controller.rb +2 -2
  10. data/app/controllers/cms_content_controller.rb +21 -8
  11. data/app/models/cms/block.rb +13 -0
  12. data/app/models/{cms_layout.rb → cms/layout.rb} +16 -44
  13. data/app/models/{cms_page.rb → cms/page.rb} +26 -57
  14. data/app/models/{cms_site.rb → cms/site.rb} +8 -6
  15. data/app/models/cms/snippet.rb +36 -0
  16. data/app/models/{cms_upload.rb → cms/upload.rb} +5 -3
  17. data/app/views/cms_admin/layouts/_form.html.erb +2 -2
  18. data/app/views/cms_admin/pages/_form.html.erb +5 -5
  19. data/app/views/cms_admin/pages/_form_blocks.html.erb +3 -3
  20. data/app/views/cms_admin/uploads/_index.html.erb +1 -1
  21. data/app/views/layouts/cms_admin.html.erb +2 -38
  22. data/app/views/layouts/cms_admin/_body.html.erb +17 -0
  23. data/app/views/layouts/cms_admin/_center.html.erb +6 -0
  24. data/app/views/layouts/cms_admin/_head.html.erb +11 -0
  25. data/app/views/layouts/cms_admin/_left.html.erb +7 -0
  26. data/app/views/layouts/cms_admin/_right.html.erb +1 -0
  27. data/comfortable_mexican_sofa.gemspec +94 -96
  28. data/config/environments/development.rb +1 -1
  29. data/config/environments/production.rb +1 -1
  30. data/config/environments/test.rb +1 -1
  31. data/config/initializers/comfortable_mexican_sofa.rb +10 -12
  32. data/db/cms_fixtures/example.com/layouts/default/_default.yml +1 -0
  33. data/db/cms_fixtures/example.com/layouts/default/content.html +5 -0
  34. data/db/cms_fixtures/example.com/layouts/default/css.css +1 -0
  35. data/db/cms_fixtures/example.com/layouts/default/js.js +1 -0
  36. data/db/cms_fixtures/example.com/layouts/default/nested/_nested.yml +1 -0
  37. data/db/cms_fixtures/example.com/layouts/default/nested/content.html +2 -0
  38. data/db/cms_fixtures/example.com/layouts/default/nested/css.css +1 -0
  39. data/db/cms_fixtures/example.com/layouts/default/nested/js.js +1 -0
  40. data/db/cms_fixtures/example.com/pages/index/_index.yml +2 -0
  41. data/db/cms_fixtures/example.com/pages/index/child/_child.yml +2 -0
  42. data/db/cms_fixtures/example.com/pages/index/child/left.html +1 -0
  43. data/db/cms_fixtures/example.com/pages/index/child/right.html +1 -0
  44. data/db/cms_fixtures/example.com/pages/index/content.html +2 -0
  45. data/db/cms_fixtures/example.com/snippets/default/_default.yml +1 -0
  46. data/db/cms_fixtures/example.com/snippets/default/content.html +1 -0
  47. data/db/migrate/01_create_cms.rb +11 -11
  48. data/db/migrate/upgrades/02_upgrade_to_1_1_0.rb +19 -0
  49. data/lib/comfortable_mexican_sofa.rb +6 -13
  50. data/lib/comfortable_mexican_sofa/configuration.rb +21 -20
  51. data/lib/comfortable_mexican_sofa/controller_methods.rb +3 -4
  52. data/lib/comfortable_mexican_sofa/engine.rb +1 -1
  53. data/lib/comfortable_mexican_sofa/fixtures.rb +155 -0
  54. data/lib/comfortable_mexican_sofa/form_builder.rb +7 -15
  55. data/lib/comfortable_mexican_sofa/{cms_tag.rb → tag.rb} +42 -23
  56. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_datetime.rb +4 -5
  57. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_integer.rb +4 -5
  58. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_string.rb +4 -5
  59. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_text.rb +4 -5
  60. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/helper.rb +2 -5
  61. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_datetime.rb +4 -5
  62. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_integer.rb +4 -5
  63. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_rich_text.rb +4 -5
  64. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_string.rb +4 -5
  65. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_text.rb +4 -5
  66. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/partial.rb +2 -5
  67. data/lib/comfortable_mexican_sofa/tags/snippet.rb +13 -0
  68. data/lib/comfortable_mexican_sofa/view_methods.rb +4 -3
  69. data/lib/generators/cms_generator.rb +1 -1
  70. data/lib/tasks/comfortable_mexican_sofa.rake +12 -272
  71. data/public/javascripts/comfortable_mexican_sofa/cms.js +1 -1
  72. data/test/fixtures/{cms_blocks.yml → cms/blocks.yml} +2 -2
  73. data/test/fixtures/{cms_layouts.yml → cms/layouts.yml} +3 -3
  74. data/test/fixtures/{cms_pages.yml → cms/pages.yml} +4 -4
  75. data/test/fixtures/{cms_sites.yml → cms/sites.yml} +0 -0
  76. data/test/fixtures/{cms_snippets.yml → cms/snippets.yml} +1 -1
  77. data/test/fixtures/{cms_uploads.yml → cms/uploads.yml} +1 -1
  78. data/test/functional/cms_admin/layouts_controller_test.rb +6 -6
  79. data/test/functional/cms_admin/pages_controller_test.rb +64 -64
  80. data/test/functional/cms_admin/sites_controller_test.rb +5 -5
  81. data/test/functional/cms_admin/snippets_controller_test.rb +6 -6
  82. data/test/functional/cms_admin/uploads_controller_test.rb +4 -4
  83. data/test/functional/cms_content_controller_test.rb +27 -11
  84. data/test/integration/fixtures_test.rb +43 -0
  85. data/test/integration/sites_test.rb +23 -13
  86. data/test/test_helper.rb +9 -8
  87. data/test/unit/{cms_configuration_test.rb → configuration_test.rb} +5 -3
  88. data/test/unit/fixtures_test.rb +198 -0
  89. data/test/unit/models/block_test.rb +33 -0
  90. data/test/unit/models/layout_test.rb +129 -0
  91. data/test/unit/models/page_test.rb +199 -0
  92. data/test/unit/models/site_test.rb +41 -0
  93. data/test/unit/models/snippet_test.rb +32 -0
  94. data/test/unit/models/upload_test.rb +32 -0
  95. data/test/unit/{cms_tag_test.rb → tag_test.rb} +61 -44
  96. data/test/unit/tags/field_datetime_test.rb +44 -0
  97. data/test/unit/tags/field_integer_test.rb +43 -0
  98. data/test/unit/tags/field_string_test.rb +46 -0
  99. data/test/unit/tags/field_text_test.rb +42 -0
  100. data/test/unit/{cms_tags → tags}/helper_test.rb +18 -6
  101. data/test/unit/tags/page_datetime_test.rb +44 -0
  102. data/test/unit/tags/page_integer_test.rb +43 -0
  103. data/test/unit/tags/page_rich_text.rb +43 -0
  104. data/test/unit/{cms_tags → tags}/page_string_test.rb +15 -5
  105. data/test/unit/tags/page_text_test.rb +46 -0
  106. data/test/unit/{cms_tags → tags}/partial_test.rb +24 -8
  107. data/test/unit/tags/snippet_test.rb +45 -0
  108. data/test/unit/view_methods_test.rb +2 -2
  109. metadata +95 -121
  110. data/app/models/cms_block.rb +0 -28
  111. data/app/models/cms_snippet.rb +0 -69
  112. data/db/cms_seeds/example.local/layouts/default.yml +0 -8
  113. data/db/cms_seeds/example.local/layouts/nested.yml +0 -6
  114. data/db/cms_seeds/example.local/pages/child.yml +0 -10
  115. data/db/cms_seeds/example.local/pages/child/subchild.yml +0 -14
  116. data/db/cms_seeds/example.local/pages/index.yml +0 -11
  117. data/db/cms_seeds/example.local/snippets/example.yml +0 -4
  118. data/lib/comfortable_mexican_sofa/cms_tag/snippet.rb +0 -18
  119. data/test/cms_seeds/test.host/layouts/broken.yml +0 -1
  120. data/test/cms_seeds/test.host/layouts/default.yml +0 -3
  121. data/test/cms_seeds/test.host/layouts/nested.yml +0 -4
  122. data/test/cms_seeds/test.host/pages/broken.yml +0 -1
  123. data/test/cms_seeds/test.host/pages/child.yml +0 -10
  124. data/test/cms_seeds/test.host/pages/child/subchild.yml +0 -10
  125. data/test/cms_seeds/test.host/pages/index.yml +0 -10
  126. data/test/cms_seeds/test.host/snippets/broken.yml +0 -1
  127. data/test/cms_seeds/test.host/snippets/default.yml +0 -3
  128. data/test/integration/rake_tasks_test.rb +0 -65
  129. data/test/integration/render_cms_seed_test.rb +0 -34
  130. data/test/unit/cms_block_test.rb +0 -43
  131. data/test/unit/cms_layout_test.rb +0 -179
  132. data/test/unit/cms_page_test.rb +0 -257
  133. data/test/unit/cms_site_test.rb +0 -41
  134. data/test/unit/cms_snippet_test.rb +0 -77
  135. data/test/unit/cms_tags/field_datetime_test.rb +0 -34
  136. data/test/unit/cms_tags/field_integer_test.rb +0 -33
  137. data/test/unit/cms_tags/field_string_test.rb +0 -34
  138. data/test/unit/cms_tags/field_text_test.rb +0 -32
  139. data/test/unit/cms_tags/page_datetime_test.rb +0 -34
  140. data/test/unit/cms_tags/page_integer_test.rb +0 -33
  141. data/test/unit/cms_tags/page_rich_text.rb +0 -33
  142. data/test/unit/cms_tags/page_text_test.rb +0 -34
  143. data/test/unit/cms_tags/snippet_test.rb +0 -33
  144. data/test/unit/cms_upload_test.rb +0 -26
@@ -10,7 +10,7 @@ class CmsAdmin::SitesControllerTest < ActionController::TestCase
10
10
  end
11
11
 
12
12
  def test_get_index_with_no_sites
13
- CmsSite.delete_all
13
+ Cms::Site.delete_all
14
14
  get :index
15
15
  assert_response :redirect
16
16
  assert_redirected_to :action => :new
@@ -42,19 +42,19 @@ class CmsAdmin::SitesControllerTest < ActionController::TestCase
42
42
  end
43
43
 
44
44
  def test_creation
45
- assert_difference 'CmsSite.count' do
45
+ assert_difference 'Cms::Site.count' do
46
46
  post :create, :cms_site => {
47
47
  :label => 'Test Site',
48
48
  :hostname => 'test.site.local'
49
49
  }
50
50
  assert_response :redirect
51
- assert_redirected_to :action => :edit, :id => CmsSite.last
51
+ assert_redirected_to :action => :edit, :id => Cms::Site.last
52
52
  assert_equal 'Site created', flash[:notice]
53
53
  end
54
54
  end
55
55
 
56
56
  def test_creation_failure
57
- assert_no_difference 'CmsSite.count' do
57
+ assert_no_difference 'Cms::Site.count' do
58
58
  post :create, :cms_site => { }
59
59
  assert_response :success
60
60
  assert_template :new
@@ -89,7 +89,7 @@ class CmsAdmin::SitesControllerTest < ActionController::TestCase
89
89
  end
90
90
 
91
91
  def test_destroy
92
- assert_difference 'CmsSite.count', -1 do
92
+ assert_difference 'Cms::Site.count', -1 do
93
93
  delete :destroy, :id => cms_sites(:default)
94
94
  assert_response :redirect
95
95
  assert_redirected_to :action => :index
@@ -10,7 +10,7 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
10
10
  end
11
11
 
12
12
  def test_get_index_with_no_snippets
13
- CmsSnippet.delete_all
13
+ Cms::Snippet.delete_all
14
14
  get :index
15
15
  assert_response :redirect
16
16
  assert_redirected_to :action => :new
@@ -41,22 +41,22 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
41
41
  end
42
42
 
43
43
  def test_creation
44
- assert_difference 'CmsSnippet.count' do
44
+ assert_difference 'Cms::Snippet.count' do
45
45
  post :create, :cms_snippet => {
46
46
  :label => 'Test Snippet',
47
47
  :slug => 'test-snippet',
48
48
  :content => 'Test Content'
49
49
  }
50
50
  assert_response :redirect
51
- snippet = CmsSnippet.last
52
- assert_equal cms_sites(:default), snippet.cms_site
51
+ snippet = Cms::Snippet.last
52
+ assert_equal cms_sites(:default), snippet.site
53
53
  assert_redirected_to :action => :edit, :id => snippet
54
54
  assert_equal 'Snippet created', flash[:notice]
55
55
  end
56
56
  end
57
57
 
58
58
  def test_creation_failure
59
- assert_no_difference 'CmsSnippet.count' do
59
+ assert_no_difference 'Cms::Snippet.count' do
60
60
  post :create, :cms_snippet => { }
61
61
  assert_response :success
62
62
  assert_template :new
@@ -91,7 +91,7 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
91
91
  end
92
92
 
93
93
  def test_destroy
94
- assert_difference 'CmsSnippet.count', -1 do
94
+ assert_difference 'Cms::Snippet.count', -1 do
95
95
  delete :destroy, :id => cms_snippets(:default)
96
96
  assert_response :redirect
97
97
  assert_redirected_to :action => :index
@@ -3,21 +3,21 @@ require File.expand_path('../../test_helper', File.dirname(__FILE__))
3
3
  class CmsAdmin::UploadsControllerTest < ActionController::TestCase
4
4
 
5
5
  def test_create
6
- assert_difference 'CmsUpload.count', 1 do
6
+ assert_difference 'Cms::Upload.count', 1 do
7
7
  xhr :post, :create, :file => fixture_file_upload('files/valid_image.jpg')
8
8
  assert_response :success
9
9
  end
10
10
  end
11
11
 
12
- def test_create_fails
13
- assert_no_difference 'CmsUpload.count' do
12
+ def test_create_failure
13
+ assert_no_difference 'Cms::Upload.count' do
14
14
  xhr :post, :create, :file => nil
15
15
  assert_response :bad_request
16
16
  end
17
17
  end
18
18
 
19
19
  def test_destroy
20
- assert_difference 'CmsUpload.count', -1 do
20
+ assert_difference 'Cms::Upload.count', -1 do
21
21
  xhr :delete, :destroy, :id => cms_uploads(:default)
22
22
  assert_response :success
23
23
  end
@@ -32,13 +32,13 @@ class CmsContentControllerTest < ActionController::TestCase
32
32
  end
33
33
 
34
34
  def test_render_page_not_found_with_custom_404
35
- page = cms_sites(:default).cms_pages.create!(
35
+ page = cms_sites(:default).pages.create!(
36
36
  :label => '404',
37
37
  :slug => '404',
38
38
  :parent_id => cms_pages(:default).id,
39
- :cms_layout_id => cms_layouts(:default).id,
39
+ :layout_id => cms_layouts(:default).id,
40
40
  :is_published => '1',
41
- :cms_blocks_attributes => [
41
+ :blocks_attributes => [
42
42
  { :label => 'default_page_text',
43
43
  :type => 'CmsTag::PageText',
44
44
  :content => 'custom 404 page content' }
@@ -52,6 +52,22 @@ class CmsContentControllerTest < ActionController::TestCase
52
52
  assert_match /custom 404 page content/, response.body
53
53
  end
54
54
 
55
+ def test_render_page_with_no_site
56
+ Cms::Site.destroy_all
57
+
58
+ get :render_html, :cms_path => ''
59
+ assert_response 404
60
+ assert_equal 'Site Not Found', response.body
61
+ end
62
+
63
+ def test_render_page_with_no_layout
64
+ Cms::Layout.destroy_all
65
+
66
+ get :render_html, :cms_path => ''
67
+ assert_response 404
68
+ assert_equal 'Layout Not Found', response.body
69
+ end
70
+
55
71
  def test_render_page_with_redirect
56
72
  cms_pages(:child).update_attribute(:target_page, cms_pages(:default))
57
73
  assert_equal cms_pages(:default), cms_pages(:child).target_page
@@ -68,15 +84,15 @@ class CmsContentControllerTest < ActionController::TestCase
68
84
  end
69
85
 
70
86
  def test_render_page_with_irb_disabled
71
- assert ComfortableMexicanSofa.config.disable_irb
87
+ assert_equal false, ComfortableMexicanSofa.config.allow_irb
72
88
 
73
- irb_page = cms_sites(:default).cms_pages.create!(
89
+ irb_page = cms_sites(:default).pages.create!(
74
90
  :label => 'irb',
75
91
  :slug => 'irb',
76
92
  :parent_id => cms_pages(:default).id,
77
- :cms_layout_id => cms_layouts(:default).id,
93
+ :layout_id => cms_layouts(:default).id,
78
94
  :is_published => '1',
79
- :cms_blocks_attributes => [
95
+ :blocks_attributes => [
80
96
  { :label => 'default_page_text',
81
97
  :content => 'text <%= 2 + 2 %> text' }
82
98
  ]
@@ -87,15 +103,15 @@ class CmsContentControllerTest < ActionController::TestCase
87
103
  end
88
104
 
89
105
  def test_render_page_with_irb_enabled
90
- ComfortableMexicanSofa.config.disable_irb = false
106
+ ComfortableMexicanSofa.config.allow_irb = true
91
107
 
92
- irb_page = cms_sites(:default).cms_pages.create!(
108
+ irb_page = cms_sites(:default).pages.create!(
93
109
  :label => 'irb',
94
110
  :slug => 'irb',
95
111
  :parent_id => cms_pages(:default).id,
96
- :cms_layout_id => cms_layouts(:default).id,
112
+ :layout_id => cms_layouts(:default).id,
97
113
  :is_published => '1',
98
- :cms_blocks_attributes => [
114
+ :blocks_attributes => [
99
115
  { :label => 'default_page_text',
100
116
  :content => 'text <%= 2 + 2 %> text' }
101
117
  ]
@@ -0,0 +1,43 @@
1
+ require File.expand_path('../test_helper', File.dirname(__FILE__))
2
+
3
+ class FixturesTest < ActionDispatch::IntegrationTest
4
+
5
+ def setup
6
+ host! 'example.com'
7
+ cms_sites(:default).update_attribute(:hostname, 'example.com')
8
+ end
9
+
10
+ def test_fixtures_disabled
11
+ assert_no_difference ['Cms::Layout.count', 'Cms::Page.count', 'Cms::Snippet.count'] do
12
+ get '/'
13
+ assert_response :success
14
+
15
+ assert_equal 'Default Page', Cms::Page.root.label
16
+ assert_equal 'Default Layout', Cms::Layout.find_by_slug('default').label
17
+ assert_equal 'Default Snippet', Cms::Snippet.find_by_slug('default').label
18
+ end
19
+ end
20
+
21
+ def test_fixtures_enabled
22
+ ComfortableMexicanSofa.config.enable_fixtures = true
23
+ Cms::Layout.destroy_all
24
+ Cms::Page.destroy_all
25
+ Cms::Snippet.destroy_all
26
+
27
+ assert_difference 'Cms::Page.count', 2 do
28
+ assert_difference 'Cms::Layout.count', 2 do
29
+ assert_difference 'Cms::Snippet.count', 1 do
30
+ get '/'
31
+ assert_response :success
32
+
33
+ assert_equal 'Home Fixture Page', Cms::Page.root.label
34
+ assert_equal 'Default Fixture Layout', Cms::Layout.find_by_slug('default').label
35
+ assert_equal 'Default Fixture Snippet', Cms::Snippet.find_by_slug('default').label
36
+
37
+ assert_equal "<html>\n <body>\n Home Page Fixture Content\nFixture Content for Default Snippet\n </body>\n</html>", response.body
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ end
@@ -8,12 +8,12 @@ class SitesTest < ActionDispatch::IntegrationTest
8
8
  end
9
9
 
10
10
  def test_get_admin_with_no_site
11
- CmsSite.delete_all
12
- assert_difference 'CmsSite.count' do
11
+ Cms::Site.delete_all
12
+ assert_difference 'Cms::Site.count' do
13
13
  http_auth :get, cms_admin_pages_path
14
14
  assert_response :redirect
15
15
  assert_redirected_to new_cms_admin_page_path
16
- site = CmsSite.first
16
+ site = Cms::Site.first
17
17
  assert_equal 'test.host', site.hostname
18
18
  assert_equal 'Default Site', site.label
19
19
  end
@@ -22,7 +22,7 @@ class SitesTest < ActionDispatch::IntegrationTest
22
22
  def test_get_admin_with_wrong_site
23
23
  site = cms_sites(:default)
24
24
  site.update_attribute(:hostname, 'remote.host')
25
- assert_no_difference 'CmsSite.count' do
25
+ assert_no_difference 'Cms::Site.count' do
26
26
  http_auth :get, cms_admin_pages_path
27
27
  assert_response :success
28
28
  site.reload
@@ -31,10 +31,11 @@ class SitesTest < ActionDispatch::IntegrationTest
31
31
  end
32
32
 
33
33
  def test_get_admin_with_two_wrong_sites
34
- CmsSite.delete_all
35
- CmsSite.create!(:label => 'Site1', :hostname => 'site1.host')
36
- CmsSite.create!(:label => 'Site2', :hostname => 'site2.host')
37
- assert_no_difference 'CmsSite.count' do
34
+ ComfortableMexicanSofa.config.enable_multiple_sites = true
35
+ Cms::Site.delete_all
36
+ Cms::Site.create!(:label => 'Site1', :hostname => 'site1.host')
37
+ Cms::Site.create!(:label => 'Site2', :hostname => 'site2.host')
38
+ assert_no_difference 'Cms::Site.count' do
38
39
  http_auth :get, cms_admin_pages_path
39
40
  assert_response :redirect
40
41
  assert_redirected_to cms_admin_sites_path
@@ -42,10 +43,10 @@ class SitesTest < ActionDispatch::IntegrationTest
42
43
  end
43
44
  end
44
45
 
45
- def test_get_admin_with_no_site_and_no_auto_manage
46
- ComfortableMexicanSofa.config.auto_manage_sites = false
47
- CmsSite.delete_all
48
- assert_no_difference 'CmsSite.count' do
46
+ def test_get_admin_with_no_site_and_multiple_sites_enabled
47
+ ComfortableMexicanSofa.config.enable_multiple_sites = true
48
+ Cms::Site.delete_all
49
+ assert_no_difference 'Cms::Site.count' do
49
50
  http_auth :get, cms_admin_pages_path
50
51
  assert_response :redirect
51
52
  assert_redirected_to cms_admin_sites_path
@@ -53,7 +54,16 @@ class SitesTest < ActionDispatch::IntegrationTest
53
54
  end
54
55
  end
55
56
 
56
- def test_get_public_page_for_non_existent_site
57
+ def test_get_public_page_for_wrong_host_with_single_site
58
+ host! 'bogus.host'
59
+ get '/'
60
+ assert_response :success
61
+ assert assigns(:cms_site)
62
+ assert_equal 'test.host', assigns(:cms_site).hostname
63
+ end
64
+
65
+ def test_get_public_page_for_wrong_host_with_mutiple_sites
66
+ ComfortableMexicanSofa.config.enable_multiple_sites = true
57
67
  host! 'bogus.host'
58
68
  get '/'
59
69
  assert_response 404
data/test/test_helper.rb CHANGED
@@ -14,14 +14,15 @@ class ActiveSupport::TestCase
14
14
  # resetting default configuration
15
15
  def reset_config
16
16
  ComfortableMexicanSofa.configure do |config|
17
- config.cms_title = 'ComfortableMexicanSofa MicroCMS'
18
- config.authentication = 'ComfortableMexicanSofa::HttpAuth'
19
- config.seed_data_path = nil
20
- config.admin_route_prefix = 'cms-admin'
21
- config.admin_route_redirect = "/cms-admin/pages"
22
- config.auto_manage_sites = true
23
- config.disable_irb = true
24
- config.enable_caching = true
17
+ config.cms_title = 'ComfortableMexicanSofa MicroCMS'
18
+ config.authentication = 'ComfortableMexicanSofa::HttpAuth'
19
+ config.admin_route_prefix = 'cms-admin'
20
+ config.admin_route_redirect = "/cms-admin/pages"
21
+ config.enable_multiple_sites = false
22
+ config.allow_irb = false
23
+ config.enable_caching = true
24
+ config.enable_fixtures = false
25
+ config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
25
26
  end
26
27
  ComfortableMexicanSofa::HttpAuth.username = 'username'
27
28
  ComfortableMexicanSofa::HttpAuth.password = 'password'
@@ -1,16 +1,18 @@
1
1
  require File.expand_path('../test_helper', File.dirname(__FILE__))
2
2
 
3
- class CmsConfigurationTest < ActiveSupport::TestCase
3
+ class ConfigurationTest < ActiveSupport::TestCase
4
4
 
5
5
  def test_configuration_presense
6
6
  assert config = ComfortableMexicanSofa.configuration
7
7
  assert_equal 'ComfortableMexicanSofa MicroCMS', config.cms_title
8
8
  assert_equal 'ComfortableMexicanSofa::HttpAuth', config.authentication
9
- assert_equal nil, config.seed_data_path
10
9
  assert_equal 'cms-admin', config.admin_route_prefix
11
10
  assert_equal '/cms-admin/pages', config.admin_route_redirect
12
- assert_equal true, config.disable_irb
11
+ assert_equal false, config.enable_multiple_sites
12
+ assert_equal false, config.allow_irb
13
13
  assert_equal true, config.enable_caching
14
+ assert_equal false, config.enable_fixtures
15
+ assert_equal File.expand_path('db/cms_fixtures', Rails.root), config.fixtures_path
14
16
  end
15
17
 
16
18
  def test_initialization_overrides
@@ -0,0 +1,198 @@
1
+ require File.expand_path('../test_helper', File.dirname(__FILE__))
2
+
3
+ class ViewMethodsTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ @site = cms_sites(:default)
7
+ @site.update_attribute(:hostname, 'example.com')
8
+ end
9
+
10
+ def test_sync_layouts_creating
11
+ Cms::Layout.delete_all
12
+
13
+ assert_difference 'Cms::Layout.count', 2 do
14
+ ComfortableMexicanSofa::Fixtures.sync_layouts(@site)
15
+ assert layout = Cms::Layout.find_by_slug('default')
16
+ assert_equal 'Default Fixture Layout', layout.label
17
+ assert_equal "<html>\n <body>\n {{ cms:page:content }}\n </body>\n</html>", layout.content
18
+ assert_equal 'body{color: red}', layout.css
19
+ assert_equal '// default js', layout.js
20
+
21
+ assert nested_layout = Cms::Layout.find_by_slug('nested')
22
+ assert_equal layout, nested_layout.parent
23
+ assert_equal 'Default Fixture Nested Layout', nested_layout.label
24
+ assert_equal "<div class='left'> {{ cms:page:left }} </div>\n<div class='right'> {{ cms:page:right }} </div>", nested_layout.content
25
+ assert_equal 'div{float:left}', nested_layout.css
26
+ assert_equal '// nested js', nested_layout.js
27
+ end
28
+ end
29
+
30
+ def test_sync_layouts_updating_and_deleting
31
+
32
+ layout = cms_layouts(:default)
33
+ nested_layout = cms_layouts(:nested)
34
+ child_layout = cms_layouts(:child)
35
+ layout.update_attribute(:updated_at, 10.years.ago)
36
+ nested_layout.update_attribute(:updated_at, 10.years.ago)
37
+ child_layout.update_attribute(:updated_at, 10.years.ago)
38
+
39
+ assert_difference 'Cms::Layout.count', -1 do
40
+ ComfortableMexicanSofa::Fixtures.sync_layouts(@site)
41
+
42
+ layout.reload
43
+ assert_equal 'Default Fixture Layout', layout.label
44
+ assert_equal "<html>\n <body>\n {{ cms:page:content }}\n </body>\n</html>", layout.content
45
+ assert_equal 'body{color: red}', layout.css
46
+ assert_equal '// default js', layout.js
47
+
48
+ nested_layout.reload
49
+ assert_equal layout, nested_layout.parent
50
+ assert_equal 'Default Fixture Nested Layout', nested_layout.label
51
+ assert_equal "<div class='left'> {{ cms:page:left }} </div>\n<div class='right'> {{ cms:page:right }} </div>", nested_layout.content
52
+ assert_equal 'div{float:left}', nested_layout.css
53
+ assert_equal '// nested js', nested_layout.js
54
+
55
+ assert_nil Cms::Layout.find_by_slug('child')
56
+ end
57
+ end
58
+
59
+ def test_sync_layouts_ignoring
60
+ layout = cms_layouts(:default)
61
+ layout_path = File.join(ComfortableMexicanSofa.config.fixtures_path, @site.hostname, 'layouts', 'default')
62
+ attr_file_path = File.join(layout_path, '_default.yml')
63
+ content_file_path = File.join(layout_path, 'content.html')
64
+ css_file_path = File.join(layout_path, 'css.css')
65
+ js_file_path = File.join(layout_path, 'js.js')
66
+
67
+ assert layout.updated_at >= File.mtime(attr_file_path)
68
+ assert layout.updated_at >= File.mtime(content_file_path)
69
+ assert layout.updated_at >= File.mtime(css_file_path)
70
+ assert layout.updated_at >= File.mtime(js_file_path)
71
+
72
+ ComfortableMexicanSofa::Fixtures.sync_layouts(@site)
73
+ layout.reload
74
+ assert_equal 'default', layout.slug
75
+ assert_equal 'Default Layout', layout.label
76
+ 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
77
+ assert_equal 'default_css', layout.css
78
+ assert_equal 'default_js', layout.js
79
+ end
80
+
81
+ def test_sync_pages_creating
82
+ Cms::Page.delete_all
83
+
84
+ layout = cms_layouts(:default)
85
+ layout.update_attribute(:content, '<html>{{cms:page:content}}</html>')
86
+
87
+ nested = cms_layouts(:nested)
88
+ nested.update_attribute(:content, '<html>{{cms:page:left}}<br/>{{cms:page:right}}</html>')
89
+
90
+ assert_difference 'Cms::Page.count', 2 do
91
+ ComfortableMexicanSofa::Fixtures.sync_pages(@site)
92
+
93
+ assert page = Cms::Page.find_by_full_path('/')
94
+ assert_equal 'index', page.slug
95
+ assert_equal "<html>Home Page Fixture Content\ndefault_snippet_content</html>", page.content
96
+ assert page.is_published?
97
+
98
+ assert child_page = Cms::Page.find_by_full_path('/child')
99
+ assert_equal page, child_page.parent
100
+ assert_equal 'child', child_page.slug
101
+ assert_equal '<html>Child Page Left Fixture Content<br/>Child Page Right Fixture Content</html>', child_page.content
102
+ end
103
+ end
104
+
105
+ def test_sync_pages_updating_and_deleting
106
+ page = cms_pages(:default)
107
+ page.update_attribute(:updated_at, 10.years.ago)
108
+ assert_equal 'Default Page', page.label
109
+
110
+ child = cms_pages(:child)
111
+ child.update_attribute(:slug, 'old')
112
+
113
+ assert_no_difference 'Cms::Page.count' do
114
+ ComfortableMexicanSofa::Fixtures.sync_pages(@site)
115
+
116
+ page.reload
117
+ assert_equal 'Home Fixture Page', page.label
118
+
119
+ assert_nil Cms::Page.find_by_slug('old')
120
+ end
121
+ end
122
+
123
+ def test_sync_pages_ignoring
124
+ page = cms_pages(:default)
125
+ page_path = File.join(ComfortableMexicanSofa.config.fixtures_path, @site.hostname, 'pages', 'index')
126
+ attr_file_path = File.join(page_path, '_index.yml')
127
+ content_file_path = File.join(page_path, 'content.html')
128
+
129
+ assert page.updated_at >= File.mtime(attr_file_path)
130
+ assert page.updated_at >= File.mtime(content_file_path)
131
+
132
+ ComfortableMexicanSofa::Fixtures.sync_pages(@site)
133
+ page.reload
134
+ assert_equal nil, page.slug
135
+ assert_equal 'Default Page', page.label
136
+ assert_equal "\nlayout_content_a\ndefault_page_text_content_a\ndefault_snippet_content\ndefault_page_text_content_b\nlayout_content_b\ndefault_snippet_content\nlayout_content_c", page.content
137
+ end
138
+
139
+ def test_sync_snippets_creating
140
+ Cms::Snippet.delete_all
141
+
142
+ assert_difference 'Cms::Snippet.count' do
143
+ ComfortableMexicanSofa::Fixtures.sync_snippets(@site)
144
+ assert snippet = Cms::Snippet.last
145
+ assert_equal 'default', snippet.slug
146
+ assert_equal 'Default Fixture Snippet', snippet.label
147
+ assert_equal 'Fixture Content for Default Snippet', snippet.content
148
+ end
149
+ end
150
+
151
+ def test_sync_snippets_updating
152
+ snippet = cms_snippets(:default)
153
+ snippet.update_attribute(:updated_at, 10.years.ago)
154
+ assert_equal 'default', snippet.slug
155
+ assert_equal 'Default Snippet', snippet.label
156
+ assert_equal 'default_snippet_content', snippet.content
157
+
158
+ assert_no_difference 'Cms::Snippet.count' do
159
+ ComfortableMexicanSofa::Fixtures.sync_snippets(@site)
160
+ snippet.reload
161
+ assert_equal 'default', snippet.slug
162
+ assert_equal 'Default Fixture Snippet', snippet.label
163
+ assert_equal 'Fixture Content for Default Snippet', snippet.content
164
+ end
165
+ end
166
+
167
+ def test_sync_snippets_deleting
168
+ snippet = cms_snippets(:default)
169
+ snippet.update_attribute(:slug, 'old')
170
+
171
+ assert_no_difference 'Cms::Snippet.count' do
172
+ ComfortableMexicanSofa::Fixtures.sync_snippets(@site)
173
+ assert snippet = Cms::Snippet.last
174
+ assert_equal 'default', snippet.slug
175
+ assert_equal 'Default Fixture Snippet', snippet.label
176
+ assert_equal 'Fixture Content for Default Snippet', snippet.content
177
+
178
+ assert_nil Cms::Snippet.find_by_slug('old')
179
+ end
180
+ end
181
+
182
+ def test_sync_snippets_ignoring
183
+ snippet = cms_snippets(:default)
184
+ snippet_path = File.join(ComfortableMexicanSofa.config.fixtures_path, @site.hostname, 'snippets', 'default')
185
+ attr_file_path = File.join(snippet_path, '_default.yml')
186
+ content_file_path = File.join(snippet_path, 'content.html')
187
+
188
+ assert snippet.updated_at >= File.mtime(attr_file_path)
189
+ assert snippet.updated_at >= File.mtime(content_file_path)
190
+
191
+ ComfortableMexicanSofa::Fixtures.sync_snippets(@site)
192
+ snippet.reload
193
+ assert_equal 'default', snippet.slug
194
+ assert_equal 'Default Snippet', snippet.label
195
+ assert_equal 'default_snippet_content', snippet.content
196
+ end
197
+
198
+ end