GithubHelp home page GithubHelp logo

aggregate's People

Contributors

alecjacobs5401 avatar c-simmons avatar caitlinrhd avatar chrisatanasian avatar colindkelley avatar collin-mcgrath avatar declanvk avatar deltaroe avatar dtognazzini avatar gabe-kent avatar jacobdanielferguson avatar jebentier avatar lmaragon avatar mikeweaver avatar nburwell avatar omeedrj avatar primiti avatar retrogiant89 avatar rjkearns avatar ttstarck avatar yinonrousso avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aggregate's Issues

Default values for new aggregate attributes are not applied when the new attribute is being added to an existing ActiveRecord DB column

When adding a new aggregate_attribute with a default value, e.g.

aggregate_attribute :days, :integer, default: 0

The new attribute when added to an ActiveRecord object that already has serialized data in its aggregate storage column will not have its default value applied, and will instead have a value of nil.

Example

  1. Have a model with existing aggregate attributes
aggregate_attribute :description, :string
aggregate_attribute :friendly_label, :string
  1. Create a record, set those values (which will be saved in the DB).
person = Person.create!
person.set!(description: "very cool", friendly_label: "Jim")
  1. Update the code to have add a new attribute
aggregate_attribute :description, :string
aggregate_attribute :friendly_label, :string
aggregate_attribute :favorite_number, :integer, default: 0
  1. The new value on person for favorite_number will be nil instead of 0, which is confusing.
person = Person.find(ID) # Assume it's the same person record as above
person.favorite_number == nil

An important note is that the person record will not have a favorite_number key in its serialized aggregate data that's stored in the DB.

Rails 6.1+ Tests Won't Run: Fix References to ActiveRecord::DefineCallback

Currently tests won't run for Rails 6 because they of this error.

master => ~/invoca/aggregate/ bundle exec appraisal rails-6 ruby test/unit/aggregate_store_test.rb
>> BUNDLE_GEMFILE=/Users/orabani/invoca/aggregate/gemfiles/rails_6.gemfile bundle exec ruby test/unit/aggregate_store_test.rb
Traceback (most recent call last):
	5: from test/unit/aggregate_store_test.rb:3:in `<main>'
	4: from test/unit/aggregate_store_test.rb:3:in `require_relative'
	3: from /Users/orabani/invoca/aggregate/test/test_helper.rb:6:in `<top (required)>'
	2: from /Users/orabani/invoca/aggregate/test/test_helper.rb:6:in `require'
	1: from /Users/orabani/invoca/aggregate/lib/aggregate.rb:6:in `<top (required)>'
/Users/orabani/invoca/aggregate/lib/aggregate.rb:6:in `require': cannot load such file -- active_record/define_callbacks (LoadError)

This is happening because the required module was removed in Rails 6.

https://github.com/rails/rails/blob/5-2-stable/activerecord/lib/active_record/define_callbacks.rb#L4-L7

Update: For now we've blocked support for Rails >= 6.1, but we'll need to address this once we get to the point where we'll want/need to support those later versions.

Empty string given as the foreign key ID for an aggregate_belongs_to attribute ends up storing the ID as 0

Description

id_or_value.to_i within Aggregate::ForeignKeyReference#initialize can cause an empty string given as an id to be stored as 0. This 0 will then be stored as the aggregate_belongs_to attribute's ID in serialized storage data. This means that trying to fetch the associated DB record will (most likely always) raise an exception because the record won't be found, which ends up becoming confusing to debug because it's not necessarily clear to the consumer of the gem why 0 is being stored as the ID.

@id = id_or_value.to_i

Example

aggregate_belongs_to :user, "User"
my_object.user_id = ""
my_object.save!

my_object.user_id == 0

Suggested Fix

  • When id_or_value is not an ActiveRecord::Base object, we should raise an ArgumentError if id_or_value is nil or an empty string

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.