fesplugas-typus 0.9.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.
Files changed (154) hide show
  1. data/.gitignore +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +80 -0
  4. data/Rakefile +61 -0
  5. data/VERSION +1 -0
  6. data/app/controllers/admin/master_controller.rb +324 -0
  7. data/app/controllers/typus_controller.rb +127 -0
  8. data/app/helpers/admin/form_helper.rb +351 -0
  9. data/app/helpers/admin/master_helper.rb +99 -0
  10. data/app/helpers/admin/public_helper.rb +24 -0
  11. data/app/helpers/admin/sidebar_helper.rb +259 -0
  12. data/app/helpers/admin/table_helper.rb +227 -0
  13. data/app/helpers/typus_helper.rb +169 -0
  14. data/app/models/typus_mailer.rb +14 -0
  15. data/app/models/typus_user.rb +5 -0
  16. data/app/views/admin/dashboard/_sidebar.html.erb +9 -0
  17. data/app/views/admin/resources/edit.html.erb +29 -0
  18. data/app/views/admin/resources/index.html.erb +28 -0
  19. data/app/views/admin/resources/new.html.erb +27 -0
  20. data/app/views/admin/resources/show.html.erb +21 -0
  21. data/app/views/admin/shared/_footer.html.erb +1 -0
  22. data/app/views/admin/shared/_pagination.html.erb +28 -0
  23. data/app/views/layouts/admin.html.erb +72 -0
  24. data/app/views/layouts/typus.html.erb +29 -0
  25. data/app/views/typus/dashboard.html.erb +13 -0
  26. data/app/views/typus/recover_password.html.erb +7 -0
  27. data/app/views/typus/reset_password.html.erb +13 -0
  28. data/app/views/typus/sign_in.html.erb +9 -0
  29. data/app/views/typus/sign_up.html.erb +7 -0
  30. data/app/views/typus_mailer/reset_password_link.erb +11 -0
  31. data/config/locales/es.yml +106 -0
  32. data/config/locales/pt-BR.yml +108 -0
  33. data/config/locales/typus_hacks.yml +14 -0
  34. data/config/routes.rb +14 -0
  35. data/generators/typus/templates/config/initializers/typus.rb +27 -0
  36. data/generators/typus/templates/config/typus/application.yml +45 -0
  37. data/generators/typus/templates/config/typus/application_roles.yml +23 -0
  38. data/generators/typus/templates/config/typus/typus.yml +14 -0
  39. data/generators/typus/templates/config/typus/typus_roles.yml +2 -0
  40. data/generators/typus/templates/db/create_typus_users.rb +21 -0
  41. data/generators/typus/templates/public/images/admin/arrow_down.gif +0 -0
  42. data/generators/typus/templates/public/images/admin/arrow_up.gif +0 -0
  43. data/generators/typus/templates/public/images/admin/spinner.gif +0 -0
  44. data/generators/typus/templates/public/images/admin/status_false.gif +0 -0
  45. data/generators/typus/templates/public/images/admin/status_true.gif +0 -0
  46. data/generators/typus/templates/public/images/admin/trash.gif +0 -0
  47. data/generators/typus/templates/public/javascripts/admin/application.js +14 -0
  48. data/generators/typus/templates/public/stylesheets/admin/reset.css +68 -0
  49. data/generators/typus/templates/public/stylesheets/admin/screen.css +709 -0
  50. data/generators/typus/typus_generator.rb +141 -0
  51. data/generators/typus_update_schema_to_01/templates/config/typus.yml +14 -0
  52. data/generators/typus_update_schema_to_01/templates/migration.rb +11 -0
  53. data/generators/typus_update_schema_to_01/typus_update_schema_to_01_generator.rb +19 -0
  54. data/init.rb +19 -0
  55. data/lib/typus/active_record.rb +298 -0
  56. data/lib/typus/authentication.rb +155 -0
  57. data/lib/typus/configuration.rb +92 -0
  58. data/lib/typus/format.rb +56 -0
  59. data/lib/typus/generator.rb +173 -0
  60. data/lib/typus/hash.rb +10 -0
  61. data/lib/typus/locale.rb +17 -0
  62. data/lib/typus/object.rb +22 -0
  63. data/lib/typus/quick_edit.rb +33 -0
  64. data/lib/typus/reloader.rb +17 -0
  65. data/lib/typus/string.rb +11 -0
  66. data/lib/typus/user.rb +137 -0
  67. data/lib/typus.rb +133 -0
  68. data/lib/vendor/active_record.rb +15 -0
  69. data/lib/vendor/paginator.rb +143 -0
  70. data/tasks/typus_tasks.rake +26 -0
  71. data/test/config/broken/application.yml +68 -0
  72. data/test/config/broken/application_roles.yml +20 -0
  73. data/test/config/broken/empty.yml +0 -0
  74. data/test/config/broken/empty_roles.yml +0 -0
  75. data/test/config/broken/undefined.yml +3 -0
  76. data/test/config/broken/undefined_roles.yml +6 -0
  77. data/test/config/default/typus.yml +14 -0
  78. data/test/config/default/typus_roles.yml +2 -0
  79. data/test/config/empty/empty_01.yml +0 -0
  80. data/test/config/empty/empty_01_roles.yml +0 -0
  81. data/test/config/empty/empty_02.yml +0 -0
  82. data/test/config/empty/empty_02_roles.yml +0 -0
  83. data/test/config/locales/es.yml +10 -0
  84. data/test/config/ordered/001_roles.yml +2 -0
  85. data/test/config/ordered/002_roles.yml +2 -0
  86. data/test/config/unordered/app_one_roles.yml +2 -0
  87. data/test/config/unordered/app_two_roles.yml +2 -0
  88. data/test/config/working/application.yml +67 -0
  89. data/test/config/working/application_roles.yml +22 -0
  90. data/test/config/working/typus.yml +14 -0
  91. data/test/config/working/typus_roles.yml +2 -0
  92. data/test/fixtures/app/controllers/admin/assets_controller.rb +2 -0
  93. data/test/fixtures/app/controllers/admin/categories_controller.rb +2 -0
  94. data/test/fixtures/app/controllers/admin/comments_controller.rb +2 -0
  95. data/test/fixtures/app/controllers/admin/pages_controller.rb +2 -0
  96. data/test/fixtures/app/controllers/admin/posts_controller.rb +2 -0
  97. data/test/fixtures/app/controllers/admin/status_controller.rb +6 -0
  98. data/test/fixtures/app/controllers/admin/typus_users_controller.rb +2 -0
  99. data/test/fixtures/app/controllers/admin/watch_dog_controller.rb +6 -0
  100. data/test/fixtures/app/views/admin/comments/_edit_bottom.html.erb +1 -0
  101. data/test/fixtures/app/views/admin/comments/_edit_sidebar.html.erb +1 -0
  102. data/test/fixtures/app/views/admin/comments/_edit_top.html.erb +1 -0
  103. data/test/fixtures/app/views/admin/comments/_index_bottom.html.erb +1 -0
  104. data/test/fixtures/app/views/admin/comments/_index_sidebar.html.erb +1 -0
  105. data/test/fixtures/app/views/admin/comments/_index_top.html.erb +1 -0
  106. data/test/fixtures/app/views/admin/comments/_new_bottom.html.erb +1 -0
  107. data/test/fixtures/app/views/admin/comments/_new_sidebar.html.erb +1 -0
  108. data/test/fixtures/app/views/admin/comments/_new_top.html.erb +1 -0
  109. data/test/fixtures/app/views/admin/comments/_show_bottom.html.erb +1 -0
  110. data/test/fixtures/app/views/admin/comments/_show_sidebar.html.erb +1 -0
  111. data/test/fixtures/app/views/admin/comments/_show_top.html.erb +1 -0
  112. data/test/fixtures/app/views/admin/dashboard/_bottom.html.erb +1 -0
  113. data/test/fixtures/app/views/admin/dashboard/_sidebar.html.erb +1 -0
  114. data/test/fixtures/app/views/admin/dashboard/_top.html.erb +1 -0
  115. data/test/fixtures/app/views/admin/shared/_footer.html.erb +1 -0
  116. data/test/fixtures/app/views/admin/status/index.html.erb +1 -0
  117. data/test/fixtures/app/views/admin/templates/_datepicker.html.erb +1 -0
  118. data/test/fixtures/assets.yml +11 -0
  119. data/test/fixtures/categories.yml +14 -0
  120. data/test/fixtures/comments.yml +27 -0
  121. data/test/fixtures/pages.yml +41 -0
  122. data/test/fixtures/posts.yml +37 -0
  123. data/test/fixtures/typus_users.yml +54 -0
  124. data/test/functional/admin/assets_controller_test.rb +57 -0
  125. data/test/functional/admin/categories_controller_test.rb +106 -0
  126. data/test/functional/admin/comments_controller_test.rb +121 -0
  127. data/test/functional/admin/master_controller_test.rb +5 -0
  128. data/test/functional/admin/posts_controller_test.rb +278 -0
  129. data/test/functional/admin/status_controller_test.rb +43 -0
  130. data/test/functional/admin/typus_users_controller_test.rb +239 -0
  131. data/test/functional/typus_controller_test.rb +315 -0
  132. data/test/helper.rb +51 -0
  133. data/test/helpers/admin/form_helper_test.rb +316 -0
  134. data/test/helpers/admin/master_helper_test.rb +65 -0
  135. data/test/helpers/admin/public_helper_test.rb +22 -0
  136. data/test/helpers/admin/sidebar_helper_test.rb +351 -0
  137. data/test/helpers/admin/table_helper_test.rb +255 -0
  138. data/test/helpers/typus_helper_test.rb +106 -0
  139. data/test/lib/active_record_test.rb +372 -0
  140. data/test/lib/configuration_test.rb +91 -0
  141. data/test/lib/hash_test.rb +11 -0
  142. data/test/lib/routes_test.rb +82 -0
  143. data/test/lib/string_test.rb +25 -0
  144. data/test/lib/typus_test.rb +105 -0
  145. data/test/models.rb +51 -0
  146. data/test/schema.rb +64 -0
  147. data/test/unit/typus_mailer_test.rb +33 -0
  148. data/test/unit/typus_test.rb +17 -0
  149. data/test/unit/typus_user_roles_test.rb +90 -0
  150. data/test/unit/typus_user_test.rb +177 -0
  151. data/test/vendor/active_record_test.rb +18 -0
  152. data/test/vendor/paginator_test.rb +138 -0
  153. data/typus.gemspec +225 -0
  154. metadata +241 -0
