Skip to content

Commit

Permalink
Reproduce the rails 5.1 compatiability issue
Browse files Browse the repository at this point in the history
Rails 5.1 and above add automatic validation for belongs_to association.
It is enabled by an initializer added to new projects. Adding that
configuartion in dummy app will reproduce the issue in test case
  • Loading branch information
tachyons committed Apr 23, 2018
1 parent 4436e38 commit 27c4a5c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/merit/models/active_record/merit/activity_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ActivityLog < ActiveRecord::Base
self.table_name = :merit_activity_logs

belongs_to :action, class_name: 'Merit::Action'
belongs_to :related_change, polymorphic: true
belongs_to :related_change, polymorphic: true, optional: true

This comment has been minimized.

Copy link
@rectifyer

rectifyer Jul 25, 2018

FYI, this seems to break Rails 4 since optional isn't a valid key there. Once I downloaded to Merit 3.0.1 it worked again.

This comment has been minimized.

Copy link
@tute

tute Jul 25, 2018

Member

Thank you for the note. We aren't testing against Rails 4.x as it's unsupported, so it makes sense to use previous merit versions to run alongside Rails 4 apps. Thanks!

has_one :sash, through: :related_change

if show_attr_accessible?
Expand Down
3 changes: 3 additions & 0 deletions test/dummy/config/initializers/new_framework_defaults.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if Rails.version >= "5.1"
Rails.application.config.active_record.belongs_to_required_by_default = true
end

0 comments on commit 27c4a5c

Please sign in to comment.