mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
add test-cases for primary-key-less-views. Closes #16555.
This commit is contained in:
parent
d2069d60ae
commit
ec6eee5db0
1 changed files with 43 additions and 0 deletions
|
@ -37,5 +37,48 @@ class ViewWithPrimaryKeyTest < ActiveRecord::TestCase
|
|||
["name", :string],
|
||||
["status", :integer]], Ebook.columns.map { |c| [c.name, c.type] })
|
||||
end
|
||||
|
||||
def test_attributes
|
||||
assert_equal({"id" => 2, "name" => "Ruby for Rails", "status" => 0},
|
||||
Ebook.first.attributes)
|
||||
end
|
||||
end
|
||||
|
||||
class ViewWithoutPrimaryKeyTest < ActiveRecord::TestCase
|
||||
fixtures :books
|
||||
|
||||
class Paperback < ActiveRecord::Base; end
|
||||
|
||||
setup do
|
||||
@connection = ActiveRecord::Base.connection
|
||||
@connection.execute <<-SQL
|
||||
CREATE VIEW paperbacks
|
||||
AS SELECT name, status FROM books WHERE format = 'paperback'
|
||||
SQL
|
||||
end
|
||||
|
||||
teardown do
|
||||
@connection.execute "DROP VIEW IF EXISTS paperbacks"
|
||||
end
|
||||
|
||||
def test_reading
|
||||
books = Paperback.all
|
||||
assert_equal ["Agile Web Development with Rails"], books.map(&:name)
|
||||
end
|
||||
|
||||
def test_table_exists
|
||||
view_name = Paperback.table_name
|
||||
assert @connection.table_exists?(view_name), "'#{view_name}' table should exist"
|
||||
end
|
||||
|
||||
def test_column_definitions
|
||||
assert_equal([["name", :string],
|
||||
["status", :integer]], Paperback.columns.map { |c| [c.name, c.type] })
|
||||
end
|
||||
|
||||
def test_attributes
|
||||
assert_equal({"name" => "Agile Web Development with Rails", "status" => 0},
|
||||
Paperback.first.attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue