spec/graphql/schema/object_spec.rb in graphql-1.8.5 vs spec/graphql/schema/object_spec.rb in graphql-1.8.6
- old
+ new
@@ -39,18 +39,36 @@
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
- it "does not inherit singleton methods from base interface when implementing base interface" do
+ it "should take Ruby name (without Type suffix) as default graphql name" do
+ TestingClassType = Class.new(GraphQL::Schema::Object)
+ assert_equal "TestingClass", TestingClassType.graphql_name
+ end
+
+ it "raise on anonymous class without declared graphql name" do
+ anonymous_class = Class.new(GraphQL::Schema::Object)
+ assert_raises NotImplementedError do
+ anonymous_class.graphql_name
+ end
+ end
+ end
+
+ describe "implementing interfaces" do
+ it "raises an error when trying to implement a non-interface module" do
object_type = Class.new(GraphQL::Schema::Object)
- methods = object_type.singleton_methods
- method_defs = Hash[methods.zip(methods.map{|method| object_type.method(method.to_sym)})]
- object_type.implements(GraphQL::Schema::Interface)
- new_method_defs = Hash[methods.zip(methods.map{|method| object_type.method(method.to_sym)})]
- assert_equal method_defs, new_method_defs
+ module NotAnInterface
+ end
+
+ err = assert_raises do
+ object_type.implements(NotAnInterface)
+ end
+
+ message = "NotAnInterface cannot be implemented since it's not a GraphQL Interface. Use `include` for plain Ruby modules."
+ assert_equal message, err.message
end
it "does not inherit singleton methods from base interface when implementing another interface" do
object_type = Class.new(GraphQL::Schema::Object)
methods = object_type.singleton_methods
@@ -61,21 +79,9 @@
end
object_type.implements(InterfaceType)
new_method_defs = Hash[methods.zip(methods.map{|method| object_type.method(method.to_sym)})]
assert_equal method_defs, new_method_defs
- end
-
- it "should take Ruby name (without Type suffix) as default graphql name" do
- TestingClassType = Class.new(GraphQL::Schema::Object)
- assert_equal "TestingClass", TestingClassType.graphql_name
- end
-
- it "raise on anonymous class without declared graphql name" do
- anonymous_class = Class.new(GraphQL::Schema::Object)
- assert_raises NotImplementedError do
- anonymous_class.graphql_name
- end
end
end
describe "wrapping a Hash" do
it "automatically looks up symbol and string keys" do