Equivalent scrapbook

…note on Factory girl

FactoryGirl trait

    factory :client do
      sequence(:name) { |n| "Client #{n}"}

      trait :foobar do
        name 'Foo Bar'
      end

      trait :with_registries do
        registry_ids { [FactoryGirl.create(:registry ).id] }
      end

      trait :owned_by_some_user do
        association :owner, factory: [:user, with_another_trait]
      end
    end














------------------------------------------------------

get valid_attributes without not accessable ones

http://stackoverflow.com/questions/5103572/factorygirl-attributes-for-not-giving-me-associated-attributes

(FactoryGirl.build :contact).attributes.symbolize_keys.reject { |key, value| !Contact.attr_accessible[:default].collect { |attribute| attribute.to_sym }.include?(key) }

------------------------------------------------------






describe 'something' do
  let(:tomas) { Factory.create :person }

  before :each do
    tomas.do_somethisg
  end

end



https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md



FactoryGirl.define do
  factory :facebook_platform, :class => Platform::Facebook do
    association :person, :factory => :person #it will create association object if the 'has_many' & 'belongs_to' is set propperly
    platform_identifier '123'
  end
end



http://robots.thoughtbot.com/post/254496652/aint-no-calla-back-girl

Factory.define :article_with_comment, :parent => :article do |article|
  article.after_create { |a| Factory(:comment, :article => a) }
end