Skip to content

Commit

Permalink
Revert "Replace usage of request.fullpath / request.referrer with obj…
Browse files Browse the repository at this point in the history
…ect entity approach."

This reverts commit c51da14.
  • Loading branch information
steveyken committed Dec 5, 2023
1 parent 7c13e93 commit 233d870
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
13 changes: 7 additions & 6 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ def link_to_delete(record, options = {})

#----------------------------------------------------------------------------
def link_to_discard(object)
if entity.present?
link_to(t(:discard),
url_for(controller: entity.class.to_s.tableize, action: 'discard', id: entity.id, attachment: object.class.name, attachment_id: object.id),
method: :post,
remote: true)
end
current_url = (request.xhr? ? request.referer : request.fullpath)
parent, parent_id = current_url.scan(%r{/(\w+)/(\d+)}).flatten

link_to(t(:discard),
url_for(controller: parent, action: :discard, id: parent_id, attachment: object.class.name, attachment_id: object.id),
method: :post,
remote: true)
end

#----------------------------------------------------------------------------
Expand Down
19 changes: 7 additions & 12 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,13 @@
end
end

describe "link_to_discard" do
let(:contact) { create(:contact) }
let(:opportunity) { create(:opportunity) }
before do
contact.opportunities << opportunity
allow(helper).to receive(:entity).and_return(contact)
end
it do
link = helper.link_to_discard(opportunity)
expect(link).to match(%r{contacts/#{contact.id}/discard})
expect(link).to match(/attachment=Opportunity&amp;attachment_id=#{opportunity.id}/)
end
it "link_to_discard" do
lead = create(:lead)
allow(controller.request).to receive(:fullpath).and_return("http://www.example.com/leads/#{lead.id}")

link = helper.link_to_discard(lead)
expect(link).to match(%r{leads/#{lead.id}/discard})
expect(link).to match(/attachment=Lead&amp;attachment_id=#{lead.id}/)
end

describe "shown_on_landing_page?" do
Expand Down

0 comments on commit 233d870

Please sign in to comment.