Specflow: How to generate a unique string by ValueRetriever and store it for the current Scenario, without any issue in parallel execution - bdd

to make test data unique for correctly selecting in tests. I'm looking for solution to generate a unique string and replace it to the "(*)" in Feature file. The generated unique string should be remained to the end of the Scenario, and it's safe when tests are executed parallelly (each Scenario should hold its own unique string).
I currently generate the unique string by create a custom class UniqueStringRetriever : IValueRetriever but duno how to register it to avoid parallel execution problem.
Does anyone have idea for this situation please leave your help in here. I do appreciate that.
Background:
Given the following Customer
| First Name | Last Name |
| David (*) | Brown |
Scenario: Search Customer by First Name
When user search Customer by First Name
| First Name |
| David (*) |
Then the result list displays 'David (*)' customer

Related

Is it better to scan a table, or to create just one hash key?

I'm developing iOS app, using Swift, and I need to be able to get the posts based on how close they are to a certain location, and sort them based on when they were posted.
I know how to check how close one item's post location is to another location, but, my problem is that I need to get all of the posts within a x miles of the user.
Would it be better to scan the table, which as I understand, selects every single value from the database, and then check if every item returned is within x miles of the user? This seems resource-intensive, as I'm expecting for there to be a lot of posts.
Or, would it be better to create another table that has a static hash key, and set two local secondary indexes, one for the latitude, and one for the longitude, and just query for that one static hash key, and query where the latitude is between x and y, and the longitude is between a and b?
The AWS DynamoDB documentation warns against using a hash key that is accessed too much:
But is it really as bad as they make it seem to use the same hash key?
This would be in a table with the following values for a static hash key, where Post ID is the ID of the actual post.
**static hash key** | **latitude (local secondary index)** | **longitude (local secondary index)** | **dateCreated (local secondary index) | **Post ID**
and for the scan option:
**ID** | **latitude ** | **longitude ** | **date created ** | **poster** | **comments** | **flags** | **upvotes** | **downvotes** | **popularity**
Would having a static key be better than scanning a table performance-wise? How about cost-wise?
Follow the guidelines. We are suffering from two problems in production because of bad hashes. So my advice to you is to drop the static hash concept. It won't scale at a reasonable price, and will be a pain to monitor.
Building on top of the scan approach, you can reason about using Global Secondary Indices on the lat/lang attributes.

Rails - Associating database/models with Modules that aren't database tables

I want to create "associations" (or an equivalent concept with similar methods available from having associations). It is with this table of information, that does NOT need to be updated wahtsoever with other tables that DO involve CRUD.
This is my non-updated table of information:
Table name: Personalities
personality_type | alternate_name | CF1 | CF2 | CF3 | CF4 | CF5 | CF6 | CF7 | CF8
----------------------------------------------------------------------------------
ENTj | ENTJ | Te | Ni | Se | Fi | etc | etc | |
INTp | INTJ | (more data values)
ISFj | ISFP | (more data values)
ESFp | ESFP | (more data values)
So it seems to me that making this non-updated into a database table and performing queries on it would be a silly and pointless way of designing my code, since that would entail all of the query loading time overhead.
So I was thinking of something like making a separate Ruby module, but wasn't sure how to "associate" it with other tables that would be full-fledged database tables with models.
1) How do I associate a non-database class instance based on ActiveRecords::Base with one?
2) Which format/data type should I put my non-updated table of information in? class, module, multiple class instances, a 2 dimensional array, or 2 dimensional hash?
My goal in sorting out this decision is to be able to use the similar method notations that comes with associating database models. (e.g. two tables called "Personality" and "User" would allow Rails/Ruby code like #user.alternate_name. and #personality.user.email).
3) Does the fact that rails uses hidden :id, and timestamp columns affect this in any way?
(If this question is a bit broad, feel free to ignore answering it).
Much thanks!
-A user can have only one personality type.
-Other database models need to refer to personality type information independent of the user model.
Presumably only the User model can have a personality type. Why not create an array of these types as a constant in the User model, which you can then refer to in forms etc for selection using User::PERSONALITY_TYPES.
For example:
class User
PERSONALITY_TYPES = %w{ ENTJ INTJ ISFP ESFP }
# ... other model code
end
Then simply store the index of the personality type within the array as the user's personality_type_index.
Perhaps I'm oversimplifying your needs, but this is the approach I would start with.

