typus 0.9.29 → 0.9.30
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 +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
@@ -1,105 +0,0 @@
|
|
1
|
-
require 'test/helper'
|
2
|
-
|
3
|
-
# Test position action if acts as list is installed.
|
4
|
-
|
5
|
-
class Admin::CategoriesControllerTest < ActionController::TestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
user = typus_users(:editor)
|
9
|
-
@request.session[:typus_user_id] = user.id
|
10
|
-
@request.env['HTTP_REFERER'] = '/admin/categories'
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_should_position_item_one_step_down
|
14
|
-
return if !defined?(ActiveRecord::Acts::List)
|
15
|
-
first_category = categories(:first)
|
16
|
-
assert_equal 1, first_category.position
|
17
|
-
second_category = categories(:second)
|
18
|
-
assert_equal 2, second_category.position
|
19
|
-
get :position, { :id => first_category.id, :go => 'move_lower' }
|
20
|
-
assert flash[:success]
|
21
|
-
assert_match /Record moved lower./, flash[:success]
|
22
|
-
assert_equal 2, first_category.reload.position
|
23
|
-
assert_equal 1, second_category.reload.position
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_should_position_item_one_step_up
|
27
|
-
return if !defined?(ActiveRecord::Acts::List)
|
28
|
-
first_category = categories(:first)
|
29
|
-
assert_equal 1, first_category.position
|
30
|
-
second_category = categories(:second)
|
31
|
-
assert_equal 2, second_category.position
|
32
|
-
get :position, { :id => second_category.id, :go => 'move_higher' }
|
33
|
-
assert flash[:success]
|
34
|
-
assert_match /Record moved higher./, flash[:success]
|
35
|
-
assert_equal 2, first_category.reload.position
|
36
|
-
assert_equal 1, second_category.reload.position
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_should_position_top_item_to_bottom
|
40
|
-
return if !defined?(ActiveRecord::Acts::List)
|
41
|
-
first_category = categories(:first)
|
42
|
-
assert_equal 1, first_category.position
|
43
|
-
get :position, { :id => first_category.id, :go => 'move_to_bottom' }
|
44
|
-
assert flash[:success]
|
45
|
-
assert_match /Record moved to bottom./, flash[:success]
|
46
|
-
assert_equal 3, first_category.reload.position
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_should_position_bottom_item_to_top
|
50
|
-
return if !defined?(ActiveRecord::Acts::List)
|
51
|
-
third_category = categories(:third)
|
52
|
-
assert_equal 3, third_category.position
|
53
|
-
get :position, { :id => third_category.id, :go => 'move_to_top' }
|
54
|
-
assert flash[:success]
|
55
|
-
assert_match /Record moved to top./, flash[:success]
|
56
|
-
assert_equal 1, third_category.reload.position
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_should_verify_items_are_sorted_by_position_on_list
|
60
|
-
get :index
|
61
|
-
assert_response :success
|
62
|
-
assert_equal [ 1, 2, 3 ], assigns['items'].items.map(&:position)
|
63
|
-
assert_equal [ 2, 3, 1 ], Category.find(:all, :order => "id ASC").map(&:position)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_should_allow_admin_to_add_a_category
|
67
|
-
admin = typus_users(:admin)
|
68
|
-
@request.session[:typus_user_id] = admin.id
|
69
|
-
assert admin.can_perform?('Category', 'create')
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_should_not_allow_designer_to_add_a_category
|
73
|
-
designer = typus_users(:designer)
|
74
|
-
@request.session[:typus_user_id] = designer.id
|
75
|
-
category = categories(:first)
|
76
|
-
get :new
|
77
|
-
assert_response :redirect
|
78
|
-
assert flash[:notice]
|
79
|
-
assert_equal "Designer can't perform action (new).", flash[:notice]
|
80
|
-
assert_redirected_to :action => :index
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_should_allow_admin_to_destroy_a_category
|
84
|
-
admin = typus_users(:admin)
|
85
|
-
@request.session[:typus_user_id] = admin.id
|
86
|
-
category = categories(:first)
|
87
|
-
get :destroy, { :id => category.id }
|
88
|
-
assert_response :redirect
|
89
|
-
assert flash[:success]
|
90
|
-
assert_match /Category successfully removed./, flash[:success]
|
91
|
-
assert_redirected_to :action => :index
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_should_not_allow_designer_to_destroy_a_category
|
95
|
-
designer = typus_users(:designer)
|
96
|
-
@request.session[:typus_user_id] = designer.id
|
97
|
-
category = categories(:first)
|
98
|
-
get :destroy, { :id => category.id, :method => :delete }
|
99
|
-
assert_response :redirect
|
100
|
-
assert flash[:notice]
|
101
|
-
assert_match /Designer can't delete this item/, flash[:notice]
|
102
|
-
assert_redirected_to :action => :index
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'test/helper'
|
2
|
-
|
3
|
-
# Test template extensions rendering and things related to views.
|
4
|
-
|
5
|
-
class Admin::CommentsControllerTest < ActionController::TestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@typus_user = typus_users(:admin)
|
9
|
-
@request.session[:typus_user_id] = @typus_user.id
|
10
|
-
@comment = comments(:first)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_should_render_comments_partials_on_index
|
14
|
-
get :index
|
15
|
-
assert_response :success
|
16
|
-
partials = %w( _index.html.erb _sidebar.html.erb )
|
17
|
-
partials.each { |p| assert_match p, @response.body }
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_should_render_comments_partials_on_new
|
21
|
-
get :new
|
22
|
-
assert_response :success
|
23
|
-
partials = %w( _new.html.erb _sidebar.html.erb )
|
24
|
-
partials.each { |p| assert_match p, @response.body }
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_should_render_comments_partials_on_edit
|
28
|
-
get :edit, { :id => @comment.id }
|
29
|
-
assert_response :success
|
30
|
-
partials = %w( _edit.html.erb _sidebar.html.erb )
|
31
|
-
partials.each { |p| assert_match p, @response.body }
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_should_render_comments_partials_on_show
|
35
|
-
get :show, { :id => @comment.id }
|
36
|
-
assert_response :success
|
37
|
-
partials = %w( _show.html.erb _sidebar.html.erb )
|
38
|
-
partials.each { |p| assert_match p, @response.body }
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_should_verify_page_title_on_index
|
42
|
-
get :index
|
43
|
-
assert_select 'title', "#{Typus::Configuration.options[:app_name]} - Comments"
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_should_verify_page_title_on_new
|
47
|
-
get :new
|
48
|
-
assert_select 'title', "#{Typus::Configuration.options[:app_name]} - Comments › New"
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_should_verify_page_title_on_edit
|
52
|
-
comment = comments(:first)
|
53
|
-
get :edit, :id => comment.id
|
54
|
-
assert_select 'title', "#{Typus::Configuration.options[:app_name]} - Comments › Edit"
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_should_show_add_new_link_in_index
|
58
|
-
get :index
|
59
|
-
assert_response :success
|
60
|
-
assert_match 'Add entry', @response.body
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_should_not_show_add_new_link_in_index
|
64
|
-
|
65
|
-
typus_user = typus_users(:designer)
|
66
|
-
@request.session[:typus_user_id] = typus_user.id
|
67
|
-
|
68
|
-
get :index
|
69
|
-
assert_response :success
|
70
|
-
assert_no_match /Add comment/, @response.body
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_should_show_trash_item_image_and_link_in_index
|
75
|
-
get :index
|
76
|
-
assert_response :success
|
77
|
-
assert_match /Trash/, @response.body
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_should_not_show_remove_item_link_in_index
|
81
|
-
|
82
|
-
typus_user = typus_users(:designer)
|
83
|
-
@request.session[:typus_user_id] = typus_user.id
|
84
|
-
|
85
|
-
get :index
|
86
|
-
assert_response :success
|
87
|
-
assert_no_match /Trash/, @response.body
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_should_verify_new_comment_contains_a_link_to_add_a_new_post
|
92
|
-
get :new
|
93
|
-
match = '/admin/posts/new?back_to=%2Fadmin%2Fcomments%2Fnew&selected=post_id'
|
94
|
-
assert_match match, @response.body
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_should_verify_edit_comment_contains_a_link_to_add_a_new_post
|
98
|
-
comment = comments(:first)
|
99
|
-
get :edit, :id => comment.id
|
100
|
-
match = "/admin/posts/new?back_to=%2Fadmin%2Fcomments%2Fedit%2F#{comment.id}&selected=post_id"
|
101
|
-
assert_match match, @response.body
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_should_generate_csv
|
105
|
-
|
106
|
-
return if !defined?(FasterCSV)
|
107
|
-
|
108
|
-
expected = <<-RAW
|
109
|
-
Email,Post
|
110
|
-
john@example.com,1
|
111
|
-
me@example.com,1
|
112
|
-
john@example.com,
|
113
|
-
me@example.com,1
|
114
|
-
RAW
|
115
|
-
|
116
|
-
get :index, :format => 'csv'
|
117
|
-
assert_equal expected, @response.body
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'test/helper'
|
2
|
-
|
3
|
-
# Test private methods.
|
4
|
-
|
5
|
-
class Admin::MasterControllerTest < ActionController::TestCase
|
6
|
-
|
7
|
-
def test_check_resource
|
8
|
-
assert true
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_find_item
|
12
|
-
assert true
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_check_ownership_of_item
|
16
|
-
assert true
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_check_ownership_of_items
|
20
|
-
assert true
|
21
|
-
end
|
22
|
-
|
23
|
-
def check_ownership_of_referal_item
|
24
|
-
assert true
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_set_fields
|
28
|
-
assert true
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_set_order
|
32
|
-
assert true
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_set_tiny_mce
|
36
|
-
assert true
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_select_template
|
40
|
-
assert true
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_create_with_back_to
|
44
|
-
assert true
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_error_handler
|
48
|
-
assert true
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
@@ -1,300 +0,0 @@
|
|
1
|
-
require 'test/helper'
|
2
|
-
|
3
|
-
# Test CRUD actions and ...
|
4
|
-
#
|
5
|
-
# - Relate comment which is a has_many relationship.
|
6
|
-
# - Unrelate comment which is a has_many relationship.
|
7
|
-
|
8
|
-
class Admin::PostsControllerTest < ActionController::TestCase
|
9
|
-
|
10
|
-
def setup
|
11
|
-
typus_user = typus_users(:admin)
|
12
|
-
@request.session[:typus_user_id] = typus_user.id
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_should_redirect_to_login
|
16
|
-
|
17
|
-
@request.session[:typus_user_id] = nil
|
18
|
-
|
19
|
-
get :index
|
20
|
-
assert_response :redirect
|
21
|
-
assert_redirected_to admin_sign_in_path(:back_to => '/admin/posts')
|
22
|
-
get :edit, { :id => 1 }
|
23
|
-
assert_response :redirect
|
24
|
-
assert_redirected_to admin_sign_in_path(:back_to => '/admin/posts')
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_should_render_index
|
29
|
-
get :index
|
30
|
-
assert_response :success
|
31
|
-
assert_template 'index'
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_should_render_new
|
35
|
-
test_should_update_item_and_redirect_to_index
|
36
|
-
get :new
|
37
|
-
assert_response :success
|
38
|
-
assert_template 'new'
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_should_create_item_and_redirect_to_index
|
42
|
-
|
43
|
-
options = Typus::Configuration.options.merge(:index_after_save => true)
|
44
|
-
Typus::Configuration.stubs(:options).returns(options)
|
45
|
-
|
46
|
-
assert_difference 'Post.count' do
|
47
|
-
post :create, { :item => { :title => 'This is another title', :body => 'Body' } }
|
48
|
-
assert_response :redirect
|
49
|
-
assert_redirected_to :action => 'index'
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_should_create_item_and_redirect_to_edit
|
55
|
-
|
56
|
-
options = Typus::Configuration.options.merge(:index_after_save => false)
|
57
|
-
Typus::Configuration.stubs(:options).returns(options)
|
58
|
-
|
59
|
-
assert_difference 'Post.count' do
|
60
|
-
post :create, { :item => { :title => 'This is another title', :body => 'Body' } }
|
61
|
-
assert_response :redirect
|
62
|
-
assert_redirected_to :controller => 'admin/posts', :action => 'edit', :id => Post.last
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_should_render_show
|
68
|
-
post_ = posts(:published)
|
69
|
-
get :show, { :id => post_.id }
|
70
|
-
assert_response :success
|
71
|
-
assert_template 'show'
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_should_render_edit
|
75
|
-
post_ = posts(:published)
|
76
|
-
get :edit, { :id => post_.id }
|
77
|
-
assert_response :success
|
78
|
-
assert_template 'edit'
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_should_update_item_and_redirect_to_index
|
82
|
-
|
83
|
-
options = Typus::Configuration.options.merge(:index_after_save => true)
|
84
|
-
Typus::Configuration.stubs(:options).returns(options)
|
85
|
-
|
86
|
-
post_ = posts(:published)
|
87
|
-
post :update, { :id => post_.id, :title => 'Updated' }
|
88
|
-
assert_response :redirect
|
89
|
-
assert_redirected_to :action => 'index'
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_should_update_item_and_redirect_to_edit
|
94
|
-
|
95
|
-
options = Typus::Configuration.options.merge(:index_after_save => false)
|
96
|
-
Typus::Configuration.stubs(:options).returns(options)
|
97
|
-
|
98
|
-
post_ = posts(:published)
|
99
|
-
post :update, { :id => post_.id, :title => 'Updated' }
|
100
|
-
assert_response :redirect
|
101
|
-
assert_redirected_to :controller => 'admin/posts', :action => 'edit', :id => post_.id
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_should_allow_admin_to_toggle_item
|
106
|
-
@request.env['HTTP_REFERER'] = '/admin/posts'
|
107
|
-
post = posts(:unpublished)
|
108
|
-
get :toggle, { :id => post.id, :field => 'status' }
|
109
|
-
assert_response :redirect
|
110
|
-
assert_redirected_to :action => 'index'
|
111
|
-
assert flash[:success]
|
112
|
-
assert Post.find(post.id).status
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_should_perform_a_search
|
116
|
-
typus_user = typus_users(:admin)
|
117
|
-
@request.session[:typus_user_id] = typus_user.id
|
118
|
-
get :index, { :search => 'neinonon' }
|
119
|
-
assert_response :success
|
120
|
-
assert_template 'index'
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_should_relate_category_to_post_which_is_a_habtm_relationship
|
124
|
-
category = categories(:first)
|
125
|
-
post_ = posts(:published)
|
126
|
-
@request.env['HTTP_REFERER'] = "/admin/posts/edit/#{post_.id}#categories"
|
127
|
-
assert_difference('category.posts.count') do
|
128
|
-
post :relate, { :id => post_.id, :related => { :model => 'Category', :id => category.id } }
|
129
|
-
end
|
130
|
-
assert_response :redirect
|
131
|
-
assert flash[:success]
|
132
|
-
assert_redirected_to @request.env['HTTP_REFERER']
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_should_unrelate_category_from_post_which_is_a_habtm_relationship
|
136
|
-
category = categories(:first)
|
137
|
-
post_ = posts(:published)
|
138
|
-
@request.env['HTTP_REFERER'] = "/admin/posts/edit/#{post_.id}#categories"
|
139
|
-
assert_difference('category.posts.count', 0) do
|
140
|
-
post :unrelate, { :id => post_.id, :resource => 'Category', :resource_id => category.id, :association => 'has_and_belongs_to_many' }
|
141
|
-
end
|
142
|
-
assert_response :redirect
|
143
|
-
assert flash[:success]
|
144
|
-
assert_match /Category unrelated from/, flash[:success]
|
145
|
-
assert_redirected_to @request.env['HTTP_REFERER']
|
146
|
-
end
|
147
|
-
|
148
|
-
##
|
149
|
-
# This is a polimorphic relationship.
|
150
|
-
#
|
151
|
-
def test_should_unrelate_an_asset_from_a_post
|
152
|
-
|
153
|
-
post_ = posts(:published)
|
154
|
-
|
155
|
-
@request.env['HTTP_REFERER'] = "/admin/posts/edit/#{post_.id}#assets"
|
156
|
-
|
157
|
-
assert_difference('post_.assets.count', -1) do
|
158
|
-
get :unrelate, { :id => post_.id, :resource => 'Asset', :resource_id => post_.assets.first.id, :association => 'has_many' }
|
159
|
-
end
|
160
|
-
|
161
|
-
assert_response :redirect
|
162
|
-
assert_redirected_to @request.env['HTTP_REFERER']
|
163
|
-
assert flash[:success]
|
164
|
-
assert_match /Asset removed from/, flash[:success]
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_should_check_redirection_when_theres_no_http_referer_on_new
|
169
|
-
|
170
|
-
typus_user = typus_users(:designer)
|
171
|
-
@request.session[:typus_user_id] = typus_user.id
|
172
|
-
|
173
|
-
get :new
|
174
|
-
assert_response :redirect
|
175
|
-
assert_redirected_to admin_dashboard_path
|
176
|
-
|
177
|
-
assert flash[:notice]
|
178
|
-
assert_equal "Designer can't perform action (new).", flash[:notice]
|
179
|
-
|
180
|
-
@request.env['HTTP_REFERER'] = '/admin/posts'
|
181
|
-
|
182
|
-
typus_user = typus_users(:designer)
|
183
|
-
@request.session[:typus_user_id] = typus_user.id
|
184
|
-
|
185
|
-
get :new
|
186
|
-
assert_response :redirect
|
187
|
-
assert_redirected_to '/admin/posts'
|
188
|
-
|
189
|
-
assert flash[:notice]
|
190
|
-
assert_equal "Designer can't perform action (new).", flash[:notice]
|
191
|
-
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_should_disable_toggle_and_check_links_are_disabled
|
195
|
-
|
196
|
-
options = Typus::Configuration.options.merge(:toggle => false)
|
197
|
-
Typus::Configuration.stubs(:options).returns(options)
|
198
|
-
|
199
|
-
@request.env['HTTP_REFERER'] = '/admin/posts'
|
200
|
-
post = posts(:unpublished)
|
201
|
-
get :toggle, { :id => post.id, :field => 'status' }
|
202
|
-
assert_response :redirect
|
203
|
-
assert_redirected_to :action => 'index'
|
204
|
-
assert !flash[:success]
|
205
|
-
assert !flash[:error]
|
206
|
-
assert flash[:notice]
|
207
|
-
assert_equal "Toggle is disabled.", flash[:notice]
|
208
|
-
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_should_show_form_templates
|
212
|
-
get :new
|
213
|
-
assert_response :success
|
214
|
-
assert_match /datepicker_template_published_at/, @response.body
|
215
|
-
end
|
216
|
-
|
217
|
-
def test_should_verify_root_can_edit_any_record
|
218
|
-
Post.find(:all).each do |post|
|
219
|
-
get :edit, { :id => post.id }
|
220
|
-
assert_response :success
|
221
|
-
assert_template 'edit'
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
def test_should_verify_editor_can_view_all_records
|
226
|
-
Post.find(:all).each do |post|
|
227
|
-
get :show, { :id => post.id }
|
228
|
-
assert_response :success
|
229
|
-
assert_template 'show'
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_should_verify_editor_can_edit_their_records
|
234
|
-
|
235
|
-
typus_user = typus_users(:editor)
|
236
|
-
@request.session[:typus_user_id] = typus_user.id
|
237
|
-
|
238
|
-
post = posts(:owned_by_editor)
|
239
|
-
get :edit, { :id => post.id }
|
240
|
-
assert_response :success
|
241
|
-
|
242
|
-
end
|
243
|
-
|
244
|
-
def test_should_verify_editor_cannot_edit_other_users_records
|
245
|
-
|
246
|
-
@request.env['HTTP_REFERER'] = '/admin/posts'
|
247
|
-
|
248
|
-
typus_user = typus_users(:editor)
|
249
|
-
@request.session[:typus_user_id] = typus_user.id
|
250
|
-
|
251
|
-
post = posts(:owned_by_admin)
|
252
|
-
get :edit, { :id => post.id }
|
253
|
-
assert_response :redirect
|
254
|
-
assert_redirected_to '/admin/posts'
|
255
|
-
assert flash[:notice]
|
256
|
-
assert_equal "You don't have permission to access this item.", flash[:notice]
|
257
|
-
|
258
|
-
end
|
259
|
-
|
260
|
-
def test_should_verify_admin_updating_an_item_does_not_change_typus_user_id_if_not_defined
|
261
|
-
post_ = posts(:owned_by_editor)
|
262
|
-
post :update, { :id => post_.id, :item => { :title => 'Updated by admin' } }
|
263
|
-
post_updated = Post.find(post_.id)
|
264
|
-
assert_equal post_.typus_user_id, post_updated.typus_user_id
|
265
|
-
end
|
266
|
-
|
267
|
-
def test_should_verify_admin_updating_an_item_does_change_typus_user_id_to_whatever_admin_wants
|
268
|
-
post_ = posts(:owned_by_editor)
|
269
|
-
post :update, { :id => post_.id, :item => { :title => 'Updated', :typus_user_id => 108 } }
|
270
|
-
post_updated = Post.find(post_.id)
|
271
|
-
assert_equal 108, post_updated.typus_user_id
|
272
|
-
end
|
273
|
-
|
274
|
-
def test_should_verify_editor_updating_an_item_does_not_change_typus_user_id
|
275
|
-
|
276
|
-
typus_user = typus_users(:editor)
|
277
|
-
@request.session[:typus_user_id] = typus_user.id
|
278
|
-
|
279
|
-
[ 108, nil ].each do |typus_user_id|
|
280
|
-
post_ = posts(:owned_by_editor)
|
281
|
-
post :update, { :id => post_.id, :item => { :title => 'Updated', :typus_user_id => typus_user_id } }
|
282
|
-
post_updated = Post.find(post_.id)
|
283
|
-
assert_equal typus_user.id, post_updated.typus_user_id
|
284
|
-
end
|
285
|
-
|
286
|
-
end
|
287
|
-
|
288
|
-
def test_should_verify_typus_user_id_of_item_when_creating_record
|
289
|
-
|
290
|
-
typus_user = typus_users(:editor)
|
291
|
-
@request.session[:typus_user_id] = typus_user.id
|
292
|
-
|
293
|
-
post :create, { :item => { :title => "Chunky Bacon", :body => "Lorem ipsum ..." } }
|
294
|
-
post_ = Post.find_by_title("Chunky Bacon")
|
295
|
-
|
296
|
-
assert_equal typus_user.id, post_.typus_user_id
|
297
|
-
|
298
|
-
end
|
299
|
-
|
300
|
-
end
|