diff --git a/vendor/plugins/nested_has_many_through/.gitignore b/vendor/plugins/nested_has_many_through/.gitignore new file mode 100644 index 0000000..57f3a0b --- /dev/null +++ b/vendor/plugins/nested_has_many_through/.gitignore @@ -0,0 +1,2 @@ +.garlic +doc/* diff --git a/vendor/plugins/nested_has_many_through/CHANGELOG b/vendor/plugins/nested_has_many_through/CHANGELOG new file mode 100644 index 0000000..2a62803 --- /dev/null +++ b/vendor/plugins/nested_has_many_through/CHANGELOG @@ -0,0 +1,4 @@ +* spec'd and fixed some problems with using named_scope in edge + +* Initial commit + diff --git a/vendor/plugins/nested_has_many_through/MIT-LICENSE b/vendor/plugins/nested_has_many_through/MIT-LICENSE new file mode 100644 index 0000000..906139d --- /dev/null +++ b/vendor/plugins/nested_has_many_through/MIT-LICENSE @@ -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. \ No newline at end of file diff --git a/vendor/plugins/nested_has_many_through/README.rdoc b/vendor/plugins/nested_has_many_through/README.rdoc new file mode 100755 index 0000000..03f01f6 --- /dev/null +++ b/vendor/plugins/nested_has_many_through/README.rdoc @@ -0,0 +1,92 @@ +http://plugins.ardes.com > nested_has_many_through + += 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 it's running on 2.0, 2.1, and 2.2 stable branches + +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) diff --git a/vendor/plugins/nested_has_many_through/SPECDOC b/vendor/plugins/nested_has_many_through/SPECDOC new file mode 100644 index 0000000..6ce019f --- /dev/null +++ b/vendor/plugins/nested_has_many_through/SPECDOC @@ -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 diff --git a/vendor/plugins/nested_has_many_through/TODO b/vendor/plugins/nested_has_many_through/TODO new file mode 100644 index 0000000..76e4409 --- /dev/null +++ b/vendor/plugins/nested_has_many_through/TODO @@ -0,0 +1,10 @@ +* 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 \ No newline at end of file diff --git a/vendor/plugins/nested_has_many_through/garlic.rb b/vendor/plugins/nested_has_many_through/garlic.rb new file mode 100644 index 0000000..57c0b85 --- /dev/null +++ b/vendor/plugins/nested_has_many_through/garlic.rb @@ -0,0 +1,27 @@ +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 + ['origin/2-2-stable', 'origin/2-1-stable', 'origin/2-0-stable'].each do |rails| + # specify how to prepare app and run CI task + target "Rails: #{rails}", :tree_ish => 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 diff --git a/vendor/plugins/nested_has_many_through/spec/app.rb b/vendor/plugins/nested_has_many_through/spec/app.rb new file mode 100644 index 0000000..71c7c4e --- /dev/null +++ b/vendor/plugins/nested_has_many_through/spec/app.rb @@ -0,0 +1,84 @@ +# Testing app setup + +################## +# Database schema +################## + +ActiveRecord::Migration.suppress_messages do + ActiveRecord::Schema.define(:version => 0) do + create_table :users, :force => true do |t| + t.column "type", :string + end + + create_table :posts, :force => true do |t| + t.column "author_id", :integer + t.column "category_id", :integer + t.column "inflamatory", :boolean + end + + create_table :categories, :force => true do |t| + end + + create_table :comments, :force => true do |t| + t.column "user_id", :integer + t.column "post_id", :integer + end + end +end + +######### +# Models +# +# Domain model is this: +# +# - authors (type of user) can create posts in categories +# - users can comment on posts +# - authors have similar_posts: posts in the same categories as ther posts +# - authors have similar_authors: authors of the recommended_posts +# - authors have posts_of_similar_authors: all posts by similar authors (not just the similar posts, +# similar_posts is be a subset of this collection) +# - authors have commenters: users who have commented on their posts +# +class User < ActiveRecord::Base + has_many :comments + has_many :commented_posts, :through => :comments, :source => :post, :uniq => true + has_many :commented_authors, :through => :commented_posts, :source => :author, :uniq => true + has_many :posts_of_interest, :through => :commented_authors, :source => :posts_of_similar_authors, :uniq => true + has_many :categories_of_interest, :through => :posts_of_interest, :source => :category, :uniq => true +end + +class Author < User + has_many :posts + has_many :categories, :through => :posts + 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 + + # testing with_scope + def self.find_inflamatory(*args) + with_scope :find => {:conditions => {:inflamatory => true}} do + find(*args) + end + end + + # only test named_scope in edge + named_scope(:inflamatory, :conditions => {:inflamatory => true}) if respond_to?(:named_scope) + + belongs_to :author + belongs_to :category + has_many :comments + has_many :commenters, :through => :comments, :source => :user, :uniq => true +end + +class Category < ActiveRecord::Base + has_many :posts +end + +class Comment < ActiveRecord::Base + belongs_to :user + belongs_to :post +end \ No newline at end of file diff --git a/vendor/plugins/nested_has_many_through/spec/models/author_spec.rb b/vendor/plugins/nested_has_many_through/spec/models/author_spec.rb new file mode 100644 index 0000000..36ccf18 --- /dev/null +++ b/vendor/plugins/nested_has_many_through/spec/models/author_spec.rb @@ -0,0 +1,85 @@ +require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper')) +require File.expand_path(File.join(File.dirname(__FILE__), '../app')) + +describe Author do + describe "(newly created)" do + before do + @category = Category.create! + @other_category = Category.create! + @author = Author.create! + end + + it "#posts should == []" do + @author.posts.should == [] + end + + it "#categories should == []" do + @author.categories.should == [] + end + + it "#similar_posts should == []" do + @author.similar_posts.should == [] + end + + it "#similar_authors should == []" do + @author.similar_authors.should == [] + end + + it "#commenters should == []" do + @author.commenters.should == [] + end + + describe "who creates post with category" do + before do + @post = Post.create! :author => @author, :category => @category + end + + it "#posts should == [post]" do + @author.posts.should == [@post] + end + + it "#categories should == [category]" do + @author.categories.should == [@category] + end + + describe "and @other_author creates post2 in category" do + + before do + @other_author = Author.create! + @post2 = Post.create! :author => @other_author, :category => @category + end + + it "#posts should == [post2]" do + @author.posts.should == [@post] + end + + it "#categories should == [category]" do + @author.categories.should == [@category] + end + + it "#similar_posts.should == [post, post2]" do + @author.similar_posts.should == [@post, @post2] + end + + it "#similar_authors.should == [@author, @other_author]" do + @author.similar_authors.should == [@author, @other_author] + end + + describe "and creates @other_post in @other_category" do + before do + @other_category = Category.create! + @other_post = Post.create! :author => @other_author, :category => @other_category + end + + it "#similar_posts.should == [@post, @post2]" do + @author.similar_posts.should == [@post, @post2] + end + + it "#posts_by_similar_authors.should == [@post, @post2, @other_post]" do + @author.posts_of_similar_authors.should == [@post, @post2, @other_post] + end + end + end + end + end +end \ No newline at end of file diff --git a/vendor/plugins/nested_has_many_through/spec/models/commenter_spec.rb b/vendor/plugins/nested_has_many_through/spec/models/commenter_spec.rb new file mode 100644 index 0000000..b57b3ce --- /dev/null +++ b/vendor/plugins/nested_has_many_through/spec/models/commenter_spec.rb @@ -0,0 +1,109 @@ +require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper')) +require File.expand_path(File.join(File.dirname(__FILE__), '../app')) + +describe 'Commenter use case (a1: p1>c1, a2: p2>c1, p3>c2, a3: p4>c3)' do + before do + @c1 = Category.create! + @c2 = Category.create! + @c3 = Category.create! + @a1 = Author.create! + @a2 = Author.create! + @a3 = Author.create! + @p1 = @a1.posts.create! :category => @c1 + @p2 = @a2.posts.create! :category => @c1 + @p3 = @a2.posts.create! :category => @c2 + @p4 = @a3.posts.create! :category => @c3 + @a1.reload + @a2.reload + end + + it "a1.posts should == [p1]" do + @a1.posts.should == [@p1] + end + + it "a1.categories should == [c1]" do + @a1.categories.should == [@c1] + end + + it "a2.posts should == [p2, p3]" do + @a2.posts.should == [@p2, @p3] + end + + it "a2.categories should == [c1, c2]" do + @a2.categories.should == [@c1, @c2] + end + + describe "u1 comments on p2" do + before do + @u1 = User.create! + @comment = @p2.comments.create! :user => @u1 + end + + it "u1.comments should == [comment]" do + @u1.comments.should == [@comment] + end + + it "a1.commenters should be empty" do + @a1.commenters.should be_empty + end + + it "a2.commenters should == [u1]" do + @a2.commenters.should == [@u1] + end + + it "u1.commented_posts should == [p2]" do + @u1.commented_posts.should == [@p2] + end + + it "u1.commented_posts.find_inflamatory(:all) should be empty" do + @u1.commented_posts.find_inflamatory(:all).should be_empty + end + + if ActiveRecord::Base.respond_to?(:named_scope) + it "u1.commented_posts.inflamatory should be empty" do + @u1.commented_posts.inflamatory.should be_empty + end + end + + it "u1.commented_authors should == [a2]" do + @u1.commented_authors.should == [@a2] + end + + it "u1.posts_of_interest should == [p1, p2, p3]" do + @u1.posts_of_interest.should == [@p1, @p2, @p3] + end + + it "u1.categories_of_interest should == [c1, c2]" do + @u1.categories_of_interest.should == [@c1, @c2] + end + + describe "when p2 is inflamatory" do + before do + @p2.toggle!(:inflamatory) + end + + it "p2 should be inflamatory" do + @p2.should be_inflamatory + end + + it "u1.commented_posts.find_inflamatory(:all) should == [p2]" do + # uniq ids is here (and next spec) because eager loading changed behaviour 2.0.2 => edge + @u1.commented_posts.find_inflamatory(:all).collect(&:id).uniq.should == [@p2.id] + end + + it "u1.posts_of_interest.find_inflamatory(:all).uniq should == [p2]" do + @u1.posts_of_interest.find_inflamatory(:all).collect(&:id).uniq.should == [@p2.id] + end + + if ActiveRecord::Base.respond_to?(:named_scope) + it "u1.commented_posts.inflamatory should == [p2]" do + @u1.commented_posts.inflamatory.should == [@p2] + end + + it "u1.posts_of_interest.inflamatory should == [p2]" do + @u1.posts_of_interest.inflamatory.should == [@p2] + end + end + end + end +end diff --git a/vendor/plugins/nested_has_many_through/spec/spec_helper.rb b/vendor/plugins/nested_has_many_through/spec/spec_helper.rb new file mode 100644 index 0000000..8e21f5b --- /dev/null +++ b/vendor/plugins/nested_has_many_through/spec/spec_helper.rb @@ -0,0 +1,23 @@ +# This file is copied to ~/spec when you run 'ruby script/generate rspec' +# from the project root directory. +ENV["RAILS_ENV"] ||= "test" +require File.expand_path(File.join(File.dirname(__FILE__), "../../../../config/environment")) +require 'spec/rails' + +Spec::Runner.configure do |config| + config.use_transactional_fixtures = true + config.use_instantiated_fixtures = false + config.fixture_path = RAILS_ROOT + '/spec/fixtures' + + # You can declare fixtures for each behaviour like this: + # describe "...." do + # fixtures :table_a, :table_b + # + # Alternatively, if you prefer to declare them only once, you can + # do so here, like so ... + # + # config.global_fixtures = :table_a, :table_b + # + # If you declare global fixtures, be aware that they will be declared + # for all of your examples, even those that don't use them. +end \ No newline at end of file -- libgit2 0.21.2