kuhsaft 0.3.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. data/README.md +127 -77
  2. data/Rakefile +15 -10
  3. data/app/assets/javascripts/kuhsaft/application.js +2 -0
  4. data/app/assets/javascripts/kuhsaft/cms/application.js +16 -4
  5. data/app/assets/javascripts/kuhsaft/cms/customizations.js +1 -0
  6. data/app/assets/stylesheets/kuhsaft/application.css.sass +4 -0
  7. data/app/assets/stylesheets/kuhsaft/cms/application.css.sass +125 -0
  8. data/app/assets/stylesheets/kuhsaft/cms/customizations.css.sass +1 -0
  9. data/app/controllers/kuhsaft/application_controller.rb +5 -0
  10. data/app/controllers/kuhsaft/cms/admin_controller.rb +8 -10
  11. data/app/controllers/kuhsaft/cms/bricks_controller.rb +35 -0
  12. data/app/controllers/kuhsaft/cms/pages_controller.rb +16 -19
  13. data/app/controllers/kuhsaft/pages_controller.rb +4 -10
  14. data/app/helpers/cms_helper.rb +3 -3
  15. data/app/helpers/kuhsaft/application_helper.rb +21 -0
  16. data/app/helpers/kuhsaft/cms/application_helper.rb +10 -0
  17. data/app/helpers/kuhsaft/cms/pages_helper.rb +14 -0
  18. data/app/helpers/pages_helper.rb +18 -21
  19. data/app/models/kuhsaft/accordion_brick.rb +16 -0
  20. data/app/models/kuhsaft/accordion_item_brick.rb +22 -0
  21. data/app/models/kuhsaft/brick.rb +85 -0
  22. data/app/models/kuhsaft/brick_type.rb +7 -0
  23. data/app/models/kuhsaft/cms.rb +7 -0
  24. data/app/models/kuhsaft/cms/admin.rb +20 -0
  25. data/app/models/kuhsaft/column_brick.rb +23 -0
  26. data/app/models/kuhsaft/image_brick.rb +19 -0
  27. data/app/models/kuhsaft/image_size.rb +52 -0
  28. data/app/models/kuhsaft/link_brick.rb +19 -0
  29. data/app/models/kuhsaft/page.rb +83 -101
  30. data/app/models/kuhsaft/partition.rb +18 -0
  31. data/app/models/kuhsaft/placeholder_brick.rb +11 -0
  32. data/app/models/kuhsaft/slider_brick.rb +16 -0
  33. data/app/models/kuhsaft/text_brick.rb +9 -0
  34. data/app/models/kuhsaft/two_column_brick.rb +50 -0
  35. data/app/models/kuhsaft/video_brick.rb +20 -0
  36. data/app/uploaders/kuhsaft/asset_uploader.rb +2 -2
  37. data/app/uploaders/kuhsaft/image_brick_image_uploader.rb +63 -0
  38. data/app/views/kuhsaft/accordion_bricks/_accordion_brick.html.haml +3 -0
  39. data/app/{assets/stylesheets/kuhsaft/cms/base/partials/_forms.css.sass → views/kuhsaft/accordion_bricks/accordion_brick/_edit.html.haml} +0 -0
  40. data/app/views/kuhsaft/accordion_item_bricks/_accordion_item_brick.html.haml +8 -0
  41. data/app/views/kuhsaft/accordion_item_bricks/accordion_item_brick/_edit.html.haml +1 -0
  42. data/app/views/kuhsaft/cms/admin/_brick_type_dropdown.html.haml +10 -0
  43. data/app/views/kuhsaft/cms/admin/_content_language_switch.html.haml +7 -0
  44. data/app/views/kuhsaft/cms/admin/_empty_state.html.haml +5 -0
  45. data/app/views/kuhsaft/cms/admin/_main_navigation.html.haml +6 -0
  46. data/app/views/kuhsaft/cms/assets/index.html.haml +2 -2
  47. data/app/views/kuhsaft/cms/bricks/_brick_item.html.haml +38 -0
  48. data/app/views/kuhsaft/cms/bricks/_brick_list.html.haml +4 -0
  49. data/app/views/kuhsaft/cms/bricks/create.js.haml +1 -0
  50. data/app/views/kuhsaft/cms/bricks/destroy.js.haml +7 -0
  51. data/app/views/kuhsaft/cms/bricks/update.js.haml +2 -0
  52. data/app/views/kuhsaft/cms/pages/_branch.html.haml +17 -9
  53. data/app/views/kuhsaft/cms/pages/_form.html.haml +25 -60
  54. data/app/views/kuhsaft/cms/pages/edit.html.haml +14 -8
  55. data/app/views/kuhsaft/cms/pages/index.html.haml +8 -8
  56. data/app/views/kuhsaft/cms/pages/new.html.haml +1 -10
  57. data/app/views/kuhsaft/column_bricks/_column_brick.html.haml +3 -0
  58. data/app/views/kuhsaft/{cms/page_parts/edit.html.haml → column_bricks/column_brick/_edit.html.haml} +0 -0
  59. data/app/views/kuhsaft/image_bricks/_image_brick.html.haml +9 -0
  60. data/app/views/kuhsaft/image_bricks/image_brick/_edit.html.haml +10 -0
  61. data/app/views/kuhsaft/link_bricks/_link_brick.html.haml +3 -0
  62. data/app/views/kuhsaft/link_bricks/link_brick/_edit.html.haml +3 -0
  63. data/app/views/kuhsaft/pages/show.html.haml +5 -3
  64. data/app/views/kuhsaft/placeholder_bricks/_placeholder_brick.html.haml +2 -0
  65. data/app/views/kuhsaft/placeholder_bricks/placeholder_brick/_edit.html.haml +1 -0
  66. data/app/views/kuhsaft/slider_bricks/_slider_brick.html.haml +10 -0
  67. data/app/views/kuhsaft/{cms/page_parts/index.html.haml → slider_bricks/slider_brick/_edit.html.haml} +0 -0
  68. data/app/views/kuhsaft/text_bricks/_text_brick.html.haml +12 -0
  69. data/app/views/kuhsaft/text_bricks/text_brick/_edit.html.haml +2 -0
  70. data/app/views/kuhsaft/two_column_bricks/_two_column_brick.html.haml +3 -0
  71. data/app/views/kuhsaft/two_column_bricks/two_column_brick/_childs.html.haml +5 -0
  72. data/app/views/kuhsaft/two_column_bricks/two_column_brick/_edit.html.haml +1 -0
  73. data/app/views/kuhsaft/video_bricks/_video_brick.html.haml +9 -0
  74. data/app/views/kuhsaft/video_bricks/video_brick/_edit.html.haml +8 -0
  75. data/app/views/layouts/kuhsaft/cms/application.html.haml +20 -0
  76. data/config/initializers/devise.rb +231 -0
  77. data/config/initializers/simple_form.rb +142 -0
  78. data/config/initializers/simple_form_bootstrap.rb +45 -0
  79. data/config/locales/kuhsaft.en.yml +4 -1
  80. data/config/locales/models/kuhsaft/accordion_brick/de.yml +4 -0
  81. data/config/locales/models/kuhsaft/accordion_item_brick/de.yml +7 -0
  82. data/config/locales/models/kuhsaft/column_brick/de.yml +6 -0
  83. data/config/locales/models/kuhsaft/image_brick/de.yml +10 -0
  84. data/config/locales/models/kuhsaft/image_size/de.yml +13 -0
  85. data/config/locales/models/kuhsaft/link_brick/de.yml +9 -0
  86. data/config/locales/models/kuhsaft/page/de.yml +17 -0
  87. data/config/locales/models/kuhsaft/placeholder_brick/de.yml +8 -0
  88. data/config/locales/models/kuhsaft/slider_brick/de.yml +4 -0
  89. data/config/locales/models/kuhsaft/text_brick/de.yml +8 -0
  90. data/config/locales/models/kuhsaft/two_column_brick/de.yml +7 -0
  91. data/config/locales/models/kuhsaft/video_brick/de.yml +9 -0
  92. data/config/locales/simple_form.en.yml +26 -0
  93. data/config/locales/views/kuhsaft/cms/admin/de.yml +10 -0
  94. data/config/locales/views/kuhsaft/cms/bricks/de.yml +8 -0
  95. data/config/locales/views/kuhsaft/cms/pages/de.yml +9 -0
  96. data/config/locales/views/kuhsaft/cms/video_bricks/de.yml +7 -0
  97. data/config/locales/views/kuhsaft/text_brick/de.yml +6 -0
  98. data/config/locales/views/layouts/de.yml +6 -0
  99. data/config/routes.rb +10 -11
  100. data/db/migrate/01_create_kuhsaft_pages.rb +31 -0
  101. data/db/migrate/02_create_kuhsaft_bricks.rb +23 -0
  102. data/db/migrate/03_create_kuhsaft_brick_types.rb +12 -0
  103. data/db/migrate/04_create_kuhsaft_assets.rb +10 -0
  104. data/db/migrate/05_create_kuhsaft_cms_admins.rb +46 -0
  105. data/db/migrate/06_add_template_name_to_kuhsaft_bricks.rb +7 -0
  106. data/db/seeds.rb +14 -0
  107. data/lib/generators/kuhsaft/translations/add_generator.rb +26 -0
  108. data/lib/kuhsaft.rb +8 -1
  109. data/lib/kuhsaft/brick_list.rb +71 -0
  110. data/lib/kuhsaft/engine.rb +17 -12
  111. data/lib/kuhsaft/partial_extractor.rb +21 -0
  112. data/lib/kuhsaft/translatable.rb +40 -0
  113. data/lib/kuhsaft/version.rb +1 -1
  114. data/lib/tasks/kuhsaft_tasks.rake +10 -0
  115. data/lib/templates/kuhsaft/translations/add_translation.html.erb +13 -0
  116. data/spec/dummy/Rakefile +1 -1
  117. data/spec/dummy/app/assets/javascripts/application.js +9 -3
  118. data/spec/dummy/app/assets/stylesheets/application.css +11 -5
  119. data/spec/dummy/app/controllers/application_controller.rb +0 -6
  120. data/spec/dummy/app/views/layouts/application.html.erb +1 -1
  121. data/spec/dummy/config/application.rb +24 -7
  122. data/spec/dummy/config/boot.rb +3 -2
  123. data/spec/dummy/config/database.yml +6 -3
  124. data/spec/dummy/config/environments/development.rb +8 -1
  125. data/spec/dummy/config/environments/production.rb +9 -2
  126. data/spec/dummy/config/environments/test.rb +4 -9
  127. data/spec/dummy/config/initializers/inflections.rb +5 -0
  128. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  129. data/spec/dummy/config/initializers/session_store.rb +1 -1
  130. data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
  131. data/spec/dummy/config/locales/en.yml +2 -2
  132. data/spec/dummy/config/routes.rb +2 -57
  133. data/spec/dummy/db/{migrate/.gitkeep → .gitkeep} +0 -0
  134. data/spec/dummy/public/500.html +0 -1
  135. data/spec/dummy/{lib/tasks → public/stylesheets}/.gitkeep +0 -0
  136. data/spec/factories.rb +11 -17
  137. data/spec/features/cms_auth_spec.rb +9 -0
  138. data/spec/features/cms_pages_spec.rb +23 -0
  139. data/spec/helpers/kuhsaft/cms/application_helper_spec.rb +25 -0
  140. data/spec/lib/brick_list_spec.rb +39 -0
  141. data/spec/lib/engine_spec.rb +25 -0
  142. data/spec/lib/translatable_spec.rb +85 -0
  143. data/spec/models/accordion_brick_spec.rb +32 -0
  144. data/spec/models/accordion_item_brick_spec.rb +50 -0
  145. data/spec/models/asset_spec.rb +25 -23
  146. data/spec/models/brick_spec.rb +110 -0
  147. data/spec/models/cms/admin_spec.rb +26 -0
  148. data/spec/models/column_brick_spec.rb +32 -0
  149. data/spec/models/image_brick_spec.rb +36 -0
  150. data/spec/models/image_size_spec.rb +36 -0
  151. data/spec/models/link_brick_spec.rb +45 -0
  152. data/spec/models/page_spec.rb +262 -281
  153. data/spec/models/placeholder_brick_spec.rb +40 -0
  154. data/spec/models/slider_brick_spec.rb +20 -0
  155. data/spec/models/text_brick_spec.rb +14 -0
  156. data/spec/models/two_column_brick_spec.rb +72 -0
  157. data/spec/models/video_brick_spec.rb +26 -0
  158. data/spec/spec_helper.rb +60 -51
  159. data/spec/support/kuhsaft_spec_helper.rb +4 -28
  160. data/spec/support/request_macros.rb +19 -0
  161. data/vendor/assets/javascripts/redactor.min.js +12 -0
  162. data/vendor/assets/stylesheets/redactor.css +692 -0
  163. metadata +402 -346
  164. data/.gitignore +0 -19
  165. data/.rspec +0 -2
  166. data/.rvmrc +0 -47
  167. data/CHANGELOG.md +0 -81
  168. data/Gemfile +0 -2
  169. data/Guardfile +0 -25
  170. data/LICENSE +0 -7
  171. data/app/assets/images/kuhsaft/add-child-page.png +0 -0
  172. data/app/assets/images/kuhsaft/closedhand.cur +0 -0
  173. data/app/assets/images/kuhsaft/delete.png +0 -0
  174. data/app/assets/images/kuhsaft/header-bg.jpg +0 -0
  175. data/app/assets/images/kuhsaft/module-nav-tab-bg.png +0 -0
  176. data/app/assets/images/kuhsaft/openhand.cur +0 -0
  177. data/app/assets/images/kuhsaft/page-edit-icon.png +0 -0
  178. data/app/assets/images/kuhsaft/page-new-icon.png +0 -0
  179. data/app/assets/images/kuhsaft/page-part-draggable-area.png +0 -0
  180. data/app/assets/images/kuhsaft/page-tree-breadcrumb-arrow.png +0 -0
  181. data/app/assets/images/kuhsaft/pages-breadcrumb-icon.png +0 -0
  182. data/app/assets/images/kuhsaft/tab-bg.png +0 -0
  183. data/app/assets/images/kuhsaft/toggle-arrow-closed.png +0 -0
  184. data/app/assets/images/kuhsaft/toggle-arrow-open.png +0 -0
  185. data/app/assets/images/kuhsaft/wrapper-bg.png +0 -0
  186. data/app/assets/javascripts/kuhsaft/cms/backend.js +0 -34
  187. data/app/assets/javascripts/kuhsaft/cms/jquery-ui-1.8.12.custom.min.js +0 -192
  188. data/app/assets/javascripts/kuhsaft/cms/jquery.elastic.source.js +0 -161
  189. data/app/assets/javascripts/kuhsaft/cms/jquery.min.js +0 -18
  190. data/app/assets/javascripts/kuhsaft/cms/jquery_ujs.js +0 -336
  191. data/app/assets/stylesheets/kuhsaft/cms/application.css +0 -6
  192. data/app/assets/stylesheets/kuhsaft/cms/base/base.css.sass +0 -9
  193. data/app/assets/stylesheets/kuhsaft/cms/base/partials/_assets.css.sass +0 -15
  194. data/app/assets/stylesheets/kuhsaft/cms/base/partials/_buttons.css.sass +0 -34
  195. data/app/assets/stylesheets/kuhsaft/cms/base/partials/_generic.css.sass +0 -342
  196. data/app/assets/stylesheets/kuhsaft/cms/base/partials/_simple_form.css.sass +0 -76
  197. data/app/controllers/kuhsaft/cms/page_parts_controller.rb +0 -34
  198. data/app/models/kuhsaft/localized_page.rb +0 -81
  199. data/app/models/kuhsaft/page_part.rb +0 -12
  200. data/app/models/kuhsaft/page_part/content.rb +0 -76
  201. data/app/models/kuhsaft/page_part/markdown.rb +0 -8
  202. data/app/views/kuhsaft/cms/page_parts/destroy.js.haml +0 -1
  203. data/app/views/kuhsaft/cms/page_parts/new.html.haml +0 -0
  204. data/app/views/kuhsaft/cms/page_parts/show.html.haml +0 -0
  205. data/app/views/kuhsaft/cms/page_parts/update.js.haml +0 -0
  206. data/app/views/kuhsaft/page_part/markdowns/_edit_markdown.html.haml +0 -1
  207. data/app/views/kuhsaft/page_part/markdowns/_show_markdown.html.haml +0 -1
  208. data/app/views/kuhsaft/pages/index.html.haml +0 -0
  209. data/app/views/layouts/kuhsaft/admin.html.haml +0 -35
  210. data/config/initializers/generators.rb +0 -7
  211. data/config/initializers/page_parts.rb +0 -17
  212. data/kuhsaft.gemspec +0 -39
  213. data/lib/generators/kuhsaft/install/assets_generator.rb +0 -12
  214. data/lib/generators/kuhsaft/install/migrations_generator.rb +0 -43
  215. data/lib/templates/kuhsaft/install/acts_as_taggable_on_migration.rb +0 -37
  216. data/lib/templates/kuhsaft/install/add_fulltext_to_localized_page.rb +0 -9
  217. data/lib/templates/kuhsaft/install/add_page_type_to_localized_pages.rb +0 -9
  218. data/lib/templates/kuhsaft/install/add_published_at_to_localized_pages.rb +0 -9
  219. data/lib/templates/kuhsaft/install/add_tags_to_page_part_contents.rb +0 -9
  220. data/lib/templates/kuhsaft/install/add_type_to_page_part_contents.rb +0 -9
  221. data/lib/templates/kuhsaft/install/add_url_to_localized_pages.rb +0 -9
  222. data/lib/templates/kuhsaft/install/create_assets.rb +0 -12
  223. data/lib/templates/kuhsaft/install/create_kuhsaft_localized_pages.rb +0 -19
  224. data/lib/templates/kuhsaft/install/create_kuhsaft_pages.rb +0 -14
  225. data/lib/templates/kuhsaft/install/create_page_part_contents.rb +0 -14
  226. data/spec/controllers/cms_assets_controller_spec.rb +0 -26
  227. data/spec/controllers/cms_pages_controller_spec.rb +0 -65
  228. data/spec/controllers/page_parts_controller_spec.rb +0 -60
  229. data/spec/controllers/pages_controller_spec.rb +0 -30
  230. data/spec/dummy/app/assets/images/rails.png +0 -0
  231. data/spec/helpers/cms_helper_spec.rb +0 -22
  232. data/spec/helpers/pages_helper_spec.rb +0 -119
  233. data/spec/integration/navigation_spec.rb +0 -9
  234. data/spec/models/localized_page_spec.rb +0 -266
  235. data/spec/models/page_part_content_spec.rb +0 -95
  236. data/spec/models/page_part_spec.rb +0 -17
  237. data/spec/requests/cms_pages_spec.rb +0 -27
  238. data/spec/routing/assets_routing_spec.rb +0 -63
  239. data/spec/routing/page_part_routing_spec.rb +0 -70
  240. data/spec/routing/pages_routing_spec.rb +0 -74
