require 'spec_helper'

describe "Log entries", type: :feature do
  stub_authorization!

  let!(:payment) { create(:payment) }

  context "with a successful log entry" do
    before do
      response = ActiveMerchant::Billing::Response.new(
        true,
        "Transaction successful",
        transid: "ABCD1234"
      )

      payment.log_entries.create(
        source: payment.source,
        details: response.to_yaml
      )
    end

    it "shows a successful attempt" do
      visit spree.admin_order_payments_path(payment.order)
      click_on payment.number
      click_link "Logs"
      within("#listing_log_entries") do
        expect(page).to have_content("Transaction successful")
      end
    end
  end

  context "with a failed log entry" do
    before do
      response = ActiveMerchant::Billing::Response.new(
        false,
        "Transaction failed",
        transid: "ABCD1234"
      )

      payment.log_entries.create(
        source: payment.source,
        details: response.to_yaml
      )
    end

    it "shows a failed attempt" do
      visit spree.admin_order_payments_path(payment.order)
      click_on payment.number
      click_link "Logs"
      within("#listing_log_entries") do
        expect(page).to have_content("Transaction failed")
      end
    end
  end
end

require 'spec_helper'

describe "Log entries", type: :feature do
  stub_authorization!

  let!(:payment) { create(:payment) }

  context "with a successful log entry" do
    before do
      response = ActiveMerchant::Billing::Response.new(
        true,
        "Transaction successful",
        transid: "ABCD1234"
      )

      payment.log_entries.create(
        details: response.to_yaml
      )
    end

    it "shows a successful attempt" do
      visit spree.admin_order_payments_path(payment.order)
      click_on payment.number
      click_link "Logs"
      within("#listing_log_entries") do
        expect(page).to have_content("Transaction successful")
      end
    end
  end

  context "with a failed log entry" do
    before do
      response = ActiveMerchant::Billing::Response.new(
        false,
        "Transaction failed",
        transid: "ABCD1234"
      )

      payment.log_entries.create(
        source: payment.source,
        details: response.to_yaml
      )
    end

    it "shows a failed attempt" do
      visit spree.admin_order_payments_path(payment.order)
      click_on payment.number
      click_link "Logs"
      within("#listing_log_entries") do
        expect(page).to have_content("Transaction failed")
      end
    end
  end
end

Remove silly broken assignment in spec
Remove silly broken assignment in spec

This is trying to assign the payment's source to source. Not only is
that the wrong thing to do (a payment is the source of a log_entry), but
since it's being built through the payment.log_entries association, it
will have no effect.

Sometimes two wrongs do make a right!
