diff --git a/.rubocop.yml b/.rubocop.yml index ca9ec06b0c96f156ee1685df2e895d9c483439cf..d290352114c201c1732fcbf97f9267f89294494b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -67,6 +67,9 @@ Layout/AccessModifierIndentation: Layout/FirstParameterIndentation: EnforcedStyle: consistent +Layout/MultilineMethodCallIndentation: + EnforcedStyle: indented + Style/AccessModifierDeclarations: Enabled: false diff --git a/lib/bill_plan_command.rb b/lib/bill_plan_command.rb index c1a87308eeda3ee0db6ac88bc71b8e9cd70c7986..e46bb508ca644af1ba53788df157decebb1abda7 100644 --- a/lib/bill_plan_command.rb +++ b/lib/bill_plan_command.rb @@ -3,6 +3,7 @@ class BillPlanCommand def self.for(customer) return ForUnregistered.new(customer) unless customer.registered? + return ForNotExpired.new(customer) unless customer.expires_at <= Time.now unless customer.balance > customer.monthly_price return ForLowBalance.new(customer) @@ -16,10 +17,15 @@ class BillPlanCommand end def call - @customer.bill_plan(note: "Renew account plan") + billed = @customer.bill_plan(note: "Renew account plan") { |db| + @customer = Command.execution.customer_repo.with(db: db) + .find(@customer.customer_id).sync + @customer.balance > @customer.monthly_price && + @customer.expires_at <= Time.now + } Command.reply do |reply| - reply.note_type = :info - reply.note_text = "#{@customer.customer_id} billed" + reply.note_type = billed ? :info : :error + reply.note_text = "#{@customer.customer_id}#{billed ? '' : ' not'} billed" end end @@ -70,4 +76,17 @@ class BillPlanCommand end end end + + class ForNotExpired + def initialize(customer) + @customer = customer + end + + def call + Command.reply do |reply| + reply.note_type = :error + reply.note_text = "#{@customer.customer_id} is not expired" + end + end + end end diff --git a/lib/customer_plan.rb b/lib/customer_plan.rb index c349a546bfb572ee808ef36a427874bb7032f485..f4716a3bbd27e24c25501ab59740e5f7a58ce84f 100644 --- a/lib/customer_plan.rb +++ b/lib/customer_plan.rb @@ -71,9 +71,12 @@ class CustomerPlan def bill_plan(note: nil) EM.promise_fiber do - DB.transaction do + DB.transaction do |db| + next false unless !block_given? || yield(db) + charge_for_plan(note) add_one_month_to_current_plan unless activate_plan_starting_now + true end end end diff --git a/sgx_jmp.rb b/sgx_jmp.rb index 5fc7c4254dd3c849e21a6cc1df4711e6e4036d81..ad80b29feae13641e7ae35852c9e3c4c7f3e45d2 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -46,8 +46,7 @@ module SentryOugai end LOG.extend SentryOugai -CONFIG = - Dhall::Coder +CONFIG = Dhall::Coder .new(safe: Dhall::Coder::JSON_LIKE + [Symbol, Proc]) .load( "(#{ARGV[0]}) : #{__dir__}/config-schema.dhall", diff --git a/test/test_electrum.rb b/test/test_electrum.rb index 316c580852901311f4b812cb5b43d8148894db93..28290c6a8de342eca34b7157335573b3df0a30e1 100644 --- a/test/test_electrum.rb +++ b/test/test_electrum.rb @@ -28,8 +28,7 @@ class ElectrumTest < Minitest::Test property(:getaddresshistory) { string(:alnum) } em :test_getaddresshistory def getaddresshistory(address) - req = - stub_rpc("getaddresshistory", address: address) + req = stub_rpc("getaddresshistory", address: address) .to_return(body: { result: "result" }.to_json) assert_equal "result", @electrum.getaddresshistory(address).sync assert_requested(req) @@ -38,8 +37,7 @@ class ElectrumTest < Minitest::Test property(:get_tx_status) { string(:alnum) } em :test_get_tx_status def get_tx_status(tx_hash) - req = - stub_rpc("get_tx_status", txid: tx_hash) + req = stub_rpc("get_tx_status", txid: tx_hash) .to_return(body: { result: "result" }.to_json) assert_equal "result", @electrum.get_tx_status(tx_hash).sync assert_requested(req) @@ -48,11 +46,9 @@ class ElectrumTest < Minitest::Test property(:gettransaction) { [string(:alnum), string(:xdigit)] } em :test_gettransaction def gettransaction(tx_hash, dummy_tx) - req1 = - stub_rpc("gettransaction", txid: tx_hash) + req1 = stub_rpc("gettransaction", txid: tx_hash) .to_return(body: { result: dummy_tx }.to_json) - req2 = - stub_rpc("deserialize", [dummy_tx]) + req2 = stub_rpc("deserialize", [dummy_tx]) .to_return(body: { result: { outputs: [] } }.to_json) assert_kind_of Electrum::Transaction, @electrum.gettransaction(tx_hash).sync assert_requested(req1) diff --git a/test/test_tel_selections.rb b/test/test_tel_selections.rb index 1285fd05dc99a78cc8f30a039d67d6a7ac77a0b5..5bc15b7ae4fc4f18c64482c0f94fc51043008170 100644 --- a/test/test_tel_selections.rb +++ b/test/test_tel_selections.rb @@ -26,8 +26,7 @@ class TelSelectionsTest < Minitest::Test def test_for_no_rsm form = Blather::Stanza::X.new form.fields = [{ var: "q", value: "226" }] - iris_query = - TelSelections::ChooseTel::AvailableNumber + iris_query = TelSelections::ChooseTel::AvailableNumber .for(form) .instance_variable_get(:@iris_query) assert_equal( @@ -44,8 +43,7 @@ class TelSelectionsTest < Minitest::Test max 500 end end - iris_query = - TelSelections::ChooseTel::AvailableNumber + iris_query = TelSelections::ChooseTel::AvailableNumber .for(form) .instance_variable_get(:@iris_query) assert_equal(