This repository has been archived by the owner on Nov 19, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract search logic from controller
- Loading branch information
Showing
3 changed files
with
57 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
class Bug < ActiveRecord::Base | ||
validates :bug_id, presence: true | ||
|
||
def self.opened_bugs_for(components) | ||
bug_statuses = %w(NEW ASSIGNED VERIFIED REOPENED) | ||
where(component: components, bug_status: bug_statuses).order('bug_id DESC') | ||
end | ||
|
||
def self.all_bugs_for(components) | ||
where(component: components).order('bug_id DESC') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,48 @@ | ||
require 'rails_helper' | ||
|
||
describe Bug do | ||
context 'DB Indexes' do | ||
it { is_expected.to have_db_index :assigned_to } | ||
it { is_expected.to have_db_index :bug_status } | ||
it { is_expected.to have_db_index :product } | ||
describe 'Validations' do | ||
specify { should validate_presence_of :bug_id } | ||
end | ||
|
||
describe 'DB Indexes' do | ||
specify { should have_db_index :assigned_to } | ||
specify { should have_db_index :bug_status } | ||
specify { should have_db_index :product } | ||
end | ||
|
||
describe '.opened_bugs_for' do | ||
before do | ||
# | ||
# bug_statuses = %w(NEW ASSIGNED VERIFIED REOPENED) | ||
# Bug.where(component: components, bug_status: bug_statuses).order('bug_id DESC') | ||
# | ||
bug_statuses = %w(NEW ASSIGNED VERIFIED REOPENED) | ||
components = ['anything'] | ||
|
||
expect(described_class).to receive(:where).with(component: components, bug_status: bug_statuses) do | ||
double.tap do |a| | ||
expect(a).to receive(:order).with('bug_id DESC') | ||
end | ||
end | ||
end | ||
|
||
specify { expect { described_class.opened_bugs_for(['anything']) }.not_to raise_error } | ||
end | ||
|
||
describe '.all_bugs_for' do | ||
before do | ||
# | ||
# Bug.where(component: components).order('bug_id DESC') | ||
# | ||
components = ['anything'] | ||
expect(described_class).to receive(:where).with(component: components) do | ||
double.tap do |a| | ||
expect(a).to receive(:order).with('bug_id DESC') | ||
end | ||
end | ||
end | ||
|
||
specify { expect { described_class.all_bugs_for(['anything']) }.not_to raise_error } | ||
end | ||
end |