migrant 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +11 -0
- data/VERSION +1 -1
- data/lib/datatype/currency.rb +1 -1
- data/lib/datatype/fixnum.rb +3 -1
- data/lib/migrant/migration_generator.rb +8 -2
- data/lib/migrant/model_extensions.rb +13 -1
- data/lib/pickle/migrant.rb +16 -0
- data/migrant.gemspec +3 -2
- data/test/test_data_schema.rb +1 -4
- data/test/test_migration_generator.rb +20 -1
- metadata +4 -3
data/README.rdoc
CHANGED
@@ -118,6 +118,17 @@ These actions won't be performed (because we don't want to hurt your data):
|
|
118
118
|
irb(main):003:0> my_business.user
|
119
119
|
=> #<User id: nil, name: "John", surname: "Smith", description: "Some string">
|
120
120
|
|
121
|
+
== Pickle/Cucumber Integration
|
122
|
+
|
123
|
+
Add the following to support/env/pickle.rb:
|
124
|
+
|
125
|
+
require 'pickle/migrant'
|
126
|
+
Pickle.configure do |config|
|
127
|
+
config.adapters = [Pickle::Migrant]
|
128
|
+
end
|
129
|
+
|
130
|
+
All pickle steps will then return a mocked model by default, overriden with any values you provide.
|
131
|
+
|
121
132
|
== Maintability / Usability concerns
|
122
133
|
* You don't have to define a structure on every model, Migrant ignores models with no definitions
|
123
134
|
* You can remove the structure definitions later and nothing bad will happen (besides losing automigration for those fields)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.1
|
data/lib/datatype/currency.rb
CHANGED
data/lib/datatype/fixnum.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module DataType
|
2
2
|
class Fixnum < Base
|
3
3
|
def column
|
4
|
-
{:type => :integer}
|
4
|
+
{:type => :integer}.tap do |options|
|
5
|
+
options.merge!(:limit => @value.size) if @value > 2147483647 # 32-bit limit. Not checking size here because a 64-bit OS always has at least 8 byte size
|
6
|
+
end
|
5
7
|
end
|
6
8
|
|
7
9
|
def self.default_mock
|
@@ -86,8 +86,14 @@ module Migrant
|
|
86
86
|
|
87
87
|
# Indexes
|
88
88
|
# down_code += NEWLINE+TABS+model.schema.indexes.collect { |fields| "remove_index :#{model.table_name}, #{fields.inspect}"}.join(NEWLINE+TABS)
|
89
|
-
|
90
|
-
|
89
|
+
begin
|
90
|
+
filename = "#{migrations_path}/#{next_migration_number}_#{activity}.rb"
|
91
|
+
File.open(filename, 'w') { |migration| migration.write(migration_template(activity, up_code, down_code)) }
|
92
|
+
rescue Errno::ENAMETOOLONG
|
93
|
+
activity = activity.split('_')[0..2].join('_')
|
94
|
+
filename = "#{migrations_path}/#{next_migration_number}_#{activity}.rb"
|
95
|
+
File.open(filename, 'w') { |migration| migration.write(migration_template(activity, up_code, down_code)) }
|
96
|
+
end
|
91
97
|
puts "Wrote #{filename}..."
|
92
98
|
end
|
93
99
|
true
|
@@ -30,6 +30,12 @@ module Migrant
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def mock(attributes={}, recursive=true)
|
33
|
+
attribs = {}
|
34
|
+
attribs.merge!(self.superclass.mock_attributes(attributes, recursive)) unless self.superclass == ActiveRecord::Base
|
35
|
+
new attribs.merge(mock_attributes(attributes, recursive))
|
36
|
+
end
|
37
|
+
|
38
|
+
def mock_attributes(attributes={}, recursive=true)
|
33
39
|
attribs = @schema.columns.collect { |name, data_type| [name, data_type.mock] }.flatten
|
34
40
|
|
35
41
|
# Only recurse to one level, otherwise things get way too complicated
|
@@ -40,7 +46,13 @@ module Migrant
|
|
40
46
|
rescue NameError; nil; end # User hasn't defined association, just skip it
|
41
47
|
end.compact.flatten
|
42
48
|
end
|
43
|
-
|
49
|
+
Hash[*attribs].merge(attributes)
|
50
|
+
end
|
51
|
+
|
52
|
+
def mock!(attributes={})
|
53
|
+
mock(attributes).tap do |mock|
|
54
|
+
mock.save!
|
55
|
+
end
|
44
56
|
end
|
45
57
|
end
|
46
58
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Pickle
|
2
|
+
class Migrant < Adapter
|
3
|
+
def self.factories
|
4
|
+
model_classes.select { |model| model.respond_to?(:mock) }.collect { |model| new(model) }
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(klass)
|
8
|
+
@klass, @name = klass, klass.name.underscore.gsub('/', '_')
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(attrs={})
|
12
|
+
@klass.mock!(Hash[attrs.collect { |k,v| [k.to_sym, v] }])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/migrant.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{migrant}
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Pascal Houliston"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-04-01}
|
13
13
|
s.description = %q{Easier schema management for Rails that compliments your domain model.}
|
14
14
|
s.email = %q{101pascal@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
"lib/migrant/migration_generator.rb",
|
43
43
|
"lib/migrant/model_extensions.rb",
|
44
44
|
"lib/migrant/schema.rb",
|
45
|
+
"lib/pickle/migrant.rb",
|
45
46
|
"lib/railtie.rb",
|
46
47
|
"lib/simple_object.rb",
|
47
48
|
"lib/tasks/db.rake",
|
data/test/test_data_schema.rb
CHANGED
@@ -68,10 +68,6 @@ class TestDataSchema < Test::Unit::TestCase
|
|
68
68
|
assert_schema(User, :email, :type => :string)
|
69
69
|
end
|
70
70
|
|
71
|
-
should "generate the column type specified by the :as key irrespective of the data type" do
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
71
|
should "generate indexes for all foreign keys automatically" do
|
76
72
|
assert_contains(Business.schema.indexes, :user_id, 'Missing index on belongs_to')
|
77
73
|
assert_contains(Business.schema.indexes, [:owner_type, :owner_id], 'Missing index on polymorphic belongs_to')
|
@@ -83,6 +79,7 @@ class TestDataSchema < Test::Unit::TestCase
|
|
83
79
|
assert_contains(Category.schema.indexes, :title, 'Missing index on :index => true column')
|
84
80
|
end
|
85
81
|
|
82
|
+
|
86
83
|
end
|
87
84
|
|
88
85
|
end
|
@@ -118,7 +118,8 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
118
118
|
assert_equal true, Migrant::MigrationGenerator.new.run, "Migration Generator reported an error"
|
119
119
|
rake_migrate
|
120
120
|
BusinessCategory.reset_column_information
|
121
|
-
|
121
|
+
BusinessCategory.mock!
|
122
|
+
mock = BusinessCategory.last
|
122
123
|
assert_not_nil(mock)
|
123
124
|
assert(mock.test_mockup_of_text.is_a?(String))
|
124
125
|
assert(mock.test_mockup_of_string.is_a?(String))
|
@@ -128,6 +129,24 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
128
129
|
assert(mock.test_mockup_of_datetime.is_a?(Time))
|
129
130
|
assert(DataType::Base.default_mock.is_a?(String))
|
130
131
|
end
|
132
|
+
|
133
|
+
should "generate example mocks for an inherited model when STI is in effect" do
|
134
|
+
assert_equal(5.00, Customer.mock.average_rating)
|
135
|
+
assert_equal("somebody@somewhere.com", Customer.mock.email)
|
136
|
+
assert(Customer.mock.is_a?(Customer))
|
137
|
+
end
|
138
|
+
|
139
|
+
should "remove extraneous text from a filename too large for the operating system" do
|
140
|
+
BusinessCategory.structure do
|
141
|
+
a_very_very_long_field_indeed_far_too_long_for_any_good_use_really true
|
142
|
+
a_very_very_long_field_indeed_far_too_long_for_any_good_use_really_2 true
|
143
|
+
a_very_very_long_field_indeed_far_too_long_for_any_good_use_really_3 true
|
144
|
+
end
|
145
|
+
|
146
|
+
BusinessCategory.belongs_to(:verylongclassthatissuretogenerateaverylargeoutputfilename, :polymorphic => true)
|
147
|
+
assert_equal true, Migrant::MigrationGenerator.new.run, "Migration Generator reported an error"
|
148
|
+
rake_migrate
|
149
|
+
end
|
131
150
|
end
|
132
151
|
end
|
133
152
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: migrant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.1.
|
5
|
+
version: 1.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Pascal Houliston
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-04-01 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- lib/migrant/migration_generator.rb
|
137
137
|
- lib/migrant/model_extensions.rb
|
138
138
|
- lib/migrant/schema.rb
|
139
|
+
- lib/pickle/migrant.rb
|
139
140
|
- lib/railtie.rb
|
140
141
|
- lib/simple_object.rb
|
141
142
|
- lib/tasks/db.rake
|
@@ -203,7 +204,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
203
204
|
requirements:
|
204
205
|
- - ">="
|
205
206
|
- !ruby/object:Gem::Version
|
206
|
-
hash:
|
207
|
+
hash: -2795285372725483730
|
207
208
|
segments:
|
208
209
|
- 0
|
209
210
|
version: "0"
|