comfortable_mexican_sofa 0.0.18 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. data/.gitignore +8 -8
  2. data/Gemfile +11 -0
  3. data/Gemfile.lock +91 -0
  4. data/README.md +4 -0
  5. data/Rakefile +28 -57
  6. data/VERSION +1 -1
  7. data/app/controllers/application_controller.rb +5 -0
  8. data/app/controllers/cms_admin/base_controller.rb +1 -21
  9. data/app/controllers/cms_admin/layouts_controller.rb +23 -38
  10. data/app/controllers/cms_admin/pages_controller.rb +24 -40
  11. data/app/controllers/cms_admin/snippets_controller.rb +26 -34
  12. data/app/controllers/cms_admin/uploads_controller.rb +27 -0
  13. data/app/controllers/cms_content_controller.rb +22 -19
  14. data/app/models/cms_block.rb +20 -6
  15. data/app/models/cms_layout.rb +34 -80
  16. data/app/models/cms_page.rb +44 -102
  17. data/app/models/cms_snippet.rb +12 -7
  18. data/app/models/cms_upload.rb +36 -0
  19. data/app/views/cms_admin/layouts/_form.html.erb +6 -0
  20. data/app/views/cms_admin/layouts/_index_branch.html.erb +24 -0
  21. data/app/views/cms_admin/layouts/edit.html.erb +6 -0
  22. data/app/views/cms_admin/layouts/index.html.erb +6 -0
  23. data/app/views/cms_admin/layouts/new.html.erb +6 -0
  24. data/app/views/cms_admin/pages/_form.html.erb +14 -0
  25. data/app/views/cms_admin/pages/_form_blocks.html.erb +7 -0
  26. data/app/views/cms_admin/pages/_index_branch.html.erb +27 -0
  27. data/app/views/cms_admin/pages/edit.html.erb +6 -0
  28. data/app/views/cms_admin/pages/form_blocks.js.erb +1 -0
  29. data/app/views/cms_admin/pages/index.html.erb +6 -0
  30. data/app/views/cms_admin/pages/new.html.erb +6 -0
  31. data/app/views/cms_admin/snippets/_form.html.erb +2 -0
  32. data/app/views/cms_admin/snippets/edit.html.erb +6 -0
  33. data/app/views/cms_admin/snippets/index.html.erb +3 -0
  34. data/app/views/cms_admin/snippets/new.html.erb +6 -0
  35. data/app/views/cms_admin/uploads/_index.html.erb +8 -0
  36. data/app/views/cms_admin/uploads/_upload.html.erb +11 -0
  37. data/app/views/cms_admin/uploads/destroy.js.erb +3 -0
  38. data/app/views/cms_admin/uploads/index.html.erb +2 -0
  39. data/app/views/layouts/cms_admin.html.erb +36 -0
  40. data/comfortable_mexican_sofa.gemspec +141 -197
  41. data/config.ru +4 -0
  42. data/config/application.rb +44 -0
  43. data/config/boot.rb +13 -0
  44. data/{test/rails_root/config → config}/database.yml +0 -0
  45. data/config/environment.rb +5 -0
  46. data/config/environments/development.rb +22 -0
  47. data/config/environments/production.rb +49 -0
  48. data/config/environments/test.rb +35 -0
  49. data/{test/rails_root/config → config}/initializers/backtrace_silencers.rb +2 -2
  50. data/{test/rails_root/config → config}/initializers/inflections.rb +1 -1
  51. data/{test/rails_root/config → config}/initializers/mime_types.rb +0 -0
  52. data/config/initializers/paperclip.rb +3 -0
  53. data/config/initializers/secret_token.rb +7 -0
  54. data/config/initializers/session_store.rb +8 -0
  55. data/{test/rails_root/config → config}/locales/en.yml +1 -1
  56. data/config/routes.rb +20 -0
  57. data/db/migrate/01_create_cms.rb +73 -0
  58. data/db/seeds.rb +7 -0
  59. data/doc/README_FOR_APP +95 -0
  60. data/lib/comfortable_mexican_sofa.rb +34 -39
  61. data/lib/comfortable_mexican_sofa/cms_acts_as_tree.rb +42 -49
  62. data/lib/comfortable_mexican_sofa/cms_form_builder.rb +107 -0
  63. data/lib/comfortable_mexican_sofa/cms_rails_extensions.rb +25 -5
  64. data/lib/comfortable_mexican_sofa/cms_tag.rb +90 -85
  65. data/lib/comfortable_mexican_sofa/cms_tag/field_datetime.rb +26 -0
  66. data/lib/comfortable_mexican_sofa/cms_tag/field_integer.rb +26 -0
  67. data/lib/comfortable_mexican_sofa/cms_tag/field_string.rb +26 -0
  68. data/lib/comfortable_mexican_sofa/cms_tag/field_text.rb +26 -0
  69. data/lib/comfortable_mexican_sofa/cms_tag/page_datetime.rb +22 -0
  70. data/lib/comfortable_mexican_sofa/cms_tag/page_integer.rb +22 -0
  71. data/lib/comfortable_mexican_sofa/cms_tag/page_string.rb +22 -0
  72. data/lib/comfortable_mexican_sofa/cms_tag/page_text.rb +22 -0
  73. data/lib/comfortable_mexican_sofa/cms_tag/partial.rb +20 -0
  74. data/lib/comfortable_mexican_sofa/cms_tag/snippet.rb +18 -0
  75. data/{generators/cms/templates → lib/generators}/README +0 -20
  76. data/lib/generators/cms_generator.rb +28 -0
  77. data/public/404.html +26 -0
  78. data/public/422.html +26 -0
  79. data/public/500.html +26 -0
  80. data/{test/rails_root/public → public}/favicon.ico +0 -0
  81. data/public/images/comfortable_mexican_sofa/body_bg.jpg +0 -0
  82. data/{generators/cms/templates/images → public/images/comfortable_mexican_sofa}/icon_regular.gif +0 -0
  83. data/public/javascripts/comfortable_mexican_sofa/cms.js +53 -0
  84. data/public/javascripts/comfortable_mexican_sofa/jquery-ui.js +325 -0
  85. data/public/javascripts/comfortable_mexican_sofa/jquery.js +154 -0
  86. data/public/javascripts/comfortable_mexican_sofa/plupload/plupload.full.min.js +1 -0
  87. data/public/javascripts/comfortable_mexican_sofa/plupload/plupload.html4.min.js +1 -0
  88. data/public/javascripts/comfortable_mexican_sofa/plupload/plupload.html5.min.js +1 -0
  89. data/public/javascripts/comfortable_mexican_sofa/rails.js +132 -0
  90. data/public/javascripts/comfortable_mexican_sofa/uploader.js +47 -0
  91. data/{test/rails_root/public → public}/robots.txt +0 -0
  92. data/public/stylesheets/comfortable_mexican_sofa/jquery-ui.css +305 -0
  93. data/public/stylesheets/comfortable_mexican_sofa/reset.css +1 -0
  94. data/public/stylesheets/comfortable_mexican_sofa/structure.css +194 -0
  95. data/public/stylesheets/comfortable_mexican_sofa/typography.css +20 -0
  96. data/script/rails +6 -0
  97. data/test/fixtures/README.md +22 -0
  98. data/test/fixtures/cms_blocks.yml +10 -34
  99. data/test/fixtures/cms_layouts.yml +37 -33
  100. data/test/fixtures/cms_pages.yml +11 -32
  101. data/test/fixtures/cms_snippets.yml +2 -6
  102. data/test/fixtures/cms_uploads.yml +4 -0
  103. data/test/fixtures/files/invalid_file.gif +9 -0
  104. data/test/fixtures/files/valid_image.jpg +0 -0
  105. data/test/functional/cms_admin/base_controller_test.rb +9 -0
  106. data/test/functional/cms_admin/layouts_controller_test.rb +61 -46
  107. data/test/functional/cms_admin/pages_controller_test.rb +201 -102
  108. data/test/functional/cms_admin/snippets_controller_test.rb +46 -39
  109. data/test/functional/cms_admin/uploads_controller_test.rb +32 -0
  110. data/test/functional/cms_content_controller_test.rb +37 -32
  111. data/test/test_helper.rb +29 -9
  112. data/test/unit/cms_block_test.rb +60 -0
  113. data/test/unit/cms_layout_test.rb +48 -0
  114. data/test/unit/cms_page_test.rb +122 -0
  115. data/test/unit/cms_snippet_test.rb +23 -0
  116. data/test/unit/cms_tag_test.rb +149 -0
  117. data/test/unit/cms_tags/field_datetime_test.rb +36 -0
  118. data/test/unit/cms_tags/field_integer_test.rb +35 -0
  119. data/test/unit/cms_tags/field_string_test.rb +35 -0
  120. data/test/unit/cms_tags/field_text_test.rb +34 -0
  121. data/test/unit/cms_tags/page_datetime_test.rb +36 -0
  122. data/test/unit/cms_tags/page_integer_test.rb +35 -0
  123. data/test/unit/cms_tags/page_string_test.rb +35 -0
  124. data/test/unit/cms_tags/page_text_test.rb +36 -0
  125. data/test/unit/cms_tags/partial_test.rb +30 -0
  126. data/test/unit/cms_tags/snippet_test.rb +34 -0
  127. data/test/unit/cms_upload_test.rb +30 -0
  128. metadata +176 -215
  129. data/CHANGELOG.rdoc +0 -2
  130. data/LICENSE +0 -20
  131. data/README.rdoc +0 -55
  132. data/app/controllers/cms_admin/attachments_controller.rb +0 -55
  133. data/app/controllers/cms_admin/categories_controller.rb +0 -69
  134. data/app/controllers/cms_admin/sections_controller.rb +0 -17
  135. data/app/controllers/cms_common/render_page.rb +0 -47
  136. data/app/helpers/cms_helper.rb +0 -12
  137. data/app/models/cms_attachment.rb +0 -17
  138. data/app/models/cms_attachment_categorization.rb +0 -5
  139. data/app/models/cms_category.rb +0 -36
  140. data/app/models/cms_page_categorization.rb +0 -6
  141. data/app/views/cms_admin/attachments/_details.html.haml +0 -27
  142. data/app/views/cms_admin/attachments/_form.html.haml +0 -24
  143. data/app/views/cms_admin/attachments/edit.html.haml +0 -10
  144. data/app/views/cms_admin/attachments/index.html.haml +0 -36
  145. data/app/views/cms_admin/attachments/new.html.haml +0 -8
  146. data/app/views/cms_admin/categories/_category.html.haml +0 -21
  147. data/app/views/cms_admin/categories/_category_subform.html.haml +0 -12
  148. data/app/views/cms_admin/categories/_form.html.haml +0 -18
  149. data/app/views/cms_admin/categories/_new.html.haml +0 -7
  150. data/app/views/cms_admin/categories/_toggle_link.html.haml +0 -9
  151. data/app/views/cms_admin/categories/_tree_branch.html.haml +0 -36
  152. data/app/views/cms_admin/categories/children.js.rjs +0 -10
  153. data/app/views/cms_admin/categories/create.js.rjs +0 -9
  154. data/app/views/cms_admin/categories/edit.html.haml +0 -10
  155. data/app/views/cms_admin/categories/index.html.haml +0 -7
  156. data/app/views/cms_admin/categories/new.html.haml +0 -8
  157. data/app/views/cms_admin/categories/show.html.haml +0 -17
  158. data/app/views/cms_admin/layouts/_details.html.haml +0 -6
  159. data/app/views/cms_admin/layouts/_form.html.haml +0 -19
  160. data/app/views/cms_admin/layouts/_toggle_link.html.haml +0 -9
  161. data/app/views/cms_admin/layouts/_tree_branch.html.haml +0 -39
  162. data/app/views/cms_admin/layouts/children.js.rjs +0 -10
  163. data/app/views/cms_admin/layouts/edit.html.haml +0 -10
  164. data/app/views/cms_admin/layouts/index.html.haml +0 -7
  165. data/app/views/cms_admin/layouts/new.html.haml +0 -8
  166. data/app/views/cms_admin/pages/_details.html.haml +0 -25
  167. data/app/views/cms_admin/pages/_form.html.haml +0 -45
  168. data/app/views/cms_admin/pages/_form_blocks.html.haml +0 -48
  169. data/app/views/cms_admin/pages/_toggle_link.html.haml +0 -10
  170. data/app/views/cms_admin/pages/_tree_branch.html.haml +0 -41
  171. data/app/views/cms_admin/pages/children.js.rjs +0 -10
  172. data/app/views/cms_admin/pages/edit.html.haml +0 -11
  173. data/app/views/cms_admin/pages/form_blocks.js.rjs +0 -1
  174. data/app/views/cms_admin/pages/index.html.haml +0 -6
  175. data/app/views/cms_admin/pages/new.html.haml +0 -9
  176. data/app/views/cms_admin/sections/show.html.haml +0 -23
  177. data/app/views/cms_admin/snippets/_form.html.haml +0 -10
  178. data/app/views/cms_admin/snippets/edit.html.haml +0 -10
  179. data/app/views/cms_admin/snippets/index.html.haml +0 -26
  180. data/app/views/cms_admin/snippets/new.html.haml +0 -8
  181. data/app/views/cms_content/show.xml.rxml +0 -27
  182. data/app/views/cms_content/sitemap.xml.rxml +0 -16
  183. data/app/views/layouts/cms_admin.html.haml +0 -44
  184. data/config/cms_routes.rb +0 -25
  185. data/generators/cms/cms_generator.rb +0 -55
  186. data/generators/cms/templates/images/arrow_bottom.gif +0 -0
  187. data/generators/cms/templates/images/arrow_right.gif +0 -0
  188. data/generators/cms/templates/images/icon_attachment.gif +0 -0
  189. data/generators/cms/templates/images/icon_category.gif +0 -0
  190. data/generators/cms/templates/images/icon_draft.gif +0 -0
  191. data/generators/cms/templates/images/icon_layout.gif +0 -0
  192. data/generators/cms/templates/images/icon_move.gif +0 -0
  193. data/generators/cms/templates/images/icon_snippet.gif +0 -0
  194. data/generators/cms/templates/images/logo.png +0 -0
  195. data/generators/cms/templates/initializers/cms.rb +0 -14
  196. data/generators/cms/templates/initializers/paperclip.rb +0 -14
  197. data/generators/cms/templates/javascripts/codemirror_init.js +0 -16
  198. data/generators/cms/templates/javascripts/mce_init.js +0 -17
  199. data/generators/cms/templates/javascripts/utilities.js +0 -27
  200. data/generators/cms/templates/migrations/create_cms.rb +0 -113
  201. data/generators/cms/templates/stylesheets/cms_master.sass +0 -414
  202. data/init.rb +0 -1
  203. data/lib/comfortable_mexican_sofa/acts_as_categorized.rb +0 -87
  204. data/lib/comfortable_mexican_sofa/acts_as_published.rb +0 -60
  205. data/lib/comfortable_mexican_sofa/cms_tags/attachment.rb +0 -3
  206. data/lib/comfortable_mexican_sofa/cms_tags/block.rb +0 -117
  207. data/lib/comfortable_mexican_sofa/cms_tags/helper.rb +0 -3
  208. data/lib/comfortable_mexican_sofa/cms_tags/page_block.rb +0 -119
  209. data/lib/comfortable_mexican_sofa/cms_tags/partial.rb +0 -19
  210. data/lib/comfortable_mexican_sofa/cms_tags/snippet.rb +0 -19
  211. data/rails/init.rb +0 -1
  212. data/test/fixtures/cms_attachment_categorizations.yml +0 -7
  213. data/test/fixtures/cms_attachments.yml +0 -6
  214. data/test/fixtures/cms_categories.yml +0 -19
  215. data/test/fixtures/cms_page_categorizations.yml +0 -15
  216. data/test/fixtures/files/upload_file.txt +0 -1
  217. data/test/functional/cms_admin/attachments_controller_test.rb +0 -63
  218. data/test/functional/cms_admin/categories_controller_test.rb +0 -86
  219. data/test/functional/cms_admin/sections_controller_test.rb +0 -9
  220. data/test/models/cms_attachment_test.rb +0 -16
  221. data/test/models/cms_block_test.rb +0 -11
  222. data/test/models/cms_categorization_test.rb +0 -39
  223. data/test/models/cms_category_test.rb +0 -71
  224. data/test/models/cms_layout_test.rb +0 -44
  225. data/test/models/cms_page_test.rb +0 -55
  226. data/test/models/cms_snippet_test.rb +0 -16
  227. data/test/models/cms_tag_test.rb +0 -70
  228. data/test/rails_root/README +0 -243
  229. data/test/rails_root/Rakefile +0 -10
  230. data/test/rails_root/app/controllers/application_controller.rb +0 -10
  231. data/test/rails_root/app/helpers/application_helper.rb +0 -3
  232. data/test/rails_root/app/views/cms/under-development.html.haml +0 -1
  233. data/test/rails_root/app/views/complex_page/_example.html.erb +0 -1
  234. data/test/rails_root/config/boot.rb +0 -110
  235. data/test/rails_root/config/environment.rb +0 -48
  236. data/test/rails_root/config/environments/development.rb +0 -17
  237. data/test/rails_root/config/environments/production.rb +0 -28
  238. data/test/rails_root/config/environments/test.rb +0 -28
  239. data/test/rails_root/config/initializers/new_rails_defaults.rb +0 -19
  240. data/test/rails_root/config/initializers/session_store.rb +0 -15
  241. data/test/rails_root/config/routes.rb +0 -43
  242. data/test/rails_root/doc/README_FOR_APP +0 -2
  243. data/test/rails_root/public/404.html +0 -30
  244. data/test/rails_root/public/422.html +0 -30
  245. data/test/rails_root/public/500.html +0 -30
  246. data/test/rails_root/public/images/rails.png +0 -0
  247. data/test/rails_root/public/index.html +0 -275
  248. data/test/rails_root/public/javascripts/application.js +0 -2
  249. data/test/rails_root/public/javascripts/controls.js +0 -963
  250. data/test/rails_root/public/javascripts/dragdrop.js +0 -973
  251. data/test/rails_root/public/javascripts/effects.js +0 -1128
  252. data/test/rails_root/public/javascripts/prototype.js +0 -4320
  253. data/test/rails_root/public/stylesheets/sass/cms_master.sass +0 -414
  254. data/test/rails_root/script/about +0 -4
  255. data/test/rails_root/script/console +0 -3
  256. data/test/rails_root/script/dbconsole +0 -3
  257. data/test/rails_root/script/destroy +0 -3
  258. data/test/rails_root/script/generate +0 -3
  259. data/test/rails_root/script/performance/benchmarker +0 -3
  260. data/test/rails_root/script/performance/profiler +0 -3
  261. data/test/rails_root/script/plugin +0 -3
  262. data/test/rails_root/script/runner +0 -3
  263. data/test/rails_root/script/server +0 -3
@@ -1,63 +1,70 @@
1
- require 'test_helper'
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
2
 
3
3
  class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
4
-
5
- def setup
6
- http_auth
7
- end
8
-
9
- def test_get_index
4
+
5
+ def test_index
10
6
  get :index
11
7
  assert_response :success
12
- assert assigns(:snippets)
8
+ assert_template 'index'
13
9
  end
14
10
 
15
- def test_get_new
11
+ def test_new
16
12
  get :new
17
13
  assert_response :success
14
+ assert_template 'new'
18
15
  end
19
16
 
20
- def test_get_edit
21
- get :edit, :id => cms_snippets(:default)
22
- assert_response :success
23
- assert assigns(:snippet)
17
+ def test_create
18
+ assert_difference 'CmsSnippet.count', 1 do
19
+ post :create, :cms_snippet => cms_snippet_params
20
+ end
21
+ assert_equal 'Snippet saved', flash[:notice]
22
+ assert_redirected_to edit_cms_admin_snippet_path(assigns(:cms_snippet))
24
23
  end
25
24
 
26
- def test_create
27
- assert_difference 'CmsSnippet.count' do
28
- post :create, :snippet => {
29
- :label => 'test_snippet',
30
- :content => 'test content'
31
- }
32
- assert_response :redirect
33
- assert_redirected_to :action => :edit
34
- assert_equal 'Snippet created', flash[:notice]
25
+ def test_create_fails
26
+ assert_no_difference 'CmsSnippet.count' do
27
+ post :create, :cms_snippet => cms_snippet_params(:label => '')
35
28
  end
