Sha256: 0042822b77ed2cfeb1d24b44079805c4541c4eb8ed4fb551671d38aac0931e00
Contents?: true
Size: 1.69 KB
Versions: 35
Compression:
Stored size: 1.69 KB
Contents
require 'spec_helper' describe Defaultable do module SparkApi module Models class TestClass < Base extend Finders include Defaultable self.element_name = 'testclass' end end end describe 'default' do it 'returns an instance of the class' do allow(TestClass).to receive(:connection).and_return(double(get: [{"Name" => 'foo'}])) expect(TestClass.default).to be_a TestClass end it 'returns nil when there are no results' do allow(TestClass).to receive(:connection).and_return(double(get: [])) expect(TestClass.default).to be nil end it "assigns the default id to the instance if it doesn't have an id" do allow(TestClass).to receive(:connection).and_return(double(get: [{"Name" => 'foo'}])) expect(TestClass.default.Id).to eq TestClass::DEFAULT_ID end it "doesn't override the id if one is present" do allow(TestClass).to receive(:connection).and_return(double(get: [{"Id" => '5', "Name" => 'foo'}])) expect(TestClass.default.Id).to eq '5' end end describe 'find' do it "calls 'default' when given the default id" do expect(TestClass).to receive(:default) TestClass.find(TestClass::DEFAULT_ID) end it "passes options to 'default'" do expect(TestClass).to receive(:default).with(foo: true) TestClass.find(TestClass::DEFAULT_ID, foo: true) end it "calls Finders.find when given a normal id" do connection = double expect(connection).to receive(:get).with("/testclass/5", {foo: true}).and_return([{}]) allow(TestClass).to receive(:connection).and_return(connection) TestClass.find('5', foo: true) end end end
Version data entries
35 entries across 35 versions & 1 rubygems