<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -208,15 +208,20 @@ module Authorization
             end
             bindvar = &quot;#{attribute_table_alias}__#{attribute_name}_#{obligation_index}&quot;.to_sym
 
-            attribute_operator = case operator
-                                 when :contains, :is             then &quot;= :#{bindvar}&quot;
-                                 when :does_not_contain, :is_not then &quot;&lt;&gt; :#{bindvar}&quot;
-                                 when :is_in, :intersects_with   then &quot;IN (:#{bindvar})&quot;
-                                 when :is_not_in                 then &quot;NOT IN (:#{bindvar})&quot;
-                                 else raise AuthorizationUsageError, &quot;Unknown operator: #{operator}&quot;
-                                 end
-            obligation_conds &lt;&lt; &quot;#{connection.quote_table_name(attribute_table_alias)}.#{connection.quote_table_name(attribute_name)} #{attribute_operator}&quot;
-            binds[bindvar] = attribute_value(value)
+            sql_attribute = &quot;#{connection.quote_table_name(attribute_table_alias)}.#{connection.quote_table_name(attribute_name)}&quot;
+            if value.nil? and [:is, :is_not].include?(operator)
+              obligation_conds &lt;&lt; &quot;#{sql_attribute} IS #{[:contains, :is].include?(operator) ? '' : 'NOT '}NULL&quot;
+            else
+              attribute_operator = case operator
+                                   when :contains, :is             then &quot;= :#{bindvar}&quot;
+                                   when :does_not_contain, :is_not then &quot;&lt;&gt; :#{bindvar}&quot;
+                                   when :is_in, :intersects_with   then &quot;IN (:#{bindvar})&quot;
+                                   when :is_not_in                 then &quot;NOT IN (:#{bindvar})&quot;
+                                   else raise AuthorizationUsageError, &quot;Unknown operator: #{operator}&quot;
+                                   end
+              obligation_conds &lt;&lt; &quot;#{sql_attribute} #{attribute_operator}&quot;
+              binds[bindvar] = attribute_value(value)
+            end
           end
         end
         obligation_conds &lt;&lt; &quot;1=1&quot; if obligation_conds.empty?</diff>
      <filename>lib/declarative_authorization/obligation_scope.rb</filename>
    </modified>
    <modified>
      <diff>@@ -168,6 +168,34 @@ class ModelTest &lt; Test::Unit::TestCase
     TestModel.delete_all
   end
 
+  def test_named_scope_with_is_nil
+    reader = Authorization::Reader::DSLReader.new
+    reader.parse %{
+      authorization do
+        role :test_role do
+          has_permission_on :test_models, :to =&gt; :read do
+            if_attribute :content =&gt; nil
+          end
+        end
+        role :test_role_not_nil do
+          has_permission_on :test_models, :to =&gt; :read do
+            if_attribute :content =&gt; is_not { nil }
+          end
+        end
+      end
+    }
+    Authorization::Engine.instance(reader)
+
+    test_model_1 = TestModel.create!
+    test_model_2 = TestModel.create! :content =&gt; &quot;Content&quot;
+
+    assert_equal test_model_1, TestModel.with_permissions_to(:read,
+      :context =&gt; :test_models, :user =&gt; MockUser.new(:test_role)).first
+    assert_equal test_model_2, TestModel.with_permissions_to(:read,
+      :context =&gt; :test_models, :user =&gt; MockUser.new(:test_role_not_nil)).first
+    TestModel.delete_all
+  end
+
   def test_named_scope_with_not_is
     reader = Authorization::Reader::DSLReader.new
     reader.parse %{</diff>
      <filename>test/model_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>0cbd80513c5c93b2c95b91ef78992f83c551d9c8</id>
    </parent>
  </parents>
  <author>
    <name>Steffen Bartsch</name>
    <email>sbartsch@tzi.org</email>
  </author>
  <url>http://github.com/stffn/declarative_authorization/commit/1154a6ee6c29c9e705340bf835e2ab8bce6a9de6</url>
  <id>1154a6ee6c29c9e705340bf835e2ab8bce6a9de6</id>
  <committed-date>2009-06-24T08:10:07-07:00</committed-date>
  <authored-date>2009-06-24T08:10:07-07:00</authored-date>
  <message>Fix SQL condition for nil values (#15)</message>
  <tree>4476686d31db96ccbd041a2e6fedd9756dc38a22</tree>
  <committer>
    <name>Steffen Bartsch</name>
    <email>sbartsch@tzi.org</email>
  </committer>
</commit>
