diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-03-24 13:30:37 -0700 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-03-24 13:30:37 -0700 |
commit | b7a588892fcd9d683d0391f9fce43df29443918e (patch) | |
tree | 1ab734b354eb90c68fc3c86a4c374ca686ba7d0b | |
parent | 1a150e144087cdd2d936823401a6d24baa31ad86 (diff) | |
download | gitlab-ci-b7a588892fcd9d683d0391f9fce43df29443918e.tar.gz |
Add project search at runner page
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/controllers/admin/runners_controller.rb | 1 | ||||
-rw-r--r-- | app/models/project.rb | 5 | ||||
-rw-r--r-- | app/views/admin/runners/show.html.haml | 8 | ||||
-rw-r--r-- | spec/features/admin/runners_spec.rb | 21 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 9 |
6 files changed, 43 insertions, 2 deletions
@@ -1,5 +1,6 @@ v7.10.0 - Projects sorting by last commit date + - Add project search at runner page v7.9.0 - Reset user session if token is invalid diff --git a/app/controllers/admin/runners_controller.rb b/app/controllers/admin/runners_controller.rb index a6ef86e..e387f4b 100644 --- a/app/controllers/admin/runners_controller.rb +++ b/app/controllers/admin/runners_controller.rb @@ -8,6 +8,7 @@ class Admin::RunnersController < Admin::ApplicationController def show @builds = @runner.builds.order('id DESC').first(30) @projects = Project.all + @projects = @projects.search(params[:search]) if params[:search].present? @projects = @projects.where("projects.id NOT IN (?)", @runner.projects.pluck(:id)) if @runner.projects.any? @projects = @projects.page(params[:page]).per(30) end diff --git a/app/models/project.rb b/app/models/project.rb index 629c4fe..dd9d9d4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -119,6 +119,11 @@ ls -la joins("LEFT JOIN #{last_commit_subquery} AS last_commit ON projects.id = last_commit.project_id"). order("CASE WHEN last_commit.created_at IS NULL THEN 1 ELSE 0 END, last_commit.created_at DESC") end + + def search(query) + where('LOWER(projects.name) LIKE :query', + query: "%#{query.try(:downcase)}%") + end end def set_default_values diff --git a/app/views/admin/runners/show.html.haml b/app/views/admin/runners/show.html.haml index 6ea987a..d6bd219 100644 --- a/app/views/admin/runners/show.html.haml +++ b/app/views/admin/runners/show.html.haml @@ -66,6 +66,14 @@ title: 'Assign runner to all projects', method: :put + %tr + %td + = form_tag admin_runner_path(@runner), class: 'form-inline', method: :get do + .form-group + = search_field_tag :search, params[:search], class: 'form-control' + = submit_tag 'Search', class: 'btn' + + %td - @projects.each do |project| %tr %td diff --git a/spec/features/admin/runners_spec.rb b/spec/features/admin/runners_spec.rb index b480894..5fe1130 100644 --- a/spec/features/admin/runners_spec.rb +++ b/spec/features/admin/runners_spec.rb @@ -22,9 +22,28 @@ describe "Admin Runners" do let(:runner) { FactoryGirl.create :runner } before do + FactoryGirl.create(:project, name: "foo") + FactoryGirl.create(:project, name: "bar") visit admin_runner_path(runner) end - it { find_field('runner_token').value.should eq runner.token } + describe 'runner info' do + it { find_field('runner_token').value.should eq runner.token } + end + + describe 'projects' do + it { page.should have_content("foo") } + it { page.should have_content("bar") } + end + + describe 'search' do + before do + fill_in 'search', with: 'foo' + click_button 'Search' + end + + it { page.should have_content("foo") } + it { page.should_not have_content("bar") } + end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 8ad2c69..6fc6c32 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -30,7 +30,7 @@ describe Project do it { should have_many(:commits) } - it { should validate_presence_of :name } + it { should validate_presence_of :name } it { should validate_presence_of :timeout } it { should validate_presence_of :default_ref } @@ -161,4 +161,11 @@ describe Project do expect(project.skip_ref?('feature/some_feature')).to eq true end end + + describe :search do + let!(:project) { FactoryGirl.create(:project, name: "foo") } + + it { Project.search('fo').should include(project) } + it { Project.search('bar').should be_empty } + end end |