Commit 6e159814
Changed files (3)
app
controllers
admin
models
spec
controllers
admin
app/controllers/admin/users_controller.rb
@@ -1,7 +1,7 @@
module Admin
class UsersController < AdminController
def index
- @users = User.all
+ @users = User.search_by(params[:q])
end
def show
app/models/user.rb
@@ -67,6 +67,10 @@ class User < ActiveRecord::Base
User.order(:creations_count => :desc)
end
+ def search_by(query)
+ self.scoped
+ end
+
def login(username, password)
user = User.find_by(email: username)
return false if user.nil?
spec/controllers/admin/users_controller_spec.rb
@@ -15,6 +15,13 @@ module Admin
get :index
expect(assigns(:users)).to include(user)
end
+
+ it "returns users that match the search results" do
+ matching_user = double
+ User.stub(:search_by).with('mo').and_return([matching_user])
+ get :index, q: 'mo'
+ expect(assigns(:users)).to include(matching_user)
+ end
end
describe "#show" do