spec/graphql/define/instance_definable_spec.rb in graphql-1.2.4 vs spec/graphql/define/instance_definable_spec.rb in graphql-1.2.5

- old
+ new

@@ -16,10 +16,14 @@ accepts_definitions :name, plant_between: DefinePlantBetween, color: GraphQL::Define.assign_metadata_key(:color) # definition added later: attr_accessor :height ensure_defined(:height) + + def color + metadata[:color] + end end end describe GraphQL::Define::InstanceDefinable do describe "extending definitions" do @@ -82,17 +86,26 @@ red_arugula = arugula.redefine(color: :red) renamed_red_arugula = red_arugula.redefine do name "Renamed Red Arugula" end - assert_equal :green, arugula.metadata[:color] + assert_equal :green, arugula.color assert_equal "Arugula", arugula.name - assert_equal :red, red_arugula.metadata[:color] + assert_equal :red, red_arugula.color assert_equal "Arugula", red_arugula.name - assert_equal :red, renamed_red_arugula.metadata[:color] + assert_equal :red, renamed_red_arugula.color assert_equal "Renamed Red Arugula", renamed_red_arugula.name + end + + it "can be chained several times" do + arugula_1 = Garden::Vegetable.define(name: "Arugula") { color :green } + arugula_2 = arugula_1.redefine { color :red } + arugula_3 = arugula_2.redefine { plant_between(1..3) } + assert_equal ["Arugula", :green], [arugula_1.name, arugula_1.color] + assert_equal ["Arugula", :red], [arugula_2.name, arugula_2.color] + assert_equal ["Arugula", :red], [arugula_3.name, arugula_3.color] end end describe "#metadata" do it "gets values from definitions" do