Factory Girl Why does it create two records for every one requested? - factory-bot

Using:
factory_girl-2.6.4
cucumber-1.2.1
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
Rails 3.0.15
FactoryGirl.define do
factory :user do
email {Factory.next(:email)}
password 'test123'
end
factory :participant do
factory :person do
sequence(:name) {|n| Faker::Name.last_name + " #{n}" }
sequence(:other_names) { |n| Faker::Name.first_name }
type Participant::PERSON_TYPE
end
factory :organisation do
sequence(:name) {|n| Faker::Company.name + " #{n} Pty Ltd" }
type Participant::ORGANISATION_TYPE
sequence(:abn) {|n| "56 122 456 78#{n}" }
end
end
factory :client do
association :participant, :factory=>:organisation #, :name=> Faker::Name.name + ' Client'
role_type { RoleType.where(:id => RoleType::CLIENT_ID).first }
type Role::CLIENT_TYPE
sequence(:email) {|n| Faker::Internet::user_name + ".client#{n}#mailinator.com" }
std_account { Faker::PhoneNumber.phone_number[0,20] }
commenced_on { rand(60).days.ago }
end
In Cucumber
Feature: test the construction of a factories
Background: Because factories also need to be tested
Given a client exists # factory_girl-2.6.4/lib/factory_girl/step_definitions.rb:107
And Show Roles # features/step_definitions/sign_in.rb:19
This produces 2 organisation (which is a participant) & 2 clients as follows:
"-------- Roles & Organisations -------"
[#<Client id: 2, participant_id: 2, user_id: nil, role_type_id: 5, type: "Client", std_account: "(989)416-2268", email: "amani.aufderhar.client1#mailinator.com", url: nil, phone: nil, mobile: nil, fax: nil, commenced_on: "2012-05-14", expired_on: nil, created_at: "2012-06-23 03:27:43", updated_at: "2012-06-23 03:27:43", lock_version: 0>,
#<Client id: 3, participant_id: 3, user_id: nil, role_type_id: 5, type: "Client", std_account: "301.424.0762 x123", email: "brennan.client2#mailinator.com", url: nil, phone: nil, mobile: nil, fax: nil, commenced_on: "2012-05-28", expired_on: nil, created_at: "2012-06-23 03:27:43", updated_at: "2012-06-23 03:27:43", lock_version: 0>]
[#<Organisation id: 2, name: "Lowe, Lesch and Swift 1 Pty Ltd", type: "Organisation", other_names: nil, preferred_name: nil, salutation_id: nil, abn: "56 122 456 781", expired_on: nil, created_at: "2012-06-23 03:27:42", updated_at: "2012-06-23 03:27:42", lock_version: 0>,
#<Organisation id: 3, name: "Deckow, Strosin and Schiller 2 Pty Ltd", type: "Organisation", other_names: nil, preferred_name: nil, salutation_id: nil, abn: "56 122 456 782", expired_on: nil, created_at: "2012-06-23 03:27:43", updated_at: "2012-06-23 03:27:43", lock_version: 0>]
Can any shed some light on this for me please - there should be exactly one of each as I understand it.
Ross

Updated factory_girl to latest version.Problem went away.

Related

Unable to query many to many relationship as mentioned in amplify datastore docs

I am facing error while getting data from many to many relationship in amplify datastore. It was working fine but suddenly it was sending error. Below are my tables models
type Company
#model
#auth(rules: [{ allow: owner }, { allow: groups, groupsField: "invites" }]) {
id: ID!
name: String
users: [UserCompany] #connection(keyName: "byCompany", fields: ["id"])
}
type UserCompany
#model
#key(name: "byOwner", fields: ["owner"])
#key(name: "byUser", fields: ["userID", "companyID"])
#key(name: "byCompany", fields: ["companyID", "userID"])
#auth(
rules: [{ allow: owner }, { allow: groups, groupsField: "accessors" }]
) {
id: ID!
userID: ID
companyID: ID
user: User! #connection(fields: ["userID"])
company: Company! #connection(fields: ["companyID"])
owner: String
accessors: [String]
}
type User
#model
#aws_api_key
#aws_cognito_user_pools
#auth(
rules: [
{ allow: owner }
{ allow: groups, groupsField: "user_group" }
{ allow: groups, groupsField: "tenant_group" }
]
) {
id: ID!
company_name: String
company_address: String
contact_name: String
profile_image: String
email: String
phone: String
UserCompanys: [UserCompany]
#connection(keyName: "byUser", fields: ["id"])
owner: String
tenant_group: [String]
user_group: String
};
I was getting UserCompany like this
this.users = (await DataStore.query(UserCompany)).filter( (item) => item.user.id === id );
and it was working fine
but from last Friday suddenly I am facing this error.
Error: Field user is required
at datastore.js:219
at datastore.js:276
at Array.forEach ()
at initializeInstance (datastore.js:274)
at datastore.js:284
at e.i.produce (immer.esm.js:1)
at new UserCompany (datastore.js:283)
at IndexedDBAdapter.modelInstanceCreator (datastore.js:211)
at IndexedDBAdapter.js:516
at Array.map ()
at resolvePromise (zone-evergreen.js:798)
at zone-evergreen.js:705
at rejected (tslib.es6.js:74)
at ZoneDelegate.invoke (zone-evergreen.js:364)
at Object.onInvoke (core.js:28513)
at ZoneDelegate.invoke (zone-evergreen.js:363)
at Zone.run (zone-evergreen.js:123)
at zone-evergreen.js:857
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Object.onInvokeTask (core.js:28500)
After this error system is unable to run other functions.
Is there anyway to get pivot table data of many to many relationship using Datastore.

