cocoon 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -157,9 +157,8 @@ There is no limit to the amount of nesting, though.
157
157
 
158
158
  ## Todo
159
159
 
160
- * complete the sample projects -for simple_form- and normal rails forms
161
160
  * add more sample relations: has_many :through, belongs_to, ...
162
- * complete the test-coverage
161
+ * improve the tests (test the javascript too)(if anybody wants to lend a hand ...?)
163
162
 
164
163
  ## Copyright
165
164
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cocoon}
8
- s.version = "1.0.2"
8
+ s.version = "1.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nathan Van der Auwera"]
12
- s.date = %q{2011-03-06}
12
+ s.date = %q{2011-03-15}
13
13
  s.description = %q{Unobtrusive nested forms handling, using jQuery. Use this and discover cocoon-heaven.}
14
14
  s.email = %q{nathan@dixis.com}
15
15
  s.extra_rdoc_files = [
@@ -32,6 +32,8 @@ Gem::Specification.new do |s|
32
32
  "spec/dummy/Rakefile",
33
33
  "spec/dummy/app/controllers/application_controller.rb",
34
34
  "spec/dummy/app/helpers/application_helper.rb",
35
+ "spec/dummy/app/models/comment.rb",
36
+ "spec/dummy/app/models/post.rb",
35
37
  "spec/dummy/app/views/layouts/application.html.erb",
36
38
  "spec/dummy/config.ru",
37
39
  "spec/dummy/config/application.rb",
@@ -48,6 +50,9 @@ Gem::Specification.new do |s|
48
50
  "spec/dummy/config/initializers/session_store.rb",
49
51
  "spec/dummy/config/locales/en.yml",
50
52
  "spec/dummy/config/routes.rb",
53
+ "spec/dummy/db/migrate/20110306212208_create_posts.rb",
54
+ "spec/dummy/db/migrate/20110306212250_create_comments.rb",
55
+ "spec/dummy/db/schema.rb",
51
56
  "spec/dummy/public/404.html",
52
57
  "spec/dummy/public/422.html",
53
58
  "spec/dummy/public/500.html",
@@ -71,6 +76,8 @@ Gem::Specification.new do |s|
71
76
  s.test_files = [
72
77
  "spec/spec_helper.rb",
73
78
  "spec/dummy/app/controllers/application_controller.rb",
79
+ "spec/dummy/app/models/comment.rb",
80
+ "spec/dummy/app/models/post.rb",
74
81
  "spec/dummy/app/helpers/application_helper.rb",
75
82
  "spec/dummy/config/environment.rb",
76
83
  "spec/dummy/config/initializers/session_store.rb",
@@ -84,6 +91,9 @@ Gem::Specification.new do |s|
84
91
  "spec/dummy/config/application.rb",
85
92
  "spec/dummy/config/routes.rb",
86
93
  "spec/dummy/config/boot.rb",
94
+ "spec/dummy/db/schema.rb",
95
+ "spec/dummy/db/migrate/20110306212208_create_posts.rb",
96
+ "spec/dummy/db/migrate/20110306212250_create_comments.rb",
87
97
  "spec/cocoon_spec.rb",
88
98
  "spec/integration/navigation_spec.rb"
89
99
  ]
@@ -61,12 +61,9 @@ module Cocoon
61
61
  html_options[:'data-association'] = association.to_s.singularize
62
62
 
63
63
  new_object = f.object.class.reflect_on_association(association).klass.new
64
- model_name = new_object.class.name.underscore
65
- hidden_div = content_tag('div', :id => "#{model_name}_fields_template", :style => "display:none;") do
66
- render_association(association, f, new_object)
67
- end
64
+ html_options[:'data-template'] = CGI.escapeHTML(render_association(association, f, new_object))
68
65
 
69
- hidden_div.html_safe + link_to(name, '#', html_options )
66
+ link_to(name, '#', html_options )
70
67
  end
71
68
  end
72
69
 
@@ -2,7 +2,7 @@ $(document).ready(function() {
2
2
 
3
3
  $('.add_fields').live('click', function() {
4
4
  var assoc = $(this).attr('data-association');
5
- var content = $(this).siblings('#' + assoc + '_fields_template').html();
5
+ var content = $(this).attr('data-template');
6
6
  var insertionPosition = $(this).attr('data-association-insertion-position');
7
7
  var insertionNode = $(this).attr('data-association-insertion-node');
8
8
  var regexp_braced = new RegExp('\\[new_' + assoc + '\\]', 'g');
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Cocoon do
4
-
5
4
  class TestClass < ActionView::Base
6
5
 
7
6
  end
@@ -11,4 +10,80 @@ describe Cocoon do
11
10
  it { should respond_to(:link_to_add_association) }
12
11
  it { should respond_to(:link_to_remove_association) }
13
12
 
14
- end
13
+ context "link_to_add_association" do
14
+ before(:each) do
15
+ @tester = TestClass.new
16
+ @post = Post.new
17
+ @form_obj = stub(:object => @post)
18
+ @tester.stub(:render_association).and_return('form<tag>')
19
+ end
20
+
21
+ context "without a block" do
22
+ it "should accept a name" do
23
+ result = @tester.link_to_add_association('add something', @form_obj, :comments)
24
+ result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-template="form&amp;lt;tag&amp;gt;">add something</a>'
25
+ end
26
+
27
+ it "should accept html options and pass them to link_to" do
28
+ result = @tester.link_to_add_association('add something', @form_obj, :comments, {:class => 'something silly'})
29
+ result.to_s.should == '<a href="#" class="something silly add_fields" data-association="comment" data-template="form&amp;lt;tag&amp;gt;">add something</a>'
30
+ end
31
+ end
32
+
33
+ context "with a block" do
34
+ it "the block gives the link text" do
35
+ result = @tester.link_to_add_association(@form_obj, :comments) do
36
+ "some long name"
37
+ end
38
+ result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-template="form&amp;lt;tag&amp;gt;">some long name</a>'
39
+ end
40
+
41
+ it "should accept html options and pass them to link_to" do
42
+ result = @tester.link_to_add_association(@form_obj, :comments, {:class => 'floppy disk'}) do
43
+ "some long name"
44
+ end
45
+ result.to_s.should == '<a href="#" class="floppy disk add_fields" data-association="comment" data-template="form&amp;lt;tag&amp;gt;">some long name</a>'
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
52
+ context "link_to_remove_association" do
53
+ before(:each) do
54
+ @tester = TestClass.new
55
+ @post = Post.new
56
+ @form_obj = stub(:object => @post, :object_name => @post.class.name)
57
+ end
58
+
59
+ context "without a block" do
60
+ it "should accept a name" do
61
+ result = @tester.link_to_remove_association('remove something', @form_obj)
62
+ result.to_s.should == "<input id=\"Post__destroy\" name=\"Post[_destroy]\" type=\"hidden\" /><a href=\"#\" class=\"remove_fields dynamic\">remove something</a>"
63
+ end
64
+
65
+ it "should accept html options and pass them to link_to" do
66
+ result = @tester.link_to_remove_association('remove something', @form_obj, {:class => 'add_some_class', :'data-something' => 'bla'})
67
+ result.to_s.should == "<input id=\"Post__destroy\" name=\"Post[_destroy]\" type=\"hidden\" /><a href=\"#\" class=\"add_some_class remove_fields dynamic\" data-something=\"bla\">remove something</a>"
68
+ end
69
+
70
+ end
71
+
72
+ context "with a block" do
73
+ it "the block gives the name" do
74
+ result = @tester.link_to_remove_association(@form_obj) do
75
+ "remove some long name"
76
+ end
77
+ result.to_s.should == "<input id=\"Post__destroy\" name=\"Post[_destroy]\" type=\"hidden\" /><a href=\"#\" class=\"remove_fields dynamic\">remove some long name</a>"
78
+ end
79
+
80
+ it "should accept html options and pass them to link_to" do
81
+ result = @tester.link_to_remove_association(@form_obj, {:class => 'add_some_class', :'data-something' => 'bla'}) do
82
+ "remove some long name"
83
+ end
84
+ result.to_s.should == "<input id=\"Post__destroy\" name=\"Post[_destroy]\" type=\"hidden\" /><a href=\"#\" class=\"add_some_class remove_fields dynamic\" data-something=\"bla\">remove some long name</a>"
85
+ end
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,3 @@
1
+ class Comment < ActiveRecord::Base
2
+ belongs_to :post
3
+ end
@@ -0,0 +1,3 @@
1
+ class Post < ActiveRecord::Base
2
+ has_many :comments
3
+ end
@@ -0,0 +1,14 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :body
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :posts
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ class CreateComments < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :comments do |t|
4
+ t.text :body
5
+ t.string :author
6
+ t.integer :post_id
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :comments
14
+ end
15
+ end
@@ -0,0 +1,30 @@
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 => 20110306212250) do
14
+
15
+ create_table "comments", :force => true do |t|
16
+ t.text "body"
17
+ t.string "author"
18
+ t.integer "post_id"
19
+ t.datetime "created_at"
20
+ t.datetime "updated_at"
21
+ end
22
+
23
+ create_table "posts", :force => true do |t|
24
+ t.string "title"
25
+ t.text "body"
26
+ t.datetime "created_at"
27
+ t.datetime "updated_at"
28
+ end
29
+
30
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 2
9
- version: 1.0.2
8
+ - 3
9
+ version: 1.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nathan Van der Auwera
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-06 00:00:00 +01:00
17
+ date: 2011-03-15 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -57,6 +57,8 @@ files:
57
57
  - spec/dummy/Rakefile
58
58
  - spec/dummy/app/controllers/application_controller.rb
59
59
  - spec/dummy/app/helpers/application_helper.rb
60
+ - spec/dummy/app/models/comment.rb
61
+ - spec/dummy/app/models/post.rb
60
62
  - spec/dummy/app/views/layouts/application.html.erb
61
63
  - spec/dummy/config.ru
62
64
  - spec/dummy/config/application.rb
@@ -73,6 +75,9 @@ files:
73
75
  - spec/dummy/config/initializers/session_store.rb
74
76
  - spec/dummy/config/locales/en.yml
75
77
  - spec/dummy/config/routes.rb
78
+ - spec/dummy/db/migrate/20110306212208_create_posts.rb
79
+ - spec/dummy/db/migrate/20110306212250_create_comments.rb
80
+ - spec/dummy/db/schema.rb
76
81
  - spec/dummy/public/404.html
77
82
  - spec/dummy/public/422.html
78
83
  - spec/dummy/public/500.html
@@ -101,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
106
  requirements:
102
107
  - - ">="
103
108
  - !ruby/object:Gem::Version
104
- hash: -715901887
109
+ hash: -916485471
105
110
  segments:
106
111
  - 0
107
112
  version: "0"
@@ -123,6 +128,8 @@ summary: gem that enables easier nested forms with standard forms, formtastic an
123
128
  test_files:
124
129
  - spec/spec_helper.rb
125
130
  - spec/dummy/app/controllers/application_controller.rb
131
+ - spec/dummy/app/models/comment.rb
132
+ - spec/dummy/app/models/post.rb
126
133
  - spec/dummy/app/helpers/application_helper.rb
127
134
  - spec/dummy/config/environment.rb
128
135
  - spec/dummy/config/initializers/session_store.rb
@@ -136,5 +143,8 @@ test_files:
136
143
  - spec/dummy/config/application.rb
137
144
  - spec/dummy/config/routes.rb
138
145
  - spec/dummy/config/boot.rb
146
+ - spec/dummy/db/schema.rb
147
+ - spec/dummy/db/migrate/20110306212208_create_posts.rb
148
+ - spec/dummy/db/migrate/20110306212250_create_comments.rb
139
149
  - spec/cocoon_spec.rb
140
150
  - spec/integration/navigation_spec.rb