dry_forms 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/dry_forms.gemspec +59 -0
- data/lib/dry_forms/builder_additions.rb +75 -0
- data/lib/dry_forms/form_helper_additions.rb +7 -0
- data/lib/dry_forms.rb +36 -0
- data/pkg/dry_forms-0.0.1.gem +0 -0
- data/test/helper.rb +32 -0
- data/test/support/models.rb +42 -0
- data/test/test_dry_forms.rb +179 -0
- metadata +96 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Macario Ortega
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= dry_forms
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Macario Ortega. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "dry_forms"
|
8
|
+
gem.summary = %Q{Form builder additions for drier and localized forms, and association fields adding and removing with jQuery sweetness}
|
9
|
+
gem.description = %Q{Form builder additions for drier and localized forms, and association fields adding and removing with jQuery sweetness inspired by Ryan Bates' Railcast #197}
|
10
|
+
gem.email = "macarui@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/maca/dry_forms"
|
12
|
+
gem.authors = ["Macario Ortega"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "dry_forms #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/dry_forms.gemspec
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{dry_forms}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Macario Ortega"]
|
12
|
+
s.date = %q{2010-08-06}
|
13
|
+
s.description = %q{Form builder additions for drier and localized forms, and association fields adding and removing with jQuery sweetness inspired by Ryan Bates' Railcast #197}
|
14
|
+
s.email = %q{macarui@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"dry_forms.gemspec",
|
27
|
+
"lib/dry_forms.rb",
|
28
|
+
"lib/dry_forms/builder_additions.rb",
|
29
|
+
"lib/dry_forms/form_helper_additions.rb",
|
30
|
+
"pkg/dry_forms-0.0.1.gem",
|
31
|
+
"test/helper.rb",
|
32
|
+
"test/support/models.rb",
|
33
|
+
"test/test_dry_forms.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/maca/dry_forms}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.7}
|
39
|
+
s.summary = %q{Form builder additions for drier and localized forms, and association fields adding and removing with jQuery sweetness}
|
40
|
+
s.test_files = [
|
41
|
+
"test/helper.rb",
|
42
|
+
"test/support/models.rb",
|
43
|
+
"test/test_dry_forms.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module DryForms
|
2
|
+
module BuilderAdditions
|
3
|
+
helpers = ActionView::Helpers::FormBuilder.field_helpers.dup
|
4
|
+
helpers -= ['hidden_field', 'apply_form_for_options!', 'label', 'fields_for']
|
5
|
+
helpers += %w(date_select datetime_select time_select collection_select select country_select time_zone_select)
|
6
|
+
|
7
|
+
helpers.each do |name|
|
8
|
+
define_method "custom_#{name}" do |attribute, *args|
|
9
|
+
opts = args.extract_options!
|
10
|
+
label_text = opts.delete(:label_text) || @object ? @object.class.human_attribute_name(attribute) : attribute.to_s.titleize
|
11
|
+
label_opts = opts.delete(:label_options) || {}
|
12
|
+
html_opts = opts.delete(:html) || {}
|
13
|
+
html_opts[:class] = "#{name} #{html_opts[:class]}".strip
|
14
|
+
|
15
|
+
label = label attribute, label_text
|
16
|
+
field = send name, attribute, *(args << opts)
|
17
|
+
|
18
|
+
DryForms.field_markup label, field, @object && @object.errors[attribute], html_opts
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def fields_for_association association, options = {}, &block
|
23
|
+
association = association.to_s
|
24
|
+
|
25
|
+
unless @object.respond_to? "#{association.pluralize}_attributes="
|
26
|
+
raise NotImplementedError, "Please call `accepts_nested_attributes_for :#{association.pluralize}` in your `#{@object.class}` Model"
|
27
|
+
end
|
28
|
+
|
29
|
+
raise ArgumentError, "Missing block" unless block_given?
|
30
|
+
|
31
|
+
association_class = @object.class.reflect_on_association(association.to_sym).klass
|
32
|
+
singular_name = association.singularize
|
33
|
+
fields = association_fields association, &block
|
34
|
+
new_object = @object.send(association).build options.delete(:default_attributes) || {}
|
35
|
+
js_fields = association_fields association, new_object, :child_index => "new_#{singular_name}", &block
|
36
|
+
|
37
|
+
@template.concat <<-HTML
|
38
|
+
<div id="#{association}">
|
39
|
+
#{fields}
|
40
|
+
#{@template.javascript_tag "var fields_for_#{singular_name} = '#{js_fields.strip.gsub /\n\s+|\n/, ''}';"}
|
41
|
+
<a href="#" class="add_fields" data-association="#{singular_name}">#{I18n.t 'dry_forms.add', :model => association_class.human_name}</a>
|
42
|
+
</div>
|
43
|
+
HTML
|
44
|
+
end
|
45
|
+
|
46
|
+
def custom_fields_for *args, &block
|
47
|
+
opts = args.extract_options!
|
48
|
+
html_opts = opts.delete(:html) || {}
|
49
|
+
fields = @template.capture{fields_for *(args << opts), &block}
|
50
|
+
@template.concat DryForms.fields_for_markup(fields, html_opts) unless fields.empty?
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def association_fields association, object = nil, opts = {}, &block
|
55
|
+
opts.merge! :html => {:class => "associated", :'data-association' => association.singularize}
|
56
|
+
|
57
|
+
fields = @template.capture do
|
58
|
+
custom_fields_for association.to_sym, object, opts do |fields|
|
59
|
+
<<-HTML
|
60
|
+
#{fields.hidden_field :_destroy}
|
61
|
+
#{yield fields}
|
62
|
+
<a class="remove" href="#">#{I18n.t "dry_forms.remove"}</a>
|
63
|
+
HTML
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# def submit *args
|
69
|
+
# options = args.extract_options!
|
70
|
+
# options[:class] = "submit #{ options[:class] }".strip
|
71
|
+
# value = args.first || I18n.t(@object.new_record? ? 'create' : 'save', :scope => 'helpers.submit')
|
72
|
+
# super value, options
|
73
|
+
# end
|
74
|
+
end
|
75
|
+
end
|
data/lib/dry_forms.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'dry_forms/builder_additions'
|
4
|
+
require 'dry_forms/form_helper_additions'
|
5
|
+
|
6
|
+
module DryForms
|
7
|
+
class << self
|
8
|
+
def field_markup label, field, errors = nil, opts = {}
|
9
|
+
unless errors.blank?
|
10
|
+
error_explanation = %{ <span class="errors">#{ [*errors].to_sentence }</span>}
|
11
|
+
opts[:class] = "#{ opts[:class] } with_errors".strip
|
12
|
+
end
|
13
|
+
attributes = opts.map{|k,v| %{#{k}="#{v}"} }.join(' ')
|
14
|
+
|
15
|
+
<<-HTML
|
16
|
+
<dl #{attributes}>
|
17
|
+
<dt>#{label}#{error_explanation}</dt>
|
18
|
+
<dd>#{field}</dd>
|
19
|
+
</dl>
|
20
|
+
HTML
|
21
|
+
end
|
22
|
+
|
23
|
+
def fields_for_markup fields, opts = {}
|
24
|
+
attributes = opts.map{|k,v| %{#{k}="#{v}"} }.join(' ')
|
25
|
+
<<-HTML
|
26
|
+
<fieldset #{ attributes }>
|
27
|
+
#{fields}
|
28
|
+
</fieldset>
|
29
|
+
HTML
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
ActionView::Helpers::FormBuilder.send :include, DryForms
|
35
|
+
ActionView::Helpers::FormBuilder.send :include, DryForms::BuilderAdditions
|
36
|
+
ActionView::Helpers::FormHelper.send :include, DryForms::FormHelperAdditions
|
Binary file
|
data/test/helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
|
5
|
+
require 'active_support'
|
6
|
+
require 'action_pack'
|
7
|
+
require 'active_record'
|
8
|
+
require 'action_controller'
|
9
|
+
require 'action_view'
|
10
|
+
require 'action_view/test_case'
|
11
|
+
require 'action_controller/test_process'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift "#{File.dirname __FILE__}/../lib"
|
14
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
15
|
+
|
16
|
+
require 'dry_forms'
|
17
|
+
require 'support/models'
|
18
|
+
|
19
|
+
ActionController::Base.view_paths << FIXTURES = "#{ File.dirname __FILE__ }/fixtures'"
|
20
|
+
|
21
|
+
class ActionView::TestCase::TestController
|
22
|
+
attr_reader :url_for_options
|
23
|
+
def url_for(options)
|
24
|
+
@url_for_options = options
|
25
|
+
"/do"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class ActionView::Base
|
30
|
+
def protect_against_forgery?; end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
ActiveRecord::Migration.verbose = false
|
2
|
+
ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:"
|
3
|
+
|
4
|
+
ActiveRecord::Schema.define :version => 1 do
|
5
|
+
create_table :posts do |t|
|
6
|
+
t.string :title
|
7
|
+
t.integer :author_id
|
8
|
+
t.text :body
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table :authors do |t|
|
13
|
+
t.string :name
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
|
17
|
+
create_table :comments do |t|
|
18
|
+
t.string :title
|
19
|
+
t.integer :author_id
|
20
|
+
t.text :body
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
class Post < ActiveRecord::Base
|
29
|
+
belongs_to :author
|
30
|
+
accepts_nested_attributes_for :author
|
31
|
+
validates_presence_of :title
|
32
|
+
end
|
33
|
+
|
34
|
+
class Comment < ActiveRecord::Base
|
35
|
+
belongs_to :author
|
36
|
+
end
|
37
|
+
|
38
|
+
class Author < ActiveRecord::Base
|
39
|
+
has_many :posts
|
40
|
+
has_many :comments
|
41
|
+
accepts_nested_attributes_for :posts
|
42
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class FormHelperTest < ActionView::TestCase
|
4
|
+
tests ActionView::Helpers::FormHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@post = Post.new :title => "Hello World", :body => "Has to work"
|
8
|
+
@author = Author.new :name => "Macario"
|
9
|
+
@comment = Comment.new :title => "Hello World", :body => "Looking good"
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'helper method rendering' do
|
13
|
+
should 'render check_box with custom markup and display human_attribute_name' do
|
14
|
+
erb = <<-ERB
|
15
|
+
<% custom_form_for :post, @post do |f| %>
|
16
|
+
<%= f.custom_text_field :title, :class => 'title' %>
|
17
|
+
<% end %>
|
18
|
+
ERB
|
19
|
+
|
20
|
+
html = <<-HTML
|
21
|
+
<form action='/do' method='post'>
|
22
|
+
<dl class="text_field">
|
23
|
+
<dt><label for="post_title">Title</label></dt>
|
24
|
+
<dd>#{ text_field(:post, :title, :class => 'title') }</dd>
|
25
|
+
</dl>
|
26
|
+
</form>
|
27
|
+
HTML
|
28
|
+
|
29
|
+
assert_dom_equal html, render(:inline => erb)
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'render check_box with custom markup and display human_attribute_name and html attributes' do
|
33
|
+
erb = <<-ERB
|
34
|
+
<% custom_form_for :post, @post do |f| %>
|
35
|
+
<%= f.custom_text_field :title, :class => 'title', :html => {:id => 'id', :class => 'class'} %>
|
36
|
+
<% end %>
|
37
|
+
ERB
|
38
|
+
|
39
|
+
html = <<-HTML
|
40
|
+
<form action='/do' method='post'>
|
41
|
+
<dl class="text_field class" id="id">
|
42
|
+
<dt><label for="post_title">Title</label></dt>
|
43
|
+
<dd>#{ text_field(:post, :title, :class => 'title') }</dd>
|
44
|
+
</dl>
|
45
|
+
</form>
|
46
|
+
HTML
|
47
|
+
|
48
|
+
assert_dom_equal html, render(:inline => erb)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'field with errors' do
|
53
|
+
should 'render check_box with custom markup and display human_attribute_name' do
|
54
|
+
@post.title = nil
|
55
|
+
assert_equal false, @post.valid?
|
56
|
+
|
57
|
+
erb = <<-ERB
|
58
|
+
<% custom_form_for :post, @post do |f| %>
|
59
|
+
<%= f.custom_text_field :title, :class => 'title' %>
|
60
|
+
<% end %>
|
61
|
+
ERB
|
62
|
+
|
63
|
+
html = <<-HTML
|
64
|
+
<form method="post" action="/do">
|
65
|
+
<dl class="text_field with_errors">
|
66
|
+
<dt><div class="fieldWithErrors"><label for="post_title">Title</label></div><span class="errors">can't be blank</span></dt>
|
67
|
+
<dd><div class="fieldWithErrors"><input name="post[title]" size="30" class="title" id="post_title" type="text" /></div></dd>
|
68
|
+
</dl>
|
69
|
+
</form>
|
70
|
+
HTML
|
71
|
+
|
72
|
+
assert_dom_equal html, render(:inline => erb)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'field for associations' do
|
78
|
+
should 'render js fields' do
|
79
|
+
erb = <<-ERB
|
80
|
+
<% form_for :author, @author do |form| %>
|
81
|
+
<h2>Posts</h2>
|
82
|
+
<% form.fields_for_association :posts do |post| %>
|
83
|
+
<%= post.text_field :title %>
|
84
|
+
<% end %>
|
85
|
+
<% end %>
|
86
|
+
ERB
|
87
|
+
|
88
|
+
js_fields = <<-HTML
|
89
|
+
<fieldset class="associated" data-association="post">
|
90
|
+
<input id="author_posts_attributes_new_post__destroy" name="author[posts_attributes][new_post][_destroy]" type="hidden" />
|
91
|
+
<input id="author_posts_attributes_new_post_title" name="author[posts_attributes][new_post][title]" size="30" type="text" />
|
92
|
+
<a class="remove" href="#">translation missing: en, dry_forms, remove</a>
|
93
|
+
</fieldset>
|
94
|
+
HTML
|
95
|
+
|
96
|
+
html = <<-HTML
|
97
|
+
<form method="post" action="/do">
|
98
|
+
<h2>Posts</h2>
|
99
|
+
<div id="posts">
|
100
|
+
<script type="text/javascript">
|
101
|
+
//<![CDATA[
|
102
|
+
var fields_for_post = '#{js_fields.gsub(/\n\s+/, '').strip}';
|
103
|
+
//]]>
|
104
|
+
</script>
|
105
|
+
<a href="#" class="add_fields" data-association="post">translation missing: en, dry_forms, add</a>
|
106
|
+
</div>
|
107
|
+
</form>
|
108
|
+
HTML
|
109
|
+
|
110
|
+
assert_dom_equal html, render(:inline => erb)
|
111
|
+
end
|
112
|
+
|
113
|
+
should 'render field for associations' do
|
114
|
+
@author.posts << @post
|
115
|
+
|
116
|
+
erb = <<-ERB
|
117
|
+
<% form_for :author, @author do |form| %>
|
118
|
+
<h2>Posts</h2>
|
119
|
+
<% form.fields_for_association :posts do |post| %>
|
120
|
+
<%= post.text_field :title %>
|
121
|
+
<% end %>
|
122
|
+
<% end %>
|
123
|
+
ERB
|
124
|
+
|
125
|
+
js_fields = <<-HTML
|
126
|
+
<fieldset class="associated" data-association="post">
|
127
|
+
<input id="author_posts_attributes_new_post__destroy" name="author[posts_attributes][new_post][_destroy]" type="hidden" />
|
128
|
+
<input id="author_posts_attributes_new_post_title" name="author[posts_attributes][new_post][title]" size="30" type="text" />
|
129
|
+
<a class="remove" href="#">translation missing: en, dry_forms, remove</a>
|
130
|
+
</fieldset>
|
131
|
+
HTML
|
132
|
+
|
133
|
+
html = <<-HTML
|
134
|
+
<form method="post" action="/do">
|
135
|
+
<h2>Posts</h2>
|
136
|
+
<div id="posts">
|
137
|
+
<fieldset class="associated" data-association="post">
|
138
|
+
<input name="author[posts_attributes][0][_destroy]" id="author_posts_attributes_0__destroy" type="hidden" />
|
139
|
+
<input name="author[posts_attributes][0][title]" size="30" id="author_posts_attributes_0_title" value="Hello World" type="text" />
|
140
|
+
<a href="#" class="remove">translation missing: en, dry_forms, remove</a>
|
141
|
+
</fieldset>
|
142
|
+
<script type="text/javascript">
|
143
|
+
//<![CDATA[
|
144
|
+
var fields_for_post = '#{js_fields.gsub(/\n\s+/, '').strip}';
|
145
|
+
//]]>
|
146
|
+
</script>
|
147
|
+
<a href="#" class="add_fields" data-association="post">translation missing: en, dry_forms, add</a>
|
148
|
+
</div>
|
149
|
+
</form>
|
150
|
+
HTML
|
151
|
+
|
152
|
+
assert_dom_equal html, render(:inline => erb)
|
153
|
+
end
|
154
|
+
|
155
|
+
should 'raise error if model does not accepts nested attributes for association' do
|
156
|
+
assert_raises(NotImplementedError) do
|
157
|
+
form_for :comment, @comment do |form|
|
158
|
+
form.fields_for_association(:author) {}
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
should 'raise error if model does not accepts nested attributes for pluralized association' do
|
164
|
+
assert_raises(NotImplementedError) do
|
165
|
+
form_for :post, @post do |form|
|
166
|
+
form.fields_for_association(:author) {}
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
should 'raise argument error if no block is passed' do
|
172
|
+
assert_raises(ArgumentError) do
|
173
|
+
form_for :author, @author do |form|
|
174
|
+
form.fields_for_association(:posts)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dry_forms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Macario Ortega
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-06 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: thoughtbot-shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: "Form builder additions for drier and localized forms, and association fields adding and removing with jQuery sweetness inspired by Ryan Bates' Railcast #197"
|
36
|
+
email: macarui@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- dry_forms.gemspec
|
52
|
+
- lib/dry_forms.rb
|
53
|
+
- lib/dry_forms/builder_additions.rb
|
54
|
+
- lib/dry_forms/form_helper_additions.rb
|
55
|
+
- pkg/dry_forms-0.0.1.gem
|
56
|
+
- test/helper.rb
|
57
|
+
- test/support/models.rb
|
58
|
+
- test/test_dry_forms.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/maca/dry_forms
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --charset=UTF-8
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.3.7
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Form builder additions for drier and localized forms, and association fields adding and removing with jQuery sweetness
|
93
|
+
test_files:
|
94
|
+
- test/helper.rb
|
95
|
+
- test/support/models.rb
|
96
|
+
- test/test_dry_forms.rb
|