migrant 1.2.8 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +31 -3
- data/Rakefile +14 -0
- data/VERSION +1 -1
- data/lib/dsl/data_type.rb +7 -3
- data/lib/dsl/data_types/primitives.rb +43 -1
- data/lib/generators/templates/create_migration.erb +1 -1
- data/lib/migrant/migration_generator.rb +10 -4
- data/lib/migrant/model_extensions.rb +25 -7
- data/lib/migrant/schema.rb +17 -19
- data/migrant.gemspec +2 -0
- data/test/helper.rb +0 -11
- data/test/rails_app/app/models/business.rb +2 -0
- data/test/rails_app/app/models/user.rb +1 -1
- data/test/test_data_schema.rb +11 -2
- data/test/test_migration_generator.rb +25 -3
- data/test/verified_output/migrations/create_businesses.rb +17 -15
- metadata +134 -106
data/README.rdoc
CHANGED
@@ -41,6 +41,7 @@ correct database schema for you. Note that you don't need to specify foreign key
|
|
41
41
|
they are automatically inferred from your relations. Here is a further example:
|
42
42
|
|
43
43
|
class User < ActiveRecord::Base
|
44
|
+
# Define your associations BEFORE your structure block!
|
44
45
|
has_many :businesses
|
45
46
|
|
46
47
|
structure do
|
@@ -50,10 +51,10 @@ they are automatically inferred from your relations. Here is a further example:
|
|
50
51
|
timestamps # Gets you a created_at, and updated_at
|
51
52
|
|
52
53
|
# Use an array to specifiy multiple validations
|
53
|
-
secret_code 5521,
|
54
|
+
secret_code 5521, :validates => [:uniqueness, :numericality]
|
54
55
|
end
|
55
56
|
end
|
56
|
-
|
57
|
+
|
57
58
|
Now, to get your database up to date simply run:
|
58
59
|
|
59
60
|
> rake db:upgrade
|
@@ -77,6 +78,30 @@ By default, your database structure will be cloned to your test environment. If
|
|
77
78
|
automatically, simply specify an environment variable directly:
|
78
79
|
|
79
80
|
> rake db:upgrade RAILS_ENV=development
|
81
|
+
|
82
|
+
== Serialization
|
83
|
+
|
84
|
+
Keeping track of your serialized attributes can be done in the Migrant DSL (v1.3+), here's some examples:
|
85
|
+
|
86
|
+
class Business < ActiveRecord::Base
|
87
|
+
structure do
|
88
|
+
# Specify serialization automatically (e.g. using Hash, Array, OpenStruct)
|
89
|
+
awards ["Best Chicken 2007", "Business of the year 2008"]
|
90
|
+
|
91
|
+
# Serialization by example types
|
92
|
+
# This would load/store an OpenStruct but store as text in your database
|
93
|
+
staff :serialized, :example => OpenStruct.new("Manager" => "Joe")
|
94
|
+
|
95
|
+
# Default serialization storage (hash)
|
96
|
+
locations :serialized
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
These will call ActiveRecord::Base.serialize for you so don't do it again yourself! The mock generated would appear as:
|
101
|
+
|
102
|
+
irb(main):002:0> my_business = Business.mock
|
103
|
+
=> #<Business id: nil, awards: ["Best Chicken 2007", "Business of the year 2008"], staff: #<OpenStruct manager="Joe">,
|
104
|
+
locations: {}>
|
80
105
|
|
81
106
|
== Want more examples?
|
82
107
|
|
@@ -104,7 +129,6 @@ Simply run rake db:upgrade or rails generate migrations to get the required migr
|
|
104
129
|
|
105
130
|
These actions won't be performed (because we don't want to hurt your data):
|
106
131
|
|
107
|
-
* Remove tables/columns
|
108
132
|
* Changing column types where data loss may occur (e.g. varchar -> int)
|
109
133
|
|
110
134
|
== Getting a mock of your model
|
@@ -129,6 +153,10 @@ Add the following to support/env/pickle.rb:
|
|
129
153
|
|
130
154
|
All pickle steps will then return a mocked model by default, overriden with any values you provide.
|
131
155
|
|
156
|
+
== Help
|
157
|
+
|
158
|
+
Be sure to check out the Github Wiki, or give me a shout on Twitter: @101pascal
|
159
|
+
|
132
160
|
== Maintability / Usability concerns
|
133
161
|
* You don't have to define a structure on every model, Migrant ignores models with no definitions
|
134
162
|
* You can remove the structure definitions later and nothing bad will happen (besides losing automigration for those fields)
|
data/Rakefile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler'
|
3
|
+
require 'simplecov'
|
4
|
+
|
3
5
|
begin
|
4
6
|
Bundler.setup(:default, :development)
|
5
7
|
rescue Bundler::BundlerError => e
|
@@ -7,6 +9,18 @@ rescue Bundler::BundlerError => e
|
|
7
9
|
$stderr.puts "Run `bundle install` to install missing gems"
|
8
10
|
exit e.status_code
|
9
11
|
end
|
12
|
+
|
13
|
+
SimpleCov.adapters.define 'migrant' do
|
14
|
+
add_filter '/test'
|
15
|
+
add_filter '/lib/tasks'
|
16
|
+
add_filter '/lib/railtie' # Not covering lines it's running here .. disabling for now
|
17
|
+
add_filter '/lib/simple_object'
|
18
|
+
|
19
|
+
add_group 'Core Extensions', '/lib/migrant'
|
20
|
+
add_group 'Schema Data Types', '/lib/datatype'
|
21
|
+
end
|
22
|
+
SimpleCov.start 'migrant'
|
23
|
+
|
10
24
|
require 'rake'
|
11
25
|
require 'rake/testtask'
|
12
26
|
Rake::TestTask.new(:test) do |test|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
data/lib/dsl/data_type.rb
CHANGED
@@ -13,12 +13,12 @@ module DataType
|
|
13
13
|
@value = options.delete(:value)
|
14
14
|
@example = options.delete(:example)
|
15
15
|
@field = options.delete(:field)
|
16
|
-
@aliases = options.delete(:was) || Array.new
|
16
|
+
@aliases = options.delete(:was) || ::Array.new
|
17
17
|
options[:type] = options.delete(:as) if options[:as] # Nice little DSL alias for 'type'
|
18
18
|
end
|
19
19
|
|
20
20
|
# Default is 'ye good ol varchar(255)
|
21
|
-
def column_defaults
|
21
|
+
def column_defaults
|
22
22
|
{ :type => :string }
|
23
23
|
end
|
24
24
|
|
@@ -31,9 +31,13 @@ module DataType
|
|
31
31
|
column[:type] == compared_column[:type]
|
32
32
|
end
|
33
33
|
|
34
|
-
def mock
|
34
|
+
def mock
|
35
35
|
@value || self.class.default_mock
|
36
36
|
end
|
37
|
+
|
38
|
+
def serialized?
|
39
|
+
false
|
40
|
+
end
|
37
41
|
|
38
42
|
# Default mock should be overridden in derived classes
|
39
43
|
def self.default_mock
|
@@ -95,7 +95,7 @@ module DataType
|
|
95
95
|
class Symbol < Base
|
96
96
|
def column_defaults
|
97
97
|
# Just construct whatever the user wants
|
98
|
-
{:type => @value || :string }.merge(@options)
|
98
|
+
{:type => ((serialized?)? :text : @value) || :string }.merge(@options)
|
99
99
|
end
|
100
100
|
|
101
101
|
def mock
|
@@ -105,10 +105,52 @@ module DataType
|
|
105
105
|
when :integer then Fixnum.default_mock
|
106
106
|
when :decimal, :float then Float.default_mock
|
107
107
|
when :datetime, :date then Date.default_mock
|
108
|
+
when :serialized, :serialize then (@example)? @example : Hash.default_mock
|
108
109
|
end
|
109
110
|
end
|
111
|
+
|
112
|
+
def serialized?
|
113
|
+
%W{serialized serialize}.include?(@value.to_s)
|
114
|
+
end
|
115
|
+
|
116
|
+
def serialized_class_name
|
117
|
+
klass_name = (@example)? @example.class.to_s : "Hash"
|
118
|
+
|
119
|
+
klass_name.constantize
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Objects
|
124
|
+
class Object < Base
|
125
|
+
def column_defaults
|
126
|
+
{:type => :text }
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.default_mock
|
130
|
+
self.native_class.new
|
131
|
+
end
|
132
|
+
|
133
|
+
def mock
|
134
|
+
@value || self.default_mock
|
135
|
+
end
|
136
|
+
|
137
|
+
def serialized?
|
138
|
+
true
|
139
|
+
end
|
140
|
+
|
141
|
+
def serialized_class_name
|
142
|
+
self.class.native_class
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.native_class
|
146
|
+
self.to_s.split('::').last.constantize
|
147
|
+
end
|
110
148
|
end
|
111
149
|
|
150
|
+
# Store these objects serialized by default
|
151
|
+
class Array < Object; end;
|
152
|
+
class Hash < Object; end;
|
153
|
+
class OpenStruct < Object; end;
|
112
154
|
end
|
113
155
|
|
114
156
|
|
@@ -2,7 +2,7 @@ class <%= @activity.camelize.gsub(/\s/, '') %> < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
3
3
|
create_table :<%= @table_name %> do |t|
|
4
4
|
<% @columns.each do |field, options| %>
|
5
|
-
t.<%= options.delete(:type) %> :<%= field %><%= (options.blank?)? '': ", "+options.to_a.collect { |o| ":#{o[0]}=>#{o[1]}" }.sort.join(', ') %>
|
5
|
+
t.<%= options.delete(:type) %> :<%= field %><%= (options.blank?)? '': ", "+options.to_a.collect { |o| ":#{o[0]}=>#{o[1].inspect}" }.sort.join(', ') %>
|
6
6
|
<% end %>
|
7
7
|
end
|
8
8
|
<% @indexes.each do |index| %>
|
@@ -18,7 +18,13 @@ module Migrant
|
|
18
18
|
# Get all tables and compare to the desired schema
|
19
19
|
# The next line is an evil hack to recursively load all model files in app/models
|
20
20
|
# This needs to be done because Rails normally lazy-loads these files, resulting a blank descendants list of AR::Base
|
21
|
-
|
21
|
+
model_root = "#{Rails.root.to_s}/app/models/"
|
22
|
+
|
23
|
+
Dir["#{model_root}**/*.rb"].each do |file|
|
24
|
+
if (model_name = file.sub(model_root, '').match(/(.*)?\.rb$/))
|
25
|
+
model_name[1].camelize.constantize
|
26
|
+
end
|
27
|
+
end
|
22
28
|
|
23
29
|
ActiveRecord::Base.descendants.select { |model| model.schema && model.schema.requires_migration? }.each do |model|
|
24
30
|
model.reset_column_information # db:migrate doesn't do this
|
@@ -146,11 +152,11 @@ module Migrant
|
|
146
152
|
end
|
147
153
|
|
148
154
|
begin
|
149
|
-
|
155
|
+
prompt = "> #{message} [#{mappings.collect { |shortcut, choice| choice.to_s.sub(shortcut, '('+shortcut+')') }.join(' / ')}]: "
|
150
156
|
if warning
|
151
|
-
STDOUT.print red, bold,
|
157
|
+
STDOUT.print red, bold, prompt, reset
|
152
158
|
else
|
153
|
-
STDOUT.print bold,
|
159
|
+
STDOUT.print bold, prompt, reset
|
154
160
|
end
|
155
161
|
STDOUT.flush
|
156
162
|
input = STDIN.gets.downcase
|
@@ -1,15 +1,28 @@
|
|
1
1
|
module Migrant
|
2
2
|
module ModelExtensions
|
3
3
|
attr_accessor :schema
|
4
|
+
|
5
|
+
def belongs_to(*args)
|
6
|
+
super
|
7
|
+
create_migrant_schema
|
8
|
+
@schema.add_association(self.reflect_on_association(args.first))
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_migrant_schema
|
12
|
+
if self.superclass == ActiveRecord::Base
|
13
|
+
@schema ||= Schema.new
|
14
|
+
else
|
15
|
+
@schema ||= InheritedSchema.new(self.superclass.schema)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
4
19
|
def structure(type=nil, &block)
|
5
20
|
# Using instance_*evil* to get the neater DSL on the models.
|
6
21
|
# So, my_field in the structure block actually calls Migrant::Schema.my_field
|
7
22
|
|
23
|
+
create_migrant_schema
|
8
24
|
if self.superclass == ActiveRecord::Base
|
9
|
-
@schema ||= Schema.new
|
10
|
-
@schema.add_associations(self.reflect_on_all_associations)
|
11
25
|
@schema.define_structure(type, &block)
|
12
|
-
|
13
26
|
@schema.validations.each do |field, validation_options|
|
14
27
|
validations = (validation_options.class == Array)? validation_options : [validation_options]
|
15
28
|
validations.each do |validation|
|
@@ -17,9 +30,14 @@ module Migrant
|
|
17
30
|
self.validates(field, validation)
|
18
31
|
end
|
19
32
|
end
|
33
|
+
# Set up serialized columns as required
|
34
|
+
@schema.columns.select do |name, column|
|
35
|
+
if column.serialized? && !serialized_attributes.keys.include?(name.to_s)
|
36
|
+
serialize(name, column.serialized_class_name)
|
37
|
+
end
|
38
|
+
end
|
20
39
|
else
|
21
40
|
self.superclass.structure(&block) # For STI, cascade all fields onto the parent model
|
22
|
-
@schema = InheritedSchema.new(self.superclass.schema)
|
23
41
|
end
|
24
42
|
end
|
25
43
|
|
@@ -42,7 +60,7 @@ module Migrant
|
|
42
60
|
end
|
43
61
|
|
44
62
|
def mock_attributes(attributes={}, recursive=true)
|
45
|
-
attribs = @schema.columns.collect { |name, data_type| [name, data_type.mock] }.flatten
|
63
|
+
attribs = @schema.columns.collect { |name, data_type| [name, data_type.mock] }.flatten(1)
|
46
64
|
|
47
65
|
# Only recurse to one level, otherwise things get way too complicated
|
48
66
|
if recursive
|
@@ -55,8 +73,8 @@ module Migrant
|
|
55
73
|
Hash[*attribs].merge(attributes)
|
56
74
|
end
|
57
75
|
|
58
|
-
def mock!(attributes={})
|
59
|
-
mock(attributes).tap do |mock|
|
76
|
+
def mock!(attributes={}, recursive=true)
|
77
|
+
mock(attributes, recursive).tap do |mock|
|
60
78
|
mock.save!
|
61
79
|
end
|
62
80
|
end
|
data/lib/migrant/schema.rb
CHANGED
@@ -29,26 +29,25 @@ module Migrant
|
|
29
29
|
@proxy.translate_fancy_dsl(&block) if block_given?
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
32
|
+
def add_association(association)
|
33
|
+
# Rails 3.1 changes primary_key_name to foreign_key (correct behaviour), so this is essentially backwards compatibility for Rails 3.0
|
34
|
+
field = (association.respond_to?(:foreign_key))? association.foreign_key.to_sym : association.primary_key_name.to_sym
|
35
|
+
|
36
|
+
case association.macro
|
37
|
+
when :belongs_to
|
38
|
+
if association.options[:polymorphic]
|
39
|
+
@columns[(association.name.to_s+'_type').to_sym] = DataType::Polymorphic.new(:field => field)
|
40
|
+
@indexes << [(association.name.to_s+'_type').to_sym, field]
|
41
|
+
end
|
42
|
+
@columns[field] = DataType::ForeignKey.new(:field => field)
|
43
|
+
@indexes << field
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
47
|
def requires_migration?
|
49
48
|
true
|
50
49
|
end
|
51
|
-
|
50
|
+
|
52
51
|
# If the user defines structure(:partial), irreversible changes are ignored (removing a column, for example)
|
53
52
|
def partial?
|
54
53
|
@type == :partial
|
@@ -64,7 +63,7 @@ module Migrant
|
|
64
63
|
|
65
64
|
def add_field(field, data_type = nil, options = {})
|
66
65
|
data_type = DataType::String if data_type.nil?
|
67
|
-
puts [":#{field}", "#{data_type}", "#{options.inspect}"].collect { |s| s.ljust(25) }.join if ENV['DEBUG']
|
66
|
+
puts [":#{field}", "#{data_type.class.to_s}", "#{options.inspect}"].collect { |s| s.ljust(25) }.join if ENV['DEBUG']
|
68
67
|
|
69
68
|
# Fields that do special things go here.
|
70
69
|
if field == :timestamps
|
@@ -76,8 +75,8 @@ module Migrant
|
|
76
75
|
# Add index if explicitly asked
|
77
76
|
@indexes << field if options.delete(:index) || data_type.class.to_s == 'Hash' && data_type.delete(:index)
|
78
77
|
@validations[field] = options.delete(:validates) if options[:validates]
|
79
|
-
options.merge!(:field => field)
|
80
|
-
|
78
|
+
options.merge!(:field => field)
|
79
|
+
|
81
80
|
# Matches: description DataType::Paragraph, :index => true
|
82
81
|
if data_type.is_a?(Class) && data_type.respond_to?(:migrant_data_type?)
|
83
82
|
@columns[field] = data_type.new(options)
|
@@ -93,7 +92,6 @@ module Migrant
|
|
93
92
|
end
|
94
93
|
end
|
95
94
|
end
|
96
|
-
|
97
95
|
end
|
98
96
|
|
99
97
|
class InheritedSchema < Schema
|
@@ -101,7 +99,7 @@ module Migrant
|
|
101
99
|
|
102
100
|
def initialize(parent_schema)
|
103
101
|
@parent_schema = parent_schema
|
104
|
-
@columns =
|
102
|
+
@columns = Hash.new
|
105
103
|
@indexes = Array.new
|
106
104
|
end
|
107
105
|
|
data/migrant.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.summary = %q{All the fun of ActiveRecord, without writing your migrations, and a dash of mocking.}
|
23
23
|
|
24
24
|
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
25
|
+
s.add_development_dependency(%q<minitest>, [">= 1.6.0"])
|
25
26
|
s.add_development_dependency(%q<ansi>, [">= 0"])
|
26
27
|
s.add_development_dependency(%q<turn>, [">= 0"])
|
27
28
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
@@ -29,6 +30,7 @@ Gem::Specification.new do |s|
|
|
29
30
|
s.add_development_dependency(%q<terminal-table>, [">= 0"])
|
30
31
|
s.add_development_dependency(%q<term-ansicolor>, [">= 0"])
|
31
32
|
s.add_development_dependency(%q<rake>, [">= 0.8.7"])
|
33
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
32
34
|
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
33
35
|
s.add_dependency(%q<faker>, [">= 0"])
|
34
36
|
s.add_dependency(%q<term-ansicolor>, [">= 0"])
|
data/test/helper.rb
CHANGED
@@ -1,16 +1,5 @@
|
|
1
|
-
require 'simplecov'
|
2
1
|
require 'fileutils'
|
3
2
|
|
4
|
-
SimpleCov.adapters.define 'migrant' do
|
5
|
-
add_filter '/test'
|
6
|
-
add_filter '/lib/tasks'
|
7
|
-
add_filter '/lib/railtie' # Not covering lines it's running here .. disabling for now
|
8
|
-
add_filter '/lib/simple_object'
|
9
|
-
|
10
|
-
add_group 'Core Extensions', '/lib/migrant'
|
11
|
-
add_group 'Schema Data Types', '/lib/datatype'
|
12
|
-
end
|
13
|
-
#SimpleCov.start 'migrant'
|
14
3
|
ENV['RAILS_ENV'] = 'test'
|
15
4
|
|
16
5
|
require 'rubygems'
|
data/test/test_data_schema.rb
CHANGED
@@ -86,8 +86,17 @@ class TestDataSchema < Test::Unit::TestCase
|
|
86
86
|
should "generate indexes on any column when explicitly asked to" do
|
87
87
|
assert_contains(Category.schema.indexes, :title, 'Missing index on :index => true column')
|
88
88
|
end
|
89
|
-
|
90
|
-
|
89
|
+
|
90
|
+
should "generate a text column for serialized fields" do
|
91
|
+
assert_schema(Business, :awards, :type => :text)
|
92
|
+
assert_schema(Business, :managers, :type => :text)
|
93
|
+
|
94
|
+
assert_equal(Array, Business.schema.columns[:awards].mock.class)
|
95
|
+
assert_equal(Hash, Business.schema.columns[:managers].mock.class)
|
96
|
+
|
97
|
+
assert(Business.serialized_attributes.keys.include?("awards"), "Should call ActiveRecord::Base.serialize")
|
98
|
+
assert(Business.serialized_attributes.keys.include?("managers"), "Should call ActiveRecord::Base.serialize")
|
99
|
+
end
|
91
100
|
end
|
92
101
|
|
93
102
|
end
|
@@ -30,6 +30,10 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
flunk "No migration could be found"
|
32
32
|
end
|
33
|
+
|
34
|
+
def delete_last_migration
|
35
|
+
File.delete(Dir.glob(File.join(File.dirname(__FILE__), 'rails_app', 'db' ,'migrate', '*.rb')).last)
|
36
|
+
end
|
33
37
|
|
34
38
|
context "The migration generator" do
|
35
39
|
should "create migrations for all new tables" do
|
@@ -117,14 +121,19 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
117
121
|
test_mockup_of_float :float
|
118
122
|
test_mockup_of_datetime :datetime
|
119
123
|
test_mockup_of_currency DataType::Currency
|
124
|
+
test_mockup_serialized :serialized
|
125
|
+
test_mockup_hash OpenStruct.new({'a' => 'b'})
|
126
|
+
test_mockup_serialized_example :serialized, :example => OpenStruct.new({'c' => 'd'})
|
120
127
|
end
|
128
|
+
|
121
129
|
|
122
130
|
BusinessCategory.belongs_to(:notaclass, :polymorphic => true)
|
123
131
|
generate_migrations
|
124
132
|
rake_migrate
|
125
133
|
BusinessCategory.reset_column_information
|
126
|
-
BusinessCategory.mock!
|
134
|
+
m = BusinessCategory.mock!
|
127
135
|
mock = BusinessCategory.last
|
136
|
+
|
128
137
|
assert_not_nil(mock)
|
129
138
|
assert(mock.test_mockup_of_text.is_a?(String))
|
130
139
|
assert(mock.test_mockup_of_string.is_a?(String))
|
@@ -133,6 +142,16 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
133
142
|
assert(mock.test_mockup_of_currency.is_a?(BigDecimal))
|
134
143
|
assert(mock.test_mockup_of_datetime.is_a?(Time))
|
135
144
|
assert(DataType::Base.default_mock.is_a?(String))
|
145
|
+
assert(mock.test_mockup_serialized.is_a?(Hash))
|
146
|
+
assert(mock.test_mockup_hash.is_a?(OpenStruct))
|
147
|
+
assert_equal(mock.test_mockup_hash.a, 'b')
|
148
|
+
assert(mock.test_mockup_serialized_example.is_a?(OpenStruct))
|
149
|
+
assert_equal(mock.test_mockup_serialized_example.c, 'd')
|
150
|
+
end
|
151
|
+
|
152
|
+
should "not rescursively generate mocks for an inherited model when prohibited by the user" do
|
153
|
+
category_mock = BusinessCategory.mock!({}, false)
|
154
|
+
assert_not_nil(category_mock)
|
136
155
|
end
|
137
156
|
|
138
157
|
should "generate example mocks for an inherited model when STI is in effect" do
|
@@ -141,6 +160,7 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
141
160
|
assert(Customer.mock.is_a?(Customer))
|
142
161
|
end
|
143
162
|
|
163
|
+
|
144
164
|
should "remove extraneous text from a filename too large for the operating system" do
|
145
165
|
BusinessCategory.structure do
|
146
166
|
a_very_very_long_field_indeed_far_too_long_for_any_good_use_really true
|
@@ -148,9 +168,11 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
148
168
|
a_very_very_long_field_indeed_far_too_long_for_any_good_use_really_3 true
|
149
169
|
end
|
150
170
|
|
151
|
-
BusinessCategory.belongs_to(:verylongclassthatissuretogenerateaverylargeoutputfilename
|
171
|
+
BusinessCategory.belongs_to(:verylongclassthatissuretogenerateaverylargeoutputfilename)
|
152
172
|
generate_migrations
|
153
|
-
|
173
|
+
delete_last_migration # Can't actually test migration because the index name is too long!
|
174
|
+
# BusinessCategory.schema.undo_structure_column(:verylongclassthatissuretogenerateaverylargeoutputfilename_id)
|
175
|
+
BusinessCategory.reset_structure!
|
154
176
|
end
|
155
177
|
|
156
178
|
should "remove columns when requested and confirmed by the user" do
|
@@ -1,21 +1,23 @@
|
|
1
1
|
class CreateBusinesses < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :businesses do |t|
|
4
|
-
t.integer :user_id
|
5
|
-
t.string :owner_type
|
6
|
-
t.integer :owner_id
|
7
|
-
t.string :name
|
8
|
-
t.string :website
|
9
|
-
t.text :address
|
10
|
-
t.string :summary
|
11
|
-
t.text :description
|
12
|
-
t.string :landline
|
13
|
-
t.string :mobile
|
14
|
-
t.integer :operating_days, :limit=>1
|
15
|
-
t.datetime :date_established
|
16
|
-
t.datetime :next_sale
|
17
|
-
t.boolean :verified
|
18
|
-
t.string :location, :limit=>127
|
4
|
+
t.integer :user_id
|
5
|
+
t.string :owner_type
|
6
|
+
t.integer :owner_id
|
7
|
+
t.string :name
|
8
|
+
t.string :website
|
9
|
+
t.text :address
|
10
|
+
t.string :summary
|
11
|
+
t.text :description
|
12
|
+
t.string :landline
|
13
|
+
t.string :mobile
|
14
|
+
t.integer :operating_days, :limit=>1
|
15
|
+
t.datetime :date_established
|
16
|
+
t.datetime :next_sale
|
17
|
+
t.boolean :verified
|
18
|
+
t.string :location, :limit=>127
|
19
|
+
t.text :awards
|
20
|
+
t.text :managers
|
19
21
|
end
|
20
22
|
add_index :businesses, :user_id
|
21
23
|
add_index :businesses, [:owner_type, :owner_id]
|
metadata
CHANGED
@@ -1,145 +1,170 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: migrant
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.8
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 1.3.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Pascal Houliston
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
date: 2011-05-23 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
15
16
|
name: thoughtbot-shoulda
|
16
|
-
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
19
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version:
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
22
24
|
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: minitest
|
23
28
|
prerelease: false
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: ansi
|
27
|
-
requirement: &70104235209920 !ruby/object:Gem::Requirement
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
30
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version:
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.6.0
|
33
35
|
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: ansi
|
34
39
|
prerelease: false
|
35
|
-
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: turn
|
38
|
-
requirement: &70104235209100 !ruby/object:Gem::Requirement
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
41
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version:
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
44
46
|
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: turn
|
45
50
|
prerelease: false
|
46
|
-
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: sqlite3
|
49
|
-
requirement: &70104235208420 !ruby/object:Gem::Requirement
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
52
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version:
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
55
57
|
type: :development
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: sqlite3
|
56
61
|
prerelease: false
|
57
|
-
|
58
|
-
- !ruby/object:Gem::Dependency
|
59
|
-
name: simplecov
|
60
|
-
requirement: &70104235207540 !ruby/object:Gem::Requirement
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
61
63
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version:
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
66
68
|
type: :development
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: simplecov
|
67
72
|
prerelease: false
|
68
|
-
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: terminal-table
|
71
|
-
requirement: &70104235206840 !ruby/object:Gem::Requirement
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
72
74
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version:
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
77
79
|
type: :development
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: terminal-table
|
78
83
|
prerelease: false
|
79
|
-
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
name: term-ansicolor
|
82
|
-
requirement: &70104235205000 !ruby/object:Gem::Requirement
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
83
85
|
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version:
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
88
90
|
type: :development
|
91
|
+
version_requirements: *id007
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: term-ansicolor
|
89
94
|
prerelease: false
|
90
|
-
|
91
|
-
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0"
|
101
|
+
type: :development
|
102
|
+
version_requirements: *id008
|
103
|
+
- !ruby/object:Gem::Dependency
|
92
104
|
name: rake
|
93
|
-
|
105
|
+
prerelease: false
|
106
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
94
107
|
none: false
|
95
|
-
requirements:
|
96
|
-
- -
|
97
|
-
- !ruby/object:Gem::Version
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
98
111
|
version: 0.8.7
|
99
112
|
type: :development
|
113
|
+
version_requirements: *id009
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: simplecov
|
100
116
|
prerelease: false
|
101
|
-
|
102
|
-
|
117
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: "0"
|
123
|
+
type: :development
|
124
|
+
version_requirements: *id010
|
125
|
+
- !ruby/object:Gem::Dependency
|
103
126
|
name: rails
|
104
|
-
|
127
|
+
prerelease: false
|
128
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
105
129
|
none: false
|
106
|
-
requirements:
|
107
|
-
- -
|
108
|
-
- !ruby/object:Gem::Version
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
109
133
|
version: 3.0.0
|
110
134
|
type: :runtime
|
111
|
-
|
112
|
-
|
113
|
-
- !ruby/object:Gem::Dependency
|
135
|
+
version_requirements: *id011
|
136
|
+
- !ruby/object:Gem::Dependency
|
114
137
|
name: faker
|
115
|
-
|
138
|
+
prerelease: false
|
139
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
116
140
|
none: false
|
117
|
-
requirements:
|
118
|
-
- -
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
version:
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: "0"
|
121
145
|
type: :runtime
|
122
|
-
|
123
|
-
|
124
|
-
- !ruby/object:Gem::Dependency
|
146
|
+
version_requirements: *id012
|
147
|
+
- !ruby/object:Gem::Dependency
|
125
148
|
name: term-ansicolor
|
126
|
-
|
149
|
+
prerelease: false
|
150
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
127
151
|
none: false
|
128
|
-
requirements:
|
129
|
-
- -
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version:
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: "0"
|
132
156
|
type: :runtime
|
133
|
-
|
134
|
-
version_requirements: *70104235198100
|
157
|
+
version_requirements: *id013
|
135
158
|
description: Easier schema management for Rails that compliments your domain model.
|
136
159
|
email: 101pascal@gmail.com
|
137
160
|
executables: []
|
161
|
+
|
138
162
|
extensions: []
|
139
|
-
|
163
|
+
|
164
|
+
extra_rdoc_files:
|
140
165
|
- LICENSE
|
141
166
|
- README.rdoc
|
142
|
-
files:
|
167
|
+
files:
|
143
168
|
- .gitignore
|
144
169
|
- .rvmrc
|
145
170
|
- Gemfile
|
@@ -224,27 +249,30 @@ files:
|
|
224
249
|
- test/verified_output/migrations/renamed_old_spots.rb
|
225
250
|
homepage: http://github.com/pascalh1011/migrant
|
226
251
|
licenses: []
|
252
|
+
|
227
253
|
post_install_message:
|
228
254
|
rdoc_options: []
|
229
|
-
|
255
|
+
|
256
|
+
require_paths:
|
230
257
|
- lib
|
231
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
258
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
232
259
|
none: false
|
233
|
-
requirements:
|
234
|
-
- -
|
235
|
-
- !ruby/object:Gem::Version
|
236
|
-
version:
|
237
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
260
|
+
requirements:
|
261
|
+
- - ">="
|
262
|
+
- !ruby/object:Gem::Version
|
263
|
+
version: "0"
|
264
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
265
|
none: false
|
239
|
-
requirements:
|
240
|
-
- -
|
241
|
-
- !ruby/object:Gem::Version
|
242
|
-
version:
|
266
|
+
requirements:
|
267
|
+
- - ">="
|
268
|
+
- !ruby/object:Gem::Version
|
269
|
+
version: "0"
|
243
270
|
requirements: []
|
271
|
+
|
244
272
|
rubyforge_project:
|
245
|
-
rubygems_version: 1.8.
|
273
|
+
rubygems_version: 1.8.5
|
246
274
|
signing_key:
|
247
275
|
specification_version: 3
|
248
|
-
summary: All the fun of ActiveRecord, without writing your migrations, and a dash
|
249
|
-
of mocking.
|
276
|
+
summary: All the fun of ActiveRecord, without writing your migrations, and a dash of mocking.
|
250
277
|
test_files: []
|
278
|
+
|