@@ -1,39 +1,41 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Kuhsaft::Asset do
4
+
5
+ let :asset do
6
+ create(:asset)
7
+ end
8
+
9
+ let :uploader do
10
+ u = Kuhsaft::AssetUploader.new(asset, :file)
11
+ u.store!(File.open(File.join(Kuhsaft::Engine.root, 'spec', 'dummy', 'app', 'assets', 'images', 'spec-image.png')))
12
+ u
13
+ end
14
+
4
15
  before do
5
16
  Kuhsaft::AssetUploader.enable_processing = true
6
- @asset = Factory(:asset)
7
- @uploader = Kuhsaft::AssetUploader.new(@asset, :file)
8
- @uploader.store!(File.open(File.join(Kuhsaft::Engine.root, 'spec', 'dummy', 'app', 'assets', 'images', 'spec-image.png')))
9
17
  end
10
-
18
+
11
19
  after do
12
20
  Kuhsaft::AssetUploader.enable_processing = false
13
21
  end
14
-
15
- it 'should have a thumbnail' do
16
- @uploader.should respond_to(:thumb)
22
+
23
+ it 'has a thumbnail' do
24
+ uploader.should respond_to(:thumb)
17
25
  end
18
-
19
- it "should make the image readable only to the owner and not executable" do
26
+
27
+ it "makes the image readable only to the owner and not executable" do
20
28
  pending 'how and where do we ensure permissions?'
