Skip to content

Commit d56bf9d

Browse files
committed
Move belongs_to tests to existing associations block
1 parent a4c84d2 commit d56bf9d

1 file changed

Lines changed: 24 additions & 21 deletions

File tree

spec/rails_admin/config/fields/base_spec.rb

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,6 @@ class ConditionalValidationTest < Tableless
7474
end
7575
end
7676

77-
context 'on a belongs_to association' do
78-
before do
79-
class BelongsToTest < Tableless
80-
belongs_to :draft, optional: true
81-
belongs_to :team, optional: false
82-
belongs_to :image, required: true
83-
belongs_to :player, required: false
84-
end
85-
end
86-
87-
it 'respects optional on associations' do
88-
expect(RailsAdmin.config('BelongsToTest').fields.detect { |f| f.name == :draft }).not_to be_required
89-
expect(RailsAdmin.config('BelongsToTest').fields.detect { |f| f.name == :team }).to be_required
90-
end
91-
92-
it 'respects required on associations' do
93-
expect(RailsAdmin.config('BelongsToTest').fields.detect { |f| f.name == :image }).to be_required
94-
expect(RailsAdmin.config('BelongsToTest').fields.detect { |f| f.name == :player }).not_to be_required
95-
end
96-
end
97-
9877
context 'on a Paperclip installation' do
9978
it 'should detect required fields' do
10079
expect(RailsAdmin.config('Image').fields.detect { |f| f.name == :file }.with(object: Image.new)).to be_required
@@ -107,9 +86,15 @@ class RelTest < Tableless
10786
column :league_id, :integer
10887
column :division_id, :integer, nil, false
10988
column :player_id, :integer
89+
column :team_id, :integer
90+
column :draft_id, :integer
91+
column :image_id, :integer
11092
belongs_to :league, optional: true
11193
belongs_to :division, optional: true
11294
belongs_to :player, optional: true
95+
belongs_to :team, optional: false
96+
belongs_to :draft, required: true
97+
belongs_to :image, required: false
11398
validates_numericality_of(:player_id, only_integer: true)
11499
end
115100
@fields = RailsAdmin.config(RelTest).create.fields
@@ -132,6 +117,24 @@ class RelTest < Tableless
132117
expect(@fields.detect { |f| f.name == :player }.required?).to be_truthy
133118
end
134119
end
120+
121+
describe 'for belongs_to association with optional: false' do
122+
it 'is required' do
123+
expect(@fields.detect { |f| f.name == :team }.required?).to be_truthy
124+
end
125+
end
126+
127+
describe 'for belongs_to association with required: true' do
128+
it 'is required' do
129+
expect(@fields.detect { |f| f.name == :draft }.required?).to be_truthy
130+
end
131+
end
132+
133+
describe 'for belongs_to association with required: false' do
134+
it 'is optional' do
135+
expect(@fields.detect { |f| f.name == :image }.required?).to be_falsey
136+
end
137+
end
135138
end
136139
end
137140

0 commit comments

Comments
 (0)