Created
April 16, 2014 15:16
-
-
Save halsk/10892466 to your computer and use it in GitHub Desktop.
テストデータジェネレータに Fabrication-gem を使う ref: http://qiita.com/hal_sk/items/e301259c8c49f5266699
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| group :test do | |
| gem 'fabrication' #追加 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Fabricator(:user) do | |
| id 1 | |
| name 'user' | |
| email '[email protected]' | |
| 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