21
- @uploader.should have_permissions(0600)
29
+ uploader.should have_permissions(0600)
22
30
  end
23
-
31
+
24
32
  describe '#file_type' do
25
- it 'should have a file_type' do
26
- @asset.should respond_to(:file_type)
33
+ it 'has a file_type' do
34
+ asset.should respond_to(:file_type)
27
35
  end
28
-
29
- it 'should be symbolized' do
30
- @asset.file_type.should be_a(Symbol)
31
- end
32
- end
33
-
34
- describe '#name' do
35
- it 'should have a name' do
36
- @asset.should respond_to(:name)
36
+
37
+ it 'is symbolized' do
38
+ asset.file_type.should be_a(Symbol)
37
39
  end
38
40
  end
39
- end
41
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kuhsaft::Brick do
4
+ let :brick do
5
+ Kuhsaft::Brick.new
6
+ end
7
+
8
+ describe '#valid?' do
9
+ it 'sets a default locale' do
10
+ brick.should_receive(:set_locale)
11
+ brick.valid?
12
+ end
13
+
14
+ it 'sets a default position' do
15
+ brick.should_receive(:set_position)
16
+ brick.valid?
17
+ end
18
+ end
19
+
20
+ describe '#set_position' do
21
+ context 'witout a position' do
22
+ it 'sets a default' do
23
+ brick.set_position
24
+ brick.position.should be(1)
25
+ end
26
+ end
27
+
28
+ context 'with a position' do
29
+ it 'does not change' do
30
+ brick.position = 3
31
+ expect { brick.set_position }.to_not change(brick, :position)
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#set_locale' do
37
+ context 'witout a locale' do
38
+ it 'sets a default' do
39
+ brick.set_locale
40
+ brick.locale.should == I18n.locale
41
+ end
42
+ end
43
+
44
+ context 'with a locale' do
45
+ it 'does not change' do
46
+ brick.locale = 'de'
47
+ expect { brick.set_locale }.to_not change(brick, :locale)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '#brick_list_type' do
53
+ it 'returns Kuhsaft::Brick' do
54
+ brick.brick_list_type.should == 'Kuhsaft::Brick'
55
+ end
56
+ end
57
+
58
+ describe '#parents' do
59
+ it 'returns the chain of parents' do
60
+ item1, item2, item3 = mock, mock, Kuhsaft::Brick.new
61
+ item2.stub(:brick_list).and_return(item1)
62
+ item3.stub(:brick_list).and_return(item2)
63
+ item3.parents.should == [item1, item2]
64
+ end
65
+ end
66
+
67
+ describe '#to_edit_partial_path' do
68
+ it 'returns the path to the form partial' do
69
+ Kuhsaft::TextBrick.new.to_edit_partial_path.should == 'kuhsaft/text_bricks/text_brick/edit'
70
+ end
71
+ end
72
+
73
+ describe '#to_edit_childs_partial_path' do
74
+ it 'returns the path to the form partial' do
75
+ Kuhsaft::TextBrick.new.to_edit_childs_partial_path.should == 'kuhsaft/text_bricks/text_brick/childs'
76
+ end
77
+ end
78
+
79
+ describe '#bricks' do
80
+ it 'can not have childs by default' do
81
+ brick.should_not respond_to(:bricks)
82
+ end
83
+ end
84
+
85
+ describe '#to_style_class' do
86
+ it 'returns a css classname' do
87
+ Kuhsaft::TextBrick.new.to_style_class.should == 'kuhsaft-text-brick'
88
+ end
89
+ end
90
+
91
+ describe '#to_style_id' do
92
+ it 'returns a unique DOM id' do
93
+ brick = Kuhsaft::TextBrick.new
94
+ brick.stub(:id).and_return(104)
95
+ brick.to_style_id.should == 'kuhsaft-text-brick-104'
96
+ end
97
+ end
98
+
99
+ describe '#backend_label' do
100
+ it 'returns the name of the brick' do
101
+ brick = Kuhsaft::TextBrick.new
102
+ brick.backend_label.should == 'Text'
103
+ end
104
+
105
+ context 'with the parenthesis option given' do
106
+ brick = Kuhsaft::TextBrick.new
107
+ brick.backend_label(:parenthesis => true).should == '(Text)'
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kuhsaft::Cms::Admin do
4
+
5
+ let :admin do
6
+ Kuhsaft::Cms::Admin.new
7
+ end
8
+
9
+ describe '#admin?' do
10
+ it 'is true and the default' do
11
+ admin.admin?.should be_true
12
+ end
13
+ end
14
+
15
+ describe '#editor?' do
16
+ it 'is false' do
17
+ admin.editor?.should be_false
18
+ end
19
+ end
20
+
21
+ describe '#author?' do
22
+ it 'is false' do
23
+ admin.author?.should be_false
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kuhsaft::ColumnBrick do
4
+
5
+ let :column_brick do
6
+ Kuhsaft::ColumnBrick.new
7
+ end
8
+
9
+ describe '#user_can_delete?' do
10
+ it 'returns false' do
11
+ column_brick.user_can_delete?.should be_false
12
+ end
13
+ end
14
+
15
+ describe '#user_can_save' do
16
+ it 'returns false' do
17
+ column_brick.user_can_save?.should be_false
18
+ end
19
+ end
20
+
21
+ describe '#renders_own_childs?' do
22
+ it 'returns false' do
23
+ column_brick.renders_own_childs?.should be_false
24
+ end
25
+ end
26
+
27
+ describe '#bricks' do
28
+ it 'can have childs' do
29
+ column_brick.should respond_to(:bricks)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kuhsaft::ImageBrick do
4
+
5
+ let :image_brick do
6
+ Kuhsaft::ImageBrick.new
7
+ end
8
+
9
+ describe '#valid' do
10
+ before do
11
+ image_brick.valid?
12
+ end
13
+
14
+ context 'without an #image' do
15
+ it 'has en error' do
16
+ image_brick.should have(1).error_on(:image)
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '#save' do
22
+ context 'when changing the image size' do
23
+ it 'regenerates the image version' do
24
+ image_brick.stub(:image_size_changed?).and_return(true)
25
+ image_brick.image.should_receive(:recreate_versions!)
26
+ image_brick.resize_image_if_size_changed
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#bricks' do
32
+ it 'can not have childs' do
33
+ image_brick.should_not respond_to(:bricks)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kuhsaft::ImageSize do
4
+ before do
5
+ Kuhsaft::ImageSize.build_defaults!
6
+ end
7
+
8
+ describe '.build_defaults!' do
9
+ it 'sets the default sizes' do
10
+ Kuhsaft::ImageSize.all.should == [Kuhsaft::ImageSize.gallery_size,
11
+ Kuhsaft::ImageSize.teaser_size]
12
+ end
13
+ end
14
+
15
+ describe '.clear!' do
16
+ before do
17
+ Kuhsaft::ImageSize.clear!
18
+ end
19
+
20
+ it 'empties the list' do
21
+ Kuhsaft::ImageSize.all.should be_empty
22
+ end
23
+ end
24
+
25
+ describe '.add' do
26
+ it 'adds a new image size' do
27
+ expect { Kuhsaft::ImageSize.add(:stuff, 200, 100) }.to change(Kuhsaft::ImageSize.all, :count).by(1)
28
+ end
29
+ end
30
+
31
+ describe '.find_by_name' do
32
+ it 'returns the size' do
33
+ Kuhsaft::ImageSize.find_by_name('gallery').should == Kuhsaft::ImageSize.gallery_size
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kuhsaft::LinkBrick do
4
+
5
+ let :link_brick do
6
+ Kuhsaft::LinkBrick.new
7
+ end
8
+
9
+ describe '#valid' do
10
+ before do
11
+ link_brick.valid?
12
+ end
13
+
14
+ context 'without a #href' do
15
+ it 'has en error' do
16
+ link_brick.should have(1).error_on(:href)
17
+ end
18
+ end
19
+
20
+ context 'without a #caption' do
21
+ it 'has an error' do
22
+ link_brick.should have(1).error_on(:caption)
23
+ end
24
+ end
25
+ end
26
+
27
+ describe '#bricks' do
28
+ it 'can not have childs' do
29
+ link_brick.should_not respond_to(:bricks)
30
+ end
31
+ end
32
+
33
+ describe '.styles' do
34
+ it 'returns the available link styles' do
35
+ Kuhsaft::LinkBrick.styles.should == %w(pdf word excel button external)
36
+ end
37
+ end
38
+
39
+ describe '#to_style_class' do
40
+ it 'includes the link style' do
41
+ link_brick.stub(:link_style).and_return('pdf')
42
+ link_brick.to_style_class.should == 'kuhsaft-link-brick pdf'
43
+ end
44
+ end
45
+ end
@@ -1,331 +1,312 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Kuhsaft::Page do
4
-
5
- before do
6
- set_lang :en
4
+ subject { described_class }
5
+
6
+ describe '.search' do
7
+ before do
8
+ create :page
9
+ create :page
10
+ create :page
11
+ end
12
+
13
+ it 'should find any containing the search term' do
14
+ Kuhsaft::Page.search('lorem').should have_at_least(0).items
15
+ end
16
+
17
+ it 'should find with "English Title"' do
18
+ Kuhsaft::Page.search('English Title').should have_at_least(1).item
19
+ end
20
+
21
+ it 'should only find published results' do
22
+ Kuhsaft::Page.search('English Title').should be_all { |p| p.published? == true }
23
+ end
7
24
  end
