typus 1.0.0.pre8 → 1.0.0.pre9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. data/CHANGELOG +4 -6
  2. data/Gemfile +16 -13
  3. data/Gemfile.lock +26 -2
  4. data/Rakefile +2 -3
  5. data/app/controllers/admin/base_controller.rb +3 -5
  6. data/app/controllers/admin/resources_controller.rb +24 -26
  7. data/app/helpers/admin/base_helper.rb +14 -22
  8. data/app/helpers/admin/dashboard_helper.rb +2 -5
  9. data/app/helpers/admin/filters_helper.rb +6 -8
  10. data/app/helpers/admin/form_helper.rb +3 -9
  11. data/app/helpers/admin/preview_helper.rb +4 -6
  12. data/app/helpers/admin/relationships_helper.rb +9 -11
  13. data/app/helpers/admin/resources_helper.rb +6 -24
  14. data/app/helpers/admin/search_helper.rb +1 -1
  15. data/app/helpers/admin/sidebar_helper.rb +12 -15
  16. data/app/helpers/admin/table_helper.rb +13 -13
  17. data/app/views/admin/dashboard/show.html.erb +1 -1
  18. data/app/views/admin/helpers/_apps.html.erb +4 -3
  19. data/app/views/admin/helpers/_header.html.erb +2 -2
  20. data/app/views/admin/helpers/dashboard/_applications.html.erb +3 -3
  21. data/app/views/admin/helpers/dashboard/_resources.html.erb +17 -13
  22. data/app/views/admin/helpers/filters/_filters.html.erb +9 -27
  23. data/app/views/admin/helpers/resources/_pagination.html.erb +8 -9
  24. data/app/views/admin/helpers/search/_search.html.erb +1 -1
  25. data/app/views/admin/mailer/reset_password_link.text.erb +3 -0
  26. data/app/views/admin/resources/_form.html.erb +4 -4
  27. data/app/views/admin/resources/edit.html.erb +2 -3
  28. data/app/views/admin/resources/index.html.erb +15 -13
  29. data/app/views/admin/resources/new.html.erb +2 -2
  30. data/app/views/admin/resources/show.html.erb +1 -2
  31. data/app/views/admin/templates/_boolean.html.erb +1 -1
  32. data/app/views/admin/templates/_has_many.html.erb +2 -4
  33. data/app/views/admin/templates/_has_n.html.erb +1 -1
  34. data/app/views/admin/templates/_selector.html.erb +0 -1
  35. data/app/views/admin/templates/_string.html.erb +1 -1
  36. data/app/views/layouts/admin/session.html.erb +1 -1
  37. data/config/available_locales/ca.yml +3 -5
  38. data/config/available_locales/de.yml +2 -4
  39. data/config/available_locales/es.yml +2 -4
  40. data/config/available_locales/fr.yml +40 -39
  41. data/config/available_locales/fr_models.yml +2 -2
  42. data/config/available_locales/hu.yml +3 -5
  43. data/config/available_locales/it.yml +0 -4
  44. data/config/available_locales/language.yml.template +2 -4
  45. data/config/available_locales/pt-BR.yml +2 -4
  46. data/config/available_locales/ru.yml +2 -4
  47. data/config/routes.rb +1 -0
  48. data/lib/generators/templates/config/initializers/typus.rb +5 -5
  49. data/lib/generators/templates/config/initializers/typus_authentication.rb +5 -5
  50. data/lib/generators/templates/config/initializers/typus_resources.rb +7 -7
  51. data/lib/generators/templates/config/typus/README +11 -13
  52. data/lib/generators/templates/controller.rb +0 -2
  53. data/lib/generators/templates/functional_test.rb +4 -15
  54. data/lib/generators/typus/migration_generator.rb +0 -1
  55. data/lib/support/active_record.rb +18 -9
  56. data/lib/support/fake_user.rb +42 -0
  57. data/lib/support/object.rb +1 -0
  58. data/lib/support/string.rb +0 -32
  59. data/lib/tasks/typus.rake +0 -8
  60. data/lib/typus.rb +34 -18
  61. data/lib/typus/authentication/base.rb +26 -0
  62. data/lib/typus/authentication/http_basic.rb +22 -0
  63. data/lib/typus/authentication/none.rb +19 -0
  64. data/lib/typus/authentication/session.rb +190 -0
  65. data/lib/typus/format.rb +12 -19
  66. data/lib/typus/orm/active_record.rb +13 -51
  67. data/lib/typus/resources.rb +0 -9
  68. data/lib/typus/version.rb +1 -1
  69. data/test/factories.rb +43 -0
  70. data/test/fixtures/rails_app/app/controllers/application_controller.rb +0 -1
  71. data/test/fixtures/rails_app/app/models/page.rb +0 -4
  72. data/test/fixtures/rails_app/config/application.rb +6 -3
  73. data/test/fixtures/rails_app/config/database.yml +12 -20
  74. data/test/fixtures/rails_app/config/typus/application.yml +4 -8
  75. data/test/fixtures/rails_app/db/test.sqlite3 +0 -0
  76. data/test/fixtures/rails_app/log/test.log +227115 -0
  77. data/test/fixtures/rails_app/tmp/export-posts-20101012213057.csv +2 -0
  78. data/test/fixtures/rails_app/tmp/export-posts-20101012213132.csv +2 -0
  79. data/test/fixtures/rails_app/tmp/export-posts-20101012213234.csv +2 -0
  80. data/test/fixtures/rails_app/tmp/export-posts-20101012213506.csv +2 -0
  81. data/test/fixtures/rails_app/tmp/export-posts-20101012215057.csv +2 -0
  82. data/test/fixtures/rails_app/tmp/export-posts-20101012215217.csv +2 -0
  83. data/test/fixtures/rails_app/tmp/export-posts-20101012215415.csv +2 -0
  84. data/test/fixtures/rails_app/tmp/export-posts-20101012215443.csv +2 -0
  85. data/test/fixtures/rails_app/tmp/export-posts-20101012215509.csv +2 -0
  86. data/test/fixtures/rails_app/tmp/export-posts-20101012215528.csv +2 -0
  87. data/test/fixtures/rails_app/tmp/export-posts-20101012215551.csv +2 -0
  88. data/test/fixtures/rails_app/tmp/export-posts-20101012215615.csv +2 -0
  89. data/test/fixtures/rails_app/tmp/export-posts-20101012215640.csv +2 -0
  90. data/test/fixtures/rails_app/tmp/export-posts-20101012215714.csv +2 -0
  91. data/test/fixtures/rails_app/tmp/export-posts-20101012215744.csv +2 -0
  92. data/test/fixtures/rails_app/tmp/export-posts-20101012215814.csv +2 -0
  93. data/test/fixtures/rails_app/tmp/export-posts-20101012215836.csv +2 -0
  94. data/test/fixtures/rails_app/tmp/export-posts-20101012215906.csv +2 -0
  95. data/test/fixtures/rails_app/tmp/export-posts-20101012220659.csv +2 -0
  96. data/test/fixtures/rails_app/tmp/export-posts-20101012221043.csv +2 -0
  97. data/test/fixtures/rails_app/tmp/export-posts-20101012221258.csv +2 -0
  98. data/test/fixtures/rails_app/tmp/export-posts-20101012222558.csv +2 -0
  99. data/test/fixtures/rails_app/tmp/export-posts-20101012222752.csv +2 -0
  100. data/test/fixtures/rails_app/tmp/export-posts-20101012222848.csv +2 -0
  101. data/test/fixtures/rails_app/tmp/export-posts-20101012223433.csv +2 -0
  102. data/test/fixtures/rails_app/tmp/export-posts-20101012223535.csv +2 -0
  103. data/test/fixtures/rails_app/tmp/export-posts-20101012224003.csv +2 -0
  104. data/test/fixtures/rails_app/tmp/export-posts-20101012224052.csv +2 -0
  105. data/test/fixtures/rails_app/tmp/export-posts-20101012224109.csv +2 -0
  106. data/test/fixtures/rails_app/tmp/export-posts-20101012224139.csv +2 -0
  107. data/test/fixtures/rails_app/tmp/export-posts-20101012224205.csv +2 -0
  108. data/test/fixtures/rails_app/tmp/export-posts-20101012224243.csv +2 -0
  109. data/test/fixtures/rails_app/tmp/export-posts-20101012225119.csv +2 -0
  110. data/test/fixtures/rails_app/tmp/export-posts-20101013063215.csv +2 -0
  111. data/test/fixtures/rails_app/tmp/export-posts-20101013063300.csv +2 -0
  112. data/test/fixtures/rails_app/tmp/export-posts-20101013063352.csv +2 -0
  113. data/test/fixtures/rails_app/tmp/export-posts-20101013063427.csv +2 -0
  114. data/test/fixtures/rails_app/tmp/export-posts-20101013063448.csv +2 -0
  115. data/test/fixtures/rails_app/tmp/export-posts-20101013063530.csv +2 -0
  116. data/test/fixtures/rails_app/tmp/export-posts-20101013063559.csv +2 -0
  117. data/test/fixtures/rails_app/tmp/export-posts-20101013063646.csv +2 -0
  118. data/test/fixtures/rails_app/tmp/export-posts-20101013063737.csv +2 -0
  119. data/test/fixtures/rails_app/tmp/export-posts-20101013063822.csv +2 -0
  120. data/test/fixtures/rails_app/tmp/export-posts-20101013063837.csv +2 -0
  121. data/test/fixtures/rails_app/tmp/export-posts-20101013063919.csv +2 -0
  122. data/test/fixtures/rails_app/tmp/export-posts-20101013063939.csv +2 -0
  123. data/test/fixtures/rails_app/tmp/export-posts-20101013063952.csv +2 -0
  124. data/test/fixtures/rails_app/tmp/export-posts-20101013064220.csv +2 -0
  125. data/test/fixtures/rails_app/tmp/export-posts-20101013064253.csv +2 -0
  126. data/test/fixtures/rails_app/tmp/export-posts-20101013064318.csv +2 -0
  127. data/test/fixtures/rails_app/tmp/export-posts-20101013064404.csv +2 -0
  128. data/test/fixtures/rails_app/tmp/export-posts-20101013064452.csv +2 -0
  129. data/test/fixtures/rails_app/tmp/export-posts-20101013064536.csv +2 -0
  130. data/test/fixtures/rails_app/tmp/export-posts-20101013064652.csv +2 -0
  131. data/test/fixtures/rails_app/tmp/export-posts-20101013064845.csv +2 -0
  132. data/test/fixtures/rails_app/tmp/export-posts-20101013065023.csv +2 -0
  133. data/test/fixtures/rails_app/tmp/export-posts-20101013065137.csv +2 -0
  134. data/test/fixtures/rails_app/tmp/export-posts-20101013065713.csv +2 -0
  135. data/test/fixtures/rails_app/tmp/export-posts-20101013065954.csv +2 -0
  136. data/test/fixtures/rails_app/tmp/export-posts-20101013070057.csv +2 -0
  137. data/test/fixtures/rails_app/tmp/export-posts-20101013070116.csv +2 -0
  138. data/test/fixtures/rails_app/tmp/export-posts-20101013070156.csv +2 -0
  139. data/test/fixtures/rails_app/tmp/export-posts-20101013070349.csv +2 -0
  140. data/test/fixtures/rails_app/tmp/export-posts-20101013070429.csv +2 -0
  141. data/test/fixtures/rails_app/tmp/export-posts-20101013070448.csv +2 -0
  142. data/test/fixtures/rails_app/tmp/export-posts-20101013070514.csv +2 -0
  143. data/test/fixtures/rails_app/tmp/export-posts-20101013070709.csv +2 -0
  144. data/test/fixtures/rails_app/tmp/export-posts-20101013070745.csv +2 -0
  145. data/test/fixtures/rails_app/tmp/export-posts-20101013070809.csv +2 -0
  146. data/test/fixtures/rails_app/tmp/export-posts-20101013070905.csv +2 -0
  147. data/test/fixtures/rails_app/tmp/export-posts-20101013070955.csv +2 -0
  148. data/test/fixtures/rails_app/tmp/export-posts-20101013071116.csv +2 -0
  149. data/test/fixtures/rails_app/tmp/export-posts-20101013071209.csv +2 -0
  150. data/test/fixtures/rails_app/tmp/export-posts-20101013071335.csv +2 -0
  151. data/test/fixtures/rails_app/tmp/export-posts-20101013071632.csv +2 -0
  152. data/test/fixtures/rails_app/tmp/export-posts-20101013071643.csv +2 -0
  153. data/test/fixtures/rails_app/tmp/export-posts-20101013071735.csv +2 -0
  154. data/test/fixtures/rails_app/tmp/export-posts-20101013071749.csv +2 -0
  155. data/test/fixtures/rails_app/tmp/export-posts-20101013072030.csv +2 -0
  156. data/test/fixtures/rails_app/tmp/export-posts-20101013072050.csv +2 -0
  157. data/test/fixtures/rails_app/tmp/export-posts-20101013072108.csv +2 -0
  158. data/test/fixtures/rails_app/tmp/export-posts-20101013072713.csv +2 -0
  159. data/test/fixtures/rails_app/tmp/export-posts-20101013072751.csv +2 -0
  160. data/test/fixtures/rails_app/tmp/export-posts-20101013072912.csv +2 -0
  161. data/test/fixtures/rails_app/tmp/export-posts-20101013074546.csv +2 -0
  162. data/test/fixtures/rails_app/tmp/export-posts-20101018180512.csv +2 -0
  163. data/test/fixtures/rails_app/tmp/export-posts-20101018183359.csv +2 -0
  164. data/test/fixtures/rails_app/tmp/export-posts-20101018183608.csv +2 -0
  165. data/test/fixtures/rails_app/tmp/export-posts-20101018183759.csv +2 -0
  166. data/test/functional/admin/account_controller_test.rb +1 -1
  167. data/test/functional/admin/{resources_controller_assets_relationships.rb → assets_controller_test.rb} +12 -16
  168. data/test/functional/admin/categories_controller_test.rb +62 -0
  169. data/test/functional/admin/{resources_controller_comments_toggle_test.rb → comments_controller_test.rb} +0 -0
  170. data/test/functional/admin/dashboard_controller_test.rb +34 -2
  171. data/test/functional/admin/posts_controller_test.rb +548 -0
  172. data/test/functional/admin/session_controller_test.rb +2 -2
  173. data/test/functional/admin/{resources_controller_tableless_resource_test.rb → status_controller_test.rb} +0 -0
  174. data/test/functional/admin/{resources_controller_typus_users_test.rb → typus_users_controller_test.rb} +2 -2
  175. data/test/helpers/admin/base_helper_test.rb +35 -37
  176. data/test/helpers/admin/dashboard_helper_test.rb +4 -8
  177. data/test/helpers/admin/form_helper_test.rb +9 -34
  178. data/test/helpers/admin/resources_helper_test.rb +28 -16
  179. data/test/helpers/admin/sidebar_helper_test.rb +14 -27
  180. data/test/helpers/admin/table_helper_test.rb +24 -68
  181. data/test/integration/login_test.rb +13 -0
  182. data/test/integration_test_helper.rb +21 -0
  183. data/test/lib/support/active_record_test.rb +72 -21
  184. data/test/lib/support/array_test.rb +2 -6
  185. data/test/lib/support/string_test.rb +21 -30
  186. data/test/lib/typus/active_record_test.rb +162 -100
  187. data/test/lib/typus/resource_test.rb +2 -3
  188. data/test/lib/typus_test.rb +25 -22
  189. data/test/test_helper.rb +4 -17
  190. data/test/unit/admin/mailer_test.rb +2 -2
  191. data/test/unit/typus_user_roles_test.rb +23 -23
  192. data/test/unit/typus_user_test.rb +30 -24
  193. data/typus.gemspec +0 -1
  194. metadata +111 -60
  195. data/app/models/admin/fake_user.rb +0 -46
  196. data/lib/generators/templates/model.yml +0 -10
  197. data/lib/typus/authentication.rb +0 -241
  198. data/lib/vendor/paginator.rb +0 -143
  199. data/test/factories/assets.rb +0 -5
  200. data/test/factories/categories.rb +0 -3
  201. data/test/factories/comments.rb +0 -6
  202. data/test/factories/pages.rb +0 -5
  203. data/test/factories/pictures.rb +0 -7
  204. data/test/factories/posts.rb +0 -6
  205. data/test/factories/typus_users.rb +0 -8
  206. data/test/fixtures/rails_app/README +0 -244
  207. data/test/fixtures/rails_app/app/helpers/application_helper.rb +0 -2
  208. data/test/fixtures/rails_app/app/views/layouts/application.html.erb +0 -14
  209. data/test/fixtures/rails_app/config/environments/development.rb +0 -19
  210. data/test/fixtures/rails_app/config/environments/production.rb +0 -42
  211. data/test/fixtures/rails_app/config/initializers/acts_as_list.rb +0 -258
  212. data/test/fixtures/rails_app/config/initializers/acts_as_tree.rb +0 -98
  213. data/test/fixtures/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  214. data/test/fixtures/rails_app/config/initializers/inflections.rb +0 -10
  215. data/test/fixtures/rails_app/config/initializers/mime_types.rb +0 -5
  216. data/test/fixtures/rails_app/config/locales/en.yml +0 -5
  217. data/test/fixtures/rails_app/db/seeds.rb +0 -7
  218. data/test/fixtures/rails_app/public/404.html +0 -26
  219. data/test/fixtures/rails_app/public/422.html +0 -26
  220. data/test/fixtures/rails_app/public/500.html +0 -26
  221. data/test/fixtures/rails_app/public/favicon.ico +0 -0
  222. data/test/fixtures/rails_app/public/images/rails.png +0 -0
  223. data/test/fixtures/rails_app/public/index.html +0 -279
  224. data/test/fixtures/rails_app/public/javascripts/application.js +0 -2
  225. data/test/fixtures/rails_app/public/javascripts/controls.js +0 -965
  226. data/test/fixtures/rails_app/public/javascripts/dragdrop.js +0 -974
  227. data/test/fixtures/rails_app/public/javascripts/effects.js +0 -1123
  228. data/test/fixtures/rails_app/public/javascripts/prototype.js +0 -4874
  229. data/test/fixtures/rails_app/public/javascripts/rails.js +0 -118
  230. data/test/fixtures/rails_app/public/robots.txt +0 -5
  231. data/test/fixtures/rails_app/script/rails +0 -9
  232. data/test/functional/admin/dashboard_controller_http_basic_test.rb +0 -24
  233. data/test/functional/admin/dashboard_controller_none_test.rb +0 -18
  234. data/test/functional/admin/resources_controller_categories_before_test.rb +0 -10
  235. data/test/functional/admin/resources_controller_categories_lists_test.rb +0 -44
  236. data/test/functional/admin/resources_controller_categories_views_test.rb +0 -10
  237. data/test/functional/admin/resources_controller_posts_before_test.rb +0 -10
  238. data/test/functional/admin/resources_controller_posts_crud_custom_test.rb +0 -27
  239. data/test/functional/admin/resources_controller_posts_crud_test.rb +0 -44
  240. data/test/functional/admin/resources_controller_posts_formats_test.rb +0 -39
  241. data/test/functional/admin/resources_controller_posts_forms_test.rb +0 -58
  242. data/test/functional/admin/resources_controller_posts_permissions_test.rb +0 -100
  243. data/test/functional/admin/resources_controller_posts_relationships_test.rb +0 -91
  244. data/test/functional/admin/resources_controller_posts_roles.rb +0 -52
  245. data/test/functional/admin/resources_controller_posts_views_test.rb +0 -143
  246. data/test/lib/vendor/paginator_test.rb +0 -141
  247. data/typus-1.0.0.pre7.gem +0 -0
