diff --git a/backend/app/controllers/spree/admin/store_credit_reasons_controller.rb b/backend/app/controllers/spree/admin/store_credit_reasons_controller.rb
new file mode 100644
index 00000000000..19bd4735e29
--- /dev/null
+++ b/backend/app/controllers/spree/admin/store_credit_reasons_controller.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+module Spree
+ module Admin
+ class StoreCreditReasonsController < ResourceController
+ end
+ end
+end
diff --git a/backend/app/controllers/spree/admin/store_credits_controller.rb b/backend/app/controllers/spree/admin/store_credits_controller.rb
index 6a219875d99..8e645a36422 100644
--- a/backend/app/controllers/spree/admin/store_credits_controller.rb
+++ b/backend/app/controllers/spree/admin/store_credits_controller.rb
@@ -5,8 +5,8 @@ module Admin
class StoreCreditsController < ResourceController
belongs_to 'spree/user', model_class: Spree.user_class
before_action :load_categories, only: [:new]
- before_action :load_update_reasons, only: [:edit_amount, :edit_validity]
- before_action :ensure_update_reason, only: [:update_amount, :invalidate]
+ before_action :load_reasons, only: [:edit_amount, :edit_validity]
+ before_action :ensure_store_credit_reason, only: [:update_amount, :invalidate]
helper Spree::Admin::StoreCreditEventsHelper
@@ -50,7 +50,7 @@ def update
def update_amount
@store_credit = @user.store_credits.find(params[:id])
amount = params.require(:store_credit).require(:amount)
- if @store_credit.update_amount(amount, @update_reason, try_spree_current_user)
+ if @store_credit.update_amount(amount, @store_credit_reason, try_spree_current_user)
flash[:success] = flash_message_for(@store_credit, :successfully_updated)
redirect_to admin_user_store_credit_path(@user, @store_credit)
else
@@ -60,7 +60,7 @@ def update_amount
def invalidate
@store_credit = @user.store_credits.find(params[:id])
- if @store_credit.invalidate(@update_reason, try_spree_current_user)
+ if @store_credit.invalidate(@store_credit_reason, try_spree_current_user)
redirect_to admin_user_store_credit_path(@user, @store_credit)
else
render_edit_page
@@ -78,18 +78,18 @@ def collection
@collection = super.reverse_order
end
- def load_update_reasons
- @update_reasons = Spree::StoreCreditUpdateReason.all.order(:name)
+ def load_reasons
+ @store_credit_reasons = Spree::StoreCreditReason.active.order(:name)
end
def load_categories
@credit_categories = Spree::StoreCreditCategory.all.order(:name)
end
- def ensure_update_reason
- @update_reason = Spree::StoreCreditUpdateReason.find_by(id: params[:update_reason_id])
- unless @update_reason
- @store_credit.errors.add(:base, t('spree.admin.store_credits.errors.update_reason_required'))
+ def ensure_store_credit_reason
+ @store_credit_reason = Spree::StoreCreditReason.find_by(id: params[:store_credit_reason_id])
+ unless @store_credit_reason
+ @store_credit.errors.add(:base, t('spree.admin.store_credits.errors.store_credit_reason_required'))
render_edit_page
end
end
@@ -103,7 +103,7 @@ def render_edit_page
translation_key = 'invalidate'
end
- load_update_reasons
+ load_reasons
flash[:error] = "#{t("spree.admin.store_credits.unable_to_#{translation_key}")}: #{@store_credit.errors.full_messages.join(', ')}"
render(template) && return
end
diff --git a/backend/app/views/spree/admin/shared/_settings_checkout_tabs.html.erb b/backend/app/views/spree/admin/shared/_settings_checkout_tabs.html.erb
index 3d7682294c5..c606c88e6cb 100644
--- a/backend/app/views/spree/admin/shared/_settings_checkout_tabs.html.erb
+++ b/backend/app/views/spree/admin/shared/_settings_checkout_tabs.html.erb
@@ -16,6 +16,10 @@
<% if can?(:display, Spree::AdjustmentReason) %>
<%= settings_tab_item plural_resource_name(Spree::AdjustmentReason), spree.admin_adjustment_reasons_path %>
<% end %>
+
+ <% if can?(:display, Spree::StoreCreditReason) %>
+ <%= settings_tab_item plural_resource_name(Spree::StoreCreditReason), spree.admin_store_credit_reasons_path %>
+ <% end %>
<% end %>
diff --git a/backend/app/views/spree/admin/store_credit_reasons/edit.html.erb b/backend/app/views/spree/admin/store_credit_reasons/edit.html.erb
new file mode 100644
index 00000000000..527c2034433
--- /dev/null
+++ b/backend/app/views/spree/admin/store_credit_reasons/edit.html.erb
@@ -0,0 +1,15 @@
+<%= render 'spree/admin/shared/settings_checkout_tabs' %>
+
+<% admin_breadcrumb t('spree.settings') %>
+<% admin_breadcrumb t('spree.admin.tab.checkout') %>
+<% admin_breadcrumb link_to plural_resource_name(Spree::StoreCreditReason), spree.admin_store_credit_reasons_path %>
+<% admin_breadcrumb @object.name %>
+
+<%= render partial: 'spree/shared/error_messages', locals: { target: @object } %>
+
+<%= form_for [:admin, @object] do |f| %>
+
+<% end %>
diff --git a/backend/app/views/spree/admin/store_credit_reasons/index.html.erb b/backend/app/views/spree/admin/store_credit_reasons/index.html.erb
new file mode 100644
index 00000000000..8e86844c7ec
--- /dev/null
+++ b/backend/app/views/spree/admin/store_credit_reasons/index.html.erb
@@ -0,0 +1,56 @@
+<%= render 'spree/admin/shared/settings_checkout_tabs' %>
+
+<% admin_breadcrumb(t('spree.settings')) %>
+<% admin_breadcrumb(t('spree.admin.tab.checkout')) %>
+<% admin_breadcrumb(plural_resource_name(Spree::StoreCreditReason)) %>
+
+<% content_for :page_actions do %>
+
+<% end %>
+
+<% if @collection.any? %>
+
+
+
+
+
+
+
+
+ <%= Spree::StoreCreditReason.human_attribute_name(:name) %> |
+ <%= Spree::StoreCreditReason.human_attribute_name(:state) %> |
+ |
+
+
+
+ <% @collection.each do |store_credit_reason| %>
+
+
+ <%= store_credit_reason.name %>
+ |
+
+
+ <%= t(store_credit_reason.active? ? :active : :inactive, scope: 'spree') %>
+
+ |
+
+ <%= link_to_edit store_credit_reason, no_text: true %>
+ <% if can?(:destroy, store_credit_reason) %>
+ <%= link_to_delete store_credit_reason, no_text: true %>
+ <% end %>
+ |
+
+ <% end %>
+
+
+<% else %>
+
+ <%= render 'spree/admin/shared/no_objects_found',
+ resource: Spree::StoreCreditReason,
+ new_resource_url: new_object_url %>
+
+<% end %>
diff --git a/backend/app/views/spree/admin/store_credit_reasons/new.html.erb b/backend/app/views/spree/admin/store_credit_reasons/new.html.erb
new file mode 100644
index 00000000000..edac68eb8c8
--- /dev/null
+++ b/backend/app/views/spree/admin/store_credit_reasons/new.html.erb
@@ -0,0 +1,18 @@
+<%= render 'spree/admin/shared/settings_checkout_tabs' %>
+
+<% admin_breadcrumb(t('spree.settings')) %>
+<% admin_breadcrumb(t('spree.admin.tab.checkout')) %>
+<% admin_breadcrumb(link_to plural_resource_name(Spree::StoreCreditReason), spree.admin_store_credit_reasons_path) %>
+<% admin_breadcrumb(t('spree.new_store_credit_reason')) %>
+
+<% content_for :page_actions do %>
+<% end %>
+
+<%= render partial: 'spree/shared/error_messages', locals: { target: @object } %>
+
+<%= form_for [:admin, @object] do |f| %>
+
+<% end %>
diff --git a/backend/app/views/spree/admin/store_credit_reasons/shared/_form.html.erb b/backend/app/views/spree/admin/store_credit_reasons/shared/_form.html.erb
new file mode 100644
index 00000000000..35094676278
--- /dev/null
+++ b/backend/app/views/spree/admin/store_credit_reasons/shared/_form.html.erb
@@ -0,0 +1,15 @@
+
+
+ <%= f.field_container :name do %>
+ <%= f.label :name, class: 'required' %>
+ <%= f.text_field :name, class: 'fullwidth' %>
+ <% end %>
+
+
+
+
+
+
diff --git a/backend/app/views/spree/admin/store_credits/_store_credit_reason_field.html.erb b/backend/app/views/spree/admin/store_credits/_store_credit_reason_field.html.erb
new file mode 100644
index 00000000000..7464c216c9d
--- /dev/null
+++ b/backend/app/views/spree/admin/store_credits/_store_credit_reason_field.html.erb
@@ -0,0 +1,7 @@
+<%= f.field_container :reason do %>
+ <%= f.label :store_credit_reason, t('spree.reason'), class: 'required' %>
+ <%= select_tag :store_credit_reason_id, options_from_collection_for_select(@store_credit_reasons, :id, :name),
+ include_blank: t('spree.choose_reason'), class: 'custom-select fullwidth',
+ placeholder: t('spree.admin.store_credits.select_amount_store_credit_reason') %>
+ <%= f.error_message_on :store_credit_reason %>
+<% end %>
diff --git a/backend/app/views/spree/admin/store_credits/_update_reason_field.html.erb b/backend/app/views/spree/admin/store_credits/_update_reason_field.html.erb
deleted file mode 100644
index c2784dd5b95..00000000000
--- a/backend/app/views/spree/admin/store_credits/_update_reason_field.html.erb
+++ /dev/null
@@ -1,7 +0,0 @@
-<%= f.field_container :reason do %>
- <%= f.label :reason, t('spree.reason'), class: 'required' %>
- <%= select_tag :update_reason_id, options_from_collection_for_select(@update_reasons, :id, :name),
- include_blank: t('spree.choose_reason'), class: 'custom-select fullwidth',
- placeholder: t('spree.admin.store_credits.select_amount_update_reason') %>
- <%= f.error_message_on :reason %>
-<% end %>
diff --git a/backend/app/views/spree/admin/store_credits/edit_amount.html.erb b/backend/app/views/spree/admin/store_credits/edit_amount.html.erb
index b2eb657f334..90dd5c58afd 100644
--- a/backend/app/views/spree/admin/store_credits/edit_amount.html.erb
+++ b/backend/app/views/spree/admin/store_credits/edit_amount.html.erb
@@ -23,7 +23,7 @@
<% end %>
- <%= render 'update_reason_field', f: f %>
+ <%= render 'store_credit_reason_field', f: f %>
<%= render 'spree/admin/shared/edit_resource_links',
diff --git a/backend/app/views/spree/admin/store_credits/edit_validity.html.erb b/backend/app/views/spree/admin/store_credits/edit_validity.html.erb
index 8a803a17fb9..5d13735f9a9 100644
--- a/backend/app/views/spree/admin/store_credits/edit_validity.html.erb
+++ b/backend/app/views/spree/admin/store_credits/edit_validity.html.erb
@@ -15,7 +15,7 @@
- <%= render partial: 'update_reason_field', locals: { f: f } %>
+ <%= render partial: 'store_credit_reason_field', locals: { f: f } %>
diff --git a/backend/app/views/spree/admin/store_credits/show.html.erb b/backend/app/views/spree/admin/store_credits/show.html.erb
index b0dbbfdd9d4..d66161da918 100644
--- a/backend/app/views/spree/admin/store_credits/show.html.erb
+++ b/backend/app/views/spree/admin/store_credits/show.html.erb
@@ -84,7 +84,7 @@
<%= t('spree.admin.store_credits.created_by') %> |
<%= Spree::StoreCreditEvent.human_attribute_name(:user_total_amount) %> |
<%= Spree::StoreCreditEvent.human_attribute_name(:amount_remaining) %> |
- <%= Spree::StoreCreditUpdateReason.human_attribute_name(:name) %> |
+ <%= Spree::StoreCreditReason.human_attribute_name(:name) %> |
@@ -98,7 +98,7 @@
<%= store_credit_event_originator_link(event) %> |
<%= event.display_user_total_amount %> |
<%= event.display_remaining_amount %> |
- <%= event.update_reason.try!(:name) %> |
+ <%= event.store_credit_reason.try!(:name) %> |
<% end %>
diff --git a/backend/config/routes.rb b/backend/config/routes.rb
index 30d3fcf9a00..532fcdd07ae 100644
--- a/backend/config/routes.rb
+++ b/backend/config/routes.rb
@@ -145,6 +145,7 @@
resources :adjustment_reasons, except: [:show, :destroy]
resources :refund_reasons, except: [:show, :destroy]
resources :return_reasons, except: [:show, :destroy]
+ resources :store_credit_reasons, except: [:show]
resources :shipping_methods
resources :shipping_categories
diff --git a/backend/spec/controllers/spree/admin/store_credits_controller_spec.rb b/backend/spec/controllers/spree/admin/store_credits_controller_spec.rb
index 5f581616ced..14a3875ec39 100644
--- a/backend/spec/controllers/spree/admin/store_credits_controller_spec.rb
+++ b/backend/spec/controllers/spree/admin/store_credits_controller_spec.rb
@@ -3,8 +3,8 @@
require 'spec_helper'
shared_examples "update reason loader" do
- it "sets the update_reasons variable to a list of categories sorted by category name " do
- expect(assigns(:update_reasons)).to eq [update_reason]
+ it "sets the store_credit_reasons variable to a list of categories sorted by category name " do
+ expect(assigns(:store_credit_reasons)).to eq [store_credit_reason]
end
end
@@ -16,11 +16,11 @@
let!(:b_credit_category) { create(:store_credit_category, name: "B category") }
let!(:a_credit_category) { create(:store_credit_category, name: "A category") }
- let!(:update_reason) { create(:store_credit_update_reason) }
+ let!(:store_credit_reason) { create(:store_credit_reason) }
describe "#show" do
let!(:store_credit) { create(:store_credit, user: user, category: a_credit_category) }
- let!(:event) { create(:store_credit_auth_event, store_credit: store_credit, created_at: 5.days.ago) }
+ let!(:event) { create(:store_credit_auth_event, store_credit: store_credit, created_at: 5.days.ago) }
before { get :show, params: { user_id: user.id, id: store_credit.id } }
@@ -173,12 +173,12 @@
describe "#update_amount" do
let(:original_amount) { 100.0 }
let!(:store_credit) { create(:store_credit, user: user, amount: original_amount) }
- let!(:update_reason) { create(:store_credit_update_reason) }
+ let!(:store_credit_reason) { create(:store_credit_reason) }
let(:parameters) do
{
user_id: user.id,
id: store_credit.id,
- update_reason_id: update_reason.id,
+ store_credit_reason_id: store_credit_reason.id,
store_credit: {
amount: updated_amount
}
@@ -271,7 +271,7 @@
{
user_id: user.id,
id: store_credit.id,
- update_reason_id: update_reason.id
+ store_credit_reason_id: store_credit_reason.id
}
end
diff --git a/backend/spec/features/admin/store_credits_spec.rb b/backend/spec/features/admin/store_credits_spec.rb
index 4b93cb3b2e9..dd4cd22eb68 100644
--- a/backend/spec/features/admin/store_credits_spec.rb
+++ b/backend/spec/features/admin/store_credits_spec.rb
@@ -107,7 +107,7 @@
describe "updating store credit" do
let(:updated_amount) { "99.0" }
- let!(:update_reason) { create(:store_credit_update_reason) }
+ let!(:store_credit_reason) { create(:store_credit_reason) }
before do
visit spree.admin_path
@@ -123,7 +123,7 @@
click_link "Change amount"
expect(page).to have_content 'Editing store credit amount'
page.fill_in 'store_credit_amount', with: updated_amount
- page.select update_reason.name, from: 'update_reason_id'
+ page.select store_credit_reason.name, from: 'store_credit_reason_id'
click_button "Update"
expect(page.find('#sc-detail-table')).to have_content "$99.00"
expect(store_credit.reload.amount.to_f).to eq updated_amount.to_f
diff --git a/backend/spec/helpers/admin/store_credit_events_helper_spec.rb b/backend/spec/helpers/admin/store_credit_events_helper_spec.rb
index bdbab968bc0..9283ee92a92 100644
--- a/backend/spec/helpers/admin/store_credit_events_helper_spec.rb
+++ b/backend/spec/helpers/admin/store_credit_events_helper_spec.rb
@@ -87,10 +87,10 @@
end
context "originator is not specifically handled" do
- let(:originator) { create(:store_credit_update_reason) }
+ let(:originator) { create(:store_credit) }
it "raises an error" do
- expect { subject }.to raise_error(RuntimeError, "Unexpected originator type Spree::StoreCreditUpdateReason")
+ expect { subject }.to raise_error(RuntimeError, "Unexpected originator type Spree::StoreCredit")
end
end
end
diff --git a/core/app/models/spree/store_credit.rb b/core/app/models/spree/store_credit.rb
index 69a21eef2d5..df6f88399e1 100644
--- a/core/app/models/spree/store_credit.rb
+++ b/core/app/models/spree/store_credit.rb
@@ -41,7 +41,7 @@ class Spree::StoreCredit < Spree::PaymentSource
before_destroy :validate_no_amount_used
validate :validate_no_amount_used, if: :discarded?
- attr_accessor :action, :action_amount, :action_originator, :action_authorization_code, :update_reason
+ attr_accessor :action, :action_amount, :action_originator, :action_authorization_code, :store_credit_reason
extend Spree::DisplayMoney
money_methods :amount, :amount_used, :amount_authorized
@@ -176,7 +176,7 @@ def update_amount(amount, reason, user_performing_update)
self.amount = amount
self.action_amount = self.amount - previous_amount
self.action = ADJUSTMENT_ACTION
- self.update_reason = reason
+ self.store_credit_reason = reason
self.action_originator = user_performing_update
save
end
@@ -184,7 +184,7 @@ def update_amount(amount, reason, user_performing_update)
def invalidate(reason, user_performing_invalidation)
if invalidateable?
self.action = INVALIDATE_ACTION
- self.update_reason = reason
+ self.store_credit_reason = reason
self.action_originator = user_performing_invalidation
self.invalidated_at = Time.current
save
@@ -241,7 +241,7 @@ def store_event
amount_remaining: amount_remaining,
user_total_amount: user.available_store_credit_total(currency: currency),
originator: action_originator,
- update_reason: update_reason
+ store_credit_reason: store_credit_reason
})
end
diff --git a/core/app/models/spree/store_credit_event.rb b/core/app/models/spree/store_credit_event.rb
index 405b60234c4..07c0294337d 100644
--- a/core/app/models/spree/store_credit_event.rb
+++ b/core/app/models/spree/store_credit_event.rb
@@ -12,9 +12,9 @@ class StoreCreditEvent < Spree::Base
belongs_to :store_credit
belongs_to :originator, polymorphic: true
- belongs_to :update_reason, class_name: "Spree::StoreCreditUpdateReason"
+ belongs_to :store_credit_reason, class_name: 'Spree::StoreCreditReason', inverse_of: :store_credit_events
- validates_presence_of :update_reason, if: :action_requires_reason?
+ validates_presence_of :store_credit_reason, if: :action_requires_reason?
NON_EXPOSED_ACTIONS = [Spree::StoreCredit::ELIGIBLE_ACTION, Spree::StoreCredit::AUTHORIZE_ACTION]
diff --git a/core/app/models/spree/store_credit_reason.rb b/core/app/models/spree/store_credit_reason.rb
new file mode 100644
index 00000000000..27377c2866f
--- /dev/null
+++ b/core/app/models/spree/store_credit_reason.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class Spree::StoreCreditReason < Spree::Base
+ include Spree::NamedType
+
+ has_many :store_credit_events, inverse_of: :store_credit_reason
+
+ validates :name, presence: true, uniqueness: { case_sensitive: false, allow_blank: true }
+
+ scope :active, -> { where(active: true) }
+end
diff --git a/core/app/models/spree/store_credit_update_reason.rb b/core/app/models/spree/store_credit_update_reason.rb
deleted file mode 100644
index 6c986caa60b..00000000000
--- a/core/app/models/spree/store_credit_update_reason.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-# frozen_string_literal: true
-
-class Spree::StoreCreditUpdateReason < Spree::Base
-end
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 6e14f17259e..d90c059e0a3 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -355,7 +355,7 @@ en:
amount_remaining: Total Unused
user_total_amount: Total Amount
spree/store_credit_update_reason:
- name: Reason For Updating
+ name: Name
spree/tax_category:
description: Description
is_default: Default
@@ -693,6 +693,9 @@ en:
spree/store_credit_category:
one: Category
other: Categories
+ spree/store_credit_reason:
+ one: Store Credit Reason
+ other: Store Credit Reasons
spree/tax_category:
one: Tax Category
other: Tax Categories
@@ -908,6 +911,7 @@ en:
cannot_change_used_store_credit: Store credit that has been claimed cannot
be changed
update_reason_required: A reason for the change must be selected
+ store_credit_reason_required: A reason for the change must be selected
history: Store credit history
invalidate_store_credit: Invalidating store credit
invalidated: Invalidated
@@ -919,6 +923,7 @@ en:
reason_for_updating: Reason for updating
refund_originator: 'Refund - Order #%{order_number}'
resource_name: store credits
+ select_amount_store_credit_reason: Select a reason for updating the amount
select_amount_update_reason: Select a reason for updating the amount
select_reason: Select a reason for this store credit
total_unused: Total unused
@@ -1586,6 +1591,7 @@ en:
new_stock_movement: New Stock Movement
new_store: New Store
new_store_credit: New Store Credit
+ new_store_credit_reason: New Store Credit Reason
new_tax_category: New Tax Category
new_tax_rate: New Tax Rate
new_taxon: New Taxon
diff --git a/core/db/default/spree/store_credit.rb b/core/db/default/spree/store_credit.rb
index 8218ab3231e..d4c1fbc58c0 100644
--- a/core/db/default/spree/store_credit.rb
+++ b/core/db/default/spree/store_credit.rb
@@ -19,4 +19,4 @@
Spree::StoreCreditCategory.find_or_create_by!(name: 'Gift Card')
-Spree::StoreCreditUpdateReason.find_or_create_by!(name: 'Credit Given In Error')
+Spree::StoreCreditReason.find_or_create_by!(name: 'Credit Given In Error')
diff --git a/core/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb b/core/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb
new file mode 100644
index 00000000000..3ed6048390d
--- /dev/null
+++ b/core/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+class CreateSpreeStoreCreditReasonsTable < ActiveRecord::Migration[5.1]
+ class StoreCreditUpdateReason < ActiveRecord::Base
+ self.table_name = "spree_store_credit_update_reasons"
+ end
+
+ class StoreCreditReason < ActiveRecord::Base
+ self.table_name = "spree_store_credit_reasons"
+ end
+
+ def up
+ create_table :spree_store_credit_reasons do |t|
+ t.string :name
+ t.boolean :active, default: true
+
+ t.timestamps
+ end
+
+ StoreCreditUpdateReason.all.each do |update_reason|
+ StoreCreditReason.create!(name: update_reason.name)
+ end
+
+ drop_table :spree_store_credit_update_reasons
+ rename_column :spree_store_credit_events, :update_reason_id, :store_credit_reason_id
+ end
+
+ def down
+ create_table :spree_store_credit_update_reasons do |t|
+ t.string :name
+
+ t.timestamps
+ end
+
+ StoreCreditReason.all.each do |store_credit_reason|
+ StoreCreditUpdateReason.create!(name: store_credit_reason.name)
+ end
+
+ drop_table :spree_store_credit_reasons
+ rename_column :spree_store_credit_events, :store_credit_reason_id, :update_reason_id
+ end
+end
diff --git a/core/lib/spree/testing_support/factories/store_credit_event_factory.rb b/core/lib/spree/testing_support/factories/store_credit_event_factory.rb
index 42e2c831f04..ed0f77e11a7 100644
--- a/core/lib/spree/testing_support/factories/store_credit_event_factory.rb
+++ b/core/lib/spree/testing_support/factories/store_credit_event_factory.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spree/testing_support/factories/store_credit_factory'
-require 'spree/testing_support/factories/store_credit_update_reason_factory'
+require 'spree/testing_support/factories/store_credit_reason_factory'
FactoryBot.define do
factory :store_credit_event, class: 'Spree::StoreCreditEvent' do
@@ -18,13 +18,13 @@
end
factory :store_credit_adjustment_event do
- action { Spree::StoreCredit::ADJUSTMENT_ACTION }
- update_reason { create(:store_credit_update_reason) }
+ action { Spree::StoreCredit::ADJUSTMENT_ACTION }
+ store_credit_reason { create(:store_credit_reason) }
end
factory :store_credit_invalidate_event do
- action { Spree::StoreCredit::INVALIDATE_ACTION }
- update_reason { create(:store_credit_update_reason) }
+ action { Spree::StoreCredit::INVALIDATE_ACTION }
+ store_credit_reason { create(:store_credit_reason) }
end
end
end
diff --git a/core/lib/spree/testing_support/factories/store_credit_reason_factory.rb b/core/lib/spree/testing_support/factories/store_credit_reason_factory.rb
new file mode 100644
index 00000000000..a16a4c045d3
--- /dev/null
+++ b/core/lib/spree/testing_support/factories/store_credit_reason_factory.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :store_credit_reason, class: 'Spree::StoreCreditReason' do
+ name "Input error"
+ end
+end
diff --git a/core/lib/spree/testing_support/factories/store_credit_update_reason_factory.rb b/core/lib/spree/testing_support/factories/store_credit_update_reason_factory.rb
deleted file mode 100644
index a29411c073f..00000000000
--- a/core/lib/spree/testing_support/factories/store_credit_update_reason_factory.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-# frozen_string_literal: true
-
-FactoryBot.define do
- factory :store_credit_update_reason, class: 'Spree::StoreCreditUpdateReason' do
- name { "Input error" }
- end
-end
diff --git a/core/spec/lib/spree/core/testing_support/factories/store_credit_reason_factory_spec.rb b/core/spec/lib/spree/core/testing_support/factories/store_credit_reason_factory_spec.rb
new file mode 100644
index 00000000000..d631343ab11
--- /dev/null
+++ b/core/spec/lib/spree/core/testing_support/factories/store_credit_reason_factory_spec.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+require 'spree/testing_support/factories/store_credit_reason_factory'
+
+RSpec.describe 'store credit reason factory' do
+ let(:factory_class) { Spree::StoreCreditReason }
+
+ describe 'store credit reason' do
+ let(:factory) { :store_credit_reason }
+
+ it_behaves_like 'a working factory'
+ end
+end
diff --git a/core/spec/lib/spree/core/testing_support/factories/store_credit_update_reason_factory_spec.rb b/core/spec/lib/spree/core/testing_support/factories/store_credit_update_reason_factory_spec.rb
deleted file mode 100644
index d3447f1ffaf..00000000000
--- a/core/spec/lib/spree/core/testing_support/factories/store_credit_update_reason_factory_spec.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-require 'rails_helper'
-require 'spree/testing_support/factories/store_credit_update_reason_factory'
-
-RSpec.describe 'store credit update reason factory' do
- let(:factory_class) { Spree::StoreCreditUpdateReason }
-
- describe 'store credit update reason' do
- let(:factory) { :store_credit_update_reason }
-
- it_behaves_like 'a working factory'
- end
-end
diff --git a/core/spec/models/spree/store_credit_event_spec.rb b/core/spec/models/spree/store_credit_event_spec.rb
index daa8351f6af..d832b063bd3 100644
--- a/core/spec/models/spree/store_credit_event_spec.rb
+++ b/core/spec/models/spree/store_credit_event_spec.rb
@@ -34,11 +34,11 @@
end
end
- describe "update reason validation" do
+ describe "update store credit reason validation" do
subject { event.valid? }
context "adjustment event" do
- context "has an update reason" do
+ context "has a store credit reason" do
let(:event) { build(:store_credit_adjustment_event) }
it "returns true" do
@@ -46,22 +46,22 @@
end
end
- context "doesn't have an update reason" do
- let(:event) { build(:store_credit_adjustment_event, update_reason: nil) }
+ context "doesn't have a store credit reason" do
+ let(:event) { build(:store_credit_adjustment_event, store_credit_reason: nil) }
it "returns false" do
expect(subject).to eq false
end
- it "adds an error message indicating the update reason is missing" do
+ it "adds an error message indicating the store credit reason is missing" do
subject
- expect(event.errors.full_messages).to match ["Update reason can't be blank"]
+ expect(event.errors.full_messages).to match ["Store credit reason can't be blank"]
end
end
end
context "invalidate event" do
- context "has an update reason" do
+ context "has a store credit reason" do
let(:event) { build(:store_credit_invalidate_event) }
it "returns true" do
@@ -69,21 +69,21 @@
end
end
- context "doesn't have an update reason" do
- let(:event) { build(:store_credit_invalidate_event, update_reason: nil) }
+ context "doesn't have a store credit reason" do
+ let(:event) { build(:store_credit_invalidate_event, store_credit_reason: nil) }
it "returns false" do
expect(subject).to eq false
end
- it "adds an error message indicating the update reason is missing" do
+ it "adds an error message indicating the store credit reason is missing" do
subject
- expect(event.errors.full_messages).to match ["Update reason can't be blank"]
+ expect(event.errors.full_messages).to match ["Store credit reason can't be blank"]
end
end
end
- context "event doesn't require an update reason" do
+ context "event doesn't require a store credit reason" do
let(:event) { build(:store_credit_auth_event) }
it "returns true" do
diff --git a/core/spec/models/spree/store_credit_spec.rb b/core/spec/models/spree/store_credit_spec.rb
index e40c15d9858..1086a5855c5 100644
--- a/core/spec/models/spree/store_credit_spec.rb
+++ b/core/spec/models/spree/store_credit_spec.rb
@@ -809,7 +809,7 @@
describe "#update_amount" do
let(:invalidation_user) { create(:user) }
- let(:invalidation_reason) { create(:store_credit_update_reason) }
+ let(:invalidation_reason) { create(:store_credit_reason) }
subject { store_credit.update_amount(amount, invalidation_reason, invalidation_user) }
@@ -852,7 +852,7 @@
describe "#invalidate" do
let(:invalidation_user) { create(:user) }
- let(:invalidation_reason) { create(:store_credit_update_reason) }
+ let(:invalidation_reason) { create(:store_credit_reason) }
before do
store_credit.save!