bbenezech-nested_form 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +104 -0
- data/Rakefile +30 -0
- data/lib/generators/nested_form/install_generator.rb +17 -0
- data/lib/nested_form.rb +1 -0
- data/lib/nested_form/builder_mixin.rb +66 -0
- data/lib/nested_form/builders.rb +23 -0
- data/lib/nested_form/engine.rb +14 -0
- data/lib/nested_form/view_helper.rb +42 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +5 -0
- data/spec/dummy/app/assets/javascripts/jquery.js +8981 -0
- data/spec/dummy/app/assets/javascripts/jquery_nested_form.js +71 -0
- data/spec/dummy/app/assets/javascripts/projects.js +2 -0
- data/spec/dummy/app/assets/javascripts/prototype.js +6082 -0
- data/spec/dummy/app/assets/javascripts/prototype_nested_form.js +51 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/assets/stylesheets/projects.css +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/projects_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/projects_helper.rb +2 -0
- data/spec/dummy/app/models/milestone.rb +3 -0
- data/spec/dummy/app/models/project.rb +4 -0
- data/spec/dummy/app/models/task.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +11 -0
- data/spec/dummy/app/views/projects/new.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +42 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +27 -0
- data/spec/dummy/config/environments/production.rb +54 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +59 -0
- data/spec/dummy/db/migrate/20110710143903_initial_tables.rb +23 -0
- data/spec/dummy/db/schema.rb +29 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/test/functional/projects_controller_test.rb +7 -0
- data/spec/dummy/test/unit/helpers/projects_helper_test.rb +4 -0
- data/spec/form_spec.rb +31 -0
- data/spec/nested_form/builder_spec.rb +42 -0
- data/spec/nested_form/view_helper_spec.rb +47 -0
- data/spec/spec_helper.rb +16 -0
- metadata +126 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
class InitialTables < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :projects do |t|
|
4
|
+
t.string :name
|
5
|
+
end
|
6
|
+
|
7
|
+
create_table :tasks do |t|
|
8
|
+
t.integer :project_id
|
9
|
+
t.string :name
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table :milestones do |t|
|
13
|
+
t.integer :task_id
|
14
|
+
t.string :name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.down
|
19
|
+
drop_table :projects
|
20
|
+
drop_table :tasks
|
21
|
+
drop_table :milestones
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended to check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(:version => 20110710143903) do
|
14
|
+
|
15
|
+
create_table "milestones", :force => true do |t|
|
16
|
+
t.integer "task_id"
|
17
|
+
t.string "name"
|
18
|
+
end
|
19
|
+
|
20
|
+
create_table "projects", :force => true do |t|
|
21
|
+
t.string "name"
|
22
|
+
end
|
23
|
+
|
24
|
+
create_table "tasks", :force => true do |t|
|
25
|
+
t.integer "project_id"
|
26
|
+
t.string "name"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
data/spec/form_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'NestedForm' do
|
4
|
+
include Capybara::DSL
|
5
|
+
|
6
|
+
def check_form
|
7
|
+
page.should have_no_css('form .fields input[id$=name]')
|
8
|
+
click_link 'Add new task'
|
9
|
+
page.should have_css('form .fields input[id$=name]', :count => 1)
|
10
|
+
find('form .fields input[id$=name]').should be_visible
|
11
|
+
find('form .fields input[id$=_destroy]').value.should == 'false'
|
12
|
+
|
13
|
+
click_link 'Remove'
|
14
|
+
find('form .fields input[id$=_destroy]').value.should == '1'
|
15
|
+
find('form .fields input[id$=name]').should_not be_visible
|
16
|
+
|
17
|
+
click_link 'Add new task'
|
18
|
+
click_link 'Add new task'
|
19
|
+
fields = all('form .fields')
|
20
|
+
fields.select { |field| field.visible? }.count.should == 2
|
21
|
+
fields.reject { |field| field.visible? }.count.should == 1
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should work with jQuery and Prototype', :js => true do
|
25
|
+
visit '/projects/new'
|
26
|
+
check_form
|
27
|
+
|
28
|
+
visit '/projects/new?type=prototype'
|
29
|
+
check_form
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
[NestedForm::Builder, NestedForm::SimpleBuilder, defined?(NestedForm::FormtasticBuilder) ? NestedForm::FormtasticBuilder : nil].compact.each do |builder|
|
4
|
+
describe builder do
|
5
|
+
describe "with no options" do
|
6
|
+
before(:each) do
|
7
|
+
@project = Project.new
|
8
|
+
@template = ActionView::Base.new
|
9
|
+
@template.output_buffer = ""
|
10
|
+
@builder = builder.new(:item, @project, @template, {}, proc {})
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has an add link which behaves similar to a Rails link_to" do
|
14
|
+
@builder.link_to_add("Add", :tasks).should == '<a href="javascript:void(0)" class="add_nested_fields" data-association="tasks">Add</a>'
|
15
|
+
@builder.link_to_add("Add", :tasks, :class => "foo", :href => "url").should == '<a href="url" class="foo add_nested_fields" data-association="tasks">Add</a>'
|
16
|
+
@builder.link_to_add(:tasks) { "Add" }.should == '<a href="javascript:void(0)" class="add_nested_fields" data-association="tasks">Add</a>'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has a remove link which behaves similar to a Rails link_to" do
|
20
|
+
@builder.link_to_remove("Remove").should == '<input id="item__destroy" name="item[_destroy]" type="hidden" value="false" /><a href="javascript:void(0)" class="remove_nested_fields">Remove</a>'
|
21
|
+
@builder.link_to_remove("Remove", :class => "foo", :href => "url").should == '<input id="item__destroy" name="item[_destroy]" type="hidden" value="false" /><a href="url" class="foo remove_nested_fields">Remove</a>'
|
22
|
+
@builder.link_to_remove { "Remove" }.should == '<input id="item__destroy" name="item[_destroy]" type="hidden" value="false" /><a href="javascript:void(0)" class="remove_nested_fields">Remove</a>'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should wrap nested fields each in a div with class" do
|
26
|
+
2.times { @project.tasks.build }
|
27
|
+
@builder.fields_for(:tasks) do
|
28
|
+
"Task"
|
29
|
+
end.should == '<div class="fields">Task</div><div class="fields">Task</div>'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should add task fields to hidden div after form" do
|
33
|
+
pending
|
34
|
+
output = ""
|
35
|
+
mock(@template).after_nested_form(:tasks) { |arg, block| output << block.call }
|
36
|
+
@builder.fields_for(:tasks) { "Task" }
|
37
|
+
@builder.link_to_add("Add", :tasks)
|
38
|
+
output.should == '<div id="tasks_fields_blueprint" style="display: none"><div class="fields">Task</div></div>'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NestedForm::ViewHelper do
|
4
|
+
include RSpec::Rails::HelperExampleGroup
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
_routes.draw do
|
8
|
+
resources :projects
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should pass nested form builder to form_for along with other options" do
|
13
|
+
pending
|
14
|
+
mock.proxy(_view).form_for(:first, :as => :second, :other => :arg, :builder => NestedForm::Builder) do |form_html|
|
15
|
+
form_html
|
16
|
+
end
|
17
|
+
_view.nested_form_for(:first, :as => :second, :other => :arg) {"form"}
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should pass instance of NestedForm::Builder to nested_form_for block" do
|
21
|
+
_view.nested_form_for(Project.new) do |f|
|
22
|
+
f.should be_instance_of(NestedForm::Builder)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should pass instance of NestedForm::SimpleBuilder to simple_nested_form_for block" do
|
27
|
+
_view.simple_nested_form_for(Project.new) do |f|
|
28
|
+
f.should be_instance_of(NestedForm::SimpleBuilder)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if defined?(NestedForm::FormtasticBuilder)
|
33
|
+
it "should pass instance of NestedForm::FormtasticBuilder to semantic_nested_form_for block" do
|
34
|
+
_view.semantic_nested_form_for(Project.new) do |f|
|
35
|
+
f.should be_instance_of(NestedForm::FormtasticBuilder)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should append content to end of nested form" do
|
41
|
+
_view.after_nested_form(:tasks) { _view.concat("123") }
|
42
|
+
_view.after_nested_form(:milestones) { _view.concat("456") }
|
43
|
+
_view.nested_form_for(Project.new) {}
|
44
|
+
_view.output_buffer.should include("123456")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require 'rspec/rails'
|
6
|
+
require 'capybara/rspec'
|
7
|
+
|
8
|
+
Capybara.javascript_driver = :selenium
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.mock_with :mocha
|
11
|
+
end
|
12
|
+
|
13
|
+
Rails.backtrace_cleaner.remove_silencers!
|
14
|
+
|
15
|
+
# Load support files
|
16
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bbenezech-nested_form
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ryan Bates
|
9
|
+
- Andrea Singh
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-11-18 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec-rails
|
17
|
+
requirement: &70293943121360 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.6.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70293943121360
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: mocha
|
28
|
+
requirement: &70293943120320 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70293943120320
|
37
|
+
description: Gem to conveniently handle multiple models in a single form with Rails
|
38
|
+
3 and jQuery or Prototype. Version maintained by fxposter.
|
39
|
+
email: ryan@railscasts.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- lib/generators/nested_form/install_generator.rb
|
45
|
+
- lib/nested_form/builder_mixin.rb
|
46
|
+
- lib/nested_form/builders.rb
|
47
|
+
- lib/nested_form/engine.rb
|
48
|
+
- lib/nested_form/view_helper.rb
|
49
|
+
- lib/nested_form.rb
|
50
|
+
- spec/dummy/app/assets/javascripts/application.js
|
51
|
+
- spec/dummy/app/assets/javascripts/jquery.js
|
52
|
+
- spec/dummy/app/assets/javascripts/jquery_nested_form.js
|
53
|
+
- spec/dummy/app/assets/javascripts/projects.js
|
54
|
+
- spec/dummy/app/assets/javascripts/prototype.js
|
55
|
+
- spec/dummy/app/assets/javascripts/prototype_nested_form.js
|
56
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
57
|
+
- spec/dummy/app/assets/stylesheets/projects.css
|
58
|
+
- spec/dummy/app/controllers/application_controller.rb
|
59
|
+
- spec/dummy/app/controllers/projects_controller.rb
|
60
|
+
- spec/dummy/app/helpers/application_helper.rb
|
61
|
+
- spec/dummy/app/helpers/projects_helper.rb
|
62
|
+
- spec/dummy/app/models/milestone.rb
|
63
|
+
- spec/dummy/app/models/project.rb
|
64
|
+
- spec/dummy/app/models/task.rb
|
65
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
66
|
+
- spec/dummy/app/views/projects/new.html.erb
|
67
|
+
- spec/dummy/config/application.rb
|
68
|
+
- spec/dummy/config/boot.rb
|
69
|
+
- spec/dummy/config/database.yml
|
70
|
+
- spec/dummy/config/environment.rb
|
71
|
+
- spec/dummy/config/environments/development.rb
|
72
|
+
- spec/dummy/config/environments/production.rb
|
73
|
+
- spec/dummy/config/environments/test.rb
|
74
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
75
|
+
- spec/dummy/config/initializers/inflections.rb
|
76
|
+
- spec/dummy/config/initializers/mime_types.rb
|
77
|
+
- spec/dummy/config/initializers/secret_token.rb
|
78
|
+
- spec/dummy/config/initializers/session_store.rb
|
79
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
80
|
+
- spec/dummy/config/locales/en.yml
|
81
|
+
- spec/dummy/config/routes.rb
|
82
|
+
- spec/dummy/config.ru
|
83
|
+
- spec/dummy/db/migrate/20110710143903_initial_tables.rb
|
84
|
+
- spec/dummy/db/schema.rb
|
85
|
+
- spec/dummy/public/404.html
|
86
|
+
- spec/dummy/public/422.html
|
87
|
+
- spec/dummy/public/500.html
|
88
|
+
- spec/dummy/public/favicon.ico
|
89
|
+
- spec/dummy/Rakefile
|
90
|
+
- spec/dummy/script/rails
|
91
|
+
- spec/dummy/test/functional/projects_controller_test.rb
|
92
|
+
- spec/dummy/test/unit/helpers/projects_helper_test.rb
|
93
|
+
- spec/form_spec.rb
|
94
|
+
- spec/nested_form/builder_spec.rb
|
95
|
+
- spec/nested_form/view_helper_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
- CHANGELOG.rdoc
|
98
|
+
- LICENSE
|
99
|
+
- Rakefile
|
100
|
+
- README.rdoc
|
101
|
+
homepage: http://github.com/bbenezech/nested_form
|
102
|
+
licenses: []
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 1.3.4
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project: bbenezech-nested_form
|
121
|
+
rubygems_version: 1.8.11
|
122
|
+
signing_key:
|
123
|
+
specification_version: 3
|
124
|
+
summary: Gem to conveniently handle multiple models in a single form. Version maintained
|
125
|
+
by fxposter.
|
126
|
+
test_files: []
|