clearance 0.8.8 → 0.9.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of clearance might be problematic. Click here for more details.

Files changed (94) hide show
  1. data/CHANGELOG.md +8 -0
  2. data/README.md +27 -32
  3. data/Rakefile +25 -31
  4. data/app/controllers/clearance/passwords_controller.rb +1 -1
  5. data/app/controllers/clearance/sessions_controller.rb +1 -1
  6. data/app/models/clearance_mailer.rb +4 -4
  7. data/app/views/passwords/edit.html.erb +1 -1
  8. data/app/views/passwords/new.html.erb +2 -2
  9. data/app/views/sessions/new.html.erb +1 -1
  10. data/app/views/users/_form.html.erb +1 -1
  11. data/app/views/users/new.html.erb +1 -1
  12. data/config/routes.rb +30 -0
  13. data/lib/clearance.rb +2 -1
  14. data/lib/clearance/authentication.rb +2 -2
  15. data/lib/clearance/configuration.rb +10 -3
  16. data/lib/clearance/engine.rb +8 -0
  17. data/lib/clearance/user.rb +5 -6
  18. data/lib/rails/generators/clearance_features_generator.rb +20 -0
  19. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/password_reset.feature +1 -1
  20. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/sign_in.feature +0 -0
  21. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/sign_out.feature +0 -0
  22. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/sign_up.feature +0 -0
  23. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/step_definitions/clearance_steps.rb +13 -5
  24. data/lib/rails/generators/clearance_generator.rb +68 -0
  25. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/README +0 -0
  26. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/clearance.rb +0 -0
  27. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/factories.rb +0 -0
  28. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/migrations/create_users.rb +0 -1
  29. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/migrations/update_users.rb +0 -1
  30. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/user.rb +0 -0
  31. data/lib/rails/generators/clearance_views_generator.rb +14 -0
  32. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/passwords/edit.html.erb +3 -3
  33. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/passwords/new.html.erb +3 -3
  34. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/sessions/new.html.erb +3 -3
  35. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/users/_inputs.html.erb +1 -1
  36. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/users/new.html.erb +2 -2
  37. data/shoulda_macros/clearance.rb +9 -17
  38. data/test/controllers/confirmations_controller_test.rb +6 -6
  39. data/test/controllers/passwords_controller_test.rb +10 -10
  40. data/test/controllers/sessions_controller_test.rb +57 -16
  41. data/test/controllers/users_controller_test.rb +12 -8
  42. data/test/models/clearance_mailer_test.rb +2 -2
  43. data/test/models/user_test.rb +14 -7
  44. data/test/rails_root/app/helpers/application_helper.rb +0 -3
  45. data/test/rails_root/config/application.rb +46 -0
  46. data/test/rails_root/config/boot.rb +5 -109
  47. data/test/rails_root/config/environment.rb +5 -15
  48. data/test/rails_root/config/environments/development.rb +15 -15
  49. data/test/rails_root/config/environments/production.rb +42 -1
  50. data/test/rails_root/config/environments/test.rb +25 -29
  51. data/test/rails_root/config/initializers/backtrace_silencers.rb +7 -0
  52. data/test/rails_root/config/initializers/inflections.rb +1 -1
  53. data/test/rails_root/config/initializers/secret_token.rb +7 -0
  54. data/test/rails_root/config/initializers/session_store.rb +8 -0
  55. data/test/rails_root/config/routes.rb +57 -2
  56. data/test/rails_root/features/step_definitions/web_steps.rb +125 -165
  57. data/test/rails_root/features/support/env.rb +24 -14
  58. data/test/rails_root/features/support/paths.rb +26 -4
  59. data/test/rails_root/test/functional/accounts_controller_test.rb +0 -1
  60. data/test/rails_root/test/performance/browsing_test.rb +9 -0
  61. data/test/rails_root/test/test_helper.rb +13 -0
  62. data/test/rails_root/vendor/plugins/dynamic_form/init.rb +5 -0
  63. data/test/rails_root/vendor/plugins/dynamic_form/lib/action_view/helpers/dynamic_form.rb +300 -0
  64. data/test/rails_root/vendor/plugins/dynamic_form/test/dynamic_form_i18n_test.rb +42 -0
  65. data/test/rails_root/vendor/plugins/dynamic_form/test/dynamic_form_test.rb +370 -0
  66. data/test/rails_root/vendor/plugins/dynamic_form/test/test_helper.rb +9 -0
  67. data/test/test_helper.rb +30 -1
  68. metadata +104 -49
  69. data/VERSION +0 -1
  70. data/generators/clearance/USAGE +0 -1
  71. data/generators/clearance/clearance_generator.rb +0 -68
  72. data/generators/clearance/lib/insert_commands.rb +0 -33
  73. data/generators/clearance/lib/rake_commands.rb +0 -22
  74. data/generators/clearance_features/USAGE +0 -1
  75. data/generators/clearance_features/clearance_features_generator.rb +0 -19
  76. data/generators/clearance_features/templates/features/support/paths.rb +0 -23
  77. data/generators/clearance_views/USAGE +0 -0
  78. data/generators/clearance_views/clearance_views_generator.rb +0 -27
  79. data/lib/clearance/routes.rb +0 -49
  80. data/test/rails_root/app/helpers/confirmations_helper.rb +0 -2
  81. data/test/rails_root/app/helpers/passwords_helper.rb +0 -2
  82. data/test/rails_root/config/initializers/requires.rb +0 -13
  83. data/test/rails_root/config/initializers/time_formats.rb +0 -4
  84. data/test/rails_root/db/migrate/20100225210436_clearance_create_users.rb +0 -21
  85. data/test/rails_root/features/step_definitions/clearance_steps.rb +0 -122
  86. data/test/rails_root/features/step_definitions/factory_girl_steps.rb +0 -5
  87. data/test/rails_root/public/dispatch.rb +0 -10
  88. data/test/rails_root/script/create_project.rb +0 -52
  89. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +0 -21
  90. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/formtastic.rb +0 -1236
  91. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/justin_french/formtastic.rb +0 -10
  92. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/rails/init.rb +0 -3
  93. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/formtastic_spec.rb +0 -2900
  94. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/test_helper.rb +0 -14
