rgeo / rgeo-activerecord

RGeo ActiveRecord extensions and tools for spatial connection adapters
Other
89 stars 64 forks source link

`SpatialFactoryStore#default` API can be hard to grasps #80

Open BuonOmo opened 1 month ago

BuonOmo commented 1 month ago

Issue create from this discussion: https://github.com/rgeo/activerecord-postgis-adapter/pull/412#discussion_r1800782440

The accessor for #default also behaves as a setter:

      def default(attrs = {})
        @default || default_for_attrs(attrs)
      end

This was messing up with the test suite in activerecord-postgis-adapter. Shall we find an API that is less error-prone?

For instance, a user doing:

old_default = spatial_factory_store.default
spatial_factory_store.default = my_mock
# some tests
spatial_factory_store.default = old_default

would actually get a different instance of spatial_factory_store at the beginning and the end (the first one doesn't necessarily have default set, the second one does).

Another issue is this one:

# in initializer
spatial_factory_store.default = some_default

# later in the codebase
factory = spatial_factory_store.default(specific_attributes)
# the `specific_attributes` will not be taken into account