mini_record-compat 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
- [![Build Status](https://secure.travis-ci.org/DAddYE/mini_record.png)](http://travis-ci.org/DAddYE/mini_record)
1
+ # DEPRECATED
2
2
 
3
+ The old `mini_record-compat` gem has been deprecated in favor of [`active_record_inline_schema`](https://github.com/seamusabshere/active_record_inline_schema).
4
+
5
+ Please use [`active_record_inline_schema`](https://github.com/seamusabshere/active_record_inline_schema) or [original mini_record](https://github.com/DAddYE/mini_record) instead of `mini_record-compat`.
6
+
7
+ # DEPRECATED
3
8
 
4
9
  MiniRecord is a micro extension for our `ActiveRecord` gem.
5
10
  With MiniRecord you can add the ability to create columns outside the default `schema.rb`, directly
data/Rakefile CHANGED
@@ -30,7 +30,7 @@ task :test_each_db_adapter do
30
30
  puts
31
31
  puts "#{'*'*10} Running #{db_adapter} tests"
32
32
  puts
33
- puts `bundle exec rake test TEST=spec/#{db_adapter}_spec.rb`
33
+ puts `bundle exec rake test DB_ADAPTER=#{db_adapter} TEST=spec/#{db_adapter}_spec.rb`
34
34
  end
35
35
  end
36
36
 
@@ -27,7 +27,11 @@ module MiniRecord
27
27
  options = args.extract_options!
28
28
  type = options.delete(:as) || options.delete(:type) || :string
29
29
  args.each do |column_name|
30
- table_definition.send(type, column_name, options)
30
+ if table_definition.respond_to?(type)
31
+ table_definition.send(type, column_name, options)
32
+ else
33
+ table_definition.column(column_name, type, options)
34
+ end
31
35
  column_name = table_definition.columns[-1].name
32
36
  case index_name = options.delete(:index)
33
37
  when Hash
@@ -104,23 +108,31 @@ module MiniRecord
104
108
 
105
109
  # avoid using connection.create_table because in 3.0.x it ignores table_definition
106
110
  # and it also is too eager about adding a primary key column
107
- create_sql = "CREATE TABLE "
108
- create_sql << "#{quoted_table_name} ("
109
- create_sql << table_definition.to_sql
110
- create_sql << ") #{create_table_options}"
111
- connection.execute create_sql
111
+ create_sql = "CREATE TABLE #{quoted_table_name} (#{table_definition.to_sql}) #{create_table_options}"
112
112
 
113
- if non_standard_primary_key
114
- if sqlite?
113
+ if sqlite?
114
+ connection.execute create_sql
115
+ if non_standard_primary_key
115
116
  add_index primary_key, :unique => true
116
- elsif mysql? or postgresql?
117
- # can't use add_index method because it won't let you do "PRIMARY KEY"
117
+ end
118
+ elsif postgresql?
119
+ connection.execute create_sql
120
+ if non_standard_primary_key
121
+ # can't use add_index method because it won't let you do "PRIMARY KEY"
118
122
  connection.execute "ALTER TABLE #{quoted_table_name} ADD PRIMARY KEY (#{quoted_primary_key})"
119
- else
120
- raise RuntimeError, "mini_record doesn't support non-standard primary keys for the #{connection.adapter_name} adapter!"
121
123
  end
124
+ elsif mysql?
125
+ if non_standard_primary_key
126
+ # only string keys are supported
127
+ create_sql.sub! %r{#{connection.quote_column_name(primary_key)} varchar\(255\)([^,\)]*)}, "#{connection.quote_column_name(primary_key)} varchar(255)\\1 PRIMARY KEY"
128
+ create_sql.sub! 'DEFAULT NULLPRIMARY KEY', 'PRIMARY KEY'
129
+ end
130
+ connection.execute create_sql
122
131
  end
123
132
 
133
+ if connection.respond_to?(:schema_cache)
134
+ connection.schema_cache.clear!
135
+ end
124
136
  reset_column_information
125
137
  end
126
138
 
@@ -164,7 +176,9 @@ module MiniRecord
164
176
  new_attr = {}
165
177
 
166
178
  # First, check if the field type changed
167
- if fields_in_schema[field].type.to_sym != fields_in_db[field].type.to_sym
179
+ if (fields_in_schema[field].type.to_sym != fields_in_db[field].type.to_sym) and (fields_in_schema[field].type.to_sym != fields_in_db[field].sql_type.to_sym)
180
+ # $stderr.puts "A(#{field}) - #{fields_in_schema[field].type.to_sym}"
181
+ # $stderr.puts "B(#{field}) - #{fields_in_db[field].type.to_sym} - #{fields_in_db[field].sql_type.to_sym}"
168
182
  changed = true
169
183
  end
170
184
 
@@ -178,6 +192,8 @@ module MiniRecord
178
192
  fields_in_schema[field].each_pair do |att,value|
179
193
  next if att == :type or att == :base or att == :name # special cases
180
194
  if !value.nil? && value != fields_in_db[field].send(att)
195
+ # $stderr.puts "C(#{att}) - #{value.inspect}"
196
+ # $stderr.puts "D(#{att}) - #{fields_in_db[field].send(att).inspect}"
181
197
  new_attr[att] = value
182
198
  changed = true
183
199
  end
@@ -203,6 +219,9 @@ module MiniRecord
203
219
  end
204
220
 
205
221
  # Reload column information
222
+ if connection.respond_to?(:schema_cache)
223
+ connection.schema_cache.clear!
224
+ end
206
225
  reset_column_information
207
226
  end
208
227
  end # ClassMethods
@@ -1,3 +1,3 @@
1
1
  module MiniRecord
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/mini_record.gemspec CHANGED
@@ -8,12 +8,9 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Davide D'Agostino", "Seamus Abshere"]
9
9
  s.email = ["d.dagostino@lipsiasoft.com", "seamus@abshere.net"]
10
10
  s.homepage = "https://github.com/seamusabshere/mini_record"
11
- s.summary = %q{Alternate gem published by Seamus Abshere for ActiveRecord 3.0 support. MiniRecord is a micro gem that allow you to write schema inside your model as you can do in DataMapper.}
12
- s.description = %q{
13
- With it you can add the ability to create columns outside the default schema, directly
14
- in your model in a similar way that you just know in others projects
15
- like DataMapper or MongoMapper.
16
- }.gsub(/^ {4}/, '')
11
+ spec = %q{DEPRECATED. Use active_record_inline_schema or original mini_record gem instead.}
12
+ s.summary = spec
13
+ s.description = spec
17
14
 
18
15
  # s.rubyforge_project = "mini_record"
19
16
 
@@ -23,6 +20,9 @@ Gem::Specification.new do |s|
23
20
  s.require_paths = ["lib"]
24
21
 
25
22
  s.add_runtime_dependency "activerecord", ">=3"
23
+ # s.add_runtime_dependency "activerecord", "3.0.12"
24
+ # s.add_runtime_dependency "activerecord", "3.1.3"
25
+ # s.add_runtime_dependency "activerecord", "3.2.2"
26
26
 
27
27
  # dev dependencies appear to be in the Gemfile
28
28
  end
data/spec/models.rb CHANGED
@@ -41,18 +41,26 @@ class Cat < Pet; end
41
41
  class Vegetable < ActiveRecord::Base
42
42
  include SpecHelper
43
43
 
44
- set_primary_key :latin_name
44
+ self.primary_key = 'latin_name'
45
45
 
46
46
  col :latin_name
47
47
  col :common_name
48
48
  end
49
49
 
50
+ class Gender < ActiveRecord::Base
51
+ include SpecHelper
52
+
53
+ self.primary_key = 'name'
54
+
55
+ col :name
56
+ end
57
+
50
58
  class User < ActiveRecord::Base
51
59
  include SpecHelper
60
+ self.inheritance_column = 'role' # messed up in 3.2.2
52
61
  col :name
53
62
  col :surname
54
63
  col :role
55
- set_inheritance_column :role
56
64
  end
57
65
  class Administrator < User; end
58
66
  class Customer < User; end
@@ -68,3 +76,18 @@ class AutomobileMakeModelYearVariant < ActiveRecord::Base
68
76
  col :make_model_year_name
69
77
  add_index :make_model_year_name
70
78
  end
79
+
80
+ case ENV['DB_ADAPTER']
81
+ when 'mysql'
82
+ class CustomMysql < ActiveRecord::Base
83
+ include SpecHelper
84
+ col :varb, :type => 'varbinary(255)'
85
+ col :varc, :type => 'varchar(255)'
86
+ end
87
+ when 'postgresql'
88
+ class CustomPostgresql < ActiveRecord::Base
89
+ include SpecHelper
90
+ col :inet, :type => 'inet'
91
+ col :bytea, :type => 'bytea'
92
+ end
93
+ end
@@ -1,7 +1,7 @@
1
1
  describe MiniRecord do
2
2
  before do
3
3
  ActiveRecord::Base.descendants.each do |active_record|
4
- ActiveRecord::Base.connection.drop_table active_record.table_name if active_record.table_exists?
4
+ ActiveRecord::Base.connection.drop_table active_record.table_name rescue nil
5
5
  end
6
6
  end
7
7
 
@@ -194,6 +194,11 @@ describe MiniRecord do
194
194
  end
195
195
  end
196
196
 
197
+ it 'properly creates tables with one column, a string primary key' do
198
+ Gender.auto_upgrade!
199
+ Gender.column_names.must_equal ['name']
200
+ end
201
+
197
202
  it 'is idempotent' do
198
203
  ActiveRecord::Base.descendants.each do |active_record|
199
204
  active_record.auto_upgrade!
@@ -211,6 +216,21 @@ describe MiniRecord do
211
216
  [ active_record.db_columns, active_record.db_indexes ].must_equal before
212
217
  end
213
218
  end
219
+
220
+ case ENV['DB_ADAPTER']
221
+ when 'mysql'
222
+ it "takes custom types" do
223
+ CustomMysql.auto_upgrade!
224
+ CustomMysql.columns_hash['varb'].sql_type.must_equal 'varbinary(255)'
225
+ CustomMysql.columns_hash['varc'].sql_type.must_equal 'varchar(255)'
226
+ end
227
+ when 'postgresql'
228
+ it "takes custom types" do
229
+ CustomPostgresql.auto_upgrade!
230
+ CustomPostgresql.columns_hash['inet'].sql_type.must_equal 'inet'
231
+ CustomPostgresql.columns_hash['bytea'].sql_type.must_equal 'bytea'
232
+ end
233
+ end
214
234
 
215
235
  private
216
236
 
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,10 @@ require 'bundler/setup'
3
3
  require 'mini_record'
4
4
  require 'minitest/autorun'
5
5
 
6
+ # require 'logger'
7
+ # ActiveRecord::Base.logger = Logger.new($stderr)
8
+ # ActiveRecord::Base.logger.level = Logger::DEBUG
9
+
6
10
  module SpecHelper
7
11
  def self.included(base)
8
12
  base.extend(ClassMethods)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_record-compat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-10-26 00:00:00.000000000Z
13
+ date: 2012-03-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: &2153710260 !ruby/object:Gem::Requirement
17
+ requirement: &2166679180 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,9 @@ dependencies:
22
22
  version: '3'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2153710260
26
- description: ! "\nWith it you can add the ability to create columns outside the default
27
- schema, directly\nin your model in a similar way that you just know in others projects\nlike
28
- \ DataMapper or MongoMapper.\n "
25
+ version_requirements: *2166679180
26
+ description: DEPRECATED. Use active_record_inline_schema or original mini_record gem
27
+ instead.
29
28
  email:
30
29
  - d.dagostino@lipsiasoft.com
31
30
  - seamus@abshere.net
@@ -68,12 +67,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
67
  version: '0'
69
68
  requirements: []
70
69
  rubyforge_project:
71
- rubygems_version: 1.8.10
70
+ rubygems_version: 1.8.15
72
71
  signing_key:
73
72
  specification_version: 3
74
- summary: Alternate gem published by Seamus Abshere for ActiveRecord 3.0 support. MiniRecord
75
- is a micro gem that allow you to write schema inside your model as you can do in
76
- DataMapper.
73
+ summary: DEPRECATED. Use active_record_inline_schema or original mini_record gem instead.
77
74
  test_files:
78
75
  - spec/models.rb
79
76
  - spec/mysql_spec.rb
@@ -81,3 +78,4 @@ test_files:
81
78
  - spec/shared_examples.rb
82
79
  - spec/spec_helper.rb
83
80
  - spec/sqlite3_spec.rb
81
+ has_rdoc: