diff options
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/enum_test.rb | 8 | ||||
-rw-r--r-- | activerecord/test/models/book.rb | 1 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 1 |
3 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index 34381f218c..6a9a2f6a98 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -12,14 +12,18 @@ class StoreTest < ActiveRecord::TestCase assert @book.proposed? assert_not @book.written? assert_not @book.published? + + assert @book.unread? end test "query state with symbol" do assert_equal :proposed, @book.status + assert_equal :unread, @book.read_status end test "find via scope" do assert_equal @book, Book.proposed.first + assert_equal @book, Book.unread.first end test "update by declaration" do @@ -36,5 +40,9 @@ class StoreTest < ActiveRecord::TestCase assert_equal 0, Book::STATUS[:proposed] assert_equal 1, Book::STATUS[:written] assert_equal 2, Book::STATUS[:published] + + assert_equal 0, Book::READ_STATUS[:unread] + assert_equal 2, Book::READ_STATUS[:reading] + assert_equal 3, Book::READ_STATUS[:read] end end diff --git a/activerecord/test/models/book.rb b/activerecord/test/models/book.rb index a527e41a8a..781f67557b 100644 --- a/activerecord/test/models/book.rb +++ b/activerecord/test/models/book.rb @@ -8,4 +8,5 @@ class Book < ActiveRecord::Base has_many :subscribers, through: :subscriptions enum status: [:proposed, :written, :published] + enum read_status: {unread: 0, reading: 2, read: 3} end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 5f7ce2c15c..6887cfebdc 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -95,6 +95,7 @@ ActiveRecord::Schema.define do t.integer :author_id t.column :name, :string t.column :status, :integer, default: 0 + t.column :read_status, :integer, default: 0 end create_table :booleans, :force => true do |t| |