8
-
9
- after do
10
- reset_lang
25
+
26
+ describe '.position_of' do
27
+ it 'should find the position of a page' do
28
+ page = create(:page)
29
+ Kuhsaft::Page.position_of(page.id).should == page.position
30
+ end
11
31
  end
12
-
13
- before :each do
14
- destroy_all_pages
15
- @page = Factory.create :page
32
+
33
+ describe '.find_by_url' do
34
+ it 'should find its translated content by url' do
35
+ page = create(:page)
36
+ Kuhsaft::Page.find_by_url(page.url).should eq(page)
37
+ end
38
+ end
39
+
40
+ describe '.flat_tree' do
41
+ it 'should create an ordered, flat list of the page tree' do
42
+ tree = create_page_tree
43
+ Kuhsaft::Page.flat_tree.should eq(tree)
44
+ end
16
45
  end
17
-
18
- describe 'associations' do
19
- describe '#localized_pages' do
20
- it 'should have localized_pages' do
21
- @page.should respond_to(:localized_pages)
46
+
47
+ describe '#initialize' do
48
+ context 'without values' do
49
+ let :page do
50
+ Kuhsaft::Page.new
22
51
  end
23
-
24
- it 'should have at least 1 localized page' do
25
- @page.localized_pages.should have_at_least(1).item
52
+
53
+ before do
54
+ page.valid?
26
55
  end