@@ -0,0 +1,13 @@
1
+ require 'integration_test_helper'
2
+
3
+ class LoginTest < ActionController::IntegrationTest
4
+
5
+ feature "Admin goes to login page" do
6
+
7
+ scenario "views page" do
8
+ visit '/admin'
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+ require 'capybara/rails'
3
+
4
+ module ActionController
5
+
6
+ class IntegrationTest
7
+ include Capybara
8
+ end
9
+
10
+ end
11
+
12
+ module Shoulda
13
+
14
+ module ClassMethods
15
+
16
+ alias :feature :context
17
+ alias :scenario :should
18
+
19
+ end
20
+
21
+ end
@@ -2,34 +2,85 @@ require "test_helper"
2
2
 
3
3
  class ActiveRecordTest < ActiveSupport::TestCase
4
4
 
5
- should "verify mapping instace method with an array" do
6
- post = Factory(:post)
7
- assert_equal "published", post.mapping(:status)
8
- end
5
+ context "mapping" do
9
6
 
10
- should "verify mapping instace method with an array when status if unpublished" do
11
- post = Factory(:post, :status => "unpublished")
12
- assert_equal "unpublished", post.mapping(:status)
13
- end
7
+ context "with an array" do
14
8
 
15
- should "verify mapping instace method with a hash" do
16
- page = Factory(:page)
17
- assert_equal "Published", page.mapping(:status)
18
- page = Factory(:page, :status => "unpublished")
19
- assert_equal "Not Published", page.mapping(:status)
20
- end
9
+ setup do
10
+ Post.send(:remove_const, :STATUS)
11
+ Post::STATUS = %w(pending published unpublished)
12
+ end
13
+
14
+ should "verify" do
15
+ post = Factory(:post)
16
+ assert_equal "published", post.mapping(:status)
17
+ post = Factory(:post, :status => "unpublished")
18
+ assert_equal "unpublished", post.mapping(:status)
19
+ end
20
+
21
+ end
22
+
23
+ context "with a two dimension array" do
24
+
25
+ setup do
26
+ Post.send(:remove_const, :STATUS)
27
+ Post::STATUS = [["Publicado", "published"], ["Pendiente", "pending"], ["No publicado", "unpublished"]]
28
+ end
29
+
30
+ should "verify" do
31
+ post = Factory(:post)
32
+ assert_equal "Publicado", post.mapping(:status)
33
+ post = Factory(:post, :status => "unpublished")
34
+ assert_equal "No publicado", post.mapping(:status)
35
+ end
36
+
37
+ end
38
+
39
+ context "with a hash" do
40
+
41
+ setup do
42
+ Post.send(:remove_const, :STATUS)
43
+ Post::STATUS = { "Pending - Hash" => "pending", "Published - Hash" => "published", "Not Published - Hash" => "unpublished" }
44
+ end
45
+
46
+ should "verify" do
47
+ page = Factory(:post)
48
+ assert_equal "Published - Hash", page.mapping(:status)
49
+ page = Factory(:post, :status => "unpublished")
50
+ assert_equal "Not Published - Hash", page.mapping(:status)
51
+ end
52
+
53
+ end
21
54
 
22
- should "verify to_label instace method" do
23
- assert_equal "admin@example.com", Factory(:typus_user).to_label
24
55
  end
25
56
 
26
- should "verify to_label instace method for post" do
27
- assert_match /Post#/, Factory(:post).to_label
57
+ context "to_label" do
58
+
59
+ should "return email as is an alias for to_label on TypusUser" do
60
+ assert_equal "admin@example.com", Factory(:typus_user).to_label
61
+ end
62
+
63
+ should "return name for Category" do
64
+ category = Factory(:category)
65
+ assert_match category.name, category.to_label
66
+ end
67
+
68
+ should "return default Model#id" do
69
+ assert_match /Post#/, Factory(:post).to_label
70
+ end
71
+
28
72
  end
29
73
 
30
- should "verify to_resource instance method" do
31
- assert_equal "typus_users", TypusUser.to_resource
32
- assert_equal "delayed/tasks", Delayed::Task.to_resource
74
+ context "to_resource" do
75
+
76
+ should "work for models" do
77
+ assert_equal "typus_users", TypusUser.to_resource
78
+ end
79
+
80
+ should "work for namespaced models" do
81
+ assert_equal "delayed/tasks", Delayed::Task.to_resource
82
+ end
83
+
33
84
  end
34
85
 
35
86
  end
@@ -2,14 +2,10 @@ require "test_helper"
2
2
 
3
3
  class ArrayTest < ActiveSupport::TestCase
4
4
 
5
- should "verify Array#to_hash_with" do
5
+ should "verify to_hash_with" do
6
6
  keys, values = %w(a b c), %w(1 2 3)
7
7
  expected = { "a" => "1", "b" => "2", "c" => "3" }
8
-
9
- hash = keys.to_hash_with(values)
10
-
11
- assert hash.kind_of?(Hash)
12
- assert_equal expected, hash
8
+ assert_equal expected, keys.to_hash_with(values)
13
9
  end
14
10
 
15
11
  end
@@ -7,42 +7,33 @@ class StringTest < ActiveSupport::TestCase
7
7
  assert_equal %w( a b c ), " a , b, c ".extract_settings
8
8
  end
9
9
 
10
- should "remove prefix" do
11
- assert_equal "posts", "admin/posts".remove_prefix
12
- assert_equal "typus_users", "admin/typus_users".remove_prefix
13
- assert_equal "delayed/jobs", "admin/delayed/jobs".remove_prefix
14
- end
10
+ context "remove_prefix" do
15
11
 
16
- should "remove prefix with params" do
17
- assert_equal "posts", "typus/posts".remove_prefix("typus/")
18
- assert_equal "typus_users", "typus/typus_users".remove_prefix("typus/")
19
- assert_equal "delayed/tasks", "typus/delayed/tasks".remove_prefix("typus/")
20
- end
12
+ should "remove admin by default" do
13
+ assert_equal "posts", "admin/posts".remove_prefix
14
+ assert_equal "typus_users", "admin/typus_users".remove_prefix
15
+ assert_equal "delayed/jobs", "admin/delayed/jobs".remove_prefix
16
+ end
21
17
 
