<commit_before>module Spree
  class Subscription < ActiveRecord::Base
    include RoleSubscriber
    include RestrictiveDestroyer
    include ApiHandler

    acts_as_restrictive_destroyer column: :unsubscribed_at
    attr_accessor :card_token

    belongs_to :plan
    belongs_to :user
    has_many :events, class_name: 'Spree::SubscriptionEvent'

    validates :plan_id, :email, :user_id, presence: true
    validates :plan_id, uniqueness: { scope: [:user_id, :unsubscribed_at] }
    validates :user_id, uniqueness: { scope: :unsubscribed_at }

    delegate_belongs_to :plan, :api_plan_id
    before_validation :set_email, on: :create

    validate :verify_plan, on: :create

    private

    def set_email
      self.email = user.try(:email)
    end

    def verify_plan
      errors.add :plan_id, "is not active." unless plan.try(:visible?)
    end
  end
end<commit_msg>permit one user to subscribe multiple plan<commit_after>module Spree
  class Subscription < ActiveRecord::Base
    include RoleSubscriber
    include RestrictiveDestroyer
    include ApiHandler

    acts_as_restrictive_destroyer column: :unsubscribed_at
    attr_accessor :card_token

    belongs_to :plan
    belongs_to :user
    has_many :events, class_name: 'Spree::SubscriptionEvent'

    validates :plan_id, :email, :user_id, presence: true
    validates :plan_id, uniqueness: { scope: [:user_id, :unsubscribed_at] }

    delegate_belongs_to :plan, :api_plan_id
    before_validation :set_email, on: :create

    validate :verify_plan, on: :create

    private

    def set_email
      self.email = user.try(:email)
    end

    def verify_plan
      errors.add :plan_id, "is not active." unless plan.try(:visible?)
    end
  end
end
{'fraction_non_alphanumeric': 0.07890122735242548, 'fraction_numerical': 0.0, 'mean_word_length': 3.808988764044944, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1663463', 'n_tokens_mistral': 557, 'n_tokens_neox': 544, 'n_words': 140}