瀏覽代碼

Fixed error with Rails 4.1 and below - closes #60

Andrew Kane 9 年之前
父節點
當前提交
dbb9052526
共有 5 個文件被更改,包括 13 次插入6 次删除
  1. 4 0
      CHANGELOG.md
  2. 2 2
      app/models/blazer/audit.rb
  3. 1 1
      app/models/blazer/query.rb
  4. 2 0
      lib/blazer.rb
  5. 4 3
      lib/blazer/engine.rb

+ 4 - 0
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

+ 2 - 2
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

+ 1 - 1
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

+ 2 - 0
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]

+ 4 - 3
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