@@ -4,15 +4,15 @@ class SelectTest < Minitest::Test
44 def test_basic
55 store [ { name : "Product A" , store_id : 1 } ]
66 result = Product . search ( "product" , load : false , select : [ :name , :store_id ] ) . first
7- assert_equal %w( id name store_id ) , result . keys . reject { |k | k . start_with? ( "_" ) } . sort
7+ assert_equal %w( id name store_id ) , result . to_h . keys . reject { |k | k . start_with? ( "_" ) } . sort
88 assert_equal "Product A" , result . name
99 assert_equal 1 , result . store_id
1010 end
1111
1212 def test_relation
1313 store [ { name : "Product A" , store_id : 1 } ]
1414 result = Product . search ( "product" , load : false ) . select ( :name , :store_id ) . first
15- assert_equal %w( id name store_id ) , result . keys . reject { |k | k . start_with? ( "_" ) } . sort
15+ assert_equal %w( id name store_id ) , result . to_h . keys . reject { |k | k . start_with? ( "_" ) } . sort
1616 assert_equal "Product A" , result . name
1717 assert_equal 1 , result . store_id
1818 end
@@ -32,15 +32,15 @@ def test_block_arguments
3232 def test_multiple
3333 store [ { name : "Product A" , store_id : 1 } ]
3434 result = Product . search ( "product" , load : false ) . select ( :name ) . select ( :store_id ) . first
35- assert_equal %w( id name store_id ) , result . keys . reject { |k | k . start_with? ( "_" ) } . sort
35+ assert_equal %w( id name store_id ) , result . to_h . keys . reject { |k | k . start_with? ( "_" ) } . sort
3636 assert_equal "Product A" , result . name
3737 assert_equal 1 , result . store_id
3838 end
3939
4040 def test_reselect
4141 store [ { name : "Product A" , store_id : 1 } ]
4242 result = Product . search ( "product" , load : false ) . select ( :name ) . reselect ( :store_id ) . first
43- assert_equal %w( id store_id ) , result . keys . reject { |k | k . start_with? ( "_" ) } . sort
43+ assert_equal %w( id store_id ) , result . to_h . keys . reject { |k | k . start_with? ( "_" ) } . sort
4444 assert_equal 1 , result . store_id
4545 end
4646
@@ -53,9 +53,9 @@ def test_array
5353 def test_single_field
5454 store [ { name : "Product A" , store_id : 1 } ]
5555 result = Product . search ( "product" , load : false , select : :name ) . first
56- assert_equal %w( id name ) , result . keys . reject { |k | k . start_with? ( "_" ) } . sort
56+ assert_equal %w( id name ) , result . to_h . keys . reject { |k | k . start_with? ( "_" ) } . sort
5757 assert_equal "Product A" , result . name
58- assert_nil result . store_id
58+ refute result . respond_to? ( : store_id)
5959 end
6060
6161 def test_all
@@ -76,15 +76,15 @@ def test_none
7676 def test_includes
7777 store [ { name : "Product A" , user_ids : [ 1 , 2 ] } ]
7878 result = Product . search ( "product" , load : false , select : { includes : [ :name ] } ) . first
79- assert_equal %w( id name ) , result . keys . reject { |k | k . start_with? ( "_" ) } . sort
79+ assert_equal %w( id name ) , result . to_h . keys . reject { |k | k . start_with? ( "_" ) } . sort
8080 assert_equal "Product A" , result . name
81- assert_nil result . store_id
81+ refute result . respond_to? ( : store_id)
8282 end
8383
8484 def test_excludes
8585 store [ { name : "Product A" , user_ids : [ 1 , 2 ] , store_id : 1 } ]
8686 result = Product . search ( "product" , load : false , select : { excludes : [ :name ] } ) . first
87- assert_nil result . name
87+ refute result . respond_to? ( : name)
8888 assert_equal [ 1 , 2 ] , result . user_ids
8989 assert_equal 1 , result . store_id
9090 end
@@ -94,7 +94,7 @@ def test_include_and_excludes
9494 store [ { name : "Product A" , user_ids : [ 1 , 2 ] , store_id : 1 } ]
9595 result = Product . search ( "product" , load : false , select : { includes : [ :store_id ] , excludes : [ :name ] } ) . first
9696 assert_equal 1 , result . store_id
97- assert_nil result . name
98- assert_nil result . user_ids
97+ refute result . respond_to? ( : name)
98+ refute result . respond_to? ( : user_ids)
9999 end
100100end
0 commit comments