require 'spec_helper' require 'mercado_pago_rails/mercado_pago_rails_helper' require_relative 'test_contexts' describe MercadoPagoRailsHelper do describe "#set_handlers" do context "when not all handlers are set" do it "it raises an exception" do expect { MercadoPagoRailsHelper.set_handlers(approved: TestContexts::ApprovedContext, pending: TestContexts::PendingContext, in_process: TestContexts::InProcessContext, in_mediation: TestContexts::InMediationContext, rejected: TestContexts::RejectedContext, cancelled: TestContexts::CancelledContext) }.to raise_error end end context "when all handlers are set" do before do MercadoPagoRailsHelper.set_handlers(approved: TestContexts::ApprovedContext, pending: TestContexts::PendingContext, in_process: TestContexts::InProcessContext, in_mediation: TestContexts::InMediationContext, rejected: TestContexts::RejectedContext, cancelled: TestContexts::CancelledContext, refunded: TestContexts::RefundedContext) end it "it returns the right context for approved status" do MercadoPagoRailsHelper.get_context(get_response(MercadoPagoRailsHelper::APPROVED.to_s), nil).class.should eq TestContexts::ApprovedContext end it "it returns the right context for pending status" do MercadoPagoRailsHelper.get_context(get_response(MercadoPagoRailsHelper::PENDING.to_s), nil).class.should eq TestContexts::PendingContext end it "it returns the right context for in_process status" do MercadoPagoRailsHelper.get_context(get_response(MercadoPagoRailsHelper::IN_PROCESS.to_s), nil).class.should eq TestContexts::InProcessContext end it "it returns the right context for in mediation status" do MercadoPagoRailsHelper.get_context(get_response(MercadoPagoRailsHelper::IN_MEDIATION.to_s), nil).class.should eq TestContexts::InMediationContext end it "it returns the right context for rejected status" do MercadoPagoRailsHelper.get_context(get_response(MercadoPagoRailsHelper::REJECTED.to_s), nil).class.should eq TestContexts::RejectedContext end it "it returns the right context for cancelled status" do MercadoPagoRailsHelper.get_context(get_response(MercadoPagoRailsHelper::CANCELLED.to_s), nil).class.should eq TestContexts::CancelledContext end it "it returns the right context for refunded status" do MercadoPagoRailsHelper.get_context(get_response(MercadoPagoRailsHelper::REFUNDED.to_s), nil).class.should eq TestContexts::RefundedContext end end end def get_response(status) {'response' => { 'collection' => { 'status' => status } } } end end