Created
February 27, 2013 14:47
-
-
Save tricknotes/5048408 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'activerecord', '4.0.0.beta1', require: 'active_record' | |
gem 'enumerize', github: 'brainspec/enumerize' | |
gem 'sqlite3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
USAGE
$ bundle exec ruby example.rb
This is my result.