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,124 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class TypusUserRolesTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
should "get a list of roles" do
|
|
6
|
+
roles = %w(admin designer editor)
|
|
7
|
+
assert_equal roles, Typus::Configuration.roles.map(&:first).sort
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "A TypusUser with role admin" do
|
|
11
|
+
|
|
12
|
+
setup do
|
|
13
|
+
@typus_user = Factory(:typus_user)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
should "verify models access" do
|
|
17
|
+
expected = ["Asset",
|
|
18
|
+
"Bird",
|
|
19
|
+
"Case",
|
|
20
|
+
"Category",
|
|
21
|
+
"Comment",
|
|
22
|
+
"Dog",
|
|
23
|
+
"Entry",
|
|
24
|
+
"Git",
|
|
25
|
+
"ImageHolder",
|
|
26
|
+
"Invoice",
|
|
27
|
+
"Order",
|
|
28
|
+
"Page",
|
|
29
|
+
"Post",
|
|
30
|
+
"Project",
|
|
31
|
+
"ProjectCollaborator",
|
|
32
|
+
"Status",
|
|
33
|
+
"TypusUser",
|
|
34
|
+
"User",
|
|
35
|
+
"View",
|
|
36
|
+
"WatchDog"]
|
|
37
|
+
assert_equal expected, @typus_user.resources.map(&:first).sort
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
should_eventually "verify resources without actions related are removed" do
|
|
41
|
+
assert !@typus_user.resources.map(&:first).include?('Order')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
should "have access to all actions on models" do
|
|
45
|
+
models = %w(Asset Category Comment Page Post TypusUser View)
|
|
46
|
+
%w(create read update destroy).each { |a| models.each { |m| assert @typus_user.can?(a, m) } }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
should "verify we can perform action on resource" do
|
|
50
|
+
assert @typus_user.can?('index', 'Status', { :special => true })
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
should "verify we cannot perform action on resource" do
|
|
54
|
+
assert @typus_user.cannot?('show', 'Status', { :special => true })
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
should_eventually "verify we cannot perform actions on resources which don't have that action defined" do
|
|
58
|
+
assert @typus_user.cannot?('index', 'Order')
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context "A TypusUser with role editor" do
|
|
64
|
+
|
|
65
|
+
setup do
|
|
66
|
+
@typus_user = Factory(:typus_user, :role => "editor")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
should "verify models access" do
|
|
70
|
+
expected = %w(Category Comment Git Post TypusUser View)
|
|
71
|
+
assert_equal expected, @typus_user.resources.map(&:first).sort
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
should "only create, read and update categories" do
|
|
75
|
+
%w(create read update).each { |a| assert @typus_user.can?(a, 'Category') }
|
|
76
|
+
%w(delete).each { |a| assert @typus_user.cannot?(a, 'Category') }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
should "only create, read and update posts" do
|
|
80
|
+
%w(create read update).each { |a| assert @typus_user.can?(a, 'Post') }
|
|
81
|
+
%w(delete).each { |a| assert @typus_user.cannot?(a, 'Post') }
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
should "only read, update and delete comments" do
|
|
85
|
+
%w(read update delete).each { |a| assert @typus_user.can?(a, 'Comment') }
|
|
86
|
+
%w(create).each { |a| assert @typus_user.cannot?(a, 'Comment') }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
should "only read and update typus_users" do
|
|
90
|
+
%w(read update).each { |a| assert @typus_user.can?(a, 'TypusUser') }
|
|
91
|
+
%w(create delete).each { |a| assert @typus_user.cannot?(a, 'TypusUser') }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
context "A TypusUser with role designer" do
|
|
97
|
+
|
|
98
|
+
setup do
|
|
99
|
+
@typus_user = Factory(:typus_user, :role => "designer")
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
should "verify models access" do
|
|
103
|
+
expected = %w(Category Comment Post)
|
|
104
|
+
assert_equal expected, @typus_user.resources.map(&:first).sort
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
should "only read and update categories" do
|
|
108
|
+
%w(read update).each { |a| assert @typus_user.can?(a, 'Category') }
|
|
109
|
+
%w(create delete).each { |a| assert @typus_user.cannot?(a, 'Category') }
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
should "only read comments" do
|
|
113
|
+
%w(read).each { |a| assert @typus_user.can?(a, 'Comment') }
|
|
114
|
+
%w(create update delete).each { |a| assert @typus_user.cannot?(a, 'Comment') }
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
should "only read and update posts" do
|
|
118
|
+
%w(read update).each { |a| assert @typus_user.can?(a, 'Post') }
|
|
119
|
+
%w(create delete).each { |a| assert @typus_user.cannot?(a, 'Post') }
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
end
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class TypusUserTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
[ %Q(this_is_chelm@example.com\n<script>location.href="http://spammersite.com"</script>),
|
|
6
|
+
'admin',
|
|
7
|
+
'TEST@EXAMPLE.COM',
|
|
8
|
+
'test@example',
|
|
9
|
+
'test@example.c',
|
|
10
|
+
'testexample.com' ].each do |value|
|
|
11
|
+
should_not allow_value(value).for(:email)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
[ 'test+filter@example.com',
|
|
15
|
+
'test.filter@example.com',
|
|
16
|
+
'test@example.co.uk',
|
|
17
|
+
'test@example.es' ].each do |value|
|
|
18
|
+
should allow_value(value).for(:email)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
should validate_presence_of :email
|
|
22
|
+
should validate_presence_of :role
|
|
23
|
+
|
|
24
|
+
should_not allow_mass_assignment_of :status
|
|
25
|
+
|
|
26
|
+
should ensure_length_of(:password).is_at_least(6).is_at_most(40)
|
|
27
|
+
|
|
28
|
+
should "verify columns" do
|
|
29
|
+
expected = %w(id first_name last_name email role status salt crypted_password token preferences created_at updated_at).sort
|
|
30
|
+
output = TypusUser.columns.map(&:name).sort
|
|
31
|
+
assert_equal expected, output
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "generate" do
|
|
35
|
+
|
|
36
|
+
should "not be valid if email is not passed" do
|
|
37
|
+
assert TypusUser.generate.invalid?
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
should "be valid when email is passed" do
|
|
41
|
+
options = { :email => 'demo@example.com' }
|
|
42
|
+
assert TypusUser.generate(options).valid?
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
should "accept password" do
|
|
46
|
+
options = { :email => 'demo@example.com', :password => 'XXXXXXXX' }
|
|
47
|
+
assert TypusUser.generate(options).valid?
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
should "accept role" do
|
|
51
|
+
options = { :email => 'demo@example.com', :role => 'admin' }
|
|
52
|
+
assert TypusUser.generate(options).valid?
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context "TypusUser" do
|
|
58
|
+
|
|
59
|
+
setup do
|
|
60
|
+
@typus_user = Factory(:typus_user)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
should "return email" do
|
|
64
|
+
assert_equal @typus_user.email, @typus_user.name
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
should "return first_name" do
|
|
68
|
+
@typus_user.first_name = "John"
|
|
69
|
+
assert_equal "John", @typus_user.name
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
should "return last_name" do
|
|
73
|
+
@typus_user.last_name = "Locke"
|
|
74
|
+
assert_equal "Locke", @typus_user.name
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
should "return name when first_name and last_name are set" do
|
|
78
|
+
@typus_user.first_name, @typus_user.last_name = "John", "Locke"
|
|
79
|
+
assert_equal "John Locke", @typus_user.name
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
should "return name when first_name and last_name are set to nil" do
|
|
83
|
+
@typus_user.first_name, @typus_user.last_name = nil
|
|
84
|
+
assert_equal @typus_user.email, @typus_user.name
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
should "verify salt never changes" do
|
|
88
|
+
expected = @typus_user.salt
|
|
89
|
+
@typus_user.update_attributes(:password => '11111111', :password_confirmation => '11111111')
|
|
90
|
+
assert_equal expected, @typus_user.salt
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
should "verify authenticated? returns true or false" do
|
|
94
|
+
assert @typus_user.authenticated?('12345678')
|
|
95
|
+
assert !@typus_user.authenticated?('87654321')
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
should "verify can? accepts a Class" do
|
|
99
|
+
assert @typus_user.can?('delete', TypusUser)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
should "verify can? accepts an String" do
|
|
103
|
+
assert @typus_user.can?('delete', 'TypusUser')
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
should "verify cannot? acccepts a Class" do
|
|
107
|
+
assert !@typus_user.cannot?('delete', TypusUser)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
should "verify cannot? acccepts an String" do
|
|
111
|
+
assert !@typus_user.cannot?('delete', 'TypusUser')
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
should "verify preferences are nil by default" do
|
|
115
|
+
assert @typus_user.preferences.nil?
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
should "return default_locale when no preferences are set" do
|
|
119
|
+
assert_equal :en, @typus_user.locale
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
should "be able to set a locale" do
|
|
123
|
+
@typus_user.locale = :jp
|
|
124
|
+
|
|
125
|
+
expected = {:locale => :jp}
|
|
126
|
+
assert_equal expected, @typus_user.preferences
|
|
127
|
+
assert_equal :jp, @typus_user.locale
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
should "be able to set preferences" do
|
|
131
|
+
@typus_user.preferences = {:chunky => "bacon"}
|
|
132
|
+
assert @typus_user.preferences.present?
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
should "set locale preference without overriding previously set preferences" do
|
|
136
|
+
@typus_user.preferences = {:chunky => "bacon"}
|
|
137
|
+
@typus_user.locale = :jp
|
|
138
|
+
|
|
139
|
+
expected = {:locale => :jp, :chunky => "bacon"}
|
|
140
|
+
assert_equal expected, @typus_user.preferences
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
context "Admin Role" do
|
|
146
|
+
|
|
147
|
+
setup do
|
|
148
|
+
@typus_user = Factory(:typus_user)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
should "respond true and false to is_root? and is_not_root?" do
|
|
152
|
+
assert @typus_user.is_root?
|
|
153
|
+
assert !@typus_user.is_not_root?
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
should "get a list of all applications" do
|
|
157
|
+
assert_equal Typus.applications, @typus_user.applications
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
should "get a list of application resources for CRUD Extended application" do
|
|
161
|
+
expected = ["Asset", "Category", "Comment", "Page", "Post"]
|
|
162
|
+
assert_equal expected, @typus_user.application("CRUD Extended")
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
should "get a list of application resources for Admin application" do
|
|
166
|
+
assert_equal %w(TypusUser), @typus_user.application("Admin")
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
context "Editor Role" do
|
|
172
|
+
|
|
173
|
+
setup do
|
|
174
|
+
@typus_user = Factory(:typus_user, :role => "editor")
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
should "respond true and false to is_no_root? and is_root?" do
|
|
178
|
+
assert @typus_user.is_not_root?
|
|
179
|
+
assert !@typus_user.is_root?
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
should "get a list of all applications" do
|
|
183
|
+
expected = ["Admin", "CRUD Extended"]
|
|
184
|
+
assert_equal expected, @typus_user.applications
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
should "get a list of application resources" do
|
|
188
|
+
assert_equal %w(Category Comment Post), @typus_user.application("CRUD Extended")
|
|
189
|
+
assert_equal %w(TypusUser), @typus_user.application("Admin")
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class RoutesTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
setup do
|
|
6
|
+
@routes = Rails.application.routes.routes.map(&:name)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
should "verify admin routes" do
|
|
10
|
+
expected = %w(admin)
|
|
11
|
+
expected.each { |r| assert @routes.include?(r) }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
should "verify admin dashboard routes" do
|
|
15
|
+
expected = %w(admin_dashboard)
|
|
16
|
+
expected.each { |r| assert @routes.include?(r) }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
should "verify admin account named routes" do
|
|
20
|
+
expected = %w(forgot_password_admin_account_index admin_account_index new_admin_account admin_account)
|
|
21
|
+
expected.each { |r| assert @routes.include?(r) }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
should "verify admin session named routes" do
|
|
25
|
+
expected = %w(new_admin_session admin_session)
|
|
26
|
+
expected.each { |r| assert @routes.include?(r) }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
data/test/factories.rb
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
##
|
|
2
|
+
# CRUD
|
|
3
|
+
##
|
|
4
|
+
|
|
5
|
+
Factory.define :entry do |f|
|
|
6
|
+
f.sequence(:title) { |n| "Entry##{n}" }
|
|
7
|
+
f.content "Body of the entry"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
Factory.define :case do |f|
|
|
11
|
+
f.sequence(:title) { |n| "Case##{n}" }
|
|
12
|
+
f.content "Body of the entry"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
##
|
|
16
|
+
# CRUD Extended
|
|
17
|
+
##
|
|
18
|
+
|
|
19
|
+
Factory.define :asset do |f|
|
|
20
|
+
f.sequence(:caption) { |n| "Asset##{n}" }
|
|
21
|
+
f.dragonfly File.new("#{Rails.root}/public/images/rails.png")
|
|
22
|
+
f.dragonfly_required File.new("#{Rails.root}/public/images/rails.png")
|
|
23
|
+
f.paperclip File.new("#{Rails.root}/public/images/rails.png")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Factory.define :category do |f|
|
|
27
|
+
f.sequence(:name) { |n| "Category##{n}" }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
Factory.define :comment do |f|
|
|
31
|
+
f.sequence(:name) { |n| "Comment##{n}" }
|
|
32
|
+
f.sequence(:email) { |n| "john+#{n}@example.com" }
|
|
33
|
+
f.body "Body of the comment"
|
|
34
|
+
f.association :post
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
Factory.define :page do |f|
|
|
38
|
+
f.sequence(:title) { |n| "Page##{n}" }
|
|
39
|
+
f.body "Content"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
Factory.define :post do |f|
|
|
43
|
+
f.sequence(:title) { |n| "Post##{n}" }
|
|
44
|
+
f.body "Body"
|
|
45
|
+
f.status "published"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
Factory.define :typus_user do |f|
|
|
49
|
+
f.sequence(:email) { |n| "admin+#{n}@example.com" }
|
|
50
|
+
f.role "admin"
|
|
51
|
+
f.status true
|
|
52
|
+
f.token "1A2B3C4D5E6F"
|
|
53
|
+
f.password "12345678"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
Factory.define :view do |f|
|
|
57
|
+
f.ip "127.0.0.1"
|
|
58
|
+
f.association :post
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
##
|
|
62
|
+
# HasOne Association
|
|
63
|
+
#
|
|
64
|
+
|
|
65
|
+
Factory.define :invoice do |f|
|
|
66
|
+
f.sequence(:number) { |n| "Invoice##{n}" }
|
|
67
|
+
f.association :order
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
Factory.define :order do |f|
|
|
71
|
+
f.sequence(:number) { |n| "Order##{n}" }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
##
|
|
75
|
+
# HasManyThrough Association
|
|
76
|
+
#
|
|
77
|
+
|
|
78
|
+
Factory.define :user do |f|
|
|
79
|
+
f.sequence(:name) { |n| "User##{n}" }
|
|
80
|
+
f.sequence(:email) { |n| "user.#{n}@example.com" }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
Factory.define :project do |f|
|
|
84
|
+
f.sequence(:name) { |n| "Project##{n}" }
|
|
85
|
+
f.association :user
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
Factory.define :project_collaborators do |f|
|
|
89
|
+
f.association :user
|
|
90
|
+
f.association :project
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
##
|
|
94
|
+
# Polymorphic
|
|
95
|
+
##
|
|
96
|
+
|
|
97
|
+
Factory.define :animal do |f|
|
|
98
|
+
f.sequence(:name) { |n| "Animal##{n}" }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
Factory.define :bird do |f|
|
|
102
|
+
f.sequence(:name) { |n| "Bird##{n}" }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
Factory.define :dog do |f|
|
|
106
|
+
f.sequence(:name) { |n| "Dog##{n}" }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
Factory.define :image_holder do |f|
|
|
110
|
+
f.sequence(:name) { |n| "ImageHolder##{n}" }
|
|
111
|
+
end
|