typus 0.9.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data/.gitignore +8 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +86 -0
  4. data/Rakefile +61 -0
  5. data/VERSION +1 -0
  6. data/app/controllers/admin/master_controller.rb +354 -0
  7. data/app/controllers/typus_controller.rb +128 -0
  8. data/app/helpers/admin/form_helper.rb +386 -0
  9. data/app/helpers/admin/master_helper.rb +104 -0
  10. data/app/helpers/admin/public_helper.rb +27 -0
  11. data/app/helpers/admin/sidebar_helper.rb +236 -0
  12. data/app/helpers/admin/table_helper.rb +227 -0
  13. data/app/helpers/typus_helper.rb +194 -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 +24 -0
  18. data/app/views/admin/resources/index.html.erb +23 -0
  19. data/app/views/admin/resources/new.html.erb +22 -0
  20. data/app/views/admin/resources/show.html.erb +18 -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 +73 -0
  24. data/app/views/layouts/typus.html.erb +29 -0
  25. data/app/views/typus/dashboard.html.erb +9 -0
  26. data/app/views/typus/recover_password.html.erb +7 -0
  27. data/app/views/typus/reset_password.html.erb +15 -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/typus/de.yml +109 -0
  32. data/config/locales/typus/es.yml +109 -0
  33. data/config/locales/typus/language.yml.template +113 -0
  34. data/config/locales/typus/pt-BR.yml +111 -0
  35. data/config/locales/typus/ru.yml +111 -0
  36. data/generators/typus/templates/config/initializers/typus.rb +33 -0
  37. data/generators/typus/templates/config/typus/README +51 -0
  38. data/generators/typus/templates/config/typus/application.yml +6 -0
  39. data/generators/typus/templates/config/typus/application_roles.yml +23 -0
  40. data/generators/typus/templates/config/typus/typus.yml +14 -0
  41. data/generators/typus/templates/config/typus/typus_roles.yml +2 -0
  42. data/generators/typus/templates/db/create_typus_users.rb +21 -0
  43. data/generators/typus/templates/public/images/admin/arrow_down.gif +0 -0
  44. data/generators/typus/templates/public/images/admin/arrow_up.gif +0 -0
  45. data/generators/typus/templates/public/images/admin/spinner.gif +0 -0
  46. data/generators/typus/templates/public/images/admin/status_false.gif +0 -0
  47. data/generators/typus/templates/public/images/admin/status_true.gif +0 -0
  48. data/generators/typus/templates/public/images/admin/trash.gif +0 -0
  49. data/generators/typus/templates/public/javascripts/admin/application.js +14 -0
  50. data/generators/typus/templates/public/stylesheets/admin/reset.css +68 -0
  51. data/generators/typus/templates/public/stylesheets/admin/screen.css +729 -0
  52. data/generators/typus/typus_generator.rb +122 -0
  53. data/generators/typus_update_schema_to_01/templates/config/typus.yml +14 -0
  54. data/generators/typus_update_schema_to_01/templates/migration.rb +11 -0
  55. data/generators/typus_update_schema_to_01/typus_update_schema_to_01_generator.rb +19 -0
  56. data/lib/typus.rb +122 -0
  57. data/lib/typus/active_record.rb +307 -0
  58. data/lib/typus/authentication.rb +142 -0
  59. data/lib/typus/configuration.rb +85 -0
  60. data/lib/typus/extensions/routes.rb +15 -0
  61. data/lib/typus/format.rb +55 -0
  62. data/lib/typus/generator.rb +81 -0
  63. data/lib/typus/hash.rb +8 -0
  64. data/lib/typus/locale.rb +17 -0
  65. data/lib/typus/object.rb +21 -0
  66. data/lib/typus/quick_edit.rb +40 -0
  67. data/lib/typus/reloader.rb +15 -0
  68. data/lib/typus/string.rb +11 -0
  69. data/lib/typus/templates/index.html.erb +11 -0
  70. data/lib/typus/templates/resource_controller.rb.erb +15 -0
  71. data/lib/typus/templates/resource_controller_test.rb.erb +10 -0
  72. data/lib/typus/templates/resources_controller.rb.erb +37 -0
  73. data/lib/typus/user.rb +134 -0
  74. data/lib/vendor/active_record.rb +15 -0
  75. data/lib/vendor/paginator.rb +143 -0
  76. data/rails/init.rb +3 -0
  77. data/tasks/typus_tasks.rake +32 -0
  78. data/test/config/broken/application.yml +68 -0
  79. data/test/config/broken/application_roles.yml +20 -0
  80. data/test/config/broken/empty.yml +0 -0
  81. data/test/config/broken/empty_roles.yml +0 -0
  82. data/test/config/broken/undefined.yml +3 -0
  83. data/test/config/broken/undefined_roles.yml +6 -0
  84. data/test/config/default/typus.yml +14 -0
  85. data/test/config/default/typus_roles.yml +2 -0
  86. data/test/config/empty/empty_01.yml +0 -0
  87. data/test/config/empty/empty_01_roles.yml +0 -0
  88. data/test/config/empty/empty_02.yml +0 -0
  89. data/test/config/empty/empty_02_roles.yml +0 -0
  90. data/test/config/locales/es.yml +10 -0
  91. data/test/config/ordered/001_roles.yml +2 -0
  92. data/test/config/ordered/002_roles.yml +2 -0
  93. data/test/config/unordered/app_one_roles.yml +2 -0
  94. data/test/config/unordered/app_two_roles.yml +2 -0
  95. data/test/config/working/application.yml +68 -0
  96. data/test/config/working/application_roles.yml +22 -0
  97. data/test/config/working/typus.yml +14 -0
  98. data/test/config/working/typus_roles.yml +2 -0
  99. data/test/fixtures/app/controllers/admin/assets_controller.rb +2 -0
  100. data/test/fixtures/app/controllers/admin/categories_controller.rb +2 -0
  101. data/test/fixtures/app/controllers/admin/comments_controller.rb +2 -0
  102. data/test/fixtures/app/controllers/admin/pages_controller.rb +2 -0
  103. data/test/fixtures/app/controllers/admin/posts_controller.rb +2 -0
  104. data/test/fixtures/app/controllers/admin/status_controller.rb +6 -0
  105. data/test/fixtures/app/controllers/admin/typus_users_controller.rb +2 -0
  106. data/test/fixtures/app/controllers/admin/watch_dog_controller.rb +6 -0
  107. data/test/fixtures/app/views/admin/comments/_edit.html.erb +1 -0
  108. data/test/fixtures/app/views/admin/comments/_index.html.erb +1 -0
  109. data/test/fixtures/app/views/admin/comments/_new.html.erb +1 -0
  110. data/test/fixtures/app/views/admin/comments/_show.html.erb +1 -0
  111. data/test/fixtures/app/views/admin/comments/_sidebar.html.erb +1 -0
  112. data/test/fixtures/app/views/admin/dashboard/_content.html.erb +1 -0
  113. data/test/fixtures/app/views/admin/dashboard/_sidebar.html.erb +1 -0
  114. data/test/fixtures/app/views/admin/resources/_sidebar.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 +120 -0
  127. data/test/functional/admin/master_controller_test.rb +5 -0
  128. data/test/functional/admin/posts_controller_test.rb +261 -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 +321 -0
  132. data/test/helper.rb +51 -0
  133. data/test/helpers/admin/form_helper_test.rb +337 -0
  134. data/test/helpers/admin/master_helper_test.rb +69 -0
  135. data/test/helpers/admin/public_helper_test.rb +26 -0
  136. data/test/helpers/admin/sidebar_helper_test.rb +335 -0
  137. data/test/helpers/admin/table_helper_test.rb +239 -0
  138. data/test/helpers/typus_helper_test.rb +117 -0
  139. data/test/lib/active_record_test.rb +382 -0
  140. data/test/lib/configuration_test.rb +94 -0
  141. data/test/lib/hash_test.rb +11 -0
  142. data/test/lib/routes_test.rb +71 -0
  143. data/test/lib/string_test.rb +25 -0
  144. data/test/lib/typus_test.rb +85 -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 +136 -0
  153. data/typus.gemspec +228 -0
  154. metadata +241 -0
