From e79e2b660115db9d76b574ba0463bad27c3154d1 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Mon, 29 Jan 2024 15:40:44 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=97=F0=9F=A7=B9=20`Tobias`:=20Define?= =?UTF-8?q?=20`Payment`=20relationships=20and=20attributes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is not super important to the actual feature, but it does mean that the `Payment` has clearly defined relationships, with tests that confirm the relationship. It also adds a spec to check that the `#amount` value operates as a monetized value; which doesn't seem like it does that much beyond giving us an injection point for layering in additional details. --- app/furniture/tobias/payment.rb | 2 +- spec/spec_helper.rb | 1 + spec/tobias/payment_spec.rb | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 spec/tobias/payment_spec.rb diff --git a/app/furniture/tobias/payment.rb b/app/furniture/tobias/payment.rb index 34f5d7e2e..ddd1f0778 100644 --- a/app/furniture/tobias/payment.rb +++ b/app/furniture/tobias/payment.rb @@ -2,7 +2,7 @@ class Tobias class Payment < ApplicationRecord self.table_name = "tobias_payments" - belongs_to :payout + belongs_to :payout, inverse_of: :payments monetize :amount_cents end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0cc9fbf52..7cd8f9340 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ require "faker" require "pundit/rspec" require "simplecov" +require "money-rails/test_helpers" SimpleCov.start do enable_coverage :branch diff --git a/spec/tobias/payment_spec.rb b/spec/tobias/payment_spec.rb new file mode 100644 index 000000000..19607f969 --- /dev/null +++ b/spec/tobias/payment_spec.rb @@ -0,0 +1,11 @@ +require "rails_helper" + +RSpec.describe Tobias::Payment, type: :model do + describe "#payout" do + it { is_expected.to belong_to(:payout).inverse_of(:payments) } + end + + describe "#amount" do + it { is_expected.to monetize(:amount) } + end +end