forked from rapidftr/RapidFTR
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote branch 'rikesh/master': Adding support for Capybara cukes;
advanced searching stuff.
- Loading branch information
Showing
28 changed files
with
811 additions
and
81 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
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,16 +1,37 @@ | ||
class AdvancedSearchController < ApplicationController | ||
|
||
def index | ||
def new | ||
@forms = FormSection.by_order | ||
@aside = 'shared/sidebar_links' | ||
|
||
if params[:criteria_list] | ||
@criteria_list = SearchCriteria.build_from_params params[:criteria_list] | ||
@results = SearchService.search(@criteria_list) | ||
else | ||
@criteria_list = [ SearchCriteria.new ] | ||
|
||
@criteria_list = [SearchCriteria.new] | ||
@results = [] | ||
render :index | ||
end | ||
|
||
def index | ||
@forms = FormSection.by_order | ||
@aside = 'shared/sidebar_links' | ||
new_search = !params[:criteria_list] | ||
|
||
if new_search | ||
@criteria_list = [SearchCriteria.new] | ||
@results = [] | ||
else | ||
@criteria_list = (child_fields_selected?(params[:criteria_list]) ? SearchCriteria.build_from_params(params[:criteria_list]): []) | ||
append_advanced_user_criteria(params[:created_by_value], @criteria_list) | ||
@results = SearchService.search(@criteria_list) | ||
end | ||
end | ||
|
||
def child_fields_selected?(criteria_list) | ||
!criteria_list.first[1]["field"].blank? if !criteria_list.first[1].nil? | ||
end | ||
|
||
def append_advanced_user_criteria(value, list) | ||
if (value) | ||
advanced_user_criteria = SearchCriteria.create_advanced_criteria({:field => "created_by", :value => value, :index => 12}) | ||
list.push(advanced_user_criteria) | ||
end | ||
|
||
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
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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Feature: So that I can find a child that has been entered in to RapidFTR | ||
As a user of the website | ||
I want to use the advanced search to find all relevant results | ||
|
||
@javascript | ||
Scenario: Searching for children by the user who created the child record | ||
Given the following children exist in the system: | ||
| name | created_by | | ||
| Willis | aidWorker | | ||
| Will | volunteer | | ||
|
||
And I am logged in | ||
And I am on child advanced search page | ||
|
||
When I check "created_by" | ||
And I fill in "aidWorker" for "created_by_value" | ||
And I press "Search" | ||
|
||
And I should see "Willis" in the search results | ||
|
||
@javascript | ||
Scenario: Searching for children by the child name field | ||
Given the following children exist in the system: | ||
| name | created_by | | ||
| Willis | aidWorker | | ||
| Will | volunteer | | ||
|
||
And I am logged in | ||
And I am on child advanced search page | ||
|
||
When I click text "Select A Criteria" | ||
And I click text "Name" | ||
And I fill in "Wil" for "criteria_list[0][value]" | ||
And I press "Search" | ||
|
||
And I should see "Willis" in the search results | ||
And I should see "Will" in the search results |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@javascript | ||
Feature: Test capybara is configured correctly | ||
|
||
Scenario: Log into RapidFTR | ||
Given a user "rapidftr" with a password "rapidftr" | ||
Given I am on the login page | ||
When I fill in "rapidftr" for "user_name" | ||
And I fill in "rapidftr" for "password" | ||
And I press "Log in" |
18 changes: 18 additions & 0 deletions
18
capybara_features/step_definitions/children_setup_steps.rb
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'spec/spec_helper' | ||
|
||
Given /^the following children exist in the system:$/ do |children_table| | ||
children_table.hashes.each do |child_hash| | ||
child_hash.reverse_merge!( | ||
'birthplace' => 'Cairo', | ||
'photo_path' => 'features/resources/jorge.jpg', | ||
'reporter' => 'zubair', | ||
'age_is' => 'Approximate' | ||
) | ||
photo = uploadable_photo(child_hash.delete('photo_path')) if child_hash['photo_path'] != '' | ||
unique_id = child_hash.delete('unique_id') | ||
child = Child.new_with_user_name(child_hash['created_by'], child_hash) | ||
child.photo = photo | ||
child['unique_identifier'] = unique_id if unique_id | ||
child.create! | ||
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
Given /^an? (user|admin) "([^\"]*)" with(?: a)? password "([^\"]*)"$/ do |user_type, username, password| | ||
user_type = user_type == 'user' ? 'User' : 'Administrator' | ||
@user = User.new( | ||
:user_name=>username, | ||
:password=>password, | ||
:password_confirmation=>password, | ||
:user_type=> user_type, | ||
:full_name=>username, | ||
:email=>"#{username}@test.com") | ||
@user.save! | ||
end | ||
|
||
Given /^an? (user|admin) "([^"]+)"$/ do |user_type, user_name| | ||
Given %(a #{user_type} "#{user_name}" with password "123") | ||
end | ||
|
||
Given /^I am logged in as "(.+)"/ do |user_name| | ||
@session = Session.for_user(User.find_by_user_name(user_name), nil) | ||
@session.save! | ||
@session.put_in_cookie cookies | ||
end | ||
|
||
Given /^I have an expired session/ do | ||
@session.destroy | ||
end | ||
|
||
Given /^user "(.+)" is disabled$/ do |username| | ||
user = User.find_by_user_name(username) | ||
user.disabled = true | ||
user.save! | ||
end | ||
|
||
Then /^user "(.+)" should be disabled$/ do |username| | ||
User.find_by_user_name(username).should be_disabled | ||
end | ||
|
||
Then /^user "(.+)" should not be disabled$/ do |username| | ||
User.find_by_user_name(username).should_not be_disabled | ||
end | ||
|
||
Given /^the following admin contact info:$/ do |table| | ||
contact_info = table.hashes.inject({}) do |result, current| | ||
result[current["key"]] = current["value"] | ||
result | ||
end | ||
contact_info[:id] = "administrator" | ||
ContactInformation.create contact_info | ||
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Given /^I am logged in$/ do | ||
Given "there is a User" | ||
Given "I am on the login page" | ||
Given "I fill in \"#{User.first.user_name}\" for \"user_name\"" | ||
Given "I fill in \"123\" for \"password\"" | ||
Given "I press \"Log in\"" | ||
end | ||
|
||
Given /there is a User/ do | ||
unless @user | ||
Given "a user \"mary\" with a password \"123\"" | ||
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. | ||
# It is recommended to regenerate this file in the future when you upgrade to a | ||
# newer version of cucumber-rails. Consider adding your own code to a new file | ||
# instead of editing this one. Cucumber will automatically load all features/**/*.rb | ||
# files. | ||
|
||
require 'uri' | ||
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths")) | ||
|
||
module WithinHelpers | ||
def with_scope(locator) | ||
locator ? within(locator) { yield } : yield | ||
end | ||
end | ||
World(WithinHelpers) | ||
|
||
When /^I click text "([^"]*)"(?: within "([^\"]*)")?$/ do |text_value, selector| | ||
with_scope(selector) do | ||
page.find('//a', :text => text_value).click | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'spec/spec_helper' | ||
|
||
Then /^I should see "([^\"]*)" in the search results$/ do |value| | ||
|
||
match = page.find('//a', :text => value) | ||
raise Spec::Expectations::ExpectationNotMetError, "Could not find the value: #{value} in the search results" unless match | ||
end |
Oops, something went wrong.