Skip to content

Commit

Permalink
feat(dunning): Organization has many dunning campaigns
Browse files Browse the repository at this point in the history
  • Loading branch information
rsempe committed Oct 11, 2024
1 parent 82c6a34 commit c6360f3
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/models/dunning_campaign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class DunningCampaign < ApplicationRecord
include PaperTrailTraceable

belongs_to :organization
has_many :thresholds, class_name: "DunningCampaignThreshold", dependent: :destroy

validates :name, presence: true
validates :days_between_attempts, numericality: {greater_than: 0}
Expand Down
1 change: 1 addition & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Organization < ApplicationRecord
has_many :cached_aggregations
has_many :data_exports
has_many :error_details
has_many :dunning_campaigns

has_many :stripe_payment_providers, class_name: 'PaymentProviders::StripeProvider'
has_many :gocardless_payment_providers, class_name: 'PaymentProviders::GocardlessProvider'
Expand Down
4 changes: 0 additions & 4 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions spec/models/dunning_campaign_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
it_behaves_like "paper_trail traceable"

it { is_expected.to belong_to(:organization) }
it { is_expected.to have_many(:thresholds).dependent(:destroy) }

it { is_expected.to validate_presence_of(:name) }

it { is_expected.to validate_numericality_of(:days_between_attempts).is_greater_than(0)}
it { is_expected.to validate_numericality_of(:max_attempts).is_greater_than(0)}
it { is_expected.to validate_numericality_of(:days_between_attempts).is_greater_than(0) }
it { is_expected.to validate_numericality_of(:max_attempts).is_greater_than(0) }

it { is_expected.to validate_uniqueness_of(:code).scoped_to(:organization_id) }
end
1 change: 1 addition & 0 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
it { is_expected.to have_many(:netsuite_integrations) }
it { is_expected.to have_many(:xero_integrations) }
it { is_expected.to have_many(:data_exports) }
it { is_expected.to have_many(:dunning_campaigns) }

it { is_expected.to validate_inclusion_of(:default_currency).in_array(described_class.currency_list) }

Expand Down

0 comments on commit c6360f3

Please sign in to comment.