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

Restrict deletion of payment method if associated with payments or credit cards #8055

Merged
merged 1 commit into from Jun 12, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/app/models/spree/payment_method.rb
Expand Up @@ -12,8 +12,10 @@ class PaymentMethod < Spree::Base

validates :name, presence: true

has_many :payments, class_name: "Spree::Payment", inverse_of: :payment_method
has_many :credit_cards, class_name: "Spree::CreditCard"
with_options dependent: :restrict_with_error do
has_many :payments, class_name: "Spree::Payment", inverse_of: :payment_method
has_many :credit_cards, class_name: "Spree::CreditCard"
end

def self.providers
Rails.application.config.spree.payment_methods
Expand Down
5 changes: 5 additions & 0 deletions core/spec/models/spree/payment_method_spec.rb
@@ -1,6 +1,11 @@
require 'spec_helper'

describe Spree::PaymentMethod, type: :model do
describe "Associations" do
it { is_expected.to have_many(:payments).class_name("Spree::Payment").inverse_of(:payment_method).dependent(:restrict_with_error) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [135/120]

it { is_expected.to have_many(:credit_cards).class_name("Spree::CreditCard").dependent(:restrict_with_error) }
end

context "visibility scopes" do
before do
[nil, '', 'both', 'front_end', 'back_end'].each do |display_on|
Expand Down