mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Fixed problem when name of the trait was not a symbol
This commit is contained in:
parent
f46fe8f238
commit
f4ad4f0c87
3 changed files with 18 additions and 2 deletions
|
@ -5,7 +5,7 @@ module FactoryBot
|
|||
@strategy = strategy
|
||||
|
||||
@overrides = traits_and_overrides.extract_options!
|
||||
@traits = traits_and_overrides
|
||||
@traits = traits_and_overrides.map(&:to_sym)
|
||||
end
|
||||
|
||||
def run(runner_strategy = @strategy, &block)
|
||||
|
|
|
@ -4,7 +4,7 @@ module FactoryBot
|
|||
attr_reader :name, :definition
|
||||
|
||||
def initialize(name, &block)
|
||||
@name = name
|
||||
@name = name.to_sym
|
||||
@block = block
|
||||
@definition = Definition.new(@name)
|
||||
|
||||
|
|
|
@ -24,6 +24,10 @@ describe "an instance generated by a factory with multiple traits" do
|
|||
admin { true }
|
||||
end
|
||||
|
||||
trait "admin_string" do
|
||||
admin true
|
||||
end
|
||||
|
||||
trait :admin_trait do
|
||||
admin { true }
|
||||
end
|
||||
|
@ -165,6 +169,18 @@ describe "an instance generated by a factory with multiple traits" do
|
|||
its(:date_of_birth) { should eq Date.parse("1/1/2000") }
|
||||
end
|
||||
|
||||
context "when trait is defined as string" do
|
||||
context "when is called as symbol" do
|
||||
subject { FactoryBot.create(:user, :admin_string) }
|
||||
its(:admin) { should be_truthy }
|
||||
end
|
||||
|
||||
context "when is called as string" do
|
||||
subject { FactoryBot.create(:user, "admin_string") }
|
||||
its(:admin) { should be_truthy }
|
||||
end
|
||||
end
|
||||
|
||||
context "factory outside of scope" do
|
||||
subject { FactoryBot.create(:user_without_admin_scoping) }
|
||||
it { expect { subject }.to raise_error(ArgumentError, "Trait not registered: admin_trait") }
|
||||
|
|
Loading…
Reference in a new issue