spec/controllers/payanyway_controller_spec.rb in payanyway-2.2.2 vs spec/controllers/payanyway_controller_spec.rb in payanyway-2.3.0

- old
+ new

@@ -8,10 +8,19 @@ expect(response.body).to eq('FAIL') end end + describe 'POST #pay' do + + it 'should render "FAIL" text' do + post :pay + expect(response.body).to eq('FAIL') + end + + end + describe 'GET #success' do it 'should add message to logger' do expect(Rails.logger).to receive(:info).with("PAYANYWAY: Called success payment url for order '676'").and_call_original get :success, { 'MNT_TRANSACTION_ID' => 676 } @@ -40,39 +49,55 @@ get :in_progress, { 'MNT_TRANSACTION_ID' => 676 } end end - describe 'GET #check' do - context 'when empty params' do - it 'should raise error' do - expect{ get :check }.not_to raise_error + [:get, :post].each do |method| + + describe "#{method.upcase} #check" do + context 'when empty params' do + it 'should raise error' do + expect{ + public_send(method, :check) + }.not_to raise_error + end end - end - context 'when invalid signature' do - it 'should raise error' do - expect{ get(:check, { 'MNT_TRANSACTION_ID' => 676 }) }.to raise_error + context 'when invalid signature' do + it 'should raise error' do + expect{ public_send(method, :check, { 'MNT_TRANSACTION_ID' => 676 }) }.to raise_error + end end - end - context 'when valid signature' do - it 'should add message to logger' do - expect(Rails.logger).not_to receive(:info).with(/PAYANYWAY: XML response for check/) - expect_any_instance_of(Payanyway::Controller).to receive(:check_implementation).and_return(amount: 12, state: :paid) + context 'when valid signature' do + it 'should add message to logger' do + expect(Rails.logger).not_to receive(:info).with(/PAYANYWAY: XML response for check/) + expect_any_instance_of(Payanyway::Controller). + to receive(:check_implementation).and_return(amount: 12, state: :paid) - get :check, { 'MNT_ID' => Payanyway::Gateway.config['moneta_id'].to_s, 'MNT_TRANSACTION_ID' => 676, 'MNT_SIGNATURE' => '79c1c4f41a0a70bb107c976ebba25811' } + public_send method, :check, { + 'MNT_ID' => Payanyway::Gateway.config['moneta_id'].to_s, + 'MNT_TRANSACTION_ID' => 676, + 'MNT_SIGNATURE' => '79c1c4f41a0a70bb107c976ebba25811' + } - expect(Nokogiri::XML(response.body).at_css('MNT_RESPONSE')).to be_present + expect(Nokogiri::XML(response.body).at_css('MNT_RESPONSE')).to be_present + end end - end - context 'when logger flag is true' do - it 'should add message to logger' do - expect(Rails.logger).to receive(:info).with(/PAYANYWAY: XML response for check/) + context 'when logger flag is true' do + it 'should add message to logger' do + expect(Rails.logger).to receive(:info).with(/PAYANYWAY: XML response for check/) - expect_any_instance_of(Payanyway::Controller).to receive(:check_implementation).and_return(amount: 12, state: :paid, logger: true) - get :check, { 'MNT_ID' => Payanyway::Gateway.config['moneta_id'].to_s, 'MNT_TRANSACTION_ID' => 676, 'MNT_SIGNATURE' => '79c1c4f41a0a70bb107c976ebba25811' } + expect_any_instance_of(Payanyway::Controller). + to receive(:check_implementation).and_return(amount: 12, state: :paid, logger: true) + public_send method, :check, { + 'MNT_ID' => Payanyway::Gateway.config['moneta_id'].to_s, + 'MNT_TRANSACTION_ID' => 676, + 'MNT_SIGNATURE' => '79c1c4f41a0a70bb107c976ebba25811' + } + end end end + end end