Skip to content

Commit

Permalink
Added Model#destroy and Model#destroy!
Browse files Browse the repository at this point in the history
  • Loading branch information
dkubb committed May 25, 2010
1 parent ce817d0 commit 602d061
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/dm-core/model.rb
Expand Up @@ -494,6 +494,26 @@ def create!(attributes = {})
_create(attributes, false)
end

# Remove all Resources from the repository
#
# @return [Boolean]
# true if the resources were successfully destroyed
#
# @api public
def destroy
all.destroy
end

# Remove all Resources from the repository, bypassing validation
#
# @return [Boolean]
# true if the resources were successfully destroyed
#
# @api public
def destroy!
all.destroy!
end

# Copy a set of records from one repository to another.
#
# @param [String] source_repository_name
Expand Down
12 changes: 12 additions & 0 deletions spec/public/model_spec.rb
Expand Up @@ -242,6 +242,18 @@ def model?; true end
end
end

[ :destroy, :destroy! ].each do |method|
describe "##{method}" do
subject { model.send(method) }

let(:model) { @article_model }

it 'should remove all resources' do
method(:subject).should change { model.any? }.from(true).to(false)
end
end
end

it_should_behave_like 'Finder Interface'

it 'DataMapper::Model should respond to raise_on_save_failure' do
Expand Down

0 comments on commit 602d061

Please sign in to comment.