spud_cms 0.8.17 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/README.markdown +30 -13
  2. data/app/assets/images/spud/admin/snippets_thumb.png +0 -0
  3. data/app/assets/images/spud/admin/snippets_thumb@2x.png +0 -0
  4. data/app/assets/javascripts/spud/admin/cms/application.js +3 -3
  5. data/app/controllers/pages_controller.rb +6 -23
  6. data/app/controllers/spud/admin/menu_items_controller.rb +6 -10
  7. data/app/controllers/spud/admin/menus_controller.rb +1 -1
  8. data/app/controllers/spud/admin/pages_controller.rb +40 -86
  9. data/app/controllers/spud/cms/sitemaps_controller.rb +1 -1
  10. data/app/helpers/spud/cms/application_helper.rb +50 -26
  11. data/app/models/spud_menu_item.rb +10 -13
  12. data/app/models/spud_page.rb +12 -4
  13. data/app/models/spud_page_liquid_tag.rb +4 -0
  14. data/app/models/spud_page_partial.rb +40 -1
  15. data/app/observers/page_sweeper.rb +48 -0
  16. data/app/views/pages/show.html.erb +9 -11
  17. data/app/views/spud/admin/pages/_form.html.erb +15 -16
  18. data/app/views/spud/admin/pages/_page_partials_form.html.erb +3 -3
  19. data/app/views/spud/admin/pages/index.html.erb +1 -1
  20. data/app/views/spud/admin/pages/show.html.erb +4 -6
  21. data/config/routes.rb +3 -3
  22. data/db/migrate/20120911190030_add_symbol_name_to_spud_page_partials.rb +5 -0
  23. data/db/migrate/20120912121313_modify_site_id_for_spud_pages.rb +15 -0
  24. data/db/migrate/20121016233715_add_content_processed_to_spud_page_partials.rb +5 -0
  25. data/db/migrate/20121112151110_add_layout_to_spud_pages.rb +8 -0
  26. data/db/migrate/20121112212113_create_spud_page_liquid_tags.rb +11 -0
  27. data/lib/spud_cms.rb +1 -0
  28. data/lib/spud_cms/configuration.rb +4 -7
  29. data/lib/spud_cms/engine.rb +37 -16
  30. data/lib/spud_cms/template_parser.rb +121 -0
  31. data/lib/spud_cms/version.rb +1 -1
  32. data/spec/controllers/pages_controller_spec.rb +108 -0
  33. data/spec/controllers/spud/admin/menu_items_controller_spec.rb +148 -0
  34. data/spec/controllers/spud/admin/menus_controller_spec.rb +121 -0
  35. data/spec/controllers/spud/admin/pages_controller_spec.rb +5 -13
  36. data/spec/controllers/spud/cms/sitemaps_controller_spec.rb +35 -4
  37. data/spec/dummy/app/controllers/application_controller.rb +1 -1
  38. data/spec/dummy/db/schema.rb +146 -0
  39. data/spec/dummy/log/development.log +341 -0
  40. data/spec/dummy/log/test.log +182863 -0
  41. data/spec/helpers/spud/cms/application_helper_spec.rb +160 -0
  42. data/spec/models/spud_menu_item_spec.rb +31 -0
  43. data/spec/models/spud_page_liquid_tag_spec.rb +5 -0
  44. data/spec/models/spud_page_partial_spec.rb +44 -0
  45. data/spec/models/spud_page_spec.rb +1 -2
  46. metadata +50 -19
  47. data/app/assets/images/spud/admin/templates_thumb.png +0 -0
  48. data/app/controllers/spud/admin/templates_controller.rb +0 -73
  49. data/app/models/page_sweeper.rb +0 -63
  50. data/app/models/spud_template.rb +0 -10
  51. data/app/views/layouts/spud/admin/cms/detail.html.erb +0 -5
  52. data/spec/models/spud_template_spec.rb +0 -34
@@ -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
@@ -11,7 +11,7 @@ describe Spud::Admin::PagesController do
11
11
 
12
12
  describe :index do
13
13
  it "should return an array of parent pages" do
14
- 2.times {|x| FactoryGirl.create(:spud_page) }
14
+ 2.times {|x| s = FactoryGirl.create(:spud_page)}
15
15
  get :index
