typus 0.9.29 → 0.9.30
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -54
- data/VERSION +1 -1
- data/app/controllers/admin/master_controller.rb +36 -18
- data/app/helpers/admin/form_helper.rb +40 -7
- data/app/helpers/admin/table_helper.rb +6 -17
- data/app/views/admin/resources/show.html.erb +1 -2
- data/app/views/admin/templates/_file.html.erb +2 -40
- data/app/views/layouts/admin.html.erb +3 -0
- data/config/locales/de.yml +0 -1
- data/config/locales/es.yml +0 -1
- data/config/locales/fr.yml +0 -1
- data/config/locales/language.yml.template +0 -1
- data/config/locales/pt-BR.yml +0 -1
- data/config/locales/ru.yml +0 -1
- data/generators/typus/templates/public/stylesheets/admin/screen.css +1 -1
- data/generators/typus/typus_generator.rb +1 -1
- data/lib/typus/preview.rb +66 -2
- data/tasks/typus_tasks.rake +0 -2
- data/test/config/working/application.yml +9 -3
- data/test/config/working/application_roles.yml +3 -1
- data/test/fixtures/app/views/admin/{comments → posts}/_edit.html.erb +0 -0
- data/test/fixtures/app/views/admin/{comments → posts}/_index.html.erb +0 -0
- data/test/fixtures/app/views/admin/{comments → posts}/_new.html.erb +0 -0
- data/test/fixtures/app/views/admin/{comments → posts}/_show.html.erb +0 -0
- data/test/fixtures/app/views/admin/{comments → posts}/_sidebar.html.erb +0 -0
- data/test/functional/admin/{assets_controller_test.rb → master_controller_assets_relationships.rb} +23 -13
- data/test/functional/admin/master_controller_categories_lists_test.rb +64 -0
- data/test/functional/admin/master_controller_posts_before_test.rb +10 -0
- data/test/functional/admin/master_controller_posts_crud_test.rb +97 -0
- data/test/functional/admin/master_controller_posts_formats_test.rb +59 -0
- data/test/functional/admin/master_controller_posts_permissions_test.rb +127 -0
- data/test/functional/admin/master_controller_posts_relationships_test.rb +86 -0
- data/test/functional/admin/master_controller_posts_roles.rb +50 -0
- data/test/functional/admin/master_controller_posts_toggle_test.rb +35 -0
- data/test/functional/admin/master_controller_posts_views_test.rb +209 -0
- data/test/functional/admin/{status_controller_test.rb → master_controller_tableless_resource_test.rb} +5 -11
- data/test/functional/admin/{typus_users_controller_test.rb → master_controller_typus_users_test.rb} +10 -37
- data/test/functional/typus_controller_test.rb +154 -136
- data/test/helpers/admin/form_helper_test.rb +49 -27
- data/test/helpers/admin/sidebar_helper_test.rb +4 -7
- data/test/lib/active_record_test.rb +8 -8
- data/test/lib/typus_test.rb +1 -1
- data/test/models.rb +8 -1
- data/test/schema.rb +6 -0
- data/test/unit/typus_user_roles_test.rb +4 -4
- data/typus.gemspec +31 -21
- metadata +31 -21
- data/test/functional/admin/categories_controller_test.rb +0 -105
- data/test/functional/admin/comments_controller_test.rb +0 -121
- data/test/functional/admin/master_controller_test.rb +0 -51
- data/test/functional/admin/posts_controller_test.rb +0 -300
data/lib/typus/preview.rb
CHANGED
@@ -2,9 +2,73 @@ module Typus
|
|
2
2
|
|
3
3
|
module InstanceMethods
|
4
4
|
|
5
|
-
|
5
|
+
include ActionView::Helpers::UrlHelper
|
6
|
+
|
7
|
+
# OPTIMIZE
|
8
|
+
def typus_preview_on_table(attribute)
|
9
|
+
|
10
|
+
attachment = attribute.split('_file_name').first
|
6
11
|
file_preview = Typus::Configuration.options[:file_preview]
|
7
|
-
|
12
|
+
file_thumbnail = Typus::Configuration.options[:file_thumbnail]
|
13
|
+
|
14
|
+
if send(attachment).styles.member?(file_preview) && send("#{attachment}_content_type") =~ /^image\/.+/
|
15
|
+
<<-HTML
|
16
|
+
<script type="text/javascript" charset="utf-8">
|
17
|
+
$(document).ready(function() { $("##{to_dom}").fancybox(); });
|
18
|
+
</script>
|
19
|
+
<a id="#{to_dom}" href="#{send(attachment).url(file_preview)}">#{send(attribute)}</a>
|
20
|
+
HTML
|
21
|
+
else
|
22
|
+
<<-HTML
|
23
|
+
<a href="#{send(attachment).url}">#{send(attribute)}</a>
|
24
|
+
HTML
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# OPTIMIZE
|
29
|
+
def typus_preview(attribute)
|
30
|
+
|
31
|
+
attachment = attribute.split('_file_name').first
|
32
|
+
|
33
|
+
case send("#{attachment}_content_type")
|
34
|
+
when /^image\/.+/
|
35
|
+
file_preview = Typus::Configuration.options[:file_preview]
|
36
|
+
file_thumbnail = Typus::Configuration.options[:file_thumbnail]
|
37
|
+
if send(attachment).styles.member?(file_preview) && send(attachment).styles.member?(file_thumbnail)
|
38
|
+
<<-HTML
|
39
|
+
<script type="text/javascript" charset="utf-8">
|
40
|
+
$(document).ready(function() { $("##{to_dom}").fancybox(); });
|
41
|
+
</script>
|
42
|
+
<a id="#{to_dom}" href="#{send(attachment).url(file_preview)}" title="#{typus_name}">
|
43
|
+
<img src="#{send(attachment).url(file_thumbnail)}" />
|
44
|
+
</a>
|
45
|
+
HTML
|
46
|
+
elsif send(attachment).styles.member?(file_thumbnail)
|
47
|
+
<<-HTML
|
48
|
+
<a href="#{send(attachment).url}" title="#{typus_name}">
|
49
|
+
<img src="#{send(attachment).url(file_thumbnail)}" />
|
50
|
+
</a>
|
51
|
+
HTML
|
52
|
+
elsif send(attachment).styles.member?(file_preview)
|
53
|
+
<<-HTML
|
54
|
+
<script type="text/javascript" charset="utf-8">
|
55
|
+
$(document).ready(function() { $("##{to_dom}").fancybox(); });
|
56
|
+
</script>
|
57
|
+
<a id="#{to_dom}" href="#{send(attachment).url(file_preview)}" title="#{typus_name}">
|
58
|
+
#{send(attribute)}
|
59
|
+
</a>
|
60
|
+
HTML
|
61
|
+
else
|
62
|
+
<<-HTML
|
63
|
+
<a href="#{send(attachment).url}">#{send(attribute)}</a>
|
64
|
+
HTML
|
65
|
+
end
|
66
|
+
else
|
67
|
+
<<-HTML
|
68
|
+
<a href="#{send(attachment).url}">#{send(attribute)}</a>
|
69
|
+
HTML
|
70
|
+
end
|
71
|
+
|
8
72
|
end
|
9
73
|
|
10
74
|
end
|
data/tasks/typus_tasks.rake
CHANGED
@@ -44,6 +44,8 @@ Post:
|
|
44
44
|
list: title, created_at, status
|
45
45
|
form: title, body, created_at, status, published_at
|
46
46
|
relationship: title, created_at
|
47
|
+
csv: title, status
|
48
|
+
xml: title, status
|
47
49
|
options:
|
48
50
|
selectors: status
|
49
51
|
read_only: permalink
|
@@ -52,7 +54,7 @@ Post:
|
|
52
54
|
created_at: post_short
|
53
55
|
templates:
|
54
56
|
published_at: datepicker
|
55
|
-
relationships: assets, categories
|
57
|
+
relationships: assets, categories, comments, views
|
56
58
|
actions:
|
57
59
|
index: cleanup
|
58
60
|
edit: send_as_newsletter, preview
|
@@ -60,9 +62,13 @@ Post:
|
|
60
62
|
search: title
|
61
63
|
order_by: title, -created_at
|
62
64
|
application: Blog
|
65
|
+
export: csv, xml
|
63
66
|
|
64
67
|
CustomUser:
|
65
68
|
fields:
|
66
69
|
list: first_name, last_name, email
|
67
|
-
|
68
|
-
|
70
|
+
|
71
|
+
View:
|
72
|
+
fields:
|
73
|
+
list: ip, post
|
74
|
+
form: ip, post
|
@@ -8,6 +8,7 @@ admin:
|
|
8
8
|
Post: create, read, update, delete
|
9
9
|
Status: index
|
10
10
|
WatchDog: index, cleanup
|
11
|
+
View: create, read, update, delete
|
11
12
|
|
12
13
|
editor:
|
13
14
|
Category: create, read, update
|
@@ -15,8 +16,9 @@ editor:
|
|
15
16
|
Git: index
|
16
17
|
Post: create, read, update
|
17
18
|
TypusUser: read, update
|
19
|
+
View: create, read, update, delete
|
18
20
|
|
19
21
|
designer:
|
20
22
|
Category: read, update
|
21
23
|
Comment: read
|
22
|
-
Post: read
|
24
|
+
Post: read, update
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/functional/admin/{assets_controller_test.rb → master_controller_assets_relationships.rb}
RENAMED
@@ -1,18 +1,22 @@
|
|
1
1
|
require 'test/helper'
|
2
2
|
|
3
|
-
# Test polimorphic relationships using the relate & unrelate actions.
|
4
|
-
|
5
3
|
class Admin::AssetsControllerTest < ActionController::TestCase
|
6
4
|
|
7
5
|
def setup
|
8
|
-
|
9
|
-
@request.session[:typus_user_id] = typus_user.id
|
6
|
+
@request.session[:typus_user_id] = typus_users(:admin).id
|
10
7
|
end
|
11
8
|
|
12
9
|
def test_should_test_polymorphic_relationship_message
|
10
|
+
|
13
11
|
post_ = posts(:published)
|
14
|
-
get :new, { :back_to => "/admin/posts/#{post_.id}/edit",
|
15
|
-
|
12
|
+
get :new, { :back_to => "/admin/posts/#{post_.id}/edit",
|
13
|
+
:resource => post_.class.name, :resource_id => post_.id }
|
14
|
+
|
15
|
+
assert_select 'body div#flash' do
|
16
|
+
assert_select 'p', "You're adding a new Asset to Post. Do you want to cancel it?"
|
17
|
+
assert_select 'a', "Do you want to cancel it?"
|
18
|
+
end
|
19
|
+
|
16
20
|
end
|
17
21
|
|
18
22
|
def test_should_create_a_polymorphic_relationship
|
@@ -20,21 +24,28 @@ class Admin::AssetsControllerTest < ActionController::TestCase
|
|
20
24
|
post_ = posts(:published)
|
21
25
|
|
22
26
|
assert_difference('post_.assets.count') do
|
23
|
-
post :create, { :back_to => "/admin/posts/edit/#{post_.id}",
|
27
|
+
post :create, { :back_to => "/admin/posts/edit/#{post_.id}",
|
28
|
+
:resource => post_.class.name, :resource_id => post_.id }
|
24
29
|
end
|
25
30
|
|
26
31
|
assert_response :redirect
|
27
32
|
assert_redirected_to '/admin/posts/edit/1#assets'
|
28
|
-
assert flash[:success]
|
29
33
|
assert_equal "Asset successfully assigned to Post.", flash[:success]
|
30
34
|
|
31
35
|
end
|
32
36
|
|
33
|
-
def
|
37
|
+
def test_should_render_edit_and_verify_message_on_polymorphic_relationship
|
38
|
+
|
34
39
|
post_ = posts(:published)
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
get :edit, { :id => assets(:first).id,
|
41
|
+
:back_to => "/admin/posts/#{post_.id}/edit",
|
42
|
+
:resource => post_.class.name, :resource_id => post_.id }
|
43
|
+
|
44
|
+
assert_select 'body div#flash' do
|
45
|
+
assert_select 'p', "You're updating a Asset for Post. Do you want to cancel it?"
|
46
|
+
assert_select 'a', "Do you want to cancel it?"
|
47
|
+
end
|
48
|
+
|
38
49
|
end
|
39
50
|
|
40
51
|
def test_should_return_to_back_to_url
|
@@ -48,7 +59,6 @@ class Admin::AssetsControllerTest < ActionController::TestCase
|
|
48
59
|
post :update, { :back_to => "/admin/posts/#{post_.id}/edit", :resource => post_.class.name, :resource_id => post_.id, :id => asset_.id }
|
49
60
|
assert_response :redirect
|
50
61
|
assert_redirected_to '/admin/posts/1/edit#assets'
|
51
|
-
assert flash[:success]
|
52
62
|
assert_equal "Asset successfully updated.", flash[:success]
|
53
63
|
|
54
64
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test/helper'
|
2
|
+
|
3
|
+
class Admin::CategoriesControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@request.session[:typus_user_id] = typus_users(:admin).id
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_verify_items_are_sorted_by_position_on_list
|
10
|
+
get :index
|
11
|
+
assert_response :success
|
12
|
+
assert_equal [ 1, 2, 3 ], assigns['items'].items.map(&:position)
|
13
|
+
assert_equal [ 2, 3, 1 ], Category.find(:all, :order => "id ASC").map(&:position)
|
14
|
+
end
|
15
|
+
|
16
|
+
if defined?(ActiveRecord::Acts::List)
|
17
|
+
|
18
|
+
def test_should_position_item_one_step_down
|
19
|
+
|
20
|
+
first_category = categories(:first)
|
21
|
+
assert_equal 1, first_category.position
|
22
|
+
second_category = categories(:second)
|
23
|
+
assert_equal 2, second_category.position
|
24
|
+
|
25
|
+
get :position, { :id => first_category.id, :go => 'move_lower' }
|
26
|
+
assert_response :redirect
|
27
|
+
assert_redirected_to admin_dashboard_path
|
28
|
+
|
29
|
+
assert_equal "Record moved lower.", flash[:success]
|
30
|
+
assert_equal 2, first_category.reload.position
|
31
|
+
assert_equal 1, second_category.reload.position
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_position_item_one_step_up
|
36
|
+
first_category = categories(:first)
|
37
|
+
assert_equal 1, first_category.position
|
38
|
+
second_category = categories(:second)
|
39
|
+
assert_equal 2, second_category.position
|
40
|
+
get :position, { :id => second_category.id, :go => 'move_higher' }
|
41
|
+
assert_equal "Record moved higher.", flash[:success]
|
42
|
+
assert_equal 2, first_category.reload.position
|
43
|
+
assert_equal 1, second_category.reload.position
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_should_position_top_item_to_bottom
|
47
|
+
first_category = categories(:first)
|
48
|
+
assert_equal 1, first_category.position
|
49
|
+
get :position, { :id => first_category.id, :go => 'move_to_bottom' }
|
50
|
+
assert_equal "Record moved to bottom.", flash[:success]
|
51
|
+
assert_equal 3, first_category.reload.position
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_should_position_bottom_item_to_top
|
55
|
+
third_category = categories(:third)
|
56
|
+
assert_equal 3, third_category.position
|
57
|
+
get :position, { :id => third_category.id, :go => 'move_to_top' }
|
58
|
+
assert_equal "Record moved to top.", flash[:success]
|
59
|
+
assert_equal 1, third_category.reload.position
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'test/helper'
|
2
|
+
|
3
|
+
class Admin::PostsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
##
|
6
|
+
# Actions related to index.
|
7
|
+
##
|
8
|
+
|
9
|
+
def test_should_index_items
|
10
|
+
get :index
|
11
|
+
assert_response :success
|
12
|
+
assert_template 'index'
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Actions related to new.
|
17
|
+
##
|
18
|
+
|
19
|
+
def test_should_new_an_item
|
20
|
+
get :new
|
21
|
+
assert_response :success
|
22
|
+
assert_template 'new'
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Actions related to create.
|
27
|
+
##
|
28
|
+
|
29
|
+
def test_should_create_an_item
|
30
|
+
|
31
|
+
assert_difference 'Post.count' do
|
32
|
+
post :create, { :item => { :title => 'This is another title', :body => 'Body' } }
|
33
|
+
assert_response :redirect
|
34
|
+
assert_redirected_to :controller => 'admin/posts', :action => 'edit', :id => Post.last
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_create_an_item_and_redirect_to_index
|
40
|
+
|
41
|
+
options = Typus::Configuration.options.merge(:index_after_save => true)
|
42
|
+
Typus::Configuration.stubs(:options).returns(options)
|
43
|
+
|
44
|
+
assert_difference 'Post.count' do
|
45
|
+
post :create, { :item => { :title => 'This is another title', :body => 'Body' } }
|
46
|
+
assert_response :redirect
|
47
|
+
assert_redirected_to :action => 'index'
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Actions related to show.
|
54
|
+
##
|
55
|
+
|
56
|
+
def test_should_show_an_item
|
57
|
+
post_ = posts(:published)
|
58
|
+
get :show, { :id => post_.id }
|
59
|
+
assert_response :success
|
60
|
+
assert_template 'show'
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# Actions related to edit.
|
65
|
+
##
|
66
|
+
|
67
|
+
def test_should_edit_an_item
|
68
|
+
get :edit, { :id => posts(:published) }
|
69
|
+
assert_response :success
|
70
|
+
assert_template 'edit'
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# Actions related to update.
|
75
|
+
##
|
76
|
+
|
77
|
+
def test_should_update_an_item
|
78
|
+
|
79
|
+
post_ = posts(:published)
|
80
|
+
post :update, { :id => post_.id, :title => 'Updated' }
|
81
|
+
assert_response :redirect
|
82
|
+
assert_redirected_to :controller => 'admin/posts', :action => 'edit', :id => post_.id
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_should_update_an_item_and_redirect_to_index
|
87
|
+
|
88
|
+
options = Typus::Configuration.options.merge(:index_after_save => true)
|
89
|
+
Typus::Configuration.stubs(:options).returns(options)
|
90
|
+
|
91
|
+
post :update, { :id => posts(:published), :title => 'Updated' }
|
92
|
+
assert_response :redirect
|
93
|
+
assert_redirected_to :action => 'index'
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test/helper'
|
2
|
+
|
3
|
+
class Admin::PostsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def test_should_generate_xml
|
6
|
+
|
7
|
+
assert @typus_user.is_root?
|
8
|
+
|
9
|
+
expected = <<-RAW
|
10
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
11
|
+
<posts type="array">
|
12
|
+
<post>
|
13
|
+
<status type="boolean">false</status>
|
14
|
+
<title>Owned by admin</title>
|
15
|
+
</post>
|
16
|
+
<post>
|
17
|
+
<status type="boolean">false</status>
|
18
|
+
<title>Owned by editor</title>
|
19
|
+
</post>
|
20
|
+
<post>
|
21
|
+
<status type="boolean">true</status>
|
22
|
+
<title>Title One</title>
|
23
|
+
</post>
|
24
|
+
<post>
|
25
|
+
<status type="boolean">false</status>
|
26
|
+
<title>Title Two</title>
|
27
|
+
</post>
|
28
|
+
</posts>
|
29
|
+
RAW
|
30
|
+
|
31
|
+
get :index, :format => 'xml'
|
32
|
+
assert_equal expected, @response.body
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_generate_csv
|
37
|
+
|
38
|
+
assert @typus_user.is_root?
|
39
|
+
|
40
|
+
begin
|
41
|
+
require 'fastercsv'
|
42
|
+
rescue LoadError
|
43
|
+
return
|
44
|
+
end
|
45
|
+
|
46
|
+
expected = <<-RAW
|
47
|
+
Title,Status
|
48
|
+
Owned by admin,false
|
49
|
+
Owned by editor,false
|
50
|
+
Title One,true
|
51
|
+
Title Two,false
|
52
|
+
RAW
|
53
|
+
|
54
|
+
get :index, :format => 'csv'
|
55
|
+
assert_equal expected, @response.body
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|