Skip to content

Instantly share code, notes, and snippets.

@lawrencepit
Created October 29, 2008 04:17
Show Gist options
  • Save lawrencepit/20621 to your computer and use it in GitHub Desktop.
Save lawrencepit/20621 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
$: << '~/project/merb/dm/specs/dm-core/lib'
require 'dm-core'
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')
class Article
include DataMapper::Resource
property :id, Serial
property :title, String
end
DataMapper.auto_migrate!
# setup
@article_repository = repository(:default)
@model = Article
@articles_query = DataMapper::Query.new(@article_repository, @model, :title => 'Sample Article')
@article = @model.create(:title => 'Sample Article')
@other = @model.create(:title => 'Other Article')
@articles = @model.all(@articles_query)
# test
puts "#{@articles.size} articles"
@return = @articles.slice!(2, 2)
puts "@return = nil" if @return.nil?
@articles.dup.destroy!
Wed, 29 Oct 2008 04:25:11 GMT ~ debug ~ DROP TABLE IF EXISTS "articles"
Wed, 29 Oct 2008 04:25:11 GMT ~ debug ~ PRAGMA table_info('articles')
Wed, 29 Oct 2008 04:25:11 GMT ~ debug ~ SELECT sqlite_version(*)
Wed, 29 Oct 2008 04:25:11 GMT ~ debug ~ CREATE TABLE "articles" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "title" VARCHAR(50))
Wed, 29 Oct 2008 04:25:11 GMT ~ debug ~ INSERT INTO "articles" ("title") VALUES ('Sample Article')
Wed, 29 Oct 2008 04:25:11 GMT ~ debug ~ INSERT INTO "articles" ("title") VALUES ('Other Article')
Wed, 29 Oct 2008 04:25:11 GMT ~ debug ~ SELECT "id", "title" FROM "articles" WHERE ("title" = 'Sample Article') ORDER BY "id"
1 articles
@return = nil
Wed, 29 Oct 2008 04:25:11 GMT ~ debug ~ DELETE FROM "articles" WHERE ("title" = 'Sample Article') AND ("id" IN (1))
/Users/copa/project/merb/dm/specs/dm-core/lib/dm-core/collection.rb:579:in `destroy!': undefined method `key' for nil:NilClass (NoMethodError)
from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.8/lib/extlib/lazy_array.rb:15:in `each'
from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.8/lib/extlib/lazy_array.rb:15:in `each'
from /Users/copa/project/merb/dm/specs/dm-core/lib/dm-core/collection.rb:576:in `destroy!'
from dm2.rb:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment