Commit 77ee8a51 by Prem Sichanugrist

Add command recorder for our migrations

This is for Rails 3.1+
parent 76cbfb80
...@@ -68,3 +68,27 @@ Feature: Migration ...@@ -68,3 +68,27 @@ Feature: Migration
When I rollback a migration When I rollback a migration
Then I should not have attachment columns for "avatar" Then I should not have attachment columns for "avatar"
Scenario: Rails 3.2 change method
Given I am using Rails newer than 3.1
When I write to "db/migrate/01_create_users.rb" with:
"""
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users
end
end
"""
When I write to "db/migrate/02_add_attachment_to_users.rb" with:
"""
class AddAttachmentToUsers < ActiveRecord::Migration
def change
add_attachment :users, :avatar
end
end
"""
And I run a migration
Then I should have attachment columns for "avatar"
When I rollback a migration
Then I should not have attachment columns for "avatar"
...@@ -130,3 +130,9 @@ end ...@@ -130,3 +130,9 @@ end
When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname| When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
comment_out_gem_in_gemfile gemname comment_out_gem_in_gemfile gemname
end end
Given /^I am using Rails newer than ([\d\.]+)$/ do |version|
if framework_version < version
pending "Not supported in Rails < #{version}"
end
end
...@@ -12,6 +12,10 @@ module Paperclip ...@@ -12,6 +12,10 @@ module Paperclip
ActiveRecord::ConnectionAdapters::Table.send :include, TableDefinition ActiveRecord::ConnectionAdapters::Table.send :include, TableDefinition
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, TableDefinition ActiveRecord::ConnectionAdapters::TableDefinition.send :include, TableDefinition
ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Statements ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Statements
if defined?(ActiveRecord::Migration::CommandRecorder) # Rails 3.1+
ActiveRecord::Migration::CommandRecorder.send :include, CommandRecorder
end
end end
module Statements module Statements
...@@ -55,5 +59,17 @@ module Paperclip ...@@ -55,5 +59,17 @@ module Paperclip
attachment(*attachment_names) attachment(*attachment_names)
end end
end end
module CommandRecorder
def add_attachment(*args)
record(:add_attachment, args)
end
private
def invert_add_attachment(args)
[:remove_attachment, args]
end
end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment