Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of git@github.com:sam/dm-more
- Loading branch information
Showing
7 changed files
with
312 additions
and
84 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
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 |
---|---|---|
@@ -1,14 +1,34 @@ | ||
require File.dirname(__FILE__) + '/sample_migration' | ||
require File.dirname(__FILE__) + '/../lib/spec/example/migration_example_group.rb' | ||
require File.dirname(__FILE__) + '/../lib/spec/example/migration_example_group' | ||
|
||
describe :create_people_table, :type => :migration do | ||
|
||
before(:all) do | ||
puts "Inserts here" | ||
before do | ||
run_migration | ||
end | ||
|
||
it 'should do something' do | ||
puts "hi" | ||
it 'should create a people table' do | ||
repository(:default).should have_table(:people) | ||
end | ||
|
||
it 'should have an id column as the primary key' do | ||
table(:people).should have_column(:id) | ||
table(:people).column(:id).type.should == 'int' | ||
table(:people).column(:id).should be_primary_key | ||
end | ||
|
||
it 'should have a name column as a string' do | ||
puts table(:people).inspect | ||
puts query("PRAGMA table_info(people)") | ||
table(:people).should have_column(:name) | ||
table(:people).column(:name).type.should == 'string' | ||
table(:people).column(:name).should_not permit_null | ||
end | ||
|
||
it 'should have a nullable age column as a int' do | ||
table(:people).should have_column(:age) | ||
table(:people).column(:age).type.should == 'int' | ||
table(:people).column(:age).should_not permit_null | ||
end | ||
|
||
end |
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
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
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,100 @@ | ||
|
||
module Spec | ||
module Matchers | ||
module Migration | ||
|
||
def have_table(table_name) | ||
HaveTableMatcher.new(table_name) | ||
end | ||
|
||
def have_column(column_name) | ||
HaveColumnMatcher.new(column_name) | ||
end | ||
|
||
def permit_null | ||
NullableColumnMatcher.new | ||
end | ||
|
||
def be_primary_key | ||
PrimaryKeyMatcher.new | ||
end | ||
|
||
class HaveTableMatcher | ||
|
||
attr_accessor :table_name, :repository | ||
|
||
def initialize(table_name) | ||
@table_name = table_name | ||
end | ||
|
||
def matches?(repository) | ||
repository.adapter.table_exists?(table_name) | ||
end | ||
|
||
def failure_message | ||
%(expected #{repository} to have table '#{table_name}') | ||
end | ||
|
||
def negative_failure_message | ||
%(expected #{repository} to not have table '#{table_name}') | ||
end | ||
|
||
end | ||
|
||
class HaveColumnMatcher | ||
|
||
attr_accessor :table, :column_name | ||
|
||
def initialize(column_name) | ||
@column_name = column_name | ||
end | ||
|
||
def matches?(table) | ||
@table = table | ||
table.columns.map(&:name).include?(column_name.to_s) | ||
end | ||
|
||
def failure_message | ||
%(expected #{table} to have column '#{column_name}') | ||
end | ||
|
||
def negative_failure_message | ||
%(expected #{table} to not have column '#{column_name}') | ||
end | ||
|
||
end | ||
|
||
class NullableColumnMatcher | ||
|
||
attr_accessor :column | ||
|
||
def matches?(column) | ||
@column = column | ||
! column.not_null | ||
end | ||
|
||
def failure_message | ||
%(expected #{column.name} to permit NULL) | ||
end | ||
|
||
def negative_failure_message | ||
%(expected #{column.name} to be NOT NULL) | ||
end | ||
|
||
end | ||
|
||
class PrimaryKeyMatcher | ||
|
||
attr_accessor :column | ||
|
||
def matches?(column) | ||
@column = column | ||
column.primary_key | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end | ||
|
Oops, something went wrong.