|
11 | 11 | expect(object.assign_attributes(nil)).to be nil
|
12 | 12 | end
|
13 | 13 | end
|
14 |
| - |
15 |
| - describe 'has_one association' do |
16 |
| - let(:draft) { FactoryBot.create(:draft) } |
17 |
| - let(:player) { FactoryBot.build(:player).extend(RailsAdmin::Adapters::ActiveRecord::ObjectExtension) } |
18 |
| - before do |
19 |
| - class PlayerWithAutoSave < Player |
20 |
| - has_one :draft, inverse_of: :player, foreign_key: :player_id, autosave: true |
21 |
| - end |
22 |
| - end |
23 |
| - |
24 |
| - it 'provides id getter' do |
25 |
| - player.draft = draft |
26 |
| - expect(player.draft_id).to eq draft.id |
27 |
| - end |
28 |
| - |
29 |
| - context 'on create' do |
30 |
| - before do |
31 |
| - player.draft_id = draft.id |
32 |
| - expect(player.draft).to receive(:save).once.and_call_original |
33 |
| - player.save |
34 |
| - end |
35 |
| - |
36 |
| - it 'persists associated documents changes on save' do |
37 |
| - expect(player.reload.draft).to eq draft |
38 |
| - end |
39 |
| - end |
40 |
| - |
41 |
| - context 'on update' do |
42 |
| - let(:player) { FactoryBot.create(:player).extend(RailsAdmin::Adapters::ActiveRecord::ObjectExtension) } |
43 |
| - before do |
44 |
| - player.draft_id = draft.id |
45 |
| - end |
46 |
| - |
47 |
| - it 'persists associated documents changes on assignment' do |
48 |
| - expect(player.reload.draft).to eq draft |
49 |
| - end |
50 |
| - end |
51 |
| - |
52 |
| - context 'with explicit id setter' do |
53 |
| - let(:user) { ManagingUser.create(FactoryBot.attributes_for(:user)) } |
54 |
| - let(:team) { ManagedTeam.create(FactoryBot.attributes_for(:team)) } |
55 |
| - |
56 |
| - it 'works without issues' do |
57 |
| - user.team_id = team.id |
58 |
| - expect(user.reload.team).to eq team |
59 |
| - end |
60 |
| - end |
61 |
| - |
62 |
| - context 'when associated class has custom primary key' do |
63 |
| - let(:league) { FactoryBot.build(:league).extend(RailsAdmin::Adapters::ActiveRecord::ObjectExtension) } |
64 |
| - let(:division) { FactoryBot.create :division } |
65 |
| - |
66 |
| - it 'does not break' do |
67 |
| - league.division_id = division.id |
68 |
| - league.save! |
69 |
| - expect(league.reload.division).to eq division |
70 |
| - end |
71 |
| - end |
72 |
| - end |
73 | 14 | end
|
0 commit comments