29
+ assert_response :success
30
+ assert_template 'new'
31
+ end
32
+
33
+ def test_edit
34
+ get :edit, :id => cms_snippets(:default)
35
+ assert_response :success
36
+ assert_template 'edit'
36
37
  end
37
38
 
38
39
  def test_update
39
40
  snippet = cms_snippets(:default)
40
-
41
- put :update, :id => snippet, :snippet => {
42
- :label => 'new_test_label',
43
- :content => 'new test content'
44
- }
45
- assert_response :redirect
46
- assert_redirected_to :action => :edit
47
- assert_equal 'Snippet updated', flash[:notice]
48
-
49
- snippet.reload
50
- assert_equal 'new_test_label', snippet.label
51
- assert_equal 'new test content', snippet.content
41
+ put :update, :id => snippet, :cms_snippet => {:label => 'new-label'}
42
+ assert_equal 'Snippet saved', flash[:notice]
43
+ assert_redirected_to edit_cms_admin_snippet_path(assigns(:cms_snippet))
44
+ assert_equal 'new-label', assigns(:cms_snippet).label
45
+ end
46
+
47
+ def test_update_fails
48
+ snippet = cms_snippets(:default)
49
+ put :update, :id => snippet, :cms_snippet => {:label => ''}
50
+ assert_response :success
51
+ assert_template 'edit'
52
+ assert_equal 'default', snippet.label
52
53
  end