@@ -1,6 +1,6 @@
1
1
  # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
- # It is recommended to regenerate this file in the future when you upgrade to a
3
- # newer version of cucumber-rails. Consider adding your own code to a new file
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
4
  # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
5
  # files.
6
6
 
@@ -12,16 +12,17 @@ require 'cucumber/rails/world'
12
12
  require 'cucumber/rails/active_record'
13
13
  require 'cucumber/web/tableish'
14
14
 
15
- require 'webrat'
16
- require 'webrat/core/matchers'
15
+ require 'capybara/rails'
16
+ require 'capybara/cucumber'
17
+ require 'capybara/session'
18
+ require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
19
+ # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
20
+ # order to ease the transition to Capybara we set the default here. If you'd
21
+ # prefer to use XPath just remove this line and adjust any selectors in your
22
+ # steps to use the XPath syntax.
23
+ Capybara.default_selector = :css
17
24
 
18
- Webrat.configure do |config|
19
- config.mode = :rails
20
- config.open_error_files = false # Set to true if you want error pages to pop up in the browser
21
- end
22
-
23
-
24
- # If you set this to false, any error raised from within your app will bubble
25
+ # If you set this to false, any error raised from within your app will bubble
25
26
  # up to your step definition and out to cucumber unless you catch it somewhere
26
27
  # on the way. You can make Rails rescue errors and render error pages on a
27
28
  # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
@@ -33,15 +34,24 @@ end
33
34
  ActionController::Base.allow_rescue = false
34
35
 
35
36
  # If you set this to true, each scenario will run in a database transaction.
36
- # You can still turn off transactions on a per-scenario basis, simply tagging
37
+ # You can still turn off transactions on a per-scenario basis, simply tagging
37
38
  # a feature or scenario with the @no-txn tag. If you are using Capybara,
38
39
  # tagging with @culerity or @javascript will also turn transactions off.
39
40
  #
40
41
  # If you set this to false, transactions will be off for all scenarios,
41
42
  # regardless of whether you use @no-txn or not.
42
43
  #
43
- # Beware that turning transactions off will leave data in your database
44
- # after each scenario, which can lead to hard-to-debug failures in
44
+ # Beware that turning transactions off will leave data in your database
45
+ # after each scenario, which can lead to hard-to-debug failures in
45
46
  # subsequent scenarios. If you do this, we recommend you create a Before
46
47
  # block that will explicitly put your database in a known state.
47
48
  Cucumber::Rails::World.use_transactional_fixtures = true
49
+ # How to clean your database when transactions are turned off. See
50
+ # http://github.com/bmabey/database_cleaner for more info.
51
+ if defined?(ActiveRecord::Base)
52
+ begin
53
+ require 'database_cleaner'
54
+ DatabaseCleaner.strategy = :truncation
55
+ rescue LoadError => ignore_if_database_cleaner_not_present
56
+ end
57
+ end
@@ -1,21 +1,43 @@
1
1
  module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in web_steps.rb
7
+ #
2
8
  def path_to(page_name)
3
9
  case page_name
4
10
 
5
11
  when /the home\s?page/
6
12
  '/'
13
+
14
+ # Add more mappings here.
7
15
  when /the sign up page/i
8
16
  sign_up_path
9
17
  when /the sign in page/i
10
18
  sign_in_path
11
19
  when /the password reset request page/i
12
20
  new_password_path
13
-
14
- # Add more page name => path mappings here
21
+ when /the sign up page/i
22
+ sign_up_path
23
+ when /the sign in page/i
24
+ sign_in_path
25
+ when /the password reset request page/i
26
+ new_password_path
27
+ # Here is an example that pulls values out of the Regexp:
28
+ #
29
+ # when /^(.*)'s profile page$/i
30
+ # user_profile_path(User.find_by_login($1))
15
31
 
16
32
  else
17
- raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
18
- "Now, go and add a mapping in #{__FILE__}"
33
+ begin
34
+ page_name =~ /the (.*) page/
35
+ path_components = $1.split(/\s+/)
36
+ self.send(path_components.push('path').join('_').to_sym)
37
+ rescue Object => e
38
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
39
+ "Now, go and add a mapping in #{__FILE__}"
40
+ end
19
41
  end
20
42
  end
21
43
  end
@@ -5,7 +5,6 @@ class AccountsControllerTest < ActionController::TestCase
5
5
  context "when signed out" do
6
6
  setup { sign_out }
7
7
  should_deny_access_on :get, :edit
8
- should_deny_access_on :put, :update
9
8
  end
10
9
 
