mirror of https://github.com/rails/rails
Merge pull request #44718 from ghousemohamed/extend-test-cases-for-object-in-activesupport
Add missing test cases for Object in activesupport
This commit is contained in:
commit
da22687eef
|
@ -2,6 +2,7 @@
|
|||
|
||||
require_relative "../../abstract_unit"
|
||||
require "active_support/core_ext/date/acts_like"
|
||||
require "active_support/core_ext/string/behavior"
|
||||
require "active_support/core_ext/time/acts_like"
|
||||
require "active_support/core_ext/date_time/acts_like"
|
||||
require "active_support/core_ext/object/acts_like"
|
||||
|
@ -13,6 +14,15 @@ class ObjectTests < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class Stringish < String
|
||||
end
|
||||
|
||||
class DuckString
|
||||
def acts_like_string?
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def test_duck_typing
|
||||
object = Object.new
|
||||
time = Time.now
|
||||
|
@ -35,4 +45,15 @@ class ObjectTests < ActiveSupport::TestCase
|
|||
assert duck.acts_like?(:time)
|
||||
assert_not duck.acts_like?(:date)
|
||||
end
|
||||
|
||||
def test_acts_like_string
|
||||
string = Stringish.new
|
||||
duck_string = DuckString.new
|
||||
|
||||
assert string.acts_like?(:string)
|
||||
assert_not string.acts_like?(:invalid)
|
||||
|
||||
assert duck_string.acts_like?(:string)
|
||||
assert_not string.acts_like?(:invalid)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue