This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a proper test suite of the schema helper
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
require 'test/helper' | ||
require 'ostruct' | ||
|
||
class MockSchema | ||
include Paperclip::Schema | ||
|
||
def initialize(table_name = nil) | ||
@table_name = table_name | ||
@columns = {} | ||
end | ||
|
||
def column(name, type) | ||
@columns[name] = type | ||
end | ||
|
||
def remove_column(table_name, column_name) | ||
@columns.delete(column_name) | ||
end | ||
|
||
def has_column?(column_name) | ||
@columns.key?(column_name) | ||
end | ||
|
||
def type_of(column_name) | ||
@columns[column_name] | ||
end | ||
end | ||
|
||
class SchemaTest < Test::Unit::TestCase | ||
context "Migrating up" do | ||
setup do | ||
@schema = MockSchema.new | ||
@schema.has_attached_file :avatar | ||
end | ||
|
||
should "create the file_name column" do | ||
assert @schema.has_column?(:avatar_file_name) | ||
end | ||
|
||
should "create the content_type column" do | ||
assert @schema.has_column?(:avatar_content_type) | ||
end | ||
|
||
should "create the file_size column" do | ||
assert @schema.has_column?(:avatar_file_size) | ||
end | ||
|
||
should "create the updated_at column" do | ||
assert @schema.has_column?(:avatar_updated_at) | ||
end | ||
|
||
should "make the file_name column a string" do | ||
assert_equal :string, @schema.type_of(:avatar_file_name) | ||
end | ||
|
||
should "make the content_type column a string" do | ||
assert_equal :string, @schema.type_of(:avatar_content_type) | ||
end | ||
|
||
should "make the file_size column an integer" do | ||
assert_equal :integer, @schema.type_of(:avatar_file_size) | ||
end | ||
|
||
should "make the updated_at column a datetime" do | ||
assert_equal :datetime, @schema.type_of(:avatar_updated_at) | ||
end | ||
end | ||
end |