diff --git a/api/app/models/spree/webhooks/subscriber.rb b/api/app/models/spree/webhooks/subscriber.rb index 2f5f728f23c..31c10731256 100644 --- a/api/app/models/spree/webhooks/subscriber.rb +++ b/api/app/models/spree/webhooks/subscriber.rb @@ -3,7 +3,31 @@ module Webhooks class Subscriber < Spree::Webhooks::Base validates :url, 'spree/url': true, presence: true + validate :check_uri_path + scope :active, -> { where(active: true) } + + def self.urls_for(event) + where_condition = case ActiveRecord::Base.connection.adapter_name + when 'Mysql2' + ["('*' MEMBER OF(subscriptions) OR ? MEMBER OF(subscriptions))", event] + when 'PostgreSQL' + ["subscriptions @> '[\"*\"]' OR subscriptions @> ?", [event].to_json] + end + where(where_condition).pluck(:url) + end + + private + + def check_uri_path + uri = begin + URI.parse(url) + rescue URI::InvalidURIError + return false + end + + errors.add(:url, 'the URL must have a path') if uri.blank? || uri.path.blank? + end end end end diff --git a/api/app/serializers/spree/api/v2/platform/asset_serializer.rb b/api/app/serializers/spree/api/v2/platform/asset_serializer.rb new file mode 100644 index 00000000000..e1f9b931ee5 --- /dev/null +++ b/api/app/serializers/spree/api/v2/platform/asset_serializer.rb @@ -0,0 +1,13 @@ +module Spree + module Api + module V2 + module Platform + class AssetSerializer < BaseSerializer + include ResourceSerializerConcern + + belongs_to :viewable, polymorphic: true + end + end + end + end +end diff --git a/api/app/serializers/spree/api/v2/platform/property_serializer.rb b/api/app/serializers/spree/api/v2/platform/property_serializer.rb new file mode 100644 index 00000000000..ebf9767a77b --- /dev/null +++ b/api/app/serializers/spree/api/v2/platform/property_serializer.rb @@ -0,0 +1,11 @@ +module Spree + module Api + module V2 + module Platform + class PropertySerializer < BaseSerializer + include ResourceSerializerConcern + end + end + end + end +end diff --git a/api/app/serializers/spree/api/v2/platform/prototype_serializer.rb b/api/app/serializers/spree/api/v2/platform/prototype_serializer.rb new file mode 100644 index 00000000000..3fef1158d07 --- /dev/null +++ b/api/app/serializers/spree/api/v2/platform/prototype_serializer.rb @@ -0,0 +1,15 @@ +module Spree + module Api + module V2 + module Platform + class PrototypeSerializer < BaseSerializer + include ResourceSerializerConcern + + has_many :properties + has_many :option_types + has_many :taxons + end + end + end + end +end diff --git a/api/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rb b/api/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rb new file mode 100644 index 00000000000..8665a342444 --- /dev/null +++ b/api/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rb @@ -0,0 +1,10 @@ +module Spree + module Api + module V2 + module Platform + class ReimbursementCreditSerializer < BaseSerializer + end + end + end + end +end diff --git a/api/app/serializers/spree/api/v2/platform/role_serializer.rb b/api/app/serializers/spree/api/v2/platform/role_serializer.rb new file mode 100644 index 00000000000..b747813aa03 --- /dev/null +++ b/api/app/serializers/spree/api/v2/platform/role_serializer.rb @@ -0,0 +1,11 @@ +module Spree + module Api + module V2 + module Platform + class RoleSerializer < BaseSerializer + include ResourceSerializerConcern + end + end + end + end +end diff --git a/api/app/serializers/spree/api/v2/platform/stock_item_serializer.rb b/api/app/serializers/spree/api/v2/platform/stock_item_serializer.rb index ff7fb00d1c1..ded1fab01c1 100644 --- a/api/app/serializers/spree/api/v2/platform/stock_item_serializer.rb +++ b/api/app/serializers/spree/api/v2/platform/stock_item_serializer.rb @@ -5,8 +5,6 @@ module Platform class StockItemSerializer < BaseSerializer include ResourceSerializerConcern - set_type :stock_item - attribute :is_available do |stock_item| stock_item.available? end diff --git a/api/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rb b/api/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rb new file mode 100644 index 00000000000..c5049be4cb9 --- /dev/null +++ b/api/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rb @@ -0,0 +1,15 @@ +module Spree + module Api + module V2 + module Platform + class StockTransferSerializer < BaseSerializer + include ResourceSerializerConcern + + belongs_to :destination_location, serializer: :stock_location + belongs_to :source_location, serializer: :stock_location + has_many :stock_movements + end + end + end + end +end diff --git a/api/app/services/spree/webhooks/subscribers/queue_requests.rb b/api/app/services/spree/webhooks/subscribers/queue_requests.rb index c957af06a46..5aaa94e1806 100644 --- a/api/app/services/spree/webhooks/subscribers/queue_requests.rb +++ b/api/app/services/spree/webhooks/subscribers/queue_requests.rb @@ -5,26 +5,10 @@ class QueueRequests prepend Spree::ServiceModule::Base def call(body:, event:) - subscriberd_urls_for(event).each do |url| + Spree::Webhooks::Subscriber.active.urls_for(event).each do |url| Spree::Webhooks::Subscribers::MakeRequestJob.perform_later(body, event, url) end end - - private - - def subscriberd_urls_for(event) - Spree::Webhooks::Subscriber.active.where(subscriptions_where_statement(event)).pluck(:url) - end - - # FIXME: this should be written as scope - def subscriptions_where_statement(event) - case ActiveRecord::Base.connection.adapter_name - when 'Mysql2' - ["('*' MEMBER OF(subscriptions) OR ? MEMBER OF(subscriptions))", event] - when 'PostgreSQL' - ["subscriptions @> '[\"*\"]' OR subscriptions @> ?", [event].to_json] - end - end end end end diff --git a/api/spec/models/spree/webhooks/subscriber_spec.rb b/api/spec/models/spree/webhooks/subscriber_spec.rb index 1bf2dfed77b..36241c4f099 100644 --- a/api/spec/models/spree/webhooks/subscriber_spec.rb +++ b/api/spec/models/spree/webhooks/subscriber_spec.rb @@ -2,16 +2,43 @@ describe Spree::Webhooks::Subscriber do describe 'validations' do - context 'url format' do + context 'url format (UrlValidator)' do it 'is invalid with an invalid url' do endpoint = described_class.new(url: 'google.com') expect(endpoint.valid?).to be(false) end it 'is valid with a valid url' do - endpoint = described_class.new(url: 'http://google.com') + endpoint = described_class.new(url: 'http://google.com/') expect(endpoint.valid?).to be(true) end end + + context 'url path' do + it 'is invalid a url without path' do + endpoint = described_class.new(url: 'http://google.com') + expect(endpoint.valid?).to be(false) + expect(endpoint.errors.messages).to eq(url: ['the URL must have a path']) + end + end + end + + describe '.urls_for' do + subject { described_class.urls_for(event) } + + let(:event) { 'order.complete' } + let(:subscriptions) { ['order.complete'] } + let!(:subscriber) { described_class.create(url: url, subscriptions: subscriptions, active: true) } + let(:url) { 'https://url1.com/' } + + context 'with subscriptions for the given event' do + it { expect(subject).to eq([url]) } + end + + context 'without subscriptions for the given event, but "*"' do + let(:subscriptions) { ['*'] } + + it { expect(subject).to eq([url]) } + end end end diff --git a/api/spec/serializers/spree/api/v2/platform/asset_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/asset_serializer_spec.rb new file mode 100644 index 00000000000..174a333ba69 --- /dev/null +++ b/api/spec/serializers/spree/api/v2/platform/asset_serializer_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe Spree::Api::V2::Platform::AssetSerializer do + include_context 'API v2 serializers params' + + subject { described_class.new(resource, params: serializer_params).serializable_hash } + + let(:viewable) { create(:variant) } + let(:type) { :asset } + let(:resource) { create(type, viewable: viewable) } + + it do + expect(subject).to eq( + data: { + id: resource.id.to_s, + attributes: { + viewable_type: resource.viewable_type, + attachment_height: resource.attachment_height, + attachment_file_size: resource.attachment_file_size, + position: resource.position, + attachment_content_type: resource.attachment_content_type, + attachment_file_name: resource.attachment_file_name, + type: resource.type, + attachment_updated_at: resource.attachment_updated_at, + alt: resource.alt, + created_at: resource.created_at, + updated_at: resource.updated_at + }, + relationships: { + viewable: { + data: { + id: viewable.id.to_s, + type: :variant + } + } + }, + type: type + } + ) + end +end diff --git a/api/spec/serializers/spree/api/v2/platform/property_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/property_serializer_spec.rb new file mode 100644 index 00000000000..2672c555685 --- /dev/null +++ b/api/spec/serializers/spree/api/v2/platform/property_serializer_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe Spree::Api::V2::Platform::PropertySerializer do + include_context 'API v2 serializers params' + + subject { described_class.new(resource, params: serializer_params).serializable_hash } + + let(:type) { :property } + let(:resource) { create(type) } + + it do + expect(subject).to eq( + data: { + id: resource.id.to_s, + type: type, + attributes: { + name: resource.name, + presentation: resource.presentation, + created_at: resource.created_at, + updated_at: resource.updated_at, + filterable: resource.filterable, + filter_param: resource.filter_param + } + } + ) + end +end diff --git a/api/spec/serializers/spree/api/v2/platform/prototype_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/prototype_serializer_spec.rb new file mode 100644 index 00000000000..16261718491 --- /dev/null +++ b/api/spec/serializers/spree/api/v2/platform/prototype_serializer_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe Spree::Api::V2::Platform::PrototypeSerializer do + include_context 'API v2 serializers params' + + subject { described_class.new(resource, params: serializer_params).serializable_hash } + + let(:property) { create(:property) } + let(:option_type) { create(:option_type) } + let(:resource) { create(type, properties: [property], option_types: [option_type], taxons: [taxon]) } + let(:taxon) { create(:taxon) } + let(:type) { :prototype } + + it do + expect(subject).to eq( + data: { + id: resource.id.to_s, + attributes: { + name: resource.name, + created_at: resource.created_at, + updated_at: resource.updated_at + }, + relationships: { + properties: { + data: [{ + id: property.id.to_s, + type: :property + }] + }, + option_types: { + data: [{ + id: option_type.id.to_s, + type: :option_type + }] + }, + taxons: { + data: [{ + id: taxon.id.to_s, + type: :taxon + }] + } + }, + type: type + } + ) + end +end diff --git a/api/spec/serializers/spree/api/v2/platform/refund_reason_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/refund_reason_serializer_spec.rb new file mode 100644 index 00000000000..807a0f29c10 --- /dev/null +++ b/api/spec/serializers/spree/api/v2/platform/refund_reason_serializer_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe Spree::Api::V2::Platform::RefundReasonSerializer do + include_context 'API v2 serializers params' + + subject { described_class.new(resource, params: serializer_params).serializable_hash } + + let(:type) { :refund_reason } + let(:resource) { create(type) } + + it do + expect(subject).to eq( + data: { + id: resource.id.to_s, + attributes: { + name: resource.name, + active: resource.active, + mutable: resource.mutable, + created_at: resource.created_at, + updated_at: resource.updated_at + }, + type: type + } + ) + end +end diff --git a/api/spec/serializers/spree/api/v2/platform/reimbursement_credit_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/reimbursement_credit_serializer_spec.rb new file mode 100644 index 00000000000..c9361e73976 --- /dev/null +++ b/api/spec/serializers/spree/api/v2/platform/reimbursement_credit_serializer_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe Spree::Api::V2::Platform::ReimbursementCreditSerializer do + include_context 'API v2 serializers params' + + subject { described_class.new(resource, params: serializer_params).serializable_hash } + + let(:type) { :reimbursement_credit } + let(:resource) { create(type, creditable: create(:store_credit)) } + + it do + expect(subject).to eq( + data: { + id: resource.id.to_s, + type: type + } + ) + end +end diff --git a/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb new file mode 100644 index 00000000000..e17ef9d0141 --- /dev/null +++ b/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' + +describe Spree::Api::V2::Platform::ReimbursementSerializer do + include_context 'API v2 serializers params' + + subject { described_class.new(resource, params: serializer_params).serializable_hash } + + let(:reimbursement_credit) { create(:reimbursement_credit, creditable: create(:store_credit)) } + let(:payment) { create(:payment, state: 'completed') } + let(:type) { :reimbursement } + let(:refund) { create(:refund, amount: payment.credit_allowed - 1) } + let(:resource) { create(type, refunds: [refund], credits: [reimbursement_credit]) } + + it do + expect(subject).to eq( + data: { + id: resource.id.to_s, + attributes: { + number: resource.number, + reimbursement_status: resource.reimbursement_status, + total: resource.total, + created_at: resource.created_at, + updated_at: resource.updated_at, + display_total: resource.display_total, + }, + relationships: { + order: { + data: { + id: resource.order.id.to_s, + type: :order + } + }, + customer_return: { + data: { + id: resource.customer_return.id.to_s, + type: :customer_return + } + }, + refunds: { + data: [{ + id: refund.id.to_s, + type: :refund + }] + }, + reimbursement_credits: { + data: [{ + id: reimbursement_credit.id.to_s, + type: :reimbursement_credit + }] + }, + return_items: { + data: [{ + id: resource.return_items.first.id.to_s, + type: :return_item + }] + } + }, + type: type + } + ) + end +end diff --git a/api/spec/serializers/spree/api/v2/platform/role_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/role_serializer_spec.rb new file mode 100644 index 00000000000..531b625276f --- /dev/null +++ b/api/spec/serializers/spree/api/v2/platform/role_serializer_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe Spree::Api::V2::Platform::RoleSerializer do + include_context 'API v2 serializers params' + + subject { described_class.new(resource, params: serializer_params).serializable_hash } + + let(:type) { :role } + let(:resource) { create(type) } + + it do + expect(subject).to eq( + data: { + id: resource.id.to_s, + type: type, + attributes: { + name: resource.name, + created_at: resource.created_at, + updated_at: resource.updated_at + } + } + ) + end +end diff --git a/api/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rb new file mode 100644 index 00000000000..b317caf0c12 --- /dev/null +++ b/api/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +describe Spree::Api::V2::Platform::StockItemSerializer do + include_context 'API v2 serializers params' + + subject { described_class.new(resource, params: serializer_params).serializable_hash } + + let(:resource) { stock_location.stock_items.order(:id).first } + let(:stock_location) { create(:stock_location_with_items) } + let(:type) { :stock_item } + + it do + expect(subject).to eq( + data: { + id: resource.id.to_s, + attributes: { + backorderable: resource.backorderable, + count_on_hand: resource.count_on_hand, + created_at: resource.created_at, + deleted_at: resource.deleted_at, + is_available: resource.available?, + updated_at: resource.updated_at + }, + relationships: { + stock_location: { + data: { + id: stock_location.id.to_s, + type: :stock_location + } + }, + variant: { + data: { + id: resource.variant.id.to_s, + type: :variant + } + } + }, + type: type + } + ) + end +end diff --git a/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb new file mode 100644 index 00000000000..fad1e40eb73 --- /dev/null +++ b/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe Spree::Api::V2::Platform::StockLocationSerializer do + include_context 'API v2 serializers params' + + subject { described_class.new(resource, params: serializer_params).serializable_hash } + + let(:resource) { create(:stock_location_with_items, shipments: [shipment]) } + let(:type) { :stock_location } + let(:shipment) { create(:shipment) } + + it do + expect(subject).to eq( + data: { + id: resource.id.to_s, + type: type, + attributes: { + active: resource.active, + address1: resource.address1, + address2: resource.address2, + admin_name: resource.admin_name, + backorderable_default: resource.backorderable_default, + city: resource.city, + created_at: resource.created_at, + default: resource.default, + name: resource.name, + phone: resource.phone, + propagate_all_variants: resource.propagate_all_variants, + state_name: resource.state_name, + updated_at: resource.updated_at, + zipcode: resource.zipcode + }, + relationships: { + shipments: { + data: [{ + id: shipment.id.to_s, + type: :shipment + }] + }, + stock_items: { + data: [{ + id: resource.stock_items[0].id.to_s, + type: :stock_item + }, { + id: resource.stock_items[1].id.to_s, + type: :stock_item + }] + } + } + } + ) + end +end diff --git a/api/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rb new file mode 100644 index 00000000000..33fd0066d6f --- /dev/null +++ b/api/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe Spree::Api::V2::Platform::StockMovementSerializer do + include_context 'API v2 serializers params' + + subject { described_class.new(resource, params: serializer_params).serializable_hash } + + let(:type) { :stock_movement } + let(:stock_location) { create(:stock_location_with_items) } + let(:stock_item) { stock_location.stock_items.order(:id).first } + let(:resource) { create(type, stock_item: stock_item) } + + it do + expect(subject).to eq( + data: { + id: resource.id.to_s, + attributes: { + quantity: resource.quantity, + action: resource.action, + originator_type: resource.originator_type, + created_at: resource.created_at, + updated_at: resource.updated_at + }, + type: type + } + ) + end +end diff --git a/api/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rb new file mode 100644 index 00000000000..745a88370e9 --- /dev/null +++ b/api/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe Spree::Api::V2::Platform::StockTransferSerializer do + subject { described_class.new(resource, params: serializer_params).serializable_hash } + + include_context 'API v2 serializers params' + + let(:destination_location) { create(:stock_location) } + let(:resource) { create(type, destination_location: destination_location, source_location: source_location) } + let(:source_location) { create(:stock_location) } + let(:stock_item) { stock_location.stock_items.order(:id).first } + let(:stock_location) { create(:stock_location_with_items) } + let(:type) { :stock_transfer } + + let!(:stock_movement) { create(:stock_movement, stock_item: stock_item, originator: resource) } + + it do + expect(subject).to eq( + data: { + id: resource.id.to_s, + attributes: { + type: resource.type, + reference: resource.reference, + created_at: resource.created_at, + updated_at: resource.updated_at, + number: resource.number + }, + relationships: { + stock_movements: { + data: [{ + id: stock_movement.id.to_s, + type: :stock_movement + }] + }, + source_location: { + data: { + id: source_location.id.to_s, + type: :stock_location + } + }, + destination_location: { + data: { + id: destination_location.id.to_s, + type: :stock_location + } + } + }, + type: type, + } + ) + end +end diff --git a/api/spec/services/spree/webhooks/subscribers/queue_requests_spec.rb b/api/spec/services/spree/webhooks/subscribers/queue_requests_spec.rb index 769591395d3..99bf120ef1f 100644 --- a/api/spec/services/spree/webhooks/subscribers/queue_requests_spec.rb +++ b/api/spec/services/spree/webhooks/subscribers/queue_requests_spec.rb @@ -16,10 +16,10 @@ end context 'with subscriptions for the given event' do - context 'when endpoint subscriptions includes all events (*)' do - before { stub_request(:post, endpoint.url) } + context 'when subscriber subscriptions includes all events (*)' do + before { stub_request(:post, subscriber.url) } - let(:endpoint) do + let(:subscriber) do Spree::Webhooks::Subscriber.create( url: 'https://url1.com/', subscriptions: ['*'], @@ -29,15 +29,15 @@ it 'queues a job to make a request' do expect { subject }.to( - have_enqueued_job(make_request_job).with(body, event, endpoint.url).on_queue(queue) + have_enqueued_job(make_request_job).with(body, event, subscriber.url).on_queue(queue) ) end end - context 'when endpoint subscriptions includes the specific event being used' do - before { stub_request(:post, endpoint.url) } + context 'when subscriber subscriptions includes the specific event being used' do + before { stub_request(:post, subscriber.url) } - let(:endpoint) do + let(:subscriber) do Spree::Webhooks::Subscriber.create( url: 'https://url2.com/', subscriptions: [event], @@ -47,17 +47,17 @@ it 'queues a job to make a request' do expect { subject }.to( - have_enqueued_job(make_request_job).with(body, event, endpoint.url).on_queue(queue) + have_enqueued_job(make_request_job).with(body, event, subscriber.url).on_queue(queue) ) end end - context 'when endpoint subscriptions are not enabled' do - let(:endpoint) do + context 'when subscriber subscriptions are not active' do + let!(:subscriber) do Spree::Webhooks::Subscriber.create( url: 'https://url3.com/', subscriptions: [event], - enabled: false + active: false ) end @@ -66,8 +66,8 @@ end end - context 'when endpoint subscriptions do not include the event or "*"' do - let(:endpoint) do + context 'when subscriber subscriptions do not include the event or "*"' do + let!(:subscriber) do Spree::Webhooks::Subscriber.create( url: 'https://url4.com/', subscriptions: ['order.resume'], diff --git a/core/lib/spree/testing_support/factories/asset_factory.rb b/core/lib/spree/testing_support/factories/asset_factory.rb new file mode 100644 index 00000000000..e08b6142db3 --- /dev/null +++ b/core/lib/spree/testing_support/factories/asset_factory.rb @@ -0,0 +1,15 @@ +FactoryBot.define do + factory :asset, class: Spree::Asset do + viewable_type {} + viewable_id {} + attachment_width { 340 } + attachment_height { 280 } + attachment_file_size { 128 } + position { 1 } + attachment_content_type { '.jpg' } + attachment_file_name { 'attachment.jpg' } + type {} + attachment_updated_at {} + alt {} + end +end diff --git a/core/lib/spree/testing_support/factories/reimbursement_credit_factory.rb b/core/lib/spree/testing_support/factories/reimbursement_credit_factory.rb new file mode 100644 index 00000000000..8a03944383b --- /dev/null +++ b/core/lib/spree/testing_support/factories/reimbursement_credit_factory.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :reimbursement_credit, class: Spree::Reimbursement::Credit do + reimbursement + + amount { 100.00 } + end +end diff --git a/core/lib/spree/testing_support/factories/stock_transfer_factory.rb b/core/lib/spree/testing_support/factories/stock_transfer_factory.rb new file mode 100644 index 00000000000..68c85e3772d --- /dev/null +++ b/core/lib/spree/testing_support/factories/stock_transfer_factory.rb @@ -0,0 +1,9 @@ +FactoryBot.define do + factory :stock_transfer, class: Spree::StockTransfer do + destination_location {} + number {} + reference {} + source_location {} + type {} + end +end diff --git a/core/spec/validators/spree/url_validator_spec.rb b/core/spec/validators/spree/url_validator_spec.rb index 97789da4924..499d7678cef 100644 --- a/core/spec/validators/spree/url_validator_spec.rb +++ b/core/spec/validators/spree/url_validator_spec.rb @@ -2,8 +2,8 @@ module Spree module Test - class Product < ActiveRecord::Base - self.table_name = 'test_products' + Product = Struct.new(:url, keyword_init: true) do + include ActiveModel::Validations validates :url, 'spree/url': true end @@ -11,16 +11,6 @@ class Product < ActiveRecord::Base end describe Spree::UrlValidator do - before(:all) do - ActiveRecord::Base.connection.create_table :test_products, force: true do |t| - t.string :url - end - end - - after(:all) do - ActiveRecord::Base.connection.drop_table :test_products, if_exists: true - end - describe 'validating the given URL' do context 'is invalid' do it { expect(Spree::Test::Product.new(url: nil).valid?).to eq(false) }