@@ -14,29 +14,35 @@ module ForestLiana
1414 end
1515 end
1616
17- context 'on a model having 3 belongsTo associations' do
17+ context 'on a model having some belongsTo associations' do
18+ let ( :expected_association_attributes ) do
19+ [
20+ { name : :owner , klass : User } ,
21+ { name : :cutter , klass : User } ,
22+ { name : :island , klass : Island } ,
23+ { name : :eponymous_island , klass : Island } ,
24+ ]
25+ end
26+
1827 it 'should return the one-one associations' do
1928 associations = QueryHelper . get_one_associations ( Tree )
20- expect ( associations . length ) . to eq ( 3 )
21- expect ( associations . first . name ) . to eq ( :owner )
22- expect ( associations . first . klass ) . to eq ( User )
23- expect ( associations . second . name ) . to eq ( :cutter )
24- expect ( associations . second . klass ) . to eq ( User )
25- expect ( associations . third . name ) . to eq ( :island )
26- expect ( associations . third . klass ) . to eq ( Island )
29+ expect ( associations . length ) . to eq ( expected_association_attributes . length )
30+ associations . zip ( expected_association_attributes ) . each do |association , expected_attributes |
31+ expect ( association ) . to have_attributes ( expected_attributes )
32+ end
2733 end
2834 end
2935 end
3036
3137 describe 'get_one_association_names_symbol' do
3238 it 'should return the one-one associations names as symbols' do
33- expect ( QueryHelper . get_one_association_names_symbol ( Tree ) ) . to eq ( [ :owner , :cutter , :island ] )
39+ expect ( QueryHelper . get_one_association_names_symbol ( Tree ) ) . to eq ( [ :owner , :cutter , :island , :eponymous_island ] )
3440 end
3541 end
3642
3743 describe 'get_one_association_names_string' do
3844 it 'should return the one-one associations names as strings' do
39- expect ( QueryHelper . get_one_association_names_string ( Tree ) ) . to eq ( [ 'owner' , 'cutter' , 'island' ] )
45+ expect ( QueryHelper . get_one_association_names_string ( Tree ) ) . to eq ( [ 'owner' , 'cutter' , 'island' , 'eponymous_island' ] )
4046 end
4147 end
4248
@@ -64,8 +70,9 @@ module ForestLiana
6470 end
6571
6672 it 'should return relationships on models having a custom table name' do
67- expect ( tables_associated_to_relations_name [ 'isle' ] . length ) . to eq ( 1 )
73+ expect ( tables_associated_to_relations_name [ 'isle' ] . length ) . to eq ( 2 )
6874 expect ( tables_associated_to_relations_name [ 'isle' ] . first ) . to eq ( :island )
75+ expect ( tables_associated_to_relations_name [ 'isle' ] . second ) . to eq ( :eponymous_island )
6976 end
7077 end
7178 end
0 commit comments