tb_cms 0.9.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,69 @@
1
+ require 'spud_core'
2
+ require 'spud_permalinks'
3
+ require 'codemirror-rails'
4
+ require 'liquid'
5
+
6
+ module Spud
7
+ module Cms
8
+ class Engine < Rails::Engine
9
+ engine_name :spud_cms
10
+
11
+ config.generators do |g|
12
+ g.test_framework :rspec, :view_specs => false
13
+ end
14
+
15
+ initializer :admin do
16
+ Spud::Core.configure do |config|
17
+ config.admin_applications += [{:name => "Pages",:thumbnail => "spud/admin/pages_thumb.png",:url => "/spud/admin/pages",:order => 0}]
18
+ if Spud::Cms.menus_enabled
19
+ config.admin_applications += [{:name => "Menus",:thumbnail => "spud/admin/menus_thumb.png",:url => "/spud/admin/menus",:order => 2}]
20
+ end
21
+
22
+ if Spud::Cms.snippets_enabled
23
+ config.admin_applications += [{:name => "Snippets",:thumbnail => "spud/admin/snippets_thumb.png",:url => "/spud/admin/snippets",:order => 3}]
24
+ end
25
+
26
+ if Spud::Cms.enable_sitemap == true
27
+ config.sitemap_urls += [:spud_cms_sitemap_url]
28
+ end
29
+ end
30
+ end
31
+
32
+ initializer :model_overrides_cms do |config|
33
+ ActiveRecord::Base.class_eval do
34
+ include Spud::Searchable
35
+ end
36
+ end
37
+ initializer :cms_sweepers do |config|
38
+ if ActiveRecord::Base.connection.tables.include?('spud_pages')
39
+ Spud::Admin::ApplicationController.instance_eval do
40
+ cache_sweeper :page_sweeper, :except => [:show,:index]
41
+ end
42
+ end
43
+ end
44
+
45
+ initializer :spud_cms_routes do |config|
46
+ config.routes_reloader.paths << File.expand_path('../page_route.rb', __FILE__)
47
+ end
48
+
49
+ initializer :assets do |config|
50
+ Rails.application.config.assets.precompile += ["spud/admin/cms*"]
51
+ Spud::Core.append_admin_javascripts('spud/admin/cms/application')
52
+ Spud::Core.append_admin_stylesheets('spud/admin/cms/application')
53
+ end
54
+
55
+ initializer :liquid do |config|
56
+ Liquid::Template.register_tag('snippet', Spud::Cms::LiquidSnippet)
57
+ end
58
+
59
+ initializer :template_parser do |config|
60
+ @template_parser = Spud::Cms::TemplateParser.new()
61
+ end
62
+
63
+ def template_parser
64
+ return @template_parser
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,29 @@
1
+ require 'liquid'
2
+ module Spud
3
+ module Cms
4
+ class LiquidSnippet < Liquid::Tag
5
+ def initialize(tag_name, snippet_name, tokens)
6
+ @snippet_name = snippet_name
7
+ @snippet = SpudSnippet.where(:name => snippet_name).first
8
+
9
+ end
10
+
11
+ def tag_name
12
+ return "snippet"
13
+ end
14
+ def tag_value
15
+ return @snippet_name
16
+ end
17
+
18
+ def render(context)
19
+
20
+ if !@snippet.blank?
21
+ return @snippet.content_processed.html_safe
22
+ else
23
+ return ''
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.append do
2
+ # constraints :path => /(?!assets)/ do
3
+ match "*id", :controller => "pages",:action => "show", :as => "page"
4
+ # end
5
+ end
@@ -0,0 +1,126 @@
1
+ module Spud
2
+ module Cms
3
+ class TemplateParser
4
+
5
+
6
+ def layouts(site_short_name=nil)
7
+ if(site_short_name != nil)
8
+ filtered_layouts = {}
9
+ all_layouts.each do |key,value|
10
+ if value[:sites].include?(site_short_name.to_s.downcase)
11
+ filtered_layouts[key] = value
12
+ end
13
+ end
14
+ return filtered_layouts
15
+ else
16
+ return all_layouts
17
+ end
18
+ end
19
+
20
+ def all_layouts
21
+ if @layouts && Rails.env != 'development'
22
+ return @layouts
23
+ end
24
+ @layouts = {}
25
+ engines.each do |engine|
26
+ @layouts.merge! process_layouts(engine.root.join('app','views','layouts'))
27
+ end
28
+ @layouts.merge! process_layouts(Rails.application.root.join('app','views','layouts'))
29
+
30
+ check_for_defaults(@layouts)
31
+
32
+ return @layouts
33
+ end
34
+
35
+
36
+ private
37
+ def process_layouts(filepath)
38
+ layouts = {}
39
+ Dir.glob(filepath.join("**","*.html.*")) do |template|
40
+
41
+ layout = process_layout(template)
42
+ layouts[layout_path(template)] = layout if !layout.blank?
43
+
44
+ end
45
+ return layouts
46
+ end
47
+
48
+ def process_layout(template)
49
+ f = File.open(template)
50
+ header = []
51
+ f.each_line do |line|
52
+ header << line
53
+ break if line.blank?
54
+ end
55
+ f.close
56
+ # puts header
57
+ if header.blank? == false
58
+ layout = {:partials => []}
59
+
60
+ header.each do |header_line|
61
+ process_directive(header_line, layout)
62
+ end
63
+ layout[:partials] = ["Body"] if layout[:partials].blank?
64
+ layout[:sites] = [Spud::Core.config.short_name.downcase] if layout[:sites].blank?
65
+ if layout[:template_name].blank? == false
66
+ return layout
67
+ else
68
+ return nil
69
+ end
70
+ end
71
+ return nil
72
+ end
73
+
74
+ def check_for_defaults(layouts)
75
+ default_layout_path = layout_path(Rails.application.root.join('app','views','layouts',Spud::Cms.default_page_layout))
76
+ puts(layouts)
77
+ if layouts[default_layout_path].blank?
78
+ layouts[default_layout_path] = {:template_name => "Default", :partials => ["Body"], :sites => [Spud::Core.short_name.downcase], :default => true}
79
+ else
80
+ layouts[default_layout_path][:default] = true
81
+ end
82
+
83
+ Spud::Core.multisite_config.each do |config|
84
+ cms_config = Spud::Cms.site_config_for_short_name(config[:short_name])
85
+ layout_path = cms_config.blank? == false && cms_config[:default_page_layout].blank? == false ? layout_path(Rails.application.root.join('app','views','layouts',cms_config[:default_page_layout])) : default_layout_path
86
+
87
+ layout = layouts[layout_path]
88
+ if layout.blank?
89
+ layouts[layout_path] = {:template_name => "Default", :partials => ["Body"], :sites => [config[:short_name].to_s.downcase], :default => true}
90
+ else
91
+ layouts[layout_path][:sites] << config[:short_name].to_s.downcase
92
+ layouts[layout_path][:default] = true
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ def layout_path(template)
99
+ dir, base = File.split(template)
100
+ path_components = dir.split("/")
101
+ component = path_components.shift
102
+ while component != "layouts" do
103
+ component = path_components.shift
104
+ end
105
+ path_components << base.downcase.split(".")[0]
106
+ return "#{path_components.join("/")}"
107
+ end
108
+
109
+ def process_directive(line,layout)
110
+ if template_matcher = line.match(/\-?\#template\_name\:(.*)/)
111
+ layout[:template_name] = template_matcher[1].strip
112
+ end
113
+ if template_matcher = line.match(/\-?\#html\:(.*)/)
114
+ layout[:partials] << template_matcher[1].strip
115
+ end
116
+ if template_matcher = line.match(/\-?\#site_name\:(.*)/)
117
+ layout[:sites] = template_matcher[1].split(",").collect {|s| s.strip.downcase}
118
+ end
119
+ end
120
+
121
+ def engines
122
+ Rails::Application::Railties.engines
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,25 @@
1
+ module Spud
2
+ module Cms
3
+ module TestFiles
4
+ class << self
5
+ def load_all
6
+ load_specs
7
+ load_factories
8
+ load_support
9
+ end
10
+
11
+ def load_specs
12
+ Dir[File.join(File.expand_path('../../../', __FILE__), "spec/**/*_spec.rb")].each {|f| require f}
13
+ end
14
+
15
+ def load_factories
16
+ Dir[File.join(File.expand_path('../../../', __FILE__), "factories/*")].each {|f| require f}
17
+ end
18
+
19
+ def load_support
20
+ Dir[File.join(File.expand_path('../../../', __FILE__), "spec/support/**/*.rb")].each {|f| require f}
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module Spud
2
+ module Cms
3
+ VERSION = "0.9.18"
4
+ end
5
+ end
data/lib/spud_cms.rb ADDED
@@ -0,0 +1,10 @@
1
+
2
+ module Spud
3
+ module Cms
4
+ require 'spud_cms/configuration'
5
+ require 'spud_cms/template_parser'
6
+ require 'spud_cms/liquid_snippet'
7
+ require 'spud_cms/engine' if defined?(Rails)
8
+ end
9
+ end
10
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :spud_cms do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagesController do
4
+ describe :show do
5
+ before(:each) do
6
+ Spud::Core.configure do |config|
7
+ config.site_name = "Test Site"
8
+ config.multisite_mode_enabled = false
9
+ config.multisite_config = []
10
+ end
11
+ Spud::Cms.configure do |config|
12
+ config.cache_mode = false
13
+ end
14
+ end
15
+ it "should render a page" do
16
+ page = FactoryGirl.create(:spud_page)
17
+ get :show ,:id => page.url_name
18
+ assigns(:layout).should render_template(:layout => "layouts/#{Spud::Cms.default_page_layout}")
19
+ response.should be_success
20
+ end
21
+
22
+ it "should render home page if id is blank" do
23
+ page = FactoryGirl.create(:spud_page,:name => "home")
24
+ get :show
25
+ assigns(:page).should == page
26
+ response.should be_success
27
+ end
28
+
29
+ it "should redirect to new page url from old page url if it was changed" do
30
+ page = FactoryGirl.create(:spud_page,:name => "about")
31
+ page.name = "about us"
32
+ page.save
33
+
34
+ get :show, :id => "about"
35
+
36
+ response.should redirect_to page_url(:id => "about-us")
37
+
38
+ end
39
+
40
+
41
+
42
+ it "should not allow access to private pages when logged out" do
43
+ page = FactoryGirl.create(:spud_page,:name => "about",:visibility => 1)
44
+
45
+ get :show, :id => "about"
46
+ response.should redirect_to new_spud_user_session_url()
47
+ end
48
+
49
+ describe "page caching" do
50
+ before(:each) do
51
+ Spud::Cms.configure do |config|
52
+ config.cache_mode = nil
53
+ end
54
+ end
55
+
56
+
57
+ end
58
+
59
+ describe "authorized login" do
60
+ before(:each) do
61
+ activate_authlogic
62
+ u = SpudUser.new(:login => "testuser",:email => "test@testuser.com",:password => "test",:password_confirmation => "test")
63
+ u.super_admin = true
64
+ u.save
65
+ @user = SpudUserSession.create(u)
66
+ end
67
+
68
+ it "should allow access to private pages when logged in" do
69
+ page = FactoryGirl.create(:spud_page,:name => "about",:visibility => 1)
70
+
71
+ get :show, :id => "about"
72
+ response.should be_success
73
+ end
74
+ end
75
+
76
+ describe "multisite enabled" do
77
+ before(:each) do
78
+ Spud::Core.configure do |config|
79
+ config.site_name = "Test Site"
80
+ config.multisite_mode_enabled = true
81
+ config.multisite_config = [{:hosts => ["test.host"], :site_name =>"Site B", :site_id => 1}]
82
+ end
83
+ end
84
+
85
+ it "should not show a page on a different site" do
86
+ page = FactoryGirl.create(:spud_page,:name => "about",:site_id => 0)
87
+ get :show,:id=>"about"
88
+ response.response_code.should == 404
89
+ end
90
+
91
+ it "should show the right page" do
92
+ page = FactoryGirl.create(:spud_page,:name => "about",:site_id => 0)
93
+ page2 = FactoryGirl.create(:spud_page,:name => "about",:site_id => 1)
94
+ get :show,:id=>"about"
95
+ assigns(:page).should == page2
96
+ end
97
+
98
+ it "should return the homepage of the current site" do
99
+ page = FactoryGirl.create(:spud_page,:name => "home",:site_id => 0)
100
+ page_site1 = FactoryGirl.create(:spud_page,:name => "home",:site_id => 1)
101
+
102
+ get :show
103
+ assigns(:page).should == page_site1
104
+ end
105
+
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spud::Admin::CmsController do
4
+ it "should return site_config by short_name" do
5
+ Spud::Cms.configure do |config|
6
+ config.multisite_config = [{:short_name => "siteb",:site_name => "Test Site B",:site_id => 2}]
7
+ end
8
+
9
+ Spud::Cms.site_config_for_short_name(:siteb)[:site_id].should == 2
10
+ end
11
+ end
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spud::Admin::MenuItemsController do
4
+ before(:each) do
5
+ ActiveRecord::Base.observers.disable(:page_sweeper)
6
+
7
+ activate_authlogic
8
+ u = SpudUser.new(:login => "testuser",:email => "test@testuser.com",:password => "test",:password_confirmation => "test")
9
+ u.super_admin = true
10
+ u.save
11
+ @user = SpudUserSession.create(u)
12
+ Spud::Core.configure do |config|
13
+ config.site_name = "Test Site"
14
+ config.multisite_mode_enabled = false
15
+ config.multisite_config = []
16
+ end
17
+
18
+ @menu = FactoryGirl.create(:spud_menu)
19
+ end
20
+
21
+
22
+ describe :index do
23
+ it "should return an array of menus" do
24
+ 2.times {|x| s = FactoryGirl.create(:spud_menu_item,:spud_menu_id => @menu.id,:parent_id => @menu.id)}
25
+ get :index,:menu_id =>@menu.id
26
+
27
+ assigns(:menu_items).count.should be > 1
28
+ end
29
+ it "should redirect if the menu is not found" do
30
+ get :index,:menu_id => @menu.id + 1
31
+ response.should redirect_to spud_admin_menus_url
32
+ flash[:error].should_not be_blank
33
+ end
34
+ end
35
+
36
+ describe :new do
37
+ it "should assign a new menu" do
38
+ get :new,:menu_id =>@menu.id
39
+ assigns(:menu_item).should_not be_blank
40
+ response.should be_success
41
+ end
42
+ end
43
+
44
+ describe :create do
45
+ it "should create a new menu item with a valid form submission" do
46
+ lambda {
47
+ post :create,:menu_id => @menu.id, :spud_menu_item => FactoryGirl.attributes_for(:spud_menu_item,:parent_id => nil).reject{|k,v| k == 'id' || k == :spud_menu_id}
48
+ }.should change(SpudMenuItem,:count).by(1)
49
+ response.should be_redirect
50
+ end
51
+
52
+ it "should not create a menu item with an invalid form entry" do
53
+ yamldata = FactoryGirl.attributes_for(:spud_menu_item,:name => nil).reject{|k,v| k == 'id' || k == :spud_menu_id}
54
+
55
+ lambda {
56
+ post :create,:menu_id => @menu.id, :spud_menu_item => FactoryGirl.attributes_for(:spud_menu_item,:name => nil,:parent_id => nil).reject{|k,v| k == 'id' || k == :spud_menu_id}
57
+ }.should_not change(SpudMenuItem,:count)
58
+ end
59
+
60
+ it "should autoset order if not specified" do
61
+ menuitem = FactoryGirl.create(:spud_menu_item,:parent_id => @menu.id)
62
+
63
+ post :create,:menu_id => @menu.id, :spud_menu_item => FactoryGirl.attributes_for(:spud_menu_item,:menu_order => nil,:parent_id => nil).reject{|k,v| k == 'id' || k == :spud_menu_id}
64
+ assigns(:menu_item).menu_order.should == 1
65
+ end
66
+
67
+ it "should assign the menu name based on page name if left blank" do
68
+ page = FactoryGirl.create(:spud_page)
69
+ post :create,:menu_id => @menu.id, :spud_menu_item => FactoryGirl.attributes_for(:spud_menu_item,:name => nil,:spud_page_id => page.id).reject{|k,v| k == 'id' || k == :spud_menu_id}
70
+ assigns(:menu_item).name.should == page.name
71
+ end
72
+
73
+ it "should set the parent to a submenu if specified" do
74
+ menuitem = FactoryGirl.create(:spud_menu_item,:parent_id => @menu.id)
75
+ post :create,:menu_id => @menu.id, :spud_menu_item => FactoryGirl.attributes_for(:spud_menu_item,:parent_id => menuitem.id).reject{|k,v| k == 'id' || k == :spud_menu_id}
76
+ assigns(:menu_item).parent.should == menuitem
77
+ end
78
+ end
79
+
80
+ describe :edit do
81
+ it "should respond with menu item by id" do
82
+ menu1 = FactoryGirl.create(:spud_menu_item)
83
+ menu2 = FactoryGirl.create(:spud_menu_item)
84
+ get :edit, :menu_id => @menu.id,:id => menu2.id
85
+ assigns(:menu_item).should == menu2
86
+ end
87
+
88
+ it "should redirect_to index if menu item not found" do
89
+ get :edit,:menu_id => @menu.id,:id => "345"
90
+ response.should redirect_to spud_admin_menu_menu_items_url(:menu_id => @menu.id)
91
+ end
92
+ end
93
+
94
+ describe :update do
95
+ it "should update the name when the name attribute is changed" do
96
+ menu_item = FactoryGirl.create(:spud_menu_item)
97
+ new_name = 'MyMenu'
98
+ lambda {
99
+ put :update,:menu_id => @menu.id,:id => menu_item.id, :spud_menu_item => menu_item.attributes.merge!(:name => new_name,:parent_id => nil).reject{|k,v| k.to_sym == :spud_menu_id || k == 'id' || k.to_sym == :updated_at || k.to_sym == :created_at}
100
+ menu_item.reload
101
+ }.should change(menu_item,:name).to(new_name)
102
+ end
103
+ it "should assign a menu to a submenu if parentid is defined" do
104
+ menu_item1 = FactoryGirl.create(:spud_menu_item)
105
+ menu_item = FactoryGirl.create(:spud_menu_item)
106
+
107
+ lambda {
108
+ put :update,:menu_id => @menu.id,:id => menu_item.id, :spud_menu_item => menu_item.attributes.merge!(:parent_id => menu_item1.id).reject{|k,v| k.to_sym == :spud_menu_id || k == 'id' || k.to_sym == :updated_at || k.to_sym == :created_at}
109
+ menu_item.reload
110
+ }.should change(menu_item,:parent).to(menu_item1)
111
+ end
112
+ end
113
+
114
+
115
+ describe :destroy do
116
+ it "should destroy the menu item" do
117
+ menu_item = FactoryGirl.create(:spud_menu_item,:parent_id => @menu.id)
118
+ lambda {
119
+ delete :destroy,:menu_id => @menu.id,:id => menu_item.id
120
+ }.should change(SpudMenuItem,:count).by(-1)
121
+ end
122
+ end
123
+
124
+ describe :multisite do
125
+ before(:each) do
126
+ Spud::Core.configure do |config|
127
+ config.site_name = "Test Site"
128
+ config.multisite_mode_enabled = true
129
+ config.multisite_config = [{:hosts => ["test.host"], :site_name =>"Site B", :site_id => 1,:short_name => "siteb"}]
130
+ end
131
+ Spud::Cms.configure do |config|
132
+ config.multisite_config = [{:short_name => "siteb",:default_page_parts => ["Body","Sidebar"]}]
133
+ end
134
+ session[:admin_site] = 1
135
+ end
136
+
137
+
138
+ describe :edit do
139
+ it "should not allow editing of a menu_item in a menu that is different from the current admin site" do
140
+ menu_item = FactoryGirl.create(:spud_menu_item)
141
+ get :edit,:id => menu_item.id,:menu_id => @menu.id
142
+ response.should redirect_to spud_admin_menus_url
143
+ flash[:warning].should_not be_blank
144
+ end
145
+ end
146
+
147
+ end
148
+ end
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spud::Admin::MenusController do
4
+ before(:each) do
5
+ activate_authlogic
6
+ u = SpudUser.new(:login => "testuser",:email => "test@testuser.com",:password => "test",:password_confirmation => "test")
7
+ u.super_admin = true
8
+ u.save
9
+ @user = SpudUserSession.create(u)
10
+ Spud::Core.configure do |config|
11
+ config.site_name = "Test Site"
12
+ config.multisite_mode_enabled = false
13
+ config.multisite_config = []
14
+ end
15
+ end
16
+
17
+
18
+ describe :index do
19
+ it "should return an array of menus" do
20
+ 2.times {|x| s = FactoryGirl.create(:spud_menu)}
21
+ get :index
22
+
23
+ assigns(:menus).count.should be > 1
24
+ end
25
+
26
+ end
27
+
28
+ describe :new do
29
+ it "should response with new menu" do
30
+ get :new
31
+ assigns(:menu).should_not be_blank
32
+ response.should be_success
33
+ end
34
+ end
35
+
36
+ describe :create do
37
+ it "should create a new menu with a valid form submission" do
38
+ lambda {
39
+ post :create, :spud_menu => FactoryGirl.attributes_for(:spud_menu).reject{|k,v| k == 'site_id' || k == 'id'}
40
+ }.should change(SpudMenu,:count).by(1)
41
+ response.should be_redirect
42
+ end
43
+
44
+ it "should not create a menu with an invalid form entry" do
45
+ lambda {
46
+ post :create, :spud_menu => FactoryGirl.attributes_for(:spud_menu,:name => nil).reject{|k,v| k == 'site_id' || k == 'id'}
47
+ }.should_not change(SpudMenu,:count)
48
+
49
+
50
+ end
51
+ end
52
+
53
+ describe :multisite do
54
+ before(:each) do
55
+ Spud::Core.configure do |config|
56
+ config.site_name = "Test Site"
57
+ config.multisite_mode_enabled = true
58
+ config.multisite_config = [{:hosts => ["test.host"], :site_name =>"Site B", :site_id => 1}]
59
+ end
60
+
61
+ end
62
+ it "should not allow editing of a menu on a different site id" do
63
+ menu2 = FactoryGirl.create(:spud_menu,:site_id => 1)
64
+ get :edit,:id => menu2.id
65
+
66
+ response.should redirect_to spud_admin_menus_url
67
+ end
68
+ end
69
+
70
+ describe :edit do
71
+ it "should response with menu by id" do
72
+ menu1 = FactoryGirl.create(:spud_menu)
73
+ menu2 = FactoryGirl.create(:spud_menu)
74
+ get :edit,:id => menu2.id
75
+ assigns(:menu).should == menu2
76
+ end
77
+ it "should redirect to index if menu not found" do
78
+ get :edit,:id => 3
79
+ response.should redirect_to spud_admin_menus_url
80
+ end
81
+
82
+ end
83
+
84
+ describe :update do
85
+ it "should update the name when the name attribute is changed" do
86
+ menu = FactoryGirl.create(:spud_menu)
87
+ new_name = 'MyMenu'
88
+ lambda {
89
+ put :update,:id => menu.id, :spud_menu => menu.attributes.merge!(:name => new_name).reject{|k,v| k == 'site_id' || k == 'id'}
90
+ menu.reload
91
+ }.should change(menu,:name).to(new_name)
92
+
93
+ end
94
+
95
+ it "should redirect to the admin menus after a successful update" do
96
+ menu = FactoryGirl.create(:spud_menu)
97
+ put :update,:id => menu.id,:spud_menu => menu.attributes.merge!(:name => "MyMenu").reject{|k,v| k == 'site_id' || k == 'id'}
98
+
99
+ response.should redirect_to(spud_admin_menu_menu_items_url(:menu_id => menu.id))
100
+ end
101
+ end
102
+
103
+ describe :destroy do
104
+ it "should destroy the menu" do
105
+ menu = FactoryGirl.create(:spud_menu)
106
+ lambda {
107
+ delete :destroy, :id => menu.id
108
+ }.should change(SpudMenu,:count).by(-1)
109
+ response.should be_redirect
110
+ end
111
+
112
+ it "should not destroy the menu with a wrong id" do
113
+ menu = FactoryGirl.create(:spud_menu)
114
+ lambda {
115
+ delete :destroy,:id => "23532"
116
+ }.should_not change(SpudMenu,:count)
117
+ response.should be_redirect
118
+ end
119
+
120
+ end
121
+ end