Sha256: 6dfb469f2094e114fe13682a48fb9ebb0fa5414eb879833a814d8cb2c3f28b69
Contents?: true
Size: 1.18 KB
Versions: 22
Compression:
Stored size: 1.18 KB
Contents
require 'spec_helper' RSpec.describe 'deferred accepts_nested_attributes' do before :each do Person.create!(name: 'Alice') Person.create!(name: 'Bob') Team.create!(name: 'Database Administration') Team.create!(name: 'End-User Support') Team.create!(name: 'Operations') end let(:bob) { Person.where(name: 'Bob').first } let(:dba) { Team.where(name: 'Database Administration').first } let(:support) { Team.where(name: 'End-User Support').first } let(:operations) { Team.where(name: 'Operations').first } # TODO: Write more tests. it 'should mass assign' do p = Person.first p.teams << Team.first << Team.last << Team.find(2) p.save # Destroy team 2 and 3. Keep team 1. p = Person.first p.attributes = { teams_attributes: [ { id: 1 }, { id: 3, _destroy: '1' }, { id: 2, _destroy: '1' } ] } expect(p.teams.length).to eq(1) expect(p.team_ids.sort).to eq([1]) Person.first expect(Person.first.teams.length).to eq(3) expect(Person.first.team_ids.sort).to eq([1,2,3]) p.save! p = Person.first expect(p.teams.length).to eq(1) expect(p.team_ids.sort).to eq([1]) end end
Version data entries
22 entries across 22 versions & 1 rubygems