Commit cefffc60 authored by Steffen van Bergerem's avatar Steffen van Bergerem

Move contacts search to contacts#index

parent 9f28b935
......@@ -32,7 +32,7 @@ app.views.PublisherMention = app.views.SearchBase.extend({
typeaheadInput: this.typeaheadInput,
customSearch: true,
autoselect: true,
remoteRoute: "/contacts/search"
remoteRoute: "/contacts"
});
},
......
......@@ -13,17 +13,12 @@ class ContactsController < ApplicationController
# Used by the mobile site
format.mobile { set_up_contacts_mobile }
end
end
def search
@people = Person.search(params[:q], current_user, only_contacts: true).limit(15)
respond_to do |format|
format.json do
@people = @people.limit(15)
# Used for mentions in the publisher
format.json {
@people = Person.search(params[:q], current_user, only_contacts: true).limit(15)
render json: @people
end
}
end
end
......
......@@ -155,9 +155,6 @@ Diaspora::Application.routes.draw do
resources :contacts, only: %i(index)
get "contacts/search" => "contacts#search"
resources :aspect_memberships, :only => [:destroy, :create]
resources :share_visibilities, :only => [:update]
resources :blocks, :only => [:create, :destroy]
......
......@@ -48,28 +48,26 @@ describe ContactsController, :type => :controller do
expect(contacts.to_set).to eq(bob.contacts.to_set)
end
end
end
describe "#search" do
before do
@eugene = FactoryGirl.create(:person, profile: FactoryGirl.build(:profile, first_name: "Eugene", last_name: "W"))
bob.share_with(@eugene, bob.aspects.first)
@casey = FactoryGirl.create(:person, profile: FactoryGirl.build(:profile, first_name: "Casey", last_name: "W"))
end
context "format json" do
before do
@person1 = FactoryGirl.create(:person)
bob.share_with(@person1, bob.aspects.first)
@person2 = FactoryGirl.create(:person)
end
describe "via json" do
it "succeeds" do
get :search, q: "Eugene", format: "json"
get :index, q: @person1.first_name, format: "json"
expect(response).to be_success
end
it "responds with json" do
get :search, q: "Eugene", format: "json"
expect(response.body).to eq([@eugene].to_json)
get :index, q: @person1.first_name, format: "json"
expect(response.body).to eq([@person1].to_json)
end
it "only returns contacts" do
get :search, q: "Casey", format: "json"
get :index, q: @person2.first_name, format: "json"
expect(response.body).to eq([].to_json)
end
end
......
......@@ -19,7 +19,7 @@ describe("app.views.PublisherMention", function() {
expect(call.args[0].typeaheadInput.selector).toBe("#publisher .typeahead-mention-box");
expect(call.args[0].customSearch).toBeTruthy();
expect(call.args[0].autoselect).toBeTruthy();
expect(call.args[0].remoteRoute).toBe("/contacts/search");
expect(call.args[0].remoteRoute).toBe("/contacts");
});
it("calls bindTypeaheadEvents", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment