Created
August 11, 2015 19:03
-
-
Save dcaliri/81f6091783180a00bac1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/models/registration.rb b/app/models/registration.rb | |
index ac4c0e7..823f956 100644 | |
--- a/app/models/registration.rb | |
+++ b/app/models/registration.rb | |
@@ -962,12 +962,15 @@ class Registration < ActiveRecord::Base | |
self.country == country | |
end | |
- def can_be_cancelled_by_attendee? | |
- # we can't cancel a registration that has been more than 7 days from creation | |
- # more info: http://www.procon.sp.gov.br/texto.asp?id=3316 | |
- brazilian_refund_law = is_from?('Brasil') && created_at > 7.days.ago | |
+ def are_we_obligated_to_refund? | |
+ # http://www.procon.sp.gov.br/texto.asp?id=3316 | |
+ is_from?('Brasil') && | |
+ (self.created_at + 7.days) > Time.now && | |
+ (self.event.start_date - 2.days) > Time.now | |
+ end | |
- is_owner? && (free? || current_payment.nil? || brazilian_refund_law) | |
+ def can_be_cancelled_by_attendee? | |
+ is_owner? && (free? || current_payment.nil? || are_we_obligated_to_refund?) | |
end | |
def can_be_refunded_by_organizer? | |
diff --git a/test/unit/registration_test.rb b/test/unit/registration_test.rb | |
index 62a1925..16fac5e 100644 | |
--- a/test/unit/registration_test.rb | |
+++ b/test/unit/registration_test.rb | |
@@ -1166,6 +1166,22 @@ class RegistrationTest < ActiveSupport::TestCase | |
assert @registration.current_boleto_url | |
end | |
+ should 'be cancelable by attendee if still unpaid' do | |
+ assert_nil @registration.purchased_at | |
+ assert @registration.can_be_cancelled_by_attendee? | |
+ end | |
+ | |
+ context 'was paid' do | |
+ setup do | |
+ @registration.update_column :purchased_at, 1.hour.ago | |
+ end | |
+ | |
+ should 'be cancelable if the event date is after 2 days from now and it hasn not been more than 7 days since the attendee registered' do | |
+ puts "Evento el dia: #{@event.start_date}" | |
+ puts "Se registró el #{@registration.created_at}" | |
+ end | |
+ end | |
+ | |
context 'boleto bancario is dued' do | |
setup do | |
@boleto = @registration.boleto_bancarios.where(amount: @registration.current_available_amount).first |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment