Sha256: e4cc34b8a51f852308807ba86987334e49cac0bca8ef6092e8e8d4ed1ca90ca4
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
require "spec_helper" describe AdaptivePayments::Node do let(:child_model) do Class.new(AdaptivePayments::JsonModel) do attribute :example, String end end let(:model) do klass = child_model Class.new(AdaptivePayments::JsonModel) do attribute :child, AdaptivePayments::Node[klass] end end describe "default type" do let(:child) { model.new.child } it "is an instance of the boxed type" do expect(child).to be_an_instance_of(child_model) end end describe "coercion" do let(:object) { model.new(:child => { :example => "anything" }) } it "coerces hash to instances of the given type" do expect(object.child).to be_an_instance_of(child_model) end it "maintains the original keys" do expect(object.child.example).to eq("anything") end end describe "#to_json" do context "when not empty" do let(:json) { model.new(:child => { :example => "whatever" }).to_json } it "is present as a child in the output" do expect(json).to eq('{"child":{"example":"whatever"}}') end end context "when empty" do let(:json) { model.new.to_json } it "is omitted from the output" do expect(json).to eq('{}') end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
creative-pp-adaptive-1.1.1 | spec/public/node_spec.rb |