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
@@ -1,28 +0,0 @@
1
- class CmsBlock < ActiveRecord::Base
2
-
3
- # -- Relationships --------------------------------------------------------
4
- belongs_to :cms_page
5
-
6
- # -- Validations ----------------------------------------------------------
7
- validates :label,
8
- :presence => true,
9
- :uniqueness => { :scope => :cms_page_id }
10
-
11
- # -- Class Methods --------------------------------------------------------
12
- def self.initialize_or_find(cms_page, label)
13
- if block = cms_page.cms_blocks.detect{ |b| b.label == label.to_s }
14
- self.new(
15
- :record_id => block.id,
16
- :cms_page => cms_page,
17
- :label => block.label,
18
- :content => block.content
19
- )
20
- else
21
- self.new(
22
- :label => label.to_s,
23
- :cms_page => cms_page
24
- )
25
- end
26
- end
27
-
28
- end
@@ -1,69 +0,0 @@
1
- class CmsSnippet < ActiveRecord::Base
2
-
3
- # -- Relationships --------------------------------------------------------
4
- belongs_to :cms_site
5
-
6
- # -- Callbacks ------------------------------------------------------------
7
- after_save :clear_cached_page_content
8
- after_destroy :clear_cached_page_content
9
-
10
- # -- Validations ----------------------------------------------------------
11
- validates :cms_site_id,
12
- :presence => true
13
- validates :label,
14
- :presence => true
15
- validates :slug,
16
- :presence => true,
17
- :uniqueness => { :scope => :cms_site_id },
18
- :format => { :with => /^\w[a-z0-9_-]*$/i }
19
-
20
- # -- Class Methods --------------------------------------------------------
21
- def self.content_for(slug)
22
- (s = find_by_slug(slug)) ? s.content : ''
23
- end
24
-
25
- def self.initialize_or_find(cms_page, slug)
26
- load_for_slug(cms_page.cms_site, slug) || new(:slug => slug)
27
- end
28
-
29
- # Attempting to initialize snippet object from yaml file that is found in config.seed_data_path
30
- def self.load_from_file(site, name)
31
- return nil if ComfortableMexicanSofa.config.seed_data_path.blank?
32
- file_path = "#{ComfortableMexicanSofa.config.seed_data_path}/#{site.hostname}/snippets/#{name}.yml"
33
- return nil unless File.exists?(file_path)
34
- attributes = YAML.load_file(file_path).symbolize_keys!
35
- new(attributes)
36
- rescue
37
- raise "Failed to load from #{file_path}"
38
- end
39
-
40
- # Wrapper around load_from_file and find_by_slug
41
- # returns layout object if loaded / found
42
- def self.load_for_slug!(site, slug)
43
- if ComfortableMexicanSofa.configuration.seed_data_path
44
- load_from_file(site, slug)
45
- else
46
- # FIX: This a bit odd... Snippet is used as a tag, so sometimes there's no site scope
47
- # being passed. So we're enforcing this only if it's found. Need to review.
48
- conditions = site ? {:conditions => {:cms_site_id => site.id}} : {}
49
- find_by_slug(slug, conditions)
50
- end || raise(ActiveRecord::RecordNotFound, "CmsSnippet with slug: #{slug} cannot be found")
51
- end
52
-
53
- # Non-blowing-up version of the method above
54
- def self.load_for_slug(site, slug)
55
- load_for_slug!(site, slug)
56
- rescue ActiveRecord::RecordNotFound
57
- nil
58
- end
59
-
60
- protected
61
-
62
- # Note: This might be slow. We have no idea where the snippet is used, so
63
- # gotta reload every single page. Kinda sucks, but might be ok unless there
64
- # are hundreds of pages.
65
- def clear_cached_page_content
66
- CmsPage.all.each{ |page| page.save! }
67
- end
68
-
69
- end
@@ -1,8 +0,0 @@
1
- label: Default Layout
2
- slug: default
3
- content: |-
4
- <html>
5
- <body>
6
- {{ cms:page:content }}
7
- </body>
8
- </html>
@@ -1,6 +0,0 @@
1
- label: Nested Layout
2
- slug: nested
3
- parent: default
4
- content: |-
5
- <div class='left'> {{ cms:page:left }} </div>
6
- <div class='left'> {{ cms:page:right }} </div>
@@ -1,10 +0,0 @@
1
- label: Child Page
2
- parent: /
3
- cms_layout: default
4
- full_path: /child
5
- slug: child
6
- cms_blocks_attributes:
7
- -
8
- label: content
9
- content: |-
10
- Child Page Content
@@ -1,14 +0,0 @@
1
- label: Sub-Child Page
2
- parent: /child
3
- cms_layout: nested
4
- full_path: /child/subchild
5
- slug: subchild
6
- cms_blocks_attributes:
7
- -
8
- label: left
9
- content: |-
10
- Sub Child Page Left Content
11
- -
12
- label: right
13
- content: |-
14
- Sub Child Page Right Content
@@ -1,11 +0,0 @@
1
- label: Home Page
2
- parent:
3
- cms_layout: default
4
- full_path: /
5
- slug:
6
- cms_blocks_attributes:
7
- -
8
- label: content
9
- content: |-
10
- Home Page Content
11
- {{ cms:snippet:example }}
@@ -1,4 +0,0 @@
1
- label: Example Snippet
2
- slug: example
3
- content: |-
4
- Content for Example Snippet
@@ -1,18 +0,0 @@
1
- class CmsTag::Snippet < CmsSnippet
2
-
3
- include CmsTag
4
-
5
- def identifier
6
- "#{self.class.name.underscore}_#{self.slug}"
7
- end
8
-
9
- def self.regex_tag_signature(label = nil)
10
- label ||= /[\w\-]+/
11
- /\{\{\s*cms:snippet:(#{label})\s*\}\}/
12
- end
13
-
14
- def content
15
- self.read_attribute(:content)
16
- end
17
-
18
- end
@@ -1 +0,0 @@
1
- broken yml file
@@ -1,3 +0,0 @@
1
- label: Default Layout
2
- slug: default
3
- content: <html>{{cms:page:content}}</html>
@@ -1,4 +0,0 @@
1
- label: Nested Layout
2
- slug: nested
3
- parent: default
4
- content: <div>{{cms:page:content}}</div>
@@ -1 +0,0 @@
1
- broken yml file
@@ -1,10 +0,0 @@
1
- label: Child Page
2
- parent: /
3
- cms_layout: default
4
- full_path: /child
5
- slug: child
6
- cms_blocks_attributes:
7
- -
8
- label: content
9
- content: |-
10
- Child Page Content
@@ -1,10 +0,0 @@
1
- label: Child Page
2
- parent: /child
3
- cms_layout: nested
4
- full_path: /child/subchild
5
- slug: subchild
6
- cms_blocks_attributes:
7
- -
8
- label: content
9
- content: |-
10
- Sub Child Page Content {{cms:snippet:default}}
@@ -1,10 +0,0 @@
1
- label: Default Page
2
- parent:
3
- cms_layout: default
4
- full_path: /
5
- slug:
6
- cms_blocks_attributes:
7
- -
8
- label: content
9
- content: |-
10
- Default Page Content
@@ -1 +0,0 @@
1
- broken yml file
@@ -1,3 +0,0 @@
1
- label: Default Snippet
2
- slug: default
3
- content: Content for Default Snippet
@@ -1,65 +0,0 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
2
-
3
- require 'rake'
4
- require 'rake/rdoctask'
5
- require 'rake/testtask'
6
-
7
- Rake.application.rake_require '../lib/tasks/comfortable_mexican_sofa'
8
-
9
- class RakeTasksTest < ActionDispatch::IntegrationTest
10
-
11
- def test_layouts_import
12
- CmsLayout.destroy_all
13
- ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
14
-
15
- assert_difference 'CmsLayout.count', 2 do
16
- capture_rake_output{
17
- Rake.application['comfortable_mexican_sofa:import:check_for_requirements'].execute(
18
- :from => 'test.host', :to => 'test.host' )
19
- Rake.application['comfortable_mexican_sofa:import:layouts'].execute(
20
- :from => 'test.host', :to => 'test.host' )
21
- }
22
- end
23
- end
24
-
25
- def test_pages_import
26
- CmsPage.destroy_all
27
- ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
28
-
29
- assert_difference ['CmsPage.count', 'CmsBlock.count'], 3 do
30
- capture_rake_output{
31
- Rake.application['comfortable_mexican_sofa:import:check_for_requirements'].execute(
32
- :from => 'test.host', :to => 'test.host' )
33
- Rake.application['comfortable_mexican_sofa:import:pages'].execute(
34
- :from => 'test.host', :to => 'test.host' )
35
- }
36
- end
37
- end
38
-
39
- def test_snippets_import
40
- CmsSnippet.destroy_all
41
- ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
42
-
43
- assert_difference 'CmsSnippet.count', 1 do
44
- capture_rake_output{
45
- Rake.application['comfortable_mexican_sofa:import:check_for_requirements'].execute(
46
- :from => 'test.host', :to => 'test.host' )
47
- Rake.application['comfortable_mexican_sofa:import:snippets'].execute(
48
- :from => 'test.host', :to => 'test.host' )
49
- }
50
- end
51
- end
52
-
53
- protected
54
-
55
- def capture_rake_output
56
- s = StringIO.new
57
- oldstdout = $stdout
58
- $stdout = s
59
- yield
60
- s.string
61
- ensure
62
- $stdout = oldstdout
63
- end
64
-
65
- end
@@ -1,34 +0,0 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
2
-
3
- class RenderCmsSeedTest < ActionDispatch::IntegrationTest
4
-
5
- def test_render_with_seed_data_enabled
6
- get '/child/subchild'
7
- assert_response 404
8
-
9
- ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
10
-
11
- get '/child/subchild'
12
- assert_response :success
13
- assert_equal '<html><div>Sub Child Page Content Content for Default Snippet</div></html>', response.body
14
- end
15
-
16
- def test_get_seed_data_page
17
- ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
18
-
19
- get '/'
20
- assert_response :success
21
- assert assigns(:cms_page)
22
- assert assigns(:cms_page).new_record?
23
- end
24
-
25
- def test_get_seed_data_css
26
- ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
27
-
28
- get '/cms-css/default'
29
- assert_response :success
30
- assert assigns(:cms_layout)
31
- assert assigns(:cms_layout).new_record?
32
- end
33
-
34
- end
@@ -1,43 +0,0 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
2
-
3
- class CmsBlockTest < ActiveSupport::TestCase
4
-
5
- def test_fixtures_validity
6
- CmsBlock.all.each do |block|
7
- assert block.valid?, block.errors.full_messages.to_s
8
- end
9
- end
10
-
11
- def test_new_via_page_nested_attributes
12
- assert_difference ['CmsPage.count', 'CmsBlock.count'] do
13
- page = CmsPage.create!(
14
- :cms_site => cms_sites(:default),
15
- :cms_layout => cms_layouts(:default),
16
- :label => 'test page',
17
- :slug => 'test_page',
18
- :parent_id => cms_pages(:default).id,
19
- :cms_blocks_attributes => [
20
- {
21
- :label => 'test_block',
22
- :content => 'test_content'
23
- }
24
- ]
25
- )
26
- assert_equal 1, page.cms_blocks.count
27
- block = page.cms_blocks.first
28
- assert_equal 'test_block', block.label
29
- assert_equal 'test_content', block.content
30
- end
31
- end
32
-
33
- def test_initialize_or_find
34
- tag = CmsTag::PageText.initialize_or_find(cms_pages(:default), :default_field_text)
35
- assert_equal 'default_field_text', tag.label
36
- assert_equal 'default_field_text_content', tag.content
37
-
38
- tag = CmsTag::PageText.initialize_or_find(cms_pages(:default), :new_block)
39
- assert_equal 'new_block', tag.label
40
- assert tag.content.blank?
41
- end
42
-
43
- end
@@ -1,179 +0,0 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
2
-
3
- class CmsLayoutTest < ActiveSupport::TestCase
4
-
5
- def test_fixtures_validity
6
- CmsLayout.all.each do |layout|
7
- assert layout.valid?, layout.errors.full_messages.to_s
8
- end
9
- end
10
-
11
- def test_validations
12
- layout = CmsLayout.create
13
- assert layout.errors.present?
14
- assert_has_errors_on layout, [:label, :slug, :content]
15
- end
16
-
17
- def test_validation_of_tag_presence
18
- layout = CmsLayout.create(:content => 'some text')
19
- assert_has_errors_on layout, :content
20
-
21
- layout = CmsLayout.create(:content => '{cms:snippet:blah}')
22
- assert_has_errors_on layout, :content
23
-
24
- layout = cms_sites(:default).cms_layouts.new(
25
- :label => 'test',
26
- :slug => 'test',
27
- :content => '{{cms:page:blah}}'
28
- )
29
- assert layout.valid?
30
-
31
- layout = cms_sites(:default).cms_layouts.new(
32
- :label => 'test',
33
- :slug => 'test',
34
- :content => '{{cms:field:blah}}'
35
- )
36
- assert layout.valid?
37
- end
38
-
39
- def test_creation
40
- assert_difference 'CmsLayout.count' do
41
- layout = cms_sites(:default).cms_layouts.create(
42
- :label => 'New Layout',
43
- :slug => 'new-layout',
44
- :content => '{{cms:page:content}}',
45
- :css => 'css',
46
- :js => 'js'
47
- )
48
- assert_equal 'New Layout', layout.label
49
- assert_equal 'new-layout', layout.slug
50
- assert_equal '{{cms:page:content}}', layout.content
51
- assert_equal 'css', layout.css
52
- assert_equal 'js', layout.js
53
- end
54
- end
55
-
56
- def test_options_for_select
57
- assert_equal ['Default Layout', 'Nested Layout', '. . Child Layout'],
58
- CmsLayout.options_for_select(cms_sites(:default)).collect{|t| t.first}
59
- assert_equal ['Default Layout', 'Nested Layout'],
60
- CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:child)).collect{|t| t.first}
61
- assert_equal ['Default Layout'],
62
- CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:nested)).collect{|t| t.first}
63
- end
64
-
65
- def test_app_layouts_for_select
66
- assert_equal ['cms_admin.html.erb'], CmsLayout.app_layouts_for_select
67
- end
68
-
69
- def test_merged_content_with_same_child_content
70
- parent_layout = cms_layouts(:nested)
71
- assert_equal "{{cms:page:header}}\n{{cms:page:content}}", parent_layout.content
72
- assert_equal "{{cms:page:header}}\n{{cms:page:content}}", parent_layout.merged_content
73
-
74
- child_layout = cms_layouts(:child)
75
- assert_equal parent_layout, child_layout.parent
76
- assert_equal "{{cms:page:left_column}}\n{{cms:page:right_column}}", child_layout.content
77
- assert_equal "{{cms:page:header}}\n{{cms:page:left_column}}\n{{cms:page:right_column}}", child_layout.merged_content
78
-
79
- child_layout.update_attribute(:content, '{{cms:page:content}}')
80
- assert_equal "{{cms:page:header}}\n{{cms:page:content}}", child_layout.merged_content
81
-
82
- parent_layout.update_attribute(:content, '{{cms:page:whatever}}')
83
- child_layout.reload
84
- assert_equal '{{cms:page:content}}', child_layout.merged_content
85
- end
86
-
87
- def test_load_from_file
88
- assert !CmsLayout.load_from_file(cms_sites(:default), 'default')
89
-
90
- ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
91
-
92
- assert !CmsLayout.load_from_file(cms_sites(:default), 'bogus')
93
-
94
- assert layout = CmsLayout.load_from_file(cms_sites(:default), 'default')
95
- assert_equal 'Default Layout', layout.label
96
- assert_equal '<html>{{cms:page:content}}</html>', layout.content
97
-
98
- assert layout = CmsLayout.load_from_file(cms_sites(:default), 'nested')
99
- assert_equal 'Nested Layout', layout.label
100
- assert_equal '<div>{{cms:page:content}}</div>', layout.content
101
- assert_equal '<html><div>{{cms:page:content}}</div></html>', layout.merged_content
102
- end
103
-
104
- def test_load_from_file_broken
105
- ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
106
- error_message = "Failed to load from #{ComfortableMexicanSofa.configuration.seed_data_path}/test.host/layouts/broken.yml"
107
- assert_exception_raised RuntimeError, error_message do
108
- CmsLayout.load_from_file(cms_sites(:default), 'broken')
109
- end
110
- end
111
-
112
- def test_load_for_slug
113
- assert layout = CmsLayout.load_for_slug!(cms_sites(:default), 'default')
114
- assert !layout.new_record?
115
- db_content = layout.content
116
-
117
- ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
118
- assert layout = CmsLayout.load_for_slug!(cms_sites(:default), 'default')
119
- assert layout.new_record?
120
- file_content = layout.content
121
- assert_not_equal db_content, file_content
122
- end
123
-
124
- def test_load_for_slug_exceptions
125
- assert_exception_raised ActiveRecord::RecordNotFound, 'CmsLayout with slug: not_found cannot be found' do
126
- CmsLayout.load_for_slug!(cms_sites(:default), 'not_found')
127
- end
128
- assert !CmsLayout.load_for_slug(cms_sites(:default), 'not_found')
129
-
130
- ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
131
- assert_exception_raised ActiveRecord::RecordNotFound, 'CmsLayout with slug: not_found cannot be found' do
132
- CmsLayout.load_for_slug!(cms_sites(:default), 'not_found')
133
- end
134
- assert !CmsLayout.load_for_slug(cms_sites(:default), 'not_found')
135
- end
136
-
137
- def test_update_forces_page_content_reload
138
- layout_1 = cms_layouts(:nested)
139
- layout_2 = cms_layouts(:child)
140
- page_1 = cms_sites(:default).cms_pages.create!(
141
- :label => 'page_1',
142
- :slug => 'page-1',
143
- :parent_id => cms_pages(:default).id,
144
- :cms_layout_id => layout_1.id,
145
- :is_published => '1',
146
- :cms_blocks_attributes => [
147
- { :label => 'header',
148
- :content => 'header_content' },
149
- { :label => 'content',
150
- :content => 'content_content' }
151
- ]
152
- )
153
- page_2 = cms_sites(:default).cms_pages.create!(
154
- :label => 'page_2',
155
- :slug => 'page-2',
156
- :parent_id => cms_pages(:default).id,
157
- :cms_layout_id => layout_2.id,
158
- :is_published => '1',
159
- :cms_blocks_attributes => [
160
- { :label => 'header',
161
- :content => 'header_content' },
162
- { :label => 'left_column',
163
- :content => 'left_column_content' },
164
- { :label => 'right_column',
165
- :content => 'left_column_content' }
166
- ]
167
- )
168
- assert_equal "header_content\ncontent_content", page_1.content
169
- assert_equal "header_content\nleft_column_content\nleft_column_content", page_2.content
170
-
171
- layout_1.update_attribute(:content, "Updated {{cms:page:content}}")
172
- page_1.reload
173
- page_2.reload
174
-
175
- assert_equal "Updated content_content", page_1.content
176
- assert_equal "Updated left_column_content\nleft_column_content", page_2.content
177
- end
178
-
179
- end