53
54
 
54
55
  def test_destroy
55
56
  assert_difference 'CmsSnippet.count', -1 do
56
57
  delete :destroy, :id => cms_snippets(:default)
57
- assert_response :redirect
58
- assert_redirected_to :action => :index
59
- assert_equal 'Snippet removed', flash[:notice]
60
58
  end
59
+ assert_equal 'Snippet deleted', flash[:notice]
60
+ assert_redirected_to cms_admin_snippets_path
61
61
  end
62
-
63
- end
62
+
63
+ protected
64
+ def cms_snippet_params(options = {})
65
+ {
66
+ :label => 'snippet-label',
67
+ :content => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit'
68
+ }.merge(options)
69
+ end
70
+ end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ class CmsAdmin::UploadsControllerTest < ActionController::TestCase
4
+
5
+ def test_index
6
+ get :index
7
+ assert_response :success
8
+ end
9
+
10
+ def test_create
11
+ assert_difference 'CmsUpload.count', 1 do
12
+ xhr :post, :create, :file => fixture_file_upload('files/valid_image.jpg')
13
+ assert_response :success
14
+ end
15
+ end
16
+
17
+ def test_create_fails
18
+ assert_no_difference 'CmsUpload.count' do
19
+ xhr :post, :create, :file => nil
20
+ assert_has_errors_on assigns(:cms_upload), [:file_file_name]
21
+ assert_response :success
22
+ end
23
+ end
24
+
25
+ def test_destroy
26
+ assert_difference 'CmsUpload.count', -1 do
27
+ xhr :delete, :destroy, :id => cms_uploads(:default)
28
+ assert_response :success
29
+ end
30
+ end
31
+
32
+ end
@@ -1,52 +1,57 @@
1
- require 'test_helper'
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class CmsContentControllerTest < ActionController::TestCase
4
+
5
+ def test_render_page
6
+ get :render_html, :cms_path => ''
7
+ assert_equal assigns(:cms_page), cms_pages(:default)
8
+ assert_response :success
9
+ assert_equal rendered_content_formatter(
10
+ '
11
+ layout_content_a
12
+ default_page_text_content_a
13
+ default_snippet_content
14
+ default_page_text_content_b
15
+ layout_content_b
16
+ default_snippet_content
17
+ layout_content_c'
18
+ ), @response.body
19
+ end
4
20
 
