2013-11-02 15:01:31 -04:00
|
|
|
require 'cases/helper'
|
|
|
|
require 'models/book'
|
|
|
|
|
|
|
|
class StoreTest < ActiveRecord::TestCase
|
|
|
|
fixtures :books
|
|
|
|
|
|
|
|
setup do
|
2013-11-02 16:13:02 -04:00
|
|
|
@book = books(:awdr)
|
2013-11-02 15:01:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "query state by predicate" do
|
|
|
|
assert @book.proposed?
|
|
|
|
assert_not @book.written?
|
|
|
|
assert_not @book.published?
|
2013-11-02 20:48:16 -04:00
|
|
|
|
|
|
|
assert @book.unread?
|
2013-11-02 15:01:31 -04:00
|
|
|
end
|
2013-11-02 16:08:36 -04:00
|
|
|
|
2013-11-02 15:01:31 -04:00
|
|
|
test "query state with symbol" do
|
|
|
|
assert_equal :proposed, @book.status
|
2013-11-02 20:48:16 -04:00
|
|
|
assert_equal :unread, @book.read_status
|
2013-11-02 15:01:31 -04:00
|
|
|
end
|
|
|
|
|
2013-11-02 19:18:31 -04:00
|
|
|
test "find via scope" do
|
|
|
|
assert_equal @book, Book.proposed.first
|
2013-11-02 20:48:16 -04:00
|
|
|
assert_equal @book, Book.unread.first
|
2013-11-02 19:18:31 -04:00
|
|
|
end
|
|
|
|
|
2013-11-02 15:01:31 -04:00
|
|
|
test "update by declaration" do
|
|
|
|
@book.written!
|
|
|
|
assert @book.written?
|
|
|
|
end
|
2013-11-02 16:08:36 -04:00
|
|
|
|
2013-11-02 15:01:31 -04:00
|
|
|
test "update by setter" do
|
|
|
|
@book.update! status: :written
|
|
|
|
assert @book.written?
|
|
|
|
end
|
2013-11-02 16:08:36 -04:00
|
|
|
|
2013-11-02 15:01:31 -04:00
|
|
|
test "constant" do
|
|
|
|
assert_equal 0, Book::STATUS[:proposed]
|
|
|
|
assert_equal 1, Book::STATUS[:written]
|
|
|
|
assert_equal 2, Book::STATUS[:published]
|
2013-11-02 20:48:16 -04:00
|
|
|
|
|
|
|
assert_equal 0, Book::READ_STATUS[:unread]
|
|
|
|
assert_equal 2, Book::READ_STATUS[:reading]
|
|
|
|
assert_equal 3, Book::READ_STATUS[:read]
|
2013-11-02 15:01:31 -04:00
|
|
|
end
|
|
|
|
end
|