Skip to content

Instantly share code, notes, and snippets.

@danhigham
Created July 20, 2011 05:55
Show Gist options
  • Save danhigham/1094421 to your computer and use it in GitHub Desktop.
Save danhigham/1094421 to your computer and use it in GitHub Desktop.
RSpec test cases for enums with dm-redis-adapter
#!/usr/bin/ruby
require 'rubygems'
require 'datamapper'
require 'rspec'
class Book
include DataMapper::Resource
property :id, Serial
property :book_type, Enum[ :fiction, :non_fiction ], :default => :fiction
property :title, String
end
DataMapper.setup(:default, {:adapter => "redis"})
# DataMapper.setup(:default, 'sqlite::memory:')
DataMapper.auto_migrate!
# Tests
describe "Datamapper Redis Adapter" do
it "should save and load the same record with a default book_type" do
title = "Hitchhikers Guide to the Galaxy"
Book.create :title => title
book = Book.first(:title => title)
book.book_type.should == :fiction
end
it "should save and load the same record with a non default book_type" do
title = "Isaac Asimovs New Guide to Science"
Book.create :title => title, :book_type => :non_fiction
book = Book.first(:title => title, :book_type => :non_fiction)
book.book_type.should == :non_fiction
end
it "book_type should be initialised by default before saving for default" do
title = "Hitchhikers Guide to the Galaxy"
b = Book.new :title => title
b.book_type.should == :fiction
end
it "book_type should be initialised by default before saving for non default" do
title = "Isaac Asimovs New Guide to Science"
b = Book.new :title => title, :book_type => :non_fiction
b.book_type.should == :non_fiction
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment