tolaria 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +66 -0
- data/.yardopts +4 -0
- data/CNAME +1 -0
- data/CONTRIBUTING.md +32 -0
- data/Gemfile +2 -0
- data/LICENSE.md +9 -0
- data/README.md +538 -0
- data/Rakefile +52 -0
- data/app/assets/fonts/admin/fontawesome.eot +0 -0
- data/app/assets/fonts/admin/fontawesome.svg +565 -0
- data/app/assets/fonts/admin/fontawesome.ttf +0 -0
- data/app/assets/fonts/admin/fontawesome.woff +0 -0
- data/app/assets/fonts/admin/fontawesome.woff2 +0 -0
- data/app/assets/images/admin/columbia_banner.png +0 -0
- data/app/assets/images/admin/favicon.ico +0 -0
- data/app/assets/images/admin/noise.png +0 -0
- data/app/assets/images/admin/select_arrows.svg +1 -0
- data/app/assets/javascripts/admin/admin.js +4 -0
- data/app/assets/javascripts/admin/base.js +12 -0
- data/app/assets/javascripts/admin/lib/backbone.js +1888 -0
- data/app/assets/javascripts/admin/lib/jquery.chosen.js +1272 -0
- data/app/assets/javascripts/admin/lib/jquery.js +10361 -0
- data/app/assets/javascripts/admin/lib/jquery.selection.js +352 -0
- data/app/assets/javascripts/admin/lib/moment.js +3103 -0
- data/app/assets/javascripts/admin/lib/no.js +6 -0
- data/app/assets/javascripts/admin/lib/underscore.js +1570 -0
- data/app/assets/javascripts/admin/models/composer_buttons.js +45 -0
- data/app/assets/javascripts/admin/models/rails_meta.js +4 -0
- data/app/assets/javascripts/admin/views/field_with_errors.js +19 -0
- data/app/assets/javascripts/admin/views/fields/attachment_field.js +32 -0
- data/app/assets/javascripts/admin/views/fields/has_many.js +64 -0
- data/app/assets/javascripts/admin/views/fields/image_association_select.js +31 -0
- data/app/assets/javascripts/admin/views/fields/markdown_composer.js +167 -0
- data/app/assets/javascripts/admin/views/fields/searchable_select.js +70 -0
- data/app/assets/javascripts/admin/views/fields/slug_field.js +38 -0
- data/app/assets/javascripts/admin/views/fields/swatch_field.js +55 -0
- data/app/assets/javascripts/admin/views/fields/timestamp_field.js +80 -0
- data/app/assets/javascripts/admin/views/flash_message.js +18 -0
- data/app/assets/javascripts/admin/views/form_orchestrator.js +41 -0
- data/app/assets/javascripts/admin/views/navigation.js +20 -0
- data/app/assets/javascripts/admin/views/resource_form.js +18 -0
- data/app/assets/javascripts/admin/views/search_form.js +20 -0
- data/app/assets/javascripts/admin/views/sessions.js +109 -0
- data/app/assets/javascripts/admin/views/virtual_form.js +47 -0
- data/app/assets/stylesheets/admin/_base.scss +5 -0
- data/app/assets/stylesheets/admin/_reset.scss +149 -0
- data/app/assets/stylesheets/admin/_root.scss +63 -0
- data/app/assets/stylesheets/admin/admin.scss +4 -0
- data/app/assets/stylesheets/admin/components/_blank_slate.scss +44 -0
- data/app/assets/stylesheets/admin/components/_buttons.scss +82 -0
- data/app/assets/stylesheets/admin/components/_flash_message.scss +64 -0
- data/app/assets/stylesheets/admin/components/_footer.scss +9 -0
- data/app/assets/stylesheets/admin/components/_header.scss +107 -0
- data/app/assets/stylesheets/admin/components/_index_table.scss +120 -0
- data/app/assets/stylesheets/admin/components/_main.scss +68 -0
- data/app/assets/stylesheets/admin/components/_markdown_body.scss +109 -0
- data/app/assets/stylesheets/admin/components/_navigation.scss +110 -0
- data/app/assets/stylesheets/admin/components/_pagination.scss +36 -0
- data/app/assets/stylesheets/admin/components/_pill.scss +11 -0
- data/app/assets/stylesheets/admin/components/_resource_form.scss +222 -0
- data/app/assets/stylesheets/admin/components/_search_form.scss +36 -0
- data/app/assets/stylesheets/admin/components/_sessions.scss +152 -0
- data/app/assets/stylesheets/admin/components/_show_table.scss +67 -0
- data/app/assets/stylesheets/admin/components/forms/_attachment_field.scss +59 -0
- data/app/assets/stylesheets/admin/components/forms/_chosen.scss +478 -0
- data/app/assets/stylesheets/admin/components/forms/_image_association_select.scss +20 -0
- data/app/assets/stylesheets/admin/components/forms/_markdown_composer.scss +149 -0
- data/app/assets/stylesheets/admin/components/forms/_nested_fields.scss +63 -0
- data/app/assets/stylesheets/admin/components/forms/_searchable_select.scss +8 -0
- data/app/assets/stylesheets/admin/components/forms/_slug_field.scss +20 -0
- data/app/assets/stylesheets/admin/components/forms/_swatch_field.scss +47 -0
- data/app/assets/stylesheets/admin/components/forms/_timestamp_field.scss +15 -0
- data/app/assets/stylesheets/admin/components/help_link.scss +6 -0
- data/app/assets/stylesheets/admin/mixins/_clearfix.scss +18 -0
- data/app/assets/stylesheets/admin/mixins/_min_max_width.scss +11 -0
- data/app/assets/stylesheets/admin/mixins/_rgbb.scss +7 -0
- data/app/assets/stylesheets/admin/mixins/_visuallyhidden.scss +33 -0
- data/app/assets/stylesheets/admin/settings/_animations.scss +21 -0
- data/app/assets/stylesheets/admin/settings/_breakpoints.scss +2 -0
- data/app/assets/stylesheets/admin/settings/_colors.scss +32 -0
- data/app/assets/stylesheets/admin/settings/_fonts.scss +31 -0
- data/app/assets/stylesheets/admin/settings/_icons.scss +1658 -0
- data/app/controllers/admin/admin_controller.rb +21 -0
- data/app/controllers/admin/sessions_controller.rb +112 -0
- data/app/controllers/tolaria/resource_controller.rb +132 -0
- data/app/controllers/tolaria/tolaria_controller.rb +40 -0
- data/app/helpers/admin/table_helper.rb +175 -0
- data/app/helpers/admin/view_helper.rb +76 -0
- data/app/mailers/passcode_mailer.rb +11 -0
- data/app/models/administrator.rb +146 -0
- data/app/views/admin/administrators/_form.html.erb +16 -0
- data/app/views/admin/administrators/_index.html.erb +20 -0
- data/app/views/admin/administrators/_search.html.erb +5 -0
- data/app/views/admin/administrators/_show.html.erb +14 -0
- data/app/views/admin/help/help_link.html.erb +16 -0
- data/app/views/admin/session/form.html.erb +52 -0
- data/app/views/admin/shared/_flash_messages.html.erb +42 -0
- data/app/views/admin/shared/_footer.html.erb +8 -0
- data/app/views/admin/shared/_head.html.erb +11 -0
- data/app/views/admin/shared/_header.html.erb +43 -0
- data/app/views/admin/shared/_navigation.html.erb +47 -0
- data/app/views/admin/shared/_skiplinks.html.erb +0 -0
- data/app/views/admin/shared/forms/_attachment_field.html.erb +17 -0
- data/app/views/admin/shared/forms/_has_many.html.erb +14 -0
- data/app/views/admin/shared/forms/_has_many_header.html.erb +19 -0
- data/app/views/admin/shared/forms/_image_association_select.html.erb +6 -0
- data/app/views/admin/shared/forms/_image_field.html.erb +19 -0
- data/app/views/admin/shared/forms/_markdown_composer.html.erb +29 -0
- data/app/views/admin/shared/forms/_searchable_select.html.erb +3 -0
- data/app/views/admin/shared/forms/_slug_field.html.erb +9 -0
- data/app/views/admin/shared/forms/_swatch_field.html.erb +4 -0
- data/app/views/admin/shared/forms/_timestamp_field.html.erb +19 -0
- data/app/views/admin/tolaria_resource/_form_buttons.html.erb +10 -0
- data/app/views/admin/tolaria_resource/_index_table.html.erb +73 -0
- data/app/views/admin/tolaria_resource/_search_form.html.erb +32 -0
- data/app/views/admin/tolaria_resource/_show_buttons.html.erb +13 -0
- data/app/views/admin/tolaria_resource/edit.html.erb +34 -0
- data/app/views/admin/tolaria_resource/index.html.erb +36 -0
- data/app/views/admin/tolaria_resource/new.html.erb +1 -0
- data/app/views/admin/tolaria_resource/show.html.erb +52 -0
- data/app/views/kaminari/admin/_first_page.html.erb +9 -0
- data/app/views/kaminari/admin/_last_page.html.erb +9 -0
- data/app/views/kaminari/admin/_next_page.html.erb +9 -0
- data/app/views/kaminari/admin/_page.html.erb +17 -0
- data/app/views/kaminari/admin/_paginator.html.erb +21 -0
- data/app/views/kaminari/admin/_prev_page.html.erb +9 -0
- data/app/views/layouts/admin/admin.html.erb +21 -0
- data/app/views/layouts/admin/sessions.html.erb +12 -0
- data/app/views/passcode_mailer/passcode.text.erb +5 -0
- data/lib/generators/tolaria/install/install_generator.rb +21 -0
- data/lib/generators/tolaria/install/templates/administrators_migration.rb +31 -0
- data/lib/generators/tolaria/install/templates/tolaria_initializer.rb +93 -0
- data/lib/tasks/admin.rake +32 -0
- data/lib/tolaria.rb +27 -0
- data/lib/tolaria/active_record.rb +55 -0
- data/lib/tolaria/admin.rb +4 -0
- data/lib/tolaria/categories.rb +21 -0
- data/lib/tolaria/config.rb +40 -0
- data/lib/tolaria/default_config.rb +74 -0
- data/lib/tolaria/engine.rb +23 -0
- data/lib/tolaria/form_buildable.rb +203 -0
- data/lib/tolaria/help_links.rb +78 -0
- data/lib/tolaria/introspection.rb +13 -0
- data/lib/tolaria/manage.rb +57 -0
- data/lib/tolaria/managed_class.rb +90 -0
- data/lib/tolaria/markdown.rb +28 -0
- data/lib/tolaria/random_tokens.rb +16 -0
- data/lib/tolaria/reload.rb +21 -0
- data/lib/tolaria/routes.rb +33 -0
- data/lib/tolaria/version.rb +13 -0
- data/test/demo/Rakefile +4 -0
- data/test/demo/app/assets/javascripts/application.js +1 -0
- data/test/demo/app/assets/stylesheets/application.scss +1 -0
- data/test/demo/app/controllers/application_controller.rb +5 -0
- data/test/demo/app/controllers/concerns/.keep +0 -0
- data/test/demo/app/controllers/homepage_controller.rb +4 -0
- data/test/demo/app/helpers/application_helper.rb +2 -0
- data/test/demo/app/mailers/.keep +0 -0
- data/test/demo/app/models/.keep +0 -0
- data/test/demo/app/models/blog_post.rb +43 -0
- data/test/demo/app/models/footnote.rb +5 -0
- data/test/demo/app/models/image.rb +19 -0
- data/test/demo/app/models/legal_page.rb +24 -0
- data/test/demo/app/models/miscellany.rb +12 -0
- data/test/demo/app/models/topic.rb +22 -0
- data/test/demo/app/models/video.rb +16 -0
- data/test/demo/app/views/admin/blog_posts/_form.html.erb +48 -0
- data/test/demo/app/views/admin/blog_posts/_search.html.erb +5 -0
- data/test/demo/app/views/admin/help/markdown-help.md +95 -0
- data/test/demo/app/views/admin/images/_form.html.erb +26 -0
- data/test/demo/app/views/admin/legal_pages/_form.html.erb +15 -0
- data/test/demo/app/views/admin/topics/_form.html.erb +3 -0
- data/test/demo/app/views/admin/videos/_form.html.erb +11 -0
- data/test/demo/app/views/homepage/homepage.html.erb +3 -0
- data/test/demo/app/views/layouts/application.html.erb +14 -0
- data/test/demo/bin/bundle +3 -0
- data/test/demo/bin/rails +4 -0
- data/test/demo/bin/rake +4 -0
- data/test/demo/bin/setup +29 -0
- data/test/demo/config.ru +4 -0
- data/test/demo/config/application.rb +26 -0
- data/test/demo/config/boot.rb +4 -0
- data/test/demo/config/database.yml +18 -0
- data/test/demo/config/environment.rb +3 -0
- data/test/demo/config/environments/development.rb +43 -0
- data/test/demo/config/environments/test.rb +44 -0
- data/test/demo/config/initializers/assets.rb +11 -0
- data/test/demo/config/initializers/cookies_serializer.rb +2 -0
- data/test/demo/config/initializers/filter_parameter_logging.rb +3 -0
- data/test/demo/config/initializers/inflections.rb +17 -0
- data/test/demo/config/initializers/markdown.rb +44 -0
- data/test/demo/config/initializers/secret_token.rb +2 -0
- data/test/demo/config/initializers/session_store.rb +2 -0
- data/test/demo/config/initializers/tolaria.rb +17 -0
- data/test/demo/config/initializers/wrap_parameters.rb +14 -0
- data/test/demo/config/routes.rb +4 -0
- data/test/demo/db/migrate/20150601202901_create_administrators.rb +31 -0
- data/test/demo/db/migrate/20150603204006_add_testing_models.rb +27 -0
- data/test/demo/db/migrate/20150609232013_create_footnotes.rb +10 -0
- data/test/demo/db/migrate/20150610135235_create_additional_demo_objects.rb +50 -0
- data/test/demo/db/schema.rb +112 -0
- data/test/demo/log/.keep +0 -0
- data/test/demo/public/404.html +67 -0
- data/test/demo/public/422.html +67 -0
- data/test/demo/public/500.html +66 -0
- data/test/demo/public/favicon.ico +0 -0
- data/test/integration/help_link_test.rb +73 -0
- data/test/integration/interface_test.rb +63 -0
- data/test/integration/router_test.rb +73 -0
- data/test/integration/session_test.rb +88 -0
- data/test/test_helper.rb +58 -0
- data/test/unit/configuration_test.rb +21 -0
- data/test/unit/managed_classes_test.rb +54 -0
- data/test/unit/markdown_test.rb +12 -0
- data/test/unit/menu_test.rb +32 -0
- data/test/unit/random_tokens_test.rb +13 -0
- data/tolaria.gemspec +35 -0
- metadata +499 -0
|
File without changes
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class HelpLinkTest < ActionDispatch::IntegrationTest
|
|
4
|
+
|
|
5
|
+
test "demo help link is rendering, Markdown works" do
|
|
6
|
+
sign_in_dummy_administrator!
|
|
7
|
+
visit("/admin/blog_posts")
|
|
8
|
+
assert page.has_content?("Markdown Help")
|
|
9
|
+
visit("/admin/help/markdown-help")
|
|
10
|
+
assert page.has_content?("paragraph"), "Should see Markdown help"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "link_to Help links work" do
|
|
14
|
+
|
|
15
|
+
sign_in_dummy_administrator!
|
|
16
|
+
original_config = Tolaria.config.help_links
|
|
17
|
+
|
|
18
|
+
Tolaria.config.help_links = [{
|
|
19
|
+
title: "Google",
|
|
20
|
+
link_to: "https://www.google.com",
|
|
21
|
+
}]
|
|
22
|
+
Tolaria.reload!
|
|
23
|
+
visit("/admin/blog_posts")
|
|
24
|
+
assert page.has_content?("Google"), "Should see Google link"
|
|
25
|
+
|
|
26
|
+
Tolaria.config.help_links = original_config
|
|
27
|
+
Tolaria.reload!
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
test "reject invalid HelpLinks" do
|
|
32
|
+
|
|
33
|
+
@original_config = Tolaria.config.help_links
|
|
34
|
+
|
|
35
|
+
assert_raises RuntimeError do
|
|
36
|
+
Tolaria.config.help_links = [{
|
|
37
|
+
title: "Evon Gnashblade",
|
|
38
|
+
}]
|
|
39
|
+
Tolaria.reload!
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
assert_raises RuntimeError do
|
|
43
|
+
Tolaria.config.help_links = [{
|
|
44
|
+
title: "Evon Gnashblade",
|
|
45
|
+
markdown_file: "junk"
|
|
46
|
+
}]
|
|
47
|
+
Tolaria.reload!
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
assert_raises RuntimeError do
|
|
51
|
+
Tolaria.config.help_links = [{
|
|
52
|
+
title: "Evon Gnashblade",
|
|
53
|
+
markdown_file: "junk",
|
|
54
|
+
slug: "evon",
|
|
55
|
+
link_to: "evon"
|
|
56
|
+
}]
|
|
57
|
+
Tolaria.reload!
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
assert_raises RuntimeError, ArgumentError do
|
|
61
|
+
Tolaria.config.help_links = [{
|
|
62
|
+
link_to: "junk"
|
|
63
|
+
}]
|
|
64
|
+
Tolaria.reload!
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
Tolaria.config.help_links = @original_config
|
|
68
|
+
Tolaria.reload!
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class InterfaceTest < ActionDispatch::IntegrationTest
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
BlogPost.destroy_all
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def teardown
|
|
10
|
+
BlogPost.destroy_all
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "menu is rendering" do
|
|
14
|
+
sign_in_dummy_administrator!
|
|
15
|
+
visit("/admin/blog_posts")
|
|
16
|
+
assert page.has_content?("Blog Posts")
|
|
17
|
+
assert page.has_content?("Topics")
|
|
18
|
+
assert page.has_content?("Administrators")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test "get the blog index and see empty slate" do
|
|
22
|
+
sign_in_dummy_administrator!
|
|
23
|
+
visit("/admin/blog_posts")
|
|
24
|
+
assert page.has_content?("New Blog Post")
|
|
25
|
+
assert page.has_content?("Blog Posts")
|
|
26
|
+
assert page.has_content?("live here")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test "create a blog post, see it on the index, inspect it" do
|
|
30
|
+
|
|
31
|
+
sign_in_dummy_administrator!
|
|
32
|
+
visit("/admin/blog_posts")
|
|
33
|
+
first(".button.-primary").click
|
|
34
|
+
fill_in("blog_post[title]", with:"Neko Atsume")
|
|
35
|
+
fill_in("blog_post[summary]", with:"Neko Atsume")
|
|
36
|
+
fill_in("blog_post[body]", with:"Neko Atsume")
|
|
37
|
+
first(".button.-primary").click
|
|
38
|
+
|
|
39
|
+
assert page.current_path.include?(admin_blog_posts_path)
|
|
40
|
+
assert page.has_content?("Neko Atsume")
|
|
41
|
+
assert page.has_content?("created the"), "should see flash message"
|
|
42
|
+
|
|
43
|
+
find_link("Neko Atsume").click
|
|
44
|
+
|
|
45
|
+
assert page.current_path.include?(admin_blog_post_path(BlogPost.first.id))
|
|
46
|
+
assert page.has_content?("Neko Atsume")
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
test "blog post fails validation and sees flash message" do
|
|
51
|
+
|
|
52
|
+
sign_in_dummy_administrator!
|
|
53
|
+
visit("/admin/blog_posts")
|
|
54
|
+
first(".button.-primary").click
|
|
55
|
+
fill_in "blog_post[title]", with:"Neko Atsume"
|
|
56
|
+
first(".button.-primary").click
|
|
57
|
+
|
|
58
|
+
assert page.has_content?("correct the following"), "should see flash message"
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class RouterTest < ActionDispatch::IntegrationTest
|
|
4
|
+
|
|
5
|
+
test "draws admin routes" do
|
|
6
|
+
assert admin_new_session_path, "route should exist"
|
|
7
|
+
assert admin_destroy_session_path, "route should exist"
|
|
8
|
+
assert admin_root_path, "route should exist"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test "draws automatic model routes" do
|
|
12
|
+
|
|
13
|
+
class ::Card < ActiveRecord::Base
|
|
14
|
+
manage_with_tolaria using:{
|
|
15
|
+
allowed_actions: [:index, :show]
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Re-draw the routes
|
|
20
|
+
Rails.application.routes.draw do
|
|
21
|
+
Tolaria.draw_routes(self)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Test all of the routes Tolaria should have drawn
|
|
25
|
+
# from here and from the demo application
|
|
26
|
+
|
|
27
|
+
assert_equal admin_cards_path, "/admin/cards"
|
|
28
|
+
assert_equal admin_card_path(1), "/admin/cards/1"
|
|
29
|
+
|
|
30
|
+
assert admin_blog_posts_path, "route should exist"
|
|
31
|
+
assert admin_blog_posts_path(1), "route should exist"
|
|
32
|
+
assert edit_admin_blog_post_path(1), "route should exist"
|
|
33
|
+
assert admin_blog_post_path(1), "route should exist"
|
|
34
|
+
|
|
35
|
+
assert admin_topics_path, "route should exist"
|
|
36
|
+
assert admin_topic_path(1), "route should exist"
|
|
37
|
+
assert edit_admin_topic_path(1), "route should exist"
|
|
38
|
+
assert admin_topic_path(1), "route should exist"
|
|
39
|
+
|
|
40
|
+
# Unseat the Card class so that it doesn't leak out of this test
|
|
41
|
+
assert Tolaria.discard_managed_class(Card), "should discard class"
|
|
42
|
+
Object.send(:remove_const, :Card)
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
test "correctly draws uncountable routes" do
|
|
47
|
+
|
|
48
|
+
ActiveSupport::Inflector.inflections do |inflect|
|
|
49
|
+
inflect.uncountable << "pokemon"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class ::Pokemon < ActiveRecord::Base
|
|
53
|
+
manage_with_tolaria using:{
|
|
54
|
+
icon: "gear",
|
|
55
|
+
}
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Re-draw the routes
|
|
59
|
+
Rails.application.routes.draw do
|
|
60
|
+
Tolaria.draw_routes(self)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
assert_equal "/admin/pokemon", admin_pokemon_index_path
|
|
64
|
+
assert_equal "/admin/pokemon/1", admin_pokemon_path(1)
|
|
65
|
+
assert_equal "/admin/pokemon/1/edit", edit_admin_pokemon_path(1)
|
|
66
|
+
|
|
67
|
+
# Unseat the class so that it doesn't leak out of this test
|
|
68
|
+
assert Tolaria.discard_managed_class(Pokemon), "should discard class"
|
|
69
|
+
Object.send(:remove_const, :Pokemon)
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class SessionTest < ActionDispatch::IntegrationTest
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@administrator = create_dummy_administrator!
|
|
7
|
+
reset!
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def fill_out_signin_form!(email:, passcode:)
|
|
11
|
+
visit("/admin/signin")
|
|
12
|
+
find("#session-form-email").set(email)
|
|
13
|
+
find("#session-form-passcode", visible:false).set(passcode)
|
|
14
|
+
find("#session-form-submit").click
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Assert that we landed back on the signin form with the rejection message showing
|
|
18
|
+
def assert_failed_authentication!
|
|
19
|
+
assert page.has_content?("wasn’t correct"), "should see rejection flash message"
|
|
20
|
+
assert_equal "/admin/signin", current_path
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test "should get redirected to the signin form" do
|
|
24
|
+
visit("/admin")
|
|
25
|
+
assert_equal "/admin/signin", current_path
|
|
26
|
+
assert_equal 200, status_code
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test "should get the signin form" do
|
|
30
|
+
visit "/admin/signin"
|
|
31
|
+
assert_equal 200, status_code
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
test "session form doesn't explode when junk submitted" do
|
|
35
|
+
post "/admin/signin", {
|
|
36
|
+
a: "Z6b4y26r16eSz6w7qLef722MC1IGK36K",
|
|
37
|
+
b: { c: "LKgagZfpIhQMV8xfKfwSalp3RO6Nm6e6" }
|
|
38
|
+
}
|
|
39
|
+
assert_response :see_other
|
|
40
|
+
assert response["Location"].include?("signin")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
test "can sign in with passcode" do
|
|
44
|
+
sign_in_dummy_administrator!
|
|
45
|
+
assert current_path.exclude?("/admin/signin")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
test "can't sign in with bad passcode" do
|
|
49
|
+
passcode = @administrator.set_passcode!
|
|
50
|
+
fill_out_signin_form! email:@administrator.email, passcode:"bad passcode"
|
|
51
|
+
assert_failed_authentication!
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
test "can't sign in with an expired passcode" do
|
|
55
|
+
passcode = @administrator.set_passcode!
|
|
56
|
+
Timecop.freeze(Time.current + Tolaria.config.passcode_lifespan + 1.second) do
|
|
57
|
+
fill_out_signin_form! email:@administrator.email, passcode:passcode
|
|
58
|
+
assert_failed_authentication!
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
test "account gets locked and unlocks" do
|
|
63
|
+
|
|
64
|
+
passcode = @administrator.set_passcode!
|
|
65
|
+
|
|
66
|
+
Tolaria.config.lockout_threshold.times do |i|
|
|
67
|
+
fill_out_signin_form! email:@administrator.email, passcode:"bad passcode"
|
|
68
|
+
assert_failed_authentication!
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
fill_out_signin_form! email:@administrator.email, passcode:passcode
|
|
72
|
+
assert_failed_authentication!
|
|
73
|
+
|
|
74
|
+
@administrator.reload
|
|
75
|
+
assert @administrator.locked?, "account should be locked"
|
|
76
|
+
|
|
77
|
+
Timecop.freeze(Time.current + Tolaria.config.lockout_duration + 1.second) do
|
|
78
|
+
refute @administrator.locked?, "account should unlock after duration"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
@administrator.unlock_account!
|
|
82
|
+
@administrator.reload
|
|
83
|
+
refute @administrator.locked?, "account should be unlock when instructed"
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# -----------------------------------------------------------------------------
|
|
2
|
+
# TEST SETUP
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
# Configure Rails and load libraries
|
|
6
|
+
ENV["RAILS_ENV"] = "test"
|
|
7
|
+
require File.expand_path("../../test/demo/config/environment.rb", __FILE__)
|
|
8
|
+
require "rails/test_help"
|
|
9
|
+
require "tolaria"
|
|
10
|
+
require "capybara/rails"
|
|
11
|
+
require "timecop"
|
|
12
|
+
require "minitest/unit"
|
|
13
|
+
require "minitest/pride"
|
|
14
|
+
|
|
15
|
+
# Filter out Minitest backtrace while allowing backtrace from
|
|
16
|
+
# other libraries to be shown.
|
|
17
|
+
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
|
18
|
+
|
|
19
|
+
# Run Timecop in safe mode so time tests don't leak
|
|
20
|
+
Timecop.safe_mode = true
|
|
21
|
+
|
|
22
|
+
# Load support files
|
|
23
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
24
|
+
|
|
25
|
+
# Load fixtures from the engine
|
|
26
|
+
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
|
|
27
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
|
28
|
+
ActiveSupport::TestCase.fixtures :all
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class ActionDispatch::IntegrationTest
|
|
32
|
+
|
|
33
|
+
# Include the Rails route helpers
|
|
34
|
+
include Rails.application.routes.url_helpers
|
|
35
|
+
|
|
36
|
+
# Include support for the Capybara DSL
|
|
37
|
+
include Capybara::DSL
|
|
38
|
+
Capybara.javascript_driver = :webkit
|
|
39
|
+
|
|
40
|
+
# A method to create a dummy administrator and return it
|
|
41
|
+
def create_dummy_administrator!
|
|
42
|
+
return Administrator.find_or_create_by!({
|
|
43
|
+
name: "宮本 茂",
|
|
44
|
+
organization: "Nintendo",
|
|
45
|
+
email: "someone@example.com",
|
|
46
|
+
})
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def sign_in_dummy_administrator!
|
|
50
|
+
@administrator = create_dummy_administrator!
|
|
51
|
+
passcode = @administrator.set_passcode!
|
|
52
|
+
visit("/admin/signin")
|
|
53
|
+
find("#session-form-email").set(@administrator.email)
|
|
54
|
+
find("#session-form-passcode", visible:false).set(passcode)
|
|
55
|
+
find("#session-form-submit").click
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class CongfigurationTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
test "can't assign unknown config" do
|
|
6
|
+
assert_raises NoMethodError do
|
|
7
|
+
Tolaria.configure do |config|
|
|
8
|
+
config.bullshit = "ಠ_ಠ"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "can't pass a block to Tolaria.config" do
|
|
14
|
+
assert_raises ArgumentError do
|
|
15
|
+
Tolaria.config do |config|
|
|
16
|
+
config.bullshit = "ಠ_ಠ"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class ManagedClassesTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
test "can manage, check, and unmanage a model" do
|
|
6
|
+
|
|
7
|
+
class ::Card < ActiveRecord::Base
|
|
8
|
+
manage_with_tolaria using:{
|
|
9
|
+
icon: "credit-card",
|
|
10
|
+
priority: 5,
|
|
11
|
+
category: "Payments",
|
|
12
|
+
default_order: "id DESC",
|
|
13
|
+
paginated: true,
|
|
14
|
+
allowed_actions: [:index, :show]
|
|
15
|
+
}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Find that class
|
|
19
|
+
managed_class = Tolaria.managed_classes.find do |managed_class|
|
|
20
|
+
managed_class.klass.eql?(Card)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Did we find the class we just managed?
|
|
24
|
+
assert managed_class.present?
|
|
25
|
+
assert managed_class.klass.eql?(Card)
|
|
26
|
+
|
|
27
|
+
# Can we can get our settings back?
|
|
28
|
+
assert_equal managed_class.icon, "credit-card"
|
|
29
|
+
assert_equal managed_class.priority, 5
|
|
30
|
+
assert_equal managed_class.category, "Payments"
|
|
31
|
+
assert_equal managed_class.default_order, "id DESC"
|
|
32
|
+
assert_equal managed_class.allowed_actions, [:index, :show]
|
|
33
|
+
assert managed_class.paginated, true
|
|
34
|
+
|
|
35
|
+
# Can we check action allowances?
|
|
36
|
+
assert managed_class.allows?(:index), "should allow `index` action"
|
|
37
|
+
assert managed_class.allows?(:show), "should allow `show` action"
|
|
38
|
+
refute managed_class.allows?(:edit), "shouldn't allow `edit` action"
|
|
39
|
+
refute managed_class.allows?(:discard), "shouldn't allow nonsense action"
|
|
40
|
+
|
|
41
|
+
# Are our autogenerated name are correct?
|
|
42
|
+
assert_equal managed_class.controller_name, "CardsController"
|
|
43
|
+
assert_equal managed_class.param_key, :card
|
|
44
|
+
|
|
45
|
+
# Can we throw away our work?
|
|
46
|
+
assert Tolaria.discard_managed_class(Card), "should unseat Card class"
|
|
47
|
+
assert Tolaria.managed_classes.collect(&:klass).exclude?(Card), "shouldn't have card class"
|
|
48
|
+
|
|
49
|
+
# Unseat the Card class so that it doesn't leak out of this test
|
|
50
|
+
Object.send(:remove_const, :Card)
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class MarkdownTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
test "generate a paragraph" do
|
|
6
|
+
assert_equal(
|
|
7
|
+
"<p>Ach! Hans, run! Its the Pascagoyf!</p>".squish,
|
|
8
|
+
Tolaria.render_markdown("Ach! Hans, run! Its the Pascagoyf!").squish
|
|
9
|
+
)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|