Skip to content

Instantly share code, notes, and snippets.

@royw
Created November 11, 2009 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save royw/231789 to your computer and use it in GitHub Desktop.
Save royw/231789 to your computer and use it in GitHub Desktop.
require 'spec'
require 'dm-core'
require 'dm-validations'
require 'dm-timestamps'
require 'dm-types'
require 'dm-aggregates'
DataMapper.setup(:default, 'mysql://localhost/test')
# DataMapper.setup(:default, 'sqlite3::memory:')
# DataObjects::Sqlite3.logger = DataMapper::Logger.new("test-db.log", :debug)
class Keyword
include DataMapper::Resource
# Property definitions
property :id, Serial
property :text, String, :length => 255
timestamps :at
validates_with_method :unique_text
def unique_text
result = true
Keyword.all(:text => self.text).each do |k|
result = false if k.text == self.text
end
result
end
end
DataMapper.auto_migrate!
describe 'case sensitivity' do
it 'should be case sensitive' do
Keyword.count.should == 0
Keyword.create(:text => 'polish')
Keyword.count.should == 1
Keyword.create(:text => 'Polish')
Keyword.count.should == 2
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment