Sha256: 1e3cefcce5cac2230a1e8a48eec7b2dec9ed543221adbe3f5d846f26c79930e2

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe 'Factory' do
  context 'basic factory functionality' do
    before do
      Falcor::Fabricator.define :blog_post do
        field :title, "My post"
        field :body, "Lots of text"
      end
    end

    it 'can create a basic factory with default attributes' do
      post = Factory :blog_post
      expect(post.title).to eq "My post"
      expect(post.body).to eq "Lots of text"
    end

    it 'generates the expected hash for JSON' do
      post = Factory :blog_post
      expect(post.to_json).to eq({ "title" => "My post", "body" => "Lots of text" })
    end

    it 'allows attributes to be overridden' do
      post = Factory :blog_post, title: "My super sweet post"
      expect(post.title).to eq "My super sweet post"
    end
  end

  context 'factory associations' do
    before do
      Falcor::Fabricator.define :author do
        field :username, "matt@example.com"
        field :password, "password"
      end

      Falcor::Fabricator.define :blog_post do
        field :title, "My post"
        field :body, "Lots of text"
        association :author
      end
    end

    it 'can create associations that default to the factory named by the attribute' do
      post = Factory :blog_post
      expect(post.author.username).to eq "matt@example.com"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
falcor-0.0.3 spec/factory_spec.rb
falcor-0.0.2 spec/factory_spec.rb