Sha256: 0dbef95346f0be8d281d5660170cb3e3e613c5fcb694172f8ac9b98f91820a53
Contents?: true
Size: 1.35 KB
Versions: 3
Compression:
Stored size: 1.35 KB
Contents
require "date" require "spec_helper" module Garden module DefinePlantBetween def self.call(plant, plant_range) plant.start_planting_on = plant_range.begin plant.end_planting_on = plant_range.end end end class Vegetable include GraphQL::Define::InstanceDefinable lazy_defined_attr_accessor :name, :start_planting_on, :end_planting_on accepts_definitions :name, plant_between: DefinePlantBetween # definition added later: lazy_defined_attr_accessor :height end end describe GraphQL::Define::InstanceDefinable do describe "extending definitions" do before do Garden::Vegetable.accepts_definitions(:height) end after do Garden::Vegetable.own_dictionary.delete(:height) end it "accepts after-the-fact definitions" do corn = Garden::Vegetable.define do name "Corn" height 8 end assert_equal "Corn", corn.name assert_equal 8, corn.height end end describe "applying custom definitions" do it "uses custom callables" do tomato = Garden::Vegetable.define do name "Tomato" plant_between Date.new(2000, 4, 20)..Date.new(2000, 6, 1) end assert_equal "Tomato", tomato.name assert_equal Date.new(2000, 4, 20), tomato.start_planting_on assert_equal Date.new(2000, 6, 1), tomato.end_planting_on end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
graphql-0.17.2 | spec/graphql/define/instance_definable_spec.rb |
graphql-0.17.1 | spec/graphql/define/instance_definable_spec.rb |
graphql-0.17.0 | spec/graphql/define/instance_definable_spec.rb |