16
16
 
17
17
  assigns(:pages).count.should be > 1
@@ -34,21 +34,13 @@ describe Spud::Admin::PagesController do
34
34
  response.should be_success
35
35
  end
36
36
 
37
- it "should render custom layout if template in use" do
38
- t = FactoryGirl.build(:spud_template)
39
- t.base_layout = 'content_left'
40
- t.save
41
- p = FactoryGirl.create(:spud_page,:template_id => t.id)
42
37
 
43
- get :show ,:id => p.id
44
- assigns(:layout).should render_template(:layout => "layouts/#{t.base_layout}")
45
- end
46
38
 
47
- it "should redirect if no id specified" do
48
- get :show
39
+ # it "should redirect if no id specified" do
40
+ # get :show,:id => nil
49
41
 
50
- response.should redirect_to spud_admin_pages_url
51
- end
42
+ # response.should redirect_to spud_admin_pages_url
43
+ # end
52
44
 
53
45
  end
54
46
 
@@ -2,16 +2,47 @@ require 'spec_helper'
2
2
 
3
3
  describe Spud::Cms::SitemapsController do
4
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
+
12
+ end
5
13
  it "should return the sitemap urls" do
6
-
14
+
7
15
  get :show, :format => :xml
8
-
16
+
9
17
  assigns(:pages).should == SpudPage.published_pages.public.order(:spud_page_id)
10
18
  end
11
-
19
+
12
20
  it "should only respond to an XML format" do
13
21
  get :show
14
22
  response.response_code.should == 406
15
23
  end
24
+
25
+ describe :multisite do
26
+ before(:each) do
27
+ Spud::Core.configure do |config|
28
+ config.site_name = "Test Site"
29
+ config.multisite_mode_enabled = true
30
+ config.multisite_config = [{:hosts => ["test.host"], :site_name =>"Site B", :site_id => 1}]
31
+ end
32
+ end
33
+
34
+ it "should only assign pages for current site" do
35
+ 2.times {|x| s = FactoryGirl.create(:spud_page)}
36
+ 3.times {|x| s = FactoryGirl.create(:spud_page,:site_id => 1)}
37
+
38
+ get :show, :format => :xml
39
+
40
+ assigns(:pages).should == SpudPage.published_pages.public.order(:spud_page_id).site(1)
41
+
42
+ end
43
+
44
+ end
16
45
  end
17
- end
46
+
47
+
48
+ end
@@ -1,3 +1,3 @@
1
- class ApplicationController < ActionController::Base
1
+ class ApplicationController < Spud::ApplicationController
2
2
  protect_from_forgery
3
3
  end
@@ -0,0 +1,146 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20121112151110) do
15
+
16
+ create_table "spud_admin_permissions", :force => true do |t|
17
+ t.integer "user_id"
18
+ t.string "name"
19
+ t.boolean "access"
20
+ t.datetime "created_at", :null => false
21
+ t.datetime "updated_at", :null => false
22
+ t.string "scope"
23
+ end
24
+
25
+ create_table "spud_menu_items", :force => true do |t|
26
+ t.string "parent_type"
27
+ t.integer "parent_id"
28
+ t.integer "item_type"
29
+ t.integer "spud_page_id"
30
+ t.integer "menu_order", :default => 0
31
+ t.string "url"
32
+ t.datetime "created_at", :null => false
33
+ t.datetime "updated_at", :null => false
34
+ t.string "name"
35
+ t.integer "spud_menu_id"
36
+ t.string "classes"
37
+ end
38
+
39
+ add_index "spud_menu_items", ["menu_order"], :name => "index_spud_menu_items_on_menu_order"
40
+ add_index "spud_menu_items", ["parent_type", "parent_id"], :name => "index_spud_menu_items_on_parent_type_and_parent_id"
41
+ add_index "spud_menu_items", ["spud_menu_id"], :name => "index_spud_menu_items_on_spud_menu_id"
42
+
43
+ create_table "spud_menus", :force => true do |t|
44
+ t.string "name"
45
+ t.text "description"
46
+ t.datetime "created_at", :null => false
47
+ t.datetime "updated_at", :null => false
48
+ t.integer "site_id", :default => 0, :null => false
49
+ end
50
+
51
+ add_index "spud_menus", ["site_id"], :name => "index_spud_menus_on_site_id"
52
+
53
+ create_table "spud_page_partial_revisions", :force => true do |t|
54
+ t.string "name"
55
+ t.text "content"
56
+ t.string "format"
57
+ t.integer "spud_page_id"
58
+ t.datetime "created_at", :null => false
59
+ t.datetime "updated_at", :null => false
60
+ end
61
+
62
+ add_index "spud_page_partial_revisions", ["spud_page_id", "name"], :name => "revision_idx"
63
+
64
+ create_table "spud_page_partials", :force => true do |t|
65
+ t.integer "spud_page_id"
66
+ t.string "name"
67
+ t.text "content"
68
+ t.string "format"
69
+ t.datetime "created_at", :null => false
70
+ t.datetime "updated_at", :null => false
71
+ t.string "symbol_name"
72
+ t.text "content_processed"
73
+ end
74
+
75
+ add_index "spud_page_partials", ["spud_page_id"], :name => "index_spud_page_partials_on_spud_page_id"
76
+
77
+ create_table "spud_pages", :force => true do |t|
78
+ t.string "name"
79
+ t.string "url_name"
80
+ t.datetime "publish_at"
81
+ t.integer "created_by"
82
+ t.integer "updated_by"
83
+ t.string "format", :default => "html"
84
+ t.integer "spud_page_id"
85
+ t.text "meta_description"
86
+ t.string "meta_keywords"
87
+ t.integer "page_order"
88
+ t.datetime "created_at", :null => false
89
+ t.datetime "updated_at", :null => false
90
+ t.integer "visibility", :default => 0
91
+ t.boolean "published", :default => true
92
+ t.boolean "use_custom_url_name", :default => false
93
+ t.text "notes"
94
+ t.integer "site_id", :default => 0, :null => false
95
+ t.string "layout"
96
+ end
97
+
98
+ add_index "spud_pages", ["site_id"], :name => "index_spud_pages_on_site_id"
99
+
100
+ create_table "spud_permalinks", :force => true do |t|
101
+ t.string "url_name"
102
+ t.string "attachment_type"
103
+ t.integer "attachment_id"
104
+ t.datetime "created_at", :null => false
105
+ t.datetime "updated_at", :null => false
106
+ t.integer "site_id"
107
+ end
108
+
109
+ add_index "spud_permalinks", ["attachment_type", "attachment_id"], :name => "index_spud_permalinks_on_attachment_type_and_attachment_id"
110
+ add_index "spud_permalinks", ["site_id"], :name => "index_spud_permalinks_on_site_id"
111
+
112
+ create_table "spud_user_settings", :force => true do |t|
113
+ t.integer "spud_user_id"
114
+ t.string "key"
115
+ t.string "value"
116
+ t.datetime "created_at", :null => false
117
+ t.datetime "updated_at", :null => false
118
+ end
119
+
120
+ create_table "spud_users", :force => true do |t|
121
+ t.string "first_name"
122
+ t.string "last_name"
123
+ t.boolean "super_admin"
124
+ t.string "login", :null => false
125
+ t.string "email", :null => false
126
+ t.string "crypted_password", :null => false
127
+ t.string "password_salt", :null => false
128
+ t.string "persistence_token", :null => false
129
+ t.string "single_access_token", :null => false
130
+ t.string "perishable_token", :null => false
131
+ t.integer "login_count", :default => 0, :null => false
132
+ t.integer "failed_login_count", :default => 0, :null => false
133
+ t.datetime "last_request_at"
134
+ t.datetime "current_login_at"
135
+ t.datetime "last_login_at"
136
+ t.string "current_login_ip"
137
+ t.string "last_login_ip"
138
+ t.datetime "created_at", :null => false
139
+ t.datetime "updated_at", :null => false
140
+ t.string "time_zone"
141
+ end
142
+
143
+ add_index "spud_users", ["email"], :name => "index_spud_users_on_email"
144
+ add_index "spud_users", ["login"], :name => "index_spud_users_on_login"
145
+
146
+ end