tb_cms 0.9.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.markdown +110 -0
  4. data/Rakefile +28 -0
  5. data/app/assets/images/spud/admin/menus_thumb.png +0 -0
  6. data/app/assets/images/spud/admin/menus_thumb@2x.png +0 -0
  7. data/app/assets/images/spud/admin/pages_thumb.png +0 -0
  8. data/app/assets/images/spud/admin/snippets_thumb.png +0 -0
  9. data/app/assets/images/spud/admin/snippets_thumb@2x.png +0 -0
  10. data/app/assets/javascripts/spud/admin/cms/application.js +25 -0
  11. data/app/assets/javascripts/spud/admin/cms/menu_items.js +35 -0
  12. data/app/assets/javascripts/spud/admin/cms/pages.js +29 -0
  13. data/app/assets/javascripts/spud/admin/snippets.js +2 -0
  14. data/app/assets/stylesheets/spud/admin/cms/application.css +28 -0
  15. data/app/assets/stylesheets/spud/admin/cms.css +4 -0
  16. data/app/assets/stylesheets/spud/admin/snippets.css +4 -0
  17. data/app/controllers/pages_controller.rb +90 -0
  18. data/app/controllers/spud/admin/cms_controller.rb +3 -0
  19. data/app/controllers/spud/admin/menu_items_controller.rb +115 -0
  20. data/app/controllers/spud/admin/menus_controller.rb +55 -0
  21. data/app/controllers/spud/admin/pages_controller.rb +182 -0
  22. data/app/controllers/spud/admin/snippets_controller.rb +61 -0
  23. data/app/controllers/spud/cms/sitemaps_controller.rb +13 -0
  24. data/app/helpers/spud/cms/application_helper.rb +283 -0
  25. data/app/models/spud_menu.rb +9 -0
  26. data/app/models/spud_menu_item.rb +72 -0
  27. data/app/models/spud_page.rb +131 -0
  28. data/app/models/spud_page_liquid_tag.rb +4 -0
  29. data/app/models/spud_page_partial.rb +67 -0
  30. data/app/models/spud_page_partial_revision.rb +5 -0
  31. data/app/models/spud_snippet.rb +42 -0
  32. data/app/observers/page_sweeper.rb +48 -0
  33. data/app/observers/snippet_sweeper.rb +41 -0
  34. data/app/views/pages/not_found.html.erb +2 -0
  35. data/app/views/pages/show.html.erb +24 -0
  36. data/app/views/spud/admin/menu_items/_form.html.erb +51 -0
  37. data/app/views/spud/admin/menu_items/_menu_item_row.html.erb +22 -0
  38. data/app/views/spud/admin/menu_items/edit.html.erb +10 -0
  39. data/app/views/spud/admin/menu_items/index.html.erb +17 -0
  40. data/app/views/spud/admin/menu_items/new.html.erb +12 -0
  41. data/app/views/spud/admin/menus/_form.html.erb +11 -0
  42. data/app/views/spud/admin/menus/edit.html.erb +13 -0
  43. data/app/views/spud/admin/menus/index.html.erb +24 -0
  44. data/app/views/spud/admin/menus/new.html.erb +7 -0
  45. data/app/views/spud/admin/pages/_form.html.erb +95 -0
  46. data/app/views/spud/admin/pages/_page_partials_form.html.erb +18 -0
  47. data/app/views/spud/admin/pages/_page_row.html.erb +18 -0
  48. data/app/views/spud/admin/pages/edit.html.erb +32 -0
  49. data/app/views/spud/admin/pages/index.html.erb +13 -0
  50. data/app/views/spud/admin/pages/new.html.erb +34 -0
  51. data/app/views/spud/admin/pages/show.html.erb +20 -0
  52. data/app/views/spud/admin/snippets/_form.html.erb +8 -0
  53. data/app/views/spud/admin/snippets/edit.html.erb +7 -0
  54. data/app/views/spud/admin/snippets/index.html.erb +24 -0
  55. data/app/views/spud/admin/snippets/new.html.erb +7 -0
  56. data/app/views/spud/admin/templates/_form.html.erb +43 -0
  57. data/app/views/spud/admin/templates/edit.html.erb +9 -0
  58. data/app/views/spud/admin/templates/index.html.erb +17 -0
  59. data/app/views/spud/admin/templates/new.html.erb +11 -0
  60. data/app/views/spud/cms/sitemaps/show.xml.builder +16 -0
  61. data/config/boot.rb +6 -0
  62. data/config/routes.rb +29 -0
  63. data/db/migrate/20120101192412_create_spud_pages.rb +19 -0
  64. data/db/migrate/20120101193138_create_spud_menus.rb +10 -0
  65. data/db/migrate/20120101193255_create_spud_menu_items.rb +17 -0
  66. data/db/migrate/20120101194124_create_spud_templates.rb +11 -0
  67. data/db/migrate/20120103034659_create_spud_page_partials.rb +13 -0
  68. data/db/migrate/20120104194032_add_visibility_to_spud_pages.rb +6 -0
  69. data/db/migrate/20120107181337_add_menu_name_to_spud_menu_items.rb +5 -0
  70. data/db/migrate/20120111134754_add_use_custom_url_name_to_spud_pages.rb +5 -0
  71. data/db/migrate/20120118141852_add_notes_to_spud_pages.rb +5 -0
  72. data/db/migrate/20120126232428_add_menu_id_to_spud_menu_items.rb +7 -0
  73. data/db/migrate/20120128163601_add_classes_to_spud_menu_items.rb +6 -0
  74. data/db/migrate/20120329132314_add_site_id_to_spud_pages.rb +6 -0
  75. data/db/migrate/20120329132322_add_site_id_to_spud_templates.rb +6 -0
  76. data/db/migrate/20120329132330_add_site_id_to_spud_menus.rb +6 -0
  77. data/db/migrate/20120510195151_create_spud_page_partial_revisions.rb +13 -0
  78. data/db/migrate/20120911190030_add_symbol_name_to_spud_page_partials.rb +5 -0
  79. data/db/migrate/20120912121313_modify_site_id_for_spud_pages.rb +15 -0
  80. data/db/migrate/20121016233715_add_content_processed_to_spud_page_partials.rb +5 -0
  81. data/db/migrate/20121112151110_add_layout_to_spud_pages.rb +8 -0
  82. data/db/migrate/20121112212113_create_spud_page_liquid_tags.rb +11 -0
  83. data/db/migrate/20121119025608_create_spud_snippets.rb +17 -0
  84. data/db/migrate/20121119030136_change_liquid_tags_to_polymorphic.rb +17 -0
  85. data/lib/generators/spud/cms/template_generator.rb +17 -0
  86. data/lib/generators/spud/cms/templates/template.html.erb +28 -0
  87. data/lib/spud_cms/configuration.rb +27 -0
  88. data/lib/spud_cms/engine.rb +69 -0
  89. data/lib/spud_cms/liquid_snippet.rb +29 -0
  90. data/lib/spud_cms/page_route.rb +5 -0
  91. data/lib/spud_cms/template_parser.rb +126 -0
  92. data/lib/spud_cms/test_files.rb +25 -0
  93. data/lib/spud_cms/version.rb +5 -0
  94. data/lib/spud_cms.rb +10 -0
  95. data/lib/tasks/spud_cms_tasks.rake +4 -0
  96. data/spec/controllers/pages_controller_spec.rb +108 -0
  97. data/spec/controllers/spud/admin/cms_controller_spec.rb +11 -0
  98. data/spec/controllers/spud/admin/menu_items_controller_spec.rb +148 -0
  99. data/spec/controllers/spud/admin/menus_controller_spec.rb +121 -0
  100. data/spec/controllers/spud/admin/pages_controller_spec.rb +111 -0
  101. data/spec/controllers/spud/admin/snippets_controller_spec.rb +5 -0
  102. data/spec/controllers/spud/cms/sitemaps_controller_spec.rb +48 -0
  103. data/spec/dummy/README.rdoc +261 -0
  104. data/spec/dummy/Rakefile +7 -0
  105. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  106. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  107. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  108. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  109. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  110. data/spec/dummy/app/views/layouts/content_left.html.erb +0 -0
  111. data/spec/dummy/config/application.rb +59 -0
  112. data/spec/dummy/config/boot.rb +10 -0
  113. data/spec/dummy/config/database.yml +15 -0
  114. data/spec/dummy/config/environment.rb +5 -0
  115. data/spec/dummy/config/environments/development.rb +37 -0
  116. data/spec/dummy/config/environments/production.rb +67 -0
  117. data/spec/dummy/config/environments/test.rb +37 -0
  118. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  119. data/spec/dummy/config/initializers/inflections.rb +15 -0
  120. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  121. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  122. data/spec/dummy/config/initializers/session_store.rb +8 -0
  123. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  124. data/spec/dummy/config/locales/en.yml +5 -0
  125. data/spec/dummy/config/routes.rb +3 -0
  126. data/spec/dummy/config.ru +4 -0
  127. data/spec/dummy/db/migrate/20120307002859_create_spud_admin_permissions.spud_core.rb +12 -0
  128. data/spec/dummy/db/migrate/20120307002860_create_spud_users.spud_core.rb +30 -0
  129. data/spec/dummy/db/migrate/20120307003559_create_spud_permalinks.spud_permalinks.rb +12 -0
  130. data/spec/dummy/db/migrate/20120610123555_add_time_zone_to_spud_user.spud_core.rb +7 -0
  131. data/spec/dummy/db/migrate/20120610123556_add_scope_to_spud_admin_permissions.spud_core.rb +7 -0
  132. data/spec/dummy/db/migrate/20120610123557_create_spud_user_settings.spud_core.rb +12 -0
  133. data/spec/dummy/db/migrate/20120610123615_add_site_id_to_spud_permalinks.spud_permalinks.rb +7 -0
  134. data/spec/dummy/db/schema.rb +171 -0
  135. data/spec/dummy/log/test.log +1874 -0
  136. data/spec/dummy/public/404.html +26 -0
  137. data/spec/dummy/public/422.html +26 -0
  138. data/spec/dummy/public/500.html +25 -0
  139. data/spec/dummy/public/favicon.ico +0 -0
  140. data/spec/dummy/script/rails +6 -0
  141. data/spec/helpers/spud/cms/application_helper_spec.rb +160 -0
  142. data/spec/models/spud_menu_item_spec.rb +31 -0
  143. data/spec/models/spud_page_liquid_tag_spec.rb +5 -0
  144. data/spec/models/spud_page_partial_revision_spec.rb +5 -0
  145. data/spec/models/spud_page_partial_spec.rb +44 -0
  146. data/spec/models/spud_page_spec.rb +163 -0
  147. data/spec/models/spud_snippet_spec.rb +5 -0
  148. data/spec/spec_helper.rb +40 -0
  149. data/spec/support/authlogic_helper.rb +2 -0
  150. metadata +427 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,160 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spud::Cms::ApplicationHelper do