27
- end
28
-
29
- describe '#childs' do
30
- it 'should have child pages' do
31
- @page.childs << Factory.create(:page)
32
- @page.childs.should have_at_least(1).page
56
+
57
+ it 'has a mandatory title' do
58
+ page.should have(1).error_on(:title)
59
+ end
60
+
61
+ it 'has a mandatory slug' do
62
+ page.should have(1).error_on(:slug)
33
63
  end
34
64
  end
35
65
  end
36
-
37
- describe 'class methods' do
38
- describe '#root_pages' do
39
- before { destroy_all_pages }
40
- it 'should have a list of the toplevel pages' do
41
- root_page = Factory.create :page
42
- Kuhsaft::Page.root_pages.should have_at_least(1).page
43
- end
66
+
67
+ describe '#published' do
68
+ it 'returns only published pages' do
69
+ p1, p2, p3 = 3.times.map { create(:page) }
70
+ p2.update_attribute :published, Kuhsaft::PublishState::UNPUBLISHED
71
+ Kuhsaft::Page.published.should be_all { |p| p.published?.should be_true }
44
72
  end
45
-
46
- describe '#position_of' do
47
- it 'should find the position of a page' do
48
- page = Factory.create :page
49
- position = page.position
50
- Kuhsaft::Page.position_of(page.id).should == position
51
- end
73
+ end
74
+
75
+ describe '#without_self' do
76
+ it 'returns pages but not itself' do
77
+ 2.times { create(:page) }
78
+ page = Kuhsaft::Page.first
79
+ page.without_self.should_not include(page)
52
80
  end
