Skip to content
Browse files

Fix bug with registering AS:TestCase [closes #73]

Let description Strings match MiniTest::Spec even if ActiveRecord::Base is defined.
Add conditional to the register_spec_type check, like the other checks.
Added tests.
Thanks to @agirorn for the submission!
  • Loading branch information...
1 parent 5c5f016 commit b4ee8bb9467e232c5c87afd19721de85a8b9eb16 @agirorn agirorn committed with Sep 9, 2012
Showing with 28 additions and 1 deletion.
  1. +1 −1 lib/minitest/rails/active_support.rb
  2. +27 −0 test/rails/test_active_support_spec_type.rb
View
2 lib/minitest/rails/active_support.rb
@@ -27,7 +27,7 @@ def assert_block msg = nil
if defined?(ActiveRecord::Base)
# Use AS::TestCase for the base class when describing a model
register_spec_type(self) do |desc|
- desc < ActiveRecord::Base
+ desc < ActiveRecord::Base if desc.is_a?(Class)
end
end
View
27 test/rails/test_active_support_spec_type.rb
@@ -0,0 +1,27 @@
+require "minitest/autorun"
+require "rails"
+
+require "active_record"
+load "minitest/rails/active_support.rb" # Force reload
+# Not sure why we need to reload, but we do...
+
+class SomeRandomModel < ActiveRecord::Base; end
+
+class TestActiveSupportSpecType < MiniTest::Unit::TestCase
+
+ def assert_support actual
+ assert_equal MiniTest::Rails::ActiveSupport::TestCase, actual
+ end
+
+ def assert_spec actual
+ assert_equal MiniTest::Spec, actual
+ end
+
+ def test_spec_type_resolves_for_actitive_record_constants
+ assert_support MiniTest::Spec.spec_type(SomeRandomModel)
+ end
+
+ def test_spec_type_doesnt_resolve_random_strings
+ assert_spec MiniTest::Spec.spec_type("Unmatched String")
+ end
+end

0 comments on commit b4ee8bb

Please sign in to comment.
Something went wrong with that request. Please try again.