22
- should "extract_resource" do
23
- assert_equal "posts", "admin/posts".extract_resource
24
- assert_equal "typus_users", "admin/typus_users".extract_resource
25
- assert_equal "delayed/tasks", "admin/delayed/tasks".extract_resource
26
- end
18
+ should "remove what we want to" do
19
+ assert_equal "posts", "typus/posts".remove_prefix("typus/")
20
+ assert_equal "typus_users", "typus/typus_users".remove_prefix("typus/")
21
+ assert_equal "delayed/tasks", "typus/delayed/tasks".remove_prefix("typus/")
22
+ end
27
23
 
28
- should "extract_class" do
29
- assert_equal Post, "admin/posts".extract_class
30
- assert_equal TypusUser, "admin/typus_users".extract_class
31
- assert_equal Delayed::Task, "admin/delayed/tasks".extract_class
32
24
  end
33
25
 
34
- should "extract_human_name" do
35
- assert_equal "Post", "admin/posts".extract_human_name
36
- assert_equal "Typus user", "admin/typus_users".extract_human_name
37
- assert_equal "Task", "admin/delayed/tasks".extract_human_name
38
- end
26
+ context "extract_class" do
27
+
28
+ should "work for models" do
29
+ assert_equal Post, "admin/posts".extract_class
30
+ assert_equal TypusUser, "admin/typus_users".extract_class
31
+ end
32
+
33
+ should "work for namespaced models" do
34
+ assert_equal Delayed::Task, "admin/delayed/tasks".extract_class
35
+ end
39
36
 
40
- should "verify String#typus_actions_on" do
41
- assert_equal %w(cleanup), "Post".typus_actions_on("index")
42
- assert_equal %w(cleanup), "Post".typus_actions_on(:index)
43
- assert_equal %w(send_as_newsletter preview), "Post".typus_actions_on(:edit)
44
- assert "TypusUser".typus_actions_on(:unexisting).empty?
45
- assert "Post".typus_actions_on(:index).kind_of?(Array)
46
37
  end