53
-
54
- describe '#find_by_url' do
55
- before { destroy_all_pages }
56
- it 'should find its translated content by url' do
57
- page = Factory.create(:page)
58
- Kuhsaft::Page.find_by_url(page.url).should eq(page)
59
- end
81
+ end
82
+
83
+ describe '#nesting_name' do
84
+ let :page do
85
+ create(:page)
60
86
  end
61
-
62
- describe '#flat_tree' do
63
- before { destroy_all_pages }
64
- it 'should create an ordered, flat list of the page tree' do
65
- tree = create_page_tree
66
- Kuhsaft::Page.flat_tree.should eq(tree)
67
- end
87
+
88
+ let :child_page do
89
+ create(:page, :parent => page)
68
90
  end
69
-
70
- describe '#published' do
71
- before { destroy_all_pages }
72
- it 'should get only published pages' do
73
- p1, p2, p3 = 3.times.map { Factory.create :page }
74
- p2.translation.update_attribute :published, Kuhsaft::PublishState::UNPUBLISHED
75
- Kuhsaft::Page.published.should be_all { |p| p.published?.should be_true }
76
- Kuhsaft::Page.published.length.should be(2)
77
- end
91
+
92
+ let :child_child_page do
93
+ create(:page, :parent => child_page)
78
94
  end
79
-
80
- describe '#current_locale' do
81
- before { destroy_all_pages }
82
- it 'should only return pages with translations in the current locale' do
83
- p1 = Factory.create :page
84
- p1.translation.update_attribute :locale, :fr
85
- p2 = Factory.create :page
86
- p2.translation.update_attribute :locale, :fr
87
- p3 = Factory.create :page
88
- Kuhsaft::Page.current_translation_locale = :fr
89
- Kuhsaft::Page.current_locale.should have(2).items
90
- Kuhsaft::Page.current_translation_locale = :en
95
+
96
+ context 'on the topmost level' do
97
+ it 'has a label representing it\'s nesting depth without a leading dash' do
98
+ page.nesting_name.should eq(page.title)
91
99
  end
92
100
  end
93
-
94
- describe 'languages and locales' do
95
- describe '#translation_locales' do
96
- it 'should provide an array of translation locales' do
97
- Kuhsaft::Page.translation_locales.should be_an_instance_of(Array)
98
- end
99
-
100
- it 'should contain :en as minimal translation locale' do
101
- Kuhsaft::Page.translation_locales.include?(:en).should be_true
102
- end
103
-
104
- it 'should contain only locale symbols' do
105
- Kuhsaft::Page.translation_locales = ['de']
106
- Kuhsaft::Page.translation_locales.should be_all { |l| l.should be_an_instance_of(Symbol)}
107
- end
101
+
102
+ context 'on the first level' do
103
+ it 'should have a label with one dash' do
104
+ child_page.nesting_name.should eq("- #{child_page.title}")
108
105
  end
109
-
110
- describe '#current_translation_locale' do
111
- it 'should have the current translation locale' do
112
- Kuhsaft::Page.current_translation_locale = 'de'
113
- Kuhsaft::Page.current_translation_locale.should be(:de)
114
- end
106
+ end
107
+
108
+ context 'on the second level' do
109
+ it 'should have a label with two dashes' do
110
+ child_child_page.nesting_name.should eq("-- #{child_child_page.title}")
115
111
  end
116
112
  end
117
113
  end
118
-
119
- describe 'instance methods' do
120
- describe '#root?' do
121
- it 'should return true for a page without a parent' do
122
- Factory::create(:page).root?.should be_true
123
- end
114
+
115
+ describe '#parent_pages' do
116
+ let :page do
117
+ create(:page)
124
118
  end
125
-
126
- describe '#without_self' do
127
- it 'should return pages but not itself' do
128
- 10.times { Factory.create :page }
129
- page = Kuhsaft::Page.first
130
- page.without_self.should_not include(page)
131
- end
132
- after { destroy_all_pages }
119
+
120
+ let :child_page do
121
+ create(:page, :parent => page)
133
122
  end
134
-
135
- describe '#nesting_name' do
136
- before do
137
- @p1, @p2, @p3 = create_page_tree
138
- end
139
-
140
- context 'on the topmost level' do
141
- it 'should have a label representing it\'s nesting depth without a leading dash' do
142
- @p1.nesting_name.should eq('English Title 1')
143
- end
144
- end
145
-
146
- context 'on the first level' do
147
- it 'should have a label with one dash' do
148
- @p2.nesting_name.should eq('- English Title 2')
149
- end
150
- end
151
-
152
- context 'on the second level' do
153
- it 'should have a label with two dashes' do
154
- @p3.nesting_name.should eq('-- English Title 3')
155
- end
156
- end
157
- end
158
-
159
- describe '#siblings' do
160
- it 'should know it\'s siblings' do
161
- Factory.create(:page).should respond_to(:siblings)
162
- end
163
-
164
- it 'should be a list of pages' do
165
- Factory.create(:page).siblings.should be_all { |p| p.should be_an_instance_of(Kuhsaft::Page) }
166
- end
123
+
124
+ it 'has a list of parent pages' do
125
+ child_page.parent_pages.should == [page]
167
126
  end
168
-
169
- describe '#parent' do
170
- before do
171
- @page = Factory::create :page
172
- @child = Factory::create :page
173
- @page.childs << @child
174
- end
175
-
176
- it 'should know it\'s parent page' do
177
- @child.should respond_to(:parent)
178
- end
179
-
180
- it 'should be a Kuhsaft::Page' do
181
- @child.parent.should be_an_instance_of(Kuhsaft::Page)
182
- end
127
+
128
+ it 'is ordered from top to bottom' do
129
+ child_page.parent_pages.last.should == page
183
130
  end
184
-
185
- describe '#translation' do
186
- it 'should have a translation' do
187
- @page.should respond_to(:translation)
188
- end
189
-
190
- it 'should return a Kuhsaft::LocalizedPage' do
191
- @page.translation.should be_an_instance_of(Kuhsaft::LocalizedPage)
192
- end
193
-
194
- context 'when saving the page' do
195
- it 'should save the translation' do
196
- @page.translation.title = 'some localized title'
197
- @page.should_receive(:save_translation)
198
- @page.save
199
- end
131
+ end
132
+
133
+ describe '#link' do
134
+ context 'when it has no content' do
135
+ it 'should return the link of it\'s first child' do
136
+ page = create(:page)
137
+ child = create(:page, :parent => page)
138
+ page.body = nil
139
+ page.save
140
+ page.link.should == child.link
200
141
  end
201
142
  end
202
-
203
- describe '#page_part_type' do
204
- it 'accepts a page_part_type to determine which page_part needs to be added' do
205
- @page.should respond_to(:page_part_type)
206
- end
143
+ end
144
+
145
+ describe '#increment_position' do
146
+ it 'increments the position by 1' do
147
+ page = create :page
148
+ position = page.position
149
+ page.increment_position
150
+ page.position.should == (position + 1)
207
151
  end
208
-
209
- describe '#parent_pages' do
210
- it 'should have parent_pages' do
211
- @page.should respond_to(:parent_pages)
212
- end
213
-
214
- it 'should have a list of parent pages' do
215
- @page.parent_pages.should be_instance_of(Array)
216
- end
217
-
218
- it 'should be ordered from top to bottom' do
219
- @page.parent_pages.last.should be(@page)
220
- end
152
+ end
153
+
154
+ describe '#decrement_position' do
155
+ it 'decrements the position by 1' do
156
+ page = create :page
157
+ position = page.position
158
+ page.decrement_position
159
+ page.position.should == (position - 1)
221
160
  end
222
-
223
- describe '#link' do
224
- it 'should have a link' do
225
- @page.should respond_to(:link)
226
- end
227
-
228
- context 'when it has no content' do
229
- it 'should return the link of it\'s first child' do
230
- page = Factory.create :page
231
- child = Factory.create :page
232
- page.childs << child
233
- page.translation.body = nil
234
- page.save
235
- page.link.should == child.link
236
- end
237
- end
161
+ end
162
+
163
+ describe '#preceding_sibling' do
164
+ it 'finds the predecing sibling' do
165
+ page1 = create :page
166
+ page2 = create :page
167
+ page3 = create :page
168
+ page3.preceding_sibling.id.should == page2.id
238
169
  end
239
170
  end
240
-
241
- describe 'custom ordering' do
242
- describe '#increment_position' do
243
- it 'should increment it\'s position by 1' do
244
- page = Factory.create :page
245
- position = page.position
246
- page.increment_position
247
- page.position.should == (position + 1)
248
- end
171
+
172
+ describe '#succeeding_sibling' do
173
+ it 'finds the succeeding sibling' do
174
+ page1 = create :page
175
+ page2 = create :page
176
+ page3 = create :page
177
+ page2.succeeding_sibling.id.should == page3.id
249
178
  end
250
-
251
- describe '#decrement_position' do
252
- it 'should decrement it\'s position by 1' do
253
- page = Factory.create :page
254
- position = page.position
255
- page.decrement_position
256
- page.position.should == (position - 1)
257
- end
179
+ end
180
+
181
+ describe '#reposition' do
182
+ it 'repositions before a page, specified by id' do
183
+ page1 = create :page
184
+ page2 = create :page
185
+ page3 = create :page
186
+ page3.reposition page1.id
187
+ page3.preceding_sibling.id.should == page1.id
258
188
  end
