Permalink
Browse files

add spec for Many-to-many

  • Loading branch information...
unixcharles committed Dec 23, 2010
1 parent 22228b2 commit 3bc92da646009425a45e205d0cc60e8eef205ea1
Showing with 47 additions and 0 deletions.
  1. +18 −0 spec/immortal_spec.rb
  2. +29 −0 spec/spec_helper.rb
View
@@ -177,4 +177,22 @@
ImmortalModel.count.should == 2
end
it "should consider an Many-to-many association with through as deleted when the join is deleted." do
@n = ImmortalNode.create! :title => 'testing association'
@join = ImmortalJoin.create! :immortal_model_id => @m.id, :immortal_node_id => @n.id
@m.reload
@m.immortal_nodes.count.should == 1
@n.reload
@n.immortal_models.count.should == 1
@join.destroy
@m.reload
@m.immortal_nodes.count.should == 0
@n.reload
@n.immortal_models.count.should == 0
end
end
View
@@ -27,6 +27,18 @@
t.boolean :deleted, :default => false
t.timestamps
end
create_table :immortal_joins do |t|
t.integer :immortal_model_id
t.integer :immortal_node_id
t.boolean :deleted, :default => false
t.timestamps
end
create_table :immortal_nodes do |t|
t.string :title
t.integer :value
t.boolean :deleted, :default => false
t.timestamps
end
end
ensure
$stdout = old_stdout
@@ -35,6 +47,9 @@
class ImmortalModel < ActiveRecord::Base
include Immortal
has_many :immortal_nodes, :through => :immortal_joins
has_many :immortal_joins
attr_accessor :before_d, :after_d, :before_u, :after_u
before_destroy :set_before
@@ -60,3 +75,17 @@ def set_before_update
end
end
class ImmortalJoin < ActiveRecord::Base
include Immortal
belongs_to :immortal_model
belongs_to :immortal_node
end
class ImmortalNode < ActiveRecord::Base
include Immortal
has_many :immortal_joins
has_many :immortal_models, :through => :immortal_joins
end

0 comments on commit 3bc92da

Please sign in to comment.