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
@@ -0,0 +1,33 @@
1
+ require File.expand_path('../../test_helper', File.dirname(__FILE__))
2
+
3
+ class BlockTest < ActiveSupport::TestCase
4
+
5
+ def test_fixtures_validity
6
+ Cms::Block.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 ['Cms::Page.count', 'Cms::Block.count'] do
13
+ page = Cms::Page.create!(
14
+ :site => cms_sites(:default),
15
+ :layout => cms_layouts(:default),
16
+ :label => 'test page',
17
+ :slug => 'test_page',
18
+ :parent_id => cms_pages(:default).id,
19
+ :blocks_attributes => [
20
+ {
21
+ :label => 'default_page_text',
22
+ :content => 'test_content'
23
+ }
24
+ ]
25
+ )
26
+ assert_equal 1, page.blocks.count
27
+ block = page.blocks.first
28
+ assert_equal 'default_page_text', block.label
29
+ assert_equal 'test_content', block.content
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,129 @@
1
+ require File.expand_path('../../test_helper', File.dirname(__FILE__))
2
+
3
+ class CmsLayoutTest < ActiveSupport::TestCase
4
+
5
+ def test_fixtures_validity
6
+ Cms::Layout.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 = cms_sites(:default).layouts.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 = cms_sites(:default).layouts.create(:content => 'some text')
19
+ assert_has_errors_on layout, :content
20
+
21
+ layout = cms_sites(:default).layouts.create(:content => '{cms:snippet:blah}')
22
+ assert_has_errors_on layout, :content
23
+
24
+ layout = cms_sites(:default).layouts.new(
25
+ :label => 'test',
26
+ :slug => 'test',
27
+ :content => '{{cms:page:blah}}'
28
+ )
29
+ assert layout.valid?
30
+
31
+ layout = cms_sites(:default).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 'Cms::Layout.count' do
41
+ layout = cms_sites(:default).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
+ Cms::Layout.options_for_select(cms_sites(:default)).collect{|t| t.first}
59
+ assert_equal ['Default Layout', 'Nested Layout'],
60
+ Cms::Layout.options_for_select(cms_sites(:default), cms_layouts(:child)).collect{|t| t.first}
61
+ assert_equal ['Default Layout'],
62
+ Cms::Layout.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'], Cms::Layout.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_update_forces_page_content_reload
88
+ layout_1 = cms_layouts(:nested)
89
+ layout_2 = cms_layouts(:child)
90
+ page_1 = cms_sites(:default).pages.create!(
91
+ :label => 'page_1',
92
+ :slug => 'page-1',
93
+ :parent_id => cms_pages(:default).id,
94
+ :layout_id => layout_1.id,
95
+ :is_published => '1',
96
+ :blocks_attributes => [
97
+ { :label => 'header',
98
+ :content => 'header_content' },
99
+ { :label => 'content',
100
+ :content => 'content_content' }
101
+ ]
102
+ )
103
+ page_2 = cms_sites(:default).pages.create!(
104
+ :label => 'page_2',
105
+ :slug => 'page-2',
106
+ :parent_id => cms_pages(:default).id,
107
+ :layout_id => layout_2.id,
108
+ :is_published => '1',
109
+ :blocks_attributes => [
110
+ { :label => 'header',
111
+ :content => 'header_content' },
112
+ { :label => 'left_column',
113
+ :content => 'left_column_content' },
114
+ { :label => 'right_column',
115
+ :content => 'left_column_content' }
116
+ ]
117
+ )
118
+ assert_equal "header_content\ncontent_content", page_1.content
119
+ assert_equal "header_content\nleft_column_content\nleft_column_content", page_2.content
120
+
121
+ layout_1.update_attribute(:content, "Updated {{cms:page:content}}")
122
+ page_1.reload
123
+ page_2.reload
124
+
125
+ assert_equal "Updated content_content", page_1.content
126
+ assert_equal "Updated left_column_content\nleft_column_content", page_2.content
127
+ end
128
+
129
+ end
@@ -0,0 +1,199 @@
1
+ require File.expand_path('../../test_helper', File.dirname(__FILE__))
2
+
3
+ class CmsPageTest < ActiveSupport::TestCase
4
+
5
+ def test_fixtures_validity
6
+ Cms::Page.all.each do |page|
7
+ assert page.valid?, page.errors.full_messages.to_s
8
+ assert_equal page.read_attribute(:content), page.content(true)
9
+ end
10
+ end
11
+
12
+ def test_validations
13
+ page = Cms::Page.new
14
+ page.save
15
+ assert page.invalid?
16
+ assert_has_errors_on page, [:layout, :slug, :label]
17
+ end
18
+
19
+ def test_validation_of_parent_presence
20
+ page = cms_sites(:default).pages.new(new_params)
21
+ assert !page.parent
22
+ assert page.valid?, page.errors.full_messages.to_s
23
+ assert_equal cms_pages(:default), page.parent
24
+ end
25
+
26
+ def test_validation_of_parent_relationship
27
+ page = cms_pages(:default)
28
+ assert !page.parent
29
+ page.parent = page
30
+ assert page.invalid?
31
+ assert_has_errors_on page, :parent_id
32
+ page.parent = cms_pages(:child)
33
+ assert page.invalid?
34
+ assert_has_errors_on page, :parent_id
35
+ end
36
+
37
+ def test_validation_of_target_page
38
+ page = cms_pages(:child)
39
+ page.target_page = cms_pages(:default)
40
+ page.save!
41
+ assert_equal cms_pages(:default), page.target_page
42
+ page.target_page = page
43
+ assert page.invalid?
44
+ assert_has_errors_on page, :target_page_id
45
+ end
46
+
47
+ def test_creation
48
+ assert_difference ['Cms::Page.count', 'Cms::Block.count'] do
49
+ page = cms_sites(:default).pages.create!(
50
+ :label => 'test',
51
+ :slug => 'test',
52
+ :parent_id => cms_pages(:default).id,
53
+ :layout_id => cms_layouts(:default).id,
54
+ :blocks_attributes => [
55
+ { :label => 'default_page_text',
56
+ :content => 'test' }
57
+ ]
58
+ )
59
+ assert page.is_published?
60
+ assert_equal 1, page.position
61
+ end
62
+ end
63
+
64
+ def test_initialization_of_full_path
65
+ page = Cms::Page.new
66
+ assert_equal '/', page.full_path
67
+
68
+ page = Cms::Page.new(new_params)
69
+ assert page.invalid?
70
+ assert_has_errors_on page, :site_id
71
+
72
+ page = cms_sites(:default).pages.new(new_params(:parent => cms_pages(:default)))
73
+ assert page.valid?
74
+ assert_equal '/test-page', page.full_path
75
+
76
+ page = cms_sites(:default).pages.new(new_params(:parent => cms_pages(:child)))
77
+ assert page.valid?
78
+ assert_equal '/child-page/test-page', page.full_path
79
+
80
+ Cms::Page.destroy_all
81
+ page = cms_sites(:default).pages.new(new_params)
82
+ assert page.valid?
83
+ assert_equal '/', page.full_path
84
+ end
85
+
86
+ def test_sync_child_pages
87
+ page = cms_pages(:child)
88
+ page_1 = cms_sites(:default).pages.create!(new_params(:parent => page, :slug => 'test-page-1'))
89
+ page_2 = cms_sites(:default).pages.create!(new_params(:parent => page, :slug => 'test-page-2'))
90
+ page_3 = cms_sites(:default).pages.create!(new_params(:parent => page_2, :slug => 'test-page-3'))
91
+ page_4 = cms_sites(:default).pages.create!(new_params(:parent => page_1, :slug => 'test-page-4'))
92
+ assert_equal '/child-page/test-page-1', page_1.full_path
93
+ assert_equal '/child-page/test-page-2', page_2.full_path
94
+ assert_equal '/child-page/test-page-2/test-page-3', page_3.full_path
95
+ assert_equal '/child-page/test-page-1/test-page-4', page_4.full_path
96
+
97
+ page.update_attributes!(:slug => 'updated-page')
98
+ assert_equal '/updated-page', page.full_path
99
+ page_1.reload; page_2.reload; page_3.reload; page_4.reload
100
+ assert_equal '/updated-page/test-page-1', page_1.full_path
101
+ assert_equal '/updated-page/test-page-2', page_2.full_path
102
+ assert_equal '/updated-page/test-page-2/test-page-3', page_3.full_path
103
+ assert_equal '/updated-page/test-page-1/test-page-4', page_4.full_path
104
+
105
+ page_2.update_attributes!(:parent => page_1)
106
+ page_1.reload; page_2.reload; page_3.reload; page_4.reload
107
+ assert_equal '/updated-page/test-page-1', page_1.full_path
108
+ assert_equal '/updated-page/test-page-1/test-page-2', page_2.full_path
109
+ assert_equal '/updated-page/test-page-1/test-page-2/test-page-3', page_3.full_path
110
+ assert_equal '/updated-page/test-page-1/test-page-4', page_4.full_path
111
+ end
112
+
113
+ def test_children_count_updating
114
+ page_1 = cms_pages(:default)
115
+ page_2 = cms_pages(:child)
116
+ assert_equal 1, page_1.children_count
117
+ assert_equal 0, page_2.children_count
118
+
119
+ page_3 = cms_sites(:default).pages.create!(new_params(:parent => page_2))
120
+ page_1.reload; page_2.reload
121
+ assert_equal 1, page_1.children_count
122
+ assert_equal 1, page_2.children_count
123
+ assert_equal 0, page_3.children_count
124
+
125
+ page_3.update_attributes!(:parent => page_1)
126
+ page_1.reload; page_2.reload
127
+ assert_equal 2, page_1.children_count
128
+ assert_equal 0, page_2.children_count
129
+
130
+ page_3.destroy
131
+ page_1.reload; page_2.reload
132
+ assert_equal 1, page_1.children_count
133
+ assert_equal 0, page_2.children_count
134
+ end
135
+
136
+ def test_cascading_destroy
137
+ assert_difference 'Cms::Page.count', -2 do
138
+ cms_pages(:default).destroy
139
+ end
140
+ end
141
+
142
+ def test_options_for_select
143
+ assert_equal ['Default Page', '. . Child Page'],
144
+ Cms::Page.options_for_select(cms_sites(:default)).collect{|t| t.first }
145
+ assert_equal ['Default Page'],
146
+ Cms::Page.options_for_select(cms_sites(:default), cms_pages(:child)).collect{|t| t.first }
147
+ assert_equal [],
148
+ Cms::Page.options_for_select(cms_sites(:default), cms_pages(:default))
149
+
150
+ page = Cms::Page.new(new_params(:parent => cms_pages(:default)))
151
+ assert_equal ['Default Page', '. . Child Page'],
152
+ Cms::Page.options_for_select(cms_sites(:default), page).collect{|t| t.first }
153
+ end
154
+
155
+ def test_cms_blocks_attributes_accessor
156
+ page = cms_pages(:default)
157
+ assert_equal page.blocks.count, page.blocks_attributes.size
158
+ assert_equal 'default_field_text', page.blocks_attributes.first[:label]
159
+ assert_equal 'default_field_text_content', page.blocks_attributes.first[:content]
160
+ assert page.blocks_attributes.first[:id]
161
+ end
162
+
163
+ def test_content_caching
164
+ page = cms_pages(:default)
165
+ assert_equal page.read_attribute(:content), page.content
166
+ assert_equal page.read_attribute(:content), page.content(true)
167
+
168
+ page.update_attribute(:content, 'changed')
169
+ assert_equal page.read_attribute(:content), page.content
170
+ assert_equal page.read_attribute(:content), page.content(true)
171
+ assert_not_equal 'changed', page.read_attribute(:content)
172
+ end
173
+
174
+ def test_scope_published
175
+ assert_equal 2, Cms::Page.published.count
176
+ cms_pages(:child).update_attribute(:is_published, false)
177
+ assert_equal 1, Cms::Page.published.count
178
+ end
179
+
180
+ def test_root?
181
+ assert cms_pages(:default).root?
182
+ assert !cms_pages(:child).root?
183
+ end
184
+
185
+ def test_url
186
+ assert_equal 'http://test.host/', cms_pages(:default).url
187
+ assert_equal 'http://test.host/child-page', cms_pages(:child).url
188
+ end
189
+
190
+ protected
191
+
192
+ def new_params(options = {})
193
+ {
194
+ :label => 'Test Page',
195
+ :slug => 'test-page',
196
+ :layout => cms_layouts(:default)
197
+ }.merge(options)
198
+ end
199
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path('../../test_helper', File.dirname(__FILE__))
2
+
3
+ class CmsSiteTest < ActiveSupport::TestCase
4
+
5
+ def test_fixtures_validity
6
+ Cms::Site.all.each do |site|
7
+ assert site.valid?, site.errors.full_messages.to_s
8
+ end
9
+ end
10
+
11
+ def test_validation
12
+ site = Cms::Site.new
13
+ assert site.invalid?
14
+ assert_has_errors_on site, [:label, :hostname]
15
+
16
+ site = Cms::Site.new(:label => 'My Site', :hostname => 'http://mysite.com')
17
+ assert site.invalid?
18
+ assert_has_errors_on site, :hostname
19
+
20
+ site = Cms::Site.new(:label => 'My Site', :hostname => 'mysite.com')
21
+ assert site.valid?
22
+ end
23
+
24
+ def test_cascading_destroy
25
+ assert_difference 'Cms::Site.count', -1 do
26
+ assert_difference 'Cms::Layout.count', -3 do
27
+ assert_difference 'Cms::Page.count', -2 do
28
+ assert_difference 'Cms::Snippet.count', -1 do
29
+ cms_sites(:default).destroy
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ def test_options_for_select
37
+ assert_equal 1, Cms::Site.options_for_select.size
38
+ assert_equal 'Default Site (test.host)', Cms::Site.options_for_select[0][0]
39
+ end
40
+
41
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../../test_helper', File.dirname(__FILE__))
2
+
3
+ class CmsSnippetTest < ActiveSupport::TestCase
4
+
5
+ def test_fixtures_validity
6
+ Cms::Snippet.all.each do |snippet|
7
+ assert snippet.valid?, snippet.errors.full_messages.to_s
8
+ end
9
+ end
10
+
11
+ def test_validations
12
+ snippet = Cms::Snippet.new
13
+ snippet.save
14
+ assert snippet.invalid?
15
+ assert_has_errors_on snippet, [:label, :slug]
16
+ end
17
+
18
+ def test_method_content
19
+ assert_equal cms_snippets(:default).content, Cms::Snippet.content_for('default')
20
+ assert_equal '', Cms::Snippet.content_for('nonexistent_snippet')
21
+ end
22
+
23
+ def test_update_forces_page_content_reload
24
+ snippet = cms_snippets(:default)
25
+ page = cms_pages(:default)
26
+ assert_match snippet.content, page.content
27
+ snippet.update_attribute(:content, 'new_snippet_content')
28
+ page.reload
29
+ assert_match /new_snippet_content/, page.content
30
+ end
31
+
32
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../../test_helper', File.dirname(__FILE__))
2
+
3
+ class CmsUploadTest < ActiveSupport::TestCase
4
+
5
+ def test_fixtures_validity
6
+ Cms::Upload.all.each do |upload|
7
+ assert upload.valid?, upload.errors.full_messages.to_s
8
+ end
9
+ end
10
+
11
+ def test_validations
12
+ assert_no_difference 'Cms::Upload.count' do
13
+ upload = Cms::Upload.create
14
+ assert upload.errors.present?
15
+ assert_has_errors_on upload, [:file_file_name]
16
+ end
17
+ end
18
+
19
+ def test_create
20
+ assert_difference 'Cms::Upload.count' do
21
+ cms_sites(:default).uploads.create(
22
+ :file => fixture_file_upload('files/valid_image.jpg')
23
+ )
24
+ end
25
+ end
26
+
27
+ def test_create_failure
28
+ assert_no_difference 'Cms::Upload.count' do
29
+ cms_sites(:default).uploads.create(:file => '')
30
+ end
31
+ end
32
+ end