Skip to content

Commit

Permalink
Refactor epp error due to Rails 6.1 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yulgolem committed May 3, 2021
1 parent c5f8768 commit 6a878f8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/controllers/repp/v1/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def handle_errors(obj = nil, update: false)
@epp_errors ||= []

obj&.construct_epp_errors
@epp_errors += obj.errors[:epp_errors] if obj
@epp_errors += obj.errors.where(:epp_errors).map(&:options) if obj

format_epp_errors if update
@epp_errors.uniq!
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/repp/v1/domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def initiate_transfer(transfer)
@successful << { type: 'domain_transfer', domain_name: domain.name }
else
@errors << { type: 'domain_transfer', domain_name: domain.name,
errors: domain.errors[:epp_errors] }
errors: domain.errors.where(:epp_errors)[0].options }
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/interactions/actions/domain_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def initialize(domain, transfer_code, user)
end

def call
return unless domain_exists?
return unless valid_transfer_code?
return false unless domain_exists?
return false unless valid_transfer_code?

run_validations

Expand Down
7 changes: 4 additions & 3 deletions app/models/concerns/epp_errors.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module EppErrors
extend ActiveSupport::Concern
included do
attr_accessor :epp_errors
end

def construct_epp_errors
epp_errors = []
Expand All @@ -19,9 +22,7 @@ def construct_epp_errors

epp_errors << collect_parent_errors(attr, errors)
end

errors.add(:epp_errors, epp_errors)
errors[:epp_errors].flatten!
errors.add(:epp_errors, epp_errors) unless epp_errors.empty?
end

def collect_parent_errors(attr, errors)
Expand Down
8 changes: 4 additions & 4 deletions test/integration/repp/v1/domains/transfer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_does_not_transfer_domain_if_not_transferable
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]

assert_equal 'Object status prohibits operation', json[:data][:failed][0][:errors][0][:msg]
assert_equal 'Object status prohibits operation', json[:data][:failed][0][:errors][:msg]

@domain.reload

Expand All @@ -100,7 +100,7 @@ def test_does_not_transfer_domain_with_invalid_auth_code
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]

assert_equal "Invalid authorization information", json[:data][:failed][0][:errors][0][:msg]
assert_equal "Invalid authorization information", json[:data][:failed][0][:errors][:msg]
end

def test_does_not_transfer_domain_to_same_registrar
Expand All @@ -121,7 +121,7 @@ def test_does_not_transfer_domain_to_same_registrar
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]

assert_equal 'Domain already belongs to the querying registrar', json[:data][:failed][0][:errors][0][:msg]
assert_equal 'Domain already belongs to the querying registrar', json[:data][:failed][0][:errors][:msg]

@domain.reload

Expand All @@ -146,7 +146,7 @@ def test_does_not_transfer_domain_if_discarded
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]

assert_equal 'Object is not eligible for transfer', json[:data][:failed][0][:errors][0][:msg]
assert_equal 'Object is not eligible for transfer', json[:data][:failed][0][:errors][:msg]

@domain.reload

Expand Down

0 comments on commit 6a878f8

Please sign in to comment.