Return only results based on current object for dynamic menus

If I have an object that has_many - how would I go about getting back only the results that are related to the original results related ids?
Example:
tier_tbl
| id | name
1 low
2 med
3 high
randomdata_tbl
| id | tier_id | name
1 1 xxx
2 1 yyy
3 2 zzz
I would like to build a query that returns only, in the case of the above example, rows 1 and 2 from tier_tbl, because only 1 and 2 exist in the tier_id data.
Im new to activerecord, and without a loop, don't know a good way of doing this. Does rails allow for this kind of query building in an easier way?
The reasoning behind this is so that I can list only menu items that relate to the specific object I am dealing with. If the object i am dealing with has only the items contained in randomdata_tbl, there is no reason to display the 3rd tier name. So i'd like to omit it completely. I need to go this direction because of the way the models are set up. The example im dealing with is slightly more complicated.
Thanks
Lets call your first table tiers and second table randoms
If tier has many randoms and you want to find all tiers whoes id present in table randoms, you can do it that way:
# database query only
Tier.joins(:randoms).uniq
or
# with some ruby code
Tier.select{ |t| t.randoms.any? }

Getting the most recent record for each unique user in Parse using PFQuery

I'm using Parse.com, and have two classes: User and Report. A User may issue several reports during a day, but I'm only interested in the most recent one. However, I need to get all the reports that meet specific criteria, but only the most recent one.
The end result is an array of Reports, where the User is unique on each one, something like this:
ObjectId | ReportedValue | User | CreatedAt
1234 | 100 | aaaa | 2013-05-20T04:23:41.907Z
1235 | 100 | bbbb | 2013-04-29T05:10:41.907Z
1236 | 100 | cccc | 2013-05-20T02:14:41.907Z
1237 | 100 | dddd | 2013-05-19T04:03:41.907Z
So, User aaaa might have 20 reports, but I only need the most recent, for each user. However, I'm searching based on the ReportedValue being 100, and the desired result is the report objects, not the user, so I'd prefer not to go through every user.
Is this possible in Parse?
Consider using another object in the data model to assist with this. It would basically be a container with a relationship to Report. When any new report is saved, a bit of cloud code runs which:
Finds the previous latest Report for the associated user
Removes that report from the container relation
Adds the new report to the container relation
Working this way, your app can make a single, simple, query on the relation to get all of the latest Reports.
From Rest API.... works providing the user's OID is in the ACL segment in the records in the Class you are querying.
in addition to the other predicate of your query, parse can limit the number of returned rows..
--data-urlencode 'limit=1' \
--data-urlencode 'skip=0' \
For the user, if you GET the row from user table for the user you are querying
and the 'token' field value for that user and then with your report query, Set an extra header to the sessionToken value you will get ONLY THAT User's report objects.
-H "X-Parse-Session-Token: pn..." \
you will get just that user's reports
AND
results.size = 1

How can I test a view of product detail information in Cucumber?

I have an application with a product detail page. On that page the user can see prices, descriptions, specifications, all pretty standard stuff. But I want to test this view in Cucumber.
Right now I use factories to generate product identifiers and leave everything else blank. If I add defaults to the factories, then check for those same defaults in the features, then I've tightly coupled those two components (bad).
Is the only real way to do this to supply all of the values I'm testing for in the feature file itself?
Cucumber tables are a good way to handle this, and it's simple to tie them into your factories. I'm assuming that you're using FactoryGirl, but it matters little.
Scenario: I want to see some product details
Given the following product data
| name | price | description |
| Foo | 1.99 | Yay, it's foo |
| Bar | 4.99 | Yay, it's bar |
Then somewhere in your step definitions you'll want to tie this into your factory.
Given /^the following product data$/ do |table|
table.hashes.each do |hash|
Factory.create(:product, hash)
end
end
Note that the 'magic' here comes from naming the table columns in the feature the same as your db columns, which become the keys in hash.

Resources