-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42bc34d
commit 897b639
Showing
7 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class ProgressiveBillingTreshold < ApplicationRecord | ||
include PaperTrailTraceable | ||
include Currencies | ||
|
||
belongs_to :plan | ||
|
||
monetize :amount_cents | ||
|
||
validates :amount_currency, inclusion: {in: currency_list} | ||
validates :amount_cents, numericality: {greater_than: 0} | ||
validates :amount_cents, uniqueness: {scope: %i[plan_id recurring]} | ||
validates :recurring, uniqueness: {scope: :plan_id}, if: -> {recurring?} | ||
end |
15 changes: 15 additions & 0 deletions
15
db/migrate/20240802115017_create_progressive_billing_tresholds.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateProgressiveBillingTresholds < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :progressive_billing_tresholds, id: :uuid do |t| | ||
t.references :plan, null: false, index: true, foreign_key: true, type: :uuid | ||
t.string :treshold_display_name | ||
t.bigint :amount_cents, null: false | ||
t.string :amount_currency, null: false | ||
t.boolean :recurring, null: false, default: false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FactoryBot.define do | ||
factory :progressive_billing_treshold do | ||
plan | ||
treshold_display_name { Faker::Name.name } | ||
amount_cents { 100 } | ||
amount_currency { "EUR" } | ||
recurring { false } | ||
|
||
trait :recurring do | ||
recurring { true } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe ProgressiveBillingTreshold, type: :model do | ||
subject(:progressive_billing_treshold) { build(:progressive_billing_treshold) } | ||
|
||
it { is_expected.to belong_to(:plan) } | ||
|
||
it { is_expected.to validate_inclusion_of(:amount_currency).in_array(Currencies::ACCEPTED_CURRENCIES.keys) } | ||
it { is_expected.to validate_numericality_of(:amount_cents).is_greater_than(0) } | ||
it { is_expected.to validate_uniqueness_of(:amount_cents).scoped_to(%i[plan_id recurring]) } | ||
it { is_expected.to validate_uniqueness_of(:recurring).scoped_to(:plan_id) } | ||
end |