From fde9d042fb7b8d6ef69909e0f388aa92dea8a748 Mon Sep 17 00:00:00 2001 From: josephMG Date: Tue, 20 Feb 2018 23:16:10 +0800 Subject: [PATCH] Add belongs_to optional true to setup_association --- lib/impressionist/setup_association.rb | 6 +++++- tests/spec/minitest_helper.rb | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/impressionist/setup_association.rb b/lib/impressionist/setup_association.rb index 1bc5227..b5c3c16 100644 --- a/lib/impressionist/setup_association.rb +++ b/lib/impressionist/setup_association.rb @@ -12,7 +12,11 @@ module Impressionist end def define_belongs_to - receiver.belongs_to(:impressionable, :polymorphic => true) + if ::Rails::VERSION::MAJOR.to_i >= 5 + receiver.belongs_to(:impressionable, :polymorphic => true, :optional => true) + else + receiver.belongs_to(:impressionable, :polymorphic => true) + end end def set diff --git a/tests/spec/minitest_helper.rb b/tests/spec/minitest_helper.rb index eeb22af..e4f904f 100644 --- a/tests/spec/minitest_helper.rb +++ b/tests/spec/minitest_helper.rb @@ -1,4 +1,7 @@ $:.unshift(File.dirname __FILE__) +require 'rails/all' +require 'rails/test_help' require "minitest/autorun" require "minitest/pride" +require 'minitest/rails'