From 3c251a8fd263ff0d5de02ad3f1e2589bdaa68199 Mon Sep 17 00:00:00 2001 From: waschbar01 Date: Fri, 9 Mar 2018 19:26:24 -0600 Subject: [PATCH 1/4] hw complete --- 1.3.2' | 0 Gemfile.lock | 1 + lib/desugaring.rb | 36 ++++++++++++++++++++++++--------- lib/retail_transaction.rb | 4 ++++ test/retail_transaction_test.rb | 35 +++++++++++++++++++++++++++++++- test/test_helper.rb | 5 +++-- 6 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 1.3.2' diff --git a/1.3.2' b/1.3.2' new file mode 100644 index 0000000..e69de29 diff --git a/Gemfile.lock b/Gemfile.lock index 8c1dbb3..858d89f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,6 +23,7 @@ GEM PLATFORMS ruby + x64-mingw32 DEPENDENCIES aasm! diff --git a/lib/desugaring.rb b/lib/desugaring.rb index 8d52908..a33637b 100644 --- a/lib/desugaring.rb +++ b/lib/desugaring.rb @@ -1,9 +1,11 @@ module DesugaringExercises + # ’ not the same as ' + def all_the_sugar(recipients, event, message) mail message, - to: recipients.map(&:email), - subject: "You’re invited to #{event.title} on #{event.date}" + to: recipients.map(&:email), + subject: "You’re invited to #{event.title} on #{event.date}" end # Ruby allows you to pass arguments to a method without using parentheses. Ruby programmers lovingly @@ -21,7 +23,9 @@ def all_the_sugar(recipients, event, message) # Copy the contents of the previous method here and remove this sugar. # def desugared_poetry(recipients, event, message) - implement_me! + mail(message, + to: recipients.map(&:email), + subject: "You’re invited to #{event.title} on #{event.date}") end # Ruby allows you to pass arguments identified by name instead of just by position. They are really just @@ -36,7 +40,9 @@ def desugared_poetry(recipients, event, message) # Copy the contents of the previous method here and remove this sugar. # def desugared_named_args(recipients, event, message) - implement_me! + mail(message, + {to: recipients.map(&:email), + subject: "You’re invited to #{event.title} on #{event.date}"}) end # Ruby’s general syntax for hashes is `{key => value, key => value, ...}`. Because it is so common to use @@ -51,7 +57,9 @@ def desugared_named_args(recipients, event, message) # Copy the contents of the previous method here and remove this sugar. # def desugared_symbol_keys(recipients, event, message) - implement_me! + mail(message, + {:to => recipients.map(&:email), + :subject => "You’re invited to #{event.title} on #{event.date}"}) end # You may be wondering how `map(&:email)` works. When you precede the last argument of a method call with @@ -70,7 +78,9 @@ def desugared_symbol_keys(recipients, event, message) # Copy the contents of the previous method here and remove this sugar. # def desugared_attr_proc(recipients, event, message) - implement_me! + mail(message, + {:to => recipients.map{ |x| x.email }, + :subject => "You’re invited to #{event.title} on #{event.date}"}) end # You may recall from the Ruby koans that when you put `#{something}` in a `"`-delimited string, Ruby will @@ -88,7 +98,9 @@ def desugared_attr_proc(recipients, event, message) # Copy the contents of the previous method here and remove this sugar. # def desugared_interpolation(recipients, event, message) - implement_me! + mail(message, + {:to => recipients.map{ |x| x.email }, + :subject => "You’re invited to " + event.title.to_s + " on " + event.date.to_s}) end # Ruby tracks local variables lexically at compile time. Wherever you say `x = y`, the compiler assumes that @@ -110,7 +122,9 @@ def desugared_interpolation(recipients, event, message) # (Think: which names are local variables, and which are not?) # def desugared_implicit_self(recipients, event, message) - implement_me! + self.mail(message, + {:to => recipients.map{ |x| x.email }, + :subject => "You’re invited to " + event.title.to_s + " on " + event.date.to_s}) end # In Ruby, unlike Python, there are no properties distinct from method calls. When you say `x.y`, you are @@ -131,7 +145,9 @@ def desugared_implicit_self(recipients, event, message) # but structurally quite similar! # def desugared_implicit_parens(recipients, event, message) - implement_me! + self.mail(message, + {:to => recipients.map(){ |x| x.email() }, + :subject => "You’re invited to " + event.title().to_s() + " on " + event.date().to_s()}) end # In Ruby, every value is an object and every action is a method call. That includes operators. A binary @@ -153,7 +169,7 @@ def desugared_implicit_parens(recipients, event, message) # get added before the things on the right. (a + b + c) means ((a + b) + c), NOT (a + (b + c)). # def desugared_operators(recipients, event, message) - implement_me! + self.mail(message,{:to => recipients.map(){|x|x.email() }, :subject => ((("You’re invited to ".+event.title().to_s()).+(" on ")).(+event.date().to_s()))}) end # Compare that to the version at the top. diff --git a/lib/retail_transaction.rb b/lib/retail_transaction.rb index 1bfa0e3..c14b73a 100644 --- a/lib/retail_transaction.rb +++ b/lib/retail_transaction.rb @@ -39,6 +39,7 @@ def paid? state :processing_payment state :payment_declined state :settled + state :refunded event :check_out do transitions from: :ringing_up, to: :collecting_payment, @@ -61,5 +62,8 @@ def paid? event :payment_declined do transitions from: :processing_payment, to: :payment_declined end + + event :refund do + end end end diff --git a/test/retail_transaction_test.rb b/test/retail_transaction_test.rb index 823cbfe..c07aa55 100644 --- a/test/retail_transaction_test.rb +++ b/test/retail_transaction_test.rb @@ -103,6 +103,11 @@ assert_equal false, tx.settled? assert_equal true, tx.payment_declined? end + + # No. 2 - ensure can't be refunded + it "cannot be refunded" do + assert_invalid_transition{ tx.refund! } + end end describe "with declined payment" do @@ -114,6 +119,11 @@ tx.payment_declined! end + # No. 2 - ensure can't be refunded + it "cannot be refunded" do + assert_invalid_transition{ tx.refund! } + end + it "cannot add more items" do assert_raises do tx.add_item("half a slice of bologna") @@ -149,8 +159,31 @@ tx.payment_authorized! end + # Settled cannot be reopened + it "cannot be reopened" do + assert_invalid_transition { tx.reopen! } + end + + it "can be refunded" do + tx.refund! + assert_equal false, tx.settled? + assert_equal true, tx.refunded? + end + end + + it "cannot be refunded a second time" do + assert_invalid_transition {tx. refund! } + + # No. 5 Refunded cannot be reopened, same as settled it "cannot be reopened" do - assert_invalid_transition { tx.reopen! } + assert_invalid_transition { tx.refund! } end + end + + # Refund tests + # 1. Test that ensures a settled order can be refunded + # 3. New describe group for orders that are already refunded + # 4. Test transactions cannot be refunded a second time + # 5. Test a refunded order cannot be reopened end diff --git a/test/test_helper.rb b/test/test_helper.rb index a343433..296289d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,8 +8,9 @@ # To see full test names when running tests: # -# require "minitest/reporters" -# Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new +# only helpful for retail transaction tests/dedbolt +#require "minitest/reporters" +#Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new module Minitest::Assertions def assert_invalid_transition From 53ee4dd0cffb9c1151847af130412605c2eff77d Mon Sep 17 00:00:00 2001 From: waschbar01 Date: Fri, 9 Mar 2018 19:28:39 -0600 Subject: [PATCH 2/4] hw complete not sure why these changes didn't commit? --- lib/retail_transaction.rb | 1 + test/retail_transaction_test.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/retail_transaction.rb b/lib/retail_transaction.rb index c14b73a..545e1f0 100644 --- a/lib/retail_transaction.rb +++ b/lib/retail_transaction.rb @@ -64,6 +64,7 @@ def paid? end event :refund do + transitions from: :settled, to: :refunded end end end diff --git a/test/retail_transaction_test.rb b/test/retail_transaction_test.rb index c07aa55..b20ad40 100644 --- a/test/retail_transaction_test.rb +++ b/test/retail_transaction_test.rb @@ -164,6 +164,7 @@ assert_invalid_transition { tx.reopen! } end + # No. 1: check if can be refunded? it "can be refunded" do tx.refund! assert_equal false, tx.settled? @@ -171,8 +172,11 @@ end end + describe "refunded" do # No 3. describe group for orders already refunded/in refund state + # No. 4 Cannot be refunded for second time it "cannot be refunded a second time" do assert_invalid_transition {tx. refund! } + end # No. 5 Refunded cannot be reopened, same as settled it "cannot be reopened" do @@ -183,6 +187,7 @@ # Refund tests # 1. Test that ensures a settled order can be refunded + # 2. Add tests to one or two other states that ensure they cannot be refunded # 3. New describe group for orders that are already refunded # 4. Test transactions cannot be refunded a second time # 5. Test a refunded order cannot be reopened From c8c05b5ef75df742f99b4e4953cb7c1cbed112cf Mon Sep 17 00:00:00 2001 From: waschbar01 Date: Fri, 9 Mar 2018 19:36:23 -0600 Subject: [PATCH 3/4] Fix bug; alll tests pass now --- lib/desugaring.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/desugaring.rb b/lib/desugaring.rb index a33637b..62481a5 100644 --- a/lib/desugaring.rb +++ b/lib/desugaring.rb @@ -169,7 +169,7 @@ def desugared_implicit_parens(recipients, event, message) # get added before the things on the right. (a + b + c) means ((a + b) + c), NOT (a + (b + c)). # def desugared_operators(recipients, event, message) - self.mail(message,{:to => recipients.map(){|x|x.email() }, :subject => ((("You’re invited to ".+event.title().to_s()).+(" on ")).(+event.date().to_s()))}) + self.mail(message,{:to => recipients.map(){ |x| x.email() }, :subject => ((("You’re invited to ".+(event.title.to_s())).+(' on ')).+(event.date.to_s()))}) end # Compare that to the version at the top. From b32b07b5b02c8fa0f2705d2e2f660ca3ecd3ba59 Mon Sep 17 00:00:00 2001 From: waschbar01 Date: Fri, 9 Mar 2018 19:41:37 -0600 Subject: [PATCH 4/4] Fixed overlook was changed to refund! from reopen! --- test/retail_transaction_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/retail_transaction_test.rb b/test/retail_transaction_test.rb index b20ad40..5153eb5 100644 --- a/test/retail_transaction_test.rb +++ b/test/retail_transaction_test.rb @@ -180,7 +180,7 @@ # No. 5 Refunded cannot be reopened, same as settled it "cannot be reopened" do - assert_invalid_transition { tx.refund! } + assert_invalid_transition { tx.reopen! } end end