Skip to content

Commit

Permalink
adds feature specs around searching for contributors
Browse files Browse the repository at this point in the history
adds integration specs around searching for a company

adds code to show what fields a user can search contributors, icla signers, or ccla signers by

forgive me rubocop, for I have sinned...

corrects variable assignment in a condition that rubocop was cranky about
  • Loading branch information
nellshamrell committed Feb 10, 2016
1 parent 05a6a5d commit 6ecb8c3
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 13 deletions.
15 changes: 7 additions & 8 deletions app/controllers/contributors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,9 @@ def become_a_contributor
# Display all of the users who are authorized to contribute
#
def index
if params[:contributors_q].present?
# Finds the intersection between the users returned by the search
# and the list of users who are authorized contributors
contributors = User.search(params[:contributors_q]) & User.authorized_contributors

else
contributors = User.authorized_contributors
end
# Finds the intersection between the users returned by the search
# and the list of users who are authorized contributors
contributors = params[:contributors_q].present? ? authorized_users_from_search(params[:contributors_q]) : User.authorized_contributors

# Using Kaminari.paginate_array because finding the intersection of two active record relations returns an array
@contributors = Kaminari.paginate_array(contributors).page(params[:page]).per(20)
Expand All @@ -66,4 +61,8 @@ def find_contributor
def contributor_params
params.require(:contributor).permit(:admin)
end

def authorized_users_from_search(search_param)
User.search(search_param) & User.authorized_contributors
end
end
11 changes: 11 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,15 @@ def search_path(controller_name)
ccla_signatures_path
end
end

def search_field_text(controller_name)
case controller_name
when 'contributors'
'Search for a contributor by name, email, chef or github username'
when 'icla_signatures'
'Search for an ICLA signer by name or email'
when 'ccla_signatures'
'Search for a CCLA signer by name or email'
end
end
end
4 changes: 2 additions & 2 deletions app/views/application/_contributors_list_heading.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<div class="contributor_search">
<%= form_tag search_path(controller.controller_name), method: :get do %>
<%= label_tag :contributors_search, 'Search' %>
<%= search_field_tag :contributors_q, params[:contributors_q], placeholder: 'Search for a contributor', class: "bar" %>
<%= button_tag(type: 'Submit', class: 'button') do %>
<%= search_field_tag :contributors_q, params[:contributors_q], placeholder: search_field_text(controller.controller_name), class: "bar", id: 'contributors_q' %>
<%= button_tag(type: 'submit', class: 'button', id: 'search_button') do %>
Search
<% end %>
<% end %>
Expand Down
103 changes: 100 additions & 3 deletions spec/features/contributors_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
let(:billy_contributor) { create(:contributor, user: billy) }

before do
# Making usernames distinct
suzie.chef_account.update_attributes!(
username: 'suzie',
uid: 'suzie'
)

billy.chef_account.update_attributes!(
username: 'billy',
uid: 'billy'
)

# Create ICLA
create(:icla)

Expand All @@ -30,21 +41,107 @@
end

it 'shows a search field' do
expect(page).to have_field('Search')
expect(page).to have_field('contributors_q')
end

it 'shows a search button' do
expect(page).to have_button('Search')
end

it 'shows the contributors' do
expect(page).to have_content(suzie.username)
expect(page).to have_content(billy.username)
end

describe 'user searches for a contributor' do
before do
fill_in('Search', with: suzie.username)
click_button('Search')
within '.contributor_search' do
fill_in('contributors_q', with: 'suzie')
submit_form
end
end

it 'shows the contributor the user searched for' do
expect(page).to have_content(suzie.username)
expect(page).to_not have_content(billy.username)
end
end
end

describe 'user clicks on the Individuals tab' do
let(:gary) { create(:user, first_name: 'Gary', last_name: 'Indiana', email: 'garyindiana@chef.io') }

before do
gary.chef_account.update_attributes!(
username: 'gary',
uid: 'gary'
)

expect(gary.signed_icla?).to eq(false)

click_link('Individuals')
end

it 'shows ICLA signers' do
expect(page).to have_content(suzie.username)
expect(page).to have_content(billy.username)
expect(page).to_not have_content(gary.username)
end

describe 'user searches for an ICLA signer' do
before do
# overwriting values of the icla factory to make distinct
suzie.icla_signatures.first.update_attributes!(
first_name: 'Sally',
last_name: 'Sue',
email: 'sallysue@chef.io'
)

billy.icla_signatures.first.update_attributes!(
first_name: 'Billy',
last_name: 'Bob',
email: 'billybob@chef.io'
)

within '.contributor_search' do
fill_in('contributors_q', with: 'Sally')
submit_form
end
end

it 'shows the contributor the user searched for' do
expect(page).to have_content(suzie.first_name)
expect(page).to_not have_content(billy.first_name)
end
end
end

describe 'user clicks on the Companies tab' do
let!(:org1) { create(:organization) }
let!(:org2) { create(:organization) }
let!(:ccla_signature1) { create(:ccla_signature, organization: org1, company: 'International House of Pancakes') }
let!(:ccla_signature2) { create(:ccla_signature, organization: org2, company: "Bob's Fish Shack") }

before do
click_link('Companies')
end

it 'shows the CCLA companies' do
expect(page).to have_content(ccla_signature1.company)
expect(page).to have_content(ccla_signature2.company)
end

describe 'user searchs for a company' do
before do
within '.contributor_search' do
fill_in('contributors_q', with: ccla_signature1.company)
submit_form
end
end

it 'shows the company the user searches for' do
expect(page).to have_content(ccla_signature1.company)
expect(page).to_not have_content(ccla_signature2.company)
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,24 @@
end
end
end

describe '#search_field_text' do
context 'when using the contributors controller' do
it 'returns the contributors search text' do
expect(search_field_text('contributors')).to eq('Search for a contributor by name, email, chef or github username')
end
end

context 'when using the icla signatures controller' do
it 'returns the icla signatures search text' do
expect(search_field_text('icla_signatures')).to eq('Search for an ICLA signer by name or email')
end
end

context 'when using the ccla signatures controller' do
it 'returns the ccla signatures search text' do
expect(search_field_text('ccla_signatures')).to eq('Search for a CCLA signer by name or email')
end
end
end
end

0 comments on commit 6ecb8c3

Please sign in to comment.