diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-06-06 07:24:22 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-06-06 07:26:55 +0900 |
commit | c40502f9f063baf7fb07ea4203b0b277fddd95a1 (patch) | |
tree | d7c628117d96d3b7c76678ffaeddaf2a59b6d9a4 /activerecord/test/cases | |
parent | e7e9e0722aea751886aeb7e501fadf115e95897e (diff) | |
download | rails-c40502f9f063baf7fb07ea4203b0b277fddd95a1.tar.gz rails-c40502f9f063baf7fb07ea4203b0b277fddd95a1.tar.bz2 rails-c40502f9f063baf7fb07ea4203b0b277fddd95a1.zip |
Load schema before assertion
Without this, test fails because the load schema when pluck is executed.
Steps to reproduce:
```
bin/test -a postgresql -w --seed 61689 test/cases/*test.rb -n "/^(?:InheritanceComputeTypeTest#(?:test_inheritance_new_with_subclass_as_default)|CalculationsTest#(?:test_pluck_loaded_relation))$/"
# Running:
.F
Failure:
CalculationsTest#test_pluck_loaded_relation [/home/yaginuma/program/rails/master_y_yagi/rails/activerecord/test/cases/calculations_test.rb:722]:
1 instead of 0 queries were executed.
Queries:
SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ANY (current_schemas(false)) AND c.relname = 'companies' AND c.relkind IN ('r','v','m').
Expected: 0
Actual: 1
bin/test test/cases/calculations_test.rb:7
```
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/calculations_test.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 21c5c0efee..adfca08289 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -718,21 +718,27 @@ class CalculationsTest < ActiveRecord::TestCase end def test_pluck_loaded_relation + Company.attribute_names # Load schema information so we don't query below companies = Company.order(:id).limit(3).load + assert_no_queries do assert_equal ["37signals", "Summit", "Microsoft"], companies.pluck(:name) end end def test_pluck_loaded_relation_multiple_columns + Company.attribute_names # Load schema information so we don't query below companies = Company.order(:id).limit(3).load + assert_no_queries do assert_equal [[1, "37signals"], [2, "Summit"], [3, "Microsoft"]], companies.pluck(:id, :name) end end def test_pluck_loaded_relation_sql_fragment + Company.attribute_names # Load schema information so we don't query below companies = Company.order(:name).limit(3).load + assert_queries 1 do assert_equal ["37signals", "Apex", "Ex Nihilo"], companies.pluck("DISTINCT name") end |