Skip to content

Commit

Permalink
Merge pull request #483 from sparc-request/jw_org_filter_gen_users
Browse files Browse the repository at this point in the history
Jw org filter gen users
  • Loading branch information
amcates committed Jun 13, 2016
2 parents 3c2ce78 + 4d61708 commit 01cdeb4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 27 deletions.
9 changes: 5 additions & 4 deletions app/controllers/dashboard/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ def index
# if we are an admin we want to default to admin organizations
if @admin
@organizations = Dashboard::IdentityOrganizations.new(@user.id).admin_organizations_with_protocols
default_filter_params[:admin_filter] = "for_admin #{current_user.id}"
default_filter_params[:admin_filter] = "for_admin #{@user.id}"
else
@organizations = Dashboard::IdentityOrganizations.new(@user.id).general_user_organizations_with_protocols
default_filter_params[:admin_filter] = "for_identity #{current_user.id}"
default_filter_params[:admin_filter] = "for_identity #{@user.id}"
params[:filterrific][:admin_filter] = "for_identity #{@user.id}" if params[:filterrific]
end

@filterrific =
initialize_filterrific(Protocol, params[:filterrific],
default_filter_params: default_filter_params,
Expand All @@ -54,7 +54,8 @@ def index
persistence_id: false #resets filters on page reload
) || return

@protocols = @filterrific.find.page(params[:page])
@protocols = @filterrific.find.page(params[:page])

@admin_protocols = Protocol.for_admin(@user.id).pluck(:id)
@protocol_filters = ProtocolFilter.latest_for_user(@user.id, 5)
#toggles the display of the navigation bar, instead of breadcrumbs
Expand Down
1 change: 0 additions & 1 deletion app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ class Protocol < ActiveRecord::Base

scope :admin_filter, -> (params) {
filter, id = params.split(" ")

if filter == 'for_admin'
return filtered_for_admin(id)
elsif filter == 'for_identity'
Expand Down
2 changes: 1 addition & 1 deletion app/views/dashboard/protocols/index.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

$("#filterrific_form").html("<%= escape_javascript(render(partial: '/dashboard/protocol_filters/filter_protocols_form', locals: {filterrific: @filterrific, current_user: @user, admin: @admin})) %>")
$("#filterrific_results").html("<%= escape_javascript(render(partial: '/dashboard/protocols/protocols_list', locals: {protocols: @protocols, admin_protocols: @admin_protocols})) %>")
$("#filterrific_results").html("<%= escape_javascript(render(partial: '/dashboard/protocols/protocols_list', locals: {protocols: @protocols, current_user: @user, admin_protocols: @admin_protocols})) %>")
$(".selectpicker").selectpicker()
8 changes: 6 additions & 2 deletions spec/controllers/dashboard/protocols/get_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@
context 'user has no admin organizations' do
before(:each) do
@logged_in_user = build_stubbed(:identity)

allow(@logged_in_user).to receive(:authorized_admin_organizations).
and_return([])

paginated_protocols = double('protocols', page: [:protocols])
protocol = build_stubbed(:protocol)
build_stubbed(:project_role, identity: @logged_in_user, protocol: protocol)

paginated_protocols = double('protocols', page: @logged_in_user.protocols)
filterrific = double('filterrific', find: paginated_protocols)
allow(controller).to receive(:initialize_filterrific).
and_return(filterrific)
Expand All @@ -65,7 +69,7 @@
end

it "should assign @protocols to those returned by filterrific" do
expect(assigns(:protocols)).to eq [:protocols]
expect(assigns(:protocols)).to eq @logged_in_user.protocols
end

it 'should assign @protocol_filters to the five most recent filters' do
Expand Down
28 changes: 9 additions & 19 deletions spec/features/dashboard/protocols/index/filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,48 +209,38 @@ def visit_protocols_index_page
expect(@page.search_results).to have_protocols(text: "Protocol1")
end

it "should match against associated users first name case insensitively" do
it "should match against associated users first name case insensitively (lowercase)" do
protocol1 = create_protocol(archived: false, short_title: "Protocol1")
create(:project_role, identity: user, role: "very-important", project_rights: "to-party", protocol: protocol1)
create(:project_role, identity: create(:identity, first_name: "name1"), role: "very-important", project_rights: "to-party", protocol: protocol1)

protocol2 = create_protocol(archived: false, short_title: "Protocol2")
create(:project_role, identity: user, role: "very-important", project_rights: "to-party", protocol: protocol2)
create(:project_role, identity: create(:identity, first_name: "Name1"), role: "very-important", project_rights: "to-party", protocol: protocol2)

protocol3 = create_protocol(archived: false, short_title: "Protocol3")
create(:project_role, identity: user, role: "very-important", project_rights: "to-party", protocol: protocol3)
create(:project_role, identity: create(:identity, first_name: "name3"), role: "very-important", project_rights: "to-party", protocol: protocol3)

visit_protocols_index_page
@page.filter_protocols.search_field.set("name1")
@page.filter_protocols.apply_filter_button.click

@page.filter_protocols.search_field.set("john")
@page.filter_protocols.apply_filter_button.click()
expect(@page.search_results).to have_protocols(text: "Protocol1")
expect(@page.search_results).to have_protocols(text: "Protocol2")
expect(@page.search_results).to have_no_protocols(text: "Protocol3")
expect(@page.search_results).to have_protocols(text: "Protocol3")
end

it "should match against associated users last name case insensitively" do
it "should match against associated users last name case insensitively (uppercase)" do
protocol1 = create_protocol(archived: false, short_title: "Protocol1")
create(:project_role, identity: user, role: "very-important", project_rights: "to-party", protocol: protocol1)
create(:project_role, identity: create(:identity, last_name: "name1"), role: "very-important", project_rights: "to-party", protocol: protocol1)

protocol2 = create_protocol(archived: false, short_title: "Protocol2")
create(:project_role, identity: user, role: "very-important", project_rights: "to-party", protocol: protocol2)
create(:project_role, identity: create(:identity, last_name: "Name1"), role: "very-important", project_rights: "to-party", protocol: protocol2)

protocol3 = create_protocol(archived: false, short_title: "Protocol3")
create(:project_role, identity: user, role: "very-important", project_rights: "to-party", protocol: protocol3)
create(:project_role, identity: create(:identity, last_name: "name3"), role: "very-important", project_rights: "to-party", protocol: protocol3)

visit_protocols_index_page
@page.filter_protocols.search_field.set("name1")
@page.filter_protocols.apply_filter_button.click
@page.filter_protocols.search_field.set("John")
@page.filter_protocols.apply_filter_button.click()

expect(@page.search_results).to have_protocols(text: "Protocol1")
expect(@page.search_results).to have_protocols(text: "Protocol2")
expect(@page.search_results).to have_no_protocols(text: "Protocol3")
expect(@page.search_results).to have_protocols(text: "Protocol3")
end
end

Expand Down

0 comments on commit 01cdeb4

Please sign in to comment.