How to use text method of Queries Package

Best Capybara code snippet using Queries.text

queries_controller_test.rb

Source:queries_controller_test.rb Github

copy

Full Screen

...9 login_user user10 end11 describe 'Adds new query' do12 let(:acase) { cases(:queries_case) }13 test 'requires query text' do14 post :create, params: { case_id: acase.id, query: { query_text: nil } }15 assert_response :bad_request16 assert_includes json_response['query_text'], "can't be blank"17 end18 test 'to the end of the query list if no position is provided' do19 query_text = 'New Query'20 post :create, params: { case_id: acase.id, query: { query_text: query_text } }21 assert_response :ok22 query_response = json_response['query']23 assert_not_nil query_response['queryId']24 assert_equal query_response['arrangedAt'], 025 assert_equal query_response['query_text'], query_text26 query = acase.queries.first27 assert_equal query.id, query_response['queryId']28 assert_equal query.query_text, query_text29 end30 test 'return the new display order of the queries' do31 query_text = 'New Query'32 post :create, params: { case_id: acase.id, query: { query_text: query_text } }33 assert_response :ok34 display_order = json_response['displayOrder']35 assert_not_nil display_order36 assert_instance_of Array, display_order37 end38 test 'at the proper position when one is provided' do39 query_text = 'New Query'40 position = 241 post :create, params: { case_id: acase.id, query: { query_text: query_text }, position: 2 }42 assert_response :ok43 query_response = json_response['query']44 assert_not_nil query_response['queryId']45 assert_equal query_response['query_text'], query_text46 acase.reload47 query = acase.queries[position]48 assert_equal query.id, query_response['queryId']49 assert_equal query.query_text, query_text50 end51 test 'with special characters in name' do52 query_text = 'New Query 会议'53 post :create, params: { case_id: acase.id, query: { query_text: query_text } }54 assert_response :ok55 query_response = json_response['query']56 assert_not_nil query_response['queryId']57 assert_equal query_response['arrangedAt'], 058 assert_equal query_response['query_text'], query_text59 end60 test 'handles when query already exists' do61 query_text = 'New Query'62 post :create, params: { case_id: acase.id, query: { query_text: query_text } }63 assert_response :ok64 query_response = json_response['query']65 assert_not_nil query_response['queryId']66 assert_equal query_response['arrangedAt'], 067 assert_equal query_response['query_text'], query_text68 count = acase.queries.count69 query_text = 'New Query'70 post :create, params: { case_id: acase.id, query: { query_text: query_text } }71 assert_response :no_content72 acase.reload73 new_count = acase.queries.count74 assert_equal count, new_count75 end76 test 'strips whitespace from query text' do77 query_text = 'New Query '78 post :create, params: { case_id: acase.id, query: { query_text: query_text } }79 assert_response :ok80 query_response = json_response['query']81 assert_not_nil query_response['queryId']82 assert_equal query_response['arrangedAt'], 083 assert_equal query_response['query_text'], query_text.strip84 count = acase.queries.count85 query_text = ' New Query'86 post :create, params: { case_id: acase.id, query: { query_text: query_text } }87 assert_response :no_content88 acase.reload89 new_count = acase.queries.count90 assert_equal count, new_count91 end92 test 'accepts a different variation of the same query text' do93 query_text = 'dog'94 assert_difference 'acase.queries.count' do95 post :create, params: { case_id: acase.id, query: { query_text: query_text } }96 assert_response :ok97 query_response = json_response['query']98 assert_equal query_response['query_text'], query_text99 end100 query_text = 'Dog'101 assert_difference 'acase.queries.count' do102 post :create, params: { case_id: acase.id, query: { query_text: query_text } }103 assert_response :ok104 query_response = json_response(true)['query']105 assert_equal query_response['query_text'], query_text106 end107 query_text = 'DoG'108 assert_difference 'acase.queries.count' do109 post :create, params: { case_id: acase.id, query: { query_text: query_text } }110 assert_response :ok111 query_response = json_response(true)['query']112 assert_equal query_response['query_text'], query_text113 end114 query_text = 'dOg'115 assert_difference 'acase.queries.count' do116 post :create, params: { case_id: acase.id, query: { query_text: query_text } }117 assert_response :ok118 query_response = json_response(true)['query']119 assert_equal query_response['query_text'], query_text120 end121 end122 describe 'analytics' do123 test 'posts event' do124 expects_any_ga_event_call125 query_text = 'New Query'126 perform_enqueued_jobs do127 post :create, params: { case_id: acase.id, query: { query_text: query_text } }128 assert_response :ok129 end130 end131 end132 end133 describe 'Fetches case queries' do134 let(:acase) { cases(:queries_case) }135 test 'returns case queries in order' do136 get :index, params: { case_id: acase.id }137 assert_response :ok138 queries = JSON.parse(response.body)['queries']139 assert_equal queries[0]['arrangedAt'], 1140 assert_equal queries[1]['arrangedAt'], 2141 assert_equal queries[2]['arrangedAt'], 3...

Full Screen

Full Screen

snapshot_manager.rb

Source:snapshot_manager.rb Github

copy

Full Screen

...90 # rubocop:disable Metrics/MethodLength91 def import_queries queries92 queries_to_import = []93 keys = queries.keys94 # Fetch all queries for the snapshot's case where the query text95 # matches the keys in the hash supplied in the params.96 queries_params = {97 query_text: keys,98 case_id: @snapshot.case_id,99 }100 indexed_queries = Query.where(queries_params)101 .all102 .index_by(&:query_text)103 # Start by adding queries to snapshot.104 # First, setup all queries to be added in an array.105 print_step 'Importing queries'106 block_with_progress_bar(keys.length) do |i|107 query_text = keys[i]108 query = fetch_or_create_query indexed_queries, query_text109 snapshot_query = @snapshot.snapshot_queries.where(query_id: query.id).first_or_initialize110 queries[query.id] = queries.delete(keys[i])111 queries_to_import << snapshot_query112 end113 # Second, mass insert queries.114 SnapshotQuery.import queries_to_import115 # End of queries import.116 # Updates keys after we switched them out from the text to the id117 keys = queries.keys118 data = {}119 queries.each { |key, q| data[key] = q[:docs] || q['docs'] }120 # Then import docs for the queries that were just created.121 import_docs keys, data122 self123 end124 # rubocop:enable Metrics/MethodLength125 def csv_to_queries_hash docs126 print_step 'Transforming csv into a queries hash'127 query_docs = {}128 block_with_progress_bar(docs.length) do |i|129 row = extract_doc_info docs[i]130 query_docs[row[:query_text]] ||= { docs: [] }131 query_docs[row[:query_text]][:docs] << row132 end133 query_docs134 end135 private136 def setup_docs_for_query query, docs137 results = []138 return results if docs.blank?139 return results if query.blank?140 docs = normalize_docs_array docs141 docs = docs.sort { |d1, d2| d1[:position].to_i <=> d2[:position].to_i }142 docs.each_with_index do |doc, index|143 doc_params = {144 doc_id: doc[:id],145 explain: doc[:explain],146 position: doc[:position] || (index + 1),147 rated_only: doc[:rated_only] || false,148 }149 results << query.snapshot_docs.build(doc_params)150 end151 results152 end153 def extract_doc_info row154 case @options[:format]155 when :csv156 {157 query_text: row[0],158 id: row[1],159 position: row[2],160 }161 when :hash162 row.deep_symbolize_keys163 else164 row165 end166 end167 def normalize_docs_array docs168 return [] if docs.blank?169 result = docs.map do |each|170 each = each.to_unsafe_h if each.is_a?(ActionController::Parameters)171 each = each.to_hash if each.is_a?(ActiveSupport::HashWithIndifferentAccess)172 each.symbolize_keys! if each.present?173 end.compact174 result175 end176 def import_docs keys, data177 docs_to_import = []178 indexed_snap_queries = @snapshot.snapshot_queries179 .where(query_id: keys)180 .all181 .index_by { |q| q.query_id.to_s }182 print_step 'Importing docs'183 block_with_progress_bar(keys.length) do |i|184 query_id = keys[i]185 docs = data[keys[i]]186 snapshot_query = indexed_snap_queries[query_id.to_s]187 query_docs = setup_docs_for_query snapshot_query, docs188 docs_to_import += query_docs189 end190 SnapshotDoc.import docs_to_import191 self192 end193 def fetch_or_create_query indexed_queries, query_text194 if indexed_queries[query_text].present?195 indexed_queries[query_text]196 else197 query_params = {198 query_text: query_text,199 case_id: @snapshot.case_id,200 }201 Query.create(query_params)202 end203 end204end205# rubocop:enable Metrics/ClassLength...

Full Screen

Full Screen

ratings_importer.rb

Source:ratings_importer.rb Github

copy

Full Screen

...39 #40 # 2 ways to import ratings:41 # i. The naive way:42 # a. Loop through each row43 # b. Create or fetch the query based on the query text (cache the query)44 # c. Create or update the rating45 # ii. The less naive way, which we are using:46 # a. Map from the rows all the unique queries47 # b. Fetch all the existing queries48 # c. Determine which queries do not already exist49 # d. Create remaining queries in bulk50 # e. Updating existing ratings if needed51 # f. Create remaining ratings in mass52 #53 # a. Map from the rows all the unique queries54 normalized_rows = @ratings.map { |row| extract_rating_info row }55 query_texts = normalized_rows.pluck(:query_text)56 unique_queries = query_texts.uniq57 # b. Fetch all the existing queries58 queries_params = {59 query_text: unique_queries,60 case_id: @acase.id,61 }62 indexed_queries = Query.where(queries_params)63 .all64 .index_by(&:query_text)65 # c. Determine which queries do not already exist66 existing_queries = indexed_queries.keys67 non_existing_queries = unique_queries - existing_queries68 if non_existing_queries.empty?69 @queries = indexed_queries70 else71 # d. Create remaining queries in bulk72 queries_to_import = []73 print_step 'Importing queries'74 block_with_progress_bar(non_existing_queries.length) do |i|75 query_text = non_existing_queries[i]76 query = Query.new query_text: query_text, case_id: @acase.id77 queries_to_import << query78 end79 # Mass insert queries80 Query.import queries_to_import81 # Refetch the queries now that we've created new ones82 queries_params = {83 query_text: unique_queries,84 case_id: @acase.id,85 }86 @queries = Query.where(queries_params)87 .all88 .index_by(&:query_text)89 end90 # e. Create or update ratings91 ratings_to_import = []92 ratings_to_update = []93 print_step 'Importing ratings'94 block_with_progress_bar(normalized_rows.length) do |i|95 row = normalized_rows[i]96 query_text = row[:query_text]97 doc_id = row[:doc_id]98 rating = row[:rating]99 if doc_id.present? && rating.present? # queries are always created.100 print_step "Importing rating: #{rating} for query: #{query_text} and doc: #{doc_id}"101 query = @queries[query_text]102 exists = query.ratings.where(doc_id: doc_id).first103 if exists.present? && @options[:force]104 exists.rating = rating105 ratings_to_update << exists106 elsif exists.blank?107 ratings_to_import << query.ratings.build(doc_id: doc_id, rating: rating)108 end109 end110 end111 # Mass update ratings112 ActiveRecord::Base.transaction do113 ratings_to_update.each(&:save)114 end115 # Mass insert ratings116 Rating.import ratings_to_import117 return unless @options[:clear_existing]118 print_step 'Clearing unused queries'119 @acase.queries.each do |query|120 query.destroy if @queries[query.query_text].blank?121 end122 end123 # rubocop:enable Metrics/PerceivedComplexity124 # rubocop:enable Metrics/AbcSize125 # rubocop:enable Metrics/MethodLength126 # rubocop:enable Metrics/CyclomaticComplexity127 private128 # rubocop:disable Metrics/MethodLength129 def extract_rating_info row130 case @options[:format]131 when :csv132 {133 query_text: row[0].is_a?(String) ? row[0].strip : row[0],134 doc_id: row[1].is_a?(String) ? row[1].strip : row[1],135 rating: row[2].is_a?(String) ? row[2].strip : row[2],136 }137 when :hash138 row.deep_symbolize_keys139 row.each do |k, v|140 row[k] = v.strip if v.is_a?(String)141 end142 row143 else144 row145 end146 end147 # rubocop:enable Metrics/MethodLength...

Full Screen

Full Screen

text

Using AI Code Generation

copy

Full Screen

1 def text(query)2 @query.text(query)3query.text('hello')4 def text(query)5query.text('hello')

Full Screen

Full Screen

text

Using AI Code Generation

copy

Full Screen

1 def text(query)2 @query.text(query)3query.text('hello')4 def text(query)5query.text('hello')

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful