Sha256: 8386520e7676d101947d6aa961707122b30efabc89c2fb7d2a5648b2148f4320

Contents?: true

Size: 1.43 KB

Versions: 9

Compression:

Stored size: 1.43 KB

Contents

def it_acts_as_create_command(namespace, type)
  plural = type.to_s.pluralize.to_sym
  namespaced_type = "#{namespace.to_s.camelize}::#{type.to_s.camelize}"
  model_class = "Models::#{namespaced_type}".constantize
  serializer_class = "Serializers::#{namespaced_type}".constantize

  let(:response) { subject.class.run(params) }

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

      it "returns the newly created #{type}" do
        response.success?.should == true
        response.result.should include(plural), "The reponse should include :#{plural} array"

        response_items = response.result[plural]
        response_items.length.should == 1
        response_item = response_items.first

        model = model_class.find(response_item[:id])
        response_item.should == serializer_class.as_json(model)
      end
    end

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

      it "returns the newly created #{type}s" do
        response.success?.should == true
        response.result.should include(plural), "The reponse should include :#{plural} array"

        response_items = response.result[plural]
        response_items.length.should == 2
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
restpack_service-0.0.67 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.66 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.65 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.64 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.63 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.62 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.61 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.60 lib/restpack_service/support/matchers/create_command.rb
restpack_service-0.0.59 lib/restpack_service/support/matchers/create_command.rb