typus 3.0.6 → 3.0.7
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/.gemtest +0 -0
- data/.gitignore +15 -0
- data/Gemfile +9 -5
- data/Rakefile +34 -21
- data/app/controllers/admin/base_controller.rb +0 -4
- data/app/controllers/admin/resources_controller.rb +77 -213
- data/app/controllers/admin/session_controller.rb +1 -1
- data/app/helpers/admin/base_helper.rb +4 -4
- data/app/helpers/admin/dashboard_helper.rb +1 -3
- data/app/helpers/admin/display_helper.rb +49 -0
- data/app/helpers/admin/file_preview_helper.rb +10 -12
- data/app/helpers/admin/filters_helper.rb +1 -1
- data/app/helpers/admin/form_helper.rb +2 -13
- data/app/helpers/admin/list_helper.rb +14 -3
- data/app/helpers/admin/relationships_helper.rb +79 -62
- data/app/helpers/admin/resources_helper.rb +17 -16
- data/app/helpers/admin/search_helper.rb +1 -1
- data/app/helpers/admin/sidebar_helper.rb +1 -2
- data/app/helpers/admin/table_helper.rb +9 -4
- data/app/views/admin/helpers/_file_preview.html.erb +1 -1
- data/app/views/admin/helpers/base/_apps.html.erb +23 -0
- data/app/views/admin/helpers/{_flash_message.html.erb → base/_flash_message.html.erb} +0 -0
- data/app/views/admin/helpers/{_header.html.erb → base/_header.html.erb} +0 -0
- data/app/views/admin/helpers/{_login_info.html.erb → base/_login_info.html.erb} +0 -0
- data/app/views/admin/helpers/resources/_display_link_to_previous.html.erb +1 -1
- data/app/views/admin/resources/show.html.erb +4 -27
- data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +11 -0
- data/app/views/admin/templates/_has_n.html.erb +1 -1
- data/app/views/admin/templates/_has_one.html.erb +3 -3
- data/app/views/admin/templates/_relate_form.html.erb +1 -1
- data/app/views/admin/templates/_relate_form_with_autocomplete.html.erb +24 -0
- data/app/views/layouts/admin/base.html.erb +15 -9
- data/app/views/layouts/admin/headless.html.erb +44 -0
- data/app/views/layouts/admin/session.html.erb +3 -2
- data/doc/hudson_setup.md +19 -0
- data/lib/generators/typus/assets_generator.rb +0 -4
- data/lib/generators/typus/config_generator.rb +107 -0
- data/lib/generators/typus/controller_generator.rb +0 -4
- data/lib/generators/typus/initializers_generator.rb +22 -0
- data/lib/generators/typus/migration_generator.rb +0 -4
- data/lib/generators/typus/typus_generator.rb +8 -101
- data/lib/generators/typus/views_generator.rb +0 -4
- data/lib/support/active_record.rb +8 -2
- data/lib/support/fake_user.rb +2 -0
- data/lib/support/hash.rb +1 -1
- data/lib/support/string.rb +3 -3
- data/lib/tasks/typus.rake +1 -1
- data/lib/typus.rb +15 -6
- data/lib/typus/controller/actions.rb +69 -0
- data/lib/typus/controller/associations.rb +82 -0
- data/lib/typus/controller/autocomplete.rb +16 -0
- data/lib/typus/controller/filters.rb +24 -0
- data/lib/typus/controller/format.rb +70 -0
- data/lib/typus/orm/active_record.rb +9 -240
- data/lib/typus/orm/active_record/class_methods.rb +227 -0
- data/lib/typus/orm/active_record/instance_methods.rb +13 -0
- data/lib/typus/orm/active_record/search.rb +17 -5
- data/lib/typus/orm/active_record/user.rb +157 -0
- data/lib/typus/regex.rb +11 -0
- data/lib/typus/version.rb +1 -1
- data/test/app/controllers/admin/account_controller_test.rb +104 -0
- data/test/app/controllers/admin/assets_controller_test.rb +153 -0
- data/test/app/controllers/admin/base_controller_test.rb +41 -0
- data/test/app/controllers/admin/birds_controller_test.rb +42 -0
- data/test/app/controllers/admin/cases_controller_test.rb +21 -0
- data/test/app/controllers/admin/categories_controller_test.rb +141 -0
- data/test/app/controllers/admin/comments_controller_test.rb +79 -0
- data/test/app/controllers/admin/dashboard_controller_test.rb +162 -0
- data/test/app/controllers/admin/image_holders_controller_test.rb +75 -0
- data/test/app/controllers/admin/invoices_controller_test.rb +78 -0
- data/test/app/controllers/admin/orders_controller_test.rb +18 -0
- data/test/app/controllers/admin/pages_controller_test.rb +37 -0
- data/test/app/controllers/admin/posts_controller_test.rb +745 -0
- data/test/app/controllers/admin/projects_controller_test.rb +52 -0
- data/test/app/controllers/admin/session_controller_test.rb +92 -0
- data/test/app/controllers/admin/status_controller_test.rb +54 -0
- data/test/app/controllers/admin/typus_users_controller_test.rb +160 -0
- data/test/app/controllers/admin/users_controller_test.rb +106 -0
- data/test/app/helpers/admin/base_helper_test.rb +83 -0
- data/test/app/helpers/admin/dashboard_helper_test.rb +32 -0
- data/test/app/helpers/admin/file_preview_helper_test.rb +82 -0
- data/test/app/helpers/admin/filters_helper_test.rb +161 -0
- data/test/app/helpers/admin/form_helper_test.rb +126 -0
- data/test/app/helpers/admin/list_helper_test.rb +59 -0
- data/test/app/helpers/admin/relationships_helper_test.rb +19 -0
- data/test/app/helpers/admin/resources_helper_test.rb +46 -0
- data/test/app/helpers/admin/search_helper_test.rb +60 -0
- data/test/app/helpers/admin/sidebar_helper_test.rb +34 -0
- data/test/app/helpers/admin/table_helper_test.rb +215 -0
- data/test/app/mailers/admin/mailer_test.rb +32 -0
- data/test/app/models/typus_user_roles_test.rb +124 -0
- data/test/app/models/typus_user_test.rb +194 -0
- data/test/config/routes_test.rb +29 -0
- data/test/factories.rb +111 -0
- data/test/fixtures/config/broken/application.yml +68 -0
- data/test/fixtures/config/broken/application_roles.yml +20 -0
- data/test/fixtures/config/broken/empty.yml +0 -0
- data/test/fixtures/config/broken/empty_roles.yml +0 -0
- data/test/fixtures/config/broken/undefined.yml +3 -0
- data/test/fixtures/config/broken/undefined_roles.yml +6 -0
- data/test/fixtures/config/default/typus.yml +13 -0
- data/test/fixtures/config/default/typus_roles.yml +2 -0
- data/test/fixtures/config/empty/empty_01.yml +0 -0
- data/test/fixtures/config/empty/empty_01_roles.yml +0 -0
- data/test/fixtures/config/empty/empty_02.yml +0 -0
- data/test/fixtures/config/empty/empty_02_roles.yml +0 -0
- data/test/fixtures/config/locales/es.yml +10 -0
- data/test/fixtures/config/namespaced/application.yml +5 -0
- data/test/fixtures/config/namespaced/application_roles.yml +2 -0
- data/test/fixtures/config/ordered/001_roles.yml +2 -0
- data/test/fixtures/config/ordered/002_roles.yml +2 -0
- data/test/fixtures/config/unordered/app_one_roles.yml +2 -0
- data/test/fixtures/config/unordered/app_two_roles.yml +2 -0
- data/test/fixtures/rails_app/.gitignore +4 -0
- data/test/fixtures/rails_app/Capfile +6 -0
- data/test/fixtures/rails_app/README +256 -0
- data/test/fixtures/rails_app/Rakefile +7 -0
- data/test/fixtures/rails_app/app/controllers/admin/animals_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/articles_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/assets_controller.rb +51 -0
- data/test/fixtures/rails_app/app/controllers/admin/birds_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/cases_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/categories_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/comments_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/dogs_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/entries_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/image_holders_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/invoices_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/orders_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/pages_controller.rb +7 -0
- data/test/fixtures/rails_app/app/controllers/admin/posts_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/project_collaborators_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/projects_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/status_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/typus_users_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/users_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/views_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/watch_dog_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/application_controller.rb +3 -0
- data/test/fixtures/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/fixtures/rails_app/app/helpers/form_helper.rb +3 -0
- data/test/fixtures/rails_app/app/models/animal.rb +21 -0
- data/test/fixtures/rails_app/app/models/article.rb +10 -0
- data/test/fixtures/rails_app/app/models/asset.rb +39 -0
- data/test/fixtures/rails_app/app/models/bird.rb +2 -0
- data/test/fixtures/rails_app/app/models/case.rb +2 -0
- data/test/fixtures/rails_app/app/models/category.rb +31 -0
- data/test/fixtures/rails_app/app/models/comment.rb +17 -0
- data/test/fixtures/rails_app/app/models/delayed/task.rb +5 -0
- data/test/fixtures/rails_app/app/models/dog.rb +2 -0
- data/test/fixtures/rails_app/app/models/entry.rb +23 -0
- data/test/fixtures/rails_app/app/models/image_holder.rb +21 -0
- data/test/fixtures/rails_app/app/models/invoice.rb +10 -0
- data/test/fixtures/rails_app/app/models/order.rb +9 -0
- data/test/fixtures/rails_app/app/models/page.rb +24 -0
- data/test/fixtures/rails_app/app/models/post.rb +32 -0
- data/test/fixtures/rails_app/app/models/project.rb +17 -0
- data/test/fixtures/rails_app/app/models/project_collaborator.rb +16 -0
- data/test/fixtures/rails_app/app/models/typus_user.rb +22 -0
- data/test/fixtures/rails_app/app/models/user.rb +10 -0
- data/test/fixtures/rails_app/app/models/view.rb +17 -0
- data/test/fixtures/rails_app/app/views/admin/assets/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/cases/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/categories/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/dashboard/_sidebar.html.erb +11 -0
- data/test/fixtures/rails_app/app/views/admin/entries/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/pages/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_edit.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_index.html.erb +5 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_new.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_show.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/resources/_sidebar.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/status/index.html.erb +9 -0
- data/test/fixtures/rails_app/app/views/admin/templates/_datepicker.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/watch_dog/index.html.erb +9 -0
- data/test/fixtures/rails_app/app/views/layouts/admin/headless.html.erb +38 -0
- data/test/fixtures/rails_app/config.ru +4 -0
- data/test/fixtures/rails_app/config/application.rb +44 -0
- data/test/fixtures/rails_app/config/boot.rb +13 -0
- data/test/fixtures/rails_app/config/database.yml +34 -0
- data/test/fixtures/rails_app/config/deploy.rb +32 -0
- data/test/fixtures/rails_app/config/environment.rb +5 -0
- data/test/fixtures/rails_app/config/environments/development.rb +32 -0
- data/test/fixtures/rails_app/config/environments/production.rb +54 -0
- data/test/fixtures/rails_app/config/environments/test.rb +40 -0
- data/test/fixtures/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/fixtures/rails_app/config/initializers/dragonfly.rb +1 -0
- data/test/fixtures/rails_app/config/initializers/inflections.rb +12 -0
- data/test/fixtures/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/fixtures/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/fixtures/rails_app/config/initializers/session_store.rb +8 -0
- data/test/fixtures/rails_app/config/initializers/typus.rb +5 -0
- data/test/fixtures/rails_app/config/initializers/typus_resources.rb +27 -0
- data/test/fixtures/rails_app/config/locales/en.yml +5 -0
- data/test/fixtures/rails_app/config/routes.rb +61 -0
- data/test/fixtures/rails_app/config/typus/README +68 -0
- data/test/fixtures/rails_app/config/typus/crud_basic.yml +10 -0
- data/test/fixtures/rails_app/config/typus/crud_basic_roles.yml +2 -0
- data/test/fixtures/rails_app/config/typus/crud_extended.yml +64 -0
- data/test/fixtures/rails_app/config/typus/crud_extended_roles.yml +18 -0
- data/test/fixtures/rails_app/config/typus/has_many.yml +0 -0
- data/test/fixtures/rails_app/config/typus/has_many_roles.yml +0 -0
- data/test/fixtures/rails_app/config/typus/has_many_through.yml +23 -0
- data/test/fixtures/rails_app/config/typus/has_many_through_roles.yml +4 -0
- data/test/fixtures/rails_app/config/typus/has_one.yml +12 -0
- data/test/fixtures/rails_app/config/typus/has_one_roles.yml +3 -0
- data/test/fixtures/rails_app/config/typus/polymorphic.yml +17 -0
- data/test/fixtures/rails_app/config/typus/polymorphic_roles.yml +5 -0
- data/test/fixtures/rails_app/config/typus/resource_roles.yml +7 -0
- data/test/fixtures/rails_app/config/typus/sti.yml +5 -0
- data/test/fixtures/rails_app/config/typus/sti_roles.yml +2 -0
- data/test/fixtures/rails_app/config/typus/typus.yml +13 -0
- data/test/fixtures/rails_app/config/typus/typus_roles.yml +2 -0
- data/test/fixtures/rails_app/config/typus/unknown.yml +3 -0
- data/test/fixtures/rails_app/config/typus/unknown_roles.yml +5 -0
- data/test/fixtures/rails_app/db/.gitkeep +0 -0
- data/test/fixtures/rails_app/db/schema.rb +174 -0
- data/test/fixtures/rails_app/db/seeds.rb +54 -0
- data/test/fixtures/rails_app/db/seeds/assets/000.jpg +0 -0
- data/test/fixtures/rails_app/db/seeds/assets/001.jpg +0 -0
- data/test/fixtures/rails_app/db/seeds/assets/002.jpg +0 -0
- data/test/fixtures/rails_app/db/seeds/assets/003.jpg +0 -0
- data/test/fixtures/rails_app/db/seeds/assets/004.jpg +0 -0
- data/test/fixtures/rails_app/public/404.html +26 -0
- data/test/fixtures/rails_app/public/422.html +26 -0
- data/test/fixtures/rails_app/public/500.html +26 -0
- 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/javascripts/application.js +2 -0
- data/test/fixtures/rails_app/public/javascripts/controls.js +965 -0
- data/test/fixtures/rails_app/public/javascripts/dragdrop.js +974 -0
- data/test/fixtures/rails_app/public/javascripts/effects.js +1123 -0
- data/test/fixtures/rails_app/public/javascripts/prototype.js +6001 -0
- data/test/fixtures/rails_app/public/javascripts/rails.js +175 -0
- data/test/fixtures/rails_app/public/robots.txt +5 -0
- data/test/fixtures/rails_app/public/stylesheets/.gitkeep +0 -0
- data/test/fixtures/rails_app/script/rails +6 -0
- data/test/lib/support/active_record_test.rb +150 -0
- data/test/lib/support/fake_user_test.rb +59 -0
- data/test/lib/support/hash_test.rb +29 -0
- data/test/lib/support/object_test.rb +17 -0
- data/test/lib/support/string_test.rb +116 -0
- data/test/lib/typus/configuration_test.rb +46 -0
- data/test/lib/typus/controller/actions_test.rb +141 -0
- data/test/lib/typus/controller/associations_test.rb +7 -0
- data/test/lib/typus/controller/autocomplete_test.rb +7 -0
- data/test/lib/typus/controller/filters_test.rb +73 -0
- data/test/lib/typus/controller/format_test.rb +7 -0
- data/test/lib/typus/i18n_test.rb +9 -0
- data/test/lib/typus/orm/active_record/class_methods_test.rb +378 -0
- data/test/lib/typus/orm/active_record/search_test.rb +330 -0
- data/test/lib/typus/regex_test.rb +53 -0
- data/test/lib/typus/resources_test.rb +41 -0
- data/test/lib/typus_test.rb +141 -0
- data/test/test_helper.rb +15 -0
- data/typus.gemspec +25 -0
- metadata +586 -64
- data/Gemfile.lock +0 -149
- data/app/views/admin/helpers/_apps.html.erb +0 -9
- data/lib/generators/templates/public/admin/javascripts/application.js +0 -2
- data/lib/generators/templates/public/admin/javascripts/jquery-1.4.4.min.js +0 -167
- data/lib/generators/templates/public/admin/javascripts/jquery.application.js +0 -16
- data/lib/generators/templates/public/admin/javascripts/jquery.rails.js +0 -160
- data/lib/generators/templates/public/admin/javascripts/jquery.searchField.js +0 -91
- data/lib/generators/templates/public/admin/stylesheets/application.css +0 -11
- data/lib/generators/templates/public/admin/stylesheets/screen.css +0 -367
- data/lib/generators/templates/public/admin/vendor/fancybox/blank.gif +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_close.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_loading.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_nav_left.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_nav_right.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_e.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_n.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_ne.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_nw.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_s.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_se.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_sw.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_w.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_left.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_main.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_over.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_right.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancybox-x.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancybox-y.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancybox.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.easing-1.3.pack.js +0 -72
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.css +0 -359
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.js +0 -1156
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.pack.js +0 -46
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.mousewheel-3.0.4.pack.js +0 -14
- data/lib/typus/actions.rb +0 -41
- data/lib/typus/filters.rb +0 -12
- data/lib/typus/format.rb +0 -70
- data/lib/typus/user.rb +0 -157
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class StringTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
should "extract_settings" do
|
|
6
|
+
assert_equal %w( a b c ), "a, b, c".extract_settings
|
|
7
|
+
assert_equal %w( a b c ), " a , b, c ".extract_settings
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "remove_prefix" do
|
|
11
|
+
|
|
12
|
+
should "return strings without default prefix" 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
|
|
17
|
+
|
|
18
|
+
should "return strings without custom prefix" do
|
|
19
|
+
assert_equal "posts", "typus/posts".remove_prefix
|
|
20
|
+
assert_equal "typus_users", "typus/typus_users".remove_prefix
|
|
21
|
+
assert_equal "delayed/tasks", "typus/delayed/tasks".remove_prefix
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "extract_class" do
|
|
27
|
+
|
|
28
|
+
setup do
|
|
29
|
+
class SucursalBancaria; end
|
|
30
|
+
|
|
31
|
+
Typus::Configuration.models_constantized = { "Post" => Post,
|
|
32
|
+
"TypusUser" => TypusUser,
|
|
33
|
+
"Delayed::Task" => Delayed::Task,
|
|
34
|
+
"SucursalBancaria" => SucursalBancaria }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
should "work for models" do
|
|
38
|
+
assert_equal Post, "admin/posts".extract_class
|
|
39
|
+
assert_equal TypusUser, "admin/typus_users".extract_class
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
should "work for namespaced models" do
|
|
43
|
+
assert_equal Delayed::Task, "admin/delayed/tasks".extract_class
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
should "work with inflections" do
|
|
47
|
+
assert_equal SucursalBancaria, "admin/sucursales_bancarias".extract_class
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "action_mapper" do
|
|
53
|
+
|
|
54
|
+
should "return list for index" do
|
|
55
|
+
assert_equal :list, 'index'.action_mapper
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
should "return form for new, create, edit and update" do
|
|
59
|
+
%w(new create edit update).each do |action|
|
|
60
|
+
assert_equal :form, action.action_mapper
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
should "return the same action for everything else" do
|
|
65
|
+
assert_equal 'undefined', 'undefined'.action_mapper
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context "acl_action_mapper" do
|
|
71
|
+
|
|
72
|
+
should "return create" do
|
|
73
|
+
%w(new create).each do |action|
|
|
74
|
+
assert_equal "create", action.acl_action_mapper
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
should "return read" do
|
|
79
|
+
%w(index show).each do |action|
|
|
80
|
+
assert_equal "read", action.acl_action_mapper
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
should "return update" do
|
|
85
|
+
%w(edit update position toggle relate unrelate).each do |action|
|
|
86
|
+
assert_equal "update", action.acl_action_mapper
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
should "return delete" do
|
|
91
|
+
%w(destroy trash).each do |action|
|
|
92
|
+
assert_equal "delete", action.acl_action_mapper
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
should "return other" do
|
|
97
|
+
%w(other).each do |action|
|
|
98
|
+
assert_equal "other", action.acl_action_mapper
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
context "to_resource" do
|
|
105
|
+
|
|
106
|
+
should "convert String into resource" do
|
|
107
|
+
assert_equal "entries", "Entry".to_resource
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
should "convert namespaced String into resource" do
|
|
111
|
+
assert_equal "category/entries", "Category::Entry".to_resource
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class ConfigurationTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
should "verify typus roles is loaded" do
|
|
6
|
+
assert Typus::Configuration.respond_to?(:roles!)
|
|
7
|
+
assert Typus::Configuration.roles!.is_a?(Hash)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
should "verify typus config file is loaded" do
|
|
11
|
+
assert Typus::Configuration.respond_to?(:config!)
|
|
12
|
+
assert Typus::Configuration.config!.is_a?(Hash)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
should "load configuration files from config broken" do
|
|
16
|
+
Typus.expects(:config_folder).at_least_once.returns("test/fixtures/config/broken")
|
|
17
|
+
assert_not_equal Hash.new, Typus::Configuration.roles!
|
|
18
|
+
assert_not_equal Hash.new, Typus::Configuration.config!
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
should "load configuration files from config empty" do
|
|
22
|
+
Typus.expects(:config_folder).at_least_once.returns("test/fixtures/config/empty")
|
|
23
|
+
assert_equal Hash.new, Typus::Configuration.roles!
|
|
24
|
+
assert_equal Hash.new, Typus::Configuration.config!
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
should "load configuration files from config ordered" do
|
|
28
|
+
Typus.expects(:config_folder).at_least_once.returns("test/fixtures/config/ordered")
|
|
29
|
+
expected = { "admin" => { "categories" => "read" } }
|
|
30
|
+
assert_equal expected, Typus::Configuration.roles!
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
should "load configuration files from config unordered" do
|
|
34
|
+
Typus.expects(:config_folder).at_least_once.returns("test/fixtures/config/unordered")
|
|
35
|
+
expected = { "admin" => { "categories" => "read, update" } }
|
|
36
|
+
assert_equal expected, Typus::Configuration.roles!
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
should "load configuration files from config default" do
|
|
40
|
+
Typus.expects(:config_folder).at_least_once.returns("test/fixtures/config/default")
|
|
41
|
+
assert_not_equal Hash.new, Typus::Configuration.roles!
|
|
42
|
+
assert_not_equal Hash.new, Typus::Configuration.config!
|
|
43
|
+
assert Typus.resources.empty?
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class ActionsTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
include Typus::Controller::Actions
|
|
6
|
+
|
|
7
|
+
context "add_resource_action" do
|
|
8
|
+
|
|
9
|
+
should "work" do
|
|
10
|
+
output = add_resource_action("something")
|
|
11
|
+
assert_equal [["something"]], @resource_actions
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
should "work when no params are set" do
|
|
15
|
+
add_resource_action()
|
|
16
|
+
assert @resource_actions.empty?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "prepend_resource_action" do
|
|
22
|
+
|
|
23
|
+
should "work without args" do
|
|
24
|
+
prepend_resource_action()
|
|
25
|
+
assert @resource_actions.empty?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
should "work with args" do
|
|
29
|
+
prepend_resource_action("something")
|
|
30
|
+
assert_equal [["something"]], @resource_actions
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
should "work prepending an action without args" do
|
|
34
|
+
add_resource_action("something")
|
|
35
|
+
prepend_resource_action()
|
|
36
|
+
assert_equal [["something"]], @resource_actions
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
should "work prepending an action with args" do
|
|
40
|
+
add_resource_action("something")
|
|
41
|
+
prepend_resource_action("something_else")
|
|
42
|
+
assert_equal [["something_else"], ["something"]], @resource_actions
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "append_resource_action" do
|
|
48
|
+
|
|
49
|
+
should "work without args" do
|
|
50
|
+
append_resource_action()
|
|
51
|
+
assert @resource_actions.empty?
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
should "work with args" do
|
|
55
|
+
append_resource_action("something")
|
|
56
|
+
assert_equal [["something"]], @resource_actions
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
should "work appending an action without args" do
|
|
60
|
+
add_resource_action("something")
|
|
61
|
+
append_resource_action()
|
|
62
|
+
assert_equal [["something"]], @resource_actions
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
should "work appending an action with args" do
|
|
66
|
+
add_resource_action("something")
|
|
67
|
+
append_resource_action("something_else")
|
|
68
|
+
assert_equal [["something"], ["something_else"]], @resource_actions
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# FIXME: Cleanup all test after this line.
|
|
74
|
+
|
|
75
|
+
context "add_resources_action" do
|
|
76
|
+
|
|
77
|
+
should "work" do
|
|
78
|
+
add_resources_action("something")
|
|
79
|
+
assert_equal [["something"]], @resources_actions
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
should "work when no params are set" do
|
|
83
|
+
add_resources_action()
|
|
84
|
+
assert @resources_actions.empty?
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context "prepend_resources_action" do
|
|
90
|
+
|
|
91
|
+
should "work without args" do
|
|
92
|
+
prepend_resources_action()
|
|
93
|
+
assert @resources_actions.empty?
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
should "work with args" do
|
|
97
|
+
prepend_resources_action("something")
|
|
98
|
+
assert_equal [["something"]], @resources_actions
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
should "work prepending an action without args" do
|
|
102
|
+
add_resources_action("something")
|
|
103
|
+
prepend_resources_action()
|
|
104
|
+
assert_equal [["something"]], @resources_actions
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
should "work prepending an action with args" do
|
|
108
|
+
add_resources_action("something")
|
|
109
|
+
prepend_resources_action("something_else")
|
|
110
|
+
assert_equal [["something_else"], ["something"]], @resources_actions
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
context "append_resources_action" do
|
|
116
|
+
|
|
117
|
+
should "work without args" do
|
|
118
|
+
append_resources_action()
|
|
119
|
+
assert @resources_actions.empty?
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
should "work with args" do
|
|
123
|
+
append_resources_action("something")
|
|
124
|
+
assert_equal [["something"]], @resources_actions
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
should "work appending an action without args" do
|
|
128
|
+
add_resources_action("something")
|
|
129
|
+
append_resources_action()
|
|
130
|
+
assert_equal [["something"]], @resources_actions
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
should "work appending an action with args" do
|
|
134
|
+
add_resources_action("something")
|
|
135
|
+
append_resources_action("something_else")
|
|
136
|
+
assert_equal [["something"], ["something_else"]], @resources_actions
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class FiltersTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
include Typus::Controller::Filters
|
|
6
|
+
|
|
7
|
+
context "add_predefined_filter" do
|
|
8
|
+
|
|
9
|
+
should "work without args" do
|
|
10
|
+
add_predefined_filter()
|
|
11
|
+
assert @predefined_filters.empty?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
should "work with args" do
|
|
15
|
+
add_predefined_filter("something")
|
|
16
|
+
assert_equal [["something"]], @predefined_filters
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "prepend_predefined_filter" do
|
|
22
|
+
|
|
23
|
+
should "work without args" do
|
|
24
|
+
prepend_predefined_filter()
|
|
25
|
+
assert @predefined_filters.empty?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
should "work with args" do
|
|
29
|
+
prepend_predefined_filter("something")
|
|
30
|
+
assert_equal [["something"]], @predefined_filters
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
should "work prepending an action without args" do
|
|
34
|
+
add_predefined_filter("something")
|
|
35
|
+
prepend_predefined_filter()
|
|
36
|
+
assert_equal [["something"]], @predefined_filters
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
should "work prepending an action with args" do
|
|
40
|
+
add_predefined_filter("something")
|
|
41
|
+
prepend_predefined_filter("something_else")
|
|
42
|
+
assert_equal [["something_else"], ["something"]], @predefined_filters
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "append_predefined_filter" do
|
|
48
|
+
|
|
49
|
+
should "work without args" do
|
|
50
|
+
append_predefined_filter()
|
|
51
|
+
assert @predefined_filters.empty?
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
should "work with args" do
|
|
55
|
+
append_predefined_filter("something")
|
|
56
|
+
assert_equal [["something"]], @predefined_filters
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
should "work appending an action without args" do
|
|
60
|
+
add_predefined_filter("something")
|
|
61
|
+
append_predefined_filter()
|
|
62
|
+
assert_equal [["something"]], @predefined_filters
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
should "work appending an action with args" do
|
|
66
|
+
add_predefined_filter("something")
|
|
67
|
+
append_predefined_filter("something_else")
|
|
68
|
+
assert_equal [["something"], ["something_else"]], @predefined_filters
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class ClassMethodsTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
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 = [[: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
|
+
|
|
25
|
+
assert_equal expected.map { |i| i.first }, TypusUser.model_fields.keys
|
|
26
|
+
assert_equal expected.map { |i| i.last }, TypusUser.model_fields.values
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
should "verify Post model_fields" do
|
|
30
|
+
expected = [[:id, :integer],
|
|
31
|
+
[:title, :string],
|
|
32
|
+
[:body, :text],
|
|
33
|
+
[:status, :string],
|
|
34
|
+
[:favorite_comment_id, :integer],
|
|
35
|
+
[:published_at, :datetime],
|
|
36
|
+
[:typus_user_id, :integer],
|
|
37
|
+
[:published, :boolean],
|
|
38
|
+
[:created_at, :datetime],
|
|
39
|
+
[:updated_at, :datetime]]
|
|
40
|
+
|
|
41
|
+
assert_equal expected.map { |i| i.first }, Post.model_fields.keys
|
|
42
|
+
assert_equal expected.map { |i| i.last }, Post.model_fields.values
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "model_relationships" do
|
|
48
|
+
|
|
49
|
+
should "be an ActiveSupport::OrderedHash" do
|
|
50
|
+
assert TypusUser.model_relationships.instance_of?(ActiveSupport::OrderedHash)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
should "verify Post model_relationships" do
|
|
54
|
+
expected = [[:comments, :has_many],
|
|
55
|
+
[:categories, :has_and_belongs_to_many],
|
|
56
|
+
[:user, nil]]
|
|
57
|
+
expected.each do |key, value|
|
|
58
|
+
assert_equal value, Post.model_relationships[key]
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context "typus_description" do
|
|
65
|
+
|
|
66
|
+
should "return the description of a model" do
|
|
67
|
+
assert_equal "System Users Administration", TypusUser.typus_description
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context "typus_fields_for" do
|
|
73
|
+
|
|
74
|
+
should "accept strings" do
|
|
75
|
+
assert_equal %w(email role status), TypusUser.typus_fields_for("list").keys
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
should "accept symbols" do
|
|
79
|
+
assert_equal %w(email role status), TypusUser.typus_fields_for(:list).keys
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
should "return list fields for TypusUser" do
|
|
83
|
+
expected = [["email", :string],
|
|
84
|
+
["role", :selector],
|
|
85
|
+
["status", :boolean]]
|
|
86
|
+
|
|
87
|
+
assert_equal expected.map { |i| i.first }, TypusUser.typus_fields_for(:list).keys
|
|
88
|
+
assert_equal expected.map { |i| i.last }, TypusUser.typus_fields_for(:list).values
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
should "return form fields for TypusUser" do
|
|
92
|
+
expected = [["first_name", :string],
|
|
93
|
+
["last_name", :string],
|
|
94
|
+
["role", :selector],
|
|
95
|
+
["email", :string],
|
|
96
|
+
["password", :password],
|
|
97
|
+
["password_confirmation", :password],
|
|
98
|
+
["locale", :selector]]
|
|
99
|
+
|
|
100
|
+
assert_equal expected.map { |i| i.first }, TypusUser.typus_fields_for(:form).keys
|
|
101
|
+
assert_equal expected.map { |i| i.last }, TypusUser.typus_fields_for(:form).values
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
should "return form fields for Asset" do
|
|
105
|
+
expected = [["caption", :string],
|
|
106
|
+
["dragonfly", :file],
|
|
107
|
+
["dragonfly_required", :file],
|
|
108
|
+
["original_file_name", :virtual]]
|
|
109
|
+
|
|
110
|
+
assert_equal expected.map { |i| i.first }, Asset.typus_fields_for(:special).keys
|
|
111
|
+
assert_equal expected.map { |i| i.last }, Asset.typus_fields_for(:special).values
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
should "raise a RuntimeError when model does not have configuration" do
|
|
115
|
+
assert_raises RuntimeError do
|
|
116
|
+
Class.new(ActiveRecord::Base).typus_fields_for(:form)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
should "return relationship fields for TypusUser" do
|
|
121
|
+
expected = %w(first_name last_name role email locale)
|
|
122
|
+
assert_equal expected, TypusUser.typus_fields_for(:relationship).keys
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
should "return undefined fields for TypusUser" do
|
|
126
|
+
expected = %w(first_name last_name role email locale)
|
|
127
|
+
assert_equal expected, TypusUser.typus_fields_for(:undefined).keys
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
should "work for transversal fields" do
|
|
131
|
+
expected = [["email", :string],
|
|
132
|
+
["post", :belongs_to],
|
|
133
|
+
["post_id", :integer],
|
|
134
|
+
["spam", :boolean],
|
|
135
|
+
["post.title", :transversal]]
|
|
136
|
+
|
|
137
|
+
assert_equal expected.map { |i| i.first }, Comment.typus_fields_for(:list).keys
|
|
138
|
+
assert_equal expected.map { |i| i.last }, Comment.typus_fields_for(:list).values
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
context "typus_filters" do
|
|
144
|
+
|
|
145
|
+
should "return filters for TypusUser" do
|
|
146
|
+
expected = [["status", :boolean],
|
|
147
|
+
["role", :string]]
|
|
148
|
+
|
|
149
|
+
assert_equal expected.map { |i| i.first }.join(", "), Typus::Configuration.config["TypusUser"]["filters"]
|
|
150
|
+
assert_equal expected.map { |i| i.first }, TypusUser.typus_filters.keys
|
|
151
|
+
assert_equal expected.map { |i| i.last }, TypusUser.typus_filters.values
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
should "return filters for Post" do
|
|
155
|
+
expected = [["published", :boolean],
|
|
156
|
+
["status", :string],
|
|
157
|
+
["created_at", :datetime]]
|
|
158
|
+
|
|
159
|
+
assert_equal expected.map { |i| i.first }.join(", "), Typus::Configuration.config["Post"]["filters"]
|
|
160
|
+
assert_equal expected.map { |i| i.first }, Post.typus_filters.keys
|
|
161
|
+
assert_equal expected.map { |i| i.last }, Post.typus_filters.values
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
context "typus_actions_on" do
|
|
167
|
+
|
|
168
|
+
should "accept strings" do
|
|
169
|
+
assert_equal %w(cleanup), Post.typus_actions_on("index")
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
should "accept symbols" do
|
|
173
|
+
assert_equal %w(cleanup), Post.typus_actions_on(:index)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
should "return actions on list for TypusUser" do
|
|
177
|
+
assert TypusUser.typus_actions_on(:list).empty?
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
should "return actions on edit for Post" do
|
|
181
|
+
assert_equal %w(send_as_newsletter preview), Post.typus_actions_on(:edit)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
context "typus_options_for" do
|
|
187
|
+
|
|
188
|
+
should "accept strings" do
|
|
189
|
+
assert_equal 15, Post.typus_options_for("form_rows")
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
should "accept symbols" do
|
|
193
|
+
assert_equal 15, Post.typus_options_for(:form_rows)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
should "return nil when options do not exist" do
|
|
197
|
+
assert_nil TypusUser.typus_options_for(:unexisting)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
should "return options for Post" do
|
|
201
|
+
assert_equal 15, Post.typus_options_for(:form_rows)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
should "return options for Page" do
|
|
205
|
+
assert_equal 25, Page.typus_options_for(:form_rows)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
should "return sortable options as a boolean" do
|
|
209
|
+
assert Post.typus_options_for(:sortable)
|
|
210
|
+
assert !Page.typus_options_for(:sortable)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
context "typus_application" do
|
|
216
|
+
|
|
217
|
+
should "return application for Post" do
|
|
218
|
+
assert_equal "CRUD Extended", Post.typus_application
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
should "return application for View" do
|
|
222
|
+
assert_equal "Unknown", View.typus_application
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
context "typus_field_options_for" do
|
|
228
|
+
|
|
229
|
+
should "verify on models" do
|
|
230
|
+
assert_equal [:status], Post.typus_field_options_for(:selectors)
|
|
231
|
+
assert_equal [:permalink], Post.typus_field_options_for(:read_only)
|
|
232
|
+
assert_equal [:created_at], Post.typus_field_options_for(:auto_generated)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
should "return empty array for unexisting option" do
|
|
236
|
+
assert Post.typus_field_options_for(:unexisting).empty?
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
context "typus_boolean" do
|
|
242
|
+
|
|
243
|
+
should "accept strings" do
|
|
244
|
+
expected = [["Active", "true"], ["Inactive", "false"]]
|
|
245
|
+
assert_equal expected, TypusUser.typus_boolean("status")
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
should "accept symbols" do
|
|
249
|
+
expected = [["Active", "true"], ["Inactive", "false"]]
|
|
250
|
+
assert_equal expected, TypusUser.typus_boolean(:status)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
should "return booleans for Post" do
|
|
254
|
+
expected = [["True", "true"], ["False", "false"]]
|
|
255
|
+
assert_equal expected, Post.typus_boolean(:status)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
should "return booleans for Comment" do
|
|
259
|
+
expected = [["Yes, it's spam", "true"], ["No, it's not spam", "false"]]
|
|
260
|
+
assert_equal expected, Comment.typus_boolean(:spam)
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
context "typus_date_format" do
|
|
266
|
+
|
|
267
|
+
should "accept strings" do
|
|
268
|
+
assert_equal :default, Post.typus_date_format("unknown")
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
should "accept symbols" do
|
|
272
|
+
assert_equal :default, Post.typus_date_format(:unknown)
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
should "return date_format for Post" do
|
|
276
|
+
assert_equal :default, Post.typus_date_format
|
|
277
|
+
assert_equal :short, Post.typus_date_format(:created_at)
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
context "typus_template" do
|
|
283
|
+
|
|
284
|
+
should "accept strings" do
|
|
285
|
+
assert_equal "datepicker", Post.typus_template("published_at")
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
should "accept symbols" do
|
|
289
|
+
assert_equal "datepicker", Post.typus_template(:published_at)
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
should "return nil if template does not exist" do
|
|
293
|
+
assert_nil Post.typus_template(:created_at)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
context "typus_defaults_for" do
|
|
299
|
+
|
|
300
|
+
should "accept strings" do
|
|
301
|
+
assert_equal %w(title), Post.typus_defaults_for("search")
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
should "accepts symbols" do
|
|
305
|
+
assert_equal %w(title), Post.typus_defaults_for(:search)
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
should "return default_for relationships on Post" do
|
|
309
|
+
assert_equal %w(categories comments views), Post.typus_defaults_for(:relationships)
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
context "typus_search_fields" do
|
|
315
|
+
|
|
316
|
+
should "return a hash with the search modifiers" do
|
|
317
|
+
search = ["=id", "^title", "body"]
|
|
318
|
+
Post.stubs(:typus_defaults_for).with(:search).returns(search)
|
|
319
|
+
expected = {"body"=>"@", "title"=>"^", "id"=>"="}
|
|
320
|
+
assert_equal expected, Post.typus_search_fields
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
should "return and empty hash" do
|
|
324
|
+
search = []
|
|
325
|
+
Post.stubs(:typus_defaults_for).with(:search).returns(search)
|
|
326
|
+
expected = {}
|
|
327
|
+
assert_equal expected, Post.typus_search_fields
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
context "typus_export_formats" do
|
|
333
|
+
|
|
334
|
+
should "return post formats" do
|
|
335
|
+
assert_equal ["csv", "xml"], Post.typus_export_formats
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
context "typus_order_by" do
|
|
341
|
+
|
|
342
|
+
should "return defaults_for order_by on Post" do
|
|
343
|
+
assert_equal "posts.title ASC, posts.created_at DESC", Post.typus_order_by
|
|
344
|
+
assert_equal %w(title -created_at), Post.typus_defaults_for(:order_by)
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
context "typus_user_id?" do
|
|
350
|
+
|
|
351
|
+
should "exist on Post" do
|
|
352
|
+
assert Post.typus_user_id?
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
should "not exist on TypusUser" do
|
|
356
|
+
assert !TypusUser.typus_user_id?
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
context "read_model_config" do
|
|
362
|
+
|
|
363
|
+
should "return data for existing model" do
|
|
364
|
+
expected = {"application"=>"CRUD Extended",
|
|
365
|
+
"fields"=>{"default"=>"caption, dragonfly, dragonfly_required",
|
|
366
|
+
"special"=>"caption, dragonfly, dragonfly_required, original_file_name"}}
|
|
367
|
+
assert_equal expected, Asset.read_model_config
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
should "raise error when model does not exist on configuration" do
|
|
371
|
+
assert_raises RuntimeError do
|
|
372
|
+
Article.read_model_config
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
end
|