47
38
 
48
39
  end
@@ -2,70 +2,82 @@ require "test_helper"
2
2
 
3
3
  class ActiveRecordTest < ActiveSupport::TestCase
4
4
 
5
- should "verify model fields is an instance of active support ordered hash" do
6
- assert TypusUser.model_fields.instance_of?(ActiveSupport::OrderedHash)
7
- end
5
+ context "model_fields" do
6
+
7
+ should "be an ActiveSupport::OrderedHash" do
8
+ assert TypusUser.model_fields.instance_of?(ActiveSupport::OrderedHash)
9
+ end
10
+
11
+ should "verify TypusUser model_fields" do
12
+ expected_fields = [[:id, :integer],
13
+ [:first_name, :string],
14
+ [:last_name, :string],
15
+ [:role, :string],
16
+ [:email, :string],
17
+ [:status, :boolean],
18
+ [:token, :string],
19
+ [:salt, :string],
20
+ [:crypted_password, :string],
21
+ [:preferences, :string],
22
+ [:created_at, :datetime],
23
+ [:updated_at, :datetime]]
24
+ assert_equal expected_fields.map { |i| i.first }, TypusUser.model_fields.keys
25
+ assert_equal expected_fields.map { |i| i.last }, TypusUser.model_fields.values
26
+ end
27
+
28
+ should "verify Post model_fields" do
29
+ expected_fields = [[:id, :integer],
30
+ [:title, :string],
31
+ [:body, :text],
32
+ [:status, :string],
33
+ [:favorite_comment_id, :integer],
34
+ [:created_at, :datetime],
35
+ [:updated_at, :datetime],
36
+ [:published_at, :datetime],
37
+ [:typus_user_id, :integer]]
38
+ assert_equal expected_fields.map { |i| i.first }, Post.model_fields.keys
39
+ assert_equal expected_fields.map { |i| i.last }, Post.model_fields.values
40
+ end
8
41
 
9
- should "return model fields for TypusUser" do
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
- [:preferences, :string],
20
- [:created_at, :datetime],
21
- [:updated_at, :datetime]]
22
- assert_equal expected_fields.map { |i| i.first }, TypusUser.model_fields.keys
23
- assert_equal expected_fields.map { |i| i.last }, TypusUser.model_fields.values
24
42
  end
25
43
 
26
- should "return model fields for post" do
27
- expected_fields = [[:id, :integer],
28
- [:title, :string],
29
- [:body, :text],
30
- [:status, :string],
31
- [:favorite_comment_id, :integer],
32
- [:created_at, :datetime],
33
- [:updated_at, :datetime],
34
- [:published_at, :datetime],
35
- [:typus_user_id, :integer]]
36
- assert_equal expected_fields.map { |i| i.first }, Post.model_fields.keys
37
- assert_equal expected_fields.map { |i| i.last }, Post.model_fields.values
38
- end
44
+ context "model_relationships" do
39
45
 
40
- should "verify_model_relationships_is_an_instance_of_active_support_ordered_hash" do
41
- assert TypusUser.model_relationships.instance_of?(ActiveSupport::OrderedHash)
42
- end
46
+ should "be an ActiveSupport::OrderedHash" do
47
+ assert TypusUser.model_relationships.instance_of?(ActiveSupport::OrderedHash)
48
+ end
43
49
 
44
- should "return_model_relationships_for_post" do
45
- expected = [[:comments, :has_many],
46
- [:categories, :has_and_belongs_to_many],
47
- [:user, nil],
48
- [:assets, :has_many]]
49
- expected.each do |i|
50
- assert_equal i.last, Post.model_relationships[i.first]
50
+ should "verify Post model_relationships" do
51
+ expected = [[:comments, :has_many],
52
+ [:categories, :has_and_belongs_to_many],
53
+ [:user, nil],
54
+ [:assets, :has_many]]
55
+ expected.each do |i|
56
+ assert_equal i.last, Post.model_relationships[i.first]
57
+ end
51
58
  end
59
+
52
60
  end
53
61
 
54
- should "return_description_of_a_model" do
55
- assert_equal "System Users Administration", TypusUser.typus_description
62
+ context "typus_description" do
63
+
64
+ should "return the description of a model" do
65
+ assert_equal "System Users Administration", TypusUser.typus_description
66
+ end
67
+
56
68
  end
57
69
 
58
- context "Typus fields for" do
70
+ context "typus_fields_for" do
59
71
 
60
- should "verify typus_fields_for accepts strings" do
72
+ should "accept strings" do
61
73
  assert_equal %w( email role status ), TypusUser.typus_fields_for("list").keys
62
74
  end
63
75
 
64
- should "verify typus_fields_for accepts symbols" do
76
+ should "accept symbols" do
65
77
  assert_equal %w( email role status ), TypusUser.typus_fields_for(:list).keys
66
78
  end
67
79
 
68
- should "return_typus_fields_for_list_for_typus_user" do
80
+ should "return list fields for TypusUser" do
69
81
  expected_fields = [["email", :string],
70
82
  ["role", :selector],
71
83
  ["status", :boolean]]
@@ -73,7 +85,7 @@ class ActiveRecordTest < ActiveSupport::TestCase
73
85
  assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for(:list).values
74
86
  end
75
87
 
