ソースを参照

Merge branch 'master' of https://github.com/ryninho/blazer into ryninho-master

Andrew Kane 8 年 前
コミット
c96ff42e02

+ 1 - 1
app/controllers/blazer/checks_controller.rb

@@ -41,7 +41,7 @@ module Blazer
     private
 
     def check_params
-      params.require(:check).permit(:query_id, :emails)
+      params.require(:check).permit(:query_id, :emails, :invert)
     end
 
     def set_check

+ 3 - 2
app/models/blazer/check.rb

@@ -9,13 +9,14 @@ module Blazer
     end
 
     def update_state(rows, error)
+      invert = self.respond_to?(:invert) && self.invert
       self.state =
         if error
           "error"
         elsif rows.any?
-          "failing"
+          invert ? "passing" : "failing"
         else
-          "passing"
+          invert ? "failing" : "passing"
         end
 
       # do not notify on creation, except when not passing

+ 16 - 0
app/views/blazer/checks/_form.html.erb

@@ -1,4 +1,7 @@
 <p class="text-muted">Checks are designed to identify bad data. A check fails if there are any results.</p>
+<% if @check.respond_to?(:invert) %>
+  <p class="text-muted">An inverted check is designed to notice missing data. It fails if there are NO results. Select "Fail if NO results are returned" below to invert the check.</p>
+<% end %>
 
 <% if @check.errors.any? %>
   <div class="alert alert-danger"><%= @check.errors.full_messages.first %></div>
@@ -14,6 +17,19 @@
       $("#check_query_id").selectize().parents(".hide").removeClass("hide");
     </script>
   </div>
+
+<% if @check.respond_to?(:invert) %>
+  <div class="form-group">
+    <%= f.label "Failure criterion?" %>
+    <%= f.select :invert, [['Fail if ANY results returned (default)', false], ['Fail if NO results returned (invert)', true]], {}, {id: 'select-invert'} %>
+    <script>
+      $("#select-invert").selectize({
+        sortField: 'text'
+      });
+    </script>
+  </div>
+<% end %>
+
   <div class="form-group">
     <%= f.label :emails %>
     <%= f.text_field :emails, placeholder: "Optional, comma separated", class: "form-control" %>