@@ -0,0 +1,106 @@
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 &rsaquo; 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
+
40
+ output = header
41
+ expected = <<-HTML
42
+ <h1>#{Typus::Configuration.options[:app_name]} <small><a href="/">View site</a></small>
43
+ </h1>
44
+ HTML
45
+
46
+ assert_equal expected, output
47
+
48
+ end
49
+
50
+ def test_header_without_root_path
51
+
52
+ # Remove root route from list
53
+ ActionController::Routing::Routes.named_routes.routes.reject! {|key, route| key == :root }
54
+
55
+ output = header
56
+ expected = <<-HTML
57
+ <h1>#{Typus::Configuration.options[:app_name]} </h1>
58
+ HTML
59
+
60
+ assert_equal expected, output
61
+
62
+ end
63
+
64
+ def test_display_flash_message
65
+
66
+ message = { :test => 'This is the message.' }
67
+
68
+ output = display_flash_message(message)
69
+ expected = <<-HTML
70
+ <div id="flash" class="test">
71
+ <p>This is the message.</p>
72
+ </div>
73
+ HTML
74
+
75
+ assert_equal expected, output
76
+
77
+ message = {}
78
+ output = display_flash_message(message)
79
+ assert output.nil?
80
+
81
+ end
82
+
83
+ def test_typus_message
84
+ output = typus_message('chunky bacon', 'yay')
85
+ expected = <<-HTML
86
+ <div id="flash" class="yay">
87
+ <p>chunky bacon</p>
88
+ </div>
89
+ HTML
90
+ assert_equal expected, output
91
+ end
92
+
93
+ def test_locales
94
+
95
+ options = { :locales => [ [ "English", :en ], [ "Español", :es ] ] }
96
+ Typus::Configuration.stubs(:options).returns(options)
97
+
98
+ output = locales('set_locale')
99
+ expected = <<-HTML
100
+ <p>Set language to <a href=\"set_locale?locale=en\">english</a>, <a href=\"set_locale?locale=es\">español</a>.</p>
101
+ HTML
102
+ assert_equal expected, output
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,372 @@
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_typus_fields_for_list_for_typus_user
54
+ expected_fields = [['email', :string],
55
+ ['role', :selector],
56
+ ['status', :boolean]]
57
+ assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for('list').keys
58
+ assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for('list').values
59
+ assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for(:list).keys
60
+ assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for(:list).values
61
+ end
62
+
63
+ def test_should_return_typus_fields_for_list_for_post
64
+ expected_fields = [['title', :string],
65
+ ['created_at', :datetime],
66
+ ['status', :selector]]
67
+ assert_equal expected_fields.map { |i| i.first }, Post.typus_fields_for('list').keys
68
+ assert_equal expected_fields.map { |i| i.last }, Post.typus_fields_for('list').values
69
+ assert_equal expected_fields.map { |i| i.first }, Post.typus_fields_for(:list).keys
70
+ assert_equal expected_fields.map { |i| i.last }, Post.typus_fields_for(:list).values
71
+ end
72
+
73
+ def test_should_return_typus_fields_for_form_for_typus_user
74
+ expected_fields = [['first_name', :string],
75
+ ['last_name', :string],
76
+ ['role', :selector],
77
+ ['email', :string],
78
+ ['password', :password],
79
+ ['password_confirmation', :password]]
80
+ assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for('form').keys
81
+ assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for('form').values
82
+ assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for(:form).keys
83
+ assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for(:form).values
84
+ end
85
+
86
+ def test_should_return_typus_fields_for_a_model_without_configuration
87
+ expected_fields = []
88
+ klass = Class.new(ActiveRecord::Base)
89
+ assert_equal expected_fields, klass.typus_fields_for(:form)
90
+ assert_equal expected_fields, klass.typus_fields_for(:list)
91
+ end
92
+
93
+ def test_should_return_typus_fields_for_relationship_for_typus_user
94
+ expected_fields = [['email', :string],
95
+ ['role', :selector],
96
+ ['status', :boolean]]
97
+ assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for('relationship').keys
98
+ assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for('relationship').values
99
+ assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for(:relationship).keys
100
+ assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for(:relationship).values
101
+ end
102
+
103
+ def test_should_return_all_fields_for_undefined_field_type_on_typus_user
104
+ expected_fields = [['email', :string],
105
+ ['role', :selector],
106
+ ['status', :boolean]]
107
+ assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for('undefined').keys
108
+ assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for('undefined').values
109
+ assert_equal expected_fields.map { |i| i.first }, TypusUser.typus_fields_for(:undefined).keys
110
+ assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for(:undefined).values
111
+ end
112
+
113
+ def test_should_return_filters_for_typus_user
114
+ expected = [['status', :boolean],
115
+ ['role', :string]]
116
+ assert_equal 'status, role', Typus::Configuration.config['TypusUser']['filters']
117
+ assert_equal expected.map { |i| i.first }, TypusUser.typus_filters.keys
118
+ assert_equal expected.map { |i| i.last }, TypusUser.typus_filters.values
119
+ end
120
+
121
+ def test_should_return_post_typus_filters
122
+ expected = [['status', :boolean],
123
+ ['created_at', :datetime],
124
+ ['user', nil],
125
+ ['user_id', nil]]
126
+ assert_equal expected.map { |i| i.first }.join(', '), Typus::Configuration.config['Post']['filters']
127
+ assert_equal expected.map { |i| i.first }, Post.typus_filters.keys
128
+ assert_equal expected.map { |i| i.last }, Post.typus_filters.values
129
+ end
130
+
131
+ def test_should_return_actions_on_list_for_typus_user
132
+ assert TypusUser.typus_actions_for('list').empty?
133
+ assert TypusUser.typus_actions_for(:list).empty?
134
+ end
135
+
136
+ def test_should_return_post_actions_on_index
137
+ assert_equal %w( cleanup ), Post.typus_actions_for('index')
138
+ assert_equal %w( cleanup ), Post.typus_actions_for(:index)
139
+ end
140
+
141
+ def test_should_return_post_actions_on_edit
142
+ assert_equal %w( send_as_newsletter preview ), Post.typus_actions_for('edit')
143
+ assert_equal %w( send_as_newsletter preview ), Post.typus_actions_for(:edit)
144
+ end
145
+
146
+ def test_should_return_field_options_for_post
147
+ assert_equal [ :status ], Post.typus_field_options_for('selectors')
148
+ assert_equal [ :status ], Post.typus_field_options_for(:selectors)
149
+ assert_equal [ :permalink ], Post.typus_field_options_for('read_only')
150
+ assert_equal [ :permalink ], Post.typus_field_options_for(:read_only)
151
+ assert_equal [ :created_at ], Post.typus_field_options_for('auto_generated')
152
+ assert_equal [ :created_at ], Post.typus_field_options_for(:auto_generated)
153
+ end
154
+
155
+ def test_should_return_options_for_post_and_page
156
+
157
+ assert_equal 10, Post.typus_options_for(:form_rows)
158
+ assert_equal 10, Post.typus_options_for('form_rows')
159
+
160
+ assert_equal 25, Page.typus_options_for(:form_rows)
161
+ assert_equal 25, Page.typus_options_for('form_rows')
162
+
163
+ assert_equal 10, Asset.typus_options_for(:form_rows)
164
+ assert_equal 10, Asset.typus_options_for('form_rows')
165
+
166
+ assert_equal 10, TypusUser.typus_options_for(:form_rows)
167
+ assert_equal 10, TypusUser.typus_options_for('form_rows')
168
+
169
+ end
170
+
171
+ def test_should_verify_typus_boolean_is_an_instance_of_active_support_ordered_hash
172
+ assert TypusUser.typus_boolean.instance_of?(ActiveSupport::OrderedHash)
173
+ end
174
+
175
+ def test_should_return_booleans_for_typus_users
176
+ assert_equal [ :true, :false ], TypusUser.typus_boolean('status').keys
177
+ assert_equal [ "Active", "Inactive" ], TypusUser.typus_boolean('status').values
178
+ assert_equal [ :true, :false ], TypusUser.typus_boolean(:status).keys
179
+ assert_equal [ "Active", "Inactive" ], TypusUser.typus_boolean(:status).values
180
+ end
181
+
182
+ def test_should_return_default_booleans_for_typus_users
183
+ assert_equal [ :true, :false ], TypusUser.typus_boolean.keys
184
+ assert_equal [ "True", "False" ], TypusUser.typus_boolean.values
185
+ end
186
+
187
+ def test_should_return_booleans_for_post
188
+ assert_equal [ :true, :false ], Post.typus_boolean('status').keys
189
+ assert_equal [ "True", "False" ], Post.typus_boolean('status').values
190
+ assert_equal [ :true, :false ], Post.typus_boolean(:status).keys
191
+ assert_equal [ "True", "False" ], Post.typus_boolean(:status).values
192
+ end
193
+
194
+ def test_should_return_date_formats_for_post
195
+ assert_equal :post_short, Post.typus_date_format('created_at')
196
+ assert_equal :post_short, Post.typus_date_format(:created_at)
197
+ assert_equal :db, Post.typus_date_format
198
+ assert_equal :db, Post.typus_date_format('unknown')
199
+ assert_equal :db, Post.typus_date_format(:unknown)
200
+ end
201
+
202
+ def test_should_return_defaults_for_post
203
+ assert_equal %w( title ), Post.typus_defaults_for('search')
204
+ assert_equal %w( title ), Post.typus_defaults_for(:search)
205
+ assert_equal %w( title -created_at ), Post.typus_defaults_for('order_by')
206
+ assert_equal %w( title -created_at ), Post.typus_defaults_for(:order_by)
207
+ end
208
+
209
+ def test_should_return_relationships_for_post
210
+ assert_equal %w( assets categories ), Post.typus_defaults_for('relationships')
211
+ assert_equal %w( assets categories ), Post.typus_defaults_for(:relationships)
212
+ assert !Post.typus_defaults_for('relationships').empty?
213
+ assert !Post.typus_defaults_for(:relationships).empty?
214
+ end
215
+
216
+ def test_should_return_order_by_for_model
217
+ assert_equal "posts.title ASC, posts.created_at DESC", Post.typus_order_by
218
+ assert_equal %w( title -created_at ), Post.typus_defaults_for('order_by')
219
+ assert_equal %w( title -created_at ), Post.typus_defaults_for(:order_by)
220
+ end
221
+
222
+ def test_should_return_sql_conditions_on_search_for_typus_user
223
+ expected = "(LOWER(first_name) LIKE '%francesc%' OR LOWER(last_name) LIKE '%francesc%' OR LOWER(email) LIKE '%francesc%' OR LOWER(role) LIKE '%francesc%')"
224
+ params = { :search => 'francesc' }
225
+ assert_equal expected, TypusUser.build_conditions(params).first
226
+ params = { :search => 'Francesc' }
227
+ assert_equal expected, TypusUser.build_conditions(params).first
228
+ end
229
+
230
+ def test_should_return_sql_conditions_on_search_and_filter_for_typus_user
231
+
232
+ case ENV['DB']
233
+ when /mysql/
234
+ boolean_true = "(`typus_users`.`status` = 1)"
235
+ boolean_false = "(`typus_users`.`status` = 0)"
236
+ else
237
+ boolean_true = "(\"typus_users\".\"status\" = 't')"
238
+ boolean_false = "(\"typus_users\".\"status\" = 'f')"
239
+ end
240
+
241
+ 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}"
242
+ params = { :search => 'francesc', :status => 'true' }
243
+ assert_equal expected, TypusUser.build_conditions(params).first
244
+ params = { :search => 'francesc', :status => 'false' }
245
+ assert_match /#{boolean_false}/, TypusUser.build_conditions(params).first
246
+
247
+ end
248
+
249
+ def test_should_return_sql_conditions_on_filtering_typus_users_by_status
250
+
251
+ case ENV['DB']
252
+ when /mysql/
253
+ boolean_true = "(`typus_users`.`status` = 1)"
254
+ boolean_false = "(`typus_users`.`status` = 0)"
255
+ else
256
+ boolean_true = "(\"typus_users\".\"status\" = 't')"
257
+ boolean_false = "(\"typus_users\".\"status\" = 'f')"
258
+ end
259
+
260
+ params = { :status => 'true' }
261
+ assert_equal boolean_true, TypusUser.build_conditions(params).first
262
+ params = { :status => 'false' }
263
+ assert_equal boolean_false, TypusUser.build_conditions(params).first
264
+
265
+ end
266
+
267
+ def test_should_return_sql_conditions_on_filtering_typus_users_by_created_at
268
+
269
+ expected = case ENV['DB']
270
+ when /postgresql/
271
+ "(created_at BETWEEN E'#{Time.today.to_s(:db)}' AND E'#{Time.today.tomorrow.to_s(:db)}')"
272
+ else
273
+ "(created_at BETWEEN '#{Time.today.to_s(:db)}' AND '#{Time.today.tomorrow.to_s(:db)}')"
274
+ end
275
+ params = { :created_at => 'today' }
276
+ assert_equal expected, TypusUser.build_conditions(params).first
277
+
278
+
279
+ expected = case ENV['DB']
280
+ when /postgresql/
281
+ "(created_at BETWEEN E'#{6.days.ago.midnight.to_s(:db)}' AND E'#{Time.today.tomorrow.to_s(:db)}')"
282
+ else
283
+ "(created_at BETWEEN '#{6.days.ago.midnight.to_s(:db)}' AND '#{Time.today.tomorrow.to_s(:db)}')"
284
+ end
285
+ params = { :created_at => 'past_7_days' }
286
+ assert_equal expected, TypusUser.build_conditions(params).first
287
+
288
+
289
+ expected = case ENV['DB']
290
+ when /postgresql/
291
+ "(created_at BETWEEN E'#{Time.today.last_month.to_s(:db)}' AND E'#{Time.today.tomorrow.to_s(:db)}')"
292
+ else
293
+ "(created_at BETWEEN '#{Time.today.last_month.to_s(:db)}' AND '#{Time.today.tomorrow.to_s(:db)}')"
294
+ end
295
+ params = { :created_at => 'this_month' }
296
+ assert_equal expected, TypusUser.build_conditions(params).first
297
+
298
+ expected = case ENV['DB']
299
+ when /postgresql/
300
+ "(created_at BETWEEN E'#{Time.today.last_year.to_s(:db)}' AND E'#{Time.today.tomorrow.to_s(:db)}')"
301
+ else
302
+ "(created_at BETWEEN '#{Time.today.last_year.to_s(:db)}' AND '#{Time.today.tomorrow.to_s(:db)}')"
303
+ end
304
+ params = { :created_at => 'this_year' }
305
+ assert_equal expected, TypusUser.build_conditions(params).first
306
+
307
+ end
308
+
309
+ def test_should_return_sql_conditions_on_filtering_posts_by_published_at
310
+ expected = case ENV['DB']
311
+ when /postgresql/
312
+ "(published_at BETWEEN E'#{Time.today.to_s(:db)}' AND E'#{Time.today.tomorrow.to_s(:db)}')"
313
+ else
314
+ "(published_at BETWEEN '#{Time.today.to_s(:db)}' AND '#{Time.today.tomorrow.to_s(:db)}')"
315
+ end
316
+ params = { :published_at => 'today' }
317
+ assert_equal expected, Post.build_conditions(params).first
318
+ end
319
+
320
+ def test_should_return_sql_conditions_on_filtering_posts_by_string
321
+ expected = case ENV['DB']
322
+ when /postgresql/
323
+ "(\"typus_users\".\"role\" = E'admin')"
324
+ when /mysql/
325
+ "(`typus_users`.`role` = 'admin')"
326
+ else
327
+ "(\"typus_users\".\"role\" = 'admin')"
328
+ end
329
+ params = { :role => 'admin' }
330
+ assert_equal expected, TypusUser.build_conditions(params).first
331
+ end
332
+
333
+ def test_should_verify_previous_and_next
334
+ assert TypusUser.instance_methods.include?('previous_and_next')
335
+ assert typus_users(:admin).previous_and_next.kind_of?(Array)
336
+ end
337
+
338
+ def test_should_verify_previous_and_next_works_without_conditions
339
+ expected = [ typus_users(:admin), typus_users(:disabled_user) ]
340
+ assert_equal expected, typus_users(:editor).previous_and_next
341
+ end
342
+
343
+ def test_should_verify_previous_and_next_works_with_conditions
344
+ expected = [ typus_users(:editor), typus_users(:removed_role) ]
345
+ conditions = { 'status' => 'true' }
346
+ assert_equal expected, typus_users(:designer).previous_and_next(conditions)
347
+ end
348
+
349
+ def test_should_verify_typus_name_is_working_properly
350
+
351
+ assert Category.new.respond_to?(:name)
352
+ assert_equal 'First Category', categories(:first).typus_name
353
+
354
+ assert !Page.new.respond_to?(:name)
355
+ assert_equal 'Page#1', pages(:published).typus_name
356
+
357
+ assert Comment.new.respond_to?(:name)
358
+ assert_equal "John", comments(:first).typus_name
359
+
360
+ end
361
+
362
+ def test_should_verify_typus_template_is_working_properly
363
+
364
+ assert_equal 'datepicker', Post.typus_template('published_at')
365
+ assert_equal 'datepicker', Post.typus_template(:published_at)
366
+
367
+ assert_equal nil, Post.typus_template('created_at')
368
+ assert_equal nil, Post.typus_template('unknown')
369
+
370
+ end
371
+
372
+ end
@@ -0,0 +1,91 @@
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.exists?(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.exists?(initializer)
27
+ assert_equal nil, Typus::Configuration.options[:end_year]
28
+ assert_equal 10, Typus::Configuration.options[:form_rows]
29
+ assert_equal true, Typus::Configuration.options[:icon_on_boolean]
30
+ assert_equal false, Typus::Configuration.options[:index_after_save]
31
+ assert_equal 5, Typus::Configuration.options[:minute_step]
32
+ assert_equal 'nil', Typus::Configuration.options[:nil]
33
+ assert_equal 15, Typus::Configuration.options[:per_page]
34
+ assert_equal 5, Typus::Configuration.options[:sidebar_selector]
35
+ assert_equal nil, Typus::Configuration.options[:start_year]
36
+ assert_equal true, Typus::Configuration.options[:toggle]
37
+ end
38
+
39
+ def test_should_verify_typus_roles_is_loaded
40
+ assert Typus::Configuration.respond_to?(:roles!)
41
+ assert Typus::Configuration.roles!.kind_of?(Hash)
42
+ end
43
+
44
+ def test_should_verify_typus_config_file_is_loaded
45
+ assert Typus::Configuration.respond_to?(:config!)
46
+ assert Typus::Configuration.config!.kind_of?(Hash)
47
+ end
48
+
49
+ def test_should_load_configuration_files_from_config_broken
50
+ options = { :config_folder => 'vendor/plugins/typus/test/config/broken' }
51
+ Typus::Configuration.stubs(:options).returns(options)
52
+ assert_not_equal Hash.new, Typus::Configuration.roles!
53
+ assert_not_equal Hash.new, Typus::Configuration.config!
54
+ end
55
+
56
+ def test_should_load_configuration_files_from_config_empty
57
+ options = { :config_folder => 'vendor/plugins/typus/test/config/empty' }
58
+ Typus::Configuration.stubs(:options).returns(options)
59
+ assert_equal Hash.new, Typus::Configuration.roles!
60
+ assert_equal Hash.new, Typus::Configuration.config!
61
+ end
62
+
63
+ def test_should_load_configuration_files_from_config_ordered
64
+ options = { :config_folder => 'vendor/plugins/typus/test/config/ordered' }
65
+ Typus::Configuration.stubs(:options).returns(options)
66
+ files = Dir["#{Rails.root}/#{Typus::Configuration.options[:config_folder]}/*_roles.yml"]
67
+ expected = files.collect { |file| File.basename(file) }
68
+ assert_equal expected, ['001_roles.yml', '002_roles.yml']
69
+ expected = { 'admin' => { 'categories' => 'read' } }
70
+ assert_equal expected, Typus::Configuration.roles!
71
+ end
72
+
73
+ def test_should_load_configuration_files_from_config_unordered
74
+ options = { :config_folder => 'vendor/plugins/typus/test/config/unordered' }
75
+ Typus::Configuration.stubs(:options).returns(options)
76
+ files = Dir["#{Rails.root}/#{Typus::Configuration.options[:config_folder]}/*_roles.yml"]
77
+ expected = files.collect { |file| File.basename(file) }
78
+ assert_equal expected, ['app_one_roles.yml', 'app_two_roles.yml']
79
+ expected = { 'admin' => { 'categories' => 'read, update' } }
80
+ assert_equal expected, Typus::Configuration.roles!
81
+ end
82
+
83
+ def test_should_load_configuration_files_from_config_default
84
+ options = { :config_folder => 'vendor/plugins/typus/test/config/default' }
85
+ Typus::Configuration.stubs(:options).returns(options)
86
+ assert_not_equal Hash.new, Typus::Configuration.roles!
87
+ assert_not_equal Hash.new, Typus::Configuration.config!
88
+ assert Typus.resources.empty?
89
+ end
90
+
91
+ end
@@ -0,0 +1,11 @@
1
+ require 'test/helper'
2
+
3
+ class HashTest < ActiveSupport::TestCase
4
+
5
+ def test_should_verify_compact
6
+ hash = { 'a' => '', 'b'=> nil, 'c' => 'hello' }
7
+ hash_compacted = { 'c' => 'hello' }
8
+ assert_equal hash_compacted, hash.compact
9
+ end
10
+
11
+ end
@@ -0,0 +1,82 @@
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
+ =begin
72
+
73
+ # FIXME
74
+
75
+ def test_should_verify_generated_routes_for_resource_controller
76
+ assert_routing '/admin/watch_dog', :controller => 'admin/watch_dog', :action => 'index'
77
+ assert_routing '/admin/watch_dog/cleanup', { :controller => 'admin/watch_dog', :action => 'cleanup' }
78
+ end
79
+
80
+ =end
81
+
82
+ 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