ruby-hyperloop / hyper-mesh

The project has moved to Hyperstack!! - Synchronization of active record models across multiple clients using Pusher, ActionCable, or Polling
https://hyperstack.org/
MIT License
22 stars 12 forks source link

Need spec for using the Model.find_by(attribute => value) scope in pre-rendering. #69

Open adamcreekroad opened 6 years ago

adamcreekroad commented 6 years ago

A bug was discovered in staging and production environments only, pre-rendering was breaking with the error RuntimeError (HyperModel fetching records failed, exception caught when applying ["find_by_nickname", "adamcreekroad"] to db object User: method missing):

It is really weird that this was working fine in development...

The fix was pushed in the latest edge branch, but it needs a spec written.

f.when_on_server { @server_data_cache[klass, ["find_by_#{attribute}", value], :id] }

Was changed to:

f.when_on_server { @server_data_cache[klass, ["find_by", { attribute => value }], 'id'] }

There were amazingly two things broken here only in staging and production:

  1. find_by_attribute(value)'s secure method was undefined and throwing that original error.
  2. @value.attributes.has_key?(method) was returning false when method was :id, which that when_on_server call up there passes through. attributes is a hash of String => String, so checking for a symbol was not working.