-
-
Notifications
You must be signed in to change notification settings - Fork 198
Member search #2260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jonodrew
wants to merge
13
commits into
codebar:master
Choose a base branch
from
jonodrew:member-search
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+221
−0
Open
Member search #2260
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c5213b5
Initial commit
jonodrew 4948fb6
Write multiple Controller tests to check logic
jonodrew 3ee75c4
Add ports to docker-compose for db
jonodrew b73a932
Set up feature tests
jonodrew 854fcd3
Write first test
jonodrew 1b91149
Add tests for model code
jonodrew 0e82d06
Add failing tests to catch future cases
jonodrew ecc8789
Switch to using local variables only
jonodrew ca43599
Add test for when search is blank
jonodrew 02b352f
Update method to return nothing if search bar is blank
jonodrew e5d622f
Move js: true up to the top of this feature
jonodrew f92228f
Force-create juliet
jonodrew 646ee02
Remove extraneous test
jonodrew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Admin::MemberSearchController < Admin::ApplicationController | ||
def index | ||
member_params = params[:member_search] || {} | ||
name = member_params[:name] | ||
members = name.blank? ? Member.none : Member.find_members(name).select(:id, :name, :surname, :pronouns) | ||
callback_url = member_params[:callback_url] || params[:callback_url] || results_admin_member_search_index_path | ||
if members.size == 1 | ||
query = { member_pick: { members: [members.first.id] } } | ||
query_string = query.to_query | ||
callback_url = "#{callback_url}?#{query_string}" | ||
redirect_to callback_url and return | ||
end | ||
|
||
render 'index', locals: { members: members, callback_url: callback_url } | ||
end | ||
|
||
def results | ||
members = Member.find(params[:member_pick][:members]) | ||
render 'show',locals: { members: members } | ||
end | ||
end |
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
= simple_form_for :member_search, url: admin_member_search_index_path, method: :get, html: {multipart: true, novalidate: true } do |f| | ||
.row | ||
.col-12.col-md-6 | ||
= f.input :name, label: 'Member Name', input_html: { placeholder: 'Enter member name' } | ||
= f.button :submit, 'Search', class: 'btn btn-primary mt-3', name: nil | ||
= f.hidden_field 'callback_url', value: callback_url |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.container.py-4.py-lg-5 | ||
.row.mb-4 | ||
.col | ||
%h1 Member search | ||
|
||
.row | ||
.col.col-md-10.col-lg-8 | ||
= render partial: 'search_form', locals: { callback_url: callback_url } | ||
|
||
.row | ||
.col.col-md-10.col-lg-8 | ||
- if members.present? | ||
%h2 Select Member | ||
= simple_form_for :member_pick, url: callback_url, method: :get do |f| | ||
.row | ||
.col-12.col-md-6 | ||
= f.label :members, 'Member Name' | ||
- members.each do |member| | ||
.form-check | ||
= f.check_box :members, { multiple: true, checked: member.id }, member.id, nil | ||
= f.label "members_#{member.id}", member.name_and_surname, class: 'form-check-label' | ||
= f.button :submit, 'Take me back', class: 'btn btn-primary mt-3', name: nil |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.container.py-4.py-lg-5 | ||
.row.mb-4 | ||
.col | ||
%h1 Results | ||
|
||
.row | ||
.col.col-md-10.col-lg-8 | ||
%h2 Search Results | ||
%ul.list-group | ||
- members.each do |member| | ||
%li.list-group-item | ||
= link_to member.name_and_surname, admin_member_path(member) |
This file contains hidden or 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 hidden or 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,6 +1,8 @@ | ||
services: | ||
db: | ||
image: postgres:17 | ||
ports: | ||
- 5433:5432 | ||
volumes: | ||
- db_data:/var/lib/postgresql/data | ||
environment: | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
RSpec.describe Admin::MemberSearchController, type: :controller do | ||
let(:member) {Fabricate.build(:member)} | ||
|
||
describe 'GET #index' do | ||
context "when user is not logged in" do | ||
before do | ||
get :index | ||
end | ||
it "redirects to the home page" do | ||
expect(response).to redirect_to(root_path) | ||
end | ||
end | ||
|
||
context "when user is an admin" do | ||
let(:fake_relation) { instance_double('ActiveRecord::Relation') } | ||
let(:fake_juliet) { instance_double('Member', id: 1, name: 'Juliet', surname: 'Montague') } | ||
|
||
before do | ||
login_as_admin(member) | ||
get :index | ||
end | ||
it "shows user the search page" do | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
context "and when admin user searches for a single existing user" do | ||
before do | ||
allow(Member).to receive(:find_members).with('Juliet').and_return(fake_relation) | ||
allow(fake_relation).to receive(:select).with(any_args).and_return([fake_juliet]) | ||
get :index, params: {member_search: {name: "Juliet", callback_url: root_path}} | ||
end | ||
it "redirects to the calling service" do | ||
expect(response).to have_http_status(:found) | ||
|
||
uri = URI.parse(response.location) | ||
redirect_params = Rack::Utils.parse_nested_query(uri.query) | ||
|
||
expect(redirect_params["member_pick"]["members"]).to eq(["1"]) | ||
end | ||
end | ||
|
||
context "and when an admin user searches and there are multiple results" do | ||
let(:fake_romeo) { double('Member', id: 2, name: 'Romeo', surname: 'Capulet')} | ||
|
||
before do | ||
allow(Member).to receive(:find_members).with('e').and_return(fake_relation) | ||
allow(fake_relation).to receive(:select).with(any_args).and_return([fake_juliet, fake_romeo]) | ||
get :index, params: {member_search: {name: 'e', callback_url: root_path}} | ||
end | ||
it "presents the found members on the index page" do | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
RSpec.describe 'Add a user to an existing workshop', js: true, type: :feature do | ||
let(:member) {Fabricate(:member)} | ||
|
||
let!(:juliet) {Fabricate(:member, name: 'Juliet', surname: 'Capulet')} | ||
let!(:romeo) { Fabricate(:member, name: 'Romeo', surname: 'Montague') } | ||
let(:workshop) {Fabricate(:workshop)} | ||
|
||
before do | ||
login_as_admin(member) | ||
@start_page = "/admin/workshops/#{workshop.id}" | ||
end | ||
|
||
scenario 'An admin searches and gets an exact match' do | ||
visit @start_page | ||
|
||
params = {callback_url: @start_page.to_s}.to_query | ||
visit "/admin/member-search?#{params}" | ||
fill_in 'Member Name', with: juliet.name_and_surname | ||
click_on 'Search' | ||
expect(page).to have_current_path(@start_page, ignore_query: true) | ||
end | ||
|
||
scenario 'An admin adds a member to a workshop' do | ||
visit @start_page | ||
|
||
params = {callback_url: @start_page.to_s}.to_query | ||
visit "/admin/member-search?#{params}" | ||
fill_in 'Member Name', with: 'e' | ||
click_on 'Search' | ||
expect(page).to have_current_path('/admin/member-search/index', ignore_query: true) | ||
|
||
expect(page).to have_content('Romeo Montague') | ||
expect(page).to have_unchecked_field('Romeo Montague') | ||
check('Romeo Montague') | ||
click_button'Take me back' | ||
|
||
expect(page).to have_current_path(@start_page, ignore_query: true) | ||
uri = URI.parse(page.current_url) | ||
params = Rack::Utils.parse_nested_query(uri.query).with_indifferent_access | ||
|
||
expect(params[:member_pick][:members]).to eq([romeo.id.to_s]) | ||
end | ||
end |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
RSpec.feature 'admin member search', type: :feature do | ||
scenario 'search returns single member to requesting service' do | ||
Fabricate(:member, :name => 'Romeo', :surname => 'Montague') | ||
Fabricate(:member, :name => 'Juliet', :surname => 'Capulet') | ||
member = Fabricate(:member) | ||
login_as_admin(member) | ||
visit admin_member_search_index_path(callback_url: results_admin_member_search_index_path) | ||
|
||
fill_in 'member_search_name', with: 'Julie' | ||
click_button 'Search' | ||
|
||
expect(page).to have_current_path(results_admin_member_search_index_path, ignore_query: true) | ||
|
||
expect(page).to have_content('Juliet Capulet') | ||
end | ||
|
||
|
||
end |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonodrew can we rename this method to find_members_by_name? Just to be explicit.