4
+ before(:each) do
5
+ ActiveRecord::Base.observers.disable(:page_sweeper)
6
+
7
+
8
+ Spud::Core.configure do |config|
9
+ config.site_name = "Test Site"
10
+ config.multisite_mode_enabled = false
11
+ config.multisite_config = []
12
+ end
13
+ end
14
+
15
+ describe :sp_list_menu do
16
+ it "should be able to find a menu by its name" do
17
+ menu = FactoryGirl.create(:spud_menu,:name => "Main")
18
+ 2.times {|x| s = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")}
19
+
20
+ helper.sp_list_menu(:name => "Main",:active_class => "active").should match /\<li/
21
+ end
22
+
23
+ it "should assign id to ul block" do
24
+ menu = FactoryGirl.create(:spud_menu)
25
+ 2.times {|x| s = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")}
26
+
27
+ helper.sp_list_menu(:name => menu.name,:id => "nav").should match /id=\'nav\'/
28
+ end
29
+
30
+ it "should render nested menu items" do
31
+ menu = FactoryGirl.create(:spud_menu,:name => "Main2")
32
+ s = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
33
+ s2 = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
34
+ s3 = FactoryGirl.create(:spud_menu_item,:parent_type => "SpudMenuItem",:parent_id => s.id,:spud_menu_id => menu.id,:url => "/",:name => "SubItem")
35
+
36
+ helper.sp_list_menu(:name => "Main2").should match /SubItem/
37
+ end
38
+
39
+ it "should respect max depth" do
40
+ menu = FactoryGirl.create(:spud_menu,:name => "Main4")
41
+ s = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
42
+ s2 = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
43
+ s3 = FactoryGirl.create(:spud_menu_item,:parent_type => "SpudMenuItem",:parent_id => s.id,:spud_menu_id => menu.id,:url => "/",:name => "SubItem")
44
+
45
+ helper.sp_list_menu(:name => "Main4",:max_depth => 1).should_not match /SubItem/
46
+ end
47
+
48
+ it "should not load menu from different site_id" do
49
+ Spud::Core.configure do |config|
50
+ config.site_name = "Test Site"
51
+ config.multisite_mode_enabled = true
52
+ config.multisite_config = [{:hosts => ["test.host"], :site_name =>"Site B", :site_id => 1}]
53
+ end
54
+ menu = FactoryGirl.create(:spud_menu,:site_id => 0)
55
+ s = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
56
+
57
+ helper.sp_list_menu(:name => menu.name).should be_blank
58
+
59
+ end
60
+ end
61
+
62
+ describe :sp_menu_with_seperator do
63
+ it "should render a flattened list of links" do
64
+ menu = FactoryGirl.create(:spud_menu,:name => "Main3")
65
+ s = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
66
+ s2 = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
67
+ s3 = FactoryGirl.create(:spud_menu_item,:parent_type => "SpudMenuItem",:parent_id => s.id,:spud_menu_id => menu.id,:url => "/",:name => "SubItem")
68
+
69
+ content = helper.sp_menu_with_seperator(:name => "Main3")
70
+ content.should match /SubItem/
71
+ content.should_not match /\<li/
72
+ end
73
+
74
+ it "should not load menu from different site_id" do
75
+
76
+ Spud::Core.configure do |config|
77
+ config.site_name = "Test Site"
78
+ config.multisite_mode_enabled = true
79
+ config.multisite_config = [{:hosts => ["test.host"], :site_name =>"Site B", :site_id => 1}]
80
+ end
81
+ menu = FactoryGirl.create(:spud_menu,:site_id => 0)
82
+ s = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
83
+ helper.sp_menu_with_seperator(:name => menu.name).should be_blank
84
+
85
+ end
86
+
87
+
88
+ end
89
+
90
+ describe :sp_list_pages do
91
+ it "should be able to list created pages" do
92
+ page = FactoryGirl.create(:spud_page)
93
+ page2 = FactoryGirl.create(:spud_page)
94
+ page3 = FactoryGirl.create(:spud_page,:spud_page_id => page.id)
95
+
96
+
97
+ content = helper.sp_list_pages(:active_class => "active")
98
+ content.should match /#{page.name}/
99
+ content.should match /#{page2.name}/
100
+ content.should match /#{page3.name}/
101
+ end
102
+
103
+ it "should assign id" do
104
+ page = FactoryGirl.create(:spud_page)
105
+ page2 = FactoryGirl.create(:spud_page)
106
+
107
+ content = helper.sp_list_pages(:id => "page_nav")
108
+ content.should match /id=\'page_nav\'/
109
+
110
+ end
111
+
112
+ it "should be able to exclude certain pages" do
113
+ page = FactoryGirl.create(:spud_page)
114
+ page2 = FactoryGirl.create(:spud_page)
115
+
116
+ content = helper.sp_list_pages(:exclude => [page2.name])
117
+ content.should match /#{page.name}/
118
+ content.should_not match /#{page2.name}/
119
+ end
120
+ it "should respect max depth" do
121
+ page = FactoryGirl.create(:spud_page)
122
+ page2 = FactoryGirl.create(:spud_page)
123
+ page3 = FactoryGirl.create(:spud_page,:spud_page_id => page.id)
124
+
125
+
126
+ content = helper.sp_list_pages(:max_depth => 1)
127
+ content.should match /#{page.name}/
128
+ content.should match /#{page2.name}/
129
+ content.should_not match /#{page3.name}/
130
+ end
131
+
132
+
133
+ it "should be able to list sub pages of a particular page" do
134
+ page = FactoryGirl.create(:spud_page)
135
+ page2 = FactoryGirl.create(:spud_page)
136
+ page3 = FactoryGirl.create(:spud_page,:spud_page_id => page.id)
137
+ content = helper.sp_list_pages(:start_page_id => page.id)
138
+ content.should_not match /#{page.name}/
139
+ content.should_not match /#{page2.name}/
140
+ content.should match /#{page3.name}/
141
+ end
142
+
143
+ it "should not load pages from different site_id" do
144
+ Spud::Core.configure do |config|
145
+ config.site_name = "Test Site"
146
+ config.multisite_mode_enabled = true
147
+ config.multisite_config = [{:hosts => ["test.host"], :site_name =>"Site B", :site_id => 1}]
148
+ end
149
+ page = FactoryGirl.create(:spud_page,:site_id => 0)
150
+ page2 = FactoryGirl.create(:spud_page,:site_id => 1)
151
+
152
+ content = helper.sp_list_pages()
153
+ content.should_not match /#{page.name}/
154
+ content.should match /#{page2.name}/
155
+
156
+ end
157
+
158
+
159
+ end
160
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpudMenuItem do
4
+
5
+ it {should have_many(:spud_menu_items)}
6
+ it {should belong_to(:spud_page)}
7
+ it {should belong_to(:spud_menu)}
8
+ it {should belong_to(:parent)}
9
+
10
+ describe :validations do
11
+ it "should require a name" do
12
+ p = FactoryGirl.build(:spud_menu_item,:name => nil)
13
+ p.should_not be_valid
14
+ end
15
+
16
+ it "should require a menu_id" do
17
+ p = FactoryGirl.build(:spud_menu_item,:spud_menu_id => nil)
18
+ p.should_not be_valid
19
+ end
20
+
21
+ it "should require a parent_type" do
22
+ p = FactoryGirl.build(:spud_menu_item,:parent_type => nil)
23
+ p.should_not be_valid
24
+ end
25
+
26
+ it "should require a parent_id" do
27
+ p = FactoryGirl.build(:spud_menu_item,:parent_id => nil)
28
+ p.should_not be_valid
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpudPageLiquidTag do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpudPagePartialRevision do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpudPagePartial do
4
+ describe "validations" do
5
+
6
+ it "should require a name" do
7
+ p = FactoryGirl.build(:spud_page_partial,:name => nil)
8
+ p.should_not be_valid
9
+ end
10
+
11
+ it "should respond with a symbol_name based on name" do
12
+ p = FactoryGirl.build(:spud_page_partial,:name => "Test Page")
13
+ p.symbol_name.should == "test_page"
14
+ end
15
+ end
16
+
17
+ describe "save hooks" do
18
+ it "should save the symbol name" do
19
+ p = Factory.create(:spud_page_partial,:name => "Test Page")
20
+ p.attributes["symbol_name"].should == "test_page"
21
+ end
22
+
23
+ it "should create a new revision if content is changed" do
24
+ p = Factory.create(:spud_page_partial,:name => "Test Page",:content =>"Home Sweet Home",:spud_page_id => 1)
25
+ SpudPagePartialRevision.where(:spud_page_id => 1,:name => "Test Page").count.should == 1
26
+ end
27
+
28
+ it "should delete old revisions beyond max_revision count" do
29
+ Spud::Cms.configure do |config|
30
+ config.max_revisions = 2
31
+ end
32
+ p = Factory.create(:spud_page_partial,:name => "Test Page",:content =>"Home Sweet Home",:spud_page_id => 1)
33
+ p.content = "Nah"
34
+ p.save
35
+
36
+ p.content = "Another change"
37
+ p.save
38
+ SpudPagePartialRevision.where(:spud_page_id => 1,:name => "Test Page").count.should == 2
39
+ end
40
+
41
+ end
42
+
43
+
44
+ end
@@ -0,0 +1,163 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpudPage do
4
+
5
+ it {should have_many(:spud_page_partials)}
6
+ it {should have_many(:spud_pages)}
7
+ it {should belong_to(:spud_page)}
8
+ it {should belong_to(:created_by_user)}
9
+ it {should belong_to(:updated_by_user)}
10
+
11
+ describe "validations" do
12
+
13
+ it "should require a name" do
14
+ p = FactoryGirl.build(:spud_page,:name => nil)
15
+ p.should_not be_valid
16
+ end
17
+
18
+ it "should require a unique url_name" do
19
+ Factory(:spud_page, :url_name => "test", :use_custom_url_name => true)
20
+ t = FactoryGirl.build(:spud_page, :url_name => "test", :use_custom_url_name => true)
21
+ t.should_not be_valid
22
+ end
23
+
24
+ it "should generate a url_name if taken" do
25
+ Factory(:spud_page, :name => "test")
26
+ t = FactoryGirl.build(:spud_page, :name => "test")
27
+ lambda {
28
+ t.valid?
29
+ }.should change(t, :url_name)
30
+ end
31
+
32
+ it "should dependantly destroy page_partials" do
33
+ t = Factory(:spud_page, :spud_page_partials => [SpudPagePartial.new(:name => "body")])
34
+ lambda {
35
+ t.destroy
36
+ }.should change(SpudPagePartial, :count).from(1).to(0)
37
+ end
38
+
39
+
40
+ end
41
+
42
+ describe "scopes" do
43
+
44
+ it "should only show published pages" do
45
+ SpudPage.published_pages.to_sql.should == SpudPage.where(:published => true).to_sql
46
+ end
47
+
48
+ it "should only show parent pages" do
49
+ SpudPage.parent_pages.to_sql.should == SpudPage.where(:spud_page_id => nil).to_sql
50
+ end
51
+
52
+ it "should only show public pages" do
53
+ SpudPage.public.to_sql.should == SpudPage.where(:visibility => 0).to_sql
54
+ end
55
+
56
+ it "should group pages by parent" do
57
+ parent_page = FactoryGirl.build(:spud_page,:name => "parent")
58
+ parent_page.save
59
+
60
+ page = FactoryGirl.build(:spud_page,:name => "Page 1")
61
+ page.spud_page = parent_page
62
+ page.save
63
+ page2 = FactoryGirl.build(:spud_page,:name => "Page 2")
64
+ page2.spud_page = parent_page
65
+ page2.save
66
+
67
+ SpudPage.grouped()[parent_page.id].count.should == 2
68
+
69
+
70
+ end
71
+
72
+ it "should return private if visibility is == 1" do
73
+ parent_page = FactoryGirl.build(:spud_page,:name => "parent",:visibility => 1)
74
+
75
+ parent_page.is_private?.should == true
76
+
77
+ parent_page.visibility = 0
78
+ parent_page.is_private?.should == false
79
+ end
80
+
81
+
82
+ end
83
+
84
+ describe "generate_url_name" do
85
+ it "should add the parent url name if a page has a parent" do
86
+ # Factory(:spud_page, :name => "test")
87
+ parent_page = FactoryGirl.build(:spud_page,:name => "about")
88
+ parent_page.save
89
+ t = FactoryGirl.build(:spud_page, :name => "test")
90
+ t.spud_page = parent_page
91
+ t.valid?
92
+
93
+ t.url_name.should == 'about/test'
94
+
95
+ end
96
+
97
+ it "should add a counter to url_name if the url_name is already in use" do
98
+ page = FactoryGirl.build(:spud_page,:name => "testimonials")
99
+ page.save
100
+
101
+ page2 = FactoryGirl.build(:spud_page,:name => "testimonials")
102
+ page2.valid?
103
+
104
+ page2.url_name.should == 'testimonials-1'
105
+ end
106
+
107
+ it "should add a counter to url_name if the url_name was once in use by another page that was renamed" do
108
+ page = FactoryGirl.build(:spud_page,:name => "another")
109
+ page.save
110
+ page.name = "again"
111
+ page.save
112
+
113
+ page2 = FactoryGirl.build(:spud_page,:name => "another")
114
+ page2.valid?
115
+
116
+ page2.url_name.should == 'another-1'
117
+ end
118
+
119
+ it "should destroy historical permalink if a page is renamed back to its previous name" do
120
+ page = FactoryGirl.build(:spud_page,:name => "permapage")
121
+ page.save
122
+
123
+ page.name = 'permapage new'
124
+ page.save
125
+
126
+ page.name = 'permapage'
127
+
128
+ basecount = SpudPermalink.count
129
+
130
+ lambda {
131
+ page.valid?
132
+ }.should change(page.spud_permalinks.where(:url_name => 'permapage'), :count).from(1).to(0)
133
+ end
134
+
135
+ it "should not allow a custom url to be reused by another page" do
136
+ page = FactoryGirl.build(:spud_page,:name => "original")
137
+ page.save
138
+
139
+ page = FactoryGirl.build(:spud_page,:name => "new",:use_custom_url_name => true,:url_name => "original")
140
+
141
+ page.valid?.should == false
142
+ end
143
+
144
+ it "should not allow a custom url to be reused by another page even if it is a historical permalink" do
145
+ page = FactoryGirl.build(:spud_page,:name => "original")
146
+ page.save
147
+ page.name = "original2"
148
+ page.save
149
+
150
+ page = FactoryGirl.build(:spud_page,:name => "new")
151
+ page.save
152
+ page.use_custom_url_name = true
153
+ page.url_name = 'original'
154
+ page.valid?.should == false
155
+ end
156
+
157
+
158
+ end
159
+
160
+
161
+
162
+
163
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpudSnippet do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,40 @@
1
+ # Track code coverage
2
+ require 'simplecov'
3
+ SimpleCov.start 'rails' do
4
+ # root "dummy/"
5
+ add_filter "/factories/"
6
+ end
7
+
8
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
9
+ ENV["RAILS_ENV"] = 'test'
10
+ require File.expand_path("../dummy/config/environment", __FILE__)
11
+ require 'rspec/rails'
12
+ require 'rspec/autorun'
13
+ require 'database_cleaner'
14
+ require 'shoulda'
15
+ require 'factory_girl'
16
+ require 'mocha'
17
+
18
+ # Requires supporting ruby files with custom matchers and macros, etc,
19
+ # in spec/support/ and its subdirectories.
20
+ ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
21
+ Dir[File.join(ENGINE_RAILS_ROOT,"spec/support/**/*.rb"), File.join(ENGINE_RAILS_ROOT,"factories/*")].each {|f| require f}
22
+
23
+ RSpec.configure do |config|
24
+ config.mock_with :mocha
25
+ config.use_transactional_fixtures = true
26
+ config.infer_base_class_for_anonymous_controllers = false
27
+
28
+ config.before(:suite) do
29
+ DatabaseCleaner.strategy = :transaction
30
+ DatabaseCleaner.clean_with(:truncation)
31
+ end
32
+
33
+ config.before(:each) do
34
+ DatabaseCleaner.start
35
+ end
36
+
37
+ config.after(:each) do
38
+ DatabaseCleaner.clean
39
+ end
40
+ end
@@ -0,0 +1,2 @@
1
+ require 'authlogic/test_case'
2
+ include Authlogic::TestCase