5
- def test_get_a_page
6
- assert cms_pages(:complex).is_published?
7
- get :show, :path => %w(complex-page)
21
+ def test_render_page_with_app_layout
22
+ cms_layouts(:default).update_attribute(:app_layout, 'cms_admin.html.erb')
23
+ get :render_html, :cms_path => ''
8
24
  assert_response :success
9
- assert assigns(:cms_page)
25
+ assert_select 'body[id=cms_admin]'
10
26
  end
11
27
 
12
- def test_get_a_unpublished_page
13
- assert !cms_pages(:unpublished).is_published?
14
- get :show, :path => %w(unpublished)
28
+ def test_render_page_not_found
29
+ get :render_html, :cms_path => 'doesnotexist'
15
30
  assert_response 404
16
31
  end
17
32
 
18
- def test_get_sitemap
19
- get :sitemap, :format => 'xml'
33
+ def test_render_css
34
+ get :render_css, :id => cms_layouts(:default)
20
35
  assert_response :success
21
- assert assigns(:cms_pages)
36
+ assert_match %r{text\/css}, @response.headers["Content-Type"]
37
+ assert_equal cms_layouts(:default).css, @response.body
22
38
  end
23
39
 
24
- def test_default_404_page
25
- get :show, :path => %w(some non existing page)
40
+ def test_render_css_not_found
41
+ get :render_css, :id => 'bogus'
26
42
  assert_response 404
