|
14 | 14 | context 'on create' do
|
15 | 15 | before do
|
16 | 16 | @draft = FactoryBot.create :draft
|
| 17 | + visit new_path(model_name: 'player') |
17 | 18 | end
|
18 | 19 |
|
19 | 20 | it 'shows selects' do
|
20 |
| - visit new_path(model_name: 'player') |
21 | 21 | is_expected.to have_selector('select#player_draft_id')
|
22 | 22 | end
|
23 | 23 |
|
24 | 24 | it 'creates an object with correct associations' do
|
25 |
| - post new_path(model_name: 'player', player: FactoryBot.attributes_for(:player).merge(name: 'Jackie Robinson', draft_id: @draft.id)) |
| 25 | + fill_in 'Name', with: 'Jackie Robinson' |
| 26 | + fill_in 'Number', with: @draft.player.number + 1 |
| 27 | + select("Draft ##{@draft.id}", from: 'Draft') |
| 28 | + click_button 'Save' |
| 29 | + is_expected.to have_content 'Player successfully created' |
26 | 30 | @player = Player.where(name: 'Jackie Robinson').first
|
27 | 31 | @draft.reload
|
28 | 32 | expect(@player.draft).to eq(@draft)
|
|
31 | 35 |
|
32 | 36 | context 'on update' do
|
33 | 37 | before do
|
34 |
| - @player = FactoryBot.create :player |
35 |
| - @draft = FactoryBot.create :draft |
36 |
| - @number = @draft.player.number + 1 # to avoid collision |
37 |
| - put edit_path(model_name: 'player', id: @player.id, player: {name: 'Jackie Robinson', draft_id: @draft.id, number: @number, position: 'Second baseman'}) |
38 |
| - @player.reload |
| 38 | + @drafts = FactoryBot.create_list :draft, 2 |
| 39 | + @player = FactoryBot.create :player, draft: @drafts[0] |
| 40 | + visit edit_path(model_name: 'player', id: @player.id) |
39 | 41 | end
|
40 | 42 |
|
41 |
| - it 'updates an object with correct attributes' do |
42 |
| - expect(@player.name).to eq('Jackie Robinson') |
43 |
| - expect(@player.number).to eq(@number) |
44 |
| - expect(@player.position).to eq('Second baseman') |
| 43 | + it 'updates an object with correct associations' do |
| 44 | + select("Draft ##{@drafts[1].id}", from: 'Draft') |
| 45 | + click_button 'Save' |
| 46 | + @player.reload |
| 47 | + expect(@player.draft).to eq(@drafts[1]) |
45 | 48 | end
|
46 | 49 |
|
47 |
| - it 'updates an object with correct associations' do |
48 |
| - @draft.reload |
49 |
| - expect(@player.draft).to eq(@draft) |
| 50 | + it 'clears the current selection' do |
| 51 | + select('', from: 'Draft') |
| 52 | + click_button 'Save' |
| 53 | + @player.reload |
| 54 | + expect(@player.draft).to be nil |
50 | 55 | end
|
51 | 56 | end
|
52 | 57 |
|
|
0 commit comments