comfortable_mexican_sofa 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/controllers/cms_admin/base_controller.rb +1 -1
- data/app/controllers/cms_admin/snippets_controller.rb +1 -0
- data/app/controllers/cms_content_controller.rb +1 -1
- data/app/models/cms/layout.rb +6 -11
- data/app/models/cms/page.rb +8 -3
- data/app/models/cms/site.rb +10 -2
- data/app/models/cms/snippet.rb +7 -2
- data/app/views/cms_admin/layouts/edit.html.erb +4 -0
- data/app/views/cms_admin/layouts/index.html.erb +4 -0
- data/app/views/cms_admin/pages/_form_blocks.html.erb +13 -3
- data/app/views/cms_admin/pages/edit.html.erb +4 -0
- data/app/views/cms_admin/pages/index.html.erb +4 -0
- data/app/views/cms_admin/sites/_mirrors.html.erb +20 -0
- data/app/views/cms_admin/snippets/edit.html.erb +4 -0
- data/app/views/cms_admin/snippets/index.html.erb +4 -0
- data/comfortable_mexican_sofa.gemspec +6 -2
- data/config/initializers/comfortable_mexican_sofa.rb +6 -1
- data/lib/comfortable_mexican_sofa.rb +1 -0
- data/lib/comfortable_mexican_sofa/configuration.rb +4 -0
- data/lib/comfortable_mexican_sofa/fixtures.rb +100 -18
- data/lib/comfortable_mexican_sofa/is_mirrored.rb +83 -0
- data/lib/tasks/comfortable_mexican_sofa.rake +15 -9
- data/public/javascripts/comfortable_mexican_sofa/cms.js +7 -0
- data/public/stylesheets/comfortable_mexican_sofa/content.css +6 -1
- data/public/stylesheets/comfortable_mexican_sofa/form.css +18 -0
- data/public/stylesheets/comfortable_mexican_sofa/structure.css +2 -7
- data/public/stylesheets/comfortable_mexican_sofa/typography.css +3 -0
- data/test/functional/cms_admin/layouts_controller_test.rb +2 -2
- data/test/functional/cms_admin/sites_controller_test.rb +2 -2
- data/test/functional/cms_admin/snippets_controller_test.rb +2 -2
- data/test/integration/mirrors_test.rb +75 -0
- data/test/test_helper.rb +1 -0
- data/test/unit/configuration_test.rb +1 -0
- data/test/unit/fixtures_test.rb +133 -43
- data/test/unit/mirrors_test.rb +153 -0
- data/test/unit/models/layout_test.rb +4 -20
- data/test/unit/models/page_test.rb +14 -4
- data/test/unit/models/site_test.rb +8 -2
- data/test/unit/models/snippet_test.rb +8 -0
- metadata +7 -3
@@ -0,0 +1,83 @@
|
|
1
|
+
module ComfortableMexicanSofa::IsMirrored
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.send :extend, ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
def is_mirrored
|
10
|
+
if ComfortableMexicanSofa.config.enable_mirror_sites
|
11
|
+
include ComfortableMexicanSofa::IsMirrored::InstanceMethods
|
12
|
+
|
13
|
+
attr_accessor :is_mirrored
|
14
|
+
|
15
|
+
after_save :sync_mirror
|
16
|
+
after_destroy :destroy_mirror
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module InstanceMethods
|
22
|
+
|
23
|
+
# Mirrors of the object found on other sites
|
24
|
+
def mirrors
|
25
|
+
(Cms::Site.all - [self.site]).collect do |site|
|
26
|
+
case self
|
27
|
+
when Cms::Layout then site.layouts.find_by_slug(self.slug)
|
28
|
+
when Cms::Page then site.pages.find_by_full_path(self.full_path)
|
29
|
+
when Cms::Snippet then site.snippets.find_by_slug(self.slug)
|
30
|
+
end
|
31
|
+
end.compact
|
32
|
+
end
|
33
|
+
|
34
|
+
# Creating or updating a mirror object. Relationships are mirrored
|
35
|
+
# but content is unique. When updating need to grab mirrors based on
|
36
|
+
# self.slug_was, new objects will use self.slug.
|
37
|
+
def sync_mirror
|
38
|
+
return if self.is_mirrored
|
39
|
+
|
40
|
+
(Cms::Site.all - [self.site]).each do |site|
|
41
|
+
mirror = case self
|
42
|
+
when Cms::Layout
|
43
|
+
m = site.layouts.find_by_slug(self.slug_was || self.slug) || site.layouts.new
|
44
|
+
m.attributes = {
|
45
|
+
:slug => self.slug,
|
46
|
+
:parent => site.layouts.find_by_slug(self.parent.try(:slug))
|
47
|
+
}
|
48
|
+
m
|
49
|
+
when Cms::Page
|
50
|
+
m = site.pages.find_by_full_path(self.full_path_was || self.full_path) || site.pages.new
|
51
|
+
m.attributes = {
|
52
|
+
:slug => self.slug,
|
53
|
+
:label => self.slug.blank?? self.label : m.label,
|
54
|
+
:parent => site.pages.find_by_full_path(self.parent.try(:full_path)),
|
55
|
+
:layout => site.layouts.find_by_slug(self.layout.slug)
|
56
|
+
}
|
57
|
+
m
|
58
|
+
when Cms::Snippet
|
59
|
+
m = site.snippets.find_by_slug(self.slug_was || self.slug) || site.snippets.new
|
60
|
+
m.attributes = {
|
61
|
+
:slug => self.slug
|
62
|
+
}
|
63
|
+
m
|
64
|
+
end
|
65
|
+
|
66
|
+
mirror.is_mirrored = true
|
67
|
+
mirror.save!
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Mirrors should be destroyed
|
72
|
+
def destroy_mirror
|
73
|
+
return if self.is_mirrored
|
74
|
+
mirrors.each do |mirror|
|
75
|
+
mirror.is_mirrored = true
|
76
|
+
mirror.destroy
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
ActiveRecord::Base.send :include, ComfortableMexicanSofa::IsMirrored
|
@@ -6,18 +6,24 @@ end
|
|
6
6
|
namespace :comfortable_mexican_sofa do
|
7
7
|
namespace :fixtures do
|
8
8
|
|
9
|
-
desc 'Import Fixture data into database
|
9
|
+
desc 'Import Fixture data into database (options: FOLDER=example.local SITE=example.com)'
|
10
10
|
task :import => :environment do |task, args|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
Cms::Site.first
|
15
|
-
end
|
16
|
-
abort 'SITE is not found. Aborting.' if !site
|
11
|
+
hostname = args[:site] || args[:folder]
|
12
|
+
site = Cms::Site.find_by_hostname(hostname)
|
13
|
+
abort "Site with hostname [#{hostname}] not found. Aborting." if !site
|
17
14
|
|
18
|
-
puts "
|
19
|
-
ComfortableMexicanSofa::Fixtures.
|
15
|
+
puts "Importing for #{site.hostname}"
|
16
|
+
ComfortableMexicanSofa::Fixtures.import_all(site.hostname, (args[:site] || site.hostname))
|
17
|
+
puts 'Done!'
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Export database data into Fixtures (options: SITE=example.com FOLDER=example.local)'
|
21
|
+
task :export => :environment do |task, args|
|
22
|
+
site = Cms::Site.find_by_hostname(args[:folder])
|
23
|
+
abort "Site with hostname [#{hostname}] not found. Aborting." if !site
|
20
24
|
|
25
|
+
puts "Exporting for #{site.hostname}"
|
26
|
+
ComfortableMexicanSofa::Fixtures.export_all((args[:site] || site.hostname), site.hostname)
|
21
27
|
puts 'Done!'
|
22
28
|
end
|
23
29
|
end
|
@@ -13,6 +13,7 @@ $.CMS = function(){
|
|
13
13
|
$.CMS.enable_desc_toggle();
|
14
14
|
$.CMS.enable_sortable_list();
|
15
15
|
if($('form.new_cms_page, form.edit_cms_page').get(0)) $.CMS.enable_page_save_form();
|
16
|
+
if($('#mirrors').get(0)) $.CMS.enable_mirrors_widget();
|
16
17
|
if($('#page_save').get(0)) $.CMS.enable_page_save_widget();
|
17
18
|
if($('#uploader_button').get(0)) $.CMS.enable_uploader();
|
18
19
|
});
|
@@ -148,6 +149,12 @@ $.CMS = function(){
|
|
148
149
|
})
|
149
150
|
});
|
150
151
|
},
|
152
|
+
|
153
|
+
enable_mirrors_widget: function(){
|
154
|
+
$('#mirrors select').change(function(){
|
155
|
+
window.location = $(this).val();
|
156
|
+
})
|
157
|
+
},
|
151
158
|
|
152
159
|
enable_page_save_widget : function(){
|
153
160
|
$('#page_save input').attr('checked', $('input#cms_page_is_published').is(':checked'));
|
@@ -1,3 +1,8 @@
|
|
1
|
+
/* -- Mirrors widget ----------------------------------------------------- */
|
2
|
+
#mirrors.box select {
|
3
|
+
width: 100%;
|
4
|
+
}
|
5
|
+
|
1
6
|
/* -- Page saving widget ------------------------------------------------- */
|
2
7
|
#page_save button {
|
3
8
|
float: right;
|
@@ -9,7 +14,6 @@
|
|
9
14
|
#page_save input {
|
10
15
|
margin-right: 5px;
|
11
16
|
}
|
12
|
-
|
13
17
|
/* -- File Upload widget ------------------------------------------------- */
|
14
18
|
#file_uploads .actions {
|
15
19
|
overflow: hidden;
|
@@ -173,6 +177,7 @@ form.search {
|
|
173
177
|
}
|
174
178
|
|
175
179
|
/* -- Page Specific stuff ------------------------------------------------ */
|
180
|
+
.c_cms_admin_sites.a_index ul.list li .item .label,
|
176
181
|
.c_cms_admin_layouts.a_index ul.list li .item .label,
|
177
182
|
.c_cms_admin_snippets.a_index ul.list li .item .label {
|
178
183
|
margin-left: 32px;
|
@@ -42,6 +42,24 @@
|
|
42
42
|
.page_form_extras {
|
43
43
|
margin-bottom: 10px;
|
44
44
|
}
|
45
|
+
#form_blocks .no_tags {
|
46
|
+
background-color: #252525;
|
47
|
+
color: #aaa;
|
48
|
+
border-radius: 3px;
|
49
|
+
margin-left: 150px;
|
50
|
+
text-align: center;
|
51
|
+
padding: 10px;
|
52
|
+
}
|
53
|
+
#form_blocks .no_tags a {
|
54
|
+
color: #fff;
|
55
|
+
}
|
56
|
+
#form_blocks .no_tags a:hover {
|
57
|
+
color: #aaa;
|
58
|
+
text-decoration: underline;
|
59
|
+
}
|
60
|
+
#form_blocks .no_tags code {
|
61
|
+
color: #B85042;
|
62
|
+
}
|
45
63
|
.form_element.field_datetime .label,
|
46
64
|
.form_element.field_integer .label,
|
47
65
|
.form_element.field_string .label,
|
@@ -15,8 +15,6 @@ html, body {
|
|
15
15
|
margin: 0px 250px 0px 175px;
|
16
16
|
min-height: 100%;
|
17
17
|
background-color: #D8D8D8;
|
18
|
-
border-left: 1px solid #484848;
|
19
|
-
border-right: 1px solid #484848;
|
20
18
|
}
|
21
19
|
.center_column .center_column_content {
|
22
20
|
padding: 25px;
|
@@ -69,19 +67,16 @@ html, body {
|
|
69
67
|
overflow: hidden;
|
70
68
|
color: #fff;
|
71
69
|
}
|
72
|
-
|
73
70
|
/* -- Flash Messages ----------------------------------------------------- */
|
74
71
|
.flash {
|
75
72
|
text-align: center;
|
76
|
-
|
73
|
+
padding: 8px;
|
77
74
|
color: #fff;
|
78
75
|
background-color: #066B12;
|
79
|
-
margin: 0px 2px;
|
80
76
|
}
|
81
77
|
.flash.error {
|
82
78
|
background-color: #9e0b0f;
|
83
79
|
}
|
84
|
-
|
85
80
|
/* -- Buttons ------------------------------------------------------------ */
|
86
81
|
a.button,
|
87
82
|
button,
|
@@ -130,7 +125,7 @@ input[type='file'] {
|
|
130
125
|
a.button.big {
|
131
126
|
float: right;
|
132
127
|
}
|
133
|
-
|
128
|
+
/* -- Sofa Version ------------------------------------------------------- */
|
134
129
|
.center_column .sofa {
|
135
130
|
position: absolute;
|
136
131
|
background: #000;
|
@@ -82,12 +82,12 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase
|
|
82
82
|
def test_update_failure
|
83
83
|
layout = cms_layouts(:default)
|
84
84
|
put :update, :id => layout, :cms_layout => {
|
85
|
-
:
|
85
|
+
:slug => ''
|
86
86
|
}
|
87
87
|
assert_response :success
|
88
88
|
assert_template :edit
|
89
89
|
layout.reload
|
90
|
-
assert_not_equal '', layout.
|
90
|
+
assert_not_equal '', layout.slug
|
91
91
|
assert_equal 'Failed to update layout', flash[:error]
|
92
92
|
end
|
93
93
|
|
@@ -80,12 +80,12 @@ class CmsAdmin::SitesControllerTest < ActionController::TestCase
|
|
80
80
|
def test_update_failure
|
81
81
|
site = cms_sites(:default)
|
82
82
|
put :update, :id => site, :cms_site => {
|
83
|
-
:
|
83
|
+
:hostname => ''
|
84
84
|
}
|
85
85
|
assert_response :success
|
86
86
|
assert_template :edit
|
87
87
|
site.reload
|
88
|
-
assert_not_equal '', site.
|
88
|
+
assert_not_equal '', site.hostname
|
89
89
|
assert_equal 'Failed to update site', flash[:error]
|
90
90
|
end
|
91
91
|
|
@@ -81,12 +81,12 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
|
|
81
81
|
def test_update_failure
|
82
82
|
snippet = cms_snippets(:default)
|
83
83
|
put :update, :id => snippet, :cms_snippet => {
|
84
|
-
:
|
84
|
+
:slug => ''
|
85
85
|
}
|
86
86
|
assert_response :success
|
87
87
|
assert_template :edit
|
88
88
|
snippet.reload
|
89
|
-
assert_not_equal '', snippet.
|
89
|
+
assert_not_equal '', snippet.slug
|
90
90
|
assert_equal 'Failed to update snippet', flash[:error]
|
91
91
|
end
|
92
92
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class MirrorsTest < ActionDispatch::IntegrationTest
|
4
|
+
|
5
|
+
def setup
|
6
|
+
ComfortableMexicanSofa.config.enable_mirror_sites = true
|
7
|
+
Cms::Site.create!(:hostname => 'test-b.host')
|
8
|
+
load(File.expand_path('app/models/cms/layout.rb', Rails.root))
|
9
|
+
load(File.expand_path('app/models/cms/page.rb', Rails.root))
|
10
|
+
load(File.expand_path('app/models/cms/snippet.rb', Rails.root))
|
11
|
+
|
12
|
+
# making mirrors
|
13
|
+
Cms::Layout.all.each{ |l| l.save! }
|
14
|
+
Cms::Page.all.each{ |p| p.save! }
|
15
|
+
Cms::Snippet.all.each { |s| s.save! }
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_get_layouts
|
19
|
+
http_auth :get, cms_admin_layouts_path
|
20
|
+
assert_response :success
|
21
|
+
assert_select 'select#mirror' do
|
22
|
+
assert_select 'option[value="http://test-b.host/cms-admin/layouts"]'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_get_layouts_edit
|
27
|
+
layout = cms_layouts(:default)
|
28
|
+
assert mirror = layout.mirrors.first
|
29
|
+
|
30
|
+
http_auth :get, edit_cms_admin_layout_path(layout)
|
31
|
+
assert_response :success
|
32
|
+
assert_select 'select#mirror' do
|
33
|
+
assert_select "option[value='http://test-b.host/cms-admin/layouts/#{mirror.id}/edit']"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_get_pages
|
38
|
+
http_auth :get, cms_admin_pages_path
|
39
|
+
assert_response :success
|
40
|
+
assert_select 'select#mirror' do
|
41
|
+
assert_select 'option[value="http://test-b.host/cms-admin/pages"]'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_get_pages_edit
|
46
|
+
page = cms_pages(:default)
|
47
|
+
assert mirror = page.mirrors.first
|
48
|
+
|
49
|
+
http_auth :get, edit_cms_admin_page_path(page)
|
50
|
+
assert_response :success
|
51
|
+
assert_select 'select#mirror' do
|
52
|
+
assert_select "option[value='http://test-b.host/cms-admin/pages/#{mirror.id}/edit']"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_get_snippets
|
57
|
+
http_auth :get, cms_admin_snippets_path
|
58
|
+
assert_response :success
|
59
|
+
assert_select 'select#mirror' do
|
60
|
+
assert_select 'option[value="http://test-b.host/cms-admin/snippets"]'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_get_snippets_edit
|
65
|
+
snippet = cms_snippets(:default)
|
66
|
+
assert mirror = snippet.mirrors.first
|
67
|
+
|
68
|
+
http_auth :get, edit_cms_admin_snippet_path(snippet)
|
69
|
+
assert_response :success
|
70
|
+
assert_select 'select#mirror' do
|
71
|
+
assert_select "option[value='http://test-b.host/cms-admin/snippets/#{mirror.id}/edit']"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -20,6 +20,7 @@ class ActiveSupport::TestCase
|
|
20
20
|
config.content_route_prefix = ''
|
21
21
|
config.admin_route_redirect = 'pages'
|
22
22
|
config.enable_multiple_sites = false
|
23
|
+
config.enable_mirror_sites = false
|
23
24
|
config.allow_irb = false
|
24
25
|
config.enable_caching = true
|
25
26
|
config.enable_fixtures = false
|
@@ -10,6 +10,7 @@ class ConfigurationTest < ActiveSupport::TestCase
|
|
10
10
|
assert_equal '', config.content_route_prefix
|
11
11
|
assert_equal 'pages', config.admin_route_redirect
|
12
12
|
assert_equal false, config.enable_multiple_sites
|
13
|
+
assert_equal false, config.enable_mirror_sites
|
13
14
|
assert_equal false, config.allow_irb
|
14
15
|
assert_equal true, config.enable_caching
|
15
16
|
assert_equal false, config.enable_fixtures
|
data/test/unit/fixtures_test.rb
CHANGED
@@ -2,30 +2,12 @@ require File.expand_path('../test_helper', File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
class FixturesTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
def
|
6
|
-
@site = cms_sites(:default)
|
7
|
-
@site.update_attribute(:hostname, 'example.com')
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_sync
|
11
|
-
Cms::Page.destroy_all
|
12
|
-
Cms::Layout.destroy_all
|
13
|
-
Cms::Snippet.destroy_all
|
14
|
-
|
15
|
-
assert_difference 'Cms::Layout.count', 2 do
|
16
|
-
assert_difference 'Cms::Page.count', 2 do
|
17
|
-
assert_difference 'Cms::Snippet.count', 1 do
|
18
|
-
ComfortableMexicanSofa::Fixtures.sync(@site)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_sync_layouts_creating
|
5
|
+
def test_import_layouts_creating
|
25
6
|
Cms::Layout.delete_all
|
26
7
|
|
27
8
|
assert_difference 'Cms::Layout.count', 2 do
|
28
|
-
ComfortableMexicanSofa::Fixtures.
|
9
|
+
ComfortableMexicanSofa::Fixtures.import_layouts('test.host', 'example.com')
|
10
|
+
|
29
11
|
assert layout = Cms::Layout.find_by_slug('default')
|
30
12
|
assert_equal 'Default Fixture Layout', layout.label
|
31
13
|
assert_equal "<html>\n <body>\n {{ cms:page:content }}\n </body>\n</html>", layout.content
|
@@ -41,8 +23,7 @@ class FixturesTest < ActiveSupport::TestCase
|
|
41
23
|
end
|
42
24
|
end
|
43
25
|
|
44
|
-
def
|
45
|
-
|
26
|
+
def test_import_layouts_updating_and_deleting
|
46
27
|
layout = cms_layouts(:default)
|
47
28
|
nested_layout = cms_layouts(:nested)
|
48
29
|
child_layout = cms_layouts(:child)
|
@@ -51,7 +32,7 @@ class FixturesTest < ActiveSupport::TestCase
|
|
51
32
|
child_layout.update_attribute(:updated_at, 10.years.ago)
|
52
33
|
|
53
34
|
assert_difference 'Cms::Layout.count', -1 do
|
54
|
-
ComfortableMexicanSofa::Fixtures.
|
35
|
+
ComfortableMexicanSofa::Fixtures.import_layouts('test.host', 'example.com')
|
55
36
|
|
56
37
|
layout.reload
|
57
38
|
assert_equal 'Default Fixture Layout', layout.label
|
@@ -70,9 +51,9 @@ class FixturesTest < ActiveSupport::TestCase
|
|
70
51
|
end
|
71
52
|
end
|
72
53
|
|
73
|
-
def
|
54
|
+
def test_import_layouts_ignoring
|
74
55
|
layout = cms_layouts(:default)
|
75
|
-
layout_path = File.join(ComfortableMexicanSofa.config.fixtures_path,
|
56
|
+
layout_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'example.com', 'layouts', 'default')
|
76
57
|
attr_file_path = File.join(layout_path, '_default.yml')
|
77
58
|
content_file_path = File.join(layout_path, 'content.html')
|
78
59
|
css_file_path = File.join(layout_path, 'css.css')
|
@@ -83,7 +64,7 @@ class FixturesTest < ActiveSupport::TestCase
|
|
83
64
|
assert layout.updated_at >= File.mtime(css_file_path)
|
84
65
|
assert layout.updated_at >= File.mtime(js_file_path)
|
85
66
|
|
86
|
-
ComfortableMexicanSofa::Fixtures.
|
67
|
+
ComfortableMexicanSofa::Fixtures.import_layouts('test.host', 'example.com')
|
87
68
|
layout.reload
|
88
69
|
assert_equal 'default', layout.slug
|
89
70
|
assert_equal 'Default Layout', layout.label
|
@@ -92,7 +73,7 @@ class FixturesTest < ActiveSupport::TestCase
|
|
92
73
|
assert_equal 'default_js', layout.js
|
93
74
|
end
|
94
75
|
|
95
|
-
def
|
76
|
+
def test_import_pages_creating
|
96
77
|
Cms::Page.delete_all
|
97
78
|
|
98
79
|
layout = cms_layouts(:default)
|
@@ -102,7 +83,7 @@ class FixturesTest < ActiveSupport::TestCase
|
|
102
83
|
nested.update_attribute(:content, '<html>{{cms:page:left}}<br/>{{cms:page:right}}</html>')
|
103
84
|
|
104
85
|
assert_difference 'Cms::Page.count', 2 do
|
105
|
-
ComfortableMexicanSofa::Fixtures.
|
86
|
+
ComfortableMexicanSofa::Fixtures.import_pages('test.host', 'example.com')
|
106
87
|
|
107
88
|
assert page = Cms::Page.find_by_full_path('/')
|
108
89
|
assert_equal layout, page.layout
|
@@ -118,7 +99,7 @@ class FixturesTest < ActiveSupport::TestCase
|
|
118
99
|
end
|
119
100
|
end
|
120
101
|
|
121
|
-
def
|
102
|
+
def test_import_pages_updating_and_deleting
|
122
103
|
page = cms_pages(:default)
|
123
104
|
page.update_attribute(:updated_at, 10.years.ago)
|
124
105
|
assert_equal 'Default Page', page.label
|
@@ -127,7 +108,7 @@ class FixturesTest < ActiveSupport::TestCase
|
|
127
108
|
child.update_attribute(:slug, 'old')
|
128
109
|
|
129
110
|
assert_no_difference 'Cms::Page.count' do
|
130
|
-
ComfortableMexicanSofa::Fixtures.
|
111
|
+
ComfortableMexicanSofa::Fixtures.import_pages('test.host', 'example.com')
|
131
112
|
|
132
113
|
page.reload
|
133
114
|
assert_equal 'Home Fixture Page', page.label
|
@@ -136,27 +117,27 @@ class FixturesTest < ActiveSupport::TestCase
|
|
136
117
|
end
|
137
118
|
end
|
138
119
|
|
139
|
-
def
|
120
|
+
def test_import_pages_ignoring
|
140
121
|
page = cms_pages(:default)
|
141
|
-
page_path = File.join(ComfortableMexicanSofa.config.fixtures_path,
|
122
|
+
page_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'example.com', 'pages', 'index')
|
142
123
|
attr_file_path = File.join(page_path, '_index.yml')
|
143
124
|
content_file_path = File.join(page_path, 'content.html')
|
144
125
|
|
145
126
|
assert page.updated_at >= File.mtime(attr_file_path)
|
146
127
|
assert page.updated_at >= File.mtime(content_file_path)
|
147
128
|
|
148
|
-
ComfortableMexicanSofa::Fixtures.
|
129
|
+
ComfortableMexicanSofa::Fixtures.import_pages('test.host', 'example.com')
|
149
130
|
page.reload
|
150
131
|
assert_equal nil, page.slug
|
151
132
|
assert_equal 'Default Page', page.label
|
152
133
|
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
|
153
134
|
end
|
154
135
|
|
155
|
-
def
|
136
|
+
def test_import_snippets_creating
|
156
137
|
Cms::Snippet.delete_all
|
157
138
|
|
158
139
|
assert_difference 'Cms::Snippet.count' do
|
159
|
-
ComfortableMexicanSofa::Fixtures.
|
140
|
+
ComfortableMexicanSofa::Fixtures.import_snippets('test.host', 'example.com')
|
160
141
|
assert snippet = Cms::Snippet.last
|
161
142
|
assert_equal 'default', snippet.slug
|
162
143
|
assert_equal 'Default Fixture Snippet', snippet.label
|
@@ -164,7 +145,7 @@ class FixturesTest < ActiveSupport::TestCase
|
|
164
145
|
end
|
165
146
|
end
|
166
147
|
|
167
|
-
def
|
148
|
+
def test_import_snippets_updating
|
168
149
|
snippet = cms_snippets(:default)
|
169
150
|
snippet.update_attribute(:updated_at, 10.years.ago)
|
170
151
|
assert_equal 'default', snippet.slug
|
@@ -172,7 +153,7 @@ class FixturesTest < ActiveSupport::TestCase
|
|
172
153
|
assert_equal 'default_snippet_content', snippet.content
|
173
154
|
|
174
155
|
assert_no_difference 'Cms::Snippet.count' do
|
175
|
-
ComfortableMexicanSofa::Fixtures.
|
156
|
+
ComfortableMexicanSofa::Fixtures.import_snippets('test.host', 'example.com')
|
176
157
|
snippet.reload
|
177
158
|
assert_equal 'default', snippet.slug
|
178
159
|
assert_equal 'Default Fixture Snippet', snippet.label
|
@@ -180,12 +161,12 @@ class FixturesTest < ActiveSupport::TestCase
|
|
180
161
|
end
|
181
162
|
end
|
182
163
|
|
183
|
-
def
|
164
|
+
def test_import_snippets_deleting
|
184
165
|
snippet = cms_snippets(:default)
|
185
166
|
snippet.update_attribute(:slug, 'old')
|
186
167
|
|
187
168
|
assert_no_difference 'Cms::Snippet.count' do
|
188
|
-
ComfortableMexicanSofa::Fixtures.
|
169
|
+
ComfortableMexicanSofa::Fixtures.import_snippets('test.host', 'example.com')
|
189
170
|
assert snippet = Cms::Snippet.last
|
190
171
|
assert_equal 'default', snippet.slug
|
191
172
|
assert_equal 'Default Fixture Snippet', snippet.label
|
@@ -195,20 +176,129 @@ class FixturesTest < ActiveSupport::TestCase
|
|
195
176
|
end
|
196
177
|
end
|
197
178
|
|
198
|
-
def
|
179
|
+
def test_import_snippets_ignoring
|
199
180
|
snippet = cms_snippets(:default)
|
200
|
-
snippet_path = File.join(ComfortableMexicanSofa.config.fixtures_path,
|
181
|
+
snippet_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'example.com', 'snippets', 'default')
|
201
182
|
attr_file_path = File.join(snippet_path, '_default.yml')
|
202
183
|
content_file_path = File.join(snippet_path, 'content.html')
|
203
184
|
|
204
185
|
assert snippet.updated_at >= File.mtime(attr_file_path)
|
205
186
|
assert snippet.updated_at >= File.mtime(content_file_path)
|
206
187
|
|
207
|
-
ComfortableMexicanSofa::Fixtures.
|
188
|
+
ComfortableMexicanSofa::Fixtures.import_snippets('test.host', 'example.com')
|
208
189
|
snippet.reload
|
209
190
|
assert_equal 'default', snippet.slug
|
210
191
|
assert_equal 'Default Snippet', snippet.label
|
211
192
|
assert_equal 'default_snippet_content', snippet.content
|
212
193
|
end
|
213
194
|
|
195
|
+
def test_import_all
|
196
|
+
Cms::Page.destroy_all
|
197
|
+
Cms::Layout.destroy_all
|
198
|
+
Cms::Snippet.destroy_all
|
199
|
+
|
200
|
+
assert_difference 'Cms::Layout.count', 2 do
|
201
|
+
assert_difference 'Cms::Page.count', 2 do
|
202
|
+
assert_difference 'Cms::Snippet.count', 1 do
|
203
|
+
ComfortableMexicanSofa::Fixtures.import_all('test.host', 'example.com')
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_export_layouts
|
210
|
+
host_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'test.test')
|
211
|
+
layout_1_attr_path = File.join(host_path, 'layouts/nested/_nested.yml')
|
212
|
+
layout_1_content_path = File.join(host_path, 'layouts/nested/content.html')
|
213
|
+
layout_1_css_path = File.join(host_path, 'layouts/nested/css.css')
|
214
|
+
layout_1_js_path = File.join(host_path, 'layouts/nested/js.js')
|
215
|
+
layout_2_attr_path = File.join(host_path, 'layouts/nested/child/_child.yml')
|
216
|
+
layout_2_content_path = File.join(host_path, 'layouts/nested/child/content.html')
|
217
|
+
layout_2_css_path = File.join(host_path, 'layouts/nested/child/css.css')
|
218
|
+
layout_2_js_path = File.join(host_path, 'layouts/nested/child/js.js')
|
219
|
+
|
220
|
+
ComfortableMexicanSofa::Fixtures.export_layouts('test.host', 'test.test')
|
221
|
+
|
222
|
+
assert File.exists?(layout_1_attr_path)
|
223
|
+
assert File.exists?(layout_1_content_path)
|
224
|
+
assert File.exists?(layout_1_css_path)
|
225
|
+
assert File.exists?(layout_1_js_path)
|
226
|
+
|
227
|
+
assert File.exists?(layout_2_attr_path)
|
228
|
+
assert File.exists?(layout_2_content_path)
|
229
|
+
assert File.exists?(layout_2_css_path)
|
230
|
+
assert File.exists?(layout_2_js_path)
|
231
|
+
|
232
|
+
assert_equal ({
|
233
|
+
'label' => 'Nested Layout',
|
234
|
+
'app_layout' => nil,
|
235
|
+
'parent' => nil
|
236
|
+
}), YAML.load_file(layout_1_attr_path)
|
237
|
+
assert_equal cms_layouts(:nested).content, IO.read(layout_1_content_path)
|
238
|
+
assert_equal cms_layouts(:nested).css, IO.read(layout_1_css_path)
|
239
|
+
assert_equal cms_layouts(:nested).js, IO.read(layout_1_js_path)
|
240
|
+
|
241
|
+
assert_equal ({
|
242
|
+
'label' => 'Child Layout',
|
243
|
+
'app_layout' => nil,
|
244
|
+
'parent' => 'nested'
|
245
|
+
}), YAML.load_file(layout_2_attr_path)
|
246
|
+
assert_equal cms_layouts(:child).content, IO.read(layout_2_content_path)
|
247
|
+
assert_equal cms_layouts(:child).css, IO.read(layout_2_css_path)
|
248
|
+
assert_equal cms_layouts(:child).js, IO.read(layout_2_js_path)
|
249
|
+
|
250
|
+
FileUtils.rm_rf(host_path)
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_export_pages
|
254
|
+
host_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'test.test')
|
255
|
+
page_1_attr_path = File.join(host_path, 'pages/index/_index.yml')
|
256
|
+
page_1_block_a_path = File.join(host_path, 'pages/index/default_field_text.html')
|
257
|
+
page_1_block_b_path = File.join(host_path, 'pages/index/default_page_text.html')
|
258
|
+
page_2_attr_path = File.join(host_path, 'pages/index/child-page/_child-page.yml')
|
259
|
+
|
260
|
+
ComfortableMexicanSofa::Fixtures.export_pages('test.host', 'test.test')
|
261
|
+
|
262
|
+
assert_equal ({
|
263
|
+
'label' => 'Default Page',
|
264
|
+
'layout' => 'default',
|
265
|
+
'parent' => nil,
|
266
|
+
'target_page' => nil,
|
267
|
+
'is_published' => true
|
268
|
+
}), YAML.load_file(page_1_attr_path)
|
269
|
+
assert_equal cms_blocks(:default_field_text).content, IO.read(page_1_block_a_path)
|
270
|
+
assert_equal cms_blocks(:default_page_text).content, IO.read(page_1_block_b_path)
|
271
|
+
|
272
|
+
assert_equal ({
|
273
|
+
'label' => 'Child Page',
|
274
|
+
'layout' => 'default',
|
275
|
+
'parent' => 'index',
|
276
|
+
'target_page' => nil,
|
277
|
+
'is_published' => true
|
278
|
+
}), YAML.load_file(page_2_attr_path)
|
279
|
+
|
280
|
+
FileUtils.rm_rf(host_path)
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_export_snippets
|
284
|
+
host_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'test.test')
|
285
|
+
attr_path = File.join(host_path, 'snippets/default/_default.yml')
|
286
|
+
content_path = File.join(host_path, 'snippets/default/content.html')
|
287
|
+
|
288
|
+
ComfortableMexicanSofa::Fixtures.export_snippets('test.host', 'test.test')
|
289
|
+
|
290
|
+
assert File.exists?(attr_path)
|
291
|
+
assert File.exists?(content_path)
|
292
|
+
assert_equal ({'label' => 'Default Snippet'}), YAML.load_file(attr_path)
|
293
|
+
assert_equal cms_snippets(:default).content, IO.read(content_path)
|
294
|
+
|
295
|
+
FileUtils.rm_rf(host_path)
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_export_all
|
299
|
+
host_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'test.test')
|
300
|
+
ComfortableMexicanSofa::Fixtures.export_all('test.host', 'test.test')
|
301
|
+
FileUtils.rm_rf(host_path)
|
302
|
+
end
|
303
|
+
|
214
304
|
end
|