File: test_default_scope_with_select.rb

package info (click to toggle)
ruby-acts-as-list 1.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 388 kB
  • sloc: ruby: 2,493; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 750 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'helper'

class Animal < ActiveRecord::Base
  acts_as_list
  default_scope -> { select(:name) }
end

class DefaultScopeWithSelectTest < Minitest::Test
  def setup
    ActiveRecord::Base.connection.create_table :animals do |t|
      t.column :position, :integer
      t.column :name, :string
    end

    ActiveRecord::Base.connection.schema_cache.clear!
    Animal.reset_column_information
    super
  end

  def teardown
    teardown_db
    super
  end

  def test_default_scope_with_select
    animal1 = Animal.create name: 'Fox'
    animal2 = Animal.create name: 'Panda'
    animal3 = Animal.create name: 'Wildebeast'
    assert_equal 1, animal1.position
    assert_equal 2, animal2.position
    assert_equal 3, animal3.position
  end
end