Sha256: 2e433e3ce784ac5c9caff2e3aa4d62b076b8476f1b15081c30e371f0647ff0eb

Contents?: true

Size: 1.54 KB

Versions: 16

Compression:

Stored size: 1.54 KB

Contents

def it_acts_as_create_command
  let(:response) { subject.class.run(params) }
  let(:resource_plural) { subject.Serializer.plural_key }
  let(:resource_singular) { subject.Serializer.singular_key }

  context "with valid params" do
    context "when creating a single item" do
      let(:item) { build("api_#{resource_singular}") }
      let(:params) { { resource_plural => [item] } }

      it_succeeds "and returns the newly created resource" do
        expect(response.result).to include(resource_plural), "The reponse should include an array of :#{resource_plural}"

        response_items = response.result[resource_plural]
        expect(response_items.length).to eq(1)

        response_item = response_items.first
        model = subject.Model.find(response_item[:id])
        expect(response_item).to eq(subject.Serializer.as_json(model))
      end
    end
  end

  context "when creating multiple items" do
    let(:item1) { build("api_#{resource_singular}".to_sym) }
    let(:item2) { build("api_#{resource_singular}".to_sym) }
    let(:params) { { resource_plural => [item1, item2] } }

    it_succeeds "and returns the newly created resources" do
      expect(response.result).to include(resource_plural), "The reponse should include an array of :#{resource_plural}"

      response_items = response.result[resource_plural]
      expect(response_items.length).to eq(2)

      response_items.each do |response_item|
        model = subject.Model.find(response_item[:id])
        expect(response_item).to eq(subject.Serializer.as_json(model))
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
restpack_service-0.0.83 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.82 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.81 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.80 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.79 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.78 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.77 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.76 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.75 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.74 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.73 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.72 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.71 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.70 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.69 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.68 lib/restpack_service/support/matchers/create_command.rb