Skip to content

Commit

Permalink
Fix admin user factory
Browse files Browse the repository at this point in the history
To avoid persistence and validation issues has_many associations
must be added after creation.
  • Loading branch information
filippoliverani committed Feb 25, 2020
1 parent a022e6e commit e69db04
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion core/lib/spree/testing_support/factories/user_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
end

factory :admin_user do
spree_roles { [Spree::Role.find_by(name: 'admin') || create(:role, name: 'admin')] }
after(:create) do |user, _|
admin_role = Spree::Role.find_by(name: 'admin') || create(:role, name: 'admin')
user.spree_roles << admin_role
end
end

factory :user_with_addresses do |_u|
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def initialize(_user)
let(:resource) { Object.new }

context 'with admin user' do
let(:user) { build :admin_user }
let(:user) { create :admin_user }
it_should_behave_like 'access granted'
it_should_behave_like 'index allowed'
end
Expand Down

0 comments on commit e69db04

Please sign in to comment.