forked from thoughtbot/paperclip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
migration.feature
94 lines (84 loc) · 2.5 KB
/
migration.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Feature: Migration
Background:
Given I generate a new rails application
And I write to "app/models/user.rb" with:
"""
class User < ActiveRecord::Base; end
"""
Scenario: Vintage syntax
When I write to "db/migrate/01_add_attachment_to_users.rb" with:
"""
class AddAttachmentToUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.has_attached_file :avatar
end
end
def self.down
drop_attached_file :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"
Scenario: New syntax with create_table
When I write to "db/migrate/01_add_attachment_to_users.rb" with:
"""
class AddAttachmentToUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.attachment :avatar
end
end
end
"""
And I run a migration
Then I should have attachment columns for "avatar"
Scenario: New syntax outside of create_table
When I write to "db/migrate/01_create_users.rb" with:
"""
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users
end
end
"""
And I write to "db/migrate/02_add_attachment_to_users.rb" with:
"""
class AddAttachmentToUsers < ActiveRecord::Migration
def self.up
add_attachment :users, :avatar
end
def self.down
remove_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"
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"