typus 1.0.0.pre8 → 1.0.0.pre9
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/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
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'capybara/rails'
|
|
3
|
+
|
|
4
|
+
module ActionController
|
|
5
|
+
|
|
6
|
+
class IntegrationTest
|
|
7
|
+
include Capybara
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module Shoulda
|
|
13
|
+
|
|
14
|
+
module ClassMethods
|
|
15
|
+
|
|
16
|
+
alias :feature :context
|
|
17
|
+
alias :scenario :should
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -2,34 +2,85 @@ require "test_helper"
|
|
|
2
2
|
|
|
3
3
|
class ActiveRecordTest < ActiveSupport::TestCase
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
post = Factory(:post)
|
|
7
|
-
assert_equal "published", post.mapping(:status)
|
|
8
|
-
end
|
|
5
|
+
context "mapping" do
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
post = Factory(:post, :status => "unpublished")
|
|
12
|
-
assert_equal "unpublished", post.mapping(:status)
|
|
13
|
-
end
|
|
7
|
+
context "with an array" do
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
setup do
|
|
10
|
+
Post.send(:remove_const, :STATUS)
|
|
11
|
+
Post::STATUS = %w(pending published unpublished)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
should "verify" do
|
|
15
|
+
post = Factory(:post)
|
|
16
|
+
assert_equal "published", post.mapping(:status)
|
|
17
|
+
post = Factory(:post, :status => "unpublished")
|
|
18
|
+
assert_equal "unpublished", post.mapping(:status)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "with a two dimension array" do
|
|
24
|
+
|
|
25
|
+
setup do
|
|
26
|
+
Post.send(:remove_const, :STATUS)
|
|
27
|
+
Post::STATUS = [["Publicado", "published"], ["Pendiente", "pending"], ["No publicado", "unpublished"]]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
should "verify" do
|
|
31
|
+
post = Factory(:post)
|
|
32
|
+
assert_equal "Publicado", post.mapping(:status)
|
|
33
|
+
post = Factory(:post, :status => "unpublished")
|
|
34
|
+
assert_equal "No publicado", post.mapping(:status)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context "with a hash" do
|
|
40
|
+
|
|
41
|
+
setup do
|
|
42
|
+
Post.send(:remove_const, :STATUS)
|
|
43
|
+
Post::STATUS = { "Pending - Hash" => "pending", "Published - Hash" => "published", "Not Published - Hash" => "unpublished" }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
should "verify" do
|
|
47
|
+
page = Factory(:post)
|
|
48
|
+
assert_equal "Published - Hash", page.mapping(:status)
|
|
49
|
+
page = Factory(:post, :status => "unpublished")
|
|
50
|
+
assert_equal "Not Published - Hash", page.mapping(:status)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
21
54
|
|
|
22
|
-
should "verify to_label instace method" do
|
|
23
|
-
assert_equal "admin@example.com", Factory(:typus_user).to_label
|
|
24
55
|
end
|
|
25
56
|
|
|
26
|
-
|
|
27
|
-
|
|
57
|
+
context "to_label" do
|
|
58
|
+
|
|
59
|
+
should "return email as is an alias for to_label on TypusUser" do
|
|
60
|
+
assert_equal "admin@example.com", Factory(:typus_user).to_label
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
should "return name for Category" do
|
|
64
|
+
category = Factory(:category)
|
|
65
|
+
assert_match category.name, category.to_label
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
should "return default Model#id" do
|
|
69
|
+
assert_match /Post#/, Factory(:post).to_label
|
|
70
|
+
end
|
|
71
|
+
|
|
28
72
|
end
|
|
29
73
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
74
|
+
context "to_resource" do
|
|
75
|
+
|
|
76
|
+
should "work for models" do
|
|
77
|
+
assert_equal "typus_users", TypusUser.to_resource
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
should "work for namespaced models" do
|
|
81
|
+
assert_equal "delayed/tasks", Delayed::Task.to_resource
|
|
82
|
+
end
|
|
83
|
+
|
|
33
84
|
end
|
|
34
85
|
|
|
35
86
|
end
|
|
@@ -2,14 +2,10 @@ require "test_helper"
|
|
|
2
2
|
|
|
3
3
|
class ArrayTest < ActiveSupport::TestCase
|
|
4
4
|
|
|
5
|
-
should "verify
|
|
5
|
+
should "verify to_hash_with" do
|
|
6
6
|
keys, values = %w(a b c), %w(1 2 3)
|
|
7
7
|
expected = { "a" => "1", "b" => "2", "c" => "3" }
|
|
8
|
-
|
|
9
|
-
hash = keys.to_hash_with(values)
|
|
10
|
-
|
|
11
|
-
assert hash.kind_of?(Hash)
|
|
12
|
-
assert_equal expected, hash
|
|
8
|
+
assert_equal expected, keys.to_hash_with(values)
|
|
13
9
|
end
|
|
14
10
|
|
|
15
11
|
end
|
|
@@ -7,42 +7,33 @@ class StringTest < ActiveSupport::TestCase
|
|
|
7
7
|
assert_equal %w( a b c ), " a , b, c ".extract_settings
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
assert_equal "posts", "admin/posts".remove_prefix
|
|
12
|
-
assert_equal "typus_users", "admin/typus_users".remove_prefix
|
|
13
|
-
assert_equal "delayed/jobs", "admin/delayed/jobs".remove_prefix
|
|
14
|
-
end
|
|
10
|
+
context "remove_prefix" do
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
should "remove admin by default" do
|
|
13
|
+
assert_equal "posts", "admin/posts".remove_prefix
|
|
14
|
+
assert_equal "typus_users", "admin/typus_users".remove_prefix
|
|
15
|
+
assert_equal "delayed/jobs", "admin/delayed/jobs".remove_prefix
|
|
16
|
+
end
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
should "remove what we want to" do
|
|
19
|
+
assert_equal "posts", "typus/posts".remove_prefix("typus/")
|
|
20
|
+
assert_equal "typus_users", "typus/typus_users".remove_prefix("typus/")
|
|
21
|
+
assert_equal "delayed/tasks", "typus/delayed/tasks".remove_prefix("typus/")
|
|
22
|
+
end
|
|
27
23
|
|
|
28
|
-
should "extract_class" do
|
|
29
|
-
assert_equal Post, "admin/posts".extract_class
|
|
30
|
-
assert_equal TypusUser, "admin/typus_users".extract_class
|
|
31
|
-
assert_equal Delayed::Task, "admin/delayed/tasks".extract_class
|
|
32
24
|
end
|
|
33
25
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
context "extract_class" do
|
|
27
|
+
|
|
28
|
+
should "work for models" do
|
|
29
|
+
assert_equal Post, "admin/posts".extract_class
|
|
30
|
+
assert_equal TypusUser, "admin/typus_users".extract_class
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
should "work for namespaced models" do
|
|
34
|
+
assert_equal Delayed::Task, "admin/delayed/tasks".extract_class
|
|
35
|
+
end
|
|
39
36
|
|
|
40
|
-
should "verify String#typus_actions_on" do
|
|
41
|
-
assert_equal %w(cleanup), "Post".typus_actions_on("index")
|
|
42
|
-
assert_equal %w(cleanup), "Post".typus_actions_on(:index)
|
|
43
|
-
assert_equal %w(send_as_newsletter preview), "Post".typus_actions_on(:edit)
|
|
44
|
-
assert "TypusUser".typus_actions_on(:unexisting).empty?
|
|
45
|
-
assert "Post".typus_actions_on(:index).kind_of?(Array)
|
|
46
37
|
end
|
|
47
38
|
|
|
48
39
|
end
|
|
@@ -2,70 +2,82 @@ require "test_helper"
|
|
|
2
2
|
|
|
3
3
|
class ActiveRecordTest < ActiveSupport::TestCase
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
context "model_fields" do
|
|
6
|
+
|
|
7
|
+
should "be an ActiveSupport::OrderedHash" do
|
|
8
|
+
assert TypusUser.model_fields.instance_of?(ActiveSupport::OrderedHash)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
should "verify TypusUser model_fields" do
|
|
12
|
+
expected_fields = [[:id, :integer],
|
|
13
|
+
[:first_name, :string],
|
|
14
|
+
[:last_name, :string],
|
|
15
|
+
[:role, :string],
|
|
16
|
+
[:email, :string],
|
|
17
|
+
[:status, :boolean],
|
|
18
|
+
[:token, :string],
|
|
19
|
+
[:salt, :string],
|
|
20
|
+
[:crypted_password, :string],
|
|
21
|
+
[:preferences, :string],
|
|
22
|
+
[:created_at, :datetime],
|
|
23
|
+
[:updated_at, :datetime]]
|
|
24
|
+
assert_equal expected_fields.map { |i| i.first }, TypusUser.model_fields.keys
|
|
25
|
+
assert_equal expected_fields.map { |i| i.last }, TypusUser.model_fields.values
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
should "verify Post model_fields" do
|
|
29
|
+
expected_fields = [[:id, :integer],
|
|
30
|
+
[:title, :string],
|
|
31
|
+
[:body, :text],
|
|
32
|
+
[:status, :string],
|
|
33
|
+
[:favorite_comment_id, :integer],
|
|
34
|
+
[:created_at, :datetime],
|
|
35
|
+
[:updated_at, :datetime],
|
|
36
|
+
[:published_at, :datetime],
|
|
37
|
+
[:typus_user_id, :integer]]
|
|
38
|
+
assert_equal expected_fields.map { |i| i.first }, Post.model_fields.keys
|
|
39
|
+
assert_equal expected_fields.map { |i| i.last }, Post.model_fields.values
|
|
40
|
+
end
|
|
8
41
|
|
|
9
|
-
should "return model fields for TypusUser" do
|
|
10
|
-
expected_fields = [[:id, :integer],
|
|
11
|
-
[:first_name, :string],
|
|
12
|
-
[:last_name, :string],
|
|
13
|
-
[:role, :string],
|
|
14
|
-
[:email, :string],
|
|
15
|
-
[:status, :boolean],
|
|
16
|
-
[:token, :string],
|
|
17
|
-
[:salt, :string],
|
|
18
|
-
[:crypted_password, :string],
|
|
19
|
-
[:preferences, :string],
|
|
20
|
-
[:created_at, :datetime],
|
|
21
|
-
[:updated_at, :datetime]]
|
|
22
|
-
assert_equal expected_fields.map { |i| i.first }, TypusUser.model_fields.keys
|
|
23
|
-
assert_equal expected_fields.map { |i| i.last }, TypusUser.model_fields.values
|
|
24
42
|
end
|
|
25
43
|
|
|
26
|
-
|
|
27
|
-
expected_fields = [[:id, :integer],
|
|
28
|
-
[:title, :string],
|
|
29
|
-
[:body, :text],
|
|
30
|
-
[:status, :string],
|
|
31
|
-
[:favorite_comment_id, :integer],
|
|
32
|
-
[:created_at, :datetime],
|
|
33
|
-
[:updated_at, :datetime],
|
|
34
|
-
[:published_at, :datetime],
|
|
35
|
-
[:typus_user_id, :integer]]
|
|
36
|
-
assert_equal expected_fields.map { |i| i.first }, Post.model_fields.keys
|
|
37
|
-
assert_equal expected_fields.map { |i| i.last }, Post.model_fields.values
|
|
38
|
-
end
|
|
44
|
+
context "model_relationships" do
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
should "be an ActiveSupport::OrderedHash" do
|
|
47
|
+
assert TypusUser.model_relationships.instance_of?(ActiveSupport::OrderedHash)
|
|
48
|
+
end
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
should "verify Post model_relationships" do
|
|
51
|
+
expected = [[:comments, :has_many],
|
|
52
|
+
[:categories, :has_and_belongs_to_many],
|
|
53
|
+
[:user, nil],
|
|
54
|
+
[:assets, :has_many]]
|
|
55
|
+
expected.each do |i|
|
|
56
|
+
assert_equal i.last, Post.model_relationships[i.first]
|
|
57
|
+
end
|
|
51
58
|
end
|
|
59
|
+
|
|
52
60
|
end
|
|
53
61
|
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
context "typus_description" do
|
|
63
|
+
|
|
64
|
+
should "return the description of a model" do
|
|
65
|
+
assert_equal "System Users Administration", TypusUser.typus_description
|
|
66
|
+
end
|
|
67
|
+
|
|
56
68
|
end
|
|
57
69
|
|
|
58
|
-
context "
|
|
70
|
+
context "typus_fields_for" do
|
|
59
71
|
|
|
60
|
-
should "
|
|
72
|
+
should "accept strings" do
|
|
61
73
|
assert_equal %w( email role status ), TypusUser.typus_fields_for("list").keys
|
|
62
74
|
end
|
|
63
75
|
|
|
64
|
-
should "
|
|
76
|
+
should "accept symbols" do
|
|
65
77
|
assert_equal %w( email role status ), TypusUser.typus_fields_for(:list).keys
|
|
66
78
|
end
|
|
67
79
|
|
|
68
|
-
should "
|
|
80
|
+
should "return list fields for TypusUser" do
|
|
69
81
|
expected_fields = [["email", :string],
|
|
70
82
|
["role", :selector],
|
|
71
83
|
["status", :boolean]]
|
|
@@ -73,7 +85,7 @@ class ActiveRecordTest < ActiveSupport::TestCase
|
|
|
73
85
|
assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for(:list).values
|
|
74
86
|
end
|
|
75
87
|
|
|
76
|
-
should "
|
|
88
|
+
should "return form fields for TypusUser" do
|
|
77
89
|
expected_fields = [["first_name", :string],
|
|
78
90
|
["last_name", :string],
|
|
79
91
|
["role", :selector],
|
|
@@ -85,30 +97,30 @@ class ActiveRecordTest < ActiveSupport::TestCase
|
|
|
85
97
|
assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for(:form).values
|
|
86
98
|
end
|
|
87
99
|
|
|
88
|
-
should "
|
|
100
|
+
should "return form fields for Picture" do
|
|
89
101
|
expected_fields = [["title", :string],
|
|
90
102
|
["picture", :file]]
|
|
91
103
|
assert_equal expected_fields.map { |i| i.first }, Picture.typus_fields_for(:form).keys
|
|
92
104
|
assert_equal expected_fields.map { |i| i.last }, Picture.typus_fields_for(:form).values
|
|
93
105
|
end
|
|
94
106
|
|
|
95
|
-
should "
|
|
107
|
+
should "return form fields for a Model without configuration" do
|
|
96
108
|
assert Class.new(ActiveRecord::Base).typus_fields_for(:form).empty?
|
|
97
109
|
end
|
|
98
110
|
|
|
99
|
-
should "
|
|
111
|
+
should "return relationship fields for TypusUser" do
|
|
100
112
|
assert_equal %w( first_name last_name role email language), TypusUser.typus_fields_for(:relationship).keys
|
|
101
113
|
end
|
|
102
114
|
|
|
103
|
-
should "
|
|
115
|
+
should "return undefined fields for TypusUser" do
|
|
104
116
|
assert_equal %w( first_name last_name role email language), TypusUser.typus_fields_for(:undefined).keys
|
|
105
117
|
end
|
|
106
118
|
|
|
107
119
|
end
|
|
108
120
|
|
|
109
|
-
context "
|
|
121
|
+
context "typus_filters" do
|
|
110
122
|
|
|
111
|
-
should "
|
|
123
|
+
should "return filters for TypusUser" do
|
|
112
124
|
expected = [["status", :boolean], ["role", :string]]
|
|
113
125
|
|
|
114
126
|
assert_equal expected.map { |i| i.first }.join(", "), Typus::Configuration.config["TypusUser"]["filters"]
|
|
@@ -116,7 +128,7 @@ class ActiveRecordTest < ActiveSupport::TestCase
|
|
|
116
128
|
assert_equal expected.map { |i| i.last }, TypusUser.typus_filters.values
|
|
117
129
|
end
|
|
118
130
|
|
|
119
|
-
should "
|
|
131
|
+
should "return filters for Post" do
|
|
120
132
|
expected = [["status", :string], ["created_at", :datetime]]
|
|
121
133
|
assert_equal expected.map { |i| i.first }.join(", "), Typus::Configuration.config["Post"]["filters"]
|
|
122
134
|
assert_equal expected.map { |i| i.first }, Post.typus_filters.keys
|
|
@@ -125,52 +137,63 @@ class ActiveRecordTest < ActiveSupport::TestCase
|
|
|
125
137
|
|
|
126
138
|
end
|
|
127
139
|
|
|
128
|
-
context "
|
|
140
|
+
context "typus_actions_on" do
|
|
129
141
|
|
|
130
|
-
should "
|
|
142
|
+
should "accept strings" do
|
|
131
143
|
assert_equal %w( cleanup ), Post.typus_actions_on("index")
|
|
132
144
|
end
|
|
133
145
|
|
|
134
|
-
should "
|
|
146
|
+
should "accept symbols" do
|
|
135
147
|
assert_equal %w( cleanup ), Post.typus_actions_on(:index)
|
|
136
148
|
end
|
|
137
149
|
|
|
138
|
-
should "
|
|
150
|
+
should "return actions on list for TypusUser" do
|
|
139
151
|
assert TypusUser.typus_actions_on(:list).empty?
|
|
140
152
|
end
|
|
141
153
|
|
|
142
|
-
should "return
|
|
154
|
+
should "return actions on edit for Post" do
|
|
143
155
|
assert_equal %w( send_as_newsletter preview ), Post.typus_actions_on(:edit)
|
|
144
156
|
end
|
|
145
157
|
|
|
146
|
-
should "return Post actions" do
|
|
147
|
-
assert_equal %w( cleanup preview send_as_newsletter ), Post.typus_actions.sort
|
|
148
|
-
end
|
|
149
|
-
|
|
150
158
|
end
|
|
151
159
|
|
|
152
|
-
context "
|
|
160
|
+
context "typus_options_for" do
|
|
153
161
|
|
|
154
|
-
should "
|
|
162
|
+
should "accept strings" do
|
|
155
163
|
assert_equal 15, Post.typus_options_for("form_rows")
|
|
156
164
|
end
|
|
157
165
|
|
|
158
|
-
should "
|
|
166
|
+
should "accept symbols" do
|
|
159
167
|
assert_equal 15, Post.typus_options_for(:form_rows)
|
|
160
168
|
end
|
|
161
169
|
|
|
162
|
-
should "
|
|
163
|
-
|
|
170
|
+
should "return nil when options do not exist" do
|
|
171
|
+
assert_nil TypusUser.typus_options_for(:unexisting)
|
|
164
172
|
end
|
|
165
173
|
|
|
166
|
-
should "return options for
|
|
174
|
+
should "return options for Post" do
|
|
167
175
|
assert_equal 15, Post.typus_options_for(:form_rows)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
should "return options for Page" do
|
|
168
179
|
assert_equal 25, Page.typus_options_for(:form_rows)
|
|
169
180
|
end
|
|
170
181
|
|
|
171
182
|
end
|
|
172
183
|
|
|
173
|
-
context "
|
|
184
|
+
context "typus_application" do
|
|
185
|
+
|
|
186
|
+
should "return application for Post" do
|
|
187
|
+
assert_equal "Blog", Post.typus_application
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
should "return application for View" do
|
|
191
|
+
assert_equal "Unknown", View.typus_application
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
context "typus_field_options_for" do
|
|
174
197
|
|
|
175
198
|
should "verify on models" do
|
|
176
199
|
assert_equal [ :status ], Post.typus_field_options_for(:selectors)
|
|
@@ -180,71 +203,110 @@ class ActiveRecordTest < ActiveSupport::TestCase
|
|
|
180
203
|
|
|
181
204
|
end
|
|
182
205
|
|
|
183
|
-
context "
|
|
206
|
+
context "typus_boolean" do
|
|
184
207
|
|
|
185
|
-
should "
|
|
186
|
-
|
|
208
|
+
should "accept strings" do
|
|
209
|
+
expected = {"Inactive"=>"false", "Active"=>"true"}
|
|
210
|
+
assert_equal expected, TypusUser.typus_boolean("status")
|
|
187
211
|
end
|
|
188
212
|
|
|
189
|
-
should "
|
|
190
|
-
|
|
213
|
+
should "accept symbols" do
|
|
214
|
+
expected = {"Inactive"=>"false", "Active"=>"true"}
|
|
215
|
+
assert_equal expected, TypusUser.typus_boolean(:status)
|
|
191
216
|
end
|
|
192
217
|
|
|
193
|
-
should "
|
|
194
|
-
|
|
218
|
+
should "return booleans for TypusUser" do
|
|
219
|
+
expected = {"Active" => "true", "Inactive" => "false"}
|
|
220
|
+
assert_equal expected, TypusUser.typus_boolean(:status)
|
|
195
221
|
end
|
|
196
222
|
|
|
197
|
-
should "
|
|
198
|
-
|
|
199
|
-
assert_equal
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
should "return_booleans_for_post" do
|
|
203
|
-
assert_equal [ :true, :false ], Post.typus_boolean(:status).keys
|
|
204
|
-
assert_equal [ "True", "False" ], Post.typus_boolean(:status).values
|
|
223
|
+
should "return booleans for Post" do
|
|
224
|
+
expected = {"True" => "true", "False" => "false"}
|
|
225
|
+
assert_equal expected, Post.typus_boolean(:status)
|
|
205
226
|
end
|
|
206
227
|
|
|
207
228
|
end
|
|
208
229
|
|
|
209
|
-
context "
|
|
230
|
+
context "typus_date_format" do
|
|
210
231
|
|
|
211
|
-
should "
|
|
232
|
+
should "accept strings" do
|
|
212
233
|
assert_equal :db, Post.typus_date_format("unknown")
|
|
213
234
|
end
|
|
214
235
|
|
|
215
|
-
should "
|
|
236
|
+
should "accept symbols" do
|
|
216
237
|
assert_equal :db, Post.typus_date_format(:unknown)
|
|
217
238
|
end
|
|
218
239
|
|
|
219
|
-
should "return
|
|
240
|
+
should "return date_format for Post" do
|
|
220
241
|
assert_equal :db, Post.typus_date_format
|
|
221
242
|
assert_equal :post_short, Post.typus_date_format(:created_at)
|
|
222
243
|
end
|
|
223
244
|
|
|
224
245
|
end
|
|
225
246
|
|
|
226
|
-
context "
|
|
247
|
+
context "typus_template" do
|
|
227
248
|
|
|
228
|
-
should "
|
|
229
|
-
assert_equal
|
|
249
|
+
should "accept strings" do
|
|
250
|
+
assert_equal "datepicker", Post.typus_template("published_at")
|
|
230
251
|
end
|
|
231
252
|
|
|
232
|
-
should "
|
|
233
|
-
assert_equal
|
|
253
|
+
should "accept symbols" do
|
|
254
|
+
assert_equal "datepicker", Post.typus_template(:published_at)
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
should "return nil if template does not exist" do
|
|
258
|
+
assert_nil Post.typus_template(:created_at)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
context "typus_defaults_for" do
|
|
264
|
+
|
|
265
|
+
should "accept strings" do
|
|
266
|
+
assert_equal %w( title ), Post.typus_defaults_for("search")
|
|
234
267
|
end
|
|
235
268
|
|
|
236
|
-
should "
|
|
269
|
+
should "accepts symbols" do
|
|
237
270
|
assert_equal %w( title ), Post.typus_defaults_for(:search)
|
|
238
271
|
end
|
|
239
272
|
|
|
240
273
|
should "return default_for relationships on Post" do
|
|
241
274
|
assert_equal %w( assets categories comments views ), Post.typus_defaults_for(:relationships)
|
|
242
|
-
assert !Post.typus_defaults_for(:relationships).empty?
|
|
243
275
|
end
|
|
244
276
|
|
|
245
277
|
end
|
|
246
278
|
|
|
247
|
-
context "
|
|
279
|
+
context "typus_search_fields" do
|
|
280
|
+
|
|
281
|
+
should "return a hash with the search modifiers" do
|
|
282
|
+
search = ["=id", "^title", "body"]
|
|
283
|
+
Post.stubs(:typus_defaults_for).with(:search).returns(search)
|
|
284
|
+
expected = {"body"=>"@", "title"=>"^", "id"=>"="}
|
|
285
|
+
assert_equal expected, Post.typus_search_fields
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
should "return and empty hash" do
|
|
289
|
+
search = []
|
|
290
|
+
Post.stubs(:typus_defaults_for).with(:search).returns(search)
|
|
291
|
+
expected = {}
|
|
292
|
+
assert_equal expected, Post.typus_search_fields
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
context "typus_export_formats" do
|
|
298
|
+
|
|
299
|
+
should "return post formats" do
|
|
300
|
+
assert_equal ["csv", "xml"], Post.typus_export_formats
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
should "return picture formats" do
|
|
304
|
+
assert_equal [], Picture.typus_export_formats
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
context "typus_order_by" do
|
|
248
310
|
|
|
249
311
|
should "return defaults_for order_by on Post" do
|
|
250
312
|
assert_equal "posts.title ASC, posts.created_at DESC", Post.typus_order_by
|
|
@@ -253,7 +315,7 @@ class ActiveRecordTest < ActiveSupport::TestCase
|
|
|
253
315
|
|
|
254
316
|
end
|
|
255
317
|
|
|
256
|
-
context "
|
|
318
|
+
context "build_conditions" do
|
|
257
319
|
|
|
258
320
|
should "generate conditions for id" do
|
|
259
321
|
Post.stubs(:typus_defaults_for).with(:search).returns(["id"])
|
|
@@ -374,7 +436,7 @@ class ActiveRecordTest < ActiveSupport::TestCase
|
|
|
374
436
|
|
|
375
437
|
end
|
|
376
438
|
|
|
377
|
-
context "
|
|
439
|
+
context "class_methods" do
|
|
378
440
|
|
|
379
441
|
should "verify typus_user_id exists on Post" do
|
|
380
442
|
assert Post.typus_user_id?
|