tb_cms 1.2.3 → 1.3.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/app/assets/javascripts/admin/cms/menu_items.js +39 -17
- data/app/assets/stylesheets/admin/cms/application.css +11 -0
- data/app/controllers/admin/menu_items_controller.rb +103 -113
- data/app/controllers/admin/menus_controller.rb +52 -53
- data/app/controllers/admin/pages_controller.rb +107 -111
- data/app/controllers/admin/snippets_controller.rb +16 -16
- data/app/controllers/cms/sitemaps_controller.rb +5 -5
- data/app/controllers/pages_controller.rb +30 -34
- data/app/helpers/cms/application_helper.rb +184 -212
- data/app/models/concerns/cms_deprecated_multisite.rb +3 -3
- data/app/models/spud_menu.rb +4 -4
- data/app/models/spud_menu_item.rb +58 -61
- data/app/models/spud_page.rb +63 -67
- data/app/models/spud_page_partial.rb +42 -44
- data/app/models/spud_page_partial_revision.rb +3 -3
- data/app/models/spud_snippet.rb +7 -7
- data/app/views/admin/menu_items/index.html.erb +1 -1
- data/lib/generators/spud/cms/layout_generator.rb +8 -8
- data/lib/spud_cms/configuration.rb +10 -10
- data/lib/spud_cms/engine.rb +28 -28
- data/lib/spud_cms/liquid_snippet.rb +5 -7
- data/lib/spud_cms/page_route.rb +1 -1
- data/lib/spud_cms/template_parser.rb +35 -40
- data/lib/spud_cms/test_files.rb +6 -6
- data/lib/spud_cms/version.rb +3 -3
- data/spec/controllers/admin/menu_items_controller_spec.rb +54 -56
- data/spec/controllers/admin/menus_controller_spec.rb +31 -37
- data/spec/controllers/admin/pages_controller_spec.rb +31 -36
- data/spec/controllers/admin/snippets_controller_spec.rb +1 -1
- data/spec/controllers/pages_controller_spec.rb +21 -21
- data/spec/dummy/config/application.rb +3 -4
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/environments/test.rb +3 -3
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/db/migrate/20141231214447_create_spud_users.tb_core.rb +12 -12
- data/spec/dummy/db/migrate/20141231214448_add_time_zone_to_spud_user.tb_core.rb +0 -1
- data/spec/dummy/db/migrate/20141231214449_add_scope_to_spud_admin_permissions.tb_core.rb +0 -1
- data/spec/dummy/db/migrate/20141231214452_create_spud_permissions.tb_core.rb +3 -3
- data/spec/dummy/db/migrate/20141231214453_create_spud_role_permissions.tb_core.rb +2 -2
- data/spec/dummy/db/migrate/20141231214455_create_spud_permalinks.tb_permalinks.rb +1 -1
- data/spec/dummy/db/migrate/20141231214456_add_site_id_to_spud_permalinks.tb_permalinks.rb +1 -1
- data/spec/dummy/db/migrate/20141231214457_modify_site_id_for_spud_permalinks.tb_permalinks.rb +4 -4
- data/spec/dummy/db/migrate/20141231214459_create_spud_pages.tb_cms.rb +1 -1
- data/spec/dummy/db/migrate/20141231214461_create_spud_menu_items.tb_cms.rb +3 -3
- data/spec/dummy/db/migrate/20141231214463_create_spud_page_partials.tb_cms.rb +1 -1
- data/spec/dummy/db/migrate/20141231214464_add_visibility_to_spud_pages.tb_cms.rb +2 -2
- data/spec/dummy/db/migrate/20141231214466_add_use_custom_url_name_to_spud_pages.tb_cms.rb +1 -1
- data/spec/dummy/db/migrate/20141231214468_add_menu_id_to_spud_menu_items.tb_cms.rb +1 -1
- data/spec/dummy/db/migrate/20141231214469_add_classes_to_spud_menu_items.tb_cms.rb +0 -1
- data/spec/dummy/db/migrate/20141231214470_add_site_id_to_spud_pages.tb_cms.rb +2 -2
- data/spec/dummy/db/migrate/20141231214471_add_site_id_to_spud_templates.tb_cms.rb +2 -2
- data/spec/dummy/db/migrate/20141231214472_add_site_id_to_spud_menus.tb_cms.rb +2 -2
- data/spec/dummy/db/migrate/20141231214473_create_spud_page_partial_revisions.tb_cms.rb +1 -1
- data/spec/dummy/db/migrate/20141231214475_modify_site_id_for_spud_pages.tb_cms.rb +8 -8
- data/spec/dummy/db/migrate/20141231214478_create_spud_page_liquid_tags.tb_cms.rb +1 -1
- data/spec/dummy/db/migrate/20141231214479_create_spud_snippets.tb_cms.rb +1 -2
- data/spec/dummy/db/migrate/20141231214480_change_liquid_tags_to_polymorphic.tb_cms.rb +2 -2
- data/spec/dummy/db/migrate/20141231214481_drop_spud_page_liquid_tags.tb_cms.rb +6 -8
- data/spec/dummy/db/migrate/20150108164814_remove_site_id_from_cms_tables.tb_cms.rb +1 -0
- data/spec/dummy/db/migrate/20150911185843_add_requires_password_change_to_spud_users.tb_core.rb +1 -1
- data/spec/dummy/db/migrate/20160215180157_create_tb_redirects.tb_redirects.rb +3 -3
- data/spec/dummy/db/schema.rb +142 -153
- data/spec/dummy/script/rails +2 -2
- data/spec/helpers/cms/application_helper_spec.rb +39 -41
- data/spec/models/spud_menu_item_spec.rb +13 -13
- data/spec/models/spud_page_partial_revision_spec.rb +1 -1
- data/spec/models/spud_page_partial_spec.rb +19 -20
- data/spec/models/spud_page_spec.rb +90 -91
- data/spec/models/spud_snippet_spec.rb +1 -1
- data/spec/rails_helper.rb +12 -6
- data/spec/spec_helper.rb +42 -44
- metadata +64 -38
- data/spec/authlogic_helper.rb +0 -2
data/lib/spud_cms/version.rb
CHANGED
@@ -1,128 +1,126 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe Admin::MenuItemsController, :
|
3
|
+
describe Admin::MenuItemsController, type: :controller do
|
4
4
|
before(:each) do
|
5
|
-
|
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
|
-
@menu = FactoryGirl.create(:spud_menu)
|
5
|
+
activate_session(admin: true)
|
11
6
|
end
|
12
7
|
|
8
|
+
let (:menu) do
|
9
|
+
FactoryGirl.create(:spud_menu)
|
10
|
+
end
|
13
11
|
|
14
12
|
describe 'index' do
|
15
|
-
it
|
16
|
-
2.times {|
|
17
|
-
get :index
|
13
|
+
it 'should return an array of menus' do
|
14
|
+
2.times { |_x| s = FactoryGirl.create(:spud_menu_item, spud_menu_id: menu.id, parent_id: menu.id) }
|
15
|
+
get :index, params: { menu_id: menu.id }
|
18
16
|
|
19
17
|
expect(assigns(:menu_items).count).to be > 1
|
20
18
|
end
|
21
|
-
it
|
22
|
-
get :index
|
19
|
+
it 'should redirect if the menu is not found' do
|
20
|
+
get :index, params: { menu_id: menu.id + 1 }
|
23
21
|
expect(response).to redirect_to admin_menus_url
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
27
25
|
describe 'new' do
|
28
|
-
it
|
29
|
-
get :new
|
26
|
+
it 'should assign a new menu' do
|
27
|
+
get :new, params: { menu_id: menu.id }
|
30
28
|
expect(assigns(:menu_item)).to_not be_blank
|
31
29
|
expect(response).to be_success
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
35
33
|
describe 'create' do
|
36
|
-
it
|
37
|
-
expect
|
38
|
-
post :create
|
39
|
-
|
34
|
+
it 'should create a new menu item with a valid form submission' do
|
35
|
+
expect do
|
36
|
+
post :create, params: { 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 } }
|
37
|
+
end.to change(SpudMenuItem, :count).by(1)
|
40
38
|
expect(response).to be_redirect
|
41
39
|
end
|
42
40
|
|
43
|
-
it
|
44
|
-
yamldata = FactoryGirl.attributes_for(:spud_menu_item
|
41
|
+
it 'should not create a menu item with an invalid form entry' do
|
42
|
+
yamldata = FactoryGirl.attributes_for(:spud_menu_item, name: nil).reject { |k, _v| k == 'id' || k == :spud_menu_id }
|
45
43
|
|
46
|
-
expect
|
47
|
-
post :create
|
48
|
-
|
44
|
+
expect do
|
45
|
+
post :create, params: { 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 } }
|
46
|
+
end.to_not change(SpudMenuItem, :count)
|
49
47
|
end
|
50
48
|
|
51
|
-
it
|
52
|
-
menuitem = FactoryGirl.create(:spud_menu_item
|
49
|
+
it 'should autoset order if not specified' do
|
50
|
+
menuitem = FactoryGirl.create(:spud_menu_item, parent_id: menu.id)
|
53
51
|
|
54
|
-
post :create
|
52
|
+
post :create, params: { 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 } }
|
55
53
|
expect(assigns(:menu_item).menu_order).to eq(1)
|
56
54
|
end
|
57
55
|
|
58
|
-
it
|
56
|
+
it 'should assign the menu name based on page name if left blank' do
|
59
57
|
page = FactoryGirl.create(:spud_page)
|
60
|
-
post :create
|
58
|
+
post :create, params: { 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 } }
|
61
59
|
expect(assigns(:menu_item).name).to eq(page.name)
|
62
60
|
end
|
63
61
|
|
64
|
-
it
|
65
|
-
menuitem = FactoryGirl.create(:spud_menu_item
|
66
|
-
post :create
|
62
|
+
it 'should set the parent to a submenu if specified' do
|
63
|
+
menuitem = FactoryGirl.create(:spud_menu_item, parent_id: menu.id)
|
64
|
+
post :create, params: { 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 } }
|
67
65
|
expect(assigns(:menu_item).parent).to eq(menuitem)
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|
71
69
|
describe 'edit' do
|
72
|
-
it
|
70
|
+
it 'should respond with menu item by id' do
|
73
71
|
menu1 = FactoryGirl.create(:spud_menu_item)
|
74
72
|
menu2 = FactoryGirl.create(:spud_menu_item)
|
75
|
-
get :edit, :menu_id
|
73
|
+
get :edit, params: { menu_id: menu.id, id: menu2.id }
|
76
74
|
expect(assigns(:menu_item)).to eq(menu2)
|
77
75
|
end
|
78
76
|
|
79
|
-
it
|
80
|
-
get :edit
|
81
|
-
expect(response).to redirect_to admin_menu_menu_items_url(:
|
77
|
+
it 'should redirect_to index if menu item not found' do
|
78
|
+
get :edit, params: { menu_id: menu.id, id: '345' }
|
79
|
+
expect(response).to redirect_to admin_menu_menu_items_url(menu_id: menu.id)
|
82
80
|
end
|
83
81
|
end
|
84
82
|
|
85
83
|
describe 'update' do
|
86
|
-
it
|
84
|
+
it 'should update the name when the name attribute is changed' do
|
87
85
|
menu_item = FactoryGirl.create(:spud_menu_item)
|
88
86
|
new_name = 'MyMenu'
|
89
|
-
expect
|
90
|
-
put :update
|
87
|
+
expect do
|
88
|
+
put :update, params: { 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 } }
|
91
89
|
menu_item.reload
|
92
|
-
|
90
|
+
end.to change(menu_item, :name).to(new_name)
|
93
91
|
end
|
94
|
-
it
|
92
|
+
it 'should assign a menu to a submenu if parentid is defined' do
|
95
93
|
menu_item1 = FactoryGirl.create(:spud_menu_item)
|
96
94
|
menu_item = FactoryGirl.create(:spud_menu_item)
|
97
95
|
|
98
|
-
expect
|
99
|
-
put :update
|
96
|
+
expect do
|
97
|
+
put :update, params: { 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 } }
|
100
98
|
menu_item.reload
|
101
|
-
|
99
|
+
end.to change(menu_item, :parent).to(menu_item1)
|
102
100
|
end
|
103
101
|
end
|
104
102
|
|
105
103
|
describe 'destroy' do
|
106
|
-
it
|
107
|
-
menu_item = FactoryGirl.create(:spud_menu_item
|
108
|
-
expect
|
109
|
-
delete :destroy
|
110
|
-
|
104
|
+
it 'should destroy the menu item' do
|
105
|
+
menu_item = FactoryGirl.create(:spud_menu_item, parent_id: menu.id)
|
106
|
+
expect do
|
107
|
+
delete :destroy, params: { menu_id: menu.id, id: menu_item.id }
|
108
|
+
end.to change(SpudMenuItem, :count).by(-1)
|
111
109
|
end
|
112
110
|
end
|
113
111
|
|
114
112
|
describe 'update_sort' do
|
115
|
-
it
|
116
|
-
ordered_arr = Array.new(5)
|
113
|
+
it 'should update all menu items menu_order fields' do
|
114
|
+
ordered_arr = Array.new(5)
|
117
115
|
ordered_arr.each_with_index do |item, index|
|
118
|
-
|
119
|
-
|
116
|
+
item = FactoryGirl.create(:spud_menu_item, parent_id: menu.id, menu_order: index)
|
117
|
+
ordered_arr[index] = item.id.to_s
|
120
118
|
end
|
121
119
|
new_order_arr = ordered_arr.shuffle
|
122
|
-
put :update_sort, :menu_id
|
120
|
+
put :update_sort, params: { menu_id: menu.id, id: ordered_arr[0], order: new_order_arr }
|
123
121
|
new_order_arr.each_with_index do |item, index|
|
124
|
-
expect(
|
125
|
-
end
|
122
|
+
expect(menu.spud_menu_items.find_by(id: item.to_i).menu_order).to be(index)
|
123
|
+
end
|
126
124
|
end
|
127
125
|
end
|
128
126
|
end
|
@@ -1,17 +1,12 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe Admin::MenusController, :
|
3
|
+
describe Admin::MenusController, type: :controller do
|
4
4
|
before(:each) do
|
5
|
-
|
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)
|
5
|
+
activate_session(admin: true)
|
10
6
|
end
|
11
7
|
|
12
|
-
|
13
8
|
describe 'index' do
|
14
|
-
it
|
9
|
+
it 'should return an array of menus' do
|
15
10
|
2.times { FactoryGirl.create(:spud_menu) }
|
16
11
|
get :index
|
17
12
|
|
@@ -21,7 +16,7 @@ describe Admin::MenusController, :type => :controller do
|
|
21
16
|
end
|
22
17
|
|
23
18
|
describe 'new' do
|
24
|
-
it
|
19
|
+
it 'should response with new menu' do
|
25
20
|
get :new
|
26
21
|
expect(assigns(:menu)).to_not be_blank
|
27
22
|
expect(response).to be_success
|
@@ -29,69 +24,68 @@ describe Admin::MenusController, :type => :controller do
|
|
29
24
|
end
|
30
25
|
|
31
26
|
describe 'create' do
|
32
|
-
it
|
33
|
-
expect
|
34
|
-
post :create, :spud_menu
|
35
|
-
|
27
|
+
it 'should create a new menu with a valid form submission' do
|
28
|
+
expect do
|
29
|
+
post :create, params: { spud_menu: FactoryGirl.attributes_for(:spud_menu).reject { |k, _v| k == 'id' } }
|
30
|
+
end.to change(SpudMenu, :count).by(1)
|
36
31
|
expect(response).to be_redirect
|
37
32
|
end
|
38
33
|
|
39
|
-
it
|
40
|
-
expect
|
41
|
-
post :create, :spud_menu
|
42
|
-
|
43
|
-
|
34
|
+
it 'should not create a menu with an invalid form entry' do
|
35
|
+
expect do
|
36
|
+
post :create, params: { spud_menu: FactoryGirl.attributes_for(:spud_menu, name: nil).reject { |k, _v| k == 'id' } }
|
37
|
+
end.to_not change(SpudMenu, :count)
|
44
38
|
|
45
39
|
end
|
46
40
|
end
|
47
41
|
|
48
42
|
describe 'edit' do
|
49
|
-
it
|
43
|
+
it 'should response with menu by id' do
|
50
44
|
menu1 = FactoryGirl.create(:spud_menu)
|
51
45
|
menu2 = FactoryGirl.create(:spud_menu)
|
52
|
-
get :edit
|
46
|
+
get :edit, params: { id: menu2.id }
|
53
47
|
expect(assigns(:menu)).to eq(menu2)
|
54
48
|
end
|
55
|
-
it
|
56
|
-
get :edit
|
49
|
+
it 'should redirect to index if menu not found' do
|
50
|
+
get :edit, params: { id: 3 }
|
57
51
|
expect(response).to redirect_to admin_menus_url
|
58
52
|
end
|
59
53
|
|
60
54
|
end
|
61
55
|
|
62
56
|
describe 'update' do
|
63
|
-
it
|
57
|
+
it 'should update the name when the name attribute is changed' do
|
64
58
|
menu = FactoryGirl.create(:spud_menu)
|
65
59
|
new_name = 'MyMenu'
|
66
|
-
expect
|
67
|
-
put :update
|
60
|
+
expect do
|
61
|
+
put :update, params: { id: menu.id, spud_menu: menu.attributes.merge!(name: new_name).reject { |k, _v| k == 'id' } }
|
68
62
|
menu.reload
|
69
|
-
|
63
|
+
end.to change(menu, :name).to(new_name)
|
70
64
|
|
71
65
|
end
|
72
66
|
|
73
|
-
it
|
67
|
+
it 'should redirect to the admin menus after a successful update' do
|
74
68
|
menu = FactoryGirl.create(:spud_menu)
|
75
|
-
put :update
|
69
|
+
put :update, params: { id: menu.id, spud_menu: menu.attributes.merge!(name: 'MyMenu').reject { |k, _v| k == 'id' } }
|
76
70
|
|
77
|
-
expect(response).to redirect_to(admin_menu_menu_items_url(:
|
71
|
+
expect(response).to redirect_to(admin_menu_menu_items_url(menu_id: menu.id))
|
78
72
|
end
|
79
73
|
end
|
80
74
|
|
81
75
|
describe 'destroy' do
|
82
|
-
it
|
76
|
+
it 'should destroy the menu' do
|
83
77
|
menu = FactoryGirl.create(:spud_menu)
|
84
|
-
expect
|
85
|
-
delete :destroy, :id
|
86
|
-
|
78
|
+
expect do
|
79
|
+
delete :destroy, params: { id: menu.id }
|
80
|
+
end.to change(SpudMenu, :count).by(-1)
|
87
81
|
expect(response).to be_redirect
|
88
82
|
end
|
89
83
|
|
90
|
-
it
|
84
|
+
it 'should not destroy the menu with a wrong id' do
|
91
85
|
menu = FactoryGirl.create(:spud_menu)
|
92
|
-
expect
|
93
|
-
delete :destroy
|
94
|
-
|
86
|
+
expect do
|
87
|
+
delete :destroy, params: { id: '23532' }
|
88
|
+
end.to_not change(SpudMenu, :count)
|
95
89
|
expect(response).to be_redirect
|
96
90
|
end
|
97
91
|
|
@@ -1,25 +1,21 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe Admin::PagesController, :
|
3
|
+
describe Admin::PagesController, type: :controller do
|
4
4
|
before(:each) do
|
5
|
-
|
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)
|
5
|
+
activate_session(admin: true)
|
10
6
|
end
|
11
7
|
|
12
8
|
describe 'index' do
|
13
|
-
it
|
14
|
-
2.times {|
|
9
|
+
it 'should return an array of parent pages' do
|
10
|
+
2.times { |_x| s = FactoryGirl.create(:spud_page) }
|
15
11
|
get :index
|
16
12
|
|
17
13
|
expect(assigns(:pages).count).to be > 1
|
18
14
|
end
|
19
15
|
|
20
|
-
it
|
21
|
-
2.times {|
|
22
|
-
FactoryGirl.create(:spud_page
|
16
|
+
it 'should only return parent pages' do
|
17
|
+
2.times { |_x| FactoryGirl.create(:spud_page) }
|
18
|
+
FactoryGirl.create(:spud_page, spud_page_id: 1)
|
23
19
|
|
24
20
|
get :index
|
25
21
|
expect(assigns(:pages).count).to eq(2)
|
@@ -27,22 +23,22 @@ describe Admin::PagesController, :type => :controller do
|
|
27
23
|
end
|
28
24
|
|
29
25
|
describe 'show' do
|
30
|
-
it
|
26
|
+
it 'should respond successfully' do
|
31
27
|
p = FactoryGirl.create(:spud_page)
|
32
|
-
get :show
|
33
|
-
expect(assigns(:layout)).to render_template(:
|
28
|
+
get :show, params: { id: p.id }
|
29
|
+
expect(assigns(:layout)).to render_template(layout: "layouts/#{Spud::Cms.default_page_layout}")
|
34
30
|
expect(response).to be_success
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
38
34
|
describe 'new' do
|
39
|
-
it
|
35
|
+
it 'should respond successfully' do
|
40
36
|
get :new
|
41
37
|
|
42
38
|
expect(response).to be_success
|
43
39
|
end
|
44
40
|
|
45
|
-
it
|
41
|
+
it 'should build a page object for the form' do
|
46
42
|
get :new
|
47
43
|
|
48
44
|
expect(assigns(:page)).to_not be_blank
|
@@ -50,10 +46,10 @@ describe Admin::PagesController, :type => :controller do
|
|
50
46
|
end
|
51
47
|
|
52
48
|
describe 'edit' do
|
53
|
-
context
|
54
|
-
it
|
49
|
+
context 'HTML format' do
|
50
|
+
it 'should load the correct page for the edit form' do
|
55
51
|
page = FactoryGirl.create(:spud_page)
|
56
|
-
get :edit, :id
|
52
|
+
get :edit, params: { id: page.id }
|
57
53
|
|
58
54
|
expect(assigns(:page).id).to eq(page.id)
|
59
55
|
end
|
@@ -61,40 +57,39 @@ describe Admin::PagesController, :type => :controller do
|
|
61
57
|
|
62
58
|
end
|
63
59
|
|
64
|
-
|
65
60
|
describe 'update' do
|
66
|
-
it
|
61
|
+
it 'should update the name when the attribute is changed' do
|
67
62
|
page = FactoryGirl.create(:spud_page)
|
68
|
-
new_name =
|
69
|
-
expect
|
70
|
-
put :update, :id
|
63
|
+
new_name = 'Adam'
|
64
|
+
expect do
|
65
|
+
put :update, params: { id: page.id, spud_page: { name: new_name } }
|
71
66
|
page.reload
|
72
|
-
|
67
|
+
end.to change(page, :name).to(new_name)
|
73
68
|
end
|
74
69
|
|
75
|
-
it
|
70
|
+
it 'should redirect to the page root index after a successful update' do
|
76
71
|
page = FactoryGirl.create(:spud_page)
|
77
|
-
new_name =
|
78
|
-
put :update, :id
|
72
|
+
new_name = 'Adam'
|
73
|
+
put :update, params: { id: page.id, spud_page: page.attributes.merge!(name: new_name).reject { |key, _value| key == 'id' || key == 'created_at' || key == 'updated_at' } }
|
79
74
|
|
80
75
|
expect(response).to redirect_to(admin_pages_url)
|
81
76
|
end
|
82
77
|
end
|
83
78
|
|
84
79
|
describe 'destroy' do
|
85
|
-
it
|
80
|
+
it 'should destroy the page' do
|
86
81
|
page = FactoryGirl.create(:spud_page)
|
87
|
-
expect
|
88
|
-
delete :destroy, :id
|
89
|
-
|
82
|
+
expect do
|
83
|
+
delete :destroy, params: { id: page.id }
|
84
|
+
end.to change(SpudPage, :count).by(-1)
|
90
85
|
expect(response).to be_redirect
|
91
86
|
end
|
92
87
|
|
93
|
-
it
|
88
|
+
it 'should destroy the user with the wrong id' do
|
94
89
|
page = FactoryGirl.create(:spud_page)
|
95
|
-
expect
|
96
|
-
delete :destroy, :id
|
97
|
-
|
90
|
+
expect do
|
91
|
+
delete :destroy, params: { id: '23532' }
|
92
|
+
end.to_not change(SpudPage, :count)
|
98
93
|
expect(response).to be_redirect
|
99
94
|
end
|
100
95
|
end
|
@@ -1,51 +1,51 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe PagesController, :
|
3
|
+
describe PagesController, type: :controller do
|
4
4
|
describe 'show' do
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'should render a page' do
|
7
7
|
page = FactoryGirl.create(:spud_page)
|
8
|
-
get :show
|
9
|
-
expect(assigns(:layout)).to render_template(:
|
8
|
+
get :show, params: { id: page.url_name }
|
9
|
+
expect(assigns(:layout)).to render_template(layout: "layouts/#{Spud::Cms.default_page_layout}")
|
10
10
|
expect(response).to be_success
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
page = FactoryGirl.create(:spud_page
|
13
|
+
it 'should render home page if id is blank' do
|
14
|
+
page = FactoryGirl.create(:spud_page, name: 'home')
|
15
15
|
get :show
|
16
16
|
expect(assigns(:page)).to eq(page)
|
17
17
|
expect(response).to be_success
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
page = FactoryGirl.create(:spud_page, :
|
22
|
-
page.update(:
|
20
|
+
it 'should redirect to new page url from old page url if it was changed' do
|
21
|
+
page = FactoryGirl.create(:spud_page, name: 'about', url_name: 'about')
|
22
|
+
page.update(url_name: 'about-us')
|
23
23
|
page.save
|
24
|
-
get :show, :id
|
24
|
+
get :show, params: { id: 'about' }
|
25
25
|
|
26
|
-
|
26
|
+
expect(response).to redirect_to page_url(id: 'about-us')
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
page = FactoryGirl.create(:spud_page
|
29
|
+
it 'should not allow access to private pages when logged out' do
|
30
|
+
page = FactoryGirl.create(:spud_page, name: 'about', visibility: 1)
|
31
31
|
|
32
|
-
get :show, :id
|
33
|
-
expect(response).to redirect_to login_path(:
|
32
|
+
get :show, params: { id: 'about' }
|
33
|
+
expect(response).to redirect_to login_path(return_to: '/about')
|
34
34
|
end
|
35
35
|
|
36
|
-
describe
|
37
|
-
|
36
|
+
describe 'authorized login' do
|
37
|
+
before(:each) do
|
38
38
|
activate_authlogic
|
39
|
-
u = SpudUser.new(:
|
39
|
+
u = SpudUser.new(login: 'testuser', email: 'test@testuser.com', password: 'test', password_confirmation: 'test')
|
40
40
|
u.super_admin = true
|
41
41
|
u.save
|
42
42
|
@user = SpudUserSession.create(u)
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
46
|
-
page = FactoryGirl.create(:spud_page
|
45
|
+
it 'should allow access to private pages when logged in' do
|
46
|
+
page = FactoryGirl.create(:spud_page, name: 'about', visibility: 1)
|
47
47
|
|
48
|
-
get :show, :id
|
48
|
+
get :show, params: { id: 'about' }
|
49
49
|
expect(response).to be_success
|
50
50
|
end
|
51
51
|
end
|
@@ -3,13 +3,13 @@ require File.expand_path('../boot', __FILE__)
|
|
3
3
|
require 'rails/all'
|
4
4
|
|
5
5
|
Bundler.require
|
6
|
-
require
|
6
|
+
require 'tb_cms'
|
7
7
|
|
8
8
|
module Dummy
|
9
9
|
class Application < Rails::Application
|
10
10
|
|
11
11
|
Spud::Core.configure do |config|
|
12
|
-
|
12
|
+
config.site_name = 'Test Site'
|
13
13
|
end
|
14
14
|
|
15
15
|
# Settings in config/environments/* take precedence over those specified here.
|
@@ -36,7 +36,7 @@ module Dummy
|
|
36
36
|
config.i18n.enforce_available_locales = true
|
37
37
|
|
38
38
|
# Configure the default encoding used in templates for Ruby 1.9.
|
39
|
-
config.encoding =
|
39
|
+
config.encoding = 'utf-8'
|
40
40
|
|
41
41
|
# Configure sensitive parameters which will be filtered from the log file.
|
42
42
|
config.filter_parameters += [:password]
|
@@ -62,4 +62,3 @@ module Dummy
|
|
62
62
|
config.assets.version = '1.0'
|
63
63
|
end
|
64
64
|
end
|
65
|
-
|
data/spec/dummy/config/boot.rb
CHANGED
@@ -9,7 +9,7 @@ Dummy::Application.configure do
|
|
9
9
|
config.action_controller.perform_caching = true
|
10
10
|
|
11
11
|
# Disable Rails's static asset server (Apache or nginx will already do this)
|
12
|
-
config.
|
12
|
+
config.public_file_server.enabled = true
|
13
13
|
|
14
14
|
# Compress JavaScripts and CSS
|
15
15
|
config.assets.compress = true
|
@@ -8,8 +8,8 @@ Dummy::Application.configure do
|
|
8
8
|
config.cache_classes = true
|
9
9
|
|
10
10
|
# Configure static asset server for tests with Cache-Control for performance
|
11
|
-
config.
|
12
|
-
config.
|
11
|
+
config.public_file_server.enabled = true
|
12
|
+
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
|
13
13
|
|
14
14
|
# Deprecated
|
15
15
|
# Log error messages when you accidentally call methods on nil
|
@@ -28,7 +28,7 @@ Dummy::Application.configure do
|
|
28
28
|
config.action_dispatch.show_exceptions = false
|
29
29
|
|
30
30
|
# Disable request forgery protection in test environment
|
31
|
-
config.action_controller.allow_forgery_protection
|
31
|
+
config.action_controller.allow_forgery_protection = false
|
32
32
|
|
33
33
|
# Tell Action Mailer not to deliver emails to the real world.
|
34
34
|
# The :test delivery method accumulates sent emails in the
|
data/spec/dummy/config.ru
CHANGED