Skip to content

Instantly share code, notes, and snippets.

@halsk
Created April 16, 2014 15:16
Show Gist options
  • Save halsk/10892466 to your computer and use it in GitHub Desktop.
Save halsk/10892466 to your computer and use it in GitHub Desktop.
テストデータジェネレータに Fabrication-gem を使う ref: http://qiita.com/hal_sk/items/e301259c8c49f5266699
group :test do
gem 'fabrication' #追加
end
class User
include Mongoid::Document
validates_presence_of :name
field :name, :type => String
field :email, :type => String, :default => ""
field :password, :type => String, :default => ""
embeds_many :user_accounts
end
class UserAccount
include Mongoid::Document
field :provider, :type => String
field :uid, :type => String
field :token, :type => String
field :auth_response, :type => String
FACEBOOK = 'facebook'.freeze
TWITTER = 'twitter'.freeze
embeded_in :user, :class_name => "User"
end
require 'spec_helper'
describe UserAccount do
describe '.all' do
before do
Fabricate(:user)
#FactoryGirl.create(:user_account, user: user)
end
subject { User.find(1) }
it { should have(1).user_accounts }
end
end
Fabricator(:user) do
id 1
name 'user'
email 'hal@test.co.jp'
password 'password'
user_accounts(count:1){|attr, i| Fabricate(:user_account) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment