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,65 @@
1
+ require 'test/helper'
2
+
3
+ class Admin::MasterHelperTest < ActiveSupport::TestCase
4
+
5
+ include Admin::MasterHelper
6
+
7
+ include ActionView::Helpers::UrlHelper
8
+ include ActionView::Helpers::TagHelper
9
+
10
+ def test_display_link_to_previous
11
+
12
+ output = display_link_to_previous(Post, { :action => 'edit', :back_to => '/back_to_param' })
13
+ expected = <<-HTML
14
+ <div id="flash" class="notice">
15
+ <p>You're updating a Post. <a href="/back_to_param">Do you want to cancel it?</a></p>
16
+ </div>
17
+ HTML
18
+
19
+ assert_equal expected, output
20
+
21
+ end
22
+
23
+ def test_remove_filter_link
24
+ output = remove_filter_link('')
25
+ assert output.nil?
26
+ end
27
+
28
+ def test_build_list_when_returns_a_typus_table
29
+
30
+ model = TypusUser
31
+ fields = [ 'email', 'role', 'status' ]
32
+ items = TypusUser.find(:all)
33
+ resource = 'typus_users'
34
+
35
+ self.stubs(:build_typus_table).returns('a_list_with_items')
36
+
37
+ output = build_list(model, fields, items, resource)
38
+ expected = 'a_list_with_items'
39
+
40
+ assert_equal expected, output
41
+
42
+ end
43
+
44
+ def test_build_list_when_returns_a_template
45
+
46
+ model = TypusUser
47
+ fields = [ 'email', 'role', 'status' ]
48
+ items = TypusUser.find(:all)
49
+ resource = 'typus_users'
50
+
51
+ self.stubs(:render).returns('a_template')
52
+ File.stubs(:exists?).returns(true)
53
+
54
+ output = build_list(model, fields, items, resource)
55
+ expected = 'a_template'
56
+
57
+ assert_equal expected, output
58
+
59
+ end
60
+
61
+ def test_build_pagination
62
+ assert true
63
+ end
64
+
65
+ end
@@ -0,0 +1,22 @@
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 = { :color => 'CC0000', :link => 'quick_edit', :resource => 'posts', :id => '1', :action => 'edit' }
10
+ output = quick_edit(options)
11
+
12
+ html = <<-HTML
13
+ <script type="text/javascript">
14
+ document.write('<script type="text/javascript" src="quick_edit?action=edit&id=1&resource=posts" />');
15
+ </script>
16
+ HTML
17
+
18
+ assert_equal html, output
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,351 @@
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
+ self.expects(:modules).with('parent_module').returns(['parent_module'])
22
+ self.expects(:modules).with('submodules').returns(['submodules'])
23
+
24
+ output = actions
25
+ expected = <<-HTML
26
+ <h2>Actions</h2>
27
+ <ul>
28
+ <li>action1</li>
29
+ <li>action2</li>
30
+ </ul>
31
+
32
+ <h2>Go to</h2>
33
+ <ul>
34
+ <li>previous</li>
35
+ <li>next</li>
36
+ </ul>
37
+
38
+ <h2>Export</h2>
39
+ <ul>
40
+ <li>csv</li>
41
+ <li>pdf</li>
42
+ </ul>
43
+
44
+ <h2>Parent module</h2>
45
+ <ul>
46
+ <li>parent_module</li>
47
+ </ul>
48
+
49
+ <h2>Submodules</h2>
50
+ <ul>
51
+ <li>submodules</li>
52
+ </ul>
53
+
54
+ HTML
55
+
56
+ assert_equal expected, output
57
+
58
+ end
59
+
60
+ def test_default_actions
61
+ assert true
62
+ end
63
+
64
+ def test_export
65
+
66
+ @resource = { :class => CustomUser }
67
+
68
+ params = { :controller => 'admin/custom_users', :action => 'index' }
69
+ self.expects(:params).at_least_once.returns(params)
70
+
71
+ output = export
72
+ expected = ["<a href=\"http://test.host/admin/custom_users.csv\">CSV</a>"]
73
+
74
+ assert_equal expected, output
75
+
76
+ end
77
+
78
+ def test_build_typus_list_with_empty_content_and_empty_header
79
+ output = build_typus_list([], :header => nil)
80
+ assert output.empty?
81
+ end
82
+
83
+ def test_build_typus_list_with_content_and_header
84
+ output = build_typus_list(['item1', 'item2'], :header => "Chunky Bacon")
85
+ assert !output.empty?
86
+ assert_match /Chunky bacon/, output
87
+ end
88
+
89
+ def test_build_typus_list_with_content_without_header
90
+ output = build_typus_list(['item1', 'item2'])
91
+ assert !output.empty?
92
+ assert_no_match /h2/, output
93
+ assert_no_match /\/h2/, output
94
+ end
95
+
96
+ def test_modules
97
+ assert true
98
+ end
99
+
100
+ def test_previous_and_next
101
+
102
+ params = { :controller => 'admin/typus_users', :action => 'index' }
103
+ self.expects(:params).at_least_once.returns(params)
104
+
105
+ output = previous_and_next
106
+ assert output.empty?
107
+
108
+ # Test when there are no records.
109
+
110
+ typus_user = TypusUser.first
111
+ @next = nil
112
+ @previous = nil
113
+
114
+ params = { :controller => 'admin/typus_users', :action => 'edit', :id => typus_user.id }
115
+ self.expects(:params).at_least_once.returns(params)
116
+
117
+ output = previous_and_next
118
+ assert output.empty?
119
+
120
+ # Test when we are on the first item.
121
+
122
+ typus_user = TypusUser.first
123
+ @previous, @next = typus_user.previous_and_next
124
+
125
+ output = previous_and_next
126
+ expected = [ "<a href=\"http://test.host/admin/typus_users/edit/#{@next.id}\">Next</a>" ]
127
+ assert_equal expected, output
128
+
129
+ # Test when we are on the last item.
130
+
131
+ typus_user = TypusUser.last
132
+ @previous, @next = typus_user.previous_and_next
133
+
134
+ output = previous_and_next
135
+ expected = [ "<a href=\"http://test.host/admin/typus_users/edit/#{@previous.id}\">Previous</a>" ]
136
+ assert_equal expected, output
137
+
138
+ # Test when we are on the middle.
139
+
140
+ typus_user = TypusUser.find(3)
141
+ @previous, @next = typus_user.previous_and_next
142
+
143
+ output = previous_and_next
144
+ expected = [ "<a href=\"http://test.host/admin/typus_users/edit/#{@next.id}\">Next</a>",
145
+ "<a href=\"http://test.host/admin/typus_users/edit/#{@previous.id}\">Previous</a>" ]
146
+ assert_equal expected, output
147
+
148
+ end
149
+
150
+ def test_previous_and_next_with_params
151
+ assert true
152
+ end
153
+
154
+ def test_search
155
+
156
+ @resource = { :class => TypusUser, :self => 'typus_users' }
157
+
158
+ params = { :controller => 'admin/typus_users', :action => 'index' }
159
+ self.expects(:params).at_least_once.returns(params)
160
+
161
+ output = search
162
+ expected = <<-HTML
163
+ <h2>Search</h2>
164
+ <form action="" method="get">
165
+ <p><input id="search" name="search" type="text" value=""/></p>
166
+ <input id="action" name="action" type="hidden" value="index" />
167
+ <input id="controller" name="controller" type="hidden" value="admin/typus_users" />
168
+ </form>
169
+ <p class="tip">Search by first name, last name, email, and role.</p>
170
+ HTML
171
+
172
+ assert_equal expected, output
173
+
174
+ end
175
+
176
+ def test_filters
177
+
178
+ @resource = { :class => TypusUser, :self => 'typus_users' }
179
+
180
+ @resource[:class].expects(:typus_filters).returns(Array.new)
181
+
182
+ output = filters
183
+ assert output.nil?
184
+
185
+ end
186
+
187
+ # TODO: Test filters when @resource[:class].typus_filters returns filters.
188
+ #
189
+ # Yes, I know, it's an ugly name for a test, but don't know how to
190
+ # name this test. Suggestions are welcome. ;)
191
+ def test_filters_with_filters
192
+ assert true
193
+ end
194
+
195
+ def test_relationship_filter
196
+ assert true
197
+ end
198
+
199
+ def test_datetime_filter
200
+
201
+ @resource = { :class => TypusUser, :self => 'typus_users' }
202
+ filter = 'created_at'
203
+
204
+ params = { :controller => 'admin/typus_users', :action => 'index' }
205
+ self.expects(:params).at_least_once.returns(params)
206
+
207
+ request = ''
208
+ output = datetime_filter(request, filter)
209
+ expected = <<-HTML
210
+ <h2>Created at</h2>
211
+ <ul>
212
+ <li><a href="http://test.host/admin/typus_users?created_at=today" class="off">Today</a></li>
213
+ <li><a href="http://test.host/admin/typus_users?created_at=past_7_days" class="off">Past 7 days</a></li>
214
+ <li><a href="http://test.host/admin/typus_users?created_at=this_month" class="off">This month</a></li>
215
+ <li><a href="http://test.host/admin/typus_users?created_at=this_year" class="off">This year</a></li>
216
+ </ul>
217
+ HTML
218
+ assert_equal expected, output
219
+
220
+ request = 'created_at=today&page=1'
221
+ output = datetime_filter(request, filter)
222
+ expected = <<-HTML
223
+ <h2>Created at</h2>
224
+ <ul>
225
+ <li><a href="http://test.host/admin/typus_users?created_at=today" class="on">Today</a></li>
226
+ <li><a href="http://test.host/admin/typus_users?created_at=past_7_days" class="off">Past 7 days</a></li>
227
+ <li><a href="http://test.host/admin/typus_users?created_at=this_month" class="off">This month</a></li>
228
+ <li><a href="http://test.host/admin/typus_users?created_at=this_year" class="off">This year</a></li>
229
+ </ul>
230
+ HTML
231
+ assert_equal expected, output
232
+
233
+ end
234
+
235
+ def test_boolean_filter
236
+
237
+ @resource = { :class => TypusUser, :self => 'typus_users' }
238
+ filter = 'status'
239
+
240
+ params = { :controller => 'admin/typus_users', :action => 'index' }
241
+ self.expects(:params).at_least_once.returns(params)
242
+
243
+ # Status is true
244
+
245
+ request = 'status=true&page=1'
246
+ output = boolean_filter(request, filter)
247
+ expected = <<-HTML
248
+ <h2>Status</h2>
249
+ <ul>
250
+ <li><a href="http://test.host/admin/typus_users?status=true" class="on">Active</a></li>
251
+ <li><a href="http://test.host/admin/typus_users?status=false" class="off">Inactive</a></li>
252
+ </ul>
253
+ HTML
254
+ assert_equal expected, output
255
+
256
+ # Status is false
257
+
258
+ request = 'status=false&page=1'
259
+ output = boolean_filter(request, filter)
260
+ expected = <<-HTML
261
+ <h2>Status</h2>
262
+ <ul>
263
+ <li><a href="http://test.host/admin/typus_users?status=true" class="off">Active</a></li>
264
+ <li><a href="http://test.host/admin/typus_users?status=false" class="on">Inactive</a></li>
265
+ </ul>
266
+ HTML
267
+ assert_equal expected, output
268
+
269
+ end
270
+
271
+ def test_string_filter_when_values_are_strings
272
+
273
+ @resource = { :class => TypusUser, :self => 'typus_users' }
274
+ filter = 'role'
275
+
276
+ params = { :controller => 'admin/typus_users', :action => 'index' }
277
+ self.expects(:params).at_least_once.returns(params)
278
+
279
+ # Roles is admin
280
+
281
+ request = 'role=admin&page=1'
282
+ @resource[:class].expects('role').returns(['admin', 'designer', 'editor'])
283
+ output = string_filter(request, filter)
284
+ expected = <<-HTML
285
+ <h2>Role</h2>
286
+ <ul>
287
+ <li><a href="http://test.host/admin/typus_users?role=admin" class="on">Admin</a></li>
288
+ <li><a href="http://test.host/admin/typus_users?role=designer" class="off">Designer</a></li>
289
+ <li><a href="http://test.host/admin/typus_users?role=editor" class="off">Editor</a></li>
290
+ </ul>
291
+ HTML
292
+ assert_equal expected, output
293
+
294
+ # Roles is editor
295
+
296
+ request = 'role=editor&page=1'
297
+ @resource[:class].expects('role').returns(['admin', 'designer', 'editor'])
298
+ output = string_filter(request, filter)
299
+ expected = <<-HTML
300
+ <h2>Role</h2>
301
+ <ul>
302
+ <li><a href="http://test.host/admin/typus_users?role=admin" class="off">Admin</a></li>
303
+ <li><a href="http://test.host/admin/typus_users?role=designer" class="off">Designer</a></li>
304
+ <li><a href="http://test.host/admin/typus_users?role=editor" class="on">Editor</a></li>
305
+ </ul>
306
+ HTML
307
+ assert_equal expected, output
308
+
309
+ end
310
+
311
+ def test_string_filter_when_values_are_arrays_of_strings
312
+
313
+ @resource = { :class => TypusUser, :self => 'typus_users' }
314
+ filter = 'role'
315
+
316
+ params = { :controller => 'admin/typus_users', :action => 'index' }
317
+ self.expects(:params).at_least_once.returns(params)
318
+
319
+ request = 'role=admin&page=1'
320
+ array = [['Administrador', 'admin'],
321
+ ['Diseñador', 'designer'],
322
+ ['Editor', 'editor']]
323
+ @resource[:class].expects('role').returns(array)
324
+
325
+ output = string_filter(request, filter)
326
+ expected = <<-HTML
327
+ <h2>Role</h2>
328
+ <ul>
329
+ <li><a href="http://test.host/admin/typus_users?role=admin" class="on">Administrador</a></li>
330
+ <li><a href="http://test.host/admin/typus_users?role=designer" class="off">Diseñador</a></li>
331
+ <li><a href="http://test.host/admin/typus_users?role=editor" class="off">Editor</a></li>
332
+ </ul>
333
+ HTML
334
+
335
+ assert_equal expected, output
336
+
337
+ end
338
+
339
+ def test_string_filter_when_empty_values
340
+
341
+ @resource = { :class => TypusUser }
342
+ filter = 'role'
343
+
344
+ request = 'role=admin&page=1'
345
+ @resource[:class].expects('role').returns([])
346
+ output = string_filter(request, filter)
347
+ assert output.empty?
348
+
349
+ end
350
+
351
+ end
@@ -0,0 +1,255 @@
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
+ =begin
189
+
190
+ # FIXME
191
+
192
+ def test_typus_table_position_field
193
+
194
+ category = categories(:first)
195
+ output = typus_table_position_field('position', category)
196
+ expected = ""
197
+
198
+ assert_equal expected, output
199
+
200
+ end
201
+
202
+ =end
203
+
204
+ def test_typus_table_datetime_field
205
+
206
+ post = posts(:published)
207
+ Time::DATE_FORMATS[:post_short] = '%m/%y'
208
+
209
+ output = typus_table_datetime_field(:created_at, post)
210
+ expected = <<-HTML
211
+ <td>#{post.created_at.strftime('%m/%y')}</td>
212
+ HTML
213
+
214
+ assert_equal expected, output
215
+
216
+ end
217
+
218
+ def test_typus_table_datetime_field_with_link
219
+
220
+ post = posts(:published)
221
+ Time::DATE_FORMATS[:post_short] = '%m/%y'
222
+
223
+ output = typus_table_datetime_field(:created_at, post, :created_at)
224
+ expected = <<-HTML
225
+ <td><a href="http://test.host/admin/posts/edit/#{post.id}">#{post.created_at.strftime('%m/%y')}</a></td>
226
+ HTML
227
+
228
+ assert_equal expected, output
229
+
230
+ end
231
+
232
+ def test_typus_table_boolean_field
233
+
234
+ options = { :icon_on_boolean => false, :toggle => false }
235
+ Typus::Configuration.stubs(:options).returns(options)
236
+
237
+ post = posts(:published)
238
+ output = typus_table_boolean_field(:status, post)
239
+ expected = <<-HTML
240
+ <td align="center">True</td>
241
+ HTML
242
+
243
+ assert_equal expected, output
244
+
245
+ post = posts(:unpublished)
246
+ output = typus_table_boolean_field(:status, post)
247
+ expected = <<-HTML
248
+ <td align="center">False</td>
249
+ HTML
250
+
251
+ assert_equal expected, output
252
+
253
+ end
254
+
255
+ end