Skip to content

Business intelligence made simple

Fixed error with Rails 4.1 and below - closes #60

Andrew Kanedbb905252695
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9f002524..e47d9df1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.3.3 [unreleased]
+
+- Fixed error with Rails 4.1 and below
+
## 1.3.2
- Added support for Rails 5
diff --git a/app/models/blazer/audit.rb b/app/models/blazer/audit.rb
index fbff8c1c..7d6495e5 100644
--- a/app/models/blazer/audit.rb
+++ b/app/models/blazer/audit.rb
@@ -1,6 +1,6 @@
module Blazer
class Audit < ActiveRecord::Base
- belongs_to :user, class_name: Blazer.user_class.to_s, required: false
- belongs_to :query, required: false
+ belongs_to :user, Blazer::BELONGS_TO_OPTIONAL.merge(class_name: Blazer.user_class.to_s)
+ belongs_to :query, Blazer::BELONGS_TO_OPTIONAL
end
end
diff --git a/app/models/blazer/query.rb b/app/models/blazer/query.rb
index 8d3109ab..36ce15b8 100644
--- a/app/models/blazer/query.rb
+++ b/app/models/blazer/query.rb
@@ -1,6 +1,6 @@
module Blazer
class Query < ActiveRecord::Base
- belongs_to :creator, class_name: Blazer.user_class.to_s, required: false if Blazer.user_class
+ belongs_to :creator, Blazer::BELONGS_TO_OPTIONAL.merge(class_name: Blazer.user_class.to_s) if Blazer.user_class
has_many :checks, dependent: :destroy
has_many :dashboard_queries, dependent: :destroy
has_many :dashboards, through: :dashboard_queries
diff --git a/lib/blazer.rb b/lib/blazer.rb
index 386bd912..75fe4fa9 100644
--- a/lib/blazer.rb
+++ b/lib/blazer.rb
@@ -30,6 +30,8 @@ module Blazer
"cancelled on user's request", # redshift
"system requested abort" # redshift
]
+ BELONGS_TO_OPTIONAL = {}
+ BELONGS_TO_OPTIONAL[:optional] = true if Rails::VERSION::MAJOR >= 5
def self.time_zone=(time_zone)
@time_zone = time_zone.is_a?(ActiveSupport::TimeZone) ? time_zone : ActiveSupport::TimeZone[time_zone.to_s]
diff --git a/lib/blazer/engine.rb b/lib/blazer/engine.rb
index bb307ce3..fcad58bf 100644
--- a/lib/blazer/engine.rb
+++ b/lib/blazer/engine.rb
@@ -22,9 +22,10 @@ module Blazer
Blazer.check_schedules = Blazer.settings["check_schedules"] if Blazer.settings.key?("check_schedules")
if Blazer.user_class
- Blazer::Query.belongs_to :creator, class_name: Blazer.user_class.to_s
- Blazer::Dashboard.belongs_to :creator, class_name: Blazer.user_class.to_s
- Blazer::Check.belongs_to :creator, class_name: Blazer.user_class.to_s
+ options = Blazer::BELONGS_TO_OPTIONAL.merge(class_name: Blazer.user_class.to_s)
+ Blazer::Query.belongs_to :creator, options
+ Blazer::Dashboard.belongs_to :creator, options
+ Blazer::Check.belongs_to :creator, options
end
Blazer.cache ||= Rails.cache