Few minor fixes:

- Gemfile.lock is kicked out
- rdoc/task fix

Added support of  in associations
This commit is contained in:
fl00r 2012-03-12 23:07:10 +04:00
parent 47b5f678b4
commit 04c231570b
6 changed files with 21 additions and 127 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ spec/dummy/tmp/
.rvmrc .rvmrc
.idea .idea
coverage/ coverage/
Gemfile.lock

View File

@ -1,125 +0,0 @@
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.1.3)
actionpack (= 3.1.3)
mail (~> 2.3.0)
actionpack (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
rack (~> 1.3.5)
rack-cache (~> 1.1)
rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
sprockets (~> 2.0.3)
activemodel (3.1.3)
activesupport (= 3.1.3)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
arel (~> 2.2.1)
tzinfo (~> 0.3.29)
activeresource (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
activesupport (3.1.3)
multi_json (~> 1.0)
arel (2.2.1)
builder (3.0.0)
diff-lcs (1.1.3)
erubis (2.7.0)
generator_spec (0.8.4)
rails (>= 3.0, < 4.0)
rspec-rails
git (1.2.5)
hike (1.2.1)
i18n (0.6.0)
jeweler (1.6.4)
bundler (~> 1.0)
git (>= 1.2.5)
rake
json (1.6.3)
json_pure (1.6.3)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.0.4)
polyglot (0.3.3)
rack (1.3.5)
rack-cache (1.1)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.1.3)
actionmailer (= 3.1.3)
actionpack (= 3.1.3)
activerecord (= 3.1.3)
activeresource (= 3.1.3)
activesupport (= 3.1.3)
bundler (~> 1.0)
railties (= 3.1.3)
railties (3.1.3)
actionpack (= 3.1.3)
activesupport (= 3.1.3)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rdoc (3.11)
json (~> 1.4)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
rspec-mocks (~> 2.7.0)
rspec-core (2.7.1)
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.7.0)
rspec-rails (2.7.0)
actionpack (~> 3.0)
activesupport (~> 3.0)
railties (~> 3.0)
rspec (~> 2.7.0)
simplecov (0.5.4)
multi_json (~> 1.0.3)
simplecov-html (~> 0.5.3)
simplecov-html (0.5.3)
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.31)
PLATFORMS
ruby
DEPENDENCIES
actionpack (>= 3.0.0)
generator_spec
jeweler
json_pure
rails (>= 3.0.0)
rspec (>= 2.6.0)
rspec-rails (>= 2.6.0)
simplecov
sqlite3-ruby

View File

@ -7,7 +7,7 @@ rescue LoadError
end end
require 'rake' require 'rake'
require 'rake/rdoctask' require 'rdoc/task'
require 'rspec/core' require 'rspec/core'
require 'rspec/core/rake_task' require 'rspec/core/rake_task'

View File

@ -65,12 +65,22 @@ module Cocoon
html_options[:'data-association'] = association.to_s.singularize html_options[:'data-association'] = association.to_s.singularize
html_options[:'data-associations'] = association.to_s.pluralize html_options[:'data-associations'] = association.to_s.pluralize
new_object = f.object.class.reflect_on_association(association).klass.new new_object = create_object(f, association)
html_options[:'data-template'] = CGI.escapeHTML(render_association(association, f, new_object, render_options)).html_safe html_options[:'data-template'] = CGI.escapeHTML(render_association(association, f, new_object, render_options)).html_safe
link_to(name, '#', html_options ) link_to(name, '#', html_options )
end end
end end
# creates new association object with its conditions, like
# `` has_many :admin_comments, class_name: "Comment", conditions: { author: "Admin" }
# will create new Comment with author "Admin"
def create_object(f, association)
assoc = f.object.class.reflect_on_association(association)
conditions = assoc.conditions.flatten
new_object = assoc.klass.new(*conditions)
end
end end
end end

View File

@ -18,6 +18,13 @@ describe Cocoon do
@tester.stub(:render_association).and_return('form<tag>') @tester.stub(:render_association).and_return('form<tag>')
end end
context "association with conditions" do
it "should create correct association" do
result = @tester.create_object(@form_obj, :admin_comments)
result.author.should == "Admin"
end
end
context "without a block" do context "without a block" do
it "should accept a name" do it "should accept a name" do
result = @tester.link_to_add_association('add something', @form_obj, :comments) result = @tester.link_to_add_association('add something', @form_obj, :comments)

View File

@ -1,4 +1,5 @@
class Post < ActiveRecord::Base class Post < ActiveRecord::Base
has_many :comments has_many :comments
has_many :admin_comments, class_name: "Comment", :conditions => { :author => "Admin" }
has_many :people has_many :people
end end