typus 0.9.17
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/.gitignore +8 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +86 -0
- data/Rakefile +61 -0
- data/VERSION +1 -0
- data/app/controllers/admin/master_controller.rb +354 -0
- data/app/controllers/typus_controller.rb +128 -0
- data/app/helpers/admin/form_helper.rb +386 -0
- data/app/helpers/admin/master_helper.rb +104 -0
- data/app/helpers/admin/public_helper.rb +27 -0
- data/app/helpers/admin/sidebar_helper.rb +236 -0
- data/app/helpers/admin/table_helper.rb +227 -0
- data/app/helpers/typus_helper.rb +194 -0
- data/app/models/typus_mailer.rb +14 -0
- data/app/models/typus_user.rb +5 -0
- data/app/views/admin/dashboard/_sidebar.html.erb +9 -0
- data/app/views/admin/resources/edit.html.erb +24 -0
- data/app/views/admin/resources/index.html.erb +23 -0
- data/app/views/admin/resources/new.html.erb +22 -0
- data/app/views/admin/resources/show.html.erb +18 -0
- data/app/views/admin/shared/_footer.html.erb +1 -0
- data/app/views/admin/shared/_pagination.html.erb +28 -0
- data/app/views/layouts/admin.html.erb +73 -0
- data/app/views/layouts/typus.html.erb +29 -0
- data/app/views/typus/dashboard.html.erb +9 -0
- data/app/views/typus/recover_password.html.erb +7 -0
- data/app/views/typus/reset_password.html.erb +15 -0
- data/app/views/typus/sign_in.html.erb +9 -0
- data/app/views/typus/sign_up.html.erb +7 -0
- data/app/views/typus_mailer/reset_password_link.erb +11 -0
- data/config/locales/typus/de.yml +109 -0
- data/config/locales/typus/es.yml +109 -0
- data/config/locales/typus/language.yml.template +113 -0
- data/config/locales/typus/pt-BR.yml +111 -0
- data/config/locales/typus/ru.yml +111 -0
- data/generators/typus/templates/config/initializers/typus.rb +33 -0
- data/generators/typus/templates/config/typus/README +51 -0
- data/generators/typus/templates/config/typus/application.yml +6 -0
- data/generators/typus/templates/config/typus/application_roles.yml +23 -0
- data/generators/typus/templates/config/typus/typus.yml +14 -0
- data/generators/typus/templates/config/typus/typus_roles.yml +2 -0
- data/generators/typus/templates/db/create_typus_users.rb +21 -0
- data/generators/typus/templates/public/images/admin/arrow_down.gif +0 -0
- data/generators/typus/templates/public/images/admin/arrow_up.gif +0 -0
- data/generators/typus/templates/public/images/admin/spinner.gif +0 -0
- data/generators/typus/templates/public/images/admin/status_false.gif +0 -0
- data/generators/typus/templates/public/images/admin/status_true.gif +0 -0
- data/generators/typus/templates/public/images/admin/trash.gif +0 -0
- data/generators/typus/templates/public/javascripts/admin/application.js +14 -0
- data/generators/typus/templates/public/stylesheets/admin/reset.css +68 -0
- data/generators/typus/templates/public/stylesheets/admin/screen.css +729 -0
- data/generators/typus/typus_generator.rb +122 -0
- data/generators/typus_update_schema_to_01/templates/config/typus.yml +14 -0
- data/generators/typus_update_schema_to_01/templates/migration.rb +11 -0
- data/generators/typus_update_schema_to_01/typus_update_schema_to_01_generator.rb +19 -0
- data/lib/typus.rb +122 -0
- data/lib/typus/active_record.rb +307 -0
- data/lib/typus/authentication.rb +142 -0
- data/lib/typus/configuration.rb +85 -0
- data/lib/typus/extensions/routes.rb +15 -0
- data/lib/typus/format.rb +55 -0
- data/lib/typus/generator.rb +81 -0
- data/lib/typus/hash.rb +8 -0
- data/lib/typus/locale.rb +17 -0
- data/lib/typus/object.rb +21 -0
- data/lib/typus/quick_edit.rb +40 -0
- data/lib/typus/reloader.rb +15 -0
- data/lib/typus/string.rb +11 -0
- data/lib/typus/templates/index.html.erb +11 -0
- data/lib/typus/templates/resource_controller.rb.erb +15 -0
- data/lib/typus/templates/resource_controller_test.rb.erb +10 -0
- data/lib/typus/templates/resources_controller.rb.erb +37 -0
- data/lib/typus/user.rb +134 -0
- data/lib/vendor/active_record.rb +15 -0
- data/lib/vendor/paginator.rb +143 -0
- data/rails/init.rb +3 -0
- data/tasks/typus_tasks.rake +32 -0
- data/test/config/broken/application.yml +68 -0
- data/test/config/broken/application_roles.yml +20 -0
- data/test/config/broken/empty.yml +0 -0
- data/test/config/broken/empty_roles.yml +0 -0
- data/test/config/broken/undefined.yml +3 -0
- data/test/config/broken/undefined_roles.yml +6 -0
- data/test/config/default/typus.yml +14 -0
- data/test/config/default/typus_roles.yml +2 -0
- data/test/config/empty/empty_01.yml +0 -0
- data/test/config/empty/empty_01_roles.yml +0 -0
- data/test/config/empty/empty_02.yml +0 -0
- data/test/config/empty/empty_02_roles.yml +0 -0
- data/test/config/locales/es.yml +10 -0
- data/test/config/ordered/001_roles.yml +2 -0
- data/test/config/ordered/002_roles.yml +2 -0
- data/test/config/unordered/app_one_roles.yml +2 -0
- data/test/config/unordered/app_two_roles.yml +2 -0
- data/test/config/working/application.yml +68 -0
- data/test/config/working/application_roles.yml +22 -0
- data/test/config/working/typus.yml +14 -0
- data/test/config/working/typus_roles.yml +2 -0
- data/test/fixtures/app/controllers/admin/assets_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/categories_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/comments_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/pages_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/posts_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/status_controller.rb +6 -0
- data/test/fixtures/app/controllers/admin/typus_users_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/watch_dog_controller.rb +6 -0
- data/test/fixtures/app/views/admin/comments/_edit.html.erb +1 -0
- data/test/fixtures/app/views/admin/comments/_index.html.erb +1 -0
- data/test/fixtures/app/views/admin/comments/_new.html.erb +1 -0
- data/test/fixtures/app/views/admin/comments/_show.html.erb +1 -0
- data/test/fixtures/app/views/admin/comments/_sidebar.html.erb +1 -0
- data/test/fixtures/app/views/admin/dashboard/_content.html.erb +1 -0
- data/test/fixtures/app/views/admin/dashboard/_sidebar.html.erb +1 -0
- data/test/fixtures/app/views/admin/resources/_sidebar.html.erb +1 -0
- data/test/fixtures/app/views/admin/shared/_footer.html.erb +1 -0
- data/test/fixtures/app/views/admin/status/index.html.erb +1 -0
- data/test/fixtures/app/views/admin/templates/_datepicker.html.erb +1 -0
- data/test/fixtures/assets.yml +11 -0
- data/test/fixtures/categories.yml +14 -0
- data/test/fixtures/comments.yml +27 -0
- data/test/fixtures/pages.yml +41 -0
- data/test/fixtures/posts.yml +37 -0
- data/test/fixtures/typus_users.yml +54 -0
- data/test/functional/admin/assets_controller_test.rb +57 -0
- data/test/functional/admin/categories_controller_test.rb +106 -0
- data/test/functional/admin/comments_controller_test.rb +120 -0
- data/test/functional/admin/master_controller_test.rb +5 -0
- data/test/functional/admin/posts_controller_test.rb +261 -0
- data/test/functional/admin/status_controller_test.rb +43 -0
- data/test/functional/admin/typus_users_controller_test.rb +239 -0
- data/test/functional/typus_controller_test.rb +321 -0
- data/test/helper.rb +51 -0
- data/test/helpers/admin/form_helper_test.rb +337 -0
- data/test/helpers/admin/master_helper_test.rb +69 -0
- data/test/helpers/admin/public_helper_test.rb +26 -0
- data/test/helpers/admin/sidebar_helper_test.rb +335 -0
- data/test/helpers/admin/table_helper_test.rb +239 -0
- data/test/helpers/typus_helper_test.rb +117 -0
- data/test/lib/active_record_test.rb +382 -0
- data/test/lib/configuration_test.rb +94 -0
- data/test/lib/hash_test.rb +11 -0
- data/test/lib/routes_test.rb +71 -0
- data/test/lib/string_test.rb +25 -0
- data/test/lib/typus_test.rb +85 -0
- data/test/models.rb +51 -0
- data/test/schema.rb +64 -0
- data/test/unit/typus_mailer_test.rb +33 -0
- data/test/unit/typus_test.rb +17 -0
- data/test/unit/typus_user_roles_test.rb +90 -0
- data/test/unit/typus_user_test.rb +177 -0
- data/test/vendor/active_record_test.rb +18 -0
- data/test/vendor/paginator_test.rb +136 -0
- data/typus.gemspec +228 -0
- metadata +241 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require 'test/helper'
|
|
2
|
+
|
|
3
|
+
class ConfigurationTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def test_should_verify_configuration_responds_to_options
|
|
6
|
+
assert Typus::Configuration.respond_to?(:options)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def test_should_verify_application_wide_configuration_options
|
|
10
|
+
initializer = "#{Rails.root}/config/initializers/typus.rb"
|
|
11
|
+
return if File.exist?(initializer)
|
|
12
|
+
assert_equal 'Typus', Typus::Configuration.options[:app_name]
|
|
13
|
+
assert_equal 'vendor/plugins/typus/test/config/working', Typus::Configuration.options[:config_folder]
|
|
14
|
+
assert_equal 'admin@example.com', Typus::Configuration.options[:email]
|
|
15
|
+
assert_equal [ [ "English", :en] ], Typus::Configuration.options[:locales]
|
|
16
|
+
assert_equal false, Typus::Configuration.options[:recover_password]
|
|
17
|
+
assert_equal 'admin', Typus::Configuration.options[:root]
|
|
18
|
+
assert_equal false, Typus::Configuration.options[:ssl]
|
|
19
|
+
assert_equal 'admin/templates', Typus::Configuration.options[:templates_folder]
|
|
20
|
+
assert_equal 'TypusUser', Typus::Configuration.options[:user_class_name]
|
|
21
|
+
assert_equal 'typus_user_id', Typus::Configuration.options[:user_fk]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_should_verify_model_configuration_options
|
|
25
|
+
initializer = "#{Rails.root}/config/initializers/typus.rb"
|
|
26
|
+
return if File.exist?(initializer)
|
|
27
|
+
assert_equal 'edit', Typus::Configuration.options[:default_action_on_item]
|
|
28
|
+
assert_nil Typus::Configuration.options[:end_year]
|
|
29
|
+
assert_equal 10, Typus::Configuration.options[:form_rows]
|
|
30
|
+
assert_equal true, Typus::Configuration.options[:icon_on_boolean]
|
|
31
|
+
assert_equal false, Typus::Configuration.options[:index_after_save]
|
|
32
|
+
assert_equal 5, Typus::Configuration.options[:minute_step]
|
|
33
|
+
assert_equal 'nil', Typus::Configuration.options[:nil]
|
|
34
|
+
assert_equal false, Typus::Configuration.options[:on_header]
|
|
35
|
+
assert_equal false, Typus::Configuration.options[:only_user_items]
|
|
36
|
+
assert_equal 15, Typus::Configuration.options[:per_page]
|
|
37
|
+
assert_equal 5, Typus::Configuration.options[:sidebar_selector]
|
|
38
|
+
assert_nil Typus::Configuration.options[:start_year]
|
|
39
|
+
assert_equal true, Typus::Configuration.options[:toggle]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_should_verify_typus_roles_is_loaded
|
|
43
|
+
assert Typus::Configuration.respond_to?(:roles!)
|
|
44
|
+
assert Typus::Configuration.roles!.kind_of?(Hash)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_should_verify_typus_config_file_is_loaded
|
|
48
|
+
assert Typus::Configuration.respond_to?(:config!)
|
|
49
|
+
assert Typus::Configuration.config!.kind_of?(Hash)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_should_load_configuration_files_from_config_broken
|
|
53
|
+
options = { :config_folder => 'vendor/plugins/typus/test/config/broken' }
|
|
54
|
+
Typus::Configuration.stubs(:options).returns(options)
|
|
55
|
+
assert_not_equal Hash.new, Typus::Configuration.roles!
|
|
56
|
+
assert_not_equal Hash.new, Typus::Configuration.config!
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_should_load_configuration_files_from_config_empty
|
|
60
|
+
options = { :config_folder => 'vendor/plugins/typus/test/config/empty' }
|
|
61
|
+
Typus::Configuration.stubs(:options).returns(options)
|
|
62
|
+
assert_equal Hash.new, Typus::Configuration.roles!
|
|
63
|
+
assert_equal Hash.new, Typus::Configuration.config!
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_should_load_configuration_files_from_config_ordered
|
|
67
|
+
options = { :config_folder => 'vendor/plugins/typus/test/config/ordered' }
|
|
68
|
+
Typus::Configuration.stubs(:options).returns(options)
|
|
69
|
+
files = Dir["#{Rails.root}/#{Typus::Configuration.options[:config_folder]}/*_roles.yml"]
|
|
70
|
+
expected = files.collect { |file| File.basename(file) }.sort
|
|
71
|
+
assert_equal expected, ['001_roles.yml', '002_roles.yml']
|
|
72
|
+
expected = { 'admin' => { 'categories' => 'read' } }
|
|
73
|
+
assert_equal expected, Typus::Configuration.roles!
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_should_load_configuration_files_from_config_unordered
|
|
77
|
+
options = { :config_folder => 'vendor/plugins/typus/test/config/unordered' }
|
|
78
|
+
Typus::Configuration.stubs(:options).returns(options)
|
|
79
|
+
files = Dir["#{Rails.root}/#{Typus::Configuration.options[:config_folder]}/*_roles.yml"]
|
|
80
|
+
expected = files.collect { |file| File.basename(file) }
|
|
81
|
+
assert_equal expected, ['app_one_roles.yml', 'app_two_roles.yml']
|
|
82
|
+
expected = { 'admin' => { 'categories' => 'read, update' } }
|
|
83
|
+
assert_equal expected, Typus::Configuration.roles!
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def test_should_load_configuration_files_from_config_default
|
|
87
|
+
options = { :config_folder => 'vendor/plugins/typus/test/config/default' }
|
|
88
|
+
Typus::Configuration.stubs(:options).returns(options)
|
|
89
|
+
assert_not_equal Hash.new, Typus::Configuration.roles!
|
|
90
|
+
assert_not_equal Hash.new, Typus::Configuration.config!
|
|
91
|
+
assert Typus.resources.empty?
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'test/helper'
|
|
2
|
+
|
|
3
|
+
class RoutesTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
include ActionController::TestCase::Assertions
|
|
6
|
+
|
|
7
|
+
def test_should_verify_admin_named_routes
|
|
8
|
+
|
|
9
|
+
routes = ActionController::Routing::Routes.named_routes.routes.keys
|
|
10
|
+
|
|
11
|
+
expected = [ :admin_sign_up, :admin_sign_in, :admin_sign_out,
|
|
12
|
+
:admin_recover_password, :admin_reset_password,
|
|
13
|
+
:admin_dashboard,
|
|
14
|
+
:admin_quick_edit, :admin_set_locale ]
|
|
15
|
+
|
|
16
|
+
expected.each { |route| assert routes.include?(route) }
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_should_verify_admin_named_routes_for_typus_users
|
|
21
|
+
|
|
22
|
+
routes = ActionController::Routing::Routes.named_routes.routes.keys
|
|
23
|
+
|
|
24
|
+
expected = [ :admin_typus_users,
|
|
25
|
+
:admin_typus_user ]
|
|
26
|
+
|
|
27
|
+
expected.each { |route| assert !routes.include?(route) }
|
|
28
|
+
|
|
29
|
+
expected = [ :relate_admin_typus_user,
|
|
30
|
+
:unrelate_admin_typus_user ]
|
|
31
|
+
|
|
32
|
+
expected.each { |route| assert !routes.include?(route) }
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_should_verify_default_admin_named_routes_for_posts
|
|
37
|
+
|
|
38
|
+
routes = ActionController::Routing::Routes.named_routes.routes.keys
|
|
39
|
+
|
|
40
|
+
expected = [ :admin_posts,
|
|
41
|
+
:admin_post ]
|
|
42
|
+
|
|
43
|
+
expected.each { |route| assert !routes.include?(route) }
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_should_verify_custom_admin_named_routes_for_posts
|
|
48
|
+
|
|
49
|
+
routes = ActionController::Routing::Routes.named_routes.routes.keys
|
|
50
|
+
|
|
51
|
+
expected = [ :cleanup_admin_posts,
|
|
52
|
+
:send_as_newsletter_admin_post,
|
|
53
|
+
:preview_admin_post ]
|
|
54
|
+
|
|
55
|
+
expected.each { |route| assert !routes.include?(route) }
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_should_verify_generated_routes_for_typus_controller
|
|
60
|
+
|
|
61
|
+
assert_routing '/admin', :controller => 'typus', :action => 'dashboard'
|
|
62
|
+
|
|
63
|
+
actions = [ 'sign_up', 'sign_in', 'sign_out',
|
|
64
|
+
'recover_password', 'reset_password',
|
|
65
|
+
'quick_edit', 'set_locale' ]
|
|
66
|
+
|
|
67
|
+
actions.each { |a| assert_routing "/admin/#{a}", :controller => 'typus', :action => a }
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'test/helper'
|
|
2
|
+
|
|
3
|
+
class StringTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def test_should_return_post_actions_for_index
|
|
6
|
+
assert_equal %w( cleanup ), 'Post'.typus_actions_for('index')
|
|
7
|
+
assert_equal %w( cleanup ), 'Post'.typus_actions_for(:index)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_should_return_post_actions_for_edit
|
|
11
|
+
assert_equal %w( send_as_newsletter preview ), 'Post'.typus_actions_for('edit')
|
|
12
|
+
assert_equal %w( send_as_newsletter preview ), 'Post'.typus_actions_for(:edit)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_should_verify_typus_actions_for_unexisting_returns_is_empty
|
|
16
|
+
assert 'TypusUser'.typus_actions_for('unexisting').empty?
|
|
17
|
+
assert 'TypusUser'.typus_actions_for(:unexisting).empty?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_should_verify_typus_actions_for_index_returns_an_array
|
|
21
|
+
assert 'Post'.typus_actions_for('index').kind_of?(Array)
|
|
22
|
+
assert 'Post'.typus_actions_for(:index).kind_of?(Array)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'test/helper'
|
|
2
|
+
|
|
3
|
+
class TypusTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def test_should_return_version
|
|
6
|
+
assert Typus.respond_to?(:version)
|
|
7
|
+
assert Typus.version.kind_of?(String)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_should_return_path
|
|
11
|
+
expected = Dir.pwd + '/lib/../'
|
|
12
|
+
assert_equal expected, Typus.root
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_should_return_locales
|
|
16
|
+
initializer = "#{Rails.root}/config/initializers/typus.rb"
|
|
17
|
+
return if File.exist?(initializer)
|
|
18
|
+
assert Typus.respond_to?(:locales)
|
|
19
|
+
assert Typus.locales.kind_of?(Array)
|
|
20
|
+
assert_equal [["English", :en]], Typus.locales
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_should_return_default_locale
|
|
24
|
+
assert Typus.respond_to?(:default_locale)
|
|
25
|
+
assert Typus.default_locale.kind_of?(Symbol)
|
|
26
|
+
assert_equal :en, Typus.default_locale
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_should_return_applications_and_should_be_sorted
|
|
30
|
+
assert Typus.respond_to?(:applications)
|
|
31
|
+
assert Typus.applications.kind_of?(Array)
|
|
32
|
+
assert_equal %w( Blog Site Typus ), Typus.applications
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_should_return_modules_of_an_application
|
|
36
|
+
assert Typus.respond_to?(:application)
|
|
37
|
+
assert_equal %w( Comment Post ), Typus.application('Blog')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_should_return_models_and_should_be_sorted
|
|
41
|
+
assert Typus.respond_to?(:models)
|
|
42
|
+
assert Typus.models.kind_of?(Array)
|
|
43
|
+
assert_equal %w( Asset Category Comment CustomUser Page Post TypusUser ), Typus.models
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_should_return_an_array_of_models_on_header
|
|
47
|
+
assert Typus.models_on_header.kind_of?(Array)
|
|
48
|
+
assert_equal ["Page"], Typus.models_on_header
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_should_verify_resources_class_method
|
|
52
|
+
assert Typus.respond_to?(:resources)
|
|
53
|
+
models = Typus.models
|
|
54
|
+
assert_equal %w( Git Order Status WatchDog ), Typus.resources(models)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_should_verify_enable_exists
|
|
58
|
+
assert Typus.respond_to?(:enable)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_should_verify_enable_exists
|
|
62
|
+
assert Typus.respond_to?(:generator)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_should_return_user_class
|
|
66
|
+
assert_equal TypusUser, Typus.user_class
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_should_return_overwritted_user_class
|
|
70
|
+
options = { :user_class_name => 'CustomUser' }
|
|
71
|
+
Typus::Configuration.stubs(:options).returns(options)
|
|
72
|
+
assert_equal CustomUser, Typus.user_class
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_should_return_user_fk
|
|
76
|
+
assert_equal 'typus_user_id', Typus.user_fk
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_should_return_overwritted_user_fk
|
|
80
|
+
options = { :user_fk => 'my_user_fk' }
|
|
81
|
+
Typus::Configuration.stubs(:options).returns(options)
|
|
82
|
+
assert_equal 'my_user_fk', Typus.user_fk
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
data/test/models.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
class Asset < ActiveRecord::Base
|
|
2
|
+
|
|
3
|
+
belongs_to :resource, :polymorphic => true
|
|
4
|
+
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class Category < ActiveRecord::Base
|
|
8
|
+
|
|
9
|
+
acts_as_list if defined?(ActiveRecord::Acts::List)
|
|
10
|
+
|
|
11
|
+
validates_presence_of :name
|
|
12
|
+
has_and_belongs_to_many :posts
|
|
13
|
+
|
|
14
|
+
def self.typus
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class Comment < ActiveRecord::Base
|
|
20
|
+
|
|
21
|
+
validates_presence_of :name, :email, :body
|
|
22
|
+
belongs_to :post
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class CustomUser < ActiveRecord::Base
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class Page < ActiveRecord::Base
|
|
30
|
+
|
|
31
|
+
acts_as_tree if defined?(ActiveRecord::Acts::Tree)
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class Post < ActiveRecord::Base
|
|
36
|
+
|
|
37
|
+
validates_presence_of :title, :body
|
|
38
|
+
has_and_belongs_to_many :categories
|
|
39
|
+
has_many :comments
|
|
40
|
+
has_many :assets, :as => :resource, :dependent => :destroy
|
|
41
|
+
belongs_to :favorite_comment, :class_name => 'Comment'
|
|
42
|
+
|
|
43
|
+
def self.status
|
|
44
|
+
%w( true false pending published unpublished )
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.typus
|
|
48
|
+
'plugin'
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
data/test/schema.rb
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
ActiveRecord::Migration.verbose = false
|
|
2
|
+
|
|
3
|
+
ActiveRecord::Schema.define do
|
|
4
|
+
|
|
5
|
+
create_table :assets, :force => true do |t|
|
|
6
|
+
t.string :caption
|
|
7
|
+
t.string :resource_type
|
|
8
|
+
t.integer :resource_id
|
|
9
|
+
t.integer :position
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
create_table :categories, :force => true do |t|
|
|
13
|
+
t.string :name
|
|
14
|
+
t.string :permalink
|
|
15
|
+
t.text :description
|
|
16
|
+
t.integer :position
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
create_table :comments, :force => true do |t|
|
|
20
|
+
t.string :email, :name
|
|
21
|
+
t.text :body
|
|
22
|
+
t.integer :post_id
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
add_index :comments, :post_id
|
|
26
|
+
|
|
27
|
+
create_table :pages, :force => true do |t|
|
|
28
|
+
t.string :title
|
|
29
|
+
t.text :body
|
|
30
|
+
t.boolean :is_published
|
|
31
|
+
t.integer :parent_id
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
create_table :posts, :force => true do |t|
|
|
35
|
+
t.string :title
|
|
36
|
+
t.text :body
|
|
37
|
+
t.boolean :status
|
|
38
|
+
t.integer :favorite_comment_id
|
|
39
|
+
t.timestamps
|
|
40
|
+
t.datetime :published_at
|
|
41
|
+
t.integer :typus_user_id
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
create_table :typus_users, :force => true do |t|
|
|
45
|
+
t.string :first_name, :default => "", :null => false
|
|
46
|
+
t.string :last_name, :default => "", :null => false
|
|
47
|
+
t.string :role, :null => false
|
|
48
|
+
t.string :email, :null => false
|
|
49
|
+
t.boolean :status, :default => false
|
|
50
|
+
t.string :token, :null => false
|
|
51
|
+
t.string :salt, :null => false
|
|
52
|
+
t.string :crypted_password, :null => false
|
|
53
|
+
t.timestamps
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
create_table :categories_posts, :force => true, :id => false do |t|
|
|
57
|
+
t.column :category_id, :integer
|
|
58
|
+
t.column :post_id, :integer
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
add_index :categories_posts, :category_id
|
|
62
|
+
add_index :categories_posts, :post_id
|
|
63
|
+
|
|
64
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'test/helper'
|
|
2
|
+
|
|
3
|
+
class TypusMailerTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@user = typus_users(:admin)
|
|
7
|
+
ActionMailer::Base.default_url_options[:host] = 'test.host'
|
|
8
|
+
@response = TypusMailer.deliver_reset_password_link(@user)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_should_verify_email_from_is_defined_by_typus_options
|
|
12
|
+
assert_equal [ Typus::Configuration.options[:email] ], @response.from
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_should_verify_email_to_is_typus_user_email
|
|
16
|
+
assert_equal [ @user.email ], @response.to
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_should_verify_email_subject
|
|
20
|
+
expected = "[#{Typus::Configuration.options[:app_name]}] Reset password"
|
|
21
|
+
assert_equal expected, @response.subject
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_should_verify_email_contains_reset_password_link_with_token
|
|
25
|
+
expected = "http://test.host/admin/reset_password?token=1A2B3C4D5E6F"
|
|
26
|
+
assert_match expected, @response.body
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_should_check_email_contains_signature
|
|
30
|
+
assert_match /--\n#{Typus::Configuration.options[:app_name]}/, @response.body
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'test/helper'
|
|
2
|
+
|
|
3
|
+
class TypusTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def test_should_verify_models
|
|
6
|
+
models = [ Category, Comment, Post, TypusUser ]
|
|
7
|
+
models.each { |m| assert m.superclass.equal?(ActiveRecord::Base) }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_should_verify_fixtures_are_loaded
|
|
11
|
+
assert_equal 3, Category.count
|
|
12
|
+
assert_equal 4, Comment.count
|
|
13
|
+
assert_equal 4, Post.count
|
|
14
|
+
assert_equal 5, TypusUser.count
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|