Skip to content

Instantly share code, notes, and snippets.

@pnomolos
Last active May 11, 2016 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pnomolos/fb7dd1c04cb7f6daefb794fe536d4594 to your computer and use it in GitHub Desktop.
Save pnomolos/fb7dd1c04cb7f6daefb794fe536d4594 to your computer and use it in GitHub Desktop.
describe Dry::Types::Rails::Railtie do
it "re-registers type subclasses" do
old_klass = SchemaStruct
class SchemaStruct
def self.bob
"bob"
end
end
expect(Dry::Types[SchemaStruct].primitive).to eq(SchemaStruct)
expect(SchemaStruct).to respond_to(:bob)
expect(Dry::Types[SchemaStruct].primitive).to respond_to(:bob)
expect(ActiveSupport::Dependencies.autoloaded?(:SchemaStruct)).to be_truthy
ActionDispatch::Reloader.prepare!
ActiveSupport::Dependencies.clear
SchemaStruct
expect(ActiveSupport::Dependencies.autoloaded?(:SchemaStruct)).to be_truthy
expect(SchemaStruct).to_not respond_to(:bob)
# The following fails
expect(Dry::Types[SchemaStruct].primitive).to_not respond_to(:bob)
end
end
# This file is autoloaded by the Rails autoloader
class SchemaStruct < Dry::Types::Struct
constructor_type :schema
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment