-
Notifications
You must be signed in to change notification settings - Fork 385
Allow nil to be set as default currency #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -949,6 +949,25 @@ class SubProduct < Product | |||||||||||||||||
| expect(price.amount).not_to eq(value.amount) | ||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| context 'without a default currency' do | ||||||||||||||||||
| let(:product) { OtherProduct.new } | ||||||||||||||||||
|
|
||||||||||||||||||
| around do |example| | ||||||||||||||||||
| default_currency = Money.default_currency | ||||||||||||||||||
| Money.default_currency = nil | ||||||||||||||||||
|
|
||||||||||||||||||
| example.run | ||||||||||||||||||
|
|
||||||||||||||||||
| Money.default_currency = default_currency | ||||||||||||||||||
| end | ||||||||||||||||||
|
Comment on lines
+952
to
+962
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is better to use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, and apologies for the misleading comment. I have a branch with improvements to the spec, I'll remove the money-rails/spec/active_record/monetizable_spec.rb Lines 783 to 790 in c7645b0
|
||||||||||||||||||
|
|
||||||||||||||||||
| it "errors a NoCurrency Error" do | ||||||||||||||||||
| expect do | ||||||||||||||||||
| product.write_monetized :price, :price_cents, 10.5, false, nil, {} | ||||||||||||||||||
| end.to raise_error(Money::Currency::NoCurrency) | ||||||||||||||||||
| end | ||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| describe "instance_currency_name" do | ||||||||||||||||||
| it "updates instance_currency_name attribute" do | ||||||||||||||||||
| product.write_monetized :sale_price, :sale_price_amount, value, false, :sale_price_currency_code, {} | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| class OtherProduct < ActiveRecord::Base | ||
| monetize :price_cents | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| class AddOtherProducts < (Rails::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[4.2] : ActiveRecord::Migration) | ||
| def change | ||
| create_table "other_products", force: :cascade do |t| | ||
| t.string "currency" | ||
| t.integer "price_cents" | ||
| t.datetime "created_at" | ||
| t.datetime "updated_at" | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Money only supports Ruby > 3.1, it is possible to use the safe navigation operator.
This kind of issues can be spotted with RuboCop