Skip to content

Commit ef5ba2d

Browse files
committed
Add more spec for rake task db:rollback
1 parent e0b78fc commit ef5ba2d

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

spec/lib/sequel_rails/railties/database_rake_spec.rb

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,20 @@
8282
end
8383

8484
describe 'db:rollback' do
85+
let(:version) { nil }
86+
let(:rake_task_call) do
87+
if version
88+
proc { `rake db:rollback VERSION=#{version}` }
89+
else
90+
proc { `rake db:rollback` }
91+
end
92+
end
93+
8594
it 'revert latest migration' do
8695
Dir.chdir app_root do
8796
begin
8897
expect do
89-
`rake db:rollback`
98+
rake_task_call.call
9099
end.to change { SequelRails::Migrations.current_migration }.from(
91100
'1365762739_add_github_username_to_users.rb'
92101
).to('1365762738_add_display_name_to_users.rb')
@@ -95,6 +104,58 @@
95104
end
96105
end
97106
end
107+
108+
context 'when version supplied' do
109+
context 'same as current version' do
110+
let(:version) { '1365762739' }
111+
112+
it 'does not revert' do
113+
Dir.chdir app_root do
114+
begin
115+
expect do
116+
rake_task_call.call
117+
end.not_to change { SequelRails::Migrations.current_migration }
118+
ensure
119+
SequelRails::Migrations.migrate_up!
120+
end
121+
end
122+
end
123+
end
124+
context 'same as last version' do
125+
let(:version) { '1365762738' }
126+
127+
it 'revert latest migration' do
128+
Dir.chdir app_root do
129+
begin
130+
expect do
131+
rake_task_call.call
132+
end.to change { SequelRails::Migrations.current_migration }.from(
133+
'1365762739_add_github_username_to_users.rb'
134+
).to('1365762738_add_display_name_to_users.rb')
135+
ensure
136+
SequelRails::Migrations.migrate_up!
137+
end
138+
end
139+
end
140+
end
141+
context 'smaller than last version' do
142+
let(:version) { '1273253849' }
143+
144+
it 'revert until migration specified by version' do
145+
Dir.chdir app_root do
146+
begin
147+
expect do
148+
rake_task_call.call
149+
end.to change { SequelRails::Migrations.current_migration }.from(
150+
'1365762739_add_github_username_to_users.rb'
151+
).to('1273253849_add_twitter_handle_to_users.rb')
152+
ensure
153+
SequelRails::Migrations.migrate_up!
154+
end
155+
end
156+
end
157+
end
158+
end
98159
end
99160

100161
describe 'db:migrate:redo' do

0 commit comments

Comments
 (0)