1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

Clean up attributes_for spec

This commit is contained in:
Joshua Clayton 2011-12-16 13:36:31 -05:00
parent 43e085ac24
commit e2f663358a
2 changed files with 8 additions and 26 deletions

View file

@ -1,30 +1,18 @@
require 'spec_helper'
describe FactoryGirl::Proxy::AttributesFor do
let(:proxy_class) { stub("proxy_class") }
subject { FactoryGirl::Proxy::AttributesFor.new(proxy_class) }
let(:result) { { :name => "John Doe", :gender => "Male", :admin => false } }
let(:attribute_assigner) { stub("attribute assigner", :hash => result) }
it_should_behave_like "proxy without association support"
it "returns a hash when asked for the result" do
subject.result(nil).should be_kind_of(Hash)
it "returns the hash from the attribute assigner" do
subject.result(attribute_assigner, lambda {|item| item }).should == result
end
it "does not instantiate the proxy class" do
proxy_class.stubs(:new)
subject.result(nil)
proxy_class.should have_received(:new).never
end
describe "after setting an attribute" do
let(:attribute) { stub("attribute", :name => :attribute, :to_proc => lambda { "value" }, :ignored => false) }
before { subject.set(attribute) }
it "sets that value in the resulting hash" do
subject.result(nil)[:attribute].should == "value"
end
it "does not run the to_create block" do
expect do
subject.result(attribute_assigner, lambda {|item| raise "failed" })
end.to_not raise_error
end
end

View file

@ -1,12 +1,6 @@
shared_examples_for "proxy without association support" do
let(:attribute) { FactoryGirl::Attribute::Association.new(:user, :user, {}) }
it "does not call FactoryGirl.create when building an association" do
FactoryGirl.stubs(:create)
subject.set(attribute)
FactoryGirl.should have_received(:create).never
end
it "returns nil when accessing an association" do
subject.association(:user, {}).should be_nil
end