Permalink
Browse files

Switched to MiniTest

  • Loading branch information...
1 parent ae46298 commit 5ebe204edc6dfe33617f481293696b398b4d2182 @sled committed Aug 19, 2011
View
@@ -1,3 +1,12 @@
source "http://rubygems.org"
gemspec
+
+platform :jruby do
+ gem 'jdbc-sqlite3'
+end
+
+platform :ruby do
+ gem 'sqlite3'
+ gem 'bson_ext'
+end
View
@@ -7,34 +7,39 @@ PATH
GEM
remote: http://rubygems.org/
specs:
- activemodel (3.0.5)
- activesupport (= 3.0.5)
+ activemodel (3.0.10)
+ activesupport (= 3.0.10)
builder (~> 2.1.2)
- i18n (~> 0.4)
- activerecord (3.0.5)
- activemodel (= 3.0.5)
- activesupport (= 3.0.5)
- arel (~> 2.0.2)
+ i18n (~> 0.5.0)
+ activerecord (3.0.10)
+ activemodel (= 3.0.10)
+ activesupport (= 3.0.10)
+ arel (~> 2.0.10)
tzinfo (~> 0.3.23)
- activesupport (3.0.5)
- arel (2.0.9)
+ activesupport (3.0.10)
+ arel (2.0.10)
bson (1.3.1)
+ bson_ext (1.3.1)
builder (2.1.2)
i18n (0.5.0)
+ minitest (2.4.0)
mongo (1.3.1)
bson (>= 1.3.1)
- mongoid (2.0.2)
+ mongoid (2.1.8)
activemodel (~> 3.0)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
- sqlite3 (1.3.3)
- tzinfo (0.3.24)
+ sqlite3 (1.3.4)
+ tzinfo (0.3.29)
PLATFORMS
ruby
DEPENDENCIES
activerecord (~> 3.0)
+ bson_ext
+ jdbc-sqlite3
+ minitest (>= 2.3.0)
mongoid (~> 2.0)
simple_enum!
sqlite3
View
@@ -1,12 +1,20 @@
require 'rake'
require 'rake/testtask'
-require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
-desc 'Test the simple_enum plugin.'
-Rake::TestTask.new(:test) do |t|
+desc 'Run both unit tests for AR und MongoID'
+task :test do
+ # thanks to https://github.com/plataformatec/devise/blob/master/Rakefile#L11
+ Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file|
+ orm = File.basename(file).split(".").first
+ exit 1 unless system "rake test ORM=#{orm}"
+ end
+end
+
+desc 'Run unit tests, use ORM=...'
+Rake::TestTask.new(:'test:unit') do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
View
@@ -177,6 +177,7 @@ def as_enum(enum_cd, values, options = {})
# allow access to defined values hash, e.g. in a select helper or finder method.
attr_name = enum_cd.to_s.pluralize
enum_attr = :"#{attr_name.downcase}_enum_hash"
+
write_inheritable_attribute(enum_attr, values)
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
@@ -256,7 +257,7 @@ def as_enum(enum_cd, values, options = {})
options = SimpleEnum.default_options.merge({ :column => "#{enum_cd}_cd" }).merge(options)
options.assert_valid_keys(:column, :whiny, :prefix, :slim, :upcase)
- field options[:column]
+ field options[:column]
super
end
end
View
@@ -24,12 +24,7 @@ Gem::Specification.new do |s|
s.add_dependency "activesupport", "~> 3.0"
+ s.add_development_dependency 'minitest', '>= 2.3.0'
s.add_development_dependency 'activerecord', '~> 3.0'
s.add_development_dependency 'mongoid', '~> 2.0'
-
- unless RUBY_PLATFORM =~ /java/
- s.add_development_dependency 'sqlite3'
- else
- s.add_development_dependency 'jdbc-sqlite3'
- end
end
@@ -1,22 +1,21 @@
require 'test_helper'
-class ArrayConversionsTest < ActiveSupport::TestCase
+class ArrayConversionsTest < MiniTest::Unit::TestCase
def setup
reload_db :genders => true
end
- test "that conversion of Gender.find(:all).map {...} to enumeration values as symbols works the same as [:male,:female]" do
-
+ def test_conversion_to_enumartions
with_enum = named_dummy('DummyArrayTest1') do
- as_enum :gender, Gender.find(:all).map { |g| [g.name.to_sym, g.id] }
+ as_enum :gender, Gender.all.map { |g| [g.name.to_sym, g.id] }
end
- assert_equal 0, with_enum.male
- assert_equal 1, with_enum.female
- assert_equal 1, with_enum.genders(:female)
+ assert_equal @male.id, with_enum.male
+ assert_equal @female.id, with_enum.female
+ assert_equal @female.id, with_enum.genders(:female)
jane = with_enum.new :gender => :female
assert_equal :female, jane.gender
- assert_equal 1, jane.gender_cd
+ assert_equal @female.id, jane.gender_cd
end
end
@@ -1,33 +1,34 @@
require 'test_helper'
-class ClassMethodsTest < ActiveSupport::TestCase
+class ClassMethodsTest < MiniTest::Unit::TestCase
def setup
reload_db
end
- test "that Klass.genders[:sym] == Klass.genders(:sym)" do
+ def test_that_klass_genders_array_accessor_equal_to_attr_accessor
assert_equal 0, Dummy.genders(:male)
assert_equal Dummy.genders(:male), Dummy.genders[:male]
assert_nil Dummy.genders(:inexistent)
assert_nil Dummy.genders[:inexistent]
- assert_not_nil Dummy.genders[:female]
+ refute_nil Dummy.genders[:female]
end
- test "inheritance of `genders` to subclasses (#issue/3)" do
+ def test_inheritance_of_genders_to_subclass
assert_equal({ :female => 1, :male => 0}, SpecificDummy.genders)
end
- test "genders reader created" do
+ def test_genders_reader_created
assert_equal [0, 1], Dummy.genders.values.sort
assert_equal %w{female male}, Dummy.genders.keys.map(&:to_s).sort
end
- test "that Klass.genders(:sym_a, :sym_b) returns an array of values, useful for IN clauses" do
+ def test_that_klass_genders_return_array_of_values
+ # usefuled for IN clauses
assert_equal [0, 1], Dummy.genders(:male, :female)
assert_equal [1, 0], Dummy.genders(:female, :male)
end
- test "generation of value shortcuts on class" do
+ def test_generation_of_value_shortcuts_on_class
g = Dummy.new
assert_equal 0, Dummy.male
@@ -39,7 +40,7 @@ def setup
assert_respond_to Dummy, :foobar
end
- test "that no Klass.shortcut are created if :slim => true" do
+ def test_that_no_klass_shortcut_are_created_if_slim_is_true
with_slim = named_dummy('Dummy1') do
as_enum :gender, [:male, :female], :slim => true
end
@@ -49,7 +50,7 @@ def setup
assert_respond_to with_slim, :genders
end
- test "that no Klass.shortcut's are created if :slim => :class, though instance shortcuts are" do
+ def test_that_no_klass_shortcuts_are_created_if_slim_set_to_class
with_slim_class = named_dummy('Dummy2') do
as_enum :gender, [:male, :female], :slim => :class
end
@@ -65,7 +66,7 @@ def setup
assert_same 1, with_slim_class.genders[:female]
end
- test "that Klass.shortcut respect :prefix => true and are prefixed by \#{enum_cd}" do
+ def test_that_klass_shortcut_respect_prefix_and_are_prefixed_correctly
with_prefix = named_dummy('Dummy3') do
as_enum :gender, [:male, :female], :prefix => true
end
@@ -78,7 +79,7 @@ def setup
assert_respond_to with_prefix, :genders
end
- test "to ensure that Klass.shortcut also work with custom prefixes" do
+ def test_to_ensure_that_klass_shortcut_also_works_with_custom_prefixes
with_custom_prefix = named_dummy('Dummy4') do
as_enum :gender, [:male, :female], :prefix => :g
end
@@ -92,22 +93,22 @@ def setup
assert_respond_to with_custom_prefix, :genders
end
- test "that the human_enum_name method returns translated/humanized values" do
+ def test_that_the_human_enum_name_method_retursn_humanized_values
assert_equal :male.to_s.humanize, Dummy.human_enum_name(:genders, :male)
assert_equal "Girl", Dummy.human_enum_name(:genders, :female)
assert_equal "Foo", Dummy.human_enum_name(:didums, :foo)
assert_equal "Foos", Dummy.human_enum_name(:didums, :foo, :count => 5)
end
- test "enum_for_select class method" do
+ def test_enum_for_select_class_method
for_select = Dummy.genders_for_select
genders = Dummy.genders
assert_equal genders.first.first, for_select.first.second
assert_equal ["Male", :male], for_select.first
assert_equal ["Girl", :female], for_select.last
end
- test "enum_for_select(:value) class method" do
+ def test_enum_for_select_class_method_with_value
for_select = Dummy.genders_for_select(:value)
assert_equal ["Male", 0], for_select.first
assert_equal ["Girl", 1], for_select.last
@@ -1,9 +1,9 @@
require 'test_helper'
require 'simple_enum/enum_hash'
-class EnumHashTest < ActiveSupport::TestCase
+class EnumHashTest < MiniTest::Unit::TestCase
- test "create new EnumHash instance from array of symbols" do
+ def test_create_new_enumhash_instance_from_array_of_symbols
genders = SimpleEnum::EnumHash.new [:male, :female]
assert_same 0, genders[:male]
@@ -12,32 +12,30 @@ class EnumHashTest < ActiveSupport::TestCase
assert_same :female, genders.female(true)
end
- test "create new EnumHash instance from Hash" do
+ def test_create_new_enumhash_instance_from_hash
status = SimpleEnum::EnumHash.new :inactive => 0, :active => 1, :archived => 99
assert_same 0, status.inactive
assert_same 1, status[:active]
end
- test "create new EnumHash instance from ActiveRecord results" do
+ def test_create_new_enumhash_instance_from_query_results
reload_db :genders => true
- genders = SimpleEnum::EnumHash.new Gender.find(:all)
-
- male = Gender.find(0)
-
- assert_same 0, genders[male]
- assert_same genders[male], genders[:male]
+ genders = SimpleEnum::EnumHash.new Gender.all
+
+ assert_same 0, genders[@male]
+ assert_same genders[@male], genders[:male]
assert_same 1, genders.female
- assert_equal male, genders.send(:male, true)
+ assert_equal @male, genders.send(:male, true)
end
- test "that EnumHash keys are ordered" do
+ def test_that_enumhash_keys_are_ordered
ordered = SimpleEnum::EnumHash.new [:alpha, :beta, :gamma, :delta, :epsilon, :zeta, :eta]
expected_keys = [:alpha, :beta, :gamma, :delta, :epsilon, :zeta, :eta]
assert_equal expected_keys, ordered.keys
end
- test "that when simple array is merge into a EnumHash, array values are the keys and indicies are values" do
+ def test_valid_key_value_association_when_simple_array_is_merged_into_enumhash
a = [:a, :b, :c, :d]
h = SimpleEnum::EnumHash.new(a)
@@ -48,7 +46,7 @@ class EnumHashTest < ActiveSupport::TestCase
assert_equal [:a, :b, :c, :d], h.keys
end
- test "that an already 'correct' looking array is converted to a hash" do
+ def test_that_an_already_correct_looking_array_is_converted_to_hash
a = [[:a, 5], [:b, 10]]
h = SimpleEnum::EnumHash.new(a)
@@ -57,16 +55,13 @@ class EnumHashTest < ActiveSupport::TestCase
assert_equal [:a, :b], h.keys
end
- test "that an array of ActiveRecords are converted to <obj> => obj.id" do
+ def test_that_an_array_of_query_results_are_converted_to_result_ids
reload_db :genders => true # reload db
- a = Gender.find(:all, :order => :id)
-
- male = Gender.find(0)
- female = Gender.find(1)
+ a = Gender.all
h = SimpleEnum::EnumHash.new(a)
- assert_same 0, h[male]
- assert_same 1, h[female]
+ assert_same 0, h[@male]
+ assert_same 1, h[@female]
end
end
View
@@ -1,12 +1,12 @@
require 'test_helper'
-class FindersTest < ActiveSupport::TestCase
+class FindersTest < MiniTest::Unit::TestCase
def setup
reload_db
end
- test "find all where :gender = :female" do
- girls = Dummy.find :all, :conditions => { :gender_cd => Dummy.genders[:female] }, :order => 'name ASC'
+ def test_find_all_female_genders
+ girls = Dummy.where(:gender_cd => Dummy.genders[:female]).sort { |a,b| a.name <=> b.name }
assert_equal 2, girls.length
@@ -15,8 +15,8 @@ def setup
assert_equal true, girls.first.female?
end
- test "find all where :word is 'gamma'" do
- gammas = Dummy.find :all, :conditions => { :word_cd => Dummy.words(:gamma) }
+ def test_find_all_gamma_words
+ gammas = Dummy.where(:word_cd => Dummy.words(:gamma)).all
assert_equal 1, gammas.length
assert_equal 'Chris', gammas.first.name
@@ -25,15 +25,19 @@ def setup
assert_equal :gamma, gammas.first.word
end
- test "find with string conditions for all :didum = :foo" do
- foos = Dummy.find :all, :conditions => ['other = ?', Dummy.didums(:foo)]
+ def test_find_all_with_attribute_didum_equal_to_foo
+ skip('Not available in Mongoid') if mongoid?
+
+ foos = Dummy.where('other = ?', Dummy.didums(:foo)).all
assert_equal 1, foos.length
assert_equal false, foos.first.foobar?
end
- test "find using insecure inline string conditions" do
- men = Dummy.find :all, :conditions => "gender_cd = #{Dummy.genders(:male)}"
+ def test_find_using_insecure_inline_string_conditions
+ skip('Not available in Mongoid') if mongoid?
+
+ men = Dummy.where("gender_cd = #{Dummy.genders(:male)}").all
assert_equal 1, men.length
assert_equal true, men.first.male?
Oops, something went wrong.

0 comments on commit 5ebe204

Please sign in to comment.