typus 1.0.0.pre8 → 1.0.0.pre9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -6
- data/Gemfile +16 -13
- data/Gemfile.lock +26 -2
- data/Rakefile +2 -3
- data/app/controllers/admin/base_controller.rb +3 -5
- data/app/controllers/admin/resources_controller.rb +24 -26
- data/app/helpers/admin/base_helper.rb +14 -22
- data/app/helpers/admin/dashboard_helper.rb +2 -5
- data/app/helpers/admin/filters_helper.rb +6 -8
- data/app/helpers/admin/form_helper.rb +3 -9
- data/app/helpers/admin/preview_helper.rb +4 -6
- data/app/helpers/admin/relationships_helper.rb +9 -11
- data/app/helpers/admin/resources_helper.rb +6 -24
- data/app/helpers/admin/search_helper.rb +1 -1
- data/app/helpers/admin/sidebar_helper.rb +12 -15
- data/app/helpers/admin/table_helper.rb +13 -13
- data/app/views/admin/dashboard/show.html.erb +1 -1
- data/app/views/admin/helpers/_apps.html.erb +4 -3
- data/app/views/admin/helpers/_header.html.erb +2 -2
- data/app/views/admin/helpers/dashboard/_applications.html.erb +3 -3
- data/app/views/admin/helpers/dashboard/_resources.html.erb +17 -13
- data/app/views/admin/helpers/filters/_filters.html.erb +9 -27
- data/app/views/admin/helpers/resources/_pagination.html.erb +8 -9
- data/app/views/admin/helpers/search/_search.html.erb +1 -1
- data/app/views/admin/mailer/reset_password_link.text.erb +3 -0
- data/app/views/admin/resources/_form.html.erb +4 -4
- data/app/views/admin/resources/edit.html.erb +2 -3
- data/app/views/admin/resources/index.html.erb +15 -13
- data/app/views/admin/resources/new.html.erb +2 -2
- data/app/views/admin/resources/show.html.erb +1 -2
- data/app/views/admin/templates/_boolean.html.erb +1 -1
- data/app/views/admin/templates/_has_many.html.erb +2 -4
- data/app/views/admin/templates/_has_n.html.erb +1 -1
- data/app/views/admin/templates/_selector.html.erb +0 -1
- data/app/views/admin/templates/_string.html.erb +1 -1
- data/app/views/layouts/admin/session.html.erb +1 -1
- data/config/available_locales/ca.yml +3 -5
- data/config/available_locales/de.yml +2 -4
- data/config/available_locales/es.yml +2 -4
- data/config/available_locales/fr.yml +40 -39
- data/config/available_locales/fr_models.yml +2 -2
- data/config/available_locales/hu.yml +3 -5
- data/config/available_locales/it.yml +0 -4
- data/config/available_locales/language.yml.template +2 -4
- data/config/available_locales/pt-BR.yml +2 -4
- data/config/available_locales/ru.yml +2 -4
- data/config/routes.rb +1 -0
- data/lib/generators/templates/config/initializers/typus.rb +5 -5
- data/lib/generators/templates/config/initializers/typus_authentication.rb +5 -5
- data/lib/generators/templates/config/initializers/typus_resources.rb +7 -7
- data/lib/generators/templates/config/typus/README +11 -13
- data/lib/generators/templates/controller.rb +0 -2
- data/lib/generators/templates/functional_test.rb +4 -15
- data/lib/generators/typus/migration_generator.rb +0 -1
- data/lib/support/active_record.rb +18 -9
- data/lib/support/fake_user.rb +42 -0
- data/lib/support/object.rb +1 -0
- data/lib/support/string.rb +0 -32
- data/lib/tasks/typus.rake +0 -8
- data/lib/typus.rb +34 -18
- data/lib/typus/authentication/base.rb +26 -0
- data/lib/typus/authentication/http_basic.rb +22 -0
- data/lib/typus/authentication/none.rb +19 -0
- data/lib/typus/authentication/session.rb +190 -0
- data/lib/typus/format.rb +12 -19
- data/lib/typus/orm/active_record.rb +13 -51
- data/lib/typus/resources.rb +0 -9
- data/lib/typus/version.rb +1 -1
- data/test/factories.rb +43 -0
- data/test/fixtures/rails_app/app/controllers/application_controller.rb +0 -1
- data/test/fixtures/rails_app/app/models/page.rb +0 -4
- data/test/fixtures/rails_app/config/application.rb +6 -3
- data/test/fixtures/rails_app/config/database.yml +12 -20
- data/test/fixtures/rails_app/config/typus/application.yml +4 -8
- data/test/fixtures/rails_app/db/test.sqlite3 +0 -0
- data/test/fixtures/rails_app/log/test.log +227115 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012213057.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012213132.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012213234.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012213506.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215057.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215217.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215415.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215443.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215509.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215528.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215551.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215615.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215640.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215714.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215744.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215814.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215836.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012215906.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012220659.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012221043.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012221258.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012222558.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012222752.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012222848.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012223433.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012223535.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012224003.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012224052.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012224109.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012224139.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012224205.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012224243.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012225119.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063215.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063300.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063352.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063427.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063448.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063530.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063559.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063646.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063737.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063822.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063837.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063919.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063939.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013063952.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013064220.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013064253.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013064318.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013064404.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013064452.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013064536.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013064652.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013064845.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013065023.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013065137.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013065713.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013065954.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013070057.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013070116.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013070156.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013070349.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013070429.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013070448.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013070514.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013070709.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013070745.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013070809.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013070905.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013070955.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013071116.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013071209.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013071335.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013071632.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013071643.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013071735.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013071749.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013072030.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013072050.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013072108.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013072713.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013072751.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013072912.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101013074546.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101018180512.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101018183359.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101018183608.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101018183759.csv +2 -0
- data/test/functional/admin/account_controller_test.rb +1 -1
- data/test/functional/admin/{resources_controller_assets_relationships.rb → assets_controller_test.rb} +12 -16
- data/test/functional/admin/categories_controller_test.rb +62 -0
- data/test/functional/admin/{resources_controller_comments_toggle_test.rb → comments_controller_test.rb} +0 -0
- data/test/functional/admin/dashboard_controller_test.rb +34 -2
- data/test/functional/admin/posts_controller_test.rb +548 -0
- data/test/functional/admin/session_controller_test.rb +2 -2
- data/test/functional/admin/{resources_controller_tableless_resource_test.rb → status_controller_test.rb} +0 -0
- data/test/functional/admin/{resources_controller_typus_users_test.rb → typus_users_controller_test.rb} +2 -2
- data/test/helpers/admin/base_helper_test.rb +35 -37
- data/test/helpers/admin/dashboard_helper_test.rb +4 -8
- data/test/helpers/admin/form_helper_test.rb +9 -34
- data/test/helpers/admin/resources_helper_test.rb +28 -16
- data/test/helpers/admin/sidebar_helper_test.rb +14 -27
- data/test/helpers/admin/table_helper_test.rb +24 -68
- data/test/integration/login_test.rb +13 -0
- data/test/integration_test_helper.rb +21 -0
- data/test/lib/support/active_record_test.rb +72 -21
- data/test/lib/support/array_test.rb +2 -6
- data/test/lib/support/string_test.rb +21 -30
- data/test/lib/typus/active_record_test.rb +162 -100
- data/test/lib/typus/resource_test.rb +2 -3
- data/test/lib/typus_test.rb +25 -22
- data/test/test_helper.rb +4 -17
- data/test/unit/admin/mailer_test.rb +2 -2
- data/test/unit/typus_user_roles_test.rb +23 -23
- data/test/unit/typus_user_test.rb +30 -24
- data/typus.gemspec +0 -1
- metadata +111 -60
- data/app/models/admin/fake_user.rb +0 -46
- data/lib/generators/templates/model.yml +0 -10
- data/lib/typus/authentication.rb +0 -241
- data/lib/vendor/paginator.rb +0 -143
- data/test/factories/assets.rb +0 -5
- data/test/factories/categories.rb +0 -3
- data/test/factories/comments.rb +0 -6
- data/test/factories/pages.rb +0 -5
- data/test/factories/pictures.rb +0 -7
- data/test/factories/posts.rb +0 -6
- data/test/factories/typus_users.rb +0 -8
- data/test/fixtures/rails_app/README +0 -244
- data/test/fixtures/rails_app/app/helpers/application_helper.rb +0 -2
- data/test/fixtures/rails_app/app/views/layouts/application.html.erb +0 -14
- data/test/fixtures/rails_app/config/environments/development.rb +0 -19
- data/test/fixtures/rails_app/config/environments/production.rb +0 -42
- data/test/fixtures/rails_app/config/initializers/acts_as_list.rb +0 -258
- data/test/fixtures/rails_app/config/initializers/acts_as_tree.rb +0 -98
- data/test/fixtures/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/fixtures/rails_app/config/initializers/inflections.rb +0 -10
- data/test/fixtures/rails_app/config/initializers/mime_types.rb +0 -5
- data/test/fixtures/rails_app/config/locales/en.yml +0 -5
- data/test/fixtures/rails_app/db/seeds.rb +0 -7
- data/test/fixtures/rails_app/public/404.html +0 -26
- data/test/fixtures/rails_app/public/422.html +0 -26
- data/test/fixtures/rails_app/public/500.html +0 -26
- data/test/fixtures/rails_app/public/favicon.ico +0 -0
- data/test/fixtures/rails_app/public/images/rails.png +0 -0
- data/test/fixtures/rails_app/public/index.html +0 -279
- data/test/fixtures/rails_app/public/javascripts/application.js +0 -2
- data/test/fixtures/rails_app/public/javascripts/controls.js +0 -965
- data/test/fixtures/rails_app/public/javascripts/dragdrop.js +0 -974
- data/test/fixtures/rails_app/public/javascripts/effects.js +0 -1123
- data/test/fixtures/rails_app/public/javascripts/prototype.js +0 -4874
- data/test/fixtures/rails_app/public/javascripts/rails.js +0 -118
- data/test/fixtures/rails_app/public/robots.txt +0 -5
- data/test/fixtures/rails_app/script/rails +0 -9
- data/test/functional/admin/dashboard_controller_http_basic_test.rb +0 -24
- data/test/functional/admin/dashboard_controller_none_test.rb +0 -18
- data/test/functional/admin/resources_controller_categories_before_test.rb +0 -10
- data/test/functional/admin/resources_controller_categories_lists_test.rb +0 -44
- data/test/functional/admin/resources_controller_categories_views_test.rb +0 -10
- data/test/functional/admin/resources_controller_posts_before_test.rb +0 -10
- data/test/functional/admin/resources_controller_posts_crud_custom_test.rb +0 -27
- data/test/functional/admin/resources_controller_posts_crud_test.rb +0 -44
- data/test/functional/admin/resources_controller_posts_formats_test.rb +0 -39
- data/test/functional/admin/resources_controller_posts_forms_test.rb +0 -58
- data/test/functional/admin/resources_controller_posts_permissions_test.rb +0 -100
- data/test/functional/admin/resources_controller_posts_relationships_test.rb +0 -91
- data/test/functional/admin/resources_controller_posts_roles.rb +0 -52
- data/test/functional/admin/resources_controller_posts_views_test.rb +0 -143
- data/test/lib/vendor/paginator_test.rb +0 -141
- data/typus-1.0.0.pre7.gem +0 -0
@@ -1,91 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class Admin::PostsControllerTest < ActionController::TestCase
|
4
|
-
|
5
|
-
##
|
6
|
-
# Post => has_many :comments
|
7
|
-
##
|
8
|
-
|
9
|
-
should "relate_comment_with_post_and_then_unrelate" do
|
10
|
-
|
11
|
-
comment = Factory(:comment, :post => nil)
|
12
|
-
post_ = Factory(:post)
|
13
|
-
@request.env['HTTP_REFERER'] = "/admin/posts/edit/#{post_.id}#comments"
|
14
|
-
|
15
|
-
assert_difference('post_.comments.count') do
|
16
|
-
post :relate, { :id => post_.id,
|
17
|
-
:related => { :model => 'Comment', :id => comment.id } }
|
18
|
-
end
|
19
|
-
|
20
|
-
assert_response :redirect
|
21
|
-
assert_redirected_to @request.env['HTTP_REFERER']
|
22
|
-
assert_equal "Comment related to Post", flash[:notice]
|
23
|
-
|
24
|
-
assert_difference('post_.comments.count', -1) do
|
25
|
-
post :unrelate, { :id => post_.id,
|
26
|
-
:resource => 'Comment', :resource_id => comment.id }
|
27
|
-
end
|
28
|
-
|
29
|
-
assert_response :redirect
|
30
|
-
assert_redirected_to @request.env['HTTP_REFERER']
|
31
|
-
assert_equal "Comment unrelated from Post", flash[:notice]
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
##
|
36
|
-
# Post => has_and_belongs_to_many :categories
|
37
|
-
##
|
38
|
-
|
39
|
-
should "relate_category_with_post_and_then_unrelate" do
|
40
|
-
|
41
|
-
category = Factory(:category)
|
42
|
-
post_ = Factory(:post)
|
43
|
-
@request.env['HTTP_REFERER'] = "/admin/posts/edit/#{post_.id}#categories"
|
44
|
-
|
45
|
-
assert_difference('category.posts.count') do
|
46
|
-
post :relate, { :id => post_.id,
|
47
|
-
:related => { :model => 'Category', :id => category.id } }
|
48
|
-
end
|
49
|
-
|
50
|
-
assert_response :redirect
|
51
|
-
assert_redirected_to @request.env['HTTP_REFERER']
|
52
|
-
assert_equal "Category related to Post", flash[:notice]
|
53
|
-
|
54
|
-
assert_difference('category.posts.count', -1) do
|
55
|
-
post :unrelate, { :id => post_.id,
|
56
|
-
:resource => 'Category', :resource_id => category.id }
|
57
|
-
end
|
58
|
-
|
59
|
-
assert_response :redirect
|
60
|
-
assert_redirected_to @request.env['HTTP_REFERER']
|
61
|
-
assert_equal "Category unrelated from Post", flash[:notice]
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
=begin
|
66
|
-
|
67
|
-
##
|
68
|
-
# Post => has_many :assets, :as => resource (Polimorphic)
|
69
|
-
##
|
70
|
-
|
71
|
-
# FIXME: ActiveRecord::UnknownAttributeError: unknown attribute: post
|
72
|
-
should "relate_asset_with_post_and_then_unrelate"
|
73
|
-
|
74
|
-
post_ = Factory(:post)
|
75
|
-
|
76
|
-
@request.env['HTTP_REFERER'] = "/admin/posts/edit/#{post_.id}#assets"
|
77
|
-
|
78
|
-
assert_difference('post_.assets.count', -1) do
|
79
|
-
get :unrelate, { :id => post_.id,
|
80
|
-
:resource => 'Asset', :resource_id => post_.assets.first.id }
|
81
|
-
end
|
82
|
-
|
83
|
-
assert_response :redirect
|
84
|
-
assert_redirected_to @request.env['HTTP_REFERER']
|
85
|
-
assert_equal "Asset unrelated from Post.", flash[:notice]
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
=end
|
90
|
-
|
91
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class Admin::PostsControllerTest < ActionController::TestCase
|
4
|
-
|
5
|
-
context "Admin" do
|
6
|
-
|
7
|
-
setup do
|
8
|
-
@admin = Factory(:typus_user)
|
9
|
-
@request.session[:typus_user_id] = @admin.id
|
10
|
-
end
|
11
|
-
|
12
|
-
should "add a category" do
|
13
|
-
assert @admin.can?("create", "Post")
|
14
|
-
end
|
15
|
-
|
16
|
-
should "destroy a post" do
|
17
|
-
get :destroy, { :id => Factory(:post).id, :method => :delete }
|
18
|
-
|
19
|
-
assert_response :redirect
|
20
|
-
assert_equal "Post successfully removed.", flash[:notice]
|
21
|
-
assert_redirected_to :action => :index
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
context "Designer" do
|
27
|
-
|
28
|
-
setup do
|
29
|
-
@designer = Factory(:typus_user, :role => "designer")
|
30
|
-
@request.session[:typus_user_id] = @designer.id
|
31
|
-
end
|
32
|
-
|
33
|
-
should "not_allow_designer_to_add_a_post" do
|
34
|
-
get :new
|
35
|
-
|
36
|
-
assert_response :redirect
|
37
|
-
assert_equal "Designer can't perform action. (new)", flash[:notice]
|
38
|
-
assert_redirected_to :action => :index
|
39
|
-
end
|
40
|
-
|
41
|
-
should "not_allow_designer_to_destroy_a_post" do
|
42
|
-
get :destroy, { :id => Factory(:post).id, :method => :delete }
|
43
|
-
|
44
|
-
assert_response :redirect
|
45
|
-
assert_equal "Designer can't delete this item.", flash[:notice]
|
46
|
-
assert_redirected_to :action => :index
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class Admin::PostsControllerTest < ActionController::TestCase
|
4
|
-
|
5
|
-
context "Index" do
|
6
|
-
|
7
|
-
setup do
|
8
|
-
get :index
|
9
|
-
end
|
10
|
-
|
11
|
-
should "render index and validates_presence_of_custom_partials" do
|
12
|
-
assert_match "posts#_index.html.erb", @response.body
|
13
|
-
end
|
14
|
-
|
15
|
-
should "render_index_and_verify_page_title" do
|
16
|
-
assert_select "title", "Posts"
|
17
|
-
end
|
18
|
-
|
19
|
-
should "render index_and_show_add_entry_link" do
|
20
|
-
assert_select "#sidebar ul" do
|
21
|
-
assert_select "li", "Add new"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
should "render_index_and_show_trash_item_image" do
|
26
|
-
assert_response :success
|
27
|
-
assert_select '.trash', 'Trash'
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
context "New" do
|
33
|
-
|
34
|
-
setup do
|
35
|
-
get :new
|
36
|
-
end
|
37
|
-
|
38
|
-
should "render new and partials_on_new" do
|
39
|
-
assert_match "posts#_new.html.erb", @response.body
|
40
|
-
end
|
41
|
-
|
42
|
-
should "render new and verify page title" do
|
43
|
-
assert_select "title", "New Post"
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
context "Edit" do
|
49
|
-
|
50
|
-
setup do
|
51
|
-
get :edit, { :id => Factory(:post).id }
|
52
|
-
end
|
53
|
-
|
54
|
-
should "render_edit_and_verify_presence_of_custom_partials" do
|
55
|
-
assert_match "posts#_edit.html.erb", @response.body
|
56
|
-
end
|
57
|
-
|
58
|
-
should "render_edit_and_verify_page_title" do
|
59
|
-
assert_select "title", "Edit Post"
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
context "Show" do
|
65
|
-
|
66
|
-
setup do
|
67
|
-
get :show, { :id => Factory(:post).id }
|
68
|
-
end
|
69
|
-
|
70
|
-
should "render_show_and_verify_presence_of_custom_partials" do
|
71
|
-
assert_match "posts#_show.html.erb", @response.body
|
72
|
-
end
|
73
|
-
|
74
|
-
should "render_show_and_verify_page_title" do
|
75
|
-
assert_select "title", "Show Post"
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
should "get_index_and_render_edit_or_show_links" do
|
81
|
-
%w(edit show).each do |action|
|
82
|
-
Typus::Resources.expects(:default_action_on_item).at_least_once.returns(action)
|
83
|
-
get :index
|
84
|
-
Post.all.each do |post|
|
85
|
-
assert_match "/posts/#{action}/#{post.id}", @response.body
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context "Designer" do
|
91
|
-
|
92
|
-
setup do
|
93
|
-
@typus_user = Factory(:typus_user, :email => "designer@example.com", :role => "designer")
|
94
|
-
@request.session[:typus_user_id] = @typus_user.id
|
95
|
-
end
|
96
|
-
|
97
|
-
should "render_index_and_not_show_add_entry_link" do
|
98
|
-
get :index
|
99
|
-
assert_response :success
|
100
|
-
assert_no_match /Add Post/, @response.body
|
101
|
-
end
|
102
|
-
|
103
|
-
should "render_index_and_not_show_trash_image" do
|
104
|
-
get :index
|
105
|
-
assert_response :success
|
106
|
-
assert_select ".trash", false
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
context "Editor" do
|
112
|
-
|
113
|
-
setup do
|
114
|
-
@typus_user = Factory(:typus_user, :email => "editor@example.com", :role => "editor")
|
115
|
-
@request.session[:typus_user_id] = @typus_user.id
|
116
|
-
end
|
117
|
-
|
118
|
-
should "get_index_and_render_edit_or_show_links_on_owned_records" do
|
119
|
-
get :index
|
120
|
-
Post.all.each do |post|
|
121
|
-
action = post.owned_by?(@typus_user) ? "edit" : "show"
|
122
|
-
assert_match "/posts/#{action}/#{post.id}", @response.body
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
should "get_index_and_render_edit_or_show_on_only_user_items" do
|
127
|
-
%w(edit show).each do |action|
|
128
|
-
Typus::Resources.stubs(:only_user_items).returns(true)
|
129
|
-
Typus::Resources.stubs(:default_action_on_item).returns(action)
|
130
|
-
get :index
|
131
|
-
Post.all.each do |post|
|
132
|
-
if post.owned_by?(@typus_user)
|
133
|
-
assert_match "/posts/#{action}/#{post.id}", @response.body
|
134
|
-
else
|
135
|
-
assert_no_match /\/posts\/#{action}\/#{post.id}/, @response.body
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
@@ -1,141 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class PaginatorTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
PER_PAGE = 10
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@data = (0..43).to_a
|
9
|
-
@pager = Paginator.new(@data.size, PER_PAGE) do |offset,per_page|
|
10
|
-
@data[offset,per_page]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_initializing_paginator_raises_exception
|
15
|
-
assert_raises(Paginator::MissingSelectError) do
|
16
|
-
@pager = Paginator.new(@data.size, PER_PAGE)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_can_get_last_page_from_page_object
|
21
|
-
assert_equal @pager.last, @pager.page(2).last
|
22
|
-
end
|
23
|
-
|
24
|
-
=begin
|
25
|
-
|
26
|
-
# FIXME: Problem with paginator.rb.
|
27
|
-
def test_can_get_first_page_from_page_object
|
28
|
-
assert_equal @pager.first, @pager.page(2).first
|
29
|
-
end
|
30
|
-
|
31
|
-
=end
|
32
|
-
|
33
|
-
def test_does_not_exceed_per_page
|
34
|
-
@pager.each do |page|
|
35
|
-
assert page.items.size <= PER_PAGE
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_only_last_page_has_less_items
|
40
|
-
@pager.each do |page|
|
41
|
-
if page != @pager.last
|
42
|
-
assert page.items.size <= PER_PAGE
|
43
|
-
else
|
44
|
-
assert page.items.size < PER_PAGE
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_returns_correct_first_page
|
50
|
-
assert_equal @pager.page(1).number, @pager.first.number
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_returns_correct_last_page
|
54
|
-
assert_equal @pager.page(5).number, @pager.last.number
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_last_page_has_no_next_page
|
58
|
-
assert !@pager.last.next?
|
59
|
-
assert !@pager.last.next
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_first_page_has_no_prev_page
|
63
|
-
assert !@pager.first.prev?
|
64
|
-
assert !@pager.first.prev
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_page_enumerable
|
68
|
-
@pager.each do |page|
|
69
|
-
assert page
|
70
|
-
page.each do |item|
|
71
|
-
assert item
|
72
|
-
end
|
73
|
-
page.each_with_index do |item, index|
|
74
|
-
assert_equal page.items[index], item
|
75
|
-
end
|
76
|
-
assert_equal page.items, page.inject([]) { |list, item| list << item }
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_each_with_index
|
81
|
-
page_offset = 0
|
82
|
-
@pager.each_with_index do |page, page_index|
|
83
|
-
assert page
|
84
|
-
assert_equal page_offset, page_index
|
85
|
-
item_offset = 0
|
86
|
-
page.each_with_index do |item, item_index|
|
87
|
-
assert item
|
88
|
-
assert_equal item_offset, item_index
|
89
|
-
item_offset += 1
|
90
|
-
end
|
91
|
-
page_offset += 1
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_number_of_pages
|
96
|
-
assert_equal 5, @pager.number_of_pages
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_passing_block_to_initializer_with_arity_of_two_yields_per_page
|
100
|
-
pager = Paginator.new(20,2) do |offset,per_page|
|
101
|
-
assert_equal 2, per_page
|
102
|
-
end
|
103
|
-
pager.page(1).items
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_passing_block_to_initializer_with_arity_of_one_does_not_yield_per_page
|
107
|
-
pager = Paginator.new(20,2) do |offset|
|
108
|
-
assert_equal 0, offset
|
109
|
-
end
|
110
|
-
pager.page(1).items
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_page_object_knows_first_and_last_item_numbers
|
114
|
-
items = (1..11).to_a
|
115
|
-
pager = Paginator.new(items.size,3) do |offset, per_page|
|
116
|
-
items[offset, per_page]
|
117
|
-
end
|
118
|
-
page = pager.page(1)
|
119
|
-
assert_equal 1, page.first_item_number
|
120
|
-
assert_equal 3, page.last_item_number
|
121
|
-
page = pager.page(2)
|
122
|
-
assert_equal 4, page.first_item_number
|
123
|
-
assert_equal 6, page.last_item_number
|
124
|
-
page = pager.page(3)
|
125
|
-
assert_equal 7, page.first_item_number
|
126
|
-
assert_equal 9, page.last_item_number
|
127
|
-
page = pager.page(4)
|
128
|
-
assert_equal 10, page.first_item_number
|
129
|
-
assert_equal 11, page.last_item_number
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
133
|
-
|
134
|
-
class PaginatorTestWithMathN < PaginatorTest
|
135
|
-
|
136
|
-
def setup
|
137
|
-
require 'mathn'
|
138
|
-
super
|
139
|
-
end
|
140
|
-
|
141
|
-
end
|
data/typus-1.0.0.pre7.gem
DELETED
Binary file
|