How do I query MongoDB collection based on related documents (in Doctrine)

I have a few related collections in my Doctrine ODM project…
# Contract.mongodb.yml
Project\Contract\Domain\Contract:
type: document
repositoryClass: Project\SymfonyBundle\ContractBundle\Repository\ContractRepository
collection: Contracts
fields:
id:
type: id
id: true
strategy: UUID
slug:
type: string
length: 128
unique: true
gedmo:
slug:
separator: -
style: default
fields:
- refNo
- name
name:
type: string
refNo:
type: string
purpose:
type: string
budgetAmount:
type: int
budgetCurrency:
type: string
length: 3
startDate:
type: date_immutable
endDate:
type: date_immutable
provider:
type: string
referenceOne:
provider:
targetDocument: Project\Contract\Domain\Provider
cascade:
- persist
- merge
- detach
- refresh
referenceMany:
reports:
targetDocument: Project\Report\Domain\Report
cascade:
- all
# Provider.mongodb.yml
Project\Contract\Domain\Provider:
type: document
repositoryClass: Project\SymfonyBundle\ContractBundle\Repository\ProviderRepository
collection: Providers
fields:
id:
type: id
id: true
strategy: UUID
slug:
type: string
length: 128
unique: true
gedmo:
slug:
separator: -
style: default
fields:
- name
name:
type: string
unique: true
referenceMany:
users:
targetDocument: Project\User\Domain\User
cascade: []
# User.mongodb.yml
Project\User\Domain\User:
type: document
repositoryClass: Project\SymfonyBundle\UserBundle\Repository\UserRepository
collection: Users
fields:
id:
type: id
id: true
strategy: UUID
What I want to do is get the contracts for a given user, but I can't work out how to query the Contracts collection based on a user. Do I need to make 2 queries? 1 to get the user's providers & then a second to query for contracts that link to one of the providers?
If you're able to advise how I do this in the console as well as Doctrine, I'd appreciate the knowledge.
Thanks in advance for your help :o)
You can use the aggregation pipeline and use the $lookup operator to join the document, See - https://docs.mongodb.com/v3.2/reference/operator/aggregation/lookup/
However if this is common, I'd consider re-modeling your documents.

Meteor, facebook login, different values returned : what about the profile picture?

