@@ -377,97 +377,6 @@ def the_parsed_query_string_from(request)
377377 end
378378 end
379379
380- describe "when converting to json" do
381- before do
382- @request = Puppet ::Indirector ::Request . new ( :facts , :find , "foo" , nil )
383- end
384-
385- it "should set the 'key'" do
386- @request . should set_json_attribute ( "key" ) . to ( "foo" )
387- end
388-
389- it "should include an attribute for its indirection name" do
390- @request . should set_json_attribute ( "type" ) . to ( "facts" )
391- end
392-
393- it "should include a 'method' attribute set to its method" do
394- @request . should set_json_attribute ( "method" ) . to ( "find" )
395- end
396-
397- it "should add all attributes under the 'attributes' attribute" do
398- @request . ip = "127.0.0.1"
399- @request . should set_json_attribute ( "attributes" , "ip" ) . to ( "127.0.0.1" )
400- end
401-
402- it "should add all options under the 'attributes' attribute" do
403- @request . options [ "opt" ] = "value"
404- PSON . parse ( @request . to_pson ) [ 'attributes' ] [ 'opt' ] . should == "value"
405- end
406-
407- it "should include the instance if provided" do
408- facts = Puppet ::Node ::Facts . new ( "foo" )
409- @request . instance = facts
410- PSON . parse ( @request . to_pson ) [ 'instance' ] . should be_instance_of ( Hash )
411- end
412- end
413-
414- describe "when converting from json" do
415- before do
416- @request = Puppet ::Indirector ::Request . new ( :facts , :find , "foo" , nil )
417- @klass = Puppet ::Indirector ::Request
418- @format = Puppet ::Network ::FormatHandler . format ( 'pson' )
419- end
420-
421- def from_json ( json )
422- @format . intern ( Puppet ::Indirector ::Request , json )
423- end
424-
425- it "should set the 'key'" do
426- from_json ( @request . to_pson ) . key . should == "foo"
427- end
428-
429- it "should fail if no key is provided" do
430- json = PSON . parse ( @request . to_pson )
431- json . delete ( "key" )
432- expect { from_json ( json . to_pson ) } . to raise_error ( ArgumentError )
433- end
434-
435- it "should set its indirector name" do
436- from_json ( @request . to_pson ) . indirection_name . should == :facts
437- end
438-
439- it "should fail if no type is provided" do
440- json = PSON . parse ( @request . to_pson )
441- json . delete ( "type" )
442- expect { from_json ( json . to_pson ) } . to raise_error ( ArgumentError )
443- end
444-
445- it "should set its method" do
446- from_json ( @request . to_pson ) . method . should == "find"
447- end
448-
449- it "should fail if no method is provided" do
450- json = PSON . parse ( @request . to_pson )
451- json . delete ( "method" )
452- expect { from_json ( json . to_pson ) } . to raise_error ( ArgumentError )
453- end
454-
455- it "should initialize with all attributes and options" do
456- @request . ip = "127.0.0.1"
457- @request . options [ "opt" ] = "value"
458- result = from_json ( @request . to_pson )
459- result . options [ :opt ] . should == "value"
460- result . ip . should == "127.0.0.1"
461- end
462-
463- it "should set its instance as an instance if one is provided" do
464- facts = Puppet ::Node ::Facts . new ( "foo" )
465- @request . instance = facts
466- result = from_json ( @request . to_pson )
467- result . instance . should be_instance_of ( Puppet ::Node ::Facts )
468- end
469- end
470-
471380 context '#do_request' do
472381 before :each do
473382 @request = Puppet ::Indirector ::Request . new ( :myind , :find , "my key" , nil )
0 commit comments