aspgems-redhillonrails_core 2.0.0.beta2 → 2.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/.gitignore +8 -0
  2. data/.travis.yml +8 -0
  3. data/CHANGELOG +16 -0
  4. data/README.md +50 -10
  5. data/README_DEV.md +41 -0
  6. data/Rakefile +43 -13
  7. data/Thorfile +45 -0
  8. data/gemfiles/rails-3.0.7 +13 -0
  9. data/gemfiles/rails-3.0.7.lock +90 -0
  10. data/gemfiles/rails-3.0.8 +13 -0
  11. data/gemfiles/rails-3.0.8.lock +90 -0
  12. data/gemfiles/rails-3.0.9 +13 -0
  13. data/gemfiles/rails-3.0.9.lock +92 -0
  14. data/gemfiles/rails-3.1.0.rc5 +13 -0
  15. data/gemfiles/rails-3.1.0.rc5.lock +106 -0
  16. data/lib/redhillonrails_core.rb +12 -0
  17. data/lib/redhillonrails_core/active_record/base.rb +1 -1
  18. data/lib/redhillonrails_core/active_record/connection_adapters/abstract/foreign_key_definition.rb +13 -6
  19. data/lib/redhillonrails_core/active_record/connection_adapters/abstract/index_definition.rb +3 -0
  20. data/lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb +10 -6
  21. data/lib/redhillonrails_core/active_record/connection_adapters/mysql_adapter.rb +27 -53
  22. data/lib/redhillonrails_core/active_record/connection_adapters/postgresql_adapter.rb +82 -57
  23. data/lib/redhillonrails_core/active_record/migration/command_recorder.rb +30 -0
  24. data/lib/redhillonrails_core/active_record/schema_dumper.rb +18 -6
  25. data/lib/redhillonrails_core/version.rb +1 -1
  26. data/redhillonrails_core.gemspec +2 -1
  27. data/spec/command_recorder_spec.rb +39 -0
  28. data/spec/connections/mysql/connection.rb +4 -6
  29. data/spec/connections/mysql2/connection.rb +4 -6
  30. data/spec/connections/postgresql/connection.rb +4 -3
  31. data/spec/connections/sqlite3/connection.rb +4 -3
  32. data/spec/foreign_key_definition_spec.rb +31 -2
  33. data/spec/foreign_key_spec.rb +15 -2
  34. data/spec/migration_spec.rb +34 -0
  35. data/spec/table_definition_spec.rb +28 -0
  36. metadata +30 -11
@@ -4,12 +4,13 @@ require 'logger'
4
4
  ActiveRecord::Base.logger = Logger.new("debug.log")
5
5
 