11
10
  context "on POST to create" do
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'rails/performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionDispatch::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7
+ #
8
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
9
+ # -- they do not yet inherit this setting
10
+ fixtures :all
11
+
12
+ # Add more helper methods to be used by all tests here...
13
+ end
@@ -0,0 +1,5 @@
1
+ require 'action_view/helpers/dynamic_form'
2
+
3
+ class ActionView::Base
4
+ include DynamicForm
5
+ end
@@ -0,0 +1,300 @@
1
+ require 'action_view/helpers'
2
+ require 'active_support/i18n'
3
+ require 'active_support/core_ext/enumerable'
4
+ require 'active_support/core_ext/object/blank'
5
+
6
+ module ActionView
7
+ module Helpers
8
+ # The Active Record Helper makes it easier to create forms for records kept in instance variables. The most far-reaching is the +form+
9
+ # method that creates a complete form for all the basic content types of the record (not associations or aggregations, though). This
10
+ # is a great way of making the record quickly available for editing, but likely to prove lackluster for a complicated real-world form.
11
+ # In that case, it's better to use the +input+ method and the specialized +form+ methods in link:classes/ActionView/Helpers/FormHelper.html
12
+ module DynamicForm
13
+ # Returns a default input tag for the type of object returned by the method. For example, if <tt>@post</tt>
14
+ # has an attribute +title+ mapped to a +VARCHAR+ column that holds "Hello World":
15
+ #
16
+ # input("post", "title")
17
+ # # => <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
18
+ def input(record_name, method, options = {})
19
+ InstanceTag.new(record_name, method, self).to_tag(options)
20
+ end
21
+
22
+ # Returns an entire form with all needed input tags for a specified Active Record object. For example, if <tt>@post</tt>
23
+ # has attributes named +title+ of type +VARCHAR+ and +body+ of type +TEXT+ then
24
+ #
25
+ # form("post")
26
+ #
27
+ # would yield a form like the following (modulus formatting):
28
+ #
29
+ # <form action='/posts/create' method='post'>
30
+ # <p>
31
+ # <label for="post_title">Title</label><br />
32
+ # <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
33
+ # </p>
34
+ # <p>
35
+ # <label for="post_body">Body</label><br />
36
+ # <textarea cols="40" id="post_body" name="post[body]" rows="20"></textarea>
37
+ # </p>
38
+ # <input name="commit" type="submit" value="Create" />
39
+ # </form>
40
+ #
41
+ # It's possible to specialize the form builder by using a different action name and by supplying another
42
+ # block renderer. For example, if <tt>@entry</tt> has an attribute +message+ of type +VARCHAR+ then
43
+ #
44
+ # form("entry",
45
+ # :action => "sign",
46
+ # :input_block => Proc.new { |record, column|
47
+ # "#{column.human_name}: #{input(record, column.name)}<br />"
48
+ # })
49
+ #
50
+ # would yield a form like the following (modulus formatting):
51
+ #
52
+ # <form action="/entries/sign" method="post">
53
+ # Message:
54
+ # <input id="entry_message" name="entry[message]" size="30" type="text" /><br />
55
+ # <input name="commit" type="submit" value="Sign" />
56
+ # </form>
57
+ #
58
+ # It's also possible to add additional content to the form by giving it a block, such as:
59
+ #
60
+ # form("entry", :action => "sign") do |form|
61
+ # form << content_tag("b", "Department")
62
+ # form << collection_select("department", "id", @departments, "id", "name")
63
+ # end
64
+ #
65
+ # The following options are available:
66
+ #
67
+ # * <tt>:action</tt> - The action used when submitting the form (default: +create+ if a new record, otherwise +update+).
68
+ # * <tt>:input_block</tt> - Specialize the output using a different block, see above.
69
+ # * <tt>:method</tt> - The method used when submitting the form (default: +post+).
70
+ # * <tt>:multipart</tt> - Whether to change the enctype of the form to "multipart/form-data", used when uploading a file (default: +false+).
71
+ # * <tt>:submit_value</tt> - The text of the submit button (default: "Create" if a new record, otherwise "Update").
72
+ def form(record_name, options = {})
73
+ record = instance_variable_get("@#{record_name}")
74
+ record = convert_to_model(record)
75
+
76
+ options = options.symbolize_keys
77
+ options[:action] ||= record.persisted? ? "update" : "create"
78
+ action = url_for(:action => options[:action], :id => record)
79
+
80
+ submit_value = options[:submit_value] || options[:action].gsub(/[^\w]/, '').capitalize
81
+
82
+ contents = form_tag({:action => action}, :method =>(options[:method] || 'post'), :enctype => options[:multipart] ? 'multipart/form-data': nil)
83
+ contents.safe_concat hidden_field(record_name, :id) if record.persisted?
84
+ contents.safe_concat all_input_tags(record, record_name, options)
85
+ yield contents if block_given?
86
+ contents.safe_concat submit_tag(submit_value)
87
+ contents.safe_concat('</form>')
88
+ end
89
+
90
+ # Returns a string containing the error message attached to the +method+ on the +object+ if one exists.
91
+ # This error message is wrapped in a <tt>DIV</tt> tag by default or with <tt>:html_tag</tt> if specified,
92
+ # which can be extended to include a <tt>:prepend_text</tt> and/or <tt>:append_text</tt> (to properly explain
93
+ # the error), and a <tt>:css_class</tt> to style it accordingly. +object+ should either be the name of an
94
+ # instance variable or the actual object. The method can be passed in either as a string or a symbol.
95
+ # As an example, let's say you have a model <tt>@post</tt> that has an error message on the +title+ attribute:
96
+ #
97
+ # <%= error_message_on "post", "title" %>
98
+ # # => <div class="formError">can't be empty</div>
99
+ #
100
+ # <%= error_message_on @post, :title %>
101
+ # # => <div class="formError">can't be empty</div>
102
+ #
103
+ # <%= error_message_on "post", "title",
104
+ # :prepend_text => "Title simply ",
105
+ # :append_text => " (or it won't work).",
106
+ # :html_tag => "span",
107
+ # :css_class => "inputError" %>
108
+ # # => <span class="inputError">Title simply can't be empty (or it won't work).</span>
109
+ def error_message_on(object, method, *args)
110
+ options = args.extract_options!
111
+ unless args.empty?
112
+ ActiveSupport::Deprecation.warn('error_message_on takes an option hash instead of separate ' +
113
+ 'prepend_text, append_text, html_tag, and css_class arguments', caller)
114
+
115
+ options[:prepend_text] = args[0] || ''
116
+ options[:append_text] = args[1] || ''
117
+ options[:html_tag] = args[2] || 'div'
118
+ options[:css_class] = args[3] || 'formError'
119
+ end
120
+ options.reverse_merge!(:prepend_text => '', :append_text => '', :html_tag => 'div', :css_class => 'formError')
121
+
122
+ object = convert_to_model(object)
123
+
124
+ if (obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))) &&
125
+ (errors = obj.errors[method]).presence
126
+ content_tag(options[:html_tag],
127
+ (options[:prepend_text].html_safe << errors.first).safe_concat(options[:append_text]),
128
+ :class => options[:css_class]
129
+ )
130
+ else
131
+ ''
132
+ end
133
+ end
134
+
135
+ # Returns a string with a <tt>DIV</tt> containing all of the error messages for the objects located as instance variables by the names
136
+ # given. If more than one object is specified, the errors for the objects are displayed in the order that the object names are
137
+ # provided.
138
+ #
139
+ # This <tt>DIV</tt> can be tailored by the following options:
140
+ #
141
+ # * <tt>:header_tag</tt> - Used for the header of the error div (default: "h2").
142
+ # * <tt>:id</tt> - The id of the error div (default: "errorExplanation").
143
+ # * <tt>:class</tt> - The class of the error div (default: "errorExplanation").
144
+ # * <tt>:object</tt> - The object (or array of objects) for which to display errors,
145
+ # if you need to escape the instance variable convention.
146
+ # * <tt>:object_name</tt> - The object name to use in the header, or any text that you prefer.
147
+ # If <tt>:object_name</tt> is not set, the name of the first object will be used.
148
+ # * <tt>:header_message</tt> - The message in the header of the error div. Pass +nil+
149
+ # or an empty string to avoid the header message altogether. (Default: "X errors
150
+ # prohibited this object from being saved").
151
+ # * <tt>:message</tt> - The explanation message after the header message and before
152
+ # the error list. Pass +nil+ or an empty string to avoid the explanation message
153
+ # altogether. (Default: "There were problems with the following fields:").
154
+ #
155
+ # To specify the display for one object, you simply provide its name as a parameter.
156
+ # For example, for the <tt>@user</tt> model:
157
+ #
158
+ # error_messages_for 'user'
159
+ #
160
+ # You can also supply an object:
161
+ #
162
+ # error_messages_for @user
163
+ #
164
+ # This will use the last part of the model name in the presentation. For instance, if
165
+ # this is a MyKlass::User object, this will use "user" as the name in the String. This
166
+ # is taken from MyKlass::User.model_name.human, which can be overridden.
167
+ #
168
+ # To specify more than one object, you simply list them; optionally, you can add an extra <tt>:object_name</tt> parameter, which
169
+ # will be the name used in the header message:
170
+ #
171
+ # error_messages_for 'user_common', 'user', :object_name => 'user'
172
+ #
173
+ # You can also use a number of objects, which will have the same naming semantics
174
+ # as a single object.
175
+ #
176
+ # error_messages_for @user, @post
177
+ #
178
+ # If the objects cannot be located as instance variables, you can add an extra <tt>:object</tt> parameter which gives the actual
179
+ # object (or array of objects to use):
180
+ #
181
+ # error_messages_for 'user', :object => @question.user
182
+ #
183
+ # NOTE: This is a pre-packaged presentation of the errors with embedded strings and a certain HTML structure. If what
184
+ # you need is significantly different from the default presentation, it makes plenty of sense to access the <tt>object.errors</tt>
185
+ # instance yourself and set it up. View the source of this method to see how easy it is.
186
+ def error_messages_for(*params)
187
+ options = params.extract_options!.symbolize_keys
188
+
189
+ objects = Array.wrap(options.delete(:object) || params).map do |object|
190
+ object = instance_variable_get("@#{object}") unless object.respond_to?(:to_model)
191
+ object = convert_to_model(object)
192
+
193
+ if object.class.respond_to?(:model_name)
194
+ options[:object_name] ||= object.class.model_name.human.downcase
195
+ end
196
+
197
+ object
198
+ end
199
+
200
+ objects.compact!
201
+ count = objects.inject(0) {|sum, object| sum + object.errors.count }
202
+
203
+ unless count.zero?
204
+ html = {}
205
+ [:id, :class].each do |key|
206
+ if options.include?(key)
207
+ value = options[key]
208
+ html[key] = value unless value.blank?
209
+ else
210
+ html[key] = 'errorExplanation'
211
+ end
212
+ end
213
+ options[:object_name] ||= params.first
214
+
215
+ I18n.with_options :locale => options[:locale], :scope => [:errors, :template] do |locale|
216
+ header_message = if options.include?(:header_message)
217
+ options[:header_message]
218
+ else
219
+ locale.t :header, :count => count, :model => options[:object_name].to_s.gsub('_', ' ')
220
+ end
221
+
222
+ message = options.include?(:message) ? options[:message] : locale.t(:body)
223
+
224
+ error_messages = objects.sum do |object|
225
+ object.errors.full_messages.map do |msg|
226
+ content_tag(:li, msg)
227
+ end
228
+ end.join.html_safe
229
+
230
+ contents = ''
231
+ contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank?
232
+ contents << content_tag(:p, message) unless message.blank?
233
+ contents << content_tag(:ul, error_messages)
234
+
235
+ content_tag(:div, contents.html_safe, html)
236
+ end
237
+ else
238
+ ''
239
+ end
240
+ end
241
+
242
+ private
243
+
244
+ def all_input_tags(record, record_name, options)
245
+ input_block = options[:input_block] || default_input_block
246
+ record.class.content_columns.collect{ |column| input_block.call(record_name, column) }.join("\n")
247
+ end
248
+
249
+ def default_input_block
250
+ Proc.new { |record, column| %(<p><label for="#{record}_#{column.name}">#{column.human_name}</label><br />#{input(record, column.name)}</p>) }
251
+ end
252
+
253
+ module InstanceTagMethods
254
+ def to_tag(options = {})
255
+ case column_type
256
+ when :string
257
+ field_type = @method_name.include?("password") ? "password" : "text"
258
+ to_input_field_tag(field_type, options)
259
+ when :text
260
+ to_text_area_tag(options)
261
+ when :integer, :float, :decimal
262
+ to_input_field_tag("text", options)
263
+ when :date
264
+ to_date_select_tag(options)
265
+ when :datetime, :timestamp
266
+ to_datetime_select_tag(options)
267
+ when :time
268
+ to_time_select_tag(options)
269
+ when :boolean
270
+ to_boolean_select_tag(options)
271
+ end
272
+ end
273
+
274
+ def column_type
275
+ object.send(:column_for_attribute, @method_name).type
276
+ end
277
+ end
278
+
279
+ module FormBuilderMethods
280
+ def error_message_on(method, *args)
281
+ @template.error_message_on(@object || @object_name, method, *args)
282
+ end
283
+
284
+ def error_messages(options = {})
285
+ @template.error_messages_for(@object_name, objectify_options(options))
286
+ end
287
+ end
288
+ end
289
+
290
+ class InstanceTag
291
+ include DynamicForm::InstanceTagMethods
292
+ end
293
+
294
+ class FormBuilder
295
+ include DynamicForm::FormBuilderMethods
296
+ end
297
+ end
298
+ end
299
+
300
+ I18n.load_path << File.expand_path("../../locale/en.yml", __FILE__)