radiant-templates-extension 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HELP_designer.textile +79 -0
- data/README.textile +123 -0
- data/Rakefile +136 -0
- data/VERSION +1 -0
- data/app/controllers/admin/part_types_controller.rb +8 -0
- data/app/controllers/admin/templates_controller.rb +38 -0
- data/app/helpers/admin/part_types_helper.rb +26 -0
- data/app/helpers/admin/templates_helper.rb +108 -0
- data/app/models/part_type.rb +14 -0
- data/app/models/template.rb +80 -0
- data/app/models/template_part.rb +21 -0
- data/app/views/admin/pages/_edit_template.html.haml +32 -0
- data/app/views/admin/pages/_edit_template_part.html.haml +20 -0
- data/app/views/admin/pages/_switch_templates.html.haml +23 -0
- data/app/views/admin/pages/_template_column.html.haml +3 -0
- data/app/views/admin/pages/_template_column_header.html.haml +1 -0
- data/app/views/admin/part_types/_form.html.haml +36 -0
- data/app/views/admin/part_types/_list.html.haml +23 -0
- data/app/views/admin/part_types/edit.html.haml +5 -0
- data/app/views/admin/part_types/index.html.haml +7 -0
- data/app/views/admin/part_types/new.html.haml +2 -0
- data/app/views/admin/part_types/remove.html.haml +15 -0
- data/app/views/admin/templates/_form.html.haml +65 -0
- data/app/views/admin/templates/_template_part.html.haml +21 -0
- data/app/views/admin/templates/_templates_css.html.haml +12 -0
- data/app/views/admin/templates/edit.html.haml +10 -0
- data/app/views/admin/templates/index.html.haml +47 -0
- data/app/views/admin/templates/new.html.haml +9 -0
- data/app/views/admin/templates/remove.html.haml +15 -0
- data/config/initializers/radiant_config.rb +3 -0
- data/config/locales/en.yml +32 -0
- data/config/routes.rb +7 -0
- data/db/migrate/001_create_templates.rb +17 -0
- data/db/migrate/002_create_template_parts.rb +15 -0
- data/db/migrate/003_rename_sublayout_column.rb +9 -0
- data/db/migrate/004_add_position_to_templates.rb +13 -0
- data/db/migrate/005_create_part_types.rb +17 -0
- data/db/migrate/006_add_description_to_template_parts.rb +9 -0
- data/db/migrate/007_add_page_class_name_to_templates.rb +9 -0
- data/db/migrate/008_add_index_to_templates.rb +9 -0
- data/db/migrate/009_create_default_part_types.rb +23 -0
- data/db/migrate/010_update_boolean_part_type.rb +9 -0
- data/db/migrate/011_add_timestamps.rb +19 -0
- data/lib/file_system/model/part_type_extensions.rb +19 -0
- data/lib/file_system/model/template_extensions.rb +52 -0
- data/lib/tasks/templates_extension_tasks.rake +28 -0
- data/lib/templates/associations.rb +7 -0
- data/lib/templates/controller_extensions.rb +20 -0
- data/lib/templates/helper.rb +75 -0
- data/lib/templates/page_extensions.rb +43 -0
- data/lib/templates/tags.rb +43 -0
- data/public/images/admin/menu_arrow.png +0 -0
- data/public/images/admin/move_higher.png +0 -0
- data/public/images/admin/move_lower.png +0 -0
- data/public/images/admin/move_to_bottom.png +0 -0
- data/public/images/admin/move_to_top.png +0 -0
- data/public/images/admin/part_type.png +0 -0
- data/public/images/admin/template.png +0 -0
- data/spec/controllers/admin_page_controller_extensions_spec.rb +61 -0
- data/spec/controllers/part_types_controller_spec.rb +89 -0
- data/spec/controllers/templates_controller_spec.rb +322 -0
- data/spec/datasets/part_types_dataset.rb +15 -0
- data/spec/datasets/templates_dataset.rb +34 -0
- data/spec/helpers/templates_helper_spec.rb +56 -0
- data/spec/models/page_extensions_spec.rb +9 -0
- data/spec/models/part_type_spec.rb +28 -0
- data/spec/models/tags_spec.rb +44 -0
- data/spec/models/template_part_spec.rb +37 -0
- data/spec/models/template_spec.rb +88 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +39 -0
- data/templates_extension.rb +83 -0
- data/vendor/plugins/acts_as_list/README +23 -0
- data/vendor/plugins/acts_as_list/init.rb +3 -0
- data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
- data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
- data/vendor/plugins/make_resourceful/DEFAULTS +148 -0
- data/vendor/plugins/make_resourceful/LICENSE +7 -0
- data/vendor/plugins/make_resourceful/README +239 -0
- data/vendor/plugins/make_resourceful/Rakefile +42 -0
- data/vendor/plugins/make_resourceful/VERSION +1 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb +87 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/controller.rb +5 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/fixtures.yml +10 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/functional_test.rb +57 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/helper.rb +2 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/migration.rb +13 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/model.rb +2 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/unit_test.rb +7 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view__form.haml +5 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_edit.haml +11 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_index.haml +5 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_new.haml +9 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_partial.haml +12 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_show.haml +14 -0
- data/vendor/plugins/make_resourceful/init.rb +3 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/base.rb +52 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/builder.rb +354 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/accessors.rb +346 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/actions.rb +92 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/callbacks.rb +51 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/responses.rb +118 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/urls.rb +137 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/maker.rb +83 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/response.rb +33 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/serialize.rb +181 -0
- data/vendor/plugins/make_resourceful/spec/accessors_spec.rb +473 -0
- data/vendor/plugins/make_resourceful/spec/actions_spec.rb +283 -0
- data/vendor/plugins/make_resourceful/spec/base_spec.rb +12 -0
- data/vendor/plugins/make_resourceful/spec/builder_spec.rb +332 -0
- data/vendor/plugins/make_resourceful/spec/callbacks_spec.rb +71 -0
- data/vendor/plugins/make_resourceful/spec/integration_spec.rb +396 -0
- data/vendor/plugins/make_resourceful/spec/maker_spec.rb +91 -0
- data/vendor/plugins/make_resourceful/spec/response_spec.rb +37 -0
- data/vendor/plugins/make_resourceful/spec/responses_spec.rb +314 -0
- data/vendor/plugins/make_resourceful/spec/rspec_on_rails/LICENSE +35 -0
- data/vendor/plugins/make_resourceful/spec/rspec_on_rails/redirect_to.rb +81 -0
- data/vendor/plugins/make_resourceful/spec/rspec_on_rails/render_template.rb +28 -0
- data/vendor/plugins/make_resourceful/spec/serialize_spec.rb +133 -0
- data/vendor/plugins/make_resourceful/spec/spec_helper.rb +279 -0
- data/vendor/plugins/make_resourceful/spec/urls_spec.rb +276 -0
- metadata +214 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
module Templates::PageExtensions
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
before_save :match_with_template
|
6
|
+
|
7
|
+
def allowed_children
|
8
|
+
[default_child, Template.all].flatten
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def match_with_template
|
15
|
+
unless self.template.blank?
|
16
|
+
self.class_name = self.template.page_class_name
|
17
|
+
self.layout_id = self.template.layout_id
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def template_name
|
22
|
+
template ? template.name : "Blank Page"
|
23
|
+
end
|
24
|
+
|
25
|
+
def is_a_blank_page?
|
26
|
+
! template_id?
|
27
|
+
end
|
28
|
+
|
29
|
+
# Meta-programming methods to determine if page is built on a specific template
|
30
|
+
# e.g. @page.is_a_press_release? assuming you have "Press Release" template defined.
|
31
|
+
begin
|
32
|
+
Template.all.each do |unique_template|
|
33
|
+
class_eval <<-CODE, __FILE__, __LINE__
|
34
|
+
def is_a_#{unique_template.name.titleize.scan(/\w+/).join.underscore}?
|
35
|
+
template_id? && template.name == "#{unique_template.name}"
|
36
|
+
end
|
37
|
+
CODE
|
38
|
+
end
|
39
|
+
rescue
|
40
|
+
# This won't run before initial migrations, which create the Template table
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Templates::Tags
|
2
|
+
include Radiant::Taggable
|
3
|
+
|
4
|
+
tag 'boolean_part' do |tag|
|
5
|
+
tag.expand
|
6
|
+
end
|
7
|
+
|
8
|
+
desc %{
|
9
|
+
Renders its contents if the selected part contains the text "true". When
|
10
|
+
used with check_box part-types in a template, can turn on and off sections
|
11
|
+
of content. The 'part' attribute is required.
|
12
|
+
|
13
|
+
*Usage*:
|
14
|
+
|
15
|
+
<pre><code><r:boolean_part:if part="display_sidebar">Sidebar content</r:boolean_part:if></code></pre>
|
16
|
+
}
|
17
|
+
tag 'boolean_part:if' do |tag|
|
18
|
+
part_name = tag.attr['part']
|
19
|
+
raise StandardTags::TagError.new("`boolean_part:if' tag requires a 'part' attribute") unless part_name
|
20
|
+
part = tag.locals.page.part(part_name)
|
21
|
+
# result = part.nil? ? "" : part.content.strip
|
22
|
+
result = part.nil? ? "" : (dev?(tag.globals.page.request) && defined?(ConcurrentDraftExtension) ? part.draft_content.strip : part.content.strip)
|
23
|
+
tag.expand if result =~ /t|true|1/i
|
24
|
+
end
|
25
|
+
|
26
|
+
desc %{
|
27
|
+
Renders its contents if the selected part does not contain the text "true". When
|
28
|
+
used with check_box part-types in a template, can turn on and off sections
|
29
|
+
of content. The 'part' attribute is required.
|
30
|
+
|
31
|
+
*Usage*:
|
32
|
+
|
33
|
+
<pre><code><r:boolean_part:unless part="display_sidebar">Sidebar content</r:boolean_part:unless></code></pre>
|
34
|
+
}
|
35
|
+
tag 'boolean_part:unless' do |tag|
|
36
|
+
part_name = tag.attr['part']
|
37
|
+
raise StandardTags::TagError.new("`boolean_part:unless' tag requires a 'part' attribute") unless part_name
|
38
|
+
part = tag.locals.page.part(part_name)
|
39
|
+
# result = part.nil? ? "" : part.content.strip
|
40
|
+
result = part.nil? ? "" : (dev?(tag.globals.page.request) && defined?(ConcurrentDraftExtension) ? part.draft_content.strip : part.content.strip)
|
41
|
+
tag.expand unless result =~ /t|true|1/i
|
42
|
+
end
|
43
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
# We only have this spec because setting up an isolated view spec would be too
|
4
|
+
# complicated. Instead we have a quasi-integration test.
|
5
|
+
describe Admin::PagesController, "edit view controlled by templates" do
|
6
|
+
integrate_views
|
7
|
+
dataset :users_and_pages, :templates
|
8
|
+
before :each do
|
9
|
+
@page = pages(:home)
|
10
|
+
@page.template = templates(:sample)
|
11
|
+
@page.stub!(:children).and_return([])
|
12
|
+
login_as :designer
|
13
|
+
end
|
14
|
+
|
15
|
+
def do_get
|
16
|
+
get :edit, :id => @page.id
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should include a hidden field containing the body/structure" do
|
20
|
+
do_get
|
21
|
+
response.should have_tag('input', :attributes => {'type' => 'hidden', 'name' => 'part[0][name]', 'value' => 'body'})
|
22
|
+
response.should have_tag('input', :attributes => {'type' => 'hidden', 'name' => 'part[0][content]'})
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should display a template part with style and class attributes" do
|
26
|
+
do_get
|
27
|
+
response.should have_tag('input', :attributes => {'type' => 'hidden', 'name' => 'part[1][name]', 'value' => 'Part 1'})
|
28
|
+
response.should have_tag('textarea', :attributes => {'name' => 'part[0][content]', 'class' => 'wysiwyg', 'style' => 'width: 100%'})
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should display a textarea template part" do
|
32
|
+
do_get
|
33
|
+
response.should have_tag('input', :attributes => {'type' => 'hidden', 'name' => 'part[1][name]', 'value' => 'extended'})
|
34
|
+
response.should have_tag('textarea', :attributes => {'name' => 'part[1][content]', 'class' => 'plaintext'})
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should display a radio_button template part" do
|
38
|
+
do_get
|
39
|
+
response.should have_tag('input', :attributes => {'type' => 'hidden', 'name' => 'part[2][name]', 'value' => 'featured?'})
|
40
|
+
response.should have_tag('input', :attributes => {'type' => 'radio_button', 'name' => 'part[2][content]', 'value' => 'true'})
|
41
|
+
response.should have_tag('input', :attributes => {'type' => 'hidden', 'name' => 'part[2][content]', 'value' => 'false'})
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should display a hidden template part" do
|
45
|
+
do_get
|
46
|
+
response.should have_tag('input', :attributes => {'type' => 'hidden', 'name' => 'part[3][name]', 'value' => 'Feature image'})
|
47
|
+
response.should have_tag('input', :attributes => {'type' => 'hidden', 'name' => 'part[3][content]'})
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should display a text field template part" do
|
51
|
+
do_get
|
52
|
+
response.should have_tag('input', :attributes => {'type' => 'hidden', 'name' => 'part[4][name]', 'value' => 'Tagline'})
|
53
|
+
response.should have_tag('input', :attributes => {'type' => 'text', 'name' => 'part[4][content]'})
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should override the class name field when the template has one specified" do
|
57
|
+
@page.template = templates(:another)
|
58
|
+
do_get
|
59
|
+
response.should have_tag('input', :attributes => {'name' => 'page[class_name]', 'value' => 'FileNotFoundPage'})
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Admin::PartTypesController do
|
4
|
+
dataset :users, :part_types
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
login_as :admin
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be a ResourceController" do
|
11
|
+
controller.should be_kind_of(Admin::ResourceController)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should handle PartTypes" do
|
15
|
+
controller.class.model_class.should == PartType
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "show" do
|
19
|
+
it "should redirect to the edit action" do
|
20
|
+
get :show, :id => 1
|
21
|
+
response.should redirect_to(edit_admin_part_type_path(params[:id]))
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should show xml when format is xml" do
|
25
|
+
part_type = PartType.first
|
26
|
+
get :show, :id => part_type.id, :format => "xml"
|
27
|
+
response.body.should == part_type.to_xml
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "with invalid page id" do
|
32
|
+
[:edit, :remove].each do |action|
|
33
|
+
before do
|
34
|
+
@parameters = {:id => 999}
|
35
|
+
end
|
36
|
+
it "should redirect the #{action} action to the index action" do
|
37
|
+
get action, @parameters
|
38
|
+
response.should redirect_to(admin_part_types_path)
|
39
|
+
end
|
40
|
+
it "should say that the 'Part Type could not be found.' after the #{action} action" do
|
41
|
+
get action, @parameters
|
42
|
+
flash[:notice].should == 'Part Type could not be found.'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
it 'should redirect the update action to the index action' do
|
46
|
+
put :update, @parameters
|
47
|
+
response.should redirect_to(admin_part_types_path)
|
48
|
+
end
|
49
|
+
it "should say that the 'Part Type could not be found.' after the update action" do
|
50
|
+
put :update, @parameters
|
51
|
+
flash[:notice].should == 'Part Type could not be found.'
|
52
|
+
end
|
53
|
+
it 'should redirect the destroy action to the index action' do
|
54
|
+
delete :destroy, @parameters
|
55
|
+
response.should redirect_to(admin_part_types_path)
|
56
|
+
end
|
57
|
+
it "should say that the 'Part Type could not be found.' after the destroy action" do
|
58
|
+
delete :destroy, @parameters
|
59
|
+
flash[:notice].should == 'Part Type could not be found.'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
{ :get => [:index, :new, :edit, :remove],
|
64
|
+
:post => [:create],
|
65
|
+
:put => [:update],
|
66
|
+
:delete => [:destroy] }.each do |method, actions|
|
67
|
+
actions.each do |action|
|
68
|
+
it "should require login to access the #{action} action" do
|
69
|
+
logout
|
70
|
+
lambda { send(method, action).should require_login }
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should allow access to admins for the #{action} action" do
|
74
|
+
lambda {
|
75
|
+
send(method, action, :id => part_type_id(:one_line))
|
76
|
+
}.should restrict_access(:allow => [users(:admin)],
|
77
|
+
:url => '/admin/pages')
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should deny non-admins for the #{action} action" do
|
81
|
+
lambda {
|
82
|
+
send(method, action, :id => part_type_id(:plaintext))
|
83
|
+
}.should restrict_access(:deny => [users(:non_admin), users(:existing)],
|
84
|
+
:url => '/admin/pages')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,322 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
# Re-raise errors caught by the controller.
|
4
|
+
Admin::TemplatesController.class_eval { def rescue_action(e) raise e end }
|
5
|
+
|
6
|
+
describe Admin::TemplatesController do
|
7
|
+
dataset :users
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
login_as :designer
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should require login for all actions" do
|
14
|
+
logout
|
15
|
+
lambda { get :index }.should require_login
|
16
|
+
lambda { get :new }.should require_login
|
17
|
+
lambda { get :edit, :id => 1 }.should require_login
|
18
|
+
lambda { post :create }.should require_login
|
19
|
+
lambda { put :update, :id => 1 }.should require_login
|
20
|
+
lambda { delete :destroy, :id => 1 }.should require_login
|
21
|
+
lambda { post :move_higher, :id => 1}.should require_login
|
22
|
+
lambda { post :move_lower, :id => 1}.should require_login
|
23
|
+
lambda { post :move_to_top, :id => 1}.should require_login
|
24
|
+
lambda { post :move_to_bottom, :id => 1}.should require_login
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "Access control" do
|
28
|
+
before :each do
|
29
|
+
@template = mock_model(Template, :save => true, :update_attributes => true,
|
30
|
+
:destroy => true, :move_to_top => true, :move_to_bottom => true,
|
31
|
+
:move_higher => true, :move_lower => true)
|
32
|
+
Template.stub!(:find).and_return(@template)
|
33
|
+
Template.stub!(:new).and_return(@template)
|
34
|
+
end
|
35
|
+
|
36
|
+
[:admin, :designer].each do |user|
|
37
|
+
describe "#{user} user" do
|
38
|
+
before :each do
|
39
|
+
login_as user
|
40
|
+
end
|
41
|
+
|
42
|
+
def redirects_to_index
|
43
|
+
response.should be_redirect
|
44
|
+
response.should redirect_to(admin_templates_path)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should have access to the index action' do
|
48
|
+
get :index
|
49
|
+
response.should be_success
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should have access to the new action' do
|
53
|
+
get :new
|
54
|
+
response.should be_success
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should have access to the create action' do
|
58
|
+
post :create
|
59
|
+
redirects_to_index
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should have access to the edit action' do
|
63
|
+
get :edit, :id => 1
|
64
|
+
response.should be_success
|
65
|
+
end
|
66
|
+
|
67
|
+
it "show should redirect to the edit action" do
|
68
|
+
get :show, :id => 1
|
69
|
+
response.should redirect_to(edit_admin_template_path(params[:id]))
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should have access to the update action' do
|
73
|
+
put :update, :id => 1
|
74
|
+
redirects_to_index
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should have access to the destroy action' do
|
78
|
+
delete :destroy, :id => 1
|
79
|
+
redirects_to_index
|
80
|
+
end
|
81
|
+
|
82
|
+
[:move_higher, :move_lower, :move_to_top, :move_to_bottom].each do |action|
|
83
|
+
it "should have access to the #{action} action" do
|
84
|
+
post action, :id => 1
|
85
|
+
redirects_to_index
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
[:existing, :non_admin].each do |user|
|
92
|
+
describe "#{user} user" do
|
93
|
+
before :each do
|
94
|
+
login_as user
|
95
|
+
end
|
96
|
+
|
97
|
+
def redirects_to_pages
|
98
|
+
response.should be_redirect
|
99
|
+
response.should redirect_to(admin_pages_path)
|
100
|
+
flash[:error].should == 'You must have designer privileges to perform this action.'
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should not have access to the index action' do
|
104
|
+
get :index
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should not have access to the new action' do
|
108
|
+
get :new
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should not have access to the create action' do
|
112
|
+
post :create
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should not have access to the edit action' do
|
116
|
+
get :edit, :id => 1
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should not have access to the update action' do
|
120
|
+
put :update, :id => 1
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should not have access to the destroy action' do
|
124
|
+
delete :destroy, :id => 1
|
125
|
+
end
|
126
|
+
|
127
|
+
[:move_higher, :move_lower, :move_to_top, :move_to_bottom].each do |action|
|
128
|
+
it "should not have access to the #{action} action" do
|
129
|
+
post action, :id => 1
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
after :each do
|
134
|
+
redirects_to_pages
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "GET to /admin/templates" do
|
141
|
+
before :each do
|
142
|
+
@template = mock_model(Template)
|
143
|
+
Template.should_receive(:find).with(:all).and_return([@template])
|
144
|
+
end
|
145
|
+
def do_get
|
146
|
+
get :index
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should load all templates" do
|
150
|
+
do_get
|
151
|
+
assigns[:content_templates].should == [@template]
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should render the index template" do
|
155
|
+
do_get
|
156
|
+
response.should render_template('index')
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "GET to /admin/templates/new" do
|
161
|
+
def do_get
|
162
|
+
get :new
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should load a new template" do
|
166
|
+
do_get
|
167
|
+
assigns[:content_template].should_not be_nil
|
168
|
+
assigns[:content_template].should be_new_record
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should render the new template" do
|
172
|
+
do_get
|
173
|
+
response.should render_template('new')
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "GET to /admin/templates/1/edit" do
|
178
|
+
before :each do
|
179
|
+
@template = mock_model(Template)
|
180
|
+
Template.should_receive(:find).with('1').and_return(@template)
|
181
|
+
end
|
182
|
+
|
183
|
+
def do_get
|
184
|
+
get :edit, :id => '1'
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should load the existing template" do
|
188
|
+
do_get
|
189
|
+
assigns[:content_template].should == @template
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should render the edit template" do
|
193
|
+
do_get
|
194
|
+
response.should render_template('edit')
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "POST to /admin/templates" do
|
199
|
+
before :each do
|
200
|
+
@template = mock_model(Template)
|
201
|
+
Template.should_receive(:new).and_return(@template)
|
202
|
+
end
|
203
|
+
|
204
|
+
def do_post
|
205
|
+
post :create
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "success path" do
|
209
|
+
before :each do
|
210
|
+
@template.should_receive(:save).and_return(true)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should redirect to the index" do
|
214
|
+
do_post
|
215
|
+
response.should redirect_to('/admin/templates')
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe "failure path" do
|
220
|
+
before :each do
|
221
|
+
@template.should_receive(:save).and_return(false)
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should add a flash error message" do
|
225
|
+
do_post
|
226
|
+
flash[:error].should be
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should render the new template again" do
|
230
|
+
do_post
|
231
|
+
response.should render_template('new')
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "PUT to /admin/templates/1" do
|
237
|
+
before :each do
|
238
|
+
@template = mock_model(Template)
|
239
|
+
Template.should_receive(:find).with('1').and_return(@template)
|
240
|
+
end
|
241
|
+
|
242
|
+
def do_put
|
243
|
+
put :update, :id => '1'
|
244
|
+
end
|
245
|
+
|
246
|
+
describe "success path" do
|
247
|
+
before :each do
|
248
|
+
@template.should_receive(:update_attributes).and_return(true)
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should redirect to the index" do
|
252
|
+
do_put
|
253
|
+
response.should redirect_to('/admin/templates')
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe "failure path" do
|
258
|
+
before :each do
|
259
|
+
@template.should_receive(:update_attributes).and_return(false)
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should add a flash error message" do
|
263
|
+
do_put
|
264
|
+
flash[:error].should be
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should render the edit template again" do
|
268
|
+
do_put
|
269
|
+
response.should render_template('edit')
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "DELETE to /admin/templates/1" do
|
275
|
+
before :each do
|
276
|
+
@template = mock_model(Template, :destroy => true)
|
277
|
+
Template.should_receive(:find).with('1').and_return(@template)
|
278
|
+
end
|
279
|
+
|
280
|
+
def do_delete
|
281
|
+
delete :destroy, :id => '1'
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should destroy the template" do
|
285
|
+
@template.should_receive(:destroy).and_return(true)
|
286
|
+
do_delete
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should redirect to the index" do
|
290
|
+
do_delete
|
291
|
+
response.should redirect_to('/admin/templates')
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
[:move_to_top, :move_to_bottom, :move_higher, :move_lower].each do |action|
|
296
|
+
describe "POST to /admin/templates/1/#{action}" do
|
297
|
+
before :each do
|
298
|
+
@template = mock_model(Template, action => true)
|
299
|
+
Template.should_receive(:find).with('1').and_return(@template)
|
300
|
+
end
|
301
|
+
|
302
|
+
define_method :do_post do
|
303
|
+
post action, :id => '1'
|
304
|
+
end
|
305
|
+
|
306
|
+
it "should call #{action} on the template" do
|
307
|
+
@template.should_receive(action).and_return(true)
|
308
|
+
do_post
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should redirect back to the index" do
|
312
|
+
do_post
|
313
|
+
response.should redirect_to('/admin/templates')
|
314
|
+
end
|
315
|
+
|
316
|
+
it "should register that templates are being reordered" do
|
317
|
+
Template.should_receive(:reordering)
|
318
|
+
do_post
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|