typus 0.9.17
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.
- data/.gitignore +8 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +86 -0
- data/Rakefile +61 -0
- data/VERSION +1 -0
- data/app/controllers/admin/master_controller.rb +354 -0
- data/app/controllers/typus_controller.rb +128 -0
- data/app/helpers/admin/form_helper.rb +386 -0
- data/app/helpers/admin/master_helper.rb +104 -0
- data/app/helpers/admin/public_helper.rb +27 -0
- data/app/helpers/admin/sidebar_helper.rb +236 -0
- data/app/helpers/admin/table_helper.rb +227 -0
- data/app/helpers/typus_helper.rb +194 -0
- data/app/models/typus_mailer.rb +14 -0
- data/app/models/typus_user.rb +5 -0
- data/app/views/admin/dashboard/_sidebar.html.erb +9 -0
- data/app/views/admin/resources/edit.html.erb +24 -0
- data/app/views/admin/resources/index.html.erb +23 -0
- data/app/views/admin/resources/new.html.erb +22 -0
- data/app/views/admin/resources/show.html.erb +18 -0
- data/app/views/admin/shared/_footer.html.erb +1 -0
- data/app/views/admin/shared/_pagination.html.erb +28 -0
- data/app/views/layouts/admin.html.erb +73 -0
- data/app/views/layouts/typus.html.erb +29 -0
- data/app/views/typus/dashboard.html.erb +9 -0
- data/app/views/typus/recover_password.html.erb +7 -0
- data/app/views/typus/reset_password.html.erb +15 -0
- data/app/views/typus/sign_in.html.erb +9 -0
- data/app/views/typus/sign_up.html.erb +7 -0
- data/app/views/typus_mailer/reset_password_link.erb +11 -0
- data/config/locales/typus/de.yml +109 -0
- data/config/locales/typus/es.yml +109 -0
- data/config/locales/typus/language.yml.template +113 -0
- data/config/locales/typus/pt-BR.yml +111 -0
- data/config/locales/typus/ru.yml +111 -0
- data/generators/typus/templates/config/initializers/typus.rb +33 -0
- data/generators/typus/templates/config/typus/README +51 -0
- data/generators/typus/templates/config/typus/application.yml +6 -0
- data/generators/typus/templates/config/typus/application_roles.yml +23 -0
- data/generators/typus/templates/config/typus/typus.yml +14 -0
- data/generators/typus/templates/config/typus/typus_roles.yml +2 -0
- data/generators/typus/templates/db/create_typus_users.rb +21 -0
- data/generators/typus/templates/public/images/admin/arrow_down.gif +0 -0
- data/generators/typus/templates/public/images/admin/arrow_up.gif +0 -0
- data/generators/typus/templates/public/images/admin/spinner.gif +0 -0
- data/generators/typus/templates/public/images/admin/status_false.gif +0 -0
- data/generators/typus/templates/public/images/admin/status_true.gif +0 -0
- data/generators/typus/templates/public/images/admin/trash.gif +0 -0
- data/generators/typus/templates/public/javascripts/admin/application.js +14 -0
- data/generators/typus/templates/public/stylesheets/admin/reset.css +68 -0
- data/generators/typus/templates/public/stylesheets/admin/screen.css +729 -0
- data/generators/typus/typus_generator.rb +122 -0
- data/generators/typus_update_schema_to_01/templates/config/typus.yml +14 -0
- data/generators/typus_update_schema_to_01/templates/migration.rb +11 -0
- data/generators/typus_update_schema_to_01/typus_update_schema_to_01_generator.rb +19 -0
- data/lib/typus.rb +122 -0
- data/lib/typus/active_record.rb +307 -0
- data/lib/typus/authentication.rb +142 -0
- data/lib/typus/configuration.rb +85 -0
- data/lib/typus/extensions/routes.rb +15 -0
- data/lib/typus/format.rb +55 -0
- data/lib/typus/generator.rb +81 -0
- data/lib/typus/hash.rb +8 -0
- data/lib/typus/locale.rb +17 -0
- data/lib/typus/object.rb +21 -0
- data/lib/typus/quick_edit.rb +40 -0
- data/lib/typus/reloader.rb +15 -0
- data/lib/typus/string.rb +11 -0
- data/lib/typus/templates/index.html.erb +11 -0
- data/lib/typus/templates/resource_controller.rb.erb +15 -0
- data/lib/typus/templates/resource_controller_test.rb.erb +10 -0
- data/lib/typus/templates/resources_controller.rb.erb +37 -0
- data/lib/typus/user.rb +134 -0
- data/lib/vendor/active_record.rb +15 -0
- data/lib/vendor/paginator.rb +143 -0
- data/rails/init.rb +3 -0
- data/tasks/typus_tasks.rake +32 -0
- data/test/config/broken/application.yml +68 -0
- data/test/config/broken/application_roles.yml +20 -0
- data/test/config/broken/empty.yml +0 -0
- data/test/config/broken/empty_roles.yml +0 -0
- data/test/config/broken/undefined.yml +3 -0
- data/test/config/broken/undefined_roles.yml +6 -0
- data/test/config/default/typus.yml +14 -0
- data/test/config/default/typus_roles.yml +2 -0
- data/test/config/empty/empty_01.yml +0 -0
- data/test/config/empty/empty_01_roles.yml +0 -0
- data/test/config/empty/empty_02.yml +0 -0
- data/test/config/empty/empty_02_roles.yml +0 -0
- data/test/config/locales/es.yml +10 -0
- data/test/config/ordered/001_roles.yml +2 -0
- data/test/config/ordered/002_roles.yml +2 -0
- data/test/config/unordered/app_one_roles.yml +2 -0
- data/test/config/unordered/app_two_roles.yml +2 -0
- data/test/config/working/application.yml +68 -0
- data/test/config/working/application_roles.yml +22 -0
- data/test/config/working/typus.yml +14 -0
- data/test/config/working/typus_roles.yml +2 -0
- data/test/fixtures/app/controllers/admin/assets_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/categories_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/comments_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/pages_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/posts_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/status_controller.rb +6 -0
- data/test/fixtures/app/controllers/admin/typus_users_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/watch_dog_controller.rb +6 -0
- data/test/fixtures/app/views/admin/comments/_edit.html.erb +1 -0
- data/test/fixtures/app/views/admin/comments/_index.html.erb +1 -0
- data/test/fixtures/app/views/admin/comments/_new.html.erb +1 -0
- data/test/fixtures/app/views/admin/comments/_show.html.erb +1 -0
- data/test/fixtures/app/views/admin/comments/_sidebar.html.erb +1 -0
- data/test/fixtures/app/views/admin/dashboard/_content.html.erb +1 -0
- data/test/fixtures/app/views/admin/dashboard/_sidebar.html.erb +1 -0
- data/test/fixtures/app/views/admin/resources/_sidebar.html.erb +1 -0
- data/test/fixtures/app/views/admin/shared/_footer.html.erb +1 -0
- data/test/fixtures/app/views/admin/status/index.html.erb +1 -0
- data/test/fixtures/app/views/admin/templates/_datepicker.html.erb +1 -0
- data/test/fixtures/assets.yml +11 -0
- data/test/fixtures/categories.yml +14 -0
- data/test/fixtures/comments.yml +27 -0
- data/test/fixtures/pages.yml +41 -0
- data/test/fixtures/posts.yml +37 -0
- data/test/fixtures/typus_users.yml +54 -0
- data/test/functional/admin/assets_controller_test.rb +57 -0
- data/test/functional/admin/categories_controller_test.rb +106 -0
- data/test/functional/admin/comments_controller_test.rb +120 -0
- data/test/functional/admin/master_controller_test.rb +5 -0
- data/test/functional/admin/posts_controller_test.rb +261 -0
- data/test/functional/admin/status_controller_test.rb +43 -0
- data/test/functional/admin/typus_users_controller_test.rb +239 -0
- data/test/functional/typus_controller_test.rb +321 -0
- data/test/helper.rb +51 -0
- data/test/helpers/admin/form_helper_test.rb +337 -0
- data/test/helpers/admin/master_helper_test.rb +69 -0
- data/test/helpers/admin/public_helper_test.rb +26 -0
- data/test/helpers/admin/sidebar_helper_test.rb +335 -0
- data/test/helpers/admin/table_helper_test.rb +239 -0
- data/test/helpers/typus_helper_test.rb +117 -0
- data/test/lib/active_record_test.rb +382 -0
- data/test/lib/configuration_test.rb +94 -0
- data/test/lib/hash_test.rb +11 -0
- data/test/lib/routes_test.rb +71 -0
- data/test/lib/string_test.rb +25 -0
- data/test/lib/typus_test.rb +85 -0
- data/test/models.rb +51 -0
- data/test/schema.rb +64 -0
- data/test/unit/typus_mailer_test.rb +33 -0
- data/test/unit/typus_test.rb +17 -0
- data/test/unit/typus_user_roles_test.rb +90 -0
- data/test/unit/typus_user_test.rb +177 -0
- data/test/vendor/active_record_test.rb +18 -0
- data/test/vendor/paginator_test.rb +136 -0
- data/typus.gemspec +228 -0
- metadata +241 -0
data/test/helper.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
|
|
2
|
+
ENV['RAILS_ENV'] = 'test'
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
|
|
4
|
+
require 'test_help'
|
|
5
|
+
require 'mocha'
|
|
6
|
+
|
|
7
|
+
begin
|
|
8
|
+
require 'redgreen'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
##
|
|
13
|
+
# Different DB settings and load our schema.
|
|
14
|
+
#
|
|
15
|
+
|
|
16
|
+
connection = case ENV['DB']
|
|
17
|
+
when /mysql/
|
|
18
|
+
{ :adapter => 'mysql', :username => 'root', :database => 'typus_test' }
|
|
19
|
+
when /postgresql/
|
|
20
|
+
{ :adapter => 'postgresql', :encoding => 'unicode', :database => 'typus_test' }
|
|
21
|
+
else
|
|
22
|
+
{ :adapter => 'sqlite3', :dbfile => ':memory:' }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
ActiveRecord::Base.establish_connection(connection)
|
|
26
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
|
|
27
|
+
|
|
28
|
+
require File.dirname(__FILE__) + '/schema'
|
|
29
|
+
|
|
30
|
+
##
|
|
31
|
+
# To test the plugin without touching the application we set our
|
|
32
|
+
# load_paths and view_paths.
|
|
33
|
+
#
|
|
34
|
+
|
|
35
|
+
ActiveSupport::Dependencies.load_paths = []
|
|
36
|
+
%w( models controllers helpers ).each do |folder|
|
|
37
|
+
ActiveSupport::Dependencies.load_paths << File.join(Typus.root, 'app', folder)
|
|
38
|
+
ActiveSupport::Dependencies.load_paths << File.join(Typus.root, 'test', 'fixtures', 'app', folder)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
ActionController::Base.view_paths = []
|
|
42
|
+
%w( app/views test/fixtures/app/views ).each do |folder|
|
|
43
|
+
ActionController::Base.append_view_path(File.join(Typus.root, folder))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
class ActiveSupport::TestCase
|
|
47
|
+
self.fixture_path = File.dirname(__FILE__) + '/fixtures'
|
|
48
|
+
self.use_transactional_fixtures = true
|
|
49
|
+
self.use_instantiated_fixtures = false
|
|
50
|
+
fixtures :all
|
|
51
|
+
end
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
require 'test/helper'
|
|
2
|
+
|
|
3
|
+
class Admin::FormHelperTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
include Admin::FormHelper
|
|
6
|
+
include Admin::MasterHelper
|
|
7
|
+
|
|
8
|
+
include ActionView::Helpers::FormHelper
|
|
9
|
+
include ActionView::Helpers::FormOptionsHelper
|
|
10
|
+
include ActionView::Helpers::DateHelper
|
|
11
|
+
include ActionView::Helpers::UrlHelper
|
|
12
|
+
include ActionView::Helpers::TagHelper
|
|
13
|
+
include ActionController::UrlWriter
|
|
14
|
+
|
|
15
|
+
def test_build_form
|
|
16
|
+
assert true
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_typus_belongs_to_field
|
|
20
|
+
|
|
21
|
+
params = { :controller => 'admin/post', :id => 1, :action => :create }
|
|
22
|
+
self.expects(:params).at_least_once.returns(params)
|
|
23
|
+
|
|
24
|
+
@current_user = mock()
|
|
25
|
+
@current_user.expects(:can_perform?).with(Post, 'create').returns(false)
|
|
26
|
+
@resource = { :class => Comment }
|
|
27
|
+
|
|
28
|
+
expected = <<-HTML
|
|
29
|
+
<li><label for="item_post">Post
|
|
30
|
+
<small></small>
|
|
31
|
+
</label>
|
|
32
|
+
<select id="item_post_id" name="item[post_id]"><option value=""></option>
|
|
33
|
+
<option value="3">Post#3</option>
|
|
34
|
+
<option value="4">Post#4</option>
|
|
35
|
+
<option value="1">Post#1</option>
|
|
36
|
+
<option value="2">Post#2</option></select></li>
|
|
37
|
+
HTML
|
|
38
|
+
|
|
39
|
+
assert_equal expected, typus_belongs_to_field('post')
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_typus_belongs_to_field_with_different_attribute_name
|
|
44
|
+
|
|
45
|
+
default_url_options[:host] = 'test.host'
|
|
46
|
+
|
|
47
|
+
params = { :controller => 'admin/post', :id => 1, :action => :edit }
|
|
48
|
+
self.expects(:params).at_least_once.returns(params)
|
|
49
|
+
|
|
50
|
+
@current_user = mock()
|
|
51
|
+
@current_user.expects(:can_perform?).with(Comment, 'create').returns(true)
|
|
52
|
+
@resource = { :class => Post }
|
|
53
|
+
|
|
54
|
+
expected = <<-HTML
|
|
55
|
+
<li><label for="item_favorite_comment">Favorite comment
|
|
56
|
+
<small><a href="http://test.host/admin/comments/new?back_to=%2Fadmin%2Fpost%2Fedit%2F1&selected=favorite_comment_id" onclick="return confirm('Are you sure you want to leave this page?\\n\\nIf you have made any changes to the fields without clicking the Save/Update entry button, your changes will be lost.\\n\\nClick OK to continue, or click Cancel to stay on this page.');">Add</a></small>
|
|
57
|
+
</label>
|
|
58
|
+
<select id="item_favorite_comment_id" name="item[favorite_comment_id]"><option value=""></option>
|
|
59
|
+
<option value="1">John</option>
|
|
60
|
+
<option value="2">Me</option>
|
|
61
|
+
<option value="3">John</option>
|
|
62
|
+
<option value="4">Me</option></select></li>
|
|
63
|
+
HTML
|
|
64
|
+
assert_equal expected, typus_belongs_to_field('favorite_comment')
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_typus_boolean_field
|
|
69
|
+
|
|
70
|
+
@resource = { :class => Post }
|
|
71
|
+
|
|
72
|
+
output = typus_boolean_field('test')
|
|
73
|
+
|
|
74
|
+
expected = <<-HTML
|
|
75
|
+
<li><label for="item_test">Test</label>
|
|
76
|
+
<input name="item[test]" type="hidden" value="0" /><input id="item_test" name="item[test]" type="checkbox" value="1" /> Checked if active</li>
|
|
77
|
+
HTML
|
|
78
|
+
|
|
79
|
+
assert_equal expected, output
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_typus_date_field
|
|
84
|
+
|
|
85
|
+
@resource = { :class => Post }
|
|
86
|
+
|
|
87
|
+
output = typus_date_field('test', {})
|
|
88
|
+
expected = <<-HTML
|
|
89
|
+
<li><label for="item_test">Test</label>
|
|
90
|
+
HTML
|
|
91
|
+
|
|
92
|
+
assert_match expected, output
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_typus_datetime_field
|
|
97
|
+
|
|
98
|
+
@resource = { :class => Post }
|
|
99
|
+
|
|
100
|
+
output = typus_datetime_field('test', {})
|
|
101
|
+
expected = <<-HTML
|
|
102
|
+
<li><label for="item_test">Test</label>
|
|
103
|
+
HTML
|
|
104
|
+
|
|
105
|
+
assert_match expected, output
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_typus_file_field
|
|
110
|
+
|
|
111
|
+
@resource = { :class => Post }
|
|
112
|
+
|
|
113
|
+
output = typus_file_field('asset_file_name')
|
|
114
|
+
expected = <<-HTML
|
|
115
|
+
<li><label for="item_asset_file_name">Asset</label>
|
|
116
|
+
<input id="item_asset" name="item[asset]" size="30" type="file" /></li>
|
|
117
|
+
HTML
|
|
118
|
+
|
|
119
|
+
assert_equal expected, output
|
|
120
|
+
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def test_typus_password_field
|
|
124
|
+
|
|
125
|
+
@resource = { :class => Post }
|
|
126
|
+
|
|
127
|
+
output = typus_password_field('test')
|
|
128
|
+
expected = <<-HTML
|
|
129
|
+
<li><label for="item_test">Test</label>
|
|
130
|
+
<input class="text" id="item_test" name="item[test]" size="30" type="password" /></li>
|
|
131
|
+
HTML
|
|
132
|
+
|
|
133
|
+
assert_equal expected, output
|
|
134
|
+
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def test_typus_selector_field
|
|
138
|
+
|
|
139
|
+
@resource = { :class => Post }
|
|
140
|
+
@item = posts(:published)
|
|
141
|
+
|
|
142
|
+
output = typus_selector_field('status')
|
|
143
|
+
|
|
144
|
+
expected = <<-HTML
|
|
145
|
+
<li><label for="item_status">Status</label>
|
|
146
|
+
<select id="item_status" name="item[status]">
|
|
147
|
+
<option value=""></option>
|
|
148
|
+
<option selected value="true">true</option>
|
|
149
|
+
<option value="false">false</option>
|
|
150
|
+
<option value="pending">pending</option>
|
|
151
|
+
<option value="published">published</option>
|
|
152
|
+
<option value="unpublished">unpublished</option>
|
|
153
|
+
</select></li>
|
|
154
|
+
HTML
|
|
155
|
+
|
|
156
|
+
assert_equal expected, output
|
|
157
|
+
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def test_typus_text_field
|
|
161
|
+
|
|
162
|
+
@resource = { :class => Post }
|
|
163
|
+
|
|
164
|
+
output = typus_text_field('test')
|
|
165
|
+
expected = <<-HTML
|
|
166
|
+
<li><label for="item_test">Test</label>
|
|
167
|
+
<textarea class="text" cols="40" id="item_test" name="item[test]" rows="10"></textarea></li>
|
|
168
|
+
HTML
|
|
169
|
+
|
|
170
|
+
assert_equal expected, output
|
|
171
|
+
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def test_typus_time_field
|
|
175
|
+
|
|
176
|
+
@resource = { :class => Post }
|
|
177
|
+
|
|
178
|
+
output = typus_time_field('test', {})
|
|
179
|
+
expected = <<-HTML
|
|
180
|
+
<li><label for="item_test">Test</label>
|
|
181
|
+
HTML
|
|
182
|
+
|
|
183
|
+
assert_match expected, output
|
|
184
|
+
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def test_typus_tree_field
|
|
188
|
+
|
|
189
|
+
return if !defined?(ActiveRecord::Acts::Tree)
|
|
190
|
+
|
|
191
|
+
self.stubs(:expand_tree_into_select_field).returns('expand_tree_into_select_field')
|
|
192
|
+
|
|
193
|
+
@resource = { :class => Page }
|
|
194
|
+
items = @resource[:class].roots
|
|
195
|
+
|
|
196
|
+
output = typus_tree_field('parent', items)
|
|
197
|
+
expected = <<-HTML
|
|
198
|
+
<li><label for="item_parent">Parent</label>
|
|
199
|
+
<select id="item_parent" name="item[parent]">
|
|
200
|
+
<option value=""></option>
|
|
201
|
+
expand_tree_into_select_field
|
|
202
|
+
</select></li>
|
|
203
|
+
HTML
|
|
204
|
+
|
|
205
|
+
assert_equal expected, output
|
|
206
|
+
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def test_typus_string_field
|
|
210
|
+
|
|
211
|
+
@resource = { :class => Post }
|
|
212
|
+
|
|
213
|
+
output = typus_string_field('test')
|
|
214
|
+
expected = <<-HTML
|
|
215
|
+
<li><label for="item_test">Test</label>
|
|
216
|
+
<input class="text" id="item_test" name="item[test]" size="30" type="text" /></li>
|
|
217
|
+
HTML
|
|
218
|
+
|
|
219
|
+
assert_equal expected, output
|
|
220
|
+
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def test_typus_relationships
|
|
224
|
+
assert true
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def test_typus_form_has_many_with_items
|
|
228
|
+
|
|
229
|
+
@current_user = typus_users(:admin)
|
|
230
|
+
@resource = { :class => Post, :self => 'posts' }
|
|
231
|
+
@item = Post.find(1)
|
|
232
|
+
|
|
233
|
+
params = { :controller => 'admin/posts', :id => 1, :action => 'edit' }
|
|
234
|
+
self.expects(:params).at_least_once.returns(params)
|
|
235
|
+
|
|
236
|
+
self.stubs(:build_list).returns('<!-- a_nice_list -->')
|
|
237
|
+
|
|
238
|
+
output = typus_form_has_many('comments')
|
|
239
|
+
expected = <<-HTML
|
|
240
|
+
<a name="comments"></a>
|
|
241
|
+
<div class="box_relationships">
|
|
242
|
+
<h2>
|
|
243
|
+
<a href="http://test.host/admin/comments" title="Comments filtered by Post#1">Comments</a>
|
|
244
|
+
<small><a href="http://test.host/admin/comments/new?back_to=%23comments&resource=post&resource_id=1">Add new</a></small>
|
|
245
|
+
</h2>
|
|
246
|
+
<!-- a_nice_list --></div>
|
|
247
|
+
HTML
|
|
248
|
+
|
|
249
|
+
assert_equal expected, output
|
|
250
|
+
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def test_typus_form_has_many_without_items
|
|
254
|
+
|
|
255
|
+
@current_user = typus_users(:admin)
|
|
256
|
+
@resource = { :class => Post, :self => 'posts' }
|
|
257
|
+
@item = Post.find(1)
|
|
258
|
+
@item.comments.destroy_all
|
|
259
|
+
|
|
260
|
+
params = { :controller => 'admin/posts', :id => 1, :action => 'edit' }
|
|
261
|
+
self.expects(:params).at_least_once.returns(params)
|
|
262
|
+
|
|
263
|
+
output = typus_form_has_many('comments')
|
|
264
|
+
expected = <<-HTML
|
|
265
|
+
<a name="comments"></a>
|
|
266
|
+
<div class="box_relationships">
|
|
267
|
+
<h2>
|
|
268
|
+
<a href="http://test.host/admin/comments" title="Comments filtered by Post#1">Comments</a>
|
|
269
|
+
<small><a href="http://test.host/admin/comments/new?back_to=%23comments&resource=post&resource_id=1">Add new</a></small>
|
|
270
|
+
</h2>
|
|
271
|
+
<div id="flash" class="notice"><p>There are no comments.</p></div>
|
|
272
|
+
</div>
|
|
273
|
+
HTML
|
|
274
|
+
|
|
275
|
+
assert_equal expected, output
|
|
276
|
+
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def test_typus_form_has_and_belongs_to_many
|
|
280
|
+
assert true
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
def test_typus_template_field
|
|
284
|
+
assert true
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def test_attribute_disabled
|
|
288
|
+
|
|
289
|
+
@resource = { :class => Post }
|
|
290
|
+
|
|
291
|
+
assert !attribute_disabled?('test')
|
|
292
|
+
|
|
293
|
+
Post.expects(:accessible_attributes).returns(['test'])
|
|
294
|
+
assert !attribute_disabled?('test')
|
|
295
|
+
|
|
296
|
+
Post.expects(:accessible_attributes).returns(['no_test'])
|
|
297
|
+
assert attribute_disabled?('test')
|
|
298
|
+
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
def test_expand_tree_into_select_field
|
|
302
|
+
|
|
303
|
+
return if !defined?(ActiveRecord::Acts::Tree)
|
|
304
|
+
|
|
305
|
+
items = Page.roots
|
|
306
|
+
|
|
307
|
+
# Page#1 is a root.
|
|
308
|
+
|
|
309
|
+
@item = Page.find(1)
|
|
310
|
+
output = expand_tree_into_select_field(items, 'parent_id')
|
|
311
|
+
expected = <<-HTML
|
|
312
|
+
<option value="1"> \_ Page#1</option>
|
|
313
|
+
<option value="2"> \_ Page#2</option>
|
|
314
|
+
<option value="3"> \_ Page#3</option>
|
|
315
|
+
<option value="4"> \_ Page#4</option>
|
|
316
|
+
<option value="5"> \_ Page#5</option>
|
|
317
|
+
<option value="6"> \_ Page#6</option>
|
|
318
|
+
HTML
|
|
319
|
+
assert_equal expected, output
|
|
320
|
+
|
|
321
|
+
# Page#4 is a children.
|
|
322
|
+
|
|
323
|
+
@item = Page.find(4)
|
|
324
|
+
output = expand_tree_into_select_field(items, 'parent_id')
|
|
325
|
+
expected = <<-HTML
|
|
326
|
+
<option value="1"> \_ Page#1</option>
|
|
327
|
+
<option value="2"> \_ Page#2</option>
|
|
328
|
+
<option selected value="3"> \_ Page#3</option>
|
|
329
|
+
<option value="4"> \_ Page#4</option>
|
|
330
|
+
<option value="5"> \_ Page#5</option>
|
|
331
|
+
<option value="6"> \_ Page#6</option>
|
|
332
|
+
HTML
|
|
333
|
+
assert_equal expected, output
|
|
334
|
+
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
@resource = { :class => Post }
|
|
13
|
+
params = { :action => 'edit', :back_to => '/back_to_param' }
|
|
14
|
+
self.expects(:params).at_least_once.returns(params)
|
|
15
|
+
|
|
16
|
+
output = display_link_to_previous
|
|
17
|
+
expected = <<-HTML
|
|
18
|
+
<div id="flash" class="notice">
|
|
19
|
+
<p>You're updating a Post. <a href="/back_to_param">Do you want to cancel it?</a></p>
|
|
20
|
+
</div>
|
|
21
|
+
HTML
|
|
22
|
+
|
|
23
|
+
assert_equal expected, output
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_remove_filter_link
|
|
28
|
+
output = remove_filter_link('')
|
|
29
|
+
assert output.nil?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_build_list_when_returns_a_typus_table
|
|
33
|
+
|
|
34
|
+
model = TypusUser
|
|
35
|
+
fields = [ 'email', 'role', 'status' ]
|
|
36
|
+
items = TypusUser.find(:all)
|
|
37
|
+
resource = 'typus_users'
|
|
38
|
+
|
|
39
|
+
self.stubs(:build_typus_table).returns('a_list_with_items')
|
|
40
|
+
|
|
41
|
+
output = build_list(model, fields, items, resource)
|
|
42
|
+
expected = 'a_list_with_items'
|
|
43
|
+
|
|
44
|
+
assert_equal expected, output
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_build_list_when_returns_a_template
|
|
49
|
+
|
|
50
|
+
model = TypusUser
|
|
51
|
+
fields = [ 'email', 'role', 'status' ]
|
|
52
|
+
items = TypusUser.find(:all)
|
|
53
|
+
resource = 'typus_users'
|
|
54
|
+
|
|
55
|
+
self.stubs(:render).returns('a_template')
|
|
56
|
+
File.stubs(:exist?).returns(true)
|
|
57
|
+
|
|
58
|
+
output = build_list(model, fields, items, resource)
|
|
59
|
+
expected = 'a_template'
|
|
60
|
+
|
|
61
|
+
assert_equal expected, output
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_build_pagination
|
|
66
|
+
assert true
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|