On a meteor app, when a log in with facebook on localhost, I obtain those fields for theuser.services.facebook:
{
accessToken: 'long_acces_tkoen_string',
expiresAt: --,
id: '--',
email: '--',
name: '--',
first_name: '--',
last_name: '--',
link: 'https://www.facebook.com/--',
username: '--',
gender: '--',
locale: '--'
}
When I deploy my app on https://modulus.io/, these fields are returned :
{
accessToken: '--',
expiresAt: --,
id: '--',
email: '--',
name: '--',
first_name: '--',
last_name: '--',
link: 'https://www.facebook.com/app_scoped_user_id/--/',
gender: '--',
locale: '--'
}
No userneame, so, no profile picture that I used to build like that : 'https://graph.facebook.com/' + user.services.facebook.username + '/picture?width=100&height=100'
How do I rebuild that ?
I understand that this is probably caused by this : https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api
But I do not understand why (and why does it work on localhost and not on modulus)
Well, actually, you can simply use the id field. I never noticed that.
But users have a new id. For instance, for me, these thre urls are working :
// old id field :
https://graph.facebook.com/558820281/picture?width=200&height=200
// old username field :
https://graph.facebook.com/huet.fabien/picture?width=200&height=200
// new id field
https://graph.facebook.com/10154176840535282/picture?width=200&height=200

Rspec is not working properly with mongodb

I have the following user class
class User
include MongoMapper::Document
key :email, String, :unique => true
end
and my rspec code
before do
#user = FactoryGirl.create(:user)
end
describe "when email address is already taken" do
before do
user_with_same_email = #user.dup
user_with_same_email.email = #user.email
user_with_same_email.save
end
it { should_not be_valid }
end
raises the following error
1) User when email address is already taken
Failure/Error: it { should_not be_valid }
expected #<User _id: BSON::ObjectId('5236bec5ebe8660fcb00001a'), accepted_tender_ids: [], avatar: #<Avatar _id: BSON::ObjectId('5236bec3ebe8660fcb000001'), digest: "c7358a60a79905a7d4e3383ba905f1baaab278b06a6f751971344cb91763068f", image: "c7358a60a79905a7d4e3383ba905f1baaab278b06a6f751971344cb91763068f">, busy: false, completed_count: 0, completed_tender_ids: [], confirmed: true, dialogs: [], dislikes: 0, email: "maurice_langworth#treutel.com", role: "customer", subspecializations: [], type: "personal"> not to be valid
Expected user is not valid but it is valid
user_with_same_email will fail to save, so there will not be a second user in the database with your email; assuming that subject is #user, there will be no conflict and the user will be valid.
Did you forget to define subject as user_with_same_email?

Ember.Select default option

How do I set the default option for a select box when the page loads? I've tried setting the default value for the selectedPersonController in the example below but to no avail. Am I doing something wrong?
var App = Ember.Application.create();
App.Person = Ember.Object.extend({
id: null,
firstName: null,
lastName: null,
fullName: function() {
return this.get('firstName') + " " + this.get('lastName');
}.property('firstName', 'lastName').cacheable()
});
App.selectedPersonController = Ember.Object.create({
person: null
});
App.peopleController = Ember.ArrayController.create({
content: [
App.Person.create({id: 1, firstName: 'Yehuda', lastName: 'Katz'}),
App.Person.create({id: 2, firstName: 'Tom', lastName: 'Dale'}),
App.Person.create({id: 3, firstName: 'Peter', lastName: 'Wagenet'}),
App.Person.create({id: 4, firstName: 'Erik', lastName: 'Bryn'})
]
});
Template:
{{view Ember.Select
contentBinding="App.peopleController"
selectionBinding="App.selectedPersonController.person"
optionLabelPath="content.fullName"
optionValuePath="content.id"}}
You don't set a specific person on your App.selectedPersonController. See a working example here: http://jsfiddle.net/ZpTYV/
// set a default selected person
App.selectedPersonController.set('person', App.peopleController.objectAt(1));
I don't know if this is a typo in your example, but you also have to declare App globally, so it can be accessed in the Handlebars template.