Sha256: ee703b607d42fd83634fd3b58cae010d5d8317b116fc0118af9d512f83180b52

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

require 'helper'

RSpec.describe Flipper::Api::Action do
  let(:action_subclass) {
    Class.new(described_class) do
      def noooope
        raise "should never run this"
      end

      def get
        [200, {}, "get"]
      end

      def post
        [200, {}, "post"]
      end

      def put
        [200, {}, "put"]
      end

      def delete
        [200, {}, "delete"]
      end
    end
  }

  it "won't run method that isn't whitelisted" do
    fake_request = Struct.new(:request_method, :env, :session).new("NOOOOPE", {}, {})
    action = action_subclass.new(flipper, fake_request)
    expect {
      action.run
    }.to raise_error(Flipper::Api::RequestMethodNotSupported)
  end

  it "will run get" do
    fake_request = Struct.new(:request_method, :env, :session).new("GET", {}, {})
    action = action_subclass.new(flipper, fake_request)
    expect(action.run).to eq([200, {}, "get"])
  end

  it "will run post" do
    fake_request = Struct.new(:request_method, :env, :session).new("POST", {}, {})
    action = action_subclass.new(flipper, fake_request)
    expect(action.run).to eq([200, {}, "post"])
  end

  it "will run put" do
    fake_request = Struct.new(:request_method, :env, :session).new("PUT", {}, {})
    action = action_subclass.new(flipper, fake_request)
    expect(action.run).to eq([200, {}, "put"])
  end

  it "will run delete" do
    fake_request = Struct.new(:request_method, :env, :session).new("DELETE", {}, {})
    action = action_subclass.new(flipper, fake_request)
    expect(action.run).to eq([200, {}, "delete"])
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flipper-api-0.9.2 spec/flipper/api/action_spec.rb
flipper-api-0.9.1 spec/flipper/api/action_spec.rb
flipper-api-0.9.0 spec/flipper/api/action_spec.rb