Commit 35227bf

mo <mo@mokhan.ca>
2019-05-29 01:36:17
handle starts with and ends with operator
1 parent 6618d14
Changed files (2)
app
models
spec
app/models/scim/visitor.rb
@@ -10,7 +10,11 @@ module Scim
       when 'ne'
         User.where.not(attr => tree[:value].to_s[1..-2])
       when 'co'
+        User.where("#{attr} like ?", "%#{tree[:value].to_s[1..-2]}%")
+      when 'sw'
         User.where("#{attr} like ?", "#{tree[:value].to_s[1..-2]}%")
+      when 'ew'
+        User.where("#{attr} like ?", "%#{tree[:value].to_s[1..-2]}")
       else
         User.none
       end
spec/models/user_spec.rb
@@ -31,7 +31,17 @@ RSpec.describe User do
     end
 
     specify do
-      results = User.scim_filter_for(tree_for("userName co \"#{random_user.email[0..3]}\""))
+      results = User.scim_filter_for(tree_for("userName co \"#{random_user.email[1..3]}\""))
+      expect(results).to match_array([random_user])
+    end
+
+    specify do
+      results = User.scim_filter_for(tree_for("userName sw \"#{random_user.email[0..3]}\""))
+      expect(results).to match_array([random_user])
+    end
+
+    specify do
+      results = User.scim_filter_for(tree_for("userName ew \"#{random_user.email[-3..-1]}\""))
       expect(results).to match_array([random_user])
     end