Sha256: aeda29350e75acfa24bda4ab9327cfa74f439154072eea5ea9a8771df5ab983e
Contents?: true
Size: 1.77 KB
Versions: 10
Compression:
Stored size: 1.77 KB
Contents
require "spec_helper" class AssociatedModel < CFoundry::V2::Model attribute :attribute, String end module CFoundry module V2 module ModelMagic describe ToMany do let(:client) { build(:client) } describe "to_many relationships" do describe "associated create" do let(:model) do TestModelBuilder.build("test-model-guid-1", client) { to_many :associated_models } end before do WebMock.stub_request(:put, /v2\/test_models\/.*\/associated_models/).to_return(:body => {}.to_json) WebMock.stub_request(:post, /v2\/associated_model/).to_return(:body => {:metadata => {:guid => "thing"}}.to_json) stub_request(:get, /v2\/test_models\/.*\/associated_models/) model.associated_models = [] end it "returns a new associated object" do expect(model.create_associated_model).to be_a(AssociatedModel) end it "sets the relation" do created = model.create_associated_model expect(model.associated_models).to include(created) end context "with attributes for the association" do it "sets these attributes on the association" do created = model.create_associated_model(:attribute => "value") expect(created.attribute).to eq("value") end end context "when creation fails" do it "raises an exception" do WebMock.stub_request(:post, /v2\/associated_model/).to_raise(:not_authorized) expect { model.create_associated_model }.to raise_error(StandardError) end end end end end end end end
Version data entries
10 entries across 10 versions & 2 rubygems