Skip to content

Commit

Permalink
set default values for transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
JuzerShakir committed Jan 2, 2024
1 parent d6b8d68 commit d04ff7e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 0 additions & 2 deletions app/controllers/transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def show

def new
@transaction = @thaali.transactions.new
# uncheck the default option
@transaction.mode = nil
end

def edit
Expand Down
3 changes: 3 additions & 0 deletions app/models/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class Transaction < ApplicationRecord

default_scope { order(date: :desc) }

# * Defaults
attribute :mode, default: nil

# * Associations
belongs_to :thaali

Expand Down
6 changes: 6 additions & 0 deletions spec/models/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
it { is_expected.to belong_to(:thaali) }
end

context "with attributes" do
describe "set default values of" do
it { expect(described_class.new.mode).to be_nil }
end
end

context "when validating" do
context "with mode" do
it { is_expected.to validate_presence_of(:mode).with_message("selection is required") }
Expand Down

0 comments on commit d04ff7e

Please sign in to comment.