27
- assert !assigns(:cms_page)
28
43
  end
29
44
 
30
- def test_custom_404_page
31
- cms_page = CmsPage.create!(
32
- :cms_layout => cms_layouts(:default),
33
- :label => '404 Page',
34
- :slug => '404'
35
- )
36
- cms_page.publish!
37
- get :show, :path => %w(some non existing page)
38
- assert_response 404
39
- assert assigns(:cms_page)
45
+ def test_render_js
46
+ get :render_js, :id => cms_layouts(:default)
47
+ assert_response :success
48
+ assert_match %r{text\/javascript}, @response.headers["Content-Type"]
49
+ assert_equal cms_layouts(:default).js, @response.body
40
50
  end
41
51
 
42
- def test_get_a_page_with_local_file_load
43
- page = CmsPage.find_by_slug('under-development')
44
- assert page
45
- assert_equal '', page.content
46
-
47
- get :show, :path => %w(under-development)
48
- assert_response :success
49
- assert_equal "file content\n", @response.body.to_s
52
+ def test_render_js_not_found
53
+ get :render_js, :id => 'bogus'
54
+ assert_response 404
50
55
  end
51
56
 
52
57
  end
data/test/test_helper.rb CHANGED
@@ -1,17 +1,37 @@
1
- ENV["RAILS_ENV"] = "test"
2
-
3
- require File.expand_path(File.dirname(__FILE__) + "/rails_root/config/environment")
4
- require 'test_help'
1
+ ENV['RAILS_ENV'] = 'test'
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
5
4
 
6
5
  class ActiveSupport::TestCase
7
- self.use_transactional_fixtures = true
8
- self.use_instantiated_fixtures = false
9
-
10
6
  fixtures :all
7
+ include ActionDispatch::TestProcess
8
+
9
+ # Example usage:
10
+ # assert_has_errors_on( @record, [:field_1, :field_2] )
11
+ # assert_has_errors_on( @record, {:field_1 => 'Message1', :field_2 => 'Message 2'} )
12
+ def assert_has_errors_on(record, fields)
13
+ fields = [fields].flatten unless fields.is_a?(Hash)
14
+ fields.each do |field, message|
15
+ assert record.errors.has_key?(field.to_sym), "#{record.class.name} should error on invalid #{field}"
16
+ if message && record.errors[field].is_a?(Array) && !message.is_a?(Array)
17
+ assert_not_nil record.errors[field].index(message)
18
+ elsif message
19
+ assert_equal message, record.errors[field]
20
+ end
21
+ end
22
+ end
23
+
24
+ # Small method that allows for better formatting in tests
25
+ def rendered_content_formatter(string)
26
+ string.gsub(/^[ ]+/, '')
27
+ end
28
+
29
+ end
30
+
31
+ class ActionController::TestCase
11
32
 
12
33
  def http_auth
