Controller method to allow enterprise users to search for other users which share management of their enterprises

This commit is contained in:
Rob Harrington
2015-01-30 12:49:00 +11:00
parent b73619d168
commit dcb24cf06c
2 changed files with 54 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
Spree::Admin::SearchController.class_eval do
def known_users
binding.pry
if exact_match = Spree.user_class.find_by_email(params[:q])
@users = [exact_match]
else
@users = spree_current_user.known_users.ransack({
:m => 'or',
:email_start => params[:q],
:ship_address_firstname_start => params[:q],
:ship_address_lastname_start => params[:q],
:bill_address_firstname_start => params[:q],
:bill_address_lastname_start => params[:q]
}).result.limit(10)
end
render :users
end
end

View File

@@ -0,0 +1,35 @@
require 'spec_helper'
describe Spree::Admin::SearchController do
include AuthenticationWorkflow
context "Distributor Enterprise User" do
let!(:owner) { create_enterprise_user( email: "test1@email.com" ) }
let!(:manager) { create_enterprise_user( email: "test2@email.com" ) }
let!(:random) { create_enterprise_user( email: "test3@email.com" ) }
let!(:enterprise) { create(:enterprise, owner: owner, users: [owner, manager]) }
before { login_as_enterprise_user [enterprise] }
describe 'searching for known users' do
describe "when search query is not an exact match" do
before do
spree_get :known_users, q: "test"
end
it "returns a list of users that I share management of enteprises with" do
expect(assigns(:users)).to include owner, manager
expect(assigns(:users)).to_not include random
end
end
describe "when search query exactly matches the email of a user in the system" do
before do
spree_get :known_users, q: "test3@email.com"
end
it "returns that user, regardless of the relationship between the two users" do
expect(assigns(:users)).to eq [random]
end
end
end
end
end