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.
- data/README.md +8 -18
- data/Rakefile +1 -4
- data/VERSION +1 -1
- data/app/controllers/cms_admin/base_controller.rb +8 -9
- data/app/controllers/cms_admin/layouts_controller.rb +5 -5
- data/app/controllers/cms_admin/pages_controller.rb +14 -14
- data/app/controllers/cms_admin/sites_controller.rb +4 -4
- data/app/controllers/cms_admin/snippets_controller.rb +4 -4
- data/app/controllers/cms_admin/uploads_controller.rb +2 -2
- data/app/controllers/cms_content_controller.rb +21 -8
- data/app/models/cms/block.rb +13 -0
- data/app/models/{cms_layout.rb → cms/layout.rb} +16 -44
- data/app/models/{cms_page.rb → cms/page.rb} +26 -57
- data/app/models/{cms_site.rb → cms/site.rb} +8 -6
- data/app/models/cms/snippet.rb +36 -0
- data/app/models/{cms_upload.rb → cms/upload.rb} +5 -3
- data/app/views/cms_admin/layouts/_form.html.erb +2 -2
- data/app/views/cms_admin/pages/_form.html.erb +5 -5
- data/app/views/cms_admin/pages/_form_blocks.html.erb +3 -3
- data/app/views/cms_admin/uploads/_index.html.erb +1 -1
- data/app/views/layouts/cms_admin.html.erb +2 -38
- data/app/views/layouts/cms_admin/_body.html.erb +17 -0
- data/app/views/layouts/cms_admin/_center.html.erb +6 -0
- data/app/views/layouts/cms_admin/_head.html.erb +11 -0
- data/app/views/layouts/cms_admin/_left.html.erb +7 -0
- data/app/views/layouts/cms_admin/_right.html.erb +1 -0
- data/comfortable_mexican_sofa.gemspec +94 -96
- data/config/environments/development.rb +1 -1
- data/config/environments/production.rb +1 -1
- data/config/environments/test.rb +1 -1
- data/config/initializers/comfortable_mexican_sofa.rb +10 -12
- data/db/cms_fixtures/example.com/layouts/default/_default.yml +1 -0
- data/db/cms_fixtures/example.com/layouts/default/content.html +5 -0
- data/db/cms_fixtures/example.com/layouts/default/css.css +1 -0
- data/db/cms_fixtures/example.com/layouts/default/js.js +1 -0
- data/db/cms_fixtures/example.com/layouts/default/nested/_nested.yml +1 -0
- data/db/cms_fixtures/example.com/layouts/default/nested/content.html +2 -0
- data/db/cms_fixtures/example.com/layouts/default/nested/css.css +1 -0
- data/db/cms_fixtures/example.com/layouts/default/nested/js.js +1 -0
- data/db/cms_fixtures/example.com/pages/index/_index.yml +2 -0
- data/db/cms_fixtures/example.com/pages/index/child/_child.yml +2 -0
- data/db/cms_fixtures/example.com/pages/index/child/left.html +1 -0
- data/db/cms_fixtures/example.com/pages/index/child/right.html +1 -0
- data/db/cms_fixtures/example.com/pages/index/content.html +2 -0
- data/db/cms_fixtures/example.com/snippets/default/_default.yml +1 -0
- data/db/cms_fixtures/example.com/snippets/default/content.html +1 -0
- data/db/migrate/01_create_cms.rb +11 -11
- data/db/migrate/upgrades/02_upgrade_to_1_1_0.rb +19 -0
- data/lib/comfortable_mexican_sofa.rb +6 -13
- data/lib/comfortable_mexican_sofa/configuration.rb +21 -20
- data/lib/comfortable_mexican_sofa/controller_methods.rb +3 -4
- data/lib/comfortable_mexican_sofa/engine.rb +1 -1
- data/lib/comfortable_mexican_sofa/fixtures.rb +155 -0
- data/lib/comfortable_mexican_sofa/form_builder.rb +7 -15
- data/lib/comfortable_mexican_sofa/{cms_tag.rb → tag.rb} +42 -23
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_datetime.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_integer.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_string.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_text.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/helper.rb +2 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_datetime.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_integer.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_rich_text.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_string.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_text.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/partial.rb +2 -5
- data/lib/comfortable_mexican_sofa/tags/snippet.rb +13 -0
- data/lib/comfortable_mexican_sofa/view_methods.rb +4 -3
- data/lib/generators/cms_generator.rb +1 -1
- data/lib/tasks/comfortable_mexican_sofa.rake +12 -272
- data/public/javascripts/comfortable_mexican_sofa/cms.js +1 -1
- data/test/fixtures/{cms_blocks.yml → cms/blocks.yml} +2 -2
- data/test/fixtures/{cms_layouts.yml → cms/layouts.yml} +3 -3
- data/test/fixtures/{cms_pages.yml → cms/pages.yml} +4 -4
- data/test/fixtures/{cms_sites.yml → cms/sites.yml} +0 -0
- data/test/fixtures/{cms_snippets.yml → cms/snippets.yml} +1 -1
- data/test/fixtures/{cms_uploads.yml → cms/uploads.yml} +1 -1
- data/test/functional/cms_admin/layouts_controller_test.rb +6 -6
- data/test/functional/cms_admin/pages_controller_test.rb +64 -64
- data/test/functional/cms_admin/sites_controller_test.rb +5 -5
- data/test/functional/cms_admin/snippets_controller_test.rb +6 -6
- data/test/functional/cms_admin/uploads_controller_test.rb +4 -4
- data/test/functional/cms_content_controller_test.rb +27 -11
- data/test/integration/fixtures_test.rb +43 -0
- data/test/integration/sites_test.rb +23 -13
- data/test/test_helper.rb +9 -8
- data/test/unit/{cms_configuration_test.rb → configuration_test.rb} +5 -3
- data/test/unit/fixtures_test.rb +198 -0
- data/test/unit/models/block_test.rb +33 -0
- data/test/unit/models/layout_test.rb +129 -0
- data/test/unit/models/page_test.rb +199 -0
- data/test/unit/models/site_test.rb +41 -0
- data/test/unit/models/snippet_test.rb +32 -0
- data/test/unit/models/upload_test.rb +32 -0
- data/test/unit/{cms_tag_test.rb → tag_test.rb} +61 -44
- data/test/unit/tags/field_datetime_test.rb +44 -0
- data/test/unit/tags/field_integer_test.rb +43 -0
- data/test/unit/tags/field_string_test.rb +46 -0
- data/test/unit/tags/field_text_test.rb +42 -0
- data/test/unit/{cms_tags → tags}/helper_test.rb +18 -6
- data/test/unit/tags/page_datetime_test.rb +44 -0
- data/test/unit/tags/page_integer_test.rb +43 -0
- data/test/unit/tags/page_rich_text.rb +43 -0
- data/test/unit/{cms_tags → tags}/page_string_test.rb +15 -5
- data/test/unit/tags/page_text_test.rb +46 -0
- data/test/unit/{cms_tags → tags}/partial_test.rb +24 -8
- data/test/unit/tags/snippet_test.rb +45 -0
- data/test/unit/view_methods_test.rb +2 -2
- metadata +95 -121
- data/app/models/cms_block.rb +0 -28
- data/app/models/cms_snippet.rb +0 -69
- data/db/cms_seeds/example.local/layouts/default.yml +0 -8
- data/db/cms_seeds/example.local/layouts/nested.yml +0 -6
- data/db/cms_seeds/example.local/pages/child.yml +0 -10
- data/db/cms_seeds/example.local/pages/child/subchild.yml +0 -14
- data/db/cms_seeds/example.local/pages/index.yml +0 -11
- data/db/cms_seeds/example.local/snippets/example.yml +0 -4
- data/lib/comfortable_mexican_sofa/cms_tag/snippet.rb +0 -18
- data/test/cms_seeds/test.host/layouts/broken.yml +0 -1
- data/test/cms_seeds/test.host/layouts/default.yml +0 -3
- data/test/cms_seeds/test.host/layouts/nested.yml +0 -4
- data/test/cms_seeds/test.host/pages/broken.yml +0 -1
- data/test/cms_seeds/test.host/pages/child.yml +0 -10
- data/test/cms_seeds/test.host/pages/child/subchild.yml +0 -10
- data/test/cms_seeds/test.host/pages/index.yml +0 -10
- data/test/cms_seeds/test.host/snippets/broken.yml +0 -1
- data/test/cms_seeds/test.host/snippets/default.yml +0 -3
- data/test/integration/rake_tasks_test.rb +0 -65
- data/test/integration/render_cms_seed_test.rb +0 -34
- data/test/unit/cms_block_test.rb +0 -43
- data/test/unit/cms_layout_test.rb +0 -179
- data/test/unit/cms_page_test.rb +0 -257
- data/test/unit/cms_site_test.rb +0 -41
- data/test/unit/cms_snippet_test.rb +0 -77
- data/test/unit/cms_tags/field_datetime_test.rb +0 -34
- data/test/unit/cms_tags/field_integer_test.rb +0 -33
- data/test/unit/cms_tags/field_string_test.rb +0 -34
- data/test/unit/cms_tags/field_text_test.rb +0 -32
- data/test/unit/cms_tags/page_datetime_test.rb +0 -34
- data/test/unit/cms_tags/page_integer_test.rb +0 -33
- data/test/unit/cms_tags/page_rich_text.rb +0 -33
- data/test/unit/cms_tags/page_text_test.rb +0 -34
- data/test/unit/cms_tags/snippet_test.rb +0 -33
- 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
|
-
|
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 '
|
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 =>
|
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 '
|
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 '
|
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
|
-
|
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 '
|
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 =
|
52
|
-
assert_equal cms_sites(:default), snippet.
|
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 '
|
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 '
|
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 '
|
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
|
13
|
-
assert_no_difference '
|
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 '
|
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).
|
35
|
+
page = cms_sites(:default).pages.create!(
|
36
36
|
:label => '404',
|
37
37
|
:slug => '404',
|
38
38
|
:parent_id => cms_pages(:default).id,
|
39
|
-
:
|
39
|
+
:layout_id => cms_layouts(:default).id,
|
40
40
|
:is_published => '1',
|
41
|
-
:
|
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
|
-
|
87
|
+
assert_equal false, ComfortableMexicanSofa.config.allow_irb
|
72
88
|
|
73
|
-
irb_page = cms_sites(:default).
|
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
|
-
:
|
93
|
+
:layout_id => cms_layouts(:default).id,
|
78
94
|
:is_published => '1',
|
79
|
-
:
|
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.
|
106
|
+
ComfortableMexicanSofa.config.allow_irb = true
|
91
107
|
|
92
|
-
irb_page = cms_sites(:default).
|
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
|
-
:
|
112
|
+
:layout_id => cms_layouts(:default).id,
|
97
113
|
:is_published => '1',
|
98
|
-
:
|
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
|
-
|
12
|
-
assert_difference '
|
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 =
|
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 '
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
46
|
-
ComfortableMexicanSofa.config.
|
47
|
-
|
48
|
-
assert_no_difference '
|
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
|
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
|
18
|
-
config.authentication
|
19
|
-
config.
|
20
|
-
config.
|
21
|
-
config.
|
22
|
-
config.
|
23
|
-
config.
|
24
|
-
config.
|
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
|
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
|
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
|