6
6
  ActiveRecord::Base.configurations = {
7
- 'redhillonrails' => {
7
+ 'postgres' => {
8
8
  :adapter => 'postgresql',
9
- :database => 'redhillonrails_core_test',
9
+ :database => 'redhillonrails_core',
10
+ :username => 'postgres',
10
11
  :min_messages => 'warning'
11
12
  }
12
13
 
13
14
  }
14
15
 
15
- ActiveRecord::Base.establish_connection 'redhillonrails'
16
+ ActiveRecord::Base.establish_connection 'postgres'
@@ -4,11 +4,12 @@ require 'logger'
4
4
  ActiveRecord::Base.logger = Logger.new("debug.log")
5
5
 
6
6
  ActiveRecord::Base.configurations = {
7
- 'redhillonrails' => {
7
+ 'sqlite3' => {
8
8
  :adapter => 'sqlite3',
9
- :database => File.expand_path(File.dirname(__FILE__) + 'redhillonrails_core.db')
9
+ :database => ':memory:',
10
+ :timeout => 500
10
11
  }
11
12
 
12
13
  }
13
14
 
14
- ActiveRecord::Base.establish_connection 'redhillonrails'
15
+ ActiveRecord::Base.establish_connection 'sqlite3'
@@ -4,12 +4,36 @@ require 'models/user'
4
4
 
5
5
  describe "Foreign Key definition" do
6
6
 
7
- let(:definition) { RedhillonrailsCore::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new("posts_user_fkey", :posts, :user, :users, :id) }
7
+ let(:fk_definition) { RedhillonrailsCore::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition }
8
8
 
9
9
  it "it is dumped to sql with quoted values" do
10
- definition.to_sql.should == %Q{CONSTRAINT posts_user_fkey FOREIGN KEY (#{quote_column_name('user')}) REFERENCES #{quote_table_name('users')} (#{quote_column_name('id')})}
10
+ definition = fk_definition.new("named_fkey", :posts, :user, :users, :id)
11
+ definition.to_sql.should == foreign_key_sql("named_fkey")
11
12
  end
12
13
 
14
+ context "when name isn't given" do
15
+
16
+ it "builds name from table and column name" do
17
+ definition = fk_definition.new(nil, :posts, :user, :users, :id)
18
+ definition.to_sql.should == foreign_key_sql("posts_user_fkey")
19
+ end
20
+
21
+ it "build name with column joined with underscore for compsite key" do
22
+ definition = fk_definition.new(nil, :orders, [:inquiry_id, :user_id], :inquiries, [:id, :user_id])
23
+ expected_definition = "CONSTRAINT orders_inquiry_id_user_id_fkey FOREIGN KEY \
24
+ (#{quote_column_name("inquiry_id")}, #{quote_column_name("user_id")}) \
25
+ REFERENCES #{quote_table_name("inquiries")} (#{quote_column_name("id")}, #{quote_column_name("user_id")})".squeeze(" ")
26
+ definition.to_sql.should == expected_definition
27
+ end
28
+
29
+ end
30
+
31
+ it "does not include name if no name or table_name is given" do
32
+ definition = fk_definition.new(nil, nil, :user, :users, :id)
33
+ definition.to_sql.should == foreign_key_sql(nil)
34
+ end
35
+
36
+ protected
13
37
  def quote_table_name(table)
14
38
  ActiveRecord::Base.connection.quote_table_name(table)
15
39
  end
@@ -18,4 +42,9 @@ describe "Foreign Key definition" do
18
42
  ActiveRecord::Base.connection.quote_column_name(column)
19
43
  end
20
44
 
45
+ def foreign_key_sql(fk_name)
46
+ [("CONSTRAINT #{fk_name}" if fk_name), "FOREIGN KEY (#{quote_column_name('user')}) "\
47
+ "REFERENCES #{quote_table_name('users')} (#{quote_column_name('id')})"].compact.join(' ')
48
+ end
49
+
21
50
  end
@@ -10,7 +10,7 @@ describe "Foreign Key" do
10
10
 
11
11
  context "when is added", "posts(author_id)" do
12
12
 
13
- before(:each) do
13
+ before(:each) do
14
14
  add_foreign_key(:posts, :author_id, :users, :id, :on_update => :cascade, :on_delete => :restrict)
15
15
  end
16
16
 
@@ -60,7 +60,7 @@ describe "Foreign Key" do
60
60
  it "is no longer available in Post.foreign_keys" do
61
61
  Comment.foreign_keys.collect(&:column_names).should_not include(%w[post_id])
62
62
  end
63
-
63
+
64
64
  it "is no longer available in User.reverse_foreign_keys" do
65
65
  Post.reverse_foreign_keys.collect(&:column_names).should_not include(%w[post_id])
66
66
  end
@@ -78,6 +78,19 @@ describe "Foreign Key" do
78
78
 
79
79
  end
80
80
 
81
+ it "shouldn't raise when restrited keyword in table name is used" do
82
+ migration.suppress_messages do
83
+ migration.create_table :select, :force => true do |t|
84
+ t.integer :post_id
85
+ end
86
+ end
87
+ expect do
88
+ add_foreign_key(:select, :post_id, :posts, :id, :name => "test_fk")
89
+ remove_foreign_key(:select, "test_fk")
90
+ end.should_not raise_error(Exception)
91
+ migration.suppress_messages { migration.drop_table :select }
92
+ end
93
+
81
94
  protected
82
95
  def add_foreign_key(*args)
83
96
  migration.suppress_messages do
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Migration" do
4
+
5
+ let(:migration) { ActiveRecord::Migration }
6
+
7
+ it "should allow to remove more then one column at once" do
8
+ migration.suppress_messages do
9
+ migration.create_table :likes, :id => false, :force => true do |t|
10
+ t.string :remarks
11
+ t.integer :post_id
12
+ t.datetime :created_at
13
+ end
14
+ migration.remove_columns :likes, :post_id, :created_at
15
+ migration.connection.columns(:likes).should have(1).column
16
+ migration.drop_table :likes
17
+ end
18
+ end
19
+
20
+ it "should raise an exception if try to remove no column" do
21
+ migration.suppress_messages do
22
+ migration.create_table :likes, :id => false, :force => true do |t|
23
+ t.string :remarks
24
+ t.integer :post_id
25
+ t.datetime :created_at
26
+ end
27
+ expect {
28
+ migration.remove_columns :likes
29
+ }.to raise_error(ArgumentError)
30
+ migration.drop_table :likes
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ require 'models/post'
4
+
5
+ describe "Table definition" do
6
+
7
+ let(:connection) { ::ActiveRecord::Migration.connection }
8
+
9
+ unless ::ActiveRecord::Base.connection.class.include?(
10
+ RedhillonrailsCore::ActiveRecord::ConnectionAdapters::Sqlite3Adapter)
11
+
12
+ it "sets table_name of foreign key definition when running migrations" do
13
+ connection.create_table :votes, :force => true do |t|
14
+ t.integer :kind
15
+ t.integer :application_id
16
+ t.integer :user_id
17
+ t.foreign_key :user_id, :users, :id
18
+ end
19
+
20
+ Vote = Class.new(ActiveRecord::Base)
21
+ Vote.foreign_keys.size.should == 1
22
+ Vote.foreign_keys[0].table_name.should == 'votes'
23
+ connection.drop_table :votes
24
+ end
25
+
26
+ end
27
+
28
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: aspgems-redhillonrails_core
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 2.0.0.beta2
5
+ version: 2.0.0.beta4
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Micha\xC5\x82 \xC5\x81omnicki"
@@ -11,11 +11,10 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-05-14 00:00:00 Z
14
+ date: 2011-08-06 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord
18
- prerelease: false
19
18
  requirement: &id001 !ruby/object:Gem::Requirement
20
19
  none: false
21
20
  requirements:
@@ -23,10 +22,10 @@ dependencies:
23
22
  - !ruby/object:Gem::Version
24
23
  version: "2"
25
24
  type: :runtime
25
+ prerelease: false
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
- prerelease: false
30
29
  requirement: &id002 !ruby/object:Gem::Requirement
31
30
  none: false
32
31
  requirements:
@@ -34,21 +33,21 @@ dependencies:
34
33
  - !ruby/object:Gem::Version
35
34
  version: "2"
36
35
  type: :runtime
36
+ prerelease: false
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rspec
40
- prerelease: false
41
40
  requirement: &id003 !ruby/object:Gem::Requirement
42
41
  none: false
43
42
  requirements:
44
43
  - - ~>
45
44
  - !ruby/object:Gem::Version
46
- version: 2.5.0
45
+ version: 2.6.0
47
46
  type: :development
47
+ prerelease: false
48
48
  version_requirements: *id003
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: pg
51
- prerelease: false
52
51
  requirement: &id004 !ruby/object:Gem::Requirement
53
52
  none: false
54
53
  requirements:
@@ -56,10 +55,10 @@ dependencies:
56
55
  - !ruby/object:Gem::Version
57
56
  version: "0"
58
57
  type: :development
58
+ prerelease: false
59
59
  version_requirements: *id004
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: mysql
62
- prerelease: false
63
62
  requirement: &id005 !ruby/object:Gem::Requirement
64
63
  none: false
65
64
  requirements:
@@ -67,10 +66,10 @@ dependencies:
67
66
  - !ruby/object:Gem::Version
68
67
  version: "0"
69
68
  type: :development
69
+ prerelease: false
70
70
  version_requirements: *id005
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: mysql2
73
- prerelease: false
74
73
  requirement: &id006 !ruby/object:Gem::Requirement
75
74
  none: false
76
75
  requirements:
@@ -78,10 +77,10 @@ dependencies:
78
77
  - !ruby/object:Gem::Version
79
78
  version: "0"
80
79
  type: :development
80
+ prerelease: false
81
81
  version_requirements: *id006
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: sqlite3-ruby
84
- prerelease: false
85
84
  requirement: &id007 !ruby/object:Gem::Requirement
86
85
  none: false
87
86
  requirements:
@@ -89,6 +88,7 @@ dependencies:
89
88
  - !ruby/object:Gem::Version
90
89
  version: 1.3.1
91
90
  type: :development
91
+ prerelease: false
92
92
  version_requirements: *id007
93
93
  description: Adds support in ActiveRecord for foreign_keys, complex indexes and other database-related stuff. Easily create foreign_keys, complex indexes and views.
94
94
  email:
@@ -101,11 +101,23 @@ extensions: []
101
101
  extra_rdoc_files: []
102
102
 
103
103
  files:
104
+ - .gitignore
105
+ - .travis.yml
104
106
  - CHANGELOG
105
107
  - Gemfile
106
108
  - MIT-LICENSE
107
109
  - README.md
110
+ - README_DEV.md
108
111
  - Rakefile
112
+ - Thorfile
113
+ - gemfiles/rails-3.0.7
114
+ - gemfiles/rails-3.0.7.lock
115
+ - gemfiles/rails-3.0.8
116
+ - gemfiles/rails-3.0.8.lock
117
+ - gemfiles/rails-3.0.9
118
+ - gemfiles/rails-3.0.9.lock
119
+ - gemfiles/rails-3.1.0.rc5
120
+ - gemfiles/rails-3.1.0.rc5.lock
109
121
  - init.rb
110
122
  - lib/redhillonrails_core.rb
111
123
  - lib/redhillonrails_core/active_record/base.rb
@@ -119,11 +131,13 @@ files:
119
131
  - lib/redhillonrails_core/active_record/connection_adapters/mysql_column.rb
120
132
  - lib/redhillonrails_core/active_record/connection_adapters/postgresql_adapter.rb
121
133
  - lib/redhillonrails_core/active_record/connection_adapters/sqlite3_adapter.rb
134
+ - lib/redhillonrails_core/active_record/migration/command_recorder.rb
122
135
  - lib/redhillonrails_core/active_record/schema.rb
123
136
  - lib/redhillonrails_core/active_record/schema_dumper.rb
124
137
  - lib/redhillonrails_core/version.rb
125
138
  - lib/tasks/db/comments.rake
126
139
  - redhillonrails_core.gemspec
140
+ - spec/command_recorder_spec.rb
127
141
  - spec/connections/mysql/connection.rb
128
142
  - spec/connections/mysql2/connection.rb
129
143
  - spec/connections/postgresql/connection.rb
@@ -132,6 +146,7 @@ files:
132
146
  - spec/foreign_key_spec.rb
133
147
  - spec/index_definition_spec.rb
134
148
  - spec/index_spec.rb
149
+ - spec/migration_spec.rb
135
150
  - spec/models/comment.rb
136
151
  - spec/models/post.rb
137
152
  - spec/models/user.rb
@@ -139,6 +154,7 @@ files:
139
154
  - spec/schema_dumper_spec.rb
140
155
  - spec/spec_helper.rb
141
156
  - spec/support/reference.rb
157
+ - spec/table_definition_spec.rb
142
158
  homepage: https://github.com/aspgems/redhillonrails_core
143
159
  licenses: []
144
160
 
@@ -152,6 +168,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
168
  requirements:
153
169
  - - ">="
154
170
  - !ruby/object:Gem::Version
171
+ hash: 437283791
172
+ segments:
173
+ - 0
155
174
  version: "0"
156
175
  required_rubygems_version: !ruby/object:Gem::Requirement
157
176
  none: false
@@ -162,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
181
  requirements: []
163
182
 
164
183
  rubyforge_project:
165
- rubygems_version: 1.7.2
184
+ rubygems_version: 1.8.5
166
185
  signing_key:
167
186
  specification_version: 3
168
187
  summary: Adds support in ActiveRecord for foreign_keys, complex indexes and other database-related stuff