spec/cfoundry/v2/model_spec.rb in new_cfoundry-4.9.1 vs spec/cfoundry/v2/model_spec.rb in new_cfoundry-4.9.2
- old
+ new
@@ -23,17 +23,22 @@
let(:manifest) { {:metadata => {:guid => "some-guid-1"}, :entity => {}} }
let(:model) { TestModel.new(guid, client, manifest) }
describe "create" do
it "uses #create!" do
- expect(model).to receive(:create!)
+ expect(model).to receive(:create!).with({})
model.create
end
+ it "passes options along to create!" do
+ expect(model).to receive(:create!).with(:accepts_incomplete => true)
+ model.create(:accepts_incomplete => true)
+ end
+
context "without errors" do
it "returns true" do
- expect(model).to receive(:create!)
+ expect(model).to receive(:create!).with({})
expect(model.create).to eq(true)
end
end
context "with errors" do
@@ -76,19 +81,35 @@
}}
}
model.foo = "bar"
end
- it "posts to the model's create url with appropriate arguments" do
- expect(client.base).to receive(:post).with("v2", :odd_endpoint,
- :content => :json,
- :accept => :json,
- :payload => {:foo => "bar"}
- ) { {:metadata => {}} }
- model.create!
+ context "without options" do
+ it "posts to the model's create url with appropriate arguments and empty params hash" do
+ expect(client.base).to receive(:post).with("v2", :odd_endpoint,
+ :content => :json,
+ :accept => :json,
+ :payload => {:foo => "bar"},
+ :params => {}
+ ) { {:metadata => {}} }
+ model.create!
+ end
end
+ context "with options" do
+ it "sends create with appropriate arguments and options" do
+ options = {:excellent => "billandted"}
+ expect(client.base).to receive(:post).with("v2", :odd_endpoint,
+ :content => :json,
+ :accept => :json,
+ :payload => {:foo => "bar"},
+ :params => options
+ ) { {:metadata => {}} }
+ model.create!(options)
+ end
+ end
+
it "clears diff" do
expect(model.diff).to be_present
model.create!
expect(model.diff).not_to be_present
end
@@ -131,20 +152,37 @@
}
}
}
end
- it "updates using the client with the v2 api, its plural model name, object guid, and diff object" do
- model.foo = "bar"
- expect(client.base).to receive(:put).with("v2", :test_models, guid,
- :content => :json,
- :accept => :json,
- :payload => {:foo => "bar"}
- )
- model.update!
+ context "without options" do
+ it "updates using the client with the v2 api, its plural model name, object guid, diff object, and empty params hash" do
+ model.foo = "bar"
+ expect(client.base).to receive(:put).with("v2", :test_models, guid,
+ :content => :json,
+ :accept => :json,
+ :payload => {:foo => "bar"},
+ :params => {}
+ )
+ model.update!
+ end
end
+ context "with options" do
+ it "sends update with the object guid, diff object and options" do
+ model.foo = "bar"
+ options = {:excellent => "billandted"}
+ expect(client.base).to receive(:put).with("v2", :test_models, guid,
+ :content => :json,
+ :accept => :json,
+ :payload => {:foo => "bar"},
+ :params => options
+ )
+ model.update!(options)
+ end
+ end
+
it "updates the updated_at timestamp" do
model.update!
expect(model.updated_at).to eq(DateTime.parse("2015-06-12 10:41:15 -0700"))
end
@@ -377,21 +415,21 @@
}.to_json)
end
it "has next_page set to true" do
results = client.test_models_first_page
- expect(results[:next_page]).to be_true
+ expect(results[:next_page]).to be_truthy
expect(results[:results].length).to eq(1)
expect(results[:results].first).to be_a TestModel
end
end
context "when there is no next page" do
let(:next_url) { nil }
it "has next_page set to false" do
results = client.test_models_first_page
- expect(results[:next_page]).to be_false
+ expect(results[:next_page]).to be_falsey
end
end
end
describe '#for_each' do