rd_resource_controller 1.0.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.rdoc +330 -0
- data/TODO +0 -0
- data/VERSION.yml +5 -0
- data/generators/scaffold_resource/USAGE +29 -0
- data/generators/scaffold_resource/scaffold_resource_generator.rb +179 -0
- data/generators/scaffold_resource/templates/controller.rb +2 -0
- data/generators/scaffold_resource/templates/fixtures.yml +10 -0
- data/generators/scaffold_resource/templates/functional_test.rb +57 -0
- data/generators/scaffold_resource/templates/helper.rb +2 -0
- data/generators/scaffold_resource/templates/migration.rb +15 -0
- data/generators/scaffold_resource/templates/model.rb +2 -0
- data/generators/scaffold_resource/templates/old_migration.rb +13 -0
- data/generators/scaffold_resource/templates/rspec/functional_spec.rb +255 -0
- data/generators/scaffold_resource/templates/rspec/helper_spec.rb +11 -0
- data/generators/scaffold_resource/templates/rspec/routing_spec.rb +61 -0
- data/generators/scaffold_resource/templates/rspec/unit_spec.rb +11 -0
- data/generators/scaffold_resource/templates/rspec/views/edit_spec.rb +28 -0
- data/generators/scaffold_resource/templates/rspec/views/index_spec.rb +26 -0
- data/generators/scaffold_resource/templates/rspec/views/new_spec.rb +30 -0
- data/generators/scaffold_resource/templates/rspec/views/show_spec.rb +25 -0
- data/generators/scaffold_resource/templates/shoulda_functional_test.rb +19 -0
- data/generators/scaffold_resource/templates/unit_test.rb +7 -0
- data/generators/scaffold_resource/templates/view__form.erb +6 -0
- data/generators/scaffold_resource/templates/view__form.haml +5 -0
- data/generators/scaffold_resource/templates/view_edit.erb +16 -0
- data/generators/scaffold_resource/templates/view_edit.haml +11 -0
- data/generators/scaffold_resource/templates/view_index.erb +22 -0
- data/generators/scaffold_resource/templates/view_index.haml +19 -0
- data/generators/scaffold_resource/templates/view_new.erb +12 -0
- data/generators/scaffold_resource/templates/view_new.haml +9 -0
- data/generators/scaffold_resource/templates/view_show.erb +9 -0
- data/generators/scaffold_resource/templates/view_show.haml +9 -0
- data/lib/resource_controller/accessors.rb +77 -0
- data/lib/resource_controller/action_options.rb +40 -0
- data/lib/resource_controller/actions.rb +75 -0
- data/lib/resource_controller/base.rb +15 -0
- data/lib/resource_controller/controller.rb +69 -0
- data/lib/resource_controller/failable_action_options.rb +25 -0
- data/lib/resource_controller/helpers/current_objects.rb +82 -0
- data/lib/resource_controller/helpers/internal.rb +80 -0
- data/lib/resource_controller/helpers/nested.rb +82 -0
- data/lib/resource_controller/helpers/singleton_customizations.rb +64 -0
- data/lib/resource_controller/helpers/urls.rb +132 -0
- data/lib/resource_controller/helpers.rb +34 -0
- data/lib/resource_controller/response_collector.rb +27 -0
- data/lib/resource_controller/singleton.rb +15 -0
- data/lib/resource_controller.rb +54 -0
- data/lib/urligence.rb +52 -0
- data/rails/init.rb +6 -0
- data/test/Gemfile +11 -0
- data/test/Rakefile +10 -0
- data/test/app/controllers/accounts_controller.rb +6 -0
- data/test/app/controllers/application_controller.rb +5 -0
- data/test/app/controllers/cms/options_controller.rb +3 -0
- data/test/app/controllers/cms/personnel_controller.rb +2 -0
- data/test/app/controllers/cms/photos_controller.rb +6 -0
- data/test/app/controllers/cms/products_controller.rb +3 -0
- data/test/app/controllers/comments_controller.rb +3 -0
- data/test/app/controllers/images_controller.rb +4 -0
- data/test/app/controllers/options_controller.rb +8 -0
- data/test/app/controllers/people_controller.rb +9 -0
- data/test/app/controllers/photos_controller.rb +12 -0
- data/test/app/controllers/posts_controller.rb +10 -0
- data/test/app/controllers/projects_controller.rb +3 -0
- data/test/app/controllers/somethings_controller.rb +3 -0
- data/test/app/controllers/tags_controller.rb +13 -0
- data/test/app/controllers/users_controller.rb +12 -0
- data/test/app/helpers/accounts_helper.rb +2 -0
- data/test/app/helpers/application_helper.rb +3 -0
- data/test/app/helpers/cms/products_helper.rb +2 -0
- data/test/app/helpers/comments_helper.rb +2 -0
- data/test/app/helpers/images_helper.rb +2 -0
- data/test/app/helpers/options_helper.rb +2 -0
- data/test/app/helpers/people_helper.rb +2 -0
- data/test/app/helpers/photos_helper.rb +2 -0
- data/test/app/helpers/posts_helper.rb +2 -0
- data/test/app/helpers/projects_helper.rb +2 -0
- data/test/app/helpers/somethings_helper.rb +2 -0
- data/test/app/helpers/tags_helper.rb +2 -0
- data/test/app/helpers/users_helper.rb +2 -0
- data/test/app/models/account.rb +4 -0
- data/test/app/models/comment.rb +3 -0
- data/test/app/models/image.rb +3 -0
- data/test/app/models/option.rb +3 -0
- data/test/app/models/personnel.rb +3 -0
- data/test/app/models/photo.rb +5 -0
- data/test/app/models/post.rb +3 -0
- data/test/app/models/product.rb +3 -0
- data/test/app/models/project.rb +2 -0
- data/test/app/models/something.rb +2 -0
- data/test/app/models/tag.rb +3 -0
- data/test/app/models/user.rb +3 -0
- data/test/app/views/accounts/_form.html.erb +4 -0
- data/test/app/views/accounts/edit.html.erb +14 -0
- data/test/app/views/accounts/new.html.erb +12 -0
- data/test/app/views/accounts/show.html.erb +5 -0
- data/test/app/views/cms/options/edit.rhtml +17 -0
- data/test/app/views/cms/options/index.rhtml +20 -0
- data/test/app/views/cms/options/new.rhtml +16 -0
- data/test/app/views/cms/options/show.rhtml +8 -0
- data/test/app/views/cms/photos/edit.rhtml +17 -0
- data/test/app/views/cms/photos/index.rhtml +20 -0
- data/test/app/views/cms/photos/new.rhtml +16 -0
- data/test/app/views/cms/photos/show.rhtml +8 -0
- data/test/app/views/cms/products/edit.rhtml +17 -0
- data/test/app/views/cms/products/index.rhtml +20 -0
- data/test/app/views/cms/products/new.rhtml +16 -0
- data/test/app/views/cms/products/show.rhtml +8 -0
- data/test/app/views/comments/edit.rhtml +27 -0
- data/test/app/views/comments/index.rhtml +24 -0
- data/test/app/views/comments/new.rhtml +26 -0
- data/test/app/views/comments/show.rhtml +18 -0
- data/test/app/views/images/_form.html.erb +4 -0
- data/test/app/views/images/edit.html.erb +14 -0
- data/test/app/views/images/new.html.erb +12 -0
- data/test/app/views/layouts/application.rhtml +17 -0
- data/test/app/views/layouts/comments.rhtml +17 -0
- data/test/app/views/layouts/options.rhtml +17 -0
- data/test/app/views/layouts/people.rhtml +17 -0
- data/test/app/views/layouts/photos.rhtml +17 -0
- data/test/app/views/layouts/projects.rhtml +17 -0
- data/test/app/views/layouts/somethings.rhtml +17 -0
- data/test/app/views/layouts/tags.rhtml +17 -0
- data/test/app/views/options/_form.html.erb +8 -0
- data/test/app/views/options/edit.html.erb +16 -0
- data/test/app/views/options/index.html.erb +21 -0
- data/test/app/views/options/new.html.erb +12 -0
- data/test/app/views/options/show.html.erb +10 -0
- data/test/app/views/people/edit.rhtml +17 -0
- data/test/app/views/people/index.rhtml +20 -0
- data/test/app/views/people/new.rhtml +16 -0
- data/test/app/views/people/show.rhtml +8 -0
- data/test/app/views/photos/edit.rhtml +17 -0
- data/test/app/views/photos/index.rhtml +20 -0
- data/test/app/views/photos/new.rhtml +16 -0
- data/test/app/views/photos/show.rhtml +8 -0
- data/test/app/views/posts/edit.rhtml +22 -0
- data/test/app/views/posts/index.rhtml +22 -0
- data/test/app/views/posts/new.rhtml +21 -0
- data/test/app/views/posts/show.rhtml +13 -0
- data/test/app/views/projects/edit.rhtml +17 -0
- data/test/app/views/projects/index.rhtml +20 -0
- data/test/app/views/projects/new.rhtml +16 -0
- data/test/app/views/projects/show.rhtml +8 -0
- data/test/app/views/somethings/edit.rhtml +17 -0
- data/test/app/views/somethings/index.rhtml +20 -0
- data/test/app/views/somethings/new.rhtml +16 -0
- data/test/app/views/somethings/show.rhtml +8 -0
- data/test/app/views/tags/edit.rhtml +17 -0
- data/test/app/views/tags/index.rhtml +20 -0
- data/test/app/views/tags/index.rjs +0 -0
- data/test/app/views/tags/new.rhtml +16 -0
- data/test/app/views/tags/show.rhtml +8 -0
- data/test/app/views/users/edit.rhtml +17 -0
- data/test/app/views/users/index.rhtml +20 -0
- data/test/app/views/users/new.rhtml +16 -0
- data/test/app/views/users/show.rhtml +8 -0
- data/test/config/application.rb +41 -0
- data/test/config/boot.rb +6 -0
- data/test/config/database.yml +9 -0
- data/test/config/environment.rb +5 -0
- data/test/config/environments/development.rb +19 -0
- data/test/config/environments/test.rb +32 -0
- data/test/config/initializers/inflections.rb +14 -0
- data/test/config/initializers/secret_token.rb +7 -0
- data/test/config/initializers/session_store.rb +8 -0
- data/test/config/routes.rb +35 -0
- data/test/config.ru +4 -0
- data/test/db/migrate/001_create_posts.rb +12 -0
- data/test/db/migrate/002_create_products.rb +11 -0
- data/test/db/migrate/003_create_comments.rb +13 -0
- data/test/db/migrate/004_create_options.rb +13 -0
- data/test/db/migrate/005_create_photos.rb +11 -0
- data/test/db/migrate/006_create_tags.rb +17 -0
- data/test/db/migrate/007_create_somethings.rb +11 -0
- data/test/db/migrate/008_create_accounts.rb +11 -0
- data/test/db/migrate/009_add_account_id_to_photos.rb +9 -0
- data/test/db/migrate/010_create_projects.rb +11 -0
- data/test/db/migrate/011_create_images.rb +12 -0
- data/test/db/migrate/012_create_users.rb +11 -0
- data/test/db/migrate/013_create_personnel.rb +11 -0
- data/test/db/migrate/014_add_personnel_id_to_photos.rb +9 -0
- data/test/db/schema.rb +78 -0
- data/test/script/console +3 -0
- data/test/script/destroy +3 -0
- data/test/script/generate +3 -0
- data/test/script/rails +6 -0
- data/test/script/server +3 -0
- data/test/test/fixtures/accounts.yml +7 -0
- data/test/test/fixtures/comments.yml +11 -0
- data/test/test/fixtures/images.yml +6 -0
- data/test/test/fixtures/options.yml +9 -0
- data/test/test/fixtures/personnel.yml +5 -0
- data/test/test/fixtures/photos.yml +9 -0
- data/test/test/fixtures/photos_tags.yml +3 -0
- data/test/test/fixtures/posts.yml +9 -0
- data/test/test/fixtures/products.yml +7 -0
- data/test/test/fixtures/projects.yml +7 -0
- data/test/test/fixtures/somethings.yml +7 -0
- data/test/test/fixtures/tags.yml +7 -0
- data/test/test/fixtures/users.yml +5 -0
- data/test/test/functional/cms/options_controller_test.rb +140 -0
- data/test/test/functional/cms/photos_controller_test.rb +37 -0
- data/test/test/functional/cms/products_controller_test.rb +37 -0
- data/test/test/functional/comments_controller_test.rb +140 -0
- data/test/test/functional/images_controller_test.rb +30 -0
- data/test/test/functional/people_controller_test.rb +147 -0
- data/test/test/functional/photos_controller_test.rb +199 -0
- data/test/test/functional/posts_controller_test.rb +21 -0
- data/test/test/functional/projects_controller_test.rb +137 -0
- data/test/test/functional/somethings_controller_test.rb +15 -0
- data/test/test/functional/tags_controller_test.rb +53 -0
- data/test/test/functional/users_controller_test.rb +137 -0
- data/test/test/test_helper.rb +14 -0
- data/test/test/unit/accessors_test.rb +110 -0
- data/test/test/unit/account_test.rb +7 -0
- data/test/test/unit/action_options_test.rb +109 -0
- data/test/test/unit/base_test.rb +11 -0
- data/test/test/unit/comment_test.rb +10 -0
- data/test/test/unit/failable_action_options_test.rb +77 -0
- data/test/test/unit/helpers/current_objects_test.rb +133 -0
- data/test/test/unit/helpers/internal_test.rb +106 -0
- data/test/test/unit/helpers/nested_test.rb +86 -0
- data/test/test/unit/helpers/singleton_current_objects_test.rb +68 -0
- data/test/test/unit/helpers/singleton_nested_test.rb +77 -0
- data/test/test/unit/helpers/singleton_urls_test.rb +67 -0
- data/test/test/unit/helpers/urls_test.rb +75 -0
- data/test/test/unit/helpers_test.rb +25 -0
- data/test/test/unit/image_test.rb +7 -0
- data/test/test/unit/option_test.rb +10 -0
- data/test/test/unit/photo_test.rb +10 -0
- data/test/test/unit/post_test.rb +10 -0
- data/test/test/unit/project_test.rb +10 -0
- data/test/test/unit/response_collector_test.rb +49 -0
- data/test/test/unit/something_test.rb +10 -0
- data/test/test/unit/tag_test.rb +10 -0
- data/test/test/unit/urligence_test.rb +205 -0
- data/test/vendor/plugins/d +1 -0
- data/test/vendor/plugins/dynamic_form/MIT-LICENSE +20 -0
- data/test/vendor/plugins/dynamic_form/README +13 -0
- data/test/vendor/plugins/dynamic_form/Rakefile +10 -0
- data/test/vendor/plugins/dynamic_form/init.rb +5 -0
- data/test/vendor/plugins/dynamic_form/lib/action_view/helpers/dynamic_form.rb +300 -0
- data/test/vendor/plugins/dynamic_form/lib/action_view/locale/en.yml +8 -0
- data/test/vendor/plugins/dynamic_form/test/dynamic_form_i18n_test.rb +42 -0
- data/test/vendor/plugins/dynamic_form/test/dynamic_form_test.rb +370 -0
- data/test/vendor/plugins/dynamic_form/test/test_helper.rb +9 -0
- metadata +421 -0
@@ -0,0 +1,370 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'action_view/template/handlers/erb'
|
3
|
+
|
4
|
+
class DynamicFormTest < ActionView::TestCase
|
5
|
+
tests ActionView::Helpers::DynamicForm
|
6
|
+
|
7
|
+
def form_for(*)
|
8
|
+
@output_buffer = super
|
9
|
+
end
|
10
|
+
|
11
|
+
silence_warnings do
|
12
|
+
class Post < Struct.new(:title, :author_name, :body, :secret, :written_on)
|
13
|
+
extend ActiveModel::Naming
|
14
|
+
include ActiveModel::Conversion
|
15
|
+
end
|
16
|
+
|
17
|
+
class User < Struct.new(:email)
|
18
|
+
extend ActiveModel::Naming
|
19
|
+
include ActiveModel::Conversion
|
20
|
+
end
|
21
|
+
|
22
|
+
class Column < Struct.new(:type, :name, :human_name)
|
23
|
+
extend ActiveModel::Naming
|
24
|
+
include ActiveModel::Conversion
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class DirtyPost
|
29
|
+
class Errors
|
30
|
+
def empty?
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
34
|
+
def count
|
35
|
+
1
|
36
|
+
end
|
37
|
+
|
38
|
+
def full_messages
|
39
|
+
["Author name can't be <em>empty</em>"]
|
40
|
+
end
|
41
|
+
|
42
|
+
def [](field)
|
43
|
+
["can't be <em>empty</em>"]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def errors
|
48
|
+
Errors.new
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def setup_post
|
53
|
+
@post = Post.new
|
54
|
+
def @post.errors
|
55
|
+
Class.new {
|
56
|
+
def [](field)
|
57
|
+
case field.to_s
|
58
|
+
when "author_name"
|
59
|
+
["can't be empty"]
|
60
|
+
when "body"
|
61
|
+
['foo']
|
62
|
+
else
|
63
|
+
[]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
def empty?() false end
|
67
|
+
def count() 1 end
|
68
|
+
def full_messages() [ "Author name can't be empty" ] end
|
69
|
+
}.new
|
70
|
+
end
|
71
|
+
|
72
|
+
def @post.persisted?() false end
|
73
|
+
def @post.to_param() nil end
|
74
|
+
|
75
|
+
def @post.column_for_attribute(attr_name)
|
76
|
+
Post.content_columns.select { |column| column.name == attr_name }.first
|
77
|
+
end
|
78
|
+
|
79
|
+
silence_warnings do
|
80
|
+
def Post.content_columns() [ Column.new(:string, "title", "Title"), Column.new(:text, "body", "Body") ] end
|
81
|
+
end
|
82
|
+
|
83
|
+
@post.title = "Hello World"
|
84
|
+
@post.author_name = ""
|
85
|
+
@post.body = "Back to the hill and over it again!"
|
86
|
+
@post.secret = 1
|
87
|
+
@post.written_on = Date.new(2004, 6, 15)
|
88
|
+
end
|
89
|
+
|
90
|
+
def setup_user
|
91
|
+
@user = User.new
|
92
|
+
def @user.errors
|
93
|
+
Class.new {
|
94
|
+
def [](field) field == "email" ? ['nonempty'] : [] end
|
95
|
+
def empty?() false end
|
96
|
+
def count() 1 end
|
97
|
+
def full_messages() [ "User email can't be empty" ] end
|
98
|
+
}.new
|
99
|
+
end
|
100
|
+
|
101
|
+
def @user.new_record?() true end
|
102
|
+
def @user.to_param() nil end
|
103
|
+
|
104
|
+
def @user.column_for_attribute(attr_name)
|
105
|
+
User.content_columns.select { |column| column.name == attr_name }.first
|
106
|
+
end
|
107
|
+
|
108
|
+
silence_warnings do
|
109
|
+
def User.content_columns() [ Column.new(:string, "email", "Email") ] end
|
110
|
+
end
|
111
|
+
|
112
|
+
@user.email = ""
|
113
|
+
end
|
114
|
+
|
115
|
+
def protect_against_forgery?
|
116
|
+
@protect_against_forgery ? true : false
|
117
|
+
end
|
118
|
+
attr_accessor :request_forgery_protection_token, :form_authenticity_token
|
119
|
+
|
120
|
+
def setup
|
121
|
+
super
|
122
|
+
setup_post
|
123
|
+
setup_user
|
124
|
+
|
125
|
+
@response = ActionController::TestResponse.new
|
126
|
+
end
|
127
|
+
|
128
|
+
def url_for(options)
|
129
|
+
options = options.symbolize_keys
|
130
|
+
[options[:action], options[:id].to_param].compact.join('/')
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_generic_input_tag
|
134
|
+
assert_dom_equal(
|
135
|
+
%(<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />), input("post", "title")
|
136
|
+
)
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_text_area_with_errors
|
140
|
+
assert_dom_equal(
|
141
|
+
%(<div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div>),
|
142
|
+
text_area("post", "body")
|
143
|
+
)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_text_field_with_errors
|
147
|
+
assert_dom_equal(
|
148
|
+
%(<div class="fieldWithErrors"><input id="post_author_name" name="post[author_name]" size="30" type="text" value="" /></div>),
|
149
|
+
text_field("post", "author_name")
|
150
|
+
)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_field_error_proc
|
154
|
+
old_proc = ActionView::Base.field_error_proc
|
155
|
+
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
|
156
|
+
%(<div class=\"fieldWithErrors\">#{html_tag} <span class="error">#{[instance.error_message].join(', ')}</span></div>).html_safe
|
157
|
+
end
|
158
|
+
|
159
|
+
assert_dom_equal(
|
160
|
+
%(<div class="fieldWithErrors"><input id="post_author_name" name="post[author_name]" size="30" type="text" value="" /> <span class="error">can't be empty</span></div>),
|
161
|
+
text_field("post", "author_name")
|
162
|
+
)
|
163
|
+
ensure
|
164
|
+
ActionView::Base.field_error_proc = old_proc if old_proc
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_form_with_string
|
168
|
+
assert_dom_equal(
|
169
|
+
%(<form action="create" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
|
170
|
+
form("post")
|
171
|
+
)
|
172
|
+
|
173
|
+
silence_warnings do
|
174
|
+
class << @post
|
175
|
+
def persisted?() true end
|
176
|
+
def to_param() id end
|
177
|
+
def id() 1 end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
assert_dom_equal(
|
182
|
+
%(<form action="update/1" method="post"><input id="post_id" name="post[id]" type="hidden" value="1" /><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Update" /></form>),
|
183
|
+
form("post")
|
184
|
+
)
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_form_with_protect_against_forgery
|
188
|
+
@protect_against_forgery = true
|
189
|
+
@request_forgery_protection_token = 'authenticity_token'
|
190
|
+
@form_authenticity_token = '123'
|
191
|
+
assert_dom_equal(
|
192
|
+
%(<form action="create" method="post"><div style='margin:0;padding:0;display:inline'><input type='hidden' name='authenticity_token' value='123' /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
|
193
|
+
form("post")
|
194
|
+
)
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_form_with_method_option
|
198
|
+
assert_dom_equal(
|
199
|
+
%(<form action="create" method="get"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
|
200
|
+
form("post", :method=>'get')
|
201
|
+
)
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_form_with_action_option
|
205
|
+
output_buffer << form("post", :action => "sign")
|
206
|
+
assert_select "form[action=sign]" do |form|
|
207
|
+
assert_select "input[type=submit][value=Sign]"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_form_with_date
|
212
|
+
silence_warnings do
|
213
|
+
def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
|
214
|
+
end
|
215
|
+
|
216
|
+
assert_dom_equal(
|
217
|
+
%(<form action="create" method="post"><p><label for="post_written_on">Written on</label><br /><select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select id="post_written_on_2i" name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="post_written_on_3i" name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>),
|
218
|
+
form("post")
|
219
|
+
)
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_form_with_datetime
|
223
|
+
silence_warnings do
|
224
|
+
def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ] end
|
225
|
+
end
|
226
|
+
@post.written_on = Time.gm(2004, 6, 15, 16, 30)
|
227
|
+
|
228
|
+
assert_dom_equal(
|
229
|
+
%(<form action="create" method="post"><p><label for="post_written_on">Written on</label><br /><select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select id="post_written_on_2i" name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="post_written_on_3i" name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n — <select id="post_written_on_4i" name="post[written_on(4i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="post_written_on_5i" name="post[written_on(5i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30" selected="selected">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>),
|
230
|
+
form("post")
|
231
|
+
)
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_error_for_block
|
235
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post")
|
236
|
+
assert_equal %(<div class="errorDeathByClass" id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
|
237
|
+
assert_equal %(<div id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => nil, :id => "errorDeathById", :header_tag => "h1")
|
238
|
+
assert_equal %(<div class="errorDeathByClass"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1")
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_error_messages_for_escapes_html
|
242
|
+
@dirty_post = DirtyPost.new
|
243
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this dirty post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be <em>empty</em></li></ul></div>), error_messages_for("dirty_post")
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_error_messages_for_handles_nil
|
247
|
+
assert_equal "", error_messages_for("notthere")
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_error_message_on_escapes_html
|
251
|
+
@dirty_post = DirtyPost.new
|
252
|
+
assert_dom_equal "<div class=\"formError\">can't be <em>empty</em></div>", error_message_on(:dirty_post, :author_name)
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_error_message_on_handles_nil
|
256
|
+
assert_equal "", error_message_on("notthere", "notthere")
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_error_message_on
|
260
|
+
assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(:post, :author_name)
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_error_message_on_no_instance_variable
|
264
|
+
other_post = @post
|
265
|
+
assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(other_post, :author_name)
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_error_message_on_with_options_hash
|
269
|
+
assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", error_message_on(:post, :author_name, :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after')
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_error_message_on_with_tag_option_in_options_hash
|
273
|
+
assert_dom_equal "<span class=\"differentError\">beforecan't be emptyafter</span>", error_message_on(:post, :author_name, :html_tag => "span", :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after')
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_error_message_on_handles_empty_errors
|
277
|
+
assert_equal "", error_message_on(@post, :tag)
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_error_messages_for_many_objects
|
281
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li><li>User email can't be empty</li></ul></div>), error_messages_for("post", "user")
|
282
|
+
|
283
|
+
# reverse the order, error order changes and so does the title
|
284
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post")
|
285
|
+
|
286
|
+
# add the default to put post back in the title
|
287
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post", :object_name => "post")
|
288
|
+
|
289
|
+
# symbols work as well
|
290
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => :post)
|
291
|
+
|
292
|
+
# any default works too
|
293
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this monkey from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "monkey")
|
294
|
+
|
295
|
+
# should space object name
|
296
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this chunky bacon from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "chunky_bacon")
|
297
|
+
|
298
|
+
# hide header and explanation messages with nil or empty string
|
299
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :header_message => nil, :message => "")
|
300
|
+
|
301
|
+
# override header and explanation messages
|
302
|
+
header_message = "Yikes! Some errors"
|
303
|
+
message = "Please fix the following fields and resubmit:"
|
304
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>#{header_message}</h2><p>#{message}</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :header_message => header_message, :message => message)
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_error_messages_for_non_instance_variable
|
308
|
+
actual_user = @user
|
309
|
+
actual_post = @post
|
310
|
+
@user = nil
|
311
|
+
@post = nil
|
312
|
+
|
313
|
+
#explicitly set object
|
314
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :object => actual_post)
|
315
|
+
|
316
|
+
#multiple objects
|
317
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post", :object => [actual_user, actual_post])
|
318
|
+
|
319
|
+
#nil object
|
320
|
+
assert_equal '', error_messages_for('user', :object => nil)
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_error_messages_for_model_objects
|
324
|
+
error = error_messages_for(@post)
|
325
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>),
|
326
|
+
error
|
327
|
+
|
328
|
+
error = error_messages_for(@user, @post)
|
329
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>),
|
330
|
+
error
|
331
|
+
end
|
332
|
+
|
333
|
+
def test_form_with_string_multipart
|
334
|
+
assert_dom_equal(
|
335
|
+
%(<form action="create" enctype="multipart/form-data" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
|
336
|
+
form("post", :multipart => true)
|
337
|
+
)
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_default_form_builder_with_dynamic_form_helpers
|
341
|
+
form_for(@post, :as => :post, :url => {}) do |f|
|
342
|
+
concat f.error_message_on('author_name')
|
343
|
+
concat f.error_messages
|
344
|
+
end
|
345
|
+
|
346
|
+
expected = %(<form class="post_new" method="post" action="" id="post_new">) +
|
347
|
+
%(<div class="formError">can't be empty</div>) +
|
348
|
+
%(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) +
|
349
|
+
%(</form>)
|
350
|
+
|
351
|
+
assert_dom_equal expected, output_buffer
|
352
|
+
end
|
353
|
+
|
354
|
+
def test_default_form_builder_no_instance_variable
|
355
|
+
post = @post
|
356
|
+
@post = nil
|
357
|
+
|
358
|
+
form_for(post, :as => :post, :url => {}) do |f|
|
359
|
+
concat f.error_message_on('author_name')
|
360
|
+
concat f.error_messages
|
361
|
+
end
|
362
|
+
|
363
|
+
expected = %(<form class="post_new" method="post" action="" id="post_new">) +
|
364
|
+
%(<div class="formError">can't be empty</div>) +
|
365
|
+
%(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) +
|
366
|
+
%(</form>)
|
367
|
+
|
368
|
+
assert_dom_equal expected, output_buffer
|
369
|
+
end
|
370
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
require 'action_view'
|
6
|
+
require 'action_controller'
|
7
|
+
require 'action_controller/test_case'
|
8
|
+
require 'active_model'
|
9
|
+
require 'action_view/helpers/dynamic_form'
|