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,59 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class Admin::ListHelperTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
include Admin::ListHelper
|
|
6
|
+
|
|
7
|
+
def render(*args); args; end
|
|
8
|
+
|
|
9
|
+
context "resources_actions" do
|
|
10
|
+
|
|
11
|
+
should "return a default value which is an empty array" do
|
|
12
|
+
assert resources_actions.empty?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
should "return a predefined value" do
|
|
16
|
+
@resources_actions = "mock"
|
|
17
|
+
assert_equal "mock", resources_actions
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "list_actions" do
|
|
23
|
+
|
|
24
|
+
should "be empty" do
|
|
25
|
+
assert list_actions.empty?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
should_eventually "return an array with our custom actions"
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context "build_list" do
|
|
33
|
+
|
|
34
|
+
setup do
|
|
35
|
+
@model = TypusUser
|
|
36
|
+
@fields = %w( email role status )
|
|
37
|
+
@items = TypusUser.all
|
|
38
|
+
@resource = "typus_users"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
should "return a table" do
|
|
42
|
+
expected = [ "admin/typus_users/list", { :items => [] } ]
|
|
43
|
+
output = build_list(@model, @fields, @items, @resource)
|
|
44
|
+
assert_equal expected, output
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
should "return a template" do
|
|
48
|
+
self.stubs(:render).returns("a_template")
|
|
49
|
+
File.stubs(:exist?).returns(true)
|
|
50
|
+
|
|
51
|
+
expected = "a_template"
|
|
52
|
+
output = build_list(@model, @fields, @items, @resource)
|
|
53
|
+
|
|
54
|
+
assert_equal expected, output
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class Admin::RelationshipsHelperTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
include Admin::RelationshipsHelper
|
|
6
|
+
|
|
7
|
+
should_eventually "test setup_relationship"
|
|
8
|
+
should_eventually "test typus_form_has_many"
|
|
9
|
+
should_eventually "test typus_form_has_and_belongs_to_many"
|
|
10
|
+
should_eventually "test build_pagination"
|
|
11
|
+
should_eventually "test build_relate_form"
|
|
12
|
+
should_eventually "test build_relationship_table"
|
|
13
|
+
should_eventually "test build_add_new"
|
|
14
|
+
should_eventually "test set_condition"
|
|
15
|
+
should_eventually "test set_conditions"
|
|
16
|
+
should_eventually "test typus_form_has_one"
|
|
17
|
+
should_eventually "test typus_belongs_to_field"
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class Admin::ResourcesHelperTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
include Admin::ResourcesHelper
|
|
6
|
+
|
|
7
|
+
include ActionView::Helpers::UrlHelper
|
|
8
|
+
include ActionView::Helpers::TagHelper
|
|
9
|
+
|
|
10
|
+
def render(*args); args; end
|
|
11
|
+
|
|
12
|
+
context "display_link_to_previous" do
|
|
13
|
+
|
|
14
|
+
setup do
|
|
15
|
+
@resource = Comment
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
should "set an url to new when not resource_id is passed" do
|
|
19
|
+
params = { :resource => "Post" }
|
|
20
|
+
|
|
21
|
+
expected = ["admin/helpers/resources/display_link_to_previous",
|
|
22
|
+
{:body=>"Cancel adding a new comment?", :url=>{:controller=>"posts", :action => 'new'}}]
|
|
23
|
+
|
|
24
|
+
assert_equal expected, display_link_to_previous(params)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
should "set an url to edit when resource_id is passed" do
|
|
28
|
+
@post = Factory(:post)
|
|
29
|
+
params = { :resource => "Post", :resource_id => @post.id }
|
|
30
|
+
|
|
31
|
+
expected = ["admin/helpers/resources/display_link_to_previous",
|
|
32
|
+
{:body=>"Cancel adding a new comment?", :url=>{:controller=>"posts", :action => 'edit', :id => @post.id}}]
|
|
33
|
+
|
|
34
|
+
assert_equal expected, display_link_to_previous(params)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
should "return nil if no resource is passed" do
|
|
38
|
+
params = { :action => "edit" }
|
|
39
|
+
self.expects(:params).at_least_once.returns(params)
|
|
40
|
+
|
|
41
|
+
assert_nil display_link_to_previous
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class Admin::SearchHelperTest < ActiveSupport::TestCase
|
|
6
|
+
|
|
7
|
+
include Admin::SearchHelper
|
|
8
|
+
|
|
9
|
+
def render(*args); args; end
|
|
10
|
+
|
|
11
|
+
context "search" do
|
|
12
|
+
|
|
13
|
+
should "reject controller and action params" do
|
|
14
|
+
parameters = {"controller"=>"admin/posts", "action"=>"index"}
|
|
15
|
+
expected = ["admin/helpers/search/search", {:hidden_filters => {}}]
|
|
16
|
+
assert_equal expected, search(Entry, parameters)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Why do you need the pagination page for a new search?
|
|
20
|
+
should "reject the page param" do
|
|
21
|
+
parameters = {"page"=>"1"}
|
|
22
|
+
expected = ["admin/helpers/search/search", {:hidden_filters => {}}]
|
|
23
|
+
assert_equal expected, search(Entry, parameters)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# TODO: I want to think about it ...
|
|
27
|
+
should "reject locale params" do
|
|
28
|
+
parameters = {"locale"=>"jp"}
|
|
29
|
+
expected = ["admin/helpers/search/search", {:hidden_filters => {}}]
|
|
30
|
+
assert_equal expected, search(Entry, parameters)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# TODO: I want to think about it ...
|
|
34
|
+
should "reject to sort_order and order_by" do
|
|
35
|
+
parameters = {"sort_order"=>"asc", "order_by"=>"title"}
|
|
36
|
+
expected = ["admin/helpers/search/search", {:hidden_filters => {}}]
|
|
37
|
+
assert_equal expected, search(Entry, parameters)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
should "reject the utf8 param because the form already contains it" do
|
|
41
|
+
parameters = {"utf8"=>"✓"}
|
|
42
|
+
expected = ["admin/helpers/search/search", {:hidden_filters => {}}]
|
|
43
|
+
assert_equal expected, search(Entry, parameters)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
should "reject the search param because the form already contains it" do
|
|
47
|
+
parameters = {"search"=>"Chunky Bacon"}
|
|
48
|
+
expected = ["admin/helpers/search/search", {:hidden_filters => {}}]
|
|
49
|
+
assert_equal expected, search(Entry, parameters)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
should "not reject applied filters" do
|
|
53
|
+
parameters = {"published"=>"true", "user_id"=>"1"}
|
|
54
|
+
expected = ["admin/helpers/search/search", {:hidden_filters=>{"published"=>"true", "user_id"=>"1"}}]
|
|
55
|
+
assert_equal expected, search(Entry, parameters)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class Admin::SidebarHelperTest < ActiveSupport::TestCase
|
|
6
|
+
|
|
7
|
+
include Admin::SidebarHelper
|
|
8
|
+
|
|
9
|
+
include ActionView::Helpers::UrlHelper
|
|
10
|
+
include ActionView::Helpers::TagHelper
|
|
11
|
+
include ActionView::Helpers::FormTagHelper
|
|
12
|
+
|
|
13
|
+
def render(*args); args; end
|
|
14
|
+
def link_to(*args); args; end
|
|
15
|
+
|
|
16
|
+
setup do
|
|
17
|
+
default_url_options[:host] = 'test.host'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context "export" do
|
|
21
|
+
|
|
22
|
+
should "return array with expected values" do
|
|
23
|
+
params = { :controller => '/admin/posts', :action => 'index' }
|
|
24
|
+
|
|
25
|
+
output = export(Post , params)
|
|
26
|
+
expected = [["Export as CSV", { :action => "index", :format => "csv", :controller => "/admin/posts" }],
|
|
27
|
+
["Export as XML", { :action => "index", :format => "xml", :controller => "/admin/posts" }]]
|
|
28
|
+
|
|
29
|
+
assert_equal expected, output
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class FakeController
|
|
4
|
+
attr_accessor :request
|
|
5
|
+
|
|
6
|
+
def config
|
|
7
|
+
@config ||= ActiveSupport::InheritableOptions.new(ActionController::Base.config)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Admin::TableHelperTest < ActiveSupport::TestCase
|
|
12
|
+
|
|
13
|
+
include Admin::TableHelper
|
|
14
|
+
|
|
15
|
+
include ActionView::Helpers::UrlHelper
|
|
16
|
+
include ActionView::Helpers::TagHelper
|
|
17
|
+
include ActionView::Helpers::TextHelper
|
|
18
|
+
include ActionView::Helpers::RawOutputHelper
|
|
19
|
+
|
|
20
|
+
include ActionView::Context
|
|
21
|
+
|
|
22
|
+
include Rails.application.routes.url_helpers
|
|
23
|
+
|
|
24
|
+
def render(*args); args; end
|
|
25
|
+
def params; {} end
|
|
26
|
+
def admin_user; end
|
|
27
|
+
|
|
28
|
+
setup do
|
|
29
|
+
default_url_options[:host] = "test.host"
|
|
30
|
+
self.stubs(:controller).returns(FakeController.new)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "table_header" do
|
|
34
|
+
|
|
35
|
+
should "work" do
|
|
36
|
+
params = { :controller => "/admin/typus_users", :action => "index" }
|
|
37
|
+
fields = TypusUser.typus_fields_for(:list)
|
|
38
|
+
|
|
39
|
+
expected = [ %(<a href="/admin/typus_users?order_by=email">Email</a>),
|
|
40
|
+
%(<a href="/admin/typus_users?order_by=role">Role</a>),
|
|
41
|
+
%(<a href="/admin/typus_users?order_by=status">Status</a>) ]
|
|
42
|
+
|
|
43
|
+
assert_equal expected, table_header(TypusUser, fields, params)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
should "work with params" do
|
|
47
|
+
params = { :controller => "/admin/typus_users", :action => "index", :search => "admin" }
|
|
48
|
+
fields = TypusUser.typus_fields_for(:list)
|
|
49
|
+
|
|
50
|
+
expected = [ %(<a href="/admin/typus_users?order_by=email&search=admin">Email</a>),
|
|
51
|
+
%(<a href="/admin/typus_users?order_by=role&search=admin">Role</a>),
|
|
52
|
+
%(<a href="/admin/typus_users?order_by=status&search=admin">Status</a>) ]
|
|
53
|
+
|
|
54
|
+
assert_equal expected, table_header(TypusUser, fields, params)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context "resource_actions" do
|
|
60
|
+
|
|
61
|
+
should "return a default value which is an empty array" do
|
|
62
|
+
assert resource_actions.empty?
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
should "return a predefined value" do
|
|
66
|
+
@resource_actions = "mock"
|
|
67
|
+
assert_equal "mock", resource_actions
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context "table_belongs_to_field" do
|
|
73
|
+
|
|
74
|
+
should "work without associated model" do
|
|
75
|
+
comment = Factory(:comment, :post => nil)
|
|
76
|
+
assert_equal "—", table_belongs_to_field("post", comment)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
should "work with associated model when user has access" do
|
|
80
|
+
admin_user.expects(:can?).returns(true)
|
|
81
|
+
comment = Factory(:comment)
|
|
82
|
+
post = comment.post
|
|
83
|
+
assert_equal %(<a href="/admin/posts/edit/#{post.id}">#{post.to_label}</a>), table_belongs_to_field("post", comment)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
should "work with associated model when user does not have access" do
|
|
87
|
+
admin_user.expects(:can?).returns(false)
|
|
88
|
+
comment = Factory(:comment)
|
|
89
|
+
post = comment.post
|
|
90
|
+
assert_equal post.to_label, table_belongs_to_field("post", comment)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
should "test_table_has_and_belongs_to_many_field" do
|
|
96
|
+
post = Factory(:post)
|
|
97
|
+
post.comments << Factory(:comment, :name => "John")
|
|
98
|
+
post.comments << Factory(:comment, :name => "Jack")
|
|
99
|
+
assert_equal "John, Jack", table_has_and_belongs_to_many_field("comments", post)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
context "table_string_field" do
|
|
103
|
+
|
|
104
|
+
should "work" do
|
|
105
|
+
post = Factory(:post)
|
|
106
|
+
assert_equal post.title, table_string_field(:title, post)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
should "work when attribute is empty" do
|
|
110
|
+
post = Factory(:post)
|
|
111
|
+
post.title = ""
|
|
112
|
+
assert_equal "—", table_string_field(:title, post)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
context "table_integer_field" do
|
|
118
|
+
|
|
119
|
+
should "work" do
|
|
120
|
+
post = Factory(:post)
|
|
121
|
+
assert_equal post.id, table_integer_field(:id, post)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
should "work when attribute is empty" do
|
|
125
|
+
post = Factory(:post)
|
|
126
|
+
post.id = nil
|
|
127
|
+
assert_equal "—", table_integer_field(:id, post)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
context "table_tree_field" do
|
|
133
|
+
|
|
134
|
+
should "work when no parent" do
|
|
135
|
+
page = Factory(:page)
|
|
136
|
+
assert_equal "—", table_tree_field("title", page)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
should "work when parent" do
|
|
140
|
+
parent = Factory(:page)
|
|
141
|
+
page = Factory(:page, :parent => parent)
|
|
142
|
+
assert_equal parent.to_label, table_tree_field("title", page)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
should "test_table_datetime_field" do
|
|
148
|
+
post = Factory(:post)
|
|
149
|
+
assert_equal post.created_at.strftime("%d %b %H:%M"), table_datetime_field(:created_at, post)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
context "table_boolean_field" do
|
|
153
|
+
|
|
154
|
+
should "work when default status is true" do
|
|
155
|
+
post = Factory(:typus_user)
|
|
156
|
+
expected = %(<a href="/admin/typus_users/toggle/#{post.id}?field=status" data-confirm="Change status?">Active</a>)
|
|
157
|
+
assert_equal expected, table_boolean_field("status", post)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
should "work when default status is false" do
|
|
161
|
+
post = Factory(:typus_user, :status => false)
|
|
162
|
+
expected = %(<a href="/admin/typus_users/toggle/#{post.id}?field=status" data-confirm="Change status?">Inactive</a>)
|
|
163
|
+
assert_equal expected, table_boolean_field("status", post)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
should "work when default status is nil" do
|
|
167
|
+
post = Factory(:typus_user, :status => nil)
|
|
168
|
+
assert post.status.nil?
|
|
169
|
+
expected = %(<a href="/admin/typus_users/toggle/#{post.id}?field=status" data-confirm="Change status?">Inactive</a>)
|
|
170
|
+
assert_equal expected, table_boolean_field("status", post)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
context "table_transversal_field" do
|
|
176
|
+
|
|
177
|
+
should "work" do
|
|
178
|
+
comment = Factory(:comment)
|
|
179
|
+
output = table_transversal_field("post.title", comment)
|
|
180
|
+
expected = comment.post.title
|
|
181
|
+
assert_equal expected, output
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
should "return a dash if the association does not exist" do
|
|
185
|
+
comment = Factory(:comment, :post => nil)
|
|
186
|
+
assert_equal "—", table_transversal_field("post.title", comment)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
should "test_table_position_field" do
|
|
192
|
+
first_category = Factory(:category, :position => 0)
|
|
193
|
+
second_category = Factory(:category, :position => 1)
|
|
194
|
+
last_category = Factory(:category, :position => 2)
|
|
195
|
+
|
|
196
|
+
output = table_position_field(nil, first_category)
|
|
197
|
+
expected = <<-HTML
|
|
198
|
+
1<br/><br/><a href="/admin/categories/position/#{first_category.id}?go=move_lower">Down</a> / <a href="/admin/categories/position/#{first_category.id}?go=move_to_bottom">Bottom</a>
|
|
199
|
+
HTML
|
|
200
|
+
assert_equal expected.strip, output
|
|
201
|
+
|
|
202
|
+
output = table_position_field(nil, second_category)
|
|
203
|
+
expected = <<-HTML
|
|
204
|
+
2<br/><br/><a href="/admin/categories/position/#{second_category.id}?go=move_to_top">Top</a> / <a href="/admin/categories/position/#{second_category.id}?go=move_higher">Up</a> / <a href="/admin/categories/position/#{second_category.id}?go=move_lower">Down</a> / <a href="/admin/categories/position/#{second_category.id}?go=move_to_bottom">Bottom</a>
|
|
205
|
+
HTML
|
|
206
|
+
assert_equal expected.strip, output
|
|
207
|
+
|
|
208
|
+
output = table_position_field(nil, last_category)
|
|
209
|
+
expected = <<-HTML
|
|
210
|
+
3<br/><br/><a href="/admin/categories/position/#{last_category.id}?go=move_to_top">Top</a> / <a href="/admin/categories/position/#{last_category.id}?go=move_higher">Up</a>
|
|
211
|
+
HTML
|
|
212
|
+
assert_equal expected.strip, output
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class Admin::MailerTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
setup do
|
|
6
|
+
@typus_user = Factory(:typus_user)
|
|
7
|
+
@url = "http://test.host/admin/account/#{@typus_user.token}"
|
|
8
|
+
@email = Admin::Mailer.reset_password_link(@typus_user, @url)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
should "verify email from is nil by default" do
|
|
12
|
+
assert_nil Admin::Mailer.default[:from]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
should "verify email to is typus user email" do
|
|
16
|
+
assert @email.to.include?(@typus_user.email)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
should "verify email subject" do
|
|
20
|
+
expected = "[#{Typus.admin_title}] Reset password"
|
|
21
|
+
assert_equal expected, @email.subject
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
should "verify default email mime_type" do
|
|
25
|
+
assert_equal "text/plain", @email.mime_type
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
should "verify email contains reset password link with token" do
|
|
29
|
+
assert_match @url, @email.body.encoded
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|