Sha256: 7de9da9217779d1251bd7b2d5602ac111ef9a9c52b039e3702d3f2a90512da06
Contents?: true
Size: 1.92 KB
Versions: 1
Compression:
Stored size: 1.92 KB
Contents
# encoding: utf-8 require 'spec_helper' describe 'Session' do let(:users) { TEST_ENV.schema[:users] } let(:relation) { TEST_ENV[:users] } let(:mapper) { relation.mapper } let(:model) { mapper.model } before do users.insert([[1, 'John'], [2, 'Jane']]) end after do users.delete([[1, 'John'], [2, 'Jane'], [2, 'Jane Doe'], [3, 'Piotr']]) end specify 'fetching an object from a relation' do TEST_ENV.session do |session| # fetch user for the first time jane1 = session[:users].restrict(name: 'Jane').one expect(jane1).to eq(model.new(id: 2, name: 'Jane')) # here IM-powered loader kicks in jane2 = session[:users].restrict(name: 'Jane').one expect(jane1).to be(jane2) end end specify 'deleting an object from a relation' do TEST_ENV.session do |session| jane = session[:users].restrict(name: 'Jane').one session[:users].delete(jane) session.flush expect(relation.to_a).not_to include(jane) end end specify 'saving an object to a relation' do TEST_ENV.session do |session| piotr = session[:users].new(id: 3, name: 'Piotr') session[:users].save(piotr) session.flush expect(relation.to_a).to include(piotr) end end specify 'updating an object in a relation' do TEST_ENV.session do |session| jane = session[:users].restrict(id: 2).one jane.name = 'Jane Doe' session[:users].save(jane) session.flush expect(relation.count).to be(2) expect(relation.to_a.last).to eql(jane) end end specify 'updating an immutable object in a relation' do TEST_ENV.session do |session| jane = session[:users].restrict(id: 2).one jane.freeze session[:users].update_attributes(jane, name: 'Jane Doe') session.flush expect(relation.count).to be(2) expect(relation.to_a.last).to eql(jane.update(name: 'Jane Doe')) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rom-0.2.0 | spec/integration/session_spec.rb |