public
Last active

Not a good idea.

  • Download Gist
active something.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
require 'rubygems'
require 'acts_as_fu'
 
build_model(:articles) do
has_many :comments do
def votes
Vote.scoped(:include => { :comment => :article }, :conditions => ['articles.id = ?', proxy_owner.id])
end
def authors
Author.scoped(:include => :comments, :conditions => ['comments.article_id = ?', proxy_owner.id])
end
end
end
 
build_model(:comments) do
integer :author_id
integer :article_id
belongs_to :article
belongs_to :author
has_many :votes
end
 
build_model(:authors) do
has_many :comments
end
 
build_model(:votes) do
integer :comment_id
belongs_to :comment
end
 
require 'spec'
 
describe 'Association funkiness' do
before(:each) do
@article = Article.create!
@comment = Comment.create! :article => @article
@other_comment = Comment.create! :article => @article
end
it "works normally" do
@article.comments.should include(@comment, @other_comment)
end
describe "loading has many relationships" do
before(:each) do
@vote = Vote.create! :comment => @comment
@other_vote = Vote.create! :comment => @other_comment
end
it "loads through has many throughs" do
@article.comments.votes.should include(@vote, @other_vote)
end
it "is a proxy object" do
@article.comments.votes.find(:first).should == @vote
end
end
describe "loading belongs to relationships" do
before(:each) do
@author = Author.create! :comments => [@comment]
@other_author = Author.create! :comments => [@other_comment]
end
it "loads through has many throughs" do
@article.comments.authors.should include(@author, @other_author)
end
it "is a proxy object" do
@article.comments.authors.find(:first).should == @author
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.