From b717ccfb31afcdd9463b70229d668b60107c9f0e Mon Sep 17 00:00:00 2001 From: Elliot Crosby-McCullough Date: Wed, 11 Jun 2014 16:57:09 +0100 Subject: [PATCH] List users by name on app edit forms. --- app/controllers/apps_controller.rb | 4 ++++ app/views/apps/_fields.html.haml | 2 +- spec/controllers/apps_controller_spec.rb | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/apps_controller.rb b/app/controllers/apps_controller.rb index eed03f0..a403d4c 100644 --- a/app/controllers/apps_controller.rb +++ b/app/controllers/apps_controller.rb @@ -36,6 +36,10 @@ class AppsController < ApplicationController app.deploys.order_by(:created_at.desc).limit(5) } + expose(:users) { + User.all.asc(:name) + } + def index; end def show app diff --git a/app/views/apps/_fields.html.haml b/app/views/apps/_fields.html.haml index 31e811a..0573bf9 100644 --- a/app/views/apps/_fields.html.haml +++ b/app/views/apps/_fields.html.haml @@ -55,7 +55,7 @@ = w.radio_button :watcher_type, :email = label_tag :watcher_type_email, 'Email Address', :for => label_for_attr(w, 'watcher_type_email') %div.watcher_params.user{:class => w.object.email.blank? ? 'chosen' : nil} - = w.select :user_id, User.all.map{|u| [u.name,u.id.to_s]}, :include_blank => '-- Select a User --' + = w.select :user_id, users.map{|u| [u.name,u.id.to_s]}, :include_blank => '-- Select a User --' %div.watcher_params.email{:class => w.object.email.present? ? 'chosen' : nil} = w.text_field :email diff --git a/spec/controllers/apps_controller_spec.rb b/spec/controllers/apps_controller_spec.rb index e572217..55d4f95 100644 --- a/spec/controllers/apps_controller_spec.rb +++ b/spec/controllers/apps_controller_spec.rb @@ -73,6 +73,16 @@ describe AppsController do expect(response).to be_success end + it "should list available watchers by name" do + Fabricate(:user, :name => "Carol") + Fabricate(:user, :name => "Alice") + Fabricate(:user, :name => "Betty") + + get :show, :id => app.id + + expect(controller.users.to_a).to eq(User.all.to_a.sort_by(&:name)) + end + context "pagination" do before(:each) do 35.times { Fabricate(:err, :problem => Fabricate(:problem, :app => app)) } -- libgit2 0.21.2