contentator 0.2.0
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.
- data/README.rdoc +45 -0
- data/test/factories.rb +40 -0
- data/test/functional/cms/admin/file_attachments_controller_test.rb +120 -0
- data/test/functional/cms/admin/page_content_blocks_controller_test.rb +159 -0
- data/test/functional/cms/admin/pages_controller_test.rb +164 -0
- data/test/functional/cms/content_controller_test.rb +43 -0
- data/test/performance/browsing_test.rb +9 -0
- data/test/test_helper.rb +12 -0
- data/test/unit/file_attachment_test.rb +33 -0
- data/test/unit/page_content_block_test.rb +40 -0
- data/test/unit/page_test.rb +103 -0
- metadata +84 -0
data/README.rdoc
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
== Contentator
|
2
|
+
|
3
|
+
Contentator is designed to be a flexible, light cms. Hopefully it won't get in your way and will give you an easy way to add inline content editing and navigation management.
|
4
|
+
|
5
|
+
== Install
|
6
|
+
|
7
|
+
For now build and install the gem with jeweler. It will be on gemcutter eventually
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
Create a new rails app with the contentator template
|
12
|
+
|
13
|
+
rails MY_APP -m YOUR_GEM_PATH/lib/template.rb
|
14
|
+
|
15
|
+
Then drop in a database.yml and fire up the database
|
16
|
+
|
17
|
+
rake db:create:all
|
18
|
+
rake db:migrate
|
19
|
+
rake db:test:prepare
|
20
|
+
|
21
|
+
Start the server and begin adding content. Go to /admin and begin adding pages.
|
22
|
+
|
23
|
+
== Custom Content
|
24
|
+
|
25
|
+
There is a generator for custom cms content types. It works much like a nested resource and creates inline editing.
|
26
|
+
|
27
|
+
script/generate content contact name:string email:string phone:string notes:text
|
28
|
+
|
29
|
+
The new content type will need to be wired up. To create a contacts template just make a new template in the page model, add an admin tool in views/cms/admin/_admin_toolbar.html.haml and create a view in views/cms/content.
|
30
|
+
|
31
|
+
== Globalization
|
32
|
+
|
33
|
+
The admin text all translatable. The english version is located in config/locales/en.yml. There is also a sample de.yml file for testing locales. Just add a new locale file to add other langauge support.
|
34
|
+
|
35
|
+
The globalization2 plugin is also installed. Dynamic content in pages and page content blocks can accept translations for any locale.
|
36
|
+
|
37
|
+
http://github.com/joshmh/globalize2
|
38
|
+
|
39
|
+
There is support for using locale subdomains already. See set_locale in the application controller. Add the following to /etc/hosts
|
40
|
+
|
41
|
+
127.0.0.1 en.localhost
|
42
|
+
127.0.0.1 de.localhost
|
43
|
+
|
44
|
+
The locale will automatically be set based on the subdomain.
|
45
|
+
|
data/test/factories.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
Factory.define :page do |f|
|
2
|
+
f.title 'Page'
|
3
|
+
f.subtitle 'Welcome to the website'
|
4
|
+
f.path 'page'
|
5
|
+
f.template_name 'content'
|
6
|
+
f.position 17
|
7
|
+
f.parent_id { Factory.next :parent_id }
|
8
|
+
f.visible true
|
9
|
+
f.in_navigation true
|
10
|
+
f.updated_at '2009-04-01 12:00:00'
|
11
|
+
end
|
12
|
+
|
13
|
+
Factory.sequence :parent_id do |n|
|
14
|
+
n
|
15
|
+
end
|
16
|
+
|
17
|
+
Factory.define :page_content_block do |f|
|
18
|
+
f.page_id { Factory(:page).id }
|
19
|
+
f.title 'Some content'
|
20
|
+
f.text 'lorem ipsum'
|
21
|
+
f.position 1
|
22
|
+
f.visible true
|
23
|
+
f.updated_at '2009-04-01 12:00:00'
|
24
|
+
end
|
25
|
+
|
26
|
+
Factory.define :file_attachment do |f|
|
27
|
+
f.owner_id { Factory(:page).id }
|
28
|
+
f.owner_type 'Page'
|
29
|
+
f.position 1
|
30
|
+
f.visible true
|
31
|
+
f.updated_at '2009-04-01 12:00:00'
|
32
|
+
end
|
33
|
+
|
34
|
+
Factory.define :other_file_attachment, :class => 'FileAttachment' do |f|
|
35
|
+
f.owner_id { Factory(:page).id }
|
36
|
+
f.owner_type 'Page'
|
37
|
+
f.position 2
|
38
|
+
f.visible true
|
39
|
+
f.updated_at '2009-04-01 12:00:00'
|
40
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../../..', 'test_helper')
|
2
|
+
|
3
|
+
class Cms::Admin::FileAttachmentsControllerTest < ActionController::TestCase
|
4
|
+
context "file attachment controller" do
|
5
|
+
setup do
|
6
|
+
@file_attachment = Factory(:file_attachment)
|
7
|
+
@page = Page.find(@file_attachment.owner_id)
|
8
|
+
@file_attachment2 = Factory(:file_attachment, :position => 17)
|
9
|
+
@file_attachment3 = Factory(:file_attachment, :position => 3)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "route" do
|
13
|
+
assert_recognizes(
|
14
|
+
{:controller => "cms/admin/file_attachments", :action => 'sort'},
|
15
|
+
{:path => '/admin/file_attachments/sort', :method => :post}
|
16
|
+
)
|
17
|
+
assert_recognizes(
|
18
|
+
{:controller => "cms/admin/file_attachments", :action => 'create'},
|
19
|
+
{:path => '/admin/file_attachments/', :method => :post}
|
20
|
+
)
|
21
|
+
assert_recognizes(
|
22
|
+
{:controller => "cms/admin/file_attachments", :action => 'new'},
|
23
|
+
{:path => '/admin/file_attachments/new', :method => :get}
|
24
|
+
)
|
25
|
+
assert_equal('/admin/file_attachments/sort', sort_cms_admin_file_attachments_path())
|
26
|
+
assert_equal('/admin/file_attachments', cms_admin_file_attachments_path )
|
27
|
+
assert_equal('/admin/file_attachments', cms_admin_file_attachments_path())
|
28
|
+
assert_equal('/admin/file_attachments/1', cms_admin_file_attachment_path(1))
|
29
|
+
end
|
30
|
+
|
31
|
+
context "on POST to :new" do
|
32
|
+
setup do
|
33
|
+
post :new, :page_id => @page.id, :owner_type => @page.class.to_s, :owner_id => @page.id
|
34
|
+
end
|
35
|
+
|
36
|
+
should_assign_to :page
|
37
|
+
should_assign_to :file_attachment
|
38
|
+
should_render_template :form
|
39
|
+
should_respond_with :success
|
40
|
+
end
|
41
|
+
|
42
|
+
context "stubbed valid file_attachment" do
|
43
|
+
setup do
|
44
|
+
FileAttachment.any_instance.stubs(:valid?).returns(true)
|
45
|
+
end
|
46
|
+
|
47
|
+
context "on POST to :create" do
|
48
|
+
setup do
|
49
|
+
post :create, :file_attachment => Factory.attributes_for(:file_attachment).merge(:owner_type => @page.class.to_s, :owner_id => @page.id, :page_id => @page.id)
|
50
|
+
end
|
51
|
+
|
52
|
+
should_change('the number of file_attachments', :by => 1 ) { FileAttachment.count }
|
53
|
+
should_assign_to :page
|
54
|
+
should_assign_to :owner
|
55
|
+
should_assign_to :file_attachment
|
56
|
+
should_render_template :file_attachments_container
|
57
|
+
should_respond_with :success
|
58
|
+
|
59
|
+
should "save to db" do
|
60
|
+
assert !assigns(:file_attachment).new_record?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "stubbed invalid page content block" do
|
66
|
+
setup do
|
67
|
+
FileAttachment.any_instance.stubs(:valid?).returns(false)
|
68
|
+
end
|
69
|
+
|
70
|
+
context "on POST to :create" do
|
71
|
+
setup do
|
72
|
+
post :create, :file_attachment => Factory.attributes_for(:file_attachment).merge(:owner_type => @page.class.to_s, :owner_id => @page.id, :page_id => @page.id)
|
73
|
+
end
|
74
|
+
|
75
|
+
should_not_change('the number of file_attachments') {FileAttachment.count}
|
76
|
+
should_assign_to :page
|
77
|
+
should_assign_to :owner
|
78
|
+
should_assign_to :file_attachment
|
79
|
+
should_render_template :form
|
80
|
+
should_respond_with :success
|
81
|
+
|
82
|
+
should "not save to db" do
|
83
|
+
assert assigns(:file_attachment).new_record?
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "on DELETE to :destroy" do
|
89
|
+
setup { get :destroy, :id => @file_attachment.id, :page_id => @page.id }
|
90
|
+
|
91
|
+
should_change('the number of page content blocks', :by => -1 ) { FileAttachment.count }
|
92
|
+
should_assign_to :page
|
93
|
+
should_assign_to :file_attachment
|
94
|
+
should_render_template :file_attachments_container
|
95
|
+
should_respond_with :success
|
96
|
+
end
|
97
|
+
|
98
|
+
context "on POST to :sort" do
|
99
|
+
should "sort file_attachment content blocks" do
|
100
|
+
assert_equal 1, @file_attachment.position
|
101
|
+
assert_equal 17, @file_attachment2.position
|
102
|
+
assert_equal 3, @file_attachment3.position
|
103
|
+
end
|
104
|
+
|
105
|
+
setup do
|
106
|
+
post :sort, :page_id => @page.id, :file_attachment => [@file_attachment3.id, @file_attachment.id, @file_attachment2.id ]
|
107
|
+
end
|
108
|
+
|
109
|
+
should "sort file_attachment content blocks" do
|
110
|
+
assert_equal 1, @file_attachment.reload.position
|
111
|
+
assert_equal 2, @file_attachment2.reload.position
|
112
|
+
assert_equal 0, @file_attachment3.reload.position
|
113
|
+
end
|
114
|
+
|
115
|
+
should_assign_to :page
|
116
|
+
should_render_without_layout()
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../../..', 'test_helper')
|
2
|
+
|
3
|
+
class Cms::Admin::PageContentBlocksControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@page_content_block = Factory(:page_content_block)
|
7
|
+
@page = Page.find(@page_content_block.page_id)
|
8
|
+
@page_content_block2 = Factory(:page_content_block, :position => 17, :page_id => @page.id)
|
9
|
+
@page_content_block3 = Factory(:page_content_block, :position => 3, :page_id => @page.id)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "route" do
|
13
|
+
assert_recognizes(
|
14
|
+
{:controller => "cms/admin/page_content_blocks", :action => 'sort'},
|
15
|
+
{:path => '/admin/page_content_blocks/sort', :method => :post}
|
16
|
+
)
|
17
|
+
assert_recognizes(
|
18
|
+
{:controller => "cms/admin/page_content_blocks", :action => 'create'},
|
19
|
+
{:path => '/admin/page_content_blocks/', :method => :post}
|
20
|
+
)
|
21
|
+
assert_recognizes(
|
22
|
+
{:controller => "cms/admin/page_content_blocks", :action => 'new'},
|
23
|
+
{:path => '/admin/page_content_blocks/new', :method => :get}
|
24
|
+
)
|
25
|
+
assert_recognizes(
|
26
|
+
{:controller => "cms/admin/page_content_blocks", :action => 'edit', :id => '1'},
|
27
|
+
{:path => '/admin/page_content_blocks/1/edit', :method => :get}
|
28
|
+
)
|
29
|
+
assert_recognizes(
|
30
|
+
{:controller => "cms/admin/page_content_blocks", :action => 'update', :id => '1'},
|
31
|
+
{:path => '/admin/page_content_blocks/1', :method => :put}
|
32
|
+
)
|
33
|
+
assert_equal('/admin/page_content_blocks/sort', sort_cms_admin_page_content_blocks_path())
|
34
|
+
assert_equal('/admin/page_content_blocks', cms_admin_page_content_blocks_path())
|
35
|
+
assert_equal('/admin/page_content_blocks/new', new_cms_admin_page_content_block_path())
|
36
|
+
assert_equal('/admin/page_content_blocks/1/edit', edit_cms_admin_page_content_block_path(1))
|
37
|
+
assert_equal('/admin/page_content_blocks/1', cms_admin_page_content_block_path(1))
|
38
|
+
end
|
39
|
+
|
40
|
+
context "on POST to :new" do
|
41
|
+
setup do
|
42
|
+
post :new, :page_id => @page.id
|
43
|
+
end
|
44
|
+
|
45
|
+
should_assign_to :page
|
46
|
+
should_assign_to :page_content_block
|
47
|
+
should_render_template :form
|
48
|
+
should_respond_with :success
|
49
|
+
end
|
50
|
+
|
51
|
+
context "on GET to :edit" do
|
52
|
+
setup { get :edit, :id => @page_content_block.id }
|
53
|
+
|
54
|
+
should_assign_to :page
|
55
|
+
should_assign_to :page_content_block
|
56
|
+
should_render_template :form
|
57
|
+
should_respond_with :success
|
58
|
+
end
|
59
|
+
|
60
|
+
context "stubbed valid page content block" do
|
61
|
+
setup do
|
62
|
+
PageContentBlock.any_instance.stubs(:valid?).returns(true)
|
63
|
+
end
|
64
|
+
|
65
|
+
context "on POST to :create" do
|
66
|
+
setup do
|
67
|
+
post :create, :page_content_block => Factory.attributes_for(:page_content_block), :page_id => @page.id
|
68
|
+
end
|
69
|
+
|
70
|
+
should_change('the number of page content blocks', :by => 1 ) { PageContentBlock.count }
|
71
|
+
should_assign_to :page
|
72
|
+
should_assign_to :page_content_block
|
73
|
+
should_render_template :page_content_blocks_container
|
74
|
+
should_respond_with :success
|
75
|
+
|
76
|
+
should "save to db" do
|
77
|
+
assert !assigns(:page_content_block).new_record?
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "on PUT to :update" do
|
82
|
+
setup do
|
83
|
+
put :update, :id => @page_content_block.id, :page_content_block => { :title => 'new title' }
|
84
|
+
end
|
85
|
+
|
86
|
+
should_assign_to :page
|
87
|
+
should_assign_to :page_content_block
|
88
|
+
should_render_template :page_content_blocks_container
|
89
|
+
should_respond_with :success
|
90
|
+
should_change('page_content_block updated' ) { @page_content_block.reload.updated_at }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "stubbed invalid page content block" do
|
95
|
+
setup do
|
96
|
+
PageContentBlock.any_instance.stubs(:valid?).returns(false)
|
97
|
+
end
|
98
|
+
|
99
|
+
context "on POST to :create" do
|
100
|
+
setup do
|
101
|
+
post :create, :page_content_block => Factory.attributes_for(:page_content_block, :page_id => @page.id)
|
102
|
+
end
|
103
|
+
|
104
|
+
should_not_change('the number of page_content_blocks') {PageContentBlock.count}
|
105
|
+
should_assign_to :page
|
106
|
+
should_assign_to :page_content_block
|
107
|
+
should_render_template :form
|
108
|
+
should_respond_with :success
|
109
|
+
|
110
|
+
should "not save to db" do
|
111
|
+
assert assigns(:page_content_block).new_record?
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "on PUT to :update" do
|
116
|
+
setup do
|
117
|
+
put :update, :id => @page_content_block.id, :page_content_block => { :updated_at => Time.now }
|
118
|
+
end
|
119
|
+
|
120
|
+
should_not_change('page_content_block updated' ) { PageContentBlock.find(@page_content_block.id).updated_at }
|
121
|
+
should_assign_to :page
|
122
|
+
should_assign_to :page_content_block
|
123
|
+
should_render_template :form
|
124
|
+
should_respond_with :success
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "on DELETE to :destroy" do
|
129
|
+
setup { get :destroy, :id => @page_content_block.id }
|
130
|
+
|
131
|
+
should_change('the number of page content blocks', :by => -1 ) { PageContentBlock.count }
|
132
|
+
should_assign_to :page
|
133
|
+
should_assign_to :page_content_block
|
134
|
+
should_render_template :page_content_blocks_container
|
135
|
+
should_respond_with :success
|
136
|
+
end
|
137
|
+
|
138
|
+
context "on POST to :sort" do
|
139
|
+
should "sort page content blocks" do
|
140
|
+
assert_equal 1, @page_content_block.position
|
141
|
+
assert_equal 17, @page_content_block2.position
|
142
|
+
assert_equal 3, @page_content_block3.position
|
143
|
+
end
|
144
|
+
|
145
|
+
setup do
|
146
|
+
post :sort, :page_id => @page.id, :page_content_block => [ @page_content_block3.id, @page_content_block.id, @page_content_block2.id ]
|
147
|
+
end
|
148
|
+
|
149
|
+
should "sort page content blocks" do
|
150
|
+
assert_equal 1, @page_content_block.reload.position
|
151
|
+
assert_equal 2, @page_content_block2.reload.position
|
152
|
+
assert_equal 0, @page_content_block3.reload.position
|
153
|
+
end
|
154
|
+
|
155
|
+
should_assign_to :page
|
156
|
+
should_render_without_layout()
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../../..', 'test_helper')
|
2
|
+
|
3
|
+
class Cms::Admin::PagesControllerTest < ActionController::TestCase
|
4
|
+
context "page controller" do
|
5
|
+
setup do
|
6
|
+
@home_page = Factory(:page, :id => 1, :slug => 'home', :path => 'home', :template_name => 'home', :parent_id => nil)
|
7
|
+
@page = Factory(:page, :parent_id => @home_page.id, :position => 2)
|
8
|
+
@child1 = Factory(:page, :title => 'Child 1', :parent_id => @page.id, :position => 3)
|
9
|
+
@child2 = Factory(:page, :title => 'Child 2', :parent_id => @page.id, :position => 4)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "route" do
|
13
|
+
assert_recognizes(
|
14
|
+
{:controller => "cms/admin/pages", :action => 'index'},
|
15
|
+
{:path => '/admin/pages', :method => :get}
|
16
|
+
)
|
17
|
+
assert_recognizes(
|
18
|
+
{:controller => "cms/admin/pages", :action => 'create'},
|
19
|
+
{:path => '/admin/pages/', :method => :post}
|
20
|
+
)
|
21
|
+
assert_recognizes(
|
22
|
+
{:controller => "cms/admin/pages", :action => 'new'},
|
23
|
+
{:path => '/admin/pages/new', :method => :get}
|
24
|
+
)
|
25
|
+
assert_recognizes(
|
26
|
+
{:controller => "cms/admin/pages", :action => 'edit', :id => '1'},
|
27
|
+
{:path => '/admin/pages/1/edit', :method => :get}
|
28
|
+
)
|
29
|
+
assert_recognizes(
|
30
|
+
{:controller => "cms/admin/pages", :action => 'update', :id => '1'},
|
31
|
+
{:path => '/admin/pages/1', :method => :put}
|
32
|
+
)
|
33
|
+
assert_recognizes(
|
34
|
+
{:controller => "cms/admin/pages", :action => 'update_page_tree'},
|
35
|
+
{:path => '/admin/pages/update_page_tree', :method => :get}
|
36
|
+
)
|
37
|
+
assert_equal('/admin/pages', cms_admin_pages_path )
|
38
|
+
assert_equal('/admin/pages', cms_admin_pages_path())
|
39
|
+
assert_equal('/admin/pages/new', new_cms_admin_page_path())
|
40
|
+
assert_equal('/admin/pages/1/edit', edit_cms_admin_page_path(1))
|
41
|
+
assert_equal('/admin/pages/1', cms_admin_page_path(1))
|
42
|
+
assert_equal('/admin/pages/update_page_tree', update_page_tree_cms_admin_pages_path())
|
43
|
+
end
|
44
|
+
|
45
|
+
context "on GET to :index" do
|
46
|
+
setup { get :index }
|
47
|
+
|
48
|
+
should_assign_to :pages
|
49
|
+
should_respond_with :success
|
50
|
+
should_render_template :index
|
51
|
+
should_not_set_the_flash
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
context "on GET to :new" do
|
56
|
+
setup { get :new }
|
57
|
+
|
58
|
+
should_assign_to :page
|
59
|
+
should_respond_with :success
|
60
|
+
should_render_template 'admin/pages/new'
|
61
|
+
end
|
62
|
+
|
63
|
+
context "on GET to :edit" do
|
64
|
+
setup { get :edit, :id => @page.id }
|
65
|
+
|
66
|
+
should_assign_to :page
|
67
|
+
should_respond_with :success
|
68
|
+
should_render_template 'admin/pages/edit'
|
69
|
+
end
|
70
|
+
|
71
|
+
context "stubbed valid page" do
|
72
|
+
setup do
|
73
|
+
Page.any_instance.stubs(:valid?).returns(true)
|
74
|
+
end
|
75
|
+
|
76
|
+
context "on POST to :create" do
|
77
|
+
setup do
|
78
|
+
post :create, :page => Factory.attributes_for(:page)
|
79
|
+
end
|
80
|
+
|
81
|
+
should_change('the number of pages', :by => 1 ) { Page.count }
|
82
|
+
should_assign_to :page
|
83
|
+
should_redirect_to('cms_admin_pages_path') { cms_admin_pages_path }
|
84
|
+
|
85
|
+
should "save to db" do
|
86
|
+
assert !assigns(:page).new_record?
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "on PUT to :update" do
|
91
|
+
setup do
|
92
|
+
put :update, :id => @page.id, :page => { :title => 'new title', :subtitle => 'here we are', :template_name => 'gallery' }
|
93
|
+
end
|
94
|
+
|
95
|
+
should_assign_to :page
|
96
|
+
should_change('page updated' ) { @page.reload.updated_at }
|
97
|
+
should_redirect_to('cms_admin_pages_path') { cms_admin_pages_path }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "stubbed invalid page" do
|
102
|
+
setup do
|
103
|
+
Page.any_instance.stubs(:valid?).returns(false)
|
104
|
+
end
|
105
|
+
|
106
|
+
context "on POST to :create" do
|
107
|
+
setup do
|
108
|
+
post :create, :page => Factory.attributes_for(:page)
|
109
|
+
end
|
110
|
+
|
111
|
+
should_not_change('the number of pages') {Page.count}
|
112
|
+
should_assign_to :page
|
113
|
+
should_render_template 'admin/pages/new'
|
114
|
+
|
115
|
+
should "not save to db" do
|
116
|
+
assert assigns(:page).new_record?
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "on PUT to :update" do
|
121
|
+
setup do
|
122
|
+
put :update, :id => @page.id, :page => { :updated_at => Time.now }
|
123
|
+
end
|
124
|
+
|
125
|
+
should_not_change('page updated' ) { Page.find(@page.id).updated_at }
|
126
|
+
should_assign_to :page
|
127
|
+
should_render_template 'admin/pages/edit'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# must not be a parent of anything
|
132
|
+
context "on DELETE to :destroy" do
|
133
|
+
setup { get :destroy, :id => @child2.id }
|
134
|
+
|
135
|
+
should_change('the number of pages', :by => -1 ) { Page.count }
|
136
|
+
should_assign_to :page
|
137
|
+
should_redirect_to('cms_admin_pages_path') { cms_admin_pages_path }
|
138
|
+
end
|
139
|
+
|
140
|
+
context "on POST to update_page_tree" do
|
141
|
+
setup do
|
142
|
+
assert_equal 2, @page.position
|
143
|
+
assert_equal 3, @child1.position
|
144
|
+
assert_equal 4, @child2.position
|
145
|
+
assert_equal @page.id, @child1.parent_id
|
146
|
+
assert_equal @page.id, @child2.parent_id
|
147
|
+
|
148
|
+
post :update_page_tree,
|
149
|
+
:tree_root => {"0"=>{"id"=>"#{@home_page.id}", "0"=>{"0"=>{"id"=>"#{@child2.id}"}, "id"=>"#{@page.id}", "1"=>{"id"=>"#{@child1.id}"}}}}
|
150
|
+
end
|
151
|
+
should_respond_with :success
|
152
|
+
|
153
|
+
should "sort tree" do
|
154
|
+
assert_equal 1, @home_page.reload.position
|
155
|
+
assert_equal 2, @page.reload.position
|
156
|
+
assert_equal 4, @child1.reload.position
|
157
|
+
assert_equal 3, @child2.reload.position
|
158
|
+
assert_equal @page.id, @child1.reload.parent_id
|
159
|
+
assert_equal @page.id, @child2.reload.parent_id
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../..', 'test_helper')
|
2
|
+
|
3
|
+
class Cms::ContentControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@home_page = Factory(:page, :id => 1, :slug => 'home', :path => 'home', :template_name => 'home')
|
7
|
+
@page = Factory(:page)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "route" do
|
11
|
+
assert_recognizes(
|
12
|
+
{:controller => "cms/content", :action => 'show', :path => ['anything']},
|
13
|
+
{:path => '/anything', :method => :get}
|
14
|
+
)
|
15
|
+
assert_equal('/anything', content_path('anything'))
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'GET show' do
|
19
|
+
setup { get :show, :path => [@page.path]}
|
20
|
+
should_respond_with :success
|
21
|
+
should_not_set_the_flash
|
22
|
+
should("assign to @page") { assert_equal assigns(:page), @page }
|
23
|
+
should_render_template :content
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'GET show (404)' do
|
27
|
+
setup { get :show, :path => ['nonexistant', 'path']}
|
28
|
+
should_respond_with :missing
|
29
|
+
should_not_set_the_flash
|
30
|
+
should_render_template "#{RAILS_ROOT}/public/404.html"
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'GET show (home)' do
|
34
|
+
setup do
|
35
|
+
get :show, :path => [@home_page.path]
|
36
|
+
end
|
37
|
+
should_respond_with :success
|
38
|
+
should_not_set_the_flash
|
39
|
+
should("assign to @page") { assert_equal assigns(:page), @home_page }
|
40
|
+
should_render_template :home
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
+
require 'test_help'
|
4
|
+
require 'shoulda'
|
5
|
+
require 'mocha'
|
6
|
+
|
7
|
+
class ActiveSupport::TestCase
|
8
|
+
def deny(condition)
|
9
|
+
assert ! condition
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FileAttachmentTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
# Setup
|
6
|
+
def setup
|
7
|
+
@file_attachment = Factory(:file_attachment)
|
8
|
+
@page = Page.find(@file_attachment.owner_id)
|
9
|
+
@other_file_attachment = Factory(:other_file_attachment, :owner_id => @page.id)
|
10
|
+
end
|
11
|
+
subject { @file_attachment }
|
12
|
+
|
13
|
+
# Database
|
14
|
+
should_have_db_column :owner_id, :type => :integer
|
15
|
+
should_have_db_column :owner_type, :type => :string
|
16
|
+
should_have_db_column :position, :type => :integer
|
17
|
+
should_have_db_column :visible, :type => :boolean
|
18
|
+
should_have_db_column :file_file_name, :type => :string
|
19
|
+
should_have_db_column :file_content_type, :type => :string
|
20
|
+
should_have_db_column :file_file_size, :type => :integer
|
21
|
+
should_have_db_column :created_at, :type => :datetime
|
22
|
+
should_have_db_column :updated_at, :type => :datetime
|
23
|
+
|
24
|
+
# Relationships
|
25
|
+
should_belong_to :owner
|
26
|
+
|
27
|
+
# Validations
|
28
|
+
|
29
|
+
should "be ordered from owner" do
|
30
|
+
assert_equal [@file_attachment, @other_file_attachment], @page.file_attachments
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PageContentBlockTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
# Setup
|
6
|
+
def setup
|
7
|
+
@page_content_block = Factory(:page_content_block)
|
8
|
+
@page = Page.find(@page_content_block.page_id)
|
9
|
+
@page_content_block2 = Factory(:page_content_block, :page_id => @page.id, :position => 2)
|
10
|
+
@page_content_block3 = Factory(:page_content_block, :page_id => @page.id, :position => 3, :visible => false)
|
11
|
+
end
|
12
|
+
subject { @page_content_block }
|
13
|
+
|
14
|
+
# Database
|
15
|
+
should_have_db_column :page_id, :type => :integer
|
16
|
+
should_have_db_column :title, :type => :string
|
17
|
+
should_have_db_column :text, :type => :text
|
18
|
+
should_have_db_column :position, :type => :integer
|
19
|
+
should_have_db_column :visible, :type => :boolean
|
20
|
+
should_have_db_column :photo_file_name, :type => :string
|
21
|
+
should_have_db_column :photo_content_type, :type => :string
|
22
|
+
should_have_db_column :photo_file_size, :type => :integer
|
23
|
+
should_have_db_column :created_at, :type => :datetime
|
24
|
+
should_have_db_column :updated_at, :type => :datetime
|
25
|
+
|
26
|
+
# Relationships
|
27
|
+
should_belong_to :page
|
28
|
+
should_have_many :file_attachments
|
29
|
+
|
30
|
+
# Validations
|
31
|
+
|
32
|
+
should "show visible" do
|
33
|
+
assert_equal [@page_content_block, @page_content_block2], PageContentBlock.visible.all
|
34
|
+
end
|
35
|
+
|
36
|
+
should "be ordered from page" do
|
37
|
+
assert_equal [@page_content_block, @page_content_block2, @page_content_block3], @page.page_content_blocks
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PageTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
# Setup
|
6
|
+
def setup
|
7
|
+
@home_page = Factory(:page, :slug => 'home', :path => 'home', :template_name => 'home', :parent_id => nil, :position => 34)
|
8
|
+
Page.stubs(:home_page).returns(@home_page)
|
9
|
+
@home_page.parent_id = nil
|
10
|
+
@page = Factory(:page)
|
11
|
+
@child = Factory(:page, :title => 'Child', :parent_id => @page.id, :visible => false, :position => 16)
|
12
|
+
end
|
13
|
+
subject { @page }
|
14
|
+
|
15
|
+
# Database
|
16
|
+
should_have_db_column :template_name, :type => :string
|
17
|
+
should_have_db_column :title, :type => :string
|
18
|
+
should_have_db_column :subtitle, :type => :string
|
19
|
+
should_have_db_column :slug, :type => :string
|
20
|
+
should_have_db_column :path, :type => :string
|
21
|
+
should_have_db_column :position, :type => :integer
|
22
|
+
should_have_db_column :parent_id, :type => :integer
|
23
|
+
should_have_db_column :visible, :type => :boolean
|
24
|
+
should_have_db_column :in_navigation, :type => :boolean
|
25
|
+
should_have_db_column :created_at, :type => :datetime
|
26
|
+
should_have_db_column :updated_at, :type => :datetime
|
27
|
+
|
28
|
+
# Relationships
|
29
|
+
should_have_many :page_content_blocks
|
30
|
+
should_have_many :file_attachments
|
31
|
+
|
32
|
+
# Validations
|
33
|
+
should_validate_presence_of :title
|
34
|
+
|
35
|
+
should "have templates home, content and gallery" do
|
36
|
+
assert Page::TEMPLATES.include?('home')
|
37
|
+
assert Page::TEMPLATES.include?('content')
|
38
|
+
assert Page::TEMPLATES.include?('gallery')
|
39
|
+
end
|
40
|
+
|
41
|
+
should "act_as_tree" do
|
42
|
+
assert_equal [@child], @page.children
|
43
|
+
end
|
44
|
+
|
45
|
+
should "find home page" do
|
46
|
+
home = Page.home_page
|
47
|
+
assert_equal 'home', home.slug
|
48
|
+
end
|
49
|
+
|
50
|
+
should "find a page with a path" do
|
51
|
+
test_page = Page.find_from_path(@page.path.split('/'))
|
52
|
+
assert_equal @page, test_page
|
53
|
+
end
|
54
|
+
|
55
|
+
should "return nil if path not found" do
|
56
|
+
page = Page.find_from_path(['a', 'nonexistant', 'path'])
|
57
|
+
deny page
|
58
|
+
end
|
59
|
+
|
60
|
+
should "not destroy if children" do
|
61
|
+
@page.destroy
|
62
|
+
assert @page
|
63
|
+
assert @page.errors.on_base.include?('Cannot delete page with children. Please delete children first.')
|
64
|
+
end
|
65
|
+
|
66
|
+
should "not destroy if home page" do
|
67
|
+
@home_page.destroy
|
68
|
+
assert @home_page
|
69
|
+
assert @home_page.errors.on_base.include?('Cannot delete home page.')
|
70
|
+
end
|
71
|
+
|
72
|
+
should "have parent slug in path" do
|
73
|
+
assert_equal "#{@page.path}/#{@child.slug}", @child.path
|
74
|
+
end
|
75
|
+
|
76
|
+
should "have templates constant of type array" do
|
77
|
+
assert_equal Array, Page::TEMPLATES.class
|
78
|
+
assert Page::TEMPLATES.length > 0
|
79
|
+
end
|
80
|
+
|
81
|
+
should "show visible" do
|
82
|
+
assert_equal [@home_page, @page], Page.visible.all
|
83
|
+
end
|
84
|
+
|
85
|
+
should "be ordered" do
|
86
|
+
assert_equal [@child, @page, @home_page], Page.ordered.all
|
87
|
+
end
|
88
|
+
|
89
|
+
should "not set parent_id of home page" do
|
90
|
+
assert_equal nil, @home_page.parent_id
|
91
|
+
@home_page.save
|
92
|
+
assert_equal nil, @home_page.parent_id
|
93
|
+
@home_page.update_attributes(:parent_id => 2)
|
94
|
+
assert_equal nil, @home_page.parent_id
|
95
|
+
end
|
96
|
+
|
97
|
+
should "not allow parent_id to be null" do
|
98
|
+
@page.parent_id = nil
|
99
|
+
@page.save
|
100
|
+
deny @page.reload.parent_id.nil?
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: contentator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Craig Partin
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-07 00:00:00 -06:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: haml
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 2
|
30
|
+
- 6
|
31
|
+
version: 2.2.6
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: A lightweight cms that focuses on in place editing.
|
35
|
+
email: cpartin@gmail.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- README.rdoc
|
42
|
+
files:
|
43
|
+
- README.rdoc
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/cpartin/contentator
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options:
|
50
|
+
- --charset=UTF-8
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.3.6
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: A lightweight cms that focuses on in place editing.
|
74
|
+
test_files:
|
75
|
+
- test/factories.rb
|
76
|
+
- test/functional/cms/admin/file_attachments_controller_test.rb
|
77
|
+
- test/functional/cms/admin/page_content_blocks_controller_test.rb
|
78
|
+
- test/functional/cms/admin/pages_controller_test.rb
|
79
|
+
- test/functional/cms/content_controller_test.rb
|
80
|
+
- test/performance/browsing_test.rb
|
81
|
+
- test/test_helper.rb
|
82
|
+
- test/unit/file_attachment_test.rb
|
83
|
+
- test/unit/page_content_block_test.rb
|
84
|
+
- test/unit/page_test.rb
|