lib/restpack_service/support/matchers.rb in restpack_service-0.0.49 vs lib/restpack_service/support/matchers.rb in restpack_service-0.0.50

- old
+ new

@@ -1,5 +1,7 @@ +require_relative 'matchers/create_command' + def is_required(*params) params.each do |param| it ":#{param} parameter must be required" do expect(subject.class.input_filters.required_inputs).to include(param) end @@ -25,49 +27,8 @@ def service_should_map(param, map) context param do map.each do |value, expected| service_request_with(param, value) { |r| r[param].should == expected } - end - end -end - -def it_acts_as_create_command(type) - plural = "#{type}s".to_sym - model_class = "Models::#{type.capitalize}".constantize - serializer_class = "Serializers::#{type.capitalize}".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