@@ -0,0 +1,26 @@
1
+ require 'test/helper'
2
+
3
+ class Admin::PublicHelperTest < ActiveSupport::TestCase
4
+
5
+ include Admin::PublicHelper
6
+
7
+ def test_quick_edit
8
+
9
+ options = { :path => 'articles/edit/1', :message => 'Edit this article' }
10
+ output = quick_edit(options)
11
+
12
+ html = <<-HTML
13
+ <script type="text/javascript">
14
+ document.write('<script type="text/javascript" src="quick_edit?message=Edit+this+article&path=articles%2Fedit%2F1" />');
15
+ </script>
16
+ HTML
17
+
18
+ assert_equal html, output
19
+
20
+ end
21
+
22
+ def admin_quick_edit_path
23
+ 'quick_edit'
24
+ end
25
+
26
+ end
@@ -0,0 +1,335 @@
1
+ require 'test/helper'
2
+
3
+ class Admin::SidebarHelperTest < ActiveSupport::TestCase
4
+
5
+ include Admin::SidebarHelper
6
+
7
+ include ActionView::Helpers::UrlHelper
8
+ include ActionController::UrlWriter
9
+ include ActionView::Helpers::TagHelper
10
+ include ActionView::Helpers::FormTagHelper
11
+
12
+ def setup
13
+ default_url_options[:host] = 'test.host'
14
+ end
15
+
16
+ def test_actions
17
+
18
+ self.expects(:default_actions).returns(['action1', 'action2'])
19
+ self.expects(:previous_and_next).returns(['previous', 'next'])
20
+ self.expects(:export).returns(['csv', 'pdf'])
21
+
22
+ output = actions
23
+ expected = <<-HTML
24
+ <h2>Actions</h2>
25
+ <ul>
26
+ <li>action1</li>
27
+ <li>action2</li>
28
+ </ul>
29
+
30
+ <h2>Go to</h2>
31
+ <ul>
32
+ <li>previous</li>
33
+ <li>next</li>
34
+ </ul>
35
+
36
+ <h2>Export</h2>
37
+ <ul>
38
+ <li>csv</li>
39
+ <li>pdf</li>
40
+ </ul>
41
+
42
+ HTML
43
+
44
+ assert_equal expected, output
45
+
46
+ end
47
+
48
+ def test_default_actions
49
+ assert true
50
+ end
51
+
52
+ def test_export
53
+
54
+ @resource = { :class => CustomUser }
55
+
56
+ params = { :controller => 'admin/custom_users', :action => 'index' }
57
+ self.expects(:params).at_least_once.returns(params)
58
+
59
+ output = export
60
+
61
+ expected = ["<a href=\"http://test.host/admin/custom_users.csv\">CSV</a>"]
62
+ assert_equal expected, output
63
+
64
+ end
65
+
66
+ def test_build_typus_list_with_empty_content_and_empty_header
67
+ output = build_typus_list([], :header => nil)
68
+ assert output.empty?
69
+ end
70
+
71
+ def test_build_typus_list_with_content_and_header
72
+ output = build_typus_list(['item1', 'item2'], :header => "Chunky Bacon")
73
+ assert !output.empty?
74
+ assert_match /Chunky bacon/, output
75
+ end
76
+
77
+ def test_build_typus_list_with_content_without_header
78
+ output = build_typus_list(['item1', 'item2'])
79
+ assert !output.empty?
80
+ assert_no_match /h2/, output
81
+ assert_no_match /\/h2/, output
82
+ end
83
+
84
+ def test_previous_and_next
85
+
86
+ params = { :controller => 'admin/typus_users', :action => 'index' }
87
+ self.expects(:params).at_least_once.returns(params)
88
+
89
+ output = previous_and_next
90
+ assert output.empty?
91
+
92
+ # Test when there are no records.
93
+
94
+ typus_user = TypusUser.first
95
+ @next = nil
96
+ @previous = nil
97
+
98
+ params = { :controller => 'admin/typus_users', :action => 'edit', :id => typus_user.id }
99
+ self.expects(:params).at_least_once.returns(params)
100
+
101
+ output = previous_and_next
102
+ assert output.empty?
103
+
104
+ # Test when we are on the first item.
105
+
106
+ typus_user = TypusUser.first
107
+ @previous, @next = typus_user.previous_and_next
108
+
109
+ output = previous_and_next
110
+ expected = [ "<a href=\"http://test.host/admin/typus_users/edit/#{@next.id}\">Next</a>" ]
111
+ assert_equal expected, output
112
+
113
+ # Test when we are on the last item.
114
+
115
+ typus_user = TypusUser.last
116
+ @previous, @next = typus_user.previous_and_next
117
+
118
+ output = previous_and_next
119
+ expected = [ "<a href=\"http://test.host/admin/typus_users/edit/#{@previous.id}\">Previous</a>" ]
120
+ assert_equal expected, output
121
+
122
+ # Test when we are on the middle.
123
+
124
+ typus_user = TypusUser.find(3)
125
+ @previous, @next = typus_user.previous_and_next
126
+
127
+ output = previous_and_next
128
+ expected = [ "<a href=\"http://test.host/admin/typus_users/edit/#{@next.id}\">Next</a>",
129
+ "<a href=\"http://test.host/admin/typus_users/edit/#{@previous.id}\">Previous</a>" ]
130
+ assert_equal expected, output
131
+
132
+ end
133
+
134
+ def test_previous_and_next_with_params
135
+ assert true
136
+ end
137
+
138
+ def test_search
139
+
140
+ @resource = { :class => TypusUser, :self => 'typus_users' }
141
+
142
+ params = { :controller => 'admin/typus_users', :action => 'index' }
143
+ self.expects(:params).at_least_once.returns(params)
144
+
145
+ output = search
146
+ expected = <<-HTML
147
+ <h2>Search</h2>
148
+ <form action="" method="get">
149
+ <p><input id="search" name="search" type="text" value=""/></p>
150
+ <input id="action" name="action" type="hidden" value="index" />
151
+ <input id="controller" name="controller" type="hidden" value="admin/typus_users" />
152
+ </form>
153
+ <p class="tip">Search by first name, last name, email, and role.</p>
154
+ HTML
155
+
156
+ assert_equal expected, output
157
+
158
+ end
159
+
160
+ def test_filters
161
+
162
+ @resource = { :class => TypusUser, :self => 'typus_users' }
163
+
164
+ @resource[:class].expects(:typus_filters).returns(Array.new)
165
+
166
+ output = filters
167
+ assert output.nil?
168
+
169
+ end
170
+
171
+ # TODO: Test filters when @resource[:class].typus_filters returns filters.
172
+ #
173
+ # Yes, I know, it's an ugly name for a test, but don't know how to
174
+ # name this test. Suggestions are welcome. ;)
175
+ def test_filters_with_filters
176
+ assert true
177
+ end
178
+
179
+ def test_relationship_filter
180
+ assert true
181
+ end
182
+
183
+ def test_datetime_filter
184
+
185
+ @resource = { :class => TypusUser, :self => 'typus_users' }
186
+ filter = 'created_at'
187
+
188
+ params = { :controller => 'admin/typus_users', :action => 'index' }
189
+ self.expects(:params).at_least_once.returns(params)
190
+
191
+ request = ''
192
+ output = datetime_filter(request, filter)
193
+ expected = <<-HTML
194
+ <h2>Created at</h2>
195
+ <ul>
196
+ <li><a href="http://test.host/admin/typus_users?created_at=today" class="off">Today</a></li>
197
+ <li><a href="http://test.host/admin/typus_users?created_at=past_7_days" class="off">Past 7 days</a></li>
198
+ <li><a href="http://test.host/admin/typus_users?created_at=this_month" class="off">This month</a></li>
199
+ <li><a href="http://test.host/admin/typus_users?created_at=this_year" class="off">This year</a></li>
200
+ </ul>
201
+ HTML
202
+ assert_equal expected, output
203
+
204
+ request = 'created_at=today&page=1'
205
+ output = datetime_filter(request, filter)
206
+ expected = <<-HTML
207
+ <h2>Created at</h2>
208
+ <ul>
209
+ <li><a href="http://test.host/admin/typus_users?created_at=today" class="on">Today</a></li>
210
+ <li><a href="http://test.host/admin/typus_users?created_at=past_7_days" class="off">Past 7 days</a></li>
211
+ <li><a href="http://test.host/admin/typus_users?created_at=this_month" class="off">This month</a></li>
212
+ <li><a href="http://test.host/admin/typus_users?created_at=this_year" class="off">This year</a></li>
213
+ </ul>
214
+ HTML
215
+ assert_equal expected, output
216
+
217
+ end
218
+
219
+ def test_boolean_filter
220
+
221
+ @resource = { :class => TypusUser, :self => 'typus_users' }
222
+ filter = 'status'
223
+
224
+ params = { :controller => 'admin/typus_users', :action => 'index' }
225
+ self.expects(:params).at_least_once.returns(params)
226
+
227
+ # Status is true
228
+
229
+ request = 'status=true&page=1'
230
+ output = boolean_filter(request, filter)
231
+ expected = <<-HTML
232
+ <h2>Status</h2>
233
+ <ul>
234
+ <li><a href="http://test.host/admin/typus_users?status=true" class="on">Active</a></li>
235
+ <li><a href="http://test.host/admin/typus_users?status=false" class="off">Inactive</a></li>
236
+ </ul>
237
+ HTML
238
+ assert_equal expected, output
239
+
240
+ # Status is false
241
+
242
+ request = 'status=false&page=1'
243
+ output = boolean_filter(request, filter)
244
+ expected = <<-HTML
245
+ <h2>Status</h2>
246
+ <ul>
247
+ <li><a href="http://test.host/admin/typus_users?status=true" class="off">Active</a></li>
248
+ <li><a href="http://test.host/admin/typus_users?status=false" class="on">Inactive</a></li>
249
+ </ul>
250
+ HTML
251
+ assert_equal expected, output
252
+
253
+ end
254
+
255
+ def test_string_filter_when_values_are_strings
256
+
257
+ @resource = { :class => TypusUser, :self => 'typus_users' }
258
+ filter = 'role'
259
+
260
+ params = { :controller => 'admin/typus_users', :action => 'index' }
261
+ self.expects(:params).at_least_once.returns(params)
262
+
263
+ # Roles is admin
264
+
265
+ request = 'role=admin&page=1'
266
+ @resource[:class].expects('role').returns(['admin', 'designer', 'editor'])
267
+ output = string_filter(request, filter)
268
+ expected = <<-HTML
269
+ <h2>Role</h2>
270
+ <ul>
271
+ <li><a href="http://test.host/admin/typus_users?role=admin" class="on">Admin</a></li>
272
+ <li><a href="http://test.host/admin/typus_users?role=designer" class="off">Designer</a></li>
273
+ <li><a href="http://test.host/admin/typus_users?role=editor" class="off">Editor</a></li>
274
+ </ul>
275
+ HTML
276
+ assert_equal expected, output
277
+
278
+ # Roles is editor
279
+
280
+ request = 'role=editor&page=1'
281
+ @resource[:class].expects('role').returns(['admin', 'designer', 'editor'])
282
+ output = string_filter(request, filter)
283
+ expected = <<-HTML
284
+ <h2>Role</h2>
285
+ <ul>
286
+ <li><a href="http://test.host/admin/typus_users?role=admin" class="off">Admin</a></li>
287
+ <li><a href="http://test.host/admin/typus_users?role=designer" class="off">Designer</a></li>
288
+ <li><a href="http://test.host/admin/typus_users?role=editor" class="on">Editor</a></li>
289
+ </ul>
290
+ HTML
291
+ assert_equal expected, output
292
+
293
+ end
294
+
295
+ def test_string_filter_when_values_are_arrays_of_strings
296
+
297
+ @resource = { :class => TypusUser, :self => 'typus_users' }
298
+ filter = 'role'
299
+
300
+ params = { :controller => 'admin/typus_users', :action => 'index' }
301
+ self.expects(:params).at_least_once.returns(params)
302
+
303
+ request = 'role=admin&page=1'
304
+ array = [['Administrador', 'admin'],
305
+ ['Diseñador', 'designer'],
306
+ ['Editor', 'editor']]
307
+ @resource[:class].expects('role').returns(array)
308
+
309
+ output = string_filter(request, filter)
310
+ expected = <<-HTML
311
+ <h2>Role</h2>
312
+ <ul>
313
+ <li><a href="http://test.host/admin/typus_users?role=admin" class="on">Administrador</a></li>
314
+ <li><a href="http://test.host/admin/typus_users?role=designer" class="off">Diseñador</a></li>
315
+ <li><a href="http://test.host/admin/typus_users?role=editor" class="off">Editor</a></li>
316
+ </ul>
317
+ HTML
318
+
319
+ assert_equal expected, output
320
+
321
+ end
322
+
323
+ def test_string_filter_when_empty_values
324
+
325
+ @resource = { :class => TypusUser }
326
+ filter = 'role'
327
+
328
+ request = 'role=admin&page=1'
329
+ @resource[:class].expects('role').returns([])
330
+ output = string_filter(request, filter)
331
+ assert output.empty?
332
+
333
+ end
334
+
335
+ end
@@ -0,0 +1,239 @@
1
+ require 'test/helper'
2
+
3
+ class Admin::TableHelperTest < ActiveSupport::TestCase
4
+
5
+ include Admin::TableHelper
6
+
7
+ include ActionView::Helpers::UrlHelper
8
+ include ActionController::UrlWriter
9
+
10
+ def test_build_typus_table
11
+ assert true
12
+ end
13
+
14
+ def test_typus_table_header
15
+
16
+ @current_user = mock()
17
+ @current_user.expects(:can_perform?).with(TypusUser, 'delete').returns(true)
18
+
19
+ fields = TypusUser.typus_fields_for(:list)
20
+
21
+ params = { :controller => 'admin/typus_users', :action => 'index' }
22
+ self.expects(:params).at_least_once.returns(params)
23
+
24
+ output = typus_table_header(TypusUser, fields)
25
+ expected = <<-HTML
26
+ <tr>
27
+ <th><a href="http://test.host/admin/typus_users?order_by=email"><div class="">Email</div></a></th>
28
+ <th><a href="http://test.host/admin/typus_users?order_by=role"><div class="">Role</div></a></th>
29
+ <th><a href="http://test.host/admin/typus_users?order_by=status"><div class="">Status</div></a></th>
30
+ <th>&nbsp;</th>
31
+ </tr>
32
+ HTML
33
+
34
+ assert_equal expected, output
35
+
36
+ end
37
+
38
+ def test_typus_table_header_with_params
39
+
40
+ @current_user = mock()
41
+ @current_user.expects(:can_perform?).with(TypusUser, 'delete').returns(true)
42
+
43
+ fields = TypusUser.typus_fields_for(:list)
44
+
45
+ params = { :controller => 'admin/typus_users', :action => 'index', :search => 'admin' }
46
+ self.expects(:params).at_least_once.returns(params)
47
+
48
+ output = typus_table_header(TypusUser, fields)
49
+ expected = <<-HTML
50
+ <tr>
51
+ <th><a href="http://test.host/admin/typus_users?order_by=email&search=admin"><div class="">Email</div></a></th>
52
+ <th><a href="http://test.host/admin/typus_users?order_by=role&search=admin"><div class="">Role</div></a></th>
53
+ <th><a href="http://test.host/admin/typus_users?order_by=status&search=admin"><div class="">Status</div></a></th>
54
+ <th>&nbsp;</th>
55
+ </tr>
56
+ HTML
57
+
58
+ assert_equal expected, output
59
+
60
+ end
61
+
62
+ def test_typus_table_header_when_user_cannot_delete_items
63
+
64
+ @current_user = mock()
65
+ @current_user.expects(:can_perform?).with(TypusUser, 'delete').returns(false)
66
+
67
+ fields = TypusUser.typus_fields_for(:list)
68
+
69
+ params = { :controller => 'admin/typus_users', :action => 'index' }
70
+ self.expects(:params).at_least_once.returns(params)
71
+
72
+ output = typus_table_header(TypusUser, fields)
73
+ expected = <<-HTML
74
+ <tr>
75
+ <th><a href="http://test.host/admin/typus_users?order_by=email"><div class="">Email</div></a></th>
76
+ <th><a href="http://test.host/admin/typus_users?order_by=role"><div class="">Role</div></a></th>
77
+ <th><a href="http://test.host/admin/typus_users?order_by=status"><div class="">Status</div></a></th>
78
+ </tr>
79
+ HTML
80
+
81
+ assert_equal expected, output
82
+
83
+ end
84
+
85
+ def test_typus_table_header_when_user_cannot_delete_items_with_params
86
+
87
+ @current_user = mock()
88
+ @current_user.expects(:can_perform?).with(TypusUser, 'delete').returns(false)
89
+
90
+ fields = TypusUser.typus_fields_for(:list)
91
+
92
+ params = { :controller => 'admin/typus_users', :action => 'index', :search => 'admin' }
93
+ self.expects(:params).at_least_once.returns(params)
94
+
95
+ output = typus_table_header(TypusUser, fields)
96
+ expected = <<-HTML
97
+ <tr>
98
+ <th><a href="http://test.host/admin/typus_users?order_by=email&search=admin"><div class="">Email</div></a></th>
99
+ <th><a href="http://test.host/admin/typus_users?order_by=role&search=admin"><div class="">Role</div></a></th>
100
+ <th><a href="http://test.host/admin/typus_users?order_by=status&search=admin"><div class="">Status</div></a></th>
101
+ </tr>
102
+ HTML
103
+
104
+ assert_equal expected, output
105
+
106
+ end
107
+
108
+ def test_typus_table_belongs_to_field
109
+
110
+ comment = comments(:without_post_id)
111
+ output = typus_table_belongs_to_field('post', comment)
112
+ expected = <<-HTML
113
+ <td></td>
114
+ HTML
115
+
116
+ assert_equal expected, output
117
+ default_url_options[:host] = 'test.host'
118
+
119
+ comment = comments(:with_post_id)
120
+ output = typus_table_belongs_to_field('post', comment)
121
+ expected = <<-HTML
122
+ <td><a href="http://test.host/admin/posts/edit/1">Post#1</a></td>
123
+ HTML
124
+
125
+ assert_equal expected, output
126
+
127
+ end
128
+
129
+ def test_typus_table_has_and_belongs_to_many_field
130
+
131
+ post = Post.find(1)
132
+
133
+ output = typus_table_has_and_belongs_to_many_field('comments', post)
134
+ expected = <<-HTML
135
+ <td>John<br />Me<br />Me</td>
136
+ HTML
137
+
138
+ assert_equal expected, output
139
+
140
+ end
141
+
142
+ def test_typus_table_string_field
143
+
144
+ post = posts(:published)
145
+ output = typus_table_string_field(:title, post, :created_at)
146
+ expected = <<-HTML
147
+ <td>#{post.title}</td>
148
+ HTML
149
+
150
+ assert_equal expected, output
151
+
152
+ end
153
+
154
+ def test_typus_table_string_field_with_link
155
+
156
+ post = posts(:published)
157
+ output = typus_table_string_field(:title, post, :title)
158
+ expected = <<-HTML
159
+ <td><a href="http://test.host/admin/posts/edit/#{post.id}">#{post.title}</a></td>
160
+ HTML
161
+
162
+ assert_equal expected, output
163
+
164
+ end
165
+
166
+ def test_typus_table_tree_field
167
+
168
+ return if !defined?(ActiveRecord::Acts::Tree)
169
+
170
+ page = pages(:published)
171
+ output = typus_table_tree_field('test', page)
172
+ expected = <<-HTML
173
+ <td></td>
174
+ HTML
175
+
176
+ assert_equal expected, output
177
+
178
+ page = pages(:unpublished)
179
+ output = typus_table_tree_field('test', page)
180
+ expected = <<-HTML
181
+ <td>Page#1</td>
182
+ HTML
183
+
184
+ assert_equal expected, output
185
+
186
+ end
187
+
188
+ def test_typus_table_datetime_field
189
+
190
+ post = posts(:published)
191
+ Time::DATE_FORMATS[:post_short] = '%m/%y'
192
+
193
+ output = typus_table_datetime_field(:created_at, post)
194
+ expected = <<-HTML
195
+ <td>#{post.created_at.strftime('%m/%y')}</td>
196
+ HTML
197
+
198
+ assert_equal expected, output
199
+
200
+ end
201
+
202
+ def test_typus_table_datetime_field_with_link
203
+
204
+ post = posts(:published)
205
+ Time::DATE_FORMATS[:post_short] = '%m/%y'
206
+
207
+ output = typus_table_datetime_field(:created_at, post, :created_at)
208
+ expected = <<-HTML
209
+ <td><a href="http://test.host/admin/posts/edit/#{post.id}">#{post.created_at.strftime('%m/%y')}</a></td>
210
+ HTML
211
+
212
+ assert_equal expected, output
213
+
214
+ end
215
+
216
+ def test_typus_table_boolean_field
217
+
218
+ options = { :icon_on_boolean => false, :toggle => false }
219
+ Typus::Configuration.stubs(:options).returns(options)
220
+
221
+ post = posts(:published)
222
+ output = typus_table_boolean_field('status', post)
223
+ expected = <<-HTML
224
+ <td align="center">True</td>
225
+ HTML
226
+
227
+ assert_equal expected, output
228
+
229
+ post = posts(:unpublished)
230
+ output = typus_table_boolean_field('status', post)
231
+ expected = <<-HTML
232
+ <td align="center">False</td>
233
+ HTML
234
+
235
+ assert_equal expected, output
236
+
237
+ end
238
+
239
+ end