13
34
  @request.env['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64('username:password')}"
14
35
  end
15
36
 
16
-
17
- end
37
+ end
@@ -0,0 +1,60 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
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
8
+ end
9
+ end
10
+
11
+ def test_new_with_cast
12
+ block = CmsBlock.new(:label => 'test_block', :content => 'test_content', :type => 'CmsTag::PageText')
13
+ assert_equal 'CmsTag::PageText', block.class.name
14
+ assert_equal 'test_block', block.label
15
+ assert_equal 'test_content', block.content
16
+
17
+ assert_difference 'CmsBlock.count' do
18
+ block.cms_page = cms_pages(:default)
19
+ block.save!
20
+ end
21
+ end
22
+
23
+ def test_new_with_cast_via_page_nested_attributes
24
+ assert_difference ['CmsPage.count', 'CmsBlock.count'] do
25
+ page = CmsPage.create!(
26
+ :cms_layout => cms_layouts(:default),
27
+ :label => 'test page',
28
+ :slug => 'test_page',
29
+ :parent_id => cms_pages(:default).id,
30
+ :cms_blocks_attributes => [
31
+ {
32
+ :label => 'test_block',
33
+ :content => 'test_content',
34
+ :type => 'CmsTag::PageText'
35
+ }
36
+ ]
37
+ )
38
+ assert_equal 1, page.cms_blocks.count
39
+ block = page.cms_blocks.first
40
+ assert_equal 'CmsTag::PageText', block.class.name
41
+ assert_equal 'test_block', block.label
42
+ assert_equal 'test_content', block.content
43
+ end
44
+ end
45
+
46
+ def test_initialize_or_find
47
+ block = CmsBlock.initialize_or_find(cms_pages(:default), :default_field_text)
48
+ assert !block.new_record?
49
+ assert_equal 'default_field_text', block.label
50
+ assert_equal 'CmsTag::FieldText', block.class.name
51
+ assert_equal 'default_field_text_content', block.content
52
+
53
+ block = CmsTag::PageText.initialize_or_find(cms_pages(:default), :new_block)
54
+ assert block.new_record?
55
+ assert_equal 'new_block', block.label
56
+ assert_equal 'CmsTag::PageText', block.class.name
57
+ assert block.content.blank?
58
+ end
59
+
60
+ end
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class CmsLayoutTest < ActiveSupport::TestCase
4
+
5
+ def test_fixtures_validity
6
+ CmsLayout.all.each do |layout|
7
+ assert layout.valid?
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, :content]
15
+ end
16
+
17
+ def test_options_for_select
18
+ assert_equal ['Default Layout', 'Nested Layout', '. . Child Layout'], CmsLayout.options_for_select.collect{|t| t.first}
19
+ assert_equal ['Default Layout', 'Nested Layout'], CmsLayout.options_for_select(cms_layouts(:child)).collect{|t| t.first}
20
+ assert_equal ['Default Layout'], CmsLayout.options_for_select(cms_layouts(:nested)).collect{|t| t.first}
21
+ end
22
+
23
+ def test_app_layouts_for_select
24
+ assert_equal ['cms_admin.html.erb'], CmsLayout.app_layouts_for_select
25
+ end
26
+
27
+ def test_merged_content
28
+ parent_layout = cms_layouts(:nested)
29
+ layout = cms_layouts(:child)
30
+ assert_equal "<cms:page:header/>\n<cms:page:left_column>\n<cms:page:right_column>", layout.merged_content
31
+ assert_equal "<cms:page:left_column>\n<cms:page:right_column>", layout.content
32
+
33
+ parent_layout.update_attribute(:content, '<cms:page:whatever/>')
34
+ layout.reload
35
+ assert_equal "<cms:page:left_column>\n<cms:page:right_column>", layout.merged_content
36
+ end
37
+
38
+ def test_merged_css
39
+ merged_css = cms_layouts(:nested).css + cms_layouts(:child).css
40
+ assert_equal merged_css, cms_layouts(:child).merged_css
41
+ end
42
+
43
+ def test_merged_js
44
+ merged_js = cms_layouts(:nested).js + cms_layouts(:child).js
45
+ assert_equal merged_js, cms_layouts(:child).merged_js
46
+ end
47
+
48
+ end
@@ -0,0 +1,122 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class CmsPageTest < ActiveSupport::TestCase
4
+
5
+ def test_fixtures_validity
6
+ CmsPage.all.each do |page|
7
+ assert page.valid?, page.errors.full_messages
8
+ end
9
+ end
10
+
11
+ def test_validations
12
+ page = CmsPage.new
13
+ page.save
14
+ assert page.invalid?
15
+ assert_has_errors_on page, [:cms_layout, :slug, :label]
16
+ end
17
+
18
+ def test_validation_of_parent_relationship
19
+ page = cms_pages(:default)
20
+ assert !page.parent
21
+ page.parent = page
22
+ assert page.invalid?
23
+ assert_has_errors_on page, :parent_id
24
+ page.parent = cms_pages(:child)
25
+ assert page.invalid?
26
+ assert_has_errors_on page, :parent_id
27
+ end
28
+
29
+ def test_initialization_of_full_path
30
+ page = CmsPage.new(new_params)
31
+ assert page.invalid?
32
+ assert_has_errors_on page, :full_path
33
+
34
+ page = CmsPage.new(new_params(:parent => cms_pages(:default)))
35
+ assert page.valid?
36
+ assert_equal '/test-page', page.full_path
37
+
38
+ page = CmsPage.new(new_params(:parent => cms_pages(:child)))
39
+ assert page.valid?
40
+ assert_equal '/child-page/test-page', page.full_path
41
+
42
+ CmsPage.destroy_all
43
+ page = CmsPage.new(new_params)
44
+ assert page.valid?
45
+ assert_equal '/', page.full_path
46
+ end
47
+
48
+ def test_sync_child_pages
49
+ page = cms_pages(:child)
50
+ page_1 = CmsPage.create!(new_params(:parent => page, :slug => 'test-page-1'))
51
+ page_2 = CmsPage.create!(new_params(:parent => page, :slug => 'test-page-2'))
52
+ page_3 = CmsPage.create!(new_params(:parent => page_2, :slug => 'test-page-3'))
53
+ page_4 = CmsPage.create!(new_params(:parent => page_1, :slug => 'test-page-4'))
54
+ assert_equal '/child-page/test-page-1', page_1.full_path
55
+ assert_equal '/child-page/test-page-2', page_2.full_path
56
+ assert_equal '/child-page/test-page-2/test-page-3', page_3.full_path
57
+ assert_equal '/child-page/test-page-1/test-page-4', page_4.full_path
58
+
59
+ page.update_attributes!(:slug => 'updated-page')
60
+ assert_equal '/updated-page', page.full_path
61
+ page_1.reload; page_2.reload; page_3.reload; page_4.reload
62
+ assert_equal '/updated-page/test-page-1', page_1.full_path
63
+ assert_equal '/updated-page/test-page-2', page_2.full_path
64
+ assert_equal '/updated-page/test-page-2/test-page-3', page_3.full_path
65
+ assert_equal '/updated-page/test-page-1/test-page-4', page_4.full_path
66
+
67
+ page_2.update_attributes!(:parent => page_1)
68
+ page_1.reload; page_2.reload; page_3.reload; page_4.reload
69
+ assert_equal '/updated-page/test-page-1', page_1.full_path
70
+ assert_equal '/updated-page/test-page-1/test-page-2', page_2.full_path
71
+ assert_equal '/updated-page/test-page-1/test-page-2/test-page-3', page_3.full_path
72
+ assert_equal '/updated-page/test-page-1/test-page-4', page_4.full_path
73
+ end
74
+
75
+ def test_children_count_updating
76
+ page_1 = cms_pages(:default)
77
+ page_2 = cms_pages(:child)
78
+ assert_equal 1, page_1.children_count
79
+ assert_equal 0, page_2.children_count
80
+
81
+ page_3 = CmsPage.create!(new_params(:parent => page_2))
82
+ page_1.reload; page_2.reload
83
+ assert_equal 1, page_1.children_count
84
+ assert_equal 1, page_2.children_count
85
+ assert_equal 0, page_3.children_count
86
+
87
+ page_3.update_attributes!(:parent => page_1)
88
+ page_1.reload; page_2.reload
89
+ assert_equal 2, page_1.children_count
90
+ assert_equal 0, page_2.children_count
91
+
92
+ page_3.destroy
93
+ page_1.reload; page_2.reload
94
+ assert_equal 1, page_1.children_count
95
+ assert_equal 0, page_2.children_count
96
+ end
97
+
98
+ def test_cascading_destroy
99
+ assert_difference 'CmsPage.count', -2 do
100
+ cms_pages(:default).destroy
101
+ end
102
+ end
103
+
104
+ def test_options_for_select
105
+ assert_equal ['Default Page', '. . Child Page'], CmsPage.options_for_select.collect{|t| t.first }
106
+ assert_equal ['Default Page'], CmsPage.options_for_select(cms_pages(:child)).collect{|t| t.first }
107
+ assert_equal [], CmsPage.options_for_select(cms_pages(:default))
108
+
109
+ page = CmsPage.new(new_params(:parent => cms_pages(:default)))
110
+ assert_equal ['Default Page', '. . Child Page'], CmsPage.options_for_select(page).collect{|t| t.first }
111
+ end
112
+
113
+ protected
114
+
115
+ def new_params(options = {})
116
+ {
117
+ :label => 'Test Page',
118
+ :slug => 'test-page',
119
+ :cms_layout => cms_layouts(:default)
120
+ }.merge(options)
121
+ end
122
+ end