Sha256: 2bf311bcb634f24fd94a9eb713b36a5329082b61ec3afd905caafaaba409127b

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'spec_helper'
require 'acceptance/acceptance_helper'

describe "a generated attributes hash" do
  include FactoryGirl::Syntax::Methods

  before do
    define_model('User')

    define_model('Post', :title   => :string,
                         :body    => :string,
                         :summary => :string,
                         :user_id => :integer) do
      belongs_to :user
    end

    FactoryGirl.define do
      factory :user do
      end

      factory :post do
        title { "default title" }
        body { "default body" }
        summary { title }
        user
        uploaded_image(nil).ignore
      end
    end
  end

  subject { attributes_for(:post, :title => 'overridden title', :uploaded_image => "foo") }

  it "assigns an overridden value" do
    subject[:title].should == "overridden title"
  end

  it "assigns a default value" do
    subject[:body].should == "default body"
  end

  it "assigns a lazy, dependent attribute" do
    subject[:summary].should == "overridden title"
  end

  it "doesn't assign associations" do
    subject[:user_id].should be_nil
  end

  it "doesn't assign ignored attributes" do
    subject[:uploaded_image].should be_nil
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
factory_girl_kibiz0r-2.0.0.beta3 spec/acceptance/attributes_for_spec.rb