spec/graphql/schema/object_spec.rb in graphql-1.8.0.pre3 vs spec/graphql/schema/object_spec.rb in graphql-1.8.0.pre4

- old
+ new

@@ -22,13 +22,13 @@ # one more than the parent class assert_equal 6, new_object_class.fields.size # inherited interfaces are present assert_equal 2, new_object_class.interfaces.size # The new field is present - assert new_object_class.fields.find { |f| f.name == "newField" } + assert new_object_class.fields.key?("newField") # The overridden field is present: - name_field = new_object_class.fields.find { |f| f.name == "name" } + name_field = new_object_class.fields["name"] assert_equal "The new description", name_field.description end it "inherits name and description" do # Manually assign a name since `.name` isn't populated for dynamic classes @@ -37,9 +37,26 @@ end new_subclass_2 = Class.new(new_subclass_1) assert_equal "NewSubclass", new_subclass_1.graphql_name assert_equal "NewSubclass", new_subclass_2.graphql_name assert_equal object_class.description, new_subclass_2.description + end + end + + describe "wrapping a Hash" do + it "automatically looks up symbol and string keys" do + query_str = <<-GRAPHQL + { + hashyEnsemble { + name + musicians { name } + } + } + GRAPHQL + res = Jazz::Schema.execute(query_str) + ensemble = res["data"]["hashyEnsemble"] + assert_equal "The Grateful Dead", ensemble["name"] + assert_equal ["Jerry Garcia"], ensemble["musicians"].map { |m| m["name"] } end end describe ".to_graphql_type" do let(:obj_type) { Jazz::Ensemble.to_graphql }