typus 0.9.17
Sign up to get free protection for your applications and to get access to all the features.
- 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,117 @@
|
|
1
|
+
require 'test/helper'
|
2
|
+
|
3
|
+
class TypusHelperTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
include TypusHelper
|
6
|
+
include ActionView::Helpers::UrlHelper
|
7
|
+
include ActionView::Helpers::TextHelper
|
8
|
+
include ActionController::UrlWriter
|
9
|
+
|
10
|
+
def test_applications
|
11
|
+
assert true
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_resources
|
15
|
+
assert true
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_typus_block_when_partial_does_not_exist
|
19
|
+
output = typus_block(:resource => 'posts', :location => 'sidebar', :partial => 'pum')
|
20
|
+
assert output.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_page_title
|
24
|
+
params = {}
|
25
|
+
options = { :app_name => 'whatistypus.com' }
|
26
|
+
Typus::Configuration.stubs(:options).returns(options)
|
27
|
+
output = page_title('custom_action')
|
28
|
+
assert_equal 'whatistypus.com - Custom action', output
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_header_with_root_path
|
32
|
+
|
33
|
+
# Add root named route
|
34
|
+
ActionController::Routing::Routes.add_named_route :root, "/", { :controller => "posts" }
|
35
|
+
|
36
|
+
# ActionView::Helpers::UrlHelper does not support strings, which are returned by named routes
|
37
|
+
# link root_path
|
38
|
+
self.stubs(:link_to).returns(%(<a href="/">View site</a>))
|
39
|
+
self.stubs(:link_to_unless_current).returns(%(<a href="/admin/dashboard">Dashboard</a>))
|
40
|
+
|
41
|
+
output = header
|
42
|
+
expected = <<-HTML
|
43
|
+
<h1>#{Typus::Configuration.options[:app_name]}</h1>
|
44
|
+
<ul>
|
45
|
+
<li><a href="/admin/dashboard">Dashboard</a></li>
|
46
|
+
<li><a href="/admin/dashboard">Dashboard</a></li>
|
47
|
+
<li><a href="/">View site</a></li>
|
48
|
+
</ul>
|
49
|
+
HTML
|
50
|
+
|
51
|
+
assert_equal expected, output
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_header_without_root_path
|
56
|
+
|
57
|
+
# Remove root route from list
|
58
|
+
ActionController::Routing::Routes.named_routes.routes.reject! {|key, route| key == :root }
|
59
|
+
|
60
|
+
self.stubs(:link_to_unless_current).returns(%(<a href="/admin/dashboard">Dashboard</a>))
|
61
|
+
|
62
|
+
output = header
|
63
|
+
expected = <<-HTML
|
64
|
+
<h1>#{Typus::Configuration.options[:app_name]}</h1>
|
65
|
+
<ul>
|
66
|
+
<li><a href="/admin/dashboard">Dashboard</a></li>
|
67
|
+
<li><a href="/admin/dashboard">Dashboard</a></li>
|
68
|
+
</ul>
|
69
|
+
HTML
|
70
|
+
|
71
|
+
assert_equal expected, output
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_display_flash_message
|
76
|
+
|
77
|
+
message = { :test => 'This is the message.' }
|
78
|
+
|
79
|
+
output = display_flash_message(message)
|
80
|
+
expected = <<-HTML
|
81
|
+
<div id="flash" class="test">
|
82
|
+
<p>This is the message.</p>
|
83
|
+
</div>
|
84
|
+
HTML
|
85
|
+
|
86
|
+
assert_equal expected, output
|
87
|
+
|
88
|
+
message = {}
|
89
|
+
output = display_flash_message(message)
|
90
|
+
assert output.nil?
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_typus_message
|
95
|
+
output = typus_message('chunky bacon', 'yay')
|
96
|
+
expected = <<-HTML
|
97
|
+
<div id="flash" class="yay">
|
98
|
+
<p>chunky bacon</p>
|
99
|
+
</div>
|
100
|
+
HTML
|
101
|
+
assert_equal expected, output
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_locales
|
105
|
+
|
106
|
+
options = { :locales => [ [ "English", :en ], [ "Español", :es ] ] }
|
107
|
+
Typus::Configuration.stubs(:options).returns(options)
|
108
|
+
|
109
|
+
output = locales('set_locale')
|
110
|
+
expected = <<-HTML
|
111
|
+
<p>Set language to <a href=\"set_locale?locale=en\">english</a>, <a href=\"set_locale?locale=es\">español</a>.</p>
|
112
|
+
HTML
|
113
|
+
assert_equal expected, output
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
@@ -0,0 +1,382 @@
|
|
1
|
+
require 'test/helper'
|
2
|
+
|
3
|
+
class ActiveRecordTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def test_should_verify_model_fields_is_an_instance_of_active_support_ordered_hash
|
6
|
+
assert TypusUser.model_fields.instance_of?(ActiveSupport::OrderedHash)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_return_model_fields_for_typus_user
|
10
|
+
expected_fields = [[:id, :integer],
|
11
|
+
[:first_name, :string],
|
12
|
+
[:last_name, :string],
|
13
|
+
[:role, :string],
|
14
|
+
[:email, :string],
|
15
|
+
[:status, :boolean],
|
16
|
+
[:token, :string],
|
17
|
+
[:salt, :string],
|
18
|
+
[:crypted_password, :string],
|
19
|
+
[:created_at, :datetime],
|
20
|
+
[:updated_at, :datetime]]
|
21
|
+
assert_equal expected_fields.map { |i| i.first }, TypusUser.model_fields.keys
|
22
|
+
assert_equal expected_fields.map { |i| i.last }, TypusUser.model_fields.values
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_return_model_fields_for_post
|
26
|
+
expected_fields = [[:id, :integer],
|
27
|
+
[:title, :string],
|
28
|
+
[:body, :text],
|
29
|
+
[:status, :boolean],
|
30
|
+
[:favorite_comment_id, :integer],
|
31
|
+
[:created_at, :datetime],
|
32
|
+
[:updated_at, :datetime],
|
33
|
+
[:published_at, :datetime],
|
34
|
+
[:typus_user_id, :integer]]
|
35
|
+
assert_equal expected_fields.map { |i| i.first }, Post.model_fields.keys
|
36
|
+
assert_equal expected_fields.map { |i| i.last }, Post.model_fields.values
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_verify_model_relationships_is_an_instance_of_active_support_ordered_hash
|
40
|
+
assert TypusUser.model_relationships.instance_of?(ActiveSupport::OrderedHash)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_return_model_relationships_for_post
|
44
|
+
expected = [[:comments, :has_many],
|
45
|
+
[:categories, :has_and_belongs_to_many],
|
46
|
+
[:user, nil],
|
47
|
+
[:assets, :has_many]]
|
48
|
+
expected.each do |i|
|
49
|
+
assert_equal i.last, Post.model_relationships[i.first]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_should_return_description_of_a_model
|
54
|
+
assert TypusUser.respond_to?(:typus_description)
|
55
|
+
assert_equal "System Users Administration", TypusUser.typus_description
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_should_return_typus_fields_for_list_for_typus_user
|
59
|
+
expected_fields = [['email', :string],
|
60
|
+
['role', :selector],
|
61
|
+
['status', :boolean]]
|
62
|
+
assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for('list').keys
|
63
|
+
assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for('list').values
|
64
|
+
assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for(:list).keys
|
65
|
+
assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for(:list).values
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_should_return_typus_fields_for_list_for_post
|
69
|
+
expected_fields = [['title', :string],
|
70
|
+
['created_at', :datetime],
|
71
|
+
['status', :selector]]
|
72
|
+
assert_equal expected_fields.map { |i| i.first }, Post.typus_fields_for('list').keys
|
73
|
+
assert_equal expected_fields.map { |i| i.last }, Post.typus_fields_for('list').values
|
74
|
+
assert_equal expected_fields.map { |i| i.first }, Post.typus_fields_for(:list).keys
|
75
|
+
assert_equal expected_fields.map { |i| i.last }, Post.typus_fields_for(:list).values
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_should_return_typus_fields_for_form_for_typus_user
|
79
|
+
expected_fields = [['first_name', :string],
|
80
|
+
['last_name', :string],
|
81
|
+
['role', :selector],
|
82
|
+
['email', :string],
|
83
|
+
['password', :password],
|
84
|
+
['password_confirmation', :password]]
|
85
|
+
assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for('form').keys
|
86
|
+
assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for('form').values
|
87
|
+
assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for(:form).keys
|
88
|
+
assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for(:form).values
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_should_return_typus_fields_for_a_model_without_configuration
|
92
|
+
expected_fields = []
|
93
|
+
klass = Class.new(ActiveRecord::Base)
|
94
|
+
assert_equal expected_fields, klass.typus_fields_for(:form)
|
95
|
+
assert_equal expected_fields, klass.typus_fields_for(:list)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_should_return_typus_fields_for_relationship_for_typus_user
|
99
|
+
expected_fields = [['email', :string],
|
100
|
+
['role', :selector],
|
101
|
+
['status', :boolean]]
|
102
|
+
assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for('relationship').keys
|
103
|
+
assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for('relationship').values
|
104
|
+
assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for(:relationship).keys
|
105
|
+
assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for(:relationship).values
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_should_return_all_fields_for_undefined_field_type_on_typus_user
|
109
|
+
expected_fields = [['email', :string],
|
110
|
+
['role', :selector],
|
111
|
+
['status', :boolean]]
|
112
|
+
assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for('undefined').keys
|
113
|
+
assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for('undefined').values
|
114
|
+
assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for(:undefined).keys
|
115
|
+
assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for(:undefined).values
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_should_return_filters_for_typus_user
|
119
|
+
expected = [['status', :boolean],
|
120
|
+
['role', :string]]
|
121
|
+
assert_equal 'status, role', Typus::Configuration.config['TypusUser']['filters']
|
122
|
+
assert_equal expected.map { |i| i.first }, TypusUser.typus_filters.keys
|
123
|
+
assert_equal expected.map { |i| i.last }, TypusUser.typus_filters.values
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_should_return_post_typus_filters
|
127
|
+
expected = [['status', :boolean],
|
128
|
+
['created_at', :datetime],
|
129
|
+
['user', nil],
|
130
|
+
['user_id', nil]]
|
131
|
+
assert_equal expected.map { |i| i.first }.join(', '), Typus::Configuration.config['Post']['filters']
|
132
|
+
assert_equal expected.map { |i| i.first }, Post.typus_filters.keys
|
133
|
+
assert_equal expected.map { |i| i.last }, Post.typus_filters.values
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_should_return_actions_on_list_for_typus_user
|
137
|
+
assert TypusUser.typus_actions_for('list').empty?
|
138
|
+
assert TypusUser.typus_actions_for(:list).empty?
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_should_return_post_actions_on_index
|
142
|
+
assert_equal %w( cleanup ), Post.typus_actions_for('index')
|
143
|
+
assert_equal %w( cleanup ), Post.typus_actions_for(:index)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_should_return_post_actions_on_edit
|
147
|
+
assert_equal %w( send_as_newsletter preview ), Post.typus_actions_for('edit')
|
148
|
+
assert_equal %w( send_as_newsletter preview ), Post.typus_actions_for(:edit)
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_should_return_field_options_for_post
|
152
|
+
assert_equal [ :status ], Post.typus_field_options_for('selectors')
|
153
|
+
assert_equal [ :status ], Post.typus_field_options_for(:selectors)
|
154
|
+
assert_equal [ :permalink ], Post.typus_field_options_for('read_only')
|
155
|
+
assert_equal [ :permalink ], Post.typus_field_options_for(:read_only)
|
156
|
+
assert_equal [ :created_at ], Post.typus_field_options_for('auto_generated')
|
157
|
+
assert_equal [ :created_at ], Post.typus_field_options_for(:auto_generated)
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_should_return_options_for_post_and_page
|
161
|
+
|
162
|
+
assert_equal 10, Post.typus_options_for(:form_rows)
|
163
|
+
assert_equal 10, Post.typus_options_for('form_rows')
|
164
|
+
|
165
|
+
assert_equal 25, Page.typus_options_for(:form_rows)
|
166
|
+
assert_equal 25, Page.typus_options_for('form_rows')
|
167
|
+
|
168
|
+
assert_equal 10, Asset.typus_options_for(:form_rows)
|
169
|
+
assert_equal 10, Asset.typus_options_for('form_rows')
|
170
|
+
|
171
|
+
assert_equal 10, TypusUser.typus_options_for(:form_rows)
|
172
|
+
assert_equal 10, TypusUser.typus_options_for('form_rows')
|
173
|
+
|
174
|
+
assert Page.typus_options_for(:on_header)
|
175
|
+
assert !TypusUser.typus_options_for(:on_header)
|
176
|
+
|
177
|
+
assert_nil TypusUser.typus_options_for(:unexisting)
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_should_verify_typus_boolean_is_an_instance_of_active_support_ordered_hash
|
182
|
+
assert TypusUser.typus_boolean.instance_of?(ActiveSupport::OrderedHash)
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_should_return_booleans_for_typus_users
|
186
|
+
assert_equal [ :true, :false ], TypusUser.typus_boolean('status').keys
|
187
|
+
assert_equal [ "Active", "Inactive" ], TypusUser.typus_boolean('status').values
|
188
|
+
assert_equal [ :true, :false ], TypusUser.typus_boolean(:status).keys
|
189
|
+
assert_equal [ "Active", "Inactive" ], TypusUser.typus_boolean(:status).values
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_should_return_default_booleans_for_typus_users
|
193
|
+
assert_equal [ :true, :false ], TypusUser.typus_boolean.keys
|
194
|
+
assert_equal [ "True", "False" ], TypusUser.typus_boolean.values
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_should_return_booleans_for_post
|
198
|
+
assert_equal [ :true, :false ], Post.typus_boolean('status').keys
|
199
|
+
assert_equal [ "True", "False" ], Post.typus_boolean('status').values
|
200
|
+
assert_equal [ :true, :false ], Post.typus_boolean(:status).keys
|
201
|
+
assert_equal [ "True", "False" ], Post.typus_boolean(:status).values
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_should_return_date_formats_for_post
|
205
|
+
assert_equal :post_short, Post.typus_date_format('created_at')
|
206
|
+
assert_equal :post_short, Post.typus_date_format(:created_at)
|
207
|
+
assert_equal :db, Post.typus_date_format
|
208
|
+
assert_equal :db, Post.typus_date_format('unknown')
|
209
|
+
assert_equal :db, Post.typus_date_format(:unknown)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_should_return_defaults_for_post
|
213
|
+
assert_equal %w( title ), Post.typus_defaults_for('search')
|
214
|
+
assert_equal %w( title ), Post.typus_defaults_for(:search)
|
215
|
+
assert_equal %w( title -created_at ), Post.typus_defaults_for('order_by')
|
216
|
+
assert_equal %w( title -created_at ), Post.typus_defaults_for(:order_by)
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_should_return_relationships_for_post
|
220
|
+
assert_equal %w( assets categories ), Post.typus_defaults_for('relationships')
|
221
|
+
assert_equal %w( assets categories ), Post.typus_defaults_for(:relationships)
|
222
|
+
assert !Post.typus_defaults_for('relationships').empty?
|
223
|
+
assert !Post.typus_defaults_for(:relationships).empty?
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_should_return_order_by_for_model
|
227
|
+
assert_equal "posts.title ASC, posts.created_at DESC", Post.typus_order_by
|
228
|
+
assert_equal %w( title -created_at ), Post.typus_defaults_for('order_by')
|
229
|
+
assert_equal %w( title -created_at ), Post.typus_defaults_for(:order_by)
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_should_return_sql_conditions_on_search_for_typus_user
|
233
|
+
expected = "(LOWER(first_name) LIKE '%francesc%' OR LOWER(last_name) LIKE '%francesc%' OR LOWER(email) LIKE '%francesc%' OR LOWER(role) LIKE '%francesc%')"
|
234
|
+
params = { :search => 'francesc' }
|
235
|
+
assert_equal expected, TypusUser.build_conditions(params).first
|
236
|
+
params = { :search => 'Francesc' }
|
237
|
+
assert_equal expected, TypusUser.build_conditions(params).first
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_should_return_sql_conditions_on_search_and_filter_for_typus_user
|
241
|
+
|
242
|
+
case ENV['DB']
|
243
|
+
when /mysql/
|
244
|
+
boolean_true = "(`typus_users`.`status` = 1)"
|
245
|
+
boolean_false = "(`typus_users`.`status` = 0)"
|
246
|
+
else
|
247
|
+
boolean_true = "(\"typus_users\".\"status\" = 't')"
|
248
|
+
boolean_false = "(\"typus_users\".\"status\" = 'f')"
|
249
|
+
end
|
250
|
+
|
251
|
+
expected = "((LOWER(first_name) LIKE '%francesc%' OR LOWER(last_name) LIKE '%francesc%' OR LOWER(email) LIKE '%francesc%' OR LOWER(role) LIKE '%francesc%')) AND #{boolean_true}"
|
252
|
+
params = { :search => 'francesc', :status => 'true' }
|
253
|
+
assert_equal expected, TypusUser.build_conditions(params).first
|
254
|
+
params = { :search => 'francesc', :status => 'false' }
|
255
|
+
assert_match /#{boolean_false}/, TypusUser.build_conditions(params).first
|
256
|
+
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_should_return_sql_conditions_on_filtering_typus_users_by_status
|
260
|
+
|
261
|
+
case ENV['DB']
|
262
|
+
when /mysql/
|
263
|
+
boolean_true = "(`typus_users`.`status` = 1)"
|
264
|
+
boolean_false = "(`typus_users`.`status` = 0)"
|
265
|
+
else
|
266
|
+
boolean_true = "(\"typus_users\".\"status\" = 't')"
|
267
|
+
boolean_false = "(\"typus_users\".\"status\" = 'f')"
|
268
|
+
end
|
269
|
+
|
270
|
+
params = { :status => 'true' }
|
271
|
+
assert_equal boolean_true, TypusUser.build_conditions(params).first
|
272
|
+
params = { :status => 'false' }
|
273
|
+
assert_equal boolean_false, TypusUser.build_conditions(params).first
|
274
|
+
|
275
|
+
end
|
276
|
+
|
277
|
+
def test_should_return_sql_conditions_on_filtering_typus_users_by_created_at
|
278
|
+
|
279
|
+
expected = case ENV['DB']
|
280
|
+
when /postgresql/
|
281
|
+
"(created_at BETWEEN E'#{Time.new.midnight.to_s(:db)}' AND E'#{Time.new.midnight.tomorrow.to_s(:db)}')"
|
282
|
+
else
|
283
|
+
"(created_at BETWEEN '#{Time.new.midnight.to_s(:db)}' AND '#{Time.new.midnight.tomorrow.to_s(:db)}')"
|
284
|
+
end
|
285
|
+
params = { :created_at => 'today' }
|
286
|
+
assert_equal expected, TypusUser.build_conditions(params).first
|
287
|
+
|
288
|
+
|
289
|
+
expected = case ENV['DB']
|
290
|
+
when /postgresql/
|
291
|
+
"(created_at BETWEEN E'#{6.days.ago.midnight.to_s(:db)}' AND E'#{Time.new.midnight.tomorrow.to_s(:db)}')"
|
292
|
+
else
|
293
|
+
"(created_at BETWEEN '#{6.days.ago.midnight.to_s(:db)}' AND '#{Time.new.midnight.tomorrow.to_s(:db)}')"
|
294
|
+
end
|
295
|
+
params = { :created_at => 'past_7_days' }
|
296
|
+
assert_equal expected, TypusUser.build_conditions(params).first
|
297
|
+
|
298
|
+
|
299
|
+
expected = case ENV['DB']
|
300
|
+
when /postgresql/
|
301
|
+
"(created_at BETWEEN E'#{Time.new.midnight.last_month.to_s(:db)}' AND E'#{Time.new.midnight.tomorrow.to_s(:db)}')"
|
302
|
+
else
|
303
|
+
"(created_at BETWEEN '#{Time.new.midnight.last_month.to_s(:db)}' AND '#{Time.new.midnight.tomorrow.to_s(:db)}')"
|
304
|
+
end
|
305
|
+
params = { :created_at => 'this_month' }
|
306
|
+
assert_equal expected, TypusUser.build_conditions(params).first
|
307
|
+
|
308
|
+
expected = case ENV['DB']
|
309
|
+
when /postgresql/
|
310
|
+
"(created_at BETWEEN E'#{Time.new.midnight.last_year.to_s(:db)}' AND E'#{Time.new.midnight.tomorrow.to_s(:db)}')"
|
311
|
+
else
|
312
|
+
"(created_at BETWEEN '#{Time.new.midnight.last_year.to_s(:db)}' AND '#{Time.new.midnight.tomorrow.to_s(:db)}')"
|
313
|
+
end
|
314
|
+
params = { :created_at => 'this_year' }
|
315
|
+
assert_equal expected, TypusUser.build_conditions(params).first
|
316
|
+
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_should_return_sql_conditions_on_filtering_posts_by_published_at
|
320
|
+
expected = case ENV['DB']
|
321
|
+
when /postgresql/
|
322
|
+
"(published_at BETWEEN E'#{Time.new.midnight.to_s(:db)}' AND E'#{Time.new.midnight.tomorrow.to_s(:db)}')"
|
323
|
+
else
|
324
|
+
"(published_at BETWEEN '#{Time.new.midnight.to_s(:db)}' AND '#{Time.new.midnight.tomorrow.to_s(:db)}')"
|
325
|
+
end
|
326
|
+
params = { :published_at => 'today' }
|
327
|
+
assert_equal expected, Post.build_conditions(params).first
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_should_return_sql_conditions_on_filtering_posts_by_string
|
331
|
+
expected = case ENV['DB']
|
332
|
+
when /postgresql/
|
333
|
+
"(\"typus_users\".\"role\" = E'admin')"
|
334
|
+
when /mysql/
|
335
|
+
"(`typus_users`.`role` = 'admin')"
|
336
|
+
else
|
337
|
+
"(\"typus_users\".\"role\" = 'admin')"
|
338
|
+
end
|
339
|
+
params = { :role => 'admin' }
|
340
|
+
assert_equal expected, TypusUser.build_conditions(params).first
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_should_verify_previous_and_next
|
344
|
+
assert TypusUser.instance_methods.include?('previous_and_next')
|
345
|
+
assert typus_users(:admin).previous_and_next.kind_of?(Array)
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_should_verify_previous_and_next_works_without_conditions
|
349
|
+
expected = [ typus_users(:admin), typus_users(:disabled_user) ]
|
350
|
+
assert_equal expected, typus_users(:editor).previous_and_next
|
351
|
+
end
|
352
|
+
|
353
|
+
def test_should_verify_previous_and_next_works_with_conditions
|
354
|
+
expected = [ typus_users(:editor), typus_users(:removed_role) ]
|
355
|
+
conditions = { 'status' => 'true' }
|
356
|
+
assert_equal expected, typus_users(:designer).previous_and_next(conditions)
|
357
|
+
end
|
358
|
+
|
359
|
+
def test_should_verify_typus_name_is_working_properly
|
360
|
+
|
361
|
+
assert Category.new.respond_to?(:name)
|
362
|
+
assert_equal 'First Category', categories(:first).typus_name
|
363
|
+
|
364
|
+
assert !Page.new.respond_to?(:name)
|
365
|
+
assert_equal 'Page#1', pages(:published).typus_name
|
366
|
+
|
367
|
+
assert Comment.new.respond_to?(:name)
|
368
|
+
assert_equal "John", comments(:first).typus_name
|
369
|
+
|
370
|
+
end
|
371
|
+
|
372
|
+
def test_should_verify_typus_template_is_working_properly
|
373
|
+
|
374
|
+
assert_equal 'datepicker', Post.typus_template('published_at')
|
375
|
+
assert_equal 'datepicker', Post.typus_template(:published_at)
|
376
|
+
|
377
|
+
assert_nil Post.typus_template('created_at')
|
378
|
+
assert_nil Post.typus_template('unknown')
|
379
|
+
|
380
|
+
end
|
381
|
+
|
382
|
+
end
|