spec/looksist_spec.rb in looksist-0.0.1 vs spec/looksist_spec.rb in looksist-0.0.2

- old
+ new

@@ -69,41 +69,51 @@ context 'lookup attributes' do it 'should generate declarative attributes on the model with simple lookup value' do module SimpleLookup class Employee include Looksist - attr_accessor :id + attr_accessor :id, :employee_id lookup :name, using= :id + lookup :unavailable, using= :employee_id def initialize(id) - @id = id + @id = @employee_id = id end end end expect(Looksist.lookup_store_client).to receive(:get).with('ids/1').and_return('Employee Name') + expect(Looksist.lookup_store_client).to receive(:get).with('employees/1').and_return(nil) e = SimpleLookup::Employee.new(1) expect(e.name).to eq('Employee Name') + expect(e.unavailable).to be(nil) end it 'should generate declarative attributes on the model with object based lookup value' do module CompositeLookup class Employee include Looksist - attr_accessor :id + attr_accessor :id, :employee_id lookup [:name, :location], using=:id + lookup [:age, :sex], using=:employee_id def initialize(id) - @id = id + @id = @employee_id = id end end end expect(Looksist.lookup_store_client).to receive(:get).with('ids/1') .and_return({name: 'Employee Name', location: 'Chennai'}.to_json) + expect(Looksist.lookup_store_client).to receive(:get).twice.with('employees/1') + .and_return(nil) e = CompositeLookup::Employee.new(1) + expect(e.name).to eq('Employee Name') expect(e.location).to eq('Chennai') + + expect(e.age).to be(nil) + expect(e.sex).to be(nil) end end end \ No newline at end of file