jorahood-ar-extensions 0.9.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +145 -0
- data/README +167 -0
- data/Rakefile +79 -0
- data/config/database.yml +7 -0
- data/config/database.yml.template +7 -0
- data/config/mysql.schema +72 -0
- data/config/postgresql.schema +39 -0
- data/db/migrate/generic_schema.rb +96 -0
- data/db/migrate/mysql_schema.rb +31 -0
- data/db/migrate/oracle_schema.rb +5 -0
- data/db/migrate/version.rb +4 -0
- data/init.rb +31 -0
- data/lib/ar-extensions/create_and_update.rb +509 -0
- data/lib/ar-extensions/csv.rb +309 -0
- data/lib/ar-extensions/delete.rb +143 -0
- data/lib/ar-extensions/extensions.rb +506 -0
- data/lib/ar-extensions/finder_options.rb +275 -0
- data/lib/ar-extensions/finders.rb +94 -0
- data/lib/ar-extensions/foreign_keys.rb +70 -0
- data/lib/ar-extensions/fulltext.rb +62 -0
- data/lib/ar-extensions/import.rb +352 -0
- data/lib/ar-extensions/insert_select.rb +178 -0
- data/lib/ar-extensions/synchronize.rb +30 -0
- data/lib/ar-extensions/temporary_table.rb +124 -0
- data/lib/ar-extensions/union.rb +204 -0
- data/lib/ar-extensions/version.rb +9 -0
- data/tests/connections/native_mysql/connection.rb +16 -0
- data/tests/connections/native_oracle/connection.rb +16 -0
- data/tests/connections/native_postgresql/connection.rb +19 -0
- data/tests/connections/native_sqlite/connection.rb +14 -0
- data/tests/connections/native_sqlite3/connection.rb +14 -0
- data/tests/fixtures/addresses.yml +25 -0
- data/tests/fixtures/books.yml +46 -0
- data/tests/fixtures/developers.yml +20 -0
- data/tests/fixtures/unit/active_record_base_finders/addresses.yml +25 -0
- data/tests/fixtures/unit/active_record_base_finders/books.yml +64 -0
- data/tests/fixtures/unit/active_record_base_finders/developers.yml +20 -0
- data/tests/fixtures/unit/synchronize/books.yml +16 -0
- data/tests/fixtures/unit/to_csv_headers/addresses.yml +8 -0
- data/tests/fixtures/unit/to_csv_headers/developers.yml +6 -0
- data/tests/fixtures/unit/to_csv_with_common_options/addresses.yml +40 -0
- data/tests/fixtures/unit/to_csv_with_common_options/developers.yml +13 -0
- data/tests/fixtures/unit/to_csv_with_common_options/languages.yml +29 -0
- data/tests/fixtures/unit/to_csv_with_common_options/teams.yml +3 -0
- data/tests/fixtures/unit/to_csv_with_default_options/developers.yml +7 -0
- data/tests/models/address.rb +4 -0
- data/tests/models/animal.rb +2 -0
- data/tests/models/book.rb +3 -0
- data/tests/models/cart_item.rb +4 -0
- data/tests/models/developer.rb +8 -0
- data/tests/models/group.rb +3 -0
- data/tests/models/language.rb +5 -0
- data/tests/models/mysql/book.rb +3 -0
- data/tests/models/mysql/test_innodb.rb +3 -0
- data/tests/models/mysql/test_memory.rb +3 -0
- data/tests/models/mysql/test_myisam.rb +3 -0
- data/tests/models/project.rb +2 -0
- data/tests/models/shopping_cart.rb +4 -0
- data/tests/models/team.rb +4 -0
- data/tests/models/topic.rb +13 -0
- data/tests/mysql/test_create_and_update.rb +290 -0
- data/tests/mysql/test_delete.rb +142 -0
- data/tests/mysql/test_finder_options.rb +121 -0
- data/tests/mysql/test_finders.rb +29 -0
- data/tests/mysql/test_import.rb +354 -0
- data/tests/mysql/test_insert_select.rb +173 -0
- data/tests/mysql/test_mysql_adapter.rb +45 -0
- data/tests/mysql/test_union.rb +81 -0
- data/tests/oracle/test_adapter.rb +14 -0
- data/tests/postgresql/test_adapter.rb +14 -0
- metadata +147 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
class MysqlAdapterTest< TestCaseSuperClass
|
2
|
+
include ActiveRecord::ConnectionAdapters
|
3
|
+
|
4
|
+
def setup
|
5
|
+
@connection = ActiveRecord::Base.connection
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_get_insert_value_sets
|
9
|
+
values = [
|
10
|
+
"('1','2','3')",
|
11
|
+
"('4','5','6')",
|
12
|
+
"('7','8','9')" ]
|
13
|
+
|
14
|
+
values_size_in_bytes = MysqlAdapter.sum_sizes( *values )
|
15
|
+
base_sql_size_in_bytes = 15
|
16
|
+
max_bytes = 30
|
17
|
+
|
18
|
+
value_sets = MysqlAdapter.get_insert_value_sets( values, base_sql_size_in_bytes, max_bytes )
|
19
|
+
assert_equal 3, value_sets.size, 'Three value sets were expected!'
|
20
|
+
|
21
|
+
# Each element in the value_sets array must be an array
|
22
|
+
value_sets.each_with_index { |e,i|
|
23
|
+
assert_kind_of Array, e, "Element #{i} was expected to be an Array!" }
|
24
|
+
|
25
|
+
# Each element in the values array should have a 1:1 correlation to the elements
|
26
|
+
# in the returned value_sets arrays
|
27
|
+
assert_equal values[0], value_sets[0].first
|
28
|
+
assert_equal values[1], value_sets[1].first
|
29
|
+
assert_equal values[2], value_sets[2].first
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_insert_many
|
33
|
+
base_sql = "INSERT INTO #{Topic.table_name} (`title`,`author_name`) VALUES "
|
34
|
+
values = [
|
35
|
+
"('Morgawr','Brooks, Terry')",
|
36
|
+
"('Antrax', 'Brooks, Terry')",
|
37
|
+
"('Jarka Ruus', 'Brooks, Terry')" ]
|
38
|
+
|
39
|
+
expected_count = Topic.count + values.size
|
40
|
+
@connection.insert_many( base_sql, values )
|
41
|
+
assert_equal expected_count, Topic.count, "Incorrect number of records in the database!"
|
42
|
+
Topic.destroy_all
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), '../test_helper') )
|
2
|
+
|
3
|
+
class UnionTest < TestCaseSuperClass
|
4
|
+
fixtures 'books'
|
5
|
+
|
6
|
+
def test_union_should_query_five_records
|
7
|
+
books = Book.find_union({:conditions => ['author_name = ?', 'Terry Brooks']},
|
8
|
+
{:conditions => 'id > 3 and id < 6'})
|
9
|
+
|
10
|
+
|
11
|
+
assert_equal(5, books.length)
|
12
|
+
books.each {|book|
|
13
|
+
assert(book.author_name == 'Terry Brooks' || (book.id > 3 && book.id < 6))
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_union_with_unused_include_should_query_five_records
|
18
|
+
books = Book.find_union({:conditions => ['author_name = ?', 'Terry Brooks']},
|
19
|
+
{:conditions => 'books.id > 3 and books.id < 6', :include => :topic})
|
20
|
+
|
21
|
+
|
22
|
+
assert_equal(5, books.length)
|
23
|
+
books.each {|book|
|
24
|
+
assert(book.author_name == 'Terry Brooks' || (book.id > 3 && book.id < 6))
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def test_union_with_include_should_load_5_books
|
30
|
+
@topic = Topic.create!(:title => 'funtimes', :author_name => 'giraffe')
|
31
|
+
Book.update_all(['topic_id = ? ', @topic.id], ['books.id > 3 and books.id < 6'])
|
32
|
+
|
33
|
+
|
34
|
+
books = Book.find_union({:conditions => ['author_name = ?', 'Terry Brooks']},
|
35
|
+
{:conditions => ['topics.title = :name',{:name => @topic.title}],
|
36
|
+
:include => ['topic']})
|
37
|
+
|
38
|
+
|
39
|
+
assert_equal(5, books.length)
|
40
|
+
|
41
|
+
books.each {|book|
|
42
|
+
assert(book.author_name == 'Terry Brooks' || (book.id > 3 && book.id < 6))
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_union_with_limit_should_query_four_records
|
47
|
+
books = Book.find_union({:conditions => ['author_name = ?', 'Terry Brooks']},
|
48
|
+
{:conditions => 'id > 3 and id < 6', :limit => 1})
|
49
|
+
|
50
|
+
assert_equal(4, books.length)
|
51
|
+
books.each {|book|
|
52
|
+
assert(book.author_name == 'Terry Brooks' || (book.id > 3 && book.id < 6))
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_count_union_should_query_five_records_for_id
|
57
|
+
count = Book.count_union(:id, {:conditions => ['author_name = ?', 'Terry Brooks']},
|
58
|
+
{:conditions => 'id > 3 and id < 6'})
|
59
|
+
|
60
|
+
assert_equal(5, count)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_union_should_query_four_records_using_limit
|
64
|
+
count = Book.count_union(:all,
|
65
|
+
{:conditions => ['author_name = ?', 'Terry Brooks']},
|
66
|
+
{:conditions => 'id > 3 and id < 6', :limit => 1})
|
67
|
+
|
68
|
+
assert_equal(4, count)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_count_union_should_count_two_authors
|
72
|
+
count = Book.count_union(:author_name, {:conditions => ['author_name = ?', 'Terry Brooks']},
|
73
|
+
{:conditions => 'id > 3 and id < 6'})
|
74
|
+
|
75
|
+
assert_equal(2, count)
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), '..', 'test_helper' ) )
|
2
|
+
|
3
|
+
class OracleAdapterTest< TestCaseSuperClass
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@target = ActiveRecord::ConnectionAdapters::OracleAdapter.allocate
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_generate_the_correct_next_value_for_sequence
|
10
|
+
result = @target.next_value_for_sequence("blah")
|
11
|
+
assert_equal 'blah.nextval', result, "wrong next value sequence identifier"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), '..', 'test_helper' ) )
|
2
|
+
|
3
|
+
class PostgreSQLAdapterTest< TestCaseSuperClass
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@target = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.allocate
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_generate_the_correct_next_value_for_sequence
|
10
|
+
result = @target.next_value_for_sequence("blah")
|
11
|
+
assert_equal %{nextval('blah')}, result, "wrong next value sequence identifier"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jorahood-ar-extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.2.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zach Dennis
|
8
|
+
- Mark Van Holstyn
|
9
|
+
- Blythe Dunham
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2009-06-16 00:00:00 -07:00
|
15
|
+
default_executable:
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: activerecord
|
19
|
+
type: :runtime
|
20
|
+
version_requirement:
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 2.1.2
|
26
|
+
version:
|
27
|
+
description: Extends ActiveRecord functionality by adding better finder/query support, as well as supporting mass data import, foreign key, CSV and temporary tables
|
28
|
+
email: zach.dennis@gmail.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files:
|
34
|
+
- README
|
35
|
+
files:
|
36
|
+
- init.rb
|
37
|
+
- Rakefile
|
38
|
+
- ChangeLog
|
39
|
+
- README
|
40
|
+
- db/migrate
|
41
|
+
- db/migrate/generic_schema.rb
|
42
|
+
- db/migrate/mysql_schema.rb
|
43
|
+
- db/migrate/oracle_schema.rb
|
44
|
+
- db/migrate/version.rb
|
45
|
+
- config/database.yml
|
46
|
+
- config/database.yml.template
|
47
|
+
- config/mysql.schema
|
48
|
+
- config/postgresql.schema
|
49
|
+
- lib/ar-extensions/create_and_update.rb
|
50
|
+
- lib/ar-extensions/csv.rb
|
51
|
+
- lib/ar-extensions/delete.rb
|
52
|
+
- lib/ar-extensions/extensions.rb
|
53
|
+
- lib/ar-extensions/finder_options.rb
|
54
|
+
- lib/ar-extensions/finders.rb
|
55
|
+
- lib/ar-extensions/foreign_keys.rb
|
56
|
+
- lib/ar-extensions/fulltext.rb
|
57
|
+
- lib/ar-extensions/import.rb
|
58
|
+
- lib/ar-extensions/insert_select.rb
|
59
|
+
- lib/ar-extensions/synchronize.rb
|
60
|
+
- lib/ar-extensions/temporary_table.rb
|
61
|
+
- lib/ar-extensions/union.rb
|
62
|
+
- lib/ar-extensions/version.rb
|
63
|
+
- tests/connections/native_mysql
|
64
|
+
- tests/connections/native_mysql/connection.rb
|
65
|
+
- tests/connections/native_oracle
|
66
|
+
- tests/connections/native_oracle/connection.rb
|
67
|
+
- tests/connections/native_postgresql
|
68
|
+
- tests/connections/native_postgresql/connection.rb
|
69
|
+
- tests/connections/native_sqlite
|
70
|
+
- tests/connections/native_sqlite/connection.rb
|
71
|
+
- tests/connections/native_sqlite3
|
72
|
+
- tests/connections/native_sqlite3/connection.rb
|
73
|
+
- tests/fixtures/addresses.yml
|
74
|
+
- tests/fixtures/books.yml
|
75
|
+
- tests/fixtures/developers.yml
|
76
|
+
- tests/fixtures/unit
|
77
|
+
- tests/fixtures/unit/active_record_base_finders
|
78
|
+
- tests/fixtures/unit/active_record_base_finders/addresses.yml
|
79
|
+
- tests/fixtures/unit/active_record_base_finders/books.yml
|
80
|
+
- tests/fixtures/unit/active_record_base_finders/developers.yml
|
81
|
+
- tests/fixtures/unit/synchronize
|
82
|
+
- tests/fixtures/unit/synchronize/books.yml
|
83
|
+
- tests/fixtures/unit/to_csv_headers
|
84
|
+
- tests/fixtures/unit/to_csv_headers/addresses.yml
|
85
|
+
- tests/fixtures/unit/to_csv_headers/developers.yml
|
86
|
+
- tests/fixtures/unit/to_csv_with_common_options
|
87
|
+
- tests/fixtures/unit/to_csv_with_common_options/addresses.yml
|
88
|
+
- tests/fixtures/unit/to_csv_with_common_options/developers.yml
|
89
|
+
- tests/fixtures/unit/to_csv_with_common_options/languages.yml
|
90
|
+
- tests/fixtures/unit/to_csv_with_common_options/teams.yml
|
91
|
+
- tests/fixtures/unit/to_csv_with_default_options
|
92
|
+
- tests/fixtures/unit/to_csv_with_default_options/developers.yml
|
93
|
+
- tests/models/address.rb
|
94
|
+
- tests/models/animal.rb
|
95
|
+
- tests/models/book.rb
|
96
|
+
- tests/models/cart_item.rb
|
97
|
+
- tests/models/developer.rb
|
98
|
+
- tests/models/group.rb
|
99
|
+
- tests/models/language.rb
|
100
|
+
- tests/models/mysql
|
101
|
+
- tests/models/mysql/book.rb
|
102
|
+
- tests/models/mysql/test_innodb.rb
|
103
|
+
- tests/models/mysql/test_memory.rb
|
104
|
+
- tests/models/mysql/test_myisam.rb
|
105
|
+
- tests/models/project.rb
|
106
|
+
- tests/models/shopping_cart.rb
|
107
|
+
- tests/models/team.rb
|
108
|
+
- tests/models/topic.rb
|
109
|
+
- tests/mysql/test_create_and_update.rb
|
110
|
+
- tests/mysql/test_delete.rb
|
111
|
+
- tests/mysql/test_finder_options.rb
|
112
|
+
- tests/mysql/test_finders.rb
|
113
|
+
- tests/mysql/test_import.rb
|
114
|
+
- tests/mysql/test_insert_select.rb
|
115
|
+
- tests/mysql/test_mysql_adapter.rb
|
116
|
+
- tests/mysql/test_union.rb
|
117
|
+
- tests/oracle/test_adapter.rb
|
118
|
+
- tests/postgresql/test_adapter.rb
|
119
|
+
has_rdoc: true
|
120
|
+
homepage: http://www.continuousthinking.com/tags/arext
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options:
|
123
|
+
- --main
|
124
|
+
- README
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: "0"
|
132
|
+
version:
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: "0"
|
138
|
+
version:
|
139
|
+
requirements: []
|
140
|
+
|
141
|
+
rubyforge_project: arext
|
142
|
+
rubygems_version: 1.2.0
|
143
|
+
signing_key:
|
144
|
+
specification_version: 2
|
145
|
+
summary: Extends ActiveRecord functionality. Added compatibility with composite-primary-keys
|
146
|
+
test_files: []
|
147
|
+
|