259
-
260
- describe '#preceding_sibling' do
261
- it 'should find the predecing sibling' do
262
- page1 = Factory.create :page
263
- page2 = Factory.create :page
264
- page3 = Factory.create :page
265
- page3.preceding_sibling.id.should == page2.id
266
- end
189
+
190
+ it 'repositions before all siblings, specified by nil' do
191
+ page1 = create :page
192
+ page2 = create :page
193
+ page2.reposition nil
194
+ page2.position.should == 1
195
+ end
196
+ end
197
+
198
+ describe '#slug' do
199
+ let :page do
200
+ build(:page)
201
+ end
202
+
203
+ it 'has a slug by default' do
204
+ page.save
205
+ page.slug.should eq(page.title.parameterize)
267
206
  end
268
-
269
- describe '#succeeding_sibling' do
270
- it 'should find the succeeding sibling' do
271
- page1 = Factory.create :page
272
- page2 = Factory.create :page
273
- page3 = Factory.create :page
274
- page2.succeeding_sibling.id.should == page3.id
207
+
208
+ context 'when it is empty' do
209
+ it 'generates the slug' do
210
+ page.should_receive(:create_slug)
211
+ page.save
275
212
  end
276
213
  end
277
-
278
- describe '#reposition' do
279
- it 'should reposition before a page, specified by id' do
280
- page1 = Factory.create :page
281
- page2 = Factory.create :page
282
- page3 = Factory.create :page
283
- page3.reposition page1.id
284
- page3.preceding_sibling.id.should == page1.id
214
+
215
+ context 'when it is not empty' do
216
+ it 'takes the slug provided by the user' do
217
+ page.slug = 'my-slug'
218
+ page.save
219
+ page.slug.should == 'my-slug'
285
220
  end
286
-
287
- it 'should reposition before all siblings, specified by nil' do
288
- page1 = Factory.create :page
289
- page2 = Factory.create :page
290
- page2.reposition nil
291
- page2.position.should == 1
221
+ end
222
+ end
223
+
224
+ describe '#url' do
225
+ context 'when it is a normal page' do
226
+ it 'returns the concatenated slug of the whole child/parent tree' do
227
+ page = create(:page, :slug => 'parent-slug', :page_type => '')
228
+ child = create(:page, :slug => 'child-slug', :page_type => '', :parent => page)
229
+ child.url.should == 'en/parent-slug/child-slug'
292
230
  end
293
231
  end
294
-
295
- describe '#siblings' do
296
- pending 'describe'
232
+
233
+ context 'when it is a navigation? page' do
234
+ it 'returns without the parent page slug' do
235
+ page = create(:page, :slug => 'parent-slug', :page_type => Kuhsaft::PageType::NAVIGATION)
236
+ child = create(:page, :slug => 'child-slug', :page_type => '', :parent => page)
237
+ child.url.should == 'en/child-slug'
238
+ end
297
239
  end
298
-
299
- describe '#position_to_top' do
300
- pending 'describe'
240
+
241
+ context 'when it is a redirect? page' do
242
+ it 'returns the plain url' do
243
+ page = create(:page, :page_type => Kuhsaft::PageType::REDIRECT, :url => '/en/news')
244
+ page.link.should eq('/en/news')
245
+ end
301
246
  end
302
-
303
- describe '#recount_siblings_position_from' do
304
- pending 'describe'
247
+ end
248
+
249
+ describe '#navigation?' do
250
+ context 'when the page_type is navigation' do
251
+ it 'returns true if the page_type is PageType::NAVIGATION' do
252
+ Kuhsaft::Page.new(:page_type => Kuhsaft::PageType::NAVIGATION).navigation?.should be_true
253
+ end
305
254
  end
306
-
307
- describe '#reposition' do
308
- pending 'describe'
255
+
256
+ context 'when the page_type is anything else' do
257
+ it 'returns false' do
258
+ Kuhsaft::Page.new(:page_type => Kuhsaft::PageType::REDIRECT).navigation?.should be_false
259
+ end
309
260
  end
310
-
311
- describe '#set_position' do
312
- pending
313
- end
314
261
  end
315
-
316
- describe 'should delegate' do
317
- it 'slug, title, published, published?, page_type, fulltext, keywords, page_parts and description to the translation' do
318
- [:slug, :title, :published, :published?, :page_type, :fulltext, :keywords, :page_parts, :description].each do |attr|
319
- @page.send(attr).should eq(@page.translation.send(attr))
262
+
263
+ describe '#redirect?' do
264
+ context 'when the page_type is a redirect' do
265
+ it 'returns true' do
266
+ Kuhsaft::Page.new(:page_type => Kuhsaft::PageType::REDIRECT).redirect?.should be_true
267
+ end
268
+ end
269
+
270
+ context 'when the page type is anything else' do
271
+ it 'returns false' do
272
+ Kuhsaft::Page.new(:page_type => Kuhsaft::PageType::NAVIGATION).redirect?.should be_false
320
273
  end
321
274
  end
322
-
323
- it 'url to the translation' do
324
- @page.url.should eq(@page.translation.url)
275
+ end
276
+
277
+ describe '#fulltext' do
278
+ let :page do
279
+ p = create(:page, :keywords => 'key words', :description => 'descrip tion', :title => 'my title')
280
+ p.bricks << Kuhsaft::TextBrick.new(:locale => I18n.locale, :text => 'oh la la')
281
+ p.save
282
+ p
325
283
  end
326
-
327
- it 'locale to the translation' do
328
- @page.locale.should be(@page.translation.locale)
284
+
285
+ context 'when saved' do
286
+ it 'it collects and assigns the fulltext' do
287
+ page.should_receive(:collect_fulltext)
288
+ page.save
289
+ end
290
+
291
+ it 'contains the title' do
292
+ page.fulltext.should include('my title')
293
+ end
294
+
295
+ it 'contains the keywords' do
296
+ page.fulltext.should include('key words')
297
+ end
298
+
299
+ it 'contains the description' do
300
+ page.fulltext.should include('descrip tion')
301
+ end
302
+
303
+ it 'contains the page part content' do
304
+ page.fulltext.should include('oh la la')
305
+ end
306
+
307
+ it 'converts all data to strings' do
308
+ expect { page.collect_fulltext }.to_not raise_error
309
+ end
329
310
  end
330
311
  end
331
- end
312
+ end