Sha256: 161d1d0d8491e8f26c30d8f19a64842dff84540c6abda8baee3323d03743397b

Contents?: true

Size: 920 Bytes

Versions: 5

Compression:

Stored size: 920 Bytes

Contents

require 'test_helper'

describe Supercharged::ChargesController do
  describe "create action" do
    context "authorized" do
      let(:fake_user) { User.create! }

      before do
        Supercharged::ChargesController.any_instance.stubs(:current_user).returns(fake_user)
      end

      context "correct conditions" do
        it "response contains id in json" do
          post :create, charge: { amount: 100 }

          assert_response :success

          expected = {"charge"=>{"id"=>1}}
          JSON.parse(@response.body).must_equal(expected)
        end
      end

      context "bad conditions" do
        it "response contains errors in json" do
          post :create, charge: { amount: 0 }

          assert_response 422

          expected = {"errors"=>{"amount"=>["must be greater than or equal to 1"]}}
          JSON.parse(@response.body).must_equal(expected)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
supercharged-2.0.4 test/supercharged/controllers/charges_controller_test.rb
supercharged-2.0.3 test/supercharged/controllers/charges_controller_test.rb
supercharged-2.0.2 test/supercharged/controllers/charges_controller_test.rb
supercharged-2.0.1 test/supercharged/controllers/charges_controller_test.rb
supercharged-2.0.0 test/supercharged/controllers/charges_controller_test.rb