Permalink
Browse files

2.3.5

  • Loading branch information...
1 parent a52a11b commit eeece3d66af88526fb3c28d5f8b1e21f54ce795e @angelo0000 angelo0000 committed May 12, 2010
@@ -0,0 +1,4 @@
+* spec'd and fixed some problems with using named_scope in edge
+
+* Initial commit
+
@@ -0,0 +1,20 @@
+Copyright (c) 2008 Ian White - ian.w.white@gmail.com
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,95 @@
+== NOTE: rails 2.3 users might want to try the experimental rails-2.3 branch
+
+= nested_has_many_through
+
+A fantastic patch/plugin has been floating around for a while:
+
+* http://dev.rubyonrails.org/ticket/6461
+* http://code.torchbox.com/svn/rails/plugins/nested_has_many_through
+
+obrie made the original ticket and Matt Westcott released the first version of
+the plugin, under the MIT license. Many others have contributed, see the trac
+ticket for details.
+
+Here is a refactored version (I didn't write the original), suitable for edge/2.0-stable
+with a bunch of acceptance specs. I'm concentrating on plugin usage, once
+it becomes stable, and well enough speced/understood, then it's time to pester
+rails-core.
+
+== Why republish this on github?
+
+* The previous implementations are very poorly speced/tested, so it's pretty
+ hard to refactor and understand this complicated bit of sql-fu, especially
+ when you're aiming at a moving target (edge)
+* the lastest patches don't apply on edge
+* github - let's collab to make this better and get a patch accepted, fork away!
+
+== Help out
+
+I'm releasing 'early and often' in the hope that people will use it and find bugs/problems.
+Report them at http://ianwhite.lighthouseapp.com, or fork and pull request, yada yada.
+
+== History
+
+Here's the original description:
+
+ This plugin makes it possible to define has_many :through relationships that
+ go through other has_many :through relationships, possibly through an
+ arbitrarily deep hierarchy. This allows associations across any number of
+ tables to be constructed, without having to resort to find_by_sql (which isn't
+ a suitable solution if you need to do eager loading through :include as well).
+
+== Contributors
+
+* Matt Westcott
+* terceiro
+* shoe
+* mhoroschun
+* Ian White (http://github.com/ianwhite)
+* Claudio (http://github.com/masterkain)
+
+Get in touch if you should be on this list
+
+== Show me the money!
+
+Here's some models from the specs:
+
+ class Author < User
+ has_many :posts
+ has_many :categories, :through => :posts, :uniq => true
+ has_many :similar_posts, :through => :categories, :source => :posts
+ has_many :similar_authors, :through => :similar_posts, :source => :author, :uniq => true
+ has_many :posts_of_similar_authors, :through => :similar_authors, :source => :posts, :uniq => true
+ has_many :commenters, :through => :posts, :uniq => true
+ end
+
+ class Post < ActiveRecord::Base
+ belongs_to :author
+ belongs_to :category
+ has_many :comments
+ has_many :commenters, :through => :comments, :source => :user, :uniq => true
+ end
+
+The first two has_manys of Author are plain vanilla, the last four are what this plugin enables
+
+ # has_many through a has_many :through
+ has_many :similar_posts, :through => :categories, :source => :posts
+
+ # doubly nested has_many :through
+ has_many :similar_authors, :through => :similar_posts, :source => :author, :uniq => true
+
+ # whoah!
+ has_many :posts_of_similar_authors, :through => :similar_authors, :source => :posts, :uniq => true
+
+ # has_many through a has_many :through in another model
+ has_many :commenters, :through => :posts, :uniq => true
+
+== What does it run on?
+
+Currently the master branch is running on 2.1, and 2.2 stable branches
+
+Recent changes have made master incompatible with rails 2.0, if you want to use this
+with rails 2.0, then use the rails-2.0 branch.
+
+If you want to run the CI suite, then check out garlic_example.rb (The CI suite
+is being cooked with garlic - git://github.com/ianwhite/garlic)
@@ -0,0 +1,77 @@
+# use pluginized rpsec if it exists
+rspec_base = File.expand_path(File.dirname(__FILE__) + '/../rspec/lib')
+$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base) and !$LOAD_PATH.include?(rspec_base)
+
+require 'spec/rake/spectask'
+require 'spec/rake/verify_rcov'
+require 'rake/rdoctask'
+
+plugin_name = 'nested_has_many_through'
+
+task :default => :spec
+
+desc "Run the specs for #{plugin_name}"
+Spec::Rake::SpecTask.new(:spec) do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.spec_opts = ["--colour"]
+end
+
+namespace :spec do
+ desc "Generate RCov report for #{plugin_name}"
+ Spec::Rake::SpecTask.new(:rcov) do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.rcov = true
+ t.rcov_dir = 'doc/coverage'
+ t.rcov_opts = ['--text-report', '--exclude', "spec/,rcov.rb,#{File.expand_path(File.join(File.dirname(__FILE__),'../../..'))}"]
+ end
+
+ namespace :rcov do
+ desc "Verify RCov threshold for #{plugin_name}"
+ RCov::VerifyTask.new(:verify => "spec:rcov") do |t|
+ t.threshold = 97.1
+ t.index_html = File.join(File.dirname(__FILE__), 'doc/coverage/index.html')
+ end
+ end
+
+ desc "Generate specdoc for #{plugin_name}"
+ Spec::Rake::SpecTask.new(:doc) do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.spec_opts = ["--format", "specdoc:SPECDOC"]
+ end
+
+ namespace :doc do
+ desc "Generate html specdoc for #{plugin_name}"
+ Spec::Rake::SpecTask.new(:html => :rdoc) do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.spec_opts = ["--format", "html:doc/rspec_report.html", "--diff"]
+ end
+ end
+end
+
+task :rdoc => :doc
+task "SPECDOC" => "spec:doc"
+
+desc "Generate rdoc for #{plugin_name}"
+Rake::RDocTask.new(:doc) do |t|
+ t.rdoc_dir = 'doc'
+ t.main = 'README.rdoc'
+ t.title = "#{plugin_name}"
+ t.template = ENV['RDOC_TEMPLATE']
+ t.options = ['--line-numbers', '--inline-source']
+ t.rdoc_files.include('README.rdoc', 'SPECDOC', 'MIT-LICENSE')
+ t.rdoc_files.include('lib/**/*.rb')
+end
+
+namespace :doc do
+ desc "Generate all documentation (rdoc, specdoc, specdoc html and rcov) for #{plugin_name}"
+ task :all => ["spec:doc:html", "spec:doc", "spec:rcov", "doc"]
+end
+
+task :cruise do
+ # run the garlic task, capture the output, if succesful make the docs and copy them to ardes
+ sh "garlic all"
+ `garlic run > .garlic/report.txt`
+ `scp -i ~/.ssh/ardes .garlic/report.txt ardes@ardes.com:~/subdomains/plugins/httpdocs/doc/#{plugin_name}_garlic_report.txt`
+ `cd .garlic/*/vendor/plugins/#{plugin_name}; rake doc:all; scp -i ~/.ssh/ardes -r doc ardes@ardes.com:~/subdomains/plugins/httpdocs/doc/#{plugin_name}`
+ puts "The build is GOOD"
+end
@@ -0,0 +1,49 @@
+
+Author (newly created)
+- #posts should == []
+- #categories should == []
+- #similar_posts should == []
+- #similar_authors should == []
+- #commenters should == []
+
+Author (newly created) who creates post with category
+- #posts should == [post]
+- #categories should == [category]
+
+Author (newly created) who creates post with category and @other_author creates post2 in category
+- #posts should == [post2]
+- #categories should == [category]
+- #similar_posts.should == [post, post2]
+- #similar_authors.should == [@author, @other_author]
+
+Author (newly created) who creates post with category and @other_author creates post2 in category and creates @other_post in @other_category
+- #similar_posts.should == [@post, @post2]
+- #posts_by_similar_authors.should == [@post, @post2, @other_post]
+
+Commenter use case (a1: p1>c1, a2: p2>c1, p3>c2, a3: p4>c3)
+- a1.posts should == [p1]
+- a1.categories should == [c1]
+- a2.posts should == [p2, p3]
+- a2.categories should == [c1, c2]
+
+Commenter use case (a1: p1>c1, a2: p2>c1, p3>c2, a3: p4>c3) u1 comments on p2
+- u1.comments should == [comment]
+- a1.commenters should be empty
+- a2.commenters should == [u1]
+- u1.commented_posts should == [p2]
+- u1.commented_posts.find_inflamatory(:all) should be empty
+- u1.commented_posts.inflamatory should be empty
+- u1.commented_authors should == [a2]
+- u1.posts_of_interest should == [p1, p2, p3]
+- u1.categories_of_interest should == [c1, c2]
+
+Commenter use case (a1: p1>c1, a2: p2>c1, p3>c2, a3: p4>c3) u1 comments on p2 when p2 is inflamatory
+- p2 should be inflamatory
+- u1.commented_posts.find_inflamatory(:all) should == [p2]
+- u1.posts_of_interest.find_inflamatory(:all) should == [p2]
+- u1.commented_posts.inflamatory should == [p2]
+- u1.posts_of_interest.inflamatory should == [p2]
+
+Finished in 0.538693 seconds
+
+31 examples, 0 failures
@@ -0,0 +1,14 @@
+* belongs_to rel
+
+* review forks on github
+
+* get C2 up to 100%
+ - spec a polymorphic relationship
+
+* quote table names
+
+* make more use of rails in construct_has_many_or_belongs_to_attributes to reduce brittleness
+
+* Add more coverage
+ - scopes
+ - raise an error when nhmt is being used in a perverse way
@@ -0,0 +1,26 @@
+garlic do
+ repo 'nested_has_many_through', :path => '.'
+
+ repo 'rails', :url => 'git://github.com/rails/rails'
+ repo 'rspec', :url => 'git://github.com/dchelimsky/rspec'
+ repo 'rspec-rails', :url => 'git://github.com/dchelimsky/rspec-rails'
+
+ # target rails versions
+ ['2-3-stable', '2-2-stable', '2-1-stable'].each do |rails|
+ target rails, :branch => "origin/#{rails}" do
+ prepare do
+ plugin 'rspec'
+ plugin 'rspec-rails' do
+ `script/generate rspec -f`
+ end
+ plugin 'nested_has_many_through', :clone => true
+ end
+
+ run do
+ cd "vendor/plugins/nested_has_many_through" do
+ sh "rake spec:rcov:verify"
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,10 @@
+require 'nested_has_many_through'
+
+ActiveRecord::Associations::HasManyThroughAssociation.send :include, NestedHasManyThrough::Association
+
+# BC
+if defined?(ActiveRecord::Reflection::ThroughReflection)
+ ActiveRecord::Reflection::ThroughReflection.send :include, NestedHasManyThrough::Reflection
+else
+ ActiveRecord::Reflection::AssociationReflection.send :include, NestedHasManyThrough::Reflection
+end
Oops, something went wrong.

0 comments on commit eeece3d

Please sign in to comment.