Skip to content

Commit

Permalink
Adding dependent option to associations
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Jul 29, 2010
1 parent 54ac923 commit 7fdc1fc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
6 changes: 6 additions & 0 deletions lib/mongoid/associations/options.rb
Expand Up @@ -9,6 +9,12 @@ def initialize(attributes = {})
self.merge!(attributes)
end

# For relational associations we want to know if we cascade deletes or
# destroys to associations.
def dependent
self[:dependent]
end

# Returns the extension if it exists, nil if not.
def extension
self[:extend]
Expand Down
51 changes: 33 additions & 18 deletions spec/unit/mongoid/associations/options_spec.rb
Expand Up @@ -2,27 +2,18 @@

describe Mongoid::Associations::Options do

describe "#stored_as" do

before do
@attributes = { :stored_as => :array }
@options = Mongoid::Associations::Options.new(@attributes)
end
describe "#dependent" do

it "returns the association storage" do
@options.stored_as.should == :array
end
end

describe "#name" do
context "when dependent option exists" do

before do
@attributes = { :name => :addresses }
@options = Mongoid::Associations::Options.new(@attributes)
end
before do
@attributes = { :dependent => :destroy }
@options = Mongoid::Associations::Options.new(@attributes)
end

it "returns the association name" do
@options.name.should == "addresses"
it "returns the option" do
@options.dependent.should == :destroy
end
end
end

Expand Down Expand Up @@ -197,6 +188,18 @@
end
end

describe "#name" do

before do
@attributes = { :name => :addresses }
@options = Mongoid::Associations::Options.new(@attributes)
end

it "returns the association name" do
@options.name.should == "addresses"
end
end

describe "#polymorphic" do

context "when attribute provided" do
Expand All @@ -222,4 +225,16 @@
end
end
end

describe "#stored_as" do

before do
@attributes = { :stored_as => :array }
@options = Mongoid::Associations::Options.new(@attributes)
end

it "returns the association storage" do
@options.stored_as.should == :array
end
end
end

0 comments on commit 7fdc1fc

Please sign in to comment.