Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spree 2.1] Fix creation of enterprises/users in specs #4821

Merged
merged 3 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/api/enterprise_attachment_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'api/admin/enterprise_serializer'

module Api
class EnterpriseAttachmentController < BaseController
class MissingImplementationError < StandardError; end
Expand Down
4 changes: 2 additions & 2 deletions app/models/enterprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class Enterprise < ActiveRecord::Base
validate :enforce_ownership_limit, if: lambda { owner_id_changed? && !owner_id.nil? }

before_validation :initialize_permalink, if: lambda { permalink.nil? }
before_validation :ensure_owner_is_manager, if: lambda { owner_id_changed? && !owner_id.nil? }
before_validation :set_unused_address_fields
after_validation :geocode_address
after_validation :ensure_owner_is_manager, if: lambda { owner_id_changed? && !owner_id.nil? }

after_touch :touch_distributors
after_create :set_default_contact
Expand Down Expand Up @@ -410,7 +410,7 @@ def geocode_address
end

def ensure_owner_is_manager
#users << owner unless users.include?(owner)
users << owner unless users.include?(owner)
end

def enforce_ownership_limit
Expand Down
13 changes: 13 additions & 0 deletions spec/factories/enterprise_factory.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
FactoryBot.define do
factory :enterprise, class: Enterprise do
transient do
users []
logo {}
promo_image {}
end

owner { FactoryBot.create :user }
sequence(:name) { |n| "Enterprise #{n}" }
sells 'any'
description 'enterprise'
long_description '<p>Hello, world!</p><p>This is a paragraph.</p>'
address { FactoryBot.create(:address) }

after(:create) do |enterprise, proxy|
proxy.users.each do |user|
enterprise.users << user unless enterprise.users.include?(user)
end
enterprise.update_attributes logo: proxy.logo, promo_image: proxy.promo_image
end
end

factory :supplier_enterprise, parent: :enterprise do
Expand Down
8 changes: 7 additions & 1 deletion spec/factories/user_factory.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
FactoryBot.modify do
factory :user do
transient do
enterprises []
end

confirmation_sent_at '1970-01-01 00:00:00'
confirmed_at '1970-01-01 00:00:01'

Expand All @@ -13,8 +17,10 @@
end
end

after(:create) do |user|
after(:create) do |user, proxy|
user.spree_roles.clear # Remove admin role

user.enterprises << proxy.enterprises
end
end

Expand Down