76
- should "return_typus_fields_for_form_for_typus_user" do
88
+ should "return form fields for TypusUser" do
77
89
  expected_fields = [["first_name", :string],
78
90
  ["last_name", :string],
79
91
  ["role", :selector],
@@ -85,30 +97,30 @@ class ActiveRecordTest < ActiveSupport::TestCase
85
97
  assert_equal expected_fields.map { |i| i.last }, TypusUser.typus_fields_for(:form).values
86
98
  end
87
99
 
88
- should "return_typus_fields_for_form_for_picture" do
100
+ should "return form fields for Picture" do
89
101
  expected_fields = [["title", :string],
90
102
  ["picture", :file]]
91
103
  assert_equal expected_fields.map { |i| i.first }, Picture.typus_fields_for(:form).keys
92
104
  assert_equal expected_fields.map { |i| i.last }, Picture.typus_fields_for(:form).values
93
105
  end
94
106
 
95
- should "return_typus_fields_for_a_model_without_configuration" do
107
+ should "return form fields for a Model without configuration" do
96
108
  assert Class.new(ActiveRecord::Base).typus_fields_for(:form).empty?
97
109
  end
98
110
 
99
- should "return_typus_fields_for_relationship_for_typus_user" do
111
+ should "return relationship fields for TypusUser" do
100
112
  assert_equal %w( first_name last_name role email language), TypusUser.typus_fields_for(:relationship).keys
101
113
  end
102
114
 
103
- should "return_all_fields_for_undefined_field_type_on_typus_user" do
115
+ should "return undefined fields for TypusUser" do
104
116
  assert_equal %w( first_name last_name role email language), TypusUser.typus_fields_for(:undefined).keys
105
117
  end
106
118
 
107
119
  end
108
120
 
109
- context "Typus filters" do
121
+ context "typus_filters" do
110
122
 
111
- should "return_filters_for_typus_user" do
123
+ should "return filters for TypusUser" do
112
124
  expected = [["status", :boolean], ["role", :string]]
113
125
 
114
126
  assert_equal expected.map { |i| i.first }.join(", "), Typus::Configuration.config["TypusUser"]["filters"]
@@ -116,7 +128,7 @@ class ActiveRecordTest < ActiveSupport::TestCase
116
128
  assert_equal expected.map { |i| i.last }, TypusUser.typus_filters.values
117
129
  end
118
130
 
119
- should "return_post_typus_filters" do
131
+ should "return filters for Post" do
120
132
  expected = [["status", :string], ["created_at", :datetime]]
121
133
  assert_equal expected.map { |i| i.first }.join(", "), Typus::Configuration.config["Post"]["filters"]
122
134
  assert_equal expected.map { |i| i.first }, Post.typus_filters.keys
@@ -125,52 +137,63 @@ class ActiveRecordTest < ActiveSupport::TestCase
125
137
 
126
138
  end
127
139
 
128
- context "Typus actions on" do
140
+ context "typus_actions_on" do
129
141
 
130
- should "verify typus_actions_on accepts strings" do
142
+ should "accept strings" do
131
143
  assert_equal %w( cleanup ), Post.typus_actions_on("index")
132
144
  end
133
145
 
134
- should "verify typus_actions_on accepts symbols" do
146
+ should "accept symbols" do
135
147
  assert_equal %w( cleanup ), Post.typus_actions_on(:index)
136
148
  end
137
149
 
138
- should "return_actions_on_list_for_typus_user" do
150
+ should "return actions on list for TypusUser" do
139
151
  assert TypusUser.typus_actions_on(:list).empty?
140
152
  end
141
153
 
142
- should "return Post actions on edit" do
154
+ should "return actions on edit for Post" do
143
155
  assert_equal %w( send_as_newsletter preview ), Post.typus_actions_on(:edit)
144
156
  end
145
157
 
146
- should "return Post actions" do
147
- assert_equal %w( cleanup preview send_as_newsletter ), Post.typus_actions.sort
148
- end
149
-
150
158
  end
151
159
 
152
- context "Typus options for" do
160
+ context "typus_options_for" do
153
161
 
154
- should "verify typus_options_for accepts strings" do
162
+ should "accept strings" do
155
163
  assert_equal 15, Post.typus_options_for("form_rows")
156
164
  end
157
165
 
158
- should "verify typus_options_for accepts symbols" do
166
+ should "accept symbols" do
159
167
  assert_equal 15, Post.typus_options_for(:form_rows)
160
168
  end
161
169
 
162
- should "verify typus_options_for returns nil when options doesnt exist" do
163
- assert TypusUser.typus_options_for(:unexisting).nil?
170
+ should "return nil when options do not exist" do
171
+ assert_nil TypusUser.typus_options_for(:unexisting)
164
172
  end
165
173
 
166
- should "return options for post and page" do
174
+ should "return options for Post" do
167
175
  assert_equal 15, Post.typus_options_for(:form_rows)
176
+ end
177
+
178
+ should "return options for Page" do
168
179
  assert_equal 25, Page.typus_options_for(:form_rows)
169
180
  end
170
181
 
171
182
  end
172
183
 
173
- context "Typus field options for" do
184
+ context "typus_application" do
185
+
186
+ should "return application for Post" do
187
+ assert_equal "Blog", Post.typus_application
188
+ end
189
+
190
+ should "return application for View" do
191
+ assert_equal "Unknown", View.typus_application
192
+ end
193
+
194
+ end
195
+
196
+ context "typus_field_options_for" do
174
197
 
175
198
  should "verify on models" do
176
199
  assert_equal [ :status ], Post.typus_field_options_for(:selectors)
@@ -180,71 +203,110 @@ class ActiveRecordTest < ActiveSupport::TestCase
180
203
 
181
204
  end
182
205
 
183
- context "Typus boolean" do
206
+ context "typus_boolean" do
184
207
 
185
- should "verify_typus_boolean_is_an_instance_of_active_support_ordered_hash" do
186
- assert TypusUser.typus_boolean("status").instance_of?(ActiveSupport::OrderedHash)
208
+ should "accept strings" do
209
+ expected = {"Inactive"=>"false", "Active"=>"true"}
210
+ assert_equal expected, TypusUser.typus_boolean("status")
187
211
  end
188
212
 
189
- should "verify typus_boolean accepts strings" do
190
- assert_equal [ :true, :false ], TypusUser.typus_boolean("status").keys
213
+ should "accept symbols" do
214
+ expected = {"Inactive"=>"false", "Active"=>"true"}
215
+ assert_equal expected, TypusUser.typus_boolean(:status)
191
216
  end
192
217
 
193
- should "verify typus_boolean accepts symbols" do
194
- assert_equal [ :true, :false ], TypusUser.typus_boolean(:status).keys
218
+ should "return booleans for TypusUser" do
219
+ expected = {"Active" => "true", "Inactive" => "false"}
220
+ assert_equal expected, TypusUser.typus_boolean(:status)
195
221
  end
196
222
 
197
- should "return_booleans_for_typus_users" do
198
- assert_equal [ :true, :false ], TypusUser.typus_boolean(:status).keys
199
- assert_equal [ "Active", "Inactive" ], TypusUser.typus_boolean(:status).values
200
- end
201
-
202
- should "return_booleans_for_post" do
203
- assert_equal [ :true, :false ], Post.typus_boolean(:status).keys
204
- assert_equal [ "True", "False" ], Post.typus_boolean(:status).values
223
+ should "return booleans for Post" do
224
+ expected = {"True" => "true", "False" => "false"}
225
+ assert_equal expected, Post.typus_boolean(:status)
205
226
  end
206
227
 
207
228
  end
208
229
 
209
- context "Typus date format" do
230
+ context "typus_date_format" do
210
231
 
211
- should "verify typus_date_format accepts strings" do
232
+ should "accept strings" do
212
233
  assert_equal :db, Post.typus_date_format("unknown")
213
234
  end
214
235
 
215
- should "verify typus_date_format accepts symbols" do
236
+ should "accept symbols" do
216
237
  assert_equal :db, Post.typus_date_format(:unknown)
217
238
  end
218
239
 
219
- should "return typus_date_formats for Post" do
240
+ should "return date_format for Post" do
220
241
  assert_equal :db, Post.typus_date_format
221
242
  assert_equal :post_short, Post.typus_date_format(:created_at)
222
243
  end
223
244
 
224
245
  end
225
246
 
226
- context "Typus defaults for" do
247
+ context "typus_template" do
227
248
 
228
- should "verify typus_defaults_for on Model accepts strings" do
229
- assert_equal %w( title ), Post.typus_defaults_for("search")
249
+ should "accept strings" do
250
+ assert_equal "datepicker", Post.typus_template("published_at")
230
251
  end
231
252
 
232
- should "verify typus_defaults_for on Model accepts symbols" do
233
- assert_equal %w( title ), Post.typus_defaults_for(:search)
253
+ should "accept symbols" do
254
+ assert_equal "datepicker", Post.typus_template(:published_at)
255
+ end
256
+
257
+ should "return nil if template does not exist" do
258
+ assert_nil Post.typus_template(:created_at)
259
+ end
260
+
261
+ end
262
+
263
+ context "typus_defaults_for" do
264
+
265
+ should "accept strings" do
266
+ assert_equal %w( title ), Post.typus_defaults_for("search")
234
267
  end
235
268
 
236
- should "return defaults_for search on Post" do
269
+ should "accepts symbols" do
237
270
  assert_equal %w( title ), Post.typus_defaults_for(:search)
238
271
  end
239
272
 
240
273
  should "return default_for relationships on Post" do
241
274
  assert_equal %w( assets categories comments views ), Post.typus_defaults_for(:relationships)
242
- assert !Post.typus_defaults_for(:relationships).empty?
243
275
  end
244
276
 
245
277
  end
246
278
 
247
- context "Typus order by" do
279
+ context "typus_search_fields" do
280
+
281
+ should "return a hash with the search modifiers" do
282
+ search = ["=id", "^title", "body"]
283
+ Post.stubs(:typus_defaults_for).with(:search).returns(search)
284
+ expected = {"body"=>"@", "title"=>"^", "id"=>"="}
285
+ assert_equal expected, Post.typus_search_fields
286
+ end
287
+
288
+ should "return and empty hash" do
289
+ search = []
290
+ Post.stubs(:typus_defaults_for).with(:search).returns(search)
291
+ expected = {}
292
+ assert_equal expected, Post.typus_search_fields
293
+ end
294
+
295
+ end
296
+
297
+ context "typus_export_formats" do
298
+
299
+ should "return post formats" do
300
+ assert_equal ["csv", "xml"], Post.typus_export_formats
301
+ end
302
+
303
+ should "return picture formats" do
304
+ assert_equal [], Picture.typus_export_formats
305
+ end
306
+
307
+ end
308
+
309
+ context "typus_order_by" do
248
310
 
249
311
  should "return defaults_for order_by on Post" do
250
312
  assert_equal "posts.title ASC, posts.created_at DESC", Post.typus_order_by
@@ -253,7 +315,7 @@ class ActiveRecordTest < ActiveSupport::TestCase
253
315
 
254
316
  end
255
317
 
256
- context "Build conditions" do
318
+ context "build_conditions" do
257
319
 
258
320
  should "generate conditions for id" do
259
321
  Post.stubs(:typus_defaults_for).with(:search).returns(["id"])
@@ -374,7 +436,7 @@ class ActiveRecordTest < ActiveSupport::TestCase
374
436
 
375
437
  end
376
438
 
377
- context "Class methods" do
439
+ context "class_methods" do
378
440
 
379
441
  should "verify typus_user_id exists on Post" do
380
442
  assert Post.typus_user_id?