Skip to content

Instantly share code, notes, and snippets.

@tricknotes
Created February 27, 2013 14:47
Show Gist options
  • Save tricknotes/5048408 to your computer and use it in GitHub Desktop.
Save tricknotes/5048408 to your computer and use it in GitHub Desktop.
require 'bundler/setup'
Bundler.require
DATABASE = './test.sqlite3'
# Setup
File.unlink(DATABASE) if File.exist?(DATABASE)
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: DATABASE
)
class InitializeDatabase < ActiveRecord::Migration
def change
create_table :coffees do |t|
t.string :size
end
end
end
InitializeDatabase.migrate(:up)
# Definition
class Coffee < ActiveRecord::Base
extend Enumerize
enumerize :size, in: %w(short middle large)
end
# Assertion
require 'test/unit'
class EnumerizeTest < Test::Unit::TestCase
def setup
Coffee.destroy_all
end
def test_create
Coffee.create(size: 'short')
assert_equal 1, Coffee.count
assert_equal 'short', Coffee.first.size # This assertion is failed!
end
end
source 'https://rubygems.org'
gem 'activerecord', '4.0.0.beta1', require: 'active_record'
gem 'enumerize', github: 'brainspec/enumerize'
gem 'sqlite3'
GIT
remote: git://github.com/brainspec/enumerize.git
revision: d07fda637ae07dcb17b37e0128767aa2eebbf9b3
specs:
enumerize (0.5.1)
activesupport (>= 3.2)
GEM
remote: https://rubygems.org/
specs:
activemodel (4.0.0.beta1)
activesupport (= 4.0.0.beta1)
builder (~> 3.1.0)
activerecord (4.0.0.beta1)
activemodel (= 4.0.0.beta1)
activerecord-deprecated_finders (~> 0.0.3)
activesupport (= 4.0.0.beta1)
arel (~> 4.0.0.beta1)
activerecord-deprecated_finders (0.0.3)
activesupport (4.0.0.beta1)
i18n (~> 0.6.2)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.33)
arel (4.0.0.beta1)
atomic (1.0.1)
builder (3.1.4)
i18n (0.6.2)
minitest (4.6.1)
multi_json (1.6.1)
sqlite3 (1.3.7)
thread_safe (0.1.0)
atomic
tzinfo (0.3.35)
PLATFORMS
ruby
DEPENDENCIES
activerecord (= 4.0.0.beta1)
enumerize!
sqlite3
@tricknotes
Copy link
Author

USAGE

$ bundle exec ruby example.rb

This is my result.

Run options: 

# Running tests:

[1/1] EnumerizeTest#test_create = 0.01 s
  1) Failure:
test_create(EnumerizeTest) [example.rb:46]:
<"short"> expected but was
<nil>.

Finished tests in 0.032182s, 31.0733 tests/s, 62.1465 assertions/s.
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips

ruby -v: ruby 2.0.0p0 (2013-02-24 revision 39473) [x86_64-darwin11.4.2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment