arel-helpers 2.10.0 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -2
- data/README.md +29 -3
- data/arel-helpers.gemspec +12 -9
- data/lib/arel-helpers/join_association.rb +61 -34
- data/lib/arel-helpers/query_builder.rb +16 -1
- data/lib/arel-helpers/version.rb +1 -1
- data/spec/aliases_spec.rb +5 -7
- data/spec/arel_table_spec.rb +11 -13
- data/spec/env/models.rb +2 -6
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +34 -0
- data/spec/internal/log/test.log +530 -0
- data/spec/join_association_spec.rb +101 -57
- data/spec/query_builder_spec.rb +39 -18
- data/spec/spec_helper.rb +10 -19
- metadata +57 -13
- data/spec/env/migrations.rb +0 -75
- data/spec/env.rb +0 -44
@@ -1,94 +1,137 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
describe ArelHelpers do
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
Post.joins(ArelHelpers.join_association(Post, :comments)).to_sql.
|
9
|
-
'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"'
|
4
|
+
describe '#join_association' do
|
5
|
+
it 'should work for a directly associated model' do
|
6
|
+
expect(Post.joins(ArelHelpers.join_association(Post, :comments)).to_sql).to(
|
7
|
+
eq('SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"')
|
8
|
+
)
|
10
9
|
end
|
11
10
|
|
12
|
-
it
|
13
|
-
Post.joins(ArelHelpers.join_association(Post, :comments, Arel::Nodes::OuterJoin)).to_sql.
|
14
|
-
'SELECT "posts".* FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id"'
|
11
|
+
it 'should work with an outer join' do
|
12
|
+
expect(Post.joins(ArelHelpers.join_association(Post, :comments, Arel::Nodes::OuterJoin)).to_sql).to(
|
13
|
+
eq('SELECT "posts".* FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id"')
|
14
|
+
)
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
Post.joins(ArelHelpers.join_association(Post, :comments) do |
|
17
|
+
it 'should allow adding additional join conditions' do
|
18
|
+
sql = Post.joins(ArelHelpers.join_association(Post, :comments) do |_assoc_name, join_conditions|
|
19
19
|
join_conditions.and(Comment[:id].eq(10))
|
20
|
-
end).to_sql
|
21
|
-
|
20
|
+
end).to_sql
|
21
|
+
|
22
|
+
expect(sql).to eq <<-SQL.squish
|
23
|
+
SELECT "posts".* FROM "posts"
|
24
|
+
INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" AND "comments"."id" = 10
|
25
|
+
SQL
|
22
26
|
end
|
23
27
|
|
24
|
-
it
|
25
|
-
Post
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
it 'should work for two models, one directly associated and the other indirectly' do
|
29
|
+
sql = Post
|
30
|
+
.joins(ArelHelpers.join_association(Post, :comments))
|
31
|
+
.joins(ArelHelpers.join_association(Comment, :author))
|
32
|
+
.to_sql
|
33
|
+
|
34
|
+
expect(sql).to eq <<-SQL.squish
|
35
|
+
SELECT "posts".* FROM "posts"
|
36
|
+
INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"
|
37
|
+
INNER JOIN "authors" ON "authors"."id" = "comments"."author_id"
|
38
|
+
SQL
|
30
39
|
end
|
31
40
|
|
32
|
-
it
|
33
|
-
Post
|
34
|
-
|
35
|
-
|
36
|
-
|
41
|
+
it 'should work for a nested hash of association names' do
|
42
|
+
sql = Post
|
43
|
+
.joins(ArelHelpers.join_association(Post, { comments: :author }))
|
44
|
+
.to_sql
|
45
|
+
|
46
|
+
expect(sql).to eq <<-SQL.squish
|
47
|
+
SELECT "posts".* FROM "posts"
|
48
|
+
INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"
|
49
|
+
INNER JOIN "authors" ON "authors"."id" = "comments"."author_id"
|
50
|
+
SQL
|
37
51
|
end
|
38
52
|
|
39
|
-
it
|
40
|
-
Post
|
41
|
-
|
42
|
-
|
43
|
-
|
53
|
+
it 'should work with outer joins when given a nested hash of association names' do
|
54
|
+
sql = Post.joins(ArelHelpers.join_association(Post, { comments: :author }, Arel::Nodes::OuterJoin)).to_sql
|
55
|
+
|
56
|
+
expect(sql).to eq <<-SQL.squish
|
57
|
+
SELECT "posts".* FROM "posts"
|
58
|
+
LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id"
|
59
|
+
LEFT OUTER JOIN "authors" ON "authors"."id" = "comments"."author_id"
|
60
|
+
SQL
|
44
61
|
end
|
45
62
|
|
46
|
-
it
|
47
|
-
Post.joins(ArelHelpers.join_association(Post, [
|
48
|
-
|
63
|
+
it 'should be able to handle multiple associations' do
|
64
|
+
expect(Post.joins(ArelHelpers.join_association(Post, %i[comments favorites])).to_sql).to(
|
65
|
+
eq <<-SQL.squish
|
66
|
+
SELECT "posts".* FROM "posts"
|
67
|
+
INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"
|
68
|
+
INNER JOIN "favorites" ON "favorites"."post_id" = "posts"."id"
|
69
|
+
SQL
|
70
|
+
)
|
49
71
|
end
|
50
72
|
|
51
|
-
it
|
52
|
-
Post.joins(ArelHelpers.join_association(Post, [
|
73
|
+
it 'should yield once for each association' do
|
74
|
+
sql = Post.joins(ArelHelpers.join_association(Post, %i[comments favorites]) do |assoc_name, join_conditions|
|
53
75
|
case assoc_name
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
76
|
+
when :favorites
|
77
|
+
join_conditions.or(Favorite[:amount].eq('lots'))
|
78
|
+
when :comments
|
79
|
+
join_conditions.and(Comment[:text].eq('Awesome post!'))
|
58
80
|
end
|
59
|
-
end).to_sql
|
60
|
-
|
81
|
+
end).to_sql
|
82
|
+
|
83
|
+
expect(sql).to eq <<-SQL.squish
|
84
|
+
SELECT "posts".* FROM "posts"
|
85
|
+
INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" AND "comments"."text" = 'Awesome post!'
|
86
|
+
INNER JOIN "favorites" (ON "favorites"."post_id" = "posts"."id" OR "favorites"."amount" = 'lots')
|
87
|
+
SQL
|
61
88
|
end
|
62
89
|
|
63
90
|
it 'should be able to handle has_and_belongs_to_many associations' do
|
64
|
-
CollabPost.joins(ArelHelpers.join_association(CollabPost, :authors)).to_sql
|
65
|
-
|
91
|
+
sql = CollabPost.joins(ArelHelpers.join_association(CollabPost, :authors)).to_sql
|
92
|
+
|
93
|
+
expect(sql).to eq <<-SQL.squish
|
94
|
+
SELECT "collab_posts".* FROM "collab_posts"
|
95
|
+
INNER JOIN "authors_collab_posts" ON "authors_collab_posts"."collab_post_id" = "collab_posts"."id"
|
96
|
+
INNER JOIN "authors" ON "authors"."id" = "authors_collab_posts"."author_id"
|
97
|
+
SQL
|
66
98
|
end
|
67
99
|
|
68
|
-
it
|
100
|
+
it 'allows adding a custom alias to the joined table' do
|
69
101
|
Comment.aliased_as(:foo) do |foo|
|
70
|
-
Post.joins(
|
71
|
-
|
102
|
+
sql = Post.joins(
|
103
|
+
ArelHelpers.join_association(Post, :comments, Arel::Nodes::InnerJoin, aliases: [foo])
|
104
|
+
).to_sql
|
105
|
+
|
106
|
+
expect(sql).to eq 'SELECT "posts".* FROM "posts" INNER JOIN "comments" "foo" ON "foo"."post_id" = "posts"."id"'
|
72
107
|
end
|
73
108
|
end
|
74
109
|
|
75
|
-
it
|
110
|
+
it 'allows aliasing multiple associations' do
|
76
111
|
Comment.aliased_as(:foo) do |foo|
|
77
112
|
Favorite.aliased_as(:bar) do |bar|
|
78
|
-
Post.joins(
|
79
|
-
|
113
|
+
sql = Post.joins(
|
114
|
+
ArelHelpers.join_association(Post, %i[comments favorites], Arel::Nodes::InnerJoin, aliases: [foo, bar])
|
115
|
+
).to_sql
|
116
|
+
|
117
|
+
expect(sql).to eq <<-SQL.squish
|
118
|
+
SELECT "posts".* FROM "posts"
|
119
|
+
INNER JOIN "comments" "foo" ON "foo"."post_id" = "posts"."id"
|
120
|
+
INNER JOIN "favorites" "bar" ON "bar"."post_id" = "posts"."id"
|
121
|
+
SQL
|
80
122
|
end
|
81
123
|
end
|
82
124
|
end
|
83
125
|
|
84
126
|
it 'handles polymorphic through associations' do
|
85
|
-
|
86
|
-
|
87
|
-
|
127
|
+
location = Location.create!
|
128
|
+
ticket = CommunityTicket.create!
|
129
|
+
CardLocation.create! card: ticket, location: location
|
130
|
+
|
131
|
+
relation = Location.joins(ArelHelpers.join_association(Location, :community_tickets))
|
88
132
|
|
89
|
-
relation.
|
90
|
-
|
91
|
-
'INNER JOIN "community_tickets" ON "community_tickets"."id" = "card_locations"."card_id"'
|
133
|
+
expect(relation.count).to eq 1
|
134
|
+
expect(relation.to_a).to include location
|
92
135
|
end
|
93
136
|
end
|
94
137
|
end
|
@@ -98,8 +141,9 @@ describe ArelHelpers::JoinAssociation do
|
|
98
141
|
include ArelHelpers::JoinAssociation
|
99
142
|
end
|
100
143
|
|
101
|
-
it
|
102
|
-
AssocPost.joins(AssocPost.join_association(:comments)).to_sql.
|
103
|
-
|
144
|
+
it 'should provide the join_association method and use the parent class as the model to join on' do
|
145
|
+
expect(AssocPost.joins(AssocPost.join_association(:comments)).to_sql).to eq <<-SQL.squish
|
146
|
+
SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"
|
147
|
+
SQL
|
104
148
|
end
|
105
149
|
end
|
data/spec/query_builder_spec.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
class TestQueryBuilder < ArelHelpers::QueryBuilder
|
@@ -13,48 +11,71 @@ class TestQueryBuilder < ArelHelpers::QueryBuilder
|
|
13
11
|
def noop
|
14
12
|
reflect(query)
|
15
13
|
end
|
14
|
+
|
15
|
+
not_nil def optional(skip:)
|
16
|
+
reflect(query.where(title: 'BarBar')) unless skip
|
17
|
+
end
|
16
18
|
end
|
17
19
|
|
18
20
|
describe ArelHelpers::QueryBuilder do
|
19
21
|
let(:builder) { TestQueryBuilder.new }
|
20
22
|
|
21
|
-
it
|
23
|
+
it 'returns (i.e. reflects) new instances of QueryBuilder' do
|
22
24
|
builder.tap do |original_builder|
|
23
25
|
original_builder.params = true
|
24
26
|
new_builder = original_builder.noop
|
25
|
-
new_builder.object_id.
|
26
|
-
new_builder.params
|
27
|
+
expect(new_builder.object_id).not_to eq original_builder.object_id
|
28
|
+
expect(new_builder.params?).to be true
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
it
|
31
|
-
Post.create(title:
|
32
|
+
it 'forwards #to_a' do
|
33
|
+
Post.create(title: 'Foobar')
|
32
34
|
builder.to_a.tap do |posts|
|
33
|
-
posts.size.
|
34
|
-
posts.first.title.
|
35
|
+
expect(posts.size).to eq 1
|
36
|
+
expect(posts.first.title).to eq 'Foobar'
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
|
-
it
|
39
|
-
builder.to_sql.strip.
|
40
|
+
it 'forwards #to_sql' do
|
41
|
+
expect(builder.to_sql.strip).to eq 'SELECT "posts".* FROM "posts"'
|
40
42
|
end
|
41
43
|
|
42
|
-
it
|
43
|
-
created_post = Post.create(title:
|
44
|
+
it 'forwards #each' do
|
45
|
+
created_post = Post.create(title: 'Foobar')
|
44
46
|
builder.each do |post|
|
45
|
-
post.
|
47
|
+
expect(post).to eq created_post
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
49
|
-
it
|
50
|
-
Post.create(title:
|
51
|
-
builder.map(&:title).
|
51
|
+
it 'forwards other enumerable methods via #each' do
|
52
|
+
Post.create(title: 'Foobar')
|
53
|
+
expect(builder.map(&:title)).to eq ['Foobar']
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'forwards #empty?' do
|
57
|
+
expect(builder.empty?).to eq true
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'forwards #size' do
|
61
|
+
expect(builder.size).to eq 0
|
52
62
|
end
|
53
63
|
|
54
64
|
ArelHelpers::QueryBuilder::TERMINAL_METHODS.each do |method|
|
55
65
|
it "does not enumerate records for #{method}" do
|
56
|
-
|
66
|
+
allow(builder).to receive :each
|
57
67
|
builder.public_send(method)
|
68
|
+
expect(builder).not_to have_received :each
|
58
69
|
end
|
59
70
|
end
|
71
|
+
|
72
|
+
it 'returns reflect on existing query if method returns a falsy value' do
|
73
|
+
expect(builder.optional(skip: true).to_sql.strip).to eq 'SELECT "posts".* FROM "posts"'
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns reflect on new query for default chainable method if value is truthy' do
|
77
|
+
expect(builder.optional(skip: false).to_sql.strip.gsub(/\s+/, ' ')).to eq <<-SQL.squish
|
78
|
+
SELECT "posts".* FROM "posts" WHERE "posts"."title" = 'BarBar'
|
79
|
+
SQL
|
80
|
+
end
|
60
81
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,29 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
$:.push(File.dirname(__FILE__))
|
1
|
+
$LOAD_PATH.push(File.dirname(__FILE__))
|
4
2
|
|
5
3
|
require 'rspec'
|
6
4
|
require 'arel-helpers'
|
7
5
|
require 'fileutils'
|
8
6
|
|
9
|
-
require '
|
7
|
+
require 'combustion'
|
8
|
+
Combustion.initialize! :active_record
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
$stdout = StringIO.new
|
14
|
-
begin
|
15
|
-
yield
|
16
|
-
ensure
|
17
|
-
$stdout = original_stdout
|
18
|
-
end
|
19
|
-
end
|
10
|
+
require 'database_cleaner'
|
11
|
+
require 'env/models'
|
20
12
|
|
21
13
|
RSpec.configure do |config|
|
22
|
-
|
14
|
+
DatabaseCleaner.strategy = :transaction
|
15
|
+
|
16
|
+
config.before(:suite) { DatabaseCleaner.clean_with :truncation }
|
23
17
|
|
24
|
-
config.before
|
25
|
-
|
26
|
-
ArelHelpers::Env.reset
|
27
|
-
silence { ArelHelpers::Env.migrate }
|
28
|
-
end
|
18
|
+
config.before { DatabaseCleaner.start }
|
19
|
+
config.after { DatabaseCleaner.clean }
|
29
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -30,6 +30,48 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '7'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: appraisal
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: combustion
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.3'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: database_cleaner
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.8'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.8'
|
33
75
|
- !ruby/object:Gem::Dependency
|
34
76
|
name: rake
|
35
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,28 +92,28 @@ dependencies:
|
|
50
92
|
requirements:
|
51
93
|
- - "~>"
|
52
94
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
95
|
+
version: '3'
|
54
96
|
type: :development
|
55
97
|
prerelease: false
|
56
98
|
version_requirements: !ruby/object:Gem::Requirement
|
57
99
|
requirements:
|
58
100
|
- - "~>"
|
59
101
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
102
|
+
version: '3'
|
61
103
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
104
|
+
name: sqlite3
|
63
105
|
requirement: !ruby/object:Gem::Requirement
|
64
106
|
requirements:
|
65
107
|
- - "~>"
|
66
108
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
109
|
+
version: 1.4.0
|
68
110
|
type: :development
|
69
111
|
prerelease: false
|
70
112
|
version_requirements: !ruby/object:Gem::Requirement
|
71
113
|
requirements:
|
72
114
|
- - "~>"
|
73
115
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
116
|
+
version: 1.4.0
|
75
117
|
description: Useful tools to help construct database queries with ActiveRecord and
|
76
118
|
Arel.
|
77
119
|
email:
|
@@ -93,9 +135,11 @@ files:
|
|
93
135
|
- lib/arel-helpers/version.rb
|
94
136
|
- spec/aliases_spec.rb
|
95
137
|
- spec/arel_table_spec.rb
|
96
|
-
- spec/env.rb
|
97
|
-
- spec/env/migrations.rb
|
98
138
|
- spec/env/models.rb
|
139
|
+
- spec/internal/config/database.yml
|
140
|
+
- spec/internal/db/combustion_test.sqlite
|
141
|
+
- spec/internal/db/schema.rb
|
142
|
+
- spec/internal/log/test.log
|
99
143
|
- spec/join_association_spec.rb
|
100
144
|
- spec/query_builder_spec.rb
|
101
145
|
- spec/spec_helper.rb
|
@@ -103,7 +147,7 @@ homepage: https://github.com/camertron/arel-helpers
|
|
103
147
|
licenses:
|
104
148
|
- MIT
|
105
149
|
metadata: {}
|
106
|
-
post_install_message:
|
150
|
+
post_install_message:
|
107
151
|
rdoc_options: []
|
108
152
|
require_paths:
|
109
153
|
- lib
|
@@ -118,8 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
162
|
- !ruby/object:Gem::Version
|
119
163
|
version: '0'
|
120
164
|
requirements: []
|
121
|
-
rubygems_version: 3.
|
122
|
-
signing_key:
|
165
|
+
rubygems_version: 3.2.22
|
166
|
+
signing_key:
|
123
167
|
specification_version: 4
|
124
168
|
summary: Useful tools to help construct database queries with ActiveRecord and Arel.
|
125
169
|
test_files: []
|
data/spec/env/migrations.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
SuperClass = if ActiveRecord::VERSION::MAJOR >= 5
|
4
|
-
ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}".to_f]
|
5
|
-
else
|
6
|
-
ActiveRecord::Migration
|
7
|
-
end
|
8
|
-
|
9
|
-
class CreatePostsTable < SuperClass
|
10
|
-
def change
|
11
|
-
create_table :posts do |t|
|
12
|
-
t.column :title, :string
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class CreateCommentsTable < SuperClass
|
18
|
-
def change
|
19
|
-
create_table :comments do |t|
|
20
|
-
t.references :post
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class CreateAuthorsTable < SuperClass
|
26
|
-
def change
|
27
|
-
create_table :authors do |t|
|
28
|
-
t.references :comment
|
29
|
-
t.references :collab_posts
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class CreateFavoritesTable < SuperClass
|
35
|
-
def change
|
36
|
-
create_table :favorites do |t|
|
37
|
-
t.references :post
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class CreateCollabPostsTable < SuperClass
|
43
|
-
def change
|
44
|
-
create_table :collab_posts do |t|
|
45
|
-
t.references :authors
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
class CreateCardsTable < SuperClass
|
51
|
-
def change
|
52
|
-
create_table :cards
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
class CreateCardLocationsTable < SuperClass
|
57
|
-
def change
|
58
|
-
create_table :card_locations do |t|
|
59
|
-
t.references :location
|
60
|
-
t.references :card, polymorphic: true
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class CreateLocationsTable < SuperClass
|
66
|
-
def change
|
67
|
-
create_table :locations
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
class CreateCommunityTicketsTable < SuperClass
|
72
|
-
def change
|
73
|
-
create_table :community_tickets
|
74
|
-
end
|
75
|
-
end
|
data/spec/env.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'env/migrations'
|
4
|
-
require 'env/models'
|
5
|
-
|
6
|
-
module ArelHelpers
|
7
|
-
class Env
|
8
|
-
class << self
|
9
|
-
|
10
|
-
def db_dir
|
11
|
-
@db_dir ||= File.join(File.dirname(File.dirname(__FILE__)), "tmp")
|
12
|
-
end
|
13
|
-
|
14
|
-
def db_file
|
15
|
-
@db_file ||= File.join(db_dir, "test.sqlite3")
|
16
|
-
end
|
17
|
-
|
18
|
-
def establish_connection
|
19
|
-
ActiveRecord::Base.establish_connection(
|
20
|
-
:adapter => "sqlite3",
|
21
|
-
:database => db_file
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
def migrate
|
26
|
-
CreatePostsTable.new.change
|
27
|
-
CreateCommentsTable.new.change
|
28
|
-
CreateAuthorsTable.new.change
|
29
|
-
CreateFavoritesTable.new.change
|
30
|
-
CreateCollabPostsTable.new.change
|
31
|
-
CreateCardsTable.new.change
|
32
|
-
CreateCardLocationsTable.new.change
|
33
|
-
CreateLocationsTable.new.change
|
34
|
-
CreateCommunityTicketsTable.new.change
|
35
|
-
end
|
36
|
-
|
37
|
-
def reset
|
38
|
-
File.unlink(db_file) if File.exist?(db_file)
|
39
|
-
FileUtils.mkdir_p(db_dir)
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|