aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/enum_test.rb
blob: 34381f218c111193b83a54bc8a3ea526e57702d7 (plain) (blame)
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
34
35
36
37
38
39
40
require 'cases/helper'
require 'models/book'

class StoreTest < ActiveRecord::TestCase
  fixtures :books

  setup do
    @book = books(:awdr)
  end

  test "query state by predicate" do
    assert @book.proposed?
    assert_not @book.written?
    assert_not @book.published?
  end

  test "query state with symbol" do
    assert_equal :proposed, @book.status
  end

  test "find via scope" do
    assert_equal @book, Book.proposed.first
  end

  test "update by declaration" do
    @book.written!
    assert @book.written?
  end

  test "update by setter" do
    @book.update! status: :written
    assert @book.written?
  end

  test "constant" do
    assert_equal 0, Book::STATUS[:proposed]
    assert_equal 1, Book::STATUS[:written]
    assert_equal 2, Book::STATUS[:published]
  end
end